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

Side by Side Diff: test/src/common/behavior_test.dart

Issue 1290643006: First cut at behaviors. This just implements the lifecycle methodsportion. We may get the rest for … (Closed) Base URL: git@github.com:dart-lang/polymer-dart.git@master
Patch Set: Created 5 years, 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2014, 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 @TestOn('browser')
5 library polymer.test.src.common.js_proxy_test;
6
7 import 'dart:html';
8 import 'dart:js';
9 import 'package:polymer/polymer.dart';
10 import 'package:test/test.dart';
11 import 'package:web_components/web_components.dart';
12
13 main() async {
14 await initPolymer();
15 MyElement el;
16
17 group('lifecycle methods', () {
18 setUp(() {
19 el = new MyElement();
20 });
21
22 test('created', () {
23 expect(el.dartInvocations['created'], [
24 [el]
25 ]);
26 expect(el.jsElement['jsInvocations']['created'], [
27 [el]
28 ]);
29 expect(el.dartInvocations['attached'], isEmpty);
30 expect(el.dartInvocations['detached'], isEmpty);
31 expect(el.dartInvocations['attributeChanged'], isEmpty);
32 });
33
34 test('attached', () {
35 document.body.append(el);
36 expect(el.dartInvocations['attached'], [
37 [el]
38 ]);
39 expect(el.jsElement['jsInvocations']['attached'], [
40 [el]
41 ]);
42 expect(el.dartInvocations['detached'], isEmpty);
43 expect(el.dartInvocations['attributeChanged'], isEmpty);
44 });
45
46 test('detached', () {
47 document.body.append(el);
48 el.remove();
49 expect(el.dartInvocations['detached'], [
50 [el]
51 ]);
52 expect(el.jsElement['jsInvocations']['detached'], [
53 [el]
54 ]);
55 expect(el.dartInvocations['attributeChanged'], isEmpty);
56 });
57
58 test('attributeChanged', () {
59 el.attributes['foo'] = 'bar';
60 expect(el.dartInvocations['attributeChanged'], [
61 [el, 'foo', null, 'bar']
62 ]);
63 expect(el.jsElement['jsInvocations']['attributeChanged'], [
64 [el, 'foo', null, 'bar']
65 ]);
66 });
67 });
68 }
69
70 @BehaviorProxy(const ['JsBehavior'])
71 abstract class JsBehavior implements CustomElementProxyMixin {
72 JsArray get jsInvocations => jsElement['jsInvocations'];
73 }
74
75 @Behavior()
76 class DartBehavior {
77 Map<String, List<List>> dartInvocations = {
78 'created': [],
79 'attached': [],
80 'detached': [],
81 'attributeChanged': []
82 };
83
84 static created(DartBehavior thisArg) {
85 thisArg.dartInvocations['created'].add([thisArg]);
86 }
87
88 static attached(DartBehavior thisArg) {
89 thisArg.dartInvocations['attached'].add([thisArg]);
90 }
91
92 static detached(DartBehavior thisArg) {
93 thisArg.dartInvocations['detached'].add([thisArg]);
94 }
95
96 static attributeChanged(DartBehavior thisArg, String name, type, value) {
97 thisArg.dartInvocations['attributeChanged']
98 .add([thisArg, name, type, value]);
99 }
100 }
101
102 @jsProxyReflectable
103 @PolymerRegister('my-element')
104 class MyElement extends PolymerElement with JsBehavior, DartBehavior {
105 MyElement.created() : super.created();
106
107 factory MyElement() => document.createElement('my-element');
108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698