зеркало из https://github.com/mozilla/gecko-dev.git
Bug 896291 - 'Close other tabs' should show the confirmation dialog if the number of tabs is greater than browser.sessionstore.max_tabs_undo. r=ttaubert,MattN
--HG-- extra : rebase_source : 0e7d5bfa58f020f49e97824da9c1c00fab369357
This commit is contained in:
Родитель
96ace1adc3
Коммит
a8fac1a113
|
@ -1671,9 +1671,26 @@
|
|||
throw new Error("Invalid argument: " + aCloseTabs);
|
||||
}
|
||||
|
||||
if (tabsToClose <= 1 ||
|
||||
aCloseTabs != this.closingTabsEnum.ALL ||
|
||||
!Services.prefs.getBoolPref("browser.tabs.warnOnClose"))
|
||||
let maxUndo =
|
||||
Services.prefs.getIntPref("browser.sessionstore.max_tabs_undo");
|
||||
let warnOnCloseOtherTabs =
|
||||
Services.prefs.getBoolPref("browser.tabs.warnOnCloseOtherTabs");
|
||||
let warnOnCloseWindow =
|
||||
Services.prefs.getBoolPref("browser.tabs.warnOnClose");
|
||||
let isWindowClosing = aCloseTabs == this.closingTabsEnum.ALL;
|
||||
|
||||
let skipWarning =
|
||||
// 1) If there is only one tab to close, we'll never warn the user.
|
||||
tabsToClose <= 1 ||
|
||||
// 2) If the whole window is going to be closed, don't warn the
|
||||
// user if the user has browser.tabs.warnOnClose set to false.
|
||||
(isWindowClosing && !warnOnCloseWindow) ||
|
||||
// 3) If the number of tabs are less than the undo threshold
|
||||
// or if the user has specifically opted-in to ignoring
|
||||
// this warning via the warnOnCloseOtherTabs pref.
|
||||
(!isWindowClosing && (!warnOnCloseOtherTabs ||
|
||||
tabsToClose <= maxUndo));
|
||||
if (skipWarning)
|
||||
return true;
|
||||
|
||||
var ps = Services.prompt;
|
||||
|
@ -1702,8 +1719,11 @@
|
|||
var reallyClose = (buttonPressed == 0);
|
||||
|
||||
// don't set the pref unless they press OK and it's false
|
||||
if (reallyClose && !warnOnClose.value)
|
||||
Services.prefs.setBoolPref("browser.tabs.warnOnClose", false);
|
||||
if (reallyClose && !warnOnClose.value) {
|
||||
let pref = isWindowClosing ? "browser.tabs.warnOnClose" :
|
||||
"browser.tabs.warnOnCloseOtherTabs";
|
||||
Services.prefs.setBoolPref(pref, false);
|
||||
}
|
||||
|
||||
return reallyClose;
|
||||
]]>
|
||||
|
|
|
@ -199,6 +199,7 @@ support-files =
|
|||
[browser_bug880101.js]
|
||||
[browser_bug882977.js]
|
||||
[browser_bug887515.js]
|
||||
[browser_bug896291_closeMaxSessionStoreTabs.js]
|
||||
[browser_bug902156.js]
|
||||
[browser_canonizeURL.js]
|
||||
[browser_clearplugindata.html]
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
function numClosedTabs()
|
||||
Cc["@mozilla.org/browser/sessionstore;1"].
|
||||
getService(Ci.nsISessionStore).
|
||||
getNumberOfTabsClosedLast(window);
|
||||
|
||||
let originalTab;
|
||||
let maxTabsUndo;
|
||||
let maxTabsUndoPlusOne;
|
||||
let acceptRemoveAllTabsDialogListener;
|
||||
let cancelRemoveAllTabsDialogListener;
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
Services.prefs.setBoolPref("browser.tabs.animate", false);
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
Services.prefs.clearUserPref("browser.tabs.animate");
|
||||
|
||||
originalTab.linkedBrowser.loadURI("about:blank");
|
||||
originalTab = null;
|
||||
});
|
||||
|
||||
// Creating and throwing away this tab guarantees that the
|
||||
// number of tabs closed in the previous tab-close operation is 1.
|
||||
let throwaway_tab = gBrowser.addTab("http://mochi.test:8888/");
|
||||
gBrowser.removeTab(throwaway_tab);
|
||||
|
||||
let undoCloseTabElement = document.getElementById("context_undoCloseTab");
|
||||
updateTabContextMenu();
|
||||
is(undoCloseTabElement.label, undoCloseTabElement.getAttribute("singletablabel"),
|
||||
"The label should be showing that the command will restore a single tab");
|
||||
|
||||
originalTab = gBrowser.selectedTab;
|
||||
gBrowser.selectedBrowser.loadURI("http://mochi.test:8888/");
|
||||
|
||||
maxTabsUndo = Services.prefs.getIntPref("browser.sessionstore.max_tabs_undo");
|
||||
maxTabsUndoPlusOne = maxTabsUndo + 1;
|
||||
let numberOfTabsLoaded = 0;
|
||||
for (let i = 0; i < maxTabsUndoPlusOne; i++) {
|
||||
let tab = gBrowser.addTab("http://mochi.test:8888/");
|
||||
let browser = gBrowser.getBrowserForTab(tab);
|
||||
browser.addEventListener("load", function onLoad() {
|
||||
browser.removeEventListener("load", onLoad, true);
|
||||
|
||||
if (++numberOfTabsLoaded == maxTabsUndoPlusOne)
|
||||
verifyUndoMultipleClose();
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
|
||||
function verifyUndoMultipleClose() {
|
||||
info("all tabs opened and loaded");
|
||||
cancelRemoveAllTabsDialogListener = new WindowListener("chrome://global/content/commonDialog.xul", cancelRemoveAllTabsDialog);
|
||||
Services.wm.addListener(cancelRemoveAllTabsDialogListener);
|
||||
gBrowser.removeAllTabsBut(originalTab);
|
||||
}
|
||||
|
||||
function cancelRemoveAllTabsDialog(domWindow) {
|
||||
ok(true, "dialog appeared in response to multiple tab close action");
|
||||
domWindow.document.documentElement.cancelDialog();
|
||||
Services.wm.removeListener(cancelRemoveAllTabsDialogListener);
|
||||
|
||||
acceptRemoveAllTabsDialogListener = new WindowListener("chrome://global/content/commonDialog.xul", acceptRemoveAllTabsDialog);
|
||||
Services.wm.addListener(acceptRemoveAllTabsDialogListener);
|
||||
waitForCondition(function () gBrowser.tabs.length == 1 + maxTabsUndoPlusOne, function verifyCancel() {
|
||||
is(gBrowser.tabs.length, 1 + maxTabsUndoPlusOne, /* The '1 +' is for the original tab */
|
||||
"All tabs should still be open after the 'Cancel' option on the prompt is chosen");
|
||||
gBrowser.removeAllTabsBut(originalTab);
|
||||
}, "Waited too long to find that no tabs were closed.");
|
||||
}
|
||||
|
||||
function acceptRemoveAllTabsDialog(domWindow) {
|
||||
ok(true, "dialog appeared in response to multiple tab close action");
|
||||
domWindow.document.documentElement.acceptDialog();
|
||||
Services.wm.removeListener(acceptRemoveAllTabsDialogListener);
|
||||
|
||||
waitForCondition(function () gBrowser.tabs.length == 1, function verifyAccept() {
|
||||
is(gBrowser.tabs.length, 1,
|
||||
"All other tabs should be closed after the 'OK' option on the prompt is chosen");
|
||||
finish();
|
||||
}, "Waited too long for the other tabs to be closed.");
|
||||
}
|
||||
|
||||
function WindowListener(aURL, aCallback) {
|
||||
this.callback = aCallback;
|
||||
this.url = aURL;
|
||||
}
|
||||
WindowListener.prototype = {
|
||||
onOpenWindow: function(aXULWindow) {
|
||||
var domWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindow);
|
||||
var self = this;
|
||||
domWindow.addEventListener("load", function() {
|
||||
domWindow.removeEventListener("load", arguments.callee, false);
|
||||
|
||||
info("domWindow.document.location.href: " + domWindow.document.location.href);
|
||||
if (domWindow.document.location.href != self.url)
|
||||
return;
|
||||
|
||||
// Allow other window load listeners to execute before passing to callback
|
||||
executeSoon(function() {
|
||||
self.callback(domWindow);
|
||||
});
|
||||
}, false);
|
||||
},
|
||||
onCloseWindow: function(aXULWindow) {},
|
||||
onWindowTitleChange: function(aXULWindow, aNewTitle) {}
|
||||
}
|
Загрузка…
Ссылка в новой задаче