Title: [227875] trunk
Revision
227875
Author
wilan...@apple.com
Date
2018-01-30 22:01:54 -0800 (Tue, 30 Jan 2018)

Log Message

Add callbacks to testRunner.statisticsSetShouldPartitionCookiesForHost() and testRunner.statisticsUpdateCookiePartitioning()
https://bugs.webkit.org/show_bug.cgi?id=181958
https://bugs.webkit.org/show_bug.cgi?id=182072
<rdar://problem/36801804>
<rdar://problem/36845795>

Reviewed by Brent Fulgham.

Because of the asynchronous nature of XPC and cookies,
we need callbacks in these TestRunner functions so that
the layout tests can wait for state changes to finish
before checking test conditions.

Source/WebKit:

* UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
(WKWebsiteDataStoreStatisticsUpdateCookiePartitioning):
(WKWebsiteDataStoreSetStatisticsShouldPartitionCookiesForHost):
* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(-[WKWebsiteDataStore _resourceLoadStatisticsUpdateCookiePartitioning]):
(-[WKWebsiteDataStore _resourceLoadStatisticsUpdateCookiePartitioning:]):
(-[WKWebsiteDataStore _resourceLoadStatisticsSetShouldPartitionCookies:forHost:]):
(-[WKWebsiteDataStore _resourceLoadStatisticsSetShouldPartitionCookies:forHost:completionHandler:]):
* UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated):
(WebKit::WebResourceLoadStatisticsStore::logUserInteraction):
(WebKit::WebResourceLoadStatisticsStore::logNonRecentUserInteraction):
(WebKit::WebResourceLoadStatisticsStore::scheduleCookiePartitioningUpdate):
(WebKit::WebResourceLoadStatisticsStore::scheduleCookiePartitioningUpdateForDomains):
(WebKit::WebResourceLoadStatisticsStore::scheduleClearPartitioningStateForDomains):
(WebKit::WebResourceLoadStatisticsStore::mergeWithDataFromDecoder):
(WebKit::WebResourceLoadStatisticsStore::clearInMemory):
(WebKit::WebResourceLoadStatisticsStore::updateCookiePartitioning):
(WebKit::WebResourceLoadStatisticsStore::updateCookiePartitioningForDomains):
(WebKit::WebResourceLoadStatisticsStore::clearPartitioningStateForDomains):
* UIProcess/WebResourceLoadStatisticsStore.h:

Tools:

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::didReceiveMessageToPage):
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::statisticsUpdateCookiePartitioning):
(WTR::TestRunner::statisticsSetShouldPartitionCookiesForHost):
(WTR::TestRunner::statisticsCallDidSetPartitionOrBlockCookiesForHostCallback):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didSetPartitionOrBlockCookiesForHost):
* WebKitTestRunner/TestInvocation.h:
* WebKitTestRunner/cocoa/TestControllerCocoa.mm:
(WTR::TestController::statisticsUpdateCookiePartitioning):
(WTR::TestController::statisticsSetShouldPartitionCookiesForHost):

LayoutTests:

* http/tests/resourceLoadStatistics/add-blocking-to-redirect-expected.txt:
* http/tests/resourceLoadStatistics/add-blocking-to-redirect.html:
* http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt:
* http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html:
* http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html:
* http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html:
* http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html:
* http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction-expected.txt:
* http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html:
* http/tests/resourceLoadStatistics/remove-blocking-in-redirect-expected.txt:
* http/tests/resourceLoadStatistics/remove-blocking-in-redirect.html:
* http/tests/resourceLoadStatistics/remove-partitioning-in-redirect-expected.txt:
* http/tests/resourceLoadStatistics/remove-partitioning-in-redirect.html:
* http/tests/resourceLoadStatistics/third-party-cookie-with-and-without-user-interaction.html:
* platform/mac-wk2/TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (227874 => 227875)


--- trunk/LayoutTests/ChangeLog	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/ChangeLog	2018-01-31 06:01:54 UTC (rev 227875)
@@ -1,3 +1,34 @@
+2018-01-30  John Wilander  <wilan...@apple.com>
+
+        Add callbacks to testRunner.statisticsSetShouldPartitionCookiesForHost() and testRunner.statisticsUpdateCookiePartitioning()
+        https://bugs.webkit.org/show_bug.cgi?id=181958
+        https://bugs.webkit.org/show_bug.cgi?id=182072
+        <rdar://problem/36801804>
+        <rdar://problem/36845795>
+
+        Reviewed by Brent Fulgham.
+
+        Because of the asynchronous nature of XPC and cookies,
+        we need callbacks in these TestRunner functions so that
+        the layout tests can wait for state changes to finish
+        before checking test conditions.
+
+        * http/tests/resourceLoadStatistics/add-blocking-to-redirect-expected.txt:
+        * http/tests/resourceLoadStatistics/add-blocking-to-redirect.html:
+        * http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt:
+        * http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html:
+        * http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html:
+        * http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html:
+        * http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html:
+        * http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction-expected.txt:
+        * http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html:
+        * http/tests/resourceLoadStatistics/remove-blocking-in-redirect-expected.txt:
+        * http/tests/resourceLoadStatistics/remove-blocking-in-redirect.html:
+        * http/tests/resourceLoadStatistics/remove-partitioning-in-redirect-expected.txt:
+        * http/tests/resourceLoadStatistics/remove-partitioning-in-redirect.html:
+        * http/tests/resourceLoadStatistics/third-party-cookie-with-and-without-user-interaction.html:
+        * platform/mac-wk2/TestExpectations:
+
 2018-01-30  Youenn Fablet  <you...@apple.com>
 
         Move http/wpt/service-workers/clone-opaque-being-loaded-response.https.html to use HTTP

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect-expected.txt (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect-expected.txt	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect-expected.txt	2018-01-31 06:01:54 UTC (rev 227875)
@@ -6,8 +6,8 @@
 PASS successfullyParsed is true
 
 TEST COMPLETE
+  
 
-
 --------
 Frame: '<!--framePath //<!--frame0-->-->'
 --------

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect.html (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect.html	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect.html	2018-01-31 06:01:54 UTC (rev 227875)
@@ -4,7 +4,7 @@
     <meta charset="UTF-8">
     <script src=""
 </head>
-<body _onload_="runTest()">
+<body>
 <script>
     description("Tests that blocking is added mid-flight in redirects.");
     jsTestIsAsync = true;
@@ -16,16 +16,6 @@
         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";
@@ -67,10 +57,11 @@
                 // Set localhost as prevalent and with no user interaction to put it in the blocking category.
                 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();
+                testRunner.statisticsUpdateCookiePartitioning(function() {
+                    runTest();
+                });
                 break;
             case "#step5":
                 // Check that no cookie gets sent for localhost under 127.0.0.1 since localhost's cookies are blocked.
@@ -103,6 +94,18 @@
                 break;
         }
     }
