Bug 1216186 - Use the actual browser name for imported bookmark folders from Chromium. r=Gijs

Using _getLocalePropertyForBrowser isn't ideal but ideally this patch would get uplifted so I didn't want to do a larger refactoring to fix this.

Differential Revision: https://phabricator.services.mozilla.com/D61104

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Matthew Noorenberghe 2020-01-28 12:27:25 +00:00
Родитель 4133cc649b
Коммит f5aec46ab3
2 изменённых файлов: 46 добавлений и 12 удалений

Просмотреть файл

@ -102,8 +102,11 @@ ChromeProfileMigrator.prototype.getResources = async function Chrome_getResource
if (chromeUserDataPath) {
let profileFolder = OS.Path.join(chromeUserDataPath, aProfile.id);
if (await OS.File.exists(profileFolder)) {
let localePropertySuffix = MigrationUtils._getLocalePropertyForBrowser(
this.getBrowserKey()
).replace(/^sourceName/, "");
let possibleResourcePromises = [
GetBookmarksResource(profileFolder),
GetBookmarksResource(profileFolder, localePropertySuffix),
GetHistoryResource(profileFolder),
GetCookiesResource(profileFolder),
];
@ -201,7 +204,7 @@ Object.defineProperty(ChromeProfileMigrator.prototype, "sourceLocked", {
},
});
async function GetBookmarksResource(aProfileFolder) {
async function GetBookmarksResource(aProfileFolder, aLocalePropertySuffix) {
let bookmarksPath = OS.Path.join(aProfileFolder, "Bookmarks");
if (!(await OS.File.exists(bookmarksPath))) {
return null;
@ -232,7 +235,7 @@ async function GetBookmarksResource(aProfileFolder) {
);
if (!MigrationUtils.isStartupMigration) {
parentGuid = await MigrationUtils.createImportedBookmarksFolder(
"Chrome", // TODO: Bug 1216186
aLocalePropertySuffix,
parentGuid
);
}
@ -249,7 +252,7 @@ async function GetBookmarksResource(aProfileFolder) {
let bookmarks = convertBookmarks(roots.other.children, errorGatherer);
if (!MigrationUtils.isStartupMigration) {
parentGuid = await MigrationUtils.createImportedBookmarksFolder(
"Chrome", // TODO: Bug 1216186
aLocalePropertySuffix,
parentGuid
);
}

Просмотреть файл

@ -4,21 +4,28 @@ const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
add_task(async function() {
let rootDir = do_get_file("chromefiles/", true);
let rootDir = do_get_file("chromefiles/", true);
add_task(async function setup_fakePaths() {
let pathId;
let subDirs = ["Google", "Chrome"];
if (AppConstants.platform == "macosx") {
subDirs.unshift("Application Support");
pathId = "ULibDir";
} else if (AppConstants.platform == "win") {
subDirs.push("User Data");
pathId = "LocalAppData";
} else {
subDirs = [".config", "google-chrome"];
pathId = "Home";
}
registerFakePath(pathId, rootDir);
});
async function testBookmarks(migratorKey, subDirs, folderName) {
if (AppConstants.platform == "macosx") {
subDirs.unshift("Application Support");
} else if (AppConstants.platform == "win") {
subDirs.push("User Data");
} else {
subDirs.unshift(".config");
}
let target = rootDir.clone();
// Pretend this is the default profile
@ -81,14 +88,20 @@ add_task(async function() {
encoding: "utf-8",
});
let migrator = await MigrationUtils.getMigrator("chrome");
let migrator = await MigrationUtils.getMigrator(migratorKey);
// Sanity check for the source.
Assert.ok(await migrator.isSourceAvailable());
let itemsSeen = { bookmarks: 0, folders: 0 };
let listener = events => {
for (let event of events) {
if (!event.title.includes("Chrome")) {
// "From " comes from the string `importedBookmarksFolder`
if (
event.title.startsWith("From ") &&
event.itemType == PlacesUtils.bookmarks.TYPE_FOLDER
) {
Assert.equal(event.title, folderName, "Bookmark folder name");
} else {
itemsSeen[
event.itemType == PlacesUtils.bookmarks.TYPE_FOLDER
? "folders"
@ -117,4 +130,22 @@ add_task(async function() {
itemsSeen.bookmarks + itemsSeen.folders,
"Telemetry reporting correct."
);
}
add_task(async function test_Chrome() {
let subDirs =
AppConstants.platform == "linux" ? ["google-chrome"] : ["Google", "Chrome"];
await testBookmarks("chrome", subDirs, "From Google Chrome");
});
add_task(async function test_ChromiumEdge() {
if (AppConstants.platform == "linux") {
// Edge isn't available on Linux.
return;
}
let subDirs =
AppConstants.platform == "macosx"
? ["Microsoft Edge"]
: ["Microsoft", "Edge"];
await testBookmarks("chromium-edge", subDirs, "From Microsoft Edge");
});