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

Side by Side Diff: chrome/browser/metrics/variations/variations_service_unittest.cc

Issue 1320503005: Revert of Turn VariationsService::GetVariationsServerURL into instance method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/metrics/variations/variations_service.h" 5 #include "chrome/browser/metrics/variations/variations_service.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/json/json_string_value_serializer.h" 10 #include "base/json/json_string_value_serializer.h"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 DISALLOW_COPY_AND_ASSIGN(VariationsServiceTest); 257 DISALLOW_COPY_AND_ASSIGN(VariationsServiceTest);
258 }; 258 };
259 259
260 TEST_F(VariationsServiceTest, GetVariationsServerURL) { 260 TEST_F(VariationsServiceTest, GetVariationsServerURL) {
261 TestVariationsPrefsStore prefs_store; 261 TestVariationsPrefsStore prefs_store;
262 PrefService* prefs = prefs_store.prefs(); 262 PrefService* prefs = prefs_store.prefs();
263 const std::string default_variations_url = 263 const std::string default_variations_url =
264 VariationsService::GetDefaultVariationsServerURLForTesting(); 264 VariationsService::GetDefaultVariationsServerURLForTesting();
265 265
266 std::string value; 266 std::string value;
267 TestVariationsService service( 267 GURL url = VariationsService::GetVariationsServerURL(prefs, std::string());
268 new web_resource::TestRequestAllowedNotifier(prefs), prefs);
269 GURL url = service.GetVariationsServerURL(prefs, std::string());
270 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url, 268 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url,
271 base::CompareCase::SENSITIVE)); 269 base::CompareCase::SENSITIVE));
272 EXPECT_FALSE(net::GetValueForKeyInQuery(url, "restrict", &value)); 270 EXPECT_FALSE(net::GetValueForKeyInQuery(url, "restrict", &value));
273 271
274 prefs_store.SetVariationsRestrictParameterPolicyValue("restricted"); 272 prefs_store.SetVariationsRestrictParameterPolicyValue("restricted");
275 url = service.GetVariationsServerURL(prefs, std::string()); 273 url = VariationsService::GetVariationsServerURL(prefs, std::string());
276 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url, 274 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url,
277 base::CompareCase::SENSITIVE)); 275 base::CompareCase::SENSITIVE));
278 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); 276 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value));
279 EXPECT_EQ("restricted", value); 277 EXPECT_EQ("restricted", value);
280 278
281 // The override value should take precedence over what's in prefs. 279 // The override value should take precedence over what's in prefs.
282 url = service.GetVariationsServerURL(prefs, "override"); 280 url = VariationsService::GetVariationsServerURL(prefs, "override");
283 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url, 281 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url,
284 base::CompareCase::SENSITIVE)); 282 base::CompareCase::SENSITIVE));
285 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); 283 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value));
286 EXPECT_EQ("override", value); 284 EXPECT_EQ("override", value);
287 } 285 }
288 286
289 TEST_F(VariationsServiceTest, VariationsURLHasOSNameParam) { 287 TEST_F(VariationsServiceTest, VariationsURLHasOSNameParam) {
290 TestingPrefServiceSimple prefs; 288 TestingPrefServiceSimple prefs;
291 VariationsService::RegisterPrefs(prefs.registry()); 289 VariationsService::RegisterPrefs(prefs.registry());
292 TestVariationsService service( 290 const GURL url =
293 new web_resource::TestRequestAllowedNotifier(&prefs), &prefs); 291 VariationsService::GetVariationsServerURL(&prefs, std::string());
294 const GURL url = service.GetVariationsServerURL(&prefs, std::string());
295 292
296 std::string value; 293 std::string value;
297 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "osname", &value)); 294 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "osname", &value));
298 EXPECT_FALSE(value.empty()); 295 EXPECT_FALSE(value.empty());
299 } 296 }
300 297
301 TEST_F(VariationsServiceTest, RequestsInitiallyNotAllowed) { 298 TEST_F(VariationsServiceTest, RequestsInitiallyNotAllowed) {
302 TestingPrefServiceSimple prefs; 299 TestingPrefServiceSimple prefs;
303 VariationsService::RegisterPrefs(prefs.registry()); 300 VariationsService::RegisterPrefs(prefs.registry());
304 301
(...skipping 27 matching lines...) Expand all
332 EXPECT_TRUE(test_service.fetch_attempted()); 329 EXPECT_TRUE(test_service.fetch_attempted());
333 } 330 }
334 331
335 TEST_F(VariationsServiceTest, SeedStoredWhenOKStatus) { 332 TEST_F(VariationsServiceTest, SeedStoredWhenOKStatus) {
336 TestingPrefServiceSimple prefs; 333 TestingPrefServiceSimple prefs;
337 VariationsService::RegisterPrefs(prefs.registry()); 334 VariationsService::RegisterPrefs(prefs.registry());
338 335
339 TestVariationsService service( 336 TestVariationsService service(
340 new web_resource::TestRequestAllowedNotifier(&prefs), &prefs); 337 new web_resource::TestRequestAllowedNotifier(&prefs), &prefs);
341 service.variations_server_url_ = 338 service.variations_server_url_ =
342 service.GetVariationsServerURL(&prefs, std::string()); 339 VariationsService::GetVariationsServerURL(&prefs, std::string());
343 service.set_intercepts_fetch(false); 340 service.set_intercepts_fetch(false);
344 341
345 net::TestURLFetcherFactory factory; 342 net::TestURLFetcherFactory factory;
346 service.DoActualFetch(); 343 service.DoActualFetch();
347 344
348 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); 345 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
349 SimulateServerResponse(net::HTTP_OK, fetcher); 346 SimulateServerResponse(net::HTTP_OK, fetcher);
350 fetcher->SetResponseString(SerializeSeed(CreateTestSeed())); 347 fetcher->SetResponseString(SerializeSeed(CreateTestSeed()));
351 348
352 EXPECT_FALSE(service.seed_stored()); 349 EXPECT_FALSE(service.seed_stored());
(...skipping 10 matching lines...) Expand all
363 net::HTTP_SERVICE_UNAVAILABLE, 360 net::HTTP_SERVICE_UNAVAILABLE,
364 }; 361 };
365 362
366 TestingPrefServiceSimple prefs; 363 TestingPrefServiceSimple prefs;
367 VariationsService::RegisterPrefs(prefs.registry()); 364 VariationsService::RegisterPrefs(prefs.registry());
368 365
369 VariationsService service( 366 VariationsService service(
370 make_scoped_ptr(new ChromeVariationsServiceClient()), 367 make_scoped_ptr(new ChromeVariationsServiceClient()),
371 new web_resource::TestRequestAllowedNotifier(&prefs), &prefs, NULL); 368 new web_resource::TestRequestAllowedNotifier(&prefs), &prefs, NULL);
372 service.variations_server_url_ = 369 service.variations_server_url_ =
373 service.GetVariationsServerURL(&prefs, std::string()); 370 VariationsService::GetVariationsServerURL(&prefs, std::string());
374 for (size_t i = 0; i < arraysize(non_ok_status_codes); ++i) { 371 for (size_t i = 0; i < arraysize(non_ok_status_codes); ++i) {
375 net::TestURLFetcherFactory factory; 372 net::TestURLFetcherFactory factory;
376 service.DoActualFetch(); 373 service.DoActualFetch();
377 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); 374 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue());
378 375
379 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); 376 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
380 SimulateServerResponse(non_ok_status_codes[i], fetcher); 377 SimulateServerResponse(non_ok_status_codes[i], fetcher);
381 service.OnURLFetchComplete(fetcher); 378 service.OnURLFetchComplete(fetcher);
382 379
383 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); 380 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue());
384 } 381 }
385 } 382 }
386 383
387 TEST_F(VariationsServiceTest, CountryHeader) { 384 TEST_F(VariationsServiceTest, CountryHeader) {
388 TestingPrefServiceSimple prefs; 385 TestingPrefServiceSimple prefs;
389 VariationsService::RegisterPrefs(prefs.registry()); 386 VariationsService::RegisterPrefs(prefs.registry());
390 387
391 TestVariationsService service( 388 TestVariationsService service(
392 new web_resource::TestRequestAllowedNotifier(&prefs), &prefs); 389 new web_resource::TestRequestAllowedNotifier(&prefs), &prefs);
393 service.variations_server_url_ = 390 service.variations_server_url_ =
394 service.GetVariationsServerURL(&prefs, std::string()); 391 VariationsService::GetVariationsServerURL(&prefs, std::string());
395 service.set_intercepts_fetch(false); 392 service.set_intercepts_fetch(false);
396 393
397 net::TestURLFetcherFactory factory; 394 net::TestURLFetcherFactory factory;
398 service.DoActualFetch(); 395 service.DoActualFetch();
399 396
400 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); 397 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
401 scoped_refptr<net::HttpResponseHeaders> headers = 398 scoped_refptr<net::HttpResponseHeaders> headers =
402 SimulateServerResponse(net::HTTP_OK, fetcher); 399 SimulateServerResponse(net::HTTP_OK, fetcher);
403 headers->AddHeader("X-Country: test"); 400 headers->AddHeader("X-Country: test");
404 fetcher->SetResponseString(SerializeSeed(CreateTestSeed())); 401 fetcher->SetResponseString(SerializeSeed(CreateTestSeed()));
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 << test.pref_value_before << ", " << test.version << ", " 547 << test.pref_value_before << ", " << test.version << ", "
551 << test.latest_country_code; 548 << test.latest_country_code;
552 549
553 histogram_tester.ExpectUniqueSample( 550 histogram_tester.ExpectUniqueSample(
554 "Variations.LoadPermanentConsistencyCountryResult", 551 "Variations.LoadPermanentConsistencyCountryResult",
555 test.expected_result, 1); 552 test.expected_result, 1);
556 } 553 }
557 } 554 }
558 555
559 } // namespace chrome_variations 556 } // namespace chrome_variations
OLDNEW
« 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