Comment-Text-constructor.js (2638B)
1 function test_constructor(ctor) { 2 test(function() { 3 var object = new window[ctor](); 4 assert_equals(Object.getPrototypeOf(object), 5 window[ctor].prototype, "Prototype chain: " + ctor); 6 assert_equals(Object.getPrototypeOf(Object.getPrototypeOf(object)), 7 CharacterData.prototype, "Prototype chain: CharacterData"); 8 assert_equals(Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf(object))), 9 Node.prototype, "Prototype chain: Node"); 10 }, "new " + ctor + "(): prototype chain"); 11 12 test(function() { 13 var object = new window[ctor](); 14 assert_true(object instanceof Node, "Should be a Node"); 15 assert_true(object instanceof CharacterData, "Should be a CharacterData"); 16 assert_true(object instanceof window[ctor], "Should be a " + ctor); 17 }, "new " + ctor + "(): instanceof"); 18 19 test(function() { 20 var object = new window[ctor](); 21 assert_equals(object.data, ""); 22 assert_equals(object.nodeValue, ""); 23 assert_equals(object.ownerDocument, document); 24 }, "new " + ctor + "(): no arguments"); 25 26 var testArgs = [ 27 [undefined, ""], 28 [null, "null"], 29 [42, "42"], 30 ["", ""], 31 ["-", "-"], 32 ["--", "--"], 33 ["-->", "-->"], 34 ["<!--", "<!--"], 35 ["\u0000", "\u0000"], 36 ["\u0000test", "\u0000test"], 37 ["&", "&"], 38 ]; 39 40 testArgs.forEach(function(a) { 41 var argument = a[0], expected = a[1]; 42 test(function() { 43 var object = new window[ctor](argument); 44 assert_equals(object.data, expected); 45 assert_equals(object.nodeValue, expected); 46 assert_equals(object.ownerDocument, document); 47 }, "new " + ctor + "(): " + format_value(argument)); 48 }); 49 50 test(function() { 51 var called = []; 52 var object = new window[ctor]({ 53 toString: function() { 54 called.push("first"); 55 return "text"; 56 } 57 }, { 58 toString: function() { 59 called.push("second"); 60 assert_unreached("Should not look at the second argument."); 61 } 62 }); 63 assert_equals(object.data, "text"); 64 assert_equals(object.nodeValue, "text"); 65 assert_equals(object.ownerDocument, document); 66 assert_array_equals(called, ["first"]); 67 }, "new " + ctor + "(): two arguments") 68 69 async_test("new " + ctor + "() should get the correct ownerDocument across globals").step(function() { 70 var iframe = document.createElement("iframe"); 71 iframe.onload = this.step_func_done(function() { 72 var object = new iframe.contentWindow[ctor](); 73 assert_equals(object.ownerDocument, iframe.contentDocument); 74 }); 75 document.body.appendChild(iframe); 76 }); 77 }