OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 |
| 3 <title>Element upgrade watchers</title> |
| 4 <meta charset="UTF-8"> |
| 5 |
| 6 <script src='../lib/element_created.js'></script> |
| 7 <script src='unittest.js'></script> |
| 8 |
| 9 <body> |
| 10 |
| 11 <script> |
| 12 |
| 13 var currentTagIndex = 0; |
| 14 function nextTagName() { |
| 15 return 'x-custom-' + (currentTagIndex++); |
| 16 } |
| 17 |
| 18 test('registerElement still works', function () { |
| 19 var Foo = Object.create(HTMLElement.prototype); |
| 20 Foo.created = false; |
| 21 Foo.createdCallback = function() { |
| 22 this.created = true; |
| 23 }; |
| 24 |
| 25 var tagName = nextTagName(); |
| 26 |
| 27 Foo = document.registerElement(tagName, {prototype: Foo}); |
| 28 |
| 29 var foo = document.createElement(tagName); |
| 30 expect(foo instanceof Foo, true); |
| 31 expect(foo.created, true); |
| 32 |
| 33 foo = new Foo(); |
| 34 expect(foo instanceof Foo, true); |
| 35 expect(foo.created, true); |
| 36 }); |
| 37 |
| 38 test('registerElement with prototype syntax still works', function () { |
| 39 var tagName = nextTagName(); |
| 40 |
| 41 var Foo = function() {}; |
| 42 Foo.prototype = Object.create(HTMLElement.prototype, { |
| 43 createdCallback: { |
| 44 value: function() { |
| 45 this.created = true; |
| 46 } |
| 47 } |
| 48 }); |
| 49 |
| 50 var Foo = document.registerElement(tagName, Foo); |
| 51 |
| 52 var foo = document.createElement(tagName); |
| 53 expect(foo instanceof Foo, true); |
| 54 expect(foo.created, true); |
| 55 |
| 56 foo = new Foo(); |
| 57 expect(foo instanceof Foo, true); |
| 58 expect(foo.created, true); |
| 59 |
| 60 var Bar = function() {}; |
| 61 Bar.prototype = Object.create(Foo.prototype, { |
| 62 attachedCallback: { |
| 63 value: function() { |
| 64 this.attached = true; |
| 65 } |
| 66 } |
| 67 }); |
| 68 |
| 69 var barTagName = nextTagName(); |
| 70 Bar = document.registerElement(barTagName, Bar); |
| 71 |
| 72 var bar = document.createElement(barTagName); |
| 73 expect(bar instanceof Bar, true); |
| 74 expect(bar instanceof Foo, true); |
| 75 expect(bar.created, true); |
| 76 |
| 77 expect(bar.attached, undefined); |
| 78 document.body.appendChild(bar); |
| 79 expect(bar.attached, true); |
| 80 }); |
| 81 |
| 82 test('callback works', function () { |
| 83 var Foo = Object.create(HTMLElement.prototype); |
| 84 Foo.created = false; |
| 85 Foo.createdCallback = function() { |
| 86 this.created = true; |
| 87 }; |
| 88 |
| 89 var tagName = nextTagName(); |
| 90 |
| 91 Foo = document.registerElement(tagName, {prototype: Foo}); |
| 92 |
| 93 var original; |
| 94 document.registerElementCreatedWatcher(tagName, { |
| 95 createdCallback: function() { |
| 96 original = this; |
| 97 } |
| 98 }); |
| 99 |
| 100 expect(document.createElement(tagName) instanceof Foo, true); |
| 101 expect(original instanceof Foo, true); |
| 102 |
| 103 original = null; |
| 104 expect(new Foo() instanceof Foo, true); |
| 105 expect(original instanceof Foo, true); |
| 106 }); |
| 107 </script> |
| 108 |
| 109 </body> |
OLD | NEW |