From fd2bd88e540ee42ea2fa1f597416dd2ccde6c80d Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Sat, 8 Apr 2017 09:36:14 +0100 Subject: [PATCH 1/9] Tests for updateViaCache (previously useCache) --- .../registration-updateviacache.https.html | 150 ++++++++++++++++++ .../update-max-aged-worker-imported-script.py | 12 ++ .../resources/update-max-aged-worker.py | 28 ++++ 3 files changed, 190 insertions(+) create mode 100644 service-workers/service-worker/registration-updateviacache.https.html create mode 100644 service-workers/service-worker/resources/update-max-aged-worker-imported-script.py create mode 100644 service-workers/service-worker/resources/update-max-aged-worker.py 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/resources/update-max-aged-worker-imported-script.py b/service-workers/service-worker/resources/update-max-aged-worker-imported-script.py new file mode 100644 index 00000000000000..3f7f88bafaac61 --- /dev/null +++ b/service-workers/service-worker/resources/update-max-aged-worker-imported-script.py @@ -0,0 +1,12 @@ +import time + +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()))] + + body = ''' + 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 new file mode 100644 index 00000000000000..1a285fe1eb749b --- /dev/null +++ b/service-workers/service-worker/resources/update-max-aged-worker.py @@ -0,0 +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 = request.GET['test']; + + body = ''' + const mainTime = {time}; + const testName = {test}; + importScripts('update-max-aged-worker-imported-script.py'); + + addEventListener('message', event => {{ + event.source.postMessage({{ + mainTime, + importTime, + test: {test} + }}); + }}); + '''.format( + time=time.time(), + test=json.dumps(test) + ) + + return headers, body From 512ae2afe8b244841816efaa0a1255aaa8b21ca2 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Sat, 8 Apr 2017 13:17:38 +0100 Subject: [PATCH 2/9] 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 60db228e4c852fac8cc2408ec141548b347891f4 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Mon, 10 Apr 2017 16:37:16 +0100 Subject: [PATCH 3/9] 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); From ad8943ab4e46d13cc8a6beb3da52bb3209a86a81 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Mon, 5 Jun 2017 15:06:31 +0100 Subject: [PATCH 4/9] =?UTF-8?q?=E2=80=9Cnever=E2=80=9D=20to=20=E2=80=9Cnon?= =?UTF-8?q?e=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service-worker/registration-updateviacache.https.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/service-workers/service-worker/registration-updateviacache.https.html b/service-workers/service-worker/registration-updateviacache.https.html index 7cfe06ed568f1f..fef44a42d056a9 100644 --- a/service-workers/service-worker/registration-updateviacache.https.html +++ b/service-workers/service-worker/registration-updateviacache.https.html @@ -5,7 +5,7 @@