Default scope used when registering a service worker is wrong
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Dec 2017 05:08:52 +0000 (05:08 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Dec 2017 05:08:52 +0000 (05:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180961

Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

Rebaseline WPT test now that more checks are passing.

* web-platform-tests/service-workers/service-worker/register-default-scope.https-expected.txt:

Source/WebCore:

The default scope we used when registering a service worker was wrong, it did not match:
- https://w3c.github.io/ServiceWorker/#start-register (Step 4)

This patch aligns our behavior with the specification.

No new tests, rebaselined existing test.

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

LayoutTests:

Update / Rebaseline WebKit tests due to behavior change.

* http/tests/workers/service/basic-register-exceptions-expected.txt:
* http/tests/workers/service/basic-unregister.https-expected.txt:
* http/tests/workers/service/resources/basic-unregister.js:
(async.test):
* http/tests/workers/service/resources/service-worker-getRegistration.js:
(async.test):
* http/tests/workers/service/self_registration-expected.txt:
* http/tests/workers/service/service-worker-clear.html:

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

LayoutTests/ChangeLog
LayoutTests/http/tests/workers/service/basic-register-exceptions-expected.txt
LayoutTests/http/tests/workers/service/basic-unregister.https-expected.txt
LayoutTests/http/tests/workers/service/resources/basic-unregister.js
LayoutTests/http/tests/workers/service/resources/service-worker-getRegistration.js
LayoutTests/http/tests/workers/service/self_registration-expected.txt
LayoutTests/http/tests/workers/service/service-worker-clear.html
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-default-scope.https-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/workers/service/ServiceWorkerContainer.cpp

index 9ee73ba..2c3ca7c 100644 (file)
@@ -1,3 +1,21 @@
+2017-12-18  Chris Dumez  <cdumez@apple.com>
+
+        Default scope used when registering a service worker is wrong
+        https://bugs.webkit.org/show_bug.cgi?id=180961
+
+        Reviewed by Youenn Fablet.
+
+        Update / Rebaseline WebKit tests due to behavior change.
+
+        * http/tests/workers/service/basic-register-exceptions-expected.txt:
+        * http/tests/workers/service/basic-unregister.https-expected.txt:
+        * http/tests/workers/service/resources/basic-unregister.js:
+        (async.test):
+        * http/tests/workers/service/resources/service-worker-getRegistration.js:
+        (async.test):
+        * http/tests/workers/service/self_registration-expected.txt:
+        * http/tests/workers/service/service-worker-clear.html:
+
 2017-12-18  Ryosuke Niwa  <rniwa@webkit.org>
 
         Assertion hit in DocumentOrderedMap::get while removing a form element
index 5eb1efd..8574de7 100644 (file)
@@ -4,5 +4,6 @@ CONSOLE MESSAGE: line 40: Registration failed with error: TypeError: serviceWork
 CONSOLE MESSAGE: line 50: Registration failed with error: TypeError: serviceWorker.register() must be called with a script URL whose path does not contain '%2f' or '%5c'
 CONSOLE MESSAGE: line 60: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() must be either HTTP or HTTPS
 CONSOLE MESSAGE: line 70: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() cannot have a path that contains '%2f' or '%5c'
+CONSOLE MESSAGE: line 80: Registration failed with error: SecurityError: Script origin does not match the registering client's origin
 CONSOLE MESSAGE: line 91: Registration failed with error: SecurityError: Scope origin does not match the registering client's origin
 
index 68d6fb8..2d8cc76 100644 (file)
@@ -5,6 +5,6 @@ PASS: Unregistration was successful
 PASS: There is no service worker registered for the origin
 PASS: Unregistration failed as expected
 PASS: There is no service worker registered for the origin
-PASS: registration scope is https://127.0.0.1:8443/workers/service/
+PASS: registration scope is https://127.0.0.1:8443/workers/service/resources/
 PASS: There is a service worker registered for the origin
 
index ec1af6c..f06a975 100644 (file)
@@ -45,7 +45,7 @@ async function test()
             log("FAIL: There is a service worker registered for the origin");
 
         registration = await navigator.serviceWorker.register("resources/basic-fetch-worker.js", { });
-        if (registration.scope === "https://127.0.0.1:8443/workers/service/")
+        if (registration.scope === "https://127.0.0.1:8443/workers/service/resources/")
             log("PASS: registration scope is " + registration.scope);
         else
             log("FAIL: registration scope is " + registration.scope);
index b7c999a..80bf305 100644 (file)
@@ -40,7 +40,7 @@ async function test()
         log("Service worker 1 registered with scope " + newRegistration1.scope);
 
         log("Registering service worker 2");
-        var newRegistration2 = await navigator.serviceWorker.register("resources/service-worker-getRegistration-worker.js");
+        var newRegistration2 = await navigator.serviceWorker.register("resources/service-worker-getRegistration-worker.js", { scope: "./" });
         log("Service worker 2 registered with scope " + newRegistration2.scope);
 
         var registration4 = await navigator.serviceWorker.getRegistration("/test1/test2");
index 8284341..474d292 100644 (file)
@@ -3,7 +3,7 @@
 Received updatefound event on self.registration
 Received install event
 * self.registration
-scope: http://127.0.0.1:8000/workers/service/
+scope: http://127.0.0.1:8000/workers/service/resources/
 updateViaCache: imports
 installing worker:
 - scriptURL: http://127.0.0.1:8000/workers/service/resources/self_registration-worker.js
@@ -15,7 +15,7 @@ Received statechange event on service worker
 Received statechange event on service worker
 Received activate event
 * self.registration
-scope: http://127.0.0.1:8000/workers/service/
+scope: http://127.0.0.1:8000/workers/service/resources/
 updateViaCache: imports
 installing worker: null
 waiting worker: null
@@ -25,7 +25,7 @@ active worker:
 
 Received statechange event on service worker
 * self.registration
-scope: http://127.0.0.1:8000/workers/service/
+scope: http://127.0.0.1:8000/workers/service/resources/
 updateViaCache: imports
 installing worker: null
 waiting worker: null
index 7cd23ee..d441487 100644 (file)
@@ -14,7 +14,7 @@ async function test()
         var hasRegistration = await internals.hasServiceWorkerRegistration("");
         log(hasRegistration ? "FAIL: Got registration" : "PASS: No registration");
 
-        await navigator.serviceWorker.register("resources/service-worker-fetch-worker.js", { });
+        await navigator.serviceWorker.register("resources/service-worker-fetch-worker.js", { scope: "./" });
 
         var hasRegistration = await internals.hasServiceWorkerRegistration("");
         log(hasRegistration ? "PASS: Got registration" : "FAIL: No registration");
index 65daed0..d2cc26c 100644 (file)
@@ -1,5 +1,16 @@
 2017-12-18  Chris Dumez  <cdumez@apple.com>
 
+        Default scope used when registering a service worker is wrong
+        https://bugs.webkit.org/show_bug.cgi?id=180961
+
+        Reviewed by Youenn Fablet.
+
+        Rebaseline WPT test now that more checks are passing.
+
+        * web-platform-tests/service-workers/service-worker/register-default-scope.https-expected.txt:
+
+2017-12-18  Chris Dumez  <cdumez@apple.com>
+
         Unreviewed, rebaseline imported/w3c/web-platform-tests/service-workers/service-worker/registration-security-error.https.html after r226087.
 
         * web-platform-tests/service-workers/service-worker/registration-security-error.https-expected.txt:
index 60ce703..85443ed 100644 (file)
@@ -1,5 +1,5 @@
 
-FAIL default scope assert_equals: The default scope should be URL("./", script_url) expected "https://localhost:9443/service-workers/service-worker/resources/" but got "https://localhost:9443/service-workers/service-worker/"
-FAIL undefined scope assert_equals: The default scope should be URL("./", script_url) expected "https://localhost:9443/service-workers/service-worker/resources/" but got "https://localhost:9443/service-workers/service-worker/"
+PASS default scope 
+PASS undefined scope 
 FAIL null scope assert_unreached: register should fail Reached unreachable code
 
index af069d8..9b801c7 100644 (file)
@@ -1,3 +1,20 @@
+2017-12-18  Chris Dumez  <cdumez@apple.com>
+
+        Default scope used when registering a service worker is wrong
+        https://bugs.webkit.org/show_bug.cgi?id=180961
+
+        Reviewed by Youenn Fablet.
+
+        The default scope we used when registering a service worker was wrong, it did not match:
+        - https://w3c.github.io/ServiceWorker/#start-register (Step 4)
+
+        This patch aligns our behavior with the specification.
+
+        No new tests, rebaselined existing test.
+
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::addRegistration):
+
 2017-12-18  Ryosuke Niwa  <rniwa@webkit.org>
 
         Assertion hit in DocumentOrderedMap::get while removing a form element
index b0fe9f8..7b9c54a 100644 (file)
@@ -141,9 +141,10 @@ void ServiceWorkerContainer::addRegistration(const String& relativeScriptURL, co
         return;
     }
 
-    String scope = options.scope.isEmpty() ? ASCIILiteral("./") : options.scope;
-    if (!scope.isEmpty())
-        jobData.scopeURL = context->completeURL(scope);
+    if (!options.scope.isEmpty())
+        jobData.scopeURL = context->completeURL(options.scope);
+    else
+        jobData.scopeURL = URL(jobData.scriptURL, "./");
 
     if (!jobData.scopeURL.isNull() && !SchemeRegistry::canServiceWorkersHandleURLScheme(jobData.scopeURL.protocol().toStringWithoutCopying())) {
         promise->reject(Exception { TypeError, ASCIILiteral("Scope URL provided to serviceWorker.register() must be either HTTP or HTTPS") });