Resource Load Statistics: Make testRunner.statisticsResetToConsistentState() take...
authorwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jul 2018 17:09:30 +0000 (17:09 +0000)
committerwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jul 2018 17:09:30 +0000 (17:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187499
<rdar://problem/41999431>

Reviewed by Chris Dumez.

Source/WebKit:

* UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
(WKWebsiteDataStoreStatisticsResetToConsistentState):
    Now uses a WTF::CallbackAggregator to call its
    completion handler when both the call to
    WebResourceLoadStatisticsStore::scheduleClearInMemory()
    and to
    WebResourceLoadStatisticsStore::resetParametersToDefaultValues()
    are complete.
* UIProcess/API/C/WKWebsiteDataStoreRef.h:
* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::scheduleClearInMemory):
    Now takes a WTF::CompletionHandler so that it can support the
    completion handler in
    WKWebsiteDataStoreStatisticsResetToConsistentState().
(WebKit::WebResourceLoadStatisticsStore::resetParametersToDefaultValues):
    Now takes a WTF::CompletionHandler so that it can support the
    completion handler in
    WKWebsiteDataStoreStatisticsResetToConsistentState().
* UIProcess/WebResourceLoadStatisticsStore.h:

Tools:

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::didReceiveMessageToPage):
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::statisticsResetToConsistentState):
(WTR::TestRunner::statisticsCallDidResetToConsistentStateCallback):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::statisticsResetToConsistentState):
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didResetStatisticsToConsistentState):
* WebKitTestRunner/TestInvocation.h:

LayoutTests:

These changes are to adopt and make use of the new completion handler in
testRunner.statisticsResetToConsistentState().

* http/tests/resourceLoadStatistics/add-blocking-to-redirect.html:
* http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html:
* http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics.html:
* http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins.html:
* http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins.html:
* http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to.html:
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics.html:
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins.html:
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion.html:
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent.html:
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins.html:
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to.html:
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion.html:
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent.html:
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to.html:
* http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics.html:
* http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html:
* http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store.html:
* http/tests/resourceLoadStatistics/grandfathering.html:
* http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction.html:
* http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction.html:
* http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html:
* 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/partitioned-and-unpartitioned-cookie-deletion.html:
* http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout-expected.txt:
* http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html:
* http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html:
* http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown.html:
* http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown.html:
* http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout.html:
* http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction.html:
* http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction.html:
* http/tests/resourceLoadStatistics/prune-statistics.html:
* http/tests/resourceLoadStatistics/remove-blocking-in-redirect.html:
* http/tests/resourceLoadStatistics/remove-partitioning-in-redirect.html:
* 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:
* http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html:
* http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html:
* http/tests/resourceLoadStatistics/telemetry-generation.html:
* http/tests/resourceLoadStatistics/third-party-cookie-with-and-without-user-interaction.html:
* http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame.html:
* http/tests/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time.html:
* http/tests/resourceLoadStatistics/user-interaction-reported-after-website-data-removal.html:

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

67 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect.html
LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to.html
LayoutTests/http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics.html
LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html
LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store.html
LayoutTests/http/tests/resourceLoadStatistics/grandfathering.html
LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction.html
LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction.html
LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html
LayoutTests/http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html
LayoutTests/http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout-expected.txt
LayoutTests/http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html
LayoutTests/http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown.html
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown.html
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout.html
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction.html
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction.html
LayoutTests/http/tests/resourceLoadStatistics/prune-statistics.html
LayoutTests/http/tests/resourceLoadStatistics/remove-blocking-in-redirect.html
LayoutTests/http/tests/resourceLoadStatistics/remove-partitioning-in-redirect.html
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip.html
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html
LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html
LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html
LayoutTests/http/tests/resourceLoadStatistics/telemetry-generation.html
LayoutTests/http/tests/resourceLoadStatistics/third-party-cookie-with-and-without-user-interaction.html
LayoutTests/http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame.html
LayoutTests/http/tests/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time.html
LayoutTests/http/tests/resourceLoadStatistics/user-interaction-reported-after-website-data-removal.html
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp
Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h
Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp
Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestInvocation.cpp
Tools/WebKitTestRunner/TestInvocation.h

index 3358cf9..f10e584 100644 (file)
@@ -1,3 +1,68 @@
+2018-07-10  John Wilander  <wilander@apple.com>
+
+        Resource Load Statistics: Make testRunner.statisticsResetToConsistentState() take a completion handler
+        https://bugs.webkit.org/show_bug.cgi?id=187499
+        <rdar://problem/41999431>
+
+        Reviewed by Chris Dumez.
+
+        These changes are to adopt and make use of the new completion handler in
+        testRunner.statisticsResetToConsistentState().
+
+        * http/tests/resourceLoadStatistics/add-blocking-to-redirect.html:
+        * http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html:
+        * http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics.html:
+        * http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins.html:
+        * http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins.html:
+        * http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to.html:
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics.html:
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins.html:
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion.html:
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent.html:
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins.html:
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to.html:
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion.html:
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent.html:
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to.html:
+        * http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics.html:
+        * http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html:
+        * http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store.html:
+        * http/tests/resourceLoadStatistics/grandfathering.html:
+        * http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction.html:
+        * http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction.html:
+        * http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html:
+        * 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/partitioned-and-unpartitioned-cookie-deletion.html:
+        * http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout-expected.txt:
+        * http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html:
+        * http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html:
+        * http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown.html:
+        * http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown.html:
+        * http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout.html:
+        * http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction.html:
+        * http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction.html:
+        * http/tests/resourceLoadStatistics/prune-statistics.html:
+        * http/tests/resourceLoadStatistics/remove-blocking-in-redirect.html:
+        * http/tests/resourceLoadStatistics/remove-partitioning-in-redirect.html:
+        * 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:
+        * http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html:
+        * http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html:
+        * http/tests/resourceLoadStatistics/telemetry-generation.html:
+        * http/tests/resourceLoadStatistics/third-party-cookie-with-and-without-user-interaction.html:
+        * http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame.html:
+        * http/tests/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time.html:
+        * http/tests/resourceLoadStatistics/user-interaction-reported-after-website-data-removal.html:
+
 2018-07-10  Truitt Savell  <tsavell@apple.com>
 
         [ MacOS Debug ] Layout Test media/media-fragments/TC0015.html is flaky
index 0666eff..1f689ee 100644 (file)
@@ -9,11 +9,13 @@
     description("Tests that blocking is added mid-flight in redirects.");
     jsTestIsAsync = true;
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     const partitionHost = "127.0.0.1:8000";
                 openIframe(redirectChainUrl + "&message=Redirect case 3, after attempted cookie creation, should receive no cookie.", runTest);
                 break;
             case "#step10":
-                setEnableFeature(false);
-                finishJSTest();
+                setEnableFeature(false, finishJSTest);
                 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);
+        setEnableFeature(true, function () {
+            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();
     }
index 7c5f9fe..e6f48df 100644 (file)
@@ -9,11 +9,13 @@
     description("Tests that partitioning is added mid-flight in redirects.");
     jsTestIsAsync = true;
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     const partitionHost = "127.0.0.1:8000";
     }
 
     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);
