Bug 1398101 - Allow the FormAutofill fields with autocomplete="off" to proceed `startSearch`. r=MattN

MozReview-Commit-ID: 6pZUPY1Fray

--HG--
extra : rebase_source : d6e671a3877f36ba29fa49d965eb710997776b7e
This commit is contained in:
Sean Lee 2017-09-11 12:11:12 +08:00
Родитель 5b44721f93
Коммит 920b6010d7
7 изменённых файлов: 132 добавлений и 13 удалений

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

@ -115,6 +115,12 @@ AutofillProfileAutoCompleteSearch.prototype = {
// - (address only) less than 3 inputs are covered by all saved fields in the storage.
if (!searchPermitted || !savedFieldNames.has(info.fieldName) || filledRecordGUID || (isAddressField &&
allFieldNames.filter(field => savedFieldNames.has(field)).length < FormAutofillUtils.AUTOFILL_FIELDS_THRESHOLD)) {
if (focusedInput.autocomplete == "off") {
// Create a dummy AddressResult as an empty search result.
let result = new AddressResult("", "", [], [], {});
listener.onSearchResult(this, result);
return;
}
let formHistory = Cc["@mozilla.org/autocomplete/search;1?name=form-history"]
.createInstance(Ci.nsIAutoCompleteSearch);
formHistory.startSearch(searchString, searchParam, previousResult, {

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

@ -7,6 +7,8 @@
let formFillChromeScript;
let expectingPopup = null;
const {FormAutofillUtils} = SpecialPowers.Cu.import("resource://formautofill/FormAutofillUtils.jsm");
async function sleep(ms = 500, reason = "Intentionally wait for UI ready") {
SimpleTest.requestFlakyTimeout(reason);
await new Promise(resolve => setTimeout(resolve, ms));
@ -112,6 +114,14 @@ async function cleanUpStorage() {
await cleanUpCreditCards();
}
function patchRecordCCNumber(record) {
const ccNumber = record["cc-number"];
const normalizedCCNumber = "*".repeat(ccNumber.length - 4) + ccNumber.substr(-4);
const ccNumberFmt = FormAutofillUtils.fmtMaskedCreditCardLabel(normalizedCCNumber);
return Object.assign({}, record, {ccNumberFmt});
}
// Utils for registerPopupShownListener(in satchel_common.js) that handles dropdown popup
// Please call "initPopupListener()" in your test and "await expectPopup()"
// if you want to wait for dropdown menu displayed.
@ -122,6 +132,16 @@ function expectPopup() {
});
}
function notExpectPopup(ms = 500) {
info("not expecting a popup");
return new Promise((resolve, reject) => {
expectingPopup = reject.bind(this, "Unexpected Popup");
// TODO: We don't have an event to notify no popup showing, so wait for 500
// ms (in default) to predict any unexpected popup showing.
setTimeout(resolve, ms);
});
}
function popupShownListener() {
info("popup shown for test ");
if (expectingPopup) {

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

@ -11,6 +11,8 @@ support-files =
[test_basic_autocomplete_form.html]
[test_basic_creditcard_autocomplete_form.html]
scheme=https
[test_creditcard_autocomplete_off.html]
scheme=https
[test_formautofill_preview_highlight.html]
[test_multiple_forms.html]
[test_on_address_submission.html]

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

@ -19,8 +19,6 @@ Form autofill test: simple form address autofill
"use strict";
const {FormAutofillUtils} = SpecialPowers.Cu.import("resource://formautofill/FormAutofillUtils.jsm");
let MOCK_STORAGE = [{
organization: "Sesame Street",
"street-address": "123 Sesame Street.\n2-line\n3-line",

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

@ -19,8 +19,6 @@ Form autofill test: simple form credit card autofill
"use strict";
const {FormAutofillUtils} = SpecialPowers.Cu.import("resource://formautofill/FormAutofillUtils.jsm");
const MOCK_STORAGE = [{
"cc-name": "John Doe",
"cc-number": "1234567812345678",
@ -38,14 +36,6 @@ const reducedMockRecord = {
"cc-number": "1234123456785678",
};
function patchRecordCCNumber(record) {
const ccNumber = record["cc-number"];
const normalizedCCNumber = "*".repeat(ccNumber.length - 4) + ccNumber.substr(-4);
const ccNumberFmt = FormAutofillUtils.fmtMaskedCreditCardLabel(normalizedCCNumber);
return Object.assign({}, record, {ccNumberFmt});
}
function checkElementFilled(element, expectedvalue) {
const focusedElem = document.activeElement;
const promises = [];

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

@ -0,0 +1,98 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test basic autofill</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="formautofill_common.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Form autofill test: simple form credit card autofill
<script>
/* import-globals-from ../../../../../testing/mochitest/tests/SimpleTest/SpawnTask.js */
/* import-globals-from ../../../../../toolkit/components/satchel/test/satchel_common.js */
/* import-globals-from formautofill_common.js */
"use strict";
const MOCK_STORAGE = [{
"cc-name": "John Doe",
"cc-number": "1234567812345678",
"cc-exp-month": 4,
"cc-exp-year": 2017,
}, {
"cc-name": "Timothy Berners-Lee",
"cc-number": "1111222233334444",
"cc-exp-month": 12,
"cc-exp-year": 2022,
}];
async function setupCreditCardStorage() {
await addCreditCard(MOCK_STORAGE[0]);
await addCreditCard(MOCK_STORAGE[1]);
}
async function setupFormHistory() {
await updateFormHistory([
{op: "add", fieldname: "cc-name", value: "John Smith"},
{op: "add", fieldname: "cc-number", value: "1234000056780000"},
]);
}
initPopupListener();
// Show Form History popup for non-autocomplete="off" field only
add_task(async function history_only_menu_checking() {
await setupFormHistory();
await setInput("#cc-number", "");
doKey("down");
await expectPopup();
checkMenuEntries(["1234000056780000"], false);
await setInput("#cc-name", "");
doKey("down");
await notExpectPopup();
});
// Show Form Autofill popup for the credit card fields.
add_task(async function check_menu_when_both_with_autocomplete_off() {
await setupCreditCardStorage();
await setInput("#cc-number", "");
doKey("down");
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primaryAffix: cc.ccNumberFmt.affix,
primary: cc.ccNumberFmt.label,
secondary: cc["cc-name"],
})));
await setInput("#cc-name", "");
doKey("down");
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-name"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
});
</script>
<p id="display"></p>
<div id="content">
<form id="form1">
<p>This is a Credit Card form with autocomplete="off" cc-name field.</p>
<p><label>Name: <input id="cc-name" autocomplete="off"></label></p>
<p><label>Card Number: <input id="cc-number" autocomplete="cc-number"></label></p>
</form>
</div>
<pre id="test"></pre>
</body>
</html>

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

@ -1067,7 +1067,12 @@ nsFormFillController::MaybeStartControllingInput(nsIDOMHTMLInputElement* aInput)
isPwmgrInput = true;
}
if (isPwmgrInput || hasList || autocomplete) {
bool isAutofillInput = false;
if (mAutofillInputs.Get(inputNode)) {
isAutofillInput = true;
}
if (isAutofillInput || isPwmgrInput || hasList || autocomplete) {
StartControllingInput(aInput);
}
}