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 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'; |
11 import 'package:unittest/html_config.dart'; | 11 import 'package:unittest/html_config.dart'; |
12 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
13 | 13 |
14 @CustomTag("dart-element") | 14 @CustomTag("dart-element") |
15 class DartElement extends PolymerElement { | 15 class DartElement extends PolymerElement { |
16 DartElement.created() : super.created(); | 16 DartElement.created() : super.created(); |
17 } | 17 } |
18 | 18 |
19 @initMethod | 19 main() => initPolymer().run(() { |
20 main() { | |
21 useHtmlConfiguration(); | 20 useHtmlConfiguration(); |
22 | 21 |
23 setUp(() => Polymer.onReady); | 22 setUp(() => Polymer.onReady); |
24 | 23 |
25 test('dart-element upgraded', () { | 24 test('dart-element upgraded', () { |
26 expect(querySelector('dart-element') is DartElement, true, | 25 expect(querySelector('dart-element') is DartElement, true, |
27 reason: 'dart-element upgraded'); | 26 reason: 'dart-element upgraded'); |
28 }); | 27 }); |
29 | 28 |
30 test('js-element in body', () => testInterop( | 29 test('js-element in body', () => testInterop( |
31 querySelector('js-element'))); | 30 querySelector('js-element'))); |
32 | 31 |
33 test('js-element in dart-element', () => testInterop( | 32 test('js-element in dart-element', () => testInterop( |
34 querySelector('dart-element').shadowRoot.querySelector('js-element'))); | 33 querySelector('dart-element').shadowRoot.querySelector('js-element'))); |
35 } | 34 }); |
36 | 35 |
37 testInterop(jsElem) { | 36 testInterop(jsElem) { |
38 expect(jsElem.shadowRoot.text, 'FOOBAR'); | 37 expect(jsElem.shadowRoot.text, 'FOOBAR'); |
39 var interop = new JsObject.fromBrowserObject(jsElem); | 38 var interop = new JsObject.fromBrowserObject(jsElem); |
40 expect(interop['baz'], 42, reason: 'can read JS custom element properties'); | 39 expect(interop['baz'], 42, reason: 'can read JS custom element properties'); |
41 | 40 |
42 jsElem.attributes['baz'] = '123'; | 41 jsElem.attributes['baz'] = '123'; |
43 return flush().then((_) { | 42 return flush().then((_) { |
44 expect(interop['baz'], 123, reason: 'attribute reflected to property'); | 43 expect(interop['baz'], 123, reason: 'attribute reflected to property'); |
45 expect(jsElem.shadowRoot.text, 'FOOBAR', reason: 'text unchanged'); | 44 expect(jsElem.shadowRoot.text, 'FOOBAR', reason: 'text unchanged'); |
(...skipping 17 matching lines...) Expand all Loading... |
63 /// Calls Platform.flush() to flush Polymer.js pending operations, e.g. | 62 /// Calls Platform.flush() to flush Polymer.js pending operations, e.g. |
64 /// dirty checking for data-bindings. | 63 /// dirty checking for data-bindings. |
65 Future flush() { | 64 Future flush() { |
66 var Platform = context['Platform']; | 65 var Platform = context['Platform']; |
67 Platform.callMethod('flush'); | 66 Platform.callMethod('flush'); |
68 | 67 |
69 var completer = new Completer(); | 68 var completer = new Completer(); |
70 Platform.callMethod('endOfMicrotask', [() => completer.complete()]); | 69 Platform.callMethod('endOfMicrotask', [() => completer.complete()]); |
71 return completer.future; | 70 return completer.future; |
72 } | 71 } |
OLD | NEW |