| Index: chrome/browser/metrics/variations/variations_service_unittest.cc
|
| diff --git a/chrome/browser/metrics/variations/variations_service_unittest.cc b/chrome/browser/metrics/variations/variations_service_unittest.cc
|
| index c7df80946ed2296ef96ee20a70eb3fd2bb0e64ba..6f67e9cd0e1923b10e6d88e3a066cca96c2d34cf 100644
|
| --- a/chrome/browser/metrics/variations/variations_service_unittest.cc
|
| +++ b/chrome/browser/metrics/variations/variations_service_unittest.cc
|
| @@ -151,106 +151,114 @@ void SimulateServerResponse(int response_code, net::TestURLFetcher* fetcher) {
|
| fetcher->set_response_code(response_code);
|
| }
|
|
|
| -} // namespace
|
| -
|
| -class VariationsServiceTest : public ::testing::Test {
|
| - protected:
|
| - VariationsServiceTest() {}
|
| -
|
| - private:
|
| -#if defined(OS_CHROMEOS)
|
| - // Not used directly. Initializes CrosSettings for testing.
|
| - chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
|
| - chromeos::ScopedTestCrosSettings test_cros_settings_;
|
| -#endif
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(VariationsServiceTest);
|
| -};
|
| -
|
| -#if !defined(OS_CHROMEOS)
|
| -TEST_F(VariationsServiceTest, VariationsURLIsValid) {
|
| +// Helper class that abstracts away platform-specific details relating to the
|
| +// pref store used for the "restrict" param policy.
|
| +class TestVariationsPrefsStore {
|
| + public:
|
| + TestVariationsPrefsStore() {
|
| #if defined(OS_ANDROID)
|
| - // Android uses profile prefs as the PrefService to generate the URL.
|
| - TestingPrefServiceSyncable prefs;
|
| - VariationsService::RegisterProfilePrefs(prefs.registry());
|
| + // Android uses profile prefs as the PrefService to generate the URL.
|
| + VariationsService::RegisterProfilePrefs(prefs_.registry());
|
| #else
|
| - TestingPrefServiceSimple prefs;
|
| - VariationsService::RegisterPrefs(prefs.registry());
|
| + VariationsService::RegisterPrefs(prefs_.registry());
|
| #endif
|
| - const std::string default_variations_url =
|
| - VariationsService::GetDefaultVariationsServerURLForTesting();
|
|
|
| - std::string value;
|
| - GURL url = VariationsService::GetVariationsServerURL(&prefs);
|
| - EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true));
|
| - EXPECT_FALSE(net::GetValueForKeyInQuery(url, "restrict", &value));
|
| -
|
| - prefs.SetString(prefs::kVariationsRestrictParameter, "restricted");
|
| - url = VariationsService::GetVariationsServerURL(&prefs);
|
| - EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true));
|
| - EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value));
|
| - EXPECT_EQ("restricted", value);
|
| -}
|
| -#else
|
| -class VariationsServiceTestChromeOS : public VariationsServiceTest {
|
| - protected:
|
| - VariationsServiceTestChromeOS() {}
|
| -
|
| - void SetUp() override {
|
| +#if defined(OS_CHROMEOS)
|
| cros_settings_ = chromeos::CrosSettings::Get();
|
| DCHECK(cros_settings_ != NULL);
|
| // Remove the real DeviceSettingsProvider and replace it with a stub that
|
| // allows modifications in a test.
|
| + // TODO(asvitkine): Make a scoped helper class for this operation.
|
| device_settings_provider_ = cros_settings_->GetProvider(
|
| chromeos::kReportDeviceVersionInfo);
|
| EXPECT_TRUE(device_settings_provider_ != NULL);
|
| EXPECT_TRUE(cros_settings_->RemoveSettingsProvider(
|
| device_settings_provider_));
|
| cros_settings_->AddSettingsProvider(&stub_settings_provider_);
|
| +#endif
|
| }
|
|
|
| - void TearDown() override {
|
| + ~TestVariationsPrefsStore() {
|
| +#if defined(OS_CHROMEOS)
|
| // Restore the real DeviceSettingsProvider.
|
| EXPECT_TRUE(
|
| cros_settings_->RemoveSettingsProvider(&stub_settings_provider_));
|
| cros_settings_->AddSettingsProvider(device_settings_provider_);
|
| +#endif
|
| }
|
|
|
| - void SetVariationsRestrictParameterPolicyValue(std::string value) {
|
| + void SetVariationsRestrictParameterPolicyValue(const std::string& value) {
|
| +#if defined(OS_CHROMEOS)
|
| cros_settings_->SetString(chromeos::kVariationsRestrictParameter, value);
|
| +#else
|
| + prefs_.SetString(prefs::kVariationsRestrictParameter, value);
|
| +#endif
|
| }
|
|
|
| + PrefService* prefs() { return &prefs_; }
|
| +
|
| private:
|
| +#if defined(OS_ANDROID)
|
| + // Android uses profile prefs as the PrefService to generate the URL.
|
| + TestingPrefServiceSyncable prefs_;
|
| +#else
|
| + TestingPrefServiceSimple prefs_;
|
| +#endif
|
| +
|
| +#if defined(OS_CHROMEOS)
|
| chromeos::CrosSettings* cros_settings_;
|
| chromeos::StubCrosSettingsProvider stub_settings_provider_;
|
| chromeos::CrosSettingsProvider* device_settings_provider_;
|
| +#endif
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(VariationsServiceTestChromeOS);
|
| + DISALLOW_COPY_AND_ASSIGN(TestVariationsPrefsStore);
|
| };
|
|
|
| -TEST_F(VariationsServiceTestChromeOS, VariationsURLIsValid) {
|
| - TestingPrefServiceSimple prefs;
|
| - VariationsService::RegisterPrefs(prefs.registry());
|
| +} // namespace
|
| +
|
| +class VariationsServiceTest : public ::testing::Test {
|
| + protected:
|
| + VariationsServiceTest() {}
|
| +
|
| + private:
|
| +#if defined(OS_CHROMEOS)
|
| + // Not used directly. Initializes CrosSettings for testing.
|
| + chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
|
| + chromeos::ScopedTestCrosSettings test_cros_settings_;
|
| +#endif
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(VariationsServiceTest);
|
| +};
|
| +
|
| +TEST_F(VariationsServiceTest, GetVariationsServerURL) {
|
| + TestVariationsPrefsStore prefs_store;
|
| + PrefService* prefs = prefs_store.prefs();
|
| const std::string default_variations_url =
|
| VariationsService::GetDefaultVariationsServerURLForTesting();
|
|
|
| std::string value;
|
| - GURL url = VariationsService::GetVariationsServerURL(&prefs);
|
| + GURL url = VariationsService::GetVariationsServerURL(prefs, std::string());
|
| EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true));
|
| EXPECT_FALSE(net::GetValueForKeyInQuery(url, "restrict", &value));
|
|
|
| - SetVariationsRestrictParameterPolicyValue("restricted");
|
| - url = VariationsService::GetVariationsServerURL(&prefs);
|
| + prefs_store.SetVariationsRestrictParameterPolicyValue("restricted");
|
| + url = VariationsService::GetVariationsServerURL(prefs, std::string());
|
| EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true));
|
| EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value));
|
| EXPECT_EQ("restricted", value);
|
| +
|
| + // The override value should take precedence over what's in prefs.
|
| + url = VariationsService::GetVariationsServerURL(prefs, "override");
|
| + EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true));
|
| + EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value));
|
| + EXPECT_EQ("override", value);
|
| }
|
| -#endif
|
|
|
| TEST_F(VariationsServiceTest, VariationsURLHasOSNameParam) {
|
| TestingPrefServiceSimple prefs;
|
| VariationsService::RegisterPrefs(prefs.registry());
|
| - const GURL url = VariationsService::GetVariationsServerURL(&prefs);
|
| + const GURL url =
|
| + VariationsService::GetVariationsServerURL(&prefs, std::string());
|
|
|
| std::string value;
|
| EXPECT_TRUE(net::GetValueForKeyInQuery(url, "osname", &value));
|
| @@ -306,8 +314,8 @@ TEST_F(VariationsServiceTest, SeedStoredWhenOKStatus) {
|
|
|
| TestVariationsService service(
|
| new web_resource::TestRequestAllowedNotifier(&prefs), &prefs);
|
| - const GURL url = VariationsService::GetVariationsServerURL(&prefs);
|
| - service.variations_server_url_ = url;
|
| + service.variations_server_url_ =
|
| + VariationsService::GetVariationsServerURL(&prefs, std::string());
|
| service.set_intercepts_fetch(false);
|
|
|
| net::TestURLFetcherFactory factory;
|
| @@ -339,8 +347,8 @@ TEST_F(VariationsServiceTest, SeedNotStoredWhenNonOKStatus) {
|
|
|
| VariationsService service(
|
| new web_resource::TestRequestAllowedNotifier(&prefs), &prefs, NULL);
|
| - const GURL url = VariationsService::GetVariationsServerURL(&prefs);
|
| - service.variations_server_url_ = url;
|
| + service.variations_server_url_ =
|
| + VariationsService::GetVariationsServerURL(&prefs, std::string());
|
| for (size_t i = 0; i < arraysize(non_ok_status_codes); ++i) {
|
| net::TestURLFetcherFactory factory;
|
| service.DoActualFetch();
|
| @@ -364,8 +372,8 @@ TEST_F(VariationsServiceTest, SeedDateUpdatedOn304Status) {
|
| net::TestURLFetcherFactory factory;
|
| VariationsService service(
|
| new web_resource::TestRequestAllowedNotifier(&prefs), &prefs, NULL);
|
| - const GURL url = VariationsService::GetVariationsServerURL(&prefs);
|
| - service.variations_server_url_ = url;
|
| + service.variations_server_url_ =
|
| + VariationsService::GetVariationsServerURL(&prefs, std::string());
|
| service.DoActualFetch();
|
| EXPECT_TRUE(
|
| prefs.FindPreference(prefs::kVariationsSeedDate)->IsDefaultValue());
|
|
|