OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../../../resources/js-test.js"></script> | 4 <script src="../../../resources/js-test.js"></script> |
5 </head> | 5 </head> |
6 <body> | 6 <body> |
7 <div id="container"></div> | 7 <div id="container"></div> |
8 <script> | 8 <script> |
9 description('Testing document.register() basic behaviors.'); | 9 description('Testing document.registerElement() basic behaviors.'); |
10 | 10 |
11 if (window.testRunner) | 11 if (window.testRunner) |
12 testRunner.dumpAsText(); | 12 testRunner.dumpAsText(); |
13 | 13 |
14 function createRegisterParameters() | 14 function createRegisterParameters() |
15 { | 15 { |
16 return { | 16 return { |
17 prototype: Object.create(HTMLElement.prototype, { thisIsPrototype: { val
ue: true } }) | 17 prototype: Object.create(HTMLElement.prototype, { thisIsPrototype: { val
ue: true } }) |
18 }; | 18 }; |
19 } | 19 } |
20 | 20 |
21 var fooConstructor = document.register('x-foo', createRegisterParameters()); | 21 var fooConstructor = document.registerElement('x-foo', createRegisterParameters(
)); |
22 shouldBe('typeof fooConstructor', '"function"'); | 22 shouldBe('typeof fooConstructor', '"function"'); |
23 shouldBe('fooConstructor.prototype.__proto__', 'HTMLElement.prototype'); | 23 shouldBe('fooConstructor.prototype.__proto__', 'HTMLElement.prototype'); |
24 shouldBeTrue('fooConstructor.prototype.thisIsPrototype'); | 24 shouldBeTrue('fooConstructor.prototype.thisIsPrototype'); |
25 | 25 |
26 // Bad prototype: prototype is already a built-in interface prototype object | 26 // Bad prototype: prototype is already a built-in interface prototype object |
27 shouldThrow('document.register("x-bad-a", HTMLElement)', '"NotSupportedError: Fa
iled to execute \'register\' on \'Document\': Registration failed for type \'x-b
ad-a\'. The prototype is already in-use as an interface prototype object."'); | 27 shouldThrow('document.registerElement("x-bad-a", HTMLElement)', '"NotSupportedEr
ror: Failed to execute \'registerElement\' on \'Document\': Registration failed
for type \'x-bad-a\'. The prototype is already in-use as an interface prototype
object."'); |
28 // Bad prototype: prototype is already a Custom Element interface prototype obje
ct | 28 // Bad prototype: prototype is already a Custom Element interface prototype obje
ct |
29 shouldThrow('document.register("x-bad-b", fooConstructor)', '"NotSupportedError:
Failed to execute \'register\' on \'Document\': Registration failed for type \'
x-bad-b\'. The prototype is already in-use as an interface prototype object."'); | 29 shouldThrow('document.registerElement("x-bad-b", fooConstructor)', '"NotSupporte
dError: Failed to execute \'registerElement\' on \'Document\': Registration fail
ed for type \'x-bad-b\'. The prototype is already in-use as an interface prototy
pe object."'); |
30 // Bad prototype: 'constructor' is not configurable | 30 // Bad prototype: 'constructor' is not configurable |
31 var proto = Object.create(HTMLElement.prototype, { | 31 var proto = Object.create(HTMLElement.prototype, { |
32 constructor: {configurable: false, writable: true} | 32 constructor: {configurable: false, writable: true} |
33 }); | 33 }); |
34 shouldThrow('document.register("x-bad-c", { prototype: proto })', '"NotSupported
Error: Failed to execute \'register\' on \'Document\': Registration failed for t
ype \'x-bad-c\'. Prototype constructor property is not configurable."'); | 34 shouldThrow('document.registerElement("x-bad-c", { prototype: proto })', '"NotSu
pportedError: Failed to execute \'registerElement\' on \'Document\': Registratio
n failed for type \'x-bad-c\'. Prototype constructor property is not configurabl
e."'); |
35 // Call as function | 35 // Call as function |
36 shouldThrow('fooConstructor()', '"TypeError: DOM object constructor cannot be ca
lled as a function."') | 36 shouldThrow('fooConstructor()', '"TypeError: DOM object constructor cannot be ca
lled as a function."') |
37 | 37 |
38 // Constructor initiated instantiation | 38 // Constructor initiated instantiation |
39 var createdFoo = new fooConstructor(); | 39 var createdFoo = new fooConstructor(); |
40 | 40 |
41 // JS built-in properties | 41 // JS built-in properties |
42 shouldBe('createdFoo.__proto__', 'fooConstructor.prototype'); | 42 shouldBe('createdFoo.__proto__', 'fooConstructor.prototype'); |
43 shouldBe('createdFoo.constructor', 'fooConstructor'); | 43 shouldBe('createdFoo.constructor', 'fooConstructor'); |
44 | 44 |
(...skipping 15 matching lines...) Expand all Loading... |
60 parsedFoo = container.firstChild; | 60 parsedFoo = container.firstChild; |
61 | 61 |
62 shouldBe('parsedFoo.__proto__', 'fooConstructor.prototype'); | 62 shouldBe('parsedFoo.__proto__', 'fooConstructor.prototype'); |
63 shouldBe('parsedFoo.tagName', '"X-FOO"'); | 63 shouldBe('parsedFoo.tagName', '"X-FOO"'); |
64 | 64 |
65 // Ensuring the wrapper is retained | 65 // Ensuring the wrapper is retained |
66 parsedFoo.someProperty = 'hello'; | 66 parsedFoo.someProperty = 'hello'; |
67 shouldBe('parsedFoo.someProperty', 'container.firstChild.someProperty'); | 67 shouldBe('parsedFoo.someProperty', 'container.firstChild.someProperty'); |
68 | 68 |
69 // Having another constructor | 69 // Having another constructor |
70 var barConstructor = document.register('x-bar', createRegisterParameters()); | 70 var barConstructor = document.registerElement('x-bar', createRegisterParameters(
)); |
71 shouldBeTrue('barConstructor !== fooConstructor'); | 71 shouldBeTrue('barConstructor !== fooConstructor'); |
72 var createdBar = new barConstructor(); | 72 var createdBar = new barConstructor(); |
73 shouldBe('createdBar.tagName', '"X-BAR"'); | 73 shouldBe('createdBar.tagName', '"X-BAR"'); |
74 | 74 |
75 // Having a subclass | 75 // Having a subclass |
76 var bazConstructor = document.register('x-baz', { prototype: Object.create(fooCo
nstructor.prototype, { thisIsAlsoPrototype: { value: true } }) }); | 76 var bazConstructor = document.registerElement('x-baz', { prototype: Object.creat
e(fooConstructor.prototype, { thisIsAlsoPrototype: { value: true } }) }); |
77 var createdBaz = new bazConstructor(); | 77 var createdBaz = new bazConstructor(); |
78 shouldBe('createdBaz.tagName', '"X-BAZ"'); | 78 shouldBe('createdBaz.tagName', '"X-BAZ"'); |
79 shouldBeTrue('createdBaz.thisIsPrototype'); | 79 shouldBeTrue('createdBaz.thisIsPrototype'); |
80 shouldBeTrue('createdBaz.thisIsAlsoPrototype'); | 80 shouldBeTrue('createdBaz.thisIsAlsoPrototype'); |
81 | 81 |
82 // With irregular cases | 82 // With irregular cases |
83 var createdUpperBar = document.createElement('X-BAR'); | 83 var createdUpperBar = document.createElement('X-BAR'); |
84 var createdMixedBar = document.createElement('X-Bar'); | 84 var createdMixedBar = document.createElement('X-Bar'); |
85 shouldBe('createdUpperBar.constructor', 'barConstructor'); | 85 shouldBe('createdUpperBar.constructor', 'barConstructor'); |
86 shouldBe('createdUpperBar.tagName', '"X-BAR"'); | 86 shouldBe('createdUpperBar.tagName', '"X-BAR"'); |
87 shouldBe('createdMixedBar.constructor', 'barConstructor'); | 87 shouldBe('createdMixedBar.constructor', 'barConstructor'); |
88 shouldBe('createdMixedBar.tagName', '"X-BAR"'); | 88 shouldBe('createdMixedBar.tagName', '"X-BAR"'); |
89 | 89 |
90 container.innerHTML = '<X-BAR></X-BAR><X-Bar></X-Bar>'; | 90 container.innerHTML = '<X-BAR></X-BAR><X-Bar></X-Bar>'; |
91 shouldBe('container.firstChild.constructor', 'barConstructor'); | 91 shouldBe('container.firstChild.constructor', 'barConstructor'); |
92 shouldBe('container.firstChild.tagName', '"X-BAR"'); | 92 shouldBe('container.firstChild.tagName', '"X-BAR"'); |
93 shouldBe('container.lastChild.constructor', 'barConstructor'); | 93 shouldBe('container.lastChild.constructor', 'barConstructor'); |
94 shouldBe('container.lastChild.tagName', '"X-BAR"'); | 94 shouldBe('container.lastChild.tagName', '"X-BAR"'); |
95 | 95 |
96 // Constructors shouldn't interfere with each other | 96 // Constructors shouldn't interfere with each other |
97 shouldBe('(new fooConstructor).tagName', '"X-FOO"'); | 97 shouldBe('(new fooConstructor).tagName', '"X-FOO"'); |
98 shouldBe('(new barConstructor).tagName', '"X-BAR"'); | 98 shouldBe('(new barConstructor).tagName', '"X-BAR"'); |
99 shouldBe('(new bazConstructor).tagName', '"X-BAZ"'); | 99 shouldBe('(new bazConstructor).tagName', '"X-BAZ"'); |
100 | 100 |
101 </script> | 101 </script> |
102 </body> | 102 </body> |
103 </html> | 103 </html> |
OLD | NEW |