Backed out changeset d16ac4c1714c (bug 1765440) for causing mochitests failures in browser_library_open_bookmark.js.
This commit is contained in:
@@ -9,122 +9,38 @@
|
||||
|
||||
const TEST_URL = "about:buildconfig";
|
||||
|
||||
/**
|
||||
* Open a bookmark from the Library and check whether it is focused and where
|
||||
* the bookmark opens, based on preferences and/or the click event.
|
||||
*
|
||||
* @param {object} options Destructured parameters.
|
||||
* @param {boolean} [options.loadInBackground=false] Whether the pref to load
|
||||
* bookmarks in the background is set.
|
||||
* @param {boolean} [options.loadInTabs=false] Whether the pref to load bookmarks
|
||||
* in new tabs (as opposed to the current tab) is set.
|
||||
* @param {"current" | "tab"} [options.where="current"] Where the bookmark is
|
||||
* expected to open (current tab or new tab).
|
||||
* @param {MouseEventOptions} [options.clickEvent={ clickCount: 2, button: 0 }]
|
||||
* Options for the simulated bookmark click. Many properties are available.
|
||||
* @see {EventUtils.synthesizeMouse}
|
||||
* @see {nsIDOMWindowUtils::sendMouseEvent}
|
||||
*/
|
||||
async function doOpenBookmarkTest({
|
||||
loadInBackground = false,
|
||||
loadInTabs = false,
|
||||
where = "current",
|
||||
clickEvent = { clickCount: 2, button: 0 },
|
||||
} = {}) {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.tabs.loadBookmarksInBackground", loadInBackground],
|
||||
["browser.tabs.loadBookmarksInTabs", loadInTabs],
|
||||
],
|
||||
});
|
||||
|
||||
// If `where` is "current", open a tab that will be reused by the bookmark. If
|
||||
// it's "tab", open a tab that can't be reused, expecting a new tab to be
|
||||
// opened when the bookmark is clicked.
|
||||
let tab1 = await BrowserTestUtils.openNewForegroundTab(
|
||||
gBrowser,
|
||||
where === "tab" ? "about:about" : "about:blank"
|
||||
);
|
||||
let loadedPromise =
|
||||
where === "tab"
|
||||
? BrowserTestUtils.waitForNewTab(gBrowser, TEST_URL, true)
|
||||
: BrowserTestUtils.browserLoaded(gBrowser, false, TEST_URL);
|
||||
|
||||
add_task(async function test_open_bookmark_from_library() {
|
||||
let bm = await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
url: TEST_URL,
|
||||
title: TEST_URL,
|
||||
});
|
||||
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(
|
||||
gBrowser,
|
||||
"about:blank"
|
||||
);
|
||||
|
||||
let gLibrary = await promiseLibrary("UnfiledBookmarks");
|
||||
gLibrary.focus();
|
||||
|
||||
registerCleanupFunction(async function () {
|
||||
await promiseLibraryClosed(gLibrary);
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
let bmLibrary = gLibrary.ContentTree.view.view.nodeForTreeIndex(0);
|
||||
Assert.equal(bmLibrary.title, bm.title, "Found bookmark in the right pane");
|
||||
|
||||
gLibrary.ContentTree.view.selectNode(bmLibrary);
|
||||
synthesizeClickOnSelectedTreeCell(gLibrary.ContentTree.view, clickEvent);
|
||||
|
||||
await loadedPromise;
|
||||
|
||||
// Only expect the browser window to be focused if the bookmark was opened in
|
||||
// the foreground.
|
||||
if (loadInBackground) {
|
||||
is(
|
||||
Services.wm.getMostRecentWindow(null),
|
||||
gLibrary,
|
||||
"Library window is still focused"
|
||||
);
|
||||
} else {
|
||||
isnot(
|
||||
Services.wm.getMostRecentWindow(null),
|
||||
gLibrary,
|
||||
"Library window is not focused"
|
||||
);
|
||||
}
|
||||
|
||||
BrowserTestUtils.removeTab(tab1);
|
||||
// There is only a tab to close if the bookmark was opened in a new tab.
|
||||
if (where === "tab") {
|
||||
BrowserTestUtils.removeTab(await loadedPromise);
|
||||
}
|
||||
}
|
||||
|
||||
add_setup(async function () {
|
||||
registerCleanupFunction(async function () {
|
||||
for (let library of Services.wm.getEnumerator("Places:Organizer")) {
|
||||
await promiseLibraryClosed(library);
|
||||
}
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
synthesizeClickOnSelectedTreeCell(gLibrary.ContentTree.view, {
|
||||
clickCount: 2,
|
||||
});
|
||||
|
||||
await BrowserTestUtils.browserLoaded(
|
||||
gBrowser.selectedBrowser,
|
||||
false,
|
||||
TEST_URL
|
||||
);
|
||||
Assert.ok(true, "Expected tab was loaded");
|
||||
});
|
||||
|
||||
add_task(function test_open_bookmark_from_library() {
|
||||
return doOpenBookmarkTest();
|
||||
});
|
||||
|
||||
add_task(
|
||||
/* Bug 1765440 - Open a bookmark from the library as a background tab, and
|
||||
confirm that the library remains focused. */
|
||||
function test_open_bookmark_in_background_from_library() {
|
||||
return doOpenBookmarkTest({
|
||||
where: "tab",
|
||||
loadInBackground: true,
|
||||
loadInTabs: true,
|
||||
clickEvent: { clickCount: 2, button: 0 },
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
add_task(
|
||||
/* Bug 1765440 - Open a bookmark from the library in a background tab via the
|
||||
middle mouse button, and confirm that the library remains focused. */
|
||||
function test_open_bookmark_in_background_from_library_middle_click() {
|
||||
return doOpenBookmarkTest({
|
||||
where: "tab",
|
||||
loadInBackground: true,
|
||||
loadInTabs: false,
|
||||
clickEvent: { clickCount: 1, button: 1 },
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -494,6 +494,10 @@ export const URILoadingHelper = {
|
||||
|
||||
// We're now committed to loading the link in an existing browser window.
|
||||
|
||||
// Raise the target window before loading the URI, since loading it may
|
||||
// result in a new frontmost window (e.g. "javascript:window.open('');").
|
||||
w.focus();
|
||||
|
||||
let targetBrowser;
|
||||
let loadInBackground;
|
||||
let uriObj;
|
||||
@@ -546,10 +550,6 @@ export const URILoadingHelper = {
|
||||
|
||||
switch (where) {
|
||||
case "current":
|
||||
// Raise the target window before loading the URI, since loading it may
|
||||
// result in a new frontmost window (e.g. "javascript:window.open('');")
|
||||
w.focus();
|
||||
|
||||
openInCurrentTab(targetBrowser, url, uriObj, params);
|
||||
|
||||
// Don't focus the content area if focus is in the address bar and we're
|
||||
@@ -561,19 +561,12 @@ export const URILoadingHelper = {
|
||||
case "tabshifted":
|
||||
loadInBackground = !loadInBackground;
|
||||
// fall through
|
||||
case "tab": {
|
||||
case "tab":
|
||||
focusUrlBar =
|
||||
!loadInBackground &&
|
||||
w.isBlankPageURL(url) &&
|
||||
!lazy.AboutNewTab.willNotifyUser;
|
||||
|
||||
// Don't focus the window when loading in background, since the caller may
|
||||
// be in a non-browser window, and the user might be trying to open several
|
||||
// pages in series.
|
||||
if (!loadInBackground) {
|
||||
w.focus();
|
||||
}
|
||||
|
||||
let tabUsedForLoad = w.gBrowser.addTab(url, {
|
||||
referrerInfo: params.referrerInfo,
|
||||
charset,
|
||||
@@ -619,7 +612,6 @@ export const URILoadingHelper = {
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user