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

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

Issue 123363002: rAc: don't open sign in continue url in new tab (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit tests Created 6 years, 11 months 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
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/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" 22 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h"
23 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_tabstrip.h" 24 #include "chrome/browser/ui/browser_tabstrip.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" 25 #include "chrome/browser/ui/tabs/tab_strip_model.h"
26 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
27 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
28 #include "chrome/test/base/in_process_browser_test.h" 28 #include "chrome/test/base/in_process_browser_test.h"
29 #include "chrome/test/base/ui_test_utils.h" 29 #include "chrome/test/base/ui_test_utils.h"
30 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" 30 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h"
31 #include "components/autofill/content/browser/wallet/mock_wallet_client.h" 31 #include "components/autofill/content/browser/wallet/mock_wallet_client.h"
32 #include "components/autofill/content/browser/wallet/wallet_service_url.h"
32 #include "components/autofill/content/browser/wallet/wallet_test_util.h" 33 #include "components/autofill/content/browser/wallet/wallet_test_util.h"
33 #include "components/autofill/core/browser/autofill_metrics.h" 34 #include "components/autofill/core/browser/autofill_metrics.h"
34 #include "components/autofill/core/browser/autofill_test_utils.h" 35 #include "components/autofill/core/browser/autofill_test_utils.h"
35 #include "components/autofill/core/browser/test_personal_data_manager.h" 36 #include "components/autofill/core/browser/test_personal_data_manager.h"
36 #include "components/autofill/core/browser/validation.h" 37 #include "components/autofill/core/browser/validation.h"
37 #include "components/autofill/core/common/autofill_switches.h" 38 #include "components/autofill/core/common/autofill_switches.h"
38 #include "components/autofill/core/common/form_data.h" 39 #include "components/autofill/core/common/form_data.h"
39 #include "components/autofill/core/common/form_field_data.h" 40 #include "components/autofill/core/common/form_field_data.h"
40 #include "content/public/browser/browser_thread.h" 41 #include "content/public/browser/browser_thread.h"
41 #include "content/public/browser/interstitial_page.h" 42 #include "content/public/browser/interstitial_page.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 use_validation_(false), 124 use_validation_(false),
124 weak_ptr_factory_(this), 125 weak_ptr_factory_(this),
125 sign_in_user_index_(0U) {} 126 sign_in_user_index_(0U) {}
126 127
127 virtual ~TestAutofillDialogController() {} 128 virtual ~TestAutofillDialogController() {}
128 129
129 virtual GURL SignInUrl() const OVERRIDE { 130 virtual GURL SignInUrl() const OVERRIDE {
130 return GURL(chrome::kChromeUIVersionURL); 131 return GURL(chrome::kChromeUIVersionURL);
131 } 132 }
132 133
133 GURL SignInContinueUrl() const {
134 return GURL(content::kAboutBlankURL);
135 }
136
137 virtual void ViewClosed() OVERRIDE { 134 virtual void ViewClosed() OVERRIDE {
138 message_loop_runner_->Quit(); 135 message_loop_runner_->Quit();
139 AutofillDialogControllerImpl::ViewClosed(); 136 AutofillDialogControllerImpl::ViewClosed();
140 } 137 }
141 138
142 virtual base::string16 InputValidityMessage( 139 virtual base::string16 InputValidityMessage(
143 DialogSection section, 140 DialogSection section,
144 ServerFieldType type, 141 ServerFieldType type,
145 const base::string16& value) OVERRIDE { 142 const base::string16& value) OVERRIDE {
146 if (!use_validation_) 143 if (!use_validation_)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 return &const_cast<TestAutofillDialogController*>(this)->test_manager_; 211 return &const_cast<TestAutofillDialogController*>(this)->test_manager_;
215 } 212 }
216 213
217 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { 214 virtual wallet::WalletClient* GetWalletClient() OVERRIDE {
218 return &mock_wallet_client_; 215 return &mock_wallet_client_;
219 } 216 }
220 217
221 virtual bool IsSignInContinueUrl(const GURL& url, size_t* user_index) const 218 virtual bool IsSignInContinueUrl(const GURL& url, size_t* user_index) const
222 OVERRIDE { 219 OVERRIDE {
223 *user_index = sign_in_user_index_; 220 *user_index = sign_in_user_index_;
224 return url == SignInContinueUrl(); 221 return url == wallet::GetSignInContinueUrl();
225 } 222 }
226 223
227 private: 224 private:
228 // To specify our own metric logger. 225 // To specify our own metric logger.
229 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { 226 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
230 return metric_logger_; 227 return metric_logger_;
231 } 228 }
232 229
233 const AutofillMetrics& metric_logger_; 230 const AutofillMetrics& metric_logger_;
234 TestPersonalDataManager test_manager_; 231 TestPersonalDataManager test_manager_;
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 EXPECT_EQ(1, test_generated_bubble_controller()->bubbles_shown()); 1055 EXPECT_EQ(1, test_generated_bubble_controller()->bubbles_shown());
1059 EXPECT_EQ(last_four, test_generated_bubble_controller()->backing_card_name()); 1056 EXPECT_EQ(last_four, test_generated_bubble_controller()->backing_card_name());
1060 } 1057 }
1061 1058
1062 // Simulates the user signing in to the dialog from the inline web contents. 1059 // Simulates the user signing in to the dialog from the inline web contents.
1063 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, SimulateSuccessfulSignIn) { 1060 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, SimulateSuccessfulSignIn) {
1064 browser()->profile()->GetPrefs()->SetBoolean( 1061 browser()->profile()->GetPrefs()->SetBoolean(
1065 ::prefs::kAutofillDialogPayWithoutWallet, 1062 ::prefs::kAutofillDialogPayWithoutWallet,
1066 true); 1063 true);
1067 1064
1065 wallet::SetUseTestingSignInContinueUrl();
groby-ooo-7-16 2014/01/03 00:10:22 Since this is a browser test, I'd prefer it if we
Evan Stade 2014/01/03 01:47:44 I added a FakeURLFetcherFactory (see second to las
1068 InitializeController(); 1066 InitializeController();
1069 1067
1070 controller()->OnDidFetchWalletCookieValue(std::string()); 1068 controller()->OnDidFetchWalletCookieValue(std::string());
1071 controller()->OnDidGetWalletItems( 1069 controller()->OnDidGetWalletItems(
1072 wallet::GetTestWalletItemsWithRequiredAction(wallet::GAIA_AUTH)); 1070 wallet::GetTestWalletItemsWithRequiredAction(wallet::GAIA_AUTH));
1073 1071
1074 NavEntryCommittedObserver sign_in_page_observer( 1072 NavEntryCommittedObserver sign_in_page_observer(
1075 controller()->SignInUrl(), 1073 controller()->SignInUrl(),
1076 content::NotificationService::AllSources()); 1074 content::NotificationService::AllSources());
1077 1075
1078 // Simulate a user clicking "Sign In" (which loads dialog's web contents). 1076 // Simulate a user clicking "Sign In" (which loads dialog's web contents).
1079 controller()->SignInLinkClicked(); 1077 controller()->SignInLinkClicked();
1080 EXPECT_TRUE(controller()->ShouldShowSignInWebView()); 1078 EXPECT_TRUE(controller()->ShouldShowSignInWebView());
1081 1079
1082 TestableAutofillDialogView* view = controller()->GetTestableView(); 1080 TestableAutofillDialogView* view = controller()->GetTestableView();
1083 content::WebContents* sign_in_contents = view->GetSignInWebContents(); 1081 content::WebContents* sign_in_contents = view->GetSignInWebContents();
1084 ASSERT_TRUE(sign_in_contents); 1082 ASSERT_TRUE(sign_in_contents);
1085 1083
1086 sign_in_page_observer.Wait(); 1084 sign_in_page_observer.Wait();
1087 1085
1088 NavEntryCommittedObserver continue_page_observer( 1086 NavEntryCommittedObserver continue_page_observer(
1089 controller()->SignInContinueUrl(), 1087 wallet::GetSignInContinueUrl(),
1090 content::NotificationService::AllSources()); 1088 content::NotificationService::AllSources());
1091 1089
1092 EXPECT_EQ(sign_in_contents->GetURL(), controller()->SignInUrl()); 1090 EXPECT_EQ(sign_in_contents->GetURL(), controller()->SignInUrl());
1093 1091
1094 AccountChooserModel* account_chooser_model = 1092 AccountChooserModel* account_chooser_model =
1095 controller()->AccountChooserModelForTesting(); 1093 controller()->AccountChooserModelForTesting();
1096 EXPECT_FALSE(account_chooser_model->WalletIsSelected()); 1094 EXPECT_FALSE(account_chooser_model->WalletIsSelected());
1097 1095
1098 sign_in_contents->GetController().LoadURL( 1096 content::OpenURLParams params(wallet::GetSignInContinueUrl(),
1099 controller()->SignInContinueUrl(), 1097 content::Referrer(),
1100 content::Referrer(), 1098 CURRENT_TAB,
1101 content::PAGE_TRANSITION_FORM_SUBMIT, 1099 content::PAGE_TRANSITION_LINK,
groby-ooo-7-16 2014/01/03 00:10:22 Question - why the move to calling OpenURLFromTab
Evan Stade 2014/01/03 00:14:57 because I'm trying to test AutofillDialogSignInDel
1102 std::string()); 1100 true);
1101 sign_in_contents->GetDelegate()->OpenURLFromTab(sign_in_contents, params);
1103 1102
1104 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems()); 1103 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems());
1105 continue_page_observer.Wait(); 1104 continue_page_observer.Wait();
1106 content::RunAllPendingInMessageLoop(); 1105 content::RunAllPendingInMessageLoop();
1107 1106
1108 EXPECT_FALSE(controller()->ShouldShowSignInWebView()); 1107 EXPECT_FALSE(controller()->ShouldShowSignInWebView());
1109 1108
1110 controller()->OnDidGetWalletItems( 1109 controller()->OnDidGetWalletItems(
1111 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); 1110 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED));
1112 1111
1113 // Wallet should now be selected and Chrome shouldn't have crashed (which can 1112 // Wallet should now be selected and Chrome shouldn't have crashed (which can
1114 // happen if the WebContents is deleted while proccessing a nav entry commit). 1113 // happen if the WebContents is deleted while proccessing a nav entry commit).
1115 EXPECT_TRUE(account_chooser_model->WalletIsSelected()); 1114 EXPECT_TRUE(account_chooser_model->WalletIsSelected());
1116 } 1115 }
1117 1116
1118 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AddAccount) { 1117 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AddAccount) {
1118 wallet::SetUseTestingSignInContinueUrl();
1119 InitializeController(); 1119 InitializeController();
1120 1120
1121 controller()->OnDidFetchWalletCookieValue(std::string()); 1121 controller()->OnDidFetchWalletCookieValue(std::string());
1122 std::vector<std::string> usernames; 1122 std::vector<std::string> usernames;
1123 usernames.push_back("user_0@example.com"); 1123 usernames.push_back("user_0@example.com");
1124 controller()->OnDidGetWalletItems( 1124 controller()->OnDidGetWalletItems(
1125 wallet::GetTestWalletItemsWithUsers(usernames, 0)); 1125 wallet::GetTestWalletItemsWithUsers(usernames, 0));
1126 1126
1127 // Switch to Autofill. 1127 // Switch to Autofill.
1128 AccountChooserModel* account_chooser_model = 1128 AccountChooserModel* account_chooser_model =
(...skipping 10 matching lines...) Expand all
1139 account_chooser_model->GetItemCount() - 2); 1139 account_chooser_model->GetItemCount() - 2);
1140 EXPECT_TRUE(controller()->ShouldShowSignInWebView()); 1140 EXPECT_TRUE(controller()->ShouldShowSignInWebView());
1141 1141
1142 TestableAutofillDialogView* view = controller()->GetTestableView(); 1142 TestableAutofillDialogView* view = controller()->GetTestableView();
1143 content::WebContents* sign_in_contents = view->GetSignInWebContents(); 1143 content::WebContents* sign_in_contents = view->GetSignInWebContents();
1144 ASSERT_TRUE(sign_in_contents); 1144 ASSERT_TRUE(sign_in_contents);
1145 1145
1146 sign_in_page_observer.Wait(); 1146 sign_in_page_observer.Wait();
1147 1147
1148 NavEntryCommittedObserver continue_page_observer( 1148 NavEntryCommittedObserver continue_page_observer(
1149 controller()->SignInContinueUrl(), 1149 wallet::GetSignInContinueUrl(),
1150 content::NotificationService::AllSources()); 1150 content::NotificationService::AllSources());
1151 1151
1152 EXPECT_EQ(sign_in_contents->GetURL(), controller()->SignInUrl()); 1152 EXPECT_EQ(sign_in_contents->GetURL(), controller()->SignInUrl());
1153 1153
1154 EXPECT_FALSE(account_chooser_model->WalletIsSelected()); 1154 EXPECT_FALSE(account_chooser_model->WalletIsSelected());
1155 1155
1156 // User signs into new account, account 3. 1156 // User signs into new account, account 3.
1157 controller()->set_sign_in_user_index(3U); 1157 controller()->set_sign_in_user_index(3U);
1158 sign_in_contents->GetController().LoadURL( 1158 content::OpenURLParams params(wallet::GetSignInContinueUrl(),
1159 controller()->SignInContinueUrl(), 1159 content::Referrer(),
1160 content::Referrer(), 1160 CURRENT_TAB,
1161 content::PAGE_TRANSITION_FORM_SUBMIT, 1161 content::PAGE_TRANSITION_LINK,
1162 std::string()); 1162 true);
1163 sign_in_contents->GetDelegate()->OpenURLFromTab(sign_in_contents, params);
1163 1164
1164 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems()); 1165 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems());
1165 continue_page_observer.Wait(); 1166 continue_page_observer.Wait();
1166 content::RunAllPendingInMessageLoop(); 1167 content::RunAllPendingInMessageLoop();
1167 1168
1168 EXPECT_FALSE(controller()->ShouldShowSignInWebView()); 1169 EXPECT_FALSE(controller()->ShouldShowSignInWebView());
1169 EXPECT_EQ(3U, controller()->GetTestingWalletClient()->user_index()); 1170 EXPECT_EQ(3U, controller()->GetTestingWalletClient()->user_index());
1170 1171
1171 usernames.push_back("user_1@example.com"); 1172 usernames.push_back("user_1@example.com");
1172 usernames.push_back("user_2@example.com"); 1173 usernames.push_back("user_2@example.com");
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 MAYBE_DoesntWorkOnBrokenHttps) { 1419 MAYBE_DoesntWorkOnBrokenHttps) {
1419 net::SpawnedTestServer https_server( 1420 net::SpawnedTestServer https_server(
1420 net::SpawnedTestServer::TYPE_HTTPS, 1421 net::SpawnedTestServer::TYPE_HTTPS,
1421 SSLOptions(SSLOptions::CERT_EXPIRED), 1422 SSLOptions(SSLOptions::CERT_EXPIRED),
1422 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 1423 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1423 ASSERT_TRUE(https_server.Start()); 1424 ASSERT_TRUE(https_server.Start());
1424 EXPECT_FALSE(RunTestPage(https_server)); 1425 EXPECT_FALSE(RunTestPage(https_server));
1425 } 1426 }
1426 1427
1427 } // namespace autofill 1428 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698