Title: [223722] branches/safari-604-branch
Revision
223722
Author
jmarc...@apple.com
Date
2017-10-19 16:11:55 -0700 (Thu, 19 Oct 2017)

Log Message

Cherry-pick r223565. rdar://problem/35041490

Modified Paths

Added Paths

Diff

Modified: branches/safari-604-branch/LayoutTests/ChangeLog (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/ChangeLog	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/ChangeLog	2017-10-19 23:11:55 UTC (rev 223722)
@@ -1,5 +1,47 @@
 2017-10-19  Jason Marcell  <jmarc...@apple.com>
 
+        Cherry-pick r223565. rdar://problem/35041490
+
+    2017-10-17  John Wilander  <wilan...@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-19  Jason Marcell  <jmarc...@apple.com>
+
         Cherry-pick r223253. rdar://problem/35077489
 
     2017-10-12  John Wilander  <wilan...@apple.com>

Added: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt (0 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt	                        (rev 0)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt	2017-10-19 23:11:55 UTC (rev 223722)
@@ -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

Added: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html (0 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html	                        (rev 0)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -0,0 +1,108 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <script src=""
+</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 = ""
+        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 = "" + 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>

Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src=""
-    <script src=""
     <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") {
@@ -20,9 +34,12 @@
                     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() {
@@ -29,14 +46,15 @@
             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=""
+<iframe src=""
 </iframe>
 </body>
 </html>
\ No newline at end of file

Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src=""
-    <script src=""
     <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") {
@@ -20,9 +34,12 @@
                     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() {
@@ -29,9 +46,10 @@
             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>

Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src=""
-    <script src=""
     <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") {
@@ -20,9 +34,12 @@
                     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() {
@@ -29,9 +46,10 @@
             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>

Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src=""
-    <script src=""
     <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") {
@@ -20,9 +34,12 @@
                     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() {
@@ -29,9 +46,10 @@
             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>

Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src=""
-    <script src=""
     <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") {
@@ -20,9 +34,12 @@
                     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() {
@@ -29,9 +46,10 @@
             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>

Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src=""
-    <script src=""
     <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") {
@@ -20,9 +34,12 @@
                     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() {
@@ -29,9 +46,10 @@
             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>

Added: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect-expected.txt (0 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect-expected.txt	                        (rev 0)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect-expected.txt	2017-10-19 23:11:55 UTC (rev 223722)
@@ -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

Added: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html (0 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html	                        (rev 0)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <script src=""
+</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 = ""
+        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 = "" + 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>

Added: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/get-cookies.php (0 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/get-cookies.php	                        (rev 0)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/get-cookies.php	2017-10-19 23:11:55 UTC (rev 223722)
@@ -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

Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/redirect.php (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/redirect.php	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/redirect.php	2017-10-19 23:11:55 UTC (rev 223722)
@@ -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();
 ?>

Added: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/set-cookie.php (0 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/set-cookie.php	                        (rev 0)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/set-cookie.php	2017-10-19 23:11:55 UTC (rev 223722)
@@ -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 = "" 10);
+}
+</script>
\ No newline at end of file

Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip.html (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip.html	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src=""
-    <script src=""
     <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") {
@@ -20,9 +34,12 @@
                     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() {
@@ -29,9 +46,10 @@
             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>

Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src=""
-    <script src=""
     <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") {
@@ -20,9 +34,12 @@
                     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() {
@@ -29,9 +46,10 @@
             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>

Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src=""
-    <script src=""
     <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") {
@@ -20,9 +34,12 @@
                     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() {
@@ -29,9 +46,10 @@
             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>

Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src=""
-    <script src=""
     <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") {
@@ -20,9 +34,12 @@
                     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() {
@@ -29,9 +46,10 @@
             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>

Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src=""
-    <script src=""
     <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") {
@@ -20,9 +34,12 @@
                     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() {
@@ -29,9 +46,10 @@
             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>

Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html	2017-10-19 23:11:55 UTC (rev 223722)
@@ -2,17 +2,31 @@
 <html>
 <head>
     <script src=""
-    <script src=""
     <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") {
@@ -20,9 +34,12 @@
                     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() {
@@ -29,9 +46,10 @@
             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>

Modified: branches/safari-604-branch/LayoutTests/platform/ios/TestExpectations (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/platform/ios/TestExpectations	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/platform/ios/TestExpectations	2017-10-19 23:11:55 UTC (rev 223722)
@@ -2959,6 +2959,9 @@
 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 ]
 

Modified: branches/safari-604-branch/LayoutTests/platform/mac-wk2/TestExpectations (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/platform/mac-wk2/TestExpectations	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/platform/mac-wk2/TestExpectations	2017-10-19 23:11:55 UTC (rev 223722)
@@ -723,3 +723,5 @@
 http/tests/loading/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame.html [ Pass ]
 http/tests/loading/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time.html [ Pass ]
 http/tests/loading/resourceLoadStatistics/user-interaction-reported-after-website-data-removal.html [ Pass ]
+[ HighSierra+ ] http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html [ Pass ]
+[ HighSierra+ ] http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html [ Pass ]

Modified: branches/safari-604-branch/LayoutTests/platform/wk2/TestExpectations (223721 => 223722)


--- branches/safari-604-branch/LayoutTests/platform/wk2/TestExpectations	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/LayoutTests/platform/wk2/TestExpectations	2017-10-19 23:11:55 UTC (rev 223722)
@@ -684,7 +684,11 @@
 webkit.org/b/173499 http/tests/loading/resourceLoadStatistics/telemetry-generation.html [ Pass Failure ]
 http/tests/loading/resourceLoadStatistics/prune-statistics.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.
 ########################################
 

Modified: branches/safari-604-branch/Source/WebCore/ChangeLog (223721 => 223722)


--- branches/safari-604-branch/Source/WebCore/ChangeLog	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/Source/WebCore/ChangeLog	2017-10-19 23:11:55 UTC (rev 223722)
@@ -1,5 +1,25 @@
 2017-10-19  Jason Marcell  <jmarc...@apple.com>
 
+        Cherry-pick r223565. rdar://problem/35041490
+
+    2017-10-17  John Wilander  <wilan...@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-19  Jason Marcell  <jmarc...@apple.com>
+
         Cherry-pick r223253. rdar://problem/35077489
 
     2017-10-12  John Wilander  <wilan...@apple.com>

Modified: branches/safari-604-branch/Source/WebCore/loader/ResourceLoadObserver.h (223721 => 223722)


--- branches/safari-604-branch/Source/WebCore/loader/ResourceLoadObserver.h	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/Source/WebCore/loader/ResourceLoadObserver.h	2017-10-19 23:11:55 UTC (rev 223722)
@@ -52,8 +52,6 @@
 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&);
@@ -63,6 +61,7 @@
 
     WEBCORE_EXPORT void setNotificationCallback(WTF::Function<void (Vector<ResourceLoadStatistics>&&)>&&);
 
+    WEBCORE_EXPORT void notifyObserver();
     WEBCORE_EXPORT void clearState();
 private:
     ResourceLoadObserver();
@@ -71,7 +70,6 @@
     ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
 
     void scheduleNotificationIfNeeded();
-    void notifyObserver();
     Vector<ResourceLoadStatistics> takeStatistics();
 
     HashMap<String, ResourceLoadStatistics> m_resourceStatisticsMap;

Modified: branches/safari-604-branch/Source/WebKit/ChangeLog (223721 => 223722)


--- branches/safari-604-branch/Source/WebKit/ChangeLog	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/Source/WebKit/ChangeLog	2017-10-19 23:11:55 UTC (rev 223722)
@@ -1,5 +1,28 @@
 2017-10-19  Jason Marcell  <jmarc...@apple.com>
 
+        Cherry-pick r223565. rdar://problem/35041490
+
+    2017-10-17  John Wilander  <wilan...@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-19  Jason Marcell  <jmarc...@apple.com>
+
         Cherry-pick r223253. rdar://problem/35077489
 
     2017-10-12  John Wilander  <wilan...@apple.com>

Modified: branches/safari-604-branch/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm (223721 => 223722)


--- branches/safari-604-branch/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2017-10-19 23:11:55 UTC (rev 223722)
@@ -187,6 +187,16 @@
         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) {
@@ -231,6 +241,16 @@
 #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 {

Modified: branches/safari-604-branch/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp (223721 => 223722)


--- branches/safari-604-branch/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp	2017-10-19 23:11:55 UTC (rev 223722)
@@ -282,3 +282,8 @@
 {
     ResourceLoadObserver::shared().clearState();
 }
+
+void WKBundleResourceLoadStatisticsNotifyObserver(WKBundleRef)
+{
+    ResourceLoadObserver::shared().notifyObserver();
+}

Modified: branches/safari-604-branch/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h (223721 => 223722)


--- branches/safari-604-branch/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h	2017-10-19 23:11:55 UTC (rev 223722)
@@ -92,6 +92,7 @@
 WK_EXPORT void WKBundleSetTabKeyCyclesThroughElements(WKBundleRef bundle, WKBundlePageRef page, bool enabled);
 
 WK_EXPORT void WKBundleClearResourceLoadStatistics(WKBundleRef);
+WK_EXPORT void WKBundleResourceLoadStatisticsNotifyObserver(WKBundleRef);
 
 #ifdef __cplusplus
 }

Modified: branches/safari-604-branch/Tools/ChangeLog (223721 => 223722)


--- branches/safari-604-branch/Tools/ChangeLog	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/Tools/ChangeLog	2017-10-19 23:11:55 UTC (rev 223722)
@@ -1,5 +1,27 @@
 2017-10-19  Jason Marcell  <jmarc...@apple.com>
 
+        Cherry-pick r223565. rdar://problem/35041490
+
+    2017-10-17  John Wilander  <wilan...@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-19  Jason Marcell  <jmarc...@apple.com>
+
         Cherry-pick r223253. rdar://problem/35077489
 
     2017-10-12  John Wilander  <wilan...@apple.com>

Modified: branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (223721 => 223722)


--- branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2017-10-19 23:11:55 UTC (rev 223722)
@@ -271,6 +271,7 @@
     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);

Modified: branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp (223721 => 223722)


--- branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2017-10-19 23:11:55 UTC (rev 223722)
@@ -831,4 +831,9 @@
     WebCoreTestSupport::setAllowsAnySSLCertificate(allowsAnySSLCertificate);
 }
 
+void InjectedBundle::statisticsNotifyObserver()
+{
+    WKBundleResourceLoadStatisticsNotifyObserver(m_bundle);
+}
+
 } // namespace WTR

Modified: branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h (223721 => 223722)


--- branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h	2017-10-19 23:11:55 UTC (rev 223722)
@@ -133,7 +133,9 @@
     unsigned imageCountInGeneralPasteboard() const;
 
     void setAllowsAnySSLCertificate(bool);
-    
+
+    void statisticsNotifyObserver();
+
 private:
     InjectedBundle();
     ~InjectedBundle();

Modified: branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (223721 => 223722)


--- branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2017-10-19 23:11:55 UTC (rev 223722)
@@ -1502,7 +1502,12 @@
     
     callTestRunnerCallback(StatisticsDidRunTelemetryCallbackID, 1, &result);
 }
-    
+
+void TestRunner::statisticsNotifyObserver()
+{
+    InjectedBundle::singleton().statisticsNotifyObserver();
+}
+
 void TestRunner::statisticsProcessStatisticsAndDataRecords()
 {
     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsProcessStatisticsAndDataRecords"));

Modified: branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (223721 => 223722)


--- branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2017-10-19 23:11:46 UTC (rev 223721)
+++ branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2017-10-19 23:11:55 UTC (rev 223722)
@@ -356,6 +356,7 @@
     void statisticsDidModifyDataRecordsCallback();
     void statisticsDidScanDataRecordsCallback();
     void statisticsDidRunTelemetryCallback(unsigned totalPrevalentResources, unsigned totalPrevalentResourcesWithUserInteraction, unsigned top3SubframeUnderTopFrameOrigins);
+    void statisticsNotifyObserver();
     void statisticsProcessStatisticsAndDataRecords();
     void statisticsUpdateCookiePartitioning();
     void statisticsSetShouldPartitionCookiesForHost(JSStringRef hostName, bool value);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to