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

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: 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/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..a90756b98c8f044bba4a6df9c203eca294e0e39a
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/postmessage-cross-process.html
@@ -0,0 +1,53 @@
+<!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) {
+ testRunner.setCanOpenWindows();
+}
+
+function openUrlInNewWindow(url) {
falken 2014/11/20 02:29:12 In Service Worker test style <http://www.chromium.
Marijn Kruisselbrink 2014/11/20 20:41:12 Done.
Marijn Kruisselbrink 2014/11/20 20:41:12 Done.
+ var a = document.createElement('a');
+ a.href = url;
+ // rel=noreferrer causes chrome to open the link in a new renderer process.
+ a.setAttribute('rel', 'noreferrer');
+ a.target = '_blank';
+ a.click();
+}
+
+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);
falken 2014/11/20 02:29:12 You can just use registration.active directly. No
Marijn Kruisselbrink 2014/11/20 20:41:12 Done.
+ })
+ .then(function(worker) {
+ openUrlInNewWindow('resources/postmessage-cross-process-helper.html');
+ var messageChannel = new MessageChannel();
+ messageChannel.port1.onmessage = t.step_func(onMessage);
+ worker.postMessage({resultport: messageChannel.port2},
+ [messageChannel.port2]);
+ })
+ .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 ack values posted by new window in order.');
+ t.done();
+ }
+ }, 'postMessage MessagePorts from client to SW in a different process');
+</script>

Powered by Google App Engine
This is Rietveld 408576698