Bug 887876 - Use Sqlite.jsm in browser/components/migration. r=mak
authorGeorge Veneel Dogga <georgeveneeldogga@gmail.com>
Fri, 20 Jan 2017 04:35:00 -0500
changeset 377896 6328f5d01711068b42ec2d61e04a3f899d4c84d4
parent 377895 5267191b229f425a34f26f0d7a96fd5391f3105d
child 377897 538094a7900cdec31ad57faf9a6937104edce590
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs887876
milestone53.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 887876 - Use Sqlite.jsm in browser/components/migration. r=mak
browser/components/migration/tests/unit/head_migration.js
browser/components/migration/tests/unit/test_Chrome_passwords.js
--- a/browser/components/migration/tests/unit/head_migration.js
+++ b/browser/components/migration/tests/unit/head_migration.js
@@ -15,17 +15,18 @@ Cu.import("resource://gre/modules/Promis
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://testing-common/TestUtils.jsm");
 Cu.import("resource://testing-common/PlacesTestUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
                                   "resource://gre/modules/FileUtils.jsm");
-
+XPCOMUtils.defineLazyModuleGetter(this, "Sqlite",
+                                  "resource://gre/modules/Sqlite.jsm");
 // Initialize profile.
 var gProfD = do_get_profile();
 
 Cu.import("resource://testing-common/AppInfo.jsm"); /* globals updateAppInfo */
 updateAppInfo();
 
 /**
  * Migrates the requested resource and waits for the migration to be complete.
--- a/browser/components/migration/tests/unit/test_Chrome_passwords.js
+++ b/browser/components/migration/tests/unit/test_Chrome_passwords.js
@@ -75,41 +75,22 @@ const TEST_LOGINS = [
     timesUsed: 1,
   },
 ];
 
 var crypto = new OSCrypto();
 var dbConn;
 
 function promiseSetPassword(login) {
-  return new Promise((resolve, reject) => {
-    let stmt = dbConn.createAsyncStatement(`
-      UPDATE logins
-      SET password_value = :password_value
-      WHERE rowid = :rowid
-    `);
-    let passwordValue = crypto.stringToArray(crypto.encryptData(login.password));
-    stmt.bindBlobByName("password_value", passwordValue, passwordValue.length);
-    stmt.params.rowid = login.id;
-
-    stmt.executeAsync({
-      handleError(aError) {
-        reject("Error with the query: " + aError.message);
-      },
-
-      handleCompletion(aReason) {
-        if (aReason === Ci.mozIStorageStatementCallback.REASON_FINISHED) {
-          resolve();
-        } else {
-          reject("Query has failed: " + aReason);
-        }
-      },
-    });
-    stmt.finalize();
-  });
+  let passwordValue = crypto.stringToArray(crypto.encryptData(login.password));
+  return dbConn.execute(`UPDATE logins
+                         SET password_value = :password_value
+                         WHERE rowid = :rowid
+                        `, { password_value: passwordValue,
+                             rowid: login.id });
 }
 
 function checkLoginsAreEqual(passwordManagerLogin, chromeLogin, id) {
   passwordManagerLogin.QueryInterface(Ci.nsILoginMetaInfo);
 
   Assert.equal(passwordManagerLogin.username, chromeLogin.username,
                "The two logins ID " + id + " have the same username");
   Assert.equal(passwordManagerLogin.password, chromeLogin.password,
@@ -142,23 +123,23 @@ function generateDifferentLogin(login) {
   newLogin.timeCreated = login.timeCreated + 1;
   newLogin.timePasswordChanged = login.timePasswordChanged + 1;
   newLogin.timesUsed = login.timesUsed + 1;
   return newLogin;
 }
 
 add_task(function* setup() {
   let loginDataFile = do_get_file("AppData/Local/Google/Chrome/User Data/Default/Login Data");
-  dbConn = Services.storage.openUnsharedDatabase(loginDataFile);
+  dbConn = yield Sqlite.openConnection({ path: loginDataFile.path });
   registerFakePath("LocalAppData", do_get_file("AppData/Local/"));
 
   do_register_cleanup(() => {
     Services.logins.removeAllLogins();
-    dbConn.asyncClose();
     crypto.finalize();
+    return dbConn.close();
   });
 });
 
 add_task(function* test_importIntoEmptyDB() {
   for (let login of TEST_LOGINS) {
     yield promiseSetPassword(login);
   }