1 function getObject(interface) {
4 var e
= document
.createElementNS("http://example.com/", "example");
5 assert_true(e
instanceof Element
);
6 assert_false(e
instanceof HTMLElement
);
7 assert_false(e
instanceof SVGElement
);
10 var e
= document
.createElement("html");
11 assert_true(e
instanceof HTMLElement
);
13 case "HTMLBodyElement":
14 var e
= document
.createElement("body");
15 assert_true(e
instanceof HTMLBodyElement
);
17 case "HTMLFormElement":
18 var e
= document
.createElement("form");
19 assert_true(e
instanceof HTMLFormElement
);
21 case "HTMLFrameSetElement":
22 var e
= document
.createElement("frameset");
23 assert_true(e
instanceof HTMLFrameSetElement
);
26 var e
= document
.createElementNS("http://www.w3.org/2000/svg", "rect");
27 assert_true(e
instanceof SVGElement
);
30 assert_true(document
instanceof Document
);
33 assert_true(window
instanceof Window
);
38 function testSet(interface, attribute
) {
40 var object
= getObject(interface);
42 assert_equals(object
[attribute
], null, "Initially null");
43 object
[attribute
] = nop
;
44 assert_equals(object
[attribute
], nop
, "Return same function");
45 object
[attribute
] = "";
46 assert_equals(object
[attribute
], null, "Return null after setting string");
47 object
[attribute
] = null;
48 assert_equals(object
[attribute
], null, "Finally null");
49 }, "Set " + interface + "." + attribute
);
51 function testReflect(interface, attribute
) {
53 var element
= getObject(interface);
54 assert_false(element
.hasAttribute(attribute
), "Initially missing");
55 element
.setAttribute(attribute
, "return");
56 assert_equals(element
.getAttribute(attribute
), "return", "Return same string");
57 assert_equals(typeof element
[attribute
], "function", "Convert to function");
58 element
.removeAttribute(attribute
);
59 }, "Reflect " + interface + "." + attribute
);
61 function testForwardToWindow(interface, attribute
) {
63 var element
= getObject(interface);
64 window
[attribute
] = null;
65 element
.setAttribute(attribute
, "return");
66 assert_equals(typeof window
[attribute
], "function", "Convert to function");
67 assert_equals(window
[attribute
], element
[attribute
], "Forward content attribute");
69 element
[attribute
] = nop
;
70 assert_equals(window
[attribute
], nop
, "Forward IDL attribute");
71 window
[attribute
] = null;
72 }, "Forward " + interface + "." + attribute
+ " to Window");
74 // Object.propertyIsEnumerable cannot be used because it doesn't
75 // work with properties inherited through the prototype chain.
76 function getEnumerable(interface) {
78 for (var attribute
in getObject(interface)) {
79 enumerable
[attribute
] = true;
83 var enumerableCache
= {};
84 function testEnumerate(interface, attribute
) {
85 if (!(interface in enumerableCache
)) {
86 enumerableCache
[interface] = getEnumerable(interface);
89 assert_true(enumerableCache
[interface][attribute
]);
90 }, "Enumerate " + interface + "." + attribute
);