Skip to content

Commit d59e726

Browse files
Default scope used when registering a service worker is wrong
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: http://svn.webkit.org/repository/webkit/trunk@226096 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent d4ca018 commit d59e726

File tree

11 files changed

+60
-12
lines changed

11 files changed

+60
-12
lines changed

LayoutTests/ChangeLog

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2017-12-18 Chris Dumez <[email protected]>
2+
3+
Default scope used when registering a service worker is wrong
4+
https://bugs.webkit.org/show_bug.cgi?id=180961
5+
6+
Reviewed by Youenn Fablet.
7+
8+
Update / Rebaseline WebKit tests due to behavior change.
9+
10+
* http/tests/workers/service/basic-register-exceptions-expected.txt:
11+
* http/tests/workers/service/basic-unregister.https-expected.txt:
12+
* http/tests/workers/service/resources/basic-unregister.js:
13+
(async.test):
14+
* http/tests/workers/service/resources/service-worker-getRegistration.js:
15+
(async.test):
16+
* http/tests/workers/service/self_registration-expected.txt:
17+
* http/tests/workers/service/service-worker-clear.html:
18+
119
2017-12-18 Ryosuke Niwa <[email protected]>
220

321
Assertion hit in DocumentOrderedMap::get while removing a form element

LayoutTests/http/tests/workers/service/basic-register-exceptions-expected.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ CONSOLE MESSAGE: line 40: Registration failed with error: TypeError: serviceWork
44
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'
55
CONSOLE MESSAGE: line 60: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() must be either HTTP or HTTPS
66
CONSOLE MESSAGE: line 70: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() cannot have a path that contains '%2f' or '%5c'
7+
CONSOLE MESSAGE: line 80: Registration failed with error: SecurityError: Script origin does not match the registering client's origin
78
CONSOLE MESSAGE: line 91: Registration failed with error: SecurityError: Scope origin does not match the registering client's origin
89

LayoutTests/http/tests/workers/service/basic-unregister.https-expected.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ PASS: Unregistration was successful
55
PASS: There is no service worker registered for the origin
66
PASS: Unregistration failed as expected
77
PASS: There is no service worker registered for the origin
8-
PASS: registration scope is https://127.0.0.1:8443/workers/service/
8+
PASS: registration scope is https://127.0.0.1:8443/workers/service/resources/
99
PASS: There is a service worker registered for the origin
1010

LayoutTests/http/tests/workers/service/resources/basic-unregister.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async function test()
4545
log("FAIL: There is a service worker registered for the origin");
4646

4747
registration = await navigator.serviceWorker.register("resources/basic-fetch-worker.js", { });
48-
if (registration.scope === "https://127.0.0.1:8443/workers/service/")
48+
if (registration.scope === "https://127.0.0.1:8443/workers/service/%3Cspan%20class="x x-first x-last">resources/")
4949
log("PASS: registration scope is " + registration.scope);
5050
else
5151
log("FAIL: registration scope is " + registration.scope);

LayoutTests/http/tests/workers/service/resources/service-worker-getRegistration.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function test()
4040
log("Service worker 1 registered with scope " + newRegistration1.scope);
4141

4242
log("Registering service worker 2");
43-
var newRegistration2 = await navigator.serviceWorker.register("resources/service-worker-getRegistration-worker.js");
43+
var newRegistration2 = await navigator.serviceWorker.register("resources/service-worker-getRegistration-worker.js", { scope: "./" });
4444
log("Service worker 2 registered with scope " + newRegistration2.scope);
4545

4646
var registration4 = await navigator.serviceWorker.getRegistration("/test1/test2");

