Title: [224710] trunk
Revision
224710
Author
cdu...@apple.com
Date
2017-11-10 16:00:01 -0800 (Fri, 10 Nov 2017)

Log Message

[Service Workers] Implement better support for "Clear Registration" algorithm
https://bugs.webkit.org/show_bug.cgi?id=179441

Reviewed by Brady Eidson.

LayoutTests/imported/w3c:

Rebaseline WPT test due to behavior change. Unfortunately, the check goes from PASS to FAIL.
The reason is that we do not implement "Try Clear Registration" algorithm, only the "Clear
Registration" one. The test expects that a registration object does not get cleared after
unregistration because it is "in use". However, because we do not yet support checking if
a registration is "in use" in try clear, we proceed to clearing the registration and marking
its service workers as redundant.

Previously, the test was passing because even though we were clearing the registration, we
did not mark its service workers as redundant yet. As a result, we would still report that
the registration as having an active worker with "activated" state and the test would think
we did not clear the registration, even though we did.

* web-platform-tests/service-workers/service-worker/getregistrations.https-expected.txt:

Source/WebCore:

Implement better support for "Clear Registration" algorithm as per:
- https://w3c.github.io/ServiceWorker/#clear-registration-algorithm

In particular, we now properly clear the service workers on the ServiceWorkerRegistration
object and we properly update its service workers' state to "redundant".

Test: http/tests/workers/service/registration-clear-redundant-worker.html

* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::clearRegistration):

LayoutTests:

Add layout test coverage.

* http/tests/workers/service/registration-clear-redundant-worker-expected.txt: Added.
* http/tests/workers/service/registration-clear-redundant-worker.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (224709 => 224710)


--- trunk/LayoutTests/ChangeLog	2017-11-10 23:44:32 UTC (rev 224709)
+++ trunk/LayoutTests/ChangeLog	2017-11-11 00:00:01 UTC (rev 224710)
@@ -1,3 +1,15 @@
+2017-11-10  Chris Dumez  <cdu...@apple.com>
+
+        [Service Workers] Implement better support for "Clear Registration" algorithm
+        https://bugs.webkit.org/show_bug.cgi?id=179441
+
+        Reviewed by Brady Eidson.
+
+        Add layout test coverage.
+
+        * http/tests/workers/service/registration-clear-redundant-worker-expected.txt: Added.
+        * http/tests/workers/service/registration-clear-redundant-worker.html: Added.
+
 2017-11-10  Ryan Haddad  <ryanhad...@apple.com>
 
         Unreviewed, rolling out r224705.

Added: trunk/LayoutTests/http/tests/workers/service/registration-clear-redundant-worker-expected.txt (0 => 224710)


--- trunk/LayoutTests/http/tests/workers/service/registration-clear-redundant-worker-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/registration-clear-redundant-worker-expected.txt	2017-11-11 00:00:01 UTC (rev 224710)
@@ -0,0 +1,6 @@
+PASS: Unregistration was successful
+PASS: Worker became redundant after unregistering
+PASS: registration.installing is null
+PASS: registration.waiting is null
+PASS: registration.active is null
+

Added: trunk/LayoutTests/http/tests/workers/service/registration-clear-redundant-worker.html (0 => 224710)


