mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-12 22:28:59 +02:00
***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8
This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:
ChromeUtils.import("resource://gre/modules/Services.jsm");
is approximately the same as the following, in the new model:
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs
This was done using the followng script:
https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16750
--HG--
extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895
extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
304 lines
8.3 KiB
JavaScript
304 lines
8.3 KiB
JavaScript
"use strict";
|
|
|
|
var FormAutofillHeuristics, LabelUtils;
|
|
add_task(async function() {
|
|
({FormAutofillHeuristics, LabelUtils} = ChromeUtils.import("resource://formautofill/FormAutofillHeuristics.jsm"));
|
|
});
|
|
|
|
const TESTCASES = [
|
|
{
|
|
description: "Input element in a label element",
|
|
document: `<form>
|
|
<label> E-Mail
|
|
<input id="targetElement" type="text">
|
|
</label>
|
|
</form>`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "email",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "A label element is out of the form contains the related input",
|
|
document: `<label for="targetElement"> E-Mail</label>
|
|
<form>
|
|
<input id="targetElement" type="text">
|
|
</form>`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "email",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "A label element contains span element",
|
|
document: `<label for="targetElement">FOO<span>E-Mail</span>BAR</label>
|
|
<form>
|
|
<input id="targetElement" type="text">
|
|
</form>`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "email",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "The signature in 'name' attr of an input",
|
|
document: `<input id="targetElement" name="email" type="text">`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "email",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "The signature in 'id' attr of an input",
|
|
document: `<input id="targetElement_email" name="tel" type="text">`,
|
|
elementId: "targetElement_email",
|
|
expectedReturnValue: {
|
|
fieldName: "email",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "Select element in a label element",
|
|
document: `<form>
|
|
<label> State
|
|
<select id="targetElement"></select>
|
|
</label>
|
|
</form>`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "address-level1",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "A select element without a form wrapped",
|
|
document: `<label for="targetElement">State</label>
|
|
<select id="targetElement"></select>`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "address-level1",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "address line input",
|
|
document: `<label for="targetElement">street</label>
|
|
<input id="targetElement" type="text">`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "address-line1",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "CJK character - Traditional Chinese",
|
|
document: `<label> 郵遞區號
|
|
<input id="targetElement" />
|
|
</label>`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "postal-code",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "CJK character - Japanese",
|
|
document: `<label> 郵便番号
|
|
<input id="targetElement" />
|
|
</label>`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "postal-code",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "CJK character - Korean",
|
|
document: `<label> 우편 번호
|
|
<input id="targetElement" />
|
|
</label>`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "postal-code",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "",
|
|
document: `<input id="targetElement" name="fullname">`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "name",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "input element with \"submit\" type",
|
|
document: `<input id="targetElement" type="submit" />`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: null,
|
|
},
|
|
{
|
|
description: "The signature in 'name' attr of an email input",
|
|
document: `<input id="targetElement" name="email" type="number">`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "email",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "input element with \"email\" type",
|
|
document: `<input id="targetElement" type="email" />`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "email",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "Exclude United State string",
|
|
document: `<label>United State
|
|
<input id="targetElement" />
|
|
</label>`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: null,
|
|
},
|
|
{
|
|
description: "\"County\" field with \"United State\" string",
|
|
document: `<label>United State County
|
|
<input id="targetElement" />
|
|
</label>`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "address-level1",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "\"city\" field with double \"United State\" string",
|
|
document: `<label>United State united sTATE city
|
|
<input id="targetElement" />
|
|
</label>`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "address-level2",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
{
|
|
description: "Verify credit card number",
|
|
document: `<form>
|
|
<label for="targetElement"> Card Number</label>
|
|
<input id="targetElement" type="text">
|
|
</form>`,
|
|
elementId: "targetElement",
|
|
expectedReturnValue: {
|
|
fieldName: "cc-number",
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
},
|
|
},
|
|
];
|
|
|
|
TESTCASES.forEach(testcase => {
|
|
add_task(async function() {
|
|
info("Starting testcase: " + testcase.description);
|
|
|
|
let doc = MockDocument.createTestDocument(
|
|
"http://localhost:8080/test/", testcase.document);
|
|
|
|
let element = doc.getElementById(testcase.elementId);
|
|
let value = FormAutofillHeuristics.getInfo(element);
|
|
|
|
Assert.deepEqual(value, testcase.expectedReturnValue);
|
|
LabelUtils.clearLabelMap();
|
|
});
|
|
});
|
|
|
|
add_task(async function test_regexp_list() {
|
|
info("Verify the fieldName support for select element.");
|
|
let SUPPORT_LIST = {
|
|
"email": null, // email
|
|
"tel-extension": null, // tel-extension
|
|
"phone": null, // tel
|
|
"organization": null, // organization
|
|
"street-address": null, // street-address
|
|
"address1": null, // address-line1
|
|
"address2": null, // address-line2
|
|
"address3": null, // address-line3
|
|
"city": "address-level2",
|
|
"region": "address-level1",
|
|
"postal-code": null, // postal-code
|
|
"country": "country",
|
|
"fullname": null, // name
|
|
"fname": null, // given-name
|
|
"mname": null, // additional-name
|
|
"lname": null, // family-name
|
|
"cardholder": null, // cc-name
|
|
"cc-number": null, // cc-number
|
|
"addmonth": "cc-exp-month",
|
|
"addyear": "cc-exp-year",
|
|
};
|
|
for (let label of Object.keys(SUPPORT_LIST)) {
|
|
let testcase = {
|
|
description: `A select element supports ${label} or not`,
|
|
document: `<select id="${label}"></select>`,
|
|
elementId: label,
|
|
expectedReturnValue: (SUPPORT_LIST[label] ? {
|
|
fieldName: SUPPORT_LIST[label],
|
|
section: "",
|
|
addressType: "",
|
|
contactType: "",
|
|
} : null),
|
|
};
|
|
info(testcase.description);
|
|
info(testcase.document);
|
|
let doc = MockDocument.createTestDocument(
|
|
"http://localhost:8080/test/", testcase.document);
|
|
|
|
let element = doc.getElementById(testcase.elementId);
|
|
let value = FormAutofillHeuristics.getInfo(element);
|
|
|
|
Assert.deepEqual(value, testcase.expectedReturnValue, label);
|
|
}
|
|
LabelUtils.clearLabelMap();
|
|
});
|
|
|