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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 13 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/autofill/account_chooser_model.h" | 15 #include "chrome/browser/ui/autofill/account_chooser_model.h" |
16 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 16 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
17 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 17 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
18 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 18 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
19 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 19 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
20 #include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_controlle r.h" | 20 #include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_controlle r.h" |
21 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" | 21 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" |
22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
25 #include "chrome/common/url_constants.h" | |
25 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
26 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
27 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" | 28 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" |
28 #include "components/autofill/content/browser/wallet/mock_wallet_client.h" | 29 #include "components/autofill/content/browser/wallet/mock_wallet_client.h" |
29 #include "components/autofill/content/browser/wallet/wallet_test_util.h" | 30 #include "components/autofill/content/browser/wallet/wallet_test_util.h" |
30 #include "components/autofill/core/browser/autofill_common_test.h" | 31 #include "components/autofill/core/browser/autofill_common_test.h" |
31 #include "components/autofill/core/browser/autofill_metrics.h" | 32 #include "components/autofill/core/browser/autofill_metrics.h" |
32 #include "components/autofill/core/browser/test_personal_data_manager.h" | 33 #include "components/autofill/core/browser/test_personal_data_manager.h" |
33 #include "components/autofill/core/browser/validation.h" | 34 #include "components/autofill/core/browser/validation.h" |
34 #include "components/autofill/core/common/autofill_switches.h" | 35 #include "components/autofill/core/common/autofill_switches.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 mock_wallet_client_( | 98 mock_wallet_client_( |
98 Profile::FromBrowserContext(contents->GetBrowserContext())-> | 99 Profile::FromBrowserContext(contents->GetBrowserContext())-> |
99 GetRequestContext(), this, form_data.origin), | 100 GetRequestContext(), this, form_data.origin), |
100 message_loop_runner_(runner), | 101 message_loop_runner_(runner), |
101 use_validation_(false), | 102 use_validation_(false), |
102 weak_ptr_factory_(this) {} | 103 weak_ptr_factory_(this) {} |
103 | 104 |
104 virtual ~TestAutofillDialogController() {} | 105 virtual ~TestAutofillDialogController() {} |
105 | 106 |
106 virtual GURL SignInUrl() const OVERRIDE { | 107 virtual GURL SignInUrl() const OVERRIDE { |
108 return GURL(chrome::kChromeUIVersionURL); | |
109 } | |
110 | |
111 GURL SignInContinueUrl() const { | |
107 return GURL(content::kAboutBlankURL); | 112 return GURL(content::kAboutBlankURL); |
108 } | 113 } |
109 | 114 |
110 virtual void ViewClosed() OVERRIDE { | 115 virtual void ViewClosed() OVERRIDE { |
111 message_loop_runner_->Quit(); | 116 message_loop_runner_->Quit(); |
112 AutofillDialogControllerImpl::ViewClosed(); | 117 AutofillDialogControllerImpl::ViewClosed(); |
113 } | 118 } |
114 | 119 |
115 virtual string16 InputValidityMessage( | 120 virtual string16 InputValidityMessage( |
116 DialogSection section, | 121 DialogSection section, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 protected: | 184 protected: |
180 virtual PersonalDataManager* GetManager() OVERRIDE { | 185 virtual PersonalDataManager* GetManager() OVERRIDE { |
181 return &test_manager_; | 186 return &test_manager_; |
182 } | 187 } |
183 | 188 |
184 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { | 189 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { |
185 return &mock_wallet_client_; | 190 return &mock_wallet_client_; |
186 } | 191 } |
187 | 192 |
188 virtual bool IsSignInContinueUrl(const GURL& url) const OVERRIDE { | 193 virtual bool IsSignInContinueUrl(const GURL& url) const OVERRIDE { |
189 return true; | 194 return url == SignInContinueUrl(); |
190 } | 195 } |
191 | 196 |
192 private: | 197 private: |
193 // To specify our own metric logger. | 198 // To specify our own metric logger. |
194 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { | 199 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { |
195 return metric_logger_; | 200 return metric_logger_; |
196 } | 201 } |
197 | 202 |
198 const AutofillMetrics& metric_logger_; | 203 const AutofillMetrics& metric_logger_; |
199 TestPersonalDataManager test_manager_; | 204 TestPersonalDataManager test_manager_; |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
891 controller()->OnDidAuthenticateInstrument(true); | 896 controller()->OnDidAuthenticateInstrument(true); |
892 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); | 897 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); |
893 controller()->ForceFinishSubmit(); | 898 controller()->ForceFinishSubmit(); |
894 | 899 |
895 RunMessageLoop(); | 900 RunMessageLoop(); |
896 | 901 |
897 EXPECT_EQ(1, test_generated_bubble_controller()->bubbles_shown()); | 902 EXPECT_EQ(1, test_generated_bubble_controller()->bubbles_shown()); |
898 EXPECT_EQ(last_four, test_generated_bubble_controller()->backing_card_name()); | 903 EXPECT_EQ(last_four, test_generated_bubble_controller()->backing_card_name()); |
899 } | 904 } |
900 | 905 |
901 // Simulates the user successfully signing in to the dialog for the first time. | 906 // Simulates the user signing in to the dialog from the inline web contents. |
902 // The controller listens for nav entry commits and should not destroy the web | 907 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, SimulateSuccessfulSignIn) { |
903 // contents before its post load code runs (which would cause a crash). | |
904 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, SignInNoCrash) { | |
905 browser()->profile()->GetPrefs()->SetBoolean( | 908 browser()->profile()->GetPrefs()->SetBoolean( |
906 ::prefs::kAutofillDialogPayWithoutWallet, | 909 ::prefs::kAutofillDialogPayWithoutWallet, |
907 true); | 910 true); |
908 | 911 |
909 InitializeController(); | 912 InitializeController(); |
910 | 913 |
914 controller()->OnDidFetchWalletCookieValue(std::string()); | |
915 std::vector<std::string> usernames(1, "user@example.com"); | |
916 controller()->OnUserNameFetchSuccess(usernames); | |
Evan Stade
2013/11/05 00:02:20
I think it makes more sense to have a username fet
Dan Beam
2013/11/05 00:16:33
Done.
| |
917 controller()->OnDidGetWalletItems( | |
918 wallet::GetTestWalletItemsWithRequiredAction(wallet::GAIA_AUTH)); | |
919 | |
920 ui_test_utils::UrlLoadObserver sign_in_page_observer( | |
921 controller()->SignInUrl(), | |
922 content::NotificationService::AllSources()); | |
923 | |
924 // Simulate a user clicking "Sign In" (which loads dialog's web contents). | |
925 controller()->SignInLinkClicked(); | |
926 EXPECT_TRUE(controller()->ShouldShowSignInWebView()); | |
927 | |
928 TestableAutofillDialogView* view = controller()->GetTestableView(); | |
929 content::WebContents* sign_in_contents = view->GetSignInWebContents(); | |
930 ASSERT_TRUE(sign_in_contents); | |
931 | |
932 sign_in_page_observer.Wait(); | |
933 | |
934 ui_test_utils::UrlLoadObserver continue_page_observer( | |
935 controller()->SignInContinueUrl(), | |
936 content::NotificationService::AllSources()); | |
937 | |
938 EXPECT_EQ(sign_in_contents->GetURL(), controller()->SignInUrl()); | |
939 | |
911 const AccountChooserModel& account_chooser_model = | 940 const AccountChooserModel& account_chooser_model = |
912 controller()->AccountChooserModelForTesting(); | 941 controller()->AccountChooserModelForTesting(); |
913 EXPECT_FALSE(account_chooser_model.WalletIsSelected()); | 942 EXPECT_FALSE(account_chooser_model.WalletIsSelected()); |
914 | 943 |
915 ui_test_utils::UrlLoadObserver observer( | 944 sign_in_contents->GetController().LoadURL( |
916 controller()->SignInUrl(), | 945 controller()->SignInContinueUrl(), |
917 content::NotificationService::AllSources()); | 946 content::Referrer(), |
947 content::PAGE_TRANSITION_FORM_SUBMIT, | |
948 std::string()); | |
918 | 949 |
919 controller()->SignInLinkClicked(); | 950 continue_page_observer.Wait(); |
920 std::vector<std::string> usernames(1, "user@example.com"); | 951 EXPECT_FALSE(controller()->ShouldShowSignInWebView()); |
921 controller()->OnUserNameFetchSuccess(usernames); | 952 |
922 controller()->OnDidFetchWalletCookieValue(std::string()); | 953 content::RunAllPendingInMessageLoop(); |
954 | |
923 controller()->OnDidGetWalletItems( | 955 controller()->OnDidGetWalletItems( |
924 wallet::GetTestWalletItemsWithRequiredAction(wallet::GAIA_AUTH)); | 956 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); |
925 | 957 |
926 TestableAutofillDialogView* view = controller()->GetTestableView(); | 958 // Wallet should now be selected and Chrome shouldn't have crashed (which can |
927 EXPECT_TRUE(view->GetSignInWebContents()); | 959 // happen if the WebContents is deleted while proccessing a nav entry commit). |
928 EXPECT_TRUE(controller()->ShouldShowSignInWebView()); | |
929 observer.Wait(); | |
930 | |
931 // Wallet should now be selected and Chrome shouldn't have crashed. | |
932 EXPECT_TRUE(account_chooser_model.WalletIsSelected()); | 960 EXPECT_TRUE(account_chooser_model.WalletIsSelected()); |
933 } | 961 } |
934 | 962 |
935 // Verify that filling a form works correctly, including filling the CVC when | 963 // Verify that filling a form works correctly, including filling the CVC when |
936 // that is requested separately. | 964 // that is requested separately. |
937 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillFormIncludesCVC) { | 965 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillFormIncludesCVC) { |
938 AutofillDialogControllerImpl* controller = | 966 AutofillDialogControllerImpl* controller = |
939 SetUpHtmlAndInvoke("<input autocomplete='cc-csc'>"); | 967 SetUpHtmlAndInvoke("<input autocomplete='cc-csc'>"); |
940 | 968 |
941 AddCreditcardToProfile(controller->profile(), test::GetVerifiedCreditCard()); | 969 AddCreditcardToProfile(controller->profile(), test::GetVerifiedCreditCard()); |
942 AddAutofillProfileToProfile(controller->profile(), | 970 AddAutofillProfileToProfile(controller->profile(), |
943 test::GetVerifiedProfile()); | 971 test::GetVerifiedProfile()); |
944 | 972 |
945 TestableAutofillDialogView* view = controller->GetTestableView(); | 973 TestableAutofillDialogView* view = controller->GetTestableView(); |
946 view->SetTextContentsOfSuggestionInput(SECTION_CC, ASCIIToUTF16("123")); | 974 view->SetTextContentsOfSuggestionInput(SECTION_CC, ASCIIToUTF16("123")); |
947 view->SubmitForTesting(); | 975 view->SubmitForTesting(); |
948 ExpectDomMessage("success"); | 976 ExpectDomMessage("success"); |
949 EXPECT_EQ("123", GetValueForHTMLFieldOfType("cc-csc")); | 977 EXPECT_EQ("123", GetValueForHTMLFieldOfType("cc-csc")); |
950 } | 978 } |
951 | 979 |
952 } // namespace autofill | 980 } // namespace autofill |
OLD | NEW |