Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: pkg/polymer/test/js_interop_test.dart

Issue 182193002: [polymer] interop with polymer-element and polymer.js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library polymer.test.web.js_interop_test;
6
7 import 'dart:async';
8 import 'dart:html';
9 import 'dart:js';
10 import 'package:polymer/polymer.dart';
11 import 'package:unittest/html_config.dart';
12 import 'package:unittest/unittest.dart';
13
14 @CustomTag("dart-element")
15 class DartElement extends PolymerElement {
16 DartElement.created() : super.created();
17 }
18
19 main() => initPolymer().run(() {
20 useHtmlConfiguration();
21
22 setUp(() => Polymer.onReady);
23
24 test('dart-element upgraded', () {
25 expect(querySelector('dart-element') is DartElement, true,
26 reason: 'dart-element upgraded');
27 });
28
29 test('js-element in body', () => testInterop(
30 querySelector('js-element')));
31
32 test('js-element in dart-element', () => testInterop(
33 querySelector('dart-element').shadowRoot.querySelector('js-element')));
34 });
35
36 testInterop(jsElem) {
37 expect(jsElem.shadowRoot.text, 'FOOBAR');
38 var interop = new JsObject.fromBrowserObject(jsElem);
39 expect(interop['baz'], 42, reason: 'can read JS custom element properties');
40
41 jsElem.attributes['baz'] = '123';
42 return flush().then((_) {
43 expect(interop['baz'], 123, reason: 'attribute reflected to property');
44 expect(jsElem.shadowRoot.text, 'FOOBAR', reason: 'text unchanged');
45
46 interop['baz'] = 777;
47 return flush();
48 }).then((_) {
49 expect(jsElem.attributes['baz'], '777',
50 reason: 'property reflected to attribute');
51
52 expect(jsElem.shadowRoot.text, 'FOOBAR', reason: 'text unchanged');
53
54 interop.callMethod('aJsMethod', [123]);
55 return flush();
56 }).then((_) {
57 expect(jsElem.shadowRoot.text, '900', reason: 'text set by JS method');
58 expect(interop['baz'], 777, reason: 'unchanged');
59 });
60 }
61
62 /// Calls Platform.flush() to flush Polymer.js pending operations, e.g.
63 /// dirty checking for data-bindings.
64 Future flush() {
65 var Platform = context['Platform'];
66 Platform.callMethod('flush');
67
68 var completer = new Completer();
69 Platform.callMethod('endOfMicrotask', [() => completer.complete()]);
70 return completer.future;
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698