OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.web.js_interop_test; | 5 library polymer.test.web.js_interop_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'dart:js'; | 9 import 'dart:js'; |
10 import 'package:polymer/polymer.dart'; | 10 import 'package:polymer/polymer.dart'; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 expect(querySelector('dart-element') is DartElement, true, | 49 expect(querySelector('dart-element') is DartElement, true, |
50 reason: 'dart-element upgraded'); | 50 reason: 'dart-element upgraded'); |
51 }); | 51 }); |
52 | 52 |
53 test('js-element in body', () => testInterop( | 53 test('js-element in body', () => testInterop( |
54 querySelector('js-element'))); | 54 querySelector('js-element'))); |
55 | 55 |
56 test('js-element in dart-element', () => testInterop( | 56 test('js-element in dart-element', () => testInterop( |
57 querySelector('dart-element').shadowRoot.querySelector('js-element'))); | 57 querySelector('dart-element').shadowRoot.querySelector('js-element'))); |
58 | 58 |
59 test('elements can be passed through Node.bind to JS', () { | |
60 var text = querySelector('dart-element2') | |
61 .shadowRoot.querySelector('js-element2') | |
62 .shadowRoot.text; | |
63 expect(text, 'QUX:123'); | |
64 }); | |
65 | |
66 test('objects with functions can be passed through Node.bind to JS', () { | 59 test('objects with functions can be passed through Node.bind to JS', () { |
67 var sr = querySelector('dart-element3') | 60 var sr = querySelector('dart-element3') |
68 .shadowRoot.querySelector('js-element3') | 61 .shadowRoot.querySelector('js-element3') |
69 .shadowRoot; | 62 .shadowRoot; |
70 | 63 |
71 return new Future(() { | 64 return new Future(() { |
72 expect(sr.text, 'js-element3[qux]:765'); | 65 expect(sr.text, 'js-element3[qux]:765'); |
73 }); | 66 }); |
74 }); | 67 }); |
75 | 68 |
(...skipping 17 matching lines...) Expand all Loading... | |
93 expect(interop['foobar'], 42); | 86 expect(interop['foobar'], 42); |
94 | 87 |
95 // Text will update asynchronously | 88 // Text will update asynchronously |
96 expect(jsElem.shadowRoot.text, 'FOOBAR:40'); | 89 expect(jsElem.shadowRoot.text, 'FOOBAR:40'); |
97 | 90 |
98 return _onTextChanged(jsElem.shadowRoot).then((_) { | 91 return _onTextChanged(jsElem.shadowRoot).then((_) { |
99 expect(jsElem.shadowRoot.text, 'FOOBAR:42'); | 92 expect(jsElem.shadowRoot.text, 'FOOBAR:42'); |
100 }); | 93 }); |
101 }); | 94 }); |
102 }); | 95 }); |
96 | |
97 test('elements can be passed through Node.bind to JS', () { | |
Siggi Cherem (dart-lang)
2014/08/26 22:41:39
let's move it back where it was, since that's no l
jakemac
2014/08/27 14:59:50
Done.
| |
98 var text = querySelector('dart-element2') | |
99 .shadowRoot.querySelector('js-element2') | |
100 .shadowRoot.text; | |
101 expect(text, 'QUX:123'); | |
102 }); | |
103 }); | 103 }); |
104 | 104 |
105 Future<List<MutationRecord>> _onTextChanged(Node node) { | 105 Future<List<MutationRecord>> _onTextChanged(Node node) { |
106 var completer = new Completer(); | 106 var completer = new Completer(); |
107 new MutationObserver((mutations, observer) { | 107 new MutationObserver((mutations, observer) { |
108 observer.disconnect(); | 108 observer.disconnect(); |
109 completer.complete(mutations); | 109 completer.complete(mutations); |
110 })..observe(node, characterData: true, subtree: true); | 110 })..observe(node, characterData: true, subtree: true); |
111 return completer.future; | 111 return completer.future; |
112 } | 112 } |
(...skipping 27 matching lines...) Expand all Loading... | |
140 /// Calls Platform.flush() to flush Polymer.js pending operations, e.g. | 140 /// Calls Platform.flush() to flush Polymer.js pending operations, e.g. |
141 /// dirty checking for data-bindings. | 141 /// dirty checking for data-bindings. |
142 Future flush() { | 142 Future flush() { |
143 var Platform = context['Platform']; | 143 var Platform = context['Platform']; |
144 Platform.callMethod('flush'); | 144 Platform.callMethod('flush'); |
145 | 145 |
146 var completer = new Completer(); | 146 var completer = new Completer(); |
147 Platform.callMethod('endOfMicrotask', [() => completer.complete()]); | 147 Platform.callMethod('endOfMicrotask', [() => completer.complete()]); |
148 return completer.future; | 148 return completer.future; |
149 } | 149 } |
OLD | NEW |