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 "chrome/browser/ui/webui/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/sync_setup_handler.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/signin/fake_auth_status_provider.h" | 16 #include "chrome/browser/signin/fake_auth_status_provider.h" |
17 #include "chrome/browser/signin/fake_signin_manager.h" | 17 #include "chrome/browser/signin/fake_signin_manager.h" |
18 #include "chrome/browser/signin/signin_manager.h" | 18 #include "chrome/browser/signin/signin_manager.h" |
19 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
20 #include "chrome/browser/sync/profile_sync_service_factory.h" | 20 #include "chrome/browser/sync/profile_sync_service_factory.h" |
21 #include "chrome/browser/sync/profile_sync_service_mock.h" | 21 #include "chrome/browser/sync/profile_sync_service_mock.h" |
22 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 22 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
23 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 23 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
24 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 24 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
27 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
| 28 #include "chrome/test/base/testing_browser_process.h" |
| 29 #include "chrome/test/base/scoped_testing_local_state.h" |
28 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
29 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
32 #include "ui/base/layout.h" | 34 #include "ui/base/layout.h" |
33 | 35 |
34 using ::testing::_; | 36 using ::testing::_; |
35 using ::testing::Mock; | 37 using ::testing::Mock; |
36 using ::testing::Return; | 38 using ::testing::Return; |
37 using ::testing::ReturnRef; | 39 using ::testing::ReturnRef; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 using SyncSetupHandler::have_signin_tracker; | 315 using SyncSetupHandler::have_signin_tracker; |
314 | 316 |
315 private: | 317 private: |
316 virtual void DisplayGaiaLoginInNewTabOrWindow() OVERRIDE {} | 318 virtual void DisplayGaiaLoginInNewTabOrWindow() OVERRIDE {} |
317 | 319 |
318 // Weak pointer to parent profile. | 320 // Weak pointer to parent profile. |
319 Profile* profile_; | 321 Profile* profile_; |
320 DISALLOW_COPY_AND_ASSIGN(TestingSyncSetupHandler); | 322 DISALLOW_COPY_AND_ASSIGN(TestingSyncSetupHandler); |
321 }; | 323 }; |
322 | 324 |
323 class SigninManagerBaseMock : public FakeSigninManagerBase { | |
324 public: | |
325 explicit SigninManagerBaseMock(Profile* profile) | |
326 : FakeSigninManagerBase(profile) {} | |
327 MOCK_CONST_METHOD1(IsAllowedUsername, bool(const std::string& username)); | |
328 }; | |
329 | |
330 static ProfileKeyedService* BuildSigninManagerBaseMock( | |
331 content::BrowserContext* profile) { | |
332 return new SigninManagerBaseMock(static_cast<Profile*>(profile)); | |
333 } | |
334 | |
335 // The boolean parameter indicates whether the test is run with ClientOAuth | 325 // The boolean parameter indicates whether the test is run with ClientOAuth |
336 // or not. The test parameter is a bool: whether or not to test with/ | 326 // or not. The test parameter is a bool: whether or not to test with/ |
337 // /ClientLogin enabled or not. | 327 // /ClientLogin enabled or not. |
338 class SyncSetupHandlerTest : public testing::TestWithParam<bool> { | 328 class SyncSetupHandlerTest : public testing::TestWithParam<bool> { |
339 public: | 329 public: |
340 SyncSetupHandlerTest() : error_(GoogleServiceAuthError::NONE) {} | 330 SyncSetupHandlerTest() : error_(GoogleServiceAuthError::NONE) {} |
341 virtual void SetUp() OVERRIDE { | 331 virtual void SetUp() OVERRIDE { |
342 bool use_client_login_flow = GetParam(); | 332 bool use_client_login_flow = GetParam(); |
343 if (use_client_login_flow) { | 333 if (use_client_login_flow) { |
344 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 334 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
(...skipping 13 matching lines...) Expand all Loading... |
358 profile_.get(), | 348 profile_.get(), |
359 ProfileSyncServiceMock::BuildMockProfileSyncService)); | 349 ProfileSyncServiceMock::BuildMockProfileSyncService)); |
360 mock_pss_->Initialize(); | 350 mock_pss_->Initialize(); |
361 | 351 |
362 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault( | 352 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault( |
363 Return(syncer::IMPLICIT_PASSPHRASE)); | 353 Return(syncer::IMPLICIT_PASSPHRASE)); |
364 ON_CALL(*mock_pss_, GetPassphraseTime()).WillByDefault( | 354 ON_CALL(*mock_pss_, GetPassphraseTime()).WillByDefault( |
365 Return(base::Time())); | 355 Return(base::Time())); |
366 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault( | 356 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault( |
367 Return(base::Time())); | 357 Return(base::Time())); |
| 358 #if defined(OS_CHROMEOS) |
368 mock_signin_ = static_cast<SigninManagerBase*>( | 359 mock_signin_ = static_cast<SigninManagerBase*>( |
369 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 360 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
370 profile_.get(), BuildSigninManagerBaseMock)); | 361 profile_.get(), FakeSigninManagerBase::Build)); |
| 362 #else |
| 363 mock_signin_ = static_cast<SigninManagerBase*>( |
| 364 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 365 profile_.get(), FakeSigninManager::Build)); |
| 366 #endif |
371 handler_.reset(new TestingSyncSetupHandler(&web_ui_, profile_.get())); | 367 handler_.reset(new TestingSyncSetupHandler(&web_ui_, profile_.get())); |
372 } | 368 } |
373 | 369 |
374 // Setup the expectations for calls made when displaying the config page. | 370 // Setup the expectations for calls made when displaying the config page. |
375 void SetDefaultExpectationsForConfigPage() { | 371 void SetDefaultExpectationsForConfigPage() { |
376 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()). | 372 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()). |
377 WillRepeatedly(Return(GetAllTypes())); | 373 WillRepeatedly(Return(GetAllTypes())); |
378 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()). | 374 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()). |
379 WillRepeatedly(Return(GetAllTypes())); | 375 WillRepeatedly(Return(GetAllTypes())); |
380 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()). | 376 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()). |
381 WillRepeatedly(Return(false)); | 377 WillRepeatedly(Return(false)); |
382 } | 378 } |
383 | 379 |
384 void SetupInitializedProfileSyncService() { | 380 void SetupInitializedProfileSyncService() { |
385 // An initialized ProfileSyncService will have already completed sync setup | 381 // An initialized ProfileSyncService will have already completed sync setup |
386 // and will have an initialized sync backend. | 382 // and will have an initialized sync backend. |
387 mock_signin_->SetAuthenticatedUsername(kTestUser); | 383 if (!mock_signin_->IsInitialized()) { |
| 384 profile_->GetPrefs()->SetString( |
| 385 prefs::kGoogleServicesUsername, kTestUser); |
| 386 mock_signin_->Initialize(profile_.get()); |
| 387 } |
388 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 388 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
389 .WillRepeatedly(Return(true)); | 389 .WillRepeatedly(Return(true)); |
390 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 390 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
391 .WillRepeatedly(Return(true)); | 391 .WillRepeatedly(Return(true)); |
392 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 392 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
393 .WillRepeatedly(Return(true)); | 393 .WillRepeatedly(Return(true)); |
394 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 394 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
395 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(true)); | 395 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(true)); |
396 } | 396 } |
397 | 397 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 LoginUIServiceFactory::GetForProfile( | 490 LoginUIServiceFactory::GetForProfile( |
491 profile_.get())->current_login_ui()); | 491 profile_.get())->current_login_ui()); |
492 } | 492 } |
493 } | 493 } |
494 | 494 |
495 // Verifies that the handler correctly handles a cancellation when | 495 // Verifies that the handler correctly handles a cancellation when |
496 // it is displaying the spinner to the user. | 496 // it is displaying the spinner to the user. |
497 TEST_P(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { | 497 TEST_P(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { |
498 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 498 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
499 .WillRepeatedly(Return(true)); | 499 .WillRepeatedly(Return(true)); |
500 mock_signin_->SetAuthenticatedUsername(kTestUser); | 500 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); |
| 501 mock_signin_->Initialize(profile_.get()); |
501 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 502 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
502 .WillRepeatedly(Return(true)); | 503 .WillRepeatedly(Return(true)); |
503 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 504 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
504 .WillRepeatedly(Return(false)); | 505 .WillRepeatedly(Return(false)); |
505 error_ = GoogleServiceAuthError::AuthErrorNone(); | 506 error_ = GoogleServiceAuthError::AuthErrorNone(); |
506 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 507 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
507 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); | 508 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); |
508 | 509 |
509 // We're simulating a user setting up sync, which would cause the backend to | 510 // We're simulating a user setting up sync, which would cause the backend to |
510 // kick off initialization, but not download user data types. The sync | 511 // kick off initialization, but not download user data types. The sync |
(...skipping 21 matching lines...) Expand all Loading... |
532 LoginUIServiceFactory::GetForProfile( | 533 LoginUIServiceFactory::GetForProfile( |
533 profile_.get())->current_login_ui()); | 534 profile_.get())->current_login_ui()); |
534 } | 535 } |
535 | 536 |
536 // Verifies that the handler correctly transitions from showing the spinner | 537 // Verifies that the handler correctly transitions from showing the spinner |
537 // to showing a configuration page when signin completes successfully. | 538 // to showing a configuration page when signin completes successfully. |
538 TEST_P(SyncSetupHandlerTest, | 539 TEST_P(SyncSetupHandlerTest, |
539 DisplayConfigureWithBackendDisabledAndSigninSuccess) { | 540 DisplayConfigureWithBackendDisabledAndSigninSuccess) { |
540 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 541 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
541 .WillRepeatedly(Return(true)); | 542 .WillRepeatedly(Return(true)); |
542 mock_signin_->SetAuthenticatedUsername(kTestUser); | 543 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); |
| 544 mock_signin_->Initialize(profile_.get()); |
543 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 545 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
544 .WillRepeatedly(Return(true)); | 546 .WillRepeatedly(Return(true)); |
545 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 547 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
546 .WillRepeatedly(Return(false)); | 548 .WillRepeatedly(Return(false)); |
547 error_ = GoogleServiceAuthError::AuthErrorNone(); | 549 error_ = GoogleServiceAuthError::AuthErrorNone(); |
548 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 550 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
549 // Sync backend is stopped initially, and will start up. | 551 // Sync backend is stopped initially, and will start up. |
550 EXPECT_CALL(*mock_pss_, sync_initialized()) | 552 EXPECT_CALL(*mock_pss_, sync_initialized()) |
551 .WillRepeatedly(Return(false)); | 553 .WillRepeatedly(Return(false)); |
552 SetDefaultExpectationsForConfigPage(); | 554 SetDefaultExpectationsForConfigPage(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 | 591 |
590 // Verifies the case where the user cancels after the sync backend has | 592 // Verifies the case where the user cancels after the sync backend has |
591 // initialized (meaning it already transitioned from the spinner to a proper | 593 // initialized (meaning it already transitioned from the spinner to a proper |
592 // configuration page, tested by | 594 // configuration page, tested by |
593 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user | 595 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user |
594 // before the user has continued on. | 596 // before the user has continued on. |
595 TEST_P(SyncSetupHandlerTest, | 597 TEST_P(SyncSetupHandlerTest, |
596 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { | 598 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { |
597 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 599 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
598 .WillRepeatedly(Return(true)); | 600 .WillRepeatedly(Return(true)); |
599 mock_signin_->SetAuthenticatedUsername(kTestUser); | 601 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); |
| 602 mock_signin_->Initialize(profile_.get()); |
600 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 603 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
601 .WillRepeatedly(Return(true)); | 604 .WillRepeatedly(Return(true)); |
602 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 605 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
603 .WillRepeatedly(Return(false)); | 606 .WillRepeatedly(Return(false)); |
604 error_ = GoogleServiceAuthError::AuthErrorNone(); | 607 error_ = GoogleServiceAuthError::AuthErrorNone(); |
605 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 608 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
606 EXPECT_CALL(*mock_pss_, sync_initialized()) | 609 EXPECT_CALL(*mock_pss_, sync_initialized()) |
607 .WillOnce(Return(false)) | 610 .WillOnce(Return(false)) |
608 .WillRepeatedly(Return(true)); | 611 .WillRepeatedly(Return(true)); |
609 SetDefaultExpectationsForConfigPage(); | 612 SetDefaultExpectationsForConfigPage(); |
610 handler_->OpenSyncSetup(); | 613 handler_->OpenSyncSetup(); |
611 handler_->SigninSuccess(); | 614 handler_->SigninSuccess(); |
612 | 615 |
613 // It's important to tell sync the user cancelled the setup flow before we | 616 // It's important to tell sync the user cancelled the setup flow before we |
614 // tell it we're through with the setup progress. | 617 // tell it we're through with the setup progress. |
615 testing::InSequence seq; | 618 testing::InSequence seq; |
616 EXPECT_CALL(*mock_pss_, DisableForUser()); | 619 EXPECT_CALL(*mock_pss_, DisableForUser()); |
617 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false)); | 620 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false)); |
618 | 621 |
619 handler_->CloseSyncSetup(); | 622 handler_->CloseSyncSetup(); |
620 EXPECT_EQ(NULL, | 623 EXPECT_EQ(NULL, |
621 LoginUIServiceFactory::GetForProfile( | 624 LoginUIServiceFactory::GetForProfile( |
622 profile_.get())->current_login_ui()); | 625 profile_.get())->current_login_ui()); |
623 } | 626 } |
624 | 627 |
625 TEST_P(SyncSetupHandlerTest, | 628 TEST_P(SyncSetupHandlerTest, |
626 DisplayConfigureWithBackendDisabledAndSigninFalied) { | 629 DisplayConfigureWithBackendDisabledAndSigninFalied) { |
627 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 630 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
628 .WillRepeatedly(Return(true)); | 631 .WillRepeatedly(Return(true)); |
629 mock_signin_->SetAuthenticatedUsername(kTestUser); | 632 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); |
| 633 mock_signin_->Initialize(profile_.get()); |
630 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 634 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
631 .WillRepeatedly(Return(true)); | 635 .WillRepeatedly(Return(true)); |
632 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 636 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
633 .WillRepeatedly(Return(false)); | 637 .WillRepeatedly(Return(false)); |
634 error_ = GoogleServiceAuthError::AuthErrorNone(); | 638 error_ = GoogleServiceAuthError::AuthErrorNone(); |
635 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 639 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
636 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); | 640 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); |
637 | 641 |
638 handler_->OpenSyncSetup(); | 642 handler_->OpenSyncSetup(); |
639 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 643 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
640 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 644 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
641 std::string page; | 645 std::string page; |
642 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 646 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
643 EXPECT_EQ(page, "spinner"); | 647 EXPECT_EQ(page, "spinner"); |
644 GoogleServiceAuthError error( | 648 GoogleServiceAuthError error( |
645 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 649 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
646 handler_->SigninFailed(error); | 650 handler_->SigninFailed(error); |
647 // On failure, the dialog will be closed. | 651 // On failure, the dialog will be closed. |
648 EXPECT_EQ(NULL, | 652 EXPECT_EQ(NULL, |
649 LoginUIServiceFactory::GetForProfile( | 653 LoginUIServiceFactory::GetForProfile( |
650 profile_.get())->current_login_ui()); | 654 profile_.get())->current_login_ui()); |
651 } | 655 } |
652 | 656 |
653 #if !defined(OS_CHROMEOS) | 657 #if !defined(OS_CHROMEOS) |
654 | 658 |
655 namespace { | |
656 class SigninManagerMock : public FakeSigninManager { | |
657 public: | |
658 explicit SigninManagerMock(Profile* profile) : FakeSigninManager(profile) { | |
659 } | |
660 | |
661 virtual void StartSignIn(const std::string& username, | |
662 const std::string& password, | |
663 const std::string& login_token, | |
664 const std::string& login_captcha) OVERRIDE { | |
665 SetAuthenticatedUsername(username); | |
666 } | |
667 | |
668 MOCK_CONST_METHOD1(IsAllowedUsername, bool(const std::string& username)); | |
669 }; | |
670 } | |
671 | |
672 static ProfileKeyedService* BuildSigninManagerMock( | |
673 content::BrowserContext* profile) { | |
674 return new SigninManagerMock(static_cast<Profile*>(profile)); | |
675 } | |
676 | |
677 class SyncSetupHandlerNonCrosTest : public SyncSetupHandlerTest { | 659 class SyncSetupHandlerNonCrosTest : public SyncSetupHandlerTest { |
678 public: | 660 public: |
679 SyncSetupHandlerNonCrosTest() {} | 661 SyncSetupHandlerNonCrosTest() {} |
680 virtual void SetUp() OVERRIDE { | 662 virtual void SetUp() OVERRIDE { |
681 SyncSetupHandlerTest::SetUp(); | 663 SyncSetupHandlerTest::SetUp(); |
682 mock_signin_ = static_cast<SigninManagerMock*>( | 664 mock_signin_ = static_cast<SigninManagerBase*>( |
683 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 665 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
684 profile_.get(), BuildSigninManagerMock)); | 666 profile_.get(), FakeSigninManager::Build)); |
685 } | 667 } |
686 }; | 668 }; |
687 | 669 |
688 TEST_P(SyncSetupHandlerNonCrosTest, HandleGaiaAuthFailure) { | 670 TEST_P(SyncSetupHandlerNonCrosTest, HandleGaiaAuthFailure) { |
689 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 671 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
690 .WillRepeatedly(Return(false)); | 672 .WillRepeatedly(Return(false)); |
691 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 673 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
692 .WillRepeatedly(Return(false)); | 674 .WillRepeatedly(Return(false)); |
693 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 675 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
694 .WillRepeatedly(Return(false)); | 676 .WillRepeatedly(Return(false)); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 // complete yet). | 770 // complete yet). |
789 handler_->TryLogin(kTestUser, kTestPassword, std::string(), std::string()); | 771 handler_->TryLogin(kTestUser, kTestPassword, std::string(), std::string()); |
790 handler_->GaiaCredentialsValid(); | 772 handler_->GaiaCredentialsValid(); |
791 ASSERT_EQ(2U, web_ui_.call_data().size()); | 773 ASSERT_EQ(2U, web_ui_.call_data().size()); |
792 EXPECT_EQ("SyncSetupOverlay.showSuccessAndSettingUp", | 774 EXPECT_EQ("SyncSetupOverlay.showSuccessAndSettingUp", |
793 web_ui_.call_data()[1].function_name); | 775 web_ui_.call_data()[1].function_name); |
794 // Now fake a sync error. | 776 // Now fake a sync error. |
795 GoogleServiceAuthError none(GoogleServiceAuthError::NONE); | 777 GoogleServiceAuthError none(GoogleServiceAuthError::NONE); |
796 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 778 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
797 .WillRepeatedly(Return(true)); | 779 .WillRepeatedly(Return(true)); |
798 mock_signin_->SignOut(); | 780 // On non-Cros platforms, we use SigninManager. |
| 781 static_cast<SigninManager*>(mock_signin_)->SignOut(); |
799 handler_->SigninFailed(none); | 782 handler_->SigninFailed(none); |
800 ASSERT_EQ(3U, web_ui_.call_data().size()); | 783 ASSERT_EQ(3U, web_ui_.call_data().size()); |
801 // Validate the second JS call (the first call was already tested by | 784 // Validate the second JS call (the first call was already tested by |
802 // the DisplayBasicLogin test). | 785 // the DisplayBasicLogin test). |
803 const TestWebUI::CallData& data = web_ui_.call_data()[2]; | 786 const TestWebUI::CallData& data = web_ui_.call_data()[2]; |
804 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 787 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
805 std::string page; | 788 std::string page; |
806 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 789 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
807 EXPECT_EQ(page, "login"); | 790 EXPECT_EQ(page, "login"); |
808 // Now make sure that the appropriate params are being passed. | 791 // Now make sure that the appropriate params are being passed. |
(...skipping 29 matching lines...) Expand all Loading... |
838 handler_->TryLogin(kTestUser, kTestPassword, std::string(), std::string()); | 821 handler_->TryLogin(kTestUser, kTestPassword, std::string(), std::string()); |
839 handler_->GaiaCredentialsValid(); | 822 handler_->GaiaCredentialsValid(); |
840 ASSERT_EQ(2U, web_ui_.call_data().size()); | 823 ASSERT_EQ(2U, web_ui_.call_data().size()); |
841 EXPECT_EQ("SyncSetupOverlay.showSuccessAndSettingUp", | 824 EXPECT_EQ("SyncSetupOverlay.showSuccessAndSettingUp", |
842 web_ui_.call_data()[1].function_name); | 825 web_ui_.call_data()[1].function_name); |
843 // Now fake a sync gaia error. | 826 // Now fake a sync gaia error. |
844 GoogleServiceAuthError unavailable( | 827 GoogleServiceAuthError unavailable( |
845 GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 828 GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
846 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 829 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
847 .WillRepeatedly(Return(false)); | 830 .WillRepeatedly(Return(false)); |
848 mock_signin_->SignOut(); | 831 // On non-Cros platforms, we use SigninManager. |
| 832 static_cast<SigninManager*>(mock_signin_)->SignOut(); |
849 handler_->SigninFailed(unavailable); | 833 handler_->SigninFailed(unavailable); |
850 ASSERT_EQ(3U, web_ui_.call_data().size()); | 834 ASSERT_EQ(3U, web_ui_.call_data().size()); |
851 // Validate the second JS call (the first call was already tested by | 835 // Validate the second JS call (the first call was already tested by |
852 // the DisplayBasicLogin test). | 836 // the DisplayBasicLogin test). |
853 const TestWebUI::CallData& data = web_ui_.call_data()[2]; | 837 const TestWebUI::CallData& data = web_ui_.call_data()[2]; |
854 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 838 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
855 std::string page; | 839 std::string page; |
856 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 840 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
857 EXPECT_EQ(page, "login"); | 841 EXPECT_EQ(page, "login"); |
858 // Now make sure that the appropriate params are being passed. | 842 // Now make sure that the appropriate params are being passed. |
859 DictionaryValue* dictionary; | 843 DictionaryValue* dictionary; |
860 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 844 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
861 CheckShowSyncSetupArgs(dictionary, | 845 CheckShowSyncSetupArgs(dictionary, |
862 std::string(), | 846 std::string(), |
863 false, | 847 false, |
864 GoogleServiceAuthError::SERVICE_UNAVAILABLE, | 848 GoogleServiceAuthError::SERVICE_UNAVAILABLE, |
865 kTestUser, | 849 kTestUser, |
866 true, | 850 true, |
867 std::string()); | 851 std::string()); |
868 } else { | 852 } else { |
869 ASSERT_FALSE(handler_->is_configuring_sync()); | 853 ASSERT_FALSE(handler_->is_configuring_sync()); |
870 ASSERT_TRUE(handler_->have_signin_tracker()); | 854 ASSERT_TRUE(handler_->have_signin_tracker()); |
871 } | 855 } |
872 } | 856 } |
873 | 857 |
874 // Tests that trying to log in with an invalid username results in an error | 858 // Tests that trying to log in with an invalid username results in an error |
875 // displayed to the user. | 859 // displayed to the user. |
876 TEST_P(SyncSetupHandlerNonCrosTest, SubmitAuthWithInvalidUsername) { | 860 TEST_P(SyncSetupHandlerNonCrosTest, SubmitAuthWithInvalidUsername) { |
877 SigninManagerMock* mock_signin = | 861 ScopedTestingLocalState local_state( |
878 static_cast<SigninManagerMock*>(mock_signin_); | 862 TestingBrowserProcess::GetGlobal()); |
879 EXPECT_CALL(*mock_signin, IsAllowedUsername(_)). | 863 local_state.Get()->SetString( |
880 WillRepeatedly(Return(false)); | 864 prefs::kGoogleServicesUsernamePattern, ".*@valid.com"); |
881 | 865 |
882 // Generate a blob of json that matches what would be submitted by the login | 866 // Generate a blob of json that matches what would be submitted by the login |
883 // javascript code. | 867 // javascript code. |
884 DictionaryValue args; | 868 DictionaryValue args; |
885 args.SetString("user", "user@not_allowed.com"); | 869 args.SetString("user", "user@not_allowed.com"); |
886 args.SetString("pass", "password"); | 870 args.SetString("pass", "password"); |
887 args.SetString("captcha", std::string()); | 871 args.SetString("captcha", std::string()); |
888 args.SetString("otp", std::string()); | 872 args.SetString("otp", std::string()); |
889 args.SetString("accessCode", std::string()); | 873 args.SetString("accessCode", std::string()); |
890 std::string json; | 874 std::string json; |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 ExpectConfig(); | 1306 ExpectConfig(); |
1323 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 1307 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
1324 DictionaryValue* dictionary; | 1308 DictionaryValue* dictionary; |
1325 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 1309 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
1326 CheckBool(dictionary, "encryptAllData", true); | 1310 CheckBool(dictionary, "encryptAllData", true); |
1327 } | 1311 } |
1328 | 1312 |
1329 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam, | 1313 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam, |
1330 SyncSetupHandlerTest, | 1314 SyncSetupHandlerTest, |
1331 Values(true, false)); | 1315 Values(true, false)); |
OLD | NEW |