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

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

Issue 420673002: Roll polymer packages to version 0.3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | 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, scheduleMicrotask; 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')
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 }); 57 });
58 } 58 }
59 59
60 // TODO(sorvell): In IE, the unbind time is indeterminate, so wait an 60 // TODO(sorvell): In IE, the unbind time is indeterminate, so wait an
61 // extra beat. 61 // extra beat.
62 delay(x) => new Future.delayed(new Duration(milliseconds: 50), () => x); 62 delay(x) => new Future.delayed(new Duration(milliseconds: 50), () => x);
63 63
64 // TODO(jmesserly): fix this when it's easier to get a private symbol. 64 // TODO(jmesserly): fix this when it's easier to get a private symbol.
65 final unboundSymbol = reflectClass(Polymer).declarations.keys 65 final unboundSymbol = reflectClass(Polymer).declarations.keys
66 .firstWhere((s) => MirrorSystem.getName(s) == '_unbound'); 66 .firstWhere((s) => MirrorSystem.getName(s) == '_unbound');
67 final observersSymbol = reflectClass(Polymer).declarations.keys
68 .firstWhere((s) => MirrorSystem.getName(s) == '_observers');
67 69
68 _unbound(node) => reflect(node).getField(unboundSymbol).reflectee; 70 _unbound(node) => reflect(node).getField(unboundSymbol).reflectee;
71 _observerCount(node) =>
72 reflect(node).getField(observersSymbol).reflectee.length;
69 73
70 unbindTests() { 74 unbindTests() {
71 var xTest = document.querySelector('x-test'); 75 var xTest = document.querySelector('x-test');
72 xTest.foo = 'bar'; 76 xTest.foo = 'bar';
73 scheduleMicrotask(Observable.dirtyCheck); 77 scheduleMicrotask(Observable.dirtyCheck);
74 78
75 return delay(null).then((_) { 79 return delay(null).then((_) {
76 expect(_unbound(xTest), null, reason: 80 expect(_unbound(xTest), null, reason:
77 'element is bound when inserted'); 81 'element is bound when inserted');
78 expect(xTest.fooWasChanged, true, reason: 82 expect(xTest.fooWasChanged, true, reason:
79 'element is actually bound'); 83 'element is actually bound');
84 // Dart note: we don't have a way to check for the global count of
85 // observables/bindables, so we just check the count in the node.
86 expect(_observerCount(xTest), greaterThan(0));
80 xTest.remove(); 87 xTest.remove();
81 }).then(delay).then((_) { 88 }).then(delay).then((_) {
82 expect(_unbound(xTest), true, reason: 89 expect(_unbound(xTest), true, reason:
83 'element is unbound when removed'); 90 'element is unbound when removed');
91 expect(_observerCount(xTest), 0);
84 return new XTest(); 92 return new XTest();
85 }).then(delay).then((node) { 93 }).then(delay).then((node) {
86 expect(_unbound(node), null, reason: 94 expect(_unbound(node), null, reason:
87 'element is bound when not inserted'); 95 'element is bound when not inserted');
88 node.foo = 'bar'; 96 node.foo = 'bar';
97 expect(_observerCount(node), greaterThan(0));
89 scheduleMicrotask(Observable.dirtyCheck); 98 scheduleMicrotask(Observable.dirtyCheck);
90 return node; 99 return node;
91 }).then(delay).then((node) { 100 }).then(delay).then((node) {
92 expect(node.fooWasChanged, true, reason: 'node is actually bound'); 101 expect(node.fooWasChanged, true, reason: 'node is actually bound');
102 node.unbindAll();
93 var n = new XTest(); 103 var n = new XTest();
94 n.cancelUnbindAll(); 104 n.cancelUnbindAll();
95 return n; 105 return n;
96 }).then(delay).then((node) { 106 }).then(delay).then((node) {
97 expect(_unbound(node), null, reason: 107 expect(_unbound(node), null, reason:
98 'element is bound when cancelUnbindAll is called'); 108 'element is bound when cancelUnbindAll is called');
109 expect(_observerCount(node), greaterThan(0));
99 node.unbindAll(); 110 node.unbindAll();
100 expect(_unbound(node), true, reason: 111 expect(_unbound(node), true, reason:
101 'element is unbound when unbindAll is called'); 112 'element is unbound when unbindAll is called');
113 expect(_observerCount(node), 0);
102 var n = new XTest()..id = 'foobar!!!'; 114 var n = new XTest()..id = 'foobar!!!';
103 document.body.append(n); 115 document.body.append(n);
104 return n; 116 return n;
105 }).then(delay).then((node) { 117 }).then(delay).then((node) {
106 expect(_unbound(node), null, reason: 118 expect(_unbound(node), null, reason:
107 'element is bound when manually inserted'); 119 'element is bound when manually inserted');
120 expect(_observerCount(node), greaterThan(0));
108 node.remove(); 121 node.remove();
109 return node; 122 return node;
110 }).then(delay).then((node) { 123 }).then(delay).then((node) {
111 expect(_unbound(node), true, reason: 124 expect(_unbound(node), true, reason:
112 'element is unbound when manually removed is called'); 125 'element is unbound when manually removed is called');
126 expect(_observerCount(node), 0);
113 }); 127 });
114 } 128 }
OLDNEW
« no previous file with comments | « pkg/polymer/test/publish_inherited_properties_test.dart ('k') | pkg/polymer_expressions/CHANGELOG.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698