| Index: LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/resources/update-worker.php
|
| diff --git a/LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/resources/update-worker.php b/LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/resources/update-worker.php
|
| index 2486820c26c5f6483270a2d15f6527ec3ee11662..b64198aa978aa0bd893fbb55982732fe0eaee680 100644
|
| --- a/LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/resources/update-worker.php
|
| +++ b/LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/resources/update-worker.php
|
| @@ -1,8 +1,21 @@
|
| <?php
|
| -// Force the browser to cache this script. update() should always bypass this
|
| -// cache and fetch a new version.
|
| -header('Cache-Control: max-age=86400');
|
| -
|
| +if(!isset($_COOKIE['mode']))
|
| + $mode = 'no-cache'; // Set mode to 'no-cache' for initial register().
|
| +else
|
| + $mode = $_COOKIE['mode'];
|
| +
|
| +if ($mode == 'no-cache') {
|
| + // Set max-age to 0 so the next update will go to the network.
|
| + // Set cookie value to 'cache' so the next fetch will work in 'cache' mode.
|
| + header('Cache-Control: max-age=0');
|
| + setcookie('mode', 'cache');
|
| +} else if ($mode == 'cache') {
|
| + // Set max-age to non-zero value so the next update will be served from cache.
|
| + // Unset cookie value.
|
| + header('Cache-Control: max-age=3600');
|
| + unset($_COOKIE['mode']);
|
| + setcookie('mode', '', time() - 3600);
|
| +}
|
| // Return a different script for each access.
|
| header('Content-Type:application/javascript');
|
| echo '// ' . microtime();
|
| @@ -24,11 +37,26 @@ self.addEventListener('activate', function(e) {
|
| self.addEventListener('fetch', function(e) {
|
| events_seen.push('fetch');
|
| e.respondWith(new Response(events_seen));
|
| + events_seen = []; // Init events_seen for the next update.
|
| });
|
|
|
| self.addEventListener('message', function(e) {
|
| events_seen.push('message');
|
| - self.registration.update();
|
| + self.registration.update()
|
| + .then(function() {
|
| + if (self.registration.installing) // A new version found.
|
| + events_seen.push('new-version');
|
| + else // The same version served.
|
| + events_seen.push('cached-version');
|
| +
|
| + self.clients.matchAll().then(function(clients) {
|
| + clients.forEach(function(c) {
|
| + if (c.url == e.data) {
|
| + c.postMessage('update resolved');
|
| + }
|
| + });
|
| + });
|
| + });
|
| });
|
|
|
| // update() during the script evaluation should be ignored.
|
|
|