[3PCD] Update recording metrics when tracking protection onboard
This Cl update IsBlockedByThirdPartyDeprecationExperiment
with adding check whether tracking protection is actually onboard. This
means the third party cookie is real blocked. In other words, we only
record blink feature usage metrics when the 3PCD experiment is actual
block third party cookies and some mechanisms have re-enabled the third
party cookie access.
This also change the meaning of some UMA metric like:
PageLoad.Clients.ThirdPartyCookieAccessBlockedByExperiment. Once the
tracking protection is onboard, page load metric observer won't record
any cookie metrics unless some mechanisms re-enable third party cookie
access.
OBSOLETE_HISTOGRAMS=histogram PageLoad.Clients.ThirdPartyCookieAccessBlockedByExperiment is replaced by PageLoad.Clients.TPCD.ThirdPartyCookieAccessBlockedByExperiment2
OBSOLETE_HISTOGRAMS=histogram PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd is replaced by PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd2
OBSOLETE_HISTOGRAMS=histogram PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment is replaced by PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment2
Change-Id: Iafbd196b32342fe2490c577bbdd5dcbd18db4748
Bug: 1494080
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5033124
Commit-Queue: Victor Tan <victortan@chromium.org>
Reviewed-by: John Delaney <johnidel@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1227550}
diff --git a/chrome/browser/page_load_metrics/observers/third_party_cookie_deprecation_metrics_observer_browsertest.cc b/chrome/browser/page_load_metrics/observers/third_party_cookie_deprecation_metrics_observer_browsertest.cc
index 7cbb9f2b..03413859 100644
--- a/chrome/browser/page_load_metrics/observers/third_party_cookie_deprecation_metrics_observer_browsertest.cc
+++ b/chrome/browser/page_load_metrics/observers/third_party_cookie_deprecation_metrics_observer_browsertest.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/net/storage_test_utils.h"
+#include "chrome/browser/privacy_sandbox/tracking_protection_onboarding_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/subresource_filter/subresource_filter_browser_test_harness.h"
#include "chrome/browser/tpcd/experiment/tpcd_experiment_features.h"
@@ -27,6 +28,7 @@
#include "components/content_settings/core/common/pref_names.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "components/prefs/pref_service.h"
+#include "components/privacy_sandbox/tracking_protection_onboarding.h"
#include "components/subresource_filter/core/common/common_features.h"
#include "components/subresource_filter/core/common/test_ruleset_utils.h"
#include "components/tpcd/metadata/parser.h"
@@ -49,15 +51,22 @@
constexpr char kHostC[] = "c.test";
const char kThirdPartyCookieAccessBlockedHistogram[] =
- "PageLoad.Clients.ThirdPartyCookieAccessBlockedByExperiment";
+ "PageLoad.Clients.TPCD.ThirdPartyCookieAccessBlockedByExperiment2";
const char kThirdPartyCookieAllowMechanismHistogram[] =
"PageLoad.Clients.TPCD.CookieAccess.ThirdPartyCookieAllowMechanism";
+const char kThirdPartyCookieIsAdOrNonAdHistogram[] =
+ "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd2";
+
+const char kThirdPartyCookieAdBlockedByExperimentHistogram[] =
+ "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment2";
+
struct Allow3PCMechanismBrowserTestCase {
bool explicit_setting_allow_3p_cookie = false;
bool global_setting_allow_3p_cookie = false;
bool tpcd_metadata_allow_3p_cookie = false;
+ bool tracking_protection_onboard = false;
};
// Skip complex test cases setting for TPCD_SUPPORT and TPCD_HEURISTICS since
@@ -66,7 +75,6 @@
{
.explicit_setting_allow_3p_cookie = true,
},
-
{
.global_setting_allow_3p_cookie = true,
},
@@ -74,6 +82,18 @@
.tpcd_metadata_allow_3p_cookie = true,
},
{
+ .explicit_setting_allow_3p_cookie = true,
+ .tracking_protection_onboard = true,
+ },
+ {
+ .global_setting_allow_3p_cookie = true,
+ .tracking_protection_onboard = true,
+ },
+ {
+ .tpcd_metadata_allow_3p_cookie = true,
+ .tracking_protection_onboard = true,
+ },
+ {
// test cases for all value as default.
},
};
@@ -147,12 +167,27 @@
run_loop.Run();
}
+ void SetUpTrackingProtectionOnboard() {
+ browser()->profile()->GetPrefs()->SetInteger(
+ prefs::kTrackingProtectionOnboardingStatus,
+ static_cast<int>(privacy_sandbox::TrackingProtectionOnboarding::
+ OnboardingStatus::kOnboarded));
+ EXPECT_EQ(onboarding_service()->GetOnboardingStatus(),
+ privacy_sandbox::TrackingProtectionOnboarding::OnboardingStatus::
+ kOnboarded);
+ }
+
content::WebContents* web_contents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}
net::EmbeddedTestServer* https_server() { return &https_server_; }
+ privacy_sandbox::TrackingProtectionOnboarding* onboarding_service() {
+ return TrackingProtectionOnboardingFactory::GetForProfile(
+ browser()->profile());
+ }
+
protected:
base::test::ScopedFeatureList scoped_feature_list_;
@@ -202,6 +237,20 @@
: tpcd::experiment::utils::ExperimentState::kIneligible));
}
+ void SetUpTrackingProtectionOnboardWith3PCAllow(
+ const std::vector<GURL>& third_party_urls) {
+ SetUpTrackingProtectionOnboard();
+ // If tracking protection is onboard, observer's OnCookieAccess won't be
+ // triggered without any re-enable mechanisms. For testing purpose, we
+ // explicitly set allowing third party cookie access for test URLs.
+ for (auto third_party_url : third_party_urls) {
+ HostContentSettingsMapFactory::GetForProfile(browser()->profile())
+ ->SetContentSettingDefaultScope(third_party_url, GURL(),
+ ContentSettingsType::COOKIES,
+ CONTENT_SETTING_ALLOW);
+ }
+ }
+
void FetchCookies(const std::string& host, const std::string& path) {
// Fetch a subresrouce.
std::string fetch_subresource_script = R"(
@@ -255,8 +304,7 @@
false, 0);
histogram_tester.ExpectBucketCount(kThirdPartyCookieAccessBlockedHistogram,
true, 0);
- histogram_tester.ExpectTotalCount(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd", 0);
+ histogram_tester.ExpectTotalCount(kThirdPartyCookieIsAdOrNonAdHistogram, 0);
// Should not record allow mechanism metrics on first party.
histogram_tester.ExpectUniqueSample(kThirdPartyCookieAllowMechanismHistogram,
@@ -271,6 +319,7 @@
IN_PROC_BROWSER_TEST_P(ThirdPartyCookieDeprecationObserverBrowserTest,
ThirdPartyCookiesReadAndWrite) {
SetUpThirdPartyCookieExperimentWithClientState();
+ SetUpTrackingProtectionOnboardWith3PCAllow({GetURL(kHostB)});
content::CookieChangeObserver observer(web_contents(), 2);
base::HistogramTester histogram_tester;
@@ -352,6 +401,7 @@
IN_PROC_BROWSER_TEST_P(ThirdPartyCookieDeprecationObserverBrowserTest,
ThirdPartyJavaScriptCookieReadAndWrite) {
SetUpThirdPartyCookieExperimentWithClientState();
+ SetUpTrackingProtectionOnboardWith3PCAllow({GetURL(kHostB)});
content::CookieChangeObserver observer(web_contents(), 2);
base::HistogramTester histogram_tester;
@@ -382,9 +432,8 @@
blink::mojom::WebFeature::kThirdPartyCookieAccessBlockByExperiment, 1);
histogram_tester.ExpectUniqueSample(kThirdPartyCookieAccessBlockedHistogram,
true, 2);
- histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd",
- false, 1);
+ histogram_tester.ExpectUniqueSample(kThirdPartyCookieIsAdOrNonAdHistogram,
+ false, 1);
} else {
histogram_tester.ExpectBucketCount(
"Blink.UseCounter.Features",
@@ -397,6 +446,7 @@
IN_PROC_BROWSER_TEST_P(ThirdPartyCookieDeprecationObserverBrowserTest,
ThirdPartyAdCookieRead) {
SetUpThirdPartyCookieExperimentWithClientState();
+ SetUpTrackingProtectionOnboardWith3PCAllow({GetURL(kHostB)});
content::CookieChangeObserver observer(web_contents());
base::HistogramTester histogram_tester;
@@ -413,26 +463,25 @@
"Blink.UseCounter.Features",
blink::mojom::WebFeature::kThirdPartyCookieAdAccessBlockByExperiment,
1);
+ histogram_tester.ExpectUniqueSample(kThirdPartyCookieIsAdOrNonAdHistogram,
+ true, 1);
histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd", true,
- 1);
- histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment", true, 1);
+ kThirdPartyCookieAdBlockedByExperimentHistogram, true, 1);
} else {
histogram_tester.ExpectBucketCount(
"Blink.UseCounter.Features",
blink::mojom::WebFeature::kThirdPartyCookieAdAccessBlockByExperiment,
0);
histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment", false, 1);
- histogram_tester.ExpectTotalCount(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd", 0);
+ kThirdPartyCookieAdBlockedByExperimentHistogram, false, 1);
+ histogram_tester.ExpectTotalCount(kThirdPartyCookieIsAdOrNonAdHistogram, 0);
}
}
IN_PROC_BROWSER_TEST_P(ThirdPartyCookieDeprecationObserverBrowserTest,
ThirdPartyNonAdCookieRead) {
SetUpThirdPartyCookieExperimentWithClientState();
+ SetUpTrackingProtectionOnboardWith3PCAllow({GetURL(kHostB)});
base::HistogramTester histogram_tester;
NavigateToPageWithFrame(kHostA); // Same origin cookie read.
@@ -447,12 +496,11 @@
"Blink.UseCounter.Features",
blink::mojom::WebFeature::kThirdPartyCookieAdAccessBlockByExperiment, 0);
histogram_tester.ExpectTotalCount(
- "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment", 0);
+ kThirdPartyCookieAdBlockedByExperimentHistogram, 0);
if (IsRecordThirdPartyCookiesExperimentMetrics()) {
- histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd",
- false, 1);
+ histogram_tester.ExpectUniqueSample(kThirdPartyCookieIsAdOrNonAdHistogram,
+ false, 1);
}
}
@@ -475,14 +523,14 @@
"Blink.UseCounter.Features",
blink::mojom::WebFeature::kThirdPartyCookieAdAccessBlockByExperiment, 0);
histogram_tester.ExpectTotalCount(
- "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment", 0);
- histogram_tester.ExpectTotalCount(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd", 0);
+ kThirdPartyCookieAdBlockedByExperimentHistogram, 0);
+ histogram_tester.ExpectTotalCount(kThirdPartyCookieIsAdOrNonAdHistogram, 0);
}
IN_PROC_BROWSER_TEST_P(ThirdPartyCookieDeprecationObserverBrowserTest,
ThirdPartyAdCookieReadSubframe) {
SetUpThirdPartyCookieExperimentWithClientState();
+ SetUpTrackingProtectionOnboardWith3PCAllow({GetURL(kHostB)});
content::CookieChangeObserver observer(web_contents(), 2);
base::HistogramTester histogram_tester;
@@ -496,22 +544,22 @@
NavigateToUntrackedUrl();
histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment",
+ kThirdPartyCookieAdBlockedByExperimentHistogram,
IsRecordThirdPartyCookiesExperimentMetrics(), 1);
if (IsRecordThirdPartyCookiesExperimentMetrics()) {
histogram_tester.ExpectBucketCount(
"Blink.UseCounter.Features",
blink::mojom::WebFeature::kThirdPartyCookieAdAccessBlockByExperiment,
1);
- histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd", true,
- 1);
+ histogram_tester.ExpectUniqueSample(kThirdPartyCookieIsAdOrNonAdHistogram,
+ true, 1);
}
}
IN_PROC_BROWSER_TEST_P(ThirdPartyCookieDeprecationObserverBrowserTest,
ThirdPartyAdCookieReadScriptTaggedSubframe) {
SetUpThirdPartyCookieExperimentWithClientState();
+ SetUpTrackingProtectionOnboardWith3PCAllow({GetURL(kHostB)});
base::HistogramTester histogram_tester;
NavigateToPageWithFrame(kHostA); // Same origin cookie read.
@@ -532,22 +580,22 @@
NavigateToUntrackedUrl();
histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment",
+ kThirdPartyCookieAdBlockedByExperimentHistogram,
IsRecordThirdPartyCookiesExperimentMetrics(), 1);
if (IsRecordThirdPartyCookiesExperimentMetrics()) {
histogram_tester.ExpectBucketCount(
"Blink.UseCounter.Features",
blink::mojom::WebFeature::kThirdPartyCookieAdAccessBlockByExperiment,
1);
- histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd", true,
- 1);
+ histogram_tester.ExpectUniqueSample(kThirdPartyCookieIsAdOrNonAdHistogram,
+ true, 1);
}
}
IN_PROC_BROWSER_TEST_P(ThirdPartyCookieDeprecationObserverBrowserTest,
ThirdPartyAdCookieReadOnRedirect) {
SetUpThirdPartyCookieExperimentWithClientState();
+ SetUpTrackingProtectionOnboardWith3PCAllow({GetURL(kHostB), GetURL(kHostC)});
content::CookieChangeObserver observer(web_contents());
base::HistogramTester histogram_tester;
@@ -555,10 +603,9 @@
// 3p cookie write
FetchCookies(kHostB, "/set-cookie?thirdparty=1;SameSite=None;Secure&isad=1");
// 3p cookie read
- FetchCookies(
- kHostC,
- "/server-redirect?" +
- https_server()->GetURL("b.test", "/empty.html?isad=1").spec());
+ FetchCookies(kHostC,
+ "/server-redirect?" +
+ https_server()->GetURL(kHostB, "/empty.html?isad=1").spec());
NavigateToUntrackedUrl();
@@ -567,20 +614,18 @@
"Blink.UseCounter.Features",
blink::mojom::WebFeature::kThirdPartyCookieAdAccessBlockByExperiment,
1);
+ histogram_tester.ExpectUniqueSample(kThirdPartyCookieIsAdOrNonAdHistogram,
+ true, 1);
histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd", true,
- 1);
- histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment", true, 1);
+ kThirdPartyCookieAdBlockedByExperimentHistogram, true, 1);
} else {
histogram_tester.ExpectBucketCount(
"Blink.UseCounter.Features",
blink::mojom::WebFeature::kThirdPartyCookieAdAccessBlockByExperiment,
0);
histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment", false, 1);
- histogram_tester.ExpectTotalCount(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd", 0);
+ kThirdPartyCookieAdBlockedByExperimentHistogram, false, 1);
+ histogram_tester.ExpectTotalCount(kThirdPartyCookieIsAdOrNonAdHistogram, 0);
}
}
@@ -596,6 +641,9 @@
ASSERT_TRUE(https_server->Start());
SetUpThirdPartyCookieExperimentWithClientState();
+ SetUpTrackingProtectionOnboardWith3PCAllow(
+ {GetURL(kHostB), https_server->GetURL(kHostB, "/"),
+ https_server->GetURL(kHostC, "/")});
base::HistogramTester histogram_tester;
NavigateToPageWithFrame(kHostA); // Same origin cookie read.
@@ -635,17 +683,17 @@
"Blink.UseCounter.Features",
blink::mojom::WebFeature::kThirdPartyCookieAdAccessBlockByExperiment, 0);
histogram_tester.ExpectTotalCount(
- "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment", 0);
+ kThirdPartyCookieAdBlockedByExperimentHistogram, 0);
if (IsRecordThirdPartyCookiesExperimentMetrics()) {
- histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd",
- false, 1);
+ histogram_tester.ExpectUniqueSample(kThirdPartyCookieIsAdOrNonAdHistogram,
+ false, 1);
}
}
IN_PROC_BROWSER_TEST_P(ThirdPartyCookieDeprecationObserverBrowserTest,
ThirdPartyAdJavaScriptCookieRead) {
SetUpThirdPartyCookieExperimentWithClientState();
+ SetUpTrackingProtectionOnboardWith3PCAllow({GetURL(kHostB)});
content::CookieChangeObserver observer(web_contents(),
/*num_expected_calls=*/2);
@@ -669,20 +717,18 @@
"Blink.UseCounter.Features",
blink::mojom::WebFeature::kThirdPartyCookieAdAccessBlockByExperiment,
1);
+ histogram_tester.ExpectUniqueSample(kThirdPartyCookieIsAdOrNonAdHistogram,
+ true, 1);
histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd", true,
- 1);
- histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment", true, 1);
+ kThirdPartyCookieAdBlockedByExperimentHistogram, true, 1);
} else {
histogram_tester.ExpectBucketCount(
"Blink.UseCounter.Features",
blink::mojom::WebFeature::kThirdPartyCookieAdAccessBlockByExperiment,
0);
histogram_tester.ExpectUniqueSample(
- "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment", false, 1);
- histogram_tester.ExpectTotalCount(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd", 0);
+ kThirdPartyCookieAdBlockedByExperimentHistogram, false, 1);
+ histogram_tester.ExpectTotalCount(kThirdPartyCookieIsAdOrNonAdHistogram, 0);
}
}
@@ -728,6 +774,11 @@
tpcd::experiment::prefs::kTPCDExperimentClientState,
static_cast<int>(tpcd::experiment::utils::ExperimentState::kEligible));
+ // Set up tracking protection onboard status.
+ if (test_case_.tracking_protection_onboard) {
+ SetUpTrackingProtectionOnboard();
+ }
+
if (test_case_.explicit_setting_allow_3p_cookie) {
HostContentSettingsMapFactory::GetForProfile(browser()->profile())
->SetContentSettingDefaultScope(third_party_url, GURL(),
@@ -776,6 +827,8 @@
void VerifyThirdPartyCookieAllowMechanism(
const base::HistogramTester& histogram_tester) {
+ // Notes: All the blink feature usage metric only record when tracking
+ // protection is onboard.
if (test_case_.explicit_setting_allow_3p_cookie) {
histogram_tester.ExpectUniqueSample(
kThirdPartyCookieAllowMechanismHistogram,
@@ -784,16 +837,22 @@
"Blink.UseCounter.Features",
blink::mojom::WebFeature::
kThirdPartyCookieDeprecation_AllowByExplicitSetting,
- 1);
+ test_case_.tracking_protection_onboard ? 1 : 0);
} else if (test_case_.global_setting_allow_3p_cookie) {
+ // If tracking protection is onboard, the global setting is not allow
+ // third party to access cookie. Also, it blocks re-enable third-party
+ // cookies access through pref key prefs::kCookieControlsMode used by
+ // enterprise policy BlockThirdPartyCookies. In this case, page load
+ // metrics observers' OnCookie(Read|Change) won't be triggered.
histogram_tester.ExpectUniqueSample(
kThirdPartyCookieAllowMechanismHistogram,
- /*kAllowByGlobalSetting*/ 2, 2);
+ /*kAllowByGlobalSetting*/ 2,
+ test_case_.tracking_protection_onboard ? 0 : 2);
histogram_tester.ExpectBucketCount(
"Blink.UseCounter.Features",
blink::mojom::WebFeature::
kThirdPartyCookieDeprecation_AllowByGlobalSetting,
- 1);
+ 0);
} else if (test_case_.tpcd_metadata_allow_3p_cookie) {
histogram_tester.ExpectUniqueSample(
kThirdPartyCookieAllowMechanismHistogram,
@@ -802,20 +861,32 @@
"Blink.UseCounter.Features",
blink::mojom::WebFeature::
kThirdPartyCookieDeprecation_AllowBy3PCDMetadata,
- 1);
+ test_case_.tracking_protection_onboard ? 1 : 0);
} else {
- // the default is allow if none of mechanisms applied.
histogram_tester.ExpectUniqueSample(
kThirdPartyCookieAllowMechanismHistogram,
- /*kAllowByGlobalSetting*/ 2, 2);
+ /*kAllowByGlobalSetting*/ 2,
+ test_case_.tracking_protection_onboard ? 0 : 2);
+ // If tracking protection is onboard, the global setting is not allow
+ // third party to access cookie.
histogram_tester.ExpectBucketCount(
"Blink.UseCounter.Features",
blink::mojom::WebFeature::
kThirdPartyCookieDeprecation_AllowByGlobalSetting,
- 1);
+ 0);
}
}
+ int CanTriggerCookieChangeObserver() {
+ // If tracking protection is onboard, the CookieChangeObserver is trigger
+ // only when some mechanisms re-enable the third party cookie access
+ if (test_case_.tracking_protection_onboard) {
+ return test_case_.explicit_setting_allow_3p_cookie ||
+ test_case_.tpcd_metadata_allow_3p_cookie;
+ }
+ return true;
+ }
+
private:
Allow3PCMechanismBrowserTestCase test_case_;
base::ScopedTempDir fake_install_dir_;
@@ -838,7 +909,9 @@
NavigateFrameTo(kHostB, "/set-cookie?thirdparty=1;SameSite=None;Secure");
// 3p cookie read
NavigateFrameTo(kHostB, "/");
- observer.Wait();
+ if (CanTriggerCookieChangeObserver()) {
+ observer.Wait();
+ }
NavigateToUntrackedUrl();
VerifyThirdPartyCookieAllowMechanism(histogram_tester);
@@ -862,13 +935,16 @@
// Read a third-party cookie.
EXPECT_TRUE(content::ExecJs(frame, "let x = document.cookie;"));
- observer.Wait();
+ if (CanTriggerCookieChangeObserver()) {
+ observer.Wait();
+ }
NavigateToUntrackedUrl();
VerifyThirdPartyCookieAllowMechanism(histogram_tester);
}
class ThirdPartyCookieDeprecationObserverSSABrowserTest
- : public ThirdPartyCookieDeprecationObserverBaseBrowserTest {
+ : public ThirdPartyCookieDeprecationObserverBaseBrowserTest,
+ public testing::WithParamInterface<bool> {
public:
ThirdPartyCookieDeprecationObserverSSABrowserTest() = default;
@@ -888,7 +964,9 @@
void SetUp() override {
scoped_feature_list_.InitWithFeaturesAndParameters(
- {{content_settings::features::kTrackingProtection3pcd, {}},
+ {{features::kCookieDeprecationFacilitatedTesting,
+ {{tpcd::experiment::kDisable3PCookiesName, "true"}}},
+ {content_settings::features::kTrackingProtection3pcd, {}},
{blink::features::kStorageAccessAPI, {}}},
{});
subresource_filter::SubresourceFilterBrowserTest::SetUp();
@@ -904,6 +982,18 @@
R"(, "serviceSites": ["https://)", kHostB, R"("]})"}));
}
+ void SetUpThirdPartyCookieExperiment() {
+ Wait();
+ g_browser_process->local_state()->SetInteger(
+ tpcd::experiment::prefs::kTPCDExperimentClientState,
+ static_cast<int>(tpcd::experiment::utils::ExperimentState::kEligible));
+
+ // Set up tracking protection onboard status.
+ if (GetParam()) {
+ SetUpTrackingProtectionOnboard();
+ }
+ }
+
void SetCrossSiteCookieOnHost(const std::string& host) {
GURL host_url = GetURL(host);
std::string cookie = base::StrCat({"cross-site=", host});
@@ -927,8 +1017,13 @@
}
};
-IN_PROC_BROWSER_TEST_F(ThirdPartyCookieDeprecationObserverSSABrowserTest,
+INSTANTIATE_TEST_SUITE_P(,
+ ThirdPartyCookieDeprecationObserverSSABrowserTest,
+ testing::Bool());
+
+IN_PROC_BROWSER_TEST_P(ThirdPartyCookieDeprecationObserverSSABrowserTest,
ThirdPartyCookiesReadAndWrite) {
+ SetUpThirdPartyCookieExperiment();
SetCrossSiteCookieOnHost(kHostB);
content::CookieChangeObserver observer(web_contents(), 2);
@@ -953,10 +1048,16 @@
// with storage access API owner.
histogram_tester.ExpectUniqueSample(kThirdPartyCookieAllowMechanismHistogram,
/*kAllowByStorageAccess*/ 6, 0);
+ histogram_tester.ExpectBucketCount(
+ "Blink.UseCounter.Features",
+ blink::mojom::WebFeature::
+ kThirdPartyCookieDeprecation_AllowByStorageAccess,
+ 0);
}
-IN_PROC_BROWSER_TEST_F(ThirdPartyCookieDeprecationObserverSSABrowserTest,
+IN_PROC_BROWSER_TEST_P(ThirdPartyCookieDeprecationObserverSSABrowserTest,
ThirdPartyJavaScriptCookieReadAndWrite) {
+ SetUpThirdPartyCookieExperiment();
SetCrossSiteCookieOnHost(kHostB);
content::CookieChangeObserver observer(web_contents(), 2);
@@ -978,4 +1079,10 @@
histogram_tester.ExpectUniqueSample(kThirdPartyCookieAllowMechanismHistogram,
/*kAllowByStorageAccess*/ 6, 2);
+ // Only record blink usage when tracking protection is onboard.
+ histogram_tester.ExpectBucketCount(
+ "Blink.UseCounter.Features",
+ blink::mojom::WebFeature::
+ kThirdPartyCookieDeprecation_AllowByStorageAccess,
+ GetParam() ? 1 : 0);
}
diff --git a/chrome/browser/page_load_metrics/observers/third_party_cookie_deprecation_page_load_metrics_observer.cc b/chrome/browser/page_load_metrics/observers/third_party_cookie_deprecation_page_load_metrics_observer.cc
index 110f9f7..b27f1ead 100644
--- a/chrome/browser/page_load_metrics/observers/third_party_cookie_deprecation_page_load_metrics_observer.cc
+++ b/chrome/browser/page_load_metrics/observers/third_party_cookie_deprecation_page_load_metrics_observer.cc
@@ -6,6 +6,7 @@
#include "base/metrics/histogram_macros.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
+#include "chrome/browser/privacy_sandbox/tracking_protection_onboarding_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tpcd/experiment/experiment_manager_impl.h"
#include "chrome/browser/tpcd/experiment/tpcd_experiment_features.h"
@@ -21,6 +22,8 @@
using ThirdPartyCookieAllowMechanism =
content_settings::CookieSettingsBase::ThirdPartyCookieAllowMechanism;
+using OnboardingStatus =
+ privacy_sandbox::TrackingProtectionOnboarding::OnboardingStatus;
bool IsSameSite(const GURL& url1, const GURL& url2) {
return url1.SchemeIs(url2.scheme()) &&
@@ -29,13 +32,6 @@
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
}
-void ReportThirdPartyCookieAllowMechanismHistogram(
- ThirdPartyCookieAllowMechanism result) {
- UMA_HISTOGRAM_ENUMERATION(
- "PageLoad.Clients.TPCD.CookieAccess.ThirdPartyCookieAllowMechanism",
- result);
-}
-
} // namespace
ThirdPartyCookieDeprecationMetricsObserver::
@@ -45,6 +41,8 @@
experiment_manager_ =
tpcd::experiment::ExperimentManagerImpl::GetForProfile(profile);
cookie_settings_ = CookieSettingsFactory::GetForProfile(profile);
+ tracking_protection_onboarding_ =
+ TrackingProtectionOnboardingFactory::GetForProfile(profile);
}
ThirdPartyCookieDeprecationMetricsObserver::
@@ -106,65 +104,71 @@
}
// Record third party cookie metrics if the access is blocked by third
- // party cookies deprecation experiment.
+ // party cookies deprecation experiment when some mechanism re-enable the
+ // third party cookie access.
bool is_blocked_by_experiment = IsBlockedByThirdPartyDeprecationExperiment();
UMA_HISTOGRAM_BOOLEAN(
- "PageLoad.Clients.ThirdPartyCookieAccessBlockedByExperiment",
+ "PageLoad.Clients.TPCD.ThirdPartyCookieAccessBlockedByExperiment2",
is_blocked_by_experiment);
const ThirdPartyCookieAllowMechanism allow_mechanism =
cookie_settings_->GetThirdPartyCookieAllowMechanism(
url, first_party_url, cookie_setting_overrides);
if (allow_mechanism != ThirdPartyCookieAllowMechanism::kNone) {
- ReportThirdPartyCookieAllowMechanismHistogram(allow_mechanism);
+ UMA_HISTOGRAM_ENUMERATION(
+ "PageLoad.Clients.TPCD.CookieAccess.ThirdPartyCookieAllowMechanism",
+ allow_mechanism);
}
- std::vector<blink::mojom::WebFeature> third_party_cookie_features;
- if (is_blocked_by_experiment) {
- third_party_cookie_features.push_back(
- blink::mojom::WebFeature::kThirdPartyCookieAccessBlockByExperiment);
+ if (!is_blocked_by_experiment) {
+ return;
+ }
- // Record the each allow mechanism feature usage when the 3PCD experiment is
- // trying to block third party cookies.
- switch (allow_mechanism) {
- case ThirdPartyCookieAllowMechanism::kAllowByExplicitSetting:
- third_party_cookie_features.push_back(
- blink::mojom::WebFeature::
- kThirdPartyCookieDeprecation_AllowByExplicitSetting);
- break;
- case ThirdPartyCookieAllowMechanism::kAllowByGlobalSetting:
- third_party_cookie_features.push_back(
- blink::mojom::WebFeature::
- kThirdPartyCookieDeprecation_AllowByGlobalSetting);
- break;
- case ThirdPartyCookieAllowMechanism::kAllowBy3PCDMetadata:
- third_party_cookie_features.push_back(
- blink::mojom::WebFeature::
- kThirdPartyCookieDeprecation_AllowBy3PCDMetadata);
- break;
- case ThirdPartyCookieAllowMechanism::kAllowBy3PCD:
- third_party_cookie_features.push_back(
- blink::mojom::WebFeature::kThirdPartyCookieDeprecation_AllowBy3PCD);
- break;
- case ThirdPartyCookieAllowMechanism::kAllowBy3PCDHeuristics:
- third_party_cookie_features.push_back(
- blink::mojom::WebFeature::
- kThirdPartyCookieDeprecation_AllowBy3PCDHeuristics);
- break;
- case ThirdPartyCookieAllowMechanism::kAllowByStorageAccess:
- third_party_cookie_features.push_back(
- blink::mojom::WebFeature::
- kThirdPartyCookieDeprecation_AllowByStorageAccess);
- break;
- case ThirdPartyCookieAllowMechanism::kAllowByTopLevelStorageAccess:
- third_party_cookie_features.push_back(
- blink::mojom::WebFeature::
- kThirdPartyCookieDeprecation_AllowByTopLevelStorageAccess);
- break;
- default:
- // No feature usage recorded for unknow mechanism values.
- break;
- }
+ // Record the following blink feature usage cookie metrics when the 3PCD
+ // experiment is actual block third party cookies, which means tracking
+ // protection is onboard.
+ std::vector<blink::mojom::WebFeature> third_party_cookie_features;
+ third_party_cookie_features.push_back(
+ blink::mojom::WebFeature::kThirdPartyCookieAccessBlockByExperiment);
+
+ switch (allow_mechanism) {
+ case ThirdPartyCookieAllowMechanism::kAllowByExplicitSetting:
+ third_party_cookie_features.push_back(
+ blink::mojom::WebFeature::
+ kThirdPartyCookieDeprecation_AllowByExplicitSetting);
+ break;
+ case ThirdPartyCookieAllowMechanism::kAllowByGlobalSetting:
+ third_party_cookie_features.push_back(
+ blink::mojom::WebFeature::
+ kThirdPartyCookieDeprecation_AllowByGlobalSetting);
+ break;
+ case ThirdPartyCookieAllowMechanism::kAllowBy3PCDMetadata:
+ third_party_cookie_features.push_back(
+ blink::mojom::WebFeature::
+ kThirdPartyCookieDeprecation_AllowBy3PCDMetadata);
+ break;
+ case ThirdPartyCookieAllowMechanism::kAllowBy3PCD:
+ third_party_cookie_features.push_back(
+ blink::mojom::WebFeature::kThirdPartyCookieDeprecation_AllowBy3PCD);
+ break;
+ case ThirdPartyCookieAllowMechanism::kAllowBy3PCDHeuristics:
+ third_party_cookie_features.push_back(
+ blink::mojom::WebFeature::
+ kThirdPartyCookieDeprecation_AllowBy3PCDHeuristics);
+ break;
+ case ThirdPartyCookieAllowMechanism::kAllowByStorageAccess:
+ third_party_cookie_features.push_back(
+ blink::mojom::WebFeature::
+ kThirdPartyCookieDeprecation_AllowByStorageAccess);
+ break;
+ case ThirdPartyCookieAllowMechanism::kAllowByTopLevelStorageAccess:
+ third_party_cookie_features.push_back(
+ blink::mojom::WebFeature::
+ kThirdPartyCookieDeprecation_AllowByTopLevelStorageAccess);
+ break;
+ default:
+ // No feature usage recorded for unknow mechanism values.
+ break;
}
// Report the feature usage if there's anything to report.
@@ -187,14 +191,14 @@
bool is_blocked_by_experiment = IsBlockedByThirdPartyDeprecationExperiment();
if (is_ad_tagged) {
UMA_HISTOGRAM_BOOLEAN(
- "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment",
+ "PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment2",
is_blocked_by_experiment);
}
if (!is_blocked_by_experiment) {
return;
}
UMA_HISTOGRAM_BOOLEAN(
- "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd",
+ "PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd2",
is_ad_tagged);
if (is_ad_tagged) {
@@ -233,7 +237,13 @@
return false;
}
+ // Only record the metric when cookie deprecation label onboarding since third
+ // party cookie is not really disabled before onboarding.
return experiment_manager_ &&
experiment_manager_->IsClientEligible() == true &&
- tpcd::experiment::kDisable3PCookies.Get();
+ tpcd::experiment::kDisable3PCookies.Get() &&
+ tracking_protection_onboarding_ &&
+ tracking_protection_onboarding_->GetOnboardingStatus() ==
+ OnboardingStatus::kOnboarded;
+ ;
}
diff --git a/chrome/browser/page_load_metrics/observers/third_party_cookie_deprecation_page_load_metrics_observer.h b/chrome/browser/page_load_metrics/observers/third_party_cookie_deprecation_page_load_metrics_observer.h
index 7d04a75..61ad8ca 100644
--- a/chrome/browser/page_load_metrics/observers/third_party_cookie_deprecation_page_load_metrics_observer.h
+++ b/chrome/browser/page_load_metrics/observers/third_party_cookie_deprecation_page_load_metrics_observer.h
@@ -9,6 +9,7 @@
#include "base/memory/scoped_refptr.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/page_load_metrics/browser/page_load_metrics_observer.h"
+#include "components/privacy_sandbox/tracking_protection_onboarding.h"
namespace tpcd::experiment {
class ExperimentManager;
@@ -74,6 +75,8 @@
// Not owned and the lifetime of ExperimentManager will exceed |this|.
raw_ptr<tpcd::experiment::ExperimentManager> experiment_manager_;
+ raw_ptr<privacy_sandbox::TrackingProtectionOnboarding>
+ tracking_protection_onboarding_;
scoped_refptr<content_settings::CookieSettings> cookie_settings_;
};
diff --git a/tools/metrics/histograms/metadata/page/enums.xml b/tools/metrics/histograms/metadata/page/enums.xml
index 7ef876c..305b6fcf 100644
--- a/tools/metrics/histograms/metadata/page/enums.xml
+++ b/tools/metrics/histograms/metadata/page/enums.xml
@@ -297,7 +297,7 @@
Policy: CookiesAllowedForUrls, UserBypass)"/>
<int value="2"
label="Allow by global 3p cookie setting setting (e.g. Enterprise
- Policy: BlockThirdPartyCookies, UX)"/>
+ Policy: BlockThirdPartyCookies, UX, Default allow)"/>
<int value="3"
label="Allow by 3PCD metadata grants content settings (Global
Allowlist)"/>
diff --git a/tools/metrics/histograms/metadata/page/histograms.xml b/tools/metrics/histograms/metadata/page/histograms.xml
index d767514..98cd7a9 100644
--- a/tools/metrics/histograms/metadata/page/histograms.xml
+++ b/tools/metrics/histograms/metadata/page/histograms.xml
@@ -1328,27 +1328,16 @@
</summary>
</histogram>
-<histogram name="PageLoad.Clients.ThirdPartyCookieAccessBlockedByExperiment"
- enum="Boolean" expires_after="2024-07-01">
- <owner>victortan@chromium.org</owner>
- <owner>src/chrome/browser/tpcd/OWNERS</owner>
- <summary>
- Record when a third party accesses(read|change) cookies either via resource
- request headers or document.cookie. True means the third party cookie
- deprecation experiment is trying to block third party cookies access, while
- False means experiment is not trying to block.
- </summary>
-</histogram>
-
-<histogram name="PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment"
+<histogram name="PageLoad.Clients.TPCD.AdTPCAccess.BlockedByExperiment2"
enum="Boolean" expires_after="2024-07-01">
<owner>johnidel@chromium.org</owner>
<owner>victortan@chromium.org</owner>
<owner>src/chrome/browser/tpcd/OWNERS</owner>
<summary>
Record when a third party ad request reads cookies. True means the third
- party cookie deprecation experiment is trying to block third party cookies
- access, while False means experiment is not trying to block.
+ party cookie deprecation experiment blocks third party cookies access while
+ some mechanisms re-enable the third party cookie access. False means third
+ party cookie access isn't blocked.
</summary>
</histogram>
@@ -1365,14 +1354,30 @@
</histogram>
<histogram
- name="PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd"
+ name="PageLoad.Clients.TPCD.ThirdPartyCookieAccessBlockedByExperiment2"
+ enum="Boolean" expires_after="2024-07-01">
+ <owner>victortan@chromium.org</owner>
+ <owner>src/chrome/browser/tpcd/OWNERS</owner>
+ <summary>
+ Record when a third party accesses(read|change) cookies either via resource
+ request headers or document.cookie. True means the third party cookie
+ deprecation experiment blocks third party cookies access while some
+ mechanisms re-enable the third party cookie access. False means third party
+ cookie access isn't blocked.
+ </summary>
+</histogram>
+
+<histogram
+ name="PageLoad.Clients.TPCD.TPCAccess.BlockedByExperiment.IsAdOrNonAd2"
enum="Boolean" expires_after="2024-07-01">
<owner>johnidel@chromium.org</owner>
<owner>victortan@chromium.org</owner>
<owner>src/chrome/browser/tpcd/OWNERS</owner>
<summary>
Records whether a cookie read that would be blocked by the TPCD experiment
- is for advertising purposes. Recorded only on third party cookie reads.
+ is for advertising purposes. Recorded only on third party cookie reads are
+ blocked by the TPCD experiment when some mechanisms re-enable the third
+ party cookie access.
</summary>
</histogram>