From cd6f2161d4dcba26acb92e28e47b6f6a99fd89f9 Mon Sep 17 00:00:00 2001 From: xzhan96 Date: Mon, 4 Sep 2017 10:06:05 -0700 Subject: [PATCH] Correct the skip-waiting-installed.html behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to the latest spec, the skipWaiting promise should be resolved after 'activate' event is dispatched. This change is from https://github.com/w3c/ServiceWorker/pull/1065. Tracing through the spec, skipWaiting() enters "Try Activate". "Try Activate" invokes "Activate". "Activate" blocks until the final step: "13. Run the Update Worker State algorithm passing registration’s active worker and activated as the arguments." "Update Worker State" queues a task to set ServiceWorker#state to 'activated'. But in step 10, we have dispatched the 'activate' event. Therefore the order should be: 1. 'activate' event handler runs 2. skipWaiting() promise resolves 3. ServiceWorker#state is set to 'activated' So we correct the test case here and delete all the wrong expected files. BUG=725616 Change-Id: Id0765988c7cdf48f39bb73ccb3fc0cce6ea60949 Reviewed-on: https://chromium-review.googlesource.com/646244 Commit-Queue: Matt Falkenhagen Reviewed-by: Matt Falkenhagen Cr-Commit-Position: refs/heads/master@{#499513} --- .../skip-waiting-installed-worker.js | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/service-workers/service-worker/resources/skip-waiting-installed-worker.js b/service-workers/service-worker/resources/skip-waiting-installed-worker.js index eb63026d5c480ef..b48d502b1360663 100644 --- a/service-workers/service-worker/resources/skip-waiting-installed-worker.js +++ b/service-workers/service-worker/resources/skip-waiting-installed-worker.js @@ -1,19 +1,11 @@ -self.state = 'starting'; - -self.addEventListener('install', function() { - self.state = 'installing'; - }); +var saw_activate_event = false self.addEventListener('activate', function() { - self.state = 'activating'; + saw_activate_event = true; }); self.addEventListener('message', function(event) { var port = event.data.port; - if (self.state !== 'installing') { - port.postMessage('FAIL: Worker should be waiting in installed state'); - return; - } event.waitUntil(self.skipWaiting() .then(function(result) { if (result !== undefined) { @@ -21,9 +13,15 @@ self.addEventListener('message', function(event) { return; } - if (self.state === 'activating') { + if (!saw_activate_event) { + port.postMessage( + 'FAIL: Promise should be resolved after activate event is dispatched'); + return; + } + + if (self.registration.active.state !== 'activating') { port.postMessage( - 'FAIL: Promise should be resolved before worker is activated'); + 'FAITL: Promise should be resolved before ServiceWorker#state is set to activated'); return; }