Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 function getObject(interface) { | 1 function getObject(interface) { |
| 2 switch(interface) { | 2 switch(interface) { |
| 3 case "Element": | 3 case "SVGAnimateElement": |
|
fs
2014/03/17 14:35:27
Alternatively extend the "original" getObject with
Erik Dahlström (inactive)
2014/03/17 15:52:37
You mean add to LayoutTests/fast/dom/script-tests/
| |
| 4 var e = document.createElementNS("http://example.com/", "example"); | 4 var e = document.createElementNS("http://www.w3.org/2000/svg", "anim ate"); |
| 5 assert_true(e instanceof Element); | 5 assert_true(e instanceof SVGAnimateElement); |
| 6 assert_false(e instanceof HTMLElement); | |
| 7 assert_false(e instanceof SVGElement); | |
| 8 return e; | 6 return e; |
| 9 case "HTMLElement": | 7 case "SVGAnimateMotionElement": |
| 10 var e = document.createElement("html"); | 8 var e = document.createElementNS("http://www.w3.org/2000/svg", "anim ateMotion"); |
| 11 assert_true(e instanceof HTMLElement); | 9 assert_true(e instanceof SVGAnimateMotionElement); |
| 12 return e; | 10 return e; |
| 13 case "HTMLBodyElement": | 11 case "SVGAnimateTransformElement": |
| 14 var e = document.createElement("body"); | 12 var e = document.createElementNS("http://www.w3.org/2000/svg", "anim ateTransform"); |
| 15 assert_true(e instanceof HTMLBodyElement); | 13 assert_true(e instanceof SVGAnimateTransformElement); |
| 16 return e; | 14 return e; |
| 17 case "HTMLFormElement": | 15 case "SVGSetElement": |
| 18 var e = document.createElement("form"); | 16 var e = document.createElementNS("http://www.w3.org/2000/svg", "set" ); |
| 19 assert_true(e instanceof HTMLFormElement); | 17 assert_true(e instanceof SVGSetElement); |
| 20 return e; | 18 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 } | 19 } |
| 36 assert_unreached(); | 20 assert_unreached(); |
| 37 } | 21 } |
| 38 function testSet(interface, attribute) { | 22 function testSet(interface, attribute) { |
| 39 test(function() { | 23 test(function() { |
| 40 var object = getObject(interface); | 24 var object = getObject(interface); |
| 41 function nop() {} | 25 function nop() {} |
| 42 assert_equals(object[attribute], null, "Initially null"); | 26 assert_equals(object[attribute], null, "Initially null"); |
| 43 object[attribute] = nop; | 27 object[attribute] = nop; |
| 44 assert_equals(object[attribute], nop, "Return same function"); | 28 assert_equals(object[attribute], nop, "Return same function"); |
| 45 object[attribute] = ""; | 29 object[attribute] = ""; |
| 46 assert_equals(object[attribute], null, "Return null after setting string "); | 30 assert_equals(object[attribute], null, "Return null after setting string "); |
| 47 object[attribute] = null; | 31 object[attribute] = null; |
| 48 assert_equals(object[attribute], null, "Finally null"); | 32 assert_equals(object[attribute], null, "Finally null"); |
| 49 }, "Set " + interface + "." + attribute); | 33 }, "Set " + interface + "." + attribute); |
| 50 } | 34 } |
| 51 function testReflect(interface, attribute) { | 35 function testReflect(interface, attribute) { |
| 52 test(function() { | 36 test(function() { |
| 53 var element = getObject(interface); | 37 var element = getObject(interface); |
| 54 assert_false(element.hasAttribute(attribute), "Initially missing"); | 38 assert_false(element.hasAttribute(attribute), "Initially missing"); |
| 55 element.setAttribute(attribute, "return"); | 39 element.setAttribute(attribute, "return"); |
| 56 assert_equals(element.getAttribute(attribute), "return", "Return same st ring"); | 40 assert_equals(element.getAttribute(attribute), "return", "Return same st ring"); |
| 57 assert_equals(typeof element[attribute], "function", "Convert to functio n"); | 41 assert_equals(typeof element[attribute], "function", "Convert to functio n"); |
| 58 element.removeAttribute(attribute); | 42 element.removeAttribute(attribute); |
| 59 }, "Reflect " + interface + "." + attribute); | 43 }, "Reflect " + interface + "." + attribute); |
| 60 } | 44 } |
| 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 | 45 // Object.propertyIsEnumerable cannot be used because it doesn't |
| 75 // work with properties inherited through the prototype chain. | 46 // work with properties inherited through the prototype chain. |
| 76 function getEnumerable(interface) { | 47 function getEnumerable(interface) { |
| 77 var enumerable = {}; | 48 var enumerable = {}; |
| 78 for (var attribute in getObject(interface)) { | 49 for (var attribute in getObject(interface)) { |
| 79 enumerable[attribute] = true; | 50 enumerable[attribute] = true; |
| 80 } | 51 } |
| 81 return enumerable; | 52 return enumerable; |
| 82 } | 53 } |
| 83 var enumerableCache = {}; | 54 var enumerableCache = {}; |
| 84 function testEnumerate(interface, attribute) { | 55 function testEnumerate(interface, attribute) { |
| 85 if (!(interface in enumerableCache)) { | 56 if (!(interface in enumerableCache)) { |
| 86 enumerableCache[interface] = getEnumerable(interface); | 57 enumerableCache[interface] = getEnumerable(interface); |
| 87 } | 58 } |
| 88 test(function() { | 59 test(function() { |
| 89 assert_true(enumerableCache[interface][attribute]); | 60 assert_true(enumerableCache[interface][attribute]); |
| 90 }, "Enumerate " + interface + "." + attribute); | 61 }, "Enumerate " + interface + "." + attribute); |
| 91 } | 62 } |
| OLD | NEW |