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