зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1415913 - tabs.create without a windowId should target only normal windows, r=aswan
This introduces a new property to WindowTracker (on desktop only) called topNormalWindow
which returns the topmost window which is not a popup window. That property is then used
by tabs.create to identify the top "normal" window when a windowId is not passed to it.
Bug 1421709
has been filed to look for other opportunities to use topNormalWindow
in place of topWindow in our codebase.
MozReview-Commit-ID: DcV93wO6FoV
--HG--
extra : rebase_source : 7c7be7c364cc627d385929a2c9fd2dee757bf835
This commit is contained in:
Родитель
e1e1ed94e5
Коммит
9e8f1233a1
|
@ -14,6 +14,8 @@
|
|||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
|
||||
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
|
||||
"resource:///modules/RecentWindow.jsm");
|
||||
|
||||
var {
|
||||
ExtensionError,
|
||||
|
@ -173,6 +175,17 @@ class WindowTracker extends WindowTrackerBase {
|
|||
removeProgressListener(window, listener) {
|
||||
window.gBrowser.removeTabsProgressListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {DOMWindow|null} topNormalWindow
|
||||
* The currently active, or topmost, browser window, or null if no
|
||||
* browser window is currently open.
|
||||
* Will return the topmost "normal" (i.e., not popup) window.
|
||||
* @readonly
|
||||
*/
|
||||
get topNormalWindow() {
|
||||
return RecentWindow.getMostRecentBrowserWindow({allowPopups: false});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -328,7 +328,7 @@ this.tabs = class extends ExtensionAPI {
|
|||
return new Promise((resolve, reject) => {
|
||||
let window = createProperties.windowId !== null ?
|
||||
windowTracker.getWindow(createProperties.windowId, context) :
|
||||
windowTracker.topWindow;
|
||||
windowTracker.topNormalWindow;
|
||||
|
||||
if (!window.gBrowser) {
|
||||
let obs = (finishedWindow, topic, data) => {
|
||||
|
|
|
@ -225,3 +225,27 @@ add_task(async function test_urlbar_focus() {
|
|||
|
||||
await extension.unload();
|
||||
});
|
||||
|
||||
add_task(async function test_create_with_popup() {
|
||||
const extension = ExtensionTestUtils.loadExtension({
|
||||
async background() {
|
||||
let normalWin = await browser.windows.create();
|
||||
let lastFocusedNormalWin = await browser.windows.getLastFocused({});
|
||||
browser.test.assertEq(lastFocusedNormalWin.id, normalWin.id, "The normal window is the last focused window.");
|
||||
let popupWin = await browser.windows.create({type: "popup"});
|
||||
let lastFocusedPopupWin = await browser.windows.getLastFocused({});
|
||||
browser.test.assertEq(lastFocusedPopupWin.id, popupWin.id, "The popup window is the last focused window.");
|
||||
let newtab = await browser.tabs.create({});
|
||||
browser.test.assertEq(normalWin.id, newtab.windowId, "New tab was created in last focused normal window.");
|
||||
await Promise.all([
|
||||
browser.windows.remove(normalWin.id),
|
||||
browser.windows.remove(popupWin.id),
|
||||
]);
|
||||
browser.test.sendMessage("complete");
|
||||
},
|
||||
});
|
||||
|
||||
await extension.startup();
|
||||
await extension.awaitMessage("complete");
|
||||
await extension.unload();
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче