Add and remove cookie partition accordingly in intermediary redirect requests
authorwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Oct 2017 18:57:21 +0000 (18:57 +0000)
committerwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Oct 2017 18:57:21 +0000 (18:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178369
<rdar://problem/34467603>

Reviewed by Brent Fulgham.

Source/WebCore:

Tests: http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html
       http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html

* loader/ResourceLoadObserver.h:
    Now exposes notifyObserver() so that it can be triggered
    by the TestRunner.
    Removed unimplemented ResourceLoadObserver::setShouldThrottleObserverNotifications().

Source/WebKit:

* NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::shouldChangePartition):
    Convenience function. Comment documents the logic.
(WebKit::NetworkDataTaskCocoa::willPerformHTTPRedirection):
    Now adds and removes cookie partition based on the
    redirect-to URL's domain.
* WebProcess/InjectedBundle/API/c/WKBundle.cpp:
(WKBundleResourceLoadStatisticsNotifyObserver):
    Test infrastructure.
* WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:

Tools:

Adds the function statisticsNotifyObserver().

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::statisticsNotifyObserver):
* WebKitTestRunner/InjectedBundle/InjectedBundle.h:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::statisticsNotifyObserver):
* WebKitTestRunner/InjectedBundle/TestRunner.h:

LayoutTests:

This patch adds two new tests, relevant for the code change.
Also makes changes to existing tests to increase speed and
reliability.

* http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt: Added.
* http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html: Added.
* http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
* http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html:
* http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
* http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html:
* http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
* http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html:
* http/tests/resourceLoadStatistics/remove-partitioning-from-redirect-expected.txt: Added.
* http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html: Added.
* http/tests/resourceLoadStatistics/resources/get-cookies.php: Added.
* http/tests/resourceLoadStatistics/resources/redirect.php:
* http/tests/resourceLoadStatistics/resources/set-cookie.php: Added.
* http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
* http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html:
* http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
* http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html:
* http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
* http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html:
* platform/ios/TestExpectations:
    The two new tests are marked [ Pass ].
* platform/mac-wk2/TestExpectations:
    The two new tests are marked [ Pass ].
* platform/wk2/TestExpectations:
    The two new tests are marked [ Skip ] because they require cookie partitioning.

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

