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

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

Issue 14613002: Tests for invalid suggestions (i.e. expired cards) in the Autofill dialog. (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_unittest.cc » ('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/validation.h"
20 #include "components/autofill/browser/wallet/wallet_test_util.h" 21 #include "components/autofill/browser/wallet/wallet_test_util.h"
21 #include "components/autofill/common/form_data.h" 22 #include "components/autofill/common/form_data.h"
22 #include "components/autofill/common/form_field_data.h" 23 #include "components/autofill/common/form_field_data.h"
23 #include "content/public/test/test_utils.h" 24 #include "content/public/test/test_utils.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 26
26 namespace autofill { 27 namespace autofill {
27 28
28 namespace { 29 namespace {
29 30
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return ValidityData(); 110 return ValidityData();
110 } 111 }
111 112
112 // Saving to Chrome is tested in AutofillDialogController unit tests. 113 // Saving to Chrome is tested in AutofillDialogController unit tests.
113 // TODO(estade): test that the view defaults to saving to Chrome. 114 // TODO(estade): test that the view defaults to saving to Chrome.
114 virtual bool ShouldOfferToSaveInChrome() const OVERRIDE { 115 virtual bool ShouldOfferToSaveInChrome() const OVERRIDE {
115 return false; 116 return false;
116 } 117 }
117 118
118 // Increase visibility for testing. 119 // Increase visibility for testing.
119 AutofillDialogView* view() { return AutofillDialogControllerImpl::view(); } 120 using AutofillDialogControllerImpl::view;
120 const DetailInput* input_showing_popup() const { 121 using AutofillDialogControllerImpl::input_showing_popup;
121 return AutofillDialogControllerImpl::input_showing_popup();
122 }
123 122
124 TestPersonalDataManager* GetTestingManager() { 123 TestPersonalDataManager* GetTestingManager() {
125 return &test_manager_; 124 return &test_manager_;
126 } 125 }
127 126
127 bool IsSectionInEditState(DialogSection section) const {
128 const std::map<DialogSection, bool>& state = section_editing_state();
129 std::map<DialogSection, bool>::const_iterator it = state.find(section);
130 return it != state.end() && it->second;
131 }
132
128 using AutofillDialogControllerImpl::DisableWallet; 133 using AutofillDialogControllerImpl::DisableWallet;
129 134
130 protected: 135 protected:
131 virtual PersonalDataManager* GetManager() OVERRIDE { 136 virtual PersonalDataManager* GetManager() OVERRIDE {
132 return &test_manager_; 137 return &test_manager_;
133 } 138 }
134 139
135 private: 140 private:
136 // To specify our own metric logger. 141 // To specify our own metric logger.
137 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { 142 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 const DetailInputs& add_inputs = 463 const DetailInputs& add_inputs =
459 controller()->RequestedFieldsForSection(SECTION_CC_BILLING); 464 controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
460 for (i = 0; i < add_inputs.size(); ++i) { 465 for (i = 0; i < add_inputs.size(); ++i) {
461 if (add_inputs[i].type == CREDIT_CARD_NUMBER) { 466 if (add_inputs[i].type == CREDIT_CARD_NUMBER) {
462 EXPECT_TRUE(add_inputs[i].editable); 467 EXPECT_TRUE(add_inputs[i].editable);
463 break; 468 break;
464 } 469 }
465 } 470 }
466 ASSERT_LT(i, add_inputs.size()); 471 ASSERT_LT(i, add_inputs.size());
467 } 472 }
473
474 // Ensure that expired cards trigger invalid suggestions.
475 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, ExpiredCard) {
476 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
477 controller()->DisableWallet();
478
479 CreditCard verified_card(test::GetCreditCard());
480 verified_card.set_origin("Chrome settings");
481 ASSERT_TRUE(verified_card.IsVerified());
482 controller()->GetTestingManager()->AddTestingCreditCard(&verified_card);
483
484 CreditCard expired_card(test::GetCreditCard());
485 expired_card.set_origin("Chrome settings");
486 expired_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2007"));
487 ASSERT_TRUE(expired_card.IsVerified());
488 ASSERT_FALSE(
489 autofill::IsValidCreditCardExpirationDate(
490 expired_card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR),
491 expired_card.GetRawInfo(CREDIT_CARD_EXP_MONTH),
492 base::Time::Now()));
493 controller()->GetTestingManager()->AddTestingCreditCard(&expired_card);
494
495 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_CC);
496 ASSERT_EQ(4, model->GetItemCount());
497
498 ASSERT_TRUE(model->IsItemCheckedAt(0));
499 EXPECT_FALSE(controller()->IsSectionInEditState(SECTION_CC));
500
501 model->ActivatedAt(1);
502 ASSERT_TRUE(model->IsItemCheckedAt(1));
503 EXPECT_TRUE(controller()->IsSectionInEditState(SECTION_CC));
504 }
468 #endif // defined(TOOLKIT_VIEWS) 505 #endif // defined(TOOLKIT_VIEWS)
469 506
470 } // namespace autofill 507 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698