diff options
Diffstat (limited to 'dom/serviceworkers/test/sw_storage_not_allow.js')
-rw-r--r-- | dom/serviceworkers/test/sw_storage_not_allow.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/dom/serviceworkers/test/sw_storage_not_allow.js b/dom/serviceworkers/test/sw_storage_not_allow.js new file mode 100644 index 0000000000..2eb2403309 --- /dev/null +++ b/dom/serviceworkers/test/sw_storage_not_allow.js @@ -0,0 +1,33 @@ +let clientId; +addEventListener("fetch", function (event) { + event.respondWith( + (async function () { + if (event.request.url.includes("getClients")) { + // Expected to fail since the storage access is not allowed. + try { + await self.clients.matchAll(); + } catch (e) { + // expected failure + } + } else if (event.request.url.includes("getClient-stage1")) { + let clients = await self.clients.matchAll(); + clientId = clients[0].id; + } else if (event.request.url.includes("getClient-stage2")) { + // Expected to fail since the storage access is not allowed. + try { + await self.clients.get(clientId); + } catch (e) { + // expected failure + } + } + + // Pass through the network request once our various Clients API + // promises have completed. + return await fetch(event.request); + })() + ); +}); + +addEventListener("activate", function (event) { + event.waitUntil(clients.claim()); +}); |