OLD | NEW |
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 "components/variations/service/variations_service.h" | 5 #include "components/variations/service/variations_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 TEST_F(VariationsServiceTest, CreateTrialsFromSeed) { | 271 TEST_F(VariationsServiceTest, CreateTrialsFromSeed) { |
272 TestingPrefServiceSimple prefs; | 272 TestingPrefServiceSimple prefs; |
273 VariationsService::RegisterPrefs(prefs.registry()); | 273 VariationsService::RegisterPrefs(prefs.registry()); |
274 | 274 |
275 // Create a local base::FieldTrialList, to hold the field trials created in | 275 // Create a local base::FieldTrialList, to hold the field trials created in |
276 // this test. | 276 // this test. |
277 base::FieldTrialList field_trial_list(nullptr); | 277 base::FieldTrialList field_trial_list(nullptr); |
278 | 278 |
279 // Create a variations service. | 279 // Create a variations service. |
280 TestVariationsService service( | 280 TestVariationsService service( |
281 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 281 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs), |
282 &prefs); | 282 &prefs); |
283 service.SetCreateTrialsFromSeedCalledForTesting(false); | 283 service.SetCreateTrialsFromSeedCalledForTesting(false); |
284 | 284 |
285 // Store a seed. | 285 // Store a seed. |
286 service.StoreSeed(SerializeSeed(CreateTestSeed()), std::string(), | 286 service.StoreSeed(SerializeSeed(CreateTestSeed()), std::string(), |
287 std::string(), base::Time::Now(), false, false); | 287 std::string(), base::Time::Now(), false, false); |
288 prefs.SetInt64(prefs::kVariationsLastFetchTime, | 288 prefs.SetInt64(prefs::kVariationsLastFetchTime, |
289 base::Time::Now().ToInternalValue()); | 289 base::Time::Now().ToInternalValue()); |
290 | 290 |
291 // Check that field trials are created from the seed. Since the test study has | 291 // Check that field trials are created from the seed. Since the test study has |
292 // only 1 experiment with 100% probability weight, we must be part of it. | 292 // only 1 experiment with 100% probability weight, we must be part of it. |
293 EXPECT_TRUE(service.CreateTrialsFromSeed(base::FeatureList::GetInstance())); | 293 EXPECT_TRUE(service.CreateTrialsFromSeed(base::FeatureList::GetInstance())); |
294 EXPECT_EQ(kTestSeedExperimentName, | 294 EXPECT_EQ(kTestSeedExperimentName, |
295 base::FieldTrialList::FindFullName(kTestSeedStudyName)); | 295 base::FieldTrialList::FindFullName(kTestSeedStudyName)); |
296 } | 296 } |
297 | 297 |
298 TEST_F(VariationsServiceTest, CreateTrialsFromSeedNoLastFetchTime) { | 298 TEST_F(VariationsServiceTest, CreateTrialsFromSeedNoLastFetchTime) { |
299 TestingPrefServiceSimple prefs; | 299 TestingPrefServiceSimple prefs; |
300 VariationsService::RegisterPrefs(prefs.registry()); | 300 VariationsService::RegisterPrefs(prefs.registry()); |
301 | 301 |
302 // Create a local base::FieldTrialList, to hold the field trials created in | 302 // Create a local base::FieldTrialList, to hold the field trials created in |
303 // this test. | 303 // this test. |
304 base::FieldTrialList field_trial_list(nullptr); | 304 base::FieldTrialList field_trial_list(nullptr); |
305 | 305 |
306 // Create a variations service | 306 // Create a variations service |
307 TestVariationsService service( | 307 TestVariationsService service( |
308 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 308 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs), |
309 &prefs); | 309 &prefs); |
310 service.SetCreateTrialsFromSeedCalledForTesting(false); | 310 service.SetCreateTrialsFromSeedCalledForTesting(false); |
311 | 311 |
312 // Store a seed. To simulate a first run, |prefs::kVariationsLastFetchTime| | 312 // Store a seed. To simulate a first run, |prefs::kVariationsLastFetchTime| |
313 // is left empty. | 313 // is left empty. |
314 service.StoreSeed(SerializeSeed(CreateTestSeed()), std::string(), | 314 service.StoreSeed(SerializeSeed(CreateTestSeed()), std::string(), |
315 std::string(), base::Time::Now(), false, false); | 315 std::string(), base::Time::Now(), false, false); |
316 EXPECT_EQ(0, prefs.GetInt64(prefs::kVariationsLastFetchTime)); | 316 EXPECT_EQ(0, prefs.GetInt64(prefs::kVariationsLastFetchTime)); |
317 | 317 |
318 // Check that field trials are created from the seed. Since the test study has | 318 // Check that field trials are created from the seed. Since the test study has |
319 // only 1 experiment with 100% probability weight, we must be part of it. | 319 // only 1 experiment with 100% probability weight, we must be part of it. |
320 EXPECT_TRUE(service.CreateTrialsFromSeed(base::FeatureList::GetInstance())); | 320 EXPECT_TRUE(service.CreateTrialsFromSeed(base::FeatureList::GetInstance())); |
321 EXPECT_EQ(base::FieldTrialList::FindFullName(kTestSeedStudyName), | 321 EXPECT_EQ(base::FieldTrialList::FindFullName(kTestSeedStudyName), |
322 kTestSeedExperimentName); | 322 kTestSeedExperimentName); |
323 } | 323 } |
324 | 324 |
325 TEST_F(VariationsServiceTest, CreateTrialsFromOutdatedSeed) { | 325 TEST_F(VariationsServiceTest, CreateTrialsFromOutdatedSeed) { |
326 TestingPrefServiceSimple prefs; | 326 TestingPrefServiceSimple prefs; |
327 VariationsService::RegisterPrefs(prefs.registry()); | 327 VariationsService::RegisterPrefs(prefs.registry()); |
328 | 328 |
329 // Create a local base::FieldTrialList, to hold the field trials created in | 329 // Create a local base::FieldTrialList, to hold the field trials created in |
330 // this test. | 330 // this test. |
331 base::FieldTrialList field_trial_list(nullptr); | 331 base::FieldTrialList field_trial_list(nullptr); |
332 | 332 |
333 // Create a variations service. | 333 // Create a variations service. |
334 TestVariationsService service( | 334 TestVariationsService service( |
335 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 335 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs), |
336 &prefs); | 336 &prefs); |
337 service.SetCreateTrialsFromSeedCalledForTesting(false); | 337 service.SetCreateTrialsFromSeedCalledForTesting(false); |
338 | 338 |
339 // Store a seed, with a fetch time 31 days in the past. | 339 // Store a seed, with a fetch time 31 days in the past. |
340 const base::Time seed_date = | 340 const base::Time seed_date = |
341 base::Time::Now() - base::TimeDelta::FromDays(31); | 341 base::Time::Now() - base::TimeDelta::FromDays(31); |
342 service.StoreSeed(SerializeSeed(CreateTestSeed()), std::string(), | 342 service.StoreSeed(SerializeSeed(CreateTestSeed()), std::string(), |
343 std::string(), seed_date, false, false); | 343 std::string(), seed_date, false, false); |
344 prefs.SetInt64(prefs::kVariationsLastFetchTime, seed_date.ToInternalValue()); | 344 prefs.SetInt64(prefs::kVariationsLastFetchTime, seed_date.ToInternalValue()); |
345 | 345 |
346 // Check that field trials are not created from the seed. | 346 // Check that field trials are not created from the seed. |
347 EXPECT_FALSE(service.CreateTrialsFromSeed(base::FeatureList::GetInstance())); | 347 EXPECT_FALSE(service.CreateTrialsFromSeed(base::FeatureList::GetInstance())); |
348 EXPECT_TRUE(base::FieldTrialList::FindFullName(kTestSeedStudyName).empty()); | 348 EXPECT_TRUE(base::FieldTrialList::FindFullName(kTestSeedStudyName).empty()); |
349 } | 349 } |
350 | 350 |
351 TEST_F(VariationsServiceTest, GetVariationsServerURL) { | 351 TEST_F(VariationsServiceTest, GetVariationsServerURL) { |
352 TestingPrefServiceSimple prefs; | 352 TestingPrefServiceSimple prefs; |
353 VariationsService::RegisterPrefs(prefs.registry()); | 353 VariationsService::RegisterPrefs(prefs.registry()); |
354 const std::string default_variations_url = | 354 const std::string default_variations_url = |
355 VariationsService::GetDefaultVariationsServerURLForTesting(); | 355 VariationsService::GetDefaultVariationsServerURLForTesting(); |
356 | 356 |
357 std::string value; | 357 std::string value; |
358 std::unique_ptr<TestVariationsServiceClient> client = | 358 std::unique_ptr<TestVariationsServiceClient> client = |
359 base::WrapUnique(new TestVariationsServiceClient()); | 359 base::MakeUnique<TestVariationsServiceClient>(); |
360 TestVariationsServiceClient* raw_client = client.get(); | 360 TestVariationsServiceClient* raw_client = client.get(); |
361 VariationsService service( | 361 VariationsService service( |
362 std::move(client), | 362 std::move(client), |
363 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 363 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs), |
364 &prefs, NULL, UIStringOverrider()); | 364 &prefs, NULL, UIStringOverrider()); |
365 GURL url = service.GetVariationsServerURL(&prefs, std::string()); | 365 GURL url = service.GetVariationsServerURL(&prefs, std::string()); |
366 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url, | 366 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url, |
367 base::CompareCase::SENSITIVE)); | 367 base::CompareCase::SENSITIVE)); |
368 EXPECT_FALSE(net::GetValueForKeyInQuery(url, "restrict", &value)); | 368 EXPECT_FALSE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
369 | 369 |
370 prefs.SetString(prefs::kVariationsRestrictParameter, "restricted"); | 370 prefs.SetString(prefs::kVariationsRestrictParameter, "restricted"); |
371 url = service.GetVariationsServerURL(&prefs, std::string()); | 371 url = service.GetVariationsServerURL(&prefs, std::string()); |
372 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url, | 372 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url, |
373 base::CompareCase::SENSITIVE)); | 373 base::CompareCase::SENSITIVE)); |
(...skipping 14 matching lines...) Expand all Loading... |
388 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url, | 388 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url, |
389 base::CompareCase::SENSITIVE)); | 389 base::CompareCase::SENSITIVE)); |
390 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); | 390 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
391 EXPECT_EQ("override", value); | 391 EXPECT_EQ("override", value); |
392 } | 392 } |
393 | 393 |
394 TEST_F(VariationsServiceTest, VariationsURLHasOSNameParam) { | 394 TEST_F(VariationsServiceTest, VariationsURLHasOSNameParam) { |
395 TestingPrefServiceSimple prefs; | 395 TestingPrefServiceSimple prefs; |
396 VariationsService::RegisterPrefs(prefs.registry()); | 396 VariationsService::RegisterPrefs(prefs.registry()); |
397 TestVariationsService service( | 397 TestVariationsService service( |
398 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 398 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs), |
399 &prefs); | 399 &prefs); |
400 const GURL url = service.GetVariationsServerURL(&prefs, std::string()); | 400 const GURL url = service.GetVariationsServerURL(&prefs, std::string()); |
401 | 401 |
402 std::string value; | 402 std::string value; |
403 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "osname", &value)); | 403 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "osname", &value)); |
404 EXPECT_FALSE(value.empty()); | 404 EXPECT_FALSE(value.empty()); |
405 } | 405 } |
406 | 406 |
407 TEST_F(VariationsServiceTest, RequestsInitiallyNotAllowed) { | 407 TEST_F(VariationsServiceTest, RequestsInitiallyNotAllowed) { |
408 TestingPrefServiceSimple prefs; | 408 TestingPrefServiceSimple prefs; |
409 VariationsService::RegisterPrefs(prefs.registry()); | 409 VariationsService::RegisterPrefs(prefs.registry()); |
410 | 410 |
411 // Pass ownership to TestVariationsService, but keep a weak pointer to | 411 // Pass ownership to TestVariationsService, but keep a weak pointer to |
412 // manipulate it for this test. | 412 // manipulate it for this test. |
413 std::unique_ptr<web_resource::TestRequestAllowedNotifier> test_notifier = | 413 std::unique_ptr<web_resource::TestRequestAllowedNotifier> test_notifier = |
414 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)); | 414 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs); |
415 web_resource::TestRequestAllowedNotifier* raw_notifier = test_notifier.get(); | 415 web_resource::TestRequestAllowedNotifier* raw_notifier = test_notifier.get(); |
416 TestVariationsService test_service(std::move(test_notifier), &prefs); | 416 TestVariationsService test_service(std::move(test_notifier), &prefs); |
417 | 417 |
418 // Force the notifier to initially disallow requests. | 418 // Force the notifier to initially disallow requests. |
419 raw_notifier->SetRequestsAllowedOverride(false); | 419 raw_notifier->SetRequestsAllowedOverride(false); |
420 test_service.StartRepeatedVariationsSeedFetch(); | 420 test_service.StartRepeatedVariationsSeedFetch(); |
421 EXPECT_FALSE(test_service.fetch_attempted()); | 421 EXPECT_FALSE(test_service.fetch_attempted()); |
422 | 422 |
423 raw_notifier->NotifyObserver(); | 423 raw_notifier->NotifyObserver(); |
424 EXPECT_TRUE(test_service.fetch_attempted()); | 424 EXPECT_TRUE(test_service.fetch_attempted()); |
425 } | 425 } |
426 | 426 |
427 TEST_F(VariationsServiceTest, RequestsInitiallyAllowed) { | 427 TEST_F(VariationsServiceTest, RequestsInitiallyAllowed) { |
428 TestingPrefServiceSimple prefs; | 428 TestingPrefServiceSimple prefs; |
429 VariationsService::RegisterPrefs(prefs.registry()); | 429 VariationsService::RegisterPrefs(prefs.registry()); |
430 | 430 |
431 // Pass ownership to TestVariationsService, but keep a weak pointer to | 431 // Pass ownership to TestVariationsService, but keep a weak pointer to |
432 // manipulate it for this test. | 432 // manipulate it for this test. |
433 std::unique_ptr<web_resource::TestRequestAllowedNotifier> test_notifier = | 433 std::unique_ptr<web_resource::TestRequestAllowedNotifier> test_notifier = |
434 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)); | 434 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs); |
435 web_resource::TestRequestAllowedNotifier* raw_notifier = test_notifier.get(); | 435 web_resource::TestRequestAllowedNotifier* raw_notifier = test_notifier.get(); |
436 TestVariationsService test_service(std::move(test_notifier), &prefs); | 436 TestVariationsService test_service(std::move(test_notifier), &prefs); |
437 | 437 |
438 raw_notifier->SetRequestsAllowedOverride(true); | 438 raw_notifier->SetRequestsAllowedOverride(true); |
439 test_service.StartRepeatedVariationsSeedFetch(); | 439 test_service.StartRepeatedVariationsSeedFetch(); |
440 EXPECT_TRUE(test_service.fetch_attempted()); | 440 EXPECT_TRUE(test_service.fetch_attempted()); |
441 } | 441 } |
442 | 442 |
443 TEST_F(VariationsServiceTest, SeedStoredWhenOKStatus) { | 443 TEST_F(VariationsServiceTest, SeedStoredWhenOKStatus) { |
444 TestingPrefServiceSimple prefs; | 444 TestingPrefServiceSimple prefs; |
445 VariationsService::RegisterPrefs(prefs.registry()); | 445 VariationsService::RegisterPrefs(prefs.registry()); |
446 | 446 |
447 TestVariationsService service( | 447 TestVariationsService service( |
448 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 448 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs), |
449 &prefs); | 449 &prefs); |
450 service.set_intercepts_fetch(false); | 450 service.set_intercepts_fetch(false); |
451 | 451 |
452 net::TestURLFetcherFactory factory; | 452 net::TestURLFetcherFactory factory; |
453 service.DoActualFetch(); | 453 service.DoActualFetch(); |
454 | 454 |
455 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 455 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
456 SimulateServerResponse(net::HTTP_OK, fetcher); | 456 SimulateServerResponse(net::HTTP_OK, fetcher); |
457 fetcher->SetResponseString(SerializeSeed(CreateTestSeed())); | 457 fetcher->SetResponseString(SerializeSeed(CreateTestSeed())); |
458 | 458 |
459 EXPECT_FALSE(service.seed_stored()); | 459 EXPECT_FALSE(service.seed_stored()); |
460 service.OnURLFetchComplete(fetcher); | 460 service.OnURLFetchComplete(fetcher); |
461 EXPECT_TRUE(service.seed_stored()); | 461 EXPECT_TRUE(service.seed_stored()); |
462 } | 462 } |
463 | 463 |
464 TEST_F(VariationsServiceTest, SeedNotStoredWhenNonOKStatus) { | 464 TEST_F(VariationsServiceTest, SeedNotStoredWhenNonOKStatus) { |
465 const int non_ok_status_codes[] = { | 465 const int non_ok_status_codes[] = { |
466 net::HTTP_NO_CONTENT, | 466 net::HTTP_NO_CONTENT, |
467 net::HTTP_NOT_MODIFIED, | 467 net::HTTP_NOT_MODIFIED, |
468 net::HTTP_NOT_FOUND, | 468 net::HTTP_NOT_FOUND, |
469 net::HTTP_INTERNAL_SERVER_ERROR, | 469 net::HTTP_INTERNAL_SERVER_ERROR, |
470 net::HTTP_SERVICE_UNAVAILABLE, | 470 net::HTTP_SERVICE_UNAVAILABLE, |
471 }; | 471 }; |
472 | 472 |
473 TestingPrefServiceSimple prefs; | 473 TestingPrefServiceSimple prefs; |
474 VariationsService::RegisterPrefs(prefs.registry()); | 474 VariationsService::RegisterPrefs(prefs.registry()); |
475 | 475 |
476 TestVariationsService service( | 476 TestVariationsService service( |
477 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 477 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs), |
478 &prefs); | 478 &prefs); |
479 service.set_intercepts_fetch(false); | 479 service.set_intercepts_fetch(false); |
480 for (size_t i = 0; i < arraysize(non_ok_status_codes); ++i) { | 480 for (size_t i = 0; i < arraysize(non_ok_status_codes); ++i) { |
481 net::TestURLFetcherFactory factory; | 481 net::TestURLFetcherFactory factory; |
482 service.DoActualFetch(); | 482 service.DoActualFetch(); |
483 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); | 483 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); |
484 | 484 |
485 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 485 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
486 SimulateServerResponse(non_ok_status_codes[i], fetcher); | 486 SimulateServerResponse(non_ok_status_codes[i], fetcher); |
487 service.OnURLFetchComplete(fetcher); | 487 service.OnURLFetchComplete(fetcher); |
488 | 488 |
489 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); | 489 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); |
490 } | 490 } |
491 } | 491 } |
492 | 492 |
493 TEST_F(VariationsServiceTest, RequestGzipCompressedSeed) { | 493 TEST_F(VariationsServiceTest, RequestGzipCompressedSeed) { |
494 TestingPrefServiceSimple prefs; | 494 TestingPrefServiceSimple prefs; |
495 VariationsService::RegisterPrefs(prefs.registry()); | 495 VariationsService::RegisterPrefs(prefs.registry()); |
496 net::TestURLFetcherFactory factory; | 496 net::TestURLFetcherFactory factory; |
497 | 497 |
498 TestVariationsService service( | 498 TestVariationsService service( |
499 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 499 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs), |
500 &prefs); | 500 &prefs); |
501 service.set_intercepts_fetch(false); | 501 service.set_intercepts_fetch(false); |
502 service.DoActualFetch(); | 502 service.DoActualFetch(); |
503 | 503 |
504 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 504 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
505 net::HttpRequestHeaders headers; | 505 net::HttpRequestHeaders headers; |
506 fetcher->GetExtraRequestHeaders(&headers); | 506 fetcher->GetExtraRequestHeaders(&headers); |
507 std::string field; | 507 std::string field; |
508 ASSERT_TRUE(headers.GetHeader("A-IM", &field)); | 508 ASSERT_TRUE(headers.GetHeader("A-IM", &field)); |
509 EXPECT_EQ("gzip", field); | 509 EXPECT_EQ("gzip", field); |
(...skipping 15 matching lines...) Expand all Loading... |
525 {"IM:deflate,x-bm,gzip", false, false, false}, | 525 {"IM:deflate,x-bm,gzip", false, false, false}, |
526 }; | 526 }; |
527 | 527 |
528 TestingPrefServiceSimple prefs; | 528 TestingPrefServiceSimple prefs; |
529 VariationsService::RegisterPrefs(prefs.registry()); | 529 VariationsService::RegisterPrefs(prefs.registry()); |
530 std::string serialized_seed = SerializeSeed(CreateTestSeed()); | 530 std::string serialized_seed = SerializeSeed(CreateTestSeed()); |
531 net::TestURLFetcherFactory factory; | 531 net::TestURLFetcherFactory factory; |
532 | 532 |
533 for (size_t i = 0; i < arraysize(cases); ++i) { | 533 for (size_t i = 0; i < arraysize(cases); ++i) { |
534 TestVariationsService service( | 534 TestVariationsService service( |
535 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 535 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs), |
536 &prefs); | 536 &prefs); |
537 service.set_intercepts_fetch(false); | 537 service.set_intercepts_fetch(false); |
538 service.DoActualFetch(); | 538 service.DoActualFetch(); |
539 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 539 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
540 | 540 |
541 if (cases[i].im.empty()) | 541 if (cases[i].im.empty()) |
542 SimulateServerResponse(net::HTTP_OK, fetcher); | 542 SimulateServerResponse(net::HTTP_OK, fetcher); |
543 else | 543 else |
544 SimulateServerResponseWithHeader(net::HTTP_OK, fetcher, &cases[i].im); | 544 SimulateServerResponseWithHeader(net::HTTP_OK, fetcher, &cases[i].im); |
545 fetcher->SetResponseString(serialized_seed); | 545 fetcher->SetResponseString(serialized_seed); |
546 service.OnURLFetchComplete(fetcher); | 546 service.OnURLFetchComplete(fetcher); |
547 | 547 |
548 EXPECT_EQ(cases[i].seed_stored, service.seed_stored()); | 548 EXPECT_EQ(cases[i].seed_stored, service.seed_stored()); |
549 EXPECT_EQ(cases[i].delta_compressed, service.delta_compressed_seed()); | 549 EXPECT_EQ(cases[i].delta_compressed, service.delta_compressed_seed()); |
550 EXPECT_EQ(cases[i].gzip_compressed, service.gzip_compressed_seed()); | 550 EXPECT_EQ(cases[i].gzip_compressed, service.gzip_compressed_seed()); |
551 } | 551 } |
552 } | 552 } |
553 | 553 |
554 TEST_F(VariationsServiceTest, CountryHeader) { | 554 TEST_F(VariationsServiceTest, CountryHeader) { |
555 TestingPrefServiceSimple prefs; | 555 TestingPrefServiceSimple prefs; |
556 VariationsService::RegisterPrefs(prefs.registry()); | 556 VariationsService::RegisterPrefs(prefs.registry()); |
557 | 557 |
558 TestVariationsService service( | 558 TestVariationsService service( |
559 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 559 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs), |
560 &prefs); | 560 &prefs); |
561 service.set_intercepts_fetch(false); | 561 service.set_intercepts_fetch(false); |
562 | 562 |
563 net::TestURLFetcherFactory factory; | 563 net::TestURLFetcherFactory factory; |
564 service.DoActualFetch(); | 564 service.DoActualFetch(); |
565 | 565 |
566 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 566 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
567 scoped_refptr<net::HttpResponseHeaders> headers = | 567 scoped_refptr<net::HttpResponseHeaders> headers = |
568 SimulateServerResponse(net::HTTP_OK, fetcher); | 568 SimulateServerResponse(net::HTTP_OK, fetcher); |
569 headers->AddHeader("X-Country: test"); | 569 headers->AddHeader("X-Country: test"); |
570 fetcher->SetResponseString(SerializeSeed(CreateTestSeed())); | 570 fetcher->SetResponseString(SerializeSeed(CreateTestSeed())); |
571 | 571 |
572 EXPECT_FALSE(service.seed_stored()); | 572 EXPECT_FALSE(service.seed_stored()); |
573 service.OnURLFetchComplete(fetcher); | 573 service.OnURLFetchComplete(fetcher); |
574 EXPECT_TRUE(service.seed_stored()); | 574 EXPECT_TRUE(service.seed_stored()); |
575 EXPECT_EQ("test", service.stored_country()); | 575 EXPECT_EQ("test", service.stored_country()); |
576 } | 576 } |
577 | 577 |
578 TEST_F(VariationsServiceTest, Observer) { | 578 TEST_F(VariationsServiceTest, Observer) { |
579 TestingPrefServiceSimple prefs; | 579 TestingPrefServiceSimple prefs; |
580 VariationsService::RegisterPrefs(prefs.registry()); | 580 VariationsService::RegisterPrefs(prefs.registry()); |
581 VariationsService service( | 581 VariationsService service( |
582 base::WrapUnique(new TestVariationsServiceClient()), | 582 base::MakeUnique<TestVariationsServiceClient>(), |
583 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 583 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs), |
584 &prefs, NULL, UIStringOverrider()); | 584 &prefs, NULL, UIStringOverrider()); |
585 | 585 |
586 struct { | 586 struct { |
587 int normal_count; | 587 int normal_count; |
588 int best_effort_count; | 588 int best_effort_count; |
589 int critical_count; | 589 int critical_count; |
590 int expected_best_effort_notifications; | 590 int expected_best_effort_notifications; |
591 int expected_crtical_notifications; | 591 int expected_crtical_notifications; |
592 } cases[] = { | 592 } cases[] = { |
593 {0, 0, 0, 0, 0}, | 593 {0, 0, 0, 0, 0}, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 {"badversion,ca", "20.0.0.0", "us", "20.0.0.0,us", "us", | 672 {"badversion,ca", "20.0.0.0", "us", "20.0.0.0,us", "us", |
673 VariationsService::LOAD_COUNTRY_INVALID_PREF_HAS_SEED}, | 673 VariationsService::LOAD_COUNTRY_INVALID_PREF_HAS_SEED}, |
674 {"badversion,ca", "20.0.0.0", nullptr, "", "", | 674 {"badversion,ca", "20.0.0.0", nullptr, "", "", |
675 VariationsService::LOAD_COUNTRY_INVALID_PREF_NO_SEED}, | 675 VariationsService::LOAD_COUNTRY_INVALID_PREF_NO_SEED}, |
676 }; | 676 }; |
677 | 677 |
678 for (const auto& test : test_cases) { | 678 for (const auto& test : test_cases) { |
679 TestingPrefServiceSimple prefs; | 679 TestingPrefServiceSimple prefs; |
680 VariationsService::RegisterPrefs(prefs.registry()); | 680 VariationsService::RegisterPrefs(prefs.registry()); |
681 VariationsService service( | 681 VariationsService service( |
682 base::WrapUnique(new TestVariationsServiceClient()), | 682 base::MakeUnique<TestVariationsServiceClient>(), |
683 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 683 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs), |
684 &prefs, NULL, UIStringOverrider()); | 684 &prefs, NULL, UIStringOverrider()); |
685 | 685 |
686 if (test.pref_value_before) { | 686 if (test.pref_value_before) { |
687 base::ListValue list_value; | 687 base::ListValue list_value; |
688 for (const std::string& component : | 688 for (const std::string& component : |
689 base::SplitString(test.pref_value_before, ",", base::TRIM_WHITESPACE, | 689 base::SplitString(test.pref_value_before, ",", base::TRIM_WHITESPACE, |
690 base::SPLIT_WANT_ALL)) { | 690 base::SPLIT_WANT_ALL)) { |
691 list_value.AppendString(component); | 691 list_value.AppendString(component); |
692 } | 692 } |
693 prefs.Set(prefs::kVariationsPermanentConsistencyCountry, list_value); | 693 prefs.Set(prefs::kVariationsPermanentConsistencyCountry, list_value); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 {"", "ca", kPrefCa, true}, | 744 {"", "ca", kPrefCa, true}, |
745 {"", "", "", false}, | 745 {"", "", "", false}, |
746 {"19.0.0.0,us", "ca", kPrefCa, true}, | 746 {"19.0.0.0,us", "ca", kPrefCa, true}, |
747 {"19.0.0.0,us", "us", "19.0.0.0,us", false}, | 747 {"19.0.0.0,us", "us", "19.0.0.0,us", false}, |
748 }; | 748 }; |
749 | 749 |
750 for (const auto& test : test_cases) { | 750 for (const auto& test : test_cases) { |
751 TestingPrefServiceSimple prefs; | 751 TestingPrefServiceSimple prefs; |
752 VariationsService::RegisterPrefs(prefs.registry()); | 752 VariationsService::RegisterPrefs(prefs.registry()); |
753 TestVariationsService service( | 753 TestVariationsService service( |
754 base::WrapUnique(new web_resource::TestRequestAllowedNotifier(&prefs)), | 754 base::MakeUnique<web_resource::TestRequestAllowedNotifier>(&prefs), |
755 &prefs); | 755 &prefs); |
756 | 756 |
757 if (!test.pref_value_before.empty()) { | 757 if (!test.pref_value_before.empty()) { |
758 base::ListValue list_value; | 758 base::ListValue list_value; |
759 for (const std::string& component : | 759 for (const std::string& component : |
760 base::SplitString(test.pref_value_before, ",", base::TRIM_WHITESPACE, | 760 base::SplitString(test.pref_value_before, ",", base::TRIM_WHITESPACE, |
761 base::SPLIT_WANT_ALL)) { | 761 base::SPLIT_WANT_ALL)) { |
762 list_value.AppendString(component); | 762 list_value.AppendString(component); |
763 } | 763 } |
764 prefs.Set(prefs::kVariationsPermanentConsistencyCountry, list_value); | 764 prefs.Set(prefs::kVariationsPermanentConsistencyCountry, list_value); |
(...skipping 13 matching lines...) Expand all Loading... |
778 } | 778 } |
779 const base::ListValue* pref_value = | 779 const base::ListValue* pref_value = |
780 prefs.GetList(prefs::kVariationsPermanentConsistencyCountry); | 780 prefs.GetList(prefs::kVariationsPermanentConsistencyCountry); |
781 EXPECT_EQ(ListValueToString(expected_list_value), | 781 EXPECT_EQ(ListValueToString(expected_list_value), |
782 ListValueToString(*pref_value)) | 782 ListValueToString(*pref_value)) |
783 << test.pref_value_before << ", " << test.country_code_override; | 783 << test.pref_value_before << ", " << test.country_code_override; |
784 } | 784 } |
785 } | 785 } |
786 | 786 |
787 } // namespace variations | 787 } // namespace variations |
OLD | NEW |