From 6605ee7400ab20c23f9a912e83241502e350969e Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Sat, 8 Apr 2017 09:36:14 +0100 Subject: [PATCH 1/3] Tests for updateViaCache (previously useCache) --- .../registration-updateviacache.https.html | 150 ++++++++++++ .../registration-useCache.https.html | 223 ------------------ .../update-max-aged-worker-imported-script.py | 20 +- .../resources/update-max-aged-worker.py | 32 +-- 4 files changed, 172 insertions(+), 253 deletions(-) create mode 100644 service-workers/service-worker/registration-updateviacache.https.html delete mode 100644 service-workers/service-worker/registration-useCache.https.html diff --git a/service-workers/service-worker/registration-updateviacache.https.html b/service-workers/service-worker/registration-updateviacache.https.html new file mode 100644 index 00000000000000..f45789be830a56 --- /dev/null +++ b/service-workers/service-worker/registration-updateviacache.https.html @@ -0,0 +1,150 @@ + +Service Worker: Registration-updateViaCache + + + + + diff --git a/service-workers/service-worker/registration-useCache.https.html b/service-workers/service-worker/registration-useCache.https.html deleted file mode 100644 index 1976fa117d6c3c..00000000000000 --- a/service-workers/service-worker/registration-useCache.https.html +++ /dev/null @@ -1,223 +0,0 @@ - -Service Worker: Registration-useCache - - - - - diff --git a/service-workers/service-worker/resources/update-max-aged-worker-imported-script.py b/service-workers/service-worker/resources/update-max-aged-worker-imported-script.py index e166143e2bb2b0..3f7f88bafaac61 100644 --- a/service-workers/service-worker/resources/update-max-aged-worker-imported-script.py +++ b/service-workers/service-worker/resources/update-max-aged-worker-imported-script.py @@ -1,22 +1,12 @@ import time def main(request, response): - headers = [('Cache-Control', 'max-age=86400'), - ('Content-Type', 'application/javascript'), - ('Last-Modified', time.strftime("%a, %d %b %Y %H:%M:%S GMT", - time.gmtime()))] - - - revalidate = request.headers.has_key('if-modified-since'); + headers = [('Content-Type', 'application/javascript'), + ('Cache-Control', 'max-age=86400'), + ('Last-Modified', time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()))] body = ''' - self.addEventListener('message', function(e) { - e.data.port.postMessage({ - from: "imported", - type: "%s", - value: %s - }); - }); - ''' % ('revalidate' if revalidate else 'normal', time.time()) + const importTime = {time}; + '''.format(time=time.time()) return headers, body diff --git a/service-workers/service-worker/resources/update-max-aged-worker.py b/service-workers/service-worker/resources/update-max-aged-worker.py index 6eb7c343a269e3..1a285fe1eb749b 100644 --- a/service-workers/service-worker/resources/update-max-aged-worker.py +++ b/service-workers/service-worker/resources/update-max-aged-worker.py @@ -1,26 +1,28 @@ import time +import json def main(request, response): headers = [('Content-Type', 'application/javascript'), ('Cache-Control', 'max-age=86400'), ('Last-Modified', time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()))] - test = ''; - if 'Test' in request.GET: - test = request.GET['Test']; - - revalidate = request.headers.has_key('if-modified-since'); - + test = request.GET['test']; + body = ''' - importScripts('update-max-aged-worker-imported-script.py?Test=%s'); + const mainTime = {time}; + const testName = {test}; + importScripts('update-max-aged-worker-imported-script.py'); - self.addEventListener('message', function(e) { - e.data.port.postMessage({ - from: "main", - type: "%s", - value: %s - }); - }); - ''' % (test, 'revalidate' if revalidate else 'normal', time.time()) + addEventListener('message', event => {{ + event.source.postMessage({{ + mainTime, + importTime, + test: {test} + }}); + }}); + '''.format( + time=time.time(), + test=json.dumps(test) + ) return headers, body From fa27eab4d7a0ba28552f5e78752eadaf707a61cf Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Sat, 8 Apr 2017 13:17:38 +0100 Subject: [PATCH 2/3] Fixing trailing whitespace --- .../service-worker/registration-updateviacache.https.html | 2 +- .../service-worker/resources/update-max-aged-worker.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/service-workers/service-worker/registration-updateviacache.https.html b/service-workers/service-worker/registration-updateviacache.https.html index f45789be830a56..27842d98406de7 100644 --- a/service-workers/service-worker/registration-updateviacache.https.html +++ b/service-workers/service-worker/registration-updateviacache.https.html @@ -112,7 +112,7 @@ const sw = reg.installing; await waitForActivated(sw); const values = await getScriptTimes(sw, testName); - + opts = {scope}; if (updateViaCache2) opts.updateViaCache = updateViaCache2; diff --git a/service-workers/service-worker/resources/update-max-aged-worker.py b/service-workers/service-worker/resources/update-max-aged-worker.py index 1a285fe1eb749b..a9acf1b6de547c 100644 --- a/service-workers/service-worker/resources/update-max-aged-worker.py +++ b/service-workers/service-worker/resources/update-max-aged-worker.py @@ -7,7 +7,7 @@ def main(request, response): ('Last-Modified', time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()))] test = request.GET['test']; - + body = ''' const mainTime = {time}; const testName = {test}; From eb3f30222d349423fc468be0d3087ff38be6cfad Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Mon, 10 Apr 2017 16:37:16 +0100 Subject: [PATCH 3/3] Was checking .installing on wrong object. --- .../service-worker/registration-updateviacache.https.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/service-workers/service-worker/registration-updateviacache.https.html b/service-workers/service-worker/registration-updateviacache.https.html index 27842d98406de7..7cfe06ed568f1f 100644 --- a/service-workers/service-worker/registration-updateviacache.https.html +++ b/service-workers/service-worker/registration-updateviacache.https.html @@ -74,10 +74,10 @@ await reg.update(); if (updateViaCache == 'all') { - assert_equals(sw.installing, undefined, "No new service worker"); + assert_equals(reg.installing, null, "No new service worker"); } else { - const newWorker = sw.installing; + const newWorker = reg.installing; assert_true(!!newWorker, "New worker installing"); const newValues = await getScriptTimes(newWorker, testName); @@ -121,10 +121,10 @@ // If there's no change, register should be a no-op. // The default value should behave as 'imports'. if ((updateViaCache1 || 'imports') == (updateViaCache2 || 'imports')) { - assert_equals(sw.installing, undefined, "No new service worker"); + assert_equals(reg.installing, null, "No new service worker"); } else { - const newWorker = sw.installing; + const newWorker = reg.installing; assert_true(!!newWorker, "New worker installing"); const newValues = await getScriptTimes(newWorker, testName);