mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 16:55:40 +00:00
19781c9ae7
Summary: This test first creates a service worker and then an iframe. It expects the iframe's first load to be through the network (and for the page's script to fail to load). Once the page is set up and controlled by the SW, it reloads it (a soft reload) and the script load is intercepted by the service worker and we load a script that calls back into the test. However, there is currently no guarantee that the service worker won't activate before the iframe load and end up controlling the first load of the iframe. With this patch, we delay the service worker's activation until we start loading the iframe, allowing the first load to always be uncontrolled, thereby resolving the race. Reviewers: asuth Reviewed By: asuth Bug #: 1517406 Differential Revision: https://phabricator.services.mozilla.com/D15637 --HG-- extra : rebase_source : ff63b131b1a395289cda85ec4b46daa3022b08b4
32 lines
934 B
JavaScript
32 lines
934 B
JavaScript
var name = 'opaqueInterceptCache';
|
|
|
|
// Cross origin request to ensure that an opaque response is used
|
|
var prefix = 'http://example.com/tests/dom/serviceworkers/test/'
|
|
|
|
var testReady = new Promise(resolve => {
|
|
self.addEventListener('message', (m) => {
|
|
resolve();
|
|
}, { once: true });
|
|
});
|
|
|
|
self.addEventListener('install', function(event) {
|
|
var request = new Request(prefix + 'notify_loaded.js', { mode: 'no-cors' });
|
|
event.waitUntil(
|
|
Promise.all([caches.open(name), fetch(request), testReady]).then(function(results) {
|
|
var cache = results[0];
|
|
var response = results[1];
|
|
return cache.put('./sw_clients/does_not_exist.js', response);
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('fetch', function (event) {
|
|
event.respondWith(
|
|
caches.open(name).then(function(cache) {
|
|
return cache.match(event.request);
|
|
}).then(function(response) {
|
|
return response || fetch(event.request);
|
|
})
|
|
);
|
|
});
|