Support container.register() / registration.unregister() / inside service workers
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 3 Dec 2017 04:17:12 +0000 (04:17 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 3 Dec 2017 04:17:12 +0000 (04:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180326

Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

Rebaseline WPT test that now passes most checks.

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

Source/WebCore:

Support container.register() / registration.unregister() /  inside service workers.
This is mostly about removing the is<Document>() checks and adding testing given
that most of the work was done in r225455.

Test: http/tests/workers/service/ServiceWorkerGlobalScope_register.html

* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::addRegistration):
* workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::update):
(WebCore::ServiceWorkerRegistration::unregister):

LayoutTests:

* TestExpectations:
Unskip test for registration.unregister() that now passes.

* http/tests/workers/service/ServiceWorkerGlobalScope_register-expected.txt: Added.
* http/tests/workers/service/ServiceWorkerGlobalScope_register.html: Added.
* http/tests/workers/service/resources/ServiceWorkerGlobalScope_register-worker.js: Added.
Add test coverage for container.register().

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225456 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_register-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_register.html [new file with mode: 0644]
LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_register-worker.js [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/workers/service/ServiceWorkerContainer.cpp
Source/WebCore/workers/service/ServiceWorkerRegistration.cpp

index 1a12a69..332451e 100644 (file)
@@ -1,5 +1,20 @@
 2017-12-02  Chris Dumez  <cdumez@apple.com>
 
+        Support container.register() / registration.unregister() /  inside service workers
+        https://bugs.webkit.org/show_bug.cgi?id=180326
+
+        Reviewed by Youenn Fablet.
+
+        * TestExpectations:
+        Unskip test for registration.unregister() that now passes.
+
+        * http/tests/workers/service/ServiceWorkerGlobalScope_register-expected.txt: Added.
+        * http/tests/workers/service/ServiceWorkerGlobalScope_register.html: Added.
+        * http/tests/workers/service/resources/ServiceWorkerGlobalScope_register-worker.js: Added.
+        Add test coverage for container.register().
+
+2017-12-02  Chris Dumez  <cdumez@apple.com>
+
         Support serviceWorkerRegistration.update() inside service workers
         https://bugs.webkit.org/show_bug.cgi?id=180215
 
index 6f9b33c..860a5c8 100644 (file)
@@ -146,7 +146,6 @@ imported/w3c/web-platform-tests/secure-contexts/shared-worker-secure-first.https
 # Skip service worker tests that are timing out.
 imported/w3c/web-platform-tests/fetch/api/abort/general-serviceworker.https.html [ Skip ]
 imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/extendable-message-event.https.html [ Skip ]
-imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https.html [ Skip ]
 imported/w3c/web-platform-tests/service-workers/service-worker/clients-matchall-on-evaluation.https.html [ Skip ]
 imported/w3c/web-platform-tests/service-workers/service-worker/detached-context.https.html [ Skip ]
 imported/w3c/web-platform-tests/service-workers/service-worker/extendable-event-waituntil.https.html [ Skip ]
diff --git a/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_register-expected.txt b/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_register-expected.txt
new file mode 100644 (file)
index 0000000..cfea6f4
--- /dev/null
@@ -0,0 +1,7 @@
+* Tests that serviceWorker.register() inside service workers
+
+PASS: Registration succeeded
+PASS: registration object's scope is valid
+PASS: registration object's updateViaCache is valid
+PASS: service worker is now active
+
diff --git a/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_register.html b/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_register.html
new file mode 100644 (file)
index 0000000..02de146
--- /dev/null
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="resources/sw-test-pre.js"></script>
+<script>
+log("* Tests that serviceWorker.register() inside service workers");
+log("");
+
+navigator.serviceWorker.addEventListener("message", function(event) {
+    if (event.data === "DONE") {
+        finishSWTest();
+        return;
+    }
+    log(event.data);
+});
+
+navigator.serviceWorker.register("resources/ServiceWorkerGlobalScope_register-worker.js", { }).then(function(registration) {
+    registration.installing.postMessage("runTest");
+});
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_register-worker.js b/LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_register-worker.js
new file mode 100644 (file)
index 0000000..7492ae4
--- /dev/null
@@ -0,0 +1,40 @@
+let client = null;
+
+function log(msg)
+{
+    client.postMessage(msg);
+}
+
+async function runTest()
+{
+    try {
+        let r = await navigator.serviceWorker.register("empty-worker.js", { scope: "/test", updateViaCache: "none" });
+        log("PASS: Registration succeeded");
+
+        if (r.scope == "http://127.0.0.1:8000/test")
+            log("PASS: registration object's scope is valid");
+        else
+            log("FAIL: registration object's scope is invalid, got: " + r.scope);
+
+        if (r.updateViaCache == "none")
+            log("PASS: registration object's updateViaCache is valid");
+        else
+            log("FAIL: registration object's updateViaCache is invalid, got: " + r.updateViaCache);
+
+        worker = r.installing;
+        worker.addEventListener("statechange", function() {
+            if (worker.state === "activated") {
+                log("PASS: service worker is now active");
+                log("DONE");
+            }
+        });
+    } catch (e) {
+        log("FAIL: " + e);
+        log("DONE");
+    }
+}
+
+self.addEventListener("message", (event) => {
+    client = event.source;
+    runTest();
+});
index b6059a2..8953c65 100644 (file)
@@ -1,5 +1,16 @@
 2017-12-02  Chris Dumez  <cdumez@apple.com>
 
+        Support container.register() / registration.unregister() /  inside service workers
+        https://bugs.webkit.org/show_bug.cgi?id=180326
+
+        Reviewed by Youenn Fablet.
+
+        Rebaseline WPT test that now passes most checks.
+
+        * web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https-expected.txt:
+
+2017-12-02  Chris Dumez  <cdumez@apple.com>
+
         Support serviceWorkerRegistration.update() inside service workers
         https://bugs.webkit.org/show_bug.cgi?id=180215
 
index aa10763..1b8b748 100644 (file)
@@ -1,8 +1,7 @@
 
-Harness Error (TIMEOUT), message = null
 
-TIMEOUT Unregister on script evaluation Test timed out
-NOTRUN Unregister on installing event 
-NOTRUN Unregister on activate event 
-NOTRUN Unregister controlling service worker 
+PASS Unregister on script evaluation 
+PASS Unregister on installing event 
+PASS Unregister on activate event 
+FAIL Unregister controlling service worker promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
 
index 13d4111..a59058b 100644 (file)
@@ -1,5 +1,24 @@
 2017-12-02  Chris Dumez  <cdumez@apple.com>
 
+        Support container.register() / registration.unregister() /  inside service workers
+        https://bugs.webkit.org/show_bug.cgi?id=180326
+
+        Reviewed by Youenn Fablet.
+
+        Support container.register() / registration.unregister() /  inside service workers.
+        This is mostly about removing the is<Document>() checks and adding testing given
+        that most of the work was done in r225455.
+
+        Test: http/tests/workers/service/ServiceWorkerGlobalScope_register.html
+
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::addRegistration):
+        * workers/service/ServiceWorkerRegistration.cpp:
+        (WebCore::ServiceWorkerRegistration::update):
+        (WebCore::ServiceWorkerRegistration::unregister):
+
+2017-12-02  Chris Dumez  <cdumez@apple.com>
+
         Support serviceWorkerRegistration.update() inside service workers
         https://bugs.webkit.org/show_bug.cgi?id=180215
 
