| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../../../resources/testharness.js"></script> | 2 <script src="../../../resources/testharness.js"></script> |
| 3 <script src="../../../resources/testharnessreport.js"></script> | 3 <script src="../../../resources/testharnessreport.js"></script> |
| 4 <script src="test-harness-utils.js"></script> | 4 <script src="test-harness-utils.js"></script> |
| 5 <body> | 5 <body> |
| 6 <script> | 6 <script> |
| 7 test(function() { | 7 test(function() { |
| 8 var createdInvocations = 0; | 8 var createdInvocations = 0; |
| 9 function created() { | 9 function created() { |
| 10 createdInvocations++; | 10 createdInvocations++; |
| 11 } | 11 } |
| 12 | 12 |
| 13 var getterInvocations = 0; | 13 var getterInvocations = 0; |
| 14 function getter() { | 14 function getter() { |
| 15 getterInvocations++; | 15 getterInvocations++; |
| 16 return created; | 16 return created; |
| 17 } | 17 } |
| 18 | 18 |
| 19 function failer() { | 19 function failer() { |
| 20 assert_unreached('the created callback must not be retrieved after regis
tration'); | 20 assert_unreached('the created callback must not be retrieved after regis
tration'); |
| 21 } | 21 } |
| 22 | 22 |
| 23 var proto = Object.create(HTMLElement.prototype, { | 23 var proto = Object.create(HTMLElement.prototype, { |
| 24 createdCallback: { | 24 createdCallback: { |
| 25 get: getter | 25 get: getter |
| 26 } | 26 } |
| 27 }); | 27 }); |
| 28 var ctor = document.register('x-a', {prototype: proto}); | 28 var ctor = document.registerElement('x-a', {prototype: proto}); |
| 29 assert_equals(getterInvocations, 1, 'the created callback must have been ret
rieved'); | 29 assert_equals(getterInvocations, 1, 'the created callback must have been ret
rieved'); |
| 30 | 30 |
| 31 proto.createdCallback = failer; | 31 proto.createdCallback = failer; |
| 32 var element = new ctor(); | 32 var element = new ctor(); |
| 33 assert_equals(createdInvocations, 1, 'the created callback retrieved at regi
stration must be invoked'); | 33 assert_equals(createdInvocations, 1, 'the created callback retrieved at regi
stration must be invoked'); |
| 34 }, 'transfer created callback'); | 34 }, 'transfer created callback'); |
| 35 | 35 |
| 36 (function() { | 36 (function() { |
| 37 | 37 |
| 38 t = async_test('__proto__, :unresolved and created callback timing'); | 38 t = async_test('__proto__, :unresolved and created callback timing'); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 51 | 51 |
| 52 assert_equals(div.querySelector('x-b:not(:unresolved)'), this, 'the
:unresolved pseudoclass should cease to apply when the created callback is invok
ed'); | 52 assert_equals(div.querySelector('x-b:not(:unresolved)'), this, 'the
:unresolved pseudoclass should cease to apply when the created callback is invok
ed'); |
| 53 assert_array_equals(div.querySelectorAll(':unresolved'), [v, w], 'th
e :unresolved pseudoclass should be processed in order'); | 53 assert_array_equals(div.querySelectorAll(':unresolved'), [v, w], 'th
e :unresolved pseudoclass should be processed in order'); |
| 54 | 54 |
| 55 assert_true(t instanceof C, 'prototype upgrade should happen in orde
r (#t)'); | 55 assert_true(t instanceof C, 'prototype upgrade should happen in orde
r (#t)'); |
| 56 assert_false(v instanceof C, 'prototype upgrade should happen in ord
er (#v)'); | 56 assert_false(v instanceof C, 'prototype upgrade should happen in ord
er (#v)'); |
| 57 }, this); | 57 }, this); |
| 58 } | 58 } |
| 59 | 59 |
| 60 var protoB = Object.create(HTMLElement.prototype); | 60 var protoB = Object.create(HTMLElement.prototype); |
| 61 var B = document.register('x-b', {prototype: protoB}); | 61 var B = document.registerElement('x-b', {prototype: protoB}); |
| 62 | 62 |
| 63 var protoC = Object.create(HTMLElement.prototype); | 63 var protoC = Object.create(HTMLElement.prototype); |
| 64 protoC.createdCallback = created; | 64 protoC.createdCallback = created; |
| 65 var C = document.register('x-c', {prototype: protoC}); | 65 var C = document.registerElement('x-c', {prototype: protoC}); |
| 66 | 66 |
| 67 var div = document.createElement('div'); | 67 var div = document.createElement('div'); |
| 68 div.innerHTML = '<x-c id="t"></x-c>' + | 68 div.innerHTML = '<x-c id="t"></x-c>' + |
| 69 '<x-b id="u"></x-b>' + | 69 '<x-b id="u"></x-b>' + |
| 70 '<x-c id="v"></x-c>' + | 70 '<x-c id="v"></x-c>' + |
| 71 '<x-b id="w"></x-b>'; | 71 '<x-b id="w"></x-b>'; |
| 72 assert_equals(createdInvocations, 2, 'the created callback should have been
invoked once for each x-c element'); | 72 assert_equals(createdInvocations, 2, 'the created callback should have been
invoked once for each x-c element'); |
| 73 assert_true(div.querySelector('#w') instanceof B, '#w\'s prototype should ha
ve ultimately been upgraded'); | 73 assert_true(div.querySelector('#w') instanceof B, '#w\'s prototype should ha
ve ultimately been upgraded'); |
| 74 t.done(); | 74 t.done(); |
| 75 }); | 75 }); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 87 messages.push(msg); | 87 messages.push(msg); |
| 88 } | 88 } |
| 89 | 89 |
| 90 var proto = Object.create(frame.contentWindow.HTMLElement.prototype); | 90 var proto = Object.create(frame.contentWindow.HTMLElement.prototype); |
| 91 proto.createdCallback = function() { | 91 proto.createdCallback = function() { |
| 92 log('created started'); | 92 log('created started'); |
| 93 this.remove(); | 93 this.remove(); |
| 94 this.setAttribute('prey', 'gargoyles'); | 94 this.setAttribute('prey', 'gargoyles'); |
| 95 log('created finished'); | 95 log('created finished'); |
| 96 }; | 96 }; |
| 97 proto.enteredViewCallback = function() { log('entered'); }; | 97 proto.attachedCallback = function() { log('entered'); }; |
| 98 proto.leftViewCallback = function() { log('left'); }; | 98 proto.detachedCallback = function() { log('left'); }; |
| 99 proto.attributeChangedCallback = function() { log('attribute changed'); }; | 99 proto.attributeChangedCallback = function() { log('attribute changed'); }; |
| 100 var D = frame.contentDocument.register('x-d', {prototype: proto}); | 100 var D = frame.contentDocument.registerElement('x-d', {prototype: proto}); |
| 101 | 101 |
| 102 frame.contentDocument.body.innerHTML = '<x-d></x-d>'; | 102 frame.contentDocument.body.innerHTML = '<x-d></x-d>'; |
| 103 log('done'); | 103 log('done'); |
| 104 | 104 |
| 105 assert_array_equals( | 105 assert_array_equals( |
| 106 messages, | 106 messages, |
| 107 ['created started', 'created finished', 'entered', 'left', | 107 ['created started', 'created finished', 'entered', 'left', |
| 108 'attribute changed', 'done'], | 108 'attribute changed', 'done'], |
| 109 'callbacks should not be dispatched until the created callback has ' + | 109 'callbacks should not be dispatched until the created callback has ' + |
| 110 'finished'); | 110 'finished'); |
| 111 t.done(); | 111 t.done(); |
| 112 })); | 112 })); |
| 113 | 113 |
| 114 })(); | 114 })(); |
| 115 </script> | 115 </script> |
| OLD | NEW |