--- a/toolkit/components/prompts/test/test_modal_prompts.html
+++ b/toolkit/components/prompts/test/test_modal_prompts.html
@@ -27,17 +27,17 @@ function pollDialog(okButton) {
ok(true, "dialog button is enabled now");
pollTimer.cancel();
pollTimer = null;
okButton.click();
didDialog = true;
}
-function checkExpectedState(ui, state) {
+function checkExpectedState(ui, state, action) {
// 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");
@@ -61,45 +61,87 @@ function checkExpectedState(ui, state) {
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;
+ } else {
+ if (isOSX && state.focused && state.focused.localName == "button")
+ ok(SpecialPowers.compare(ui.infoBody, e), "buttons don't focus on OS X");
+ else if (state.focused)
+ ok(SpecialPowers.compare(state.focused, e), "Checking focused element");
+ else
+ is(e, null, "Not expecting a focused element");
+ }
+
+
+ /* Actions */
+
+
+ if (action.setCheckbox) {
+ // Annoyingly, the prompt code is driven by oncommand.
+ ui.checkbox.setChecked(true);
+ ui.checkbox.doCommand();
+ }
+
+ if (action.textField) {
+ ui.loginTextbox.setAttribute("value", action.textField);
+ }
+
+ if (action.passField) {
+ ui.password1Textbox.setAttribute("value", action.passField);
}
- if (isOSX && state.focused && state.focused.localName == "button")
- ok(SpecialPowers.compare(ui.infoBody, e), "buttons don't focus on OS X");
- else if (state.focused)
- ok(SpecialPowers.compare(state.focused, e), "Checking focused element");
- else
- is(e, null, "Not expecting a focused element");
+ switch (action.buttonClick) {
+ case "ok":
+ case 0:
+ ui.button0.click();
+ break;
+ case "cancel":
+ case 1:
+ ui.button1.click();
+ break;
+ case 2:
+ ui.button2.click();
+ break;
+ case "pollOK":
+ // 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(SpecialPowers.wrapCallback(function() {
+ pollDialog(ui.button0);
+ }),
+ 100, Ci.nsITimer.TYPE_REPEATING_SLACK);
+ break;
+ default:
+ ok(false, "checkExpectedState action listed unknown button.")
+ }
+
+ if (action.buttonClick != "pollOK")
+ didDialog = true;
}
/*
* 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) {
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;
+ let state, action;
switch(testNum) {
case 1:
// Alert
state = {
msg : "This is the alert text.",
title : "TestTitle",
iconClass : "alert-icon",
@@ -108,17 +150,20 @@ function handleDialog(ui, testNum) {
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
- checkExpectedState(ui, state);
+ action = {
+ buttonClick: "ok",
+ };
+ checkExpectedState(ui, state, action);
break;
case 2:
// AlertCheck (null checkbox label, so it's hidden)
state = {
msg : "This is the alertCheck text.",
title : "TestTitle",
iconClass : "alert-icon",
@@ -127,17 +172,20 @@ function handleDialog(ui, testNum) {
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
- checkExpectedState(ui, state);
+ action = {
+ buttonClick: "ok",
+ };
+ checkExpectedState(ui, state, action);
break;
case 3:
// AlertCheck
state = {
msg : "This is the alertCheck text.",
title : "TestTitle",
iconClass : "alert-icon",
@@ -146,21 +194,21 @@ function handleDialog(ui, testNum) {
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();
+ action = {
+ buttonClick: "ok",
+ setCheckbox: true,
+ };
+ checkExpectedState(ui, state, action);
break;
case 4:
// Confirm (ok)
state = {
msg : "This is the confirm text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -169,17 +217,20 @@ function handleDialog(ui, testNum) {
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
- checkExpectedState(ui, state);
+ action = {
+ buttonClick: "ok",
+ };
+ checkExpectedState(ui, state, action);
break;
case 5:
// Confirm (cancel)
state = {
msg : "This is the confirm text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -188,18 +239,20 @@ function handleDialog(ui, testNum) {
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
- checkExpectedState(ui, state);
- clickOK = false;
+ action = {
+ buttonClick: "cancel",
+ };
+ checkExpectedState(ui, state, action);
break;
case 6:
// ConfirmCheck (no checkbox, ok)
state = {
msg : "This is the confirmCheck text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -208,17 +261,20 @@ function handleDialog(ui, testNum) {
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
- checkExpectedState(ui, state);
+ action = {
+ buttonClick: "ok",
+ };
+ checkExpectedState(ui, state, action);
break;
case 7:
// ConfirmCheck (no checkbox, cancel)
state = {
msg : "This is the confirmCheck text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -227,18 +283,20 @@ function handleDialog(ui, testNum) {
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
- checkExpectedState(ui, state);
- clickOK = false;
+ action = {
+ buttonClick: "cancel",
+ };
+ checkExpectedState(ui, state, action);
break;
case 8:
// ConfirmCheck (ok)
state = {
msg : "This is the confirmCheck text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -247,21 +305,21 @@ function handleDialog(ui, testNum) {
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();
+ action = {
+ buttonClick: "ok",
+ setCheckbox: true,
+ };
+ checkExpectedState(ui, state, action);
break;
case 9:
// ConfirmCheck (cancel)
state = {
msg : "This is the confirmCheck text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -270,22 +328,21 @@ function handleDialog(ui, testNum) {
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();
+ action = {
+ buttonClick: "cancel",
+ setCheckbox: true,
+ };
+ checkExpectedState(ui, state, action);
break;
case 10:
// Prompt (ok, no default text)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -294,18 +351,21 @@ function handleDialog(ui, testNum) {
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
- checkExpectedState(ui, state);
- textField.setAttribute("value", "bacon");
+ action = {
+ buttonClick : "ok",
+ textField : "bacon",
+ };
+ checkExpectedState(ui, state, action);
break;
case 11:
// Prompt (ok, default text)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -314,17 +374,20 @@ function handleDialog(ui, testNum) {
checkHidden : true,
textValue : "kittens",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
- checkExpectedState(ui, state);
+ action = {
+ buttonClick: "ok",
+ };
+ checkExpectedState(ui, state, action);
break;
case 12:
// Prompt (cancel, default text)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -333,18 +396,20 @@ function handleDialog(ui, testNum) {
checkHidden : true,
textValue : "puppies",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
- checkExpectedState(ui, state);
- clickOK = false;
+ action = {
+ buttonClick: "cancel",
+ };
+ checkExpectedState(ui, state, action);
break;
case 13:
// Prompt (cancel, default text modified)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -353,19 +418,21 @@ function handleDialog(ui, testNum) {
checkHidden : true,
textValue : "puppies",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.loginTextbox.inputField,
defButton : ui.button0,
};
- checkExpectedState(ui, state);
- textField.setAttribute("value", "bacon");
- clickOK = false;
+ action = {
+ buttonClick : "cancel",
+ textField : "bacon",
+ };
+ checkExpectedState(ui, state, action);
break;
case 14:
// Prompt (ok, with checkbox)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -374,21 +441,21 @@ function handleDialog(ui, testNum) {
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();
+ action = {
+ buttonClick: "ok",
+ setCheckbox: true,
+ };
+ checkExpectedState(ui, state, action);
break;
case 15:
// Prompt (cancel, with checkbox)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -397,22 +464,21 @@ function handleDialog(ui, testNum) {
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();
+ action = {
+ buttonClick: "cancel",
+ setCheckbox: true,
+ };
+ checkExpectedState(ui, state, action);
break;
case 16:
// PromptUsernameAndPassword (ok, with checkbox)
state = {
msg : "This is the pUAP text.",
title : "TestTitle",
iconClass : "authentication-icon question-icon",
@@ -421,23 +487,23 @@ function handleDialog(ui, testNum) {
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();
+ action = {
+ buttonClick: "ok",
+ setCheckbox: true,
+ textField: "newusr",
+ passField: "newssh",
+ };
+ checkExpectedState(ui, state, action);
break;
case 17:
// PromptUsernameAndPassword (cancel, with checkbox)
state = {
msg : "This is the pUAP text.",
title : "TestTitle",
iconClass : "authentication-icon question-icon",
@@ -446,25 +512,23 @@ function handleDialog(ui, testNum) {
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;
+ action = {
+ buttonClick : "cancel",
+ setCheckbox : true,
+ textField : "newusr",
+ passField : "newssh",
+ };
+ checkExpectedState(ui, state, action);
break;
case 18:
// PromptPassword (ok, with checkbox)
state = {
msg : "This is the promptPassword text.",
title : "TestTitle",
iconClass : "authentication-icon question-icon",
@@ -473,22 +537,22 @@ function handleDialog(ui, testNum) {
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();
+ action = {
+ buttonClick : "ok",
+ setCheckbox : true,
+ passField : "newssh",
+ };
+ checkExpectedState(ui, state, action);
break;
case 19:
// PromptPassword (cancel, with checkbox)
state = {
msg : "This is the promptPassword text.",
title : "TestTitle",
iconClass : "authentication-icon question-icon",
@@ -497,24 +561,22 @@ function handleDialog(ui, testNum) {
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;
+ action = {
+ buttonClick : "cancel",
+ setCheckbox : true,
+ passField : "newssh",
+ };
+ checkExpectedState(ui, state, action);
break;
case 20:
// ConfirmEx (ok/cancel, ok)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -523,19 +585,22 @@ function handleDialog(ui, testNum) {
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
+ action = {
+ buttonClick: "ok",
+ };
is(ui.button0.label, "OK", "Checking accept-button label");
is(ui.button1.label, "Cancel", "Checking cancel-button label");
- checkExpectedState(ui, state);
+ checkExpectedState(ui, state, action);
break;
case 21:
// ConfirmEx (yes/no, cancel)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -544,20 +609,22 @@ function handleDialog(ui, testNum) {
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
+ action = {
+ buttonClick: "cancel",
+ };
is(ui.button0.label, "Yes", "Checking accept-button label");
is(ui.button1.label, "No", "Checking cancel-button label");
- checkExpectedState(ui, state);
- clickOK = false;
+ checkExpectedState(ui, state, action);
break;
case 22:
// ConfirmEx (buttons from args, checkbox, ok)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -566,24 +633,24 @@ function handleDialog(ui, testNum) {
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
+ action = {
+ buttonClick: "ok",
+ setCheckbox: true,
+ };
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();
+ checkExpectedState(ui, state, action);
break;
case 23:
// ConfirmEx (buttons from args, checkbox, cancel)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -592,27 +659,25 @@ function handleDialog(ui, testNum) {
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
focused : ui.button1, // Default changed!
defButton : ui.button1,
};
+ action = {
+ buttonClick: "cancel",
+ setCheckbox: true,
+ };
// 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;
+ checkExpectedState(ui, state, action);
break;
case 24:
// ConfirmEx (buttons from args, checkbox, button3)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -621,28 +686,25 @@ function handleDialog(ui, testNum) {
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
focused : ui.button2, // Default changed!
defButton : ui.button2,
};
+ action = {
+ buttonClick: 2,
+ setCheckbox: true,
+ };
// 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;
+ checkExpectedState(ui, state, action);
break;
case 25:
// Alert, null window
state = {
msg : "This is the alert text.",
title : "TestTitle",
iconClass : "alert-icon",
@@ -651,17 +713,20 @@ function handleDialog(ui, testNum) {
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
focused : ui.button0,
defButton : ui.button0,
};
- checkExpectedState(ui, state);
+ action = {
+ buttonClick: "ok",
+ };
+ checkExpectedState(ui, state, action);
break;
case 26:
// ConfirmEx (with delay, ok)
state = {
msg : "This is the confirmEx delay text.",
title : "TestTitle",
iconClass : "question-icon",
@@ -676,21 +741,25 @@ function handleDialog(ui, testNum) {
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;
+ action = {
+ buttonClick: "pollOK",
+ };
+
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);
+ checkExpectedState(ui, state, action);
break;
case 100:
// PromptAuth (no realm, ok, with checkbox)
state = {
msg : 'Enter username and password for http://example.com',
title : "TestTitle",
@@ -700,23 +769,23 @@ function handleDialog(ui, testNum) {
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();
+ action = {
+ buttonClick : "ok",
+ setCheckbox : true,
+ textField : "username",
+ passField : "password",
+ };
+ checkExpectedState(ui, state, action);
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 ' +
@@ -728,51 +797,31 @@ function handleDialog(ui, testNum) {
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();
+ action = {
+ buttonClick : "ok",
+ setCheckbox : true,
+ textField : "username",
+ passField : "password",
+ };
+ checkExpectedState(ui, state, action);
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(SpecialPowers.wrapCallback(function() {
- 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 + ")");