forked from mirrors/gecko-dev
MozReview-Commit-ID: C6zT7jKBb4c --HG-- extra : rebase_source : 1154380e8b4a0c3be5443ac8044febe096f550ff
72 lines
2.2 KiB
JavaScript
72 lines
2.2 KiB
JavaScript
"use strict";
|
|
|
|
Cu.import("resource://formautofill/FormAutofillContent.jsm");
|
|
|
|
const TESTCASES = [
|
|
{
|
|
description: "Form containing 5 fields with autocomplete attribute.",
|
|
document: `<form>
|
|
<input id="street-addr" autocomplete="street-address">
|
|
<input id="city" autocomplete="address-level2">
|
|
<input id="country" autocomplete="country">
|
|
<input id="email" autocomplete="email">
|
|
<input id="tel" autocomplete="tel">
|
|
<input id="without-autocomplete-1">
|
|
<input id="without-autocomplete-2">
|
|
</form>`,
|
|
expectedResult: [
|
|
"street-addr",
|
|
"city",
|
|
"country",
|
|
"email",
|
|
"tel",
|
|
],
|
|
},
|
|
{
|
|
description: "Form containing only 2 fields with autocomplete attribute.",
|
|
document: `<form>
|
|
<input id="street-addr" autocomplete="street-address">
|
|
<input id="city" autocomplete="address-level2">
|
|
<input id="without-autocomplete-1">
|
|
<input id="without-autocomplete-2">
|
|
</form>`,
|
|
expectedResult: [],
|
|
},
|
|
{
|
|
description: "Fields without form element.",
|
|
document: `<input id="street-addr" autocomplete="street-address">
|
|
<input id="city" autocomplete="address-level2">
|
|
<input id="country" autocomplete="country">
|
|
<input id="email" autocomplete="email">
|
|
<input id="tel" autocomplete="tel">
|
|
<input id="without-autocomplete-1">
|
|
<input id="without-autocomplete-2">`,
|
|
expectedResult: [
|
|
"street-addr",
|
|
"city",
|
|
"country",
|
|
"email",
|
|
"tel",
|
|
],
|
|
},
|
|
];
|
|
|
|
let markedFieldId = [];
|
|
FormAutofillContent._markAsAutofillField = function(field) {
|
|
markedFieldId.push(field.id);
|
|
};
|
|
|
|
TESTCASES.forEach(testcase => {
|
|
add_task(function* () {
|
|
do_print("Starting testcase: " + testcase.description);
|
|
|
|
markedFieldId = [];
|
|
|
|
let doc = MockDocument.createTestDocument(
|
|
"http://localhost:8080/test/", testcase.document);
|
|
FormAutofillContent.identifyAutofillFields(doc);
|
|
|
|
Assert.deepEqual(markedFieldId, testcase.expectedResult,
|
|
"Check the fields were marked correctly.");
|
|
});
|
|
});
|