35 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html
LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/resources/get-cookies.php [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/resources/redirect.php
LayoutTests/http/tests/resourceLoadStatistics/resources/set-cookie.php [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip.html
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html
LayoutTests/platform/ios/TestExpectations
LayoutTests/platform/mac-wk2/TestExpectations
LayoutTests/platform/wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/loader/ResourceLoadObserver.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm
Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp
Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp
Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

index d50ab25..5604bba 100644 (file)
@@ -1,3 +1,41 @@
+2017-10-17  John Wilander  <wilander@apple.com>
+
+        Add and remove cookie partition accordingly in intermediary redirect requests
+        https://bugs.webkit.org/show_bug.cgi?id=178369
+        <rdar://problem/34467603>
+
+        Reviewed by Brent Fulgham.
+
+        This patch adds two new tests, relevant for the code change.
+        Also makes changes to existing tests to increase speed and
+        reliability.
+
+        * http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html: Added.
+        * http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
+        * http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html:
+        * http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
+        * http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html:
+        * http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
+        * http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html:
+        * http/tests/resourceLoadStatistics/remove-partitioning-from-redirect-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html: Added.
+        * http/tests/resourceLoadStatistics/resources/get-cookies.php: Added.
+        * http/tests/resourceLoadStatistics/resources/redirect.php:
+        * http/tests/resourceLoadStatistics/resources/set-cookie.php: Added.
+        * http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
+        * http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html:
+        * http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
+        * http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html:
+        * http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html:
+        * http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html:
+        * platform/ios/TestExpectations:
+            The two new tests are marked [ Pass ].
+        * platform/mac-wk2/TestExpectations:
+            The two new tests are marked [ Pass ].
+        * platform/wk2/TestExpectations:
+            The two new tests are marked [ Skip ] because they require cookie partitioning.
+
 2017-10-17  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r223459.
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt
new file mode 100644 (file)
index 0000000..88592ed
--- /dev/null
@@ -0,0 +1,63 @@
+Tests that partitioning is added mid-flight in redirects.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
+--------
+Frame: '<!--framePath //<!--frame0-->-->'
+--------
+Should receive first-party cookie.
+Received cookie named 'firstPartyCookie'.
+Did not receive cookie named 'partitionedCookie'.
+Client-side document.cookie: firstPartyCookie=value
+
+--------
+Frame: '<!--framePath //<!--frame1-->-->'
+--------
+Redirect case, should receive first-party cookie.
+Received cookie named 'firstPartyCookie'.
+Did not receive cookie named 'partitionedCookie'.
+Client-side document.cookie: firstPartyCookie=value
+
+--------
+Frame: '<!--framePath //<!--frame2-->-->'
+--------
+Should receive no cookies.
+Did not receive cookie named 'firstPartyCookie'.
+Did not receive cookie named 'partitionedCookie'.
+Client-side document.cookie:
+
+--------
+Frame: '<!--framePath //<!--frame3-->-->'
+--------
+Redirect case, should receive no cookie.
+Did not receive cookie named 'firstPartyCookie'.
+Did not receive cookie named 'partitionedCookie'.
+Client-side document.cookie:
+
+--------
+Frame: '<!--framePath //<!--frame4-->-->'
+--------
+Set partitioned, third-party cookie.
+
+
+--------
+Frame: '<!--framePath //<!--frame5-->-->'
+--------
+Should receive partitioned cookie.
+Did not receive cookie named 'firstPartyCookie'.
+Received cookie named 'partitionedCookie'.
+Client-side document.cookie: partitionedCookie=value
+
+--------
+Frame: '<!--framePath //<!--frame6-->-->'
+--------
+Redirect case, should receive partitioned cookie.
+Did not receive cookie named 'firstPartyCookie'.
+Received cookie named 'partitionedCookie'.
+Client-side document.cookie: partitionedCookie=value
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html b/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html
new file mode 100644 (file)
index 0000000..5fc3f87
--- /dev/null
@@ -0,0 +1,108 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <script src="/js-test-resources/js-test.js"></script>
+</head>
+<body onload="runTest()">
+<script>
+    description("Tests that partitioning is added mid-flight in redirects.");
+    jsTestIsAsync = true;
+
+    function setEnableFeature(enable) {
+        if (!enable)
+            testRunner.statisticsResetToConsistentState();
+        internals.setResourceLoadStatisticsEnabled(enable);
+        testRunner.setCookieStoragePartitioningEnabled(enable);
+    }
+
+    if (document.location.hash === "") {
+        setEnableFeature(true);
+        if (testRunner.isStatisticsPrevalentResource("http://localhost"))
+            testFailed("Localhost was classified as prevalent resource before the test starts.");
+        // Make sure the network process is up-to-date.
+        testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", false);
+        testRunner.dumpChildFramesAsText();
+        document.location.hash = "step1";
+    }
+
+    const partitionHost = "127.0.0.1:8000";
+    const thirdPartyOrigin = "http://localhost:8000";
+    const resourcePath = "/resourceLoadStatistics/resources";
+    const thirdPartyBaseUrl = thirdPartyOrigin + resourcePath;
+    const firstPartyCookieName = "firstPartyCookie";
+    const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=value";
+    const partitionedCookieName = "partitionedCookie";
+    const subPathToSetPartitionedCookie = "/set-cookie.php?name=" + partitionedCookieName + "&value=value";
+    const returnUrl = "http://" + partitionHost + "/resourceLoadStatistics/add-partitioning-to-redirect.html";
+    const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + partitionedCookieName;
+    const redirectChainUrl = "http://" + partitionHost + resourcePath + "/redirect.php?redirectTo=" + thirdPartyBaseUrl + subPathToGetCookies;
+
+    function openIframe(url, onLoadHandler) {
+        const element = document.createElement("iframe");
+        element.src = url;
+        if (onLoadHandler) {
+            element.onload = onLoadHandler;
+        }
+        document.body.appendChild(element);
+    }
+
+    function runTest() {
+        switch (document.location.hash) {
+            case "#step1":
+                // Set first-party cookie for localhost.
+                document.location.href = thirdPartyBaseUrl + subPathToSetFirstPartyCookie + "#" + returnUrl + "#step2";
+                break;
+            case "#step2":
+                // Check that the cookie gets sent for localhost under 127.0.0.1 since localhost is not prevalent.
+                document.location.hash = "step3";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie.", runTest);
+                break;
+            case "#step3":
+                document.location.hash = "step4";
+                // Load an iframe in a redirect chain that starts with 127.0.0.1 and ends with localhost. Expect a cookie for localhost.
+                openIframe(redirectChainUrl + "&message=Redirect case, should receive first-party cookie.", runTest);
+                break;
+            case "#step4":
+                // Set localhost as prevalent.
+                document.location.hash = "step5";
+                testRunner.setStatisticsPrevalentResource("http://localhost", true);
+                testRunner.statisticsUpdateCookiePartitioning();
+                if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
+                    testFailed("Host did not get set as prevalent resource.");
+                runTest();
+                break;
+            case "#step5":
+                // Check that no cookie gets sent for localhost under 127.0.0.1 since localhost is partitioned.
+                document.location.hash = "step6";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies +  "&message=Should receive no cookies.", runTest);
+                break;
+            case "#step6":
+                // Load an iframe in a redirect chain that starts with 127.0.0.1 and ends with localhost. Expect no cookie for localhost.
+                document.location.hash = "step7";
+                openIframe(redirectChainUrl + "&message=Redirect case, should receive no cookie.", runTest);
+                break;
+            case "#step7":
+                // Set partitioned cookie for localhost under 127.0.0.1.
+                document.location.hash = "step8";
+                openIframe(thirdPartyBaseUrl + subPathToSetPartitionedCookie + "&message=Set partitioned, third-party cookie.", runTest);
+                break;
+            case "#step8":
+                // Check that partitioned cookie gets sent for localhost under 127.0.0.1 since localhost is partitioned.
+                document.location.hash = "step9";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies +  "&message=Should receive partitioned cookie.", runTest);
+                break;
+            case "#step9":
+                // Load an iframe in a redirect chain that starts with 127.0.0.1 and ends with localhost. Expect the partitioned cookie for localhost.
+                document.location.hash = "step10";
+                openIframe(redirectChainUrl + "&message=Redirect case, should receive partitioned cookie.", runTest);
+                break;
+            case "#step10":
+                setEnableFeature(false);
+                finishJSTest();
+                break;
+        }
+    }
+</script>
+</body>
+</html>
index 4c2e860..bc0b6f9 100644 (file)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src="/js-test-resources/js-test.js"></script>
-    <script src="/js-test-resources/ui-helper.js"></script>
     <script>
         description("Tests that redirects for a non-sandboxed iframe get counted properly.");
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
         if (testRunner) {
+            setEnableFeature(true);
             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
         }
 
-        var testPhasesDone = 0;
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
 
         function receiveMessage(event) {
             if (event.origin === "http://127.0.0.1:8000") {
                     testFailed(event.data.replace("FAIL ", ""));
             } else
                 testFailed("Received a message from an unexpected origin: " + event.origin);
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
         }
 
         function checkStats() {
             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
         }
     </script>
 </head>
 <body>
-<iframe src="http://127.0.0.1:8000/resourceLoadStatistics/resources/redirect.php/?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/redirect.php/?redirectTo=http://127.0.0.1:8000/resourceLoadStatistics/resources/iframe-report-back-loaded.html">
+<iframe src="http://127.0.0.1:8000/resourceLoadStatistics/resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/redirect.php/?redirectTo=http://127.0.0.1:8000/resourceLoadStatistics/resources/iframe-report-back-loaded.html">
 </iframe>
 </body>
 </html>
\ No newline at end of file
index 2d86605..d382c72 100644 (file)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src="/js-test-resources/js-test.js"></script>
-    <script src="/js-test-resources/ui-helper.js"></script>
     <script>
         description("Tests that redirects for a non-sandboxed iframe get counted properly.");
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
         if (testRunner) {
+            setEnableFeature(true);
             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
         }
 
-        var testPhasesDone = 0;
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
 
         function receiveMessage(event) {
             if (event.origin === "http://localhost:8000") {
                     testFailed(event.data.replace("FAIL ", ""));
             } else
                 testFailed("Received a message from an unexpected origin: " + event.origin);
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
         }
 
         function checkStats() {
             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
         }
     </script>
 </head>
