Title: [225296] trunk
Revision
225296
Author
cdu...@apple.com
Date
2017-11-29 14:19:23 -0800 (Wed, 29 Nov 2017)

Log Message

Start exposing self.registration inside service workers
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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225295 => 225296)


--- trunk/LayoutTests/ChangeLog	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/ChangeLog	2017-11-29 22:19:23 UTC (rev 225296)
@@ -1,3 +1,24 @@
+2017-11-29  Chris Dumez  <cdu...@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  <jmun...@igalia.com>
 
         [GTK] Test gardening

Modified: trunk/LayoutTests/TestExpectations (225295 => 225296)


--- trunk/LayoutTests/TestExpectations	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/TestExpectations	2017-11-29 22:19:23 UTC (rev 225296)
@@ -146,8 +146,8 @@
 # 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-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/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 ]

Added: trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt (0 => 225296)


--- trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt	2017-11-29 22:19:23 UTC (rev 225296)
@@ -0,0 +1,4 @@
+* Tests that self.registration always returns the same object
+
+PASS: returned object was the same
+

Added: trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html (0 => 225296)


--- trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html	2017-11-29 22:19:23 UTC (rev 225296)
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<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>

Added: trunk/LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js (0 => 225296)


--- trunk/LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js	2017-11-29 22:19:23 UTC (rev 225296)
@@ -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);
+});

Added: trunk/LayoutTests/http/tests/workers/service/resources/self_registration-worker.js (0 => 225296)


--- trunk/LayoutTests/http/tests/workers/service/resources/self_registration-worker.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/self_registration-worker.js	2017-11-29 22:19:23 UTC (rev 225296)
@@ -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");
+});
+

Added: trunk/LayoutTests/http/tests/workers/service/self_registration-expected.txt (0 => 225296)


--- trunk/LayoutTests/http/tests/workers/service/self_registration-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/self_registration-expected.txt	2017-11-29 22:19:23 UTC (rev 225296)
@@ -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
+
+

Added: trunk/LayoutTests/http/tests/workers/service/self_registration.html (0 => 225296)


--- trunk/LayoutTests/http/tests/workers/service/self_registration.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/self_registration.html	2017-11-29 22:19:23 UTC (rev 225296)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<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>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (225295 => 225296)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-29 22:19:23 UTC (rev 225296)
@@ -1,3 +1,12 @@
+2017-11-29  Chris Dumez  <cdu...@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  <you...@apple.com>
 
         Add support for FetchEvent.clientId

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https-expected.txt (225295 => 225296)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https-expected.txt	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https-expected.txt	2017-11-29 22:19:23 UTC (rev 225296)
@@ -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"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https-expected.txt (225295 => 225296)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https-expected.txt	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https-expected.txt	2017-11-29 22:19:23 UTC (rev 225296)
@@ -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 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https-expected.txt (225295 => 225296)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https-expected.txt	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https-expected.txt	2017-11-29 22:19:23 UTC (rev 225296)
@@ -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
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt (225295 => 225296)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt	2017-11-29 22:19:23 UTC (rev 225296)
@@ -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. 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/redirected-response.https-expected.txt (225295 => 225296)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/redirected-response.https-expected.txt	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/redirected-response.https-expected.txt	2017-11-29 22:19:23 UTC (rev 225296)
@@ -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) 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-foreign-fetch-errors.https-expected.txt (225295 => 225296)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-foreign-fetch-errors.https-expected.txt	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-foreign-fetch-errors.https-expected.txt	2017-11-29 22:19:23 UTC (rev 225296)
@@ -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 
 

Modified: trunk/Source/WebCore/ChangeLog (225295 => 225296)


--- trunk/Source/WebCore/ChangeLog	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/ChangeLog	2017-11-29 22:19:23 UTC (rev 225296)
@@ -1,3 +1,42 @@
+2017-11-29  Chris Dumez  <cdu...@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  <you...@apple.com>
 
         Add support for FetchEvent.clientId

Modified: trunk/Source/WebCore/bindings/js/JSServiceWorkerGlobalScopeCustom.cpp (225295 => 225296)


--- trunk/Source/WebCore/bindings/js/JSServiceWorkerGlobalScopeCustom.cpp	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/bindings/js/JSServiceWorkerGlobalScopeCustom.cpp	2017-11-29 22:19:23 UTC (rev 225296)
@@ -37,7 +37,7 @@
 void JSServiceWorkerGlobalScope::visitAdditionalChildren(SlotVisitor& visitor)
 {
     visitor.addOpaqueRoot(&wrapped().clients());
-    visitor.addOpaqueRoot(wrapped().registration());
+    visitor.addOpaqueRoot(&wrapped().registration());
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (225295 => 225296)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2017-11-29 22:19:23 UTC (rev 225296)
@@ -422,7 +422,7 @@
 
 void ServiceWorkerContainer::addRegistration(ServiceWorkerRegistration& registration)
 {
-    m_swConnection->addServiceWorkerRegistrationInServer(registration.identifier());
+    ensureSWClientConnection().addServiceWorkerRegistrationInServer(registration.identifier());
     m_registrations.add(registration.identifier(), &registration);
 }
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContextData.cpp (225295 => 225296)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContextData.cpp	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContextData.cpp	2017-11-29 22:19:23 UTC (rev 225296)
@@ -32,7 +32,7 @@
 
 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

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContextData.h (225295 => 225296)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContextData.h	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContextData.h	2017-11-29 22:19:23 UTC (rev 225296)
@@ -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 @@
 
 struct ServiceWorkerContextData {
     ServiceWorkerJobDataIdentifier jobDataIdentifier;
-    ServiceWorkerRegistrationKey registrationKey;
+    ServiceWorkerRegistrationData registration;
     ServiceWorkerIdentifier serviceWorkerIdentifier;
     String script;
     URL scriptURL;
@@ -52,7 +52,7 @@
 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 @@
     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 @@
     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

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp (225295 => 225296)


--- trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp	2017-11-29 22:19:23 UTC (rev 225296)
@@ -30,6 +30,7 @@
 
 #include "ServiceWorkerClients.h"
 #include "ServiceWorkerThread.h"
+#include "WorkerNavigator.h"
 
 namespace WebCore {
 
@@ -36,6 +37,7 @@
 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))
 {
 }
@@ -42,12 +44,6 @@
 
 ServiceWorkerGlobalScope::~ServiceWorkerGlobalScope() = default;
 
-ServiceWorkerRegistration* ServiceWorkerGlobalScope::registration()
-{
-    // FIXME: implement this.
-    return nullptr;
-}
-
 void ServiceWorkerGlobalScope::skipWaiting(Ref<DeferredPromise>&&)
 {
 }

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.h (225295 => 225296)


--- trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.h	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.h	2017-11-29 22:19:23 UTC (rev 225296)
@@ -49,7 +49,7 @@
     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 @@
     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;
 };
 

Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (225295 => 225296)


--- trunk/Source/WebCore/workers/service/server/SWServer.cpp	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp	2017-11-29 22:19:23 UTC (rev 225296)
@@ -344,11 +344,11 @@
     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 @@
     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));

Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (225295 => 225296)


--- trunk/Source/WebCore/workers/service/server/SWServer.h	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h	2017-11-29 22:19:23 UTC (rev 225296)
@@ -121,7 +121,7 @@
     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&);

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


--- trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp	2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp	2017-11-29 22:19:23 UTC (rev 225296)
@@ -87,7 +87,7 @@
     // - 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
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to