1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/prompts/test/test_modal_prompts.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,1240 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Modal Prompts Test</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <script type="text/javascript" src="prompt_common.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 +</head> 1.12 +<body> 1.13 +Prompter tests: modal prompts 1.14 +<p id="display"></p> 1.15 + 1.16 +<div id="content" style="display: none"> 1.17 + <iframe id="iframe"></iframe> 1.18 +</div> 1.19 + 1.20 +<pre id="test"> 1.21 +<script class="testbody" type="text/javascript;version=1.8"> 1.22 + 1.23 +var isOSX = ("nsILocalFileMac" in SpecialPowers.Ci); 1.24 +var isLinux = ("@mozilla.org/gnome-gconf-service;1" in SpecialPowers.Cc); 1.25 + 1.26 +function pollDialog(okButton) { 1.27 + if (okButton.disabled) 1.28 + return; 1.29 + 1.30 + ok(true, "dialog button is enabled now"); 1.31 + pollTimer.cancel(); 1.32 + pollTimer = null; 1.33 + okButton.click(); 1.34 + didDialog = true; 1.35 +} 1.36 + 1.37 +function checkExpectedState(ui, state) { 1.38 + 1.39 + // XXX check title? OS X has title in content 1.40 + is(ui.infoBody.textContent, state.msg, "Checking expected message"); 1.41 + is(ui.loginContainer.hidden, state.textHidden, "Checking textbox visibility"); 1.42 + is(ui.password1Container.hidden, state.passHidden, "Checking passbox visibility"); 1.43 + is(ui.checkboxContainer.hidden, state.checkHidden, "Checking checkbox visibility"); 1.44 + is(ui.checkbox.label, state.checkMsg, "Checking checkbox label"); 1.45 + is(ui.checkbox.checked, state.checked, "Checking checkbox checked"); 1.46 + if (!isTabModal) 1.47 + is(ui.infoIcon.className, "spaced " + state.iconClass, "Checking expected icon CSS class"); 1.48 + is(ui.loginTextbox.getAttribute("value"), state.textValue, "Checking textbox value"); 1.49 + is(ui.password1Textbox.getAttribute("value"), state.passValue, "Checking passbox value"); 1.50 + 1.51 + 1.52 + function isDefaultButton(b) { 1.53 + return (b.hasAttribute("default") && 1.54 + b.getAttribute("default") == "true"); 1.55 + } 1.56 + 1.57 + let shouldBeDefault; 1.58 + shouldBeDefault = SpecialPowers.compare(state.defButton, ui.button0); 1.59 + is(isDefaultButton(ui.button0), shouldBeDefault, "checking button0 default"); 1.60 + shouldBeDefault = SpecialPowers.compare(state.defButton, ui.button1); 1.61 + is(isDefaultButton(ui.button1), shouldBeDefault, "checking button1 default"); 1.62 + shouldBeDefault = SpecialPowers.compare(state.defButton, ui.button2); 1.63 + is(isDefaultButton(ui.button2), shouldBeDefault, "checking button2 default"); 1.64 + 1.65 + let fm = Cc["@mozilla.org/focus-manager;1"]. 1.66 + getService(Ci.nsIFocusManager); 1.67 + let e = fm.focusedElement; 1.68 + ok(true, "focused element is a " + (e ? e.localName : "<null>")); 1.69 + if (isLinux && !e) { 1.70 + todo(false, "Focus seems missing on Linux"); 1.71 + return; 1.72 + } 1.73 + 1.74 + if (isOSX && state.focused && state.focused.localName == "button") 1.75 + ok(SpecialPowers.compare(ui.infoBody, e), "buttons don't focus on OS X"); 1.76 + else if (state.focused) 1.77 + ok(SpecialPowers.compare(state.focused, e), "Checking focused element"); 1.78 + else 1.79 + is(e, null, "Not expecting a focused element"); 1.80 +} 1.81 + 1.82 + 1.83 +/* 1.84 + * handleDialog 1.85 + * 1.86 + * Invoked a short period of time after calling startCallbackTimer(), and 1.87 + * allows testing the actual prompt dialog while it's being displayed. Tests 1.88 + * should call startCallbackTimer() each time the auth dialog is expected (the 1.89 + * timer is a one-shot). 1.90 + */ 1.91 +function handleDialog(ui, testNum) { 1.92 + ok(true, "--- handleDialog for test " + testNum + 1.93 + " --- (isTabModal=" + isTabModal + ", usePromptService=" + usePromptService + ")"); 1.94 + 1.95 + let textField = ui.loginTextbox; 1.96 + let passField = ui.password1Textbox; 1.97 + let checkbox = ui.checkbox; 1.98 + let clickOK = true; 1.99 + let state; 1.100 + 1.101 + switch(testNum) { 1.102 + case 1: 1.103 + // Alert 1.104 + state = { 1.105 + msg : "This is the alert text.", 1.106 + title : "TestTitle", 1.107 + iconClass : "alert-icon", 1.108 + textHidden : true, 1.109 + passHidden : true, 1.110 + checkHidden : true, 1.111 + textValue : "", 1.112 + passValue : "", 1.113 + checkMsg : "", 1.114 + checked : false, 1.115 + focused : ui.button0, 1.116 + defButton : ui.button0, 1.117 + }; 1.118 + checkExpectedState(ui, state); 1.119 + break; 1.120 + 1.121 + case 2: 1.122 + // AlertCheck (null checkbox label, so it's hidden) 1.123 + state = { 1.124 + msg : "This is the alertCheck text.", 1.125 + title : "TestTitle", 1.126 + iconClass : "alert-icon", 1.127 + textHidden : true, 1.128 + passHidden : true, 1.129 + checkHidden : true, 1.130 + textValue : "", 1.131 + passValue : "", 1.132 + checkMsg : "", 1.133 + checked : false, 1.134 + focused : ui.button0, 1.135 + defButton : ui.button0, 1.136 + }; 1.137 + checkExpectedState(ui, state); 1.138 + break; 1.139 + 1.140 + case 3: 1.141 + // AlertCheck 1.142 + state = { 1.143 + msg : "This is the alertCheck text.", 1.144 + title : "TestTitle", 1.145 + iconClass : "alert-icon", 1.146 + textHidden : true, 1.147 + passHidden : true, 1.148 + checkHidden : false, 1.149 + textValue : "", 1.150 + passValue : "", 1.151 + checkMsg : "Check me out!", 1.152 + checked : false, 1.153 + focused : ui.button0, 1.154 + defButton : ui.button0, 1.155 + }; 1.156 + checkExpectedState(ui, state); 1.157 + 1.158 + // XXX dumb. old code driven by oncommand. 1.159 + checkbox.setChecked(true); 1.160 + checkbox.doCommand(); 1.161 + break; 1.162 + 1.163 + case 4: 1.164 + // Confirm (ok) 1.165 + state = { 1.166 + msg : "This is the confirm text.", 1.167 + title : "TestTitle", 1.168 + iconClass : "question-icon", 1.169 + textHidden : true, 1.170 + passHidden : true, 1.171 + checkHidden : true, 1.172 + textValue : "", 1.173 + passValue : "", 1.174 + checkMsg : "", 1.175 + checked : false, 1.176 + focused : ui.button0, 1.177 + defButton : ui.button0, 1.178 + }; 1.179 + checkExpectedState(ui, state); 1.180 + break; 1.181 + 1.182 + case 5: 1.183 + // Confirm (cancel) 1.184 + state = { 1.185 + msg : "This is the confirm text.", 1.186 + title : "TestTitle", 1.187 + iconClass : "question-icon", 1.188 + textHidden : true, 1.189 + passHidden : true, 1.190 + checkHidden : true, 1.191 + textValue : "", 1.192 + passValue : "", 1.193 + checkMsg : "", 1.194 + checked : false, 1.195 + focused : ui.button0, 1.196 + defButton : ui.button0, 1.197 + }; 1.198 + checkExpectedState(ui, state); 1.199 + clickOK = false; 1.200 + break; 1.201 + 1.202 + case 6: 1.203 + // ConfirmCheck (no checkbox, ok) 1.204 + state = { 1.205 + msg : "This is the confirmCheck text.", 1.206 + title : "TestTitle", 1.207 + iconClass : "question-icon", 1.208 + textHidden : true, 1.209 + passHidden : true, 1.210 + checkHidden : true, 1.211 + textValue : "", 1.212 + passValue : "", 1.213 + checkMsg : "", 1.214 + checked : false, 1.215 + focused : ui.button0, 1.216 + defButton : ui.button0, 1.217 + }; 1.218 + checkExpectedState(ui, state); 1.219 + break; 1.220 + 1.221 + case 7: 1.222 + // ConfirmCheck (no checkbox, cancel) 1.223 + state = { 1.224 + msg : "This is the confirmCheck text.", 1.225 + title : "TestTitle", 1.226 + iconClass : "question-icon", 1.227 + textHidden : true, 1.228 + passHidden : true, 1.229 + checkHidden : true, 1.230 + textValue : "", 1.231 + passValue : "", 1.232 + checkMsg : "", 1.233 + checked : false, 1.234 + focused : ui.button0, 1.235 + defButton : ui.button0, 1.236 + }; 1.237 + checkExpectedState(ui, state); 1.238 + clickOK = false; 1.239 + break; 1.240 + 1.241 + case 8: 1.242 + // ConfirmCheck (ok) 1.243 + state = { 1.244 + msg : "This is the confirmCheck text.", 1.245 + title : "TestTitle", 1.246 + iconClass : "question-icon", 1.247 + textHidden : true, 1.248 + passHidden : true, 1.249 + checkHidden : false, 1.250 + textValue : "", 1.251 + passValue : "", 1.252 + checkMsg : "Check me out!", 1.253 + checked : false, 1.254 + focused : ui.button0, 1.255 + defButton : ui.button0, 1.256 + }; 1.257 + checkExpectedState(ui, state); 1.258 + 1.259 + // XXX dumb. old code driven by oncommand. 1.260 + checkbox.setChecked(true); 1.261 + checkbox.doCommand(); 1.262 + break; 1.263 + 1.264 + case 9: 1.265 + // ConfirmCheck (cancel) 1.266 + state = { 1.267 + msg : "This is the confirmCheck text.", 1.268 + title : "TestTitle", 1.269 + iconClass : "question-icon", 1.270 + textHidden : true, 1.271 + passHidden : true, 1.272 + checkHidden : false, 1.273 + textValue : "", 1.274 + passValue : "", 1.275 + checkMsg : "Check me out!", 1.276 + checked : false, 1.277 + focused : ui.button0, 1.278 + defButton : ui.button0, 1.279 + }; 1.280 + checkExpectedState(ui, state); 1.281 + 1.282 + clickOK = false; 1.283 + // XXX dumb. old code driven by oncommand. 1.284 + checkbox.setChecked(true); 1.285 + checkbox.doCommand(); 1.286 + break; 1.287 + 1.288 + case 10: 1.289 + // Prompt (ok, no default text) 1.290 + state = { 1.291 + msg : "This is the prompt text.", 1.292 + title : "TestTitle", 1.293 + iconClass : "question-icon", 1.294 + textHidden : false, 1.295 + passHidden : true, 1.296 + checkHidden : true, 1.297 + textValue : "", 1.298 + passValue : "", 1.299 + checkMsg : "", 1.300 + checked : false, 1.301 + focused : ui.loginTextbox.inputField, 1.302 + defButton : ui.button0, 1.303 + }; 1.304 + checkExpectedState(ui, state); 1.305 + textField.setAttribute("value", "bacon"); 1.306 + break; 1.307 + 1.308 + case 11: 1.309 + // Prompt (ok, default text) 1.310 + state = { 1.311 + msg : "This is the prompt text.", 1.312 + title : "TestTitle", 1.313 + iconClass : "question-icon", 1.314 + textHidden : false, 1.315 + passHidden : true, 1.316 + checkHidden : true, 1.317 + textValue : "kittens", 1.318 + passValue : "", 1.319 + checkMsg : "", 1.320 + checked : false, 1.321 + focused : ui.loginTextbox.inputField, 1.322 + defButton : ui.button0, 1.323 + }; 1.324 + checkExpectedState(ui, state); 1.325 + break; 1.326 + 1.327 + case 12: 1.328 + // Prompt (cancel, default text) 1.329 + state = { 1.330 + msg : "This is the prompt text.", 1.331 + title : "TestTitle", 1.332 + iconClass : "question-icon", 1.333 + textHidden : false, 1.334 + passHidden : true, 1.335 + checkHidden : true, 1.336 + textValue : "puppies", 1.337 + passValue : "", 1.338 + checkMsg : "", 1.339 + checked : false, 1.340 + focused : ui.loginTextbox.inputField, 1.341 + defButton : ui.button0, 1.342 + }; 1.343 + checkExpectedState(ui, state); 1.344 + clickOK = false; 1.345 + break; 1.346 + 1.347 + case 13: 1.348 + // Prompt (cancel, default text modified) 1.349 + state = { 1.350 + msg : "This is the prompt text.", 1.351 + title : "TestTitle", 1.352 + iconClass : "question-icon", 1.353 + textHidden : false, 1.354 + passHidden : true, 1.355 + checkHidden : true, 1.356 + textValue : "puppies", 1.357 + passValue : "", 1.358 + checkMsg : "", 1.359 + checked : false, 1.360 + focused : ui.loginTextbox.inputField, 1.361 + defButton : ui.button0, 1.362 + }; 1.363 + checkExpectedState(ui, state); 1.364 + textField.setAttribute("value", "bacon"); 1.365 + clickOK = false; 1.366 + break; 1.367 + 1.368 + case 14: 1.369 + // Prompt (ok, with checkbox) 1.370 + state = { 1.371 + msg : "This is the prompt text.", 1.372 + title : "TestTitle", 1.373 + iconClass : "question-icon", 1.374 + textHidden : false, 1.375 + passHidden : true, 1.376 + checkHidden : false, 1.377 + textValue : "tribbles", 1.378 + passValue : "", 1.379 + checkMsg : "Check me out!", 1.380 + checked : false, 1.381 + focused : ui.loginTextbox.inputField, 1.382 + defButton : ui.button0, 1.383 + }; 1.384 + checkExpectedState(ui, state); 1.385 + 1.386 + // XXX dumb. old code driven by oncommand. 1.387 + checkbox.setChecked(true); 1.388 + checkbox.doCommand(); 1.389 + break; 1.390 + 1.391 + case 15: 1.392 + // Prompt (cancel, with checkbox) 1.393 + state = { 1.394 + msg : "This is the prompt text.", 1.395 + title : "TestTitle", 1.396 + iconClass : "question-icon", 1.397 + textHidden : false, 1.398 + passHidden : true, 1.399 + checkHidden : false, 1.400 + textValue : "tribbles", 1.401 + passValue : "", 1.402 + checkMsg : "Check me out!", 1.403 + checked : false, 1.404 + focused : ui.loginTextbox.inputField, 1.405 + defButton : ui.button0, 1.406 + }; 1.407 + checkExpectedState(ui, state); 1.408 + 1.409 + clickOK = false; 1.410 + // XXX dumb. old code driven by oncommand. 1.411 + checkbox.setChecked(true); 1.412 + checkbox.doCommand(); 1.413 + break; 1.414 + 1.415 + case 16: 1.416 + // PromptUsernameAndPassword (ok, with checkbox) 1.417 + state = { 1.418 + msg : "This is the pUAP text.", 1.419 + title : "TestTitle", 1.420 + iconClass : "authentication-icon question-icon", 1.421 + textHidden : false, 1.422 + passHidden : false, 1.423 + checkHidden : false, 1.424 + textValue : "usr", 1.425 + passValue : "ssh", 1.426 + checkMsg : "Check me out!", 1.427 + checked : false, 1.428 + focused : ui.loginTextbox.inputField, 1.429 + defButton : ui.button0, 1.430 + }; 1.431 + checkExpectedState(ui, state); 1.432 + 1.433 + textField.setAttribute("value", "newusr"); 1.434 + passField.setAttribute("value", "newssh"); 1.435 + // XXX dumb. old code driven by oncommand. 1.436 + checkbox.setChecked(true); 1.437 + checkbox.doCommand(); 1.438 + break; 1.439 + 1.440 + case 17: 1.441 + // PromptUsernameAndPassword (cancel, with checkbox) 1.442 + state = { 1.443 + msg : "This is the pUAP text.", 1.444 + title : "TestTitle", 1.445 + iconClass : "authentication-icon question-icon", 1.446 + textHidden : false, 1.447 + passHidden : false, 1.448 + checkHidden : false, 1.449 + textValue : "usr", 1.450 + passValue : "ssh", 1.451 + checkMsg : "Check me out!", 1.452 + checked : false, 1.453 + focused : ui.loginTextbox.inputField, 1.454 + defButton : ui.button0, 1.455 + }; 1.456 + checkExpectedState(ui, state); 1.457 + 1.458 + textField.setAttribute("value", "newusr"); 1.459 + passField.setAttribute("value", "newssh"); 1.460 + // XXX dumb. old code driven by oncommand. 1.461 + checkbox.setChecked(true); 1.462 + checkbox.doCommand(); 1.463 + 1.464 + clickOK = false; 1.465 + break; 1.466 + 1.467 + case 18: 1.468 + // PromptPassword (ok, with checkbox) 1.469 + state = { 1.470 + msg : "This is the promptPassword text.", 1.471 + title : "TestTitle", 1.472 + iconClass : "authentication-icon question-icon", 1.473 + textHidden : true, 1.474 + passHidden : false, 1.475 + checkHidden : false, 1.476 + textValue : "", 1.477 + passValue : "ssh", 1.478 + checkMsg : "Check me out!", 1.479 + checked : false, 1.480 + focused : ui.password1Textbox.inputField, 1.481 + defButton : ui.button0, 1.482 + }; 1.483 + checkExpectedState(ui, state); 1.484 + 1.485 + passField.setAttribute("value", "newssh"); 1.486 + // XXX dumb. old code driven by oncommand. 1.487 + checkbox.setChecked(true); 1.488 + checkbox.doCommand(); 1.489 + break; 1.490 + 1.491 + case 19: 1.492 + // PromptPassword (cancel, with checkbox) 1.493 + state = { 1.494 + msg : "This is the promptPassword text.", 1.495 + title : "TestTitle", 1.496 + iconClass : "authentication-icon question-icon", 1.497 + textHidden : true, 1.498 + passHidden : false, 1.499 + checkHidden : false, 1.500 + textValue : "", 1.501 + passValue : "ssh", 1.502 + checkMsg : "Check me out!", 1.503 + checked : false, 1.504 + focused : ui.password1Textbox.inputField, 1.505 + defButton : ui.button0, 1.506 + }; 1.507 + checkExpectedState(ui, state); 1.508 + 1.509 + passField.setAttribute("value", "newssh"); 1.510 + // XXX dumb. old code driven by oncommand. 1.511 + checkbox.setChecked(true); 1.512 + checkbox.doCommand(); 1.513 + 1.514 + clickOK = false; 1.515 + break; 1.516 + 1.517 + case 20: 1.518 + // ConfirmEx (ok/cancel, ok) 1.519 + state = { 1.520 + msg : "This is the confirmEx text.", 1.521 + title : "TestTitle", 1.522 + iconClass : "question-icon", 1.523 + textHidden : true, 1.524 + passHidden : true, 1.525 + checkHidden : true, 1.526 + textValue : "", 1.527 + passValue : "", 1.528 + checkMsg : "", 1.529 + checked : false, 1.530 + focused : ui.button0, 1.531 + defButton : ui.button0, 1.532 + }; 1.533 + is(ui.button0.label, "OK", "Checking accept-button label"); 1.534 + is(ui.button1.label, "Cancel", "Checking cancel-button label"); 1.535 + checkExpectedState(ui, state); 1.536 + break; 1.537 + 1.538 + case 21: 1.539 + // ConfirmEx (yes/no, cancel) 1.540 + state = { 1.541 + msg : "This is the confirmEx text.", 1.542 + title : "TestTitle", 1.543 + iconClass : "question-icon", 1.544 + textHidden : true, 1.545 + passHidden : true, 1.546 + checkHidden : true, 1.547 + textValue : "", 1.548 + passValue : "", 1.549 + checkMsg : "", 1.550 + checked : false, 1.551 + focused : ui.button0, 1.552 + defButton : ui.button0, 1.553 + }; 1.554 + is(ui.button0.label, "Yes", "Checking accept-button label"); 1.555 + is(ui.button1.label, "No", "Checking cancel-button label"); 1.556 + checkExpectedState(ui, state); 1.557 + clickOK = false; 1.558 + break; 1.559 + 1.560 + case 22: 1.561 + // ConfirmEx (buttons from args, checkbox, ok) 1.562 + state = { 1.563 + msg : "This is the confirmEx text.", 1.564 + title : "TestTitle", 1.565 + iconClass : "question-icon", 1.566 + textHidden : true, 1.567 + passHidden : true, 1.568 + checkHidden : false, 1.569 + textValue : "", 1.570 + passValue : "", 1.571 + checkMsg : "Check me out!", 1.572 + checked : false, 1.573 + focused : ui.button0, 1.574 + defButton : ui.button0, 1.575 + }; 1.576 + is(ui.button0.label, "butt0", "Checking accept-button label"); 1.577 + is(ui.button1.label, "butt1", "Checking cancel-button label"); 1.578 + is(ui.button2.label, "butt2", "Checking extra1-button label"); 1.579 + checkExpectedState(ui, state); 1.580 + 1.581 + // XXX dumb. old code driven by oncommand. 1.582 + checkbox.setChecked(true); 1.583 + checkbox.doCommand(); 1.584 + break; 1.585 + 1.586 + case 23: 1.587 + // ConfirmEx (buttons from args, checkbox, cancel) 1.588 + state = { 1.589 + msg : "This is the confirmEx text.", 1.590 + title : "TestTitle", 1.591 + iconClass : "question-icon", 1.592 + textHidden : true, 1.593 + passHidden : true, 1.594 + checkHidden : false, 1.595 + textValue : "", 1.596 + passValue : "", 1.597 + checkMsg : "Check me out!", 1.598 + checked : false, 1.599 + focused : ui.button1, // Default changed! 1.600 + defButton : ui.button1, 1.601 + }; 1.602 + // XXX check button1 is default 1.603 + is(ui.button0.label, "butt0", "Checking accept-button label"); 1.604 + is(ui.button1.label, "butt1", "Checking cancel-button label"); 1.605 + is(ui.button2.label, "butt2", "Checking extra1-button label"); 1.606 + checkExpectedState(ui, state); 1.607 + 1.608 + // XXX dumb. old code driven by oncommand. 1.609 + checkbox.setChecked(true); 1.610 + checkbox.doCommand(); 1.611 + 1.612 + clickOK = false; 1.613 + break; 1.614 + 1.615 + case 24: 1.616 + // ConfirmEx (buttons from args, checkbox, button3) 1.617 + state = { 1.618 + msg : "This is the confirmEx text.", 1.619 + title : "TestTitle", 1.620 + iconClass : "question-icon", 1.621 + textHidden : true, 1.622 + passHidden : true, 1.623 + checkHidden : false, 1.624 + textValue : "", 1.625 + passValue : "", 1.626 + checkMsg : "Check me out!", 1.627 + checked : false, 1.628 + focused : ui.button2, // Default changed! 1.629 + defButton : ui.button2, 1.630 + }; 1.631 + // XXX check button2 is default 1.632 + is(ui.button0.label, "butt0", "Checking accept-button label"); 1.633 + is(ui.button1.label, "butt1", "Checking cancel-button label"); 1.634 + is(ui.button2.label, "butt2", "Checking extra1-button label"); 1.635 + checkExpectedState(ui, state); 1.636 + 1.637 + // XXX dumb. old code driven by oncommand. 1.638 + checkbox.setChecked(true); 1.639 + checkbox.doCommand(); 1.640 + 1.641 + // XXX how to click button 3? 1.642 + clickOK = false; 1.643 + break; 1.644 + 1.645 + case 25: 1.646 + // Alert, null window 1.647 + state = { 1.648 + msg : "This is the alert text.", 1.649 + title : "TestTitle", 1.650 + iconClass : "alert-icon", 1.651 + textHidden : true, 1.652 + passHidden : true, 1.653 + checkHidden : true, 1.654 + textValue : "", 1.655 + passValue : "", 1.656 + checkMsg : "", 1.657 + checked : false, 1.658 + focused : ui.button0, 1.659 + defButton : ui.button0, 1.660 + }; 1.661 + checkExpectedState(ui, state); 1.662 + break; 1.663 + 1.664 + case 26: 1.665 + // ConfirmEx (with delay, ok) 1.666 + state = { 1.667 + msg : "This is the confirmEx delay text.", 1.668 + title : "TestTitle", 1.669 + iconClass : "question-icon", 1.670 + textHidden : true, 1.671 + passHidden : true, 1.672 + checkHidden : true, 1.673 + textValue : "", 1.674 + passValue : "", 1.675 + checkMsg : "", 1.676 + checked : false, 1.677 + focused : null, // nothing focused until after delay fires 1.678 + defButton : ui.button0, 1.679 + }; 1.680 + 1.681 + // OS X doesn't initially focus the button, but rather the infoBody. 1.682 + // The focus stays there even after the button-enable delay has fired. 1.683 + if (isOSX) 1.684 + state.focused = ui.infoBody; 1.685 + 1.686 + is(ui.button0.label, "OK", "Checking accept-button label"); 1.687 + is(ui.button1.label, "Cancel", "Checking cancel-button label"); 1.688 + is(ui.button0.disabled, true, "Checking accept-button is disabled"); 1.689 + is(ui.button1.disabled, false, "Checking cancel-button isn't disabled "); 1.690 + checkExpectedState(ui, state); 1.691 + break; 1.692 + 1.693 + 1.694 + case 100: 1.695 + // PromptAuth (no realm, ok, with checkbox) 1.696 + state = { 1.697 + msg : 'Enter username and password for http://example.com', 1.698 + title : "TestTitle", 1.699 + iconClass : "authentication-icon question-icon", 1.700 + textHidden : false, 1.701 + passHidden : false, 1.702 + checkHidden : false, 1.703 + textValue : "", 1.704 + passValue : "", 1.705 + checkMsg : "Check me out!", 1.706 + checked : false, 1.707 + focused : ui.loginTextbox.inputField, 1.708 + defButton : ui.button0, 1.709 + }; 1.710 + checkExpectedState(ui, state); 1.711 + 1.712 + textField.setAttribute("value", "username"); 1.713 + passField.setAttribute("value", "password"); 1.714 + // XXX dumb. old code driven by oncommand. 1.715 + checkbox.setChecked(true); 1.716 + checkbox.doCommand(); 1.717 + break; 1.718 + 1.719 + case 101: 1.720 + // PromptAuth (long realm, ok, with checkbox) 1.721 + state = { 1.722 + msg : 'A username and password are being requested by http://example.com. The site ' + 1.723 + 'says: "abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi ' + 1.724 + 'abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi ' + 1.725 + 'abcdefghi \u2026"', 1.726 + title : "TestTitle", 1.727 + iconClass : "authentication-icon question-icon", 1.728 + textHidden : false, 1.729 + passHidden : false, 1.730 + checkHidden : false, 1.731 + textValue : "", 1.732 + passValue : "", 1.733 + checkMsg : "Check me out!", 1.734 + checked : false, 1.735 + focused : ui.loginTextbox.inputField, 1.736 + defButton : ui.button0, 1.737 + }; 1.738 + checkExpectedState(ui, state); 1.739 + 1.740 + textField.setAttribute("value", "username"); 1.741 + passField.setAttribute("value", "password"); 1.742 + // XXX dumb. old code driven by oncommand. 1.743 + checkbox.setChecked(true); 1.744 + checkbox.doCommand(); 1.745 + break; 1.746 + 1.747 + default: 1.748 + ok(false, "Uhh, unhandled switch for testNum #" + testNum); 1.749 + break; 1.750 + } 1.751 + 1.752 + if (testNum == 24) { 1.753 + ui.button2.click(); 1.754 + } else if (testNum == 26) { 1.755 + // Buttons are disabled at the moment, poll until they're reenabled. 1.756 + // Can't use setInterval here, because the window's in a modal state 1.757 + // and thus DOM events are suppressed. 1.758 + pollTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); 1.759 + pollTimer.initWithCallback(SpecialPowers.wrapCallback(function() { 1.760 + pollDialog(ui.button0); 1.761 + }), 1.762 + 100, Ci.nsITimer.TYPE_REPEATING_SLACK); 1.763 + return; 1.764 + } else { 1.765 + if (clickOK) 1.766 + ui.button0.click(); 1.767 + else 1.768 + ui.button1.click(); 1.769 + } 1.770 + 1.771 + ok(true, "handleDialog done"); 1.772 + didDialog = true; 1.773 +} 1.774 + 1.775 + 1.776 +function runTests() { 1.777 + let ioService = Cc["@mozilla.org/network/io-service;1"]. 1.778 + getService(Ci.nsIIOService); 1.779 + ok(true, "Running tests (isTabModal=" + isTabModal + ", usePromptService=" + usePromptService + ")"); 1.780 + 1.781 + let prompter, promptArgs; 1.782 + if (usePromptService) { 1.783 + prompter = Cc["@mozilla.org/embedcomp/prompt-service;1"]. 1.784 + getService(Ci.nsIPromptService2); 1.785 + } else { 1.786 + prompter = Cc["@mozilla.org/prompter;1"]. 1.787 + getService(Ci.nsIPromptFactory). 1.788 + getPrompt(window, Ci.nsIPrompt); 1.789 + if (isTabModal) { 1.790 + let bag = prompter.QueryInterface(Ci.nsIWritablePropertyBag2); 1.791 + bag.setPropertyAsBool("allowTabModal", true); 1.792 + } 1.793 + } 1.794 + 1.795 + let checkVal = {}; 1.796 + let textVal = {}; 1.797 + let passVal = {}; 1.798 + let flags; 1.799 + let isOK, clickedButton; 1.800 + 1.801 + testNum = 0; 1.802 + 1.803 + // ===== test 1 ===== 1.804 + // Alert 1.805 + testNum++; 1.806 + startCallbackTimer(); 1.807 + promptArgs = ["TestTitle", "This is the alert text."]; 1.808 + if (usePromptService) 1.809 + promptArgs.unshift(window); 1.810 + prompter.alert.apply(null, promptArgs); 1.811 + 1.812 + ok(didDialog, "handleDialog was invoked"); 1.813 + 1.814 + // ===== test 2 ===== 1.815 + // AlertCheck (null checkbox label) 1.816 + testNum++; 1.817 + startCallbackTimer(); 1.818 + promptArgs = ["TestTitle", "This is the alertCheck text.", null, {}]; 1.819 + if (usePromptService) 1.820 + promptArgs.unshift(window); 1.821 + prompter.alertCheck.apply(null, promptArgs); 1.822 + ok(didDialog, "handleDialog was invoked"); 1.823 + 1.824 + 1.825 + // ===== test 3 ===== 1.826 + // AlertCheck 1.827 + testNum++; 1.828 + startCallbackTimer(); 1.829 + checkVal.value = false; 1.830 + promptArgs = ["TestTitle", "This is the alertCheck text.", "Check me out!", checkVal]; 1.831 + if (usePromptService) 1.832 + promptArgs.unshift(window); 1.833 + prompter.alertCheck.apply(null, promptArgs); 1.834 + ok(didDialog, "handleDialog was invoked"); 1.835 + is(checkVal.value, true, "checkbox was checked"); 1.836 + 1.837 + 1.838 + // ===== test 4 ===== 1.839 + // Confirm (ok) 1.840 + testNum++; 1.841 + startCallbackTimer(); 1.842 + promptArgs = ["TestTitle", "This is the confirm text."]; 1.843 + if (usePromptService) 1.844 + promptArgs.unshift(window); 1.845 + isOK = prompter.confirm.apply(null, promptArgs); 1.846 + is(isOK, true, "checked expected retval"); 1.847 + ok(didDialog, "handleDialog was invoked"); 1.848 + 1.849 + // ===== test 5 ===== 1.850 + // Confirm (cancel) 1.851 + testNum++; 1.852 + startCallbackTimer(); 1.853 + promptArgs = ["TestTitle", "This is the confirm text."]; 1.854 + if (usePromptService) 1.855 + promptArgs.unshift(window); 1.856 + isOK = prompter.confirm.apply(null, promptArgs); 1.857 + is(isOK, false, "checked expected retval"); 1.858 + ok(didDialog, "handleDialog was invoked"); 1.859 + 1.860 + 1.861 + // ===== test 6 ===== 1.862 + // ConfirmCheck (ok, null checkbox label) 1.863 + testNum++; 1.864 + startCallbackTimer(); 1.865 + promptArgs = ["TestTitle", "This is the confirmCheck text.", null, {}]; 1.866 + if (usePromptService) 1.867 + promptArgs.unshift(window); 1.868 + isOK = prompter.confirmCheck.apply(null, promptArgs); 1.869 + is(isOK, true, "checked expected retval"); 1.870 + ok(didDialog, "handleDialog was invoked"); 1.871 + 1.872 + // ===== test 7 ===== 1.873 + // ConfirmCheck (cancel, null checkbox label) 1.874 + testNum++; 1.875 + startCallbackTimer(); 1.876 + promptArgs = ["TestTitle", "This is the confirmCheck text.", null, {}]; 1.877 + if (usePromptService) 1.878 + promptArgs.unshift(window); 1.879 + isOK = prompter.confirmCheck.apply(null, promptArgs); 1.880 + is(isOK, false, "checked expected retval"); 1.881 + ok(didDialog, "handleDialog was invoked"); 1.882 + 1.883 + // ===== test 8 ===== 1.884 + // ConfirmCheck (ok) 1.885 + testNum++; 1.886 + startCallbackTimer(); 1.887 + checkVal.value = false; 1.888 + promptArgs = ["TestTitle", "This is the confirmCheck text.", "Check me out!", checkVal]; 1.889 + if (usePromptService) 1.890 + promptArgs.unshift(window); 1.891 + isOK = prompter.confirmCheck.apply(null, promptArgs); 1.892 + is(isOK, true, "checked expected retval"); 1.893 + is(checkVal.value, true, "expected checkbox setting"); 1.894 + ok(didDialog, "handleDialog was invoked"); 1.895 + 1.896 + // ===== test 9 ===== 1.897 + // ConfirmCheck (cancel) 1.898 + testNum++; 1.899 + startCallbackTimer(); 1.900 + checkVal.value = false; 1.901 + promptArgs = ["TestTitle", "This is the confirmCheck text.", "Check me out!", checkVal]; 1.902 + if (usePromptService) 1.903 + promptArgs.unshift(window); 1.904 + isOK = prompter.confirmCheck.apply(null, promptArgs); 1.905 + is(isOK, false, "checked expected retval"); 1.906 + is(checkVal.value, true, "expected checkbox setting"); 1.907 + ok(didDialog, "handleDialog was invoked"); 1.908 + 1.909 + 1.910 + // ===== test 10 ===== 1.911 + // Prompt (ok, no default text) 1.912 + testNum++; 1.913 + startCallbackTimer(); 1.914 + textVal.value = ""; 1.915 + promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}]; 1.916 + if (usePromptService) 1.917 + promptArgs.unshift(window); 1.918 + isOK = prompter.prompt.apply(null, promptArgs); 1.919 + is(isOK, true, "checked expected retval"); 1.920 + is(textVal.value, "bacon", "checking expected text value"); 1.921 + ok(didDialog, "handleDialog was invoked"); 1.922 + 1.923 + // ===== test 11 ===== 1.924 + // Prompt (ok, default text) 1.925 + testNum++; 1.926 + startCallbackTimer(); 1.927 + textVal.value = "kittens"; 1.928 + promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}]; 1.929 + if (usePromptService) 1.930 + promptArgs.unshift(window); 1.931 + isOK = prompter.prompt.apply(null, promptArgs); 1.932 + is(isOK, true, "checked expected retval"); 1.933 + is(textVal.value, "kittens", "checking expected text value"); 1.934 + ok(didDialog, "handleDialog was invoked"); 1.935 + 1.936 + // ===== test 12 ===== 1.937 + // Prompt (cancel, default text) 1.938 + testNum++; 1.939 + startCallbackTimer(); 1.940 + textVal.value = "puppies"; 1.941 + promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}]; 1.942 + if (usePromptService) 1.943 + promptArgs.unshift(window); 1.944 + isOK = prompter.prompt.apply(null, promptArgs); 1.945 + is(isOK, false, "checked expected retval"); 1.946 + is(textVal.value, "puppies", "checking expected text value"); 1.947 + ok(didDialog, "handleDialog was invoked"); 1.948 + 1.949 + // ===== test 13 ===== 1.950 + // Prompt (cancel, default text modified) 1.951 + testNum++; 1.952 + startCallbackTimer(); 1.953 + textVal.value = "puppies"; 1.954 + promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}]; 1.955 + if (usePromptService) 1.956 + promptArgs.unshift(window); 1.957 + isOK = prompter.prompt.apply(null, promptArgs); 1.958 + is(isOK, false, "checked expected retval"); 1.959 + is(textVal.value, "puppies", "checking expected text value"); 1.960 + ok(didDialog, "handleDialog was invoked"); 1.961 + 1.962 + // ===== test 14 ===== 1.963 + // Prompt (ok, with checkbox) 1.964 + testNum++; 1.965 + startCallbackTimer(); 1.966 + textVal.value = "tribbles"; 1.967 + checkVal.value = false; 1.968 + promptArgs = ["TestTitle", "This is the prompt text.", textVal, "Check me out!", checkVal]; 1.969 + if (usePromptService) 1.970 + promptArgs.unshift(window); 1.971 + isOK = prompter.prompt.apply(null, promptArgs); 1.972 + is(isOK, true, "checked expected retval"); 1.973 + is(textVal.value, "tribbles", "checking expected text value"); 1.974 + is(checkVal.value, true, "expected checkbox setting"); 1.975 + ok(didDialog, "handleDialog was invoked"); 1.976 + 1.977 + // ===== test 15 ===== 1.978 + // Prompt (cancel, with checkbox) 1.979 + testNum++; 1.980 + startCallbackTimer(); 1.981 + textVal.value = "tribbles"; 1.982 + checkVal.value = false; 1.983 + promptArgs = ["TestTitle", "This is the prompt text.", textVal, "Check me out!", checkVal]; 1.984 + if (usePromptService) 1.985 + promptArgs.unshift(window); 1.986 + isOK = prompter.prompt.apply(null, promptArgs); 1.987 + is(isOK, false, "checked expected retval"); 1.988 + is(textVal.value, "tribbles", "checking expected text value"); 1.989 + is(checkVal.value, false, "expected checkbox setting"); 1.990 + ok(didDialog, "handleDialog was invoked"); 1.991 + 1.992 + 1.993 + // ===== test 16 ===== 1.994 + // PromptUsernameAndPassword (ok) 1.995 + // Just two tests for this, since password manager already tests this extensively. 1.996 + testNum++; 1.997 + startCallbackTimer(); 1.998 + textVal.value = "usr"; 1.999 + passVal.value = "ssh"; 1.1000 + checkVal.value = false; 1.1001 + promptArgs = ["TestTitle", "This is the pUAP text.", textVal, passVal, "Check me out!", checkVal]; 1.1002 + if (usePromptService) 1.1003 + promptArgs.unshift(window); 1.1004 + isOK = prompter.promptUsernameAndPassword.apply(null, promptArgs); 1.1005 + is(isOK, true, "checked expected retval"); 1.1006 + is(textVal.value, "newusr", "checking expected text value"); 1.1007 + is(passVal.value, "newssh", "checking expected pass value"); 1.1008 + is(checkVal.value, true, "expected checkbox setting"); 1.1009 + ok(didDialog, "handleDialog was invoked"); 1.1010 + 1.1011 + // ===== test 17 ===== 1.1012 + // PromptUsernameAndPassword (cancel) 1.1013 + testNum++; 1.1014 + startCallbackTimer(); 1.1015 + textVal.value = "usr"; 1.1016 + passVal.value = "ssh"; 1.1017 + checkVal.value = false; 1.1018 + promptArgs = ["TestTitle", "This is the pUAP text.", textVal, passVal, "Check me out!", checkVal]; 1.1019 + if (usePromptService) 1.1020 + promptArgs.unshift(window); 1.1021 + isOK = prompter.promptUsernameAndPassword.apply(null, promptArgs); 1.1022 + is(isOK, false, "checked expected retval"); 1.1023 + is(textVal.value, "usr", "checking expected text value"); 1.1024 + is(passVal.value, "ssh", "checking expected pass value"); 1.1025 + is(checkVal.value, false, "expected checkbox setting"); 1.1026 + ok(didDialog, "handleDialog was invoked"); 1.1027 + 1.1028 + 1.1029 + // ===== test 18 ===== 1.1030 + // PromptPassword (ok) 1.1031 + testNum++; 1.1032 + startCallbackTimer(); 1.1033 + passVal.value = "ssh"; 1.1034 + checkVal.value = false; 1.1035 + promptArgs = ["TestTitle", "This is the promptPassword text.", passVal, "Check me out!", checkVal]; 1.1036 + if (usePromptService) 1.1037 + promptArgs.unshift(window); 1.1038 + isOK = prompter.promptPassword.apply(null, promptArgs); 1.1039 + is(isOK, true, "checked expected retval"); 1.1040 + is(passVal.value, "newssh", "checking expected pass value"); 1.1041 + is(checkVal.value, true, "expected checkbox setting"); 1.1042 + ok(didDialog, "handleDialog was invoked"); 1.1043 + 1.1044 + // ===== test 19 ===== 1.1045 + // PromptPassword (cancel) 1.1046 + testNum++; 1.1047 + startCallbackTimer(); 1.1048 + passVal.value = "ssh"; 1.1049 + checkVal.value = false; 1.1050 + promptArgs = ["TestTitle", "This is the promptPassword text.", passVal, "Check me out!", checkVal]; 1.1051 + if (usePromptService) 1.1052 + promptArgs.unshift(window); 1.1053 + isOK = prompter.promptPassword.apply(null, promptArgs); 1.1054 + is(isOK, false, "checked expected retval"); 1.1055 + is(passVal.value, "ssh", "checking expected pass value"); 1.1056 + is(checkVal.value, false, "expected checkbox setting"); 1.1057 + ok(didDialog, "handleDialog was invoked"); 1.1058 + 1.1059 + // ===== test 20 ===== 1.1060 + // ConfirmEx (ok/cancel, ok) 1.1061 + testNum++; 1.1062 + startCallbackTimer(); 1.1063 + flags = Ci.nsIPromptService.STD_OK_CANCEL_BUTTONS; 1.1064 + promptArgs = ["TestTitle", "This is the confirmEx text.", flags, null, null, null, null, {}]; 1.1065 + if (usePromptService) 1.1066 + promptArgs.unshift(window); 1.1067 + clickedButton = prompter.confirmEx.apply(null, promptArgs); 1.1068 + is(clickedButton, 0, "checked expected button num click"); 1.1069 + ok(didDialog, "handleDialog was invoked"); 1.1070 + 1.1071 + // ===== test 21 ===== 1.1072 + // ConfirmEx (yes/no, cancel) 1.1073 + testNum++; 1.1074 + startCallbackTimer(); 1.1075 + flags = Ci.nsIPromptService.STD_YES_NO_BUTTONS; 1.1076 + promptArgs = ["TestTitle", "This is the confirmEx text.", flags, null, null, null, null, {}]; 1.1077 + if (usePromptService) 1.1078 + promptArgs.unshift(window); 1.1079 + clickedButton = prompter.confirmEx.apply(null, promptArgs); 1.1080 + is(clickedButton, 1, "checked expected button num click"); 1.1081 + ok(didDialog, "handleDialog was invoked"); 1.1082 + 1.1083 + // ===== test 22 ===== 1.1084 + // ConfirmEx (buttons from args, checkbox, ok) 1.1085 + testNum++; 1.1086 + startCallbackTimer(); 1.1087 + let b = Ci.nsIPromptService.BUTTON_TITLE_IS_STRING; 1.1088 + flags = b * Ci.nsIPromptService.BUTTON_POS_2 + 1.1089 + b * Ci.nsIPromptService.BUTTON_POS_1 + 1.1090 + b * Ci.nsIPromptService.BUTTON_POS_0; 1.1091 + checkVal.value = false; 1.1092 + promptArgs = ["TestTitle", "This is the confirmEx text.", flags, 1.1093 + "butt0", "butt1", "butt2", "Check me out!", checkVal]; 1.1094 + if (usePromptService) 1.1095 + promptArgs.unshift(window); 1.1096 + clickedButton = prompter.confirmEx.apply(null, promptArgs); 1.1097 + is(clickedButton, 0, "checked expected button num click"); 1.1098 + is(checkVal.value, true, "expected checkbox setting"); 1.1099 + ok(didDialog, "handleDialog was invoked"); 1.1100 + 1.1101 + // ===== test 23 ===== 1.1102 + // ConfirmEx (buttons from args, checkbox, cancel) 1.1103 + testNum++; 1.1104 + startCallbackTimer(); 1.1105 + let b = Ci.nsIPromptService.BUTTON_TITLE_IS_STRING; 1.1106 + flags = b * Ci.nsIPromptService.BUTTON_POS_2 + 1.1107 + b * Ci.nsIPromptService.BUTTON_POS_1 + 1.1108 + b * Ci.nsIPromptService.BUTTON_POS_0; 1.1109 + flags ^= Ci.nsIPromptService.BUTTON_POS_1_DEFAULT; 1.1110 + checkVal.value = false; 1.1111 + promptArgs = ["TestTitle", "This is the confirmEx text.", flags, 1.1112 + "butt0", "butt1", "butt2", "Check me out!", checkVal]; 1.1113 + if (usePromptService) 1.1114 + promptArgs.unshift(window); 1.1115 + clickedButton = prompter.confirmEx.apply(null, promptArgs); 1.1116 + is(clickedButton, 1, "checked expected button num click"); 1.1117 + is(checkVal.value, true, "expected checkbox setting"); 1.1118 + ok(didDialog, "handleDialog was invoked"); 1.1119 + 1.1120 + // ===== test 24 ===== 1.1121 + // ConfirmEx (buttons from args, checkbox, button3) 1.1122 + testNum++; 1.1123 + startCallbackTimer(); 1.1124 + let b = Ci.nsIPromptService.BUTTON_TITLE_IS_STRING; 1.1125 + flags = b * Ci.nsIPromptService.BUTTON_POS_2 + 1.1126 + b * Ci.nsIPromptService.BUTTON_POS_1 + 1.1127 + b * Ci.nsIPromptService.BUTTON_POS_0; 1.1128 + flags ^= Ci.nsIPromptService.BUTTON_POS_2_DEFAULT; 1.1129 + checkVal.value = false; 1.1130 + promptArgs = ["TestTitle", "This is the confirmEx text.", flags, 1.1131 + "butt0", "butt1", "butt2", "Check me out!", checkVal]; 1.1132 + if (usePromptService) 1.1133 + promptArgs.unshift(window); 1.1134 + clickedButton = prompter.confirmEx.apply(null, promptArgs); 1.1135 + is(clickedButton, 2, "checked expected button num click"); 1.1136 + is(checkVal.value, true, "expected checkbox setting"); 1.1137 + ok(didDialog, "handleDialog was invoked"); 1.1138 + 1.1139 + // ===== test 25 ===== 1.1140 + // Alert, no window 1.1141 + // (skipped for tabmodal tests: window is required) 1.1142 + testNum++; 1.1143 + if (!isTabModal) { 1.1144 + startCallbackTimer(); 1.1145 + promptArgs = ["TestTitle", "This is the alert text."]; 1.1146 + if (usePromptService) 1.1147 + promptArgs.unshift(null); 1.1148 + prompter.alert.apply(null, promptArgs); 1.1149 + ok(didDialog, "handleDialog was invoked"); 1.1150 + } 1.1151 + 1.1152 + 1.1153 + // ===== test 26 ===== 1.1154 + // ConfirmEx (delay, ok) 1.1155 + // (skipped for tabmodal tests: delay not supported) 1.1156 + testNum++; 1.1157 + if (!isTabModal) { 1.1158 + startCallbackTimer(); 1.1159 + flags = (Ci.nsIPromptService.STD_OK_CANCEL_BUTTONS | Ci.nsIPromptService.BUTTON_DELAY_ENABLE); 1.1160 + promptArgs = ["TestTitle", "This is the confirmEx delay text.", flags, null, null, null, null, {}]; 1.1161 + if (usePromptService) 1.1162 + promptArgs.unshift(window); 1.1163 + clickedButton = prompter.confirmEx.apply(null, promptArgs); 1.1164 + is(clickedButton, 0, "checked expected button num click"); 1.1165 + ok(didDialog, "handleDialog was invoked"); 1.1166 + } 1.1167 + 1.1168 + // promptAuth already tested via password manager but do a few specific things here. 1.1169 + 1.1170 + 1.1171 + var channel = ioService.newChannel("http://example.com", null, null); 1.1172 + var level = Ci.nsIAuthPrompt2.LEVEL_NONE; 1.1173 + var authinfo = { 1.1174 + username : "", 1.1175 + password : "", 1.1176 + domain : "", 1.1177 + flags : Ci.nsIAuthInformation.AUTH_HOST, 1.1178 + authenticationScheme : "basic", 1.1179 + realm : "" 1.1180 + }; 1.1181 + 1.1182 + // ===== test 100 ===== 1.1183 + // promptAuth with empty realm 1.1184 + // (promptAuth is only accessible from the prompt service) 1.1185 + testNum = 100; 1.1186 + if (usePromptService) { 1.1187 + startCallbackTimer(); 1.1188 + checkVal.value = false; 1.1189 + isOK = prompter.promptAuth(window, channel, level, authinfo, "Check me out!", checkVal); 1.1190 + is(isOK, true, "checked expected retval"); 1.1191 + is(authinfo.username, "username", "checking filled username"); 1.1192 + is(authinfo.password, "password", "checking filled password"); 1.1193 + is(checkVal.value, true, "expected checkbox setting"); 1.1194 + ok(didDialog, "handleDialog was invoked"); 1.1195 + } 1.1196 + 1.1197 + // ===== test 101 ===== 1.1198 + // promptAuth with long realm 1.1199 + // (promptAuth is only accessible from the prompt service) 1.1200 + testNum++; 1.1201 + if (usePromptService) { 1.1202 + startCallbackTimer(); 1.1203 + checkVal.value = false; 1.1204 + var longString = ""; 1.1205 + for (var i = 0; i < 20; i++) 1.1206 + longString += "abcdefghi "; // 200 chars long 1.1207 + authinfo.realm = longString; 1.1208 + authinfo.username = ""; 1.1209 + authinfo.password = ""; 1.1210 + isOK = prompter.promptAuth(window, channel, level, authinfo, "Check me out!", checkVal); 1.1211 + is(isOK, true, "checked expected retval"); 1.1212 + is(authinfo.username, "username", "checking filled username"); 1.1213 + is(authinfo.password, "password", "checking filled password"); 1.1214 + is(checkVal.value, true, "expected checkbox setting"); 1.1215 + ok(didDialog, "handleDialog was invoked"); 1.1216 + } 1.1217 +} 1.1218 + 1.1219 +let testNum; 1.1220 +let pollTimer; 1.1221 + 1.1222 +/* 1.1223 + * Run the body of the 3 times: 1.1224 + * - 1st pass: with window-modal prompts, using nsIPromptService 1.1225 + * - 2nd pass: still window-modal, using nsIPrompt directly (via nsIPromptFactory) 1.1226 + * - 3rd pass: with tab-modal prompts. Can't opt into these via * nsIPromptService. 1.1227 + */ 1.1228 + 1.1229 +isTabModal = false; usePromptService = true; 1.1230 +runTests(); 1.1231 + 1.1232 +isTabModal = false; usePromptService = false; 1.1233 +runTests(); 1.1234 + 1.1235 +if (getTabModalPromptBox(window)) { 1.1236 + isTabModal = true; usePromptService = false; 1.1237 + runTests(); 1.1238 +} 1.1239 + 1.1240 +</script> 1.1241 +</pre> 1.1242 +</body> 1.1243 +</html>