Start exposing self.registration inside service workers
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2017 22:19:23 +0000 (22:19 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2017 22:19:23 +0000 (22:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180162

Reviewed by Brady Eidson.

LayoutTests/imported/w3c:

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

Source/WebCore:

Start exposing self.registration inside service workers as per:
- https://w3c.github.io/ServiceWorker/#serviceworkerglobalscope-interface

This is very initial support:
- The operations on the registration (such as update) will reject the promise for now.
- The registration's service workers are not yet populated.

This will be implemented in a follow-up.

Tests: http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html
       http/tests/workers/service/self_registration.html

* bindings/js/JSServiceWorkerGlobalScopeCustom.cpp:
(WebCore::JSServiceWorkerGlobalScope::visitAdditionalChildren):
* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::addRegistration):
* workers/service/ServiceWorkerContextData.cpp:
(WebCore::ServiceWorkerContextData::isolatedCopy const):
* workers/service/ServiceWorkerContextData.h:
(WebCore::ServiceWorkerContextData::encode const):
(WebCore::ServiceWorkerContextData::decode):
* workers/service/ServiceWorkerGlobalScope.cpp:
(WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope):
* workers/service/ServiceWorkerGlobalScope.h:
(WebCore::ServiceWorkerGlobalScope::registration):
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::updateWorker):
(WebCore::SWServer::installContextData):
* workers/service/server/SWServer.h:
* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::scriptFetchFinished):

LayoutTests:

Add layout test coverage.

* TestExpectations:
Skip test that covers self.registration.update() because it now times out. We do not support update()
on registrations inside service workers yet so the test times out waiting for the updatefound event
on the registration.

* http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt: Added.
* http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html: Added.
* http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js: Added.
* http/tests/workers/service/resources/self_registration-worker.js: Added.
* http/tests/workers/service/self_registration-expected.txt: Added.
* http/tests/workers/service/self_registration.html: Added.

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

25 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html [new file with mode: 0644]
LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js [new file with mode: 0644]
LayoutTests/http/tests/workers/service/resources/self_registration-worker.js [new file with mode: 0644]
LayoutTests/http/tests/workers/service/self_registration-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/workers/service/self_registration.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/redirected-response.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-foreign-fetch-errors.https-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSServiceWorkerGlobalScopeCustom.cpp
Source/WebCore/workers/service/ServiceWorkerContainer.cpp
Source/WebCore/workers/service/ServiceWorkerContextData.cpp
Source/WebCore/workers/service/ServiceWorkerContextData.h
Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp
Source/WebCore/workers/service/ServiceWorkerGlobalScope.h
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebCore/workers/service/server/SWServer.h
Source/WebCore/workers/service/server/SWServerJobQueue.cpp

index 49edd89..87a96de 100644 (file)
@@ -1,3 +1,24 @@
+2017-11-29  Chris Dumez  <cdumez@apple.com>
+
+        Start exposing self.registration inside service workers
+        https://bugs.webkit.org/show_bug.cgi?id=180162
+
+        Reviewed by Brady Eidson.
+
+        Add layout test coverage.
+
+        * TestExpectations:
+        Skip test that covers self.registration.update() because it now times out. We do not support update()
+        on registrations inside service workers yet so the test times out waiting for the updatefound event
+        on the registration.
+
+        * http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt: Added.
+        * http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html: Added.
+        * http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js: Added.
+        * http/tests/workers/service/resources/self_registration-worker.js: Added.
+        * http/tests/workers/service/self_registration-expected.txt: Added.
+        * http/tests/workers/service/self_registration.html: Added.
+
 2017-11-29  Javier M. Mellid  <jmunhoz@igalia.com>
 
         [GTK] Test gardening
index 111f0cb..10b7628 100644 (file)
@@ -146,8 +146,8 @@ 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/registration-attribute.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/ServiceWorkerGlobalScope/update.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 ]
@@ -168,6 +168,7 @@ imported/w3c/web-platform-tests/service-workers/service-worker/navigation-preloa
 imported/w3c/web-platform-tests/service-workers/service-worker/navigation-preload/get-state.https.html [ Skip ]
 imported/w3c/web-platform-tests/service-workers/service-worker/navigation-preload/redirect.https.html [ Skip ]
 imported/w3c/web-platform-tests/service-workers/service-worker/navigation-preload/request-headers.https.html [ Skip ]
+imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https.html [ Skip ]
 imported/w3c/web-platform-tests/service-workers/service-worker/postmessage.https.html [ Skip ]
 imported/w3c/web-platform-tests/service-workers/service-worker/postmessage-msgport-to-client.https.html [ Skip ]
 imported/w3c/web-platform-tests/service-workers/service-worker/postmessage-to-client.https.html [ Skip ]
@@ -194,7 +195,6 @@ imported/w3c/web-platform-tests/service-workers/service-worker/foreign-fetch-cor
 imported/w3c/web-platform-tests/service-workers/service-worker/invalid-header.https.html [ Pass Failure ]
 imported/w3c/web-platform-tests/service-workers/service-worker/multiple-update.https.html [ Pass Failure ]
 imported/w3c/web-platform-tests/service-workers/service-worker/performance-timeline.https.html [ Pass Failure ]
-imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https.html [ Pass Failure ]
 webkit.org/b/179452 imported/w3c/web-platform-tests/service-workers/service-worker/register-same-scope-different-script-url.https.html [ Pass Failure ]
 webkit.org/b/179194 imported/w3c/web-platform-tests/service-workers/service-worker/registration-mime-types.https.html [ Pass Failure ]
 imported/w3c/web-platform-tests/service-workers/service-worker/registration-script.https.html [ Pass Failure ]
diff --git a/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt b/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt
new file mode 100644 (file)
index 0000000..f09dd85
--- /dev/null
@@ -0,0 +1,4 @@
+* Tests that self.registration always returns the same object
+
+PASS: returned object was the same
+
diff --git a/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html b/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html
new file mode 100644 (file)
index 0000000..81f6108
--- /dev/null
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="resources/sw-test-pre.js"></script>
+<script>
+log("* Tests that self.registration always returns the same object");
+log("");
+
+navigator.serviceWorker.addEventListener("message", function(event) {
+    log(event.data);
+    finishSWTest();
+});
+
+navigator.serviceWorker.register("resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js", { }).then(function(registration) {
+    registration.installing.postMessage("runTest");
+});
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js b/LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js
new file mode 100644 (file)
index 0000000..42a825c
--- /dev/null
@@ -0,0 +1,30 @@
+function gc() {
+    if (typeof GCController !== "undefined")
+        GCController.collect();
+    else {
+        var gcRec = function (n) {
+            if (n < 1)
+                return {};
+            var temp = {i: "ab" + i + (i / 100000)};
+            temp += "foo";
+            gcRec(n-1);
+        };
+        for (var i = 0; i < 1000; i++)
+            gcRec(10);
+    }
+}
+
+let client = null;
+
+self.addEventListener("message", (event) => {
+    client = event.source;
+    self.registration.foo = 1;
+    gc();
+    setTimeout(function() {
+        gc();
+        if (self.registration.foo === 1)
+            client.postMessage("PASS: returned object was the same");
+        else
+            client.postMessage("FAIL: returned object was not the same");
+    }, 0);
+});
diff --git a/LayoutTests/http/tests/workers/service/resources/self_registration-worker.js b/LayoutTests/http/tests/workers/service/resources/self_registration-worker.js
new file mode 100644 (file)
index 0000000..30eb41b
--- /dev/null
@@ -0,0 +1,26 @@
+let results = [];
+
+function log(msg)
+{
+    results.push(msg);
+}
+
+function dumpRegistration()
+{
+    log("* self.registration");
+    log("scope: " + self.registration.scope);
+    log("updateViaCache: " + self.registration.updateViaCache);
+    log("");
+}
+
+self.addEventListener("install", function() {
+    log("Received install event");
+    dumpRegistration();
+});
+
+self.addEventListener("message", (event) => {
+    for (let result of results)
+        event.source.postMessage(result);
+    event.source.postMessage("DONE");
+});
+
diff --git a/LayoutTests/http/tests/workers/service/self_registration-expected.txt b/LayoutTests/http/tests/workers/service/self_registration-expected.txt
new file mode 100644 (file)
index 0000000..11434e8
--- /dev/null
@@ -0,0 +1,8 @@
+* Add basic testing for ServiceWorkerGlobalScope.registration
+
+Received install event
+* self.registration
+scope: http://127.0.0.1:8000/workers/service/
+updateViaCache: imports
+
+
diff --git a/LayoutTests/http/tests/workers/service/self_registration.html b/LayoutTests/http/tests/workers/service/self_registration.html
new file mode 100644 (file)
index 0000000..316fc2c
--- /dev/null
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="resources/sw-test-pre.js"></script>
+<script>
+log("* Add basic testing for ServiceWorkerGlobalScope.registration");
+log("");
+
+navigator.serviceWorker.addEventListener("message", function(event) {
+    if (event.data === "DONE") {
+        finishSWTest();
+        return;
+    }
+    log(event.data);
+});
+
+navigator.serviceWorker.register("resources/self_registration-worker.js", { }).then(function(registration) {
+    worker = registration.installing;
+    waitForState(worker, "activated").then(function() {
+        worker.postMessage("DUMP_RESULTS");
+    });
+});
+</script>
+</body>
+</html>
index 4b7d552..36f778a 100644 (file)
@@ -1,3 +1,12 @@
+2017-11-29  Chris Dumez  <cdumez@apple.com>
+
+        Start exposing self.registration inside service workers
+        https://bugs.webkit.org/show_bug.cgi?id=180162
+
+        Reviewed by Brady Eidson.
+
+        * web-platform-tests/service-workers/service-worker/redirected-response.https-expected.txt:
+
 2017-11-29  Youenn Fablet  <youenn@apple.com>
 
         Add support for FetchEvent.clientId
