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

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

Issue 794473002: Delete polymer from the Dart repo (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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/polymer/test/two_way_bind_test.html ('k') | pkg/polymer/test/unbind_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 polymer.test.unbind_test;
6
7 import 'dart:async' show Future, scheduleMicrotask;
8 import 'dart:html';
9
10 @MirrorsUsed(targets: const [Polymer], override: 'polymer.test.unbind_test')
11 import 'dart:mirrors' show reflect, reflectClass, MirrorSystem, MirrorsUsed;
12
13 import 'package:polymer/polymer.dart';
14 import 'package:unittest/unittest.dart';
15 import 'package:unittest/html_config.dart';
16
17 @CustomTag('x-test')
18 class XTest extends PolymerElement {
19 @observable var foo = '';
20 @observable var bar;
21
22 bool fooWasChanged = false;
23 var validBar;
24
25 factory XTest() => new Element.tag('x-test');
26 XTest.created() : super.created();
27
28 ready() {}
29
30 fooChanged() {
31 fooWasChanged = true;
32 }
33
34 barChanged() {
35 validBar = bar;
36 }
37
38 bool get isBarValid => validBar == bar;
39 }
40
41 main() => initPolymer().run(() {
42 useHtmlConfiguration();
43
44 setUp(() => Polymer.onReady);
45
46 test('unbind', unbindTests);
47 });
48
49 Future testAsync(List<Function> tests, int delayMs, [List args]) {
50 if (tests.length == 0) return new Future.value();
51 // TODO(jmesserly): CustomElements.takeRecords();
52 return new Future.delayed(new Duration(milliseconds: delayMs), () {
53 if (args == null) args = [];
54 var lastArgs = Function.apply(tests.removeAt(0), args);
55 return testAsync(tests, delayMs, lastArgs);
56 });
57 }
58
59 // TODO(sorvell): In IE, the unbind time is indeterminate, so wait an
60 // extra beat.
61 delay(x) => new Future.delayed(new Duration(milliseconds: 50), () => x);
62
63 // TODO(jmesserly): fix this when it's easier to get a private symbol.
64 final unboundSymbol = reflectClass(Polymer).declarations.keys
65 .firstWhere((s) => MirrorSystem.getName(s) == '_unbound');
66 final observersSymbol = reflectClass(Polymer).declarations.keys
67 .firstWhere((s) => MirrorSystem.getName(s) == '_observers');
68
69 _unbound(node) => reflect(node).getField(unboundSymbol).reflectee;
70 _observerCount(node) =>
71 reflect(node).getField(observersSymbol).reflectee.length;
72
73 unbindTests() {
74 var xTest = document.querySelector('x-test');
75 xTest.foo = 'bar';
76 scheduleMicrotask(Observable.dirtyCheck);
77
78 return delay(null).then((_) {
79 expect(_unbound(xTest), null, reason:
80 'element is bound when inserted');
81 expect(xTest.fooWasChanged, true, reason:
82 'element is actually bound');
83 // Dart note: we don't have a way to check for the global count of
84 // observables/bindables, so we just check the count in the node.
85 expect(_observerCount(xTest), greaterThan(0));
86 xTest.remove();
87 }).then(delay).then((_) {
88 expect(_unbound(xTest), true, reason:
89 'element is unbound when removed');
90 expect(_observerCount(xTest), 0);
91 return new XTest();
92 }).then(delay).then((node) {
93 expect(_unbound(node), null, reason:
94 'element is bound when not inserted');
95 node.foo = 'bar';
96 expect(_observerCount(node), greaterThan(0));
97 scheduleMicrotask(Observable.dirtyCheck);
98 return node;
99 }).then(delay).then((node) {
100 expect(node.fooWasChanged, true, reason: 'node is actually bound');
101 node.unbindAll();
102 var n = new XTest();
103 n.cancelUnbindAll();
104 return n;
105 }).then(delay).then((node) {
106 expect(_unbound(node), null, reason:
107 'element is bound when cancelUnbindAll is called');
108 expect(_observerCount(node), greaterThan(0));
109 node.unbindAll();
110 expect(_unbound(node), true, reason:
111 'element is unbound when unbindAll is called');
112 expect(_observerCount(node), 0);
113 var n = new XTest()..id = 'foobar!!!';
114 document.body.append(n);
115 return n;
116 }).then(delay).then((node) {
117 expect(_unbound(node), null, reason:
118 'element is bound when manually inserted');
119 expect(_observerCount(node), greaterThan(0));
120 node.remove();
121 return node;
122 }).then(delay).then((node) {
123 expect(_unbound(node), true, reason:
124 'element is unbound when manually removed is called');
125 expect(_observerCount(node), 0);
126 });
127 }
OLDNEW
« no previous file with comments | « pkg/polymer/test/two_way_bind_test.html ('k') | pkg/polymer/test/unbind_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698