/** * Test for LoginFormState._getPasswordFields using LoginFormFactory. */ /* globals todo_check_eq */ "use strict"; const { LoginFormFactory } = ChromeUtils.importESModule( "resource://gre/modules/LoginFormFactory.sys.mjs" ); const { LoginFormState } = ChromeUtils.importESModule( "resource://gre/modules/LoginManagerChild.sys.mjs" ); const TESTCASES = [ { description: "Empty document", document: ``, returnedFieldIDsByFormLike: [], minPasswordLength: undefined, }, { description: "Non-password input with no
`, returnedFieldIDsByFormLike: [["pw1"]], minPasswordLength: undefined, }, { description: "Form with 2 password fields", document: ``, returnedFieldIDsByFormLike: [["pw1", "pw2"]], minPasswordLength: undefined, }, { description: "1 password field in a form, 1 outside", document: ``, returnedFieldIDsByFormLike: [["pw1"], ["pw2"]], minPasswordLength: undefined, }, { description: "2 password fields outside of a `, returnedFieldIDsByFormLike: [["pw1"], ["pw2"]], minPasswordLength: undefined, }, { description: "2 password fields outside of a `, returnedFieldIDsByFormLike: [[], []], minPasswordLength: 2, }, { description: "minPasswordLength should also skip white-space only fields", /* eslint-disable no-tabs */ document: ` `, /* eslint-enable no-tabs */ returnedFieldIDsByFormLike: [[], []], minPasswordLength: 2, }, { description: "minPasswordLength should skip too-short field values", document: ``, returnedFieldIDsByFormLike: [["pw"]], minPasswordLength: 2, }, { description: "minPasswordLength should allow matching-length field values", document: ``, returnedFieldIDsByFormLike: [["pw-matchlen", "pw"]], minPasswordLength: 2, }, { description: "2 password fields outside of a `, returnedFieldIDsByFormLike: [["pw1"], []], minPasswordLength: 2, fieldOverrideRecipe: { // Ensure a recipe without `notPasswordSelector` doesn't cause a problem. hosts: ["localhost:8080"], }, }, { description: "3 password fields outside of a `, returnedFieldIDsByFormLike: [["pw3"], ["pw2"]], minPasswordLength: 2, fieldOverrideRecipe: { hosts: ["localhost:8080"], notPasswordSelector: "#pw1", }, }, { beforeGetFunction(doc) { doc.getElementById("pw1").remove(); }, description: "1 password field outside of a `, returnedFieldIDsByFormLike: [["pw"]], minPasswordLength: 2, }, { description: "Single characters composed of multiple code units should ideally fail minPasswordLength of 2", document: ``, minPasswordLength: 2, }, ]; // Note: Bug 780449 tracks our handling of emoji and multi-code-point characters in password fields // and the .length we should expect when a password value includes them for (let tc of EMOJI_TESTCASES) { info("Sanity checking the testcase: " + tc.description); (function () { let testcase = tc; add_task(async function () { info("Starting testcase: " + testcase.description); let document = MockDocument.createTestDocument( "http://localhost:8080/test/", testcase.document ); let input = document.querySelector("input[type='password']"); Assert.ok(input, "Found the password field"); let formLike = LoginFormFactory.createFromField(input); let pwFields = LoginFormState._getPasswordFields(formLike, { minPasswordLength: testcase.minPasswordLength, }); info("Got password fields: " + pwFields.length); todo_check_eq( pwFields.length, 0, "Check a single-character (emoji) password is excluded from the password fields collection" ); }); })(); }