Bug 1797527 - Update PersonalToolbar policy with newtab feature. r=mstriemer

Differential Revision: https://phabricator.services.mozilla.com/D160814
This commit is contained in:
Mike Kaply 2022-11-02 19:32:13 +00:00
Родитель a044cb65e4
Коммит a929f73a08
3 изменённых файлов: 76 добавлений и 20 удалений

Просмотреть файл

@ -846,23 +846,18 @@ export var Policies = {
DisplayBookmarksToolbar: {
onBeforeUIStartup(manager, param) {
let value = (!param).toString();
let visibility;
if (typeof param === "boolean") {
visibility = param ? "always" : "newtab";
} else {
visibility = param;
}
// This policy is meant to change the default behavior, not to force it.
// If this policy was alreay applied and the user chose to re-hide the
// If this policy was already applied and the user chose to re-hide the
// bookmarks toolbar, do not show it again.
runOncePerModification("displayBookmarksToolbar", value, () => {
// Set the preference to keep the bookmarks bar open and also
// declaratively open the bookmarks toolbar. Otherwise, default
// to showing it on the New Tab Page.
runOncePerModification("displayBookmarksToolbar", visibility, () => {
let visibilityPref = "browser.toolbars.bookmarks.visibility";
let visibility = param ? "always" : "newtab";
Services.prefs.setCharPref(visibilityPref, visibility);
lazy.gXulStore.setValue(
BROWSER_DOCUMENT_URL,
"PersonalToolbar",
"collapsed",
value
);
});
},
},

Просмотреть файл

@ -391,7 +391,8 @@
},
"DisplayBookmarksToolbar": {
"type": "boolean"
"type": ["boolean", "string"],
"enum": ["always", "never", "newtab"]
},
"DisplayMenuBar": {

Просмотреть файл

@ -3,17 +3,15 @@
"use strict";
add_setup(async function() {
// Since testing will apply the policy after the browser has already started,
// we will need to open a new window to actually see the toolbar
add_task(async function test_personaltoolbar_shown_old() {
await setupPolicyEngineWithJson({
policies: {
DisplayBookmarksToolbar: true,
},
});
});
add_task(async function test_menu_shown() {
// Since testing will apply the policy after the browser has already started,
// we will need to open a new window to actually see the toolbar
let newWin = await BrowserTestUtils.openNewBrowserWindow();
let menuBar = newWin.document.getElementById("PersonalToolbar");
is(
@ -24,3 +22,65 @@ add_task(async function test_menu_shown() {
await BrowserTestUtils.closeWindow(newWin);
});
add_task(async function test_personaltoolbar_shown() {
await setupPolicyEngineWithJson({
policies: {
DisplayBookmarksToolbar: "always",
},
});
let newWin = await BrowserTestUtils.openNewBrowserWindow();
let menuBar = newWin.document.getElementById("PersonalToolbar");
is(
menuBar.getAttribute("collapsed"),
"false",
"The bookmarks toolbar should not be hidden"
);
await BrowserTestUtils.closeWindow(newWin);
});
add_task(async function test_personaltoolbar_hidden() {
await setupPolicyEngineWithJson({
policies: {
DisplayBookmarksToolbar: "never",
},
});
let newWin = await BrowserTestUtils.openNewBrowserWindow();
let menuBar = newWin.document.getElementById("PersonalToolbar");
is(
menuBar.getAttribute("collapsed"),
"true",
"The bookmarks toolbar should be hidden"
);
await BrowserTestUtils.closeWindow(newWin);
});
add_task(async function test_personaltoolbar_newtabonly() {
await setupPolicyEngineWithJson({
policies: {
DisplayBookmarksToolbar: "newtab",
},
});
let newWin = await BrowserTestUtils.openNewBrowserWindow();
let menuBar = newWin.document.getElementById("PersonalToolbar");
is(
menuBar.getAttribute("collapsed"),
"true",
"The bookmarks toolbar should be hidden"
);
await BrowserTestUtils.openNewForegroundTab(newWin.gBrowser, "about:newtab");
menuBar = newWin.document.getElementById("PersonalToolbar");
is(
menuBar.getAttribute("collapsed"),
"false",
"The bookmarks toolbar should not be hidden"
);
await BrowserTestUtils.closeWindow(newWin);
});