index 6eb223a..08fc514 100644 (file)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src="/js-test-resources/js-test.js"></script>
-    <script src="/js-test-resources/ui-helper.js"></script>
     <script>
         description("Tests that redirects for a non-sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
         if (testRunner) {
+            setEnableFeature(true);
             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
         }
 
-        var testPhasesDone = 0;
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
 
         function receiveMessage(event) {
             if (event.origin === "http://127.0.0.1:8000") {
                     testFailed(event.data.replace("FAIL ", ""));
             } else
                 testFailed("Received a message from an unexpected origin: " + event.origin);
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
         }
 
         function checkStats() {
             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
         }
     </script>
 </head>
index f23acd4..67f89a4 100644 (file)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src="/js-test-resources/js-test.js"></script>
-    <script src="/js-test-resources/ui-helper.js"></script>
     <script>
         description("Tests that redirects for a non-sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
         if (testRunner) {
+            setEnableFeature(true);
             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
         }
 
-        var testPhasesDone = 0;
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
 
         function receiveMessage(event) {
             if (event.origin === "http://localhost:8000") {
                     testFailed(event.data.replace("FAIL ", ""));
             } else
                 testFailed("Received a message from an unexpected origin: " + event.origin);
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
         }
 
         function checkStats() {
             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
         }
     </script>
 </head>
index ea52c38..4dc0f59 100644 (file)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src="/js-test-resources/js-test.js"></script>
-    <script src="/js-test-resources/ui-helper.js"></script>
     <script>
         description("Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
         if (testRunner) {
+            setEnableFeature(true);
             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
         }
 
-        var testPhasesDone = 0;
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
 
         function receiveMessage(event) {
             if (event.origin === "null") {
                     testFailed(event.data.replace("FAIL ", ""));
             } else
                 testFailed("Received a message from an unexpected origin: " + event.origin);
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
         }
 
         function checkStats() {
             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
         }
     </script>
 </head>
index 653bdeb..65d35e6 100644 (file)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src="/js-test-resources/js-test.js"></script>
-    <script src="/js-test-resources/ui-helper.js"></script>
     <script>
         description("Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
         if (testRunner) {
+            setEnableFeature(true);
             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
         }
 
-        var testPhasesDone = 0;
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
 
         function receiveMessage(event) {
             if (event.origin === "null") {
                     testFailed(event.data.replace("FAIL ", ""));
             } else
                 testFailed("Received a message from an unexpected origin: " + event.origin);
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
         }
 
         function checkStats() {
             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
         }
     </script>
 </head>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect-expected.txt
new file mode 100644 (file)
index 0000000..6922b06
--- /dev/null
@@ -0,0 +1,25 @@
+Tests that partitioning is removed mid-flight in redirects.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
+--------
+Frame: '<!--framePath //<!--frame0-->-->'
+--------
+Should receive first-party cookie.
+Received cookie named 'firstPartyCookie'.
+Did not receive cookie named 'partitionedCookie'.
+Client-side document.cookie: firstPartyCookie=value
+
+--------
+Frame: '<!--framePath //<!--frame1-->-->'
+--------
+Redirect case, should receive first-party cookie.
+Received cookie named 'firstPartyCookie'.
+Did not receive cookie named 'partitionedCookie'.
+Client-side document.cookie: firstPartyCookie=value
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html b/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html
new file mode 100644 (file)
index 0000000..e1e09d7
--- /dev/null
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <script src="/js-test-resources/js-test.js"></script>
+</head>
+<body onload="runTest()">
+<script>
+    description("Tests that partitioning is removed mid-flight in redirects.");
+    jsTestIsAsync = true;
+
+    function setEnableFeature(enable) {
+        if (!enable)
+            testRunner.statisticsResetToConsistentState();
+        internals.setResourceLoadStatisticsEnabled(enable);
+        testRunner.setCookieStoragePartitioningEnabled(enable);
+    }
+
+    if (document.location.hash === "") {
+        setEnableFeature(true);
+        if (testRunner.isStatisticsPrevalentResource("http://localhost"))
+            testFailed("Localhost was classified as prevalent resource before the test starts.");
+        testRunner.dumpChildFramesAsText();
+        document.location.hash = "step1";
+    }
+
+    const partitionHost = "127.0.0.1:8000";
+    const thirdPartyOrigin = "http://localhost:8000";
+    const resourcePath = "/resourceLoadStatistics/resources";
+    const thirdPartyBaseUrl = thirdPartyOrigin + resourcePath;
+    const partitionBaseUrl = "http://" + partitionHost + resourcePath;
+    const firstPartyCookieName = "firstPartyCookie";
+    const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=value";
+    const partitionedCookieName = "partitionedCookie";
+    const returnUrl = "http://" + partitionHost + "/resourceLoadStatistics/remove-partitioning-from-redirect.html";
+    const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + partitionedCookieName;
+    const redirectChainUrl = thirdPartyBaseUrl + "/redirect.php?redirectTo=" + partitionBaseUrl + subPathToGetCookies;
+
+    function openIframe(url, onLoadHandler) {
+        const element = document.createElement("iframe");
+        element.src = url;
+        if (onLoadHandler) {
+            element.onload = onLoadHandler;
+        }
+        document.body.appendChild(element);
+    }
+
+    function runTest() {
+        switch (document.location.hash) {
+            case "#step1":
+                // Set localhost as prevalent.
+                document.location.hash = "step2";
+                testRunner.setStatisticsPrevalentResource("http://localhost", true);
+                testRunner.statisticsUpdateCookiePartitioning();
+                if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
+                    testFailed("Host did not get set as prevalent resource.");
+                runTest();
+                break;
+            case "#step2":
+                // Set first-party cookie for 127.0.0.1.
+                document.location.href = partitionBaseUrl + subPathToSetFirstPartyCookie + "#" + returnUrl + "#step3";
+                break;
+            case "#step3":
+                // Check that the cookie gets sent for 127.0.0.1 under 127.0.0.1.
+                document.location.hash = "step4";
+                openIframe(partitionBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie.", runTest);
+                break;
+            case "#step4":
+                document.location.hash = "step5";
+                // Load an iframe in a redirect chain that starts with localhost and ends with 127.0.0.1. Expect a cookie for 127.0.0.1.
+                openIframe(redirectChainUrl + "&message=Redirect case, should receive first-party cookie.", runTest);
+                break;
+            case "#step5":
+                setEnableFeature(false);
+                finishJSTest();
+                break;
+        }
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/resources/get-cookies.php b/LayoutTests/http/tests/resourceLoadStatistics/resources/get-cookies.php
new file mode 100644 (file)
index 0000000..dad8b5a
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+echo $_GET["message"] . "<br>";
+if(!isset($_COOKIE[$_GET["name1"]])) {
+    echo "Did not receive cookie named '" . $_GET["name1"] . "'.<br>";
+} else {
+    echo "Received cookie named '" . $_GET["name1"] . "'.<br>";
+}
+if(!isset($_COOKIE[$_GET["name2"]])) {
+    echo "Did not receive cookie named '" . $_GET["name2"] . "'.<br>";
+} else {
+    echo "Received cookie named '" . $_GET["name2"] . "'.<br>";
+}
+if(!empty($_GET["name3"])) {
+    if(!isset($_COOKIE[$_GET["name3"]])) {
+        echo "Did not receive cookie named '" . $_GET["name3"] . "'.<br>";
+    } else {
+        echo "Received cookie named '" . $_GET["name3"] . "'.<br>";
+    }
+}
+?>
+<p id="output"></p>
+<script>
+    document.getElementById("output").textContent = "Client-side document.cookie: " + document.cookie;
+</script>
\ No newline at end of file
index ebf396c..646cb4b 100644 (file)
@@ -1,4 +1,14 @@
 <?php
-header('Location: ' . $_GET["redirectTo"]);
+$redirectURL = $_GET["redirectTo"];
+if (isset($_GET["name2"])) {
+    $redirectURL = $redirectURL . "&name2=" . $_GET["name2"];
+}
+if (isset($_GET["name3"])) {
+    $redirectURL = $redirectURL . "&name3=" . $_GET["name3"];
+}
+if (isset($_GET["message"])) {
+    $redirectURL = $redirectURL . "&message=" . $_GET["message"];
+}
+header('Location: ' . $redirectURL);
 die();
 ?>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/resources/set-cookie.php b/LayoutTests/http/tests/resourceLoadStatistics/resources/set-cookie.php
new file mode 100644 (file)
index 0000000..3339e9b
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+setcookie($_GET["name"], $_GET["value"], (time()+60*60*24*30), "/");
+echo $_GET["message"] . "<br>";
+?>
+<script>
+if (document.location.hash) {
+    setTimeout("document.location.href = document.location.hash.substring(1)", 10);
+}
+</script>
\ No newline at end of file
index f16392e..bbfea17 100644 (file)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src="/js-test-resources/js-test.js"></script>
-    <script src="/js-test-resources/ui-helper.js"></script>
     <script>
         description("Tests that redirects for sandboxed iframes get counted properly.");
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
         if (testRunner) {
+            setEnableFeature(true);
             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
         }
 
-        var testPhasesDone = 0;
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
 
         function receiveMessage(event) {
             if (event.origin === "null") {
                     testFailed(event.data.replace("FAIL ", ""));
             } else
                 testFailed("Received a message from an unexpected origin: " + event.origin);
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
         }
 
         function checkStats() {
             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
         }
     </script>
 </head>
index 31b029e..75b567f 100644 (file)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src="/js-test-resources/js-test.js"></script>
-    <script src="/js-test-resources/ui-helper.js"></script>
     <script>
         description("Tests that redirects for sandboxed iframes get counted properly.");
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
         if (testRunner) {
+            setEnableFeature(true);
             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
         }
 
-        var testPhasesDone = 0;
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
 
         function receiveMessage(event) {
             if (event.origin === "null") {
                     testFailed(event.data.replace("FAIL ", ""));
             } else
                 testFailed("Received a message from an unexpected origin: " + event.origin);
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
         }
 
         function checkStats() {
             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
         }
     </script>
 </head>
index 80acd36..84a0c69 100644 (file)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src="/js-test-resources/js-test.js"></script>
-    <script src="/js-test-resources/ui-helper.js"></script>
     <script>
         description("Tests that redirects for a non-sandboxed iframe nested in a sandboxed iframe get counted properly.");
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
         if (testRunner) {
+            setEnableFeature(true);
             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
         }
 
-        var testPhasesDone = 0;
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
 
         function receiveMessage(event) {
             if (event.origin === "null") {
                     testFailed(event.data.replace("FAIL ", ""));
             } else
                 testFailed("Received a message from an unexpected origin: " + event.origin);
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
         }
 
         function checkStats() {
             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
         }
     </script>
 </head>
index 5ea8113..56a4f1e 100644 (file)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src="/js-test-resources/js-test.js"></script>
-    <script src="/js-test-resources/ui-helper.js"></script>
     <script>
         description("Tests that redirects for a non-sandboxed iframe nested in a sandboxed iframe get counted properly.");
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
         if (testRunner) {
+            setEnableFeature(true);
             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
         }
 
-        var testPhasesDone = 0;
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
 
         function receiveMessage(event) {
             if (event.origin === "null") {
                     testFailed(event.data.replace("FAIL ", ""));
             } else
                 testFailed("Received a message from an unexpected origin: " + event.origin);
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
         }
 
         function checkStats() {
             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
         }
     </script>
 </head>
index 38e0cc8..958d267 100644 (file)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src="/js-test-resources/js-test.js"></script>
-    <script src="/js-test-resources/ui-helper.js"></script>
     <script>
         description("Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
         if (testRunner) {
+            setEnableFeature(true);
             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
         }
 
-        var testPhasesDone = 0;
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
 
         function receiveMessage(event) {
             if (event.origin === "null") {
                     testFailed(event.data.replace("FAIL ", ""));
             } else
                 testFailed("Received a message from an unexpected origin: " + event.origin);
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
         }
 
         function checkStats() {
             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
         }
     </script>
 </head>
index 89e2f83..af7408c 100644 (file)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src="/js-test-resources/js-test.js"></script>
-    <script src="/js-test-resources/ui-helper.js"></script>
     <script>
         description("Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
         if (testRunner) {
+            setEnableFeature(true);
             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
         }
 
-        var testPhasesDone = 0;
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
 
         function receiveMessage(event) {
             if (event.origin === "null") {
                     testFailed(event.data.replace("FAIL ", ""));
             } else
                 testFailed("Received a message from an unexpected origin: " + event.origin);
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
         }
 
         function checkStats() {
             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
         }
     </script>
 </head>
index 24be28f..25baf21 100644 (file)
@@ -2782,6 +2782,9 @@ fast/canvas/webgl/texImage2D-video-flipY-false.html [ Skip ]
 fast/canvas/webgl/texImage2D-video-flipY-true.html [ Skip ]
 
 webkit.org/b/174120 http/tests/loading/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame.html [ Skip ]
+# Skipped in WK2 expectations because cookie partitioning is only available in macOS High Sierra and iOS 11.
+http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html [ Pass ]
+http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html [ Pass ]
 
 webkit.org/b/175273 imported/w3c/web-platform-tests/html/browsers/windows/noreferrer-window-name.html [ Failure ]
 
index 097d68f..c16d2be 100644 (file)
@@ -807,6 +807,8 @@ webkit.org/b/176122 media/video-controls-drop-and-restore-timeline.html [ Pass F
 [ HighSierra+ ] http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html [ Pass ]
 [ HighSierra+ ] http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html [ Pass Failure ]
 [ HighSierra+ ] http/tests/loading/resourceLoadStatistics/third-party-cookie-with-and-without-user-interaction.html [ Pass Failure ]
+[ HighSierra+ ] http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html [ Pass ]
+[ HighSierra+ ] http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html [ Pass ]
 
 # <rdar://problem/33555759>
 webkit.org/b/177616 [ HighSierra+ ] http/tests/media/video-buffered-range-contains-currentTime.html [ Pass Timeout ]
index 59300c0..402f73a 100644 (file)
@@ -691,6 +691,10 @@ webkit.org/b/173499 http/tests/loading/resourceLoadStatistics/telemetry-generati
 http/tests/loading/resourceLoadStatistics/prune-statistics.html [ Pass ]
 http/tests/storageAccess/request-storage-access-top-frame.html [ Pass ]
 http/tests/resourceLoadStatistics [ Pass ]
+# Cookie partitioning is only supported in macOS High Sierra and iOS 11.
+http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html [ Skip ]
+http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html [ Skip ]
+
 
 ### END OF (5) Progressions, expected successes that are expected failures in WebKit1.
 ########################################
index 6b0c31c..88f15a1 100644 (file)
@@ -1,3 +1,19 @@
+2017-10-17  John Wilander  <wilander@apple.com>
+
+        Add and remove cookie partition accordingly in intermediary redirect requests
+        https://bugs.webkit.org/show_bug.cgi?id=178369
+        <rdar://problem/34467603>
+
+        Reviewed by Brent Fulgham.
+
+        Tests: http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html
+               http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html
+
+        * loader/ResourceLoadObserver.h:
+            Now exposes notifyObserver() so that it can be triggered
+            by the TestRunner.
+            Removed unimplemented ResourceLoadObserver::setShouldThrottleObserverNotifications().
+
 2017-10-17  Jer Noble  <jer.noble@apple.com>
 
         Corrupted image after looping movie-backed <img>.
index fbf1a1f..29b9cb5 100644 (file)
@@ -53,8 +53,6 @@ class ResourceLoadObserver {
 public:
     WEBCORE_EXPORT static ResourceLoadObserver& shared();
 
-    WEBCORE_EXPORT void setShouldThrottleObserverNotifications(bool);
-    
     void logFrameNavigation(const Frame&, const Frame& topFrame, const ResourceRequest& newRequest, const URL& redirectUrl);
     void logSubresourceLoading(const Frame*, const ResourceRequest& newRequest, const ResourceResponse& redirectResponse);
     void logWebSocketLoading(const Frame*, const URL&);
@@ -64,6 +62,7 @@ public:
 
     WEBCORE_EXPORT void setNotificationCallback(WTF::Function<void (Vector<ResourceLoadStatistics>&&)>&&);
 
+    WEBCORE_EXPORT void notifyObserver();
     WEBCORE_EXPORT void clearState();
 private:
     ResourceLoadObserver();
@@ -72,7 +71,6 @@ private:
     ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
 
     void scheduleNotificationIfNeeded();
-    void notifyObserver();
     Vector<ResourceLoadStatistics> takeStatistics();
 
     HashMap<String, ResourceLoadStatistics> m_resourceStatisticsMap;
index 27ee09e..fd00148 100644 (file)
@@ -1,3 +1,22 @@
+2017-10-17  John Wilander  <wilander@apple.com>
+
+        Add and remove cookie partition accordingly in intermediary redirect requests
+        https://bugs.webkit.org/show_bug.cgi?id=178369
+        <rdar://problem/34467603>
+
+        Reviewed by Brent Fulgham.
+
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
+        (WebKit::shouldChangePartition):
+            Convenience function. Comment documents the logic.
+        (WebKit::NetworkDataTaskCocoa::willPerformHTTPRedirection):
+            Now adds and removes cookie partition based on the
+            redirect-to URL's domain.
+        * WebProcess/InjectedBundle/API/c/WKBundle.cpp:
+        (WKBundleResourceLoadStatisticsNotifyObserver):
+            Test infrastructure.
+        * WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:
+
 2017-10-17  Youenn Fablet  <youenn@apple.com>
 
         Cache API implementation should be able to compute storage size for WebKit client applications.
index 09ff28d..f77214b 100644 (file)
@@ -196,6 +196,16 @@ void NetworkDataTaskCocoa::didReceiveData(Ref<WebCore::SharedBuffer>&& data)
         m_client->didReceiveData(WTFMove(data));
 }
 
+static bool shouldChangePartition(const String& requiredStoragePartition, const String& currentStoragePartition)
+{
+    // The need for a partion change is according to the following:
+    //      currentStoragePartition:  null  ""    abc
+    // requiredStoragePartition: ""   false false true
+    //                           abc  true  true  false
+    //                           xyz  true  true  true
+    return !((requiredStoragePartition.isEmpty() && currentStoragePartition.isEmpty()) || currentStoragePartition == requiredStoragePartition);
+}
+
 void NetworkDataTaskCocoa::willPerformHTTPRedirection(WebCore::ResourceResponse&& redirectResponse, WebCore::ResourceRequest&& request, RedirectCompletionHandler&& completionHandler)
 {
     if (redirectResponse.httpStatusCode() == 307 || redirectResponse.httpStatusCode() == 308) {
@@ -240,6 +250,16 @@ void NetworkDataTaskCocoa::willPerformHTTPRedirection(WebCore::ResourceResponse&
 #endif
     }
     
+#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
+    if (m_storedCredentialsPolicy == WebCore::StoredCredentialsPolicy::Use) {
+        String requiredStoragePartition = m_session->networkStorageSession().cookieStoragePartition(request);
+        if (shouldChangePartition(requiredStoragePartition, m_task.get()._storagePartitionIdentifier)) {
+            LOG(NetworkSession, "%llu %s cookies for redirected URL %s", [m_task taskIdentifier], (requiredStoragePartition.isEmpty() ? "Not partitioning" : "Partitioning"), request.url().string().utf8().data());
+            m_task.get()._storagePartitionIdentifier = requiredStoragePartition;
+        }
+    }
+#endif
+
     if (m_client)
         m_client->willPerformHTTPRedirection(WTFMove(redirectResponse), WTFMove(request), WTFMove(completionHandler));
     else {
index 34bce00..fbeed5b 100644 (file)
@@ -282,3 +282,8 @@ void WKBundleClearResourceLoadStatistics(WKBundleRef)
 {
     ResourceLoadObserver::shared().clearState();
 }
+
+void WKBundleResourceLoadStatisticsNotifyObserver(WKBundleRef)
+{
+    ResourceLoadObserver::shared().notifyObserver();
+}
index 9b58a9e..e424228 100644 (file)
@@ -92,6 +92,7 @@ WK_EXPORT bool WKBundleIsProcessingUserGesture(WKBundleRef bundle);
 WK_EXPORT void WKBundleSetTabKeyCyclesThroughElements(WKBundleRef bundle, WKBundlePageRef page, bool enabled);
 
 WK_EXPORT void WKBundleClearResourceLoadStatistics(WKBundleRef);
+WK_EXPORT void WKBundleResourceLoadStatisticsNotifyObserver(WKBundleRef);
 
 #ifdef __cplusplus
 }
index fd45555..e8d3f8f 100644 (file)
@@ -1,3 +1,21 @@
+2017-10-17  John Wilander  <wilander@apple.com>
+
+        Add and remove cookie partition accordingly in intermediary redirect requests
+        https://bugs.webkit.org/show_bug.cgi?id=178369
+        <rdar://problem/34467603>
+
+        Reviewed by Brent Fulgham.
+
+        Adds the function statisticsNotifyObserver().
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::statisticsNotifyObserver):
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::statisticsNotifyObserver):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+
 2017-10-17  Youenn Fablet  <youenn@apple.com>
 
         Cache API implementation should be able to compute storage size for WebKit client applications.
index 9f91dfd..d178fec 100644 (file)
@@ -278,6 +278,7 @@ interface TestRunner {
     void setStatisticsSubresourceUniqueRedirectTo(DOMString hostName, DOMString hostNameRedirectedTo);
     void setStatisticsTimeToLiveUserInteraction(double seconds);
     void setStatisticsTimeToLiveCookiePartitionFree(double seconds);
+    void statisticsNotifyObserver();
     void statisticsProcessStatisticsAndDataRecords();
     void statisticsUpdateCookiePartitioning();
     void statisticsSetShouldPartitionCookiesForHost(DOMString hostName, boolean value);
index d6108e2..c9339f0 100644 (file)
@@ -840,4 +840,9 @@ void InjectedBundle::setAllowsAnySSLCertificate(bool allowsAnySSLCertificate)
     WebCoreTestSupport::setAllowsAnySSLCertificate(allowsAnySSLCertificate);
 }
 
+void InjectedBundle::statisticsNotifyObserver()
+{
+    WKBundleResourceLoadStatisticsNotifyObserver(m_bundle);
+}
+
 } // namespace WTR
index ad20d70..0432313 100644 (file)
@@ -133,7 +133,9 @@ public:
     unsigned imageCountInGeneralPasteboard() const;
 
     void setAllowsAnySSLCertificate(bool);
-    
+
+    void statisticsNotifyObserver();
+
 private:
     InjectedBundle();
     ~InjectedBundle();
index ef75379..07239dd 100644 (file)
@@ -1518,7 +1518,12 @@ void TestRunner::statisticsDidRunTelemetryCallback(unsigned totalPrevalentResour
     
     callTestRunnerCallback(StatisticsDidRunTelemetryCallbackID, 1, &result);
 }
-    
+
+void TestRunner::statisticsNotifyObserver()
+{
+    InjectedBundle::singleton().statisticsNotifyObserver();
+}
+
 void TestRunner::statisticsProcessStatisticsAndDataRecords()
 {
     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsProcessStatisticsAndDataRecords"));
index 8c4c9c6..9ff81b6 100644 (file)
@@ -363,6 +363,7 @@ public:
     void statisticsDidModifyDataRecordsCallback();
     void statisticsDidScanDataRecordsCallback();
     void statisticsDidRunTelemetryCallback(unsigned totalPrevalentResources, unsigned totalPrevalentResourcesWithUserInteraction, unsigned top3SubframeUnderTopFrameOrigins);
+    void statisticsNotifyObserver();
     void statisticsProcessStatisticsAndDataRecords();
     void statisticsUpdateCookiePartitioning();
     void statisticsSetShouldPartitionCookiesForHost(JSStringRef hostName, bool value);