+        setEnableFeature(true, function () {
+            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();
     }
index 547c911..9a5d275 100644 (file)
@@ -19,8 +19,9 @@
         else
             testPassed("Host did not get classified as prevalent resource.");
 
-        testRunner.statisticsResetToConsistentState();
-        testRunner.notifyDone();
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
     }
 
     function runTestRunnerTest() {
index 90edc8b..02d6dad 100644 (file)
@@ -19,8 +19,9 @@
         else
             testPassed("Host did not get classified as prevalent resource.");
 
-        testRunner.statisticsResetToConsistentState();
-        testRunner.notifyDone();
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
     }
 
     function runTestRunnerTest() {
index 8699709..4bf30a8 100644 (file)
@@ -18,8 +18,9 @@
         else
             testPassed("Host did not get classified as prevalent resource.");
 
-        testRunner.statisticsResetToConsistentState();
-        testRunner.notifyDone();
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
     }
 
     function runTestRunnerTest() {
index 957191f..6523e27 100644 (file)
         else
             testPassed("Host did not get classified as prevalent resource.");
 
-        testRunner.statisticsResetToConsistentState();
         internals.setResourceLoadStatisticsEnabled(false);
-        testRunner.notifyDone();
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
     }
 
     function runTestRunnerTest() {
index 4971757..8ce5461 100644 (file)
         else
             testPassed("Host classified as prevalent resource.");
 
-        testRunner.statisticsResetToConsistentState();
         internals.setResourceLoadStatisticsEnabled(false);
-        testRunner.notifyDone();        
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
     }
 
     function runTestRunnerTest() {
index 175e8de..d307ff4 100644 (file)
         else
             testPassed("Host classified as prevalent resource.");
 
-        testRunner.statisticsResetToConsistentState();
         internals.setResourceLoadStatisticsEnabled(false);
-        testRunner.notifyDone();
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
     }
 
     function runTestRunnerTest() {
index fcc68f9..bcace88 100644 (file)
     const subresourceOrigin3 = "http://127.0.0.4:8000/temp";
     const subresourceOrigin4 = "http://127.0.0.5:8000/temp";
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function runTest() {
         if (testRunner.isStatisticsVeryPrevalentResource("http://localhost:8000"))
             testFailed("Colluding localhost got classified as very prevalent resource.");
 
-        setEnableFeature(false);
-        finishJSTest();
+        setEnableFeature(false, finishJSTest);
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
-        setEnableFeature(true);
+        setEnableFeature(true, function () {
+            testRunner.setStatisticsPrevalentResource(statisticsUrl, false);
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
 
-        testRunner.setStatisticsPrevalentResource(statisticsUrl, false);
-        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
-            testFailed("Host did not get set as non-prevalent resource.");
+        });
     }
 </script>
 <iframe onload="runTest()" src="http://localhost:8000/resourceLoadStatistics/resources/redirect.php?redirectTo=http://127.0.0.1:8000/resourceLoadStatistics/onclick.html"></iframe>
index bdd4731..46b889b 100644 (file)
     const statisticsUrl = "http://" + hostUnderTest + "/temp";
     const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function completeTest() {
@@ -28,8 +30,7 @@
         else
             testPassed("Host classified as prevalent resource.");
 
-        setEnableFeature(false);
-        finishJSTest();
+        setEnableFeature(false, finishJSTest);
     }
 
     function runTest() {
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
-        setEnableFeature(true);
-        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-
-        testRunner.setStatisticsPrevalentResource(statisticsUrl, false);
-        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
-            testFailed("Host did not get set as non-prevalent resource.");
-        runTest();
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+
+            testRunner.setStatisticsPrevalentResource(statisticsUrl, false);
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+            runTest();
+        });
     }
 </script>
 </body>
index b7ae41c..25f7898 100644 (file)
         else
             testPassed("Host classified as prevalent resource.");
 
-        testRunner.statisticsResetToConsistentState();
         internals.setResourceLoadStatisticsEnabled(false);
-        testRunner.notifyDone();
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
     }
 
     function runTestRunnerTest() {
index cc46668..f04fdc4 100644 (file)
         else
             testPassed("Host classified as prevalent resource.");
 
-        testRunner.statisticsResetToConsistentState();
         internals.setResourceLoadStatisticsEnabled(false);
-        testRunner.notifyDone();
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
     }
 
     function runTestRunnerTest() {
index 3e5de35..ab2a372 100644 (file)
     const topFrameOrigin4 = "http://127.0.0.5:8000/temp";
     const topFrameOrigin5 = "http://localhost:8000/";
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function runTest() {
         if (testRunner.isStatisticsVeryPrevalentResource(topFrameOrigin5))
             testFailed("Colluding localhost got classified as very prevalent resource.");
 
-        setEnableFeature(false);
-        finishJSTest();
+        setEnableFeature(false, finishJSTest);
     }
 
     if (document.location.hash === "" && window.testRunner && window.internals) {
-        setEnableFeature(true);
-
-        testRunner.setStatisticsPrevalentResource(statisticsUrl, false);
-        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
-            testFailed("Host did not get set as non-prevalent resource.");
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsPrevalentResource(statisticsUrl, false);
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
 
-        document.location.href = topFrameOrigin5 + "resourceLoadStatistics/resources/redirect.php?redirectTo=http://127.0.0.1:8000/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion.html#continue";
+            document.location.href = topFrameOrigin5 + "resourceLoadStatistics/resources/redirect.php?redirectTo=http://127.0.0.1:8000/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion.html#continue";
+        });
     } else {
         testRunner.statisticsNotifyObserver();
         runTest();
index 9866087..f2eb3a3 100644 (file)
     const statisticsUrl = "http://" + hostUnderTest + "/temp";
     const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function completeTest() {
@@ -28,8 +30,7 @@
         else
             testPassed("Host classified as prevalent resource.");
 
-        setEnableFeature(false);
-        finishJSTest();
+        setEnableFeature(false, finishJSTest);
     }
 
     function runTest() {
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
-        setEnableFeature(true);
-        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-
-        testRunner.setStatisticsPrevalentResource(statisticsUrl, false);
-        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
-            testFailed("Host did not get set as non-prevalent resource.");
-        runTest();
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+
+            testRunner.setStatisticsPrevalentResource(statisticsUrl, false);
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+            runTest();
+        });
     }
 </script>
 </body>
index 5918692..c3e9213 100644 (file)
     const topFrameOrigin3 = "http://127.0.0.4:8000/temp";
     const topFrameOrigin4 = "http://127.0.0.5:8000/temp";
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function completeTest() {
@@ -31,8 +33,7 @@
         else
             testPassed("Host classified as prevalent resource.");
 
-        setEnableFeature(false);
-        finishJSTest();
+        setEnableFeature(false, finishJSTest);
     }
 
     function runTest() {
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
-        setEnableFeature(true);
-        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-
-        testRunner.setStatisticsPrevalentResource(statisticsUrl, false);
-        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
-            testFailed("Host did not get set as non-prevalent resource.");
-        runTest();
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+
+            testRunner.setStatisticsPrevalentResource(statisticsUrl, false);
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+            runTest();
+        });
     }
 </script>
 </body>
index dee06fd..922e3cc 100644 (file)
     for (var i = startNum; i < numberOfSubresourceDomains + startNum; ++i)
         topFrameOrigins.push("http://127.0.0." + i + ":8000/temp")
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function completeTest() {
@@ -32,8 +34,7 @@
         else
             testPassed("Host classified as very prevalent resource.");
 
-        setEnableFeature(false);
-        finishJSTest();
+        setEnableFeature(false, finishJSTest);
     }
 
     function runTestRunnerTest() {
@@ -64,8 +65,7 @@
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
-        setEnableFeature(true);
-        runTestRunnerTest();
+        setEnableFeature(true, runTestRunnerTest);
     }
 </script>
 </body>
index 1547f1a..0e99ab9 100644 (file)
         else
             testPassed("Host is no longer a prevalent resource after the store was cleared.");
 
-        testRunner.statisticsResetToConsistentState();
         internals.setResourceLoadStatisticsEnabled(false);
-        testRunner.notifyDone();
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
     }
 
     function testStep2() {
index b446ae2..457eb0e 100644 (file)
         else
             testPassed("Host is no longer a prevalent resource after the store was cleared.");
 
-        testRunner.statisticsResetToConsistentState();
         internals.setResourceLoadStatisticsEnabled(false);
-        testRunner.notifyDone();        
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
     }
 
     function runTestRunnerTest() {
index 63030fe..f49fd8b 100644 (file)
     const thirdPartyBaseUrl = thirdPartyOrigin + "/resourceLoadStatistics/resources";
     const subPathToSetThirdPartyCookie = "/set-cookie.php?name=" + thirdPartyCookieName + "&value=" + cookieValue;
 
-    function setEnableFeature(enable) {
-        if (!enable) {
-            testRunner.statisticsResetToConsistentState();
-        }
+    function setEnableFeature(enable, completionHandler) {
         testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(enable);
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function finishTest() {
-        setEnableFeature(false);
-        testRunner.notifyDone();
+        setEnableFeature(false, function() {
+            testRunner.notifyDone();
+        });
     }
 
     function fireDataModificationHandlerAndContinue() {
     }
 
     if (document.location.hash === "" && window.testRunner && window.internals) {
-        setEnableFeature(true);
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
+            testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
 
-        testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
-        testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
-
-        testRunner.waitUntilDone();
-        testRunner.dumpChildFramesAsText();
-        document.location.hash = "step1";
-    }
-
-    runTest();
+            testRunner.waitUntilDone();
+            testRunner.dumpChildFramesAsText();
+            document.location.hash = "step1";
+            runTest();
+        });
+    } else
+        runTest();
 </script>
 </body>
 </html>
