| OLD | NEW |
| (Empty) |
| 1 function getObject(interface) { | |
| 2 switch(interface) { | |
| 3 case "Element": | |
| 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); | |
| 8 return e; | |
| 9 case "HTMLElement": | |
| 10 var e = document.createElement("html"); | |
| 11 assert_true(e instanceof HTMLElement); | |
| 12 return e; | |
| 13 case "HTMLBodyElement": | |
| 14 var e = document.createElement("body"); | |
| 15 assert_true(e instanceof HTMLBodyElement); | |
| 16 return e; | |
| 17 case "HTMLFormElement": | |
| 18 var e = document.createElement("form"); | |
| 19 assert_true(e instanceof HTMLFormElement); | |
| 20 return e; | |
| 21 case "HTMLFrameSetElement": | |
| 22 var e = document.createElement("frameset"); | |
| 23 assert_true(e instanceof HTMLFrameSetElement); | |
| 24 return e; | |
| 25 case "SVGElement": | |
| 26 var e = document.createElementNS("http://www.w3.org/2000/svg", "rect
"); | |
| 27 assert_true(e instanceof SVGElement); | |
| 28 return e; | |
| 29 case "Document": | |
| 30 assert_true(document instanceof Document); | |
| 31 return document; | |
| 32 case "Window": | |
| 33 assert_true(window instanceof Window); | |
| 34 return window; | |
| 35 } | |
| 36 assert_unreached(); | |
| 37 } | |
| 38 function testSet(interface, attribute) { | |
| 39 test(function() { | |
| 40 var object = getObject(interface); | |
| 41 function nop() {} | |
| 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); | |
| 50 } | |
| 51 function testReflect(interface, attribute) { | |
| 52 test(function() { | |
| 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 st
ring"); | |
| 57 assert_equals(typeof element[attribute], "function", "Convert to functio
n"); | |
| 58 element.removeAttribute(attribute); | |
| 59 }, "Reflect " + interface + "." + attribute); | |
| 60 } | |
| 61 function testForwardToWindow(interface, attribute) { | |
| 62 test(function() { | |
| 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 at
tribute"); | |
| 68 function nop() {} | |
| 69 element[attribute] = nop; | |
| 70 assert_equals(window[attribute], nop, "Forward IDL attribute"); | |
| 71 window[attribute] = null; | |
| 72 }, "Forward " + interface + "." + attribute + " to Window"); | |
| 73 } | |
| 74 // Object.propertyIsEnumerable cannot be used because it doesn't | |
| 75 // work with properties inherited through the prototype chain. | |
| 76 function getEnumerable(interface) { | |
| 77 var enumerable = {}; | |
| 78 for (var attribute in getObject(interface)) { | |
| 79 enumerable[attribute] = true; | |
| 80 } | |
| 81 return enumerable; | |
| 82 } | |
| 83 var enumerableCache = {}; | |
| 84 function testEnumerate(interface, attribute) { | |
| 85 if (!(interface in enumerableCache)) { | |
| 86 enumerableCache[interface] = getEnumerable(interface); | |
| 87 } | |
| 88 test(function() { | |
| 89 assert_true(enumerableCache[interface][attribute]); | |
| 90 }, "Enumerate " + interface + "." + attribute); | |
| 91 } | |
| OLD | NEW |