Bug 1560029 - Share GENERATED_PASSWORD_* consts between test frameworks. r=sfoster

Differential Revision: https://phabricator.services.mozilla.com/D39406

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Matthew Noorenberghe 2019-07-26 22:02:47 +00:00
parent 34062ae5d2
commit 7ce754b367
7 changed files with 63 additions and 23 deletions

View File

@ -456,3 +456,8 @@ this.LoginTestUtils.masterPassword = {
this._set(false);
},
};
this.LoginTestUtils.generation = {
LENGTH: 15,
REGEX: /^[a-km-np-zA-HJ-NP-Z2-9]{15}$/,
};

View File

@ -105,10 +105,13 @@ add_task(async function fill_generated_password_empty_field() {
browser,
[passwordInputSelector],
function checkFinalFieldValue(inputSelector) {
let { LoginTestUtils: LTU } = ChromeUtils.import(
"resource://testing-common/LoginTestUtils.jsm"
);
const input = content.document.querySelector(inputSelector);
is(
input.value.length,
15,
LTU.generation.LENGTH,
"Password field was filled with generated password"
);
isnot(
@ -153,10 +156,13 @@ add_task(async function fill_generated_password_nonempty_field() {
browser,
[passwordInputSelector],
function checkFinalFieldValue(inputSelector) {
let { LoginTestUtils: LTU } = ChromeUtils.import(
"resource://testing-common/LoginTestUtils.jsm"
);
const input = content.document.querySelector(inputSelector);
is(
input.value.length,
15,
LTU.generation.LENGTH,
"Password field was filled with generated password"
);
isnot(
@ -212,9 +218,12 @@ add_task(async function fill_generated_password_with_matching_logins() {
browser,
[passwordInputSelector],
function checkFinalFieldValue(inputSelector) {
let { LoginTestUtils: LTU } = ChromeUtils.import(
"resource://testing-common/LoginTestUtils.jsm"
);
is(
content.document.querySelector(inputSelector).value.length,
15,
LTU.generation.LENGTH,
"Password field was filled with generated password"
);
}

View File

@ -101,10 +101,13 @@ async function verifyGeneratedPasswordWasFilled(
browser,
[passwordInputSelector],
function checkFinalFieldValue(inputSelector) {
let { LoginTestUtils: LTU } = ChromeUtils.import(
"resource://testing-common/LoginTestUtils.jsm"
);
let passwordInput = content.document.querySelector(inputSelector);
is(
passwordInput.value.length,
15,
LTU.generation.LENGTH,
"Password field was filled with generated password"
);
}
@ -231,7 +234,7 @@ async function openAndVerifyDoorhanger(browser, type, expected) {
);
is(
passwordValue.length,
15,
LoginTestUtils.generation.LENGTH,
"Doorhanger password field has generated 15-char value"
);
is(
@ -338,13 +341,17 @@ add_task(async function autocomplete_generated_password_auto_saved() {
// Check properties of the newly auto-saved login
is(username, "", "Saved login should have no username");
is(password.length, 15, "Saved login should have generated password");
is(
password.length,
LoginTestUtils.generation.LENGTH,
"Saved login should have generated password"
);
let notif = await openAndVerifyDoorhanger(browser, "password-change", {
dismissed: true,
anchorExtraAttr: "attention",
usernameValue: "",
passwordLength: 15,
passwordLength: LoginTestUtils.generation.LENGTH,
});
await clickDoorhangerButton(notif, DONT_CHANGE_BUTTON);
// confirm the extraAttr attribute is removed after opening & dismissing the doorhanger
@ -403,7 +410,7 @@ add_task(async function autocomplete_generated_password_saved_empty_username() {
dismissed: true,
anchorExtraAttr: "",
usernameValue: "",
passwordLength: 15,
passwordLength: LoginTestUtils.generation.LENGTH,
});
await hideDoorhangerPopup(browser);
info("Waiting to verifyGeneratedPasswordWasFilled");
@ -415,7 +422,7 @@ add_task(async function autocomplete_generated_password_saved_empty_username() {
dismissed: false,
anchorExtraAttr: "",
usernameValue: "",
passwordLength: 15,
passwordLength: LoginTestUtils.generation.LENGTH,
});
await clickDoorhangerButton(notif, CHANGE_BUTTON);
@ -466,7 +473,7 @@ add_task(async function contextfill_generated_password_saved_empty_username() {
dismissed: true,
anchorExtraAttr: "",
usernameValue: "",
passwordLength: 15,
passwordLength: LoginTestUtils.generation.LENGTH,
});
await hideDoorhangerPopup(browser);
info("Waiting to verifyGeneratedPasswordWasFilled");
@ -478,7 +485,7 @@ add_task(async function contextfill_generated_password_saved_empty_username() {
dismissed: false,
anchorExtraAttr: "",
usernameValue: "",
passwordLength: 15,
passwordLength: LoginTestUtils.generation.LENGTH,
});
await clickDoorhangerButton(notif, CHANGE_BUTTON);
@ -561,7 +568,7 @@ add_task(async function contextmenu_fill_generated_password_and_set_username() {
{
timesUsed: 1,
username: "",
passwordLength: 15,
passwordLength: LoginTestUtils.generation.LENGTH,
},
],
});
@ -571,7 +578,7 @@ add_task(async function contextmenu_fill_generated_password_and_set_username() {
dismissed: true,
anchorExtraAttr: "attention",
usernameValue: "differentuser",
passwordLength: 15,
passwordLength: LoginTestUtils.generation.LENGTH,
});
await hideDoorhangerPopup(browser);
info("Waiting to verifyGeneratedPasswordWasFilled");
@ -583,7 +590,7 @@ add_task(async function contextmenu_fill_generated_password_and_set_username() {
dismissed: false,
anchorExtraAttr: "",
usernameValue: "differentuser",
passwordLength: 15,
passwordLength: LoginTestUtils.generation.LENGTH,
});
storageChangedPromise = TestUtils.topicObserved(
@ -599,7 +606,7 @@ add_task(async function contextmenu_fill_generated_password_and_set_username() {
null,
{
username: "differentuser",
passwordLength: 15,
passwordLength: LoginTestUtils.generation.LENGTH,
timesUsed: 1,
},
],
@ -662,7 +669,7 @@ add_task(async function contextmenu_password_change_form_without_username() {
{
timesUsed: 1,
username: "",
passwordLength: 15,
passwordLength: LoginTestUtils.generation.LENGTH,
},
],
});
@ -672,7 +679,7 @@ add_task(async function contextmenu_password_change_form_without_username() {
dismissed: true,
anchorExtraAttr: "attention",
usernameValue: "",
passwordLength: 15,
passwordLength: LoginTestUtils.generation.LENGTH,
});
await hideDoorhangerPopup(browser);
// remove notification so we can unambiguously check no new notification gets created later

View File

@ -25,8 +25,11 @@ const { Services } = SpecialPowers.Cu.import(
{}
);
const GENERATED_PASSWORD_LENGTH = 15;
const GENERATED_PASSWORD_REGEX = /^[a-km-np-zA-HJ-NP-Z2-9]{15}$/;
const {
LENGTH: GENERATED_PASSWORD_LENGTH,
REGEX: GENERATED_PASSWORD_REGEX,
} = LoginTestUtils.generation;
const LOGIN_FIELD_UTILS = LoginTestUtils.loginField;
const TESTS_DIR = "/tests/toolkit/components/passwordmgr/test/";
/**

View File

@ -68,7 +68,11 @@ add_task(async function test_doAutocompleteSearch_generated_noLogins() {
equal(msg1.requestId, arg1.requestId, "requestId matches");
equal(msg1.logins.length, 0, "no logins");
ok(msg1.generatedPassword, "has a generated password");
equal(msg1.generatedPassword.length, 15, "generated password length");
equal(
msg1.generatedPassword.length,
LoginTestUtils.generation.LENGTH,
"generated password length"
);
sendMessageStub.resetHistory();
info("repeat the search and ensure the same password was used");

View File

@ -48,7 +48,11 @@ add_task(async function test_getGeneratedPassword() {
let password1 = LMP.getGeneratedPassword(99);
notEqual(password1, null, "Check password was returned");
equal(password1.length, 15, "Check password length");
equal(
password1.length,
LoginTestUtils.generation.LENGTH,
"Check password length"
);
equal(LMP._generatedPasswordsByPrincipalOrigin.size, 1, "1 added to cache");
equal(
LMP._generatedPasswordsByPrincipalOrigin.get(
@ -84,7 +88,11 @@ add_task(async function test_getGeneratedPassword() {
password3,
"Different password for a different origin for the same BC"
);
equal(password3.length, 15, "Check password3 length");
equal(
password3.length,
LoginTestUtils.generation.LENGTH,
"Check password3 length"
);
info("Now checks cases where null should be returned");

View File

@ -82,7 +82,11 @@ function stubGeneratedPasswordForBrowsingContextId(id) {
let generatedPassword = LMP.getGeneratedPassword(id);
notEqual(generatedPassword, null, "Check password was returned");
equal(generatedPassword.length, 15, "Check password length");
equal(
generatedPassword.length,
LoginTestUtils.generation.LENGTH,
"Check password length"
);
equal(LMP._generatedPasswordsByPrincipalOrigin.size, 1, "1 added to cache");
equal(
LMP._generatedPasswordsByPrincipalOrigin.get(