fune/browser/components/places/tests/browser/browser_autoshow_bookmarks_toolbar.js
Jonathan Sudiaman 1f02cc1ca2 Bug 1812083 - Enable delayed apply bookmarks in Firefox Nightly r=mak
As expected, the try job flagged a bunch of test failures when flipping the default `delayedApply` pref to `true`. Some of these failures are legitimate issues:

  - When creating a new folder in the tree under "Location", renaming the folder doesn't update its name in the Location field.
  - When right clicking a bookmark in the sidebar, and creating a new folder, the folder doesn't get placed before the bookmark, i.e. the insertion point is ignored.

And as you pointed out, tags were being wiped out on blur in the Star/Toolbar panels. These issues have been fixed. The rest of the failures have been fixed in one of these ways:

  - Update the test to pass regardless of `delayedApply` setting. This was the preferred method.
  - Force the test to use instant apply. This was only done for tests that have an existing delayed apply counterpart.
  - Force the entire test suite to use instant apply. This was only done for one file, namely `browser_bookmark_popup.js`. I'll file a bug to spin off a delayed apply version of this suite.

try job with `delayedApply` enabled: https://treeherder.mozilla.org/jobs?repo=try&revision=50e9cdb65feaec07c9519e928caf62042c3df9a4
try job with `delayedApply` disabled: https://treeherder.mozilla.org/jobs?repo=try&revision=1102b5076a79bf08a0e4b073fdf369af97a16ef7

Differential Revision: https://phabricator.services.mozilla.com/D168690
2023-02-16 17:31:49 +00:00

176 lines
5.5 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const LOCATION_PREF = "browser.bookmarks.defaultLocation";
const TOOLBAR_VISIBILITY_PREF = "browser.toolbars.bookmarks.visibility";
let bookmarkPanel;
let win;
add_setup(async function() {
Services.prefs.clearUserPref(LOCATION_PREF);
await PlacesUtils.bookmarks.eraseEverything();
// Panel must be instant apply for tests to pass.
await SpecialPowers.pushPrefEnv({
set: [["browser.bookmarks.editDialog.delayedApply.enabled", false]],
});
win = await BrowserTestUtils.openNewBrowserWindow();
let oldTimeout = win.StarUI._autoCloseTimeout;
// Make the timeout something big, so it doesn't interact badly with tests.
win.StarUI._autoCloseTimeout = 6000000;
win.StarUI._createPanelIfNeeded();
bookmarkPanel = win.document.getElementById("editBookmarkPanel");
bookmarkPanel.setAttribute("animate", false);
registerCleanupFunction(async () => {
bookmarkPanel = null;
win.StarUI._autoCloseTimeout = oldTimeout;
await BrowserTestUtils.closeWindow(win);
win = null;
await PlacesUtils.bookmarks.eraseEverything();
Services.prefs.clearUserPref(LOCATION_PREF);
});
});
/**
* Helper to check we've shown the toolbar
*
* @param {object} options
* Options for the test
* @param {boolean} options.showToolbar
* If the toolbar should be shown or not
* @param {string} options.expectedFolder
* The expected folder to be shown
* @param {string} options.reason
* The reason the toolbar should be shown
*/
async function checkResponse({ showToolbar, expectedFolder, reason }) {
// Check folder.
let menuList = win.document.getElementById("editBMPanel_folderMenuList");
Assert.equal(
menuList.label,
PlacesUtils.getString(expectedFolder),
`Should have ${expectedFolder} selected ${reason}.`
);
// Check toolbar:
let toolbar = win.document.getElementById("PersonalToolbar");
Assert.equal(
!toolbar.collapsed,
showToolbar,
`Toolbar should be ${showToolbar ? "visible" : "hidden"} ${reason}.`
);
let hiddenPromise = promisePopupHidden(
win.document.getElementById("editBookmarkPanel")
);
// Confirm and close the dialog.
let guid = win.gEditItemOverlay._paneInfo.itemGuid;
let promiseRemoved = PlacesTestUtils.waitForNotification(
"bookmark-removed",
events => events.some(e => e.guid == guid)
);
win.document.getElementById("editBookmarkPanelRemoveButton").click();
await hiddenPromise;
await promiseRemoved;
}
/**
* Test that if we create a bookmark on the toolbar, we show the
* toolbar:
*/
add_task(async function test_new_on_toolbar() {
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: "https://example.com/1" },
async browser => {
let toolbar = win.document.getElementById("PersonalToolbar");
Assert.equal(
toolbar.collapsed,
true,
"Bookmarks toolbar should start out collapsed."
);
let shownPromise = promisePopupShown(
win.document.getElementById("editBookmarkPanel")
);
win.document.getElementById("Browser:AddBookmarkAs").doCommand();
await shownPromise;
await TestUtils.waitForCondition(
() => !toolbar.collapsed,
"Toolbar should be shown."
);
let expectedFolder = "BookmarksToolbarFolderTitle";
let reason = "when creating a bookmark there";
await checkResponse({ showToolbar: true, expectedFolder, reason });
}
);
});
/**
* Test that if we create a bookmark on the toolbar, we do not
* show the toolbar if toolbar should never be shown:
*/
add_task(async function test_new_on_toolbar_never_show_toolbar() {
await SpecialPowers.pushPrefEnv({
set: [[TOOLBAR_VISIBILITY_PREF, "never"]],
});
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: "https://example.com/1" },
async browser => {
let toolbar = win.document.getElementById("PersonalToolbar");
Assert.equal(
toolbar.collapsed,
true,
"Bookmarks toolbar should start out collapsed."
);
let shownPromise = promisePopupShown(
win.document.getElementById("editBookmarkPanel")
);
win.document.getElementById("Browser:AddBookmarkAs").doCommand();
await shownPromise;
let expectedFolder = "BookmarksToolbarFolderTitle";
let reason = "when the visibility pref is 'never'";
await checkResponse({ showToolbar: false, expectedFolder, reason });
}
);
await SpecialPowers.popPrefEnv();
});
/**
* Test that if we edit an existing bookmark, we don't show the toolbar.
*/
add_task(async function test_existing_on_toolbar() {
// Create the bookmark first:
await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
title: "Test for editing",
url: "https://example.com/editing-test",
});
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: "https://example.com/editing-test" },
async browser => {
await TestUtils.waitForCondition(
() => win.BookmarkingUI.status == BookmarkingUI.STATUS_STARRED,
"Page should be starred."
);
let toolbar = win.document.getElementById("PersonalToolbar");
Assert.equal(
toolbar.collapsed,
true,
"Bookmarks toolbar should start out collapsed."
);
await clickBookmarkStar(win);
let expectedFolder = "BookmarksToolbarFolderTitle";
let reason = "when editing a bookmark there";
await checkResponse({ showToolbar: false, expectedFolder, reason });
}
);
});