+
+    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";
+        // Make sure the network process is up-to-date.
+        testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", false, runTest);
+    } else {
+        runTest();
+    }
 </script>
 </body>
 </html>

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt	2018-01-31 06:01:54 UTC (rev 227875)
@@ -6,8 +6,8 @@
 PASS successfullyParsed is true
 
 TEST COMPLETE
+  
 
-
 --------
 Frame: '<!--framePath //<!--frame0-->-->'
 --------

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html	2018-01-31 06:01:54 UTC (rev 227875)
@@ -4,7 +4,7 @@
     <meta charset="UTF-8">
     <script src=""
 </head>
-<body _onload_="runTest()">
+<body>
 <script>
     description("Tests that partitioning is added mid-flight in redirects.");
     jsTestIsAsync = true;
@@ -16,16 +16,6 @@
         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";
@@ -67,11 +57,12 @@
                 // Set localhost as prevalent and with non-recent user interaction to put it in the partitioning category.
                 document.location.hash = "step5";
                 testRunner.setStatisticsPrevalentResource("http://localhost", true);
-                testRunner.setStatisticsHasHadNonRecentUserInteraction("http://localhost");
-                testRunner.statisticsUpdateCookiePartitioning();
                 if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
                     testFailed("Host did not get set as prevalent resource.");
-                runTest();
+                testRunner.setStatisticsHasHadNonRecentUserInteraction("http://localhost");
+                testRunner.statisticsUpdateCookiePartitioning(function() {
+                    runTest();
+                });
                 break;
             case "#step5":
                 // Check that no cookie gets sent for localhost under 127.0.0.1 since localhost is partitioned.
@@ -104,6 +95,18 @@
                 break;
         }
     }
+
+    if (document.location.hash === "") {
+        setEnableFeature(true);
+        if (testRunner.isStatisticsPrevalentResource("http://localhost"))
+            testFailed("Localhost was classified as prevalent resource before the test started.");
+        testRunner.dumpChildFramesAsText();
+        document.location.hash = "step1";
+        // Make sure the network process is up-to-date.
+        testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", false, runTest);
+    } else {
+        runTest();
+    }
 </script>
 </body>
 </html>

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html	2018-01-31 06:01:54 UTC (rev 227875)
@@ -60,17 +60,21 @@
                 openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive one cookie.", runTest);
                 break;
             case "#step3":
-                // Setup localhost for partitioning and set a partitioned cookie for localhost under 127.0.0.1.
+                // Setup localhost for partitioning.
                 document.location.hash = "step4";
-                testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, true);
-                openIframe(thirdPartyBaseUrl + subPathToSetPartitionedCookie + "&message=Setting partitioned, third party cookie.", runTest);
+                testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, true, runTest);
                 break;
             case "#step4":
-                // Load localhost under 127.0.0.1 and check that it gets only the partitioned cookie. End by aquiring user interaction for localhost.
+                // Set a partitioned cookie for localhost under 127.0.0.1.
                 document.location.hash = "step5";
+                openIframe(thirdPartyBaseUrl + subPathToSetPartitionedCookie + "&message=Setting partitioned, third party cookie.", runTest);
+                break;
+            case "#step5":
+                // Load localhost under 127.0.0.1 and check that it gets only the partitioned cookie. End by acquiring user interaction for localhost.
+                document.location.hash = "step6";
                 openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive one partitioned, third party cookie.", setUserInteractionAndContinue);
                 break;
-            case "#step5":
+            case "#step6":
                 // Load localhost under 127.0.0.1 and check that it gets its non-partitioned cookie after user interaction.
                 openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=After user interaction, should receive one non-partitioned, first party cookie.", finishTest);
                 break;
@@ -82,14 +86,14 @@
 
         testRunner.setStatisticsPrevalentResource(thirdPartyHostname, false);
         testRunner.setStatisticsHasHadUserInteraction(thirdPartyOrigin, false);
-        testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, false);
-
         testRunner.waitUntilDone();
         testRunner.dumpChildFramesAsText();
         document.location.hash = "step1";
+
+        testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, false, runTest);
+    } else {
+        runTest();
     }
-
-    runTest();
 </script>
 </body>
 </html>

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html	2018-01-31 06:01:54 UTC (rev 227875)
@@ -86,7 +86,6 @@
         }
     }
 
-
     if (document.location.host === partitionHost && document.location.hash === "" && window.testRunner && window.internals) {
         setEnableFeature(true);
 
@@ -93,17 +92,19 @@
         testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
         testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
 
-        testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", true);
+        testRunner.waitUntilDone();
+        testRunner.dumpChildFramesAsText();
+        document.location.hash = "step1";
+
         testRunner.setStatisticsPrevalentResource("http://localhost", true);
         if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
             testFailed("Host did not get set as prevalent resource.");
 
-        testRunner.waitUntilDone();
-        testRunner.dumpChildFramesAsText();
-        document.location.hash = "step1";
+        testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", true, runTest);
+    } else {
+        runTest();
     }
 
