gecko/toolkit/components/prompts/test/test_modal_prompts.html
2011-10-28 19:52:27 -07:00

1253 lines
42 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Modal Prompts Test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="prompt_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Prompter tests: modal prompts
<p id="display"></p>
<div id="content" style="display: none">
<iframe id="iframe"></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript;version=1.8">
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var isOSX = ("nsILocalFileMac" in Components.interfaces);
var isLinux = ("@mozilla.org/gnome-gconf-service;1" in Components.classes);
function pollDialog(okButton) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
if (okButton.disabled)
return;
ok(true, "dialog button is enabled now");
pollTimer.cancel();
pollTimer = null;
okButton.click();
didDialog = true;
}
function checkExpectedState(ui, state) {
// XXX check title? OS X has title in content
is(ui.infoBody.textContent, state.msg, "Checking expected message");
is(ui.loginContainer.hidden, state.textHidden, "Checking textbox visibility");
is(ui.password1Container.hidden, state.passHidden, "Checking passbox visibility");
is(ui.checkboxContainer.hidden, state.checkHidden, "Checking checkbox visibility");
is(ui.checkbox.label, state.checkMsg, "Checking checkbox label");
is(ui.checkbox.checked, state.checked, "Checking checkbox checked");
if (!isTabModal)
is(ui.infoIcon.className, "spaced " + state.iconClass, "Checking expected icon CSS class");
is(ui.loginTextbox.getAttribute("value"), state.textValue, "Checking textbox value");
is(ui.password1Textbox.getAttribute("value"), state.passValue, "Checking passbox value");
function isDefaultButton(b) {
return (b.hasAttribute("default") &&
b.getAttribute("default") == "true");
}
let shouldBeDefault;
shouldBeDefault = (state.defButton == ui.button0);
is(isDefaultButton(ui.button0), shouldBeDefault, "checking button0 default");
shouldBeDefault = (state.defButton == ui.button1);
is(isDefaultButton(ui.button1), shouldBeDefault, "checking button1 default");
shouldBeDefault = (state.defButton == ui.button2);
is(isDefaultButton(ui.button2), shouldBeDefault, "checking button2 default");
let fm = Cc["@mozilla.org/focus-manager;1"].
getService(Ci.nsIFocusManager);
let e = fm.focusedElement;
ok(true, "focused element is a " + (e ? e.localName : "<null>"));
if (isLinux && !e) {
todo(false, "Focus seems missing on Linux");
return;
}
if (isOSX && state.focused && state.focused.localName == "button")
ok(ui.infoBody == e, "buttons don't focus on OS X");
else if (state.focused)
ok(state.focused == e, "Checking focused element");
else
is(e, null, "Not expecting a focused element");
}
/*
* handleDialog
*
* Invoked a short period of time after calling startCallbackTimer(), and
* allows testing the actual prompt dialog while it's being displayed. Tests
* should call startCallbackTimer() each time the auth dialog is expected (the
* timer is a one-shot).
*/
function handleDialog(ui, testNum) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
ok(true, "--- handleDialog for test " + testNum +
" --- (isTabModal=" + isTabModal + ", usePromptService=" + usePromptService + ")");
let textField = ui.loginTextbox;
let passField = ui.password1Textbox;
let checkbox = ui.checkbox;
let clickOK = true;
let state;
switch(testNum) {
case 1:
// Alert
state = {
msg : "This is the alert text.",
title : "TestTitle",
iconClass : "alert-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
checkExpectedState(ui, state);
break;
case 2:
// AlertCheck (null checkbox label, so it's hidden)
state = {
msg : "This is the alertCheck text.",
title : "TestTitle",
iconClass : "alert-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
checkExpectedState(ui, state);
break;
case 3:
// AlertCheck
state = {
msg : "This is the alertCheck text.",
title : "TestTitle",
iconClass : "alert-icon",
textHidden : true,
passHidden : true,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
checkExpectedState(ui, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 4:
// Confirm (ok)
state = {
msg : "This is the confirm text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
checkExpectedState(ui, state);
break;
case 5:
// Confirm (cancel)
state = {
msg : "This is the confirm text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
checkExpectedState(ui, state);
clickOK = false;
break;
case 6:
// ConfirmCheck (no checkbox, ok)
state = {
msg : "This is the confirmCheck text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
checkExpectedState(ui, state);
break;
case 7:
// ConfirmCheck (no checkbox, cancel)
state = {
msg : "This is the confirmCheck text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
checkExpectedState(ui, state);
clickOK = false;
break;
case 8:
// ConfirmCheck (ok)
state = {
msg : "This is the confirmCheck text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
checkExpectedState(ui, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 9:
// ConfirmCheck (cancel)
state = {
msg : "This is the confirmCheck text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
checkExpectedState(ui, state);
clickOK = false;
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 10:
// Prompt (ok, no default text)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : false,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
checkExpectedState(ui, state);
textField.setAttribute("value", "bacon");
break;
case 11:
// Prompt (ok, default text)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : false,
passHidden : true,
checkHidden : true,
textValue : "kittens",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
checkExpectedState(ui, state);
break;
case 12:
// Prompt (cancel, default text)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : false,
passHidden : true,
checkHidden : true,
textValue : "puppies",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
checkExpectedState(ui, state);
clickOK = false;
break;
case 13:
// Prompt (cancel, default text modified)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : false,
passHidden : true,
checkHidden : true,
textValue : "puppies",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
checkExpectedState(ui, state);
textField.setAttribute("value", "bacon");
clickOK = false;
break;
case 14:
// Prompt (ok, with checkbox)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : false,
passHidden : true,
checkHidden : false,
textValue : "tribbles",
passValue : "",
checkMsg : "Check me out!",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
checkExpectedState(ui, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 15:
// Prompt (cancel, with checkbox)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : false,
passHidden : true,
checkHidden : false,
textValue : "tribbles",
passValue : "",
checkMsg : "Check me out!",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
checkExpectedState(ui, state);
clickOK = false;
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 16:
// PromptUsernameAndPassword (ok, with checkbox)
state = {
msg : "This is the pUAP text.",
title : "TestTitle",
iconClass : "authentication-icon question-icon",
textHidden : false,
passHidden : false,
checkHidden : false,
textValue : "usr",
passValue : "ssh",
checkMsg : "Check me out!",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
checkExpectedState(ui, state);
textField.setAttribute("value", "newusr");
passField.setAttribute("value", "newssh");
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 17:
// PromptUsernameAndPassword (cancel, with checkbox)
state = {
msg : "This is the pUAP text.",
title : "TestTitle",
iconClass : "authentication-icon question-icon",
textHidden : false,
passHidden : false,
checkHidden : false,
textValue : "usr",
passValue : "ssh",
checkMsg : "Check me out!",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
checkExpectedState(ui, state);
textField.setAttribute("value", "newusr");
passField.setAttribute("value", "newssh");
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
clickOK = false;
break;
case 18:
// PromptPassword (ok, with checkbox)
state = {
msg : "This is the promptPassword text.",
title : "TestTitle",
iconClass : "authentication-icon question-icon",
textHidden : true,
passHidden : false,
checkHidden : false,
textValue : "",
passValue : "ssh",
checkMsg : "Check me out!",
checked : false,
focused : ui.password1Textbox.inputField,
defButton : ui.button0,
};
checkExpectedState(ui, state);
passField.setAttribute("value", "newssh");
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 19:
// PromptPassword (cancel, with checkbox)
state = {
msg : "This is the promptPassword text.",
title : "TestTitle",
iconClass : "authentication-icon question-icon",
textHidden : true,
passHidden : false,
checkHidden : false,
textValue : "",
passValue : "ssh",
checkMsg : "Check me out!",
checked : false,
focused : ui.password1Textbox.inputField,
defButton : ui.button0,
};
checkExpectedState(ui, state);
passField.setAttribute("value", "newssh");
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
clickOK = false;
break;
case 20:
// ConfirmEx (ok/cancel, ok)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
is(ui.button0.label, "OK", "Checking accept-button label");
is(ui.button1.label, "Cancel", "Checking cancel-button label");
checkExpectedState(ui, state);
break;
case 21:
// ConfirmEx (yes/no, cancel)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
is(ui.button0.label, "Yes", "Checking accept-button label");
is(ui.button1.label, "No", "Checking cancel-button label");
checkExpectedState(ui, state);
clickOK = false;
break;
case 22:
// ConfirmEx (buttons from args, checkbox, ok)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
is(ui.button0.label, "butt0", "Checking accept-button label");
is(ui.button1.label, "butt1", "Checking cancel-button label");
is(ui.button2.label, "butt2", "Checking extra1-button label");
checkExpectedState(ui, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 23:
// ConfirmEx (buttons from args, checkbox, cancel)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
focused : ui.button1, // Default changed!
defButton : ui.button1,
};
// XXX check button1 is default
is(ui.button0.label, "butt0", "Checking accept-button label");
is(ui.button1.label, "butt1", "Checking cancel-button label");
is(ui.button2.label, "butt2", "Checking extra1-button label");
checkExpectedState(ui, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
clickOK = false;
break;
case 24:
// ConfirmEx (buttons from args, checkbox, button3)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
focused : ui.button2, // Default changed!
defButton : ui.button2,
};
// XXX check button2 is default
is(ui.button0.label, "butt0", "Checking accept-button label");
is(ui.button1.label, "butt1", "Checking cancel-button label");
is(ui.button2.label, "butt2", "Checking extra1-button label");
checkExpectedState(ui, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
// XXX how to click button 3?
clickOK = false;
break;
case 25:
// Alert, null window
state = {
msg : "This is the alert text.",
title : "TestTitle",
iconClass : "alert-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
checkExpectedState(ui, state);
break;
case 26:
// ConfirmEx (with delay, ok)
state = {
msg : "This is the confirmEx delay text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : null, // nothing focused until after delay fires
defButton : ui.button0,
};
// OS X doesn't initially focus the button, but rather the infoBody.
// The focus stays there even after the button-enable delay has fired.
if (isOSX)
state.focused = ui.infoBody;
is(ui.button0.label, "OK", "Checking accept-button label");
is(ui.button1.label, "Cancel", "Checking cancel-button label");
is(ui.button0.disabled, true, "Checking accept-button is disabled");
is(ui.button1.disabled, false, "Checking cancel-button isn't disabled ");
checkExpectedState(ui, state);
break;
case 100:
// PromptAuth (no realm, ok, with checkbox)
state = {
msg : 'Enter username and password for http://example.com',
title : "TestTitle",
iconClass : "authentication-icon question-icon",
textHidden : false,
passHidden : false,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
checkExpectedState(ui, state);
textField.setAttribute("value", "username");
passField.setAttribute("value", "password");
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 101:
// PromptAuth (long realm, ok, with checkbox)
state = {
msg : 'A username and password are being requested by http://example.com. The site ' +
'says: "abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi ' +
'abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi ' +
'abcdefghi \u2026"',
title : "TestTitle",
iconClass : "authentication-icon question-icon",
textHidden : false,
passHidden : false,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
checkExpectedState(ui, state);
textField.setAttribute("value", "username");
passField.setAttribute("value", "password");
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
default:
ok(false, "Uhh, unhandled switch for testNum #" + testNum);
break;
}
if (testNum == 24) {
ui.button2.click();
} else if (testNum == 26) {
// Buttons are disabled at the moment, poll until they're reenabled.
// Can't use setInterval here, because the window's in a modal state
// and thus DOM events are suppressed.
pollTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
pollTimer.initWithCallback(function() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
pollDialog(ui.button0);
},
100, Ci.nsITimer.TYPE_REPEATING_SLACK);
return;
} else {
if (clickOK)
ui.button0.click();
else
ui.button1.click();
}
ok(true, "handleDialog done");
didDialog = true;
}
function runTests() {
let ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
ok(true, "Running tests (isTabModal=" + isTabModal + ", usePromptService=" + usePromptService + ")");
let prompter, promptArgs;
if (usePromptService) {
prompter = Cc["@mozilla.org/embedcomp/prompt-service;1"].
getService(Ci.nsIPromptService2);
} else {
prompter = Cc["@mozilla.org/prompter;1"].
getService(Ci.nsIPromptFactory).
getPrompt(window, Ci.nsIPrompt);
if (isTabModal) {
let bag = prompter.QueryInterface(Ci.nsIWritablePropertyBag2);
bag.setPropertyAsBool("allowTabModal", true);
}
}
let checkVal = {};
let textVal = {};
let passVal = {};
let flags;
let isOK, clickedButton;
testNum = 0;
// ===== test 1 =====
// Alert
testNum++;
startCallbackTimer();
promptArgs = ["TestTitle", "This is the alert text."];
if (usePromptService)
promptArgs.unshift(window);
prompter.alert.apply(null, promptArgs);
ok(didDialog, "handleDialog was invoked");
// ===== test 2 =====
// AlertCheck (null checkbox label)
testNum++;
startCallbackTimer();
promptArgs = ["TestTitle", "This is the alertCheck text.", null, {}];
if (usePromptService)
promptArgs.unshift(window);
prompter.alertCheck.apply(null, promptArgs);
ok(didDialog, "handleDialog was invoked");
// ===== test 3 =====
// AlertCheck
testNum++;
startCallbackTimer();
checkVal.value = false;
promptArgs = ["TestTitle", "This is the alertCheck text.", "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
prompter.alertCheck.apply(null, promptArgs);
ok(didDialog, "handleDialog was invoked");
is(checkVal.value, true, "checkbox was checked");
// ===== test 4 =====
// Confirm (ok)
testNum++;
startCallbackTimer();
promptArgs = ["TestTitle", "This is the confirm text."];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.confirm.apply(null, promptArgs);
is(isOK, true, "checked expected retval");
ok(didDialog, "handleDialog was invoked");
// ===== test 5 =====
// Confirm (cancel)
testNum++;
startCallbackTimer();
promptArgs = ["TestTitle", "This is the confirm text."];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.confirm.apply(null, promptArgs);
is(isOK, false, "checked expected retval");
ok(didDialog, "handleDialog was invoked");
// ===== test 6 =====
// ConfirmCheck (ok, null checkbox label)
testNum++;
startCallbackTimer();
promptArgs = ["TestTitle", "This is the confirmCheck text.", null, {}];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.confirmCheck.apply(null, promptArgs);
is(isOK, true, "checked expected retval");
ok(didDialog, "handleDialog was invoked");
// ===== test 7 =====
// ConfirmCheck (cancel, null checkbox label)
testNum++;
startCallbackTimer();
promptArgs = ["TestTitle", "This is the confirmCheck text.", null, {}];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.confirmCheck.apply(null, promptArgs);
is(isOK, false, "checked expected retval");
ok(didDialog, "handleDialog was invoked");
// ===== test 8 =====
// ConfirmCheck (ok)
testNum++;
startCallbackTimer();
checkVal.value = false;
promptArgs = ["TestTitle", "This is the confirmCheck text.", "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.confirmCheck.apply(null, promptArgs);
is(isOK, true, "checked expected retval");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 9 =====
// ConfirmCheck (cancel)
testNum++;
startCallbackTimer();
checkVal.value = false;
promptArgs = ["TestTitle", "This is the confirmCheck text.", "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.confirmCheck.apply(null, promptArgs);
is(isOK, false, "checked expected retval");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 10 =====
// Prompt (ok, no default text)
testNum++;
startCallbackTimer();
textVal.value = "";
promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.prompt.apply(null, promptArgs);
is(isOK, true, "checked expected retval");
is(textVal.value, "bacon", "checking expected text value");
ok(didDialog, "handleDialog was invoked");
// ===== test 11 =====
// Prompt (ok, default text)
testNum++;
startCallbackTimer();
textVal.value = "kittens";
promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.prompt.apply(null, promptArgs);
is(isOK, true, "checked expected retval");
is(textVal.value, "kittens", "checking expected text value");
ok(didDialog, "handleDialog was invoked");
// ===== test 12 =====
// Prompt (cancel, default text)
testNum++;
startCallbackTimer();
textVal.value = "puppies";
promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.prompt.apply(null, promptArgs);
is(isOK, false, "checked expected retval");
is(textVal.value, "puppies", "checking expected text value");
ok(didDialog, "handleDialog was invoked");
// ===== test 13 =====
// Prompt (cancel, default text modified)
testNum++;
startCallbackTimer();
textVal.value = "puppies";
promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.prompt.apply(null, promptArgs);
is(isOK, false, "checked expected retval");
is(textVal.value, "puppies", "checking expected text value");
ok(didDialog, "handleDialog was invoked");
// ===== test 14 =====
// Prompt (ok, with checkbox)
testNum++;
startCallbackTimer();
textVal.value = "tribbles";
checkVal.value = false;
promptArgs = ["TestTitle", "This is the prompt text.", textVal, "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.prompt.apply(null, promptArgs);
is(isOK, true, "checked expected retval");
is(textVal.value, "tribbles", "checking expected text value");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 15 =====
// Prompt (cancel, with checkbox)
testNum++;
startCallbackTimer();
textVal.value = "tribbles";
checkVal.value = false;
promptArgs = ["TestTitle", "This is the prompt text.", textVal, "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.prompt.apply(null, promptArgs);
is(isOK, false, "checked expected retval");
is(textVal.value, "tribbles", "checking expected text value");
is(checkVal.value, false, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 16 =====
// PromptUsernameAndPassword (ok)
// Just two tests for this, since password manager already tests this extensively.
testNum++;
startCallbackTimer();
textVal.value = "usr";
passVal.value = "ssh";
checkVal.value = false;
promptArgs = ["TestTitle", "This is the pUAP text.", textVal, passVal, "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.promptUsernameAndPassword.apply(null, promptArgs);
is(isOK, true, "checked expected retval");
is(textVal.value, "newusr", "checking expected text value");
is(passVal.value, "newssh", "checking expected pass value");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 17 =====
// PromptUsernameAndPassword (cancel)
testNum++;
startCallbackTimer();
textVal.value = "usr";
passVal.value = "ssh";
checkVal.value = false;
promptArgs = ["TestTitle", "This is the pUAP text.", textVal, passVal, "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.promptUsernameAndPassword.apply(null, promptArgs);
is(isOK, false, "checked expected retval");
is(textVal.value, "usr", "checking expected text value");
is(passVal.value, "ssh", "checking expected pass value");
is(checkVal.value, false, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 18 =====
// PromptPassword (ok)
testNum++;
startCallbackTimer();
passVal.value = "ssh";
checkVal.value = false;
promptArgs = ["TestTitle", "This is the promptPassword text.", passVal, "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.promptPassword.apply(null, promptArgs);
is(isOK, true, "checked expected retval");
is(passVal.value, "newssh", "checking expected pass value");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 19 =====
// PromptPassword (cancel)
testNum++;
startCallbackTimer();
passVal.value = "ssh";
checkVal.value = false;
promptArgs = ["TestTitle", "This is the promptPassword text.", passVal, "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.promptPassword.apply(null, promptArgs);
is(isOK, false, "checked expected retval");
is(passVal.value, "ssh", "checking expected pass value");
is(checkVal.value, false, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 20 =====
// ConfirmEx (ok/cancel, ok)
testNum++;
startCallbackTimer();
flags = Ci.nsIPromptService.STD_OK_CANCEL_BUTTONS;
promptArgs = ["TestTitle", "This is the confirmEx text.", flags, null, null, null, null, {}];
if (usePromptService)
promptArgs.unshift(window);
clickedButton = prompter.confirmEx.apply(null, promptArgs);
is(clickedButton, 0, "checked expected button num click");
ok(didDialog, "handleDialog was invoked");
// ===== test 21 =====
// ConfirmEx (yes/no, cancel)
testNum++;
startCallbackTimer();
flags = Ci.nsIPromptService.STD_YES_NO_BUTTONS;
promptArgs = ["TestTitle", "This is the confirmEx text.", flags, null, null, null, null, {}];
if (usePromptService)
promptArgs.unshift(window);
clickedButton = prompter.confirmEx.apply(null, promptArgs);
is(clickedButton, 1, "checked expected button num click");
ok(didDialog, "handleDialog was invoked");
// ===== test 22 =====
// ConfirmEx (buttons from args, checkbox, ok)
testNum++;
startCallbackTimer();
let b = Ci.nsIPromptService.BUTTON_TITLE_IS_STRING;
flags = b * Ci.nsIPromptService.BUTTON_POS_2 +
b * Ci.nsIPromptService.BUTTON_POS_1 +
b * Ci.nsIPromptService.BUTTON_POS_0;
checkVal.value = false;
promptArgs = ["TestTitle", "This is the confirmEx text.", flags,
"butt0", "butt1", "butt2", "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
clickedButton = prompter.confirmEx.apply(null, promptArgs);
is(clickedButton, 0, "checked expected button num click");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 23 =====
// ConfirmEx (buttons from args, checkbox, cancel)
testNum++;
startCallbackTimer();
let b = Ci.nsIPromptService.BUTTON_TITLE_IS_STRING;
flags = b * Ci.nsIPromptService.BUTTON_POS_2 +
b * Ci.nsIPromptService.BUTTON_POS_1 +
b * Ci.nsIPromptService.BUTTON_POS_0;
flags ^= Ci.nsIPromptService.BUTTON_POS_1_DEFAULT;
checkVal.value = false;
promptArgs = ["TestTitle", "This is the confirmEx text.", flags,
"butt0", "butt1", "butt2", "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
clickedButton = prompter.confirmEx.apply(null, promptArgs);
is(clickedButton, 1, "checked expected button num click");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 24 =====
// ConfirmEx (buttons from args, checkbox, button3)
testNum++;
startCallbackTimer();
let b = Ci.nsIPromptService.BUTTON_TITLE_IS_STRING;
flags = b * Ci.nsIPromptService.BUTTON_POS_2 +
b * Ci.nsIPromptService.BUTTON_POS_1 +
b * Ci.nsIPromptService.BUTTON_POS_0;
flags ^= Ci.nsIPromptService.BUTTON_POS_2_DEFAULT;
checkVal.value = false;
promptArgs = ["TestTitle", "This is the confirmEx text.", flags,
"butt0", "butt1", "butt2", "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
clickedButton = prompter.confirmEx.apply(null, promptArgs);
is(clickedButton, 2, "checked expected button num click");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 25 =====
// Alert, no window
// (skipped for tabmodal tests: window is required)
testNum++;
if (!isTabModal) {
startCallbackTimer();
promptArgs = ["TestTitle", "This is the alert text."];
if (usePromptService)
promptArgs.unshift(null);
prompter.alert.apply(null, promptArgs);
ok(didDialog, "handleDialog was invoked");
}
// ===== test 26 =====
// ConfirmEx (delay, ok)
// (skipped for tabmodal tests: delay not supported)
testNum++;
if (!isTabModal) {
startCallbackTimer();
flags = (Ci.nsIPromptService.STD_OK_CANCEL_BUTTONS | Ci.nsIPromptService.BUTTON_DELAY_ENABLE);
promptArgs = ["TestTitle", "This is the confirmEx delay text.", flags, null, null, null, null, {}];
if (usePromptService)
promptArgs.unshift(window);
clickedButton = prompter.confirmEx.apply(null, promptArgs);
is(clickedButton, 0, "checked expected button num click");
ok(didDialog, "handleDialog was invoked");
}
// promptAuth already tested via password manager but do a few specific things here.
var channel = ioService.newChannel("http://example.com", null, null);
var level = Ci.nsIAuthPrompt2.LEVEL_NONE;
var authinfo = {
username : "",
password : "",
domain : "",
flags : Ci.nsIAuthInformation.AUTH_HOST,
authenticationScheme : "basic",
realm : ""
};
// ===== test 100 =====
// promptAuth with empty realm
// (promptAuth is only accessible from the prompt service)
testNum = 100;
if (usePromptService) {
startCallbackTimer();
checkVal.value = false;
promptArgs = [channel, level, authinfo, "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.promptAuth.apply(null, promptArgs);
is(isOK, true, "checked expected retval");
is(authinfo.username, "username", "checking filled username");
is(authinfo.password, "password", "checking filled password");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
}
// ===== test 101 =====
// promptAuth with long realm
// (promptAuth is only accessible from the prompt service)
testNum++;
if (usePromptService) {
startCallbackTimer();
checkVal.value = false;
var longString = "";
for (var i = 0; i < 20; i++)
longString += "abcdefghi "; // 200 chars long
authinfo.realm = longString;
authinfo.username = "";
authinfo.password = "";
promptArgs = [channel, level, authinfo, "Check me out!", checkVal];
if (usePromptService)
promptArgs.unshift(window);
isOK = prompter.promptAuth.apply(null, promptArgs);
is(isOK, true, "checked expected retval");
is(authinfo.username, "username", "checking filled username");
is(authinfo.password, "password", "checking filled password");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
}
}
let testNum;
let pollTimer;
/*
* Run the body of the 3 times:
* - 1st pass: with window-modal prompts, using nsIPromptService
* - 2nd pass: still window-modal, using nsIPrompt directly (via nsIPromptFactory)
* - 3rd pass: with tab-modal prompts. Can't opt into these via * nsIPromptService.
*/
isTabModal = false; usePromptService = true;
runTests();
isTabModal = false; usePromptService = false;
runTests();
if (getTabModalPromptBox(window)) {
isTabModal = true; usePromptService = false;
runTests();
}
</script>
</pre>
</body>
</html>