pjs/embedding/qa/jstests/nsIPromptTest.txt

157 строки
5.1 KiB
Plaintext

<HTML>
<HEAD>
<TITLE> Testing nsIPrompt Interface </TITLE>
<!--
Written by Dharma.
Tests last run on 04/30/01.
Tests last run on 05/08/01.
-->
<SCRIPT TYPE="text/javascript">
function getnsIPromptObj()
{
// get an implementation of nsIPrompt.
// (interface definition is embedding/browser/webBrowser)
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].
getService(Components.interfaces.nsIWindowWatcher);
// window is javascript window which is always available.
var prompter = ww.getNewPrompter(window); // nsIPrompt
}
catch(e) {
alert("Exception: " + e);
}
return prompter;
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT TYPE="text/javascript">
var promptObj = getnsIPromptObj();
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
// checking the alert() method.
/*
promptObj.alert("alert dialog", "text here");
*/
// checking the alertCheck method.
/*
var checkbox = {value:1};
promptObj.alertCheck("alertcheck dialog","text message",
"check or uncheck",checkbox);
alert(checkbox.value);
*/
// checking the confirm method
/*
var boo = promptObj.confirm("confirm dialog", " Do you want to continue");
//var boo = promptObj.confirm("confirm dialog","first", "second");
alert(boo);
*/
// checking the confirmCheck method.
/*
var checkbox = {value:0};
var boo = promptObj.confirmCheck("confirmcheck dialog",
"Do you want to continue",
"check or uncheck", checkbox);
alert("Checkbox checked: " + checkbox.value);
alert("Confirmation accepted: " + boo);
*/
// checking the confirmEx method.
var checkbox = {value:1};
// first variation.
/*
var std_buttons = (promptObj.BUTTON_TITLE_OK * promptObj.BUTTON_POS_0) +
(promptObj.BUTTON_TITLE_CANCEL * promptObj.BUTTON_POS_1) +
(promptObj.BUTTON_TITLE_SAVE * promptObj.BUTTON_POS_2);
*/
// second variation.
/*
var std_buttons = (promptObj.BUTTON_TITLE_IS_STRING * promptObj.BUTTON_POS_0) +
(promptObj.BUTTON_TITLE_IS_STRING * promptObj.BUTTON_POS_1) +
(promptObj.BUTTON_TITLE_IS_STRING * promptObj.BUTTON_POS_2);
var buttonPressed = promptObj.confirmEx("confirmEx dialog", "text message", std_buttons,
"Button0", "Button1", "Button2",
"check or uncheck", checkbox);
alert("Checkbox checked: " + checkbox.value);
alert("Button pressed: " + buttonPressed);
*/
// checking the prompt method.
/*
var val = {value:"default value"};
var checkbox = {value:1};
*/
/** notes
Passing var checkbox = {value:null}; is not null.
If you don't want the checkbox, you need to pass null, not a value
which contains null.
Since checkbox is an inout param,it can never be null when called from js.
Q.Make check message as null.(in this case "check or uncheck").Default title
should be shown.Its not showing default title and its not showing the checkbox also.
A.The comment in the API will have to change, not the code. The idea was, if
checkMsg == null && checkValue != null, to use a default title for the checkbox.
Since checkValue is an inout param, it isn't possible to pass null from JS as it
is from C++. So, the prompt implementation requires both the message and the
value to be non-null in order to show the checkbox.
**/
/*
var boo = promptObj.prompt("prompt dialog", "text message",
val, "check or uncheck", checkbox);
alert("Value: " + val.value);
alert("Checkbox checked: " + checkbox.value);
alert("Confirmation accepted: " + boo);
*/
// checking the promptPassword method.
/*
var password = {value:"dharma"};
var checkbox = {value:1};
var boo = promptObj.promptPassword("promptPassword dialog", "Enter the password",
password, "check or uncheck", checkbox);
alert("pass: " + password.value);
alert("checkbox checked: " + checkbox.value);
alert("confirmation accepted: " + boo);
*/
// checking the promptUsernameAndPassword method.
/*
var username = {value:"Dharma"};
var password = {value:"Gopal"};
var checkbox = {value:1};
var boo = promptObj.promptUsernameAndPassword("promptUsernameAndPassword dialog",
"Enter Username and Password", username, password,
"check or uncheck", checkbox);
alert("username: " + username.value);
alert("pass: " + password.value);
alert("checkbox checked: " + checkbox.value);
alert("confirmation accepted: " + boo);
*/
// Checking the select method.
selectList = new Array("first","second","third","fourth");
var outSelection = {value:0};
var boo = promptObj.select("select dialog", "Select one:",
4, selectList, outSelection);
alert("outSelection: " + outSelection.value);
alert("confirmation accepted: " + boo);
}
catch(e) {
alert("Exception: " + e);
}
alert("END");
</script>
</body>
</html>