| 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/signin_manager.h" |
| 17 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
| 18 #include "chrome/browser/signin/signin_manager_fake.h" | 19 #include "chrome/browser/signin/signin_manager_fake.h" |
| 19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 20 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 20 #include "chrome/browser/sync/profile_sync_service_mock.h" | 21 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 21 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 22 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 22 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 23 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 23 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 24 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
| 24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 using SyncSetupHandler::have_signin_tracker; | 325 using SyncSetupHandler::have_signin_tracker; |
| 325 | 326 |
| 326 private: | 327 private: |
| 327 virtual void DisplayGaiaLoginInNewTabOrWindow() OVERRIDE {} | 328 virtual void DisplayGaiaLoginInNewTabOrWindow() OVERRIDE {} |
| 328 | 329 |
| 329 // Weak pointer to parent profile. | 330 // Weak pointer to parent profile. |
| 330 Profile* profile_; | 331 Profile* profile_; |
| 331 DISALLOW_COPY_AND_ASSIGN(TestingSyncSetupHandler); | 332 DISALLOW_COPY_AND_ASSIGN(TestingSyncSetupHandler); |
| 332 }; | 333 }; |
| 333 | 334 |
| 334 class SigninManagerMock : public FakeSigninManager { | 335 class SigninManagerBaseMock : public FakeSigninManagerBase { |
| 335 public: | 336 public: |
| 336 explicit SigninManagerMock(Profile* profile) : FakeSigninManager(profile) {} | 337 explicit SigninManagerBaseMock(Profile* profile) |
| 338 : FakeSigninManagerBase(profile) {} |
| 337 MOCK_CONST_METHOD1(IsAllowedUsername, bool(const std::string& username)); | 339 MOCK_CONST_METHOD1(IsAllowedUsername, bool(const std::string& username)); |
| 338 }; | 340 }; |
| 339 | 341 |
| 340 static ProfileKeyedService* BuildSigninManagerMock(Profile* profile) { | 342 static ProfileKeyedService* BuildSigninManagerBaseMock(Profile* profile) { |
| 341 return new SigninManagerMock(profile); | 343 return new SigninManagerBaseMock(profile); |
| 342 } | 344 } |
| 343 | 345 |
| 344 // The boolean parameter indicates whether the test is run with ClientOAuth | 346 // The boolean parameter indicates whether the test is run with ClientOAuth |
| 345 // or not. The test parameter is a bool: whether or not to test with/ | 347 // or not. The test parameter is a bool: whether or not to test with/ |
| 346 // /ClientLogin enabled or not. | 348 // /ClientLogin enabled or not. |
| 347 class SyncSetupHandlerTest : public testing::TestWithParam<bool> { | 349 class SyncSetupHandlerTest : public testing::TestWithParam<bool> { |
| 348 public: | 350 public: |
| 349 SyncSetupHandlerTest() : error_(GoogleServiceAuthError::NONE) {} | 351 SyncSetupHandlerTest() : error_(GoogleServiceAuthError::NONE) {} |
| 350 virtual void SetUp() OVERRIDE { | 352 virtual void SetUp() OVERRIDE { |
| 351 bool use_client_login_flow = GetParam(); | 353 bool use_client_login_flow = GetParam(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 365 mock_pss_ = static_cast<ProfileSyncServiceMock*>( | 367 mock_pss_ = static_cast<ProfileSyncServiceMock*>( |
| 366 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 368 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 367 profile_.get(), | 369 profile_.get(), |
| 368 ProfileSyncServiceMock::BuildMockProfileSyncService)); | 370 ProfileSyncServiceMock::BuildMockProfileSyncService)); |
| 369 mock_pss_->Initialize(); | 371 mock_pss_->Initialize(); |
| 370 | 372 |
| 371 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault( | 373 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault( |
| 372 Return(syncer::IMPLICIT_PASSPHRASE)); | 374 Return(syncer::IMPLICIT_PASSPHRASE)); |
| 373 ON_CALL(*mock_pss_, GetPassphraseTime()).WillByDefault( | 375 ON_CALL(*mock_pss_, GetPassphraseTime()).WillByDefault( |
| 374 Return(base::Time())); | 376 Return(base::Time())); |
| 375 mock_signin_ = static_cast<SigninManagerMock*>( | 377 mock_signin_ = static_cast<SigninManagerBase*>( |
| 376 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 378 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 377 profile_.get(), BuildSigninManagerMock)); | 379 profile_.get(), BuildSigninManagerBaseMock)); |
| 378 handler_.reset(new TestingSyncSetupHandler(&web_ui_, profile_.get())); | 380 handler_.reset(new TestingSyncSetupHandler(&web_ui_, profile_.get())); |
| 379 } | 381 } |
| 380 | 382 |
| 381 // Setup the expectations for calls made when displaying the config page. | 383 // Setup the expectations for calls made when displaying the config page. |
| 382 void SetDefaultExpectationsForConfigPage() { | 384 void SetDefaultExpectationsForConfigPage() { |
| 383 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()). | 385 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()). |
| 384 WillRepeatedly(Return(GetAllTypes())); | 386 WillRepeatedly(Return(GetAllTypes())); |
| 385 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()). | 387 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()). |
| 386 WillRepeatedly(Return(GetAllTypes())); | 388 WillRepeatedly(Return(GetAllTypes())); |
| 387 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()). | 389 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()). |
| (...skipping 30 matching lines...) Expand all Loading... |
| 418 std::string page; | 420 std::string page; |
| 419 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 421 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
| 420 EXPECT_EQ(page, "done"); | 422 EXPECT_EQ(page, "done"); |
| 421 } | 423 } |
| 422 | 424 |
| 423 scoped_ptr<Profile> profile_; | 425 scoped_ptr<Profile> profile_; |
| 424 ProfileSyncServiceMock* mock_pss_; | 426 ProfileSyncServiceMock* mock_pss_; |
| 425 GoogleServiceAuthError error_; | 427 GoogleServiceAuthError error_; |
| 426 // MessageLoop instance is required to work with OneShotTimer. | 428 // MessageLoop instance is required to work with OneShotTimer. |
| 427 MessageLoop message_loop_; | 429 MessageLoop message_loop_; |
| 428 SigninManagerMock* mock_signin_; | 430 SigninManagerBase* mock_signin_; |
| 429 TestWebUI web_ui_; | 431 TestWebUI web_ui_; |
| 430 scoped_ptr<TestingSyncSetupHandler> handler_; | 432 scoped_ptr<TestingSyncSetupHandler> handler_; |
| 431 }; | 433 }; |
| 432 | 434 |
| 433 TEST_P(SyncSetupHandlerTest, Basic) { | 435 TEST_P(SyncSetupHandlerTest, Basic) { |
| 434 } | 436 } |
| 435 | 437 |
| 436 TEST_P(SyncSetupHandlerTest, DisplayBasicLogin) { | 438 TEST_P(SyncSetupHandlerTest, DisplayBasicLogin) { |
| 437 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 439 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 438 .WillRepeatedly(Return(false)); | 440 .WillRepeatedly(Return(false)); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 EXPECT_EQ(page, "spinner"); | 658 EXPECT_EQ(page, "spinner"); |
| 657 GoogleServiceAuthError error( | 659 GoogleServiceAuthError error( |
| 658 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 660 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 659 handler_->SigninFailed(error); | 661 handler_->SigninFailed(error); |
| 660 // On failure, the dialog will be closed. | 662 // On failure, the dialog will be closed. |
| 661 EXPECT_EQ(NULL, | 663 EXPECT_EQ(NULL, |
| 662 LoginUIServiceFactory::GetForProfile( | 664 LoginUIServiceFactory::GetForProfile( |
| 663 profile_.get())->current_login_ui()); | 665 profile_.get())->current_login_ui()); |
| 664 } | 666 } |
| 665 | 667 |
| 666 TEST_P(SyncSetupHandlerTest, HandleGaiaAuthFailure) { | 668 #if !defined(OS_CHROMEOS) |
| 669 |
| 670 namespace { |
| 671 class SigninManagerMock : public FakeSigninManager { |
| 672 public: |
| 673 explicit SigninManagerMock(Profile* profile) : FakeSigninManager(profile) { |
| 674 } |
| 675 |
| 676 virtual void StartSignIn(const std::string& username, |
| 677 const std::string& password, |
| 678 const std::string& login_token, |
| 679 const std::string& login_captcha) OVERRIDE { |
| 680 SetAuthenticatedUsername(username); |
| 681 } |
| 682 |
| 683 MOCK_CONST_METHOD1(IsAllowedUsername, bool(const std::string& username)); |
| 684 }; |
| 685 } |
| 686 |
| 687 static ProfileKeyedService* BuildSigninManagerMock(Profile* profile) { |
| 688 return new SigninManagerMock(profile); |
| 689 } |
| 690 |
| 691 class SyncSetupHandlerNonCrosTest : public SyncSetupHandlerTest { |
| 692 public: |
| 693 SyncSetupHandlerNonCrosTest() {} |
| 694 virtual void SetUp() OVERRIDE { |
| 695 SyncSetupHandlerTest::SetUp(); |
| 696 mock_signin_ = static_cast<SigninManagerMock*>( |
| 697 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 698 profile_.get(), BuildSigninManagerMock)); |
| 699 } |
| 700 }; |
| 701 |
| 702 TEST_P(SyncSetupHandlerNonCrosTest, HandleGaiaAuthFailure) { |
| 667 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 703 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 668 .WillRepeatedly(Return(false)); | 704 .WillRepeatedly(Return(false)); |
| 669 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 705 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 670 .WillRepeatedly(Return(false)); | 706 .WillRepeatedly(Return(false)); |
| 671 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 707 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
| 672 .WillRepeatedly(Return(false)); | 708 .WillRepeatedly(Return(false)); |
| 673 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 709 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 674 .WillRepeatedly(Return(false)); | 710 .WillRepeatedly(Return(false)); |
| 675 // Open the web UI. | 711 // Open the web UI. |
| 676 handler_->OpenSyncSetup(false); | 712 handler_->OpenSyncSetup(false); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 695 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 731 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 696 CheckShowSyncSetupArgs( | 732 CheckShowSyncSetupArgs( |
| 697 dictionary, "", false, GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, | 733 dictionary, "", false, GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, |
| 698 kTestUser, true, ""); | 734 kTestUser, true, ""); |
| 699 } else { | 735 } else { |
| 700 ASSERT_FALSE(handler_->is_configuring_sync()); | 736 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 701 ASSERT_TRUE(handler_->have_signin_tracker()); | 737 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 702 } | 738 } |
| 703 } | 739 } |
| 704 | 740 |
| 705 TEST_P(SyncSetupHandlerTest, HandleCaptcha) { | 741 TEST_P(SyncSetupHandlerNonCrosTest, HandleCaptcha) { |
| 706 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 742 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 707 .WillRepeatedly(Return(false)); | 743 .WillRepeatedly(Return(false)); |
| 708 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 744 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 709 .WillRepeatedly(Return(false)); | 745 .WillRepeatedly(Return(false)); |
| 710 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 746 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
| 711 .WillRepeatedly(Return(false)); | 747 .WillRepeatedly(Return(false)); |
| 712 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 748 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 713 .WillRepeatedly(Return(false)); | 749 .WillRepeatedly(Return(false)); |
| 714 // Open the web UI. | 750 // Open the web UI. |
| 715 handler_->OpenSyncSetup(false); | 751 handler_->OpenSyncSetup(false); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 735 CheckShowSyncSetupArgs( | 771 CheckShowSyncSetupArgs( |
| 736 dictionary, "", false, GoogleServiceAuthError::CAPTCHA_REQUIRED, | 772 dictionary, "", false, GoogleServiceAuthError::CAPTCHA_REQUIRED, |
| 737 kTestUser, true, kTestCaptchaImageUrl); | 773 kTestUser, true, kTestCaptchaImageUrl); |
| 738 } else { | 774 } else { |
| 739 ASSERT_FALSE(handler_->is_configuring_sync()); | 775 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 740 ASSERT_TRUE(handler_->have_signin_tracker()); | 776 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 741 } | 777 } |
| 742 } | 778 } |
| 743 | 779 |
| 744 // TODO(kochi): We need equivalent tests for ChromeOS. | 780 // TODO(kochi): We need equivalent tests for ChromeOS. |
| 745 TEST_P(SyncSetupHandlerTest, UnrecoverableErrorInitializingSync) { | 781 TEST_P(SyncSetupHandlerNonCrosTest, UnrecoverableErrorInitializingSync) { |
| 746 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 782 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 747 .WillRepeatedly(Return(false)); | 783 .WillRepeatedly(Return(false)); |
| 748 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 784 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 749 .WillRepeatedly(Return(false)); | 785 .WillRepeatedly(Return(false)); |
| 750 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 786 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 751 .WillRepeatedly(Return(false)); | 787 .WillRepeatedly(Return(false)); |
| 752 // Open the web UI. | 788 // Open the web UI. |
| 753 handler_->OpenSyncSetup(false); | 789 handler_->OpenSyncSetup(false); |
| 754 | 790 |
| 755 if (!SyncPromoUI::UseWebBasedSigninFlow()) { | 791 if (!SyncPromoUI::UseWebBasedSigninFlow()) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 780 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 816 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 781 CheckShowSyncSetupArgs( | 817 CheckShowSyncSetupArgs( |
| 782 dictionary, "", true, GoogleServiceAuthError::NONE, | 818 dictionary, "", true, GoogleServiceAuthError::NONE, |
| 783 kTestUser, true, ""); | 819 kTestUser, true, ""); |
| 784 } else { | 820 } else { |
| 785 ASSERT_FALSE(handler_->is_configuring_sync()); | 821 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 786 ASSERT_TRUE(handler_->have_signin_tracker()); | 822 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 787 } | 823 } |
| 788 } | 824 } |
| 789 | 825 |
| 790 TEST_P(SyncSetupHandlerTest, GaiaErrorInitializingSync) { | 826 TEST_P(SyncSetupHandlerNonCrosTest, GaiaErrorInitializingSync) { |
| 791 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 827 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 792 .WillRepeatedly(Return(false)); | 828 .WillRepeatedly(Return(false)); |
| 793 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 829 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 794 .WillRepeatedly(Return(false)); | 830 .WillRepeatedly(Return(false)); |
| 795 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 831 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 796 .WillRepeatedly(Return(false)); | 832 .WillRepeatedly(Return(false)); |
| 797 // Open the web UI. | 833 // Open the web UI. |
| 798 handler_->OpenSyncSetup(false); | 834 handler_->OpenSyncSetup(false); |
| 799 | 835 |
| 800 if (!SyncPromoUI::UseWebBasedSigninFlow()) { | 836 if (!SyncPromoUI::UseWebBasedSigninFlow()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 826 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 862 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 827 CheckShowSyncSetupArgs( | 863 CheckShowSyncSetupArgs( |
| 828 dictionary, "", false, GoogleServiceAuthError::SERVICE_UNAVAILABLE, | 864 dictionary, "", false, GoogleServiceAuthError::SERVICE_UNAVAILABLE, |
| 829 kTestUser, true, ""); | 865 kTestUser, true, ""); |
| 830 } else { | 866 } else { |
| 831 ASSERT_FALSE(handler_->is_configuring_sync()); | 867 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 832 ASSERT_TRUE(handler_->have_signin_tracker()); | 868 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 833 } | 869 } |
| 834 } | 870 } |
| 835 | 871 |
| 872 // Tests that trying to log in with an invalid username results in an error |
| 873 // displayed to the user. |
| 874 TEST_P(SyncSetupHandlerNonCrosTest, SubmitAuthWithInvalidUsername) { |
| 875 SigninManagerMock* mock_signin = |
| 876 static_cast<SigninManagerMock*>(mock_signin_); |
| 877 EXPECT_CALL(*mock_signin, IsAllowedUsername(_)). |
| 878 WillRepeatedly(Return(false)); |
| 879 |
| 880 // Generate a blob of json that matches what would be submitted by the login |
| 881 // javascript code. |
| 882 DictionaryValue args; |
| 883 args.SetString("user", "user@not_allowed.com"); |
| 884 args.SetString("pass", "password"); |
| 885 args.SetString("captcha", ""); |
| 886 args.SetString("otp", ""); |
| 887 args.SetString("accessCode", ""); |
| 888 std::string json; |
| 889 base::JSONWriter::Write(&args, &json); |
| 890 ListValue list_args; |
| 891 list_args.Append(new StringValue(json)); |
| 892 |
| 893 // Mimic a login attempt from the UI. |
| 894 handler_->HandleSubmitAuth(&list_args); |
| 895 |
| 896 // Should result in the login page being displayed again. |
| 897 ASSERT_EQ(1U, web_ui_.call_data().size()); |
| 898 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 899 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
| 900 std::string page; |
| 901 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
| 902 EXPECT_EQ(page, "login"); |
| 903 |
| 904 // Also make sure that the appropriate error message is being passed. |
| 905 DictionaryValue* dictionary; |
| 906 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 907 std::string err = l10n_util::GetStringUTF8(IDS_SYNC_LOGIN_NAME_PROHIBITED); |
| 908 CheckShowSyncSetupArgs( |
| 909 dictionary, err, false, GoogleServiceAuthError::NONE, "", true, ""); |
| 910 handler_->CloseSyncSetup(); |
| 911 EXPECT_EQ(NULL, |
| 912 LoginUIServiceFactory::GetForProfile( |
| 913 profile_.get())->current_login_ui()); |
| 914 } |
| 915 |
| 916 #endif // #if !defined(OS_CHROMEOS) |
| 917 |
| 836 TEST_P(SyncSetupHandlerTest, TestSyncEverything) { | 918 TEST_P(SyncSetupHandlerTest, TestSyncEverything) { |
| 837 std::string args = GetConfiguration( | 919 std::string args = GetConfiguration( |
| 838 NULL, SYNC_ALL_DATA, GetAllTypes(), "", ENCRYPT_PASSWORDS); | 920 NULL, SYNC_ALL_DATA, GetAllTypes(), "", ENCRYPT_PASSWORDS); |
| 839 ListValue list_args; | 921 ListValue list_args; |
| 840 list_args.Append(new StringValue(args)); | 922 list_args.Append(new StringValue(args)); |
| 841 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 923 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
| 842 .WillRepeatedly(Return(false)); | 924 .WillRepeatedly(Return(false)); |
| 843 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 925 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 844 .WillRepeatedly(Return(false)); | 926 .WillRepeatedly(Return(false)); |
| 845 SetupInitializedProfileSyncService(); | 927 SetupInitializedProfileSyncService(); |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 // This should display the sync setup dialog (not login). | 1306 // This should display the sync setup dialog (not login). |
| 1225 handler_->OpenSyncSetup(false); | 1307 handler_->OpenSyncSetup(false); |
| 1226 | 1308 |
| 1227 ExpectConfig(); | 1309 ExpectConfig(); |
| 1228 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 1310 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 1229 DictionaryValue* dictionary; | 1311 DictionaryValue* dictionary; |
| 1230 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 1312 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 1231 CheckBool(dictionary, "encryptAllData", true); | 1313 CheckBool(dictionary, "encryptAllData", true); |
| 1232 } | 1314 } |
| 1233 | 1315 |
| 1234 // Tests that trying to log in with an invalid username results in an error | |
| 1235 // displayed to the user. | |
| 1236 TEST_P(SyncSetupHandlerTest, SubmitAuthWithInvalidUsername) { | |
| 1237 EXPECT_CALL(*mock_signin_, IsAllowedUsername(_)). | |
| 1238 WillRepeatedly(Return(false)); | |
| 1239 | |
| 1240 // Generate a blob of json that matches what would be submitted by the login | |
| 1241 // javascript code. | |
| 1242 DictionaryValue args; | |
| 1243 args.SetString("user", "user@not_allowed.com"); | |
| 1244 args.SetString("pass", "password"); | |
| 1245 args.SetString("captcha", ""); | |
| 1246 args.SetString("otp", ""); | |
| 1247 args.SetString("accessCode", ""); | |
| 1248 std::string json; | |
| 1249 base::JSONWriter::Write(&args, &json); | |
| 1250 ListValue list_args; | |
| 1251 list_args.Append(new StringValue(json)); | |
| 1252 | |
| 1253 // Mimic a login attempt from the UI. | |
| 1254 handler_->HandleSubmitAuth(&list_args); | |
| 1255 | |
| 1256 // Should result in the login page being displayed again. | |
| 1257 ASSERT_EQ(1U, web_ui_.call_data().size()); | |
| 1258 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | |
| 1259 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | |
| 1260 std::string page; | |
| 1261 ASSERT_TRUE(data.arg1->GetAsString(&page)); | |
| 1262 EXPECT_EQ(page, "login"); | |
| 1263 | |
| 1264 // Also make sure that the appropriate error message is being passed. | |
| 1265 DictionaryValue* dictionary; | |
| 1266 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | |
| 1267 std::string err = l10n_util::GetStringUTF8(IDS_SYNC_LOGIN_NAME_PROHIBITED); | |
| 1268 CheckShowSyncSetupArgs( | |
| 1269 dictionary, err, false, GoogleServiceAuthError::NONE, "", true, ""); | |
| 1270 handler_->CloseSyncSetup(); | |
| 1271 EXPECT_EQ(NULL, | |
| 1272 LoginUIServiceFactory::GetForProfile( | |
| 1273 profile_.get())->current_login_ui()); | |
| 1274 } | |
| 1275 | |
| 1276 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam, | 1316 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam, |
| 1277 SyncSetupHandlerTest, | 1317 SyncSetupHandlerTest, |
| 1278 Values(true, false)); | 1318 Values(true, false)); |
| OLD | NEW |