--- trunk/LayoutTests/http/tests/workers/service/registration-clear-redundant-worker.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/registration-clear-redundant-worker.html	2017-11-11 00:00:01 UTC (rev 224710)
@@ -0,0 +1,42 @@
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+navigator.serviceWorker.register("resources/resources/empty-worker.js", { }).then(function(registration) {
+    waitForState(registration.installing, "activated").then(function() {
+        let worker = registration.active;
+        registration.unregister().then(function (success) {
+            if (success)
+                log("PASS: Unregistration was successful");
+            else
+                log("FAIL: Unregistration failed");
+        }).then(function() {
+            waitForState(worker, "redundant").then(function() {
+                log("PASS: Worker became redundant after unregistering");
+                setTimeout(function() {
+                    if (registration.installing)
+                        log("FAIL: registration.installing should be null");
+                    else
+                        log("PASS: registration.installing is null");
+
+                    if (registration.waiting)
+                        log("FAIL: registration.waiting should be null");
+                    else
+                        log("PASS: registration.waiting is null");
+
+                    if (registration.active)
+                        log("FAIL: registration.active should be null");
+                    else
+                        log("PASS: registration.active is null");
+
+                    finishSWTest();
+                }, 0);
+            });
+        });
+    });
+});
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (224709 => 224710)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-10 23:44:32 UTC (rev 224709)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-11 00:00:01 UTC (rev 224710)
@@ -1,3 +1,24 @@
+2017-11-10  Chris Dumez  <cdu...@apple.com>
+
+        [Service Workers] Implement better support for "Clear Registration" algorithm
+        https://bugs.webkit.org/show_bug.cgi?id=179441
+
+        Reviewed by Brady Eidson.
+
+        Rebaseline WPT test due to behavior change. Unfortunately, the check goes from PASS to FAIL.
+        The reason is that we do not implement "Try Clear Registration" algorithm, only the "Clear
+        Registration" one. The test expects that a registration object does not get cleared after
+        unregistration because it is "in use". However, because we do not yet support checking if
+        a registration is "in use" in try clear, we proceed to clearing the registration and marking
+        its service workers as redundant.
+
+        Previously, the test was passing because even though we were clearing the registration, we
+        did not mark its service workers as redundant yet. As a result, we would still report that
+        the registration as having an active worker with "activated" state and the test would think
+        we did not clear the registration, even though we did.
+
+        * web-platform-tests/service-workers/service-worker/getregistrations.https-expected.txt:
+
 2017-11-10  Ms2ger  <ms2...@igalia.com>
 
         Allow XHR to override the User-Agent header.

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistrations.https-expected.txt (224709 => 224710)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistrations.https-expected.txt	2017-11-10 23:44:32 UTC (rev 224709)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistrations.https-expected.txt	2017-11-11 00:00:01 UTC (rev 224710)
@@ -3,6 +3,6 @@
 FAIL Register then getRegistrations assert_array_equals: getRegistrations should resolve with array of registrations. lengths differ, expected 1 got 0
 FAIL Register multiple times then getRegistrations assert_array_equals: getRegistrations should resolve with array of registrations. lengths differ, expected 2 got 0
 PASS Register then Unregister then getRegistrations 
-PASS Register then Unregister with controlled frame then getRegistrations 
+FAIL Register then Unregister with controlled frame then getRegistrations assert_equals: expected "activated" but got "redundant"
 FAIL getRegistrations promise resolves only with same origin registrations. assert_array_equals: getRegistrations should only return same origin registrations. lengths differ, expected 1 got 0
 

Modified: trunk/Source/WebCore/ChangeLog (224709 => 224710)


--- trunk/Source/WebCore/ChangeLog	2017-11-10 23:44:32 UTC (rev 224709)
+++ trunk/Source/WebCore/ChangeLog	2017-11-11 00:00:01 UTC (rev 224710)
@@ -1,3 +1,21 @@
+2017-11-10  Chris Dumez  <cdu...@apple.com>
+
+        [Service Workers] Implement better support for "Clear Registration" algorithm
+        https://bugs.webkit.org/show_bug.cgi?id=179441
+
+        Reviewed by Brady Eidson.
+
+        Implement better support for "Clear Registration" algorithm as per:
+        - https://w3c.github.io/ServiceWorker/#clear-registration-algorithm
+
+        In particular, we now properly clear the service workers on the ServiceWorkerRegistration
+        object and we properly update its service workers' state to "redundant".
+
+        Test: http/tests/workers/service/registration-clear-redundant-worker.html
+
+        * workers/service/server/SWServerJobQueue.cpp:
+        (WebCore::SWServerJobQueue::clearRegistration):
+
 2017-11-10  Ryan Haddad  <ryanhad...@apple.com>
 
         Unreviewed, rolling out r224705.

Modified: trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp (224709 => 224710)


--- trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp	2017-11-10 23:44:32 UTC (rev 224709)
+++ trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp	2017-11-11 00:00:01 UTC (rev 224710)
@@ -333,9 +333,24 @@
 }
 
 // https://w3c.github.io/ServiceWorker/#clear-registration
+static void clearRegistrationWorker(SWServerRegistration& registration, SWServerWorker* worker, ServiceWorkerRegistrationState state)
+{
+    if (!worker)
+        return;
+
+    worker->terminate();
+    registration.updateWorkerState(*worker, ServiceWorkerState::Redundant);
+    registration.updateRegistrationState(state, nullptr);
+}
+
+// https://w3c.github.io/ServiceWorker/#clear-registration
 void SWServerJobQueue::clearRegistration(SWServerRegistration& registration)
 {
-    // FIXME: Update / terminate the registration's service workers.
+    clearRegistrationWorker(registration, registration.installingWorker(), ServiceWorkerRegistrationState::Installing);
+    clearRegistrationWorker(registration, registration.waitingWorker(), ServiceWorkerRegistrationState::Waiting);
+    clearRegistrationWorker(registration, registration.activeWorker(), ServiceWorkerRegistrationState::Active);
+
+    // Remove scope to registration map[scopeString].
     m_server.removeRegistration(registration.key());
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to