index ac66008..6722208 100644 (file)
     const statisticsUrl = "http://" + hostUnderTest + "/temp";
     const otherPrevalentUrl = "http://localhost:8000/temp";
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function runTestRunnerTest() {
@@ -46,8 +48,9 @@
             else
                 testFailed("Cookie deleted or document.cookie contains other cookies: " + document.cookie);
 
-            setEnableFeature(false);
-            testRunner.notifyDone();
+            setEnableFeature(false, function() {
+                testRunner.notifyDone();
+            });
         });
         testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
         testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
         testRunner.waitUntilDone();
-        setEnableFeature(true);
-        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-        runTestRunnerTest();
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+            runTestRunnerTest();
+        });
     }
 </script>
 </body>
index 88239b5..1befc13 100644 (file)
     const statisticsUrl = "http://" + hostUnderTest + "/temp";
     const otherPrevalentUrl = "http://localhost:8000/temp";
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function runTestRunnerTest() {
@@ -46,8 +48,9 @@
             else
                 testFailed("Cookie deleted or document.cookie contains other cookies: " + document.cookie);
 
-            setEnableFeature(false);
-            testRunner.notifyDone();
+            setEnableFeature(false, function() {
+                testRunner.notifyDone();
+            });
         });
         testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
         testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
         testRunner.waitUntilDone();
-        setEnableFeature(true);
-        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-        runTestRunnerTest();
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+            runTestRunnerTest();
+        });
     }
 </script>
 </body>
index f2b4166..f24f489 100644 (file)
     const fragmentWithReturnUrl = "http://127.0.0.1:8000/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html";
     const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + partitionedCookieName;
 
-    function setEnableFeature(enable) {
-        if (!enable) {
-            testRunner.statisticsResetToConsistentState();
-        }
-        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(enable);
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function finishTest() {
-        setEnableFeature(false);
-        testRunner.notifyDone();
+        setEnableFeature(false, function() {
+            testRunner.notifyDone();
+        });
     }
 
     function openIframe(url, onLoadHandler) {
     }
 
     if (document.location.host === partitionHost && document.location.hash == "" && window.testRunner && window.internals) {
-        setEnableFeature(true);
-
-        testRunner.setStatisticsPrevalentResource(thirdPartyHostname, false);
-        testRunner.setStatisticsHasHadUserInteraction(thirdPartyOrigin, false);
-        testRunner.waitUntilDone();
-        testRunner.dumpChildFramesAsText();
-        document.location.hash = "step1";
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsPrevalentResource(thirdPartyHostname, false);
+            testRunner.setStatisticsHasHadUserInteraction(thirdPartyOrigin, false);
+            testRunner.waitUntilDone();
+            testRunner.dumpChildFramesAsText();
+            document.location.hash = "step1";
 
-        testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, false, runTest);
+            testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, false, runTest);
+        });
     } else {
         runTest();
     }
index bc0b6f9..4752395 100644 (file)
@@ -7,22 +7,17 @@
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
 
-        function setEnableFeature(enable) {
-            if (!enable)
-                testRunner.statisticsResetToConsistentState();
+        function setEnableFeature(enable, completionHandler) {
             internals.setResourceLoadStatisticsEnabled(enable);
             testRunner.setCookieStoragePartitioningEnabled(enable);
+            if (!enable)
+                testRunner.statisticsResetToConsistentState(completionHandler);
+            else
+                completionHandler();
         }
 
         function finishTest() {
-            setEnableFeature(false);
-            finishJSTest();
-        }
-
-        if (testRunner) {
-            setEnableFeature(true);
-            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-            testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            setEnableFeature(false, finishJSTest);
         }
 
         var lastPageInRedirectChainLoaded = false;
             if (lastPageInRedirectChainLoaded)
                 finishTest();
         }