LayoutTests/http/tests/workers/service/self_registration-expected.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Received updatefound event on self.registration
44
Received install event
55
* self.registration
6-
scope: http://127.0.0.1:8000/workers/service/
6+
scope: http://127.0.0.1:8000/workers/service/resources/
77
updateViaCache: imports
88
installing worker:
99
- scriptURL: http://127.0.0.1:8000/workers/service/resources/self_registration-worker.js
@@ -15,7 +15,7 @@ Received statechange event on service worker
1515
Received statechange event on service worker
1616
Received activate event
1717
* self.registration
18-
scope: http://127.0.0.1:8000/workers/service/
18+
scope: http://127.0.0.1:8000/workers/service/resources/
1919
updateViaCache: imports
2020
installing worker: null
2121
waiting worker: null
@@ -25,7 +25,7 @@ active worker:
2525

2626
Received statechange event on service worker
2727
* self.registration
28-
scope: http://127.0.0.1:8000/workers/service/
28+
scope: http://127.0.0.1:8000/workers/service/resources/
2929
updateViaCache: imports
3030
installing worker: null
3131
waiting worker: null

LayoutTests/http/tests/workers/service/service-worker-clear.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
var hasRegistration = await internals.hasServiceWorkerRegistration("");
1515
log(hasRegistration ? "FAIL: Got registration" : "PASS: No registration");
1616

17-
await navigator.serviceWorker.register("resources/service-worker-fetch-worker.js", { });
17+
await navigator.serviceWorker.register("resources/service-worker-fetch-worker.js", { scope: "./" });
1818

1919
var hasRegistration = await internals.hasServiceWorkerRegistration("");
2020
log(hasRegistration ? "PASS: Got registration" : "FAIL: No registration");

LayoutTests/imported/w3c/ChangeLog

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2017-12-18 Chris Dumez <[email protected]>
2+
3+
Default scope used when registering a service worker is wrong
4+
https://bugs.webkit.org/show_bug.cgi?id=180961
5+
6+
Reviewed by Youenn Fablet.
7+
8+
Rebaseline WPT test now that more checks are passing.
9+
10+
* web-platform-tests/service-workers/service-worker/register-default-scope.https-expected.txt:
11+
112
2017-12-18 Chris Dumez <[email protected]>
213

314
Unreviewed, rebaseline imported/w3c/web-platform-tests/service-workers/service-worker/registration-security-error.https.html after r226087.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
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/"
3-
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/"
2+
PASS default scope
3+
PASS undefined scope
44
FAIL null scope assert_unreached: register should fail Reached unreachable code
55

Source/WebCore/ChangeLog

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
2017-12-18 Chris Dumez <[email protected]>
2+
3+
Default scope used when registering a service worker is wrong
4+
https://bugs.webkit.org/show_bug.cgi?id=180961
5+
6+
Reviewed by Youenn Fablet.
7+
8+
The default scope we used when registering a service worker was wrong, it did not match:
9+
- https://w3c.github.io/ServiceWorker/#start-register (Step 4)
10+
11+
This patch aligns our behavior with the specification.
12+
13+
No new tests, rebaselined existing test.
14+
15+
* workers/service/ServiceWorkerContainer.cpp:
16+
(WebCore::ServiceWorkerContainer::addRegistration):
17+
118
2017-12-18 Ryosuke Niwa <[email protected]>
219

320
Assertion hit in DocumentOrderedMap::get while removing a form element

Source/WebCore/workers/service/ServiceWorkerContainer.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ void ServiceWorkerContainer::addRegistration(const String& relativeScriptURL, co
141141
return;
142142
}
143143

144-
String scope = options.scope.isEmpty() ? ASCIILiteral("./") : options.scope;
145-
if (!scope.isEmpty())
146-
jobData.scopeURL = context->completeURL(scope);
144+
if (!options.scope.isEmpty())
145+
jobData.scopeURL = context->completeURL(options.scope);
146+
else
147+
jobData.scopeURL = URL(jobData.scriptURL, "./");
147148

148149
if (!jobData.scopeURL.isNull() && !SchemeRegistry::canServiceWorkersHandleURLScheme(jobData.scopeURL.protocol().toStringWithoutCopying())) {
149150
promise->reject(Exception { TypeError, ASCIILiteral("Scope URL provided to serviceWorker.register() must be either HTTP or HTTPS") });

0 commit comments

Comments
 (0)