Title: [229086] trunk
Revision
229086
Author
[email protected]
Date
2018-02-27 18:28:15 -0800 (Tue, 27 Feb 2018)

Log Message

Do not trigger a service worker match in case of document redirection if it will be already served by AppCache
https://bugs.webkit.org/show_bug.cgi?id=183185
<rdar://problem/37693796>

Patch by Youenn Fablet <[email protected]> on 2018-02-27
Reviewed by Chris Dumez.

Source/WebCore:

Disabling service worker matching in case there is a substitute data.
Otherwise there is a risk for a double load, substitute data first and the new load
triggered if matching a new registration.
A future fix should first do service worker registration matching and if there is no registration query appcache.

Test: http/tests/appcache/main-resource-redirect-with-sw.html

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::redirectReceived):

LayoutTests:

* http/tests/appcache/main-resource-redirect-with-sw-expected.txt: Added.
* http/tests/appcache/main-resource-redirect-with-sw.html: Added.
* http/tests/appcache/resources/main-resource-redirect-with-sw.manifest: Added.
* http/tests/appcache/resources/register-resources-service-worker.html: Added.
* http/tests/appcache/service-worker-proxy.js: Added.
* platform/gtk/TestExpectations:
* platform/mac-wk1/TestExpectations:
* platform/win/TestExpectations:
* platform/wpe/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (229085 => 229086)


--- trunk/LayoutTests/ChangeLog	2018-02-28 02:05:59 UTC (rev 229085)
+++ trunk/LayoutTests/ChangeLog	2018-02-28 02:28:15 UTC (rev 229086)
@@ -1,3 +1,21 @@
+2018-02-27  Youenn Fablet  <[email protected]>
+
+        Do not trigger a service worker match in case of document redirection if it will be already served by AppCache
+        https://bugs.webkit.org/show_bug.cgi?id=183185
+        <rdar://problem/37693796>
+
+        Reviewed by Chris Dumez.
+
+        * http/tests/appcache/main-resource-redirect-with-sw-expected.txt: Added.
+        * http/tests/appcache/main-resource-redirect-with-sw.html: Added.
+        * http/tests/appcache/resources/main-resource-redirect-with-sw.manifest: Added.
+        * http/tests/appcache/resources/register-resources-service-worker.html: Added.
+        * http/tests/appcache/service-worker-proxy.js: Added.
+        * platform/gtk/TestExpectations:
+        * platform/mac-wk1/TestExpectations:
+        * platform/win/TestExpectations:
+        * platform/wpe/TestExpectations:
+
 2018-02-27  Ryan Haddad  <[email protected]>
 
         Mark http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html as flaky.

Added: trunk/LayoutTests/http/tests/appcache/main-resource-redirect-with-sw-expected.txt (0 => 229086)


--- trunk/LayoutTests/http/tests/appcache/main-resource-redirect-with-sw-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/appcache/main-resource-redirect-with-sw-expected.txt	2018-02-28 02:28:15 UTC (rev 229086)
@@ -0,0 +1,2 @@
+CONSOLE MESSAGE: line 1: ApplicationCache is deprecated. Please use ServiceWorkers instead.
+PASS

Added: trunk/LayoutTests/http/tests/appcache/main-resource-redirect-with-sw.html (0 => 229086)


