Skip to content

Commit 403f0c3

Browse files
committed
Add callbacks to testRunner.statisticsSetShouldPartitionCookiesForHost() and testRunner.statisticsUpdateCookiePartitioning()
https://bugs.webkit.org/show_bug.cgi?id=181958 https://bugs.webkit.org/show_bug.cgi?id=182072 <rdar://problem/36801804> <rdar://problem/36845795> Reviewed by Brent Fulgham. Because of the asynchronous nature of XPC and cookies, we need callbacks in these TestRunner functions so that the layout tests can wait for state changes to finish before checking test conditions. Source/WebKit: * UIProcess/API/C/WKWebsiteDataStoreRef.cpp: (WKWebsiteDataStoreStatisticsUpdateCookiePartitioning): (WKWebsiteDataStoreSetStatisticsShouldPartitionCookiesForHost): * UIProcess/API/Cocoa/WKWebsiteDataStore.mm: (-[WKWebsiteDataStore _resourceLoadStatisticsUpdateCookiePartitioning]): (-[WKWebsiteDataStore _resourceLoadStatisticsUpdateCookiePartitioning:]): (-[WKWebsiteDataStore _resourceLoadStatisticsSetShouldPartitionCookies:forHost:]): (-[WKWebsiteDataStore _resourceLoadStatisticsSetShouldPartitionCookies:forHost:completionHandler:]): * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h: * UIProcess/WebResourceLoadStatisticsStore.cpp: (WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated): (WebKit::WebResourceLoadStatisticsStore::logUserInteraction): (WebKit::WebResourceLoadStatisticsStore::logNonRecentUserInteraction): (WebKit::WebResourceLoadStatisticsStore::scheduleCookiePartitioningUpdate): (WebKit::WebResourceLoadStatisticsStore::scheduleCookiePartitioningUpdateForDomains): (WebKit::WebResourceLoadStatisticsStore::scheduleClearPartitioningStateForDomains): (WebKit::WebResourceLoadStatisticsStore::mergeWithDataFromDecoder): (WebKit::WebResourceLoadStatisticsStore::clearInMemory): (WebKit::WebResourceLoadStatisticsStore::updateCookiePartitioning): (WebKit::WebResourceLoadStatisticsStore::updateCookiePartitioningForDomains): (WebKit::WebResourceLoadStatisticsStore::clearPartitioningStateForDomains): * UIProcess/WebResourceLoadStatisticsStore.h: Tools: * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp: (WTR::InjectedBundle::didReceiveMessageToPage): * WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::TestRunner::statisticsUpdateCookiePartitioning): (WTR::TestRunner::statisticsSetShouldPartitionCookiesForHost): (WTR::TestRunner::statisticsCallDidSetPartitionOrBlockCookiesForHostCallback): * WebKitTestRunner/InjectedBundle/TestRunner.h: * WebKitTestRunner/TestInvocation.cpp: (WTR::TestInvocation::didSetPartitionOrBlockCookiesForHost): * WebKitTestRunner/TestInvocation.h: * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::TestController::statisticsUpdateCookiePartitioning): (WTR::TestController::statisticsSetShouldPartitionCookiesForHost): LayoutTests: * http/tests/resourceLoadStatistics/add-blocking-to-redirect-expected.txt: * http/tests/resourceLoadStatistics/add-blocking-to-redirect.html: * http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt: * http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html: * http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html: * http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html: * http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html: * http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction-expected.txt: * http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html: * http/tests/resourceLoadStatistics/remove-blocking-in-redirect-expected.txt: * http/tests/resourceLoadStatistics/remove-blocking-in-redirect.html: * http/tests/resourceLoadStatistics/remove-partitioning-in-redirect-expected.txt: * http/tests/resourceLoadStatistics/remove-partitioning-in-redirect.html: * http/tests/resourceLoadStatistics/third-party-cookie-with-and-without-user-interaction.html: * platform/mac-wk2/TestExpectations: Canonical link: https://commits.webkit.org/198125@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227875 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 323ad28 commit 403f0c3

