Bug 1019885 - Fix broken import of disabled hosts from previous profiles. r=dolske
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Thu, 05 Jun 2014 16:44:42 +0100
changeset 207264 275b8b4d30ec268c77a0dbe35710673fb34a53ee
parent 207263 413ea58159cf6b333798351ba1824122d98eb5cc
child 207265 24f124582f70a64103835464160441bc0a449c69
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs1019885
milestone32.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 1019885 - Fix broken import of disabled hosts from previous profiles. r=dolske
toolkit/components/passwordmgr/LoginImport.jsm
toolkit/components/passwordmgr/LoginStore.jsm
toolkit/components/passwordmgr/test/unit/test_module_LoginImport.js
--- a/toolkit/components/passwordmgr/LoginImport.jsm
+++ b/toolkit/components/passwordmgr/LoginImport.jsm
@@ -160,20 +160,17 @@ this.LoginImport.prototype = {
       }
 
       rows = yield connection.execute("SELECT * FROM moz_disabledHosts");
       for (let row of rows) {
         try {
           let id = row.getResultByName("id");
           let hostname = row.getResultByName("hostname");
 
-          this.store.data.disabledHosts.push({
-            id: this.store.data.nextId++,
-            hostname: hostname,
-          });
+          this.store.data.disabledHosts.push(hostname);
         } catch (ex) {
           Cu.reportError("Error importing disabled host: " + ex);
         }
       }
     } finally {
       yield connection.close();
     }
   }),
--- a/toolkit/components/passwordmgr/LoginStore.jsm
+++ b/toolkit/components/passwordmgr/LoginStore.jsm
@@ -262,16 +262,41 @@ LoginStore.prototype = {
     }
     if (!this.data.disabledHosts) {
       this.data.disabledHosts = [];
     }
 
     // Indicate that the current version of the code has touched the file.
     this.data.version = kDataVersion;
 
+    // Due to bug 1019885, invalid data was created by the import process in
+    // Nightly.  This automated procedure fixes the error.  This is provided as
+    // a convenience to Nightly users and can be safely removed after Nightly
+    // users are updated to the new version.
+    let originalDisabledHosts = this.data.disabledHosts;
+    if (originalDisabledHosts.some(hostItem => typeof hostItem != "string")) {
+
+      this.data.disabledHosts = [];
+
+      for (let hostItem of originalDisabledHosts) {
+        // Fix each item if it is in the broken format.
+        if (typeof hostItem != "string") {
+          hostItem = hostItem.hostname;
+        }
+
+        // Ensure we don't create duplicates in the process.
+        if (this.data.disabledHosts.indexOf(hostItem) == -1) {
+          this.data.disabledHosts.push(hostItem);
+        }
+      }
+
+      // Ensure the updated data is saved.
+      this.saveSoon();
+    }
+
     this.dataReady = true;
   },
 
   /**
    * Called when the data changed, this triggers asynchronous serialization.
    */
   saveSoon: function () this._saver.arm(),
 
--- a/toolkit/components/passwordmgr/test/unit/test_module_LoginImport.js
+++ b/toolkit/components/passwordmgr/test/unit/test_module_LoginImport.js
@@ -165,20 +165,18 @@ add_task(function test_import()
              loginDataItem.timeLastUsed == loginInfo.timeLastUsed &&
              loginDataItem.timePasswordChanged == loginInfo.timePasswordChanged &&
              loginDataItem.timesUsed == loginInfo.timesUsed;
     });
   }));
 
   // Verify that disabled hosts have been imported.
   do_check_eq(store.data.disabledHosts.length, 2);
-  do_check_true(store.data.disabledHosts.some(
-                dataItem => dataItem.hostname == "http://www.example.com"));
-  do_check_true(store.data.disabledHosts.some(
-                dataItem => dataItem.hostname == "https://www.example.org"));
+  do_check_true(store.data.disabledHosts.indexOf("http://www.example.com") != -1);
+  do_check_true(store.data.disabledHosts.indexOf("https://www.example.org") != -1);
 });
 
 /**
  * Tests imports of NULL values due to a downgraded database.
  */
 add_task(function test_import_downgraded()
 {
   let store = new LoginStore(getTempFile("test-import-downgraded.json").path);