OLD | NEW |
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"> |
| 5 var sJs = 0; |
| 6 var callbacks = []; |
| 7 var numCallbacks = 0; |
| 8 // Trivial method to run all 4 callbacks in order once they are all |
| 9 // registered. |
| 10 function registerCallback(index, callback) { |
| 11 callbacks[index] = callback; |
| 12 numCallbacks++; |
| 13 if (numCallbacks == 4) { |
| 14 for (var i = 0; i < numCallbacks; i++) { |
| 15 callbacks[i](); |
| 16 } |
| 17 } |
| 18 } |
| 19 </script> |
4 </head> | 20 </head> |
5 <body> | 21 <body> |
6 | 22 |
7 <script type="application/dart"> | 23 <script type="application/dart"> |
8 import 'dart:async'; | 24 import 'dart:async'; |
9 import 'package:unittest/unittest.dart'; | 25 import 'package:unittest/unittest.dart'; |
10 import 'package:unittest/html_config.dart'; | |
11 import 'Multiscript.dart'; | 26 import 'Multiscript.dart'; |
12 | 27 |
13 main() { | 28 main() { |
14 useHtmlConfiguration(true); | 29 State.registerCallback(0, () { |
15 State.record(0); | |
16 test('Multiple script tags', () { | |
17 // FIXME: Rewrite this test to use html-imports. | 30 // FIXME: Rewrite this test to use html-imports. |
18 expect(State.s, equals(1)); | 31 print("Running script 0"); |
| 32 State.update(); |
| 33 expect(State.sJs, equals(1)); |
| 34 expect(State.sDart, equals(1)); |
19 }); | 35 }); |
20 } | 36 } |
21 </script> | 37 </script> |
22 | 38 |
23 <script type="application/dart"> | 39 <script type="application/dart"> |
| 40 import 'dart:js' as js; |
| 41 import 'dart:math'; |
24 import 'package:unittest/unittest.dart'; | 42 import 'package:unittest/unittest.dart'; |
25 import 'Multiscript.dart'; | 43 import 'Multiscript.dart'; |
26 | 44 |
27 main() { | 45 main() { |
28 State.record(1); | 46 State.registerCallback(1, () { |
29 expect(State.s, equals(2)); | 47 print("Running script 1"); |
| 48 State.update(); |
| 49 expect(State.sJs, equals(2)); |
| 50 expect(State.sDart, equals(1)); |
| 51 js.context['doubleValue'] = (x) => x*2; |
| 52 expect(js.context.callMethod('doubleValue', [21]), equals(42)); |
| 53 expect(js.context.callMethod('doubleValue', ["Foo"]), equals("FooFoo")); |
| 54 // Point is not a primitive type so passing it to a different isolate is |
| 55 // not allowed. |
| 56 expect(js.context.callMethod('doubleValue', [new Point(2, 4)]), |
| 57 equals(new Point(4, 8))); |
| 58 }); |
30 } | 59 } |
31 </script> | 60 </script> |
32 | 61 |
33 <script type="application/dart"> | 62 <script type="application/dart"> |
34 import 'package:unittest/unittest.dart'; | 63 import 'package:unittest/unittest.dart'; |
35 import 'Multiscript.dart'; | 64 import 'Multiscript.dart'; |
36 | 65 |
37 main() { | 66 main() { |
38 State.record(2); | 67 State.registerCallback(2, () { |
39 expect(State.s, equals(3)); | 68 print("Running script 2"); |
| 69 State.update(); |
| 70 expect(State.sJs, equals(3)); |
| 71 expect(State.sDart, equals(1)); |
| 72 }); |
40 } | 73 } |
41 </script> | 74 </script> |
42 | 75 |
43 <script type="application/dart"> | 76 <script type="application/dart"> |
| 77 import 'dart:js' as js; |
| 78 import 'dart:math'; |
44 import 'package:unittest/unittest.dart'; | 79 import 'package:unittest/unittest.dart'; |
| 80 import 'package:unittest/html_config.dart'; |
45 import 'Multiscript.dart'; | 81 import 'Multiscript.dart'; |
46 | 82 |
47 main() { | 83 main() { |
48 State.record(3); | 84 State.registerCallback(3, () { |
49 expect(State.s, equals(4)); | 85 print("Running script 3"); |
| 86 useHtmlConfiguration(true); |
| 87 test('Multiple script tags', () { |
| 88 State.update(); |
| 89 expect(State.sJs, equals(4)); |
| 90 expect(State.sDart, equals(1)); |
| 91 |
| 92 // doubleValue is from a different Dart isolate but arguments are primitiv
e |
| 93 // types so it is safe to call. |
| 94 expect(js.context.callMethod('doubleValue', [21]), equals(42)); |
| 95 expect(js.context.callMethod('doubleValue', ["Foo"]), equals("FooFoo")); |
| 96 // 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 |
| 98 // 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. |
| 100 expect(() { |
| 101 try { |
| 102 js.context.callMethod('doubleValue', [new Point(2, 4)]); |
| 103 } catch (e) { |
| 104 throw new Exception(e.toString()); |
| 105 } |
| 106 }, |
| 107 throwsException); |
| 108 }); |
| 109 }); |
50 } | 110 } |
51 </script> | 111 </script> |
52 </body> | 112 </body> |
53 </html> | 113 </html> |
OLD | NEW |