-    runTest();
 </script>
 </body>
 </html>

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html	2018-01-31 06:01:54 UTC (rev 227875)
@@ -40,8 +40,7 @@
     }
 
     function fireShouldPartitionCookiesHandlerAndContinue() {
-        testRunner.statisticsUpdateCookiePartitioning();
-        runTest();
+        testRunner.statisticsUpdateCookiePartitioning(runTest);
     }
 
     function setShortCookiePartitioningTimeOutPlusFireShouldPartitionCookiesHandlerAndContinue() {

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction-expected.txt (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction-expected.txt	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction-expected.txt	2018-01-31 06:01:54 UTC (rev 227875)
@@ -1,5 +1,5 @@
+  
 
-
 --------
 Frame: '<!--framePath //<!--frame0-->-->'
 --------

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html	2018-01-31 06:01:54 UTC (rev 227875)
@@ -5,7 +5,7 @@
     <title>Test for Partitioned Cookies With and Without User Interaction</title>
     <script src=""
 </head>
-<body _onload_="runTest()">
+<body>
 <script>
     const partitionHost = "127.0.0.1:8000";
     const thirdPartyOrigin = "http://localhost:8000";
@@ -73,11 +73,13 @@
     if (document.location.host === partitionHost && document.location.hash == "" && window.testRunner && window.internals) {
         setEnableFeature(true);
 
-        testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", true);
-
         testRunner.waitUntilDone();
         testRunner.dumpChildFramesAsText();
         document.location.hash = "step1";
+
+        testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", true, runTest);
+    } else {
+        runTest();
     }
 </script>
 </body>

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/remove-blocking-in-redirect-expected.txt (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/remove-blocking-in-redirect-expected.txt	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/remove-blocking-in-redirect-expected.txt	2018-01-31 06:01:54 UTC (rev 227875)
@@ -6,8 +6,8 @@
 PASS successfullyParsed is true
 
 TEST COMPLETE
+  
 
-
 --------
 Frame: '<!--framePath //<!--frame0-->-->'
 --------

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/remove-blocking-in-redirect.html (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/remove-blocking-in-redirect.html	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/remove-blocking-in-redirect.html	2018-01-31 06:01:54 UTC (rev 227875)
@@ -4,7 +4,7 @@
     <meta charset="UTF-8">
     <script src=""
 </head>
-<body _onload_="runTest()">
+<body>
 <script>
     description("Tests that blocking is removed mid-flight in redirects.");
     jsTestIsAsync = true;
@@ -16,16 +16,6 @@
         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";
@@ -68,10 +58,11 @@
                 // Set localhost as prevalent and with non-recent user interaction to put it in the blocking category.
                 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();
+                testRunner.statisticsUpdateCookiePartitioning(function() {
+                    runTest();
+                });
                 break;
             case "#step5":
                 // Set partitioned cookie for localhost under 127.0.0.1.
@@ -94,6 +85,18 @@
                 break;
         }
     }
+
+    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";
+        // Make sure the network process is up-to-date.
+        testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", false, runTest);
+    } else {
+        runTest();
+    }
 </script>
 </body>
 </html>

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-in-redirect-expected.txt (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-in-redirect-expected.txt	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-in-redirect-expected.txt	2018-01-31 06:01:54 UTC (rev 227875)
@@ -6,8 +6,8 @@
 PASS successfullyParsed is true
 
 TEST COMPLETE
+  
 
-
 --------
 Frame: '<!--framePath //<!--frame0-->-->'
 --------

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-in-redirect.html (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-in-redirect.html	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-in-redirect.html	2018-01-31 06:01:54 UTC (rev 227875)
@@ -4,7 +4,7 @@
     <meta charset="UTF-8">
     <script src=""
 </head>
-<body _onload_="runTest()">
+<body>
 <script>
     description("Tests that partitioning is removed mid-flight in redirects.");
     jsTestIsAsync = true;
@@ -16,16 +16,6 @@
         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";
@@ -68,11 +58,12 @@
                 // Set localhost as prevalent and with non-recent user interaction to put it in the partitioning category.
                 document.location.hash = "step5";
                 testRunner.setStatisticsPrevalentResource("http://localhost", true);
-                testRunner.setStatisticsHasHadNonRecentUserInteraction("http://localhost");
-                testRunner.statisticsUpdateCookiePartitioning();
                 if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
                     testFailed("Host did not get set as prevalent resource.");
-                runTest();
+                testRunner.setStatisticsHasHadNonRecentUserInteraction("http://localhost");
+                testRunner.statisticsUpdateCookiePartitioning(function() {
+                    runTest();
+                });
                 break;
             case "#step5":
                 // Set partitioned cookie for localhost under 127.0.0.1.
@@ -95,6 +86,18 @@
                 break;
         }
     }
+
+    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";
+        // Make sure the network process is up-to-date.
+        testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", false, runTest);
+    } else {
+        runTest();
+    }
 </script>
 </body>
 </html>

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/third-party-cookie-with-and-without-user-interaction.html (227874 => 227875)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/third-party-cookie-with-and-without-user-interaction.html	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/third-party-cookie-with-and-without-user-interaction.html	2018-01-31 06:01:54 UTC (rev 227875)
@@ -69,14 +69,18 @@
             case "#step4":
                 // Flag localhost for partitioning and set a partitioned cookie.
                 document.location.hash = "step5";
-                testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, true);
-                openIframe(thirdPartyBaseUrl + subPathToSetPartitionedThirdPartyCookie + "&message=Setting partitioned, third party cookie.", runTest);
+                testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, true, runTest);
                 break;
             case "#step5":
+                // Flag localhost for partitioning and set a partitioned cookie.
                 document.location.hash = "step6";
+                openIframe(thirdPartyBaseUrl + subPathToSetPartitionedThirdPartyCookie + "&message=Setting partitioned, third party cookie.", runTest);
+                break;
+            case "#step6":
+                document.location.hash = "step7";
                 openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should only receive partitioned, third party cookie.", setUserInteractionAndContinue);
                 break;
-            case "#step6":
+            case "#step7":
                 openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=After user interaction, should receive non-partitioned cookies set in a first-party context and in a third-party context.", finishTest);
                 break;
         }
@@ -85,17 +89,17 @@
     if (document.location.host === partitionHost && document.location.hash == "" && window.testRunner && window.internals) {
         setEnableFeature(true);
 
+        testRunner.waitUntilDone();
+        testRunner.dumpChildFramesAsText();
+        document.location.hash = "step1";
+
         // Start test with third party as non-prevalent
         testRunner.setStatisticsPrevalentResource(thirdPartyHostname, false);
         testRunner.setStatisticsHasHadUserInteraction(thirdPartyOrigin, false);
-        testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, false);
-
-        testRunner.waitUntilDone();
-        testRunner.dumpChildFramesAsText();
-        document.location.hash = "step1";
+        testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, false, runTest);
+    } else {
+        runTest();
     }
