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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/html/html.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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('JsInteropObjPassingTest');
6 #import('../../pkg/unittest/unittest.dart');
7 #import('../../pkg/unittest/html_config.dart');
8 #import('dart:html');
9 #import('dart:isolate');
10
11 injectSource(code) {
12 final script = new ScriptElement();
13 script.type = 'text/javascript';
14 script.innerHTML = code;
15 document.body.nodes.add(script);
16 }
17
18 var jsProxyTest = """
19 function TestType(x) {
20 this.x = x;
21 }
22 TestType.prototype.razzle = function () {
23 return this.x * 2;
24 }
25 var data = new TestType(21);
26
27 var port1 = new ReceivePortSync();
28 port1.receive(function (x) {
29 return x.razzle();
30 });
31 window.registerPort('test1a', port1.toSendPort());
32
33 var port2 = window.lookupPort('test1b');
34 port2.callSync(data);
35 """;
36
37 var dartProxyTest = """
38 var port2 = new ReceivePortSync();
39 port2.receive(function (x) {
40 var port1 = window.lookupPort('test2a');
41 port1.callSync(x);
42 });
43 window.registerPort('test2b', port2.toSendPort());
44 """;
45
46 main() {
47 useHtmlConfiguration();
48
49 test('js-proxy', () {
50 int invoked = 0;
51
52 var port2 = new ReceivePortSync();
53 port2.receive((x) {
54 var port1 = window.lookupPort('test1a');
55 var result = port1.callSync(x);
56 expect(result, equals(42));
57 ++invoked;
58 });
59 window.registerPort('test1b', port2.toSendPort());
60
61 injectSource(jsProxyTest);
62 expect(invoked, equals(1));
63 });
64
65 test('dart-proxy', () {
66 injectSource(dartProxyTest);
67
68 var buffer = new StringBuffer();
69 buffer.add('hello');
70
71 var port1 = new ReceivePortSync();
72 port1.receive((x) => x.add(' from dart'));
73 window.registerPort('test2a', port1.toSendPort());
74
75 var port2 = window.lookupPort('test2b');
76 port2.callSync(buffer);
77
78 expect(buffer.toString(), equals('hello from dart'));
79 });
80 }
OLDNEW
« 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