30 files changed

Lines changed: 319 additions & 140 deletions

LayoutTests/ChangeLog

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
2018-01-30 John Wilander <wilander@apple.com>
2+
3+
Add callbacks to testRunner.statisticsSetShouldPartitionCookiesForHost() and testRunner.statisticsUpdateCookiePartitioning()
4+
https://bugs.webkit.org/show_bug.cgi?id=181958
5+
https://bugs.webkit.org/show_bug.cgi?id=182072
6+
<rdar://problem/36801804>
7+
<rdar://problem/36845795>
8+
9+
Reviewed by Brent Fulgham.
10+
11+
Because of the asynchronous nature of XPC and cookies,
12+
we need callbacks in these TestRunner functions so that
13+
the layout tests can wait for state changes to finish
14+
before checking test conditions.
15+
16+
* http/tests/resourceLoadStatistics/add-blocking-to-redirect-expected.txt:
17+
* http/tests/resourceLoadStatistics/add-blocking-to-redirect.html:
18+
* http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt:
19+
* http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html:
20+
* http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html:
21+
* http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html:
22+
* http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html:
23+
* http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction-expected.txt:
24+
* http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html:
25+
* http/tests/resourceLoadStatistics/remove-blocking-in-redirect-expected.txt:
26+
* http/tests/resourceLoadStatistics/remove-blocking-in-redirect.html:
27+
* http/tests/resourceLoadStatistics/remove-partitioning-in-redirect-expected.txt:
28+
* http/tests/resourceLoadStatistics/remove-partitioning-in-redirect.html:
29+
* http/tests/resourceLoadStatistics/third-party-cookie-with-and-without-user-interaction.html:
30+
* platform/mac-wk2/TestExpectations:
31+
132
2018-01-30 Youenn Fablet <youenn@apple.com>
233

334
Move http/wpt/service-workers/clone-opaque-being-loaded-response.https.html to use HTTP

LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
66
PASS successfullyParsed is true
77

88
TEST COMPLETE
9-
9+
1010

1111
--------
1212
Frame: '<!--framePath //<!--frame0-->-->'

LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect.html

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8">
55
<script src="/js-test-resources/js-test.js"></script>
66
</head>
7-
<body onload="runTest()">
7+
<body>
88
<script>
99
description("Tests that blocking is added mid-flight in redirects.");
1010
jsTestIsAsync = true;
@@ -16,16 +16,6 @@
1616
testRunner.setCookieStoragePartitioningEnabled(enable);
1717
}
1818

19-
if (document.location.hash === "") {
20-
setEnableFeature(true);
21-
if (testRunner.isStatisticsPrevalentResource("http://localhost"))
22-
testFailed("Localhost was classified as prevalent resource before the test starts.");
23-
// Make sure the network process is up-to-date.
24-
testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", false);
25-
testRunner.dumpChildFramesAsText();
26-
document.location.hash = "step1";
27-
}
28-
2919
const partitionHost = "127.0.0.1:8000";
3020
const thirdPartyOrigin = "http://localhost:8000";
3121
const resourcePath = "/resourceLoadStatistics/resources";
@@ -67,10 +57,11 @@
6757
// Set localhost as prevalent and with no user interaction to put it in the blocking category.
6858
document.location.hash = "step5";
6959
testRunner.setStatisticsPrevalentResource("http://localhost", true);
70-
testRunner.statisticsUpdateCookiePartitioning();
7160
if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
7261
testFailed("Host did not get set as prevalent resource.");
73-
runTest();
62+
testRunner.statisticsUpdateCookiePartitioning(function() {
63+
runTest();
64+
});
7465
break;
7566
case "#step5":
7667
// Check that no cookie gets sent for localhost under 127.0.0.1 since localhost's cookies are blocked.
@@ -103,6 +94,18 @@
10394
break;
10495
}
10596
}
97+
98+
if (document.location.hash === "") {
99+
setEnableFeature(true);
100+
if (testRunner.isStatisticsPrevalentResource("http://localhost"))
101+
testFailed("Localhost was classified as prevalent resource before the test starts.");
102+
testRunner.dumpChildFramesAsText();
103+
document.location.hash = "step1";
104+
// Make sure the network process is up-to-date.
105+
testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", false, runTest);
106+
} else {
107+
runTest();
108+
}
106109
</script>
107110
</body>
108111
</html>

LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
66
PASS successfullyParsed is true
77

88
TEST COMPLETE
9-
9+
1010

1111
--------
1212
Frame: '<!--framePath //<!--frame0-->-->'

LayoutTests/http/tests/resourceLoadStatistics/add-partitioning-to-redirect.html

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8">
55
<script src="/js-test-resources/js-test.js"></script>
66
</head>
7-
<body onload="runTest()">
7+
<body>
88
<script>
99
description("Tests that partitioning is added mid-flight in redirects.");
1010
jsTestIsAsync = true;
@@ -16,16 +16,6 @@
1616
testRunner.setCookieStoragePartitioningEnabled(enable);
1717
}
1818

19-
if (document.location.hash === "") {
20-
setEnableFeature(true);
21-
if (testRunner.isStatisticsPrevalentResource("http://localhost"))
22-
testFailed("Localhost was classified as prevalent resource before the test starts.");
23-
// Make sure the network process is up-to-date.
24-
testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", false);
25-
testRunner.dumpChildFramesAsText();
26-
document.location.hash = "step1";
27-
}
28-
2919
const partitionHost = "127.0.0.1:8000";
3020
const thirdPartyOrigin = "http://localhost:8000";
3121
const resourcePath = "/resourceLoadStatistics/resources";
@@ -67,11 +57,12 @@
6757
// Set localhost as prevalent and with non-recent user interaction to put it in the partitioning category.
6858
document.location.hash = "step5";
6959
testRunner.setStatisticsPrevalentResource("http://localhost", true);
70-
testRunner.setStatisticsHasHadNonRecentUserInteraction("http://localhost");
71-
testRunner.statisticsUpdateCookiePartitioning();
7260
if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
7361
testFailed("Host did not get set as prevalent resource.");
74-
runTest();
62+
testRunner.setStatisticsHasHadNonRecentUserInteraction("http://localhost");
63+
testRunner.statisticsUpdateCookiePartitioning(function() {
64+
runTest();
65+
});
7566
break;
7667
case "#step5":
7768
// Check that no cookie gets sent for localhost under 127.0.0.1 since localhost is partitioned.
@@ -104,6 +95,18 @@
10495
break;
10596
}
10697
}
98+
99+
if (document.location.hash === "") {
100+
setEnableFeature(true);
101+
if (testRunner.isStatisticsPrevalentResource("http://localhost"))
102+
testFailed("Localhost was classified as prevalent resource before the test started.");
103+
testRunner.dumpChildFramesAsText();
104+
document.location.hash = "step1";
105+
// Make sure the network process is up-to-date.
106+
testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", false, runTest);
107+
} else {
108+
runTest();
109+
}
107110
</script>
108111
</body>
109112
</html>

LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,21 @@
6060
openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive one cookie.", runTest);
6161
break;
6262
case "#step3":
63-
// Setup localhost for partitioning and set a partitioned cookie for localhost under 127.0.0.1.
63+
// Setup localhost for partitioning.
6464
document.location.hash = "step4";
65-
testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, true);
66-
openIframe(thirdPartyBaseUrl + subPathToSetPartitionedCookie + "&message=Setting partitioned, third party cookie.", runTest);
65+
testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, true, runTest);
6766
break;
6867
case "#step4":
69-
// Load localhost under 127.0.0.1 and check that it gets only the partitioned cookie. End by aquiring user interaction for localhost.
68+
// Set a partitioned cookie for localhost under 127.0.0.1.
7069
document.location.hash = "step5";
71-
openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive one partitioned, third party cookie.", setUserInteractionAndContinue);
70+
openIframe(thirdPartyBaseUrl + subPathToSetPartitionedCookie + "&message=Setting partitioned, third party cookie.", runTest);
7271
break;
7372
case "#step5":
73+
// Load localhost under 127.0.0.1 and check that it gets only the partitioned cookie. End by acquiring user interaction for localhost.
74+
document.location.hash = "step6";
75+
openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive one partitioned, third party cookie.", setUserInteractionAndContinue);
76+
break;
77+
case "#step6":
7478
// Load localhost under 127.0.0.1 and check that it gets its non-partitioned cookie after user interaction.
7579
openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=After user interaction, should receive one non-partitioned, first party cookie.", finishTest);
7680
break;
@@ -82,14 +86,14 @@
8286

8387
testRunner.setStatisticsPrevalentResource(thirdPartyHostname, false);
8488
testRunner.setStatisticsHasHadUserInteraction(thirdPartyOrigin, false);
85-
testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, false);
86-
8789
testRunner.waitUntilDone();
8890
testRunner.dumpChildFramesAsText();
8991
document.location.hash = "step1";
90-
}
9192

92-
runTest();
93+
testRunner.statisticsSetShouldPartitionCookiesForHost(thirdPartyHostname, false, runTest);
94+
} else {
95+
runTest();
96+
}
9397
</script>
9498
</body>
9599
</html>

LayoutTests/http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,25 @@
8686
}
8787
}
8888

89-
9089
if (document.location.host === partitionHost && document.location.hash === "" && window.testRunner && window.internals) {
9190
setEnableFeature(true);
9291

9392
testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
9493
testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
9594

96-
testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", true);
95+
testRunner.waitUntilDone();
96+
testRunner.dumpChildFramesAsText();
97+
document.location.hash = "step1";
98+
9799
testRunner.setStatisticsPrevalentResource("http://localhost", true);
98100
if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
99101
testFailed("Host did not get set as prevalent resource.");
100102

101-
testRunner.waitUntilDone();
102-
testRunner.dumpChildFramesAsText();
103-
document.location.hash = "step1";
103+
testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", true, runTest);
104+
} else {
105+
runTest();
104106
}
105107

106-
runTest();
107108
</script>
108109
</body>
109110
</html>

LayoutTests/http/tests/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
}
4141

4242
function fireShouldPartitionCookiesHandlerAndContinue() {
43-
testRunner.statisticsUpdateCookiePartitioning();
44-
runTest();
43+
testRunner.statisticsUpdateCookiePartitioning(runTest);
4544
}
4645

4746
function setShortCookiePartitioningTimeOutPlusFireShouldPartitionCookiesHandlerAndContinue() {

LayoutTests/http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22

33
--------
44
Frame: '<!--framePath //<!--frame0-->-->'

LayoutTests/http/tests/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Test for Partitioned Cookies With and Without User Interaction</title>
66
<script src="../../resources/js-test-pre.js"></script>
77
</head>
8-
<body onload="runTest()">
8+
<body>
99
<script>
1010
const partitionHost = "127.0.0.1:8000";
1111
const thirdPartyOrigin = "http://localhost:8000";
@@ -73,11 +73,13 @@
7373
if (document.location.host === partitionHost && document.location.hash == "" && window.testRunner && window.internals) {
7474
setEnableFeature(true);
7575

76-
testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", true);
77-
7876
testRunner.waitUntilDone();
7977
testRunner.dumpChildFramesAsText();
8078
document.location.hash = "step1";
79+
80+
testRunner.statisticsSetShouldPartitionCookiesForHost("localhost", true, runTest);
81+
} else {
82+
runTest();
8183
}
8284
</script>
8385
</body>

0 commit comments

Comments
 (0)