Chromium Code Reviews| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 | 88 |
| 89 // Because Polymer.js two-way bindings are just a getter/setter pair | 89 // Because Polymer.js two-way bindings are just a getter/setter pair |
| 90 // pointing at the original, we will see the new value immediately. | 90 // pointing at the original, we will see the new value immediately. |
| 91 expect(dartElem.twoWay, 42); | 91 expect(dartElem.twoWay, 42); |
| 92 | 92 |
| 93 expect(interop['foobar'], 42); | 93 expect(interop['foobar'], 42); |
| 94 | 94 |
| 95 // Text will update asynchronously | 95 // Text will update asynchronously |
| 96 expect(jsElem.shadowRoot.text, 'FOOBAR:40'); | 96 expect(jsElem.shadowRoot.text, 'FOOBAR:40'); |
| 97 | 97 |
| 98 return new Future(() { | 98 return _onTextChanged(jsElem.shadowRoot).then((_) { |
|
Siggi Cherem (dart-lang)
2014/07/08 16:50:38
could we replace this with:
jsElem.onMutation(js
Jennifer Messerly
2014/07/08 18:39:18
no, for two reasons:
* jsElem is a JS element so
| |
| 99 expect(jsElem.shadowRoot.text, 'FOOBAR:42'); | 99 expect(jsElem.shadowRoot.text, 'FOOBAR:42'); |
| 100 }); | 100 }); |
| 101 }); | 101 }); |
| 102 }); | 102 }); |
| 103 }); | 103 }); |
| 104 | 104 |
| 105 Future<List<MutationRecord>> _onTextChanged(Node node) { | |
| 106 var completer = new Completer(); | |
| 107 new MutationObserver((mutations, observer) { | |
| 108 observer.disconnect(); | |
| 109 completer.complete(mutations); | |
| 110 })..observe(node, characterData: true, subtree: true); | |
| 111 return completer.future; | |
| 112 } | |
| 113 | |
| 105 testInterop(jsElem) { | 114 testInterop(jsElem) { |
| 106 expect(jsElem.shadowRoot.text, 'FOOBAR'); | 115 expect(jsElem.shadowRoot.text, 'FOOBAR'); |
| 107 var interop = new JsObject.fromBrowserObject(jsElem); | 116 var interop = new JsObject.fromBrowserObject(jsElem); |
| 108 expect(interop['baz'], 42, reason: 'can read JS custom element properties'); | 117 expect(interop['baz'], 42, reason: 'can read JS custom element properties'); |
| 109 | 118 |
| 110 jsElem.attributes['baz'] = '123'; | 119 jsElem.attributes['baz'] = '123'; |
| 111 return flush().then((_) { | 120 return flush().then((_) { |
| 112 expect(interop['baz'], 123, reason: 'attribute reflected to property'); | 121 expect(interop['baz'], 123, reason: 'attribute reflected to property'); |
| 113 expect(jsElem.shadowRoot.text, 'FOOBAR', reason: 'text unchanged'); | 122 expect(jsElem.shadowRoot.text, 'FOOBAR', reason: 'text unchanged'); |
| 114 | 123 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 131 /// Calls Platform.flush() to flush Polymer.js pending operations, e.g. | 140 /// Calls Platform.flush() to flush Polymer.js pending operations, e.g. |
| 132 /// dirty checking for data-bindings. | 141 /// dirty checking for data-bindings. |
| 133 Future flush() { | 142 Future flush() { |
| 134 var Platform = context['Platform']; | 143 var Platform = context['Platform']; |
| 135 Platform.callMethod('flush'); | 144 Platform.callMethod('flush'); |
| 136 | 145 |
| 137 var completer = new Completer(); | 146 var completer = new Completer(); |
| 138 Platform.callMethod('endOfMicrotask', [() => completer.complete()]); | 147 Platform.callMethod('endOfMicrotask', [() => completer.complete()]); |
| 139 return completer.future; | 148 return completer.future; |
| 140 } | 149 } |
| OLD | NEW |