/* * Test for LoginManagerContent._getPasswordFields using LoginFormFactory. */ "use strict"; const LMCBackstagePass = Cu.import("resource://gre/modules/LoginManagerContent.jsm"); const { LoginManagerContent, LoginFormFactory } = LMCBackstagePass; const TESTCASES = [ { description: "Empty document", document: ``, returnedFieldIDsByFormLike: [], skipEmptyFields: undefined, }, { description: "Non-password input with no
`, returnedFieldIDsByFormLike: [["pw1"]], skipEmptyFields: undefined, }, { description: "Form with 2 password fields", document: ``, returnedFieldIDsByFormLike: [["pw1", "pw2"]], skipEmptyFields: undefined, }, { description: "1 password field in a form, 1 outside", document: ``, returnedFieldIDsByFormLike: [["pw1"], ["pw2"]], skipEmptyFields: undefined, }, { description: "2 password fields outside of a `, returnedFieldIDsByFormLike: [["pw1"], ["pw2"]], skipEmptyFields: undefined, }, { description: "2 password fields outside of a `, returnedFieldIDsByFormLike: [[], []], skipEmptyFields: true, }, { description: "skipEmptyFields should also skip white-space only fields", document: ` `, returnedFieldIDsByFormLike: [[], []], skipEmptyFields: true, }, { description: "2 password fields outside of a `, returnedFieldIDsByFormLike: [["pw1"], []], skipEmptyFields: true, }, ]; for (let tc of TESTCASES) { do_print("Sanity checking the testcase: " + tc.description); (function() { let testcase = tc; add_task(function*() { do_print("Starting testcase: " + testcase.description); let document = MockDocument.createTestDocument("http://localhost:8080/test/", testcase.document); let mapRootElementToFormLike = new Map(); for (let input of document.querySelectorAll("input")) { let formLike = LoginFormFactory.createFromField(input); let existingFormLike = mapRootElementToFormLike.get(formLike.rootElement); if (!existingFormLike) { mapRootElementToFormLike.set(formLike.rootElement, formLike); continue; } // If the formLike is already present, ensure that the properties are the same. do_print("Checking if the new FormLike for the same root has the same properties"); formLikeEqual(formLike, existingFormLike); } Assert.strictEqual(mapRootElementToFormLike.size, testcase.returnedFieldIDsByFormLike.length, "Check the correct number of different formLikes were returned"); let formLikeIndex = -1; for (let formLikeFromInput of mapRootElementToFormLike.values()) { formLikeIndex++; let pwFields = LoginManagerContent._getPasswordFields(formLikeFromInput, testcase.skipEmptyFields); if (formLikeFromInput.rootElement instanceof Ci.nsIDOMHTMLFormElement) { let formLikeFromForm = LoginFormFactory.createFromForm(formLikeFromInput.rootElement); do_print("Checking that the FormLike created for the