mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1855498 - Remove isFieldVisible logic in formautofill r=credential-management-reviewers,dimi
Differential Revision: https://phabricator.services.mozilla.com/D199783
This commit is contained in:
parent
4c0015a633
commit
1855a96448
@ -20,8 +20,6 @@ skip-if = ["apple_silicon && !debug"]
|
||||
|
||||
["browser_fr_fields.js"]
|
||||
|
||||
["browser_ignore_invisible_fields.js"]
|
||||
|
||||
["browser_ignore_unfocusable_fields.js"]
|
||||
|
||||
["browser_label_rules.js"]
|
||||
|
@ -1,136 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/* global add_heuristic_tests */
|
||||
|
||||
"use strict";
|
||||
|
||||
add_heuristic_tests([
|
||||
{
|
||||
description:
|
||||
"All fields are visible (interactivityCheckMode is set to visibility).",
|
||||
prefs: [
|
||||
[
|
||||
"extensions.formautofill.heuristics.interactivityCheckMode",
|
||||
"visibility",
|
||||
],
|
||||
],
|
||||
fixtureData: `
|
||||
<html>
|
||||
<body>
|
||||
<form>
|
||||
<input type="text" id="name" autocomplete="name" />
|
||||
<input type="text" id="tel" autocomplete="tel" />
|
||||
<input type="text" id="email" autocomplete="email" />
|
||||
<input type="text" id="country" autocomplete="country"/>
|
||||
<input type="text" id="postal-code" autocomplete="postal-code" />
|
||||
<input type="text" id="address-line1" autocomplete="address-line1" />
|
||||
<div>
|
||||
<input type="text" id="address-line2" autocomplete="address-line2" />
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
`,
|
||||
expectedResult: [
|
||||
{
|
||||
default: {
|
||||
reason: "autocomplete",
|
||||
},
|
||||
fields: [
|
||||
{ fieldName: "name" },
|
||||
{ fieldName: "tel" },
|
||||
{ fieldName: "email" },
|
||||
{ fieldName: "country" },
|
||||
{ fieldName: "postal-code" },
|
||||
{ fieldName: "address-line1" },
|
||||
{ fieldName: "address-line2" },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
description:
|
||||
"Some fields are invisible due to css styling (interactivityCheckMode is set to visibility).",
|
||||
prefs: [
|
||||
[
|
||||
"extensions.formautofill.heuristics.interactivityCheckMode",
|
||||
"visibility",
|
||||
],
|
||||
],
|
||||
fixtureData: `
|
||||
<html>
|
||||
<body>
|
||||
<form>
|
||||
<input type="text" id="name" autocomplete="name" />
|
||||
<input type="text" id="tel" autocomplete="tel" />
|
||||
<input type="text" id="email" autocomplete="email" />
|
||||
<input type="text" id="country" autocomplete="country" />
|
||||
<input type="text" id="postal-code" autocomplete="postal-code" hidden />
|
||||
<input type="text" id="address-line1" autocomplete="address-line1" style="display:none" />
|
||||
<div style="visibility: hidden">
|
||||
<input type="text" id="address-line2" autocomplete="address-line2" />
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
`,
|
||||
expectedResult: [
|
||||
{
|
||||
default: {
|
||||
reason: "autocomplete",
|
||||
},
|
||||
fields: [
|
||||
{ fieldName: "name" },
|
||||
{ fieldName: "tel" },
|
||||
{ fieldName: "email" },
|
||||
{ fieldName: "country" },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
// hidden, style="display:none" are always considered (when mode visibility)
|
||||
description:
|
||||
"Number of form elements exceeds the threshold (interactivityCheckMode is set to visibility).",
|
||||
prefs: [
|
||||
["extensions.formautofill.heuristics.visibilityCheckThreshold", 1],
|
||||
[
|
||||
"extensions.formautofill.heuristics.interactivityCheckMode",
|
||||
"visibility",
|
||||
],
|
||||
],
|
||||
fixtureData: `
|
||||
<html>
|
||||
<body>
|
||||
<form>
|
||||
<input type="text" id="name" autocomplete="name" />
|
||||
<input type="text" id="tel" autocomplete="tel" />
|
||||
<input type="text" id="email" autocomplete="email" />
|
||||
<input type="text" id="country" autocomplete="country" disabled />
|
||||
<input type="text" id="postal-code" autocomplete="postal-code" hidden />
|
||||
<input type="text" id="address-line1" autocomplete="address-line1" style="display:none" />
|
||||
<div style="visibility: hidden">
|
||||
<input type="text" id="address-line2" autocomplete="address-line2" />
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
`,
|
||||
expectedResult: [
|
||||
{
|
||||
default: {
|
||||
reason: "autocomplete",
|
||||
},
|
||||
fields: [
|
||||
{ fieldName: "name" },
|
||||
{ fieldName: "tel" },
|
||||
{ fieldName: "email" },
|
||||
{ fieldName: "country" },
|
||||
{ fieldName: "address-line2" },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
@ -8,12 +8,7 @@ http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
add_heuristic_tests([
|
||||
{
|
||||
description: "All visual fields are considered focusable.",
|
||||
prefs: [
|
||||
[
|
||||
"extensions.formautofill.heuristics.interactivityCheckMode",
|
||||
"focusability",
|
||||
],
|
||||
],
|
||||
|
||||
fixtureData: `
|
||||
<html>
|
||||
<body>
|
||||
@ -55,12 +50,7 @@ add_heuristic_tests([
|
||||
// ignore opacity (see Bug 1835852),
|
||||
description:
|
||||
"Invisible fields with style.opacity=0 set are considered focusable.",
|
||||
prefs: [
|
||||
[
|
||||
"extensions.formautofill.heuristics.interactivityCheckMode",
|
||||
"focusability",
|
||||
],
|
||||
],
|
||||
|
||||
fixtureData: `
|
||||
<html>
|
||||
<body>
|
||||
@ -101,12 +91,7 @@ add_heuristic_tests([
|
||||
{
|
||||
description:
|
||||
"Some fields are considered unfocusable due to their invisibility.",
|
||||
prefs: [
|
||||
[
|
||||
"extensions.formautofill.heuristics.interactivityCheckMode",
|
||||
"focusability",
|
||||
],
|
||||
],
|
||||
|
||||
fixtureData: `
|
||||
<html>
|
||||
<body>
|
||||
@ -140,12 +125,7 @@ add_heuristic_tests([
|
||||
},
|
||||
{
|
||||
description: `Disabled field and field with tabindex="-1" is considered unfocusable`,
|
||||
prefs: [
|
||||
[
|
||||
"extensions.formautofill.heuristics.interactivityCheckMode",
|
||||
"focusability",
|
||||
],
|
||||
],
|
||||
|
||||
fixtureData: `
|
||||
<html>
|
||||
<body>
|
||||
|
@ -6,7 +6,6 @@ skip-if = [
|
||||
firefox-appdir = "browser"
|
||||
head = "head.js"
|
||||
support-files = ["../fixtures/**"]
|
||||
prefs = ["extensions.formautofill.heuristics.visibilityCheckThreshold=0"]
|
||||
|
||||
["test_activeStatus.js"]
|
||||
|
||||
|
@ -3975,9 +3975,6 @@ pref("extensions.formautofill.loglevel", "Warn");
|
||||
// Temporary prefs that we will be removed when enabling capture on form removal and on page navigation in Fx123.
|
||||
pref("extensions.formautofill.heuristics.captureOnFormRemoval", false);
|
||||
pref("extensions.formautofill.heuristics.captureOnPageNavigation", false);
|
||||
// The interactivityCheckMode pref is only temporary.
|
||||
// It will be removed when we decide to only support the `focusability` mode
|
||||
pref("extensions.formautofill.heuristics.interactivityCheckMode", "focusability");
|
||||
|
||||
pref("toolkit.osKeyStore.loglevel", "Warn");
|
||||
|
||||
|
@ -27,10 +27,6 @@ const IOS_DEFAULT_PREFERENCES = {
|
||||
"extensions.formautofill.addresses.ignoreAutocompleteOff": true,
|
||||
"extensions.formautofill.heuristics.enabled": true,
|
||||
"extensions.formautofill.section.enabled": true,
|
||||
// WebKit doesn't support the checkVisibility API, setting the threshold value to 0 to ensure
|
||||
// `IsFieldVisible` function doesn't use it
|
||||
"extensions.formautofill.heuristics.visibilityCheckThreshold": 0,
|
||||
"extensions.formautofill.heuristics.interactivityCheckMode": "focusability",
|
||||
"extensions.formautofill.heuristics.captureOnFormRemoval": false,
|
||||
"extensions.formautofill.heuristics.captureOnPageNavigation": false,
|
||||
"extensions.formautofill.focusOnAutofill": false,
|
||||
|
@ -31,12 +31,6 @@ HTMLElement.prototype.getAutocompleteInfo = function () {
|
||||
};
|
||||
};
|
||||
|
||||
// Bug 1835024. Webkit doesn't support `checkVisibility` API
|
||||
// https://drafts.csswg.org/cssom-view-1/#dom-element-checkvisibility
|
||||
HTMLElement.prototype.checkVisibility = function (options) {
|
||||
throw new Error(`Not implemented: WebKit doesn't support checkVisibility `);
|
||||
};
|
||||
|
||||
// This function helps us debug better when an error occurs because a certain mock is missing
|
||||
const withNotImplementedError = obj =>
|
||||
new Proxy(obj, {
|
||||
|
@ -14,10 +14,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
||||
LabelUtils: "resource://gre/modules/shared/LabelUtils.sys.mjs",
|
||||
});
|
||||
|
||||
ChromeUtils.defineLazyGetter(lazy, "log", () =>
|
||||
FormAutofill.defineLogGetter(lazy, "FormAutofillHeuristics")
|
||||
);
|
||||
|
||||
/**
|
||||
* To help us classify sections, we want to know what fields can appear
|
||||
* multiple times in a row.
|
||||
@ -601,40 +597,18 @@ export const FormAutofillHeuristics = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Get form elements that are of credit card or address type and filtered by either
|
||||
* visibility or focusability - depending on the interactivity mode (default = focusability)
|
||||
* This distinction is only temporary as we want to test switching from visibility mode
|
||||
* to focusability mode. The visibility mode is then removed.
|
||||
* Get focusable form elements that are of credit card or address type
|
||||
*
|
||||
* @param {HTMLElement} form
|
||||
* @returns {Array<HTMLElement>} elements filtered by interactivity mode (visibility or focusability)
|
||||
* @returns {Array<HTMLElement>} focusable elements
|
||||
*/
|
||||
getFormElements(form) {
|
||||
let elements = Array.from(form.elements).filter(element =>
|
||||
lazy.FormAutofillUtils.isCreditCardOrAddressFieldType(element)
|
||||
);
|
||||
const interactivityMode = lazy.FormAutofillUtils.interactivityCheckMode;
|
||||
|
||||
if (interactivityMode == "focusability") {
|
||||
elements = elements.filter(element =>
|
||||
let elements = Array.from(form.elements).filter(
|
||||
element =>
|
||||
lazy.FormAutofillUtils.isCreditCardOrAddressFieldType(element) &&
|
||||
lazy.FormAutofillUtils.isFieldFocusable(element)
|
||||
);
|
||||
} else if (interactivityMode == "visibility") {
|
||||
// Due to potential performance impact while running visibility check on
|
||||
// a large amount of elements, a comprehensive visibility check
|
||||
// (considering opacity and CSS visibility) is only applied when the number
|
||||
// of eligible elements is below a certain threshold.
|
||||
const runVisiblityCheck =
|
||||
elements.length < lazy.FormAutofillUtils.visibilityCheckThreshold;
|
||||
if (!runVisiblityCheck) {
|
||||
lazy.log.debug(
|
||||
`Skip running visibility check, because of too many elements (${elements.length})`
|
||||
);
|
||||
}
|
||||
elements = elements.filter(element =>
|
||||
lazy.FormAutofillUtils.isFieldVisible(element, runVisiblityCheck)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
return elements;
|
||||
},
|
||||
|
||||
|
@ -301,26 +301,6 @@ FormAutofillUtils = {
|
||||
return element && !element.readOnly && !element.disabled;
|
||||
},
|
||||
|
||||
/**
|
||||
* Determines if an element is visually hidden or not.
|
||||
*
|
||||
* @param {HTMLElement} element
|
||||
* @param {boolean} visibilityCheck true to run visiblity check against
|
||||
* element.checkVisibility API. Otherwise, test by only checking
|
||||
* `hidden` and `display` attributes
|
||||
* @returns {boolean} true if the element is visible
|
||||
*/
|
||||
isFieldVisible(element, visibilityCheck = true) {
|
||||
if (visibilityCheck && element.checkVisibility) {
|
||||
return element.checkVisibility({
|
||||
checkOpacity: true,
|
||||
checkVisibilityCSS: true,
|
||||
});
|
||||
}
|
||||
|
||||
return !element.hidden && element.style.display != "none";
|
||||
},
|
||||
|
||||
/**
|
||||
* Determines if an element is focusable
|
||||
* and accessible via keyboard navigation or not.
|
||||
@ -1140,20 +1120,6 @@ XPCOMUtils.defineLazyPreferenceGetter(
|
||||
pref => parseFloat(pref)
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
FormAutofillUtils,
|
||||
"visibilityCheckThreshold",
|
||||
"extensions.formautofill.heuristics.visibilityCheckThreshold",
|
||||
200
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
FormAutofillUtils,
|
||||
"interactivityCheckMode",
|
||||
"extensions.formautofill.heuristics.interactivityCheckMode",
|
||||
"focusability"
|
||||
);
|
||||
|
||||
// This is only used in iOS
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
FormAutofillUtils,
|
||||
|
Loading…
Reference in New Issue
Block a user