Skip to content

Commit c37d6ca

Browse files
shuranhuangChromium LUCI CQ
authored andcommitted
[Merge 116] Include unpartitioned cookie availability check in hasStorageAccess()
This change is based on spec PR privacycg/storage-access#174. (cherry picked from commit 120b35b) Bug: 1433013 Change-Id: I6c29b2a2afddb288d40d946040dc73fbe76b6fcb Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4611289 Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Shuran Huang <[email protected]> Reviewed-by: Chris Fredrickson <[email protected]> Cr-Original-Commit-Position: refs/heads/main@{#1161766} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4665808 Auto-Submit: Shuran Huang <[email protected]> Reviewed-by: Dominic Farolino <[email protected]> Commit-Queue: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/branch-heads/5845@{chromium#322} Cr-Branched-From: 5a5dff6-refs/heads/main@{#1160321}
1 parent 2c1cd95 commit c37d6ca

File tree

6 files changed

+78
-13
lines changed

6 files changed

+78
-13
lines changed

chrome/browser/storage_access_api/api_browsertest.cc

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "components/policy/policy_constants.h"
3939
#include "components/prefs/pref_service.h"
4040
#include "content/public/browser/browser_context.h"
41+
#include "content/public/browser/navigation_handle.h"
4142
#include "content/public/browser/storage_partition.h"
4243
#include "content/public/common/content_paths.h"
4344
#include "content/public/test/browser_task_environment.h"
@@ -622,13 +623,12 @@ IN_PROC_BROWSER_TEST_F(
622623
EXPECT_EQ(ReadCookiesAndContent(GetFrame(), kHostB),
623624
CookieBundleWithContent("cross-site=b.test"));
624625

625-
// TODO(https://crbug.com/1441133): We should either make sure there is way to
626-
// let developer check whether they need to call rSA(), or no prompt is shown
627-
// when 3p cookie is allowed.
628-
EXPECT_FALSE(storage::test::HasStorageAccessForFrame(GetFrame()));
626+
EXPECT_TRUE(storage::test::HasStorageAccessForFrame(GetFrame()));
629627
prompt_factory()->set_response_type(
630628
permissions::PermissionRequestManager::ACCEPT_ALL);
631629
EXPECT_TRUE(storage::test::RequestAndCheckStorageAccessForFrame(GetFrame()));
630+
// TODO(https://crbug.com/1441133): No prompt should be shown when 3p cookie
631+
// is allowed.
632632
EXPECT_EQ(1, prompt_factory()->TotalRequestCount());
633633
}
634634

@@ -835,7 +835,10 @@ IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
835835
EXPECT_FALSE(storage::test::HasStorageAccessForFrame(GetFrame()));
836836
prompt_factory()->set_response_type(
837837
permissions::PermissionRequestManager::ACCEPT_ALL);
838-
EXPECT_TRUE(storage::test::RequestAndCheckStorageAccessForFrame(GetFrame()));
838+
// TODO(https://crbug.com/1441133): requestStorageAccess() should be rejected
839+
// when 3p cookie is blocked by user explicitly.
840+
EXPECT_TRUE(content::ExecJs(GetFrame(), "document.requestStorageAccess()"));
841+
EXPECT_FALSE(storage::test::HasStorageAccessForFrame(GetFrame()));
839842

840843
EXPECT_EQ(ReadCookies(GetFrame(), kHostB), NoCookies());
841844
}
@@ -857,9 +860,11 @@ IN_PROC_BROWSER_TEST_F(
857860

858861
prompt_factory()->set_response_type(
859862
permissions::PermissionRequestManager::ACCEPT_ALL);
860-
863+
// TODO(https://crbug.com/1441133): requestStorageAccess() should be rejected
864+
// when 3p cookie is blocked by user explicitly.
861865
EXPECT_TRUE(
862-
storage::test::RequestAndCheckStorageAccessForFrame(GetNestedFrame()));
866+
content::ExecJs(GetNestedFrame(), "document.requestStorageAccess()"));
867+
EXPECT_FALSE(storage::test::HasStorageAccessForFrame(GetNestedFrame()));
863868

