Index: LayoutTests/dart/Multiscript.html |
diff --git a/LayoutTests/dart/Multiscript.html b/LayoutTests/dart/Multiscript.html |
index 967d842bf4c47c029023bcf23065e35fc2631387..c4df14cbbc6f0b6f9470818b0a58626b23961143 100644 |
--- a/LayoutTests/dart/Multiscript.html |
+++ b/LayoutTests/dart/Multiscript.html |
@@ -1,32 +1,61 @@ |
<html> |
<head> |
<script type="application/javascript" src="../../../../dart/pkg/unittest/lib/test_controller.js"></script> |
+<script type="application/javascript"> |
+var sJs = 0; |
+var callbacks = []; |
+var numCallbacks = 0; |
+// Trivial method to run all 4 callbacks in order once they are all |
+// registered. |
+function registerCallback(index, callback) { |
+ callbacks[index] = callback; |
+ numCallbacks++; |
+ if (numCallbacks == 4) { |
+ for (var i = 0; i < numCallbacks; i++) { |
+ callbacks[i](); |
+ } |
+ } |
+} |
+</script> |
</head> |
<body> |
<script type="application/dart"> |
import 'dart:async'; |
import 'package:unittest/unittest.dart'; |
-import 'package:unittest/html_config.dart'; |
import 'Multiscript.dart'; |
main() { |
- useHtmlConfiguration(true); |
- State.record(0); |
- test('Multiple script tags', () { |
+ State.registerCallback(0, () { |
// FIXME: Rewrite this test to use html-imports. |
- expect(State.s, equals(1)); |
+ print("Running script 0"); |
+ State.update(); |
+ expect(State.sJs, equals(1)); |
+ expect(State.sDart, equals(1)); |
}); |
} |
</script> |
<script type="application/dart"> |
+import 'dart:js' as js; |
+import 'dart:math'; |
import 'package:unittest/unittest.dart'; |
import 'Multiscript.dart'; |
main() { |
- State.record(1); |
- expect(State.s, equals(2)); |
+ State.registerCallback(1, () { |
+ print("Running script 1"); |
+ State.update(); |
+ expect(State.sJs, equals(2)); |
+ expect(State.sDart, equals(1)); |
+ js.context['doubleValue'] = (x) => x*2; |
+ expect(js.context.callMethod('doubleValue', [21]), equals(42)); |
+ expect(js.context.callMethod('doubleValue', ["Foo"]), equals("FooFoo")); |
+ // Point is not a primitive type so passing it to a different isolate is |
+ // not allowed. |
+ expect(js.context.callMethod('doubleValue', [new Point(2, 4)]), |
+ equals(new Point(4, 8))); |
+ }); |
} |
</script> |
@@ -35,18 +64,49 @@ import 'package:unittest/unittest.dart'; |
import 'Multiscript.dart'; |
main() { |
- State.record(2); |
- expect(State.s, equals(3)); |
+ State.registerCallback(2, () { |
+ print("Running script 2"); |
+ State.update(); |
+ expect(State.sJs, equals(3)); |
+ expect(State.sDart, equals(1)); |
+ }); |
} |
</script> |
<script type="application/dart"> |
+import 'dart:js' as js; |
+import 'dart:math'; |
import 'package:unittest/unittest.dart'; |
+import 'package:unittest/html_config.dart'; |
import 'Multiscript.dart'; |
main() { |
- State.record(3); |
- expect(State.s, equals(4)); |
+ State.registerCallback(3, () { |
+ print("Running script 3"); |
+ useHtmlConfiguration(true); |
+ test('Multiple script tags', () { |
+ State.update(); |
+ expect(State.sJs, equals(4)); |
+ expect(State.sDart, equals(1)); |
+ |
+ // doubleValue is from a different Dart isolate but arguments are primitive |
+ // types so it is safe to call. |
+ expect(js.context.callMethod('doubleValue', [21]), equals(42)); |
+ expect(js.context.callMethod('doubleValue', ["Foo"]), equals("FooFoo")); |
+ // Point is not a primitive type so passing it to a different isolate |
+ // using js interop results in a JsObject rather than a Point. A |
+ // NoSuchMethodError is thrown in the other Dart isolate but once the |
+ // error gets to this isolate it shows up as just an Unhandled Exception. |
+ expect(() { |
+ try { |
+ js.context.callMethod('doubleValue', [new Point(2, 4)]); |
+ } catch (e) { |
+ throw new Exception(e.toString()); |
+ } |
+ }, |
+ throwsException); |
+ }); |
+ }); |
} |
</script> |
</body> |