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

Unified Diff: LayoutTests/http/tests/serviceworker/postmessage-cross-process.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: 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/postmessage-cross-process.html
diff --git a/LayoutTests/http/tests/serviceworker/postmessage-cross-process.html b/LayoutTests/http/tests/serviceworker/postmessage-cross-process.html
new file mode 100644
index 0000000000000000000000000000000000000000..13b28f72b18339120be4f842b968eb14565b0287
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/postmessage-cross-process.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<title>Service Worker: postMessage across processes</title>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.js"></script>
+<script>
+if (window.testRunner) {
jsbell 2014/11/18 00:24:14 Since this is validating chrome-specific behavior
Marijn Kruisselbrink 2014/11/18 01:16:13 Yeah, I guess this is kind of on the edge between
Marijn Kruisselbrink 2014/11/20 20:41:12 And I've convinced myself that even though the tes
+ testRunner.setCanOpenWindows();
+}
+
+async_test(function(t) {
+ var scope = 'resources/simple.html';
+ var registration;
+ service_worker_unregister_and_register(
+ t, 'resources/postmessage-cross-process-worker.js', scope)
+ .then(function(r) {
+ registration = r;
+ return wait_for_activated(t, registration);
+ })
+ .then(function() {
+ return get_newest_worker(registration);
+ })
+ .then(function(worker) {
+ var a = document.createElement('a');
jsbell 2014/11/18 00:24:14 Maybe factor this out into a helper function?
Marijn Kruisselbrink 2014/11/18 01:16:13 Done.
+ a.href = 'resources/postmessage-cross-process-helper.html';
+ a.setAttribute('rel', 'noreferrer');
jsbell 2014/11/18 00:24:14 I assume this is the magic that effectively forces
Marijn Kruisselbrink 2014/11/18 01:16:13 Yes.
+ a.target = '_blank';
+ a.click();
+
+ var messageChannel = new MessageChannel();
+ messageChannel.port1.onmessage = t.step_func(onMessage);
+ worker.postMessage({resultport: messageChannel.port2}, [messageChannel.port2]);
jsbell 2014/11/18 00:24:14 wrap at 80 columns
Marijn Kruisselbrink 2014/11/18 01:16:13 Done.
+ })
+ .catch(unreached_rejection(t));
+
+ var expected = [
+ 'Acking value: 1',
+ 'Acking value: 2',
+ ];
+
+ function onMessage(e) {
+ var result = e.data;
+ assert_array_equals(result, expected,
+ 'Worker should post back expected values.');
jsbell 2014/11/18 00:24:14 Can you explain more than the assertion already do
Marijn Kruisselbrink 2014/11/18 01:16:13 Done.
+ t.done();
+ }
+ }, 'postMessage MessagePorts from client to SW in a different process');
+</script>

Powered by Google App Engine
This is Rietveld 408576698