Commit 07911797 authored by Andrey Kosyakov's avatar Andrey Kosyakov Committed by Commit Bot

DevTools: fix ServiceWorker.deliverPushMessage

Originally regressed by
https://chromium-review.googlesource.com/c/chromium/src/+/876657

Bug: 878524
Change-Id: I3526eea2063a795b6f9049008cc564ca65c1ba04
Reviewed-on: https://chromium-review.googlesource.com/1255606Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595653}
parent bce553b6
...@@ -175,6 +175,7 @@ void ServiceWorkerHandler::SetRenderer(int process_host_id, ...@@ -175,6 +175,7 @@ void ServiceWorkerHandler::SetRenderer(int process_host_id,
storage_partition_ = storage_partition_ =
static_cast<StoragePartitionImpl*>(process_host->GetStoragePartition()); static_cast<StoragePartitionImpl*>(process_host->GetStoragePartition());
DCHECK(storage_partition_); DCHECK(storage_partition_);
browser_context_ = process_host->GetBrowserContext();
context_ = static_cast<ServiceWorkerContextWrapper*>( context_ = static_cast<ServiceWorkerContextWrapper*>(
storage_partition_->GetServiceWorkerContext()); storage_partition_->GetServiceWorkerContext());
} }
......
Tests delivery of a push message to the service worker.
Got message: push message
(async function(testRunner) {
var {page, session, dp} = await testRunner.startURL(
'resources/push-message-service-worker.html',
`Tests delivery of a push message to the service worker.`);
async function waitForServiceWorkerActivation() {
let versions;
do {
const result = await dp.ServiceWorker.onceWorkerVersionUpdated();
versions = result.params.versions;
} while (!versions.length || versions[0].status !== "activated");
return versions[0].registrationId;
}
var registrationIdPromise = waitForServiceWorkerActivation();
await dp.Runtime.enable();
await dp.ServiceWorker.enable();
const registrationId = await registrationIdPromise;
dp.ServiceWorker.deliverPushMessage({origin: 'http://127.0.0.1:8000', registrationId: registrationId, data: 'push message'});
const message = await session.evaluateAsync('window.__messagePromise');
testRunner.log(`Got message: ${message}`);
testRunner.completeTest();
});
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>Service worker for a push message test</title>
<script>
function installSW() {
navigator.serviceWorker.register('push-message-service-worker.js');
}
window.__messagePromise = new Promise(fulfill =>
navigator.serviceWorker.onmessage = e => fulfill(e.data));
</script>
</head>
<body onload="installSW()"></body>
</html>
self.addEventListener('push', async function (event) {
const clients = await self.clients.matchAll({includeUncontrolled: true});
for (const c of clients)
c.postMessage(event.data.text());
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment