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

Side by Side Diff: pkg/web_components/test/interop_test.dart

Issue 319263002: Add "created-watcher" to the web_components package. This was adapted from (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/web_components/test/interop2_test.html ('k') | pkg/web_components/test/interop_test.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library template_wrappers_test;
6
7 import 'dart:html';
8 import 'dart:async';
9 import 'dart:js' show context, JsObject;
10 import 'package:unittest/html_config.dart';
11 import 'package:unittest/unittest.dart';
12 import 'package:web_components/interop.dart';
13
14 main() {
15 useHtmlConfiguration();
16 registerDartType('x-a', XAWrapper);
17 registerDartType('x-b', XBWrapper, extendsTag: 'div');
18 registerDartType('x-c', XCWrapper);
19
20 test('interop is supported', () {
21 expect(isSupported, isTrue);
22 });
23
24 test('previously created elements are not upgraded', () {
25 var a = document.querySelector('x-a');
26 expect(a is HtmlElement, isTrue, reason: 'x-a is HtmlElement');
27 expect(a is XAWrapper, isFalse, reason: 'x-a should not be upgraded yet');
28 expect(_readX(a), 0);
29
30 var b = document.querySelector('[is=x-b]');
31 expect(b is DivElement, isTrue, reason: 'x-b is DivElement');
32 expect(b is XBWrapper, isFalse, reason: 'x-b should not be upgraded yet');
33 expect(_readX(b), 1);
34
35 var c = document.querySelector('x-c');
36 expect(c is HtmlElement, isTrue, reason: 'x-c is HtmlElement');
37 expect(c is XCWrapper, isFalse, reason: 'x-c should not be upgraded yet');
38 expect(_readX(c), null, reason: 'x-c has not been registered in JS yet');
39 });
40
41 test('events seen for anything created after registering Dart type', () {
42 context.callMethod('addA');
43 var list = document.querySelectorAll('x-a');
44 expect(list.length, 2);
45 var a = list[1];
46 expect(a is HtmlElement, isTrue, reason: 'x-a is HtmlElement');
47 expect(a is XAWrapper, isTrue, reason: 'x-a is upgraded to XAWrapper');
48 expect(a.x, 2);
49 expect(a.wrapperCount, 0);
50
51 context.callMethod('addB');
52 list = document.querySelectorAll('[is=x-b]');
53 expect(list.length, 2);
54 var b = list[1];
55 expect(b is DivElement, isTrue, reason: 'x-b is DivElement');
56 expect(b is XBWrapper, isTrue, reason: 'x-b is upgraded to XBWrapper');
57 expect(b.x, 3);
58 expect(b.wrapperCount, 1);
59 });
60
61 test('events seen if Dart type is registered before registerElement', () {
62 var c = document.querySelector('x-c');
63 expect(c is XCWrapper, isFalse);
64 expect(_readX(c), null, reason: 'x-c has not been registered in JS yet');
65
66 context.callMethod('registerC');
67 c = document.querySelector('x-c');
68 expect(c is XCWrapper, isTrue);
69 expect(c.x, 4);
70 expect(c.wrapperCount, 2);
71
72 context.callMethod('addC');
73 var list = document.querySelectorAll('x-c');
74 expect(list.length, 2);
75 expect(list[0], c);
76 c = list[1];
77 expect(c is HtmlElement, isTrue, reason: 'x-c is HtmlElement');
78 expect(c is XCWrapper, isTrue, reason: 'x-c is upgraded to XCWrapper');
79 expect(c.x, 5);
80 expect(c.wrapperCount, 3);
81 });
82 }
83 int _count = 0;
84
85 abstract class Wrapper {
86 int wrapperCount = _count++;
87 int get x => _readX(this);
88 }
89
90 _readX(e) => new JsObject.fromBrowserObject(e)['x'];
91
92 class XAWrapper extends HtmlElement with Wrapper {
93 XAWrapper.created() : super.created();
94 }
95
96 class XBWrapper extends DivElement with Wrapper {
97 XBWrapper.created() : super.created();
98 }
99
100 class XCWrapper extends HtmlElement with Wrapper {
101 XCWrapper.created() : super.created();
102 }
OLDNEW
« no previous file with comments | « pkg/web_components/test/interop2_test.html ('k') | pkg/web_components/test/interop_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698