summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/sw_storage_not_allow.js
blob: 2eb24033094012e0e9d037a22178d6427eef145a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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());
});