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

Side by Side Diff: chrome/browser/signin/cross_device_promo_unittest.cc

Issue 1162103003: ListAccounts will return the Gaia ID as well as the email of the account. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/signin/cross_device_promo.h" 5 #include "chrome/browser/signin/cross_device_promo.h"
6 6
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
10 #include "chrome/browser/prefs/browser_prefs.h" 10 #include "chrome/browser/prefs/browser_prefs.h"
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 1); 279 1);
280 } 280 }
281 } 281 }
282 282
283 TEST_F(CrossDevicePromoTest, TrackAccountsInCookie) { 283 TEST_F(CrossDevicePromoTest, TrackAccountsInCookie) {
284 InitPromoVariation(); 284 InitPromoVariation();
285 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting()); 285 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting());
286 286
287 ASSERT_FALSE(prefs()->HasPrefPath( 287 ASSERT_FALSE(prefs()->HasPrefPath(
288 prefs::kCrossDevicePromoObservedSingleAccountCookie)); 288 prefs::kCrossDevicePromoObservedSingleAccountCookie));
289 std::vector<std::pair<std::string, bool>> accounts; 289 std::vector<gaia::ListedAccount> accounts;
290 290
291 // Setting a single cookie sets the time. 291 // Setting a single cookie sets the time.
292 base::Time before_setting_cookies = base::Time::Now(); 292 base::Time before_setting_cookies = base::Time::Now();
293 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false); 293 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false);
294 cookie_manager_service()->SetListAccountsResponseOneAccount("foo@bar.com"); 294 cookie_manager_service()->SetListAccountsResponseOneAccount("foo@bar.com");
295 EXPECT_FALSE(cookie_manager_service()->ListAccounts(&accounts)); 295 EXPECT_FALSE(cookie_manager_service()->ListAccounts(&accounts));
296 base::RunLoop().RunUntilIdle(); 296 base::RunLoop().RunUntilIdle();
297 297
298 base::Time after_setting_cookies = base::Time::Now(); 298 base::Time after_setting_cookies = base::Time::Now();
299 ASSERT_TRUE(prefs()->HasPrefPath( 299 ASSERT_TRUE(prefs()->HasPrefPath(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 base::HistogramTester test_single_account; 349 base::HistogramTester test_single_account;
350 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting()); 350 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting());
351 test_single_account.ExpectUniqueSample( 351 test_single_account.ExpectUniqueSample(
352 "Signin.XDevicePromo.Eligibility", 352 "Signin.XDevicePromo.Eligibility",
353 signin_metrics::NOT_SINGLE_GAIA_ACCOUNT, 1); 353 signin_metrics::NOT_SINGLE_GAIA_ACCOUNT, 1);
354 } 354 }
355 355
356 // Notice a single account. 356 // Notice a single account.
357 { 357 {
358 base::HistogramTester test_single_account; 358 base::HistogramTester test_single_account;
359 std::vector<std::pair<std::string, bool>> accounts; 359 std::vector<gaia::ListedAccount> accounts;
360 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false); 360 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false);
361 cookie_manager_service()->SetListAccountsResponseOneAccount("foo@bar.com"); 361 cookie_manager_service()->SetListAccountsResponseOneAccount("foo@bar.com");
362 EXPECT_FALSE(cookie_manager_service()->ListAccounts(&accounts)); 362 EXPECT_FALSE(cookie_manager_service()->ListAccounts(&accounts));
363 base::RunLoop().RunUntilIdle(); 363 base::RunLoop().RunUntilIdle();
364 364
365 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting()); 365 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting());
366 test_single_account.ExpectUniqueSample( 366 test_single_account.ExpectUniqueSample(
367 "Signin.XDevicePromo.Eligibility", 367 "Signin.XDevicePromo.Eligibility",
368 signin_metrics::UNKNOWN_COUNT_DEVICES, 1); 368 signin_metrics::UNKNOWN_COUNT_DEVICES, 1);
369 } 369 }
370 370
371 // Set a single account that hasn't been around for "long enough". 371 // Set a single account that hasn't been around for "long enough".
372 { 372 {
373 base::HistogramTester test_single_account; 373 base::HistogramTester test_single_account;
374 prefs()->SetInt64(prefs::kCrossDevicePromoObservedSingleAccountCookie, 374 prefs()->SetInt64(prefs::kCrossDevicePromoObservedSingleAccountCookie,
375 InOneHour()); 375 InOneHour());
376 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting()); 376 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting());
377 test_single_account.ExpectBucketCount( 377 test_single_account.ExpectBucketCount(
378 "Signin.XDevicePromo.Eligibility", 378 "Signin.XDevicePromo.Eligibility",
379 signin_metrics::NOT_SINGLE_GAIA_ACCOUNT, 1); 379 signin_metrics::NOT_SINGLE_GAIA_ACCOUNT, 1);
380 } 380 }
381 } 381 }
382 382
383 TEST_F(CrossDevicePromoTest, NumDevicesEligibility) { 383 TEST_F(CrossDevicePromoTest, NumDevicesEligibility) {
384 // Start with a variation, signed in, and one account in the cookie jar. 384 // Start with a variation, signed in, and one account in the cookie jar.
385 InitPromoVariation(); 385 InitPromoVariation();
386 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting()); 386 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting());
387 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false); 387 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false);
388 cookie_manager_service()->SetListAccountsResponseOneAccount("foo@bar.com"); 388 cookie_manager_service()->SetListAccountsResponseOneAccount("foo@bar.com");
389 std::vector<std::pair<std::string, bool>> accounts; 389 std::vector<gaia::ListedAccount> accounts;
390 EXPECT_FALSE(cookie_manager_service()->ListAccounts(&accounts)); 390 EXPECT_FALSE(cookie_manager_service()->ListAccounts(&accounts));
391 base::RunLoop().RunUntilIdle(); 391 base::RunLoop().RunUntilIdle();
392 392
393 // Ensure we appropriate schedule a check for listing devices. 393 // Ensure we appropriate schedule a check for listing devices.
394 { 394 {
395 base::HistogramTester test_missing_list_devices; 395 base::HistogramTester test_missing_list_devices;
396 int64 earliest_time_to_check_list_devices = 396 int64 earliest_time_to_check_list_devices =
397 base::Time::Now().ToInternalValue(); 397 base::Time::Now().ToInternalValue();
398 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting()); 398 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting());
399 int64 latest_time_to_check_list_devices = InOneHour(); 399 int64 latest_time_to_check_list_devices = InOneHour();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 variations_params["MinutesBetweenBrowsingSessions"] = "0"; 449 variations_params["MinutesBetweenBrowsingSessions"] = "0";
450 variations_params["MinutesMaxContextSwitchDuration"] = "10"; 450 variations_params["MinutesMaxContextSwitchDuration"] = "10";
451 variations_params["RPCThrottle"] = "101"; 451 variations_params["RPCThrottle"] = "101";
452 EXPECT_TRUE(variations::AssociateVariationParams("CrossDevicePromo", "A", 452 EXPECT_TRUE(variations::AssociateVariationParams("CrossDevicePromo", "A",
453 variations_params)); 453 variations_params));
454 base::FieldTrialList::CreateFieldTrial("CrossDevicePromo", "A"); 454 base::FieldTrialList::CreateFieldTrial("CrossDevicePromo", "A");
455 455
456 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting()); 456 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting());
457 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false); 457 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false);
458 cookie_manager_service()->SetListAccountsResponseOneAccount("foo@bar.com"); 458 cookie_manager_service()->SetListAccountsResponseOneAccount("foo@bar.com");
459 std::vector<std::pair<std::string, bool>> accounts; 459 std::vector<gaia::ListedAccount> accounts;
460 EXPECT_FALSE(cookie_manager_service()->ListAccounts(&accounts)); 460 EXPECT_FALSE(cookie_manager_service()->ListAccounts(&accounts));
461 base::RunLoop().RunUntilIdle(); 461 base::RunLoop().RunUntilIdle();
462 462
463 // Ensure Device Activity Fetch gets throttled. 463 // Ensure Device Activity Fetch gets throttled.
464 { 464 {
465 base::HistogramTester test_throttle_rpc; 465 base::HistogramTester test_throttle_rpc;
466 prefs()->SetInt64(prefs::kCrossDevicePromoNextFetchListDevicesTime, 466 prefs()->SetInt64(prefs::kCrossDevicePromoNextFetchListDevicesTime,
467 base::Time::Now().ToInternalValue()); 467 base::Time::Now().ToInternalValue());
468 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting()); 468 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting());
469 test_throttle_rpc.ExpectUniqueSample( 469 test_throttle_rpc.ExpectUniqueSample(
470 "Signin.XDevicePromo.Eligibility", 470 "Signin.XDevicePromo.Eligibility",
471 signin_metrics::THROTTLED_FETCHING_DEVICE_ACTIVITY, 1); 471 signin_metrics::THROTTLED_FETCHING_DEVICE_ACTIVITY, 1);
472 } 472 }
473 } 473 }
474 474
475 TEST_F(CrossDevicePromoTest, NumDevicesKnown) { 475 TEST_F(CrossDevicePromoTest, NumDevicesKnown) {
476 // Start with a variation, signed in, and one account, sync devices in 1 hour. 476 // Start with a variation, signed in, and one account, sync devices in 1 hour.
477 InitPromoVariation(); 477 InitPromoVariation();
478 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting()); 478 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting());
479 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false); 479 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false);
480 cookie_manager_service()->SetListAccountsResponseOneAccount("foo@bar.com"); 480 cookie_manager_service()->SetListAccountsResponseOneAccount("foo@bar.com");
481 std::vector<std::pair<std::string, bool>> accounts; 481 std::vector<gaia::ListedAccount> accounts;
482 EXPECT_FALSE(cookie_manager_service()->ListAccounts(&accounts)); 482 EXPECT_FALSE(cookie_manager_service()->ListAccounts(&accounts));
483 base::RunLoop().RunUntilIdle(); 483 base::RunLoop().RunUntilIdle();
484 prefs()->SetInt64(prefs::kCrossDevicePromoNextFetchListDevicesTime, 484 prefs()->SetInt64(prefs::kCrossDevicePromoNextFetchListDevicesTime,
485 InOneHour()); 485 InOneHour());
486 486
487 // If there is no device present. 487 // If there is no device present.
488 { 488 {
489 base::HistogramTester test_no_devices; 489 base::HistogramTester test_no_devices;
490 prefs()->SetInteger(prefs::kCrossDevicePromoNumDevices, 0); 490 prefs()->SetInteger(prefs::kCrossDevicePromoNumDevices, 0);
491 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting()); 491 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting());
492 test_no_devices.ExpectUniqueSample("Signin.XDevicePromo.Eligibility", 492 test_no_devices.ExpectUniqueSample("Signin.XDevicePromo.Eligibility",
493 signin_metrics::ZERO_DEVICES, 1); 493 signin_metrics::ZERO_DEVICES, 1);
494 } 494 }
495 495
496 // If there is one device present. 496 // If there is one device present.
497 { 497 {
498 prefs()->SetInteger(prefs::kCrossDevicePromoNumDevices, 1); 498 prefs()->SetInteger(prefs::kCrossDevicePromoNumDevices, 1);
499 EXPECT_TRUE(promo()->CheckPromoEligibilityForTesting()); 499 EXPECT_TRUE(promo()->CheckPromoEligibilityForTesting());
500 } 500 }
501 } 501 }
502 502
503 TEST_F(CrossDevicePromoTest, FetchDeviceResults) { 503 TEST_F(CrossDevicePromoTest, FetchDeviceResults) {
504 // Start with a variation, signed in, and one account, sync devices in 1 hour. 504 // Start with a variation, signed in, and one account, sync devices in 1 hour.
505 InitPromoVariation(); 505 InitPromoVariation();
506 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting()); 506 EXPECT_FALSE(promo()->CheckPromoEligibilityForTesting());
507 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false); 507 cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false);
508 cookie_manager_service()->SetListAccountsResponseOneAccount("foo@bar.com"); 508 cookie_manager_service()->SetListAccountsResponseOneAccount("foo@bar.com");
509 std::vector<std::pair<std::string, bool>> accounts; 509 std::vector<gaia::ListedAccount> accounts;
510 EXPECT_FALSE(cookie_manager_service()->ListAccounts(&accounts)); 510 EXPECT_FALSE(cookie_manager_service()->ListAccounts(&accounts));
511 base::RunLoop().RunUntilIdle(); 511 base::RunLoop().RunUntilIdle();
512 prefs()->SetInt64(prefs::kCrossDevicePromoNextFetchListDevicesTime, 512 prefs()->SetInt64(prefs::kCrossDevicePromoNextFetchListDevicesTime,
513 base::Time::Now().ToInternalValue()); 513 base::Time::Now().ToInternalValue());
514 prefs()->SetInteger(prefs::kCrossDevicePromoNumDevices, 1); 514 prefs()->SetInteger(prefs::kCrossDevicePromoNumDevices, 1);
515 515
516 // If there is no device found. 516 // If there is no device found.
517 { 517 {
518 base::HistogramTester test_no_devices; 518 base::HistogramTester test_no_devices;
519 std::vector<DeviceActivityFetcher::DeviceActivity> devices; 519 std::vector<DeviceActivityFetcher::DeviceActivity> devices;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 EXPECT_EQ(2, prefs()->GetInteger(prefs::kCrossDevicePromoNumDevices)); 609 EXPECT_EQ(2, prefs()->GetInteger(prefs::kCrossDevicePromoNumDevices));
610 EXPECT_EQ(device2_last_active.ToInternalValue(), 610 EXPECT_EQ(device2_last_active.ToInternalValue(),
611 prefs()->GetInt64(prefs::kCrossDevicePromoLastDeviceActiveTime)); 611 prefs()->GetInt64(prefs::kCrossDevicePromoLastDeviceActiveTime));
612 EXPECT_TRUE(prefs()->GetBoolean(prefs::kCrossDevicePromoActive)); 612 EXPECT_TRUE(prefs()->GetBoolean(prefs::kCrossDevicePromoActive));
613 test_two_devices.ExpectUniqueSample("Signin.XDevicePromo.Eligibility", 613 test_two_devices.ExpectUniqueSample("Signin.XDevicePromo.Eligibility",
614 signin_metrics::ELIGIBLE, 1); 614 signin_metrics::ELIGIBLE, 1);
615 EXPECT_TRUE(observer.is_active()); 615 EXPECT_TRUE(observer.is_active());
616 EXPECT_EQ(1, observer.times_set_active()); 616 EXPECT_EQ(1, observer.times_set_active());
617 } 617 }
618 } 618 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/cross_device_promo.cc ('k') | chrome/browser/signin/fake_gaia_cookie_manager_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698