index 4bbb346..df1825b 100644 (file)
@@ -1,6 +1,5 @@
 
-Harness Error (TIMEOUT), message = null
 
-FAIL Verify registration attributes on ServiceWorkerGlobalScope assert_unreached: unregister and register should not fail: TypeError: null is not an object (evaluating 'self.registration.scope') Reached unreachable code
-FAIL Verify registration attributes on ServiceWorkerGlobalScope of the newer worker assert_unreached: unregister and register should not fail: TypeError: null is not an object (evaluating 'self.registration.scope') Reached unreachable code
+FAIL Verify registration attributes on ServiceWorkerGlobalScope assert_equals: Service Worker should respond to fetch expected "updatefound,install,statechange(installed),statechange(activating),activate,statechange(activated),fetch" but got "{\"error\": {\"message\": \"\", \"code\": 404}}"
+FAIL Verify registration attributes on ServiceWorkerGlobalScope of the newer worker promise_test: Unhandled rejection with value: object "Error: wait_for_state must be passed a ServiceWorker"
 
index e0d8921..aa10763 100644 (file)
@@ -1,8 +1,8 @@
 
 Harness Error (TIMEOUT), message = null
 
-FAIL Unregister on script evaluation assert_unreached: unregister and register should not fail: TypeError: null is not an object (evaluating 'self.registration.unregister') Reached unreachable code
-TIMEOUT Unregister on installing event Test timed out
+TIMEOUT Unregister on script evaluation Test timed out
+NOTRUN Unregister on installing event 
 NOTRUN Unregister on activate event 
 NOTRUN Unregister controlling service worker 
 
index 20058e3..861196d 100644 (file)
@@ -1,3 +1,6 @@
 
-FAIL Update a registration on ServiceWorkerGlobalScope assert_unreached: unregister and register should not fail: TypeError: null is not an object (evaluating 'self.registration.addEventListener') Reached unreachable code
+
+Harness Error (TIMEOUT), message = null
+
+TIMEOUT Update a registration on ServiceWorkerGlobalScope Test timed out
 
index 9202105..0769b96 100644 (file)
@@ -1,34 +1,34 @@
-CONSOLE MESSAGE: Unhandled Promise Rejection: TypeError: TypeError: null is not an object (evaluating 'self.registration.scope')
-CONSOLE MESSAGE: line 50: Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'registrations[0].unregister')
+  
 
+Harness Error (TIMEOUT), message = null
 
