OLD | NEW |
---|---|
1 // Copyright (c) 2013, 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'; |
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 @CustomTag("dart-element2") | |
20 class DartElement2 extends PolymerElement { | |
21 Element get quux => this.querySelector('.quux'); | |
22 DartElement2.created() : super.created(); | |
23 } | |
24 | |
25 @CustomTag("dart-element3") | |
26 class DartElement3 extends PolymerElement { | |
27 @observable var quux; | |
28 DartElement3.created() : super.created(); | |
29 | |
30 domReady() { | |
31 quux = new JsObject.jsify({ | |
32 'aDartMethod': (x) => 444 + x | |
33 }); | |
34 } | |
35 } | |
36 | |
19 main() => initPolymer().run(() { | 37 main() => initPolymer().run(() { |
20 useHtmlConfiguration(); | 38 useHtmlConfiguration(); |
21 | 39 |
22 setUp(() => Polymer.onReady); | 40 setUp(() => Polymer.onReady); |
23 | 41 |
24 test('dart-element upgraded', () { | 42 test('dart-element upgraded', () { |
25 expect(querySelector('dart-element') is DartElement, true, | 43 expect(querySelector('dart-element') is DartElement, true, |
26 reason: 'dart-element upgraded'); | 44 reason: 'dart-element upgraded'); |
27 }); | 45 }); |
28 | 46 |
29 test('js-element in body', () => testInterop( | 47 test('js-element in body', () => testInterop( |
30 querySelector('js-element'))); | 48 querySelector('js-element'))); |
31 | 49 |
32 test('js-element in dart-element', () => testInterop( | 50 test('js-element in dart-element', () => testInterop( |
33 querySelector('dart-element').shadowRoot.querySelector('js-element'))); | 51 querySelector('dart-element').shadowRoot.querySelector('js-element'))); |
52 | |
53 test('elements can be passed through Node.bind to JS', () { | |
54 var text = querySelector('dart-element2') | |
55 .shadowRoot.querySelector('js-element2') | |
56 .shadowRoot.text; | |
57 expect(text, 'QUX:123'); | |
58 }); | |
59 | |
60 test('objects with funcdtions can be passed through Node.bind to JS', () { | |
Siggi Cherem (dart-lang)
2014/06/27 18:40:52
funcdtions => functions
Jennifer Messerly
2014/06/27 19:10:03
eek good catch!
| |
61 var sr = querySelector('dart-element3') | |
62 .shadowRoot.querySelector('js-element3') | |
63 .shadowRoot; | |
64 | |
65 return new Future(() { | |
66 expect(sr.text, 'js-element3[qux]:765'); | |
67 }); | |
68 }); | |
34 }); | 69 }); |
35 | 70 |
36 testInterop(jsElem) { | 71 testInterop(jsElem) { |
37 expect(jsElem.shadowRoot.text, 'FOOBAR'); | 72 expect(jsElem.shadowRoot.text, 'FOOBAR'); |
38 var interop = new JsObject.fromBrowserObject(jsElem); | 73 var interop = new JsObject.fromBrowserObject(jsElem); |
39 expect(interop['baz'], 42, reason: 'can read JS custom element properties'); | 74 expect(interop['baz'], 42, reason: 'can read JS custom element properties'); |
40 | 75 |
41 jsElem.attributes['baz'] = '123'; | 76 jsElem.attributes['baz'] = '123'; |
42 return flush().then((_) { | 77 return flush().then((_) { |
43 expect(interop['baz'], 123, reason: 'attribute reflected to property'); | 78 expect(interop['baz'], 123, reason: 'attribute reflected to property'); |
(...skipping 18 matching lines...) Expand all Loading... | |
62 /// Calls Platform.flush() to flush Polymer.js pending operations, e.g. | 97 /// Calls Platform.flush() to flush Polymer.js pending operations, e.g. |
63 /// dirty checking for data-bindings. | 98 /// dirty checking for data-bindings. |
64 Future flush() { | 99 Future flush() { |
65 var Platform = context['Platform']; | 100 var Platform = context['Platform']; |
66 Platform.callMethod('flush'); | 101 Platform.callMethod('flush'); |
67 | 102 |
68 var completer = new Completer(); | 103 var completer = new Completer(); |
69 Platform.callMethod('endOfMicrotask', [() => completer.complete()]); | 104 Platform.callMethod('endOfMicrotask', [() => completer.complete()]); |
70 return completer.future; | 105 return completer.future; |
71 } | 106 } |
OLD | NEW |