forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clear-Site-Data: clients uncontrolled by service workers after storag…
…e directive Adds a failing test, asserting that pages actively controlled by a service worker become uncontrolled after the Clear-Site-Data storage directive. We agreed on this behavior in a spec issue and confirmed the need for this test at the TPAC Service Workers F2F. w3c/ServiceWorker#614 F2F notes: https://docs.google.com/document/d/1_Qfw5m3BJEaL1xIzTJd41HXjgJ9gq7mroBDXqSJIzic/edit
- Loading branch information
Showing
4 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Clear-Site-Data + Service Workers Test Page</title> | ||
<script src="/resources/testharness.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
function pollForControllingWorker(cb) { | ||
navigator.serviceWorker.getRegistration().then(function(reg) { | ||
if (navigator.serviceWorker.controller && !reg.waiting && reg.active && reg.active.state === 'activated') { | ||
cb(); | ||
} else { | ||
step_timeout(() => { | ||
pollForControllingWorker(cb); | ||
}, 100); | ||
} | ||
}); | ||
} | ||
|
||
function requestServiceWorkerPage() { | ||
// Make a request to a URL that is only served by the service worker | ||
fetch("sw-page").then(function(result) { | ||
window.top.postMessage({ | ||
subject: "service-worker-page-request", | ||
ok: result.ok | ||
}, "*"); | ||
}); | ||
} | ||
window.addEventListener("message", requestServiceWorkerPage); | ||
|
||
pollForControllingWorker(requestServiceWorkerPage); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
/* This file is intentionally left blank. */ | ||
|
||
self.addEventListener('install', () => { | ||
return self.skipWaiting(); | ||
}); | ||
|
||
self.addEventListener('activate', (e) => { | ||
e.waitUntil(self.clients.claim()); | ||
}); | ||
|
||
self.addEventListener('fetch', (e) => { | ||
const url = new URL(e.request.url); | ||
if (url.pathname.match('sw-page')) { | ||
e.respondWith(new Response('from-service-worker')); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters