gecko/toolkit/components/prompts/test/test_modal_prompts.html

1153 lines
38 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Modal Prompts Test</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="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');
let prompter = Cc["@mozilla.org/embedcomp/prompt-service;1"].
getService(Ci.nsIPromptService2);
let ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
let pollTimer;
function pollDialog(dialog) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
if (dialog.getButton("accept").disabled)
return;
ok(true, "dialog button is enabled now");
pollTimer.cancel();
pollTimer = null;
dialog.acceptDialog();
didDialog = true;
}
function checkExpectedState(doc, state) {
let msg = doc.getElementById("info.body").textContent;
let icon = doc.getElementById("info.icon");
let textOuter = doc.getElementById("loginContainer");
let passOuter = doc.getElementById("password1Container");
let checkOuter = doc.getElementById("checkboxContainer");
let textField = doc.getElementById("loginTextbox");
let passField = doc.getElementById("password1Textbox");
let checkbox = doc.getElementById("checkbox");
let textValue = textField.getAttribute("value");
let passValue = passField.getAttribute("value");
is(msg, state.msg, "Checking expected message");
// XXX check title? OS X has title in content
is(icon.className, "spaced " + state.iconClass, "Checking expected icon CSS class");
is(textOuter.hidden, state.textHidden, "Checking textbox visibility");
is(passOuter.hidden, state.passHidden, "Checking passbox visibility");
is(checkOuter.hidden, state.checkHidden, "Checking checkbox visibility");
is(textValue, state.textValue, "Checking textbox value");
is(passValue, state.passValue, "Checking passbox value");
is(checkbox.label, state.checkMsg, "Checking checkbox label");
is(checkbox.checked, state.checked, "Checking checkbox checked");
}
function checkExpectedSelectState(doc, state) {
let msg = doc.getElementById("info.txt").value;
// XXX check title? OS X has title in content
let listbox = doc.getElementById("list");
is(msg, state.msg, "Checking expected message");
// XXX check title? OS X has title in content
// Compare listbox contents
let count = listbox.itemCount;
is(count, state.items.length, "Checking listbox length");
if (count)
is(listbox.selectedIndex, 0, "Checking selected index");
for (let i = 0; i < count; i++) {
let item = listbox.getItemAtIndex(i).label;
is(item, items[i], "Checking item #" + i + " label");
}
}
/*
* 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(doc, testNum) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
ok(true, "--- handleDialog for test " + testNum + " ---");
let textField = doc.getElementById("loginTextbox");
let passField = doc.getElementById("password1Textbox");
let checkbox = doc.getElementById("checkbox");
let dialog = doc.getElementsByTagName("dialog")[0];
let listbox = doc.getElementById("list"); // only relevant for selectDialog
let clickOK = true;
let state;
// XXX check focused element
// XXX check text/passbox labels?
// XXX check button labels?
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,
};
checkExpectedState(doc, state);
//is(doc.activeElement, userfield.inputField, "focus correct for test" + testNum);
//doc.commandDispatcher.rewindFocus();
//is(doc.activeElement, body, "description focusable");
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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, state);
passField.setAttribute("value", "newssh");
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
clickOK = false;
break;
case 20:
// Select (0 items)
state = {
msg : "This is the select text.",
title : "TestTitle",
items : [],
};
checkExpectedSelectState(doc, state);
break;
case 21:
// Select (3 items, default ok)
state = {
msg : "This is the select text.",
title : "TestTitle",
items : ["one", "two", "three"],
};
checkExpectedSelectState(doc, state);
break;
case 22:
// Select (3 items, change selection, ok)
state = {
msg : "This is the select text.",
title : "TestTitle",
items : ["one", "two", "three"],
};
checkExpectedSelectState(doc, state);
// XXX need to trigger old code's click listener
listbox.selectedIndex = 1;
//listbox.getItemAtIndex(1).click();
break;
case 23:
// Select (3 items, cancel)
state = {
msg : "This is the select text.",
title : "TestTitle",
items : ["one", "two", "three"],
};
checkExpectedSelectState(doc, state);
clickOK = false;
break;
case 24:
// 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,
};
is(dialog.getButton("accept").label, "OK", "Checking accept-button label");
is(dialog.getButton("cancel").label, "Cancel", "Checking cancel-button label");
checkExpectedState(doc, state);
break;
case 25:
// 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,
};
is(dialog.getButton("accept").label, "Yes", "Checking accept-button label");
is(dialog.getButton("cancel").label, "No", "Checking cancel-button label");
checkExpectedState(doc, state);
clickOK = false;
break;
case 26:
// 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,
};
is(dialog.getButton("accept").label, "butt0", "Checking accept-button label");
is(dialog.getButton("cancel").label, "butt1", "Checking cancel-button label");
is(dialog.getButton("extra1").label, "butt2", "Checking extra1-button label");
checkExpectedState(doc, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 27:
// 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,
};
// XXX check button1 is default
is(dialog.getButton("accept").label, "butt0", "Checking accept-button label");
is(dialog.getButton("cancel").label, "butt1", "Checking cancel-button label");
is(dialog.getButton("extra1").label, "butt2", "Checking extra1-button label");
checkExpectedState(doc, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
clickOK = false;
break;
case 28:
// 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,
};
// XXX check button2 is default
is(dialog.getButton("accept").label, "butt0", "Checking accept-button label");
is(dialog.getButton("cancel").label, "butt1", "Checking cancel-button label");
is(dialog.getButton("extra1").label, "butt2", "Checking extra1-button label");
checkExpectedState(doc, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
// XXX how to click button 3?
clickOK = false;
break;
case 29:
// 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,
};
checkExpectedState(doc, state);
break;
case 30:
// 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,
};
is(dialog.getButton("accept").label, "OK", "Checking accept-button label");
is(dialog.getButton("cancel").label, "Cancel", "Checking cancel-button label");
is(dialog.getButton("accept").disabled, true, "Checking accept-button is disabled");
is(dialog.getButton("cancel").disabled, false, "Checking cancel-button isn't disabled ");
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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,
};
checkExpectedState(doc, 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 == 28) {
dialog._doButtonCommand("extra1");
} else if (testNum == 30) {
// 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() { pollDialog(dialog); },
100, Ci.nsITimer.TYPE_REPEATING_SLACK);
return;
} else {
if (clickOK)
dialog.acceptDialog();
else
dialog.cancelDialog();
}
ok(true, "handleDialog done");
didDialog = true;
}
let testNum = 0;
let checkVal = {};
let textVal = {};
let passVal = {};
let selectVal = {};
let flags;
let isOK, clickedButton;
// ===== test 1 =====
// Alert
testNum++;
startCallbackTimer();
prompter.alert(window, "TestTitle", "This is the alert text.");
ok(didDialog, "handleDialog was invoked");
// ===== test 2 =====
// AlertCheck (null checkbox label)
testNum++;
startCallbackTimer();
prompter.alertCheck(window, "TestTitle", "This is the alertCheck text.", null, {});
ok(didDialog, "handleDialog was invoked");
// ===== test 3 =====
// AlertCheck
testNum++;
startCallbackTimer();
checkVal.value = false;
prompter.alertCheck(window, "TestTitle", "This is the alertCheck text.", "Check me out!", checkVal);
ok(didDialog, "handleDialog was invoked");
is(checkVal.value, true, "checkbox was checked");
// ===== test 4 =====
// Confirm (ok)
testNum++;
startCallbackTimer();
isOK = prompter.confirm(window, "TestTitle", "This is the confirm text.");
is(isOK, true, "checked expected retval");
ok(didDialog, "handleDialog was invoked");
// ===== test 5 =====
// Confirm (cancel)
testNum++;
startCallbackTimer();
isOK = prompter.confirm(window, "TestTitle", "This is the confirm text.");
is(isOK, false, "checked expected retval");
ok(didDialog, "handleDialog was invoked");
// ===== test 6 =====
// ConfirmCheck (ok, null checkbox label)
testNum++;
startCallbackTimer();
isOK = prompter.confirmCheck(window, "TestTitle", "This is the confirmCheck text.", null, {});
is(isOK, true, "checked expected retval");
ok(didDialog, "handleDialog was invoked");
// ===== test 7 =====
// ConfirmCheck (cancel, null checkbox label)
testNum++;
startCallbackTimer();
isOK = prompter.confirmCheck(window, "TestTitle", "This is the confirmCheck text.", null, {});
is(isOK, false, "checked expected retval");
ok(didDialog, "handleDialog was invoked");
// ===== test 8 =====
// ConfirmCheck (ok)
testNum++;
startCallbackTimer();
checkVal.value = false;
isOK = prompter.confirmCheck(window, "TestTitle", "This is the confirmCheck text.", "Check me out!", checkVal);
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;
isOK = prompter.confirmCheck(window, "TestTitle", "This is the confirmCheck text.", "Check me out!", checkVal);
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 = "";
isOK = prompter.prompt(window, "TestTitle", "This is the prompt text.", textVal, null, {});
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";
isOK = prompter.prompt(window, "TestTitle", "This is the prompt text.", textVal, null, {});
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";
isOK = prompter.prompt(window, "TestTitle", "This is the prompt text.", textVal, null, {});
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";
isOK = prompter.prompt(window, "TestTitle", "This is the prompt text.", textVal, null, {});
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;
isOK = prompter.prompt(window, "TestTitle", "This is the prompt text.", textVal, "Check me out!", checkVal);
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;
isOK = prompter.prompt(window, "TestTitle", "This is the prompt text.", textVal, "Check me out!", checkVal);
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;
isOK = prompter.promptUsernameAndPassword(window, "TestTitle", "This is the pUAP text.", textVal, passVal, "Check me out!", checkVal);
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;
isOK = prompter.promptUsernameAndPassword(window, "TestTitle", "This is the pUAP text.", textVal, passVal, "Check me out!", checkVal);
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;
isOK = prompter.promptPassword(window, "TestTitle", "This is the promptPassword text.", passVal, "Check me out!", checkVal);
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;
isOK = prompter.promptPassword(window, "TestTitle", "This is the promptPassword text.", passVal, "Check me out!", checkVal);
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 =====
// Select (0 items, ok)
testNum++;
startCallbackTimer();
items = [];
selectVal.value = null; // outparam, just making sure.
isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal);
is(isOK, true, "checked expected retval");
is(selectVal.value, -1, "checking selected index");
ok(didDialog, "handleDialog was invoked");
// ===== test 21 =====
// Select (3 items, ok)
testNum++;
startCallbackTimer();
items = ["one", "two", "three"];
selectVal.value = null; // outparam, just making sure.
isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal);
is(isOK, true, "checked expected retval");
is(selectVal.value, 0, "checking selected index");
ok(didDialog, "handleDialog was invoked");
// ===== test 22 =====
// Select (3 items, selection changed, ok)
testNum++;
startCallbackTimer();
items = ["one", "two", "three"];
selectVal.value = null; // outparam, just making sure.
isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal);
is(isOK, true, "checked expected retval");
is(selectVal.value, 1, "checking selected index");
ok(didDialog, "handleDialog was invoked");
// ===== test 23 =====
// Select (3 items, cancel)
testNum++;
startCallbackTimer();
items = ["one", "two", "three"];
selectVal.value = null; // outparam, just making sure.
isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal);
is(isOK, false, "checked expected retval");
is(selectVal.value, 0, "checking selected index");
ok(didDialog, "handleDialog was invoked");
// ===== test 24 =====
// ConfirmEx (ok/cancel, ok)
testNum++;
startCallbackTimer();
flags = Ci.nsIPromptService.STD_OK_CANCEL_BUTTONS;
clickedButton = prompter.confirmEx(window, "TestTitle", "This is the confirmEx text.", flags, null, null, null, null, {});
is(clickedButton, 0, "checked expected button num click");
ok(didDialog, "handleDialog was invoked");
// ===== test 25 =====
// ConfirmEx (yes/no, cancel)
testNum++;
startCallbackTimer();
flags = Ci.nsIPromptService.STD_YES_NO_BUTTONS;
clickedButton = prompter.confirmEx(window, "TestTitle", "This is the confirmEx text.", flags, null, null, null, null, {});
is(clickedButton, 1, "checked expected button num click");
ok(didDialog, "handleDialog was invoked");
// ===== test 26 =====
// 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;
clickedButton = prompter.confirmEx(window, "TestTitle", "This is the confirmEx text.", flags,
"butt0", "butt1", "butt2", "Check me out!", checkVal);
is(clickedButton, 0, "checked expected button num click");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 27 =====
// 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;
clickedButton = prompter.confirmEx(window, "TestTitle", "This is the confirmEx text.", flags,
"butt0", "butt1", "butt2", "Check me out!", checkVal);
is(clickedButton, 1, "checked expected button num click");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 28 =====
// 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;
clickedButton = prompter.confirmEx(window, "TestTitle", "This is the confirmEx text.", flags,
"butt0", "butt1", "butt2", "Check me out!", checkVal);
is(clickedButton, 2, "checked expected button num click");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 29 =====
// Alert, no window
testNum++;
startCallbackTimer();
prompter.alert(null, "TestTitle", "This is the alert text.");
ok(didDialog, "handleDialog was invoked");
// ===== test 30 =====
// ConfirmEx (delay, ok)
testNum++;
startCallbackTimer();
flags = (Ci.nsIPromptService.STD_OK_CANCEL_BUTTONS | Ci.nsIPromptService.BUTTON_DELAY_ENABLE);
clickedButton = prompter.confirmEx(window, "TestTitle", "This is the confirmEx delay text.", flags, null, null, null, null, {});
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
testNum = 100;
startCallbackTimer();
checkVal.value = false;
isOK = prompter.promptAuth(window, channel, level, authinfo, "Check me out!", checkVal);
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
testNum++;
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 = "";
isOK = prompter.promptAuth(window, channel, level, authinfo, "Check me out!", checkVal);
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");
</script>
</pre>
</body>
</html>