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

Unified Diff: pkg/web_components/test/interop_test.dart

Issue 333073002: Support upgrading existing elements already on the page. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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/web_components/pubspec.yaml ('k') | pkg/web_components/test/interop_test.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/web_components/test/interop_test.dart
diff --git a/pkg/web_components/test/interop_test.dart b/pkg/web_components/test/interop_test.dart
index 64dfb6426f7bc673fb130653e803f77640f12390..cbad6e192e91d8830eb843ce0acdfc12aaabd722 100644
--- a/pkg/web_components/test/interop_test.dart
+++ b/pkg/web_components/test/interop_test.dart
@@ -12,15 +12,9 @@ import 'package:unittest/unittest.dart';
import 'package:web_components/interop.dart';
import 'package:web_components/polyfill.dart';
-final globalSetup = customElementsReady.then((_) {
- registerDartType('x-a', XAWrapper);
- registerDartType('x-b', XBWrapper, extendsTag: 'div');
- registerDartType('x-c', XCWrapper);
- });
-
main() {
useHtmlConfiguration();
- setUp(() => globalSetup);
+ setUp(() => customElementsReady);
test('interop is supported', () {
expect(isSupported, isTrue);
@@ -37,21 +31,53 @@ main() {
expect(b is XBWrapper, isFalse, reason: 'x-b should not be upgraded yet');
expect(_readX(b), 1);
+ var d = document.querySelector('x-d');
+ expect(d is HtmlElement, isTrue, reason: 'x-d is HtmlElement');
+ expect(d is XDWrapper, isFalse, reason: 'x-d should not be upgraded yet');
+ expect(_readX(d), 2);
+
+ /// Note: this registration has a global side-effect and is assumed in the
+ /// following tests.
+ registerDartType('x-a', XAWrapper);
+ registerDartType('x-b', XBWrapper, extendsTag: 'div');
+ registerDartType('x-c', XCWrapper);
+ onlyUpgradeNewElements();
+ registerDartType('x-d', XDWrapper); // late on purpose.
+
+ a = document.querySelector('x-a');
+ expect(a is HtmlElement, isTrue, reason: 'x-a is HtmlElement');
+ expect(a is XAWrapper, isTrue, reason: 'x-a is upgraded to XAWrapper');
+ expect(a.x, 0);
+ expect(a.wrapperCount, 0);
+
+ b = document.querySelector('[is=x-b]');
+ expect(b is DivElement, isTrue, reason: 'x-b is DivElement');
+ expect(b is XBWrapper, isTrue, reason: 'x-b is upgraded to XBWrapper');
+ expect(b.x, 1);
+ expect(b.wrapperCount, 1);
+
+ // x-d was not upgraded because its registration came after we stopped
+ // upgrading old elements:
+ d = document.querySelector('x-d');
+ expect(d is HtmlElement, isTrue, reason: 'x-d is HtmlElement');
+ expect(d is XDWrapper, isFalse, reason: 'x-d should not be upgraded yet');
+ expect(_readX(d), 2);
+
var c = document.querySelector('x-c');
expect(c is HtmlElement, isTrue, reason: 'x-c is HtmlElement');
expect(c is XCWrapper, isFalse, reason: 'x-c should not be upgraded yet');
expect(_readX(c), null, reason: 'x-c has not been registered in JS yet');
});
- test('events seen for anything created after registering Dart type', () {
+ test('anything created after registering Dart type is upgraded', () {
context.callMethod('addA');
var list = document.querySelectorAll('x-a');
expect(list.length, 2);
var a = list[1];
expect(a is HtmlElement, isTrue, reason: 'x-a is HtmlElement');
expect(a is XAWrapper, isTrue, reason: 'x-a is upgraded to XAWrapper');
- expect(a.x, 2);
- expect(a.wrapperCount, 0);
+ expect(a.x, 3);
+ expect(a.wrapperCount, 2);
context.callMethod('addB');
list = document.querySelectorAll('[is=x-b]');
@@ -59,8 +85,18 @@ main() {
var b = list[1];
expect(b is DivElement, isTrue, reason: 'x-b is DivElement');
expect(b is XBWrapper, isTrue, reason: 'x-b is upgraded to XBWrapper');
- expect(b.x, 3);
- expect(b.wrapperCount, 1);
+ expect(b.x, 4);
+ expect(b.wrapperCount, 3);
+
+ // New instances of x-d should be upgraded regardless.
+ context.callMethod('addD');
+ list = document.querySelectorAll('x-d');
+ expect(list.length, 2);
+ var d = list[1];
+ expect(d is HtmlElement, isTrue, reason: 'x-d is HtmlElement');
+ expect(d is XDWrapper, isTrue, reason: 'x-d is upgraded to XDWrapper');
+ expect(d.x, 5);
+ expect(d.wrapperCount, 4);
});
test('events seen if Dart type is registered before registerElement', () {
@@ -71,8 +107,8 @@ main() {
context.callMethod('registerC');
c = document.querySelector('x-c');
expect(c is XCWrapper, isTrue);
- expect(c.x, 4);
- expect(c.wrapperCount, 2);
+ expect(c.x, 6);
+ expect(c.wrapperCount, 5);
context.callMethod('addC');
var list = document.querySelectorAll('x-c');
@@ -81,8 +117,8 @@ main() {
c = list[1];
expect(c is HtmlElement, isTrue, reason: 'x-c is HtmlElement');
expect(c is XCWrapper, isTrue, reason: 'x-c is upgraded to XCWrapper');
- expect(c.x, 5);
- expect(c.wrapperCount, 3);
+ expect(c.x, 7);
+ expect(c.wrapperCount, 6);
});
}
int _count = 0;
@@ -105,3 +141,7 @@ class XBWrapper extends DivElement with Wrapper {
class XCWrapper extends HtmlElement with Wrapper {
XCWrapper.created() : super.created();
}
+
+class XDWrapper extends HtmlElement with Wrapper {
+ XDWrapper.created() : super.created();
+}
« no previous file with comments | « pkg/web_components/pubspec.yaml ('k') | pkg/web_components/test/interop_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698