Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Unified Diff: pkg/element_created/test/index.html

Issue 184033007: Prototype of Dart proxies for JS objects. Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More tests. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/element_created/pubspec.yaml ('k') | pkg/element_created/test/unittest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
« no previous file with comments | « pkg/element_created/pubspec.yaml ('k') | pkg/element_created/test/unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698