Bug 1780436 - Reuse getFormElementByName in password manager and remove usage of $_. r=sgalich

Depends on D154670

Differential Revision: https://phabricator.services.mozilla.com/D154671
This commit is contained in:
issammani 2022-08-17 15:16:03 +00:00
Родитель 10b0dfd4c9
Коммит f0ed2595e2
21 изменённых файлов: 131 добавлений и 157 удалений

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

@ -41,36 +41,6 @@ let authPromptIsCommonDialog =
false
));
/**
* Returns the element with the specified |name| attribute.
*/
function $_(formNum, name) {
var form = document.getElementById("form" + formNum);
if (!form) {
ok(false, "$_ couldn't find requested form " + formNum);
return null;
}
var element = form.querySelector(`:is([name="${name}"], [id="${name}"])`);
if (!element) {
ok(false, `$_ couldn't find requested element "${name}"`);
return null;
}
// Note that namedItem is a bit stupid, and will prefer an
// |id| attribute over a |name| attribute when looking for
// the element. Login Mananger happens to use .namedItem
// anyway, but let's rigorously check it here anyway so
// that we don't end up with tests that mistakenly pass.
if (element.getAttribute("name") != name) {
ok(false, "$_ got confused.");
return null;
}
return element;
}
/**
* Recreate a DOM tree using the outerHTML to ensure that any event listeners
* and internal state for the elements are removed.

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

@ -5,6 +5,7 @@
<title>Test behavior of unmasking in LMC._passwordEditedOrGenerated</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
<script src="pwmgr_common.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
@ -45,7 +46,7 @@ add_setup(async () => {
});
add_task(async function test_preventDefaultAndStopPropagation() {
let pword = $_(1, "pword");
let pword = getFormElementByName(1, "pword");
pword.focus();
pword.addEventListener("focus", preventDefaultAndStopProgagation);
@ -68,7 +69,7 @@ add_task(async function test_preventDefaultAndStopPropagation() {
});
add_task(async function test_fieldsMaskedAfterSavedLoginFill() {
let pword = $_(1, "pword");
let pword = getFormElementByName(1, "pword");
pword.focus();
SpecialPowers.wrap(pword).setUserInput("generatedpass");
@ -93,7 +94,7 @@ add_task(async function test_fieldsMaskedAfterSavedLoginFill() {
});
add_task(async function test_fieldsMaskedAfterReplacingWholeValue() {
let pword = $_(1, "pword");
let pword = getFormElementByName(1, "pword");
pword.focus();
SpecialPowers.wrap(pword).setUserInput("generatedpass");
@ -120,7 +121,7 @@ add_task(async function test_fieldsMaskedAfterReplacingWholeValue() {
});
add_task(async function test_fieldsUnmaskedAfterAddingCharacter() {
let pword = $_(1, "pword");
let pword = getFormElementByName(1, "pword");
pword.focus();
SpecialPowers.wrap(pword).setUserInput("generatedpass");
@ -148,7 +149,7 @@ add_task(async function test_fieldsUnmaskedAfterAddingCharacter() {
});
add_task(async function test_typeNotPassword() {
let pword = $_(1, "pword");
let pword = getFormElementByName(1, "pword");
pword.focus();
LOGIN_FIELD_UTILS.checkPasswordMasked(pword, true, "Before first fill");

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

@ -42,8 +42,8 @@ Login Manager test: no duplicate logins when using autofill and autocomplete wit
/** Test for Login Manager: related realms autofill/autocomplete. **/
let uname = $_(1, "uname");
let pword = $_(1, "pword");
const uname = getFormElementByName(1, "uname");
const pword = getFormElementByName(1, "pword");
function restoreForm() {
uname.value = "";

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

@ -126,8 +126,8 @@ let setupScript = addLoginsInParent(
/** Test for Login Manager: multiple login autocomplete. **/
var uname = $_(1, "uname");
var pword = $_(1, "pword");
let uname = getFormElementByName(1, "uname");
let pword = getFormElementByName(1, "pword");
// Restore the form to the default state.
function restoreForm() {
@ -561,8 +561,8 @@ add_task(async function test_form2() {
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: "singleuser5"});
// Turn our attention to form2
uname = $_(2, "uname");
pword = $_(2, "pword");
uname = getFormElementByName(2, "uname");
pword = getFormElementByName(2, "pword");
checkLoginForm(uname, "singleuser5", pword, "singlepass5");
restoreForm();
@ -587,8 +587,8 @@ add_task(async function test_form3() {
<button type="submit">Submit</button>
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: "singleuser5"});
uname = $_(3, "uname");
pword = $_(3, "pword");
uname = getFormElementByName(3, "uname");
pword = getFormElementByName(3, "pword");
checkLoginForm(uname, "singleuser5", pword, "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
@ -612,8 +612,8 @@ add_task(async function test_form4() {
<button type="submit">Submit</button>
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: "singleuser5"});
uname = $_(4, "uname");
pword = $_(4, "pword");
uname = getFormElementByName(4, "uname");
pword = getFormElementByName(4, "pword");
checkLoginForm(uname, "singleuser5", pword, "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
@ -637,8 +637,8 @@ add_task(async function test_form5() {
<button type="submit">Submit</button>
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: "singleuser5"});
uname = $_(5, "uname");
pword = $_(5, "pword");
uname = getFormElementByName(5, "uname");
pword = getFormElementByName(5, "pword");
checkLoginForm(uname, "singleuser5", pword, "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
@ -665,8 +665,8 @@ add_task(async function test_form6() {
// (this is a control, w/o autocomplete=off, to ensure the login
// that was being suppressed would have been filled in otherwise)
uname = $_(6, "uname");
pword = $_(6, "pword");
uname = getFormElementByName(6, "uname");
pword = getFormElementByName(6, "pword");
checkLoginForm(uname, "singleuser5", pword, "singlepass5");
});
@ -700,8 +700,8 @@ add_task(async function test_form7() {
<button type="submit">Submit</button>
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: ""});
uname = $_(7, "uname");
pword = $_(7, "pword");
uname = getFormElementByName(7, "uname");
pword = getFormElementByName(7, "pword");
checkLoginForm(uname, "", pword, "");
// Insert a new username field into the form. We'll then make sure
@ -710,7 +710,7 @@ add_task(async function test_form7() {
newField.setAttribute("type", "text");
newField.setAttribute("name", "uname2");
pword.parentNode.insertBefore(newField, pword);
is($_(7, "uname2").value, "", "Verifying empty uname2");
is(getFormElementByName(7, "uname2").value, "", "Verifying empty uname2");
// Delete login6B. It was created just to prevent filling in a login
// automatically, removing it makes it more likely that we'll catch a
@ -742,7 +742,7 @@ add_task(async function test_form7_2() {
"Wait for username to get filled");
await promiseACPopupClosed();
checkLoginForm(uname, "form7user1", pword, "");
is($_(7, "uname2").value, "", "Verifying empty uname2");
is(getFormElementByName(7, "uname2").value, "", "Verifying empty uname2");
restoreForm(); // clear field, so reloading test doesn't fail
let storageChanged = promiseStorageChanged(["removeLogin"]);
@ -768,8 +768,8 @@ add_task(async function test_form8() {
<button type="submit">Submit</button>
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: "form8user", formId: "form8"});
uname = $_(8, "uname");
pword = $_(8, "pword");
uname = getFormElementByName(8, "uname");
pword = getFormElementByName(8, "pword");
checkLoginForm(uname, "form8user", pword, "form8pass");
restoreForm();
});
@ -777,7 +777,7 @@ add_task(async function test_form8() {
add_task(async function test_form8_blur() {
checkLoginForm(uname, "", pword, "");
// Focus the previous form to trigger a blur.
$_(7, "uname").focus();
getFormElementByName(7, "uname").focus();
});
add_task(async function test_form8_2() {
@ -805,8 +805,8 @@ add_task(async function test_form9_filtering() {
// Turn our attention to form9 to test the dropdown - bug 497541
let shownPromise = promiseACShown();
uname = $_(9, "uname");
pword = $_(9, "pword");
uname = getFormElementByName(9, "uname");
pword = getFormElementByName(9, "pword");
uname.focus();
let results = await shownPromise;
checkAutoCompleteResults(results,
@ -878,8 +878,8 @@ add_task(async function test_form11_formless() {
</div>`, {fieldSelector: `input[name="uname"]`, fieldValue: "testuser11"});
// Test form-less autocomplete
uname = $_(11, "uname");
pword = $_(11, "pword");
uname = getFormElementByName(11, "uname");
pword = getFormElementByName(11, "pword");
restoreForm();
checkLoginForm(uname, "", pword, "");
let shownPromise = promiseACShown();
@ -897,8 +897,8 @@ add_task(async function test_form11_formless() {
});
add_task(async function test_form11_open_on_trusted_focus() {
uname = $_(11, "uname");
pword = $_(11, "pword");
uname = getFormElementByName(11, "uname");
pword = getFormElementByName(11, "pword");
uname.value = "";
pword.value = "";
@ -946,8 +946,8 @@ add_task(async function test_form12_recipes() {
"passwordSelector": "input[name='2']",
}],
});
uname = $_(12, "1");
pword = $_(12, "2");
uname = getFormElementByName(12, "1");
pword = getFormElementByName(12, "2");
// First test DOMAutocomplete
// Switch the password field to type=password so _fillForm marks the username
@ -987,8 +987,8 @@ add_task(async function test_form13_stays_open_upon_empty_search() {
<button type="submit">Submit</button>
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: "prefilled"});
uname = $_(13, "uname");
pword = $_(13, "pword");
uname = getFormElementByName(13, "uname");
pword = getFormElementByName(13, "pword");
checkLoginForm(uname, "prefilled", pword, "prefilled");
uname.scrollIntoView();
@ -1031,7 +1031,7 @@ add_task(async function test_form14_username_only() {
<button type="submit">Submit</button>
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: "prefilled"});
uname = $_(14, "uname");
uname = getFormElementByName(14, "uname");
pword = {value: ""};
checkLoginForm(uname, "prefilled", pword, "");
restoreForm();

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

@ -35,8 +35,8 @@ addLoginsInParent([window.location.origin, "https://differentFormSubmitURL", nul
/** Test for Login Manager: multiple login autocomplete. **/
var uname = $_(1, "uname");
var pword = $_(1, "pword");
const uname = getFormElementByName(1, "uname");
const pword = getFormElementByName(1, "pword");
// Restore the form to the default state.
function restoreForm() {

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

@ -105,8 +105,8 @@ var setupScript = runInParent(function setup() {
SpecialPowers.pushPrefEnv({"set": [["security.allow_eval_with_system_principal", true]]});
var uname = $_(1, "uname");
var pword = $_(1, "pword");
let uname = getFormElementByName(1, "uname");
let pword = getFormElementByName(1, "pword");
// Restore the form to the default state.
function restoreForm() {
@ -531,8 +531,8 @@ add_task(async function test_form2() {
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: "singleuser5"});
// Turn our attention to form2
uname = $_(2, "uname");
pword = $_(2, "pword");
uname = getFormElementByName(2, "uname");
pword = getFormElementByName(2, "pword");
checkLoginForm(uname, "singleuser5", pword, "singlepass5");
restoreForm();
@ -557,8 +557,8 @@ add_task(async function test_form3() {
<button type="submit">Submit</button>
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: "singleuser5"});
uname = $_(3, "uname");
pword = $_(3, "pword");
uname = getFormElementByName(3, "uname");
pword = getFormElementByName(3, "pword");
checkLoginForm(uname, "singleuser5", pword, "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
@ -582,8 +582,8 @@ add_task(async function test_form4() {
<button type="submit">Submit</button>
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: "singleuser5"});
uname = $_(4, "uname");
pword = $_(4, "pword");
uname = getFormElementByName(4, "uname");
pword = getFormElementByName(4, "pword");
checkLoginForm(uname, "singleuser5", pword, "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
@ -607,8 +607,8 @@ add_task(async function test_form5() {
<button type="submit">Submit</button>
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: "singleuser5"});
uname = $_(5, "uname");
pword = $_(5, "pword");
uname = getFormElementByName(5, "uname");
pword = getFormElementByName(5, "pword");
checkLoginForm(uname, "singleuser5", pword, "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
@ -635,8 +635,8 @@ add_task(async function test_form6() {
// (this is a control, w/o autocomplete=off, to ensure the login
// that was being suppressed would have been filled in otherwise)
uname = $_(6, "uname");
pword = $_(6, "pword");
uname = getFormElementByName(6, "uname");
pword = getFormElementByName(6, "pword");
checkLoginForm(uname, "singleuser5", pword, "singlepass5");
});
@ -670,8 +670,8 @@ add_task(async function test_form7() {
<button type="submit">Submit</button>
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: ""});
uname = $_(7, "uname");
pword = $_(7, "pword");
uname = getFormElementByName(7, "uname");
pword = getFormElementByName(7, "pword");
checkLoginForm(uname, "", pword, "");
// Insert a new username field into the form. We'll then make sure
@ -680,7 +680,7 @@ add_task(async function test_form7() {
newField.setAttribute("type", "text");
newField.setAttribute("name", "uname2");
pword.parentNode.insertBefore(newField, pword);
is($_(7, "uname2").value, "", "Verifying empty uname2");
is(getFormElementByName(7, "uname2").value, "", "Verifying empty uname2");
// Delete login6B. It was created just to prevent filling in a login
// automatically, removing it makes it more likely that we'll catch a
@ -706,7 +706,7 @@ add_task(async function test_form7_2() {
// the password field should have any values filled in.
await spinEventLoop();
checkLoginForm(uname, "form7user1", pword, "");
is($_(7, "uname2").value, "", "Verifying empty uname2");
is(getFormElementByName(7, "uname2").value, "", "Verifying empty uname2");
restoreForm(); // clear field, so reloading test doesn't fail
let storageChanged = promiseStorageChanged(["removeLogin"]);
@ -733,8 +733,8 @@ add_task(async function test_form8() {
</form>
`, {fieldSelector: `#form8 input[name="uname"]`, fieldValue: "form8user"});
uname = $_(8, "uname");
pword = $_(8, "pword");
uname = getFormElementByName(8, "uname");
pword = getFormElementByName(8, "pword");
checkLoginForm(uname, "form8user", pword, "form8pass");
restoreForm();
});
@ -742,7 +742,7 @@ add_task(async function test_form8() {
add_task(async function test_form8_blur() {
checkLoginForm(uname, "", pword, "");
// Focus the previous form to trigger a blur.
$_(7, "uname").focus();
getFormElementByName(7, "uname").focus();
});
add_task(async function test_form8_2() {
@ -770,8 +770,8 @@ add_task(async function test_form9_filtering() {
// Turn our attention to form9 to test the dropdown - bug 497541
let shownPromise = promiseACShown();
uname = $_(9, "uname");
pword = $_(9, "pword");
uname = getFormElementByName(9, "uname");
pword = getFormElementByName(9, "pword");
uname.focus();
let results = await shownPromise;
checkAutoCompleteResults(results,
@ -857,8 +857,8 @@ add_task(async function test_form11_recipes() {
<button type="submit">Submit</button>
</form>`, {fieldSelector: `input[name="1"]`, fieldValue: ""});
uname = $_(11, "1");
pword = $_(11, "2");
uname = getFormElementByName(11, "1");
pword = getFormElementByName(11, "2");
// First test DOMAutocomplete
// Switch the password field to type=password so _fillForm marks the username
@ -899,8 +899,8 @@ add_task(async function test_form12_formless() {
<button type="submit">Submit</button>
</div>`, {fieldSelector: `input[name="uname"]`, fieldValue: ""});
uname = $_(12, "uname");
pword = $_(12, "pword");
uname = getFormElementByName(12, "uname");
pword = getFormElementByName(12, "pword");
let shownPromise = promiseACShown();
uname.focus();
await shownPromise;
@ -930,8 +930,8 @@ add_task(async function test_form13_stays_open_upon_empty_search() {
<button type="submit">Submit</button>
</form>`, {fieldSelector: `input[name="uname"]`, fieldValue: "prefilled"});
uname = $_(13, "uname");
pword = $_(13, "pword");
uname = getFormElementByName(13, "uname");
pword = getFormElementByName(13, "pword");
checkLoginForm(uname, "prefilled", pword, "prefilled");
uname.scrollIntoView();

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

@ -39,8 +39,8 @@ Login Manager test: related realms autocomplete
/** Test for Login Manager: related realms autocomplete. **/
let uname = $_(1, "uname");
let pword = $_(1, "pword");
const uname = getFormElementByName(1, "uname");
const pword = getFormElementByName(1, "pword");
function restoreForm() {
uname.value = "";

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

@ -54,8 +54,8 @@ var setupScript = runInParent(function setup() {
<pre id="test">
<script class="testbody" type="text/javascript">
var uname = $_(1, "uname");
var pword = $_(1, "pword");
const uname = getFormElementByName(1, "uname");
const pword = getFormElementByName(1, "pword");
// Restore the form to the default state.
function restoreForm() {

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

@ -33,8 +33,8 @@ addLoginsInParent(
<pre id="test">
<script class="testbody" type="text/javascript">
var uname = $_(1, "uname");
var pword = $_(1, "pword");
const uname = getFormElementByName(1, "uname");
const pword = getFormElementByName(1, "pword");
// Restore the form to the default state.
function restoreForm() {

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

@ -161,13 +161,13 @@ add_task(async function test_autofillAutocompleteUsername_noGeneration() {
// 2nd form should not be filled
checkForm(2, "", "");
$_(2, "uname").focus();
getFormElementByName(2, "uname").focus();
await showACPopup(2, ["user1"]);
let acEvents = await waitForTelemetryEventsCondition(events => {
return events.length == 1;
}, { process: "parent", filterProps: TelemetryFilterPropsAC, clear: true }, `Wait for there to be 1 autocomplete telemetry event`);
checkACTelemetryEvent(acEvents[0], $_(2, "uname"), {
checkACTelemetryEvent(acEvents[0], getFormElementByName(2, "uname"), {
"hadPrevious": "0",
"login": "1",
"loginsFooter": "1"
@ -185,7 +185,7 @@ add_task(async function test_autofillAutocompletePassword_noGeneration() {
// 2nd form should not be filled
checkForm(2, "", "");
let pword = $_(2, "password");
let pword = getFormElementByName(2, "password");
pword.focus();
await showACPopup(2, ["user1"]);
let acEvents = await waitForTelemetryEventsCondition(events => {
@ -222,13 +222,13 @@ add_task(async function test_autofillAutocompleteUsername_noGeneration2() {
// 2nd form should not be filled
checkForm(2, "", "");
$_(2, "uname").focus();
getFormElementByName(2, "uname").focus();
// No generation option on username fields.
await showACPopup(2, ["user1"]);
let acEvents = await waitForTelemetryEventsCondition(events => {
return events.length == 1;
}, { process: "parent", filterProps: TelemetryFilterPropsAC, clear: true }, `Wait for there to be 1 autocomplete telemetry event`);
checkACTelemetryEvent(acEvents[0], $_(2, "uname"), {
checkACTelemetryEvent(acEvents[0], getFormElementByName(2, "uname"), {
"hadPrevious": "0",
"login": "1",
"loginsFooter": "1"
@ -252,7 +252,7 @@ add_task(async function test_autofillAutocompletePassword_withGeneration() {
// This form should not be filled
checkForm(formNumber, "", "");
let pword = $_(formNumber, "password");
let pword = getFormElementByName(formNumber, "password");
pword.focus();
await showACPopup(formNumber, [
@ -432,7 +432,7 @@ add_task(async function test_autofillAutocompletePassword_saveLoginDisabled() {
await LoginManager.setLoginSavingEnabled(origin, false);
let pword = $_(2, "password");
let pword = getFormElementByName(2, "password");
pword.focus();
// when login-saving is disabled for an origin, we expect no generated password row here
await showACPopup(2, ["user1"]);
@ -451,8 +451,8 @@ add_task(async function test_deleteAndReselectGeneratedPassword() {
// form should not be filled
checkForm(2, "", "");
let pword = $_(2, "password");
let uname = $_(2, "uname");
let pword = getFormElementByName(2, "password");
let uname = getFormElementByName(2, "uname");
async function showAndSelectACPopupItem(index) {
pword.focus();

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

@ -151,8 +151,8 @@ async function testConfirmPasswordFieldFilledWithGeneratedPassword({
await beforeFn(document.getElementById(`form${formNumber}`));
document.documentElement.scrollTop; // Flush pending reflows which may be caused by beforeFn.
}
let pword = $_(formNumber, passwordInputName || "pword");
let pword2 = $_(formNumber, confirmInputName || "pword-next");
let pword = getFormElementByName(formNumber, passwordInputName || "pword");
let pword2 = getFormElementByName(formNumber, confirmInputName || "pword-next");
await fillWithGeneratedPassword(pword, expectedACResults);
@ -491,9 +491,9 @@ add_task(async function test_dontFill3rdPasswordField() {
const formNumber = 4;
await testReset();
let pword = $_(formNumber, "pword");
let pword2 = $_(formNumber, "pword-next");
let pword3 = $_(formNumber, "pword-extra");
let pword = getFormElementByName(formNumber, "pword");
let pword2 = getFormElementByName(formNumber, "pword-next");
let pword3 = getFormElementByName(formNumber, "pword-extra");
await testConfirmPasswordFieldFilledWithGeneratedPassword({
formNumber,
async beforeFn(form) {

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

@ -137,8 +137,8 @@ async function testResultOfTabInteractions(testData) {
await processed;
// check autofill results
checkForm(1, testData.expectedAutofillUsername, testData.expectedAutofillPassword);
let pword = $_(1, "pword");
let uname = $_(1, "uname");
let pword = getFormElementByName(1, "pword");
let uname = getFormElementByName(1, "uname");
SpecialPowers.wrap(pword).setUserInput("");
SpecialPowers.wrap(uname).setUserInput("");
@ -181,7 +181,7 @@ async function testResultOfTabInteractions(testData) {
}, "Password field should be filled");
}
ok($_(1, "pword").matches("input:focus"), "pword field is focused");
ok(getFormElementByName(1, "pword").matches("input:focus"), "pword field is focused");
checkForm(1, testData.expectedTabbedUsername, testData.expectedTabbedPassword);
recreateTree(document.getElementById("form1"));

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

@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>Test forms with no password fields</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
@ -54,12 +55,10 @@ Login Manager test: forms with no password fields
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Login Manager: form fill, no password fields. **/
function startTest() {
is($_(3, "uname").value, "", "Checking for unfilled checkbox (form 3)");
is($_(4, "yyyyy").value, "", "Checking for unfilled text field (form 4)");
is($_(5, "uname").value, "", "Checking for unfilled text field (form 5)");
is(getFormElementByName(3, "uname").value, "", "Checking for unfilled checkbox (form 3)");
is(getFormElementByName(4, "yyyyy").value, "", "Checking for unfilled text field (form 4)");
is(getFormElementByName(5, "uname").value, "", "Checking for unfilled text field (form 5)");
SimpleTest.finish();
}

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

@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>Test for form fill with 2 password fields</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
@ -30,15 +31,15 @@ var numStartingLogins = 0;
function startTest() {
// Check for unfilled forms
is($_(1, "uname").value, "", "Checking username 1");
is($_(1, "pword").value, "", "Checking password 1A");
is($_(1, "qword").value, "", "Checking password 1B");
is(getFormElementByName(1, "uname").value, "", "Checking username 1");
is(getFormElementByName(1, "pword").value, "", "Checking password 1A");
is(getFormElementByName(1, "qword").value, "", "Checking password 1B");
// Fill in the username and password fields, for account creation.
// Form 1
SpecialPowers.wrap($_(1, "uname")).setUserInput("newuser1");
SpecialPowers.wrap($_(1, "pword")).setUserInput("newpass1");
SpecialPowers.wrap($_(1, "qword")).setUserInput("newpass1");
SpecialPowers.wrap(getFormElementByName(1, "uname")).setUserInput("newuser1");
SpecialPowers.wrap(getFormElementByName(1, "pword")).setUserInput("newpass1");
SpecialPowers.wrap(getFormElementByName(1, "qword")).setUserInput("newpass1");
// eslint-disable-next-line no-unused-vars
var button = getFormSubmitButton(1);

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

@ -40,8 +40,8 @@ addLoginsInParent(
/** Test for Login Manager: autocomplete due to multiple matching logins **/
var uname = $_(1, "uname");
var pword = $_(1, "pword");
const uname = getFormElementByName(1, "uname");
const pword = getFormElementByName(1, "pword");
// Restore the form to the default state.
function restoreForm() {

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

@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>Test for input events in Login Manager</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
@ -59,10 +60,10 @@ function onNewEvent(e) {
SimpleTest.registerCleanupFunction(function cleanup() {
clearTimeout(timeout);
$_(1, "uname").removeAttribute("oninput");
$_(1, "pword").removeAttribute("oninput");
$_(1, "uname").removeAttribute("onchange");
$_(1, "pword").removeAttribute("onchange");
getFormElementByName(1, "uname").removeAttribute("oninput");
getFormElementByName(1, "pword").removeAttribute("oninput");
getFormElementByName(1, "uname").removeAttribute("onchange");
getFormElementByName(1, "pword").removeAttribute("onchange");
document.body.removeAttribute("onload");
});

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

@ -5,6 +5,7 @@
<title>Test for input events in Login Manager when username/password are filled in already</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
@ -24,7 +25,7 @@ function onNewEvent(e) {
console.error("Got " + e.type + " event.");
if (e.type == "load") {
onloadFired = true;
$_(1, "uname").focus();
getFormElementByName(1, "uname").focus();
sendKey("Tab");
} else {
ok(false, "Got an input event for " + e.target.name + " field, which shouldn't happen.");

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

@ -33,8 +33,8 @@ let chromeScript = runChecksAfterCommonInit();
/** Test for Login Manager: contextual insecure password warning without saved logins. **/
let uname = $_(1, "uname");
let pword = $_(1, "pword");
let uname = getFormElementByName(1, "uname");
let pword = getFormElementByName(1, "pword");
// Restore the form to the default state.
function restoreForm() {

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

@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>Test input value change right after onsubmit event</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
@ -42,8 +43,8 @@ Login Manager test: input value change right after onsubmit event
add_task(async function checkFormValues() {
SpecialPowers.wrap(document.getElementById("ufield")).setUserInput("testuser");
SpecialPowers.wrap(document.getElementById("pfield")).setUserInput("testpass");
is($_(1, "uname").value, "testuser", "Checking for filled username");
is($_(1, "pword").value, "testpass", "Checking for filled password");
is(getFormElementByName(1, "uname").value, "testuser", "Checking for filled username");
is(getFormElementByName(1, "pword").value, "testpass", "Checking for filled password");
document.getElementById("form1").addEventListener("submit", () => {
// deliberately assign to .value rather than setUserInput:

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

@ -57,8 +57,8 @@ addLoginsInParent(
<script class="testbody" type="text/javascript">
/** Test for Login Manager: multiple login autocomplete. **/
var uname = $_(1, "uname");
var pword = $_(1, "pword");
let uname = getFormElementByName(1, "uname");
let pword = getFormElementByName(1, "pword");
// Restore the form to the default state.
async function reinitializeForm(index) {
@ -81,8 +81,8 @@ async function reinitializeForm(index) {
await SimpleTest.promiseFocus(window);
uname = $_(index, "uname");
pword = $_(index, "pword");
uname = getFormElementByName(index, "uname");
pword = getFormElementByName(index, "pword");
uname.value = "";
pword.value = "";
pword.focus();

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

@ -102,7 +102,7 @@ let chromeScript = runInParent(function chromeSetup() {
<pre id="test">
<script class="testbody" type="text/javascript">
function removeFocus() {
$_("-autofilled", "submit").focus();
getFormElementByName("-autofilled", "submit").focus();
}
add_setup(async () => {
@ -111,7 +111,7 @@ add_setup(async () => {
});
add_task(async function test_autofilled() {
let usernameField = $_("-autofilled", "uname");
let usernameField = getFormElementByName("-autofilled", "uname");
info("Username and password already filled so don't show autocomplete");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();
@ -126,7 +126,7 @@ add_task(async function test_autofilled() {
});
add_task(async function test_autofilled_prefilled_un() {
let usernameField = $_("-autofilled-prefilled-un", "uname");
let usernameField = getFormElementByName("-autofilled-prefilled-un", "uname");
info("Username and password already filled so don't show autocomplete");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();
@ -141,8 +141,8 @@ add_task(async function test_autofilled_prefilled_un() {
});
add_task(async function test_autofilled_focused_dynamic() {
let usernameField = $_("-autofilled-focused-dynamic", "uname");
let passwordField = $_("-autofilled-focused-dynamic", "pword");
let usernameField = getFormElementByName("-autofilled-focused-dynamic", "uname");
let passwordField = getFormElementByName("-autofilled-focused-dynamic", "pword");
info("Username and password will be filled while username focused");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();
@ -166,7 +166,7 @@ add_task(async function test_autofilled_focused_dynamic() {
// Begin testing forms that have multiple saved logins
add_task(async function test_multiple() {
let usernameField = $_("-multiple", "uname");
let usernameField = getFormElementByName("-multiple", "uname");
info("Fields not filled due to multiple so autocomplete upon focus");
let shownPromise = promiseACShown();
usernameField.focus();
@ -174,8 +174,8 @@ add_task(async function test_multiple() {
});
add_task(async function test_multiple_dynamic() {
let usernameField = $_("-multiple-dynamic", "uname");
let passwordField = $_("-multiple-dynamic", "pword");
let usernameField = getFormElementByName("-multiple-dynamic", "uname");
let passwordField = getFormElementByName("-multiple-dynamic", "pword");
info("Fields not filled but username is focused upon marking so open");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();
@ -188,7 +188,7 @@ add_task(async function test_multiple_dynamic() {
});
add_task(async function test_multiple_prefilled_un1() {
let usernameField = $_("-multiple-prefilled-un1", "uname");
let usernameField = getFormElementByName("-multiple-prefilled-un1", "uname");
info("Username and password already filled so don't show autocomplete");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();
@ -203,7 +203,7 @@ add_task(async function test_multiple_prefilled_un1() {
});
add_task(async function test_multiple_prefilled_un2() {
let usernameField = $_("-multiple-prefilled-un2", "uname");
let usernameField = getFormElementByName("-multiple-prefilled-un2", "uname");
info("Username and password already filled so don't show autocomplete");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();
@ -218,8 +218,8 @@ add_task(async function test_multiple_prefilled_un2() {
});
add_task(async function test_multiple_prefilled_focused_dynamic() {
let usernameField = $_("-multiple-prefilled-focused-dynamic", "uname");
let passwordField = $_("-multiple-prefilled-focused-dynamic", "pword");
let usernameField = getFormElementByName("-multiple-prefilled-focused-dynamic", "uname");
let passwordField = getFormElementByName("-multiple-prefilled-focused-dynamic", "pword");
info("Username and password will be filled while username focused");
let noPopupPromise = promiseNoUnexpectedPopupShown();
usernameField.focus();