Bug 1452970 - Add auto-hide option to Download toolbar icon context menu r=Gijs

MozReview-Commit-ID: VVPQesdzJ6

--HG--
extra : rebase_source : 4e53ac52adcfd2862a73ba875b59690027b13da0
This commit is contained in:
Oriol Brufau 2018-04-14 11:26:03 +02:00
parent e40aad16eb
commit 91cda569e3
4 changed files with 93 additions and 1 deletions

View File

@ -6368,6 +6368,22 @@ function UpdateCurrentCharset(target) {
}
}
function UpdateDownloadsAutoHide(popup) {
let checkbox = popup.querySelector(".customize-context-autoHide");
let isDownloads = popup.triggerNode && ["downloads-button", "wrapper-downloads-button"].includes(popup.triggerNode.id);
checkbox.hidden = !isDownloads;
if (this.window.DownloadsButton.autoHideDownloadsButton) {
checkbox.setAttribute("checked", "true");
} else {
checkbox.removeAttribute("checked");
}
}
function onDownloadsAutoHideChange(event) {
let autoHide = event.target.getAttribute("checked") == "true";
Services.prefs.setBoolPref("browser.download.autohideButton", autoHide);
}
var gPageStyleMenu = {
// This maps from a <browser> element (or, more specifically, a
// browser's permanentKey) to an Object that contains the most recent

View File

@ -332,12 +332,18 @@
</panel>
<menupopup id="toolbar-context-menu"
onpopupshowing="onViewToolbarsPopupShowing(event, document.getElementById('viewToolbarsMenuSeparator'));">
onpopupshowing="onViewToolbarsPopupShowing(event, document.getElementById('viewToolbarsMenuSeparator')); UpdateDownloadsAutoHide(this)">
<menuitem oncommand="gCustomizeMode.addToPanel(document.popupNode)"
accesskey="&customizeMenu.pinToOverflowMenu.accesskey;"
label="&customizeMenu.pinToOverflowMenu.label;"
contexttype="toolbaritem"
class="customize-context-moveToPanel"/>
<menuitem oncommand="onDownloadsAutoHideChange(event)"
type="checkbox"
accesskey="&customizeMenu.autoHideDownloadsButton.accesskey;"
label="&customizeMenu.autoHideDownloadsButton.label;"
contexttype="toolbaritem"
class="customize-context-autoHide"/>
<menuitem oncommand="gCustomizeMode.removeFromArea(document.popupNode)"
accesskey="&customizeMenu.removeFromToolbar.accesskey;"
label="&customizeMenu.removeFromToolbar.label;"

View File

@ -288,6 +288,57 @@ add_task(async function checkStateWhenHiddenInPalette() {
CustomizableUI.reset();
});
add_task(async function checkContextMenu() {
let contextMenu = document.getElementById("toolbar-context-menu");
let checkbox = contextMenu.querySelector(".customize-context-autoHide");
let button = document.getElementById("downloads-button");
is(Services.prefs.getBoolPref(kDownloadAutoHidePref), true,
"Pref should be causing us to autohide");
is(DownloadsIndicatorView.hasDownloads, false,
"Should be no downloads when starting the test");
is(button.hidden, true, "Downloads button is hidden");
info("Simulate a download to show the downloads button.");
DownloadsIndicatorView.hasDownloads = true;
is(button.hidden, false, "Downloads button is visible");
info("Check context menu");
await openContextMenu(button);
is(checkbox.hidden, false, "Auto-hide checkbox is visible");
is(checkbox.getAttribute("checked"), "true", "Auto-hide is enabled");
info("Disable auto-hide via context menu");
clickCheckbox(checkbox);
is(Services.prefs.getBoolPref(kDownloadAutoHidePref), false,
"Pref has been set to false");
info("Clear downloads");
DownloadsIndicatorView.hasDownloads = false;
is(button.hidden, false, "Downloads button is still visible");
info("Check context menu");
await openContextMenu(button);
is(checkbox.hidden, false, "Auto-hide checkbox is visible");
is(checkbox.hasAttribute("checked"), false, "Auto-hide is disabled");
info("Enable auto-hide via context menu");
clickCheckbox(checkbox);
is(button.hidden, true, "Downloads button is hidden");
is(Services.prefs.getBoolPref(kDownloadAutoHidePref), true,
"Pref has been set to true");
info("Check context menu in another button");
await openContextMenu(document.getElementById("home-button"));
is(checkbox.hidden, true, "Auto-hide checkbox is hidden");
contextMenu.hidePopup();
info("Open popup directly");
contextMenu.showPopup();
is(checkbox.hidden, true, "Auto-hide checkbox is hidden");
contextMenu.hidePopup();
});
function promiseCustomizeStart(aWindow = window) {
return new Promise(resolve => {
aWindow.gNavToolbox.addEventListener("customizationready", resolve,
@ -304,3 +355,20 @@ function promiseCustomizeEnd(aWindow = window) {
});
}
async function openContextMenu(element) {
let popupShownPromise = BrowserTestUtils.waitForEvent(document, "popupshown");
EventUtils.synthesizeMouseAtCenter(element, {type: "contextmenu", button: 2});
await popupShownPromise;
}
function clickCheckbox(checkbox) {
// Clicking a checkbox toggles its checkedness first.
if (checkbox.getAttribute("checked") == "true") {
checkbox.removeAttribute("checked");
} else {
checkbox.setAttribute("checked", "true");
}
// Then it runs the command and closes the popup.
checkbox.doCommand();
checkbox.parentElement.hidePopup();
}

View File

@ -426,6 +426,8 @@ These should match what Safari and other Apple applications use on OS X Lion. --
<!ENTITY customizeMenu.removeFromMenu.accesskey "R">
<!ENTITY customizeMenu.addMoreItems.label "Add More Items…">
<!ENTITY customizeMenu.addMoreItems.accesskey "A">
<!ENTITY customizeMenu.autoHideDownloadsButton.label "Auto-Hide in Toolbar">
<!ENTITY customizeMenu.autoHideDownloadsButton.accesskey "A">
<!-- LOCALIZATION NOTE (moreMenu.label) This label is used in the new Photon
app (hamburger) menu. When clicked, it opens a subview that contains