#include "chrome/browser/safe_browsing/chrome_user_population_helper.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial.h"
#include "base/strings/strcat.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager_factory.h"
#include "chrome/browser/safe_browsing/verdict_cache_manager_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/test/base/testing_profile.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/core/browser/verdict_cache_manager.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "components/sync/base/data_type.h"
#include "components/sync/test/test_sync_service.h"
#include "components/unified_consent/pref_names.h"
#include "components/version_info/version_info.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/protobuf/src/google/protobuf/repeated_ptr_field.h"
namespace safe_browsing {
namespace {
std::unique_ptr<KeyedService> CreateTestSyncService(
content::BrowserContext* context) { … }
}
TEST(GetUserPopulationForProfileTest, PopulatesPopulation) { … }
TEST(GetUserPopulationForProfileTest, PopulatesMBB) { … }
TEST(GetUserPopulationForProfileTest, PopulatesIncognito) { … }
TEST(GetUserPopulationForProfileTest, PopulatesSync) { … }
TEST(GetUserPopulationForProfileTest, PopulatesSignedIn) { … }
#if BUILDFLAG(FULL_SAFE_BROWSING)
TEST(GetUserPopulationForProfileTest, PopulatesAdvancedProtection) { … }
#endif
TEST(GetUserPopulationForProfileTest, PopulatesUserAgent) { … }
TEST(GetPageLoadTokenForURLTest, PopulatesEmptyTokenForEmptyProfile) { … }
TEST(GetPageLoadTokenForURLTest, PopulatesNewTokenValueForURL) { … }
TEST(GetPageLoadTokenForURLTest, PopulatesExistingTokenValueForURL) { … }
#if BUILDFLAG(IS_WIN)
TEST(GetUserPopulationForProfileWithCookieTheftExperiments,
PopulatesExperimentsForEsb) {
content::BrowserTaskEnvironment task_environment;
base::FieldTrialList::CreateFieldTrial("LockProfileCookieDatabase",
"Enabled");
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitFromCommandLine(
"LockProfileCookieDatabase<LockProfileCookieDatabase.Enabled", "");
TestingProfile profile;
SetSafeBrowsingState(profile.GetPrefs(),
SafeBrowsingState::ENHANCED_PROTECTION);
ChromeUserPopulation population =
GetUserPopulationForProfileWithCookieTheftExperiments(&profile);
EXPECT_TRUE(base::Contains(population.finch_active_groups(),
"LockProfileCookieDatabase.Enabled"));
}
TEST(GetUserPopulationForProfileWithCookieTheftExperiments,
DoesNotPopulateExperimentsForSsb) {
content::BrowserTaskEnvironment task_environment;
base::FieldTrialList::CreateFieldTrial("LockProfileCookieDatabase",
"Enabled");
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitFromCommandLine(
"LockProfileCookieDatabase<LockProfileCookieDatabase.Enabled", "");
TestingProfile profile;
SetSafeBrowsingState(profile.GetPrefs(),
SafeBrowsingState::STANDARD_PROTECTION);
ChromeUserPopulation population =
GetUserPopulationForProfileWithCookieTheftExperiments(&profile);
EXPECT_FALSE(base::Contains(population.finch_active_groups(),
"LockProfileCookieDatabase.Enabled"));
}
#endif
}