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

Unified Diff: LayoutTests/http/tests/serviceworker/chromium/stashed-ports-after-terminate.html

Issue 1063533002: Initial implementation of stashed message ports, layout tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@stashed-ports
Patch Set: address comments Created 5 years, 7 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
Index: LayoutTests/http/tests/serviceworker/chromium/stashed-ports-after-terminate.html
diff --git a/LayoutTests/http/tests/serviceworker/chromium/stashed-ports-after-terminate.html b/LayoutTests/http/tests/serviceworker/chromium/stashed-ports-after-terminate.html
new file mode 100644
index 0000000000000000000000000000000000000000..633bf282ed9eedb2354506593fd56389202dd6ff
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/chromium/stashed-ports-after-terminate.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<title>
+ Tests stashed message ports when the service worker is killed.
+</title>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="../resources/test-helpers.js"></script>
+<script>
+var worker = 'resources/stashed-ports-echo-worker.js';
+var scope = 'resources/';
+
+// Helper method that waits for a reply on a port, and resolves a promise with
+// the reply.
+function wait_for_reply(test, port) {
+ return new Promise(function(resolve) {
+ var resolved = false;
+ port.onmessage = test.step_func(function(event) {
+ assert_false(resolved);
+ resolved = true;
+ resolve(event.data);
+ });
+ });
+}
+
+test(function(test) {
+ assert_exists(window, 'internals');
+ test.done();
+ }, 'internals.terminateServiceWorker is required for the following tests.');
+
+promise_test(function(test) {
+ var sw;
+ var channel = new MessageChannel();
+ var portName = 'foobarname';
+ return service_worker_unregister_and_register(test, worker, scope + 'basic')
+ .then(function(registration) {
+ sw = registration.installing;
+ sw.postMessage({name: portName, port: channel.port2}, [channel.port2]);
+ channel.port1.postMessage('first ping');
+ return wait_for_reply(test, channel.port1);
+ })
+ .then(test.step_func(function(reply) {
+ assert_equals(reply.data, 'first ping');
+ assert_equals(reply.name, portName);
+ channel.port1.postMessage('ping pong');
+ return wait_for_reply(test, channel.port1);
+ }))
+ .then(test.step_func(function(reply) {
+ assert_equals(reply.data, 'ping pong');
+ assert_equals(reply.name, portName);
+ return internals.terminateServiceWorker(sw);
+ }))
+ .then(function() {
+ channel.port1.postMessage('second ping');
+ return wait_for_reply(test, channel.port1);
+ })
+ .then(test.step_func(function(reply) {
+ assert_equals(reply.data, 'second ping');
+ assert_equals(reply.name, portName);
+ }));
+ }, 'Messages can be send when the service worker has been terminated');
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698