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

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

Issue 1351693003: Update to use one less proxy per element (Closed) Base URL: git@github.com:dart-lang/polymer-dart.git@behaviors
Patch Set: redo! Created 5 years, 3 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
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 @TestOn('browser') 4 @TestOn('browser')
5 library polymer.test.src.common.polymer_mixin_test; 5 library polymer.test.src.common.polymer_mixin_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'package:polymer/polymer.dart'; 9 import 'package:polymer/polymer.dart';
10 import 'package:test/test.dart'; 10 import 'package:test/test.dart';
11 11
12 TestElement element; 12 TestElement element;
13 SubElement subElement;
13 14
14 main() async { 15 main() async {
15 await initPolymer(); 16 await initPolymer();
16 17
17 setUp(() { 18 setUp(() {
18 element = document.createElement('test-element'); 19 element = document.createElement('test-element');
20 subElement = element.$['sub'];
19 }); 21 });
20 22
21 test('default values', () { 23 test('default values', () {
22 expect(element.myInt, 1); 24 expect(element.myInt, 1);
23 expect(element.jsElement['myInt'], 1); 25 expect(element.jsElement['myInt'], 1);
24 }); 26 });
25 27
26 test('set', () { 28 group('set', () {
27 element.set('myInt', 2); 29 test('basic', () {
28 expect(element.myInt, 2); 30 element.set('myInt', 2);
29 expect(element.jsElement['myInt'], 2); 31 expect(element.myInt, 2);
32 expect(element.jsElement['myInt'], 2);
33 });
34
35 test('Map', () {
36 element.set('myMap.hello', 'world');
37 expect(element.myMap['hello'], 'world');
38 expect(element.jsElement['myMap']['hello'], 'world');
39 });
40
41 test('List', () {
42 element.set('myInts', [1, 2, 3]);
43 expect(element.myInts, [1, 2, 3]);
44 expect(element.jsElement['myInts'], [1, 2, 3]);
45
46 element.set('myInts.1', 4);
47 expect(element.myInts, [1, 4, 3]);
48 expect(element.jsElement['myInts'], [1, 4, 3]);
49 });
50
51 test('JsProxy', () {
52 var newModel = new Model('world');
53 element.set('myModel', newModel);
54 expect(element.myModel, newModel);
55 expect(element.jsElement['myModel'], newModel.jsProxy);
56
57 element.set('myModel.value', 'cool');
58 expect(element.myModel.value, 'cool');
59 expect(element.jsElement['myModel']['value'], 'cool');
60 });
30 }); 61 });
31 62
32 test('notifyPath', () { 63 group('notifyPath', () {
33 element.myInt = 2; 64 test('basic', () {
34 expect(element.jsElement['myInt'], 1); 65 element.myInt = 2;
35 element.notifyPath('myInt', 2); 66 expect(element.jsElement['myInt'], 1);
36 expect(element.jsElement['myInt'], 2); 67 element.notifyPath('myInt', 2);
68 expect(element.jsElement['myInt'], 2);
69 });
70
71 test('Map', () {
72 element.myMap['hello'] = 'world';
73 expect(element.get('myMap.hello'), null);
74 element.notifyPath('myMap.hello', element.myMap['hello']);
75 expect(element.jsElement['myMap']['hello'], 'world');
76 });
77
78 test('List', () {
79 element.myInts = [1, 2, 3];
80 expect(element.jsElement['myInts'], []);
81 element.notifyPath('myInts', element.myInts);
82 expect(element.jsElement['myInts'], [1, 2, 3]);
83
84 element.myInts[1] = 4;
85 expect(element.jsElement['myInts'], [1, 2, 3]);
86 element.notifyPath('myInts.1', element.myInts[1]);
87 expect(element.myInts, [1, 4, 3]);
88 expect(element.jsElement['myInts'], [1, 4, 3]);
89 });
90
91 test('JsProxy', () {
92 element.myModel = new Model('world');
93 expect(element.jsElement['myModel']['value'], 'hello');
94 element.notifyPath('myModel', element.myModel);
95 expect(element.jsElement['myModel']['value'], 'world');
96
97 element.myModel.value = 'cool';
98 expect(subElement.$['modelValue'].text, 'world');
99 element.notifyPath('myModel.value', element.myModel.value);
100 expect(subElement.$['modelValue'].text, 'cool');
101 });
37 }); 102 });
38 103
39 test('\$', () { 104 test('\$', () {
40 expect(element.$['parent'], isNotNull); 105 expect(element.$['parent'], isNotNull);
41 expect(element.$['parent'].id, 'parent'); 106 expect(element.$['parent'].id, 'parent');
42 expect(element.$['child'], isNotNull); 107 expect(element.$['child'], isNotNull);
43 expect(element.$['child'].id, 'child'); 108 expect(element.$['child'].id, 'child');
44 }); 109 });
45 110
46 test('root', () { 111 test('root', () {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 268 }
204 269
205 @PolymerRegister('test-element') 270 @PolymerRegister('test-element')
206 class TestElement extends HtmlElement with PolymerMixin, PolymerBase, JsProxy { 271 class TestElement extends HtmlElement with PolymerMixin, PolymerBase, JsProxy {
207 @property 272 @property
208 int myInt = 1; 273 int myInt = 1;
209 274
210 @property 275 @property
211 List<int> myInts = []; 276 List<int> myInts = [];
212 277
278 @property
279 Map myMap = {};
280
281 @property
282 Model myModel = new Model('hello');
283
213 TestElement.created() : super.created() { 284 TestElement.created() : super.created() {
214 polymerCreated(); 285 polymerCreated();
215 } 286 }
216 } 287 }
288
289 @PolymerRegister('sub-element')
290 class SubElement extends HtmlElement with PolymerMixin, PolymerBase, JsProxy {
291 SubElement.created() : super.created() {
292 polymerCreated();
293 }
294
295 @property
296 List<int> myInts;
297
298 @property
299 Map myMap;
300
301 @property
302 Model myModel;
303 }
304
305 class Model extends JsProxy {
306 String value;
307 Model(this.value);
308 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698