Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/nodes/attributes.html

Issue 1666363003: Import web-platform-tests@27e3d93f88a71a249d1df872a5d613b3243b9588 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed win failiure in TestExpectations Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/nodes/attributes.html
diff --git a/third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/nodes/attributes.html b/third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/nodes/attributes.html
index ab7922f3bb5c85010249d740e48d010d9fb9d73d..574ab6d1c3f83da74c4e5fd2ef9259eb0ab53617 100644
--- a/third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/nodes/attributes.html
+++ b/third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/nodes/attributes.html
@@ -19,12 +19,17 @@ var XMLNS = "http://www.w3.org/2000/xmlns/"
test(function() {
document.body.setAttribute("abc", "pass")
var attr = document.body.attributes[0]
- assert_true(attr instanceof Attr)
- assert_false(attr instanceof Node)
- assert_throws(new TypeError(), function() { attr.appendChild(document.createTextNode("fail")) })
- assert_throws(new TypeError(), function() { attr.appendChild(null) })
+ assert_true(attr instanceof Attr, "should be an Attr")
+ assert_false(attr instanceof Node, "should not be a Node")
+ var removed_members = [
+ "appendChild",
+ "insertBefore",
+ "childNodes",
+ ]
+ removed_members.forEach(function(m) {
+ assert_false(m in attr, m + " should not be supported")
+ })
assert_equals(attr.value, "pass")
- assert_false("childNodes" in attr, "Should not have childNodes")
}, "AttrExodus")
// setAttribute exhaustive tests
@@ -442,6 +447,26 @@ test(function() {
}, "Basic functionality of setAttributeNodeNS")
test(function() {
+ var el = document.createElement("div");
+ var other = document.createElement("div");
+ attr = document.createAttribute("foo");
+ assert_equals(el.setAttributeNode(attr), null);
+ assert_equals(attr.ownerElement, el);
+ assert_throws("INUSE_ATTRIBUTE_ERR",
+ function() { other.setAttributeNode(attr) },
+ "Attribute already associated with el")
+}, "If attr’s element is neither null nor element, throw an InUseAttributeError.");
+
+test(function() {
+ var el = document.createElement("div");
+ attr = document.createAttribute("foo");
+ assert_equals(el.setAttributeNode(attr), null);
+ el.setAttribute("bar", "qux");
+ assert_equals(el.setAttributeNode(attr), attr);
+ assert_equals(el.attributes[0], attr);
+}, "Replacing an attr by itself");
+
+test(function() {
var el = document.createElement("div")
el.setAttribute("foo", "bar")
var attrNode = el.getAttributeNode("foo");
@@ -460,6 +485,60 @@ test(function() {
assert_throws("INUSE_ATTRIBUTE_ERR", function(){el2.setAttributeNode(attrNode)});
}, "setAttributeNode on bound attribute should throw InUseAttributeError")
+// Have to use an async_test to see what a DOMAttrModified listener sees,
+// because otherwise the event dispatch code will swallow our exceptions. And
+// we want to make sure this test always happens, even when no mutation events
+// run.
+var setAttributeNode_mutation_test = async_test("setAttributeNode, if it fires mutation events, should fire one with the new node when resetting an existing attribute");
+
+test(function(){
+ var el = document.createElement("div")
+ var attrNode1 = document.createAttribute("foo");
+ attrNode1.value = "bar";
+ el.setAttributeNode(attrNode1);
+ var attrNode2 = document.createAttribute("foo");
+ attrNode2.value = "baz";
+
+ el.addEventListener("DOMAttrModified", function(e) {
+ // If this never gets called, that's OK, I guess. But if it gets called, it
+ // better represent a single modification with attrNode2 as the relatedNode.
+ // We have to do an inner test() call here, because otherwise the exceptions
+ // our asserts trigger will get swallowed by the event dispatch code.
+ setAttributeNode_mutation_test.step(function() {
+ assert_equals(e.attrName, "foo");
+ assert_equals(e.attrChange, MutationEvent.MODIFICATION);
+ assert_equals(e.prevValue, "bar");
+ assert_equals(e.newValue, "baz");
+ assert_equals(e.relatedNode, attrNode2);
+ });
+ });
+
+ var oldNode = el.setAttributeNode(attrNode2);
+ assert_equals(oldNode, attrNode1,
+ "Must return the old attr node from a setAttributeNode call");
+}, "setAttributeNode, if it fires mutation events, should fire one with the new node when resetting an existing attribute (outer shell)");
+setAttributeNode_mutation_test.done();
+
+test(function(){
+ var el = document.createElement("div")
+ el.setAttribute("a", "b");
+ el.setAttribute("c", "d");
+
+ assert_array_equals(Array.prototype.map.call(el.attributes, function(a) { return a.name }),
+ ["a", "c"]);
+ assert_array_equals(Array.prototype.map.call(el.attributes, function(a) { return a.value }),
+ ["b", "d"]);
+
+ var attrNode = document.createAttribute("a");
+ attrNode.value = "e";
+ el.setAttributeNode(attrNode);
+
+ assert_array_equals(Array.prototype.map.call(el.attributes, function(a) { return a.name }),
+ ["a", "c"]);
+ assert_array_equals(Array.prototype.map.call(el.attributes, function(a) { return a.value }),
+ ["e", "d"]);
+}, "setAttributeNode called with an Attr that has the same name as an existing one should not change attribute order");
+
test(function() {
var el = document.createElement("div");
el.setAttribute("foo", "bar");
@@ -532,6 +611,10 @@ test(function() {
["0", "1", "2"])
assert_array_equals(Object.getOwnPropertyNames(el.attributes),
["0", "1", "2", "a", "b"])
+ for (var propName of Object.getOwnPropertyNames(el.attributes)) {
+ assert_true(el.attributes[propName] instanceof Attr,
+ "el.attributes has an Attr for property name " + propName);
+ }
}, "Own property correctness with non-namespaced attribute before same-name namespaced one");
test(function() {
@@ -545,6 +628,10 @@ test(function() {
["0", "1", "2"])
assert_array_equals(Object.getOwnPropertyNames(el.attributes),
["0", "1", "2", "a", "b"])
+ for (var propName of Object.getOwnPropertyNames(el.attributes)) {
+ assert_true(el.attributes[propName] instanceof Attr,
+ "el.attributes has an Attr for property name " + propName);
+ }
}, "Own property correctness with namespaced attribute before same-name non-namespaced one");
test(function() {
@@ -558,5 +645,59 @@ test(function() {
["0", "1", "2"])
assert_array_equals(Object.getOwnPropertyNames(el.attributes),
["0", "1", "2", "a:b", "c:d"])
+ for (var propName of Object.getOwnPropertyNames(el.attributes)) {
+ assert_true(el.attributes[propName] instanceof Attr,
+ "el.attributes has an Attr for property name " + propName);
+ }
}, "Own property correctness with two namespaced attributes with the same name-with-prefix");
+
+test(function() {
+ var el = document.createElement("div");
+ el.setAttributeNS("foo", "A:B", "");
+ el.setAttributeNS("bar", "c:D", "");
+ el.setAttributeNS("baz", "e:F", "");
+ el.setAttributeNS("qux", "g:h", "");
+ el.setAttributeNS("", "I", "");
+ el.setAttributeNS("", "j", "");
+ assert_array_equals(Object.getOwnPropertyNames(el.attributes),
+ ["0", "1", "2", "3", "4", "5", "g:h", "j"])
+ for (var propName of Object.getOwnPropertyNames(el.attributes)) {
+ assert_true(el.attributes[propName] instanceof Attr,
+ "el.attributes has an Attr for property name " + propName);
+ }
+}, "Own property names should only include all-lowercase qualified names for an HTML element in an HTML document");
+
+test(function() {
+ var el = document.createElementNS("", "div");
+ el.setAttributeNS("foo", "A:B", "");
+ el.setAttributeNS("bar", "c:D", "");
+ el.setAttributeNS("baz", "e:F", "");
+ el.setAttributeNS("qux", "g:h", "");
+ el.setAttributeNS("", "I", "");
+ el.setAttributeNS("", "j", "");
+ assert_array_equals(Object.getOwnPropertyNames(el.attributes),
+ ["0", "1", "2", "3", "4", "5", "A:B", "c:D", "e:F", "g:h", "I", "j"])
+ for (var propName of Object.getOwnPropertyNames(el.attributes)) {
+ assert_true(el.attributes[propName] instanceof Attr,
+ "el.attributes has an Attr for property name " + propName);
+ }
+}, "Own property names should include all qualified names for a non-HTML element in an HTML document");
+
+test(function() {
+ var doc = document.implementation.createDocument(null, "");
+ assert_equals(doc.contentType, "application/xml");
+ var el = doc.createElementNS("http://www.w3.org/1999/xhtml", "div");
+ el.setAttributeNS("foo", "A:B", "");
+ el.setAttributeNS("bar", "c:D", "");
+ el.setAttributeNS("baz", "e:F", "");
+ el.setAttributeNS("qux", "g:h", "");
+ el.setAttributeNS("", "I", "");
+ el.setAttributeNS("", "j", "");
+ assert_array_equals(Object.getOwnPropertyNames(el.attributes),
+ ["0", "1", "2", "3", "4", "5", "A:B", "c:D", "e:F", "g:h", "I", "j"])
+ for (var propName of Object.getOwnPropertyNames(el.attributes)) {
+ assert_true(el.attributes[propName] instanceof Attr,
+ "el.attributes has an Attr for property name " + propName);
+ }
+}, "Own property names should include all qualified names for an HTML element in a non-HTML document");
</script>

Powered by Google App Engine
This is Rietveld 408576698