Skip to content

Commit

Permalink
Bug 1558184 [wpt PR 17246] - service worker: Drop postMessage() to re…
Browse files Browse the repository at this point in the history
…dundant workers silently., a=testonly

Automatic update from web-platform-tests
service worker: Drop postMessage() to redundant workers silently.

Update the WPT and fix behavior. Per spec change at
w3c/ServiceWorker#1146.

Bug: 972461
Change-Id: Id4bac3fbe1996382952e54d46cb405de9eb951b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1650685
Reviewed-by: Hayato Ito <hayato@chromium.org>
Reviewed-by: Kenichi Ishibashi <bashi@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#667523}

--

wp5At-commits: 0ea1346335e30ab897ee5124aeeafcae663b5f49
wpt-pr: 17246
  • Loading branch information
mfalken authored and jgraham committed Jun 19, 2019
1 parent 8eef046 commit b5d429b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@
.then(e => {
assert_equals(e.data, 'quit');
return registration.unregister(scope);
})
.then(() => { return wait_for_state(t, worker, 'redundant'); })
.then(() => {
assert_equals(worker.state, 'redundant');
assert_throws(
{name:'InvalidStateError'},
function() { worker.postMessage(''); },
'Calling postMessage on a redundant ServiceWorker should ' +
'throw InvalidStateError.');
});
}, 'postMessage to a ServiceWorker (and back via MessagePort)');

Expand Down Expand Up @@ -178,4 +169,34 @@
});
}, 'postMessage with dictionary a transferable ArrayBuffer between ServiceWorker and Client');

promise_test(async t => {
const firstScript = 'resources/postmessage-echo-worker.js?one';
const secondScript = 'resources/postmessage-echo-worker.js?two';
const scope = 'resources/';

const registration = await service_worker_unregister_and_register(t, firstScript, scope);
t.add_cleanup(() => registration.unregister());
const firstWorker = registration.installing;

const messagePromise = new Promise(resolve => {
navigator.serviceWorker.addEventListener('message', (event) => {
resolve(event.data);
}, {once: true});
});

await wait_for_state(t, firstWorker, 'activated');
await navigator.serviceWorker.register(secondScript, {scope});
const secondWorker = registration.installing;
await wait_for_state(t, firstWorker, 'redundant');

// postMessage() to a redundant worker should be dropped silently.
// Historically, this threw an exception.
firstWorker.postMessage('firstWorker');

// To test somewhat that it was not received, send a message to another
// worker and check that we get a reply for that one.
secondWorker.postMessage('secondWorker');
const data = await messagePromise;
assert_equals(data, 'secondWorker');
}, 'postMessage to a redundant worker');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
self.addEventListener('message', event => {
event.source.postMessage(event.data);
});

0 comments on commit b5d429b

Please sign in to comment.