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

Unified Diff: LayoutTests/http/tests/serviceworker/resources/postmessage-cross-process-helper.html

Issue 730543005: Add a test for cross process service worker messaging. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: address most comments Created 6 years, 1 month 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
Index: LayoutTests/http/tests/serviceworker/resources/postmessage-cross-process-helper.html
diff --git a/LayoutTests/http/tests/serviceworker/resources/postmessage-cross-process-helper.html b/LayoutTests/http/tests/serviceworker/resources/postmessage-cross-process-helper.html
new file mode 100644
index 0000000000000000000000000000000000000000..b4cff8054d59fee417ffb4c8d17092b4d9e145a7
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/resources/postmessage-cross-process-helper.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<script src="test-helpers.js"></script>
+<script>
+if (window.testRunner) {
+ // waitUntilDone here is necesary to make sure content_shell doesn't exist as
falken 2014/11/20 02:29:13 some typos here: "necesary"->"necessary", "exist"-
Marijn Kruisselbrink 2014/11/20 20:41:13 Done.
+ // soon as this file is loaded.
+ testRunner.waitUntilDone();
+}
+
+var worker;
+
+navigator.serviceWorker.getRegistration('simple.html')
+ .then(function(registration) {
+ return get_newest_worker(registration);
falken 2014/11/20 02:29:12 Since we open this file after the worker activated
Marijn Kruisselbrink 2014/11/20 20:41:12 Done.
+ })
+ .then(function(sw) {
+ worker = sw;
+ var messageChannel = new MessageChannel();
+ messageChannel.port1.onmessage = onMessage;
+ sw.postMessage({port: messageChannel.port2}, [messageChannel.port2]);
+ messageChannel.port1.postMessage({value: 1});
+ messageChannel.port1.postMessage({value: 2});
+ messageChannel.port1.postMessage({done: true});
+ });
+
+var result = [];
+
+function onMessage(e) {
falken 2014/11/20 02:29:13 on_message
Marijn Kruisselbrink 2014/11/20 20:41:13 Done.
+ var message = e.data;
+ if (message === 'quit') {
+ worker.postMessage({done: result});
+ } else {
+ result.push(message);
+ }
+};
falken 2014/11/20 02:29:12 no semi-colon needed here
Marijn Kruisselbrink 2014/11/20 20:41:13 Done.
+</script>

Powered by Google App Engine
This is Rietveld 408576698