+
+        if (testRunner) {
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
     </script>
 </head>
 <body>
index d382c72..67fa05c 100644 (file)
@@ -7,22 +7,17 @@
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
 
-        function setEnableFeature(enable) {
-            if (!enable)
-                testRunner.statisticsResetToConsistentState();
+        function setEnableFeature(enable, completionHandler) {
             internals.setResourceLoadStatisticsEnabled(enable);
             testRunner.setCookieStoragePartitioningEnabled(enable);
+            if (!enable)
+                testRunner.statisticsResetToConsistentState(completionHandler);
+            else
+                completionHandler();
         }
 
         function finishTest() {
-            setEnableFeature(false);
-            finishJSTest();
-        }
-
-        if (testRunner) {
-            setEnableFeature(true);
-            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-            testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            setEnableFeature(false, finishJSTest);
         }
 
         var lastPageInRedirectChainLoaded = false;
             if (lastPageInRedirectChainLoaded)
                 finishTest();
         }
+
+        if (testRunner) {
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
     </script>
 </head>
 <body>
index 08fc514..5fb23a1 100644 (file)
@@ -7,22 +7,17 @@
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
 
-        function setEnableFeature(enable) {
-            if (!enable)
-                testRunner.statisticsResetToConsistentState();
+        function setEnableFeature(enable, completionHandler) {
             internals.setResourceLoadStatisticsEnabled(enable);
             testRunner.setCookieStoragePartitioningEnabled(enable);
+            if (!enable)
+                testRunner.statisticsResetToConsistentState(completionHandler);
+            else
+                completionHandler();
         }
 
         function finishTest() {
-            setEnableFeature(false);
-            finishJSTest();
-        }
-
-        if (testRunner) {
-            setEnableFeature(true);
-            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-            testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            setEnableFeature(false, finishJSTest);
         }
 
         var lastPageInRedirectChainLoaded = false;
             if (lastPageInRedirectChainLoaded)
                 finishTest();
         }
+
+        if (testRunner) {
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
     </script>
 </head>
 <body>
index 67f89a4..3a123e8 100644 (file)
@@ -7,22 +7,17 @@
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
 
-        function setEnableFeature(enable) {
-            if (!enable)
-                testRunner.statisticsResetToConsistentState();
+        function setEnableFeature(enable, completionHandler) {
             internals.setResourceLoadStatisticsEnabled(enable);
             testRunner.setCookieStoragePartitioningEnabled(enable);
+            if (!enable)
+                testRunner.statisticsResetToConsistentState(completionHandler);
+            else
+                completionHandler();
         }
 
         function finishTest() {
-            setEnableFeature(false);
-            finishJSTest();
-        }
-
-        if (testRunner) {
-            setEnableFeature(true);
-            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-            testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            setEnableFeature(false, finishJSTest);
         }
 
         var lastPageInRedirectChainLoaded = false;
             if (lastPageInRedirectChainLoaded)
                 finishTest();
         }
+
+        if (testRunner) {
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
     </script>
 </head>
 <body>
index 4dc0f59..c1b37b9 100644 (file)
@@ -7,22 +7,17 @@
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
 
-        function setEnableFeature(enable) {
-            if (!enable)
-                testRunner.statisticsResetToConsistentState();
+        function setEnableFeature(enable, completionHandler) {
             internals.setResourceLoadStatisticsEnabled(enable);
             testRunner.setCookieStoragePartitioningEnabled(enable);
+            if (!enable)
+                testRunner.statisticsResetToConsistentState(completionHandler);
+            else
+                completionHandler();
         }
 
         function finishTest() {
-            setEnableFeature(false);
-            finishJSTest();
-        }
-
-        if (testRunner) {
-            setEnableFeature(true);
-            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-            testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            setEnableFeature(false, finishJSTest);
         }
 
         var lastPageInRedirectChainLoaded = false;
             if (lastPageInRedirectChainLoaded)
                 finishTest();
         }
+
+        if (testRunner) {
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
     </script>
 </head>
 <body>
index 65d35e6..9ece227 100644 (file)
@@ -7,22 +7,17 @@
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
 
-        function setEnableFeature(enable) {
-            if (!enable)
-                testRunner.statisticsResetToConsistentState();
+        function setEnableFeature(enable, completionHandler) {
             internals.setResourceLoadStatisticsEnabled(enable);
             testRunner.setCookieStoragePartitioningEnabled(enable);
+            if (!enable)
+                testRunner.statisticsResetToConsistentState(completionHandler);
+            else
+                completionHandler();
         }
 
         function finishTest() {
-            setEnableFeature(false);
-            finishJSTest();
-        }
-
-        if (testRunner) {
-            setEnableFeature(true);
-            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-            testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            setEnableFeature(false, finishJSTest);
         }
 
         var lastPageInRedirectChainLoaded = false;
             if (lastPageInRedirectChainLoaded)
                 finishTest();
         }
+
+        if (testRunner) {
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
     </script>
 </head>
 <body>
index 8296aa2..37e2c7c 100644 (file)
     const fragmentWithReturnUrl = "http://" + partitionHost + "/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html";
     const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + thirdPartyCookieName;
 
-    function setEnableFeature(enable) {
-        if (!enable) {
-            testRunner.statisticsResetToConsistentState();
-        }
-        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(enable);
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function finishTest() {
-        setEnableFeature(false);
-        finishJSTest();
+        setEnableFeature(false, finishJSTest);
     }
 
     function openIframe(url, onLoadHandler) {
     }
 
     if (document.location.host === partitionHost && document.location.hash === "" && window.testRunner && window.internals) {
-        setEnableFeature(true);
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
+            testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
 
-        testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
-        testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
+            testRunner.dumpChildFramesAsText();
+            document.location.hash = "step1";
 
-        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.setStatisticsPrevalentResource("http://localhost", true);
-        if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
-            testFailed("Host did not get set as prevalent resource.");
-
-        testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", true, runTest);
+            testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", true, runTest);
+        });
     } else {
         runTest();
     }
index 7a33027..a40d7f5 100644 (file)
@@ -1,15 +1,15 @@
-CONSOLE MESSAGE: line 114: Bootstrapping test.
-CONSOLE MESSAGE: line 65: Step 1.
-CONSOLE MESSAGE: line 70: Step 2.
-CONSOLE MESSAGE: line 77: Step 3.
-CONSOLE MESSAGE: line 84: Step 4.
-CONSOLE MESSAGE: line 54: setNormalCookiePartitioningTimeOutPlusUserInteractionAndContinue().
-CONSOLE MESSAGE: line 91: Step 5.
-CONSOLE MESSAGE: line 48: setShortCookiePartitioningTimeOutPlusFireShouldPartitionCookiesHandlerAndContinue().
-CONSOLE MESSAGE: line 43: fireShouldPartitionCookiesHandlerAndContinue().
-CONSOLE MESSAGE: line 98: Step 6.
-CONSOLE MESSAGE: line 54: setNormalCookiePartitioningTimeOutPlusUserInteractionAndContinue().
-CONSOLE MESSAGE: line 105: Step 7.
+CONSOLE MESSAGE: line 117: Bootstrapping test.
+CONSOLE MESSAGE: line 68: Step 1.
+CONSOLE MESSAGE: line 73: Step 2.
+CONSOLE MESSAGE: line 80: Step 3.
+CONSOLE MESSAGE: line 87: Step 4.
+CONSOLE MESSAGE: line 57: setNormalCookiePartitioningTimeOutPlusUserInteractionAndContinue().
+CONSOLE MESSAGE: line 94: Step 5.
+CONSOLE MESSAGE: line 51: setShortCookiePartitioningTimeOutPlusFireShouldPartitionCookiesHandlerAndContinue().
+CONSOLE MESSAGE: line 46: fireShouldPartitionCookiesHandlerAndContinue().
+CONSOLE MESSAGE: line 101: Step 6.
+CONSOLE MESSAGE: line 57: setNormalCookiePartitioningTimeOutPlusUserInteractionAndContinue().
+CONSOLE MESSAGE: line 108: Step 7.
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 26b8ba8..aa57099 100644 (file)
     const fragmentWithReturnUrl = "http://" + partitionHost + "/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html";
     const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + thirdPartyCookieName;
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
-        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(enable);
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function finishTest() {
-        setEnableFeature(false);
-        testRunner.notifyDone();
+        setEnableFeature(false, function() {
+            testRunner.notifyDone();
+        });
     }
 
     function openIframe(url, onLoadHandler) {
 
     if (document.location.hash === "" && window.testRunner && window.internals) {
         console.log("Bootstrapping test.");
-        setEnableFeature(true);
+        setEnableFeature(true, function() {
+            // Set localhost as prevalent and with non-recent user interaction to put it in the partitioning category.
+            testRunner.setStatisticsPrevalentResource("http://localhost", true);
+            if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
+                testFailed("Host did not get set as prevalent resource.");
+            testRunner.setStatisticsHasHadNonRecentUserInteraction("http://localhost");
 
-        // Set localhost as prevalent and with non-recent user interaction to put it in the partitioning category.
-        testRunner.setStatisticsPrevalentResource("http://localhost", true);
-        if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
-            testFailed("Host did not get set as prevalent resource.");
-        testRunner.setStatisticsHasHadNonRecentUserInteraction("http://localhost");
+            testRunner.statisticsUpdateCookiePartitioning();
 
-        testRunner.statisticsUpdateCookiePartitioning();
+            testRunner.waitUntilDone();
+            testRunner.dumpChildFramesAsText();
+            document.location.hash = "step1";
 
-        testRunner.waitUntilDone();
-        testRunner.dumpChildFramesAsText();
-        document.location.hash = "step1";
-    }
+            runTest();
+        });
+    } else
+        runTest();
 
-    runTest();
 </script>
 </body>
 </html>
index a3b0dce..ebfd9d7 100644 (file)
     const fragmentWithReturnUrl = "http://127.0.0.1:8000/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html";
     const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + thirdPartyCookieName;
 
-    function setEnableFeature(enable) {
-        if (!enable) {
-            testRunner.statisticsResetToConsistentState();
-        }
-        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(enable);
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function finishTest() {
-        setEnableFeature(false);
-        testRunner.notifyDone();
+        setEnableFeature(false, function() {
+            testRunner.notifyDone();
+        });
     }
 
     function openIframe(url, onLoadHandler) {
     }
 
     if (document.location.host === partitionHost && document.location.hash == "" && window.testRunner && window.internals) {
-        setEnableFeature(true);
-
-        testRunner.waitUntilDone();
-        testRunner.dumpChildFramesAsText();
-        document.location.hash = "step1";
+        setEnableFeature(true, function() {
+            testRunner.waitUntilDone();
+            testRunner.dumpChildFramesAsText();
+            document.location.hash = "step1";
 
-        testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", true, runTest);
+            testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", true, runTest);
+        });
     } else {
         runTest();
     }
index 7761d65..ee9091d 100644 (file)
@@ -36,7 +36,11 @@ onload = function() {
 
         setTimeout(function() {
             testFrame.src = "about:blank";
-            setTimeout(finishJSTest, 0);
+            setTimeout(function() {
+                testRunner.statisticsResetToConsistentState(function() {
+                    finishJSTest();
+                });
+            }, 0);
         }, 0);
     });
     testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
index 45271b5..d5cfd7f 100644 (file)
@@ -31,7 +31,11 @@ onload = function() {
 
         setTimeout(function() {
             testFrame.src = "about:blank";
-            setTimeout(finishJSTest, 0);
+            setTimeout(function() {
+                testRunner.statisticsResetToConsistentState(function() {
+                    finishJSTest();
+                });
+            }, 0);
         }, 0);
     });
     testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
index 37ce541..b8bf51e 100644 (file)
                 testFailed("Cookie not deleted: " + document.cookie);
             else
                 testPassed("Cookie deleted.");
-            testRunner.statisticsResetToConsistentState();
             internals.setResourceLoadStatisticsEnabled(false);
-            testRunner.notifyDone();
+            testRunner.statisticsResetToConsistentState(function() {
+                testRunner.notifyDone();
+            });
         });
         testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
         testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
index d575e61..0bbad25 100644 (file)
                 testPassed("Cookie not deleted.");
             else
                 testFailed("Cookie deleted or document.cookie contains other cookies: " + document.cookie);
-            testRunner.statisticsResetToConsistentState();
             internals.setResourceLoadStatisticsEnabled(false);
-            testRunner.notifyDone();
+            testRunner.statisticsResetToConsistentState(function() {
+                testRunner.notifyDone();
+            });
         });
         testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
         testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
