Bug 1437940 - fix where we look for a 'Local State' file for non-release Chrome data, r?dthayer
MozReview-Commit-ID: CXghkKKhHfx
--- a/browser/components/migration/ChromeMigrationUtils.jsm
+++ b/browser/components/migration/ChromeMigrationUtils.jsm
@@ -7,18 +7,16 @@ var EXPORTED_SYMBOLS = ["ChromeMigration
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
ChromeUtils.import("resource://gre/modules/osfile.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
var ChromeMigrationUtils = {
- _chromeUserDataPath: null,
-
_extensionVersionDirectoryNames: {},
// The cache for the locale strings.
// For example, the data could be:
// {
// "profile-id-1": {
// "extension-id-1": {
// "name": {
@@ -168,57 +166,48 @@ var ChromeMigrationUtils = {
*/
async getLastUsedProfileId() {
let localState = await this.getLocalState();
return localState ? localState.profile.last_used : "Default";
},
/**
* Get the local state file content.
+ * @param {String} dataPath the type of Chrome data we're looking for (Chromium, Canary, etc.)
* @returns {Object} The JSON-based content.
*/
- async getLocalState() {
+ async getLocalState(dataPath = "Chrome") {
let localState = null;
try {
- let localStatePath = OS.Path.join(this.getChromeUserDataPath(), "Local State");
+ let localStatePath = OS.Path.join(this.getDataPath(dataPath), "Local State");
let localStateJson = await OS.File.read(localStatePath, { encoding: "utf-8" });
localState = JSON.parse(localStateJson);
} catch (ex) {
Cu.reportError(ex);
throw ex;
}
return localState;
},
/**
* Get the path of Chrome extension directory.
* @param {String} profileId - The user profile's ID.
* @returns {String} The path of Chrome extension directory.
*/
getExtensionPath(profileId) {
- return OS.Path.join(this.getChromeUserDataPath(), profileId, "Extensions");
- },
-
- /**
- * Get the path of the Chrome user data directory.
- * @returns {String} The path of the Chrome user data directory.
- */
- getChromeUserDataPath() {
- if (!this._chromeUserDataPath) {
- this._chromeUserDataPath = this.getDataPath("Chrome");
- }
- return this._chromeUserDataPath;
+ return OS.Path.join(this.getDataPath(), profileId, "Extensions");
},
/**
* Get the path of an application data directory.
- * @param {String} chromeProjectName - The Chrome project name, e.g. "Chrome", "Chromium" or "Canary".
+ * @param {String} chromeProjectName - The Chrome project name, e.g. "Chrome", "Canary", etc.
+ * Defaults to "Chrome".
* @returns {String} The path of application data directory.
*/
- getDataPath(chromeProjectName) {
+ getDataPath(chromeProjectName = "Chrome") {
const SUB_DIRECTORIES = {
win: {
Chrome: ["Google", "Chrome"],
Chromium: ["Chromium"],
Canary: ["Google", "Chrome SxS"],
},
macosx: {
Chrome: ["Google", "Chrome"],
--- a/browser/components/migration/ChromeProfileMigrator.js
+++ b/browser/components/migration/ChromeProfileMigrator.js
@@ -155,17 +155,17 @@ ChromeProfileMigrator.prototype.getSourc
return this.__sourceProfiles;
let chromeUserDataPath = await this._getChromeUserDataPathIfExists();
if (!chromeUserDataPath)
return [];
let profiles = [];
try {
- let localState = await ChromeMigrationUtils.getLocalState();
+ let localState = await ChromeMigrationUtils.getLocalState(this._chromeUserDataPathSuffix);
let info_cache = localState.profile.info_cache;
for (let profileFolderName in info_cache) {
profiles.push({
id: profileFolderName,
name: info_cache[profileFolderName].name || profileFolderName,
});
}
} catch (e) {
--- a/browser/components/migration/tests/unit/test_ChromeMigrationUtils.js
+++ b/browser/components/migration/tests/unit/test_ChromeMigrationUtils.js
@@ -1,14 +1,14 @@
"use strict";
ChromeUtils.import("resource:///modules/ChromeMigrationUtils.jsm");
// Setup chrome user data path for all platforms.
-ChromeMigrationUtils.getChromeUserDataPath = () => {
+ChromeMigrationUtils.getDataPath = () => {
return do_get_file("Library/Application Support/Google/Chrome/").path;
};
add_task(async function test_getExtensionList_function() {
let extensionList = await ChromeMigrationUtils.getExtensionList("Default");
Assert.equal(extensionList.length, 2, "There should be 2 extensions installed.");
Assert.deepEqual(extensionList.find(extension => extension.id == "fake-extension-1"), {
id: "fake-extension-1",
--- a/browser/components/migration/tests/unit/test_ChromeMigrationUtils_path.js
+++ b/browser/components/migration/tests/unit/test_ChromeMigrationUtils_path.js
@@ -47,29 +47,16 @@ add_task(async function test_getDataPath
Assert.equal(chromiumUserDataPath,
OS.Path.join(getRootPath(), ".config", "chromium"),
"Should get the path of Chromium data directory.");
Assert.equal(canaryUserDataPath, null,
"Should get null for Canary.");
}
});
-add_task(async function test_getChromeUserDataPath_function() {
- let chromeUserDataPath = ChromeMigrationUtils.getChromeUserDataPath();
- let expectedPath;
- if (AppConstants.platform == "win") {
- expectedPath = OS.Path.join(getRootPath(), "Google", "Chrome", "User Data");
- } else if (AppConstants.platform == "macosx") {
- expectedPath = OS.Path.join(getRootPath(), "Application Support", "Google", "Chrome");
- } else {
- expectedPath = OS.Path.join(getRootPath(), ".config", "google-chrome");
- }
- Assert.equal(chromeUserDataPath, expectedPath, "Should get the path of Chrome user data directory.");
-});
-
add_task(async function test_getExtensionPath_function() {
let extensionPath = ChromeMigrationUtils.getExtensionPath("Default");
let expectedPath;
if (AppConstants.platform == "win") {
expectedPath = OS.Path.join(getRootPath(), "Google", "Chrome", "User Data", "Default", "Extensions");
} else if (AppConstants.platform == "macosx") {
expectedPath = OS.Path.join(getRootPath(), "Application Support", "Google", "Chrome", "Default", "Extensions");
} else {