function registerMockPromptService()
{ var { XPCOMUtils } = SpecialPowers.ChromeUtils.importESModule( "resource://gre/modules/XPCOMUtils.sys.mjs"
); var Ci = SpecialPowers.Ci;
function MockPrompt(aDOMWindow) {
this.domWindow = SpecialPowers.unwrap(aDOMWindow);
}
_toggleModalState()
{
// The real prompt service puts the window into a modal state
// immediately before showing a modal prompt, and leaves the modal state
// when the prompt is dismissed by the user. This mock prompt doesn't
// show anything to the user, so we only need to enter and immediately
// leave the modal state -- this is done to trigger the necessary
// accounting for triggering the "stop showing more prompts"code for
// abusive pages. var winUtils = SpecialPowers.getDOMWindowUtils(this.domWindow);
winUtils.enterModalState();
winUtils.leaveModalState();
},
prompt(aParent, aDialogTitle, aText, aValue, aCheckMsg,
aCheckState)
{ var prompt = new MockPrompt(aParent);
return prompt.prompt(aDialogTitle, aText, aValue, aCheckMsg, aCheckState);
},
};
mockPromptServiceRegisterer =
new MockObjectRegisterer("@mozilla.org/prompter;1",
MockPromptService);
mockPromptServiceRegisterer.register();
};
var expectedState;
function runtests()
{
SpecialPowers.pushPrefEnv({'set': [["dom.successive_dialog_time_limit", 3]]},
runtestsInner);
}
async function runtestsInner()
{
registerMockPromptService();
// Test that alert() works normally and then gets blocked on the
// second call.
w = window.open();
w.alert("alert message 1");
is (promptState.method, "alert", "Wrong prompt method called");
is (promptState.parent, w, "Wrong alert parent");
is (promptState.msg, "alert message 1", "Wrong alert message");
promptState = void(0);
w.alert("alert message 2");
is (promptState.method, "alertCheck", "Wrong prompt method called");
is (promptState.parent, w, "Wrong alert parent");
is (promptState.msg, "alert message 2", "Wrong alert message");
promptState = void(0);
is (promptState, void(0), "Wrong prompt state after blocked alert()");
w.close();
// Then check that alert() gets blocked with a new window, because
// dialogs are disabled/enabled on basis of browsing context groups.
w = window.open();
is (promptState, void(0), "Wrong prompt state after blocked alert()");
// Reset the state and enable the dialogs again.
SpecialPowers.DOMWindowUtils.enableDialogs();
SpecialPowers.DOMWindowUtils.resetDialogAbuseState();
// Test that confirm() works normally and then gets blocked on the
// second call.
w.confirm("confirm message 1");
is (promptState.method, "confirm", "Wrong prompt method called");
is (promptState.parent, w, "Wrong confirm parent");
is (promptState.msg, "confirm message 1", "Wrong confirm message");
promptState = void(0);
w.confirm("confirm message 2");
is (promptState.method, "confirmCheck", "Wrong prompt method called");
is (promptState.parent, w, "Wrong confirm parent");
is (promptState.msg, "confirm message 2", "Wrong confirm message");
promptState = void(0);
is (promptState, void(0), "Wrong prompt state after blocked confirm()");
w.close();
// Then check that confirm() gets blocked with a new window, because
// dialogs are disabled/enabled on basis of browsing context groups.
w = window.open();
is (promptState, void(0), "Wrong prompt state after blocked prompt()");
// Reset the state and enable the dialogs again.
SpecialPowers.DOMWindowUtils.enableDialogs();
SpecialPowers.DOMWindowUtils.resetDialogAbuseState();
// Test that prompt() works normally and then gets blocked on the
// second call.
w.prompt("prompt message 1");
is (promptState.method, "prompt", "Wrong prompt method called");
is (promptState.parent, w, "Wrong prompt parent");
is (promptState.msg, "prompt message 1", "Wrong prompt message");
is (promptState.checkMsg, null, "Wrong dialog value");
promptState = void(0);
w.prompt("prompt message 2");
is (promptState.method, "prompt", "Wrong prompt method called");
is (promptState.parent, w, "Wrong prompt parent");
is (promptState.msg, "prompt message 2", "Wrong prompt message");
is (promptState.checkMsg, "Prevent this page from creating additional dialogs", "Wrong dialog value");
promptState = void(0);
is (promptState, void(0), "Wrong prompt state after blocked prompt()");
w.close();
// Then check that prompt() gets blocked with a new window, because
// dialogs are disabled/enabled on basis of browsing context groups.
w = window.open();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.