Skip to content

Commit

Permalink
Bug 1839845 - Add a few tests for about:settings behavior. r=Gijs,rob…
Browse files Browse the repository at this point in the history
…wu,settings-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D203052
  • Loading branch information
bojidar-bg committed Feb 29, 2024
1 parent 061e6bc commit 4ad24f7
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
2 changes: 2 additions & 0 deletions browser/components/preferences/tests/browser.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ support-files = [
"addons/set_newtab.xpi",
]

["browser_about_settings.js"]

["browser_advanced_update.js"]
skip-if = ["!updater"]

Expand Down
29 changes: 29 additions & 0 deletions browser/components/preferences/tests/browser_about_settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_openPreferences_aboutSettings() {
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: "about:settings",
},
async () => {
is(
gBrowser.currentURI.spec,
"about:settings",
"about:settings should open normally"
);

// using `openPreferencesViaOpenPreferencesAPI` would introduce an extra about:blank tab we need to take care of
await openPreferences("paneGeneral");

is(
gBrowser.currentURI.spec,
"about:settings#general",
"openPreferences should keep about:settings"
);
}
);
});
2 changes: 2 additions & 0 deletions toolkit/mozapps/extensions/test/browser/browser.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ https_first_disabled = true

["browser_sidebar_hidden_categories.js"]

["browser_sidebar_preferences_button.js"]

["browser_sidebar_restore_category.js"]

["browser_subframe_install.js"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function testNoOtherTabsPresent() {
let addonsWin = await loadInitialView("extension");
let preferencesButton =
addonsWin.document.querySelector("#preferencesButton");

let preferencesPromise = BrowserTestUtils.waitForNewTab(
gBrowser,
"about:preferences"
);

preferencesButton.click();

let preferencesTab = await preferencesPromise;

is(
gBrowser.currentURI.spec,
"about:preferences",
"about:preferences should open if neither it nor about:settings are present"
);

gBrowser.removeTab(preferencesTab);

await closeView(addonsWin);
});

async function ensurePreferencesButtonFocusesTab(expectedUri) {
let addonsWin = await loadInitialView("extension");
let preferencesButton =
addonsWin.document.querySelector("#preferencesButton");

let tabCountBeforeClick = gBrowser.tabCount;
preferencesButton.click();
let tabCountAfterClick = gBrowser.tabCount;

is(
tabCountAfterClick,
tabCountBeforeClick,
"preferences button should not open new tabs"
);
is(
gBrowser.currentURI.spec,
expectedUri,
"the correct tab should be focused"
);

addonsWin.focus();
await closeView(addonsWin);
}

add_task(async function testAboutPreferencesPresent() {
await BrowserTestUtils.withNewTab("about:preferences", async () => {
await ensurePreferencesButtonFocusesTab("about:preferences");
});
});

add_task(async function testAboutSettingsPresent() {
await BrowserTestUtils.withNewTab("about:settings", async () => {
await ensurePreferencesButtonFocusesTab("about:settings");
});
});

add_task(async function testAboutSettingsAndPreferencesPresent() {
await BrowserTestUtils.withNewTab("about:settings", async () => {
await BrowserTestUtils.withNewTab("about:preferences", async () => {
await ensurePreferencesButtonFocusesTab("about:settings");
});
});
});

0 comments on commit 4ad24f7

Please sign in to comment.