-
-    runTest();
 </script>
 </body>
 </html>

Modified: trunk/LayoutTests/platform/mac-wk2/TestExpectations (227874 => 227875)


--- trunk/LayoutTests/platform/mac-wk2/TestExpectations	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/LayoutTests/platform/mac-wk2/TestExpectations	2018-01-31 06:01:54 UTC (rev 227875)
@@ -804,14 +804,14 @@
 [ HighSierra+ ] http/tests/resourceLoadStatistics/third-party-cookie-with-and-without-user-interaction.html [ Pass ]
 [ HighSierra+ ] http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html [ Pass Timeout ]
 [ HighSierra+ ] http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html [ Pass ]
+[ HighSierra+ ] http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html [ Pass ]
 [ HighSierra+ ] http/tests/resourceLoadStatistics/add-blocking-to-redirect.html [ Pass ]
 [ HighSierra+ ] http/tests/resourceLoadStatistics/remove-partitioning-in-redirect.html [ Pass ]
 [ HighSierra+ ] http/tests/resourceLoadStatistics/remove-blocking-in-redirect.html [ Pass ]
 [ HighSierra+ ] http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store.html [ Pass ]
 [ HighSierra+ ] http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html [ Pass ]
+[ HighSierra+ ] http/tests/resourceLoadStatistics/grandfathering.html [ Pass ]
 
-webkit.org/b/181958 [ HighSierra+ ] http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html [ Pass Failure ]
-
 # <rdar://problem/33555759>
 webkit.org/b/177616 [ HighSierra+ ] http/tests/media/video-buffered-range-contains-currentTime.html [ Pass Timeout ]
 
@@ -875,8 +875,6 @@
 
 webkit.org/b/181753 [ HighSierra Release ] http/wpt/service-workers/update-service-worker.https.html [ Pass Failure ]
 
-webkit.org/b/181482 http/tests/resourceLoadStatistics/grandfathering.html [ Pass ]
-
 webkit.org/b/181831 [ HighSierra ] fast/forms/searchfield-heights.html [ Pass Failure ]
 
 webkit.org/b/181957 [ Release ] http/tests/misc/resource-timing-resolution.html [ Pass Failure ]

Modified: trunk/Source/WebKit/ChangeLog (227874 => 227875)


--- trunk/Source/WebKit/ChangeLog	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Source/WebKit/ChangeLog	2018-01-31 06:01:54 UTC (rev 227875)
@@ -1,3 +1,41 @@
+2018-01-30  John Wilander  <wilan...@apple.com>
+
+        Add callbacks to testRunner.statisticsSetShouldPartitionCookiesForHost() and testRunner.statisticsUpdateCookiePartitioning()
+        https://bugs.webkit.org/show_bug.cgi?id=181958
+        https://bugs.webkit.org/show_bug.cgi?id=182072
+        <rdar://problem/36801804>
+        <rdar://problem/36845795>
+
+        Reviewed by Brent Fulgham.
+
+        Because of the asynchronous nature of XPC and cookies,
+        we need callbacks in these TestRunner functions so that
+        the layout tests can wait for state changes to finish
+        before checking test conditions.
+
+        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
+        (WKWebsiteDataStoreStatisticsUpdateCookiePartitioning):
+        (WKWebsiteDataStoreSetStatisticsShouldPartitionCookiesForHost):
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (-[WKWebsiteDataStore _resourceLoadStatisticsUpdateCookiePartitioning]):
+        (-[WKWebsiteDataStore _resourceLoadStatisticsUpdateCookiePartitioning:]):
+        (-[WKWebsiteDataStore _resourceLoadStatisticsSetShouldPartitionCookies:forHost:]):
+        (-[WKWebsiteDataStore _resourceLoadStatisticsSetShouldPartitionCookies:forHost:completionHandler:]):
+        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated):
+        (WebKit::WebResourceLoadStatisticsStore::logUserInteraction):
+        (WebKit::WebResourceLoadStatisticsStore::logNonRecentUserInteraction):
+        (WebKit::WebResourceLoadStatisticsStore::scheduleCookiePartitioningUpdate):
+        (WebKit::WebResourceLoadStatisticsStore::scheduleCookiePartitioningUpdateForDomains):
+        (WebKit::WebResourceLoadStatisticsStore::scheduleClearPartitioningStateForDomains):
+        (WebKit::WebResourceLoadStatisticsStore::mergeWithDataFromDecoder):
+        (WebKit::WebResourceLoadStatisticsStore::clearInMemory):
+        (WebKit::WebResourceLoadStatisticsStore::updateCookiePartitioning):
+        (WebKit::WebResourceLoadStatisticsStore::updateCookiePartitioningForDomains):
+        (WebKit::WebResourceLoadStatisticsStore::clearPartitioningStateForDomains):
+        * UIProcess/WebResourceLoadStatisticsStore.h:
+
 2018-01-30  Ryosuke Niwa  <rn...@webkit.org>
 
         REGRESSION(r227550): Resource timing API is disabled on macOS

Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp (227874 => 227875)


--- trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp	2018-01-31 06:01:54 UTC (rev 227875)
@@ -244,7 +244,7 @@
     if (!store)
         return;
 
-    store->scheduleCookiePartitioningUpdate();
+    store->scheduleCookiePartitioningUpdate([]() { });
 }
 
 void WKWebsiteDataStoreSetStatisticsShouldPartitionCookiesForHost(WKWebsiteDataStoreRef dataStoreRef, WKStringRef host, bool value)
@@ -254,9 +254,9 @@
         return;
 
     if (value)
-        store->scheduleCookiePartitioningUpdateForDomains({ WebKit::toImpl(host)->string() }, { }, { }, WebKit::ShouldClearFirst::No);
+        store->scheduleCookiePartitioningUpdateForDomains({ WebKit::toImpl(host)->string() }, { }, { }, WebKit::ShouldClearFirst::No, []() { });
     else