index c986143..52509c9 100644 (file)
             testFailed("Cookie not deleted: " + document.cookie);
         else
             testPassed("Cookie deleted.");
-        testRunner.statisticsResetToConsistentState();
         internals.setResourceLoadStatisticsEnabled(false);
-        testRunner.notifyDone();
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
     }
 
     function runTestRunnerTest() {
index bd6c827..bbc5c16 100644 (file)
                 failed = true;
             }
         }
-        if (failed)
-            finishJSTest();
+        if (failed) {
+            testRunner.statisticsResetToConsistentState(function() {
+                finishJSTest();
+            });
+        }
     }
 
     function checkIfPrevalent(begin, end, expected) {
                 failed = true;
             }
         }
-        if (failed)
-            finishJSTest();
+        if (failed) {
+            testRunner.statisticsResetToConsistentState(function() {
+                finishJSTest();
+            });
+        }
     }
 
     function initializeStatistics() {
@@ -90,7 +96,9 @@
             ++currentTest;
             runTest();
         } else {
-            finishJSTest();
+            testRunner.statisticsResetToConsistentState(function() {
+                finishJSTest();
+            });
         }
     }
 
index cd7046d..0e74a03 100644 (file)
@@ -9,11 +9,13 @@
     description("Tests that blocking is removed mid-flight in redirects.");
     jsTestIsAsync = true;
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     const partitionHost = "127.0.0.1:8000";
                 openIframe(redirectChainUrl + "&message=Redirect case 2, should receive first-party cookie for 127.0.0.1.", runTest);
                 break;
             case "#step8":
-                setEnableFeature(false);
-                finishJSTest();
+                setEnableFeature(false, finishJSTest);
                 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);
+        setEnableFeature(true, function() {
+            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();
     }
index aed5cf4..9c110c0 100644 (file)
@@ -9,11 +9,13 @@
     description("Tests that partitioning is removed mid-flight in redirects.");
     jsTestIsAsync = true;
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     const partitionHost = "127.0.0.1:8000";
                 openIframe(redirectChainUrl + "&message=Redirect case 2, should receive first-party cookie for 127.0.0.1.", runTest);
                 break;
             case "#step8":
-                setEnableFeature(false);
-                finishJSTest();
+                setEnableFeature(false, finishJSTest);
                 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);
