2010-09-16 18:24:14 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=61098
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 61098</title>
|
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="text/javascript" src="/mozprefs.js"></script>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/mockObjects.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body onload="runtests();">
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=61098">Mozilla Bug 61098</a>
|
|
|
|
<p id="display">
|
|
|
|
</p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
</pre>
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
/** Test for Bug 61098 **/
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2010-11-17 22:44:50 -08:00
|
|
|
var mockPromptServiceRegisterer, mockPromptFactoryRegisterer;
|
2010-09-16 18:24:14 -07:00
|
|
|
|
|
|
|
var promptState;
|
|
|
|
|
|
|
|
function registerMockPromptService()
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
2010-11-17 22:44:50 -08:00
|
|
|
function MockPrompt(aDOMWindow) {
|
|
|
|
this.domWindow = aDOMWindow;
|
2010-09-16 18:24:14 -07:00
|
|
|
}
|
|
|
|
|
2010-11-17 22:44:50 -08:00
|
|
|
MockPrompt.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPrompt]),
|
2010-09-16 18:24:14 -07:00
|
|
|
|
2010-11-17 22:44:50 -08:00
|
|
|
domWindow : null,
|
|
|
|
|
|
|
|
_toggleModalState: function()
|
2010-09-16 18:24:14 -07:00
|
|
|
{
|
2010-11-17 22:44:50 -08:00
|
|
|
// 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 = this.domWindow
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
2011-03-25 08:03:33 -07:00
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
2011-02-01 19:23:00 -08:00
|
|
|
var w = winUtils.enterModalStateWithWindow();
|
|
|
|
winUtils.leaveModalStateWithWindow(w);
|
2010-11-17 22:44:50 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
alert: function(aDialogTitle, aText)
|
|
|
|
{
|
|
|
|
this._toggleModalState();
|
2010-09-16 18:24:14 -07:00
|
|
|
promptState = {method: "alert",
|
2010-11-17 22:44:50 -08:00
|
|
|
parent: this.domWindow,
|
2010-09-16 18:24:14 -07:00
|
|
|
title: aDialogTitle,
|
|
|
|
msg: aText
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2010-11-17 22:44:50 -08:00
|
|
|
alertCheck: function(aDialogTitle, aText, aCheckMsg, aCheckState)
|
2010-09-16 18:24:14 -07:00
|
|
|
{
|
2010-11-17 22:44:50 -08:00
|
|
|
this._toggleModalState();
|
2010-09-16 18:24:14 -07:00
|
|
|
promptState = {method: "alertCheck",
|
2010-11-17 22:44:50 -08:00
|
|
|
parent: this.domWindow,
|
2010-09-16 18:24:14 -07:00
|
|
|
title: aDialogTitle,
|
|
|
|
msg: aText,
|
|
|
|
checkMsg: aCheckMsg,
|
|
|
|
checkState: aCheckState
|
|
|
|
};
|
|
|
|
|
|
|
|
aCheckState.value = true;
|
|
|
|
},
|
|
|
|
|
2010-11-17 22:44:50 -08:00
|
|
|
confirm: function(aDialogTitle, aText)
|
2010-09-16 18:24:14 -07:00
|
|
|
{
|
2010-11-17 22:44:50 -08:00
|
|
|
this._toggleModalState();
|
2010-09-16 18:24:14 -07:00
|
|
|
promptState = {method: "confirm",
|
2010-11-17 22:44:50 -08:00
|
|
|
parent: this.domWindow,
|
2010-09-16 18:24:14 -07:00
|
|
|
title: aDialogTitle,
|
|
|
|
msg: aText
|
|
|
|
};
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2010-11-17 22:44:50 -08:00
|
|
|
confirmCheck: function(aDialogTitle, aText, aCheckMsg, aCheckState)
|
2010-09-16 18:24:14 -07:00
|
|
|
{
|
2010-11-17 22:44:50 -08:00
|
|
|
this._toggleModalState();
|
2010-09-16 18:24:14 -07:00
|
|
|
promptState = {method: "confirmCheck",
|
2010-11-17 22:44:50 -08:00
|
|
|
parent: this.domWindow,
|
2010-09-16 18:24:14 -07:00
|
|
|
title: aDialogTitle,
|
|
|
|
msg: aText,
|
|
|
|
checkMsg: aCheckMsg,
|
|
|
|
checkState: aCheckState
|
|
|
|
};
|
|
|
|
|
|
|
|
aCheckState.value = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2010-11-17 22:44:50 -08:00
|
|
|
confirmEx: function(aDialogTitle, aText, aButtonFlags,
|
2010-09-16 18:24:14 -07:00
|
|
|
aButton0Title, aButton1Title, aButton2Title,
|
|
|
|
aCheckMsg, aCheckState)
|
|
|
|
{
|
2010-11-17 22:44:50 -08:00
|
|
|
this._toggleModalState();
|
2010-09-16 18:24:14 -07:00
|
|
|
promptState = {method: "confirmCheck",
|
2010-11-17 22:44:50 -08:00
|
|
|
parent: this.domWindow,
|
2010-09-16 18:24:14 -07:00
|
|
|
title: aDialogTitle,
|
|
|
|
msg: aText,
|
|
|
|
checkMsg: aCheckMsg,
|
|
|
|
checkState: aCheckState
|
|
|
|
};
|
|
|
|
|
|
|
|
if (aCheckMsg != null)
|
|
|
|
aCheckState.value = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
|
2010-11-17 22:44:50 -08:00
|
|
|
prompt: function(aDialogTitle, aText, aValue, aCheckMsg,
|
2010-09-16 18:24:14 -07:00
|
|
|
aCheckState)
|
|
|
|
{
|
2010-11-17 22:44:50 -08:00
|
|
|
this._toggleModalState();
|
2010-09-16 18:24:14 -07:00
|
|
|
promptState = {method: "prompt",
|
2010-11-17 22:44:50 -08:00
|
|
|
parent: this.domWindow,
|
2010-09-16 18:24:14 -07:00
|
|
|
title: aDialogTitle,
|
|
|
|
msg: aText,
|
|
|
|
checkMsg: aCheckMsg,
|
|
|
|
checkState: aCheckState
|
|
|
|
};
|
|
|
|
|
|
|
|
if (aCheckMsg != null)
|
|
|
|
aCheckState.value = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2010-11-17 22:44:50 -08:00
|
|
|
|
|
|
|
// Override the prompt service with our own so that we can test
|
|
|
|
// modal dialogs
|
|
|
|
|
|
|
|
function MockPromptService()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MockPromptService.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPromptFactory, Ci.nsIPromptService]),
|
|
|
|
|
|
|
|
getPrompt: function(aDOMWindow, aIID)
|
|
|
|
{
|
|
|
|
return new MockPrompt(aDOMWindow);
|
|
|
|
},
|
|
|
|
|
|
|
|
alert: function(aParent, aDialogTitle, aText)
|
|
|
|
{
|
|
|
|
var prompt = new MockPrompt(aParent);
|
|
|
|
return prompt.alert(aDialogTitle, aText);
|
|
|
|
},
|
|
|
|
|
|
|
|
alertCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState)
|
|
|
|
{
|
|
|
|
var prompt = new MockPrompt(aParent);
|
|
|
|
return prompt.alertCheck(aDialogTitle, aText, aCheckMsg, aCheckState);
|
|
|
|
},
|
|
|
|
|
|
|
|
confirm: function(aParent, aDialogTitle, aText)
|
|
|
|
{
|
|
|
|
var prompt = new MockPrompt(aParent);
|
|
|
|
return prompt.confirm(aDialogTitle, aText);
|
|
|
|
},
|
|
|
|
|
|
|
|
confirmCheck: function(aParent, aDialogTitle, aText, aCheckMsg,
|
|
|
|
aCheckState)
|
|
|
|
{
|
|
|
|
var prompt = new MockPrompt(aParent);
|
|
|
|
return prompt.confirmCheck(aDialogTitle, aText, aCheckMsg, aCheckState);
|
|
|
|
},
|
|
|
|
|
|
|
|
confirmEx: function(aParent, aDialogTitle, aText, aButtonFlags,
|
|
|
|
aButton0Title, aButton1Title, aButton2Title,
|
|
|
|
aCheckMsg, aCheckState)
|
|
|
|
{
|
|
|
|
var prompt = new MockPrompt(aParent);
|
|
|
|
return prompt.confirmEx(aDialogTitle, aText, aButtonFlags,
|
|
|
|
aButton0Title, aButton1Title, aButton2Title,
|
|
|
|
aCheckMsg, aCheckState);
|
|
|
|
},
|
|
|
|
|
|
|
|
prompt: function(aParent, aDialogTitle, aText, aValue, aCheckMsg,
|
|
|
|
aCheckState)
|
|
|
|
{
|
|
|
|
var prompt = new MockPrompt(aParent);
|
|
|
|
return prompt.prompt(aDialogTitle, aText, aValue, aCheckMsg, aCheckState);
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2010-09-16 18:24:14 -07:00
|
|
|
mockPromptServiceRegisterer =
|
|
|
|
new MockObjectRegisterer("@mozilla.org/embedcomp/prompt-service;1",
|
|
|
|
MockPromptService);
|
2010-11-17 22:44:50 -08:00
|
|
|
mockPromptFactoryRegisterer =
|
|
|
|
new MockObjectRegisterer("@mozilla.org/prompter;1",
|
|
|
|
MockPromptService);
|
2010-09-16 18:24:14 -07:00
|
|
|
|
|
|
|
mockPromptServiceRegisterer.register();
|
2010-11-17 22:44:50 -08:00
|
|
|
mockPromptFactoryRegisterer.register();
|
2010-09-16 18:24:14 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
function enableDialogLoopBlocking()
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
|
|
|
|
prefs.setIntPref("dom.successive_dialog_time_limit", 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetDialogLoopBlocking()
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
|
|
|
|
prefs.setIntPref("dom.successive_dialog_time_limit", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
var expectedState;
|
|
|
|
|
|
|
|
function runtests()
|
|
|
|
{
|
|
|
|
registerMockPromptService();
|
|
|
|
enableDialogLoopBlocking();
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
try {
|
|
|
|
w.alert("alert message 3");
|
|
|
|
} catch(e) {
|
|
|
|
is(e.name, "NS_ERROR_NOT_AVAILABLE", "Wrong exception");
|
|
|
|
}
|
|
|
|
|
|
|
|
is (promptState, void(0), "Wrong prompt state after blocked alert()");
|
|
|
|
|
|
|
|
w.close();
|
|
|
|
|
|
|
|
// Test that confirm() works normally and then gets blocked on the
|
|
|
|
// second call.
|
|
|
|
w = window.open();
|
|
|
|
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);
|
|
|
|
|
|
|
|
try {
|
|
|
|
w.confirm("confirm message 3");
|
|
|
|
} catch(e) {
|
|
|
|
is(e.name, "NS_ERROR_NOT_AVAILABLE", "Wrong exception");
|
|
|
|
}
|
|
|
|
|
|
|
|
is (promptState, void(0), "Wrong prompt state after blocked confirm()");
|
|
|
|
|
|
|
|
w.close();
|
|
|
|
|
|
|
|
// Test that prompt() works normally and then gets blocked on the
|
|
|
|
// second call.
|
|
|
|
w = window.open();
|
|
|
|
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);
|
|
|
|
|
|
|
|
try {
|
|
|
|
w.prompt("prompt message 3");
|
|
|
|
} catch(e) {
|
|
|
|
is(e.name, "NS_ERROR_NOT_AVAILABLE", "Wrong exception");
|
|
|
|
}
|
|
|
|
|
|
|
|
is (promptState, void(0), "Wrong prompt state after blocked prompt()");
|
|
|
|
|
|
|
|
w.close();
|
|
|
|
|
|
|
|
// Test that showModalDialog() works normally and then gets blocked
|
|
|
|
// on the second call.
|
|
|
|
w = window.open();
|
|
|
|
w.showModalDialog("data:text/html,%3Cscript>window.close();%3C/script>")
|
|
|
|
is (promptState, void(0), "Wrong prompt state");
|
|
|
|
|
|
|
|
// Test that showModalDialog() works normally and then gets blocked
|
|
|
|
// on the second call.
|
|
|
|
try {
|
|
|
|
w.showModalDialog("data:text/html,%3Cscript>window.close();%3C/script>")
|
|
|
|
} catch(e) {
|
|
|
|
is(e.name, "NS_ERROR_NOT_AVAILABLE", "Wrong exception");
|
|
|
|
}
|
|
|
|
is (promptState.method, "confirm", "Wrong prompt method called");
|
|
|
|
is (promptState.parent, w, "Wrong confirm parent");
|
|
|
|
is (promptState.msg, "Prevent this page from creating additional dialogs",
|
|
|
|
"Wrong confirm message");
|
|
|
|
promptState = void(0);
|
|
|
|
|
|
|
|
w.close();
|
|
|
|
|
|
|
|
resetDialogLoopBlocking();
|
2010-11-17 22:44:50 -08:00
|
|
|
|
|
|
|
mockPromptFactoryRegisterer.unregister();
|
2010-09-16 18:24:14 -07:00
|
|
|
mockPromptServiceRegisterer.unregister();
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|