Bug 1409306 - Check the existence of the profile's cc-exp-month and cc-exp-year in `findCreditCardSelectOption`. r=lchang

MozReview-Commit-ID: 5gBLJcWXkGT

--HG--
extra : rebase_source : a8374b7a7c8791788a17ec38526def4279daf327
This commit is contained in:
Sean Lee 2017-10-18 12:21:00 +08:00
Родитель e0cee9667c
Коммит c05d2f91b9
2 изменённых файлов: 89 добавлений и 4 удалений

Просмотреть файл

@ -391,14 +391,17 @@ this.FormAutofillUtils = {
},
findCreditCardSelectOption(selectEl, creditCard, fieldName) {
let oneDigitMonth = creditCard["cc-exp-month"].toString();
let twoDigitsMonth = oneDigitMonth.padStart(2, "0");
let fourDigitsYear = creditCard["cc-exp-year"].toString();
let twoDigitsYear = fourDigitsYear.substr(2, 2);
let oneDigitMonth = creditCard["cc-exp-month"] ? creditCard["cc-exp-month"].toString() : null;
let twoDigitsMonth = oneDigitMonth ? oneDigitMonth.padStart(2, "0") : null;
let fourDigitsYear = creditCard["cc-exp-year"] ? creditCard["cc-exp-year"].toString() : null;
let twoDigitsYear = fourDigitsYear ? fourDigitsYear.substr(2, 2) : null;
let options = Array.from(selectEl.options);
switch (fieldName) {
case "cc-exp-month": {
if (!oneDigitMonth) {
return null;
}
for (let option of options) {
if ([option.text, option.label, option.value].some(s => {
let result = /[1-9]\d*/.exec(s);
@ -410,6 +413,9 @@ this.FormAutofillUtils = {
break;
}
case "cc-exp-year": {
if (!fourDigitsYear) {
return null;
}
for (let option of options) {
if ([option.text, option.label, option.value].some(
s => s == twoDigitsYear || s == fourDigitsYear
@ -420,6 +426,9 @@ this.FormAutofillUtils = {
break;
}
case "cc-exp": {
if (!oneDigitMonth || !fourDigitsYear) {
return null;
}
let patterns = [
oneDigitMonth + "/" + twoDigitsYear, // 8/22
oneDigitMonth + "/" + fourDigitsYear, // 8/2022

Просмотреть файл

@ -658,6 +658,82 @@ const TESTCASES = [
expectedResult: [DEFAULT_CREDITCARD_RECORD],
expectedOptionElements: [{"cc-exp": "selected-cc-exp"}],
},
{
description: "Fill a cc-exp without cc-exp-month value in the profile",
document: `<form><select autocomplete="cc-exp">
<option value="03/17">03/17</option>
<option value="01/25">01/25</option>
</select></form>`,
profileData: [Object.assign({}, {
"guid": "123",
"cc-exp-year": 2025,
})],
expectedResult: [{
"guid": "123",
"cc-exp-year": 2025,
}],
expectedOptionElements: [],
},
{
description: "Fill a cc-exp without cc-exp-year value in the profile",
document: `<form><select autocomplete="cc-exp">
<option value="03/17">03/17</option>
<option value="01/25">01/25</option>
</select></form>`,
profileData: [Object.assign({}, {
"guid": "123",
"cc-exp-month": 1,
})],
expectedResult: [{
"guid": "123",
"cc-exp-month": 1,
}],
expectedOptionElements: [],
},
{
description: "Fill a cc-exp* without cc-exp-month value in the profile",
document: `<form>
<select autocomplete="cc-exp-month">
<option value="03">03</option>
<option value="01">01</option>
</select>
<select autocomplete="cc-exp-year">
<option value="17">2017</option>
<option value="25">2025</option>
</select>
</form>`,
profileData: [Object.assign({}, {
"guid": "123",
"cc-exp-year": 2025,
})],
expectedResult: [{
"guid": "123",
"cc-exp-year": 2025,
}],
expectedOptionElements: [],
},
{
description: "Fill a cc-exp* without cc-exp-year value in the profile",
document: `<form>
<select autocomplete="cc-exp-month">
<option value="03">03</option>
<option value="01">01</option>
</select>
<select autocomplete="cc-exp-year">
<option value="17">2017</option>
<option value="25">2025</option>
</select>
</form>`,
profileData: [Object.assign({}, {
"guid": "123",
"cc-exp-month": 1,
})],
expectedResult: [{
"guid": "123",
"cc-exp-month": 1,
}],
expectedOptionElements: [],
},
];
for (let testcase of TESTCASES) {