-FAIL Normal redirect to same-origin scope. assert_unreached: unregister and register should not fail: TypeError: null is not an object (evaluating 'self.registration.scope') Reached unreachable code
-FAIL Normal redirect to other-origin scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fallbacked redirect to same-origin out-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fallbacked redirect to same-origin same-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fallbacked redirect to same-origin other-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fallbacked redirect to other-origin out-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fallbacked redirect to other-origin in-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-generated redirect to same-origin out-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-generated redirect to same-origin same-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-generated redirect to same-origin other-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-generated redirect to other-origin out-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-generated redirect to other-origin in-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fetched redirect to same-origin out-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fetched redirect to same-origin same-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fetched redirect to same-origin other-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fetched redirect to other-origin out-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fetched redirect to other-origin in-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to same-origin out-scope with opaque redirect response. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to same-origin same-scope with opaque redirect response. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to same-origin other-scope with opaque redirect response. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to other-origin out-scope with opaque redirect response. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to other-origin in-scope with opaque redirect response. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL No location redirect response. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to same-origin out-scope with opaque redirect response which is passed through Cache. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to same-origin same-scope with opaque redirect response which is passed through Cache. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to same-origin other-scope with opaque redirect response which is passed through Cache. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to other-origin out-scope with opaque redirect response which is passed through Cache. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to other-origin in-scope with opaque redirect response which is passed through Cache. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL No location redirect response via Cache. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
+FAIL Normal redirect to same-origin scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL Normal redirect to other-origin scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-fallbacked redirect to same-origin out-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-fallbacked redirect to same-origin same-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-fallbacked redirect to same-origin other-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-fallbacked redirect to other-origin out-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-fallbacked redirect to other-origin in-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+TIMEOUT SW-generated redirect to same-origin out-scope. Test timed out
+NOTRUN SW-generated redirect to same-origin same-scope. 
+NOTRUN SW-generated redirect to same-origin other-scope. 
+NOTRUN SW-generated redirect to other-origin out-scope. 
+NOTRUN SW-generated redirect to other-origin in-scope. 
+NOTRUN SW-fetched redirect to same-origin out-scope. 
+NOTRUN SW-fetched redirect to same-origin same-scope. 
+NOTRUN SW-fetched redirect to same-origin other-scope. 
+NOTRUN SW-fetched redirect to other-origin out-scope. 
+NOTRUN SW-fetched redirect to other-origin in-scope. 
+NOTRUN Redirect to same-origin out-scope with opaque redirect response. 
+NOTRUN Redirect to same-origin same-scope with opaque redirect response. 
+NOTRUN Redirect to same-origin other-scope with opaque redirect response. 
+NOTRUN Redirect to other-origin out-scope with opaque redirect response. 
+NOTRUN Redirect to other-origin in-scope with opaque redirect response. 
+NOTRUN No location redirect response. 
+NOTRUN Redirect to same-origin out-scope with opaque redirect response which is passed through Cache. 
+NOTRUN Redirect to same-origin same-scope with opaque redirect response which is passed through Cache. 
+NOTRUN Redirect to same-origin other-scope with opaque redirect response which is passed through Cache. 
+NOTRUN Redirect to other-origin out-scope with opaque redirect response which is passed through Cache. 
+NOTRUN Redirect to other-origin in-scope with opaque redirect response which is passed through Cache. 
+NOTRUN No location redirect response via Cache. 
 
index a517181..2a1dc7d 100644 (file)
@@ -1,20 +1,21 @@
 
-FAIL initialize global state (service worker registration and caches) assert_unreached: unregister and register should not fail: TypeError: null is not an object (evaluating 'self.registration.scope') Reached unreachable code
-FAIL mode: "follow", non-intercepted request, no server redirect promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "follow", non-intercepted request promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "manual", non-intercepted request promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "error", non-intercepted request promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "follow", no mode change, no server redirect promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "follow", no mode change promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "error", mode change: "follow" promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "manual", mode change: "follow" promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "follow", mode change: "manual" promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "error", mode change: "manual" promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "manual", no mode change promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "follow", generated redirect response promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "error", generated redirect response promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "manual", generated redirect response promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL Fetch should follow the redirect response 20 times promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL Fetch should not follow the redirect response 21 times. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL restore global state (service worker registration) undefined is not an object (evaluating 'registration.unregister')
+FAIL initialize global state (service worker registration and caches) promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "follow", non-intercepted request, no server redirect promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "follow", non-intercepted request promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "manual", non-intercepted request promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "error", non-intercepted request promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "follow", no mode change, no server redirect promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "follow", no mode change promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "error", mode change: "follow" promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "manual", mode change: "follow" promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "follow", mode change: "manual" promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "error", mode change: "manual" promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "manual", no mode change promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "follow", generated redirect response promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "error", generated redirect response promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "manual", generated redirect response promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL Fetch should follow the redirect response 20 times promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL Fetch should not follow the redirect response 21 times. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+PASS restore global state (service worker registration) 
+PASS restore global state (caches) 
 
index ce8caa4..40c49f4 100644 (file)
@@ -1,4 +1,26 @@
 
 PASS foreign fetch registration 