-        store->scheduleClearPartitioningStateForDomains({ WebKit::toImpl(host)->string() });
+        store->scheduleClearPartitioningStateForDomains({ WebKit::toImpl(host)->string() }, []() { });
 }
 
 void WKWebsiteDataStoreStatisticsSubmitTelemetry(WKWebsiteDataStoreRef dataStoreRef)

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm (227874 => 227875)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2018-01-31 06:01:54 UTC (rev 227875)
@@ -497,23 +497,43 @@
 
 - (void)_resourceLoadStatisticsUpdateCookiePartitioning
 {
+    [self _resourceLoadStatisticsUpdateCookiePartitioning:^() { }];
+}
+
+- (void)_resourceLoadStatisticsUpdateCookiePartitioning:(void (^)())completionHandler
+{
     auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
-    if (!store)
+    if (!store) {
+        completionHandler();
         return;
-
-    store->scheduleCookiePartitioningUpdate();
+    }
+    
+    store->scheduleCookiePartitioningUpdate([completionHandler = makeBlockPtr(completionHandler)]() {
+        completionHandler();
+    });
 }
 
 - (void)_resourceLoadStatisticsSetShouldPartitionCookies:(BOOL)value forHost:(NSString *)host
 {
+    [self _resourceLoadStatisticsSetShouldPartitionCookies:value forHost:host completionHandler:^() { }];
+}
+
+- (void)_resourceLoadStatisticsSetShouldPartitionCookies:(BOOL)value forHost:(NSString *)host completionHandler:(void (^)())completionHandler
+{
     auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
-    if (!store)
+    if (!store) {
+        completionHandler();
         return;
+    }
 
     if (value)
-        store->scheduleCookiePartitioningUpdateForDomains({ host }, { }, { }, WebKit::ShouldClearFirst::No);
+        store->scheduleCookiePartitioningUpdateForDomains({ host }, { }, { }, WebKit::ShouldClearFirst::No, [completionHandler = makeBlockPtr(completionHandler)]() {
+            completionHandler();
+        });
     else
-        store->scheduleClearPartitioningStateForDomains({ host });
+        store->scheduleClearPartitioningStateForDomains({ host }, [completionHandler = makeBlockPtr(completionHandler)]() {
+            completionHandler();
+        });
 }
 
 - (void)_resourceLoadStatisticsSubmitTelemetry

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h (227874 => 227875)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2018-01-31 06:01:54 UTC (rev 227875)
@@ -73,8 +73,10 @@
 - (void)_resourceLoadStatisticsSetMaxStatisticsEntries:(size_t)entries WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 - (void)_resourceLoadStatisticsSetPruneEntriesDownTo:(size_t)entries WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 - (void)_resourceLoadStatisticsProcessStatisticsAndDataRecords WK_API_AVAILABLE(macosx(10.13), ios(11.0));
-- (void)_resourceLoadStatisticsUpdateCookiePartitioning WK_API_AVAILABLE(macosx(10.13), ios(11.0));
-- (void)_resourceLoadStatisticsSetShouldPartitionCookies:(BOOL)value forHost:(NSString *)host WK_API_AVAILABLE(macosx(10.13), ios(11.0));
+- (void)_resourceLoadStatisticsUpdateCookiePartitioning WK_API_DEPRECATED_WITH_REPLACEMENT("_resourceLoadStatisticsUpdateCookiePartitioning", macosx(10.13, WK_MAC_TBA), ios(11.0, WK_IOS_TBA));
+- (void)_resourceLoadStatisticsUpdateCookiePartitioning:(void (^)())completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetShouldPartitionCookies:(BOOL)value forHost:(NSString *)host WK_API_DEPRECATED_WITH_REPLACEMENT("_resourceLoadStatisticsSetShouldPartitionCookies", macosx(10.13, WK_MAC_TBA), ios(11.0, WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetShouldPartitionCookies:(BOOL)value forHost:(NSString *)host completionHandler:(void (^)())completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (void)_resourceLoadStatisticsSubmitTelemetry WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 - (void)_resourceLoadStatisticsSetNotifyPagesWhenDataRecordsWereScanned:(BOOL)value WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 - (void)_resourceLoadStatisticsSetShouldClassifyResourcesBeforeDataRecordsRemoval:(BOOL)value WK_API_AVAILABLE(macosx(10.13), ios(11.0));

Modified: trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp (227874 => 227875)


--- trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp	2018-01-31 06:01:54 UTC (rev 227875)
@@ -254,7 +254,7 @@
 
     mergeStatistics(WTFMove(origins));
     // Fire before processing statistics to propagate user interaction as fast as possible to the network process.
-    updateCookiePartitioning();
+    updateCookiePartitioning([]() { });
     processStatisticsAndDataRecords();
 }
 
@@ -386,7 +386,7 @@
         statistics.mostRecentUserInteractionTime = WallTime::now();
 
         if (statistics.isMarkedForCookiePartitioning || statistics.isMarkedForCookieBlocking)
-            updateCookiePartitioningForDomains({ }, { }, { primaryDomain }, ShouldClearFirst::No);
+            updateCookiePartitioningForDomains({ }, { }, { primaryDomain }, ShouldClearFirst::No, []() { });
     });
 }
 
@@ -400,7 +400,7 @@
         statistics.hadUserInteraction = true;
         statistics.mostRecentUserInteractionTime = WallTime::now() - (m_parameters.timeToLiveCookiePartitionFree + Seconds::fromHours(1));
 
-        updateCookiePartitioningForDomains({ primaryDomain }, { }, { }, ShouldClearFirst::No);
+        updateCookiePartitioningForDomains({ primaryDomain }, { }, { }, ShouldClearFirst::No, []() { });
     });
 }
 
@@ -563,31 +563,31 @@
     });
 }
 
-void WebResourceLoadStatisticsStore::scheduleCookiePartitioningUpdate()
+void WebResourceLoadStatisticsStore::scheduleCookiePartitioningUpdate(CompletionHandler<void()>&& callback)
 {
     // Helper function used by testing system. Should only be called from the main thread.
     ASSERT(RunLoop::isMain());
 
-    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
-        updateCookiePartitioning();
+    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this), callback = WTFMove(callback)] () mutable {
+        updateCookiePartitioning(WTFMove(callback));
     });
 }
 
