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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc

Issue 58593003: Massage Autofill dialog sign in test to be more similar to actual sign in flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
35 #include "components/autofill/core/common/form_data.h" 36 #include "components/autofill/core/common/form_data.h"
36 #include "components/autofill/core/common/form_field_data.h" 37 #include "components/autofill/core/common/form_field_data.h"
37 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
38 #include "content/public/browser/notification_service.h" 39 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
40 #include "content/public/browser/web_contents_delegate.h" 41 #include "content/public/browser/web_contents_delegate.h"
41 #include "content/public/common/url_constants.h" 42 #include "content/public/common/url_constants.h"
42 #include "content/public/test/browser_test_utils.h" 43 #include "content/public/test/browser_test_utils.h"
43 #include "content/public/test/test_utils.h" 44 #include "content/public/test/test_utils.h"
45 #include "google_apis/gaia/google_service_auth_error.h"
44 #include "testing/gmock/include/gmock/gmock.h" 46 #include "testing/gmock/include/gmock/gmock.h"
45 #include "testing/gtest/include/gtest/gtest.h" 47 #include "testing/gtest/include/gtest/gtest.h"
46 #include "third_party/WebKit/public/web/WebInputEvent.h" 48 #include "third_party/WebKit/public/web/WebInputEvent.h"
47 #include "url/gurl.h" 49 #include "url/gurl.h"
48 50
49 namespace autofill { 51 namespace autofill {
50 52
51 namespace { 53 namespace {
52 54
53 using testing::_; 55 using testing::_;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 mock_wallet_client_( 99 mock_wallet_client_(
98 Profile::FromBrowserContext(contents->GetBrowserContext())-> 100 Profile::FromBrowserContext(contents->GetBrowserContext())->
99 GetRequestContext(), this, form_data.origin), 101 GetRequestContext(), this, form_data.origin),
100 message_loop_runner_(runner), 102 message_loop_runner_(runner),
101 use_validation_(false), 103 use_validation_(false),
102 weak_ptr_factory_(this) {} 104 weak_ptr_factory_(this) {}
103 105
104 virtual ~TestAutofillDialogController() {} 106 virtual ~TestAutofillDialogController() {}
105 107
106 virtual GURL SignInUrl() const OVERRIDE { 108 virtual GURL SignInUrl() const OVERRIDE {
109 return GURL(chrome::kChromeUIVersionURL);
110 }
111
112 GURL SignInContinueUrl() const {
107 return GURL(content::kAboutBlankURL); 113 return GURL(content::kAboutBlankURL);
108 } 114 }
109 115
110 virtual void ViewClosed() OVERRIDE { 116 virtual void ViewClosed() OVERRIDE {
111 message_loop_runner_->Quit(); 117 message_loop_runner_->Quit();
112 AutofillDialogControllerImpl::ViewClosed(); 118 AutofillDialogControllerImpl::ViewClosed();
113 } 119 }
114 120
115 virtual string16 InputValidityMessage( 121 virtual string16 InputValidityMessage(
116 DialogSection section, 122 DialogSection section,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 protected: 185 protected:
180 virtual PersonalDataManager* GetManager() OVERRIDE { 186 virtual PersonalDataManager* GetManager() OVERRIDE {
181 return &test_manager_; 187 return &test_manager_;
182 } 188 }
183 189
184 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { 190 virtual wallet::WalletClient* GetWalletClient() OVERRIDE {
185 return &mock_wallet_client_; 191 return &mock_wallet_client_;
186 } 192 }
187 193
188 virtual bool IsSignInContinueUrl(const GURL& url) const OVERRIDE { 194 virtual bool IsSignInContinueUrl(const GURL& url) const OVERRIDE {
189 return true; 195 return url == SignInContinueUrl();
190 } 196 }
191 197
192 private: 198 private:
193 // To specify our own metric logger. 199 // To specify our own metric logger.
194 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { 200 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
195 return metric_logger_; 201 return metric_logger_;
196 } 202 }
197 203
198 const AutofillMetrics& metric_logger_; 204 const AutofillMetrics& metric_logger_;
199 TestPersonalDataManager test_manager_; 205 TestPersonalDataManager test_manager_;
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 controller()->OnDidAuthenticateInstrument(true); 897 controller()->OnDidAuthenticateInstrument(true);
892 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 898 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
893 controller()->ForceFinishSubmit(); 899 controller()->ForceFinishSubmit();
894 900
895 RunMessageLoop(); 901 RunMessageLoop();
896 902
897 EXPECT_EQ(1, test_generated_bubble_controller()->bubbles_shown()); 903 EXPECT_EQ(1, test_generated_bubble_controller()->bubbles_shown());
898 EXPECT_EQ(last_four, test_generated_bubble_controller()->backing_card_name()); 904 EXPECT_EQ(last_four, test_generated_bubble_controller()->backing_card_name());
899 } 905 }
900 906
901 // See http://crbug.com/314627 907 // Simulates the user signing in to the dialog from the inline web contents.
902 #if defined(OS_WIN) 908 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, SimulateSuccessfulSignIn) {
903 #define MAYBE_SignInNoCrash DISABLED_SignInNoCrash
904 #else
905 #define MAYBE_SignInNoCrash SignInNoCrash
906 #endif
907
908 // Simulates the user successfully signing in to the dialog for the first time.
909 // The controller listens for nav entry commits and should not destroy the web
910 // contents before its post load code runs (which would cause a crash).
911 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, MAYBE_SignInNoCrash) {
912 browser()->profile()->GetPrefs()->SetBoolean( 909 browser()->profile()->GetPrefs()->SetBoolean(
913 ::prefs::kAutofillDialogPayWithoutWallet, 910 ::prefs::kAutofillDialogPayWithoutWallet,
914 true); 911 true);
915 912
916 InitializeController(); 913 InitializeController();
917 914
915 controller()->OnDidFetchWalletCookieValue(std::string());
916 controller()->OnUserNameFetchFailure(GoogleServiceAuthError(
917 GoogleServiceAuthError::USER_NOT_SIGNED_UP));
918 controller()->OnDidGetWalletItems(
919 wallet::GetTestWalletItemsWithRequiredAction(wallet::GAIA_AUTH));
920
921 ui_test_utils::UrlLoadObserver sign_in_page_observer(
922 controller()->SignInUrl(),
923 content::NotificationService::AllSources());
924
925 // Simulate a user clicking "Sign In" (which loads dialog's web contents).
926 controller()->SignInLinkClicked();
927 EXPECT_TRUE(controller()->ShouldShowSignInWebView());
928
929 TestableAutofillDialogView* view = controller()->GetTestableView();
930 content::WebContents* sign_in_contents = view->GetSignInWebContents();
931 ASSERT_TRUE(sign_in_contents);
932
933 sign_in_page_observer.Wait();
934
935 ui_test_utils::UrlLoadObserver continue_page_observer(
936 controller()->SignInContinueUrl(),
937 content::NotificationService::AllSources());
938
939 EXPECT_EQ(sign_in_contents->GetURL(), controller()->SignInUrl());
940
918 const AccountChooserModel& account_chooser_model = 941 const AccountChooserModel& account_chooser_model =
919 controller()->AccountChooserModelForTesting(); 942 controller()->AccountChooserModelForTesting();
920 EXPECT_FALSE(account_chooser_model.WalletIsSelected()); 943 EXPECT_FALSE(account_chooser_model.WalletIsSelected());
921 944
922 ui_test_utils::UrlLoadObserver observer( 945 sign_in_contents->GetController().LoadURL(
923 controller()->SignInUrl(), 946 controller()->SignInContinueUrl(),
924 content::NotificationService::AllSources()); 947 content::Referrer(),
948 content::PAGE_TRANSITION_FORM_SUBMIT,
949 std::string());
925 950
926 controller()->SignInLinkClicked(); 951 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems());
952 continue_page_observer.Wait();
953 content::RunAllPendingInMessageLoop();
954
955 EXPECT_FALSE(controller()->ShouldShowSignInWebView());
956
957 controller()->OnDidGetWalletItems(
958 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED));
927 std::vector<std::string> usernames(1, "user@example.com"); 959 std::vector<std::string> usernames(1, "user@example.com");
928 controller()->OnUserNameFetchSuccess(usernames); 960 controller()->OnUserNameFetchSuccess(usernames);
929 controller()->OnDidFetchWalletCookieValue(std::string());
930 controller()->OnDidGetWalletItems(
931 wallet::GetTestWalletItemsWithRequiredAction(wallet::GAIA_AUTH));
932 961
933 TestableAutofillDialogView* view = controller()->GetTestableView(); 962 // Wallet should now be selected and Chrome shouldn't have crashed (which can
934 EXPECT_TRUE(view->GetSignInWebContents()); 963 // happen if the WebContents is deleted while proccessing a nav entry commit).
935 EXPECT_TRUE(controller()->ShouldShowSignInWebView());
936 observer.Wait();
937
938 // Wallet should now be selected and Chrome shouldn't have crashed.
939 EXPECT_TRUE(account_chooser_model.WalletIsSelected()); 964 EXPECT_TRUE(account_chooser_model.WalletIsSelected());
940 } 965 }
941 966
942 // Verify that filling a form works correctly, including filling the CVC when 967 // Verify that filling a form works correctly, including filling the CVC when
943 // that is requested separately. 968 // that is requested separately.
944 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillFormIncludesCVC) { 969 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillFormIncludesCVC) {
945 AutofillDialogControllerImpl* controller = 970 AutofillDialogControllerImpl* controller =
946 SetUpHtmlAndInvoke("<input autocomplete='cc-csc'>"); 971 SetUpHtmlAndInvoke("<input autocomplete='cc-csc'>");
947 972
948 AddCreditcardToProfile(controller->profile(), test::GetVerifiedCreditCard()); 973 AddCreditcardToProfile(controller->profile(), test::GetVerifiedCreditCard());
949 AddAutofillProfileToProfile(controller->profile(), 974 AddAutofillProfileToProfile(controller->profile(),
950 test::GetVerifiedProfile()); 975 test::GetVerifiedProfile());
951 976
952 TestableAutofillDialogView* view = controller->GetTestableView(); 977 TestableAutofillDialogView* view = controller->GetTestableView();
953 view->SetTextContentsOfSuggestionInput(SECTION_CC, ASCIIToUTF16("123")); 978 view->SetTextContentsOfSuggestionInput(SECTION_CC, ASCIIToUTF16("123"));
954 view->SubmitForTesting(); 979 view->SubmitForTesting();
955 ExpectDomMessage("success"); 980 ExpectDomMessage("success");
956 EXPECT_EQ("123", GetValueForHTMLFieldOfType("cc-csc")); 981 EXPECT_EQ("123", GetValueForHTMLFieldOfType("cc-csc"));
957 } 982 }
958 983
959 } // namespace autofill 984 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698