Index: pkg/element_created/test/index.html |
diff --git a/pkg/element_created/test/index.html b/pkg/element_created/test/index.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c8bc2e204c5d4ac800dac1bfe80c42c37318f0b1 |
--- /dev/null |
+++ b/pkg/element_created/test/index.html |
@@ -0,0 +1,109 @@ |
+<!doctype html> |
+ |
+<title>Element upgrade watchers</title> |
+<meta charset="UTF-8"> |
+ |
+<script src='../lib/element_created.js'></script> |
+<script src='unittest.js'></script> |
+ |
+<body> |
+ |
+<script> |
+ |
+var currentTagIndex = 0; |
+function nextTagName() { |
+ return 'x-custom-' + (currentTagIndex++); |
+} |
+ |
+test('registerElement still works', function () { |
+ var Foo = Object.create(HTMLElement.prototype); |
+ Foo.created = false; |
+ Foo.createdCallback = function() { |
+ this.created = true; |
+ }; |
+ |
+ var tagName = nextTagName(); |
+ |
+ Foo = document.registerElement(tagName, {prototype: Foo}); |
+ |
+ var foo = document.createElement(tagName); |
+ expect(foo instanceof Foo, true); |
+ expect(foo.created, true); |
+ |
+ foo = new Foo(); |
+ expect(foo instanceof Foo, true); |
+ expect(foo.created, true); |
+}); |
+ |
+test('registerElement with prototype syntax still works', function () { |
+ var tagName = nextTagName(); |
+ |
+ var Foo = function() {}; |
+ Foo.prototype = Object.create(HTMLElement.prototype, { |
+ createdCallback: { |
+ value: function() { |
+ this.created = true; |
+ } |
+ } |
+ }); |
+ |
+ var Foo = document.registerElement(tagName, Foo); |
+ |
+ var foo = document.createElement(tagName); |
+ expect(foo instanceof Foo, true); |
+ expect(foo.created, true); |
+ |
+ foo = new Foo(); |
+ expect(foo instanceof Foo, true); |
+ expect(foo.created, true); |
+ |
+ var Bar = function() {}; |
+ Bar.prototype = Object.create(Foo.prototype, { |
+ attachedCallback: { |
+ value: function() { |
+ this.attached = true; |
+ } |
+ } |
+ }); |
+ |
+ var barTagName = nextTagName(); |
+ Bar = document.registerElement(barTagName, Bar); |
+ |
+ var bar = document.createElement(barTagName); |
+ expect(bar instanceof Bar, true); |
+ expect(bar instanceof Foo, true); |
+ expect(bar.created, true); |
+ |
+ expect(bar.attached, undefined); |
+ document.body.appendChild(bar); |
+ expect(bar.attached, true); |
+}); |
+ |
+test('callback works', function () { |
+ var Foo = Object.create(HTMLElement.prototype); |
+ Foo.created = false; |
+ Foo.createdCallback = function() { |
+ this.created = true; |
+ }; |
+ |
+ var tagName = nextTagName(); |
+ |
+ Foo = document.registerElement(tagName, {prototype: Foo}); |
+ |
+ var original; |
+ document.registerElementCreatedWatcher(tagName, { |
+ createdCallback: function() { |
+ original = this; |
+ } |
+ }); |
+ |
+ expect(document.createElement(tagName) instanceof Foo, true); |
+ expect(original instanceof Foo, true); |
+ |
+ original = null; |
+ expect(new Foo() instanceof Foo, true); |
+ expect(original instanceof Foo, true); |
+}); |
+</script> |
+ |
+</body> |