-void WebResourceLoadStatisticsStore::scheduleCookiePartitioningUpdateForDomains(const Vector<String>& domainsToPartition, const Vector<String>& domainsToBlock, const Vector<String>& domainsToNeitherPartitionNorBlock, ShouldClearFirst shouldClearFirst)
+void WebResourceLoadStatisticsStore::scheduleCookiePartitioningUpdateForDomains(const Vector<String>& domainsToPartition, const Vector<String>& domainsToBlock, const Vector<String>& domainsToNeitherPartitionNorBlock, ShouldClearFirst shouldClearFirst, CompletionHandler<void()>&& callback)
 {
     // Helper function used by testing system. Should only be called from the main thread.
     ASSERT(RunLoop::isMain());
-    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this), domainsToPartition = crossThreadCopy(domainsToPartition), domainsToBlock = crossThreadCopy(domainsToBlock), domainsToNeitherPartitionNorBlock = crossThreadCopy(domainsToNeitherPartitionNorBlock), shouldClearFirst] {
-        updateCookiePartitioningForDomains(domainsToPartition, domainsToBlock, domainsToNeitherPartitionNorBlock, shouldClearFirst);
+    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this), domainsToPartition = crossThreadCopy(domainsToPartition), domainsToBlock = crossThreadCopy(domainsToBlock), domainsToNeitherPartitionNorBlock = crossThreadCopy(domainsToNeitherPartitionNorBlock), shouldClearFirst, callback = WTFMove(callback)] () mutable {
+        updateCookiePartitioningForDomains(domainsToPartition, domainsToBlock, domainsToNeitherPartitionNorBlock, shouldClearFirst, WTFMove(callback));
     });
 }
 
-void WebResourceLoadStatisticsStore::scheduleClearPartitioningStateForDomains(const Vector<String>& domains)
+void WebResourceLoadStatisticsStore::scheduleClearPartitioningStateForDomains(const Vector<String>& domains, CompletionHandler<void()>&& callback)
 {
     // Helper function used by testing system. Should only be called from the main thread.
     ASSERT(RunLoop::isMain());
-    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this), domains = crossThreadCopy(domains)] {
-        clearPartitioningStateForDomains(domains);
+    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this), domains = crossThreadCopy(domains), callback = WTFMove(callback)] () mutable {
+        clearPartitioningStateForDomains(domains, WTFMove(callback));
     });
 }
 
@@ -732,7 +732,7 @@
         return;
 
     mergeStatistics(WTFMove(loadedStatistics));
-    updateCookiePartitioning();
+    updateCookiePartitioning([]() { });
 
     Vector<OperatingDate> operatingDates;
     succeeded = decoder.decodeObjects("operatingDates", operatingDates, [](KeyedDecoder& decoder, OperatingDate& date) {
@@ -756,7 +756,7 @@
     m_resourceStatisticsMap.clear();
     m_operatingDates.clear();
 
-    updateCookiePartitioningForDomains({ }, { }, { }, ShouldClearFirst::Yes);
+    updateCookiePartitioningForDomains({ }, { }, { }, ShouldClearFirst::Yes, []() { });
 }
 
 bool WebResourceLoadStatisticsStore::wasAccessedAsFirstPartyDueToUserInteraction(const ResourceLoadStatistics& current, const ResourceLoadStatistics& updated)
@@ -794,7 +794,7 @@
     return statistic.isPrevalentResource && !statistic.hadUserInteraction;
 }
 
-void WebResourceLoadStatisticsStore::updateCookiePartitioning()
+void WebResourceLoadStatisticsStore::updateCookiePartitioning(CompletionHandler<void()>&& callback)
 {
     ASSERT(!RunLoop::isMain());
 
@@ -819,20 +819,25 @@
         }
     }
 
-    if (domainsToPartition.isEmpty() && domainsToBlock.isEmpty() && domainsToNeitherPartitionNorBlock.isEmpty())
+    if (domainsToPartition.isEmpty() && domainsToBlock.isEmpty() && domainsToNeitherPartitionNorBlock.isEmpty()) {
+        callback();
         return;
+    }
 