-FAIL Untitled TypeError: null is not an object (evaluating 'registration.scope')
+PASS Invalid options 
+PASS Scopes not an array 
+PASS Scopes not a string in array 
+PASS Relative url not under scope 
+PASS Absolute url not under scope 
+PASS Empty scope array 
+FAIL Call after event returned assert_throws: function "function () {
+                event.registerForeignFetch({scopes: [scope], origins: ['*']});
+              }" threw object "TypeError: event.registerForeignFetch is not a function. (In 'event.registerForeignFetch({scopes: [scope], origins: ['*']})', 'event.registerForeignFetch' is undefined)" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
+FAIL Valid scopes with wildcard origin string event.registerForeignFetch is not a function. (In 'event.registerForeignFetch({scopes: [scope], origins: ['*']})', 'event.registerForeignFetch' is undefined)
+FAIL Absolute urls event.registerForeignFetch is not a function. (In 'event.registerForeignFetch({scopes: [scope, scope + '/foo'], origins: ['*']})', 'event.registerForeignFetch' is undefined)
+FAIL Relative urls undefined is not a function (near '...event.registerForeignFetch...')
+PASS No origins specified 
+PASS Origins not a string or array 
+PASS Origins contains something not a string 
+PASS Origin not an absolute URL 
+FAIL Wildcard origin string in array event.registerForeignFetch is not a function. (In 'event.registerForeignFetch({scopes: [scope], origins: ['*']})', 'event.registerForeignFetch' is undefined)
+PASS Origin string 
+FAIL Origin string in array event.registerForeignFetch is not a function. (In 'event.registerForeignFetch({scopes: [scope], origins: ['https://example.com/']})', 'event.registerForeignFetch' is undefined)
+FAIL Array with multiple origins event.registerForeignFetch is not a function. (In 'event.registerForeignFetch({
+            scopes: [scope], origins: ['https://example.com/', 'https://chromium.org']})', 'event.registerForeignFetch' is undefined)
+PASS Origins includes wildcard and other strings 
+PASS Origins includes other strings and wildcard 
 
index b4cc587..993f3dc 100644 (file)
@@ -1,3 +1,42 @@
+2017-11-29  Chris Dumez  <cdumez@apple.com>
+
+        Start exposing self.registration inside service workers
+        https://bugs.webkit.org/show_bug.cgi?id=180162
+
+        Reviewed by Brady Eidson.
+
+        Start exposing self.registration inside service workers as per:
+        - https://w3c.github.io/ServiceWorker/#serviceworkerglobalscope-interface
+
+        This is very initial support:
+        - The operations on the registration (such as update) will reject the promise for now.
+        - The registration's service workers are not yet populated.
+
+        This will be implemented in a follow-up.
+
+        Tests: http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html
+               http/tests/workers/service/self_registration.html
+
+        * bindings/js/JSServiceWorkerGlobalScopeCustom.cpp:
+        (WebCore::JSServiceWorkerGlobalScope::visitAdditionalChildren):
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::addRegistration):
+        * workers/service/ServiceWorkerContextData.cpp:
+        (WebCore::ServiceWorkerContextData::isolatedCopy const):
+        * workers/service/ServiceWorkerContextData.h:
+        (WebCore::ServiceWorkerContextData::encode const):
+        (WebCore::ServiceWorkerContextData::decode):
+        * workers/service/ServiceWorkerGlobalScope.cpp:
+        (WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope):
+        * workers/service/ServiceWorkerGlobalScope.h:
+        (WebCore::ServiceWorkerGlobalScope::registration):
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::updateWorker):
+        (WebCore::SWServer::installContextData):
+        * workers/service/server/SWServer.h:
+        * workers/service/server/SWServerJobQueue.cpp:
+        (WebCore::SWServerJobQueue::scriptFetchFinished):
+
 2017-11-29  Youenn Fablet  <youenn@apple.com>
 
         Add support for FetchEvent.clientId
index d529e4a..91de439 100644 (file)
@@ -37,7 +37,7 @@ using namespace JSC;
 void JSServiceWorkerGlobalScope::visitAdditionalChildren(SlotVisitor& visitor)
 {
     visitor.addOpaqueRoot(&wrapped().clients());
-    visitor.addOpaqueRoot(wrapped().registration());
+    visitor.addOpaqueRoot(&wrapped().registration());
 }
 
 } // namespace WebCore
