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

Unified Diff: tests/html/js_interop_obj_passing_test.dart

Issue 10827462: Support proxying of objects between JS and Dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix html.status Created 8 years, 4 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 | « tests/html/html.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/html/js_interop_obj_passing_test.dart
diff --git a/tests/html/js_interop_obj_passing_test.dart b/tests/html/js_interop_obj_passing_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4a54010b263e28c8ac84f5a3fc349fb00a102594
--- /dev/null
+++ b/tests/html/js_interop_obj_passing_test.dart
@@ -0,0 +1,80 @@
+// Copyright (c) 2012, 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
+
+#library('JsInteropObjPassingTest');
+#import('../../pkg/unittest/unittest.dart');
+#import('../../pkg/unittest/html_config.dart');
+#import('dart:html');
+#import('dart:isolate');
+
+injectSource(code) {
+ final script = new ScriptElement();
+ script.type = 'text/javascript';
+ script.innerHTML = code;
+ document.body.nodes.add(script);
+}
+
+var jsProxyTest = """
+ function TestType(x) {
+ this.x = x;
+ }
+ TestType.prototype.razzle = function () {
+ return this.x * 2;
+ }
+ var data = new TestType(21);
+
+ var port1 = new ReceivePortSync();
+ port1.receive(function (x) {
+ return x.razzle();
+ });
+ window.registerPort('test1a', port1.toSendPort());
+
+ var port2 = window.lookupPort('test1b');
+ port2.callSync(data);
+""";
+
+var dartProxyTest = """
+ var port2 = new ReceivePortSync();
+ port2.receive(function (x) {
+ var port1 = window.lookupPort('test2a');
+ port1.callSync(x);
+ });
+ window.registerPort('test2b', port2.toSendPort());
+""";
+
+main() {
+ useHtmlConfiguration();
+
+ test('js-proxy', () {
+ int invoked = 0;
+
+ var port2 = new ReceivePortSync();
+ port2.receive((x) {
+ var port1 = window.lookupPort('test1a');
+ var result = port1.callSync(x);
+ expect(result, equals(42));
+ ++invoked;
+ });
+ window.registerPort('test1b', port2.toSendPort());
+
+ injectSource(jsProxyTest);
+ expect(invoked, equals(1));
+ });
+
+ test('dart-proxy', () {
+ injectSource(dartProxyTest);
+
+ var buffer = new StringBuffer();
+ buffer.add('hello');
+
+ var port1 = new ReceivePortSync();
+ port1.receive((x) => x.add(' from dart'));
+ window.registerPort('test2a', port1.toSendPort());
+
+ var port2 = window.lookupPort('test2b');
+ port2.callSync(buffer);
+
+ expect(buffer.toString(), equals('hello from dart'));
+ });
+}
« no previous file with comments | « tests/html/html.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698