Privacy Sandbox Settings: Remove preference reconciliation logic
When the first version of the Privacy Sandbox Settings page was
launched, logic to set the default value of the main preference was
introduced.
This logic was required to consult both synced, and un-synced, state to
determine what initial state a user should have.
This logic has been running for all users for >1 year now, and so we
expect the vast majority of users to have been appropriately
initialized.
This CL removes the logic, termed "reconciliation", from the code base.
Bug: 1166665
Change-Id: I9ede9f035e8b7ea3bb220abe4849f55f3c67a024
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3721648
Reviewed-by: Olesia Marukhno <[email protected]>
Reviewed-by: Dominic Battré <[email protected]>
Commit-Queue: Theodore Olsauskas-Warren <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1018626}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 4b07a0e..8bf0ef79 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -757,6 +757,10 @@
"ash.improved_shortcuts_notification_shown_count";
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
+// Deprecated 06/2022.
+const char kPrivacySandboxPreferencesReconciled[] =
+ "privacy_sandbox.preferences_reconciled";
+
// Register local state used only for migration (clearing or moving to a new
// key).
void RegisterLocalStatePrefsForMigration(PrefRegistrySimple* registry) {
@@ -989,6 +993,8 @@
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
registry->RegisterBooleanPref(kTokenServiceDiceCompatible, false);
#endif // BUILDFLAG(ENABLE_DICE_SUPPORT)
+
+ registry->RegisterBooleanPref(kPrivacySandboxPreferencesReconciled, false);
}
} // namespace
@@ -1951,6 +1957,9 @@
#endif
profile_prefs->ClearPref(prefs::kCloudPrintSubmitEnabled);
+ // Added 06/2022.
+ profile_prefs->ClearPref(kPrivacySandboxPreferencesReconciled);
+
// Please don't delete the following line. It is used by PRESUBMIT.py.
// END_MIGRATE_OBSOLETE_PROFILE_PREFS
diff --git a/chrome/browser/privacy_sandbox/privacy_sandbox_service.cc b/chrome/browser/privacy_sandbox/privacy_sandbox_service.cc
index a8bb01e82..4a8da669 100644
--- a/chrome/browser/privacy_sandbox/privacy_sandbox_service.cc
+++ b/chrome/browser/privacy_sandbox/privacy_sandbox_service.cc
@@ -22,10 +22,7 @@
#include "components/prefs/pref_service.h"
#include "components/privacy_sandbox/privacy_sandbox_features.h"
#include "components/privacy_sandbox/privacy_sandbox_prefs.h"
-#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/strings/grit/components_strings.h"
-#include "components/sync/driver/sync_service.h"
-#include "components/sync/driver/sync_user_settings.h"
#include "content/public/browser/browsing_data_filter_builder.h"
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/interest_group_manager.h"
@@ -49,64 +46,6 @@
bool g_dialog_diabled_for_tests = false;
-// Returns true iff based on |cookies_settings| & |prefs| third party cookies
-// are disabled by policy. This includes disabling third party cookies via
-// disabling all cookies.
-bool ThirdPartyCookiesDisabledByPolicy(
- content_settings::CookieSettings* cookie_settings,
- PrefService* prefs) {
- auto* cookie_controls_mode_pref =
- prefs->FindPreference(prefs::kCookieControlsMode);
- auto cookie_controls_mode_value =
- static_cast<content_settings::CookieControlsMode>(
- cookie_controls_mode_pref->GetValue()->GetInt());
-
- if (cookie_controls_mode_pref->IsManaged() &&
- cookie_controls_mode_value ==
- content_settings::CookieControlsMode::kBlockThirdParty) {
- return true;
- }
-
- std::string default_cookie_setting_provider;
- auto default_cookie_setting = cookie_settings->GetDefaultCookieSetting(
- &default_cookie_setting_provider);
- auto default_cookie_setting_source =
- HostContentSettingsMap::GetSettingSourceFromProviderName(
- default_cookie_setting_provider);
-
- if (default_cookie_setting_source ==
- content_settings::SettingSource::SETTING_SOURCE_POLICY &&
- default_cookie_setting == ContentSetting::CONTENT_SETTING_BLOCK) {
- return true;
- }
-
- return false;
-}
-
-// Returns whether |cookie_settings| and |prefs| imply that a user's Privacy
-// Sandbox preference should be turned off.
-bool ShouldDisablePrivacySandbox(
- content_settings::CookieSettings* cookie_settings,
- PrefService* prefs) {
- // If a user has already expressed control over the Privacy Sandbox preference
- // on any of their devices there is no need to disable it.
- if (prefs->GetBoolean(prefs::kPrivacySandboxManuallyControlled))
- return false;
-
- auto cookie_controls_mode_value =
- static_cast<content_settings::CookieControlsMode>(
- prefs->GetInteger(prefs::kCookieControlsMode));
-
- auto default_cookie_setting =
- cookie_settings->GetDefaultCookieSetting(/*provider_id=*/nullptr);
-
- // The Privacy Sandbox preference should be disabled if 3P cookies or all
- // cookies are blocked.
- return (cookie_controls_mode_value ==
- content_settings::CookieControlsMode::kBlockThirdParty ||
- default_cookie_setting == ContentSetting::CONTENT_SETTING_BLOCK);
-}
-
// Returns the number of days in |time|, rounded to the closest day by hour if
// there is at least 1 day, but rounded to 0 if |time| is less than 1 day.
int GetNumberOfDaysRoundedAboveOne(base::TimeDelta time) {
@@ -167,9 +106,6 @@
privacy_sandbox::PrivacySandboxSettings* privacy_sandbox_settings,
content_settings::CookieSettings* cookie_settings,
PrefService* pref_service,
- policy::PolicyService* policy_service,
- syncer::SyncService* sync_service,
- signin::IdentityManager* identity_manager,
content::InterestGroupManager* interest_group_manager,
profile_metrics::BrowserProfileType profile_type,
content::BrowsingDataRemover* browsing_data_remover,
@@ -180,9 +116,6 @@
: privacy_sandbox_settings_(privacy_sandbox_settings),
cookie_settings_(cookie_settings),
pref_service_(pref_service),
- policy_service_(policy_service),
- sync_service_(sync_service),
- identity_manager_(identity_manager),
interest_group_manager_(interest_group_manager),
profile_type_(profile_type),
browsing_data_remover_(browsing_data_remover),
@@ -193,7 +126,6 @@
DCHECK(privacy_sandbox_settings_);
DCHECK(pref_service_);
DCHECK(cookie_settings_);
- DCHECK(policy_service_);
// Register observers for the Privacy Sandbox & FLoC preferences.
user_prefs_registrar_.Init(pref_service_);
@@ -210,15 +142,6 @@
base::BindRepeating(&PrivacySandboxService::OnPrivacySandboxV1PrefChanged,
base::Unretained(this)));
- // On first entering the privacy sandbox experiment, users may have the
- // privacy sandbox disabled (or "reconciled") based on their current cookie
- // settings (e.g. blocking 3P cookies). Depending on the state of the sync
- // service, identity manager, and cookie setting, reconciliation may not run
- // immediately, or may not run at all.
- // TODO(crbug.com/1166665): Remove reconciliation logic when kAPI controls are
- // further separated from cookie controls.
- MaybeReconcilePrivacySandboxPref();
-
// When the user enters the Privacy Sandbox 3 experiment, the default value
// of their V2 pref must be set. This is a one time operation that is checked
// here to ensure it runs on profile startup.
@@ -228,6 +151,9 @@
// must manually enable the sandbox if they stop being restricted.
if (IsPrivacySandboxRestricted())
pref_service_->SetBoolean(prefs::kPrivacySandboxApisEnabledV2, false);
+
+ // Record preference state for UMA at each startup.
+ LogPrivacySandboxState();
}
PrivacySandboxService::~PrivacySandboxService() = default;
@@ -521,128 +447,6 @@
}
}
-void PrivacySandboxService::Shutdown() {
- StopObserving();
-}
-
-void PrivacySandboxService::OnPolicyUpdated(const policy::PolicyNamespace& ns,
- const policy::PolicyMap& previous,
- const policy::PolicyMap& current) {
- // |pref_service_| and |cookie_settings_| will have been made aware
- // of the policy changes before this observer function is called.
- MaybeReconcilePrivacySandboxPref();
-}
-
-void PrivacySandboxService::OnStateChanged(syncer::SyncService* sync) {
- MaybeReconcilePrivacySandboxPref();
-}
-
-void PrivacySandboxService::OnSyncCycleCompleted(syncer::SyncService* sync) {
- MaybeReconcilePrivacySandboxPref();
-}
-
-void PrivacySandboxService::OnErrorStateOfRefreshTokenUpdatedForAccount(
- const CoreAccountInfo& account_info,
- const GoogleServiceAuthError& error) {
- MaybeReconcilePrivacySandboxPref();
-}
-
-void PrivacySandboxService::MaybeReconcilePrivacySandboxPref() {
- // No need to reconcile preferences if it has already happened.
- if (pref_service_->GetBoolean(prefs::kPrivacySandboxPreferencesReconciled)) {
- LogPrivacySandboxState();
- return;
- }
-
- // If all or 3P cookies are disabled by policy, this will be reflected
- // directly in the Privacy Sandbox preference at the policy level. No attempt
- // should be made to reconcile the user preference while this is true, as due
- // to sync this may opt a user out on a personal device based on managed
- // device settings. If the device becomes unmanaged, or the policy changes,
- // reconciliation should occur.
- if (ThirdPartyCookiesDisabledByPolicy(cookie_settings_, pref_service_)) {
- // The policy service may already be observed, e.g. if this method is being
- // called after an update which did not result in reconciliation running.
- if (!policy_service_observed_) {
- policy_service_->AddObserver(policy::POLICY_DOMAIN_CHROME, this);
- policy_service_observed_ = true;
- LogPrivacySandboxState();
- }
- return;
- }
-
- // Reconciliation of the Privacy Sandbox preference is based on both synced
- // and unsynced settings. The synced settings are only consulted should the
- // local settings indicate the Privacy Sandbox should be disabled.
- if (!ShouldDisablePrivacySandbox(cookie_settings_, pref_service_)) {
- ReconcilePrivacySandboxPref();
- return;
- }
-
- // The current settings applied to this device indicate that the Privacy
- // Sandbox should be disabled. A decision however cannot be made until it is
- // confirmed that either:
- // A) the synced state is available, or
- // B) it has become clear that the sync state will not be available.
- // In both cases reconciliation is run. In outcome A this is obviously fine,
- // in outcome B this risks clobbering some opted in devices if this device
- // would later sync the disabled preference (e.g. by the user signing back
- // into a sync paused device).
-
- // If the service currently indicates that preferences will not be synced,
- // then outcome B has been reached.
- if (!sync_service_ || !sync_service_->IsSyncFeatureEnabled() ||
- !sync_service_->GetUserSettings()->GetSelectedTypes().Has(
- syncer::UserSelectableType::kPreferences) ||
- sync_service_->HasUnrecoverableError()) {
- ReconcilePrivacySandboxPref();
- return;
- }
-
- // If the sync service has already completed a sync cycle, then outcome A has
- // been reached.
- if (sync_service_->HasCompletedSyncCycle()) {
- ReconcilePrivacySandboxPref();
- return;
- }
-
- // If there is a persistent auth error associated with the primary account's
- // refresh token, then sync will not be able to run and then outcome B has
- // been reached.
- DCHECK(identity_manager_);
- GoogleServiceAuthError auth_error =
- identity_manager_->GetErrorStateOfRefreshTokenForAccount(
- identity_manager_->GetPrimaryAccountId(signin::ConsentLevel::kSync));
- if (auth_error.IsPersistentError()) {
- ReconcilePrivacySandboxPref();
- return;
- }
-
- // Further tracking to determine when outcome A or B has occurred requires
- // observing both the sync service and the identity manager. It is valid for
- // observation to already be occurring as this method may be called multiple
- // times if observed updates do not result in outcome A or B being reached.
- DCHECK(sync_service_);
- DCHECK(identity_manager_);
- if (!sync_service_observer_.IsObserving())
- sync_service_observer_.Observe(sync_service_.get());
- if (!identity_manager_observer_.IsObserving())
- identity_manager_observer_.Observe(identity_manager_.get());
-}
-
-void PrivacySandboxService::ReconcilePrivacySandboxPref() {
- // Reconciliation only ever affects the synced, pre-notice / consent pref.
- if (ShouldDisablePrivacySandbox(cookie_settings_, pref_service_))
- pref_service_->SetBoolean(prefs::kPrivacySandboxApisEnabled, false);
-
- pref_service_->SetBoolean(prefs::kPrivacySandboxPreferencesReconciled, true);
-
- // If observers were setup they are no longer required after reconciliation
- // has occurred.
- StopObserving();
- LogPrivacySandboxState();
-}
-
void PrivacySandboxService::InitializePrivacySandboxV2Pref() {
if (!base::FeatureList::IsEnabled(privacy_sandbox::kPrivacySandboxSettings3))
return;
@@ -676,16 +480,6 @@
pref_service_->SetBoolean(prefs::kPrivacySandboxApisEnabledV2, true);
}
-void PrivacySandboxService::StopObserving() {
- // Removing a non-observing observer is a no-op.
- sync_service_observer_.Reset();
- identity_manager_observer_.Reset();
- if (policy_service_observed_) {
- policy_service_->RemoveObserver(policy::POLICY_DOMAIN_CHROME, this);
- policy_service_observed_ = false;
- }
-}
-
void PrivacySandboxService::RecordPrivacySandboxHistogram(
PrivacySandboxService::SettingsPrivacySandboxEnabled state) {
base::UmaHistogramEnumeration("Settings.PrivacySandbox.Enabled", state);
diff --git a/chrome/browser/privacy_sandbox/privacy_sandbox_service.h b/chrome/browser/privacy_sandbox/privacy_sandbox_service.h
index 3ce4081..18def9f 100644
--- a/chrome/browser/privacy_sandbox/privacy_sandbox_service.h
+++ b/chrome/browser/privacy_sandbox/privacy_sandbox_service.h
@@ -97,9 +97,6 @@
privacy_sandbox::PrivacySandboxSettings* privacy_sandbox_settings,
content_settings::CookieSettings* cookie_settings,
PrefService* pref_service,
- policy::PolicyService* policy_service,
- syncer::SyncService* sync_service,
- signin::IdentityManager* identity_manager,
content::InterestGroupManager* interest_group_manager,
profile_metrics::BrowserProfileType profile_type,
content::BrowsingDataRemover* browsing_data_remover,
@@ -260,50 +257,9 @@
virtual void SetTopicAllowed(privacy_sandbox::CanonicalTopic topic,
bool allowed);
- // KeyedService:
- void Shutdown() override;
-
- // policy::PolicyService::Observer:
- void OnPolicyUpdated(const policy::PolicyNamespace& ns,
- const policy::PolicyMap& previous,
- const policy::PolicyMap& current) override;
-
- // syncer::SyncServiceObserver:
- void OnStateChanged(syncer::SyncService* sync) override;
- void OnSyncCycleCompleted(syncer::SyncService* sync) override;
-
- // signin::IdentityManager::Observer:
- // TODO(crbug.com/1167680): This is only required to capture failure scenarios
- // that affect sync, yet aren't reported via SyncServiceObserver.
- void OnErrorStateOfRefreshTokenUpdatedForAccount(
- const CoreAccountInfo& account_info,
- const GoogleServiceAuthError& error) override;
-
protected:
friend class PrivacySandboxServiceTest;
- FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestReconciliationBlocked,
- ReconciliationOutcome);
- FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestReconciliationBlocked,
- ImmediateReconciliationNoSync);
- FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestReconciliationBlocked,
- ImmediateReconciliationSyncComplete);
- FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestReconciliationBlocked,
- ImmediateReconciliationPersistentSyncError);
- FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestReconciliationBlocked,
- ImmediateReconciliationNoDisable);
- FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestReconciliationBlocked,
- DelayedReconciliationSyncSuccess);
- FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestReconciliationBlocked,
- DelayedReconciliationSyncFailure);
- FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestReconciliationBlocked,
- DelayedReconciliationIdentityFailure);
- FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestReconciliationBlocked,
- DelayedReconciliationSyncIssueThenManaged);
- FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestReconciliationBlocked,
- NoReconciliationAlreadyRun);
- FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestReconciliationBlocked,
- NoReconciliationSandboxSettingsDisabled);
- FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestReconciliationBlocked,
+ FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTest,
MetricsLoggingOccursCorrectly);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestNonRegularProfile,
NoMetricsRecorded);
@@ -400,25 +356,10 @@
kMaxValue = kNoDialogRequiredDisabled,
};
- // Inspects the current sync state and settings to determine if the Privacy
- // Sandbox prefs should be reconciled. Calls ReconcilePrivacySandbox()
- // immediately if appropriate, or may register sync and identity observers to
- // call ReconcilePrivacySandbox() later as appropriate.
- void MaybeReconcilePrivacySandboxPref();
-
- // Selectively disable the Privacy Sandbox preference based on the local and
- // synced state. Reconcilliation is only performed once per synced profile.
- // As the sandbox is default enabled, reconcilliation will only ever opt a
- // user out of the sandbox.
- void ReconcilePrivacySandboxPref();
-
// Potentially enables the Privacy Sandbox V2 pref if required based on
// feature parameters and the profiles current state.
void InitializePrivacySandboxV2Pref();
- // Stops any observation of services being performed by this class.
- void StopObserving();
-
// Helper function to actually make the metrics call for
// LogPrivacySandboxState.
void RecordPrivacySandboxHistogram(SettingsPrivacySandboxEnabled state);
@@ -452,9 +393,6 @@
raw_ptr<privacy_sandbox::PrivacySandboxSettings> privacy_sandbox_settings_;
raw_ptr<content_settings::CookieSettings> cookie_settings_;
raw_ptr<PrefService> pref_service_;
- raw_ptr<policy::PolicyService> policy_service_;
- raw_ptr<syncer::SyncService> sync_service_;
- raw_ptr<signin::IdentityManager> identity_manager_;
raw_ptr<content::InterestGroupManager> interest_group_manager_;
profile_metrics::BrowserProfileType profile_type_;
raw_ptr<content::BrowsingDataRemover> browsing_data_remover_;
@@ -463,18 +401,8 @@
#endif
raw_ptr<browsing_topics::BrowsingTopicsService> browsing_topics_service_;
- base::ScopedObservation<syncer::SyncService, syncer::SyncServiceObserver>
- sync_service_observer_{this};
- base::ScopedObservation<signin::IdentityManager,
- signin::IdentityManager::Observer>
- identity_manager_observer_{this};
-
PrefChangeRegistrar user_prefs_registrar_;
- // A manual record of whether policy_service_ is being observerd.
- // Unfortunately PolicyService does not support scoped observers.
- bool policy_service_observed_ = false;
-
// The set of Browser windows which have an open Privacy Sandbox dialog.
std::set<Browser*> browsers_with_open_dialogs_;
diff --git a/chrome/browser/privacy_sandbox/privacy_sandbox_service_browsertest.cc b/chrome/browser/privacy_sandbox/privacy_sandbox_service_browsertest.cc
deleted file mode 100644
index ecec501..0000000
--- a/chrome/browser/privacy_sandbox/privacy_sandbox_service_browsertest.cc
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright 2021 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/privacy_sandbox/privacy_sandbox_settings_factory.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/test/base/in_process_browser_test.h"
-#include "components/content_settings/core/common/content_settings.h"
-#include "components/policy/core/browser/browser_policy_connector.h"
-#include "components/policy/core/common/mock_configuration_policy_provider.h"
-#include "components/policy/core/common/policy_map.h"
-#include "components/policy/policy_constants.h"
-#include "components/prefs/pref_service.h"
-#include "components/privacy_sandbox/privacy_sandbox_prefs.h"
-#include "components/privacy_sandbox/privacy_sandbox_settings.h"
-#include "content/public/browser/browser_context.h"
-#include "content/public/test/browser_test.h"
-#include "content/public/test/browser_test_utils.h"
-
-class PrivacySandboxSettingsBrowserPolicyTest : public InProcessBrowserTest {
- public:
- PrivacySandboxSettingsBrowserPolicyTest() {
- policy_provider()->SetDefaultReturns(
- /*is_initialization_complete_return=*/true,
- /*is_first_policy_load_complete_return=*/true);
- policy::BrowserPolicyConnector::SetPolicyProviderForTesting(
- policy_provider());
-
- policy::PolicyMap third_party_cookies_blocked_policy;
- third_party_cookies_blocked_policy.Set(
- policy::key::kBlockThirdPartyCookies, policy::POLICY_LEVEL_MANDATORY,
- policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD,
- base::Value(true),
- /*external_data_fetcher=*/nullptr);
- policy_provider()->UpdateChromePolicy(third_party_cookies_blocked_policy);
- }
-
- privacy_sandbox::PrivacySandboxSettings* privacy_sandbox_settings() {
- return PrivacySandboxSettingsFactory::GetForProfile(browser()->profile());
- }
-
- policy::MockConfigurationPolicyProvider* policy_provider() {
- return &policy_provider_;
- }
-
- protected:
- testing::NiceMock<policy::MockConfigurationPolicyProvider> policy_provider_;
-};
-
-// Reconciliation should not run while 3P or all cookies are disabled by
-// policy, but should run if the policy is changed or removed.
-IN_PROC_BROWSER_TEST_F(PrivacySandboxSettingsBrowserPolicyTest,
- DelayedReconciliationCookieSettingsManaged) {
- privacy_sandbox_settings();
-
- // Policies set in the test constructor should have prevented reconciliation
- // from running immediately.
- EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-
- // Check that applying a different policy which also results in 3P cookies
- // being blocked does not result in reconciliation running.
- policy::PolicyMap all_cookies_blocked_policy;
- all_cookies_blocked_policy.Set(
- policy::key::kDefaultCookiesSetting, policy::POLICY_LEVEL_MANDATORY,
- policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD,
- base::Value(CONTENT_SETTING_BLOCK),
- /*external_data_fetcher=*/nullptr);
- policy_provider()->UpdateChromePolicy(all_cookies_blocked_policy);
- EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-
- // Apply policy which allows third party cookies and ensure that
- // reconciliation runs.
- policy::PolicyMap third_party_cookies_allowed_policy;
- third_party_cookies_allowed_policy.Set(
- policy::key::kBlockThirdPartyCookies, policy::POLICY_LEVEL_MANDATORY,
- policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD,
- base::Value(false),
- /*external_data_fetcher=*/nullptr);
- policy_provider()->UpdateChromePolicy(third_party_cookies_allowed_policy);
- EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-}
diff --git a/chrome/browser/privacy_sandbox/privacy_sandbox_service_factory.cc b/chrome/browser/privacy_sandbox/privacy_sandbox_service_factory.cc
index e63fdd0..5dbf4b1 100644
--- a/chrome/browser/privacy_sandbox/privacy_sandbox_service_factory.cc
+++ b/chrome/browser/privacy_sandbox/privacy_sandbox_service_factory.cc
@@ -7,13 +7,10 @@
#include "base/memory/singleton.h"
#include "chrome/browser/browsing_topics/browsing_topics_service_factory.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
-#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/privacy_sandbox/privacy_sandbox_service.h"
#include "chrome/browser/privacy_sandbox/privacy_sandbox_settings_factory.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/signin/identity_manager_factory.h"
-#include "chrome/browser/sync/sync_service_factory.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/keyed_service.h"
@@ -40,8 +37,6 @@
BrowserContextDependencyManager::GetInstance()) {
DependsOn(PrivacySandboxSettingsFactory::GetInstance());
DependsOn(CookieSettingsFactory::GetInstance());
- DependsOn(SyncServiceFactory::GetInstance());
- DependsOn(IdentityManagerFactory::GetInstance());
DependsOn(browsing_topics::BrowsingTopicsServiceFactory::GetInstance());
#if !BUILDFLAG(IS_ANDROID)
DependsOn(TrustSafetySentimentServiceFactory::GetInstance());
@@ -54,9 +49,6 @@
return new PrivacySandboxService(
PrivacySandboxSettingsFactory::GetForProfile(profile),
CookieSettingsFactory::GetForProfile(profile).get(), profile->GetPrefs(),
- profile->GetProfilePolicyConnector()->policy_service(),
- SyncServiceFactory::GetForProfile(profile),
- IdentityManagerFactory::GetForProfile(profile),
profile->GetDefaultStoragePartition()->GetInterestGroupManager(),
profile_metrics::GetBrowserProfileType(profile),
(!profile->IsGuestSession() || profile->IsOffTheRecord())
diff --git a/chrome/browser/privacy_sandbox/privacy_sandbox_service_unittest.cc b/chrome/browser/privacy_sandbox/privacy_sandbox_service_unittest.cc
index 550a32d..e6a08c8 100644
--- a/chrome/browser/privacy_sandbox/privacy_sandbox_service_unittest.cc
+++ b/chrome/browser/privacy_sandbox/privacy_sandbox_service_unittest.cc
@@ -666,17 +666,23 @@
: browser_task_environment_(
base::test::TaskEnvironment::TimeSource::MOCK_TIME) {}
- void SetUp() override {
+ void SetUp() override { CreateService(); }
+
+ virtual std::unique_ptr<
+ privacy_sandbox_test_util::MockPrivacySandboxSettingsDelegate>
+ GetMockDelegate() {
auto mock_delegate = std::make_unique<
privacy_sandbox_test_util::MockPrivacySandboxSettingsDelegate>();
- mock_delegate_ = mock_delegate.get();
+ mock_delegate->SetupDefaultResponse(/*restricted=*/false,
+ /*confirmed=*/true);
+ return mock_delegate;
+ }
- InitializeBeforeStart();
-
+ void CreateService() {
privacy_sandbox_settings_ =
std::make_unique<privacy_sandbox::PrivacySandboxSettings>(
- std::move(mock_delegate), host_content_settings_map(),
- cookie_settings(), prefs(), /*incognito_profile=*/false);
+ GetMockDelegate(), host_content_settings_map(), cookie_settings(),
+ prefs(), /*incognito_profile=*/false);
#if !BUILDFLAG(IS_ANDROID)
mock_sentiment_service_ =
std::make_unique<::testing::NiceMock<MockTrustSafetySentimentService>>(
@@ -684,20 +690,14 @@
#endif
privacy_sandbox_service_ = std::make_unique<PrivacySandboxService>(
privacy_sandbox_settings(), cookie_settings(), profile()->GetPrefs(),
- policy_service(), sync_service(),
- identity_test_env()->identity_manager(), test_interest_group_manager(),
- GetProfileType(), browsing_data_remover(),
+ test_interest_group_manager(), GetProfileType(),
+ browsing_data_remover(),
#if !BUILDFLAG(IS_ANDROID)
mock_sentiment_service(),
#endif
mock_browsing_topics_service());
}
- virtual void InitializeBeforeStart() {
- mock_delegate()->SetupDefaultResponse(/*restricted=*/false,
- /*confirmed=*/true);
- }
-
virtual profile_metrics::BrowserProfileType GetProfileType() {
return profile_metrics::BrowserProfileType::kRegular;
}
@@ -726,21 +726,12 @@
content_settings::CookieSettings* cookie_settings() {
return CookieSettingsFactory::GetForProfile(profile()).get();
}
- syncer::TestSyncService* sync_service() { return &sync_service_; }
- policy::MockPolicyService* policy_service() { return &mock_policy_service_; }
- signin::IdentityTestEnvironment* identity_test_env() {
- return &identity_test_env_;
- }
TestInterestGroupManager* test_interest_group_manager() {
return &test_interest_group_manager_;
}
content::BrowsingDataRemover* browsing_data_remover() {
return profile()->GetBrowsingDataRemover();
}
- privacy_sandbox_test_util::MockPrivacySandboxSettingsDelegate*
- mock_delegate() {
- return mock_delegate_;
- }
browsing_topics::MockBrowsingTopicsService* mock_browsing_topics_service() {
return &mock_browsing_topics_service_;
}
@@ -752,15 +743,10 @@
private:
content::BrowserTaskEnvironment browser_task_environment_;
- signin::IdentityTestEnvironment identity_test_env_;
- testing::NiceMock<policy::MockPolicyService> mock_policy_service_;
TestingProfile profile_;
base::test::ScopedFeatureList feature_list_;
- syncer::TestSyncService sync_service_;
TestInterestGroupManager test_interest_group_manager_;
- raw_ptr<privacy_sandbox_test_util::MockPrivacySandboxSettingsDelegate>
- mock_delegate_;
browsing_topics::MockBrowsingTopicsService mock_browsing_topics_service_;
#if !BUILDFLAG(IS_ANDROID)
std::unique_ptr<MockTrustSafetySentimentService> mock_sentiment_service_;
@@ -946,405 +932,6 @@
EXPECT_TRUE(prefs()->GetBoolean(prefs::kPrivacySandboxApisEnabledV2));
}
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxDialogNoticeWaiting) {
- base::HistogramTester histogram_tester;
- feature_list()->Reset();
- feature_list()->InitAndEnableFeatureWithParameters(
- privacy_sandbox::kPrivacySandboxSettings3, {{"notice-required", "true"}});
- prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
- std::make_unique<base::Value>(false));
- prefs()->SetUserPref(prefs::kPrivacySandboxNoticeDisplayed,
- std::make_unique<base::Value>(false));
-
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/false,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kDialogWaiting, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxDialogConsentWaiting) {
- base::HistogramTester histogram_tester;
- feature_list()->Reset();
- feature_list()->InitAndEnableFeatureWithParameters(
- privacy_sandbox::kPrivacySandboxSettings3,
- {{"consent-required", "true" /* consent required */}});
- prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
- std::make_unique<base::Value>(false));
- prefs()->SetUserPref(prefs::kPrivacySandboxConsentDecisionMade,
- std::make_unique<base::Value>(false));
-
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/false,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kDialogWaiting, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxV1OffDisabled) {
- base::HistogramTester histogram_tester;
- feature_list()->Reset();
- feature_list()->InitAndEnableFeatureWithParameters(
- privacy_sandbox::kPrivacySandboxSettings3,
- {{"consent-required", "false" /* consent required */}});
- prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
- std::make_unique<base::Value>(true));
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(false));
-
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/false,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kDialogOffV1OffDisabled, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxV1OffEnabled) {
- base::HistogramTester histogram_tester;
- feature_list()->Reset();
- feature_list()->InitAndEnableFeatureWithParameters(
- privacy_sandbox::kPrivacySandboxSettings3,
- {{"consent-required", "false" /* consent required */}});
- prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
- std::make_unique<base::Value>(true));
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(true));
-
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kDialogOffV1OffEnabled, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxRestricted) {
- base::HistogramTester histogram_tester;
- feature_list()->Reset();
- feature_list()->InitAndEnableFeatureWithParameters(
- privacy_sandbox::kPrivacySandboxSettings3,
- {{"consent-required", "false" /* consent required */}});
- prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxRestricted,
- std::make_unique<base::Value>(true));
-
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/false,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kDialogOffRestricted, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxManagedEnabled) {
- base::HistogramTester histogram_tester;
- feature_list()->Reset();
- feature_list()->InitAndEnableFeatureWithParameters(
- privacy_sandbox::kPrivacySandboxSettings3,
- {{"consent-required", "false" /* consent required */}});
- prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxManaged,
- std::make_unique<base::Value>(true));
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(true));
-
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kDialogOffManagedEnabled, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxManagedDisabled) {
- base::HistogramTester histogram_tester;
- feature_list()->Reset();
- feature_list()->InitAndEnableFeatureWithParameters(
- privacy_sandbox::kPrivacySandboxSettings3,
- {{"consent-required", "false" /* consent required */}});
- prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxManaged,
- std::make_unique<base::Value>(true));
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(false));
-
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/false,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kDialogOffManagedDisabled, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandbox3PCOffEnabled) {
- base::HistogramTester histogram_tester;
- feature_list()->Reset();
- feature_list()->InitAndEnableFeatureWithParameters(
- privacy_sandbox::kPrivacySandboxSettings3,
- {{"consent-required", "false" /* consent required */}});
- prefs()->SetUserPref(
- prefs::kPrivacySandboxNoConfirmationThirdPartyCookiesBlocked,
- std::make_unique<base::Value>(true));
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(true));
-
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kDialogOff3PCOffEnabled, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandbox3PCOffDisabled) {
- base::HistogramTester histogram_tester;
- feature_list()->Reset();
- feature_list()->InitAndEnableFeatureWithParameters(
- privacy_sandbox::kPrivacySandboxSettings3,
- {{"consent-required", "false" /* consent required */}});
- prefs()->SetUserPref(
- prefs::kPrivacySandboxNoConfirmationThirdPartyCookiesBlocked,
- std::make_unique<base::Value>(true));
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(false));
-
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/false,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kDialogOff3PCOffDisabled, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxConsentEnabled) {
- base::HistogramTester histogram_tester;
- feature_list()->Reset();
- feature_list()->InitAndEnableFeatureWithParameters(
- privacy_sandbox::kPrivacySandboxSettings3,
- {{"consent-required", "true" /* consent required */}});
- prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
- std::make_unique<base::Value>(false));
- prefs()->SetUserPref(prefs::kPrivacySandboxConsentDecisionMade,
- std::make_unique<base::Value>(true));
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(true));
-
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kConsentShownEnabled, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxConsentDisabled) {
- base::HistogramTester histogram_tester;
- feature_list()->Reset();
- feature_list()->InitAndEnableFeatureWithParameters(
- privacy_sandbox::kPrivacySandboxSettings3,
- {{"consent-required", "true" /* consent required */}});
- prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
- std::make_unique<base::Value>(false));
- prefs()->SetUserPref(prefs::kPrivacySandboxConsentDecisionMade,
- std::make_unique<base::Value>(true));
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(false));
-
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/false,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kConsentShownDisabled, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxNoticeEnabled) {
- base::HistogramTester histogram_tester;
- feature_list()->Reset();
- feature_list()->InitAndEnableFeatureWithParameters(
- privacy_sandbox::kPrivacySandboxSettings3,
- {{"notice-required", "true" /* consent required */}});
- prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
- std::make_unique<base::Value>(false));
- prefs()->SetUserPref(prefs::kPrivacySandboxNoticeDisplayed,
- std::make_unique<base::Value>(true));
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(true));
-
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kNoticeShownEnabled, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxNoticeDisabled) {
- base::HistogramTester histogram_tester;
- feature_list()->Reset();
- feature_list()->InitAndEnableFeatureWithParameters(
- privacy_sandbox::kPrivacySandboxSettings3,
- {{"notice-required", "true" /* consent required */}});
- prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
- std::make_unique<base::Value>(false));
- prefs()->SetUserPref(prefs::kPrivacySandboxNoticeDisplayed,
- std::make_unique<base::Value>(true));
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(false));
-
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/false,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kNoticeShownDisabled, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxManuallyControlledEnabled) {
- base::HistogramTester histogram_tester;
- feature_list()->InitAndEnableFeature(
- privacy_sandbox::kPrivacySandboxSettings3);
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(true));
- prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationManuallyControlled,
- std::make_unique<base::Value>(true));
- privacy_sandbox_service()->LogPrivacySandboxState();
- histogram_tester.ExpectUniqueSample(kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::
- kDialogOffManuallyControlledEnabled,
- 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxManuallyControlledDisabled) {
- base::HistogramTester histogram_tester;
- feature_list()->InitAndEnableFeature(
- privacy_sandbox::kPrivacySandboxSettings3);
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(false));
- prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationManuallyControlled,
- std::make_unique<base::Value>(true));
- privacy_sandbox_service()->LogPrivacySandboxState();
- histogram_tester.ExpectUniqueSample(kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::
- kDialogOffManuallyControlledDisabled,
- 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxNoDialogDisabled) {
- base::HistogramTester histogram_tester;
- feature_list()->InitAndEnableFeature(
- privacy_sandbox::kPrivacySandboxSettings3);
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(false));
- privacy_sandbox_service()->LogPrivacySandboxState();
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kNoDialogRequiredDisabled, 1);
-}
-
-TEST_F(PrivacySandboxServiceTest, PrivacySandboxNoDialogEnabled) {
- base::HistogramTester histogram_tester;
- feature_list()->InitAndEnableFeature(
- privacy_sandbox::kPrivacySandboxSettings3);
- prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
- std::make_unique<base::Value>(true));
- privacy_sandbox_service()->LogPrivacySandboxState();
- histogram_tester.ExpectUniqueSample(
- kPrivacySandboxStartupHistogram,
- PrivacySandboxService::PSStartupStates::kNoDialogRequiredEnabled, 1);
-}
-
TEST_F(PrivacySandboxServiceTest, PromptActionsUMAActions) {
base::UserActionTester user_action_tester;
@@ -1904,10 +1491,11 @@
#endif // BUILDFLAG(IS_CHROMEOS)
class PrivacySandboxPrefInitTest : public PrivacySandboxServiceTest {
- void InitializeBeforeStart() override {
+ void SetUp() override {
feature_list()->InitAndEnableFeatureWithParameters(
privacy_sandbox::kPrivacySandboxSettings3,
{{"setting-default-on", "true"}});
+ PrivacySandboxServiceTest::SetUp();
}
};
@@ -1918,15 +1506,23 @@
}
class PrivacySandboxRestrictedTest : public PrivacySandboxServiceTest {
- void InitializeBeforeStart() override {
+ public:
+ void SetUp() override {
prefs()->SetBoolean(prefs::kPrivacySandboxApisEnabledV2, true);
- mock_delegate()->SetupDefaultResponse(/*restricted=*/true,
- /*confirmed=*/true);
-
// A restriction should override a default on preference.
feature_list()->InitAndEnableFeatureWithParameters(
privacy_sandbox::kPrivacySandboxSettings3,
{{"setting-default-on", "true"}});
+ PrivacySandboxServiceTest::SetUp();
+ }
+
+ std::unique_ptr<privacy_sandbox_test_util::MockPrivacySandboxSettingsDelegate>
+ GetMockDelegate() override {
+ auto mock_delegate = std::make_unique<
+ privacy_sandbox_test_util::MockPrivacySandboxSettingsDelegate>();
+ mock_delegate->SetupDefaultResponse(/*restricted=*/true,
+ /*confirmed=*/false);
+ return mock_delegate;
}
};
@@ -1967,118 +1563,16 @@
EXPECT_THAT(service->GetBlockedTopics(), ElementsAre(topic1, topic3));
}
-class PrivacySandboxServiceTestReconciliationBlocked
- : public PrivacySandboxServiceTest {
- public:
- void InitializeBeforeStart() override {
- // Set the reconciled preference to true here, so when the service is
- // created prior to each test case running, it does not attempt to reconcile
- // the preferences. Tests must call ResetReconciledPref before testing to
- // reset the preference to it's default value.
- profile()->GetTestingPrefService()->SetUserPref(
- prefs::kPrivacySandboxPreferencesReconciled,
- std::make_unique<base::Value>(true));
- mock_delegate()->SetupDefaultResponse(/*restricted=*/false,
- /*confirmed=*/true);
- }
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxDialogNoticeWaiting) {
+ base::HistogramTester histogram_tester;
+ feature_list()->Reset();
+ feature_list()->InitAndEnableFeatureWithParameters(
+ privacy_sandbox::kPrivacySandboxSettings3, {{"notice-required", "true"}});
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
+ std::make_unique<base::Value>(false));
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoticeDisplayed,
+ std::make_unique<base::Value>(false));
- void ResetReconciledPref() {
- profile()->GetTestingPrefService()->SetUserPref(
- prefs::kPrivacySandboxPreferencesReconciled,
- std::make_unique<base::Value>(false));
- }
-};
-
-TEST_F(PrivacySandboxServiceTestReconciliationBlocked, ReconciliationOutcome) {
- // Check that reconciling preferences has the appropriate outcome based on
- // the current user cookie settings.
- ResetReconciledPref();
-
- // Blocking 3P cookies should disable.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
-
- privacy_sandbox_service()->ReconcilePrivacySandboxPref();
-
- EXPECT_FALSE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxApisEnabled));
-
- // Blocking all cookies should disable.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
-
- privacy_sandbox_service()->ReconcilePrivacySandboxPref();
-
- EXPECT_FALSE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxApisEnabled));
-
- // Blocking cookies via content setting exceptions, now matter how broad,
- // should not disable.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/
- {{"[*.]com", "*", ContentSetting::CONTENT_SETTING_BLOCK}},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
-
- privacy_sandbox_service()->ReconcilePrivacySandboxPref();
-
- EXPECT_TRUE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxApisEnabled));
-
- // If the user has already expressed control over the privacy sandbox, it
- // should not be disabled.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- profile()->GetTestingPrefService()->SetUserPref(
- prefs::kPrivacySandboxManuallyControlled,
- std::make_unique<base::Value>(true));
-
- privacy_sandbox_service()->ReconcilePrivacySandboxPref();
-
- EXPECT_TRUE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxApisEnabled));
-
- // Allowing cookies should leave the sandbox enabled.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- profile()->GetTestingPrefService()->SetUserPref(
- prefs::kPrivacySandboxManuallyControlled,
- std::make_unique<base::Value>(true));
-
- privacy_sandbox_service()->ReconcilePrivacySandboxPref();
-
- EXPECT_TRUE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxApisEnabled));
-
- // Reconciliation should not enable the privacy sandbox.
privacy_sandbox_test_util::SetupTestState(
prefs(), host_content_settings_map(),
/*privacy_sandbox_enabled=*/false,
@@ -2087,92 +1581,24 @@
/*user_cookie_exceptions=*/{},
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
- profile()->GetTestingPrefService()->SetUserPref(
- prefs::kPrivacySandboxManuallyControlled,
- std::make_unique<base::Value>(false));
+ CreateService();
- privacy_sandbox_service()->ReconcilePrivacySandboxPref();
-
- EXPECT_FALSE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxApisEnabled));
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kDialogWaiting, 1);
}
-TEST_F(PrivacySandboxServiceTestReconciliationBlocked,
- ImmediateReconciliationNoSync) {
- // Check that if the user is not syncing preferences, reconciliation occurs
- // immediately.
- ResetReconciledPref();
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxDialogConsentWaiting) {
+ base::HistogramTester histogram_tester;
+ feature_list()->Reset();
+ feature_list()->InitAndEnableFeatureWithParameters(
+ privacy_sandbox::kPrivacySandboxSettings3,
+ {{"consent-required", "true" /* consent required */}});
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
+ std::make_unique<base::Value>(false));
+ prefs()->SetUserPref(prefs::kPrivacySandboxConsentDecisionMade,
+ std::make_unique<base::Value>(false));
- auto registered_types =
- sync_service()->GetUserSettings()->GetRegisteredSelectableTypes();
- registered_types.Remove(syncer::UserSelectableType::kPreferences);
- sync_service()->GetUserSettings()->SetSelectedTypes(
- /*sync_everything=*/false, registered_types);
-
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- EXPECT_TRUE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-}
-
-TEST_F(PrivacySandboxServiceTestReconciliationBlocked,
- ImmediateReconciliationSyncComplete) {
- // Check that if sync has completed a cycle that reconciliation occurs
- // immediately.
- ResetReconciledPref();
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
-
- sync_service()->SetNonEmptyLastCycleSnapshot();
-
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- EXPECT_TRUE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-}
-
-TEST_F(PrivacySandboxServiceTestReconciliationBlocked,
- ImmediateReconciliationPersistentSyncError) {
- // Check that if sync has a persistent error that reconciliation occurs
- // immediately.
- ResetReconciledPref();
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
-
- sync_service()->SetDisableReasons(
- syncer::SyncService::DISABLE_REASON_UNRECOVERABLE_ERROR);
-
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- EXPECT_TRUE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-}
-
-TEST_F(PrivacySandboxServiceTestReconciliationBlocked,
- ImmediateReconciliationNoDisable) {
- // Check that if the local settings would not disable the privacy sandbox
- // that reconciliation runs.
- ResetReconciledPref();
privacy_sandbox_test_util::SetupTestState(
prefs(), host_content_settings_map(),
/*privacy_sandbox_enabled=*/false,
@@ -2181,185 +1607,50 @@
/*user_cookie_exceptions=*/{},
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
+ CreateService();
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- EXPECT_TRUE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kDialogWaiting, 1);
}
-TEST_F(PrivacySandboxServiceTestReconciliationBlocked,
- DelayedReconciliationSyncSuccess) {
- // Check that a sync service which has not yet started delays reconciliation
- // until it has completed a sync cycle.
- ResetReconciledPref();
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxV1OffDisabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->Reset();
+ feature_list()->InitAndEnableFeatureWithParameters(
+ privacy_sandbox::kPrivacySandboxSettings3,
+ {{"consent-required", "false" /* consent required */}});
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
+ std::make_unique<base::Value>(true));
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(false));
+
privacy_sandbox_test_util::SetupTestState(
prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
-
- sync_service()->SetEmptyLastCycleSnapshot();
-
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- EXPECT_FALSE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-
- sync_service()->SetNonEmptyLastCycleSnapshot();
- sync_service()->FireSyncCycleCompleted();
-
- EXPECT_TRUE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-}
-
-TEST_F(PrivacySandboxServiceTestReconciliationBlocked,
- DelayedReconciliationSyncFailure) {
- // Check that a sync service which has not yet started delays reconciliation
- // until a persistent error has occurred.
- ResetReconciledPref();
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
-
- sync_service()->SetEmptyLastCycleSnapshot();
-
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- EXPECT_FALSE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-
- // A transient sync startup state should not result in reconciliation.
- sync_service()->SetTransportState(
- syncer::SyncService::TransportState::START_DEFERRED);
- sync_service()->FireStateChanged();
-
- EXPECT_FALSE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-
- // A state update after an unrecoverable error should result in
- // reconciliation.
- sync_service()->SetDisableReasons(
- syncer::SyncService::DISABLE_REASON_UNRECOVERABLE_ERROR);
- sync_service()->FireStateChanged();
-
- EXPECT_TRUE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-}
-
-TEST_F(PrivacySandboxServiceTestReconciliationBlocked,
- DelayedReconciliationIdentityFailure) {
- // Check that a sync service which has not yet started delays reconciliation
- // until a persistent identity error has occurred.
- ResetReconciledPref();
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
-
- sync_service()->SetEmptyLastCycleSnapshot();
-
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- EXPECT_FALSE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-
- // An account becoming available should not result in reconciliation.
- identity_test_env()->MakePrimaryAccountAvailable("[email protected]",
- signin::ConsentLevel::kSync);
-
- EXPECT_FALSE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-
- // A successful update to refresh tokens should not result in reconciliation.
- identity_test_env()->SetRefreshTokenForPrimaryAccount();
-
- EXPECT_FALSE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-
- // A persistent authentication error for a non-primary account should not
- // result in reconciliation.
- auto non_primary_account =
- identity_test_env()->MakeAccountAvailable("[email protected]");
- identity_test_env()->SetRefreshTokenForAccount(
- non_primary_account.account_id);
- identity_test_env()->UpdatePersistentErrorOfRefreshTokenForAccount(
- non_primary_account.account_id,
- GoogleServiceAuthError(
- GoogleServiceAuthError::State::INVALID_GAIA_CREDENTIALS));
-
- EXPECT_FALSE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-
- // A persistent authentication error for the primary account should result
- // in reconciliation.
- identity_test_env()->UpdatePersistentErrorOfRefreshTokenForAccount(
- identity_test_env()->identity_manager()->GetPrimaryAccountId(
- signin::ConsentLevel::kSync),
- GoogleServiceAuthError(
- GoogleServiceAuthError::State::INVALID_GAIA_CREDENTIALS));
-
- EXPECT_TRUE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-}
-
-TEST_F(PrivacySandboxServiceTestReconciliationBlocked,
- DelayedReconciliationSyncIssueThenManaged) {
- // Check that if before an initial sync issue is resolved, the cookie settings
- // are disabled by policy, that reconciliation does not run until the policy
- // is removed.
- ResetReconciledPref();
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
-
- sync_service()->SetEmptyLastCycleSnapshot();
-
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- EXPECT_FALSE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-
- // Apply a management state that is disabling cookies. This should result
- // in the policy service being observed when the sync issue is resolved.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
+ /*privacy_sandbox_enabled=*/false,
/*block_third_party_cookies=*/false,
/*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
/*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
+ /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
+ CreateService();
- EXPECT_CALL(*policy_service(), AddObserver(policy::POLICY_DOMAIN_CHROME,
- privacy_sandbox_service()))
- .Times(1);
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kDialogOffV1OffDisabled, 1);
+}
- sync_service()->SetNonEmptyLastCycleSnapshot();
- sync_service()->FireSyncCycleCompleted();
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxV1OffEnabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->Reset();
+ feature_list()->InitAndEnableFeatureWithParameters(
+ privacy_sandbox::kPrivacySandboxSettings3,
+ {{"consent-required", "false" /* consent required */}});
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
+ std::make_unique<base::Value>(true));
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(true));
- EXPECT_FALSE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-
- // Removing the management state and firing the policy update listener should
- // result in reconciliation running.
privacy_sandbox_test_util::SetupTestState(
prefs(), host_content_settings_map(),
/*privacy_sandbox_enabled=*/true,
@@ -2368,46 +1659,312 @@
/*user_cookie_exceptions=*/{},
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
+ CreateService();
- // The HostContentSettingsMap & PrefService are inspected directly, and not
- // the PolicyMap provided here. The associated browser tests confirm that this
- // is a valid approach.
- privacy_sandbox_service()->OnPolicyUpdated(
- policy::PolicyNamespace(), policy::PolicyMap(), policy::PolicyMap());
-
- EXPECT_TRUE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kDialogOffV1OffEnabled, 1);
}
-TEST_F(PrivacySandboxServiceTestReconciliationBlocked,
- NoReconciliationAlreadyRun) {
- // Reconciliation should not run if it is recorded as already occurring.
- ResetReconciledPref();
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxRestricted) {
+ base::HistogramTester histogram_tester;
+ feature_list()->Reset();
+ feature_list()->InitAndEnableFeatureWithParameters(
+ privacy_sandbox::kPrivacySandboxSettings3,
+ {{"consent-required", "false" /* consent required */}});
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxRestricted,
+ std::make_unique<base::Value>(true));
+
privacy_sandbox_test_util::SetupTestState(
prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
+ /*privacy_sandbox_enabled=*/false,
+ /*block_third_party_cookies=*/false,
+ /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
/*user_cookie_exceptions=*/{},
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
+ CreateService();
- profile()->GetTestingPrefService()->SetUserPref(
- prefs::kPrivacySandboxPreferencesReconciled,
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kDialogOffRestricted, 1);
+}
+
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxManagedEnabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->Reset();
+ feature_list()->InitAndEnableFeatureWithParameters(
+ privacy_sandbox::kPrivacySandboxSettings3,
+ {{"consent-required", "false" /* consent required */}});
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxManaged,
+ std::make_unique<base::Value>(true));
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(true));
+
+ privacy_sandbox_test_util::SetupTestState(
+ prefs(), host_content_settings_map(),
+ /*privacy_sandbox_enabled=*/true,
+ /*block_third_party_cookies=*/false,
+ /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
+ /*user_cookie_exceptions=*/{},
+ /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
+ /*managed_cookie_exceptions=*/{});
+ CreateService();
+
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kDialogOffManagedEnabled, 1);
+}
+
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxManagedDisabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->Reset();
+ feature_list()->InitAndEnableFeatureWithParameters(
+ privacy_sandbox::kPrivacySandboxSettings3,
+ {{"consent-required", "false" /* consent required */}});
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxManaged,
+ std::make_unique<base::Value>(true));
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(false));
+
+ privacy_sandbox_test_util::SetupTestState(
+ prefs(), host_content_settings_map(),
+ /*privacy_sandbox_enabled=*/false,
+ /*block_third_party_cookies=*/false,
+ /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
+ /*user_cookie_exceptions=*/{},
+ /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
+ /*managed_cookie_exceptions=*/{});
+ CreateService();
+
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kDialogOffManagedDisabled, 1);
+}
+
+TEST_F(PrivacySandboxServiceTest, PrivacySandbox3PCOffEnabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->Reset();
+ feature_list()->InitAndEnableFeatureWithParameters(
+ privacy_sandbox::kPrivacySandboxSettings3,
+ {{"consent-required", "false" /* consent required */}});
+ prefs()->SetUserPref(
+ prefs::kPrivacySandboxNoConfirmationThirdPartyCookiesBlocked,
std::make_unique<base::Value>(true));
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(true));
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
+ privacy_sandbox_test_util::SetupTestState(
+ prefs(), host_content_settings_map(),
+ /*privacy_sandbox_enabled=*/true,
+ /*block_third_party_cookies=*/true,
+ /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
+ /*user_cookie_exceptions=*/{},
+ /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
+ /*managed_cookie_exceptions=*/{});
+ CreateService();
- // If run, reconciliation would have disabled the sandbox.
- EXPECT_TRUE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxApisEnabled));
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kDialogOff3PCOffEnabled, 1);
}
-TEST_F(PrivacySandboxServiceTestReconciliationBlocked,
- MetricsLoggingOccursCorrectly) {
+TEST_F(PrivacySandboxServiceTest, PrivacySandbox3PCOffDisabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->Reset();
+ feature_list()->InitAndEnableFeatureWithParameters(
+ privacy_sandbox::kPrivacySandboxSettings3,
+ {{"consent-required", "false" /* consent required */}});
+ prefs()->SetUserPref(
+ prefs::kPrivacySandboxNoConfirmationThirdPartyCookiesBlocked,
+ std::make_unique<base::Value>(true));
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(false));
+
+ privacy_sandbox_test_util::SetupTestState(
+ prefs(), host_content_settings_map(),
+ /*privacy_sandbox_enabled=*/false,
+ /*block_third_party_cookies=*/true,
+ /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
+ /*user_cookie_exceptions=*/{},
+ /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
+ /*managed_cookie_exceptions=*/{});
+ CreateService();
+
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kDialogOff3PCOffDisabled, 1);
+}
+
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxConsentEnabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->Reset();
+ feature_list()->InitAndEnableFeatureWithParameters(
+ privacy_sandbox::kPrivacySandboxSettings3,
+ {{"consent-required", "true" /* consent required */}});
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
+ std::make_unique<base::Value>(false));
+ prefs()->SetUserPref(prefs::kPrivacySandboxConsentDecisionMade,
+ std::make_unique<base::Value>(true));
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(true));
+
+ privacy_sandbox_test_util::SetupTestState(
+ prefs(), host_content_settings_map(),
+ /*privacy_sandbox_enabled=*/true,
+ /*block_third_party_cookies=*/false,
+ /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
+ /*user_cookie_exceptions=*/{},
+ /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
+ /*managed_cookie_exceptions=*/{});
+ CreateService();
+
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kConsentShownEnabled, 1);
+}
+
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxConsentDisabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->Reset();
+ feature_list()->InitAndEnableFeatureWithParameters(
+ privacy_sandbox::kPrivacySandboxSettings3,
+ {{"consent-required", "true" /* consent required */}});
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
+ std::make_unique<base::Value>(false));
+ prefs()->SetUserPref(prefs::kPrivacySandboxConsentDecisionMade,
+ std::make_unique<base::Value>(true));
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(false));
+
+ privacy_sandbox_test_util::SetupTestState(
+ prefs(), host_content_settings_map(),
+ /*privacy_sandbox_enabled=*/false,
+ /*block_third_party_cookies=*/false,
+ /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
+ /*user_cookie_exceptions=*/{},
+ /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
+ /*managed_cookie_exceptions=*/{});
+ CreateService();
+
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kConsentShownDisabled, 1);
+}
+
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxNoticeEnabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->Reset();
+ feature_list()->InitAndEnableFeatureWithParameters(
+ privacy_sandbox::kPrivacySandboxSettings3,
+ {{"notice-required", "true" /* consent required */}});
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
+ std::make_unique<base::Value>(false));
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoticeDisplayed,
+ std::make_unique<base::Value>(true));
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(true));
+
+ privacy_sandbox_test_util::SetupTestState(
+ prefs(), host_content_settings_map(),
+ /*privacy_sandbox_enabled=*/true,
+ /*block_third_party_cookies=*/false,
+ /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
+ /*user_cookie_exceptions=*/{},
+ /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
+ /*managed_cookie_exceptions=*/{});
+ CreateService();
+
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kNoticeShownEnabled, 1);
+}
+
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxNoticeDisabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->Reset();
+ feature_list()->InitAndEnableFeatureWithParameters(
+ privacy_sandbox::kPrivacySandboxSettings3,
+ {{"notice-required", "true" /* consent required */}});
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationSandboxDisabled,
+ std::make_unique<base::Value>(false));
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoticeDisplayed,
+ std::make_unique<base::Value>(true));
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(false));
+
+ privacy_sandbox_test_util::SetupTestState(
+ prefs(), host_content_settings_map(),
+ /*privacy_sandbox_enabled=*/false,
+ /*block_third_party_cookies=*/false,
+ /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
+ /*user_cookie_exceptions=*/{},
+ /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
+ /*managed_cookie_exceptions=*/{});
+ CreateService();
+
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kNoticeShownDisabled, 1);
+}
+
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxManuallyControlledEnabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->InitAndEnableFeature(
+ privacy_sandbox::kPrivacySandboxSettings3);
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(true));
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationManuallyControlled,
+ std::make_unique<base::Value>(true));
+ CreateService();
+ histogram_tester.ExpectUniqueSample(kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::
+ kDialogOffManuallyControlledEnabled,
+ 1);
+}
+
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxManuallyControlledDisabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->InitAndEnableFeature(
+ privacy_sandbox::kPrivacySandboxSettings3);
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(false));
+ prefs()->SetUserPref(prefs::kPrivacySandboxNoConfirmationManuallyControlled,
+ std::make_unique<base::Value>(true));
+ CreateService();
+ histogram_tester.ExpectUniqueSample(kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::
+ kDialogOffManuallyControlledDisabled,
+ 1);
+}
+
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxNoDialogDisabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->InitAndEnableFeature(
+ privacy_sandbox::kPrivacySandboxSettings3);
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(false));
+ CreateService();
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kNoDialogRequiredDisabled, 1);
+}
+
+TEST_F(PrivacySandboxServiceTest, PrivacySandboxNoDialogEnabled) {
+ base::HistogramTester histogram_tester;
+ feature_list()->InitAndEnableFeature(
+ privacy_sandbox::kPrivacySandboxSettings3);
+ prefs()->SetUserPref(prefs::kPrivacySandboxApisEnabledV2,
+ std::make_unique<base::Value>(true));
+ CreateService();
+ histogram_tester.ExpectUniqueSample(
+ kPrivacySandboxStartupHistogram,
+ PrivacySandboxService::PSStartupStates::kNoDialogRequiredEnabled, 1);
+}
+
+TEST_F(PrivacySandboxServiceTest, MetricsLoggingOccursCorrectly) {
base::HistogramTester histograms;
const std::string histogram_name = "Settings.PrivacySandbox.Enabled";
- ResetReconciledPref();
// The histogram should start off empty.
histograms.ExpectTotalCount(histogram_name, 0);
@@ -2426,7 +1983,7 @@
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
+ CreateService();
histograms.ExpectTotalCount(histogram_name, 1);
histograms.ExpectBucketCount(
@@ -2444,7 +2001,7 @@
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
+ CreateService();
histograms.ExpectTotalCount(histogram_name, 2);
histograms.ExpectBucketCount(
@@ -2462,7 +2019,7 @@
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
+ CreateService();
histograms.ExpectTotalCount(histogram_name, 3);
histograms.ExpectBucketCount(
@@ -2471,7 +2028,6 @@
kPSEnabledBlockAll),
1);
- ResetReconciledPref();
privacy_sandbox_test_util::SetupTestState(
prefs(), host_content_settings_map(),
/*privacy_sandbox_enabled=*/false,
@@ -2481,7 +2037,7 @@
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
+ CreateService();
histograms.ExpectTotalCount(histogram_name, 4);
histograms.ExpectBucketCount(
@@ -2490,7 +2046,6 @@
kPSDisabledAllowAll),
1);
- ResetReconciledPref();
privacy_sandbox_test_util::SetupTestState(
prefs(), host_content_settings_map(),
/*privacy_sandbox_enabled=*/false,
@@ -2500,7 +2055,7 @@
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
+ CreateService();
histograms.ExpectTotalCount(histogram_name, 5);
histograms.ExpectBucketCount(
@@ -2509,7 +2064,6 @@
kPSDisabledBlock3P),
1);
- ResetReconciledPref();
privacy_sandbox_test_util::SetupTestState(
prefs(), host_content_settings_map(),
/*privacy_sandbox_enabled=*/false,
@@ -2519,7 +2073,7 @@
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
+ CreateService();
histograms.ExpectTotalCount(histogram_name, 6);
histograms.ExpectBucketCount(
@@ -2528,42 +2082,6 @@
SettingsPrivacySandboxEnabled::kPSDisabledBlockAll),
1);
- // Verify that delayed reconciliation still logs properly.
- ResetReconciledPref();
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
-
- sync_service()->SetEmptyLastCycleSnapshot();
-
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
-
- EXPECT_FALSE(profile()->GetTestingPrefService()->GetBoolean(
- prefs::kPrivacySandboxPreferencesReconciled));
-
- histograms.ExpectTotalCount(histogram_name, 6);
- histograms.ExpectBucketCount(
- histogram_name,
- static_cast<int>(PrivacySandboxService::SettingsPrivacySandboxEnabled::
- kPSDisabledBlockAll),
- 1);
-
- sync_service()->SetNonEmptyLastCycleSnapshot();
- sync_service()->FireSyncCycleCompleted();
-
- histograms.ExpectTotalCount(histogram_name, 7);
- histograms.ExpectBucketCount(
- histogram_name,
- static_cast<int>(PrivacySandboxService::SettingsPrivacySandboxEnabled::
- kPSDisabledBlockAll),
- 2);
-
- ResetReconciledPref();
privacy_sandbox_test_util::SetupTestState(
prefs(), host_content_settings_map(),
/*privacy_sandbox_enabled=*/false,
@@ -2573,9 +2091,9 @@
/*managed_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
/*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
+ CreateService();
- histograms.ExpectTotalCount(histogram_name, 8);
+ histograms.ExpectTotalCount(histogram_name, 7);
histograms.ExpectBucketCount(
histogram_name,
static_cast<int>(PrivacySandboxService::SettingsPrivacySandboxEnabled::
@@ -2583,7 +2101,6 @@
1);
// Disable FLoC and test the buckets that reflect a disabled FLoC state.
- ResetReconciledPref();
profile()->GetTestingPrefService()->SetBoolean(
prefs::kPrivacySandboxFlocEnabled, false);
@@ -2596,9 +2113,9 @@
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
+ CreateService();
- histograms.ExpectTotalCount(histogram_name, 9);
+ histograms.ExpectTotalCount(histogram_name, 8);
histograms.ExpectBucketCount(
histogram_name,
static_cast<int>(PrivacySandboxService::SettingsPrivacySandboxEnabled::
@@ -2614,9 +2131,9 @@
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
+ CreateService();
- histograms.ExpectTotalCount(histogram_name, 10);
+ histograms.ExpectTotalCount(histogram_name, 9);
histograms.ExpectBucketCount(
histogram_name,
static_cast<int>(PrivacySandboxService::SettingsPrivacySandboxEnabled::
@@ -2632,9 +2149,9 @@
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
+ CreateService();
- histograms.ExpectTotalCount(histogram_name, 11);
+ histograms.ExpectTotalCount(histogram_name, 10);
histograms.ExpectBucketCount(
histogram_name,
static_cast<int>(PrivacySandboxService::SettingsPrivacySandboxEnabled::
@@ -2643,7 +2160,7 @@
}
class PrivacySandboxServiceTestNonRegularProfile
- : public PrivacySandboxServiceTestReconciliationBlocked {
+ : public PrivacySandboxServiceTest {
profile_metrics::BrowserProfileType GetProfileType() override {
return profile_metrics::BrowserProfileType::kSystem;
}
@@ -2653,7 +2170,6 @@
// Check that non-regular profiles do not record metrics.
base::HistogramTester histograms;
const std::string histogram_name = "Settings.PrivacySandbox.Enabled";
- ResetReconciledPref();
privacy_sandbox_test_util::SetupTestState(
prefs(), host_content_settings_map(),
@@ -2664,13 +2180,14 @@
/*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
/*managed_cookie_exceptions=*/{});
- privacy_sandbox_service()->MaybeReconcilePrivacySandboxPref();
+ CreateService();
// The histogram should remain empty.
histograms.ExpectTotalCount(histogram_name, 0);
}
TEST_F(PrivacySandboxServiceTestNonRegularProfile, NoDialogRequired) {
+ CreateService();
// Non-regular profiles should never have a prompt shown.
SetupDialogTestState(feature_list(), prefs(),
{/*consent_required=*/true,