index 1dfb049..75ec664 100644 (file)
@@ -422,7 +422,7 @@ SWClientConnection& ServiceWorkerContainer::ensureSWClientConnection()
 
 void ServiceWorkerContainer::addRegistration(ServiceWorkerRegistration& registration)
 {
-    m_swConnection->addServiceWorkerRegistrationInServer(registration.identifier());
+    ensureSWClientConnection().addServiceWorkerRegistrationInServer(registration.identifier());
     m_registrations.add(registration.identifier(), &registration);
 }
 
index ba58ccf..bb5eb20 100644 (file)
@@ -32,7 +32,7 @@ namespace WebCore {
 
 ServiceWorkerContextData ServiceWorkerContextData::isolatedCopy() const
 {
-    return { jobDataIdentifier, registrationKey.isolatedCopy(), serviceWorkerIdentifier, script.isolatedCopy(), scriptURL.isolatedCopy(), workerType };
+    return { jobDataIdentifier, registration.isolatedCopy(), serviceWorkerIdentifier, script.isolatedCopy(), scriptURL.isolatedCopy(), workerType };
 }
 
 } // namespace WebCore
index 8882c1a..ee90bf3 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "ServiceWorkerIdentifier.h"
 #include "ServiceWorkerJobDataIdentifier.h"
-#include "ServiceWorkerRegistrationKey.h"
+#include "ServiceWorkerRegistrationData.h"
 #include "URL.h"
 #include "WorkerType.h"
 
