OLD | NEW |
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 template_binding.test.utils; | 5 library template_binding.test.utils; |
6 | 6 |
| 7 import 'dart:async'; |
7 import 'dart:html'; | 8 import 'dart:html'; |
8 import 'package:observe/observe.dart'; | 9 import 'package:observe/observe.dart'; |
9 import 'package:template_binding/template_binding.dart'; | 10 import 'package:template_binding/template_binding.dart'; |
10 import 'package:unittest/unittest.dart'; | 11 export 'package:observe/src/dirty_check.dart' show dirtyCheckZone; |
11 | 12 |
12 import 'package:observe/src/microtask.dart'; | 13 /// A small method to help readability. Used to cause the next "then" in a chain |
13 export 'package:observe/src/microtask.dart'; | 14 /// to happen in the next microtask: |
| 15 /// |
| 16 /// future.then(newMicrotask).then(...) |
| 17 endOfMicrotask(_) => new Future.value(); |
| 18 |
| 19 /// A small method to help readability. Used to cause the next "then" in a chain |
| 20 /// to happen in the next microtask, after a timer: |
| 21 /// |
| 22 /// future.then(nextMicrotask).then(...) |
| 23 nextMicrotask(_) => new Future(() {}); |
14 | 24 |
15 final bool parserHasNativeTemplate = () { | 25 final bool parserHasNativeTemplate = () { |
16 var div = new DivElement()..innerHtml = '<table><template>'; | 26 var div = new DivElement()..innerHtml = '<table><template>'; |
17 return div.firstChild.firstChild != null && | 27 return div.firstChild.firstChild != null && |
18 div.firstChild.firstChild.tagName == 'TEMPLATE'; | 28 div.firstChild.firstChild.tagName == 'TEMPLATE'; |
19 }(); | 29 }(); |
20 | 30 |
21 recursivelySetTemplateModel(element, model, [delegate]) { | 31 recursivelySetTemplateModel(element, model, [delegate]) { |
22 for (var node in element.queryAll('*')) { | 32 for (var node in element.queryAll('*')) { |
23 if (isSemanticTemplate(node)) { | 33 if (isSemanticTemplate(node)) { |
(...skipping 26 matching lines...) Expand all Loading... |
50 set foo(value) { | 60 set foo(value) { |
51 _foo = notifyPropertyChange(#foo, _foo, value); | 61 _foo = notifyPropertyChange(#foo, _foo, value); |
52 } | 62 } |
53 | 63 |
54 get bar => _bar; | 64 get bar => _bar; |
55 set bar(value) { | 65 set bar(value) { |
56 _bar = notifyPropertyChange(#bar, _bar, value); | 66 _bar = notifyPropertyChange(#bar, _bar, value); |
57 } | 67 } |
58 } | 68 } |
59 | 69 |
60 observeTest(name, testCase) => test(name, wrapMicrotask(testCase)); | |
61 | |
62 solo_observeTest(name, testCase) => solo_test(name, wrapMicrotask(testCase)); | |
63 | |
64 DivElement testDiv; | 70 DivElement testDiv; |
65 | 71 |
66 createTestHtml(s) { | 72 createTestHtml(s) { |
67 var div = new DivElement(); | 73 var div = new DivElement(); |
68 div.setInnerHtml(s, treeSanitizer: new NullTreeSanitizer()); | 74 div.setInnerHtml(s, treeSanitizer: new NullTreeSanitizer()); |
69 testDiv.append(div); | 75 testDiv.append(div); |
70 | 76 |
71 for (var node in div.queryAll('*')) { | 77 for (var node in div.querySelectorAll('*')) { |
72 if (isSemanticTemplate(node)) TemplateBindExtension.decorate(node); | 78 if (isSemanticTemplate(node)) TemplateBindExtension.decorate(node); |
73 } | 79 } |
74 | 80 |
75 return div; | 81 return div; |
76 } | 82 } |
77 | 83 |
78 createShadowTestHtml(s) { | 84 createShadowTestHtml(s) { |
79 var div = new DivElement(); | 85 var div = new DivElement(); |
80 var root = div.createShadowRoot(); | 86 var root = div.createShadowRoot(); |
81 root.setInnerHtml(s, treeSanitizer: new NullTreeSanitizer()); | 87 root.setInnerHtml(s, treeSanitizer: new NullTreeSanitizer()); |
(...skipping 12 matching lines...) Expand all Loading... |
94 class NullTreeSanitizer implements NodeTreeSanitizer { | 100 class NullTreeSanitizer implements NodeTreeSanitizer { |
95 void sanitizeTree(Node node) {} | 101 void sanitizeTree(Node node) {} |
96 } | 102 } |
97 | 103 |
98 unbindAll(node) { | 104 unbindAll(node) { |
99 nodeBind(node).unbindAll(); | 105 nodeBind(node).unbindAll(); |
100 for (var child = node.firstChild; child != null; child = child.nextNode) { | 106 for (var child = node.firstChild; child != null; child = child.nextNode) { |
101 unbindAll(child); | 107 unbindAll(child); |
102 } | 108 } |
103 } | 109 } |
OLD | NEW |