864869
EXPECT_EQ(ReadCookies(GetNestedFrame(), kHostB), NoCookies());
865870
}
@@ -883,9 +888,11 @@ IN_PROC_BROWSER_TEST_F(
883888

884889
prompt_factory()->set_response_type(
885890
permissions::PermissionRequestManager::ACCEPT_ALL);
886-
891+
// TODO(https://crbug.com/1441133): requestStorageAccess() should be rejected
892+
// when 3p cookie is blocked by user explicitly.
887893
EXPECT_TRUE(
888-
storage::test::RequestAndCheckStorageAccessForFrame(GetNestedFrame()));
894+
content::ExecJs(GetNestedFrame(), "document.requestStorageAccess()"));
895+
EXPECT_FALSE(storage::test::HasStorageAccessForFrame(GetNestedFrame()));
889896

890897
EXPECT_EQ(ReadCookies(GetNestedFrame(), kHostC), NoCookies());
891898
}
@@ -1533,7 +1540,7 @@ IN_PROC_BROWSER_TEST_P(StorageAccessAPIStorageBrowserTest, MultiTabTest) {
15331540
storage::test::ExpectCrossTabInfoForFrame(GetFrame(), false);
15341541
storage::test::SetCrossTabInfoForFrame(GetFrame());
15351542
storage::test::ExpectCrossTabInfoForFrame(GetFrame(), true);
1536-
EXPECT_FALSE(storage::test::HasStorageAccessForFrame(GetFrame()));
1543+
EXPECT_TRUE(storage::test::HasStorageAccessForFrame(GetFrame()));
15371544

15381545
// Create a second tab to test communication between tabs.
15391546
NavigateToNewTabWithFrame(kHostA);
@@ -1545,7 +1552,7 @@ IN_PROC_BROWSER_TEST_P(StorageAccessAPIStorageBrowserTest, MultiTabTest) {
15451552
permissions::PermissionRequestManager::ACCEPT_ALL);
15461553

15471554
storage::test::ExpectCrossTabInfoForFrame(GetFrame(), true);
1548-
EXPECT_FALSE(storage::test::HasStorageAccessForFrame(GetFrame()));
1555+
EXPECT_TRUE(storage::test::HasStorageAccessForFrame(GetFrame()));
15491556

15501557
SetBlockThirdPartyCookies(true);
15511558

@@ -1879,6 +1886,7 @@ IN_PROC_BROWSER_TEST_P(StorageAccessAPIEnterprisePolicyBrowserTest,
18791886

18801887
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
18811888
EnsureOnePromptDenialSuffices) {
1889+
SetBlockThirdPartyCookies(true);
18821890
NavigateToPageWithFrame(kHostA);
18831891
NavigateFrameTo(EchoCookiesURL(kHostB));
18841892

@@ -1912,6 +1920,7 @@ IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
19121920

19131921
IN_PROC_BROWSER_TEST_F(StorageAccessAPIBrowserTest,
19141922
DismissalAllowsFuturePrompts) {
1923+
SetBlockThirdPartyCookies(true);
19151924
NavigateToPageWithFrame(kHostA);
19161925
NavigateFrameTo(EchoCookiesURL(kHostB));
19171926

@@ -2096,4 +2105,50 @@ IN_PROC_BROWSER_TEST_F(
20962105
EXPECT_EQ(ReadCookies(GetFrame(), kHostA), CookieBundle("cross-site=a.test"));
20972106
}
20982107

2108+
// Tests to verify that whether 3p cookie is already accessible is checked in
2109+
// hasStorageAccess.
2110+
class StorageAccessAPIWith3PCEnabledBrowserTest
2111+
: public StorageAccessAPIBaseBrowserTest {
2112+
public:
2113+
StorageAccessAPIWith3PCEnabledBrowserTest()
2114+
: StorageAccessAPIBaseBrowserTest(/*is_storage_partitioned=*/false) {}
2115+
};
2116+
2117+
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWith3PCEnabledBrowserTest,
2118+
AllowedWhenUnblocked) {
2119+
SetBlockThirdPartyCookies(false);
2120+
2121+
NavigateToPageWithFrame(kHostA);
2122+
NavigateFrameTo(EchoCookiesURL(kHostB));
2123+
2124+
EXPECT_TRUE(storage::test::HasStorageAccessForFrame(GetFrame()));
2125+
2126+
EXPECT_EQ(ReadCookiesAndContent(GetFrame(), kHostB),
2127+
CookieBundleWithContent("cross-site=b.test"));
2128+
}
2129+
2130+
IN_PROC_BROWSER_TEST_F(StorageAccessAPIWith3PCEnabledBrowserTest,
2131+
AllowedByUserBypass) {
2132+
SetBlockThirdPartyCookies(true);
2133+
2134+
NavigateToPageWithFrame(kHostA);
2135+
NavigateFrameTo(EchoCookiesURL(kHostB));
2136+
EXPECT_EQ(ReadCookiesAndContent(GetFrame(), kHostB), NoCookiesWithContent());
2137+
2138+
EXPECT_FALSE(storage::test::HasStorageAccessForFrame(GetFrame()));
2139+
2140+
// Enable UserBypass on hostA as top-level.
2141+
CookieSettingsFactory::GetForProfile(browser()->profile())
2142+
->SetCookieSettingForUserBypass(GetURL(kHostA));
2143+
2144+
EXPECT_TRUE(storage::test::HasStorageAccessForFrame(GetFrame()));
2145+
2146+
NavigateToPageWithFrame(kHostA);
2147+
NavigateFrameTo(EchoCookiesURL(kHostB));
2148+
EXPECT_EQ(ReadCookiesAndContent(GetFrame(), kHostB),
2149+
CookieBundleWithContent("cross-site=b.test"));
2150+
}
2151+
2152+
// TODO(crbug.com/1448957): Add test cases of 3PC enabled by other mechanisms.
2153+
20992154
} // namespace

third_party/blink/renderer/core/dom/document.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6272,8 +6272,9 @@ ScriptPromise Document::hasStorageAccess(ScriptState* script_state) {
62726272
return true;
62736273
}
62746274

6275-
// #9: return global's `has storage access`.
6276-
return dom_window_->HasStorageAccess();
6275+
// #9 & #10: checks unpartitioned cookie availability with global's `has
6276+
// storage access`.
6277+
return CookiesEnabled();
62776278
}());
62786279
return promise;
62796280
}

