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

Unified Diff: test/codegen/lib/html/isolates_test.dart

Issue 1930043002: Add all dart:html tests from the sdk to test/codegen. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: ptal Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/codegen/lib/html/interactive_test.dart ('k') | test/codegen/lib/html/js_function_getter_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/codegen/lib/html/isolates_test.dart
diff --git a/test/codegen/lib/html/isolates_test.dart b/test/codegen/lib/html/isolates_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9c07ed0eb25472461e4de99d9d4b260ae146ab2c
--- /dev/null
+++ b/test/codegen/lib/html/isolates_test.dart
@@ -0,0 +1,65 @@
+library IsolatesTest;
+import 'package:unittest/unittest.dart';
+import 'package:unittest/html_config.dart';
+import 'dart:async';
+import 'dart:html';
+import 'dart:convert';
+import 'dart:isolate' as isolate;
+
+String responseFor(message) => 'response for $message';
+
+void isolateEntry(isolate.SendPort initialReplyTo) {
+ var port = new isolate.ReceivePort();
+ initialReplyTo.send(port.sendPort);
+
+ bool wasThrown = false;
+ try {
+ window.alert('Test');
+ } catch (e) {
+ wasThrown = true;
+ }
+ // If wasn't thrown, do not listen to messages to make test fail.
+ if (!wasThrown) {
+ return;
+ }
+
+ // Check that convert library was loaded to isolate.
+ JSON.encode([1, 2, 3]);
+
+ port.listen((message) {
+ var data = message[0];
+ var replyTo = message[1];
+ replyTo.send(responseFor(data));
+ });
+}
+
+Future sendReceive(isolate.SendPort port, msg) {
+ var response = new isolate.ReceivePort();
+ port.send([msg, response.sendPort]);
+ return response.first;
+}
+
+main() {
+ useHtmlConfiguration();
+ test('IsolateSpawn', () {
+ var port = new isolate.ReceivePort();
+ isolate.Isolate.spawn(isolateEntry, port.sendPort);
+ port.close();
+ });
+ test('NonDOMIsolates', () {
+ var callback = expectAsync((){});
+ var response = new isolate.ReceivePort();
+ var remote = isolate.Isolate.spawn(isolateEntry, response.sendPort);
+ response.first.then((port) {
+ final msg1 = 'foo';
+ final msg2 = 'bar';
+ sendReceive(port, msg1).then((response) {
+ expect(response, equals(responseFor(msg1)));
+ sendReceive(port, msg2).then((response) {
+ expect(response, equals(responseFor(msg2)));
+ callback();
+ });
+ });
+ });
+ });
+}
« no previous file with comments | « test/codegen/lib/html/interactive_test.dart ('k') | test/codegen/lib/html/js_function_getter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698