--- trunk/LayoutTests/http/tests/appcache/main-resource-redirect-with-sw.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/appcache/main-resource-redirect-with-sw.html	2018-02-28 02:28:15 UTC (rev 229086)
@@ -0,0 +1,52 @@
+<html manifest="resources/main-resource-redirect-with-sw.manifest">
+<body>
+<p>Test that application cache and service worker do not mess with each other in case of redirections.</p>
+<div id="result">Testing...</div>
+<script>
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+    testRunner.setShouldDecideNavigationPolicyAfterDelay(true);
+}
+
+var serviceWorkerIframe;
+function prepareTest()
+{
+    serviceWorkerIframe = document.createElement("iframe");
+    serviceWorkerIframe.setAttribute("src", "/appcache/resources/register-resources-service-worker.html");
+    document.body.appendChild(serviceWorkerIframe);
+    serviceWorkerIframe._onload_ = async (e) => {
+        try {
+            await serviceWorkerIframe.contentWindow.registerServiceWorker();
+        } catch (e) {
+            console.log(e);
+        }
+        test();
+    };
+}
+
+function test()
+{
+    applicationCache._oncached_ = null;
+    applicationCache._onnoupdate_ = null;
+    var iframe = document.createElement("iframe");
+    iframe.setAttribute("src", "/resources/redirect.php?url=""
+    document.body.appendChild(iframe);
+    iframe._onload_ = done;
+}
+
+function done()
+{
+    applicationCache._onerror_ = null;
+    // We wait some small time to ensure that the frame loading does not trigger two concurrent loads.
+    setTimeout(() => {
+        window.document.body.innerHTML = "PASS";
+        if (window.testRunner)
+            testRunner.notifyDone();
+    }, 10);
+}
+
+applicationCache._oncached_=prepareTest;
+applicationCache._onnoupdate_=prepareTest;
+</script>
+</body>

Added: trunk/LayoutTests/http/tests/appcache/resources/main-resource-redirect-with-sw.manifest (0 => 229086)


--- trunk/LayoutTests/http/tests/appcache/resources/main-resource-redirect-with-sw.manifest	                        (rev 0)
+++ trunk/LayoutTests/http/tests/appcache/resources/main-resource-redirect-with-sw.manifest	2018-02-28 02:28:15 UTC (rev 229086)
@@ -0,0 +1,2 @@
+CACHE MANIFEST
+http://127.0.0.1:8000/appcache/resources/simple.txt

Added: trunk/LayoutTests/http/tests/appcache/resources/register-resources-service-worker.html (0 => 229086)


--- trunk/LayoutTests/http/tests/appcache/resources/register-resources-service-worker.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/appcache/resources/register-resources-service-worker.html	2018-02-28 02:28:15 UTC (rev 229086)
@@ -0,0 +1,22 @@
+<html>
+<body>
+<script>
+var scope = "/appcache/resources";
+var script = "/appcache/service-worker-proxy.js";
+
+async function registerServiceWorker()
+{
+    var registration = await navigator.serviceWorker.register(script, { scope : scope });
+    await new Promise(resolve => {
+        if (registration.active)
+            resolve(registration);
+        worker = registration.installing;
+        worker.addEventListener("statechange", () => {
+            if (worker.state === "activated")
+                resolve(registration);
+        });
+    });
+}
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/appcache/service-worker-proxy.js (0 => 229086)


--- trunk/LayoutTests/http/tests/appcache/service-worker-proxy.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/appcache/service-worker-proxy.js	2018-02-28 02:28:15 UTC (rev 229086)
@@ -0,0 +1,3 @@
+self.addEventListener("fetch", (event) => {
+    event.respondWith(fetch(event.request));
+});

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (229085 => 229086)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2018-02-28 02:05:59 UTC (rev 229085)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2018-02-28 02:28:15 UTC (rev 229086)
@@ -1129,6 +1129,7 @@
 webkit.org/b/175419 http/wpt/service-workers [ Failure ]
 webkit.org/b/175419 http/tests/inspector/network/resource-response-service-worker.html [ Skip ]
 webkit.org/b/175419 imported/w3c/web-platform-tests/service-workers [ Skip ]
+http/tests/appcache/main-resource-redirect-with-sw.html [ Skip ]
 
 # Skip anything related to WebAuthN
 http/tests/webauthn/ [ Skip ]

Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (229085 => 229086)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2018-02-28 02:05:59 UTC (rev 229085)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2018-02-28 02:28:15 UTC (rev 229086)
@@ -132,6 +132,7 @@
 http/wpt/cache-storage [ Skip ]
 http/tests/cache-storage [ Skip ]
 imported/w3c/web-platform-tests/streams/readable-byte-streams/detached-buffers.serviceworker.https.html [ Skip ]
+http/tests/appcache/main-resource-redirect-with-sw.html [ Skip ]
 
 # Skip WebRTC for now in WK1
 imported/w3c/web-platform-tests/webrtc [ Skip ]

Modified: trunk/LayoutTests/platform/win/TestExpectations (229085 => 229086)


--- trunk/LayoutTests/platform/win/TestExpectations	2018-02-28 02:05:59 UTC (rev 229085)
+++ trunk/LayoutTests/platform/win/TestExpectations	2018-02-28 02:28:15 UTC (rev 229086)
@@ -3715,6 +3715,7 @@
 imported/w3c/web-platform-tests/service-workers [ Skip ]
 http/tests/cache-storage [ Skip ]
 http/wpt/cache-storage [ Skip ]
+http/tests/appcache/main-resource-redirect-with-sw.html [ Skip ]
 
 
 # Flaky tests on Windows:

Modified: trunk/LayoutTests/platform/wpe/TestExpectations (229085 => 229086)


--- trunk/LayoutTests/platform/wpe/TestExpectations	2018-02-28 02:05:59 UTC (rev 229085)
+++ trunk/LayoutTests/platform/wpe/TestExpectations	2018-02-28 02:28:15 UTC (rev 229086)
@@ -1056,6 +1056,7 @@
 webkit.org/b/175419 http/tests/inspector/network/resource-response-service-worker.html [ Skip ]
 webkit.org/b/178576 http/wpt/service-workers [ Failure ]
 webkit.org/b/178576 imported/w3c/web-platform-tests/service-workers [ Skip ]
+http/tests/appcache/main-resource-redirect-with-sw.html [ Skip ]
 
 webkit.org/b/178316 imported/w3c/web-platform-tests/service-workers/cache-storage [ Skip ]
 webkit.org/b/178316 http/wpt/cache-storage [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (229085 => 229086)


--- trunk/Source/WebCore/ChangeLog	2018-02-28 02:05:59 UTC (rev 229085)
+++ trunk/Source/WebCore/ChangeLog	2018-02-28 02:28:15 UTC (rev 229086)
@@ -1,3 +1,21 @@
+2018-02-27  Youenn Fablet  <[email protected]>
+
+        Do not trigger a service worker match in case of document redirection if it will be already served by AppCache
+        https://bugs.webkit.org/show_bug.cgi?id=183185
+        <rdar://problem/37693796>
+
+        Reviewed by Chris Dumez.
+
+        Disabling service worker matching in case there is a substitute data.
+        Otherwise there is a risk for a double load, substitute data first and the new load
+        triggered if matching a new registration.
+        A future fix should first do service worker registration matching and if there is no registration query appcache.
+
+        Test: http/tests/appcache/main-resource-redirect-with-sw.html
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::redirectReceived):
+
 2018-02-27  Tim Horton  <[email protected]>
 
         Ensure target triple is propagated correctly to DerivedSources.make

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (229085 => 229086)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2018-02-28 02:05:59 UTC (rev 229085)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2018-02-28 02:28:15 UTC (rev 229086)
@@ -519,7 +519,7 @@
 #if ENABLE(SERVICE_WORKER)
     bool isRedirectionFromServiceWorker = redirectResponse.source() == ResourceResponse::Source::ServiceWorker;
     willSendRequest(WTFMove(request), redirectResponse, [isRedirectionFromServiceWorker, completionHandler = WTFMove(completionHandler), protectedThis = makeRef(*this), this] (auto&& request) mutable {
-        if (request.isNull() || !m_mainDocumentError.isNull() || !m_frame) {
+        if (request.isNull() || !m_mainDocumentError.isNull() || !m_frame || m_substituteData.isValid()) {
             completionHandler({ });
             return;
         }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to