Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/resources/update-worker.php

Issue 1332303002: Make registration.update() no longer force bypassing the HTTP cache (1/2) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove a trailing whitespace. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <?php 1 <?php
2 // Force the browser to cache this script. update() should always bypass this 2 if(!isset($_COOKIE['mode']))
3 // cache and fetch a new version. 3 $mode = 'no-cache'; // Set mode to 'no-cache' for initial register().
4 header('Cache-Control: max-age=86400'); 4 else
5 $mode = $_COOKIE['mode'];
5 6
7 if ($mode == 'no-cache') {
8 // Set max-age to 0 so the next update will go to the network.
9 // Set cookie value to 'cache' so the next fetch will work in 'cache' mode.
10 header('Cache-Control: max-age=0');
11 setcookie('mode', 'cache');
12 } else if ($mode == 'cache') {
13 // Set max-age to non-zero value so the next update will be served from cache.
14 // Unset cookie value.
15 header('Cache-Control: max-age=3600');
16 unset($_COOKIE['mode']);
17 setcookie('mode', '', time() - 3600);
18 }
6 // Return a different script for each access. 19 // Return a different script for each access.
7 header('Content-Type:application/javascript'); 20 header('Content-Type:application/javascript');
8 echo '// ' . microtime(); 21 echo '// ' . microtime();
9 ?> 22 ?>
10 23
11 importScripts('../../resources/test-helpers.js'); 24 importScripts('../../resources/test-helpers.js');
12 importScripts('../../resources/worker-testharness.js'); 25 importScripts('../../resources/worker-testharness.js');
13 26
14 var events_seen = []; 27 var events_seen = [];
falken 2015/10/01 14:58:03 BTW a lot of our tests do this but ideally we shou
15 28
16 self.registration.addEventListener('updatefound', function() { 29 self.registration.addEventListener('updatefound', function() {
17 events_seen.push('updatefound'); 30 events_seen.push('updatefound');
18 }); 31 });
19 32
20 self.addEventListener('activate', function(e) { 33 self.addEventListener('activate', function(e) {
21 events_seen.push('activate'); 34 events_seen.push('activate');
22 }); 35 });
23 36
24 self.addEventListener('fetch', function(e) { 37 self.addEventListener('fetch', function(e) {
25 events_seen.push('fetch'); 38 events_seen.push('fetch');
26 e.respondWith(new Response(events_seen)); 39 e.respondWith(new Response(events_seen));
40 events_seen = []; // Init events_seen for the next update.
27 }); 41 });
28 42
29 self.addEventListener('message', function(e) { 43 self.addEventListener('message', function(e) {
30 events_seen.push('message'); 44 events_seen.push('message');
31 self.registration.update(); 45 self.registration.update()
46 .then(function() {
47 if (self.registration.installing) // A new version found.
48 events_seen.push('new-version');
49 else // The same version served.
50 events_seen.push('cached-version');
51
52 self.clients.matchAll().then(function(clients) {
53 clients.forEach(function(c) {
54 if (c.url == e.data) {
55 c.postMessage('update resolved');
56 }
57 });
58 });
59 });
32 }); 60 });
33 61
34 // update() during the script evaluation should be ignored. 62 // update() during the script evaluation should be ignored.
35 self.registration.update(); 63 self.registration.update();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698