OLD | NEW |
| (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('JsInteropElementTest'); | |
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 jsElementTest = """ | |
19 var canvas = document.createElement('canvas'); | |
20 document.body.appendChild(canvas); | |
21 | |
22 var port = window.lookupPort('test1'); | |
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()); | |
32 """; | |
33 | |
34 main() { | |
35 useHtmlConfiguration(); | |
36 | |
37 test('js-element', () { | |
38 int invoked = 0; | |
39 | |
40 var port = new ReceivePortSync(); | |
41 port.receive((data) { | |
42 expect(data is CanvasElement); | |
43 ++invoked; | |
44 }); | |
45 window.registerPort('test1', port.toSendPort()); | |
46 | |
47 injectSource(jsElementTest); | |
48 expect(invoked, equals(1)); | |
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 }); | |
61 } | |
OLD | NEW |