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

Side by Side Diff: tests/html/js_interop_element_test.dart

Issue 10883037: Serialize Elements through PortSync (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix line length Created 8 years, 3 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 | « lib/html/src/Isolates.dart ('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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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('JsInteropObjInvokeTest'); 5 #library('JsInteropElementTest');
6 #import('../../pkg/unittest/unittest.dart'); 6 #import('../../pkg/unittest/unittest.dart');
7 #import('../../pkg/unittest/html_config.dart'); 7 #import('../../pkg/unittest/html_config.dart');
8 #import('dart:html'); 8 #import('dart:html');
9 #import('dart:isolate'); 9 #import('dart:isolate');
10 10
11 injectSource(code) { 11 injectSource(code) {
12 final script = new ScriptElement(); 12 final script = new ScriptElement();
13 script.type = 'text/javascript'; 13 script.type = 'text/javascript';
14 script.innerHTML = code; 14 script.innerHTML = code;
15 document.body.nodes.add(script); 15 document.body.nodes.add(script);
16 } 16 }
17 17
18 var jsProxyTest = """ 18 var jsElementTest = """
19 function TestType(x) { 19 var canvas = document.createElement('canvas');
20 this.x = x; 20 document.body.appendChild(canvas);
21 }
22 TestType.prototype.razzle = function () {
23 return this.x * 2;
24 }
25 var data = new TestType(21);
26 21
27 var port = window.lookupPort('test1'); 22 var port = window.lookupPort('test1');
28 port.callSync(data); 23 port.callSync(canvas);
24 """;
25
26 var dartElementTest = """
27 var port = new ReceivePortSync();
28 port.receive(function (data) {
29 return (data instanceof HTMLDivElement);
30 });
31 window.registerPort('test2', port.toSendPort());
29 """; 32 """;
30 33
31 main() { 34 main() {
32 useHtmlConfiguration(); 35 useHtmlConfiguration();
33 36
34 test('js-proxy', () { 37 test('js-element', () {
35 int invoked = 0; 38 int invoked = 0;
36 39
37 var port = new ReceivePortSync(); 40 var port = new ReceivePortSync();
38 port.receive((data) { 41 port.receive((data) {
39 expect(data.x, equals(21)); 42 expect(data is CanvasElement);
40 expect(data.razzle(), equals(42));
41 data.x = 100;
42 expect(data.razzle(), equals(200));
43
44 ++invoked; 43 ++invoked;
45 }); 44 });
46 window.registerPort('test1', port.toSendPort()); 45 window.registerPort('test1', port.toSendPort());
47 46
48 injectSource(jsProxyTest); 47 injectSource(jsElementTest);
49 expect(invoked, equals(1)); 48 expect(invoked, equals(1));
50 }); 49 });
50
51 test('dart-element', () {
52 injectSource(dartElementTest);
53
54 var port = window.lookupPort('test2');
55 var div = new DivElement();
56 var canvas = new CanvasElement(100,100);
57 document.body.nodes.addAll([div, canvas]);
58 expect(port.callSync(div));
59 expect(!port.callSync(canvas));
60 });
51 } 61 }
OLDNEW
« no previous file with comments | « lib/html/src/Isolates.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698