Bug 1748345, if deleting the default bookmark folder, reset the preference so that it is valid for later use, r=mak

Differential Revision: https://phabricator.services.mozilla.com/D136199
This commit is contained in:
Neil Deakin
2022-01-20 12:21:51 +00:00
parent 730bdf6964
commit 1deffdd939
4 changed files with 93 additions and 33 deletions

View File

@@ -2143,6 +2143,21 @@ var BookmarkingUI = {
isStarUpdateNeeded = true;
}
}
// Reset the default location if it is equal to the folder
// being deleted. Just check the preference directly since we
// do not want to do a asynchronous db lookup.
PlacesUIUtils.defaultParentGuid.then(parentGuid => {
if (
ev.itemType == PlacesUtils.bookmarks.TYPE_FOLDER &&
ev.guid == parentGuid
) {
Services.prefs.setCharPref(
"browser.bookmarks.defaultLocation",
PlacesUtils.bookmarks.toolbarGuid
);
}
});
break;
case "bookmark-moved":
const hasMovedInOutOtherBookmarks =

View File

@@ -302,6 +302,18 @@ add_task(async function panel_shown_for_new_bookmark_keypress_no_autoclose() {
});
});
add_task(async function bookmark_with_invalid_default_folder() {
await createAndRemoveDefaultFolder();
await test_bookmarks_popup({
isNewBookmark: true,
shouldAutoClose: true,
async popupShowFn(browser) {
EventUtils.synthesizeKey("d", { accelKey: true }, window);
},
});
});
add_task(
async function panel_shown_for_new_bookmark_compositionstart_no_autoclose() {
await test_bookmarks_popup({

View File

@@ -105,40 +105,49 @@ add_task(async function test_shortcut_location() {
* bookmark location.
*/
add_task(async function test_context_menu_link() {
await withBookmarksDialog(
true,
async function openDialog() {
const contextMenu = win.document.getElementById("contentAreaContextMenu");
is(contextMenu.state, "closed", "checking if popup is closed");
let promisePopupShown = BrowserTestUtils.waitForEvent(
contextMenu,
"popupshown"
);
BrowserTestUtils.synthesizeMouseAtCenter(
"a[href*=config]", // Bookmark about:config
{ type: "contextmenu", button: 2 },
win.gBrowser.selectedBrowser
);
await promisePopupShown;
contextMenu.activateItem(
win.document.getElementById("context-bookmarklink")
);
},
async function test(dialogWin) {
let expectedFolder = "BookmarksToolbarFolderTitle";
let expectedFolderName = PlacesUtils.getString(expectedFolder);
let folderPicker = dialogWin.document.getElementById(
"editBMPanel_folderMenuList"
);
// Check the initial state of the folder picker.
await TestUtils.waitForCondition(
() => folderPicker.selectedItem.label == expectedFolderName,
"The folder is the expected one."
);
for (let t = 0; t < 2; t++) {
if (t == 1) {
// For the second iteration, ensure that the default folder is invalid first.
await createAndRemoveDefaultFolder();
}
);
await withBookmarksDialog(
true,
async function openDialog() {
const contextMenu = win.document.getElementById(
"contentAreaContextMenu"
);
is(contextMenu.state, "closed", "checking if popup is closed");
let promisePopupShown = BrowserTestUtils.waitForEvent(
contextMenu,
"popupshown"
);
BrowserTestUtils.synthesizeMouseAtCenter(
"a[href*=config]", // Bookmark about:config
{ type: "contextmenu", button: 2 },
win.gBrowser.selectedBrowser
);
await promisePopupShown;
contextMenu.activateItem(
win.document.getElementById("context-bookmarklink")
);
},
async function test(dialogWin) {
let expectedFolder = "BookmarksToolbarFolderTitle";
let expectedFolderName = PlacesUtils.getString(expectedFolder);
let folderPicker = dialogWin.document.getElementById(
"editBMPanel_folderMenuList"
);
// Check the initial state of the folder picker.
await TestUtils.waitForCondition(
() => folderPicker.selectedItem.label == expectedFolderName,
"The folder is the expected one."
);
}
);
}
});
/**

View File

@@ -524,6 +524,30 @@ async function hideBookmarksPanel(win = window) {
await hiddenPromise;
}
// Create a temporary folder, set it as the default folder,
// then remove the folder. This is used to ensure that the
// default folder gets reset properly.
async function createAndRemoveDefaultFolder() {
let tempFolder = await PlacesUtils.bookmarks.insertTree({
guid: PlacesUtils.bookmarks.unfiledGuid,
children: [
{
title: "temp folder",
type: PlacesUtils.bookmarks.TYPE_FOLDER,
},
],
});
await SpecialPowers.pushPrefEnv({
set: [["browser.bookmarks.defaultLocation", tempFolder[0].guid]],
});
let defaultGUID = await PlacesUIUtils.defaultParentGuid;
is(defaultGUID, tempFolder[0].guid, "check default guid");
await PlacesUtils.bookmarks.remove(tempFolder);
}
registerCleanupFunction(() => {
Services.prefs.clearUserPref("browser.bookmarks.defaultLocation");
});