@@ -37,7 +37,7 @@ namespace WebCore {
 
 struct ServiceWorkerContextData {
     ServiceWorkerJobDataIdentifier jobDataIdentifier;
-    ServiceWorkerRegistrationKey registrationKey;
+    ServiceWorkerRegistrationData registration;
     ServiceWorkerIdentifier serviceWorkerIdentifier;
     String script;
     URL scriptURL;
@@ -52,7 +52,7 @@ struct ServiceWorkerContextData {
 template<class Encoder>
 void ServiceWorkerContextData::encode(Encoder& encoder) const
 {
-    encoder << jobDataIdentifier << registrationKey << serviceWorkerIdentifier << script << scriptURL << workerType;
+    encoder << jobDataIdentifier << registration << serviceWorkerIdentifier << script << scriptURL << workerType;
 }
 
 template<class Decoder>
@@ -63,8 +63,9 @@ std::optional<ServiceWorkerContextData> ServiceWorkerContextData::decode(Decoder
     if (!jobDataIdentifier)
         return std::nullopt;
 
-    auto registrationKey = ServiceWorkerRegistrationKey::decode(decoder);
-    if (!registrationKey)
+    std::optional<ServiceWorkerRegistrationData> registration;
+    decoder >> registration;
+    if (!registration)
         return std::nullopt;
 
     auto serviceWorkerIdentifier = ServiceWorkerIdentifier::decode(decoder);
@@ -83,7 +84,7 @@ std::optional<ServiceWorkerContextData> ServiceWorkerContextData::decode(Decoder
     if (!decoder.decodeEnum(workerType))
         return std::nullopt;
     
-    return {{ WTFMove(*jobDataIdentifier), WTFMove(*registrationKey), WTFMove(*serviceWorkerIdentifier), WTFMove(script), WTFMove(scriptURL), workerType }};
+    return {{ WTFMove(*jobDataIdentifier), WTFMove(*registration), WTFMove(*serviceWorkerIdentifier), WTFMove(script), WTFMove(scriptURL), workerType }};
 }
 
 } // namespace WebCore
index 3a20b3a..7f803d9 100644 (file)
 
 #include "ServiceWorkerClients.h"
 #include "ServiceWorkerThread.h"
+#include "WorkerNavigator.h"
 
 namespace WebCore {
 
 ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const ServiceWorkerContextData& data, const URL& url, const String& identifier, const String& userAgent, bool isOnline, ServiceWorkerThread& thread, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, PAL::SessionID sessionID)
     : WorkerGlobalScope(url, identifier, userAgent, isOnline, thread, shouldBypassMainWorldContentSecurityPolicy, WTFMove(topOrigin), timeOrigin, connectionProxy, socketProvider, sessionID)
     , m_contextData(crossThreadCopy(data))
+    , m_registration(ServiceWorkerRegistration::getOrCreate(*this, navigator().serviceWorker(), WTFMove(m_contextData.registration)))
     , m_clients(ServiceWorkerClients::create(*this))
 {
 }
 
 ServiceWorkerGlobalScope::~ServiceWorkerGlobalScope() = default;
 
-ServiceWorkerRegistration* ServiceWorkerGlobalScope::registration()
-{
-    // FIXME: implement this.
-    return nullptr;
-}
-
 void ServiceWorkerGlobalScope::skipWaiting(Ref<DeferredPromise>&&)
 {
 }
index 9001517..7b8f3a9 100644 (file)
@@ -49,7 +49,7 @@ public:
     bool isServiceWorkerGlobalScope() const final { return true; }
 
     ServiceWorkerClients& clients() { return m_clients.get(); }
-    ServiceWorkerRegistration* registration();
+    ServiceWorkerRegistration& registration() { return m_registration.get(); }
     
     void skipWaiting(Ref<DeferredPromise>&&);
 
@@ -61,6 +61,7 @@ private:
     ServiceWorkerGlobalScope(const ServiceWorkerContextData&, const URL&, const String& identifier, const String& userAgent, bool isOnline, ServiceWorkerThread&, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, PAL::SessionID);
 
     ServiceWorkerContextData m_contextData;
+    Ref<ServiceWorkerRegistration> m_registration;
     Ref<ServiceWorkerClients> m_clients;
 };
 
index 2862991..b74fbd2 100644 (file)
@@ -344,11 +344,11 @@ void SWServer::serviceWorkerStoppedControllingClient(Connection& connection, Ser
     registration->removeClientUsingRegistration({ connection.identifier(), contextIdentifier });
 }
 
-void SWServer::updateWorker(Connection&, const ServiceWorkerJobDataIdentifier& jobDataIdentifier, const ServiceWorkerRegistrationKey& registrationKey, const URL& url, const String& script, WorkerType type)
+void SWServer::updateWorker(Connection&, const ServiceWorkerJobDataIdentifier& jobDataIdentifier, SWServerRegistration& registration, const URL& url, const String& script, WorkerType type)
 {
     auto serviceWorkerIdentifier = generateServiceWorkerIdentifier();
 
-    ServiceWorkerContextData data = { jobDataIdentifier, registrationKey, serviceWorkerIdentifier, script, url, type };
+    ServiceWorkerContextData data = { jobDataIdentifier, registration.data(), serviceWorkerIdentifier, script, url, type };
 
     // Right now we only ever keep up to one connection to one SW context process.
     // And it should always exist if we're calling updateWorker
@@ -375,7 +375,7 @@ void SWServer::installContextData(const ServiceWorkerContextData& data)
     auto* connection = SWServerToContextConnection::globalServerToContextConnection();
     ASSERT(connection);
 
-    auto* registration = m_registrations.get(data.registrationKey);
+    auto* registration = m_registrations.get(data.registration.key);
     RELEASE_ASSERT(registration);
 
     auto result = m_workersByID.add(data.serviceWorkerIdentifier, SWServerWorker::create(*this, *registration, connection->identifier(), data.scriptURL, data.script, data.workerType, data.serviceWorkerIdentifier));
index 479bd3c..5f3eff5 100644 (file)
@@ -121,7 +121,7 @@ public:
     void postTask(CrossThreadTask&&);
     void postTaskReply(CrossThreadTask&&);
 
-    void updateWorker(Connection&, const ServiceWorkerJobDataIdentifier&, const ServiceWorkerRegistrationKey&, const URL&, const String& script, WorkerType);
+    void updateWorker(Connection&, const ServiceWorkerJobDataIdentifier&, SWServerRegistration&, const URL&, const String& script, WorkerType);
     void terminateWorker(SWServerWorker&);
     void fireInstallEvent(SWServerWorker&);
     void fireActivateEvent(SWServerWorker&);
index 721a9d4..69a9ebd 100644 (file)
@@ -87,7 +87,7 @@ void SWServerJobQueue::scriptFetchFinished(SWServer::Connection& connection, con
     // - Invoke Finish Job with job and abort these steps.
 
     // FIXME: Support the proper worker type (classic vs module)
-    m_server.updateWorker(connection, job.identifier(), m_registrationKey, job.scriptURL, result.script, WorkerType::Classic);
+    m_server.updateWorker(connection, job.identifier(), *registration, job.scriptURL, result.script, WorkerType::Classic);
 }
 
 // https://w3c.github.io/ServiceWorker/#update-algorithm