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

Side by Side Diff: pkg/polymer/test/unbind_test.dart

Issue 41293002: Fixes from polymer.dart API review (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Made Job a part of polymer Created 7 years, 1 month 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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 4
5 library polymer.test.unbind_test; 5 library polymer.test.unbind_test;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future, scheduleMicrotask;
8 import 'dart:html'; 8 import 'dart:html';
9 9
10 @MirrorsUsed(targets: const [Polymer], override: 'polymer.test.unbind_test') 10 @MirrorsUsed(targets: const [Polymer], override: 'polymer.test.unbind_test')
11 import 'dart:mirrors' show reflect, reflectClass, MirrorSystem, MirrorsUsed; 11 import 'dart:mirrors' show reflect, reflectClass, MirrorSystem, MirrorsUsed;
12 12
13 import 'package:polymer/polymer.dart'; 13 import 'package:polymer/polymer.dart';
14 import 'package:polymer/platform.dart' as Platform;
15 import 'package:unittest/unittest.dart'; 14 import 'package:unittest/unittest.dart';
16 import 'package:unittest/html_config.dart'; 15 import 'package:unittest/html_config.dart';
17 16
18 @CustomTag('x-test') 17 @CustomTag('x-test')
19 class XTest extends PolymerElement { 18 class XTest extends PolymerElement {
20 @observable var foo = ''; 19 @observable var foo = '';
21 @observable var bar; 20 @observable var bar;
22 21
23 bool forceReady = true; 22 bool forceReady = true;
24 bool fooWasChanged = false; 23 bool fooWasChanged = false;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 64
66 // TODO(jmesserly): fix this when it's easier to get a private symbol. 65 // TODO(jmesserly): fix this when it's easier to get a private symbol.
67 final unboundSymbol = reflectClass(Polymer).variables.keys 66 final unboundSymbol = reflectClass(Polymer).variables.keys
68 .firstWhere((s) => MirrorSystem.getName(s) == '_unbound'); 67 .firstWhere((s) => MirrorSystem.getName(s) == '_unbound');
69 68
70 _unbound(node) => reflect(node).getField(unboundSymbol).reflectee; 69 _unbound(node) => reflect(node).getField(unboundSymbol).reflectee;
71 70
72 unbindTests() { 71 unbindTests() {
73 var xTest = document.query('x-test'); 72 var xTest = document.query('x-test');
74 xTest.foo = 'bar'; 73 xTest.foo = 'bar';
75 Platform.flush(); 74 scheduleMicrotask(Observable.dirtyCheck);
76 75
77 return delay(null).then((_) { 76 return delay(null).then((_) {
78 expect(_unbound(xTest), null, reason: 77 expect(_unbound(xTest), null, reason:
79 'element is bound when inserted'); 78 'element is bound when inserted');
80 expect(xTest.fooWasChanged, true, reason: 79 expect(xTest.fooWasChanged, true, reason:
81 'element is actually bound'); 80 'element is actually bound');
82 xTest.remove(); 81 xTest.remove();
83 }).then(delay).then((_) { 82 }).then(delay).then((_) {
84 expect(_unbound(xTest), true, reason: 83 expect(_unbound(xTest), true, reason:
85 'element is unbound when removed'); 84 'element is unbound when removed');
86 return new XTest(); 85 return new XTest();
87 }).then(delay).then((node) { 86 }).then(delay).then((node) {
88 expect(_unbound(node), null, reason: 87 expect(_unbound(node), null, reason:
89 'element is bound when not inserted'); 88 'element is bound when not inserted');
90 node.foo = 'bar'; 89 node.foo = 'bar';
91 Platform.flush(); 90 scheduleMicrotask(Observable.dirtyCheck);
92 return node; 91 return node;
93 }).then(delay).then((node) { 92 }).then(delay).then((node) {
94 expect(node.fooWasChanged, true, reason: 'node is actually bound'); 93 expect(node.fooWasChanged, true, reason: 'node is actually bound');
95 var n = new XTest(); 94 var n = new XTest();
96 n.cancelUnbindAll(); 95 n.cancelUnbindAll();
97 return n; 96 return n;
98 }).then(delay).then((node) { 97 }).then(delay).then((node) {
99 expect(_unbound(node), null, reason: 98 expect(_unbound(node), null, reason:
100 'element is bound when cancelUnbindAll is called'); 99 'element is bound when cancelUnbindAll is called');
101 node.unbindAll(); 100 node.unbindAll();
102 expect(_unbound(node), true, reason: 101 expect(_unbound(node), true, reason:
103 'element is unbound when unbindAll is called'); 102 'element is unbound when unbindAll is called');
104 var n = new XTest()..id = 'foobar!!!'; 103 var n = new XTest()..id = 'foobar!!!';
105 document.body.append(n); 104 document.body.append(n);
106 return n; 105 return n;
107 }).then(delay).then((node) { 106 }).then(delay).then((node) {
108 expect(_unbound(node), null, reason: 107 expect(_unbound(node), null, reason:
109 'element is bound when manually inserted'); 108 'element is bound when manually inserted');
110 node.remove(); 109 node.remove();
111 return node; 110 return node;
112 }).then(delay).then((node) { 111 }).then(delay).then((node) {
113 expect(_unbound(node), true, reason: 112 expect(_unbound(node), true, reason:
114 'element is unbound when manually removed is called'); 113 'element is unbound when manually removed is called');
115 }); 114 });
116 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698