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

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

Issue 18888003: Disabling wallet and mocking out more of WalletClient while testing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: isherman@ review Created 7 years, 5 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 <map> 5 #include <map>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 15 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
16 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" 16 #include "chrome/browser/ui/autofill/autofill_dialog_view.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
19 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" 19 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h"
20 #include "components/autofill/content/browser/wallet/full_wallet.h" 20 #include "components/autofill/content/browser/wallet/full_wallet.h"
21 #include "components/autofill/content/browser/wallet/instrument.h" 21 #include "components/autofill/content/browser/wallet/instrument.h"
22 #include "components/autofill/content/browser/wallet/mock_wallet_client.h"
22 #include "components/autofill/content/browser/wallet/wallet_address.h" 23 #include "components/autofill/content/browser/wallet/wallet_address.h"
23 #include "components/autofill/content/browser/wallet/wallet_client.h"
24 #include "components/autofill/content/browser/wallet/wallet_service_url.h" 24 #include "components/autofill/content/browser/wallet/wallet_service_url.h"
25 #include "components/autofill/content/browser/wallet/wallet_test_util.h" 25 #include "components/autofill/content/browser/wallet/wallet_test_util.h"
26 #include "components/autofill/core/browser/autofill_common_test.h" 26 #include "components/autofill/core/browser/autofill_common_test.h"
27 #include "components/autofill/core/browser/autofill_metrics.h" 27 #include "components/autofill/core/browser/autofill_metrics.h"
28 #include "components/autofill/core/browser/test_personal_data_manager.h" 28 #include "components/autofill/core/browser/test_personal_data_manager.h"
29 #include "components/autofill/core/common/autofill_switches.h" 29 #include "components/autofill/core/common/autofill_switches.h"
30 #include "components/autofill/core/common/form_data.h" 30 #include "components/autofill/core/common/form_data.h"
31 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
32 #include "content/public/test/test_browser_thread_bundle.h" 32 #include "content/public/test/test_browser_thread_bundle.h"
33 #include "content/public/test/web_contents_tester.h" 33 #include "content/public/test/web_contents_tester.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 void SetUserInput(DialogSection section, const DetailOutputMap& map) { 153 void SetUserInput(DialogSection section, const DetailOutputMap& map) {
154 outputs_[section] = map; 154 outputs_[section] = map;
155 } 155 }
156 156
157 private: 157 private:
158 std::map<DialogSection, DetailOutputMap> outputs_; 158 std::map<DialogSection, DetailOutputMap> outputs_;
159 159
160 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView); 160 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView);
161 }; 161 };
162 162
163 class TestWalletClient : public wallet::WalletClient {
164 public:
165 TestWalletClient(net::URLRequestContextGetter* context,
166 wallet::WalletClientDelegate* delegate)
167 : wallet::WalletClient(context, delegate) {}
168 virtual ~TestWalletClient() {}
169
170 MOCK_METHOD3(AcceptLegalDocuments,
171 void(const std::vector<wallet::WalletItems::LegalDocument*>& documents,
172 const std::string& google_transaction_id,
173 const GURL& source_url));
174
175 MOCK_METHOD3(AuthenticateInstrument,
176 void(const std::string& instrument_id,
177 const std::string& card_verification_number,
178 const std::string& obfuscated_gaia_id));
179
180 MOCK_METHOD1(GetFullWallet,
181 void(const wallet::WalletClient::FullWalletRequest& request));
182
183 MOCK_METHOD1(GetWalletItems, void(const GURL& source_url));
184
185 MOCK_METHOD2(SaveAddress,
186 void(const wallet::Address& address, const GURL& source_url));
187
188 MOCK_METHOD3(SaveInstrument,
189 void(const wallet::Instrument& instrument,
190 const std::string& obfuscated_gaia_id,
191 const GURL& source_url));
192
193 MOCK_METHOD4(SaveInstrumentAndAddress,
194 void(const wallet::Instrument& instrument,
195 const wallet::Address& address,
196 const std::string& obfuscated_gaia_id,
197 const GURL& source_url));
198
199 MOCK_METHOD2(UpdateAddress,
200 void(const wallet::Address& address, const GURL& source_url));
201
202 virtual void UpdateInstrument(
203 const wallet::WalletClient::UpdateInstrumentRequest& update_request,
204 scoped_ptr<wallet::Address> billing_address) {
205 updated_billing_address_ = billing_address.Pass();
206 }
207
208 const wallet::Address* updated_billing_address() {
209 return updated_billing_address_.get();
210 }
211
212 private:
213 scoped_ptr<wallet::Address> updated_billing_address_;
214
215 DISALLOW_COPY_AND_ASSIGN(TestWalletClient);
216 };
217
218 // Bring over command-ids from AccountChooserModel. 163 // Bring over command-ids from AccountChooserModel.
219 class TestAccountChooserModel : public AccountChooserModel { 164 class TestAccountChooserModel : public AccountChooserModel {
220 public: 165 public:
221 TestAccountChooserModel(AccountChooserModelDelegate* delegate, 166 TestAccountChooserModel(AccountChooserModelDelegate* delegate,
222 PrefService* prefs, 167 PrefService* prefs,
223 const AutofillMetrics& metric_logger) 168 const AutofillMetrics& metric_logger)
224 : AccountChooserModel(delegate, prefs, metric_logger, 169 : AccountChooserModel(delegate, prefs, metric_logger,
225 DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {} 170 DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {}
226 virtual ~TestAccountChooserModel() {} 171 virtual ~TestAccountChooserModel() {}
227 172
(...skipping 15 matching lines...) Expand all
243 const AutofillMetrics& metric_logger, 188 const AutofillMetrics& metric_logger,
244 const DialogType dialog_type, 189 const DialogType dialog_type,
245 const base::Callback<void(const FormStructure*, 190 const base::Callback<void(const FormStructure*,
246 const std::string&)>& callback) 191 const std::string&)>& callback)
247 : AutofillDialogControllerImpl(contents, 192 : AutofillDialogControllerImpl(contents,
248 form_structure, 193 form_structure,
249 source_url, 194 source_url,
250 dialog_type, 195 dialog_type,
251 callback), 196 callback),
252 metric_logger_(metric_logger), 197 metric_logger_(metric_logger),
253 test_wallet_client_( 198 mock_wallet_client_(
254 Profile::FromBrowserContext(contents->GetBrowserContext())-> 199 Profile::FromBrowserContext(contents->GetBrowserContext())->
255 GetRequestContext(), this), 200 GetRequestContext(), this),
256 dialog_type_(dialog_type) {} 201 dialog_type_(dialog_type) {}
257 virtual ~TestAutofillDialogController() {} 202 virtual ~TestAutofillDialogController() {}
258 203
259 virtual AutofillDialogView* CreateView() OVERRIDE { 204 virtual AutofillDialogView* CreateView() OVERRIDE {
260 return new testing::NiceMock<TestAutofillDialogView>(); 205 return new testing::NiceMock<TestAutofillDialogView>();
261 } 206 }
262 207
263 void Init(content::BrowserContext* browser_context) { 208 void Init(content::BrowserContext* browser_context) {
264 test_manager_.Init(browser_context); 209 test_manager_.Init(browser_context);
265 } 210 }
266 211
267 TestAutofillDialogView* GetView() { 212 TestAutofillDialogView* GetView() {
268 return static_cast<TestAutofillDialogView*>(view()); 213 return static_cast<TestAutofillDialogView*>(view());
269 } 214 }
270 215
271 TestPersonalDataManager* GetTestingManager() { 216 TestPersonalDataManager* GetTestingManager() {
272 return &test_manager_; 217 return &test_manager_;
273 } 218 }
274 219
275 TestWalletClient* GetTestingWalletClient() { 220 wallet::MockWalletClient* GetTestingWalletClient() {
276 return &test_wallet_client_; 221 return &mock_wallet_client_;
277 } 222 }
278 223
279 const GURL& open_tab_url() { return open_tab_url_; } 224 const GURL& open_tab_url() { return open_tab_url_; }
280 225
281 virtual DialogType GetDialogType() const OVERRIDE { 226 virtual DialogType GetDialogType() const OVERRIDE {
282 return dialog_type_; 227 return dialog_type_;
283 } 228 }
284 229
285 void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; } 230 void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; }
286 231
287 void SimulateSigninError() { 232 void SimulateSigninError() {
288 OnWalletSigninError(); 233 OnWalletSigninError();
289 } 234 }
290 235
291 MOCK_METHOD0(LoadRiskFingerprintData, void()); 236 MOCK_METHOD0(LoadRiskFingerprintData, void());
292 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; 237 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData;
293 using AutofillDialogControllerImpl::IsEditingExistingData; 238 using AutofillDialogControllerImpl::IsEditingExistingData;
294 239
295 protected: 240 protected:
296 virtual PersonalDataManager* GetManager() OVERRIDE { 241 virtual PersonalDataManager* GetManager() OVERRIDE {
297 return &test_manager_; 242 return &test_manager_;
298 } 243 }
299 244
300 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { 245 virtual wallet::WalletClient* GetWalletClient() OVERRIDE {
301 return &test_wallet_client_; 246 return &mock_wallet_client_;
302 } 247 }
303 248
304 virtual void OpenTabWithUrl(const GURL& url) OVERRIDE { 249 virtual void OpenTabWithUrl(const GURL& url) OVERRIDE {
305 open_tab_url_ = url; 250 open_tab_url_ = url;
306 } 251 }
307 252
308 // Whether the information input in this dialog will be securely transmitted 253 // Whether the information input in this dialog will be securely transmitted
309 // to the requesting site. 254 // to the requesting site.
310 virtual bool TransmissionWillBeSecure() const OVERRIDE { 255 virtual bool TransmissionWillBeSecure() const OVERRIDE {
311 return true; 256 return true;
312 } 257 }
313 258
314 private: 259 private:
315 // To specify our own metric logger. 260 // To specify our own metric logger.
316 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { 261 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
317 return metric_logger_; 262 return metric_logger_;
318 } 263 }
319 264
320 const AutofillMetrics& metric_logger_; 265 const AutofillMetrics& metric_logger_;
321 TestPersonalDataManager test_manager_; 266 TestPersonalDataManager test_manager_;
322 testing::NiceMock<TestWalletClient> test_wallet_client_; 267 testing::NiceMock<wallet::MockWalletClient> mock_wallet_client_;
323 GURL open_tab_url_; 268 GURL open_tab_url_;
324 DialogType dialog_type_; 269 DialogType dialog_type_;
325 270
326 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); 271 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
327 }; 272 };
328 273
329 class AutofillDialogControllerTest : public testing::Test { 274 class AutofillDialogControllerTest : public testing::Test {
330 protected: 275 protected:
331 AutofillDialogControllerTest() 276 AutofillDialogControllerTest()
332 : form_structure_(NULL) { 277 : form_structure_(NULL) {
(...skipping 1889 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 controller()->CurrentAutocheckoutSteps()[1].type()); 2167 controller()->CurrentAutocheckoutSteps()[1].type());
2223 EXPECT_EQ(AUTOCHECKOUT_STEP_STARTED, 2168 EXPECT_EQ(AUTOCHECKOUT_STEP_STARTED,
2224 controller()->CurrentAutocheckoutSteps()[1].status()); 2169 controller()->CurrentAutocheckoutSteps()[1].status());
2225 EXPECT_EQ(AUTOCHECKOUT_STEP_BILLING, 2170 EXPECT_EQ(AUTOCHECKOUT_STEP_BILLING,
2226 controller()->CurrentAutocheckoutSteps()[2].type()); 2171 controller()->CurrentAutocheckoutSteps()[2].type());
2227 EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED, 2172 EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED,
2228 controller()->CurrentAutocheckoutSteps()[2].status()); 2173 controller()->CurrentAutocheckoutSteps()[2].status());
2229 } 2174 }
2230 2175
2231 } // namespace autofill 2176 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc ('k') | components/autofill.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698