+        setEnableFeature(true, function() {
+            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();
     }
index bbfea17..4a15495 100644 (file)
@@ -7,22 +7,24 @@
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
 
-        function setEnableFeature(enable) {
-            if (!enable)
-                testRunner.statisticsResetToConsistentState();
+        function setEnableFeature(enable, completionHandler) {
             internals.setResourceLoadStatisticsEnabled(enable);
             testRunner.setCookieStoragePartitioningEnabled(enable);
+            if (!enable)
+                testRunner.statisticsResetToConsistentState(completionHandler);
+            else
+                completionHandler();
         }
 
         function finishTest() {
-            setEnableFeature(false);
-            finishJSTest();
+            setEnableFeature(false, finishJSTest);
         }
 
         if (testRunner) {
-            setEnableFeature(true);
-            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-            testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
         }
 
         var lastPageInRedirectChainLoaded = false;
index 75b567f..3d3fbf8 100644 (file)
@@ -7,22 +7,24 @@
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
 
-        function setEnableFeature(enable) {
-            if (!enable)
-                testRunner.statisticsResetToConsistentState();
+        function setEnableFeature(enable, completionHandler) {
             internals.setResourceLoadStatisticsEnabled(enable);
             testRunner.setCookieStoragePartitioningEnabled(enable);
+            if (!enable)
+                testRunner.statisticsResetToConsistentState(completionHandler);
+            else
+                completionHandler();
         }
 
         function finishTest() {
-            setEnableFeature(false);
-            finishJSTest();
+            setEnableFeature(false, finishJSTest);
         }
 
         if (testRunner) {
-            setEnableFeature(true);
-            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-            testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
         }
 
         var lastPageInRedirectChainLoaded = false;
index 84a0c69..080929d 100644 (file)
@@ -7,22 +7,24 @@
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
 
-        function setEnableFeature(enable) {
-            if (!enable)
-                testRunner.statisticsResetToConsistentState();
+        function setEnableFeature(enable, completionHandler) {
             internals.setResourceLoadStatisticsEnabled(enable);
             testRunner.setCookieStoragePartitioningEnabled(enable);
+            if (!enable)
+                testRunner.statisticsResetToConsistentState(completionHandler);
+            else
+                completionHandler();
         }
 
         function finishTest() {
-            setEnableFeature(false);
-            finishJSTest();
+            setEnableFeature(false, finishJSTest);
         }
 
         if (testRunner) {
-            setEnableFeature(true);
-            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-            testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
         }
 
         var lastPageInRedirectChainLoaded = false;
index 56a4f1e..27598c2 100644 (file)
@@ -7,22 +7,24 @@
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
 
-        function setEnableFeature(enable) {
-            if (!enable)
-                testRunner.statisticsResetToConsistentState();
+        function setEnableFeature(enable, completionHandler) {
             internals.setResourceLoadStatisticsEnabled(enable);
             testRunner.setCookieStoragePartitioningEnabled(enable);
+            if (!enable)
+                testRunner.statisticsResetToConsistentState(completionHandler);
+            else
+                completionHandler();
         }
 
         function finishTest() {
-            setEnableFeature(false);
-            finishJSTest();
+            setEnableFeature(false, finishJSTest);
         }
 
         if (testRunner) {
-            setEnableFeature(true);
-            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-            testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
         }
 
         var lastPageInRedirectChainLoaded = false;
index 958d267..53f7a6c 100644 (file)
@@ -7,22 +7,24 @@
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
 
-        function setEnableFeature(enable) {
-            if (!enable)
-                testRunner.statisticsResetToConsistentState();
+        function setEnableFeature(enable, completionHandler) {
             internals.setResourceLoadStatisticsEnabled(enable);
             testRunner.setCookieStoragePartitioningEnabled(enable);
+            if (!enable)
+                testRunner.statisticsResetToConsistentState(completionHandler);
+            else
+                completionHandler();
         }
 
         function finishTest() {
-            setEnableFeature(false);
-            finishJSTest();
+            setEnableFeature(false, finishJSTest);
         }
 
         if (testRunner) {
-            setEnableFeature(true);
-            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-            testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
         }
 
         var lastPageInRedirectChainLoaded = false;
index af7408c..6c4c8f4 100644 (file)
@@ -7,22 +7,24 @@
         jsTestIsAsync = true;
         window.addEventListener("message", receiveMessage, false);
 
-        function setEnableFeature(enable) {
-            if (!enable)
-                testRunner.statisticsResetToConsistentState();
+        function setEnableFeature(enable, completionHandler) {
             internals.setResourceLoadStatisticsEnabled(enable);
             testRunner.setCookieStoragePartitioningEnabled(enable);
+            if (!enable)
+                testRunner.statisticsResetToConsistentState(completionHandler);
+            else
+                completionHandler();
         }
 
         function finishTest() {
-            setEnableFeature(false);
-            finishJSTest();
+            setEnableFeature(false, finishJSTest);
         }
 
         if (testRunner) {
-            setEnableFeature(true);
-            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-            testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
         }
 
         var lastPageInRedirectChainLoaded = false;
index 9d35a91..391fbb5 100644 (file)
@@ -9,11 +9,13 @@
     jsTestIsAsync = true;
     testRunner.dumpChildFramesAsText();
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function openIframe(url, onLoadHandler) {
         document.body.appendChild(element);
     }
 
-    setEnableFeature(true);
-    if (testRunner.isStatisticsPrevalentResource("http://localhost"))
-        testFailed("Localhost was classified as prevalent resource before the test started.");
-
     var referrer;
-    fetch("resources/echo-referrer.php").then(function(response) {
-        return response.text();
-    }).then(function(data) {
-        referrer = data;
-        shouldBeEqualToString("referrer", "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html");
-
-        testRunner.setStatisticsPrevalentResource("http://localhost", true);
-        if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
-            testFailed("Host did not get set as prevalent resource.");
-
-        testRunner.statisticsUpdateCookiePartitioning(function() {
-            openIframe("resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php", finishJSTest);
+    setEnableFeature(true, function() {
+        if (testRunner.isStatisticsPrevalentResource("http://localhost"))
+            testFailed("Localhost was classified as prevalent resource before the test started.");
+
+        fetch("resources/echo-referrer.php").then(function(response) {
+            return response.text();
+        }).then(function(data) {
+            referrer = data;
+            shouldBeEqualToString("referrer", "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html");
+
+            testRunner.setStatisticsPrevalentResource("http://localhost", true);
+            if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
+                testFailed("Host did not get set as prevalent resource.");
+
+            testRunner.statisticsUpdateCookiePartitioning(function() {
+                openIframe("resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php", function() {
+                    setEnableFeature(false, finishJSTest);
+                });
+            });
+
+        }).catch(function(error) {
+            console.log(error.message);
+            setEnableFeature(false, finishJSTest);
         });
-
-    }).catch(function(error) {
-        console.log(error.message);
-        finishJSTest();
     });
-
 </script>
 </body>
 </html>
index aa0b088..6d3b676 100644 (file)
@@ -9,11 +9,13 @@
     jsTestIsAsync = true;
     testRunner.dumpChildFramesAsText();
 
-    function setEnableFeature(enable) {
-        if (!enable)
-            testRunner.statisticsResetToConsistentState();
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function openIframe(url, onLoadHandler) {
         document.body.appendChild(element);
     }
 
-    setEnableFeature(true);
-    if (testRunner.isStatisticsPrevalentResource("http://localhost"))
-        testFailed("Localhost was classified as prevalent resource before the test started.");
-
     var referrer;
-    fetch("resources/echo-referrer.php").then(function(response) {
-        return response.text();
-    }).then(function(data) {
-        referrer = data;
-        shouldBeEqualToString("referrer", "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html");
+    setEnableFeature(true, function() {
+        if (testRunner.isStatisticsPrevalentResource("http://localhost"))
+            testFailed("Localhost was classified as prevalent resource before the test started.");
+
+        fetch("resources/echo-referrer.php").then(function(response) {
+            return response.text();
+        }).then(function(data) {
+            referrer = data;
+            shouldBeEqualToString("referrer", "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html");
 
-        testRunner.setStatisticsPrevalentResource("http://localhost", true);
-        if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
-            testFailed("Host did not get set as prevalent resource.");
+            testRunner.setStatisticsPrevalentResource("http://localhost", true);
+            if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
+                testFailed("Host did not get set as prevalent resource.");
 
-        testRunner.statisticsUpdateCookiePartitioning(function() {
-            fetch("http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php").then(function(response) {
-                return response.text();
-            }).then(function(data) {
-                referrer = data;
-                shouldBeEqualToString("referrer", "http://127.0.0.1:8000/");
+            testRunner.statisticsUpdateCookiePartitioning(function() {
+                fetch("http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php").then(function(response) {
+                    return response.text();
+                }).then(function(data) {
+                    referrer = data;
+                    shouldBeEqualToString("referrer", "http://127.0.0.1:8000/");
 
-                openIframe("resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php", finishJSTest);
+                    openIframe("resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php", function() {
+                        setEnableFeature(false, finishJSTest);
+                    });
 
-            }).catch(function(error) {
-                console.log(error.message);
-                finishJSTest();
+                }).catch(function(error) {
+                    console.log(error.message);
+                    setEnableFeature(false, finishJSTest);
+                });
             });
-        });
 
-    }).catch(function(error) {
-        console.log(error.message);
-        finishJSTest();
+        }).catch(function(error) {
+            console.log(error.message);
+            setEnableFeature(false, finishJSTest);
+        });
     });
-
 </script>
 </body>
 </html>
index 8eaad06..1055973 100644 (file)
     const prevalentResourceUrl3 = "http://127.0.1.3:8000/temp";
     const prevalentResourceUrl4 = "http://127.0.1.4:8000/temp";
 
+    function setEnableFeature(enable, completionHandler) {
+        internals.setResourceLoadStatisticsEnabled(enable);
+        testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
+    }
+
     function checkInsufficientClassificationAndContinue() {
         if (!testRunner.isStatisticsPrevalentResource(prevalentResourceUrl1)) {
             testFailed("Host 1 did not get classified as prevalent resource.");
-            finishJSTest();
+            setEnableFeature(false, finishJSTest);
         } else if (!testRunner.isStatisticsPrevalentResource(prevalentResourceUrl2)) {
             testFailed("Host 2 did not get classified as prevalent resource.");
-            finishJSTest();
+            setEnableFeature(false, finishJSTest);
         } else {
             testPassed("Hosts classified as prevalent resources.");
             runTelemetryAndContinue();
     function checkSufficientClassificationAndContinue() {
         if (!testRunner.isStatisticsPrevalentResource(prevalentResourceUrl1)) {
             testFailed("Host 1 did not get classified as prevalent resource.");
-            finishJSTest();
+            setEnableFeature(false, finishJSTest);
         } else if (!testRunner.isStatisticsPrevalentResource(prevalentResourceUrl2)) {
             testFailed("Host 2 did not get classified as prevalent resource.");
-            finishJSTest();
+            setEnableFeature(false, finishJSTest);
         } else if (!testRunner.isStatisticsPrevalentResource(prevalentResourceUrl3)) {
             testFailed("Host 3 did not get classified as prevalent resource.");
-            finishJSTest();
+            setEnableFeature(false, finishJSTest);
         } else if (!testRunner.isStatisticsPrevalentResource(prevalentResourceUrl4)) {
             testFailed("Host 4 did not get classified as prevalent resource.");
-            finishJSTest();
+            setEnableFeature(false, finishJSTest);
         } else {
             testPassed("Hosts classified as prevalent resources.");
             runTelemetryAndContinue();
         shouldBe("testResult.totalPrevalentResources", "4");
         shouldBe("testResult.totalPrevalentResourcesWithUserInteraction", "1");
         shouldBe("testResult.top3SubframeUnderTopFrameOrigins", "4");
-        finishJSTest();
+        setEnableFeature(false, finishJSTest);
     }
 
     if (window.testRunner) {
-        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-        testRunner.setStatisticsNotifyPagesWhenTelemetryWasCaptured(true);
-        setUpInsufficientStatisticsAndContinue();
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+            testRunner.setStatisticsNotifyPagesWhenTelemetryWasCaptured(true);
+            setUpInsufficientStatisticsAndContinue();
+        });
     }
 </script>
 </body>
index 47284b6..e217a03 100644 (file)
     const fragmentWithReturnUrl = "http://127.0.0.1:8000/resourceLoadStatistics/third-party-cookie-with-and-without-user-interaction.html";
     const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + thirdPartyCookieName + "&name3=" + partitionedThirdPartyCookieName;
 
-    function setEnableFeature(enable) {
-        if (!enable) {
-            testRunner.statisticsResetToConsistentState();
-        }
-        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(enable);
+    function setEnableFeature(enable, completionHandler) {
         internals.setResourceLoadStatisticsEnabled(enable);
         testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
     }
 
     function finishTest() {
-        setEnableFeature(false);
-        testRunner.notifyDone();
+        setEnableFeature(false, function() {
+            testRunner.notifyDone();
+        });
     }
 
     function openIframe(url, onLoadHandler) {
     }
 
     if (document.location.host === partitionHost && document.location.hash == "" && window.testRunner && window.internals) {
-        setEnableFeature(true);
-
-        testRunner.waitUntilDone();
-        testRunner.dumpChildFramesAsText();
-        document.location.hash = "step1";
+        setEnableFeature(true, function() {
+            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, runTest);
+            // Start test with third party as non-prevalent
+            testRunner.setStatisticsPrevalentResource(thirdPartyHostname, false);
+            testRunner.setStatisticsHasHadUserInteraction(thirdPartyOrigin, false);
+            testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, false, runTest);
+        });
     } else {
         runTest();
     }
index bbf13bd..a9c1be6 100644 (file)
@@ -10,6 +10,15 @@ jsTestIsAsync = true;
 const topFrameOrigin = "http://127.0.0.1:8000";
 const subFrameOrigin = "http://localhost:8000";
 
+function setEnableFeature(enable, completionHandler) {
+    internals.setResourceLoadStatisticsEnabled(enable);
+    testRunner.setCookieStoragePartitioningEnabled(enable);
+    if (!enable)
+        testRunner.statisticsResetToConsistentState(completionHandler);
+    else
+        completionHandler();
+}
+
 function activateElement(elementId) {
     var element = document.getElementById(elementId);
     var centerX = element.offsetLeft + element.offsetWidth / 2;
@@ -21,26 +30,25 @@ function finishTest() {
     shouldBeTrue("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
     shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
 
-    finishJSTest();
+    setEnableFeature(false, finishJSTest);
 }
 
 onload = function() {
-    if (internals)
-        internals.setResourceLoadStatisticsEnabled(true);
-
-    if (testRunner) {
-        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
-        testRunner.installStatisticsDidScanDataRecordsCallback(finishTest);
-    }
+    setEnableFeature(true, function() {
+        if (testRunner) {
+            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+            testRunner.installStatisticsDidScanDataRecordsCallback(finishTest);
+        }
 
-    shouldBe("document.location.origin", "topFrameOrigin");
+        shouldBe("document.location.origin", "topFrameOrigin");
 
-    if (testRunner) {
-        shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
-        shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
+        if (testRunner) {
+            shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
+            shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
 
-        activateElement("testFrame");
-    }
+            activateElement("testFrame");
+        }
+    });
 };
 </script>
 <iframe id="testFrame" src="http://localhost:8000/resourceLoadStatistics/resources/dummy.html"></iframe>
index 414a8b3..09806f4 100644 (file)
     const topFrameOrigin = "http://127.0.0.1:8000";
     const subFrameOrigin = "http://localhost:8000";
 
+    function setEnableFeature(enable, completionHandler) {
+        internals.setResourceLoadStatisticsEnabled(enable);
+        testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
+    }
+
     function activateElement(elementId, callback) {
         var element = document.getElementById(elementId);
         var centerX = element.offsetLeft + element.offsetWidth / 2;
@@ -20,7 +29,7 @@
             },
             function() {
                 testFailed("Promise rejected.");
-                finishJSTest();
+                setEnableFeature(false, finishJSTest);
             }
         );
     }
         shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
         shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
 
-        finishJSTest();
+        setEnableFeature(false, finishJSTest);
     }
 
     onload = function() {
-        if (internals)
-            internals.setResourceLoadStatisticsEnabled(true);
-
-        shouldBe("document.location.origin", "topFrameOrigin");
+        setEnableFeature(true, function() {
+            shouldBe("document.location.origin", "topFrameOrigin");
 
-        firstInteraction();
+            firstInteraction();
+        });
     };
 </script>
 <div id="testElement">This is the test element</div>
index 684f515..55bebd7 100644 (file)
     const topFrameOrigin = "http://127.0.0.1:8000";
     const subFrameOrigin = "http://localhost:8000";
 
+    function setEnableFeature(enable, completionHandler) {
+        internals.setResourceLoadStatisticsEnabled(enable);
+        testRunner.setCookieStoragePartitioningEnabled(enable);
+        if (!enable)
+            testRunner.statisticsResetToConsistentState(completionHandler);
+        else
+            completionHandler();
+    }
+
     function activateElement(elementId, callback) {
         var element = document.getElementById(elementId);
         var centerX = element.offsetLeft + element.offsetWidth / 2;
@@ -20,7 +29,7 @@
             },
             function() {
                 testFailed("Promise rejected.");
-                finishJSTest();
+                setEnableFeature(false, finishJSTest);
             }
         );
     }
         shouldBeTrue("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
         shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
 
-        finishJSTest();
+        setEnableFeature(false, finishJSTest);
     }
 
     onload = function() {
-        if (internals)
-            internals.setResourceLoadStatisticsEnabled(true);
-
-        shouldBe("document.location.origin", "topFrameOrigin");
+        setEnableFeature(true, function() {
+            shouldBe("document.location.origin", "topFrameOrigin");
 
-        firstInteraction();
+            firstInteraction();
+        });
     };
 </script>
 <div id="testElement">This is the test element</div>
index fbd43b4..2ec70fc 100644 (file)
@@ -1,3 +1,31 @@
+2018-07-10  John Wilander  <wilander@apple.com>
+
+        Resource Load Statistics: Make testRunner.statisticsResetToConsistentState() take a completion handler
+        https://bugs.webkit.org/show_bug.cgi?id=187499
+        <rdar://problem/41999431>
+
+        Reviewed by Chris Dumez.
+
+        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
+        (WKWebsiteDataStoreStatisticsResetToConsistentState):
+            Now uses a WTF::CallbackAggregator to call its
+            completion handler when both the call to
+            WebResourceLoadStatisticsStore::scheduleClearInMemory()
+            and to
+            WebResourceLoadStatisticsStore::resetParametersToDefaultValues()
+            are complete.
+        * UIProcess/API/C/WKWebsiteDataStoreRef.h:
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::scheduleClearInMemory):
+            Now takes a WTF::CompletionHandler so that it can support the
+            completion handler in
+            WKWebsiteDataStoreStatisticsResetToConsistentState().
+        (WebKit::WebResourceLoadStatisticsStore::resetParametersToDefaultValues):
+            Now takes a WTF::CompletionHandler so that it can support the
+            completion handler in
+            WKWebsiteDataStoreStatisticsResetToConsistentState().
+        * UIProcess/WebResourceLoadStatisticsStore.h:
+
 2018-07-10  Ryosuke Niwa  <rniwa@webkit.org>
 
         Disable cross-origin-window-policy by default
index ff83188..66c0303 100644 (file)
@@ -37,6 +37,7 @@
 #include "WebsiteDataRecord.h"
 #include "WebsiteDataType.h"
 #include <WebCore/URL.h>
+#include <wtf/CallbackAggregator.h>
 
 WKTypeID WKWebsiteDataStoreGetTypeID()
 {
@@ -423,14 +424,18 @@ void WKWebsiteDataStoreStatisticsClearThroughWebsiteDataRemoval(WKWebsiteDataSto
     });
 }
 
-void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef dataStoreRef)
+void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreStatisticsResetToConsistentStateFunction completionHandler)
 {
     auto* store = WebKit::toImpl(dataStoreRef)->websiteDataStore().resourceLoadStatistics();
     if (!store)
         return;
 
-    store->resetParametersToDefaultValues();
-    store->scheduleClearInMemory();
+    auto callbackAggregator = CallbackAggregator::create([context, completionHandler]() {
+        completionHandler(context);
+    });
+    
+    store->resetParametersToDefaultValues([callbackAggregator = callbackAggregator.copyRef()] { });
+    store->scheduleClearInMemory([callbackAggregator = callbackAggregator.copyRef()] { });
 }
 
 void WKWebsiteDataStoreRemoveAllFetchCaches(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveFetchCacheRemovalFunction callback)
index 1c1beba..e6b88b3 100644 (file)
@@ -84,7 +84,8 @@ typedef void (*WKWebsiteDataStoreStatisticsClearInMemoryAndPersistentStoreModifi
 WK_EXPORT void WKWebsiteDataStoreStatisticsClearInMemoryAndPersistentStoreModifiedSinceHours(WKWebsiteDataStoreRef dataStoreRef, unsigned hours, void* context, WKWebsiteDataStoreStatisticsClearInMemoryAndPersistentStoreModifiedSinceHoursFunction callback);
 typedef void (*WKWebsiteDataStoreStatisticsClearThroughWebsiteDataRemovalFunction)(void* functionContext);
 WK_EXPORT void WKWebsiteDataStoreStatisticsClearThroughWebsiteDataRemoval(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreStatisticsClearThroughWebsiteDataRemovalFunction callback);
-WK_EXPORT void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef dataStoreRef);
+typedef void (*WKWebsiteDataStoreStatisticsResetToConsistentStateFunction)(void* functionContext);
+WK_EXPORT void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreStatisticsResetToConsistentStateFunction completionHandler);
 
 typedef void (*WKWebsiteDataStoreRemoveFetchCacheRemovalFunction)(void* functionContext);
 WK_EXPORT void WKWebsiteDataStoreRemoveFetchCacheForOrigin(WKWebsiteDataStoreRef dataStoreRef, WKSecurityOriginRef origin, void* context, WKWebsiteDataStoreRemoveFetchCacheRemovalFunction callback);
index 7bd1e26..0cba7c3 100644 (file)
@@ -748,12 +748,16 @@ void WebResourceLoadStatisticsStore::scheduleCookiePartitioningStateReset()
 }
 #endif
 
-void WebResourceLoadStatisticsStore::scheduleClearInMemory()
+void WebResourceLoadStatisticsStore::scheduleClearInMemory(CompletionHandler<void()>&& completionHandler)
 {
     ASSERT(RunLoop::isMain());
-    postTask([this] {
+    postTask([this, completionHandler = WTFMove(completionHandler)]() mutable {
         if (m_memoryStore)
             m_memoryStore->clear();
+
+        postTaskReply([completionHandler = WTFMove(completionHandler)] {
+            completionHandler();
+        });
     });
 }
 
@@ -866,13 +870,17 @@ void WebResourceLoadStatisticsStore::setPruneEntriesDownTo(size_t pruneTargetCou
     });
 }
 
-void WebResourceLoadStatisticsStore::resetParametersToDefaultValues()
+void WebResourceLoadStatisticsStore::resetParametersToDefaultValues(CompletionHandler<void()>&& completionHandler)
 {
     ASSERT(RunLoop::isMain());
 
-    postTask([this] {
+    postTask([this, completionHandler = WTFMove(completionHandler)]() mutable {
         if (m_memoryStore)
             m_memoryStore->resetParametersToDefaultValues();
+
+        postTaskReply([completionHandler = WTFMove(completionHandler)] {
+            completionHandler();
+        });
     });
 }
 
index b929631..b518746 100644 (file)
@@ -114,7 +114,7 @@ public:
     void submitTelemetry();
     void scheduleCookiePartitioningStateReset();
 
-    void scheduleClearInMemory();
+    void scheduleClearInMemory(CompletionHandler<void()>&&);
     
     enum class ShouldGrandfather {
         No,
@@ -130,7 +130,7 @@ public:
     void setMaxStatisticsEntries(size_t);
     void setPruneEntriesDownTo(size_t);
 
-    void resetParametersToDefaultValues();
+    void resetParametersToDefaultValues(CompletionHandler<void()>&&);
 
     void setResourceLoadStatisticsDebugMode(bool);
 
index 2b6c789..8d06969 100644 (file)
@@ -1,3 +1,24 @@
+2018-07-10  John Wilander  <wilander@apple.com>
+
+        Resource Load Statistics: Make testRunner.statisticsResetToConsistentState() take a completion handler
+        https://bugs.webkit.org/show_bug.cgi?id=187499
+        <rdar://problem/41999431>
+
+        Reviewed by Chris Dumez.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::didReceiveMessageToPage):
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::statisticsResetToConsistentState):
+        (WTR::TestRunner::statisticsCallDidResetToConsistentStateCallback):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::statisticsResetToConsistentState):
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didResetStatisticsToConsistentState):
+        * WebKitTestRunner/TestInvocation.h:
+
 2018-07-10  Ryosuke Niwa  <rniwa@webkit.org>
 
         Disable cross-origin-window-policy by default
index 1791668..e6aa49e 100644 (file)
@@ -307,7 +307,7 @@ interface TestRunner {
     void statisticsClearInMemoryAndPersistentStore(object callback);
     void statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(unsigned long hours, object callback);
     void statisticsClearThroughWebsiteDataRemoval(object callback);
-    void statisticsResetToConsistentState();
+    void statisticsResetToConsistentState(object completionHandler);
 
     // Injected bundle form client.
     void installTextDidChangeInTextFieldCallback(object callback);
index d443f16..84f4409 100644 (file)
@@ -305,6 +305,11 @@ void InjectedBundle::didReceiveMessageToPage(WKBundlePageRef page, WKStringRef m
         return;
     }
 
+    if (WKStringIsEqualToUTF8CString(messageName, "CallDidResetStatisticsToConsistentState")) {
+        m_testRunner->statisticsCallDidResetToConsistentStateCallback();
+        return;
+    }
+    
     if (WKStringIsEqualToUTF8CString(messageName, "CallDidSetPartitionOrBlockCookiesForHost")) {
         m_testRunner->statisticsCallDidSetPartitionOrBlockCookiesForHostCallback();
         return;
index 95aaef4..4dfa758 100644 (file)
@@ -740,6 +740,7 @@ enum {
     StatisticsDidScanDataRecordsCallbackID,
     StatisticsDidRunTelemetryCallbackID,
     StatisticsDidClearThroughWebsiteDataRemovalCallbackID,
+    StatisticsDidResetToConsistentStateCallbackID,
     StatisticsDidSetPartitionOrBlockCookiesForHostCallbackID,
     AllStorageAccessEntriesCallbackID,
     DidRemoveAllSessionCredentialsCallbackID,
@@ -1894,12 +1895,19 @@ void TestRunner::statisticsCallClearThroughWebsiteDataRemovalCallback()
     callTestRunnerCallback(StatisticsDidClearThroughWebsiteDataRemovalCallbackID);
 }
 
-void TestRunner::statisticsResetToConsistentState()
+void TestRunner::statisticsResetToConsistentState(JSValueRef completionHandler)
 {
+    cacheTestRunnerCallback(StatisticsDidResetToConsistentStateCallbackID, completionHandler);
+    
     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsResetToConsistentState"));
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), 0, nullptr);
 }
 
+void TestRunner::statisticsCallDidResetToConsistentStateCallback()
+{
+    callTestRunnerCallback(StatisticsDidResetToConsistentStateCallbackID);
+}
+
 void TestRunner::installTextDidChangeInTextFieldCallback(JSValueRef callback)
 {
     cacheTestRunnerCallback(TextDidChangeInTextFieldCallbackID, callback);
index 789ba23..371e1df 100644 (file)
@@ -413,7 +413,8 @@ public:
     void statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(unsigned hours, JSValueRef callback);
     void statisticsClearThroughWebsiteDataRemoval(JSValueRef callback);
     void statisticsCallClearThroughWebsiteDataRemovalCallback();
-    void statisticsResetToConsistentState();
+    void statisticsResetToConsistentState(JSValueRef completionHandler);
+    void statisticsCallDidResetToConsistentStateCallback();
 
     // Injected bundle form client.
     void installTextDidChangeInTextFieldCallback(JSValueRef callback);
index 5c619d5..c16df4e 100644 (file)
@@ -2882,7 +2882,10 @@ void TestController::statisticsClearThroughWebsiteDataRemoval()
 void TestController::statisticsResetToConsistentState()
 {
     auto* dataStore = WKContextGetWebsiteDataStore(platformContext());
-    WKWebsiteDataStoreStatisticsResetToConsistentState(dataStore);
+    ResourceStatisticsCallbackContext context(*this);
+    WKWebsiteDataStoreStatisticsResetToConsistentState(dataStore, &context, resourceStatisticsVoidResultCallback);
+    runUntil(context.done, noTimeout);
+    m_currentInvocation->didResetStatisticsToConsistentState();
 }
 
 void TestController::addMockMediaDevice(WKStringRef persistentID, WKStringRef label, WKStringRef type)
index 05c3ce6..fe24a01 100644 (file)
@@ -1507,6 +1507,12 @@ void TestInvocation::didClearStatisticsThroughWebsiteDataRemoval()
     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
 }
 
+void TestInvocation::didResetStatisticsToConsistentState()
+{
+    WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidResetStatisticsToConsistentState"));
+    WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
+}
+
 void TestInvocation::didSetPartitionOrBlockCookiesForHost()
 {
     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetPartitionOrBlockCookiesForHost"));
index 940b324..356bac5 100644 (file)
@@ -72,6 +72,7 @@ public:
     void notifyDownloadDone();
 
     void didClearStatisticsThroughWebsiteDataRemoval();
+    void didResetStatisticsToConsistentState();
     void didSetPartitionOrBlockCookiesForHost();
     void didReceiveAllStorageAccessEntries(Vector<String>& domains);