<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[223722] branches/safari-604-branch</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/223722">223722</a></dd>
<dt>Author</dt> <dd>jmarcell@apple.com</dd>
<dt>Date</dt> <dd>2017-10-19 16:11:55 -0700 (Thu, 19 Oct 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/223565">r223565</a>. rdar://problem/35041490</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari604branchLayoutTestsChangeLog">branches/safari-604-branch/LayoutTests/ChangeLog</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsnonsandboxediframeredirectiptolocalhosttoiphtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsnonsandboxediframeredirectlocalhosttoiptolocalhosthtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsnonsandboxednestingiframewithnonsandboxediframeredirectiptolocalhosttoiphtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsnonsandboxednestingiframewithnonsandboxediframeredirectlocalhosttoiptolocalhosthtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsnonsandboxednestingiframewithsandboxediframeredirectiptolocalhosttoiphtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsnonsandboxednestingiframewithsandboxediframeredirectlocalhosttoiptolocalhosthtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsresourcesredirectphp">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/redirect.php</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticssandboxediframeredirectiptolocalhosttoiphtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip.html</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticssandboxediframeredirectlocalhosttoiptolocalhosthtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticssandboxednestingiframewithnonsandboxediframeredirectiptolocalhosttoiphtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticssandboxednestingiframewithnonsandboxediframeredirectlocalhosttoiptolocalhosthtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticssandboxednestingiframewithsandboxediframeredirectiptolocalhosttoiphtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticssandboxednestingiframewithsandboxediframeredirectlocalhosttoiptolocalhosthtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html</a></li>
<li><a href="#branchessafari604branchLayoutTestsplatformiosTestExpectations">branches/safari-604-branch/LayoutTests/platform/ios/TestExpectations</a></li>
<li><a href="#branchessafari604branchLayoutTestsplatformmacwk2TestExpectations">branches/safari-604-branch/LayoutTests/platform/mac-wk2/TestExpectations</a></li>
<li><a href="#branchessafari604branchLayoutTestsplatformwk2TestExpectations">branches/safari-604-branch/LayoutTests/platform/wk2/TestExpectations</a></li>
<li><a href="#branchessafari604branchSourceWebCoreChangeLog">branches/safari-604-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari604branchSourceWebCoreloaderResourceLoadObserverh">branches/safari-604-branch/Source/WebCore/loader/ResourceLoadObserver.h</a></li>
<li><a href="#branchessafari604branchSourceWebKitChangeLog">branches/safari-604-branch/Source/WebKit/ChangeLog</a></li>
<li><a href="#branchessafari604branchSourceWebKitNetworkProcesscocoaNetworkDataTaskCocoamm">branches/safari-604-branch/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm</a></li>
<li><a href="#branchessafari604branchSourceWebKitWebProcessInjectedBundleAPIcWKBundlecpp">branches/safari-604-branch/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp</a></li>
<li><a href="#branchessafari604branchSourceWebKitWebProcessInjectedBundleAPIcWKBundlePrivateh">branches/safari-604-branch/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h</a></li>
<li><a href="#branchessafari604branchToolsChangeLog">branches/safari-604-branch/Tools/ChangeLog</a></li>
<li><a href="#branchessafari604branchToolsWebKitTestRunnerInjectedBundleBindingsTestRunneridl">branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl</a></li>
<li><a href="#branchessafari604branchToolsWebKitTestRunnerInjectedBundleInjectedBundlecpp">branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp</a></li>
<li><a href="#branchessafari604branchToolsWebKitTestRunnerInjectedBundleInjectedBundleh">branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h</a></li>
<li><a href="#branchessafari604branchToolsWebKitTestRunnerInjectedBundleTestRunnercpp">branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp</a></li>
<li><a href="#branchessafari604branchToolsWebKitTestRunnerInjectedBundleTestRunnerh">branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsaddpartitioningtoredirectexpectedtxt">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsaddpartitioningtoredirecthtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsremovepartitioningfromredirectexpectedtxt">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect-expected.txt</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsremovepartitioningfromredirecthtml">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsresourcesgetcookiesphp">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/get-cookies.php</a></li>
<li><a href="#branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsresourcessetcookiephp">branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/set-cookie.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari604branchLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/LayoutTests/ChangeLog (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,5 +1,47 @@
</span><span class="cx"> 2017-10-19  Jason Marcell  <jmarcell@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r223565. rdar://problem/35041490
+
+    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-19  Jason Marcell  <jmarcell@apple.com>
+
</ins><span class="cx">         Cherry-pick r223253. rdar://problem/35077489
</span><span class="cx"> 
</span><span class="cx">     2017-10-12  John Wilander  <wilander@apple.com>
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsaddpartitioningtoredirectexpectedtxt"></a>
<div class="addfile"><h4>Added: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt (0 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,63 @@
</span><ins>+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
</ins></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsaddpartitioningtoredirecthtml"></a>
<div class="addfile"><h4>Added: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html (0 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,108 @@
</span><ins>+<!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>
</ins></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsnonsandboxediframeredirectiptolocalhosttoiphtml"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,17 +2,31 @@
</span><span class="cx"> <html>
</span><span class="cx"> <head>
</span><span class="cx">     <script src="/js-test-resources/js-test.js"></script>
</span><del>-    <script src="/js-test-resources/ui-helper.js"></script>
</del><span class="cx">     <script>
</span><span class="cx">         description("Tests that redirects for a non-sandboxed iframe get counted properly.");
</span><span class="cx">         jsTestIsAsync = true;
</span><span class="cx">         window.addEventListener("message", receiveMessage, false);
</span><ins>+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
</ins><span class="cx">         if (testRunner) {
</span><ins>+            setEnableFeature(true);
</ins><span class="cx">             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
</span><span class="cx">             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var testPhasesDone = 0;
</del><ins>+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
</ins><span class="cx"> 
</span><span class="cx">         function receiveMessage(event) {
</span><span class="cx">             if (event.origin === "http://127.0.0.1:8000") {
</span><span class="lines">@@ -20,9 +34,12 @@
</span><span class="cx">                     testFailed(event.data.replace("FAIL ", ""));
</span><span class="cx">             } else
</span><span class="cx">                 testFailed("Received a message from an unexpected origin: " + event.origin);
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function checkStats() {
</span><span class="lines">@@ -29,14 +46,15 @@
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
</ins><span class="cx">         }
</span><span class="cx">     </script>
</span><span class="cx"> </head>
</span><span class="cx"> <body>
</span><del>-<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">
</del><ins>+<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">
</ins><span class="cx"> </iframe>
</span><span class="cx"> </body>
</span><span class="cx"> </html>
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsnonsandboxediframeredirectlocalhosttoiptolocalhosthtml"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,17 +2,31 @@
</span><span class="cx"> <html>
</span><span class="cx"> <head>
</span><span class="cx">     <script src="/js-test-resources/js-test.js"></script>
</span><del>-    <script src="/js-test-resources/ui-helper.js"></script>
</del><span class="cx">     <script>
</span><span class="cx">         description("Tests that redirects for a non-sandboxed iframe get counted properly.");
</span><span class="cx">         jsTestIsAsync = true;
</span><span class="cx">         window.addEventListener("message", receiveMessage, false);
</span><ins>+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
</ins><span class="cx">         if (testRunner) {
</span><ins>+            setEnableFeature(true);
</ins><span class="cx">             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
</span><span class="cx">             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var testPhasesDone = 0;
</del><ins>+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
</ins><span class="cx"> 
</span><span class="cx">         function receiveMessage(event) {
</span><span class="cx">             if (event.origin === "http://localhost:8000") {
</span><span class="lines">@@ -20,9 +34,12 @@
</span><span class="cx">                     testFailed(event.data.replace("FAIL ", ""));
</span><span class="cx">             } else
</span><span class="cx">                 testFailed("Received a message from an unexpected origin: " + event.origin);
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function checkStats() {
</span><span class="lines">@@ -29,9 +46,10 @@
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
</ins><span class="cx">         }
</span><span class="cx">     </script>
</span><span class="cx"> </head>
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsnonsandboxednestingiframewithnonsandboxediframeredirectiptolocalhosttoiphtml"></a>
<div class="modfile"><h4>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)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,17 +2,31 @@
</span><span class="cx"> <html>
</span><span class="cx"> <head>
</span><span class="cx">     <script src="/js-test-resources/js-test.js"></script>
</span><del>-    <script src="/js-test-resources/ui-helper.js"></script>
</del><span class="cx">     <script>
</span><span class="cx">         description("Tests that redirects for a non-sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
</span><span class="cx">         jsTestIsAsync = true;
</span><span class="cx">         window.addEventListener("message", receiveMessage, false);
</span><ins>+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
</ins><span class="cx">         if (testRunner) {
</span><ins>+            setEnableFeature(true);
</ins><span class="cx">             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
</span><span class="cx">             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var testPhasesDone = 0;
</del><ins>+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
</ins><span class="cx"> 
</span><span class="cx">         function receiveMessage(event) {
</span><span class="cx">             if (event.origin === "http://127.0.0.1:8000") {
</span><span class="lines">@@ -20,9 +34,12 @@
</span><span class="cx">                     testFailed(event.data.replace("FAIL ", ""));
</span><span class="cx">             } else
</span><span class="cx">                 testFailed("Received a message from an unexpected origin: " + event.origin);
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function checkStats() {
</span><span class="lines">@@ -29,9 +46,10 @@
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
</ins><span class="cx">         }
</span><span class="cx">     </script>
</span><span class="cx"> </head>
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsnonsandboxednestingiframewithnonsandboxediframeredirectlocalhosttoiptolocalhosthtml"></a>
<div class="modfile"><h4>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)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,17 +2,31 @@
</span><span class="cx"> <html>
</span><span class="cx"> <head>
</span><span class="cx">     <script src="/js-test-resources/js-test.js"></script>
</span><del>-    <script src="/js-test-resources/ui-helper.js"></script>
</del><span class="cx">     <script>
</span><span class="cx">         description("Tests that redirects for a non-sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
</span><span class="cx">         jsTestIsAsync = true;
</span><span class="cx">         window.addEventListener("message", receiveMessage, false);
</span><ins>+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
</ins><span class="cx">         if (testRunner) {
</span><ins>+            setEnableFeature(true);
</ins><span class="cx">             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
</span><span class="cx">             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var testPhasesDone = 0;
</del><ins>+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
</ins><span class="cx"> 
</span><span class="cx">         function receiveMessage(event) {
</span><span class="cx">             if (event.origin === "http://localhost:8000") {
</span><span class="lines">@@ -20,9 +34,12 @@
</span><span class="cx">                     testFailed(event.data.replace("FAIL ", ""));
</span><span class="cx">             } else
</span><span class="cx">                 testFailed("Received a message from an unexpected origin: " + event.origin);
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function checkStats() {
</span><span class="lines">@@ -29,9 +46,10 @@
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
</ins><span class="cx">         }
</span><span class="cx">     </script>
</span><span class="cx"> </head>
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsnonsandboxednestingiframewithsandboxediframeredirectiptolocalhosttoiphtml"></a>
<div class="modfile"><h4>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)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,17 +2,31 @@
</span><span class="cx"> <html>
</span><span class="cx"> <head>
</span><span class="cx">     <script src="/js-test-resources/js-test.js"></script>
</span><del>-    <script src="/js-test-resources/ui-helper.js"></script>
</del><span class="cx">     <script>
</span><span class="cx">         description("Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
</span><span class="cx">         jsTestIsAsync = true;
</span><span class="cx">         window.addEventListener("message", receiveMessage, false);
</span><ins>+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
</ins><span class="cx">         if (testRunner) {
</span><ins>+            setEnableFeature(true);
</ins><span class="cx">             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
</span><span class="cx">             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var testPhasesDone = 0;
</del><ins>+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
</ins><span class="cx"> 
</span><span class="cx">         function receiveMessage(event) {
</span><span class="cx">             if (event.origin === "null") {
</span><span class="lines">@@ -20,9 +34,12 @@
</span><span class="cx">                     testFailed(event.data.replace("FAIL ", ""));
</span><span class="cx">             } else
</span><span class="cx">                 testFailed("Received a message from an unexpected origin: " + event.origin);
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function checkStats() {
</span><span class="lines">@@ -29,9 +46,10 @@
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
</ins><span class="cx">         }
</span><span class="cx">     </script>
</span><span class="cx"> </head>
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsnonsandboxednestingiframewithsandboxediframeredirectlocalhosttoiptolocalhosthtml"></a>
<div class="modfile"><h4>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)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,17 +2,31 @@
</span><span class="cx"> <html>
</span><span class="cx"> <head>
</span><span class="cx">     <script src="/js-test-resources/js-test.js"></script>
</span><del>-    <script src="/js-test-resources/ui-helper.js"></script>
</del><span class="cx">     <script>
</span><span class="cx">         description("Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
</span><span class="cx">         jsTestIsAsync = true;
</span><span class="cx">         window.addEventListener("message", receiveMessage, false);
</span><ins>+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
</ins><span class="cx">         if (testRunner) {
</span><ins>+            setEnableFeature(true);
</ins><span class="cx">             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
</span><span class="cx">             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var testPhasesDone = 0;
</del><ins>+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
</ins><span class="cx"> 
</span><span class="cx">         function receiveMessage(event) {
</span><span class="cx">             if (event.origin === "null") {
</span><span class="lines">@@ -20,9 +34,12 @@
</span><span class="cx">                     testFailed(event.data.replace("FAIL ", ""));
</span><span class="cx">             } else
</span><span class="cx">                 testFailed("Received a message from an unexpected origin: " + event.origin);
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function checkStats() {
</span><span class="lines">@@ -29,9 +46,10 @@
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
</ins><span class="cx">         }
</span><span class="cx">     </script>
</span><span class="cx"> </head>
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsremovepartitioningfromredirectexpectedtxt"></a>
<div class="addfile"><h4>Added: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect-expected.txt (0 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,25 @@
</span><ins>+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
</ins></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsremovepartitioningfromredirecthtml"></a>
<div class="addfile"><h4>Added: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html (0 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,81 @@
</span><ins>+<!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>
</ins></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsresourcesgetcookiesphp"></a>
<div class="addfile"><h4>Added: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/get-cookies.php (0 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,24 @@
</span><ins>+<?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>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsresourcesredirectphp"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/redirect.php (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,4 +1,14 @@
</span><span class="cx"> <?php
</span><del>-header('Location: ' . $_GET["redirectTo"]);
</del><ins>+$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);
</ins><span class="cx"> die();
</span><span class="cx"> ?>
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticsresourcessetcookiephp"></a>
<div class="addfile"><h4>Added: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/resources/set-cookie.php (0 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,9 @@
</span><ins>+<?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>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticssandboxediframeredirectiptolocalhosttoiphtml"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip.html (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,17 +2,31 @@
</span><span class="cx"> <html>
</span><span class="cx"> <head>
</span><span class="cx">     <script src="/js-test-resources/js-test.js"></script>
</span><del>-    <script src="/js-test-resources/ui-helper.js"></script>
</del><span class="cx">     <script>
</span><span class="cx">         description("Tests that redirects for sandboxed iframes get counted properly.");
</span><span class="cx">         jsTestIsAsync = true;
</span><span class="cx">         window.addEventListener("message", receiveMessage, false);
</span><ins>+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
</ins><span class="cx">         if (testRunner) {
</span><ins>+            setEnableFeature(true);
</ins><span class="cx">             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
</span><span class="cx">             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var testPhasesDone = 0;
</del><ins>+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
</ins><span class="cx"> 
</span><span class="cx">         function receiveMessage(event) {
</span><span class="cx">             if (event.origin === "null") {
</span><span class="lines">@@ -20,9 +34,12 @@
</span><span class="cx">                     testFailed(event.data.replace("FAIL ", ""));
</span><span class="cx">             } else
</span><span class="cx">                 testFailed("Received a message from an unexpected origin: " + event.origin);
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function checkStats() {
</span><span class="lines">@@ -29,9 +46,10 @@
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
</ins><span class="cx">         }
</span><span class="cx">     </script>
</span><span class="cx"> </head>
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticssandboxediframeredirectlocalhosttoiptolocalhosthtml"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,17 +2,31 @@
</span><span class="cx"> <html>
</span><span class="cx"> <head>
</span><span class="cx">     <script src="/js-test-resources/js-test.js"></script>
</span><del>-    <script src="/js-test-resources/ui-helper.js"></script>
</del><span class="cx">     <script>
</span><span class="cx">         description("Tests that redirects for sandboxed iframes get counted properly.");
</span><span class="cx">         jsTestIsAsync = true;
</span><span class="cx">         window.addEventListener("message", receiveMessage, false);
</span><ins>+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
</ins><span class="cx">         if (testRunner) {
</span><ins>+            setEnableFeature(true);
</ins><span class="cx">             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
</span><span class="cx">             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var testPhasesDone = 0;
</del><ins>+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
</ins><span class="cx"> 
</span><span class="cx">         function receiveMessage(event) {
</span><span class="cx">             if (event.origin === "null") {
</span><span class="lines">@@ -20,9 +34,12 @@
</span><span class="cx">                     testFailed(event.data.replace("FAIL ", ""));
</span><span class="cx">             } else
</span><span class="cx">                 testFailed("Received a message from an unexpected origin: " + event.origin);
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function checkStats() {
</span><span class="lines">@@ -29,9 +46,10 @@
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
</ins><span class="cx">         }
</span><span class="cx">     </script>
</span><span class="cx"> </head>
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticssandboxednestingiframewithnonsandboxediframeredirectiptolocalhosttoiphtml"></a>
<div class="modfile"><h4>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)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,17 +2,31 @@
</span><span class="cx"> <html>
</span><span class="cx"> <head>
</span><span class="cx">     <script src="/js-test-resources/js-test.js"></script>
</span><del>-    <script src="/js-test-resources/ui-helper.js"></script>
</del><span class="cx">     <script>
</span><span class="cx">         description("Tests that redirects for a non-sandboxed iframe nested in a sandboxed iframe get counted properly.");
</span><span class="cx">         jsTestIsAsync = true;
</span><span class="cx">         window.addEventListener("message", receiveMessage, false);
</span><ins>+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
</ins><span class="cx">         if (testRunner) {
</span><ins>+            setEnableFeature(true);
</ins><span class="cx">             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
</span><span class="cx">             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var testPhasesDone = 0;
</del><ins>+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
</ins><span class="cx"> 
</span><span class="cx">         function receiveMessage(event) {
</span><span class="cx">             if (event.origin === "null") {
</span><span class="lines">@@ -20,9 +34,12 @@
</span><span class="cx">                     testFailed(event.data.replace("FAIL ", ""));
</span><span class="cx">             } else
</span><span class="cx">                 testFailed("Received a message from an unexpected origin: " + event.origin);
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function checkStats() {
</span><span class="lines">@@ -29,9 +46,10 @@
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
</ins><span class="cx">         }
</span><span class="cx">     </script>
</span><span class="cx"> </head>
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticssandboxednestingiframewithnonsandboxediframeredirectlocalhosttoiptolocalhosthtml"></a>
<div class="modfile"><h4>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)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,17 +2,31 @@
</span><span class="cx"> <html>
</span><span class="cx"> <head>
</span><span class="cx">     <script src="/js-test-resources/js-test.js"></script>
</span><del>-    <script src="/js-test-resources/ui-helper.js"></script>
</del><span class="cx">     <script>
</span><span class="cx">         description("Tests that redirects for a non-sandboxed iframe nested in a sandboxed iframe get counted properly.");
</span><span class="cx">         jsTestIsAsync = true;
</span><span class="cx">         window.addEventListener("message", receiveMessage, false);
</span><ins>+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
</ins><span class="cx">         if (testRunner) {
</span><ins>+            setEnableFeature(true);
</ins><span class="cx">             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
</span><span class="cx">             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var testPhasesDone = 0;
</del><ins>+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
</ins><span class="cx"> 
</span><span class="cx">         function receiveMessage(event) {
</span><span class="cx">             if (event.origin === "null") {
</span><span class="lines">@@ -20,9 +34,12 @@
</span><span class="cx">                     testFailed(event.data.replace("FAIL ", ""));
</span><span class="cx">             } else
</span><span class="cx">                 testFailed("Received a message from an unexpected origin: " + event.origin);
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function checkStats() {
</span><span class="lines">@@ -29,9 +46,10 @@
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
</ins><span class="cx">         }
</span><span class="cx">     </script>
</span><span class="cx"> </head>
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticssandboxednestingiframewithsandboxediframeredirectiptolocalhosttoiphtml"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,17 +2,31 @@
</span><span class="cx"> <html>
</span><span class="cx"> <head>
</span><span class="cx">     <script src="/js-test-resources/js-test.js"></script>
</span><del>-    <script src="/js-test-resources/ui-helper.js"></script>
</del><span class="cx">     <script>
</span><span class="cx">         description("Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
</span><span class="cx">         jsTestIsAsync = true;
</span><span class="cx">         window.addEventListener("message", receiveMessage, false);
</span><ins>+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
</ins><span class="cx">         if (testRunner) {
</span><ins>+            setEnableFeature(true);
</ins><span class="cx">             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
</span><span class="cx">             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var testPhasesDone = 0;
</del><ins>+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
</ins><span class="cx"> 
</span><span class="cx">         function receiveMessage(event) {
</span><span class="cx">             if (event.origin === "null") {
</span><span class="lines">@@ -20,9 +34,12 @@
</span><span class="cx">                     testFailed(event.data.replace("FAIL ", ""));
</span><span class="cx">             } else
</span><span class="cx">                 testFailed("Received a message from an unexpected origin: " + event.origin);
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function checkStats() {
</span><span class="lines">@@ -29,9 +46,10 @@
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
</ins><span class="cx">         }
</span><span class="cx">     </script>
</span><span class="cx"> </head>
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestshttptestsresourceLoadStatisticssandboxednestingiframewithsandboxediframeredirectlocalhosttoiptolocalhosthtml"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,17 +2,31 @@
</span><span class="cx"> <html>
</span><span class="cx"> <head>
</span><span class="cx">     <script src="/js-test-resources/js-test.js"></script>
</span><del>-    <script src="/js-test-resources/ui-helper.js"></script>
</del><span class="cx">     <script>
</span><span class="cx">         description("Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
</span><span class="cx">         jsTestIsAsync = true;
</span><span class="cx">         window.addEventListener("message", receiveMessage, false);
</span><ins>+
+        function setEnableFeature(enable) {
+            if (!enable)
+                testRunner.statisticsResetToConsistentState();
+            internals.setResourceLoadStatisticsEnabled(enable);
+            testRunner.setCookieStoragePartitioningEnabled(enable);
+        }
+
+        function finishTest() {
+            setEnableFeature(false);
+            finishJSTest();
+        }
+
</ins><span class="cx">         if (testRunner) {
</span><ins>+            setEnableFeature(true);
</ins><span class="cx">             testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
</span><span class="cx">             testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var testPhasesDone = 0;
</del><ins>+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
</ins><span class="cx"> 
</span><span class="cx">         function receiveMessage(event) {
</span><span class="cx">             if (event.origin === "null") {
</span><span class="lines">@@ -20,9 +34,12 @@
</span><span class="cx">                     testFailed(event.data.replace("FAIL ", ""));
</span><span class="cx">             } else
</span><span class="cx">                 testFailed("Received a message from an unexpected origin: " + event.origin);
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function checkStats() {
</span><span class="lines">@@ -29,9 +46,10 @@
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
</span><span class="cx">             shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
</span><del>-            ++testPhasesDone;
-            if (testPhasesDone === 2)
-                finishJSTest();
</del><ins>+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
</ins><span class="cx">         }
</span><span class="cx">     </script>
</span><span class="cx"> </head>
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestsplatformiosTestExpectations"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/LayoutTests/platform/ios/TestExpectations (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2959,6 +2959,9 @@
</span><span class="cx"> fast/canvas/webgl/texImage2D-video-flipY-true.html [ Skip ]
</span><span class="cx"> 
</span><span class="cx"> webkit.org/b/174120 http/tests/loading/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame.html [ Skip ]
</span><ins>+# 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 ]
</ins><span class="cx"> 
</span><span class="cx"> webkit.org/b/175273 imported/w3c/web-platform-tests/html/browsers/windows/noreferrer-window-name.html [ Failure ]
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari604branchLayoutTestsplatformmacwk2TestExpectations"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/LayoutTests/platform/mac-wk2/TestExpectations (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -723,3 +723,5 @@
</span><span class="cx"> http/tests/loading/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame.html [ Pass ]
</span><span class="cx"> http/tests/loading/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time.html [ Pass ]
</span><span class="cx"> http/tests/loading/resourceLoadStatistics/user-interaction-reported-after-website-data-removal.html [ Pass ]
</span><ins>+[ HighSierra+ ] http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html [ Pass ]
+[ HighSierra+ ] http/tests/resourceLoadStatistics/remove-partitioning-from-redirect.html [ Pass ]
</ins></span></pre></div>
<a id="branchessafari604branchLayoutTestsplatformwk2TestExpectations"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/LayoutTests/platform/wk2/TestExpectations (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -684,7 +684,11 @@
</span><span class="cx"> webkit.org/b/173499 http/tests/loading/resourceLoadStatistics/telemetry-generation.html [ Pass Failure ]
</span><span class="cx"> http/tests/loading/resourceLoadStatistics/prune-statistics.html [ Pass ]
</span><span class="cx"> http/tests/resourceLoadStatistics [ Pass ]
</span><ins>+# 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 ]
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> ### END OF (5) Progressions, expected successes that are expected failures in WebKit1.
</span><span class="cx"> ########################################
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari604branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/Source/WebCore/ChangeLog (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,5 +1,25 @@
</span><span class="cx"> 2017-10-19  Jason Marcell  <jmarcell@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r223565. rdar://problem/35041490
+
+    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-19  Jason Marcell  <jmarcell@apple.com>
+
</ins><span class="cx">         Cherry-pick r223253. rdar://problem/35077489
</span><span class="cx"> 
</span><span class="cx">     2017-10-12  John Wilander  <wilander@apple.com>
</span></span></pre></div>
<a id="branchessafari604branchSourceWebCoreloaderResourceLoadObserverh"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/Source/WebCore/loader/ResourceLoadObserver.h (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -52,8 +52,6 @@
</span><span class="cx"> public:
</span><span class="cx">     WEBCORE_EXPORT static ResourceLoadObserver& shared();
</span><span class="cx"> 
</span><del>-    WEBCORE_EXPORT void setShouldThrottleObserverNotifications(bool);
-    
</del><span class="cx">     void logFrameNavigation(const Frame&, const Frame& topFrame, const ResourceRequest& newRequest, const URL& redirectUrl);
</span><span class="cx">     void logSubresourceLoading(const Frame*, const ResourceRequest& newRequest, const ResourceResponse& redirectResponse);
</span><span class="cx">     void logWebSocketLoading(const Frame*, const URL&);
</span><span class="lines">@@ -63,6 +61,7 @@
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT void setNotificationCallback(WTF::Function<void (Vector<ResourceLoadStatistics>&&)>&&);
</span><span class="cx"> 
</span><ins>+    WEBCORE_EXPORT void notifyObserver();
</ins><span class="cx">     WEBCORE_EXPORT void clearState();
</span><span class="cx"> private:
</span><span class="cx">     ResourceLoadObserver();
</span><span class="lines">@@ -71,7 +70,6 @@
</span><span class="cx">     ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
</span><span class="cx"> 
</span><span class="cx">     void scheduleNotificationIfNeeded();
</span><del>-    void notifyObserver();
</del><span class="cx">     Vector<ResourceLoadStatistics> takeStatistics();
</span><span class="cx"> 
</span><span class="cx">     HashMap<String, ResourceLoadStatistics> m_resourceStatisticsMap;
</span></span></pre></div>
<a id="branchessafari604branchSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/Source/WebKit/ChangeLog (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,5 +1,28 @@
</span><span class="cx"> 2017-10-19  Jason Marcell  <jmarcell@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r223565. rdar://problem/35041490
+
+    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-19  Jason Marcell  <jmarcell@apple.com>
+
</ins><span class="cx">         Cherry-pick r223253. rdar://problem/35077489
</span><span class="cx"> 
</span><span class="cx">     2017-10-12  John Wilander  <wilander@apple.com>
</span></span></pre></div>
<a id="branchessafari604branchSourceWebKitNetworkProcesscocoaNetworkDataTaskCocoamm"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -187,6 +187,16 @@
</span><span class="cx">         m_client->didReceiveData(WTFMove(data));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+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);
+}
+
</ins><span class="cx"> void NetworkDataTaskCocoa::willPerformHTTPRedirection(WebCore::ResourceResponse&& redirectResponse, WebCore::ResourceRequest&& request, RedirectCompletionHandler&& completionHandler)
</span><span class="cx"> {
</span><span class="cx">     if (redirectResponse.httpStatusCode() == 307 || redirectResponse.httpStatusCode() == 308) {
</span><span class="lines">@@ -231,6 +241,16 @@
</span><span class="cx"> #endif
</span><span class="cx">     }
</span><span class="cx">     
</span><ins>+#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
+
</ins><span class="cx">     if (m_client)
</span><span class="cx">         m_client->willPerformHTTPRedirection(WTFMove(redirectResponse), WTFMove(request), WTFMove(completionHandler));
</span><span class="cx">     else {
</span></span></pre></div>
<a id="branchessafari604branchSourceWebKitWebProcessInjectedBundleAPIcWKBundlecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -282,3 +282,8 @@
</span><span class="cx"> {
</span><span class="cx">     ResourceLoadObserver::shared().clearState();
</span><span class="cx"> }
</span><ins>+
+void WKBundleResourceLoadStatisticsNotifyObserver(WKBundleRef)
+{
+    ResourceLoadObserver::shared().notifyObserver();
+}
</ins></span></pre></div>
<a id="branchessafari604branchSourceWebKitWebProcessInjectedBundleAPIcWKBundlePrivateh"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -92,6 +92,7 @@
</span><span class="cx"> WK_EXPORT void WKBundleSetTabKeyCyclesThroughElements(WKBundleRef bundle, WKBundlePageRef page, bool enabled);
</span><span class="cx"> 
</span><span class="cx"> WK_EXPORT void WKBundleClearResourceLoadStatistics(WKBundleRef);
</span><ins>+WK_EXPORT void WKBundleResourceLoadStatisticsNotifyObserver(WKBundleRef);
</ins><span class="cx"> 
</span><span class="cx"> #ifdef __cplusplus
</span><span class="cx"> }
</span></span></pre></div>
<a id="branchessafari604branchToolsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/Tools/ChangeLog (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,5 +1,27 @@
</span><span class="cx"> 2017-10-19  Jason Marcell  <jmarcell@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r223565. rdar://problem/35041490
+
+    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-19  Jason Marcell  <jmarcell@apple.com>
+
</ins><span class="cx">         Cherry-pick r223253. rdar://problem/35077489
</span><span class="cx"> 
</span><span class="cx">     2017-10-12  John Wilander  <wilander@apple.com>
</span></span></pre></div>
<a id="branchessafari604branchToolsWebKitTestRunnerInjectedBundleBindingsTestRunneridl"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -271,6 +271,7 @@
</span><span class="cx">     void setStatisticsSubresourceUniqueRedirectTo(DOMString hostName, DOMString hostNameRedirectedTo);
</span><span class="cx">     void setStatisticsTimeToLiveUserInteraction(double seconds);
</span><span class="cx">     void setStatisticsTimeToLiveCookiePartitionFree(double seconds);
</span><ins>+    void statisticsNotifyObserver();
</ins><span class="cx">     void statisticsProcessStatisticsAndDataRecords();
</span><span class="cx">     void statisticsUpdateCookiePartitioning();
</span><span class="cx">     void statisticsSetShouldPartitionCookiesForHost(DOMString hostName, boolean value);
</span></span></pre></div>
<a id="branchessafari604branchToolsWebKitTestRunnerInjectedBundleInjectedBundlecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -831,4 +831,9 @@
</span><span class="cx">     WebCoreTestSupport::setAllowsAnySSLCertificate(allowsAnySSLCertificate);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void InjectedBundle::statisticsNotifyObserver()
+{
+    WKBundleResourceLoadStatisticsNotifyObserver(m_bundle);
+}
+
</ins><span class="cx"> } // namespace WTR
</span></span></pre></div>
<a id="branchessafari604branchToolsWebKitTestRunnerInjectedBundleInjectedBundleh"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -133,7 +133,9 @@
</span><span class="cx">     unsigned imageCountInGeneralPasteboard() const;
</span><span class="cx"> 
</span><span class="cx">     void setAllowsAnySSLCertificate(bool);
</span><del>-    
</del><ins>+
+    void statisticsNotifyObserver();
+
</ins><span class="cx"> private:
</span><span class="cx">     InjectedBundle();
</span><span class="cx">     ~InjectedBundle();
</span></span></pre></div>
<a id="branchessafari604branchToolsWebKitTestRunnerInjectedBundleTestRunnercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1502,7 +1502,12 @@
</span><span class="cx">     
</span><span class="cx">     callTestRunnerCallback(StatisticsDidRunTelemetryCallbackID, 1, &result);
</span><span class="cx"> }
</span><del>-    
</del><ins>+
+void TestRunner::statisticsNotifyObserver()
+{
+    InjectedBundle::singleton().statisticsNotifyObserver();
+}
+
</ins><span class="cx"> void TestRunner::statisticsProcessStatisticsAndDataRecords()
</span><span class="cx"> {
</span><span class="cx">     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsProcessStatisticsAndDataRecords"));
</span></span></pre></div>
<a id="branchessafari604branchToolsWebKitTestRunnerInjectedBundleTestRunnerh"></a>
<div class="modfile"><h4>Modified: branches/safari-604-branch/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (223721 => 223722)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -356,6 +356,7 @@
</span><span class="cx">     void statisticsDidModifyDataRecordsCallback();
</span><span class="cx">     void statisticsDidScanDataRecordsCallback();
</span><span class="cx">     void statisticsDidRunTelemetryCallback(unsigned totalPrevalentResources, unsigned totalPrevalentResourcesWithUserInteraction, unsigned top3SubframeUnderTopFrameOrigins);
</span><ins>+    void statisticsNotifyObserver();
</ins><span class="cx">     void statisticsProcessStatisticsAndDataRecords();
</span><span class="cx">     void statisticsUpdateCookiePartitioning();
</span><span class="cx">     void statisticsSetShouldPartitionCookiesForHost(JSStringRef hostName, bool value);
</span></span></pre>
</div>
</div>

</body>
</html>