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

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 1899893002: Card unmasking without form filling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 form->fields[1], *card); 926 form->fields[1], *card);
927 autofill_manager_->FillOrPreviewCreditCardForm( 927 autofill_manager_->FillOrPreviewCreditCardForm(
928 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, 928 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form,
929 form->fields[2], *card); 929 form->fields[2], *card);
930 autofill_manager_->FillOrPreviewCreditCardForm( 930 autofill_manager_->FillOrPreviewCreditCardForm(
931 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, 931 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form,
932 form->fields[3], *card); 932 form->fields[3], *card);
933 #endif // defined(OS_IOS) 933 #endif // defined(OS_IOS)
934 } 934 }
935 935
936 // Convenience method to cast the FullCardRequest into a CardUnmaskDelegate.
937 CardUnmaskDelegate* full_card_unmask_delegate() {
938 DCHECK(autofill_manager_->full_card_request_);
939 return (CardUnmaskDelegate*)autofill_manager_->full_card_request_.get();
940 }
941
936 protected: 942 protected:
937 base::MessageLoop message_loop_; 943 base::MessageLoop message_loop_;
938 MockAutofillClient autofill_client_; 944 MockAutofillClient autofill_client_;
939 std::unique_ptr<MockAutofillDriver> autofill_driver_; 945 std::unique_ptr<MockAutofillDriver> autofill_driver_;
940 std::unique_ptr<TestAutofillManager> autofill_manager_; 946 std::unique_ptr<TestAutofillManager> autofill_manager_;
941 std::unique_ptr<TestAutofillExternalDelegate> external_delegate_; 947 std::unique_ptr<TestAutofillExternalDelegate> external_delegate_;
942 scoped_refptr<net::TestURLRequestContextGetter> request_context_; 948 scoped_refptr<net::TestURLRequestContextGetter> request_context_;
943 TestPaymentsClient* payments_client_; 949 TestPaymentsClient* payments_client_;
944 TestAutofillDownloadManager* download_manager_; 950 TestAutofillDownloadManager* download_manager_;
945 TestPersonalDataManager personal_data_; 951 TestPersonalDataManager personal_data_;
(...skipping 3195 matching lines...) Expand 10 before | Expand all | Expand 10 after
4141 if (form.fields[i].name == ASCIIToUTF16("cardnumber")) 4147 if (form.fields[i].name == ASCIIToUTF16("cardnumber"))
4142 form.fields[i].value = ASCIIToUTF16("4012888888881881"); 4148 form.fields[i].value = ASCIIToUTF16("4012888888881881");
4143 else if (form.fields[i].name == ASCIIToUTF16("nameoncard")) 4149 else if (form.fields[i].name == ASCIIToUTF16("nameoncard"))
4144 form.fields[i].value = ASCIIToUTF16("John H Dillinger"); 4150 form.fields[i].value = ASCIIToUTF16("John H Dillinger");
4145 else if (form.fields[i].name == ASCIIToUTF16("ccmonth")) 4151 else if (form.fields[i].name == ASCIIToUTF16("ccmonth"))
4146 form.fields[i].value = ASCIIToUTF16("01"); 4152 form.fields[i].value = ASCIIToUTF16("01");
4147 else if (form.fields[i].name == ASCIIToUTF16("ccyear")) 4153 else if (form.fields[i].name == ASCIIToUTF16("ccyear"))
4148 form.fields[i].value = ASCIIToUTF16("2017"); 4154 form.fields[i].value = ASCIIToUTF16("2017");
4149 } 4155 }
4150 4156
4151 AutofillManager::UnmaskResponse response; 4157 autofill_manager_->GetOrCreateFullCardRequest()->GetFullCard(
4158 card, AutofillClient::UNMASK_FOR_AUTOFILL,
4159 autofill_manager_->weak_ptr_factory_.GetWeakPtr());
4160
4161 CardUnmaskDelegate::UnmaskResponse response;
4152 response.should_store_pan = false; 4162 response.should_store_pan = false;
4153 response.cvc = ASCIIToUTF16("123"); 4163 response.cvc = ASCIIToUTF16("123");
4154 autofill_manager_->OnUnmaskResponse(response); 4164 full_card_unmask_delegate()->OnUnmaskResponse(response);
4165
4155 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, 4166 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS,
4156 "4012888888881881"); 4167 "4012888888881881");
4168
4157 autofill_manager_->OnFormSubmitted(form); 4169 autofill_manager_->OnFormSubmitted(form);
4158 } 4170 }
4159 4171
4160 TEST_F(AutofillManagerTest, FillInUpdatedExpirationDate) { 4172 TEST_F(AutofillManagerTest, FillInUpdatedExpirationDate) {
4161 FormData form; 4173 FormData form;
4162 CreditCard card; 4174 CreditCard card;
4163 PrepareForRealPanResponse(&form, &card); 4175 PrepareForRealPanResponse(&form, &card);
4164 4176
4165 AutofillManager::UnmaskResponse response; 4177 CardUnmaskDelegate::UnmaskResponse response;
4166 response.should_store_pan = false; 4178 response.should_store_pan = false;
4167 response.cvc = ASCIIToUTF16("123"); 4179 response.cvc = ASCIIToUTF16("123");
4168 response.exp_month = ASCIIToUTF16("02"); 4180 response.exp_month = ASCIIToUTF16("02");
4169 response.exp_year = ASCIIToUTF16("2018"); 4181 response.exp_year = ASCIIToUTF16("2018");
4170 autofill_manager_->OnUnmaskResponse(response); 4182 full_card_unmask_delegate()->OnUnmaskResponse(response);
4183
4171 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, 4184 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS,
4172 "4012888888881881"); 4185 "4012888888881881");
4173
4174 EXPECT_EQ(ASCIIToUTF16("02"),
4175 autofill_manager_->unmask_request_.card.GetRawInfo(
4176 CREDIT_CARD_EXP_MONTH));
4177 EXPECT_EQ(ASCIIToUTF16("2018"),
4178 autofill_manager_->unmask_request_.card.GetRawInfo(
4179 CREDIT_CARD_EXP_4_DIGIT_YEAR));
4180 } 4186 }
4181 4187
4182 TEST_F(AutofillManagerTest, UploadCreditCard) { 4188 TEST_F(AutofillManagerTest, UploadCreditCard) {
4183 autofill_manager_->set_credit_card_upload_enabled(true); 4189 autofill_manager_->set_credit_card_upload_enabled(true);
4184 4190
4185 // Create, fill and submit an address form in order to establish a recent 4191 // Create, fill and submit an address form in order to establish a recent
4186 // profile which can be selected for the upload request. 4192 // profile which can be selected for the upload request.
4187 FormData address_form; 4193 FormData address_form;
4188 test::CreateTestAddressFormData(&address_form); 4194 test::CreateTestAddressFormData(&address_form);
4189 FormsSeen(std::vector<FormData>(1, address_form)); 4195 FormsSeen(std::vector<FormData>(1, address_form));
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
4947 FormsSeen(mixed_forms); 4953 FormsSeen(mixed_forms);
4948 4954
4949 // Suggestions should always be displayed. 4955 // Suggestions should always be displayed.
4950 for (const FormFieldData& field : mixed_form.fields) { 4956 for (const FormFieldData& field : mixed_form.fields) {
4951 GetAutofillSuggestions(mixed_form, field); 4957 GetAutofillSuggestions(mixed_form, field);
4952 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); 4958 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
4953 } 4959 }
4954 } 4960 }
4955 4961
4956 } // namespace autofill 4962 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698