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

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

Issue 1854003004: Import web-platform-tests@5a8700479d98852455bee6117558897867eb278a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <meta charset=utf-8> 2 <meta charset=utf-8>
3 <title>Attributes tests</title> 3 <title>Attributes tests</title>
4 <link rel=help href="https://dom.spec.whatwg.org/#attr"> 4 <link rel=help href="https://dom.spec.whatwg.org/#attr">
5 <link rel=help href="https://dom.spec.whatwg.org/#dom-element-setattribute"> 5 <link rel=help href="https://dom.spec.whatwg.org/#dom-element-setattribute">
6 <link rel=help href="https://dom.spec.whatwg.org/#dom-element-setattributens"> 6 <link rel=help href="https://dom.spec.whatwg.org/#dom-element-setattributens">
7 <script src="../../../../resources/testharness.js"></script> 7 <script src="../../../../resources/testharness.js"></script>
8 <script src="../../../../resources/testharnessreport.js"></script> 8 <script src="../../../../resources/testharnessreport.js"></script>
9 <script src="attributes.js"></script> 9 <script src="attributes.js"></script>
10 <script src="productions.js"></script> 10 <script src="productions.js"></script>
11 <div id="log"></div> 11 <div id="log"></div>
12 <span id="test1"></span> 12 <span id="test1"></span>
13 <span class="&amp;&lt;&gt;foo"></span> 13 <span class="&amp;&lt;&gt;foo"></span>
14 <span id="test2">
15 <span ~=""></span>
16 <span ~></span>
17 <span></span>
18 </span>
14 <script> 19 <script>
15 var XML = "http://www.w3.org/XML/1998/namespace" 20 var XML = "http://www.w3.org/XML/1998/namespace"
16 var XMLNS = "http://www.w3.org/2000/xmlns/" 21 var XMLNS = "http://www.w3.org/2000/xmlns/"
17 22
18 // AttrExodus 23 // AttrExodus
19 test(function() { 24 test(function() {
20 document.body.setAttribute("abc", "pass") 25 document.body.setAttribute("abc", "pass")
21 var attr = document.body.attributes[0] 26 var attr = document.body.attributes[0]
22 assert_true(attr instanceof Attr, "should be an Attr") 27 assert_true(attr instanceof Attr, "should be an Attr")
23 assert_false(attr instanceof Node, "should not be a Node") 28 assert_false(attr instanceof Node, "should not be a Node")
(...skipping 10 matching lines...) Expand all
34 39
35 // setAttribute exhaustive tests 40 // setAttribute exhaustive tests
36 // Step 1 41 // Step 1
37 test(function() { 42 test(function() {
38 var el = document.createElement("foo") 43 var el = document.createElement("foo")
39 for (var i = 0; i < invalid_names.length; i++) { 44 for (var i = 0; i < invalid_names.length; i++) {
40 assert_throws("INVALID_CHARACTER_ERR", function() { el.setAttribute(invalid_ names[i], "test") }) 45 assert_throws("INVALID_CHARACTER_ERR", function() { el.setAttribute(invalid_ names[i], "test") })
41 } 46 }
42 }, "When qualifiedName does not match the Name production, an " + 47 }, "When qualifiedName does not match the Name production, an " +
43 "INVALID_CHARACTER_ERR exception is to be thrown. (setAttribute)") 48 "INVALID_CHARACTER_ERR exception is to be thrown. (setAttribute)")
49 test(function() {
50 var el = document.getElementById("test2")
51 for (var i = 0; i < el.children.length; i++) {
52 assert_throws("INVALID_CHARACTER_ERR", function() {
53 el.children[i].setAttribute("~", "test")
54 })
55 }
56 }, "When qualifiedName does not match the Name production, an " +
57 "INVALID_CHARACTER_ERR exception is to be thrown, even if the attribute " +
58 "is already present. (setAttribute)")
44 59
45 // Step 2 60 // Step 2
46 test(function() { 61 test(function() {
47 var el = document.createElement("div") 62 var el = document.createElement("div")
48 el.setAttribute("ALIGN", "left") 63 el.setAttribute("ALIGN", "left")
49 assert_equals(el.getAttributeNS("", "ALIGN"), null) 64 assert_equals(el.getAttributeNS("", "ALIGN"), null)
50 assert_equals(el.getAttributeNS("", "align"), "left") 65 assert_equals(el.getAttributeNS("", "align"), "left")
51 assert_equals(el.getAttribute("align"), "left") 66 assert_equals(el.getAttribute("align"), "left")
52 }, "setAttribute should lowercase its name argument (upper case attribute)") 67 }, "setAttribute should lowercase its name argument (upper case attribute)")
53 test(function() { 68 test(function() {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // Step 1 125 // Step 1
111 test(function() { 126 test(function() {
112 var el = document.createElement("foo") 127 var el = document.createElement("foo")
113 for (var i = 0, il = invalid_names.length; i < il; ++i) { 128 for (var i = 0, il = invalid_names.length; i < il; ++i) {
114 assert_throws("INVALID_CHARACTER_ERR", 129 assert_throws("INVALID_CHARACTER_ERR",
115 function() { el.setAttributeNS("a", invalid_names[i], "fail") }) 130 function() { el.setAttributeNS("a", invalid_names[i], "fail") })
116 } 131 }
117 }, "When qualifiedName does not match the Name production, an " + 132 }, "When qualifiedName does not match the Name production, an " +
118 "INVALID_CHARACTER_ERR exception is to be thrown. (setAttributeNS)") 133 "INVALID_CHARACTER_ERR exception is to be thrown. (setAttributeNS)")
119 134
135 test(function() {
136 var el = document.getElementById("test2")
137 for (var i = 0; i < el.children.length; i++) {
138 assert_throws("INVALID_CHARACTER_ERR", function() {
139 el.children[i].setAttributeNS(null, "~", "test")
140 })
141 }
142 }, "When qualifiedName does not match the Name production, an " +
143 "INVALID_CHARACTER_ERR exception is to be thrown, even if the attribute " +
144 "is already present. (setAttributeNS)")
145
120 // Step 2 146 // Step 2
121 test(function() { 147 test(function() {
122 var el = document.createElement("foo") 148 var el = document.createElement("foo")
123 for (var i = 0, il = invalid_qnames.length; i < il; ++i) { 149 for (var i = 0, il = invalid_qnames.length; i < il; ++i) {
124 assert_throws("NAMESPACE_ERR", 150 assert_throws("NAMESPACE_ERR",
125 function() { el.setAttributeNS("a", invalid_qnames[i], "fail") }, 151 function() { el.setAttributeNS("a", invalid_qnames[i], "fail") },
126 "Expected exception for " + invalid_qnames[i] + ".") 152 "Expected exception for " + invalid_qnames[i] + ".")
127 } 153 }
128 }, "When qualifiedName does not match the QName production, an " + 154 }, "When qualifiedName does not match the QName production, an " +
129 "NAMESPACE_ERR exception is to be thrown.") 155 "NAMESPACE_ERR exception is to be thrown.")
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 for (var prop in obj) { 604 for (var prop in obj) {
579 if (obj.hasOwnProperty(prop)) { 605 if (obj.hasOwnProperty(prop)) {
580 arr.push(prop); 606 arr.push(prop);
581 } 607 }
582 } 608 }
583 return arr; 609 return arr;
584 } 610 }
585 611
586 function getEnumerableOwnProps2(obj) { 612 function getEnumerableOwnProps2(obj) {
587 return Object.getOwnPropertyNames(obj).filter( 613 return Object.getOwnPropertyNames(obj).filter(
588 (name) => Object.getOwnPropertyDescriptor(obj, name).enumerable) 614 function (name) { return Object.getOwnPropertyDescriptor(obj, name).enumerab le; })
589 } 615 }
590 616
591 test(function() { 617 test(function() {
592 var el = document.createElement("div"); 618 var el = document.createElement("div");
593 el.setAttribute("a", ""); 619 el.setAttribute("a", "");
594 el.setAttribute("b", ""); 620 el.setAttribute("b", "");
595 assert_array_equals(getEnumerableOwnProps1(el.attributes), 621 assert_array_equals(getEnumerableOwnProps1(el.attributes),
596 ["0", "1"]) 622 ["0", "1"])
597 assert_array_equals(getEnumerableOwnProps2(el.attributes), 623 assert_array_equals(getEnumerableOwnProps2(el.attributes),
598 ["0", "1"]) 624 ["0", "1"])
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 el.setAttributeNS("", "I", ""); 720 el.setAttributeNS("", "I", "");
695 el.setAttributeNS("", "j", ""); 721 el.setAttributeNS("", "j", "");
696 assert_array_equals(Object.getOwnPropertyNames(el.attributes), 722 assert_array_equals(Object.getOwnPropertyNames(el.attributes),
697 ["0", "1", "2", "3", "4", "5", "A:B", "c:D", "e:F", "g:h", "I", "j"]) 723 ["0", "1", "2", "3", "4", "5", "A:B", "c:D", "e:F", "g:h", "I", "j"])
698 for (var propName of Object.getOwnPropertyNames(el.attributes)) { 724 for (var propName of Object.getOwnPropertyNames(el.attributes)) {
699 assert_true(el.attributes[propName] instanceof Attr, 725 assert_true(el.attributes[propName] instanceof Attr,
700 "el.attributes has an Attr for property name " + propName); 726 "el.attributes has an Attr for property name " + propName);
701 } 727 }
702 }, "Own property names should include all qualified names for an HTML element in a non-HTML document"); 728 }, "Own property names should include all qualified names for an HTML element in a non-HTML document");
703 </script> 729 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698