Bug 1885189 - remove some test-only uses of prompts.contentPromptSubDialog, r=mconley

Differential Revision: https://phabricator.services.mozilla.com/D204533
This commit is contained in:
Gijs Kruitbosch 2024-03-13 22:19:58 +00:00
Родитель 024aa599f6
Коммит 07aa4af286
13 изменённых файлов: 22 добавлений и 338 удалений

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

@ -1,36 +1,11 @@
const TEST_PAGE =
"http://mochi.test:8888/browser/browser/base/content/test/general/file_double_close_tab.html";
const CONTENT_PROMPT_SUBDIALOG = Services.prefs.getBoolPref(
"prompts.contentPromptSubDialog",
false
);
var expectingDialog = false;
var wantToClose = true;
var resolveDialogPromise;
function onTabModalDialogLoaded(node) {
ok(
!CONTENT_PROMPT_SUBDIALOG,
"Should not be using content prompt subdialogs."
);
ok(expectingDialog, "Should be expecting this dialog.");
expectingDialog = false;
if (wantToClose) {
// This accepts the dialog, closing it
node.querySelector(".tabmodalprompt-button0").click();
} else {
// This keeps the page open
node.querySelector(".tabmodalprompt-button1").click();
}
if (resolveDialogPromise) {
resolveDialogPromise();
}
}
function onCommonDialogLoaded(promptWindow) {
ok(CONTENT_PROMPT_SUBDIALOG, "Should be using content prompt subdialogs.");
ok(expectingDialog, "Should be expecting this dialog.");
expectingDialog = false;
let dialog = promptWindow.Dialog;
@ -51,11 +26,9 @@ SpecialPowers.pushPrefEnv({
});
// Listen for the dialog being created
Services.obs.addObserver(onTabModalDialogLoaded, "tabmodal-dialog-loaded");
Services.obs.addObserver(onCommonDialogLoaded, "common-dialog-loaded");
registerCleanupFunction(() => {
Services.prefs.clearUserPref("browser.tabs.warnOnClose");
Services.obs.removeObserver(onTabModalDialogLoaded, "tabmodal-dialog-loaded");
Services.obs.removeObserver(onCommonDialogLoaded, "common-dialog-loaded");
});

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

@ -4,24 +4,15 @@ const TEST_PAGE =
"http://mochi.test:8888/browser/browser/base/content/test/general/file_double_close_tab.html";
var testTab;
const CONTENT_PROMPT_SUBDIALOG = Services.prefs.getBoolPref(
"prompts.contentPromptSubDialog",
false
);
function waitForDialog(callback) {
function onDialogLoaded(nodeOrDialogWindow) {
let node = CONTENT_PROMPT_SUBDIALOG
? nodeOrDialogWindow.document.querySelector("dialog")
: nodeOrDialogWindow;
Services.obs.removeObserver(onDialogLoaded, "tabmodal-dialog-loaded");
let node = nodeOrDialogWindow.document.querySelector("dialog");
Services.obs.removeObserver(onDialogLoaded, "common-dialog-loaded");
// Allow dialog's onLoad call to run to completion
Promise.resolve().then(() => callback(node));
}
// Listen for the dialog being created
Services.obs.addObserver(onDialogLoaded, "tabmodal-dialog-loaded");
Services.obs.addObserver(onDialogLoaded, "common-dialog-loaded");
}
@ -35,9 +26,7 @@ function waitForDialogDestroyed(node, callback) {
});
observer.observe(node.parentNode, { childList: true });
if (CONTENT_PROMPT_SUBDIALOG) {
node.ownerGlobal.addEventListener("unload", done);
}
node.ownerGlobal.addEventListener("unload", done);
let failureTimeout = setTimeout(function () {
ok(false, "Dialog should have been destroyed");
@ -49,12 +38,8 @@ function waitForDialogDestroyed(node, callback) {
observer.disconnect();
observer = null;
if (CONTENT_PROMPT_SUBDIALOG) {
node.ownerGlobal.removeEventListener("unload", done);
SimpleTest.executeSoon(callback);
} else {
callback();
}
node.ownerGlobal.removeEventListener("unload", done);
SimpleTest.executeSoon(callback);
}
}
@ -76,23 +61,12 @@ add_task(async function () {
let doCompletion = () => setTimeout(resolveOuter, 0);
info("Now checking if dialog is destroyed");
if (CONTENT_PROMPT_SUBDIALOG) {
ok(
!dialogNode.ownerGlobal || dialogNode.ownerGlobal.closed,
"onbeforeunload dialog should be gone."
);
if (dialogNode.ownerGlobal && !dialogNode.ownerGlobal.closed) {
dialogNode.acceptDialog();
}
} else {
ok(!dialogNode.parentNode, "onbeforeunload dialog should be gone.");
if (dialogNode.parentNode) {
// Failed to remove onbeforeunload dialog, so do it ourselves:
let leaveBtn = dialogNode.querySelector(".tabmodalprompt-button0");
waitForDialogDestroyed(dialogNode, doCompletion);
EventUtils.synthesizeMouseAtCenter(leaveBtn, {});
return;
}
ok(
!dialogNode.ownerGlobal || dialogNode.ownerGlobal.closed,
"onbeforeunload dialog should be gone."
);
if (dialogNode.ownerGlobal && !dialogNode.ownerGlobal.closed) {
dialogNode.acceptDialog();
}
doCompletion();

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

@ -9,11 +9,6 @@ const TEST_ROOT = getRootDirectory(gTestPath).replace(
"http://example.com"
);
const CONTENT_PROMPT_SUBDIALOG = Services.prefs.getBoolPref(
"prompts.contentPromptSubDialog",
false
);
add_task(async function test_beforeunload_stay_clears_urlbar() {
await SpecialPowers.pushPrefEnv({
set: [["dom.require_user_interaction_for_beforeunload", false]],
@ -27,27 +22,10 @@ add_task(async function test_beforeunload_stay_clears_urlbar() {
gURLBar.value = inputValue.slice(0, -1);
EventUtils.sendString(inputValue.slice(-1));
if (CONTENT_PROMPT_SUBDIALOG) {
let promptOpenedPromise =
BrowserTestUtils.promiseAlertDialogOpen("cancel");
EventUtils.synthesizeKey("VK_RETURN");
await promptOpenedPromise;
await TestUtils.waitForTick();
} else {
let promptOpenedPromise = TestUtils.topicObserved(
"tabmodal-dialog-loaded"
);
EventUtils.synthesizeKey("VK_RETURN");
await promptOpenedPromise;
let promptElement = browser.parentNode.querySelector("tabmodalprompt");
// Click the cancel button
promptElement.querySelector(".tabmodalprompt-button1").click();
await TestUtils.waitForCondition(
() => promptElement.parentNode == null,
"tabprompt should be removed"
);
}
let promptOpenedPromise = BrowserTestUtils.promiseAlertDialogOpen("cancel");
EventUtils.synthesizeKey("VK_RETURN");
await promptOpenedPromise;
await TestUtils.waitForTick();
// Can't just compare directly with TEST_URL because the URL may be trimmed.
// Just need it to not be the example.org thing we typed in.

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

@ -130,7 +130,6 @@ async function checkDialog(
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [
["prompts.contentPromptSubDialog", true],
["prompts.modalType.httpAuth", Ci.nsIPrompt.MODAL_TYPE_TAB],
["prompts.tabChromePromptSubDialog", true],
],

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

@ -1,13 +1,7 @@
"use strict";
const CONTENT_PROMPT_SUBDIALOG = Services.prefs.getBoolPref(
"prompts.contentPromptSubDialog",
false
);
/**
* Goes through a stacked series of dialogs opened with
* CONTENT_PROMPT_SUBDIALOG set to true, and ensures that
* Goes through a stacked series of dialogs and ensures that
* the oldest one is front-most and has the right type. It
* then closes the oldest to newest dialog.
*
@ -58,64 +52,6 @@ async function closeDialogs(tab, dialogCount) {
is(dialogs.length, 0, "Dialogs should all be dismissed.");
}
/**
* Goes through a stacked series of tabprompt modals opened with
* CONTENT_PROMPT_SUBDIALOG set to false, and ensures that
* the oldest one is front-most and has the right type. It also
* ensures that the other tabprompt modals are hidden. It
* then closes the oldest to newest dialog.
*
* @param {Element} tab The <tab> that has had tabprompt modals opened
* for it.
* @param {Number} promptCount How many modals we expected to have been
* opened.
*
* @return {Promise}
* @resolves {undefined} Once the modals have all been closed.
*/
async function closeTabModals(tab, promptCount) {
let promptElementsCount = promptCount;
while (promptElementsCount--) {
let promptElements =
tab.linkedBrowser.parentNode.querySelectorAll("tabmodalprompt");
is(
promptElements.length,
promptElementsCount + 1,
"There should be " + (promptElementsCount + 1) + " prompt(s)."
);
// The oldest should be the first.
let i = 0;
for (let promptElement of promptElements) {
let prompt = tab.linkedBrowser.tabModalPromptBox.getPrompt(promptElement);
let expectedType = ["alert", "prompt", "confirm"][i % 3];
is(
prompt.Dialog.args.text,
expectedType + " countdown #" + i,
"The #" + i + " alert should be labelled as such."
);
if (i !== promptElementsCount) {
is(prompt.element.hidden, true, "This prompt should be hidden.");
i++;
continue;
}
is(prompt.element.hidden, false, "The last prompt should not be hidden.");
prompt.onButtonClick(0);
// The click is handled async; wait for an event loop turn for that to
// happen.
await new Promise(function (resolve) {
Services.tm.dispatchToMainThread(resolve);
});
}
}
let promptElements =
tab.linkedBrowser.parentNode.querySelectorAll("tabmodalprompt");
is(promptElements.length, 0, "Prompts should all be dismissed.");
}
/*
* This test triggers multiple alerts on one single tab, because it"s possible
* for web content to do so. The behavior is described in bug 1266353.
@ -161,11 +97,7 @@ add_task(async function () {
await promptsOpenedPromise;
if (CONTENT_PROMPT_SUBDIALOG) {
await closeDialogs(tab, PROMPTCOUNT);
} else {
await closeTabModals(tab, PROMPTCOUNT);
}
await closeDialogs(tab, PROMPTCOUNT);
BrowserTestUtils.removeTab(tab);
});

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

@ -22,118 +22,7 @@ registerCleanupFunction(function () {
* the user to enable this automatically re-selecting. We then check that
* checking the checkbox does actually enable that behaviour.
*/
add_task(async function test_old_modal_ui() {
// We're intentionally testing the old modal mechanism, so disable the new one.
await SpecialPowers.pushPrefEnv({
set: [["prompts.contentPromptSubDialog", false]],
});
let firstTab = gBrowser.selectedTab;
// load page that opens prompt when page is hidden
let openedTab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
pageWithAlert,
true
);
let openedTabGotAttentionPromise = BrowserTestUtils.waitForAttribute(
"attention",
openedTab
);
// switch away from that tab again - this triggers the alert.
await BrowserTestUtils.switchTab(gBrowser, firstTab);
// ... but that's async on e10s...
await openedTabGotAttentionPromise;
// check for attention attribute
is(
openedTab.hasAttribute("attention"),
true,
"Tab with alert should have 'attention' attribute."
);
ok(!openedTab.selected, "Tab with alert should not be selected");
// switch tab back, and check the checkbox is displayed:
await BrowserTestUtils.switchTab(gBrowser, openedTab);
// check the prompt is there, and the extra row is present
let promptElements =
openedTab.linkedBrowser.parentNode.querySelectorAll("tabmodalprompt");
is(promptElements.length, 1, "There should be 1 prompt");
let ourPromptElement = promptElements[0];
let checkbox = ourPromptElement.querySelector(
"checkbox[label*='example.com']"
);
ok(checkbox, "The checkbox should be there");
ok(!checkbox.checked, "Checkbox shouldn't be checked");
// tick box and accept dialog
checkbox.checked = true;
let ourPrompt =
openedTab.linkedBrowser.tabModalPromptBox.getPrompt(ourPromptElement);
ourPrompt.onButtonClick(0);
// Wait for that click to actually be handled completely.
await new Promise(function (resolve) {
Services.tm.dispatchToMainThread(resolve);
});
// check permission is set
is(
Services.perms.ALLOW_ACTION,
PermissionTestUtils.testPermission(pageWithAlert, "focus-tab-by-prompt"),
"Tab switching should now be allowed"
);
// Check if the control center shows the correct permission.
let shown = BrowserTestUtils.waitForEvent(
window,
"popupshown",
true,
event => event.target == gPermissionPanel._permissionPopup
);
gPermissionPanel._identityPermissionBox.click();
await shown;
let labelText = SitePermissions.getPermissionLabel("focus-tab-by-prompt");
let permissionsList = document.getElementById(
"permission-popup-permission-list"
);
let label = permissionsList.querySelector(
".permission-popup-permission-label"
);
is(label.textContent, labelText);
gPermissionPanel._permissionPopup.hidePopup();
// Check if the identity icon signals granted permission.
ok(
gPermissionPanel._identityPermissionBox.hasAttribute("hasPermissions"),
"identity-box signals granted permissions"
);
let openedTabSelectedPromise = BrowserTestUtils.waitForAttribute(
"selected",
openedTab,
"true"
);
// switch to other tab again
await BrowserTestUtils.switchTab(gBrowser, firstTab);
// This is sync in non-e10s, but in e10s we need to wait for this, so yield anyway.
// Note that the switchTab promise doesn't actually guarantee anything about *which*
// tab ends up as selected when its event fires, so using that here wouldn't work.
await openedTabSelectedPromise;
// should be switched back
ok(openedTab.selected, "Ta-dah, the other tab should now be selected again!");
// In e10s, with the conformant promise scheduling, we have to wait for next tick
// to ensure that the prompt is open before removing the opened tab, because the
// promise callback of 'openedTabSelectedPromise' could be done at the middle of
// RemotePrompt.openTabPrompt() while 'DOMModalDialogClosed' event is fired.
await TestUtils.waitForTick();
BrowserTestUtils.removeTab(openedTab);
});
add_task(async function test_new_modal_ui() {
// We're intentionally testing the new modal mechanism, so make sure it's enabled.
await SpecialPowers.pushPrefEnv({
set: [["prompts.contentPromptSubDialog", true]],
});
add_task(async function test_modal_ui() {
// Make sure we clear the focus tab permission set in the previous test
PermissionTestUtils.remove(pageWithAlert, "focus-tab-by-prompt");

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

@ -3,7 +3,6 @@
"use strict";
const CONTENT_PROMPT_PREF = "prompts.contentPromptSubDialog";
const TEST_ROOT_CHROME = getRootDirectory(gTestPath);
const TEST_DIALOG_PATH = TEST_ROOT_CHROME + "subdialog.xhtml";
@ -41,13 +40,6 @@ var commonDialogsBundle = Services.strings.createBundle(
"chrome://global/locale/commonDialogs.properties"
);
// Setup.
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [[CONTENT_PROMPT_PREF, true]],
});
});
/**
* Test that a manager for content prompts is added to tab dialog box.
*/

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

@ -4,14 +4,7 @@
// beforeunload confirmation ignores the beforeunload listener and
// unblocks the original close call.
const CONTENT_PROMPT_SUBDIALOG = Services.prefs.getBoolPref(
"prompts.contentPromptSubDialog",
false
);
const DIALOG_TOPIC = CONTENT_PROMPT_SUBDIALOG
? "common-dialog-loaded"
: "tabmodal-dialog-loaded";
const DIALOG_TOPIC = "common-dialog-loaded";
add_task(async function () {
await SpecialPowers.pushPrefEnv({

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

@ -85,9 +85,6 @@ add_task(async function context_one() {
add_task(async function context_invalid() {
info("Checks the context menu with a page that offers an invalid engine.");
await SpecialPowers.pushPrefEnv({
set: [["prompts.contentPromptSubDialog", false]],
});
let url = getRootDirectory(gTestPath) + "add_search_engine_invalid.html";
await BrowserTestUtils.withNewTab(url, async tab => {

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

@ -4,19 +4,12 @@ const BASE_URL = "http://mochi.test:8888/browser/docshell/test/browser/";
const TEST_PAGE = BASE_URL + "file_onbeforeunload_0.html";
const CONTENT_PROMPT_SUBDIALOG = Services.prefs.getBoolPref(
"prompts.contentPromptSubDialog",
false
);
const { PromptTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/PromptTestUtils.sys.mjs"
);
async function withTabModalPromptCount(expected, task) {
const DIALOG_TOPIC = CONTENT_PROMPT_SUBDIALOG
? "common-dialog-loaded"
: "tabmodal-dialog-loaded";
const DIALOG_TOPIC = "common-dialog-loaded";
let count = 0;
function observer() {

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

@ -21,22 +21,12 @@ XPCOMUtils.defineLazyPreferenceGetter(
false
);
// Whether web content prompts (alert etc.) are shown as SubDialog (true)
// or TabModalPrompt (false)
XPCOMUtils.defineLazyPreferenceGetter(
kPrefs,
"contentPromptSubDialogEnabled",
"prompts.contentPromptSubDialog",
false
);
function isCommonDialog(modalType) {
return (
modalType === Services.prompt.MODAL_TYPE_WINDOW ||
(kPrefs.tabPromptSubDialogEnabled &&
modalType === Services.prompt.MODAL_TYPE_TAB) ||
(kPrefs.contentPromptSubDialogEnabled &&
modalType === Services.prompt.MODAL_TYPE_CONTENT)
modalType === Services.prompt.MODAL_TYPE_CONTENT
);
}

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

@ -13,11 +13,6 @@ var tabSubDialogsEnabled = Services.prefs.getBoolPref(
false
);
var contentPromptSubdialogsEnabled = Services.prefs.getBoolPref(
"prompts.contentPromptSubDialog",
false
);
// Define these to make EventUtils happy.
let window = this;
let parent = {};
@ -91,11 +86,7 @@ async function handlePrompt(action, modalType, isSelect) {
let ui;
let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
if (
(!contentPromptSubdialogsEnabled &&
modalType === Services.prompt.MODAL_TYPE_CONTENT) ||
(!tabSubDialogsEnabled && modalType === Services.prompt.MODAL_TYPE_TAB)
) {
if (!tabSubDialogsEnabled && modalType === Services.prompt.MODAL_TYPE_TAB) {
let gBrowser = browserWin.gBrowser;
let promptManager = gBrowser.getTabModalPromptBox(gBrowser.selectedBrowser);
let prompts = promptManager.listPrompts();

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

@ -21,10 +21,6 @@ var tabSubDialogsEnabled = SpecialPowers.Services.prefs.getBoolPref(
"prompts.tabChromePromptSubDialog",
false
);
var contentSubDialogsEnabled = SpecialPowers.Services.prefs.getBoolPref(
"prompts.contentPromptSubDialog",
false
);
var isSelectDialog = false;
var isOSX = "nsILocalFileMac" in SpecialPowers.Ci;
var isE10S = SpecialPowers.Services.appinfo.processType == 2;
@ -200,20 +196,7 @@ function checkPromptState(promptState, expectedState) {
// XXX check title? OS X has title in content
is(promptState.msg, expectedState.msg, "Checking expected message");
let isOldContentPrompt =
!promptState.isSubDialogPrompt &&
modalType === Ci.nsIPrompt.MODAL_TYPE_CONTENT;
if (isOldContentPrompt && !promptState.showCallerOrigin) {
ok(
promptState.titleHidden,
"The title should be hidden for content prompts opened with tab modal prompt."
);
} else if (
isOSX ||
promptState.isSubDialogPrompt ||
promptState.showCallerOrigin
) {
if (isOSX || promptState.isSubDialogPrompt || promptState.showCallerOrigin) {
ok(
!promptState.titleHidden,
"Checking title always visible on OS X or when opened with common dialog"