index 4f8423a..15d0fec 100644 (file)
@@ -94,12 +94,6 @@ void ServiceWorkerContainer::addRegistration(const String& relativeScriptURL, co
         return;
     }
 
-    // FIXME: Add support in workers.
-    if (!is<Document>(*context)) {
-        promise->reject(Exception { NotSupportedError, ASCIILiteral("serviceWorker.register() is not yet supported in workers") });
-        return;
-    }
-
     if (relativeScriptURL.isEmpty()) {
         promise->reject(Exception { TypeError, ASCIILiteral("serviceWorker.register() cannot be called with an empty script URL") });
         return;
index f2890ea..04cdec2 100644 (file)
@@ -116,7 +116,6 @@ void ServiceWorkerRegistration::update(Ref<DeferredPromise>&& promise)
 {
     auto* context = scriptExecutionContext();
     if (!context) {
-        ASSERT_NOT_REACHED();
         promise->reject(Exception(InvalidStateError));
         return;
     }
@@ -135,24 +134,11 @@ void ServiceWorkerRegistration::unregister(Ref<DeferredPromise>&& promise)
 {
     auto* context = scriptExecutionContext();
     if (!context) {
-        ASSERT_NOT_REACHED();
         promise->reject(Exception(InvalidStateError));
         return;
     }
 
-    // FIXME: Add support in workers.
-    if (!is<Document>(*context)) {
-        promise->reject(Exception { NotSupportedError, ASCIILiteral("serviceWorkerRegistration.unregister() is not yet supported in workers") });
-        return;
-    }
-
-    auto* container = context->serviceWorkerContainer();
-    if (!container) {
-        promise->reject(Exception(InvalidStateError));
-        return;
-    }
-
-    container->removeRegistration(m_registrationData.scopeURL, WTFMove(promise));
+    m_container->removeRegistration(m_registrationData.scopeURL, WTFMove(promise));
 }
 
 void ServiceWorkerRegistration::updateStateFromServer(ServiceWorkerRegistrationState state, RefPtr<ServiceWorker>&& serviceWorker)