third_party/blink/web_tests/external/wpt/storage-access-api/hasStorageAccess.sub.https.window.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// META: script=helpers.js
2+
// META: script=/resources/testdriver.js
3+
// META: script=/resources/testdriver-vendor.js
24
'use strict';
35

46
const {testPrefix, topLevelDocument} = processQueryParams();
@@ -9,6 +11,7 @@ promise_test(async () => {
911
}, "[" + testPrefix + "] document.hasStorageAccess() should exist on the document interface");
1012

1113
promise_test(async () => {
14+
await MaybeSetStorageAccess("*", "*", "blocked");
1215
const hasAccess = await document.hasStorageAccess();
1316
if (topLevelDocument || testPrefix.includes('same-origin')) {
1417
assert_true(hasAccess, "Access should be granted in top-level frame or iframe that is in first-party context by default.");

third_party/blink/web_tests/external/wpt/storage-access-api/resources/hasStorageAccess-ABA-iframe.https.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<meta charset=utf-8>
33

44
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testdriver.js"></script>
6+
<script src="/resources/testdriver-vendor.js"></script>
57
<script src="/storage-access-api/helpers.js"></script>
68
<body>
79
<script src="/storage-access-api/resources/hasStorageAccess-ABA-iframe.sub.https.window.js"></script>

third_party/blink/web_tests/external/wpt/storage-access-api/resources/hasStorageAccess-ABA-iframe.sub.https.window.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// META: script=../helpers.js
2+
// META: script=/resources/testdriver.js
3+
// META: script=/resources/testdriver-vendor.js
24
'use strict';
35

46
// This expects to be run in an iframe that is cross-site to the top-level frame.

third_party/blink/web_tests/external/wpt/storage-access-api/resources/hasStorageAccess-iframe.https.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<meta charset=utf-8>
33

44
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testdriver.js"></script>
6+
<script src="/resources/testdriver-vendor.js"></script>
57
<!-- no testharnessreport.js -->
68
<script src="../helpers.js"></script>
79
<div id=log></div>

0 commit comments

Comments
 (0)