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

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

Issue 15979002: Making credit card number un-editable in Wallet mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/ui/autofill/autofill_dialog_controller_impl.h » ('j') | 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/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
11 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" 11 #include "chrome/browser/ui/autofill/autofill_dialog_view.h"
12 #include "chrome/browser/ui/autofill/data_model_wrapper.h" 12 #include "chrome/browser/ui/autofill/data_model_wrapper.h"
13 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" 13 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "components/autofill/browser/autofill_common_test.h" 17 #include "components/autofill/browser/autofill_common_test.h"
18 #include "components/autofill/browser/autofill_metrics.h" 18 #include "components/autofill/browser/autofill_metrics.h"
19 #include "components/autofill/browser/test_personal_data_manager.h" 19 #include "components/autofill/browser/test_personal_data_manager.h"
20 #include "components/autofill/browser/wallet/wallet_test_util.h"
20 #include "components/autofill/common/form_data.h" 21 #include "components/autofill/common/form_data.h"
21 #include "components/autofill/common/form_field_data.h" 22 #include "components/autofill/common/form_field_data.h"
22 #include "content/public/test/test_utils.h" 23 #include "content/public/test/test_utils.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 namespace autofill { 26 namespace autofill {
26 27
27 namespace { 28 namespace {
28 29
29 void MockCallback(const FormStructure*, const std::string&) {} 30 void MockCallback(const FormStructure*, const std::string&) {}
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 const FormData& form_data, 81 const FormData& form_data,
81 const AutofillMetrics& metric_logger, 82 const AutofillMetrics& metric_logger,
82 scoped_refptr<content::MessageLoopRunner> runner, 83 scoped_refptr<content::MessageLoopRunner> runner,
83 const DialogType dialog_type) 84 const DialogType dialog_type)
84 : AutofillDialogControllerImpl(contents, 85 : AutofillDialogControllerImpl(contents,
85 form_data, 86 form_data,
86 GURL(), 87 GURL(),
87 dialog_type, 88 dialog_type,
88 base::Bind(&MockCallback)), 89 base::Bind(&MockCallback)),
89 metric_logger_(metric_logger), 90 metric_logger_(metric_logger),
90 message_loop_runner_(runner) { 91 message_loop_runner_(runner) {}
91 DisableWallet();
92 }
93 92
94 virtual ~TestAutofillDialogController() {} 93 virtual ~TestAutofillDialogController() {}
95 94
96 virtual void ViewClosed() OVERRIDE { 95 virtual void ViewClosed() OVERRIDE {
97 message_loop_runner_->Quit(); 96 message_loop_runner_->Quit();
98 AutofillDialogControllerImpl::ViewClosed(); 97 AutofillDialogControllerImpl::ViewClosed();
99 } 98 }
100 99
101 virtual string16 InputValidityMessage( 100 virtual string16 InputValidityMessage(
102 AutofillFieldType type, 101 AutofillFieldType type,
(...skipping 16 matching lines...) Expand all
119 // Increase visibility for testing. 118 // Increase visibility for testing.
120 AutofillDialogView* view() { return AutofillDialogControllerImpl::view(); } 119 AutofillDialogView* view() { return AutofillDialogControllerImpl::view(); }
121 const DetailInput* input_showing_popup() const { 120 const DetailInput* input_showing_popup() const {
122 return AutofillDialogControllerImpl::input_showing_popup(); 121 return AutofillDialogControllerImpl::input_showing_popup();
123 } 122 }
124 123
125 TestPersonalDataManager* GetTestingManager() { 124 TestPersonalDataManager* GetTestingManager() {
126 return &test_manager_; 125 return &test_manager_;
127 } 126 }
128 127
128 using AutofillDialogControllerImpl::DisableWallet;
129
129 protected: 130 protected:
130 virtual PersonalDataManager* GetManager() OVERRIDE { 131 virtual PersonalDataManager* GetManager() OVERRIDE {
131 return &test_manager_; 132 return &test_manager_;
132 } 133 }
133 134
134 private: 135 private:
135 // To specify our own metric logger. 136 // To specify our own metric logger.
136 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { 137 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
137 return metric_logger_; 138 return metric_logger_;
138 } 139 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 controller()->OnAutocheckoutError(); 260 controller()->OnAutocheckoutError();
260 controller()->view()->GetTestableView()->CancelForTesting(); 261 controller()->view()->GetTestableView()->CancelForTesting();
261 RunMessageLoop(); 262 RunMessageLoop();
262 263
263 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_FAILED, 264 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_FAILED,
264 metric_logger().autocheckout_status()); 265 metric_logger().autocheckout_status());
265 } 266 }
266 267
267 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { 268 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) {
268 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); 269 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
270 controller()->DisableWallet();
269 271
270 AutofillProfile full_profile(test::GetFullProfile()); 272 AutofillProfile full_profile(test::GetFullProfile());
271 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 273 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
272 274
273 const DetailInputs& inputs = 275 const DetailInputs& inputs =
274 controller()->RequestedFieldsForSection(SECTION_SHIPPING); 276 controller()->RequestedFieldsForSection(SECTION_SHIPPING);
275 const DetailInput& triggering_input = inputs[0]; 277 const DetailInput& triggering_input = inputs[0];
276 string16 value = full_profile.GetRawInfo(triggering_input.type); 278 string16 value = full_profile.GetRawInfo(triggering_input.type);
277 TestableAutofillDialogView* view = controller()->view()->GetTestableView(); 279 TestableAutofillDialogView* view = controller()->view()->GetTestableView();
278 view->SetTextContentsOfInput(triggering_input, 280 view->SetTextContentsOfInput(triggering_input,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 338
337 controller()->view()->GetTestableView()->SubmitForTesting(); 339 controller()->view()->GetTestableView()->SubmitForTesting();
338 EXPECT_TRUE(controller()->ShouldShowDetailArea()); 340 EXPECT_TRUE(controller()->ShouldShowDetailArea());
339 EXPECT_FALSE(controller()->ShouldShowProgressBar()); 341 EXPECT_FALSE(controller()->ShouldShowProgressBar());
340 } 342 }
341 343
342 // Tests that changing the value of a CC expiration date combobox works as 344 // Tests that changing the value of a CC expiration date combobox works as
343 // expected when Autofill is used to fill text inputs. 345 // expected when Autofill is used to fill text inputs.
344 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillComboboxFromAutofill) { 346 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillComboboxFromAutofill) {
345 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); 347 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
348 controller()->DisableWallet();
346 349
347 CreditCard card1; 350 CreditCard card1;
348 test::SetCreditCardInfo(&card1, "JJ Smith", "4111111111111111", "12", "2018"); 351 test::SetCreditCardInfo(&card1, "JJ Smith", "4111111111111111", "12", "2018");
349 controller()->GetTestingManager()->AddTestingCreditCard(&card1); 352 controller()->GetTestingManager()->AddTestingCreditCard(&card1);
350 CreditCard card2; 353 CreditCard card2;
351 test::SetCreditCardInfo(&card2, "B Bird", "3111111111111111", "11", "2017"); 354 test::SetCreditCardInfo(&card2, "B Bird", "3111111111111111", "11", "2017");
352 controller()->GetTestingManager()->AddTestingCreditCard(&card2); 355 controller()->GetTestingManager()->AddTestingCreditCard(&card2);
353 AutofillProfile full_profile(test::GetFullProfile()); 356 AutofillProfile full_profile(test::GetFullProfile());
354 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 357 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
355 358
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 EXPECT_EQ(wrapper2.GetInfo(input.type), 420 EXPECT_EQ(wrapper2.GetInfo(input.type),
418 view->GetTextContentsOfInput(input)); 421 view->GetTextContentsOfInput(input));
419 } else if (input.type == CREDIT_CARD_VERIFICATION_CODE) { 422 } else if (input.type == CREDIT_CARD_VERIFICATION_CODE) {
420 EXPECT_TRUE(view->GetTextContentsOfInput(input).empty()); 423 EXPECT_TRUE(view->GetTextContentsOfInput(input).empty());
421 } else { 424 } else {
422 EXPECT_EQ(wrapper1.GetInfo(input.type), 425 EXPECT_EQ(wrapper1.GetInfo(input.type),
423 view->GetTextContentsOfInput(input)); 426 view->GetTextContentsOfInput(input));
424 } 427 }
425 } 428 }
426 } 429 }
430
431 // Tests that credit card number is disabled while editing a Wallet instrument.
432 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, WalletCreditCardDisabled) {
433 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
434 controller()->OnUserNameFetchSuccess("user@example.com");
435
436 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
437 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
438 controller()->OnDidGetWalletItems(wallet_items.Pass());
439
440 // Click "Edit" in the billing section (while using Wallet).
441 controller()->EditClickedForSection(SECTION_CC_BILLING);
442
443 const DetailInputs& edit_inputs =
444 controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
445 size_t i;
446 for (i = 0; i < edit_inputs.size(); ++i) {
447 if (edit_inputs[i].type == CREDIT_CARD_NUMBER) {
448 EXPECT_FALSE(edit_inputs[i].editable);
449 break;
450 }
451 }
452 ASSERT_LT(i, edit_inputs.size());
453
454 // Select "Add new billing info..." while using Wallet.
455 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_CC_BILLING);
456 model->ActivatedAt(model->GetItemCount() - 2);
457
458 const DetailInputs& add_inputs =
459 controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
460 for (i = 0; i < add_inputs.size(); ++i) {
461 if (add_inputs[i].type == CREDIT_CARD_NUMBER) {
462 EXPECT_TRUE(add_inputs[i].editable);
463 break;
464 }
465 }
466 ASSERT_LT(i, add_inputs.size());
467 }
427 #endif // defined(TOOLKIT_VIEWS) 468 #endif // defined(TOOLKIT_VIEWS)
428 469
429 } // namespace autofill 470 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/autofill/autofill_dialog_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698