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

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

Issue 1137403002: Add upstream bits necessary for iOS card unmask prompt. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix autofill tests on iOS Created 5 years, 7 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 FormFieldData* month_field = nullptr; 1506 FormFieldData* month_field = nullptr;
1507 for (size_t i = 0; i < form.fields.size(); ++i) { 1507 for (size_t i = 0; i < form.fields.size(); ++i) {
1508 if (form.fields[i].name == ASCIIToUTF16("cardnumber")) 1508 if (form.fields[i].name == ASCIIToUTF16("cardnumber"))
1509 number_field = &form.fields[i]; 1509 number_field = &form.fields[i];
1510 else if (form.fields[i].name == ASCIIToUTF16("nameoncard")) 1510 else if (form.fields[i].name == ASCIIToUTF16("nameoncard"))
1511 name_field = &form.fields[i]; 1511 name_field = &form.fields[i];
1512 else if (form.fields[i].name == ASCIIToUTF16("ccmonth")) 1512 else if (form.fields[i].name == ASCIIToUTF16("ccmonth"))
1513 month_field = &form.fields[i]; 1513 month_field = &form.fields[i];
1514 } 1514 }
1515 1515
1516 // Empty form - whole form is Autofilled. 1516 // Empty form - whole form is Autofilled (except on iOS).
1517 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); 1517 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field));
1518 #if defined(OS_IOS)
1519 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field));
1520 #else
1518 EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field)); 1521 EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field));
1522 #endif // defined(OS_IOS)
1523
1519 // If the user has entered a value, it won't be overridden. 1524 // If the user has entered a value, it won't be overridden.
1520 number_field->value = ASCIIToUTF16("gibberish"); 1525 number_field->value = ASCIIToUTF16("gibberish");
1521 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); 1526 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field));
1522 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); 1527 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field));
1528
1529 // But if that value is removed, it will be Autofilled (except on iOS).
1523 number_field->value.clear(); 1530 number_field->value.clear();
1531 #if defined(OS_IOS)
1532 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field));
1533 #else
1524 EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field)); 1534 EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field));
1535 #endif // defined(OS_IOS)
1525 1536
1526 // When part of the section is Autofilled, only fill the initiating field. 1537 // When part of the section is Autofilled, only fill the initiating field.
1527 month_field->is_autofilled = true; 1538 month_field->is_autofilled = true;
1528 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field)); 1539 EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field));
1529 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field)); 1540 EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field));
1530 } 1541 }
1531 1542
1532 // Test that we correctly fill an address form from an auxiliary profile. 1543 // Test that we correctly fill an address form from an auxiliary profile.
1533 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) { 1544 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) {
1534 personal_data_.ClearAutofillProfiles(); 1545 personal_data_.ClearAutofillProfiles();
(...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after
3190 test::SetCreditCardInfo(&card, "John Dillinger", "1881" /* Visa */, "01", 3201 test::SetCreditCardInfo(&card, "John Dillinger", "1881" /* Visa */, "01",
3191 "2017"); 3202 "2017");
3192 card.SetTypeForMaskedCard(kVisaCard); 3203 card.SetTypeForMaskedCard(kVisaCard);
3193 3204
3194 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCard(_)).Times(0); 3205 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCard(_)).Times(0);
3195 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)); 3206 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _));
3196 autofill_manager_->FillOrPreviewCreditCardForm( 3207 autofill_manager_->FillOrPreviewCreditCardForm(
3197 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, form, 3208 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, form,
3198 form.fields[0], card, 0); 3209 form.fields[0], card, 0);
3199 3210
3200 // Manually fill out |form| so we can use it in OnFormSubmitted. 3211 // Manually fill out |form| so we can use it in OnFormSubmitted. On iOS, only
3212 // the selected field (the first one as specified in the call to
3213 // FillOrPreviewCreditCardForm below) is filled out because the actual
3214 // implementation only fills one field out at a time.
3215 #if defined(OS_IOS)
3216 form.fields[0].value = ASCIIToUTF16("some data");
3217 #else
3201 for (size_t i = 0; i < form.fields.size(); ++i) { 3218 for (size_t i = 0; i < form.fields.size(); ++i) {
3202 if (form.fields[i].name == ASCIIToUTF16("cardnumber")) 3219 if (form.fields[i].name == ASCIIToUTF16("cardnumber"))
3203 form.fields[i].value = ASCIIToUTF16("4012888888881881"); 3220 form.fields[i].value = ASCIIToUTF16("4012888888881881");
3204 else if (form.fields[i].name == ASCIIToUTF16("nameoncard")) 3221 else if (form.fields[i].name == ASCIIToUTF16("nameoncard"))
3205 form.fields[i].value = ASCIIToUTF16("John H Dillinger"); 3222 form.fields[i].value = ASCIIToUTF16("John H Dillinger");
3206 else if (form.fields[i].name == ASCIIToUTF16("ccmonth")) 3223 else if (form.fields[i].name == ASCIIToUTF16("ccmonth"))
3207 form.fields[i].value = ASCIIToUTF16("01"); 3224 form.fields[i].value = ASCIIToUTF16("01");
3208 else if (form.fields[i].name == ASCIIToUTF16("ccyear")) 3225 else if (form.fields[i].name == ASCIIToUTF16("ccyear"))
3209 form.fields[i].value = ASCIIToUTF16("2017"); 3226 form.fields[i].value = ASCIIToUTF16("2017");
3210 } 3227 }
3228 #endif // defined(OS_IOS)
3211 3229
3212 AutofillManager::UnmaskResponse response; 3230 AutofillManager::UnmaskResponse response;
3213 response.should_store_pan = false; 3231 response.should_store_pan = false;
3214 response.cvc = ASCIIToUTF16("123"); 3232 response.cvc = ASCIIToUTF16("123");
3215 autofill_manager_->OnUnmaskResponse(response); 3233 autofill_manager_->OnUnmaskResponse(response);
3216 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS, 3234 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS,
3217 "4012888888881881"); 3235 "4012888888881881");
3218 autofill_manager_->OnFormSubmitted(form); 3236 autofill_manager_->OnFormSubmitted(form);
3219 3237
3220 // The rest of this test is a regression test for http://crbug.com/483602. 3238 // The rest of this test is a regression test for http://crbug.com/483602.
(...skipping 26 matching lines...) Expand all
3247 form.fields[i].value = ASCIIToUTF16("Texas"); 3265 form.fields[i].value = ASCIIToUTF16("Texas");
3248 else if (form.fields[i].name == ASCIIToUTF16("zipcode")) 3266 else if (form.fields[i].name == ASCIIToUTF16("zipcode"))
3249 form.fields[i].value = ASCIIToUTF16("77401"); 3267 form.fields[i].value = ASCIIToUTF16("77401");
3250 else if (form.fields[i].name == ASCIIToUTF16("country")) 3268 else if (form.fields[i].name == ASCIIToUTF16("country"))
3251 form.fields[i].value = ASCIIToUTF16("US"); 3269 form.fields[i].value = ASCIIToUTF16("US");
3252 } 3270 }
3253 autofill_manager_->OnFormSubmitted(form); 3271 autofill_manager_->OnFormSubmitted(form);
3254 } 3272 }
3255 3273
3256 } // namespace autofill 3274 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698