Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5768)

Unified Diff: chrome/browser/metrics/variations/variations_service_unittest.cc

Issue 1313213005: Turn VariationsService::GetVariationsServerURL into instance method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 dee8dfa45d87c21d84c55fcc8449f62012fe7556..8a8524301c00239d31aeda5dd78f59ee0c2e7ad0 100644
--- a/chrome/browser/metrics/variations/variations_service_unittest.cc
+++ b/chrome/browser/metrics/variations/variations_service_unittest.cc
@@ -43,10 +43,11 @@ namespace {
// A test class used to validate expected functionality in VariationsService.
class TestVariationsService : public VariationsService {
public:
- TestVariationsService(web_resource::TestRequestAllowedNotifier* test_notifier,
- PrefService* local_state)
+ TestVariationsService(
+ scoped_ptr<web_resource::TestRequestAllowedNotifier> test_notifier,
+ PrefService* local_state)
: VariationsService(make_scoped_ptr(new ChromeVariationsServiceClient()),
- test_notifier,
+ test_notifier.Pass(),
local_state,
NULL),
intercepts_fetch_(true),
@@ -264,20 +265,23 @@ TEST_F(VariationsServiceTest, GetVariationsServerURL) {
VariationsService::GetDefaultVariationsServerURLForTesting();
std::string value;
- GURL url = VariationsService::GetVariationsServerURL(prefs, std::string());
+ TestVariationsService service(
+ make_scoped_ptr(new web_resource::TestRequestAllowedNotifier(prefs)),
+ prefs);
+ GURL url = service.GetVariationsServerURL(prefs, std::string());
EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url,
base::CompareCase::SENSITIVE));
EXPECT_FALSE(net::GetValueForKeyInQuery(url, "restrict", &value));
prefs_store.SetVariationsRestrictParameterPolicyValue("restricted");
- url = VariationsService::GetVariationsServerURL(prefs, std::string());
+ url = service.GetVariationsServerURL(prefs, std::string());
EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url,
base::CompareCase::SENSITIVE));
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");
+ url = service.GetVariationsServerURL(prefs, "override");
EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url,
base::CompareCase::SENSITIVE));
EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value));
@@ -287,8 +291,10 @@ TEST_F(VariationsServiceTest, GetVariationsServerURL) {
TEST_F(VariationsServiceTest, VariationsURLHasOSNameParam) {
TestingPrefServiceSimple prefs;
VariationsService::RegisterPrefs(prefs.registry());
- const GURL url =
- VariationsService::GetVariationsServerURL(&prefs, std::string());
+ TestVariationsService service(
+ make_scoped_ptr(new web_resource::TestRequestAllowedNotifier(&prefs)),
+ &prefs);
+ const GURL url = service.GetVariationsServerURL(&prefs, std::string());
std::string value;
EXPECT_TRUE(net::GetValueForKeyInQuery(url, "osname", &value));
@@ -301,16 +307,17 @@ TEST_F(VariationsServiceTest, RequestsInitiallyNotAllowed) {
// Pass ownership to TestVariationsService, but keep a weak pointer to
// manipulate it for this test.
- web_resource::TestRequestAllowedNotifier* test_notifier =
- new web_resource::TestRequestAllowedNotifier(&prefs);
- TestVariationsService test_service(test_notifier, &prefs);
+ scoped_ptr<web_resource::TestRequestAllowedNotifier> test_notifier =
+ make_scoped_ptr(new web_resource::TestRequestAllowedNotifier(&prefs));
+ web_resource::TestRequestAllowedNotifier* raw_notifier = test_notifier.get();
+ TestVariationsService test_service(test_notifier.Pass(), &prefs);
// Force the notifier to initially disallow requests.
- test_notifier->SetRequestsAllowedOverride(false);
+ raw_notifier->SetRequestsAllowedOverride(false);
test_service.StartRepeatedVariationsSeedFetch();
EXPECT_FALSE(test_service.fetch_attempted());
- test_notifier->NotifyObserver();
+ raw_notifier->NotifyObserver();
EXPECT_TRUE(test_service.fetch_attempted());
}
@@ -320,11 +327,12 @@ TEST_F(VariationsServiceTest, RequestsInitiallyAllowed) {
// Pass ownership to TestVariationsService, but keep a weak pointer to
// manipulate it for this test.
- web_resource::TestRequestAllowedNotifier* test_notifier =
- new web_resource::TestRequestAllowedNotifier(&prefs);
- TestVariationsService test_service(test_notifier, &prefs);
+ scoped_ptr<web_resource::TestRequestAllowedNotifier> test_notifier =
+ make_scoped_ptr(new web_resource::TestRequestAllowedNotifier(&prefs));
+ web_resource::TestRequestAllowedNotifier* raw_notifier = test_notifier.get();
+ TestVariationsService test_service(test_notifier.Pass(), &prefs);
- test_notifier->SetRequestsAllowedOverride(true);
+ raw_notifier->SetRequestsAllowedOverride(true);
test_service.StartRepeatedVariationsSeedFetch();
EXPECT_TRUE(test_service.fetch_attempted());
}
@@ -334,9 +342,10 @@ TEST_F(VariationsServiceTest, SeedStoredWhenOKStatus) {
VariationsService::RegisterPrefs(prefs.registry());
TestVariationsService service(
- new web_resource::TestRequestAllowedNotifier(&prefs), &prefs);
+ make_scoped_ptr(new web_resource::TestRequestAllowedNotifier(&prefs)),
+ &prefs);
service.variations_server_url_ =
- VariationsService::GetVariationsServerURL(&prefs, std::string());
+ service.GetVariationsServerURL(&prefs, std::string());
service.set_intercepts_fetch(false);
net::TestURLFetcherFactory factory;
@@ -365,9 +374,10 @@ TEST_F(VariationsServiceTest, SeedNotStoredWhenNonOKStatus) {
VariationsService service(
make_scoped_ptr(new ChromeVariationsServiceClient()),
- new web_resource::TestRequestAllowedNotifier(&prefs), &prefs, NULL);
+ make_scoped_ptr(new web_resource::TestRequestAllowedNotifier(&prefs)),
+ &prefs, NULL);
service.variations_server_url_ =
- VariationsService::GetVariationsServerURL(&prefs, std::string());
+ service.GetVariationsServerURL(&prefs, std::string());
for (size_t i = 0; i < arraysize(non_ok_status_codes); ++i) {
net::TestURLFetcherFactory factory;
service.DoActualFetch();
@@ -386,9 +396,10 @@ TEST_F(VariationsServiceTest, CountryHeader) {
VariationsService::RegisterPrefs(prefs.registry());
TestVariationsService service(
- new web_resource::TestRequestAllowedNotifier(&prefs), &prefs);
+ make_scoped_ptr(new web_resource::TestRequestAllowedNotifier(&prefs)),
+ &prefs);
service.variations_server_url_ =
- VariationsService::GetVariationsServerURL(&prefs, std::string());
+ service.GetVariationsServerURL(&prefs, std::string());
service.set_intercepts_fetch(false);
net::TestURLFetcherFactory factory;
@@ -411,7 +422,8 @@ TEST_F(VariationsServiceTest, Observer) {
VariationsService::RegisterPrefs(prefs.registry());
VariationsService service(
make_scoped_ptr(new ChromeVariationsServiceClient()),
- new web_resource::TestRequestAllowedNotifier(&prefs), &prefs, NULL);
+ make_scoped_ptr(new web_resource::TestRequestAllowedNotifier(&prefs)),
+ &prefs, NULL);
struct {
int normal_count;
@@ -510,7 +522,8 @@ TEST_F(VariationsServiceTest, LoadPermanentConsistencyCountry) {
VariationsService::RegisterPrefs(prefs.registry());
VariationsService service(
make_scoped_ptr(new ChromeVariationsServiceClient()),
- new web_resource::TestRequestAllowedNotifier(&prefs), &prefs, NULL);
+ make_scoped_ptr(new web_resource::TestRequestAllowedNotifier(&prefs)),
+ &prefs, NULL);
if (test.pref_value_before) {
base::ListValue list_value;
« no previous file with comments | « chrome/browser/metrics/variations/variations_service.cc ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698