-    RunLoop::main().dispatch([this, protectedThis = makeRef(*this), domainsToPartition = crossThreadCopy(domainsToPartition), domainsToBlock = crossThreadCopy(domainsToBlock), domainsToNeitherPartitionNorBlock = crossThreadCopy(domainsToNeitherPartitionNorBlock)] () {
+    RunLoop::main().dispatch([this, protectedThis = makeRef(*this), domainsToPartition = crossThreadCopy(domainsToPartition), domainsToBlock = crossThreadCopy(domainsToBlock), domainsToNeitherPartitionNorBlock = crossThreadCopy(domainsToNeitherPartitionNorBlock), callback = WTFMove(callback)] () {
         m_updatePrevalentDomainsToPartitionOrBlockCookiesHandler(domainsToPartition, domainsToBlock, domainsToNeitherPartitionNorBlock, ShouldClearFirst::No);
+        callback();
     });
 }
 
-void WebResourceLoadStatisticsStore::updateCookiePartitioningForDomains(const Vector<String>& domainsToPartition, const Vector<String>& domainsToBlock, const Vector<String>& domainsToNeitherPartitionNorBlock, ShouldClearFirst shouldClearFirst)
+void WebResourceLoadStatisticsStore::updateCookiePartitioningForDomains(const Vector<String>& domainsToPartition, const Vector<String>& domainsToBlock, const Vector<String>& domainsToNeitherPartitionNorBlock, ShouldClearFirst shouldClearFirst, CompletionHandler<void()>&& callback)
 {
     ASSERT(!RunLoop::isMain());
-    if (domainsToPartition.isEmpty() && domainsToBlock.isEmpty() && domainsToNeitherPartitionNorBlock.isEmpty() && shouldClearFirst == ShouldClearFirst::No)
+    if (domainsToPartition.isEmpty() && domainsToBlock.isEmpty() && domainsToNeitherPartitionNorBlock.isEmpty() && shouldClearFirst == ShouldClearFirst::No) {
+        callback();
         return;
-
+    }
+    
     RunLoop::main().dispatch([this, shouldClearFirst, protectedThis = makeRef(*this), domainsToPartition = crossThreadCopy(domainsToPartition), domainsToBlock = crossThreadCopy(domainsToBlock), domainsToNeitherPartitionNorBlock = crossThreadCopy(domainsToNeitherPartitionNorBlock)] () {
         m_updatePrevalentDomainsToPartitionOrBlockCookiesHandler(domainsToPartition, domainsToBlock, domainsToNeitherPartitionNorBlock, shouldClearFirst);
     });
@@ -852,13 +857,17 @@
 
     for (auto& domain : domainsToBlock)
         ensureResourceStatisticsForPrimaryDomain(domain).isMarkedForCookieBlocking = true;
+
+    callback();
 }
 
-void WebResourceLoadStatisticsStore::clearPartitioningStateForDomains(const Vector<String>& domains)
+void WebResourceLoadStatisticsStore::clearPartitioningStateForDomains(const Vector<String>& domains, CompletionHandler<void()>&& callback)
 {
     ASSERT(!RunLoop::isMain());
-    if (domains.isEmpty())
+    if (domains.isEmpty()) {
+        callback();
         return;
+    }
 
     RunLoop::main().dispatch([this, protectedThis = makeRef(*this), domains = crossThreadCopy(domains)] () {
         m_removeDomainsHandler(domains);
@@ -869,6 +878,8 @@
         statistic.isMarkedForCookiePartitioning = false;
         statistic.isMarkedForCookieBlocking = false;
     }
+
+    callback();
 }
 
 void WebResourceLoadStatisticsStore::resetCookiePartitioningState()

Modified: trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h (227874 => 227875)


--- trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h	2018-01-31 06:01:54 UTC (rev 227875)
@@ -106,9 +106,9 @@
     void setSubframeUnderTopFrameOrigin(const WebCore::URL& subframe, const WebCore::URL& topFrame);
     void setSubresourceUnderTopFrameOrigin(const WebCore::URL& subresource, const WebCore::URL& topFrame);
     void setSubresourceUniqueRedirectTo(const WebCore::URL& subresource, const WebCore::URL& hostNameRedirectedTo);
-    void scheduleCookiePartitioningUpdate();
-    void scheduleCookiePartitioningUpdateForDomains(const Vector<String>& domainsToPartition, const Vector<String>& domainsToBlock, const Vector<String>& domainsToNeitherPartitionNorBlock, ShouldClearFirst);
-    void scheduleClearPartitioningStateForDomains(const Vector<String>& domains);
+    void scheduleCookiePartitioningUpdate(CompletionHandler<void()>&&);
+    void scheduleCookiePartitioningUpdateForDomains(const Vector<String>& domainsToPartition, const Vector<String>& domainsToBlock, const Vector<String>& domainsToNeitherPartitionNorBlock, ShouldClearFirst, CompletionHandler<void()>&&);
+    void scheduleClearPartitioningStateForDomains(const Vector<String>& domains, CompletionHandler<void()>&&);
     void scheduleStatisticsAndDataRecordsProcessing();
     void submitTelemetry();
     void scheduleCookiePartitioningStateReset();
@@ -162,9 +162,9 @@
     bool hasHadUnexpiredRecentUserInteraction(WebCore::ResourceLoadStatistics&) const;
     void includeTodayAsOperatingDateIfNecessary();
     Vector<String> topPrivatelyControlledDomainsToRemoveWebsiteDataFor();
-    void updateCookiePartitioning();
-    void updateCookiePartitioningForDomains(const Vector<String>& domainsToPartition, const Vector<String>& domainsToBlock, const Vector<String>& domainsToNeitherPartitionNorBlock, ShouldClearFirst);
-    void clearPartitioningStateForDomains(const Vector<String>& domains);
+    void updateCookiePartitioning(CompletionHandler<void()>&&);
+    void updateCookiePartitioningForDomains(const Vector<String>& domainsToPartition, const Vector<String>& domainsToBlock, const Vector<String>& domainsToNeitherPartitionNorBlock, ShouldClearFirst, CompletionHandler<void()>&&);
+    void clearPartitioningStateForDomains(const Vector<String>& domains, CompletionHandler<void()>&&);
     void mergeStatistics(Vector<WebCore::ResourceLoadStatistics>&&);
     WebCore::ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
     void processStatisticsAndDataRecords();

Modified: trunk/Tools/ChangeLog (227874 => 227875)


--- trunk/Tools/ChangeLog	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Tools/ChangeLog	2018-01-31 06:01:54 UTC (rev 227875)
@@ -1,3 +1,33 @@
+2018-01-30  John Wilander  <wilan...@apple.com>
+
+        Add callbacks to testRunner.statisticsSetShouldPartitionCookiesForHost() and testRunner.statisticsUpdateCookiePartitioning()
+        https://bugs.webkit.org/show_bug.cgi?id=181958
+        https://bugs.webkit.org/show_bug.cgi?id=182072
+        <rdar://problem/36801804>
+        <rdar://problem/36845795>
+
+        Reviewed by Brent Fulgham.
+
+        Because of the asynchronous nature of XPC and cookies,
+        we need callbacks in these TestRunner functions so that
+        the layout tests can wait for state changes to finish
+        before checking test conditions.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::didReceiveMessageToPage):
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::statisticsUpdateCookiePartitioning):
+        (WTR::TestRunner::statisticsSetShouldPartitionCookiesForHost):
+        (WTR::TestRunner::statisticsCallDidSetPartitionOrBlockCookiesForHostCallback):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didSetPartitionOrBlockCookiesForHost):
+        * WebKitTestRunner/TestInvocation.h:
+        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
+        (WTR::TestController::statisticsUpdateCookiePartitioning):
+        (WTR::TestController::statisticsSetShouldPartitionCookiesForHost):
+
 2018-01-30  Basuke Suzuki  <basuke.suz...@sony.com>
 
         [webkitpy] Config file for apache is copied twice.

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (227874 => 227875)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2018-01-31 06:01:54 UTC (rev 227875)
@@ -283,8 +283,8 @@
     void setStatisticsTimeToLiveCookiePartitionFree(double seconds);
     void statisticsNotifyObserver();
     void statisticsProcessStatisticsAndDataRecords();
