Bug 1386283 - Test: Only consider connected <input>s for username/password fields. r=mconley
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Thu, 10 Jan 2019 19:25:37 +0000
changeset 510434 c39b7fb8bbdd2807f898c59fdbfcf1f528398c89
parent 510433 d5357c40725c706cb66e6ac7dce04f7821666c75
child 510435 06cb65fac0f343d8feb6ef780d1e176dad0effae
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1386283
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1386283 - Test: Only consider connected <input>s for username/password fields. r=mconley Differential Revision: https://phabricator.services.mozilla.com/D15997
toolkit/components/passwordmgr/test/unit/test_getFormFields.js
toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js
--- a/toolkit/components/passwordmgr/test/unit/test_getFormFields.js
+++ b/toolkit/components/passwordmgr/test/unit/test_getFormFields.js
@@ -26,16 +26,28 @@ const TESTCASES = [
   {
     description: "1 username & password field outside of a <form>",
     document: `<input id="un1">
       <input id="pw1" type=password>`,
     returnedFieldIDs: ["un1", "pw1", null],
     skipEmptyFields: undefined,
   },
   {
+    beforeGetFunction(doc, formLike) {
+      // Access the formLike.elements lazy getter to have it cached.
+      Assert.equal(formLike.elements.length, 2, "Check initial elements length");
+      doc.getElementById("un1").remove();
+    },
+    description: "1 username & password field outside of a <form>, un1 removed",
+    document: `<input id="un1">
+      <input id="pw1" type=password>`,
+    returnedFieldIDs: [null, "pw1", null],
+    skipEmptyFields: undefined,
+  },
+  {
     description: "1 username & password field in a <form>",
     document: `<form>
       <input id="un1">
       <input id="pw1" type=password>
       </form>`,
     returnedFieldIDs: ["un1", "pw1", null],
     skipEmptyFields: undefined,
   },
@@ -120,16 +132,20 @@ for (let tc of TESTCASES) {
       let document = MockDocument.createTestDocument("http://localhost:8080/test/",
                                                       testcase.document);
 
       let input = document.querySelector("input");
       MockDocument.mockOwnerDocumentProperty(input, document, "http://localhost:8080/test/");
 
       let formLike = LoginFormFactory.createFromField(input);
 
+      if (testcase.beforeGetFunction) {
+        await testcase.beforeGetFunction(document, formLike);
+      }
+
       let actual = LoginManagerContent._getFormFields(formLike,
                                                       testcase.skipEmptyFields,
                                                       new Set());
 
       Assert.strictEqual(testcase.returnedFieldIDs.length, 3,
                          "_getFormFields returns 3 elements");
 
       for (let i = 0; i < testcase.returnedFieldIDs.length; i++) {
--- a/toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js
+++ b/toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js
@@ -105,16 +105,25 @@ const TESTCASES = [
       <form id="form1"><input id="pw4" type=password></form>`,
     returnedFieldIDsByFormLike: [["pw3"], ["pw2"]],
     skipEmptyFields: true,
     fieldOverrideRecipe: {
       hosts: ["localhost:8080"],
       notPasswordSelector: "#pw1",
     },
   },
+  {
+    beforeGetFunction(doc) {
+      doc.getElementById("pw1").remove();
+    },
+    description: "1 password field outside of a <form> which gets removed/disconnected",
+    document: `<input id="pw1" type=password>`,
+    returnedFieldIDsByFormLike: [[]],
+    skipEmptyFields: undefined,
+  },
 ];
 
 for (let tc of TESTCASES) {
   info("Sanity checking the testcase: " + tc.description);
 
   (function() {
     let testcase = tc;
     add_task(async function() {
@@ -131,16 +140,20 @@ for (let tc of TESTCASES) {
           continue;
         }
 
         // If the formLike is already present, ensure that the properties are the same.
         info("Checking if the new FormLike for the same root has the same properties");
         formLikeEqual(formLike, existingFormLike);
       }
 
+      if (testcase.beforeGetFunction) {
+        await testcase.beforeGetFunction(document);
+      }
+
       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, {
           fieldOverrideRecipe: testcase.fieldOverrideRecipe,