| 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" |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 if (!SyncPromoUI::UseWebBasedSigninFlow()) { | 450 if (!SyncPromoUI::UseWebBasedSigninFlow()) { |
| 451 ASSERT_EQ(1U, web_ui_.call_data().size()); | 451 ASSERT_EQ(1U, web_ui_.call_data().size()); |
| 452 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 452 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 453 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 453 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
| 454 std::string page; | 454 std::string page; |
| 455 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 455 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
| 456 EXPECT_EQ(page, "login"); | 456 EXPECT_EQ(page, "login"); |
| 457 // Now make sure that the appropriate params are being passed. | 457 // Now make sure that the appropriate params are being passed. |
| 458 DictionaryValue* dictionary; | 458 DictionaryValue* dictionary; |
| 459 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 459 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 460 CheckShowSyncSetupArgs( | 460 CheckShowSyncSetupArgs(dictionary, |
| 461 dictionary, "", false, GoogleServiceAuthError::NONE, "", true, ""); | 461 std::string(), |
| 462 false, |
| 463 GoogleServiceAuthError::NONE, |
| 464 std::string(), |
| 465 true, |
| 466 std::string()); |
| 462 } else { | 467 } else { |
| 463 ASSERT_FALSE(handler_->is_configuring_sync()); | 468 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 464 ASSERT_TRUE(handler_->have_signin_tracker()); | 469 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 465 } | 470 } |
| 466 | 471 |
| 467 handler_->CloseSyncSetup(); | 472 handler_->CloseSyncSetup(); |
| 468 EXPECT_EQ(NULL, | 473 EXPECT_EQ(NULL, |
| 469 LoginUIServiceFactory::GetForProfile( | 474 LoginUIServiceFactory::GetForProfile( |
| 470 profile_.get())->current_login_ui()); | 475 profile_.get())->current_login_ui()); |
| 471 } | 476 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 487 if (!SyncPromoUI::UseWebBasedSigninFlow()) { | 492 if (!SyncPromoUI::UseWebBasedSigninFlow()) { |
| 488 ASSERT_EQ(1U, web_ui_.call_data().size()); | 493 ASSERT_EQ(1U, web_ui_.call_data().size()); |
| 489 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 494 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 490 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 495 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
| 491 std::string page; | 496 std::string page; |
| 492 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 497 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
| 493 EXPECT_EQ(page, "login"); | 498 EXPECT_EQ(page, "login"); |
| 494 // Now make sure that the appropriate params are being passed. | 499 // Now make sure that the appropriate params are being passed. |
| 495 DictionaryValue* dictionary; | 500 DictionaryValue* dictionary; |
| 496 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 501 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 497 CheckShowSyncSetupArgs( | 502 CheckShowSyncSetupArgs(dictionary, |
| 498 dictionary, "", false, GoogleServiceAuthError::NONE, "", true, ""); | 503 std::string(), |
| 504 false, |
| 505 GoogleServiceAuthError::NONE, |
| 506 std::string(), |
| 507 true, |
| 508 std::string()); |
| 499 } else { | 509 } else { |
| 500 ASSERT_FALSE(handler_->is_configuring_sync()); | 510 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 501 ASSERT_TRUE(handler_->have_signin_tracker()); | 511 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 502 } | 512 } |
| 503 | 513 |
| 504 handler_->CloseSyncSetup(); | 514 handler_->CloseSyncSetup(); |
| 505 EXPECT_EQ(NULL, | 515 EXPECT_EQ(NULL, |
| 506 LoginUIServiceFactory::GetForProfile( | 516 LoginUIServiceFactory::GetForProfile( |
| 507 profile_.get())->current_login_ui()); | 517 profile_.get())->current_login_ui()); |
| 508 } | 518 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 .WillRepeatedly(Return(false)); | 682 .WillRepeatedly(Return(false)); |
| 673 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 683 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
| 674 .WillRepeatedly(Return(false)); | 684 .WillRepeatedly(Return(false)); |
| 675 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 685 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 676 .WillRepeatedly(Return(false)); | 686 .WillRepeatedly(Return(false)); |
| 677 // Open the web UI. | 687 // Open the web UI. |
| 678 handler_->OpenSyncSetup(false); | 688 handler_->OpenSyncSetup(false); |
| 679 | 689 |
| 680 if (!SyncPromoUI::UseWebBasedSigninFlow()) { | 690 if (!SyncPromoUI::UseWebBasedSigninFlow()) { |
| 681 // Fake a failed signin attempt. | 691 // Fake a failed signin attempt. |
| 682 handler_->TryLogin(kTestUser, kTestPassword, "", ""); | 692 handler_->TryLogin(kTestUser, kTestPassword, std::string(), std::string()); |
| 683 GoogleServiceAuthError error( | 693 GoogleServiceAuthError error( |
| 684 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 694 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 685 handler_->SigninFailed(error); | 695 handler_->SigninFailed(error); |
| 686 | 696 |
| 687 ASSERT_EQ(2U, web_ui_.call_data().size()); | 697 ASSERT_EQ(2U, web_ui_.call_data().size()); |
| 688 // Validate the second JS call (the first call was already tested by | 698 // Validate the second JS call (the first call was already tested by |
| 689 // the DisplayBasicLogin test). | 699 // the DisplayBasicLogin test). |
| 690 const TestWebUI::CallData& data = web_ui_.call_data()[1]; | 700 const TestWebUI::CallData& data = web_ui_.call_data()[1]; |
| 691 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 701 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
| 692 std::string page; | 702 std::string page; |
| 693 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 703 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
| 694 EXPECT_EQ(page, "login"); | 704 EXPECT_EQ(page, "login"); |
| 695 // Now make sure that the appropriate params are being passed. | 705 // Now make sure that the appropriate params are being passed. |
| 696 DictionaryValue* dictionary; | 706 DictionaryValue* dictionary; |
| 697 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 707 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 698 CheckShowSyncSetupArgs( | 708 CheckShowSyncSetupArgs(dictionary, |
| 699 dictionary, "", false, GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, | 709 std::string(), |
| 700 kTestUser, true, ""); | 710 false, |
| 711 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, |
| 712 kTestUser, |
| 713 true, |
| 714 std::string()); |
| 701 } else { | 715 } else { |
| 702 ASSERT_FALSE(handler_->is_configuring_sync()); | 716 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 703 ASSERT_TRUE(handler_->have_signin_tracker()); | 717 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 704 } | 718 } |
| 705 } | 719 } |
| 706 | 720 |
| 707 TEST_P(SyncSetupHandlerTest, HandleCaptcha) { | 721 TEST_P(SyncSetupHandlerTest, HandleCaptcha) { |
| 708 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 722 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 709 .WillRepeatedly(Return(false)); | 723 .WillRepeatedly(Return(false)); |
| 710 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 724 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 711 .WillRepeatedly(Return(false)); | 725 .WillRepeatedly(Return(false)); |
| 712 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 726 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
| 713 .WillRepeatedly(Return(false)); | 727 .WillRepeatedly(Return(false)); |
| 714 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 728 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 715 .WillRepeatedly(Return(false)); | 729 .WillRepeatedly(Return(false)); |
| 716 // Open the web UI. | 730 // Open the web UI. |
| 717 handler_->OpenSyncSetup(false); | 731 handler_->OpenSyncSetup(false); |
| 718 | 732 |
| 719 if (!SyncPromoUI::UseWebBasedSigninFlow()) { | 733 if (!SyncPromoUI::UseWebBasedSigninFlow()) { |
| 720 // Fake a failed signin attempt that requires a captcha. | 734 // Fake a failed signin attempt that requires a captcha. |
| 721 handler_->TryLogin(kTestUser, kTestPassword, "", ""); | 735 handler_->TryLogin(kTestUser, kTestPassword, std::string(), std::string()); |
| 722 GoogleServiceAuthError error = | 736 GoogleServiceAuthError error = |
| 723 GoogleServiceAuthError::FromClientLoginCaptchaChallenge( | 737 GoogleServiceAuthError::FromClientLoginCaptchaChallenge( |
| 724 "token", GURL(kTestCaptchaImageUrl), GURL(kTestCaptchaUnlockUrl)); | 738 "token", GURL(kTestCaptchaImageUrl), GURL(kTestCaptchaUnlockUrl)); |
| 725 handler_->SigninFailed(error); | 739 handler_->SigninFailed(error); |
| 726 ASSERT_EQ(2U, web_ui_.call_data().size()); | 740 ASSERT_EQ(2U, web_ui_.call_data().size()); |
| 727 // Validate the second JS call (the first call was already tested by | 741 // Validate the second JS call (the first call was already tested by |
| 728 // the DisplayBasicLogin test). | 742 // the DisplayBasicLogin test). |
| 729 const TestWebUI::CallData& data = web_ui_.call_data()[1]; | 743 const TestWebUI::CallData& data = web_ui_.call_data()[1]; |
| 730 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 744 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
| 731 std::string page; | 745 std::string page; |
| 732 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 746 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
| 733 EXPECT_EQ(page, "login"); | 747 EXPECT_EQ(page, "login"); |
| 734 // Now make sure that the appropriate params are being passed. | 748 // Now make sure that the appropriate params are being passed. |
| 735 DictionaryValue* dictionary; | 749 DictionaryValue* dictionary; |
| 736 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 750 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 737 CheckShowSyncSetupArgs( | 751 CheckShowSyncSetupArgs(dictionary, |
| 738 dictionary, "", false, GoogleServiceAuthError::CAPTCHA_REQUIRED, | 752 std::string(), |
| 739 kTestUser, true, kTestCaptchaImageUrl); | 753 false, |
| 754 GoogleServiceAuthError::CAPTCHA_REQUIRED, |
| 755 kTestUser, |
| 756 true, |
| 757 kTestCaptchaImageUrl); |
| 740 } else { | 758 } else { |
| 741 ASSERT_FALSE(handler_->is_configuring_sync()); | 759 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 742 ASSERT_TRUE(handler_->have_signin_tracker()); | 760 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 743 } | 761 } |
| 744 } | 762 } |
| 745 | 763 |
| 746 // TODO(kochi): We need equivalent tests for ChromeOS. | 764 // TODO(kochi): We need equivalent tests for ChromeOS. |
| 747 TEST_P(SyncSetupHandlerTest, UnrecoverableErrorInitializingSync) { | 765 TEST_P(SyncSetupHandlerTest, UnrecoverableErrorInitializingSync) { |
| 748 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 766 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 749 .WillRepeatedly(Return(false)); | 767 .WillRepeatedly(Return(false)); |
| 750 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 768 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 751 .WillRepeatedly(Return(false)); | 769 .WillRepeatedly(Return(false)); |
| 752 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 770 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 753 .WillRepeatedly(Return(false)); | 771 .WillRepeatedly(Return(false)); |
| 754 // Open the web UI. | 772 // Open the web UI. |
| 755 handler_->OpenSyncSetup(false); | 773 handler_->OpenSyncSetup(false); |
| 756 | 774 |
| 757 if (!SyncPromoUI::UseWebBasedSigninFlow()) { | 775 if (!SyncPromoUI::UseWebBasedSigninFlow()) { |
| 758 ASSERT_EQ(1U, web_ui_.call_data().size()); | 776 ASSERT_EQ(1U, web_ui_.call_data().size()); |
| 759 // Fake a successful GAIA request (gaia credentials valid, but signin not | 777 // Fake a successful GAIA request (gaia credentials valid, but signin not |
| 760 // complete yet). | 778 // complete yet). |
| 761 handler_->TryLogin(kTestUser, kTestPassword, "", ""); | 779 handler_->TryLogin(kTestUser, kTestPassword, std::string(), std::string()); |
| 762 handler_->GaiaCredentialsValid(); | 780 handler_->GaiaCredentialsValid(); |
| 763 ASSERT_EQ(2U, web_ui_.call_data().size()); | 781 ASSERT_EQ(2U, web_ui_.call_data().size()); |
| 764 EXPECT_EQ("SyncSetupOverlay.showSuccessAndSettingUp", | 782 EXPECT_EQ("SyncSetupOverlay.showSuccessAndSettingUp", |
| 765 web_ui_.call_data()[1].function_name); | 783 web_ui_.call_data()[1].function_name); |
| 766 // Now fake a sync error. | 784 // Now fake a sync error. |
| 767 GoogleServiceAuthError none(GoogleServiceAuthError::NONE); | 785 GoogleServiceAuthError none(GoogleServiceAuthError::NONE); |
| 768 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 786 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
| 769 .WillRepeatedly(Return(true)); | 787 .WillRepeatedly(Return(true)); |
| 770 mock_signin_->SignOut(); | 788 mock_signin_->SignOut(); |
| 771 handler_->SigninFailed(none); | 789 handler_->SigninFailed(none); |
| 772 ASSERT_EQ(3U, web_ui_.call_data().size()); | 790 ASSERT_EQ(3U, web_ui_.call_data().size()); |
| 773 // Validate the second JS call (the first call was already tested by | 791 // Validate the second JS call (the first call was already tested by |
| 774 // the DisplayBasicLogin test). | 792 // the DisplayBasicLogin test). |
| 775 const TestWebUI::CallData& data = web_ui_.call_data()[2]; | 793 const TestWebUI::CallData& data = web_ui_.call_data()[2]; |
| 776 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 794 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
| 777 std::string page; | 795 std::string page; |
| 778 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 796 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
| 779 EXPECT_EQ(page, "login"); | 797 EXPECT_EQ(page, "login"); |
| 780 // Now make sure that the appropriate params are being passed. | 798 // Now make sure that the appropriate params are being passed. |
| 781 DictionaryValue* dictionary; | 799 DictionaryValue* dictionary; |
| 782 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 800 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 783 CheckShowSyncSetupArgs( | 801 CheckShowSyncSetupArgs(dictionary, |
| 784 dictionary, "", true, GoogleServiceAuthError::NONE, | 802 std::string(), |
| 785 kTestUser, true, ""); | 803 true, |
| 804 GoogleServiceAuthError::NONE, |
| 805 kTestUser, |
| 806 true, |
| 807 std::string()); |
| 786 } else { | 808 } else { |
| 787 ASSERT_FALSE(handler_->is_configuring_sync()); | 809 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 788 ASSERT_TRUE(handler_->have_signin_tracker()); | 810 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 789 } | 811 } |
| 790 } | 812 } |
| 791 | 813 |
| 792 TEST_P(SyncSetupHandlerTest, GaiaErrorInitializingSync) { | 814 TEST_P(SyncSetupHandlerTest, GaiaErrorInitializingSync) { |
| 793 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 815 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 794 .WillRepeatedly(Return(false)); | 816 .WillRepeatedly(Return(false)); |
| 795 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 817 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 796 .WillRepeatedly(Return(false)); | 818 .WillRepeatedly(Return(false)); |
| 797 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 819 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 798 .WillRepeatedly(Return(false)); | 820 .WillRepeatedly(Return(false)); |
| 799 // Open the web UI. | 821 // Open the web UI. |
| 800 handler_->OpenSyncSetup(false); | 822 handler_->OpenSyncSetup(false); |
| 801 | 823 |
| 802 if (!SyncPromoUI::UseWebBasedSigninFlow()) { | 824 if (!SyncPromoUI::UseWebBasedSigninFlow()) { |
| 803 ASSERT_EQ(1U, web_ui_.call_data().size()); | 825 ASSERT_EQ(1U, web_ui_.call_data().size()); |
| 804 // Fake a successful GAIA request (gaia credentials valid, but signin not | 826 // Fake a successful GAIA request (gaia credentials valid, but signin not |
| 805 // complete yet). | 827 // complete yet). |
| 806 handler_->TryLogin(kTestUser, kTestPassword, "", ""); | 828 handler_->TryLogin(kTestUser, kTestPassword, std::string(), std::string()); |
| 807 handler_->GaiaCredentialsValid(); | 829 handler_->GaiaCredentialsValid(); |
| 808 ASSERT_EQ(2U, web_ui_.call_data().size()); | 830 ASSERT_EQ(2U, web_ui_.call_data().size()); |
| 809 EXPECT_EQ("SyncSetupOverlay.showSuccessAndSettingUp", | 831 EXPECT_EQ("SyncSetupOverlay.showSuccessAndSettingUp", |
| 810 web_ui_.call_data()[1].function_name); | 832 web_ui_.call_data()[1].function_name); |
| 811 // Now fake a sync gaia error. | 833 // Now fake a sync gaia error. |
| 812 GoogleServiceAuthError unavailable( | 834 GoogleServiceAuthError unavailable( |
| 813 GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 835 GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 814 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 836 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
| 815 .WillRepeatedly(Return(false)); | 837 .WillRepeatedly(Return(false)); |
| 816 mock_signin_->SignOut(); | 838 mock_signin_->SignOut(); |
| 817 handler_->SigninFailed(unavailable); | 839 handler_->SigninFailed(unavailable); |
| 818 ASSERT_EQ(3U, web_ui_.call_data().size()); | 840 ASSERT_EQ(3U, web_ui_.call_data().size()); |
| 819 // Validate the second JS call (the first call was already tested by | 841 // Validate the second JS call (the first call was already tested by |
| 820 // the DisplayBasicLogin test). | 842 // the DisplayBasicLogin test). |
| 821 const TestWebUI::CallData& data = web_ui_.call_data()[2]; | 843 const TestWebUI::CallData& data = web_ui_.call_data()[2]; |
| 822 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 844 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
| 823 std::string page; | 845 std::string page; |
| 824 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 846 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
| 825 EXPECT_EQ(page, "login"); | 847 EXPECT_EQ(page, "login"); |
| 826 // Now make sure that the appropriate params are being passed. | 848 // Now make sure that the appropriate params are being passed. |
| 827 DictionaryValue* dictionary; | 849 DictionaryValue* dictionary; |
| 828 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 850 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 829 CheckShowSyncSetupArgs( | 851 CheckShowSyncSetupArgs(dictionary, |
| 830 dictionary, "", false, GoogleServiceAuthError::SERVICE_UNAVAILABLE, | 852 std::string(), |
| 831 kTestUser, true, ""); | 853 false, |
| 854 GoogleServiceAuthError::SERVICE_UNAVAILABLE, |
| 855 kTestUser, |
| 856 true, |
| 857 std::string()); |
| 832 } else { | 858 } else { |
| 833 ASSERT_FALSE(handler_->is_configuring_sync()); | 859 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 834 ASSERT_TRUE(handler_->have_signin_tracker()); | 860 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 835 } | 861 } |
| 836 } | 862 } |
| 837 | 863 |
| 838 TEST_P(SyncSetupHandlerTest, TestSyncEverything) { | 864 TEST_P(SyncSetupHandlerTest, TestSyncEverything) { |
| 839 std::string args = GetConfiguration( | 865 std::string args = GetConfiguration( |
| 840 NULL, SYNC_ALL_DATA, GetAllTypes(), "", ENCRYPT_PASSWORDS); | 866 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); |
| 841 ListValue list_args; | 867 ListValue list_args; |
| 842 list_args.Append(new StringValue(args)); | 868 list_args.Append(new StringValue(args)); |
| 843 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 869 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
| 844 .WillRepeatedly(Return(false)); | 870 .WillRepeatedly(Return(false)); |
| 845 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 871 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 846 .WillRepeatedly(Return(false)); | 872 .WillRepeatedly(Return(false)); |
| 847 SetupInitializedProfileSyncService(); | 873 SetupInitializedProfileSyncService(); |
| 848 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); | 874 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); |
| 849 handler_->HandleConfigure(&list_args); | 875 handler_->HandleConfigure(&list_args); |
| 850 | 876 |
| 851 // Ensure that we navigated to the "done" state since we don't need a | 877 // Ensure that we navigated to the "done" state since we don't need a |
| 852 // passphrase. | 878 // passphrase. |
| 853 ExpectDone(); | 879 ExpectDone(); |
| 854 } | 880 } |
| 855 | 881 |
| 856 TEST_P(SyncSetupHandlerTest, TurnOnEncryptAll) { | 882 TEST_P(SyncSetupHandlerTest, TurnOnEncryptAll) { |
| 857 std::string args = GetConfiguration( | 883 std::string args = GetConfiguration( |
| 858 NULL, SYNC_ALL_DATA, GetAllTypes(), "", ENCRYPT_ALL_DATA); | 884 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA); |
| 859 ListValue list_args; | 885 ListValue list_args; |
| 860 list_args.Append(new StringValue(args)); | 886 list_args.Append(new StringValue(args)); |
| 861 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 887 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
| 862 .WillRepeatedly(Return(false)); | 888 .WillRepeatedly(Return(false)); |
| 863 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 889 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 864 .WillRepeatedly(Return(false)); | 890 .WillRepeatedly(Return(false)); |
| 865 SetupInitializedProfileSyncService(); | 891 SetupInitializedProfileSyncService(); |
| 866 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()); | 892 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()); |
| 867 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); | 893 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); |
| 868 handler_->HandleConfigure(&list_args); | 894 handler_->HandleConfigure(&list_args); |
| 869 | 895 |
| 870 // Ensure that we navigated to the "done" state since we don't need a | 896 // Ensure that we navigated to the "done" state since we don't need a |
| 871 // passphrase. | 897 // passphrase. |
| 872 ExpectDone(); | 898 ExpectDone(); |
| 873 } | 899 } |
| 874 | 900 |
| 875 TEST_P(SyncSetupHandlerTest, TestPassphraseStillRequired) { | 901 TEST_P(SyncSetupHandlerTest, TestPassphraseStillRequired) { |
| 876 std::string args = GetConfiguration( | 902 std::string args = GetConfiguration( |
| 877 NULL, SYNC_ALL_DATA, GetAllTypes(), "", ENCRYPT_PASSWORDS); | 903 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); |
| 878 ListValue list_args; | 904 ListValue list_args; |
| 879 list_args.Append(new StringValue(args)); | 905 list_args.Append(new StringValue(args)); |
| 880 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 906 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
| 881 .WillRepeatedly(Return(true)); | 907 .WillRepeatedly(Return(true)); |
| 882 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 908 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 883 .WillRepeatedly(Return(true)); | 909 .WillRepeatedly(Return(true)); |
| 884 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 910 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
| 885 .WillRepeatedly(Return(false)); | 911 .WillRepeatedly(Return(false)); |
| 886 SetupInitializedProfileSyncService(); | 912 SetupInitializedProfileSyncService(); |
| 887 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); | 913 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 } | 1009 } |
| 984 | 1010 |
| 985 // Walks through each user selectable type, and tries to sync just that single | 1011 // Walks through each user selectable type, and tries to sync just that single |
| 986 // data type. | 1012 // data type. |
| 987 TEST_P(SyncSetupHandlerTest, TestSyncIndividualTypes) { | 1013 TEST_P(SyncSetupHandlerTest, TestSyncIndividualTypes) { |
| 988 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); | 1014 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); |
| 989 syncer::ModelTypeSet::Iterator it; | 1015 syncer::ModelTypeSet::Iterator it; |
| 990 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { | 1016 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { |
| 991 syncer::ModelTypeSet type_to_set; | 1017 syncer::ModelTypeSet type_to_set; |
| 992 type_to_set.Put(it.Get()); | 1018 type_to_set.Put(it.Get()); |
| 993 std::string args = GetConfiguration( | 1019 std::string args = GetConfiguration(NULL, |
| 994 NULL, CHOOSE_WHAT_TO_SYNC, type_to_set, "", ENCRYPT_PASSWORDS); | 1020 CHOOSE_WHAT_TO_SYNC, |
| 1021 type_to_set, |
| 1022 std::string(), |
| 1023 ENCRYPT_PASSWORDS); |
| 995 ListValue list_args; | 1024 ListValue list_args; |
| 996 list_args.Append(new StringValue(args)); | 1025 list_args.Append(new StringValue(args)); |
| 997 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 1026 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
| 998 .WillRepeatedly(Return(false)); | 1027 .WillRepeatedly(Return(false)); |
| 999 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 1028 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 1000 .WillRepeatedly(Return(false)); | 1029 .WillRepeatedly(Return(false)); |
| 1001 SetupInitializedProfileSyncService(); | 1030 SetupInitializedProfileSyncService(); |
| 1002 EXPECT_CALL(*mock_pss_, | 1031 EXPECT_CALL(*mock_pss_, |
| 1003 OnUserChoseDatatypes(false, ModelTypeSetMatches(type_to_set))); | 1032 OnUserChoseDatatypes(false, ModelTypeSetMatches(type_to_set))); |
| 1004 handler_->HandleConfigure(&list_args); | 1033 handler_->HandleConfigure(&list_args); |
| 1005 | 1034 |
| 1006 ExpectDone(); | 1035 ExpectDone(); |
| 1007 Mock::VerifyAndClearExpectations(mock_pss_); | 1036 Mock::VerifyAndClearExpectations(mock_pss_); |
| 1008 web_ui_.ClearTrackedCalls(); | 1037 web_ui_.ClearTrackedCalls(); |
| 1009 } | 1038 } |
| 1010 } | 1039 } |
| 1011 | 1040 |
| 1012 TEST_P(SyncSetupHandlerTest, TestSyncAllManually) { | 1041 TEST_P(SyncSetupHandlerTest, TestSyncAllManually) { |
| 1013 std::string args = GetConfiguration( | 1042 std::string args = GetConfiguration(NULL, |
| 1014 NULL, CHOOSE_WHAT_TO_SYNC, GetAllTypes(), "", ENCRYPT_PASSWORDS); | 1043 CHOOSE_WHAT_TO_SYNC, |
| 1044 GetAllTypes(), |
| 1045 std::string(), |
| 1046 ENCRYPT_PASSWORDS); |
| 1015 ListValue list_args; | 1047 ListValue list_args; |
| 1016 list_args.Append(new StringValue(args)); | 1048 list_args.Append(new StringValue(args)); |
| 1017 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) | 1049 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) |
| 1018 .WillRepeatedly(Return(false)); | 1050 .WillRepeatedly(Return(false)); |
| 1019 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 1051 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 1020 .WillRepeatedly(Return(false)); | 1052 .WillRepeatedly(Return(false)); |
| 1021 SetupInitializedProfileSyncService(); | 1053 SetupInitializedProfileSyncService(); |
| 1022 EXPECT_CALL(*mock_pss_, | 1054 EXPECT_CALL(*mock_pss_, |
| 1023 OnUserChoseDatatypes(false, ModelTypeSetMatches(GetAllTypes()))); | 1055 OnUserChoseDatatypes(false, ModelTypeSetMatches(GetAllTypes()))); |
| 1024 handler_->HandleConfigure(&list_args); | 1056 handler_->HandleConfigure(&list_args); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 ASSERT_EQ(1U, web_ui_.call_data().size()); | 1099 ASSERT_EQ(1U, web_ui_.call_data().size()); |
| 1068 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 1100 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 1069 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 1101 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
| 1070 std::string page; | 1102 std::string page; |
| 1071 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 1103 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
| 1072 EXPECT_EQ(page, "login"); | 1104 EXPECT_EQ(page, "login"); |
| 1073 DictionaryValue* dictionary; | 1105 DictionaryValue* dictionary; |
| 1074 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 1106 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 1075 // We should display a login screen with a non-editable username filled in. | 1107 // We should display a login screen with a non-editable username filled in. |
| 1076 CheckShowSyncSetupArgs(dictionary, | 1108 CheckShowSyncSetupArgs(dictionary, |
| 1077 "", | 1109 std::string(), |
| 1078 false, | 1110 false, |
| 1079 GoogleServiceAuthError::NONE, | 1111 GoogleServiceAuthError::NONE, |
| 1080 kTestUser, | 1112 kTestUser, |
| 1081 false, | 1113 false, |
| 1082 ""); | 1114 std::string()); |
| 1083 } else { | 1115 } else { |
| 1084 ASSERT_FALSE(handler_->is_configuring_sync()); | 1116 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 1085 ASSERT_TRUE(handler_->have_signin_tracker()); | 1117 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 1086 } | 1118 } |
| 1087 } | 1119 } |
| 1088 | 1120 |
| 1089 TEST_P(SyncSetupHandlerTest, ShowSetupSyncEverything) { | 1121 TEST_P(SyncSetupHandlerTest, ShowSetupSyncEverything) { |
| 1090 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 1122 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 1091 .WillRepeatedly(Return(false)); | 1123 .WillRepeatedly(Return(false)); |
| 1092 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 1124 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1237 // displayed to the user. | 1269 // displayed to the user. |
| 1238 TEST_P(SyncSetupHandlerTest, SubmitAuthWithInvalidUsername) { | 1270 TEST_P(SyncSetupHandlerTest, SubmitAuthWithInvalidUsername) { |
| 1239 EXPECT_CALL(*mock_signin_, IsAllowedUsername(_)). | 1271 EXPECT_CALL(*mock_signin_, IsAllowedUsername(_)). |
| 1240 WillRepeatedly(Return(false)); | 1272 WillRepeatedly(Return(false)); |
| 1241 | 1273 |
| 1242 // Generate a blob of json that matches what would be submitted by the login | 1274 // Generate a blob of json that matches what would be submitted by the login |
| 1243 // javascript code. | 1275 // javascript code. |
| 1244 DictionaryValue args; | 1276 DictionaryValue args; |
| 1245 args.SetString("user", "user@not_allowed.com"); | 1277 args.SetString("user", "user@not_allowed.com"); |
| 1246 args.SetString("pass", "password"); | 1278 args.SetString("pass", "password"); |
| 1247 args.SetString("captcha", ""); | 1279 args.SetString("captcha", std::string()); |
| 1248 args.SetString("otp", ""); | 1280 args.SetString("otp", std::string()); |
| 1249 args.SetString("accessCode", ""); | 1281 args.SetString("accessCode", std::string()); |
| 1250 std::string json; | 1282 std::string json; |
| 1251 base::JSONWriter::Write(&args, &json); | 1283 base::JSONWriter::Write(&args, &json); |
| 1252 ListValue list_args; | 1284 ListValue list_args; |
| 1253 list_args.Append(new StringValue(json)); | 1285 list_args.Append(new StringValue(json)); |
| 1254 | 1286 |
| 1255 // Mimic a login attempt from the UI. | 1287 // Mimic a login attempt from the UI. |
| 1256 handler_->HandleSubmitAuth(&list_args); | 1288 handler_->HandleSubmitAuth(&list_args); |
| 1257 | 1289 |
| 1258 // Should result in the login page being displayed again. | 1290 // Should result in the login page being displayed again. |
| 1259 ASSERT_EQ(1U, web_ui_.call_data().size()); | 1291 ASSERT_EQ(1U, web_ui_.call_data().size()); |
| 1260 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 1292 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 1261 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 1293 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
| 1262 std::string page; | 1294 std::string page; |
| 1263 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 1295 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
| 1264 EXPECT_EQ(page, "login"); | 1296 EXPECT_EQ(page, "login"); |
| 1265 | 1297 |
| 1266 // Also make sure that the appropriate error message is being passed. | 1298 // Also make sure that the appropriate error message is being passed. |
| 1267 DictionaryValue* dictionary; | 1299 DictionaryValue* dictionary; |
| 1268 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 1300 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 1269 std::string err = l10n_util::GetStringUTF8(IDS_SYNC_LOGIN_NAME_PROHIBITED); | 1301 std::string err = l10n_util::GetStringUTF8(IDS_SYNC_LOGIN_NAME_PROHIBITED); |
| 1270 CheckShowSyncSetupArgs( | 1302 CheckShowSyncSetupArgs(dictionary, |
| 1271 dictionary, err, false, GoogleServiceAuthError::NONE, "", true, ""); | 1303 err, |
| 1304 false, |
| 1305 GoogleServiceAuthError::NONE, |
| 1306 std::string(), |
| 1307 true, |
| 1308 std::string()); |
| 1272 handler_->CloseSyncSetup(); | 1309 handler_->CloseSyncSetup(); |
| 1273 EXPECT_EQ(NULL, | 1310 EXPECT_EQ(NULL, |
| 1274 LoginUIServiceFactory::GetForProfile( | 1311 LoginUIServiceFactory::GetForProfile( |
| 1275 profile_.get())->current_login_ui()); | 1312 profile_.get())->current_login_ui()); |
| 1276 } | 1313 } |
| 1277 | 1314 |
| 1278 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam, | 1315 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam, |
| 1279 SyncSetupHandlerTest, | 1316 SyncSetupHandlerTest, |
| 1280 Values(true, false)); | 1317 Values(true, false)); |
| OLD | NEW |