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

Unified Diff: pkg/polymer/test/js_interop_test.dart

Issue 355133002: switch Node.bind to interop (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/polymer/pubspec.yaml ('k') | pkg/polymer/test/js_interop_test.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer/test/js_interop_test.dart
diff --git a/pkg/polymer/test/js_interop_test.dart b/pkg/polymer/test/js_interop_test.dart
index 3704ccb93addc5a6d30b535d2459d6cb484bd6bf..e4bc6aa530781cb1ea2e2997f272713378c012d4 100644
--- a/pkg/polymer/test/js_interop_test.dart
+++ b/pkg/polymer/test/js_interop_test.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -11,11 +11,35 @@ import 'package:polymer/polymer.dart';
import 'package:unittest/html_config.dart';
import 'package:unittest/unittest.dart';
-@CustomTag("dart-element")
+@CustomTag('dart-element')
class DartElement extends PolymerElement {
DartElement.created() : super.created();
}
+@CustomTag('dart-element2')
+class DartElement2 extends PolymerElement {
+ Element get quux => this.querySelector('.quux');
+ DartElement2.created() : super.created();
+}
+
+@CustomTag('dart-element3')
+class DartElement3 extends PolymerElement {
+ @observable var quux;
+ DartElement3.created() : super.created();
+
+ domReady() {
+ quux = new JsObject.jsify({
+ 'aDartMethod': (x) => 444 + x
+ });
+ }
+}
+
+@CustomTag('dart-two-way')
+class DartTwoWay extends PolymerElement {
+ @observable var twoWay = 40;
+ DartTwoWay.created() : super.created();
+}
+
main() => initPolymer().run(() {
useHtmlConfiguration();
@@ -31,6 +55,51 @@ main() => initPolymer().run(() {
test('js-element in dart-element', () => testInterop(
querySelector('dart-element').shadowRoot.querySelector('js-element')));
+
+ test('elements can be passed through Node.bind to JS', () {
+ var text = querySelector('dart-element2')
+ .shadowRoot.querySelector('js-element2')
+ .shadowRoot.text;
+ expect(text, 'QUX:123');
+ });
+
+ test('objects with functions can be passed through Node.bind to JS', () {
+ var sr = querySelector('dart-element3')
+ .shadowRoot.querySelector('js-element3')
+ .shadowRoot;
+
+ return new Future(() {
+ expect(sr.text, 'js-element3[qux]:765');
+ });
+ });
+
+ test('two way bindings work', () {
+ var dartElem = querySelector('dart-two-way');
+ var jsElem = dartElem.shadowRoot.querySelector('js-two-way');
+ var interop = new JsObject.fromBrowserObject(jsElem);
+
+ return new Future(() {
+ expect(jsElem.shadowRoot.text, 'FOOBAR:40');
+
+ expect(dartElem.twoWay, 40);
+ expect(interop['foobar'], 40);
+
+ interop.callMethod('aJsMethod', [2]);
+
+ // Because Polymer.js two-way bindings are just a getter/setter pair
+ // pointing at the original, we will see the new value immediately.
+ expect(dartElem.twoWay, 42);
+
+ expect(interop['foobar'], 42);
+
+ // Text will update asynchronously
+ expect(jsElem.shadowRoot.text, 'FOOBAR:40');
+
+ return new Future(() {
+ expect(jsElem.shadowRoot.text, 'FOOBAR:42');
+ });
+ });
+ });
});
testInterop(jsElem) {
« no previous file with comments | « pkg/polymer/pubspec.yaml ('k') | pkg/polymer/test/js_interop_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698