OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>GlobalEventHandlers test</title> | 2 <title>GlobalEventHandlers test</title> |
3 <script src="../../resources/testharness.js"></script> | 3 <script src="../../resources/testharness.js"></script> |
4 <script src="../../resources/testharnessreport.js"></script> | 4 <script src="../../resources/testharnessreport.js"></script> |
5 <script> | 5 <script> |
6 // attribute list from WHATWG HTML Living Standard r8212 | 6 // attribute list from WHATWG HTML Living Standard r8212 |
7 var attributes = [ | 7 var attributes = [ |
8 "onabort", | 8 "onabort", |
9 "onblur", | 9 "onblur", |
10 "onerror", | 10 "onerror", |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 "onselect", | 58 "onselect", |
59 "onshow", | 59 "onshow", |
60 "onsort", | 60 "onsort", |
61 "onstalled", | 61 "onstalled", |
62 "onsubmit", | 62 "onsubmit", |
63 "onsuspend", | 63 "onsuspend", |
64 "ontimeupdate", | 64 "ontimeupdate", |
65 "onvolumechange", | 65 "onvolumechange", |
66 "onwaiting" | 66 "onwaiting" |
67 ]; | 67 ]; |
68 function testSet(object, attribute, name) { | 68 function getObject(interface) { |
69 function nop() {} | 69 switch(interface) { |
| 70 case "Element": |
| 71 var e = document.createElementNS("http://example.com/", "example"); |
| 72 assert_true(e instanceof Element); |
| 73 assert_false(e instanceof HTMLElement); |
| 74 assert_false(e instanceof SVGElement); |
| 75 return e; |
| 76 case "HTMLElement": |
| 77 var e = document.createElement("html"); |
| 78 assert_true(e instanceof HTMLElement); |
| 79 return e; |
| 80 case "SVGElement": |
| 81 var e = document.createElementNS("http://www.w3.org/2000/svg", "svg"
); |
| 82 assert_true(e instanceof SVGElement); |
| 83 return e; |
| 84 case "Document": |
| 85 assert_true(document instanceof Document); |
| 86 return document; |
| 87 case "Window": |
| 88 assert_true(window instanceof Window); |
| 89 return window; |
| 90 } |
| 91 assert_unreached(); |
| 92 } |
| 93 function testSet(interface, attribute) { |
70 test(function() { | 94 test(function() { |
| 95 var object = getObject(interface); |
| 96 function nop() {} |
71 assert_equals(object[attribute], null, "Initially null"); | 97 assert_equals(object[attribute], null, "Initially null"); |
72 object[attribute] = nop; | 98 object[attribute] = nop; |
73 assert_equals(object[attribute], nop, "Return same function"); | 99 assert_equals(object[attribute], nop, "Return same function"); |
74 document[attribute] = ""; | 100 document[attribute] = ""; |
75 assert_equals(document[attribute], null, "Return null after setting stri
ng"); | 101 assert_equals(document[attribute], null, "Return null after setting stri
ng"); |
76 }, "Set " + name + "." + attribute); | 102 }, "Set " + interface + "." + attribute); |
77 } | 103 } |
78 function testEnumerate(object, name) { | 104 function testReflect(interface, attribute) { |
79 // Object.propertyIsEnumerable cannot be used because it doesn't | 105 test(function() { |
80 // work with properties inherited through the prototype chain. | 106 var element = getObject(interface); |
81 test(function() { | |
82 var seen = {}; | |
83 attributes.forEach(function(attribute) { | |
84 seen[attribute] = false; | |
85 }); | |
86 for (var attribute in object) { | |
87 seen[attribute] = true; | |
88 } | |
89 attributes.forEach(function(attribute) { | |
90 assert_true(seen[attribute], "Found " + attribute); | |
91 }); | |
92 }, "Enumerate " + name + ".on*"); | |
93 } | |
94 attributes.forEach(function(attribute) { | |
95 testSet(document.createElement('div'), attribute, "element"); | |
96 test(function() { | |
97 var element = document.createElement('div'); | |
98 assert_equals(element.getAttribute(attribute), null, "Initially null"); | 107 assert_equals(element.getAttribute(attribute), null, "Initially null"); |
99 element.setAttribute(attribute, "return"); | 108 element.setAttribute(attribute, "return"); |
100 assert_equals(element.getAttribute(attribute), "return", "Return same st
ring"); | 109 assert_equals(element.getAttribute(attribute), "return", "Return same st
ring"); |
101 assert_equals(typeof element[attribute], "function", "Convert to functio
n"); | 110 assert_equals(typeof element[attribute], "function", "Convert to functio
n"); |
102 }, "Reflect element." + attribute); | 111 }, "Reflect " + interface + "." + attribute); |
103 testSet(document, attribute, "document"); | 112 } |
104 testSet(window, attribute, "window"); | 113 // Object.propertyIsEnumerable cannot be used because it doesn't |
| 114 // work with properties inherited through the prototype chain. |
| 115 var enumerable = { |
| 116 "Element": {}, |
| 117 "HTMLElement": {}, |
| 118 "SVGElement": {}, |
| 119 "Document": {}, |
| 120 "Window": {} |
| 121 }; |
| 122 Object.keys(enumerable).forEach(function(interface) { |
| 123 for (var attribute in getObject(interface)) { |
| 124 enumerable[interface][attribute] = true; |
| 125 } |
105 }); | 126 }); |
106 testEnumerate(document.createElement('div'), "element"); | 127 function testEnumerate(interface, attribute) { |
107 testEnumerate(document, "document"); | 128 test(function() { |
108 testEnumerate(window, "window"); | 129 assert_true(enumerable[interface][attribute]); |
| 130 }, "Enumerate " + interface + "." + attribute); |
| 131 } |
| 132 attributes.forEach(function(attribute) { |
| 133 test(function() { |
| 134 assert_false(attribute in getObject("Element")); |
| 135 }, "No Element." + attribute); |
| 136 testSet("HTMLElement", attribute); |
| 137 testEnumerate("HTMLElement", attribute); |
| 138 testReflect("HTMLElement", attribute); |
| 139 testSet("Document", attribute); |
| 140 testEnumerate("Document", attribute); |
| 141 testSet("Window", attribute); |
| 142 testEnumerate("Window", attribute); |
| 143 }); |
109 </script> | 144 </script> |
110 <div id="log"></div> | 145 <div id="log"></div> |
OLD | NEW |