-    void statisticsUpdateCookiePartitioning();
-    void statisticsSetShouldPartitionCookiesForHost(DOMString hostName, boolean value);
+    void statisticsUpdateCookiePartitioning(object callback);
+    void statisticsSetShouldPartitionCookiesForHost(DOMString hostName, boolean value, object callback);
     void statisticsSubmitTelemetry();
     void setStatisticsNotifyPagesWhenDataRecordsWereScanned(boolean value);
     void setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(boolean value);

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp (227874 => 227875)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2018-01-31 06:01:54 UTC (rev 227875)
@@ -245,6 +245,11 @@
         return;
     }
 
+    if (WKStringIsEqualToUTF8CString(messageName, "CallDidSetPartitionOrBlockCookiesForHost")) {
+        m_testRunner->statisticsCallDidSetPartitionOrBlockCookiesForHostCallback();
+        return;
+    }
+
     if (WKStringIsEqualToUTF8CString(messageName, "CallDidRemoveAllSessionCredentialsCallback")) {
         m_testRunner->callDidRemoveAllSessionCredentialsCallback();
         return;

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (227874 => 227875)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2018-01-31 06:01:54 UTC (rev 227875)
@@ -651,6 +651,7 @@
     StatisticsDidScanDataRecordsCallbackID,
     StatisticsDidRunTelemetryCallbackID,
     StatisticsDidClearThroughWebsiteDataRemovalCallbackID,
+    StatisticsDidSetPartitionOrBlockCookiesForHostCallbackID,
     DidRemoveAllSessionCredentialsCallbackID,
     GetApplicationManifestCallbackID,
     FirstUIScriptCallbackID = 100
@@ -1553,14 +1554,18 @@
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), 0, nullptr);
 }
 
-void TestRunner::statisticsUpdateCookiePartitioning()
+void TestRunner::statisticsUpdateCookiePartitioning(JSValueRef callback)
 {
+    cacheTestRunnerCallback(StatisticsDidSetPartitionOrBlockCookiesForHostCallbackID, callback);
+
     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsUpdateCookiePartitioning"));
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), 0, nullptr);
 }
 
-void TestRunner::statisticsSetShouldPartitionCookiesForHost(JSStringRef hostName, bool value)
+void TestRunner::statisticsSetShouldPartitionCookiesForHost(JSStringRef hostName, bool value, JSValueRef callback)
 {
+    cacheTestRunnerCallback(StatisticsDidSetPartitionOrBlockCookiesForHostCallbackID, callback);
+
     Vector<WKRetainPtr<WKStringRef>> keys;
     Vector<WKRetainPtr<WKTypeRef>> values;
     
@@ -1584,6 +1589,11 @@
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
 }
 
+void TestRunner::statisticsCallDidSetPartitionOrBlockCookiesForHostCallback()
+{
+    callTestRunnerCallback(StatisticsDidSetPartitionOrBlockCookiesForHostCallbackID);
+}
+
 void TestRunner::statisticsSubmitTelemetry()
 {
     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsSubmitTelemetry"));

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (227874 => 227875)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2018-01-31 06:01:54 UTC (rev 227875)
@@ -367,8 +367,9 @@
     void statisticsDidRunTelemetryCallback(unsigned totalPrevalentResources, unsigned totalPrevalentResourcesWithUserInteraction, unsigned top3SubframeUnderTopFrameOrigins);
     void statisticsNotifyObserver();
     void statisticsProcessStatisticsAndDataRecords();
-    void statisticsUpdateCookiePartitioning();
-    void statisticsSetShouldPartitionCookiesForHost(JSStringRef hostName, bool value);
+    void statisticsUpdateCookiePartitioning(JSValueRef callback);
+    void statisticsSetShouldPartitionCookiesForHost(JSStringRef hostName, bool value, JSValueRef callback);
+    void statisticsCallDidSetPartitionOrBlockCookiesForHostCallback();
     void statisticsSubmitTelemetry();
     void setStatisticsLastSeen(JSStringRef hostName, double seconds);
     void setStatisticsPrevalentResource(JSStringRef hostName, bool value);

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (227874 => 227875)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2018-01-31 06:01:54 UTC (rev 227875)
@@ -1345,6 +1345,12 @@
     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
 }
 
+void TestInvocation::didSetPartitionOrBlockCookiesForHost()
+{
+    WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetPartitionOrBlockCookiesForHost"));
+    WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
+}
+
 void TestInvocation::didRemoveAllSessionCredentials()
 {
     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidRemoveAllSessionCredentialsCallback"));

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.h (227874 => 227875)


--- trunk/Tools/WebKitTestRunner/TestInvocation.h	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.h	2018-01-31 06:01:54 UTC (rev 227875)
@@ -72,6 +72,7 @@
     void notifyDownloadDone();
 
     void didClearStatisticsThroughWebsiteDataRemoval();
+    void didSetPartitionOrBlockCookiesForHost();
 
     void didRemoveAllSessionCredentials();
     

Modified: trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm (227874 => 227875)


--- trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2018-01-31 05:23:52 UTC (rev 227874)
+++ trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2018-01-31 06:01:54 UTC (rev 227875)
@@ -376,12 +376,16 @@
 
 void TestController::statisticsUpdateCookiePartitioning()
 {
-    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsUpdateCookiePartitioning];
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsUpdateCookiePartitioning:^() {
+        m_currentInvocation->didSetPartitionOrBlockCookiesForHost();
+    }];
 }
 
 void TestController::statisticsSetShouldPartitionCookiesForHost(WKStringRef hostName, bool value)
 {
-    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetShouldPartitionCookies:value forHost:toNSString(hostName)];
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetShouldPartitionCookies:value forHost:toNSString(hostName) completionHandler:^() {
+        m_currentInvocation->didSetPartitionOrBlockCookiesForHost();
+    }];
 }
 
 void TestController::statisticsSubmitTelemetry()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to