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

Side by Side Diff: LayoutTests/dart/multiscript-js-interop.html

Issue 1663753002: Apply all blink changes between @202695 and tip of trunk (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/2454_1
Patch Set: Created 4 years, 10 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
OLDNEW
1 <html> 1 <html>
2 <head> 2 <head>
3 <script type="application/javascript" src="../../../../dart/pkg/unittest/lib/tes t_controller.js"></script> 3 <script type="application/javascript" src="../../../../dart/pkg/unittest/lib/tes t_controller.js"></script>
4 <script type="application/javascript"> 4 <script type="application/javascript">
5 var sJs = 0; 5 var sJs;
6 var callbacks = []; 6 var callbacks = [];
7 var numCallbacks = 0; 7 var numCallbacks = 0;
8 // Trivial method to run all 4 callbacks in order once they are all 8 // Trivial method to run all 4 callbacks in order once they are all
9 // registered. 9 // registered.
10 function registerCallback(index, callback) { 10 function registerCallback(index, callback) {
11 callbacks[index] = callback; 11 callbacks[index] = callback;
12 numCallbacks++; 12 numCallbacks++;
13 if (numCallbacks == 4) { 13 if (numCallbacks == 4) {
14 for (var i = 0; i < numCallbacks; i++) { 14 for (var i = 0; i < numCallbacks; i++) {
15 callbacks[i](); 15 callbacks[i]();
16 } 16 }
17 } 17 }
18 } 18 }
19 </script> 19 </script>
20 </head> 20 </head>
21 <body> 21 <body>
22 22
23 <script type="application/dart"> 23 <script type="application/dart">
24 import 'dart:async'; 24 import 'dart:async';
25 import 'package:js/js.dart';
25 import 'package:unittest/unittest.dart'; 26 import 'package:unittest/unittest.dart';
26 import 'Multiscript.dart'; 27 import 'multiscript-js-interop.dart';
27 28
28 main() { 29 main() {
29 State.registerCallback(0, () { 30 State.registerCallback(0, allowInterop(() {
30 // FIXME: Rewrite this test to use html-imports. 31 // FIXME: Rewrite this test to use html-imports.
31 print("Running script 0"); 32 print("Running script 0");
32 State.update(); 33 State.update();
33 expect(State.sJs, equals(1)); 34 expect(State.sJs.length, equals(1));
34 expect(State.sDart, equals(1)); 35 expect(State.sDart, equals(1));
35 }); 36 }));
36 } 37 }
37 </script> 38 </script>
38 39
39 <script type="application/dart"> 40 <script type="application/dart">
40 import 'dart:js' as js; 41 import 'package:js/js.dart';
41 import 'dart:math'; 42 import 'dart:math';
42 import 'package:unittest/unittest.dart'; 43 import 'package:unittest/unittest.dart';
43 import 'Multiscript.dart'; 44 import 'multiscript-js-interop.dart';
45
46 @JS()
47 external Function get doubleValue;
48 @JS()
49 external Function set doubleValue(Function v);
44 50
45 main() { 51 main() {
46 State.registerCallback(1, () { 52 State.registerCallback(1, allowInterop(() {
47 print("Running script 1"); 53 print("Running script 1");
48 State.update(); 54 State.update();
49 expect(State.sJs, equals(2)); 55 expect(State.sJs.length, equals(2));
50 expect(State.sDart, equals(1)); 56 expect(State.sDart, equals(1));
51 js.context['doubleValue'] = (x) => x*2; 57 doubleValue = allowInterop((x) => x*2);
52 expect(js.context.callMethod('doubleValue', [21]), equals(42)); 58 expect(doubleValue(21), equals(42));
53 expect(js.context.callMethod('doubleValue', ["Foo"]), equals("FooFoo")); 59 expect(doubleValue("Foo"), equals("FooFoo"));
54 // Point is not a primitive type so passing it to a different isolate is 60 // Point is not a primitive type so passing it to a different isolate is
55 // not allowed. 61 // not allowed.
56 expect(js.context.callMethod('doubleValue', [new Point(2, 4)]), 62 expect(doubleValue(new Point(2, 4)),
57 equals(new Point(4, 8))); 63 equals(new Point(4, 8)));
58 }); 64 }));
59 } 65 }
60 </script> 66 </script>
61 67
62 <script type="application/dart"> 68 <script type="application/dart">
69 import 'package:js/js.dart';
63 import 'package:unittest/unittest.dart'; 70 import 'package:unittest/unittest.dart';
64 import 'Multiscript.dart'; 71 import 'multiscript-js-interop.dart';
65 72
66 main() { 73 main() {
67 State.registerCallback(2, () { 74 State.registerCallback(2, allowInterop(() {
68 print("Running script 2"); 75 print("Running script 2");
69 State.update(); 76 State.update();
70 expect(State.sJs, equals(3)); 77 expect(State.sJs.length, equals(3));
71 expect(State.sDart, equals(1)); 78 expect(State.sDart, equals(1));
72 }); 79 }));
73 } 80 }
74 </script> 81 </script>
75 82
76 <script type="application/dart"> 83 <script type="application/dart">
77 import 'dart:js' as js;
78 import 'dart:math'; 84 import 'dart:math';
85 import 'package:js/js.dart';
79 import 'package:unittest/unittest.dart'; 86 import 'package:unittest/unittest.dart';
80 import 'package:unittest/html_config.dart'; 87 import 'package:unittest/html_config.dart';
81 import 'Multiscript.dart'; 88 import 'multiscript-js-interop.dart';
89
90 // This function is set by a different isolate.
91 @JS()
92 external Function get doubleValue;
82 93
83 main() { 94 main() {
84 State.registerCallback(3, () { 95 State.registerCallback(3, allowInterop(() {
85 print("Running script 3"); 96 print("Running script 3");
86 useHtmlConfiguration(true); 97 useHtmlConfiguration(true);
87 test('Multiple script tags', () { 98 test('Multiple script tags', () {
88 State.update(); 99 State.update();
89 expect(State.sJs, equals(4)); 100 expect(State.sJs.length, equals(4));
90 expect(State.sDart, equals(1)); 101 expect(State.sDart, equals(1));
91 102
92 // doubleValue is from a different Dart isolate but arguments are primitiv e 103 // doubleValue is from a different Dart isolate but arguments are primitiv e
93 // types so it is safe to call. 104 // types so it is safe to call.
94 expect(js.context.callMethod('doubleValue', [21]), equals(42)); 105 expect(doubleValue(21), equals(42));
95 expect(js.context.callMethod('doubleValue', ["Foo"]), equals("FooFoo")); 106 expect(doubleValue("Foo"), equals("FooFoo"));
96 // Point is not a primitive type so passing it to a different isolate 107 // Point is not a primitive type so passing it to a different isolate
97 // using js interop results in a JsObject rather than a Point. A 108 // using js interop results in a JsObject rather than a Point. A
98 // NoSuchMethodError is thrown in the other Dart isolate but once the 109 // NoSuchMethodError is thrown in the other Dart isolate but once the
99 // error gets to this isolate it shows up as just an Unhandled Exception. 110 // error gets to this isolate it shows up as just an Unhandled Exception.
100 expect(() { 111 expect(() {
101 try { 112 try {
102 js.context.callMethod('doubleValue', [new Point(2, 4)]); 113 doubleValue(new Point(2, 4));
103 } catch (e) { 114 } catch (e) {
104 throw new Exception(e.toString()); 115 throw new Exception(e.toString());
105 } 116 }
106 }, 117 },
107 throwsException); 118 throwsException);
108 }); 119 });
109 }); 120 }));
110 } 121 }
111 </script> 122 </script>
112 </body> 123 </body>
113 </html> 124 </html>
OLDNEW
« no previous file with comments | « LayoutTests/dart/multiscript-js-interop.dart ('k') | LayoutTests/dart/multiscript-js-interop-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698