trisquel-icecat/icecat/testing/web-platform/tests/dom/nodes/attributes-namednodemap-cross-document.window.js
2025-10-06 02:35:48 -06:00

31 lines
1.1 KiB
JavaScript

"use strict";
test(() => {
const element = document.createElement("div");
element.setAttribute("x", "first");
const attribute = element.attributes[0];
assert_equals(attribute.ownerDocument, document);
const otherDocument = new Document();
const otherElement = otherDocument.createElement("other");
assert_throws_dom("InUseAttributeError", () => otherElement.attributes.setNamedItem(attribute));
element.removeAttribute("x");
otherElement.attributes.setNamedItem(attribute);
assert_equals(attribute.ownerDocument, otherDocument);
}, "Moving an attribute between documents");
test(() => {
const element = document.createElement("div");
element.setAttribute("x", "first");
const attribute = element.attributes[0];
element.removeAttribute("x");
const otherDocument = new Document();
const otherElement = otherDocument.createElement("other");
otherElement.setAttribute("x", "second");
otherElement.attributes.setNamedItem(attribute);
assert_equals(attribute.ownerDocument, otherDocument);
assert_equals(otherElement.getAttribute("x"), "first");
}, "Replacing an attribute across documents");