Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Modal Prompts Test</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="prompt_common.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | Prompter tests: modal prompts |
michael@0 | 11 | <p id="display"></p> |
michael@0 | 12 | |
michael@0 | 13 | <div id="content" style="display: none"> |
michael@0 | 14 | <iframe id="iframe"></iframe> |
michael@0 | 15 | </div> |
michael@0 | 16 | |
michael@0 | 17 | <pre id="test"> |
michael@0 | 18 | <script class="testbody" type="text/javascript;version=1.8"> |
michael@0 | 19 | |
michael@0 | 20 | var isOSX = ("nsILocalFileMac" in SpecialPowers.Ci); |
michael@0 | 21 | var isLinux = ("@mozilla.org/gnome-gconf-service;1" in SpecialPowers.Cc); |
michael@0 | 22 | |
michael@0 | 23 | function pollDialog(okButton) { |
michael@0 | 24 | if (okButton.disabled) |
michael@0 | 25 | return; |
michael@0 | 26 | |
michael@0 | 27 | ok(true, "dialog button is enabled now"); |
michael@0 | 28 | pollTimer.cancel(); |
michael@0 | 29 | pollTimer = null; |
michael@0 | 30 | okButton.click(); |
michael@0 | 31 | didDialog = true; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function checkExpectedState(ui, state) { |
michael@0 | 35 | |
michael@0 | 36 | // XXX check title? OS X has title in content |
michael@0 | 37 | is(ui.infoBody.textContent, state.msg, "Checking expected message"); |
michael@0 | 38 | is(ui.loginContainer.hidden, state.textHidden, "Checking textbox visibility"); |
michael@0 | 39 | is(ui.password1Container.hidden, state.passHidden, "Checking passbox visibility"); |
michael@0 | 40 | is(ui.checkboxContainer.hidden, state.checkHidden, "Checking checkbox visibility"); |
michael@0 | 41 | is(ui.checkbox.label, state.checkMsg, "Checking checkbox label"); |
michael@0 | 42 | is(ui.checkbox.checked, state.checked, "Checking checkbox checked"); |
michael@0 | 43 | if (!isTabModal) |
michael@0 | 44 | is(ui.infoIcon.className, "spaced " + state.iconClass, "Checking expected icon CSS class"); |
michael@0 | 45 | is(ui.loginTextbox.getAttribute("value"), state.textValue, "Checking textbox value"); |
michael@0 | 46 | is(ui.password1Textbox.getAttribute("value"), state.passValue, "Checking passbox value"); |
michael@0 | 47 | |
michael@0 | 48 | |
michael@0 | 49 | function isDefaultButton(b) { |
michael@0 | 50 | return (b.hasAttribute("default") && |
michael@0 | 51 | b.getAttribute("default") == "true"); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | let shouldBeDefault; |
michael@0 | 55 | shouldBeDefault = SpecialPowers.compare(state.defButton, ui.button0); |
michael@0 | 56 | is(isDefaultButton(ui.button0), shouldBeDefault, "checking button0 default"); |
michael@0 | 57 | shouldBeDefault = SpecialPowers.compare(state.defButton, ui.button1); |
michael@0 | 58 | is(isDefaultButton(ui.button1), shouldBeDefault, "checking button1 default"); |
michael@0 | 59 | shouldBeDefault = SpecialPowers.compare(state.defButton, ui.button2); |
michael@0 | 60 | is(isDefaultButton(ui.button2), shouldBeDefault, "checking button2 default"); |
michael@0 | 61 | |
michael@0 | 62 | let fm = Cc["@mozilla.org/focus-manager;1"]. |
michael@0 | 63 | getService(Ci.nsIFocusManager); |
michael@0 | 64 | let e = fm.focusedElement; |
michael@0 | 65 | ok(true, "focused element is a " + (e ? e.localName : "<null>")); |
michael@0 | 66 | if (isLinux && !e) { |
michael@0 | 67 | todo(false, "Focus seems missing on Linux"); |
michael@0 | 68 | return; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | if (isOSX && state.focused && state.focused.localName == "button") |
michael@0 | 72 | ok(SpecialPowers.compare(ui.infoBody, e), "buttons don't focus on OS X"); |
michael@0 | 73 | else if (state.focused) |
michael@0 | 74 | ok(SpecialPowers.compare(state.focused, e), "Checking focused element"); |
michael@0 | 75 | else |
michael@0 | 76 | is(e, null, "Not expecting a focused element"); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | |
michael@0 | 80 | /* |
michael@0 | 81 | * handleDialog |
michael@0 | 82 | * |
michael@0 | 83 | * Invoked a short period of time after calling startCallbackTimer(), and |
michael@0 | 84 | * allows testing the actual prompt dialog while it's being displayed. Tests |
michael@0 | 85 | * should call startCallbackTimer() each time the auth dialog is expected (the |
michael@0 | 86 | * timer is a one-shot). |
michael@0 | 87 | */ |
michael@0 | 88 | function handleDialog(ui, testNum) { |
michael@0 | 89 | ok(true, "--- handleDialog for test " + testNum + |
michael@0 | 90 | " --- (isTabModal=" + isTabModal + ", usePromptService=" + usePromptService + ")"); |
michael@0 | 91 | |
michael@0 | 92 | let textField = ui.loginTextbox; |
michael@0 | 93 | let passField = ui.password1Textbox; |
michael@0 | 94 | let checkbox = ui.checkbox; |
michael@0 | 95 | let clickOK = true; |
michael@0 | 96 | let state; |
michael@0 | 97 | |
michael@0 | 98 | switch(testNum) { |
michael@0 | 99 | case 1: |
michael@0 | 100 | // Alert |
michael@0 | 101 | state = { |
michael@0 | 102 | msg : "This is the alert text.", |
michael@0 | 103 | title : "TestTitle", |
michael@0 | 104 | iconClass : "alert-icon", |
michael@0 | 105 | textHidden : true, |
michael@0 | 106 | passHidden : true, |
michael@0 | 107 | checkHidden : true, |
michael@0 | 108 | textValue : "", |
michael@0 | 109 | passValue : "", |
michael@0 | 110 | checkMsg : "", |
michael@0 | 111 | checked : false, |
michael@0 | 112 | focused : ui.button0, |
michael@0 | 113 | defButton : ui.button0, |
michael@0 | 114 | }; |
michael@0 | 115 | checkExpectedState(ui, state); |
michael@0 | 116 | break; |
michael@0 | 117 | |
michael@0 | 118 | case 2: |
michael@0 | 119 | // AlertCheck (null checkbox label, so it's hidden) |
michael@0 | 120 | state = { |
michael@0 | 121 | msg : "This is the alertCheck text.", |
michael@0 | 122 | title : "TestTitle", |
michael@0 | 123 | iconClass : "alert-icon", |
michael@0 | 124 | textHidden : true, |
michael@0 | 125 | passHidden : true, |
michael@0 | 126 | checkHidden : true, |
michael@0 | 127 | textValue : "", |
michael@0 | 128 | passValue : "", |
michael@0 | 129 | checkMsg : "", |
michael@0 | 130 | checked : false, |
michael@0 | 131 | focused : ui.button0, |
michael@0 | 132 | defButton : ui.button0, |
michael@0 | 133 | }; |
michael@0 | 134 | checkExpectedState(ui, state); |
michael@0 | 135 | break; |
michael@0 | 136 | |
michael@0 | 137 | case 3: |
michael@0 | 138 | // AlertCheck |
michael@0 | 139 | state = { |
michael@0 | 140 | msg : "This is the alertCheck text.", |
michael@0 | 141 | title : "TestTitle", |
michael@0 | 142 | iconClass : "alert-icon", |
michael@0 | 143 | textHidden : true, |
michael@0 | 144 | passHidden : true, |
michael@0 | 145 | checkHidden : false, |
michael@0 | 146 | textValue : "", |
michael@0 | 147 | passValue : "", |
michael@0 | 148 | checkMsg : "Check me out!", |
michael@0 | 149 | checked : false, |
michael@0 | 150 | focused : ui.button0, |
michael@0 | 151 | defButton : ui.button0, |
michael@0 | 152 | }; |
michael@0 | 153 | checkExpectedState(ui, state); |
michael@0 | 154 | |
michael@0 | 155 | // XXX dumb. old code driven by oncommand. |
michael@0 | 156 | checkbox.setChecked(true); |
michael@0 | 157 | checkbox.doCommand(); |
michael@0 | 158 | break; |
michael@0 | 159 | |
michael@0 | 160 | case 4: |
michael@0 | 161 | // Confirm (ok) |
michael@0 | 162 | state = { |
michael@0 | 163 | msg : "This is the confirm text.", |
michael@0 | 164 | title : "TestTitle", |
michael@0 | 165 | iconClass : "question-icon", |
michael@0 | 166 | textHidden : true, |
michael@0 | 167 | passHidden : true, |
michael@0 | 168 | checkHidden : true, |
michael@0 | 169 | textValue : "", |
michael@0 | 170 | passValue : "", |
michael@0 | 171 | checkMsg : "", |
michael@0 | 172 | checked : false, |
michael@0 | 173 | focused : ui.button0, |
michael@0 | 174 | defButton : ui.button0, |
michael@0 | 175 | }; |
michael@0 | 176 | checkExpectedState(ui, state); |
michael@0 | 177 | break; |
michael@0 | 178 | |
michael@0 | 179 | case 5: |
michael@0 | 180 | // Confirm (cancel) |
michael@0 | 181 | state = { |
michael@0 | 182 | msg : "This is the confirm text.", |
michael@0 | 183 | title : "TestTitle", |
michael@0 | 184 | iconClass : "question-icon", |
michael@0 | 185 | textHidden : true, |
michael@0 | 186 | passHidden : true, |
michael@0 | 187 | checkHidden : true, |
michael@0 | 188 | textValue : "", |
michael@0 | 189 | passValue : "", |
michael@0 | 190 | checkMsg : "", |
michael@0 | 191 | checked : false, |
michael@0 | 192 | focused : ui.button0, |
michael@0 | 193 | defButton : ui.button0, |
michael@0 | 194 | }; |
michael@0 | 195 | checkExpectedState(ui, state); |
michael@0 | 196 | clickOK = false; |
michael@0 | 197 | break; |
michael@0 | 198 | |
michael@0 | 199 | case 6: |
michael@0 | 200 | // ConfirmCheck (no checkbox, ok) |
michael@0 | 201 | state = { |
michael@0 | 202 | msg : "This is the confirmCheck text.", |
michael@0 | 203 | title : "TestTitle", |
michael@0 | 204 | iconClass : "question-icon", |
michael@0 | 205 | textHidden : true, |
michael@0 | 206 | passHidden : true, |
michael@0 | 207 | checkHidden : true, |
michael@0 | 208 | textValue : "", |
michael@0 | 209 | passValue : "", |
michael@0 | 210 | checkMsg : "", |
michael@0 | 211 | checked : false, |
michael@0 | 212 | focused : ui.button0, |
michael@0 | 213 | defButton : ui.button0, |
michael@0 | 214 | }; |
michael@0 | 215 | checkExpectedState(ui, state); |
michael@0 | 216 | break; |
michael@0 | 217 | |
michael@0 | 218 | case 7: |
michael@0 | 219 | // ConfirmCheck (no checkbox, cancel) |
michael@0 | 220 | state = { |
michael@0 | 221 | msg : "This is the confirmCheck text.", |
michael@0 | 222 | title : "TestTitle", |
michael@0 | 223 | iconClass : "question-icon", |
michael@0 | 224 | textHidden : true, |
michael@0 | 225 | passHidden : true, |
michael@0 | 226 | checkHidden : true, |
michael@0 | 227 | textValue : "", |
michael@0 | 228 | passValue : "", |
michael@0 | 229 | checkMsg : "", |
michael@0 | 230 | checked : false, |
michael@0 | 231 | focused : ui.button0, |
michael@0 | 232 | defButton : ui.button0, |
michael@0 | 233 | }; |
michael@0 | 234 | checkExpectedState(ui, state); |
michael@0 | 235 | clickOK = false; |
michael@0 | 236 | break; |
michael@0 | 237 | |
michael@0 | 238 | case 8: |
michael@0 | 239 | // ConfirmCheck (ok) |
michael@0 | 240 | state = { |
michael@0 | 241 | msg : "This is the confirmCheck text.", |
michael@0 | 242 | title : "TestTitle", |
michael@0 | 243 | iconClass : "question-icon", |
michael@0 | 244 | textHidden : true, |
michael@0 | 245 | passHidden : true, |
michael@0 | 246 | checkHidden : false, |
michael@0 | 247 | textValue : "", |
michael@0 | 248 | passValue : "", |
michael@0 | 249 | checkMsg : "Check me out!", |
michael@0 | 250 | checked : false, |
michael@0 | 251 | focused : ui.button0, |
michael@0 | 252 | defButton : ui.button0, |
michael@0 | 253 | }; |
michael@0 | 254 | checkExpectedState(ui, state); |
michael@0 | 255 | |
michael@0 | 256 | // XXX dumb. old code driven by oncommand. |
michael@0 | 257 | checkbox.setChecked(true); |
michael@0 | 258 | checkbox.doCommand(); |
michael@0 | 259 | break; |
michael@0 | 260 | |
michael@0 | 261 | case 9: |
michael@0 | 262 | // ConfirmCheck (cancel) |
michael@0 | 263 | state = { |
michael@0 | 264 | msg : "This is the confirmCheck text.", |
michael@0 | 265 | title : "TestTitle", |
michael@0 | 266 | iconClass : "question-icon", |
michael@0 | 267 | textHidden : true, |
michael@0 | 268 | passHidden : true, |
michael@0 | 269 | checkHidden : false, |
michael@0 | 270 | textValue : "", |
michael@0 | 271 | passValue : "", |
michael@0 | 272 | checkMsg : "Check me out!", |
michael@0 | 273 | checked : false, |
michael@0 | 274 | focused : ui.button0, |
michael@0 | 275 | defButton : ui.button0, |
michael@0 | 276 | }; |
michael@0 | 277 | checkExpectedState(ui, state); |
michael@0 | 278 | |
michael@0 | 279 | clickOK = false; |
michael@0 | 280 | // XXX dumb. old code driven by oncommand. |
michael@0 | 281 | checkbox.setChecked(true); |
michael@0 | 282 | checkbox.doCommand(); |
michael@0 | 283 | break; |
michael@0 | 284 | |
michael@0 | 285 | case 10: |
michael@0 | 286 | // Prompt (ok, no default text) |
michael@0 | 287 | state = { |
michael@0 | 288 | msg : "This is the prompt text.", |
michael@0 | 289 | title : "TestTitle", |
michael@0 | 290 | iconClass : "question-icon", |
michael@0 | 291 | textHidden : false, |
michael@0 | 292 | passHidden : true, |
michael@0 | 293 | checkHidden : true, |
michael@0 | 294 | textValue : "", |
michael@0 | 295 | passValue : "", |
michael@0 | 296 | checkMsg : "", |
michael@0 | 297 | checked : false, |
michael@0 | 298 | focused : ui.loginTextbox.inputField, |
michael@0 | 299 | defButton : ui.button0, |
michael@0 | 300 | }; |
michael@0 | 301 | checkExpectedState(ui, state); |
michael@0 | 302 | textField.setAttribute("value", "bacon"); |
michael@0 | 303 | break; |
michael@0 | 304 | |
michael@0 | 305 | case 11: |
michael@0 | 306 | // Prompt (ok, default text) |
michael@0 | 307 | state = { |
michael@0 | 308 | msg : "This is the prompt text.", |
michael@0 | 309 | title : "TestTitle", |
michael@0 | 310 | iconClass : "question-icon", |
michael@0 | 311 | textHidden : false, |
michael@0 | 312 | passHidden : true, |
michael@0 | 313 | checkHidden : true, |
michael@0 | 314 | textValue : "kittens", |
michael@0 | 315 | passValue : "", |
michael@0 | 316 | checkMsg : "", |
michael@0 | 317 | checked : false, |
michael@0 | 318 | focused : ui.loginTextbox.inputField, |
michael@0 | 319 | defButton : ui.button0, |
michael@0 | 320 | }; |
michael@0 | 321 | checkExpectedState(ui, state); |
michael@0 | 322 | break; |
michael@0 | 323 | |
michael@0 | 324 | case 12: |
michael@0 | 325 | // Prompt (cancel, default text) |
michael@0 | 326 | state = { |
michael@0 | 327 | msg : "This is the prompt text.", |
michael@0 | 328 | title : "TestTitle", |
michael@0 | 329 | iconClass : "question-icon", |
michael@0 | 330 | textHidden : false, |
michael@0 | 331 | passHidden : true, |
michael@0 | 332 | checkHidden : true, |
michael@0 | 333 | textValue : "puppies", |
michael@0 | 334 | passValue : "", |
michael@0 | 335 | checkMsg : "", |
michael@0 | 336 | checked : false, |
michael@0 | 337 | focused : ui.loginTextbox.inputField, |
michael@0 | 338 | defButton : ui.button0, |
michael@0 | 339 | }; |
michael@0 | 340 | checkExpectedState(ui, state); |
michael@0 | 341 | clickOK = false; |
michael@0 | 342 | break; |
michael@0 | 343 | |
michael@0 | 344 | case 13: |
michael@0 | 345 | // Prompt (cancel, default text modified) |
michael@0 | 346 | state = { |
michael@0 | 347 | msg : "This is the prompt text.", |
michael@0 | 348 | title : "TestTitle", |
michael@0 | 349 | iconClass : "question-icon", |
michael@0 | 350 | textHidden : false, |
michael@0 | 351 | passHidden : true, |
michael@0 | 352 | checkHidden : true, |
michael@0 | 353 | textValue : "puppies", |
michael@0 | 354 | passValue : "", |
michael@0 | 355 | checkMsg : "", |
michael@0 | 356 | checked : false, |
michael@0 | 357 | focused : ui.loginTextbox.inputField, |
michael@0 | 358 | defButton : ui.button0, |
michael@0 | 359 | }; |
michael@0 | 360 | checkExpectedState(ui, state); |
michael@0 | 361 | textField.setAttribute("value", "bacon"); |
michael@0 | 362 | clickOK = false; |
michael@0 | 363 | break; |
michael@0 | 364 | |
michael@0 | 365 | case 14: |
michael@0 | 366 | // Prompt (ok, with checkbox) |
michael@0 | 367 | state = { |
michael@0 | 368 | msg : "This is the prompt text.", |
michael@0 | 369 | title : "TestTitle", |
michael@0 | 370 | iconClass : "question-icon", |
michael@0 | 371 | textHidden : false, |
michael@0 | 372 | passHidden : true, |
michael@0 | 373 | checkHidden : false, |
michael@0 | 374 | textValue : "tribbles", |
michael@0 | 375 | passValue : "", |
michael@0 | 376 | checkMsg : "Check me out!", |
michael@0 | 377 | checked : false, |
michael@0 | 378 | focused : ui.loginTextbox.inputField, |
michael@0 | 379 | defButton : ui.button0, |
michael@0 | 380 | }; |
michael@0 | 381 | checkExpectedState(ui, state); |
michael@0 | 382 | |
michael@0 | 383 | // XXX dumb. old code driven by oncommand. |
michael@0 | 384 | checkbox.setChecked(true); |
michael@0 | 385 | checkbox.doCommand(); |
michael@0 | 386 | break; |
michael@0 | 387 | |
michael@0 | 388 | case 15: |
michael@0 | 389 | // Prompt (cancel, with checkbox) |
michael@0 | 390 | state = { |
michael@0 | 391 | msg : "This is the prompt text.", |
michael@0 | 392 | title : "TestTitle", |
michael@0 | 393 | iconClass : "question-icon", |
michael@0 | 394 | textHidden : false, |
michael@0 | 395 | passHidden : true, |
michael@0 | 396 | checkHidden : false, |
michael@0 | 397 | textValue : "tribbles", |
michael@0 | 398 | passValue : "", |
michael@0 | 399 | checkMsg : "Check me out!", |
michael@0 | 400 | checked : false, |
michael@0 | 401 | focused : ui.loginTextbox.inputField, |
michael@0 | 402 | defButton : ui.button0, |
michael@0 | 403 | }; |
michael@0 | 404 | checkExpectedState(ui, state); |
michael@0 | 405 | |
michael@0 | 406 | clickOK = false; |
michael@0 | 407 | // XXX dumb. old code driven by oncommand. |
michael@0 | 408 | checkbox.setChecked(true); |
michael@0 | 409 | checkbox.doCommand(); |
michael@0 | 410 | break; |
michael@0 | 411 | |
michael@0 | 412 | case 16: |
michael@0 | 413 | // PromptUsernameAndPassword (ok, with checkbox) |
michael@0 | 414 | state = { |
michael@0 | 415 | msg : "This is the pUAP text.", |
michael@0 | 416 | title : "TestTitle", |
michael@0 | 417 | iconClass : "authentication-icon question-icon", |
michael@0 | 418 | textHidden : false, |
michael@0 | 419 | passHidden : false, |
michael@0 | 420 | checkHidden : false, |
michael@0 | 421 | textValue : "usr", |
michael@0 | 422 | passValue : "ssh", |
michael@0 | 423 | checkMsg : "Check me out!", |
michael@0 | 424 | checked : false, |
michael@0 | 425 | focused : ui.loginTextbox.inputField, |
michael@0 | 426 | defButton : ui.button0, |
michael@0 | 427 | }; |
michael@0 | 428 | checkExpectedState(ui, state); |
michael@0 | 429 | |
michael@0 | 430 | textField.setAttribute("value", "newusr"); |
michael@0 | 431 | passField.setAttribute("value", "newssh"); |
michael@0 | 432 | // XXX dumb. old code driven by oncommand. |
michael@0 | 433 | checkbox.setChecked(true); |
michael@0 | 434 | checkbox.doCommand(); |
michael@0 | 435 | break; |
michael@0 | 436 | |
michael@0 | 437 | case 17: |
michael@0 | 438 | // PromptUsernameAndPassword (cancel, with checkbox) |
michael@0 | 439 | state = { |
michael@0 | 440 | msg : "This is the pUAP text.", |
michael@0 | 441 | title : "TestTitle", |
michael@0 | 442 | iconClass : "authentication-icon question-icon", |
michael@0 | 443 | textHidden : false, |
michael@0 | 444 | passHidden : false, |
michael@0 | 445 | checkHidden : false, |
michael@0 | 446 | textValue : "usr", |
michael@0 | 447 | passValue : "ssh", |
michael@0 | 448 | checkMsg : "Check me out!", |
michael@0 | 449 | checked : false, |
michael@0 | 450 | focused : ui.loginTextbox.inputField, |
michael@0 | 451 | defButton : ui.button0, |
michael@0 | 452 | }; |
michael@0 | 453 | checkExpectedState(ui, state); |
michael@0 | 454 | |
michael@0 | 455 | textField.setAttribute("value", "newusr"); |
michael@0 | 456 | passField.setAttribute("value", "newssh"); |
michael@0 | 457 | // XXX dumb. old code driven by oncommand. |
michael@0 | 458 | checkbox.setChecked(true); |
michael@0 | 459 | checkbox.doCommand(); |
michael@0 | 460 | |
michael@0 | 461 | clickOK = false; |
michael@0 | 462 | break; |
michael@0 | 463 | |
michael@0 | 464 | case 18: |
michael@0 | 465 | // PromptPassword (ok, with checkbox) |
michael@0 | 466 | state = { |
michael@0 | 467 | msg : "This is the promptPassword text.", |
michael@0 | 468 | title : "TestTitle", |
michael@0 | 469 | iconClass : "authentication-icon question-icon", |
michael@0 | 470 | textHidden : true, |
michael@0 | 471 | passHidden : false, |
michael@0 | 472 | checkHidden : false, |
michael@0 | 473 | textValue : "", |
michael@0 | 474 | passValue : "ssh", |
michael@0 | 475 | checkMsg : "Check me out!", |
michael@0 | 476 | checked : false, |
michael@0 | 477 | focused : ui.password1Textbox.inputField, |
michael@0 | 478 | defButton : ui.button0, |
michael@0 | 479 | }; |
michael@0 | 480 | checkExpectedState(ui, state); |
michael@0 | 481 | |
michael@0 | 482 | passField.setAttribute("value", "newssh"); |
michael@0 | 483 | // XXX dumb. old code driven by oncommand. |
michael@0 | 484 | checkbox.setChecked(true); |
michael@0 | 485 | checkbox.doCommand(); |
michael@0 | 486 | break; |
michael@0 | 487 | |
michael@0 | 488 | case 19: |
michael@0 | 489 | // PromptPassword (cancel, with checkbox) |
michael@0 | 490 | state = { |
michael@0 | 491 | msg : "This is the promptPassword text.", |
michael@0 | 492 | title : "TestTitle", |
michael@0 | 493 | iconClass : "authentication-icon question-icon", |
michael@0 | 494 | textHidden : true, |
michael@0 | 495 | passHidden : false, |
michael@0 | 496 | checkHidden : false, |
michael@0 | 497 | textValue : "", |
michael@0 | 498 | passValue : "ssh", |
michael@0 | 499 | checkMsg : "Check me out!", |
michael@0 | 500 | checked : false, |
michael@0 | 501 | focused : ui.password1Textbox.inputField, |
michael@0 | 502 | defButton : ui.button0, |
michael@0 | 503 | }; |
michael@0 | 504 | checkExpectedState(ui, state); |
michael@0 | 505 | |
michael@0 | 506 | passField.setAttribute("value", "newssh"); |
michael@0 | 507 | // XXX dumb. old code driven by oncommand. |
michael@0 | 508 | checkbox.setChecked(true); |
michael@0 | 509 | checkbox.doCommand(); |
michael@0 | 510 | |
michael@0 | 511 | clickOK = false; |
michael@0 | 512 | break; |
michael@0 | 513 | |
michael@0 | 514 | case 20: |
michael@0 | 515 | // ConfirmEx (ok/cancel, ok) |
michael@0 | 516 | state = { |
michael@0 | 517 | msg : "This is the confirmEx text.", |
michael@0 | 518 | title : "TestTitle", |
michael@0 | 519 | iconClass : "question-icon", |
michael@0 | 520 | textHidden : true, |
michael@0 | 521 | passHidden : true, |
michael@0 | 522 | checkHidden : true, |
michael@0 | 523 | textValue : "", |
michael@0 | 524 | passValue : "", |
michael@0 | 525 | checkMsg : "", |
michael@0 | 526 | checked : false, |
michael@0 | 527 | focused : ui.button0, |
michael@0 | 528 | defButton : ui.button0, |
michael@0 | 529 | }; |
michael@0 | 530 | is(ui.button0.label, "OK", "Checking accept-button label"); |
michael@0 | 531 | is(ui.button1.label, "Cancel", "Checking cancel-button label"); |
michael@0 | 532 | checkExpectedState(ui, state); |
michael@0 | 533 | break; |
michael@0 | 534 | |
michael@0 | 535 | case 21: |
michael@0 | 536 | // ConfirmEx (yes/no, cancel) |
michael@0 | 537 | state = { |
michael@0 | 538 | msg : "This is the confirmEx text.", |
michael@0 | 539 | title : "TestTitle", |
michael@0 | 540 | iconClass : "question-icon", |
michael@0 | 541 | textHidden : true, |
michael@0 | 542 | passHidden : true, |
michael@0 | 543 | checkHidden : true, |
michael@0 | 544 | textValue : "", |
michael@0 | 545 | passValue : "", |
michael@0 | 546 | checkMsg : "", |
michael@0 | 547 | checked : false, |
michael@0 | 548 | focused : ui.button0, |
michael@0 | 549 | defButton : ui.button0, |
michael@0 | 550 | }; |
michael@0 | 551 | is(ui.button0.label, "Yes", "Checking accept-button label"); |
michael@0 | 552 | is(ui.button1.label, "No", "Checking cancel-button label"); |
michael@0 | 553 | checkExpectedState(ui, state); |
michael@0 | 554 | clickOK = false; |
michael@0 | 555 | break; |
michael@0 | 556 | |
michael@0 | 557 | case 22: |
michael@0 | 558 | // ConfirmEx (buttons from args, checkbox, ok) |
michael@0 | 559 | state = { |
michael@0 | 560 | msg : "This is the confirmEx text.", |
michael@0 | 561 | title : "TestTitle", |
michael@0 | 562 | iconClass : "question-icon", |
michael@0 | 563 | textHidden : true, |
michael@0 | 564 | passHidden : true, |
michael@0 | 565 | checkHidden : false, |
michael@0 | 566 | textValue : "", |
michael@0 | 567 | passValue : "", |
michael@0 | 568 | checkMsg : "Check me out!", |
michael@0 | 569 | checked : false, |
michael@0 | 570 | focused : ui.button0, |
michael@0 | 571 | defButton : ui.button0, |
michael@0 | 572 | }; |
michael@0 | 573 | is(ui.button0.label, "butt0", "Checking accept-button label"); |
michael@0 | 574 | is(ui.button1.label, "butt1", "Checking cancel-button label"); |
michael@0 | 575 | is(ui.button2.label, "butt2", "Checking extra1-button label"); |
michael@0 | 576 | checkExpectedState(ui, state); |
michael@0 | 577 | |
michael@0 | 578 | // XXX dumb. old code driven by oncommand. |
michael@0 | 579 | checkbox.setChecked(true); |
michael@0 | 580 | checkbox.doCommand(); |
michael@0 | 581 | break; |
michael@0 | 582 | |
michael@0 | 583 | case 23: |
michael@0 | 584 | // ConfirmEx (buttons from args, checkbox, cancel) |
michael@0 | 585 | state = { |
michael@0 | 586 | msg : "This is the confirmEx text.", |
michael@0 | 587 | title : "TestTitle", |
michael@0 | 588 | iconClass : "question-icon", |
michael@0 | 589 | textHidden : true, |
michael@0 | 590 | passHidden : true, |
michael@0 | 591 | checkHidden : false, |
michael@0 | 592 | textValue : "", |
michael@0 | 593 | passValue : "", |
michael@0 | 594 | checkMsg : "Check me out!", |
michael@0 | 595 | checked : false, |
michael@0 | 596 | focused : ui.button1, // Default changed! |
michael@0 | 597 | defButton : ui.button1, |
michael@0 | 598 | }; |
michael@0 | 599 | // XXX check button1 is default |
michael@0 | 600 | is(ui.button0.label, "butt0", "Checking accept-button label"); |
michael@0 | 601 | is(ui.button1.label, "butt1", "Checking cancel-button label"); |
michael@0 | 602 | is(ui.button2.label, "butt2", "Checking extra1-button label"); |
michael@0 | 603 | checkExpectedState(ui, state); |
michael@0 | 604 | |
michael@0 | 605 | // XXX dumb. old code driven by oncommand. |
michael@0 | 606 | checkbox.setChecked(true); |
michael@0 | 607 | checkbox.doCommand(); |
michael@0 | 608 | |
michael@0 | 609 | clickOK = false; |
michael@0 | 610 | break; |
michael@0 | 611 | |
michael@0 | 612 | case 24: |
michael@0 | 613 | // ConfirmEx (buttons from args, checkbox, button3) |
michael@0 | 614 | state = { |
michael@0 | 615 | msg : "This is the confirmEx text.", |
michael@0 | 616 | title : "TestTitle", |
michael@0 | 617 | iconClass : "question-icon", |
michael@0 | 618 | textHidden : true, |
michael@0 | 619 | passHidden : true, |
michael@0 | 620 | checkHidden : false, |
michael@0 | 621 | textValue : "", |
michael@0 | 622 | passValue : "", |
michael@0 | 623 | checkMsg : "Check me out!", |
michael@0 | 624 | checked : false, |
michael@0 | 625 | focused : ui.button2, // Default changed! |
michael@0 | 626 | defButton : ui.button2, |
michael@0 | 627 | }; |
michael@0 | 628 | // XXX check button2 is default |
michael@0 | 629 | is(ui.button0.label, "butt0", "Checking accept-button label"); |
michael@0 | 630 | is(ui.button1.label, "butt1", "Checking cancel-button label"); |
michael@0 | 631 | is(ui.button2.label, "butt2", "Checking extra1-button label"); |
michael@0 | 632 | checkExpectedState(ui, state); |
michael@0 | 633 | |
michael@0 | 634 | // XXX dumb. old code driven by oncommand. |
michael@0 | 635 | checkbox.setChecked(true); |
michael@0 | 636 | checkbox.doCommand(); |
michael@0 | 637 | |
michael@0 | 638 | // XXX how to click button 3? |
michael@0 | 639 | clickOK = false; |
michael@0 | 640 | break; |
michael@0 | 641 | |
michael@0 | 642 | case 25: |
michael@0 | 643 | // Alert, null window |
michael@0 | 644 | state = { |
michael@0 | 645 | msg : "This is the alert text.", |
michael@0 | 646 | title : "TestTitle", |
michael@0 | 647 | iconClass : "alert-icon", |
michael@0 | 648 | textHidden : true, |
michael@0 | 649 | passHidden : true, |
michael@0 | 650 | checkHidden : true, |
michael@0 | 651 | textValue : "", |
michael@0 | 652 | passValue : "", |
michael@0 | 653 | checkMsg : "", |
michael@0 | 654 | checked : false, |
michael@0 | 655 | focused : ui.button0, |
michael@0 | 656 | defButton : ui.button0, |
michael@0 | 657 | }; |
michael@0 | 658 | checkExpectedState(ui, state); |
michael@0 | 659 | break; |
michael@0 | 660 | |
michael@0 | 661 | case 26: |
michael@0 | 662 | // ConfirmEx (with delay, ok) |
michael@0 | 663 | state = { |
michael@0 | 664 | msg : "This is the confirmEx delay text.", |
michael@0 | 665 | title : "TestTitle", |
michael@0 | 666 | iconClass : "question-icon", |
michael@0 | 667 | textHidden : true, |
michael@0 | 668 | passHidden : true, |
michael@0 | 669 | checkHidden : true, |
michael@0 | 670 | textValue : "", |
michael@0 | 671 | passValue : "", |
michael@0 | 672 | checkMsg : "", |
michael@0 | 673 | checked : false, |
michael@0 | 674 | focused : null, // nothing focused until after delay fires |
michael@0 | 675 | defButton : ui.button0, |
michael@0 | 676 | }; |
michael@0 | 677 | |
michael@0 | 678 | // OS X doesn't initially focus the button, but rather the infoBody. |
michael@0 | 679 | // The focus stays there even after the button-enable delay has fired. |
michael@0 | 680 | if (isOSX) |
michael@0 | 681 | state.focused = ui.infoBody; |
michael@0 | 682 | |
michael@0 | 683 | is(ui.button0.label, "OK", "Checking accept-button label"); |
michael@0 | 684 | is(ui.button1.label, "Cancel", "Checking cancel-button label"); |
michael@0 | 685 | is(ui.button0.disabled, true, "Checking accept-button is disabled"); |
michael@0 | 686 | is(ui.button1.disabled, false, "Checking cancel-button isn't disabled "); |
michael@0 | 687 | checkExpectedState(ui, state); |
michael@0 | 688 | break; |
michael@0 | 689 | |
michael@0 | 690 | |
michael@0 | 691 | case 100: |
michael@0 | 692 | // PromptAuth (no realm, ok, with checkbox) |
michael@0 | 693 | state = { |
michael@0 | 694 | msg : 'Enter username and password for http://example.com', |
michael@0 | 695 | title : "TestTitle", |
michael@0 | 696 | iconClass : "authentication-icon question-icon", |
michael@0 | 697 | textHidden : false, |
michael@0 | 698 | passHidden : false, |
michael@0 | 699 | checkHidden : false, |
michael@0 | 700 | textValue : "", |
michael@0 | 701 | passValue : "", |
michael@0 | 702 | checkMsg : "Check me out!", |
michael@0 | 703 | checked : false, |
michael@0 | 704 | focused : ui.loginTextbox.inputField, |
michael@0 | 705 | defButton : ui.button0, |
michael@0 | 706 | }; |
michael@0 | 707 | checkExpectedState(ui, state); |
michael@0 | 708 | |
michael@0 | 709 | textField.setAttribute("value", "username"); |
michael@0 | 710 | passField.setAttribute("value", "password"); |
michael@0 | 711 | // XXX dumb. old code driven by oncommand. |
michael@0 | 712 | checkbox.setChecked(true); |
michael@0 | 713 | checkbox.doCommand(); |
michael@0 | 714 | break; |
michael@0 | 715 | |
michael@0 | 716 | case 101: |
michael@0 | 717 | // PromptAuth (long realm, ok, with checkbox) |
michael@0 | 718 | state = { |
michael@0 | 719 | msg : 'A username and password are being requested by http://example.com. The site ' + |
michael@0 | 720 | 'says: "abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi ' + |
michael@0 | 721 | 'abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi ' + |
michael@0 | 722 | 'abcdefghi \u2026"', |
michael@0 | 723 | title : "TestTitle", |
michael@0 | 724 | iconClass : "authentication-icon question-icon", |
michael@0 | 725 | textHidden : false, |
michael@0 | 726 | passHidden : false, |
michael@0 | 727 | checkHidden : false, |
michael@0 | 728 | textValue : "", |
michael@0 | 729 | passValue : "", |
michael@0 | 730 | checkMsg : "Check me out!", |
michael@0 | 731 | checked : false, |
michael@0 | 732 | focused : ui.loginTextbox.inputField, |
michael@0 | 733 | defButton : ui.button0, |
michael@0 | 734 | }; |
michael@0 | 735 | checkExpectedState(ui, state); |
michael@0 | 736 | |
michael@0 | 737 | textField.setAttribute("value", "username"); |
michael@0 | 738 | passField.setAttribute("value", "password"); |
michael@0 | 739 | // XXX dumb. old code driven by oncommand. |
michael@0 | 740 | checkbox.setChecked(true); |
michael@0 | 741 | checkbox.doCommand(); |
michael@0 | 742 | break; |
michael@0 | 743 | |
michael@0 | 744 | default: |
michael@0 | 745 | ok(false, "Uhh, unhandled switch for testNum #" + testNum); |
michael@0 | 746 | break; |
michael@0 | 747 | } |
michael@0 | 748 | |
michael@0 | 749 | if (testNum == 24) { |
michael@0 | 750 | ui.button2.click(); |
michael@0 | 751 | } else if (testNum == 26) { |
michael@0 | 752 | // Buttons are disabled at the moment, poll until they're reenabled. |
michael@0 | 753 | // Can't use setInterval here, because the window's in a modal state |
michael@0 | 754 | // and thus DOM events are suppressed. |
michael@0 | 755 | pollTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); |
michael@0 | 756 | pollTimer.initWithCallback(SpecialPowers.wrapCallback(function() { |
michael@0 | 757 | pollDialog(ui.button0); |
michael@0 | 758 | }), |
michael@0 | 759 | 100, Ci.nsITimer.TYPE_REPEATING_SLACK); |
michael@0 | 760 | return; |
michael@0 | 761 | } else { |
michael@0 | 762 | if (clickOK) |
michael@0 | 763 | ui.button0.click(); |
michael@0 | 764 | else |
michael@0 | 765 | ui.button1.click(); |
michael@0 | 766 | } |
michael@0 | 767 | |
michael@0 | 768 | ok(true, "handleDialog done"); |
michael@0 | 769 | didDialog = true; |
michael@0 | 770 | } |
michael@0 | 771 | |
michael@0 | 772 | |
michael@0 | 773 | function runTests() { |
michael@0 | 774 | let ioService = Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 775 | getService(Ci.nsIIOService); |
michael@0 | 776 | ok(true, "Running tests (isTabModal=" + isTabModal + ", usePromptService=" + usePromptService + ")"); |
michael@0 | 777 | |
michael@0 | 778 | let prompter, promptArgs; |
michael@0 | 779 | if (usePromptService) { |
michael@0 | 780 | prompter = Cc["@mozilla.org/embedcomp/prompt-service;1"]. |
michael@0 | 781 | getService(Ci.nsIPromptService2); |
michael@0 | 782 | } else { |
michael@0 | 783 | prompter = Cc["@mozilla.org/prompter;1"]. |
michael@0 | 784 | getService(Ci.nsIPromptFactory). |
michael@0 | 785 | getPrompt(window, Ci.nsIPrompt); |
michael@0 | 786 | if (isTabModal) { |
michael@0 | 787 | let bag = prompter.QueryInterface(Ci.nsIWritablePropertyBag2); |
michael@0 | 788 | bag.setPropertyAsBool("allowTabModal", true); |
michael@0 | 789 | } |
michael@0 | 790 | } |
michael@0 | 791 | |
michael@0 | 792 | let checkVal = {}; |
michael@0 | 793 | let textVal = {}; |
michael@0 | 794 | let passVal = {}; |
michael@0 | 795 | let flags; |
michael@0 | 796 | let isOK, clickedButton; |
michael@0 | 797 | |
michael@0 | 798 | testNum = 0; |
michael@0 | 799 | |
michael@0 | 800 | // ===== test 1 ===== |
michael@0 | 801 | // Alert |
michael@0 | 802 | testNum++; |
michael@0 | 803 | startCallbackTimer(); |
michael@0 | 804 | promptArgs = ["TestTitle", "This is the alert text."]; |
michael@0 | 805 | if (usePromptService) |
michael@0 | 806 | promptArgs.unshift(window); |
michael@0 | 807 | prompter.alert.apply(null, promptArgs); |
michael@0 | 808 | |
michael@0 | 809 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 810 | |
michael@0 | 811 | // ===== test 2 ===== |
michael@0 | 812 | // AlertCheck (null checkbox label) |
michael@0 | 813 | testNum++; |
michael@0 | 814 | startCallbackTimer(); |
michael@0 | 815 | promptArgs = ["TestTitle", "This is the alertCheck text.", null, {}]; |
michael@0 | 816 | if (usePromptService) |
michael@0 | 817 | promptArgs.unshift(window); |
michael@0 | 818 | prompter.alertCheck.apply(null, promptArgs); |
michael@0 | 819 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 820 | |
michael@0 | 821 | |
michael@0 | 822 | // ===== test 3 ===== |
michael@0 | 823 | // AlertCheck |
michael@0 | 824 | testNum++; |
michael@0 | 825 | startCallbackTimer(); |
michael@0 | 826 | checkVal.value = false; |
michael@0 | 827 | promptArgs = ["TestTitle", "This is the alertCheck text.", "Check me out!", checkVal]; |
michael@0 | 828 | if (usePromptService) |
michael@0 | 829 | promptArgs.unshift(window); |
michael@0 | 830 | prompter.alertCheck.apply(null, promptArgs); |
michael@0 | 831 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 832 | is(checkVal.value, true, "checkbox was checked"); |
michael@0 | 833 | |
michael@0 | 834 | |
michael@0 | 835 | // ===== test 4 ===== |
michael@0 | 836 | // Confirm (ok) |
michael@0 | 837 | testNum++; |
michael@0 | 838 | startCallbackTimer(); |
michael@0 | 839 | promptArgs = ["TestTitle", "This is the confirm text."]; |
michael@0 | 840 | if (usePromptService) |
michael@0 | 841 | promptArgs.unshift(window); |
michael@0 | 842 | isOK = prompter.confirm.apply(null, promptArgs); |
michael@0 | 843 | is(isOK, true, "checked expected retval"); |
michael@0 | 844 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 845 | |
michael@0 | 846 | // ===== test 5 ===== |
michael@0 | 847 | // Confirm (cancel) |
michael@0 | 848 | testNum++; |
michael@0 | 849 | startCallbackTimer(); |
michael@0 | 850 | promptArgs = ["TestTitle", "This is the confirm text."]; |
michael@0 | 851 | if (usePromptService) |
michael@0 | 852 | promptArgs.unshift(window); |
michael@0 | 853 | isOK = prompter.confirm.apply(null, promptArgs); |
michael@0 | 854 | is(isOK, false, "checked expected retval"); |
michael@0 | 855 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 856 | |
michael@0 | 857 | |
michael@0 | 858 | // ===== test 6 ===== |
michael@0 | 859 | // ConfirmCheck (ok, null checkbox label) |
michael@0 | 860 | testNum++; |
michael@0 | 861 | startCallbackTimer(); |
michael@0 | 862 | promptArgs = ["TestTitle", "This is the confirmCheck text.", null, {}]; |
michael@0 | 863 | if (usePromptService) |
michael@0 | 864 | promptArgs.unshift(window); |
michael@0 | 865 | isOK = prompter.confirmCheck.apply(null, promptArgs); |
michael@0 | 866 | is(isOK, true, "checked expected retval"); |
michael@0 | 867 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 868 | |
michael@0 | 869 | // ===== test 7 ===== |
michael@0 | 870 | // ConfirmCheck (cancel, null checkbox label) |
michael@0 | 871 | testNum++; |
michael@0 | 872 | startCallbackTimer(); |
michael@0 | 873 | promptArgs = ["TestTitle", "This is the confirmCheck text.", null, {}]; |
michael@0 | 874 | if (usePromptService) |
michael@0 | 875 | promptArgs.unshift(window); |
michael@0 | 876 | isOK = prompter.confirmCheck.apply(null, promptArgs); |
michael@0 | 877 | is(isOK, false, "checked expected retval"); |
michael@0 | 878 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 879 | |
michael@0 | 880 | // ===== test 8 ===== |
michael@0 | 881 | // ConfirmCheck (ok) |
michael@0 | 882 | testNum++; |
michael@0 | 883 | startCallbackTimer(); |
michael@0 | 884 | checkVal.value = false; |
michael@0 | 885 | promptArgs = ["TestTitle", "This is the confirmCheck text.", "Check me out!", checkVal]; |
michael@0 | 886 | if (usePromptService) |
michael@0 | 887 | promptArgs.unshift(window); |
michael@0 | 888 | isOK = prompter.confirmCheck.apply(null, promptArgs); |
michael@0 | 889 | is(isOK, true, "checked expected retval"); |
michael@0 | 890 | is(checkVal.value, true, "expected checkbox setting"); |
michael@0 | 891 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 892 | |
michael@0 | 893 | // ===== test 9 ===== |
michael@0 | 894 | // ConfirmCheck (cancel) |
michael@0 | 895 | testNum++; |
michael@0 | 896 | startCallbackTimer(); |
michael@0 | 897 | checkVal.value = false; |
michael@0 | 898 | promptArgs = ["TestTitle", "This is the confirmCheck text.", "Check me out!", checkVal]; |
michael@0 | 899 | if (usePromptService) |
michael@0 | 900 | promptArgs.unshift(window); |
michael@0 | 901 | isOK = prompter.confirmCheck.apply(null, promptArgs); |
michael@0 | 902 | is(isOK, false, "checked expected retval"); |
michael@0 | 903 | is(checkVal.value, true, "expected checkbox setting"); |
michael@0 | 904 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 905 | |
michael@0 | 906 | |
michael@0 | 907 | // ===== test 10 ===== |
michael@0 | 908 | // Prompt (ok, no default text) |
michael@0 | 909 | testNum++; |
michael@0 | 910 | startCallbackTimer(); |
michael@0 | 911 | textVal.value = ""; |
michael@0 | 912 | promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}]; |
michael@0 | 913 | if (usePromptService) |
michael@0 | 914 | promptArgs.unshift(window); |
michael@0 | 915 | isOK = prompter.prompt.apply(null, promptArgs); |
michael@0 | 916 | is(isOK, true, "checked expected retval"); |
michael@0 | 917 | is(textVal.value, "bacon", "checking expected text value"); |
michael@0 | 918 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 919 | |
michael@0 | 920 | // ===== test 11 ===== |
michael@0 | 921 | // Prompt (ok, default text) |
michael@0 | 922 | testNum++; |
michael@0 | 923 | startCallbackTimer(); |
michael@0 | 924 | textVal.value = "kittens"; |
michael@0 | 925 | promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}]; |
michael@0 | 926 | if (usePromptService) |
michael@0 | 927 | promptArgs.unshift(window); |
michael@0 | 928 | isOK = prompter.prompt.apply(null, promptArgs); |
michael@0 | 929 | is(isOK, true, "checked expected retval"); |
michael@0 | 930 | is(textVal.value, "kittens", "checking expected text value"); |
michael@0 | 931 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 932 | |
michael@0 | 933 | // ===== test 12 ===== |
michael@0 | 934 | // Prompt (cancel, default text) |
michael@0 | 935 | testNum++; |
michael@0 | 936 | startCallbackTimer(); |
michael@0 | 937 | textVal.value = "puppies"; |
michael@0 | 938 | promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}]; |
michael@0 | 939 | if (usePromptService) |
michael@0 | 940 | promptArgs.unshift(window); |
michael@0 | 941 | isOK = prompter.prompt.apply(null, promptArgs); |
michael@0 | 942 | is(isOK, false, "checked expected retval"); |
michael@0 | 943 | is(textVal.value, "puppies", "checking expected text value"); |
michael@0 | 944 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 945 | |
michael@0 | 946 | // ===== test 13 ===== |
michael@0 | 947 | // Prompt (cancel, default text modified) |
michael@0 | 948 | testNum++; |
michael@0 | 949 | startCallbackTimer(); |
michael@0 | 950 | textVal.value = "puppies"; |
michael@0 | 951 | promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}]; |
michael@0 | 952 | if (usePromptService) |
michael@0 | 953 | promptArgs.unshift(window); |
michael@0 | 954 | isOK = prompter.prompt.apply(null, promptArgs); |
michael@0 | 955 | is(isOK, false, "checked expected retval"); |
michael@0 | 956 | is(textVal.value, "puppies", "checking expected text value"); |
michael@0 | 957 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 958 | |
michael@0 | 959 | // ===== test 14 ===== |
michael@0 | 960 | // Prompt (ok, with checkbox) |
michael@0 | 961 | testNum++; |
michael@0 | 962 | startCallbackTimer(); |
michael@0 | 963 | textVal.value = "tribbles"; |
michael@0 | 964 | checkVal.value = false; |
michael@0 | 965 | promptArgs = ["TestTitle", "This is the prompt text.", textVal, "Check me out!", checkVal]; |
michael@0 | 966 | if (usePromptService) |
michael@0 | 967 | promptArgs.unshift(window); |
michael@0 | 968 | isOK = prompter.prompt.apply(null, promptArgs); |
michael@0 | 969 | is(isOK, true, "checked expected retval"); |
michael@0 | 970 | is(textVal.value, "tribbles", "checking expected text value"); |
michael@0 | 971 | is(checkVal.value, true, "expected checkbox setting"); |
michael@0 | 972 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 973 | |
michael@0 | 974 | // ===== test 15 ===== |
michael@0 | 975 | // Prompt (cancel, with checkbox) |
michael@0 | 976 | testNum++; |
michael@0 | 977 | startCallbackTimer(); |
michael@0 | 978 | textVal.value = "tribbles"; |
michael@0 | 979 | checkVal.value = false; |
michael@0 | 980 | promptArgs = ["TestTitle", "This is the prompt text.", textVal, "Check me out!", checkVal]; |
michael@0 | 981 | if (usePromptService) |
michael@0 | 982 | promptArgs.unshift(window); |
michael@0 | 983 | isOK = prompter.prompt.apply(null, promptArgs); |
michael@0 | 984 | is(isOK, false, "checked expected retval"); |
michael@0 | 985 | is(textVal.value, "tribbles", "checking expected text value"); |
michael@0 | 986 | is(checkVal.value, false, "expected checkbox setting"); |
michael@0 | 987 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 988 | |
michael@0 | 989 | |
michael@0 | 990 | // ===== test 16 ===== |
michael@0 | 991 | // PromptUsernameAndPassword (ok) |
michael@0 | 992 | // Just two tests for this, since password manager already tests this extensively. |
michael@0 | 993 | testNum++; |
michael@0 | 994 | startCallbackTimer(); |
michael@0 | 995 | textVal.value = "usr"; |
michael@0 | 996 | passVal.value = "ssh"; |
michael@0 | 997 | checkVal.value = false; |
michael@0 | 998 | promptArgs = ["TestTitle", "This is the pUAP text.", textVal, passVal, "Check me out!", checkVal]; |
michael@0 | 999 | if (usePromptService) |
michael@0 | 1000 | promptArgs.unshift(window); |
michael@0 | 1001 | isOK = prompter.promptUsernameAndPassword.apply(null, promptArgs); |
michael@0 | 1002 | is(isOK, true, "checked expected retval"); |
michael@0 | 1003 | is(textVal.value, "newusr", "checking expected text value"); |
michael@0 | 1004 | is(passVal.value, "newssh", "checking expected pass value"); |
michael@0 | 1005 | is(checkVal.value, true, "expected checkbox setting"); |
michael@0 | 1006 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1007 | |
michael@0 | 1008 | // ===== test 17 ===== |
michael@0 | 1009 | // PromptUsernameAndPassword (cancel) |
michael@0 | 1010 | testNum++; |
michael@0 | 1011 | startCallbackTimer(); |
michael@0 | 1012 | textVal.value = "usr"; |
michael@0 | 1013 | passVal.value = "ssh"; |
michael@0 | 1014 | checkVal.value = false; |
michael@0 | 1015 | promptArgs = ["TestTitle", "This is the pUAP text.", textVal, passVal, "Check me out!", checkVal]; |
michael@0 | 1016 | if (usePromptService) |
michael@0 | 1017 | promptArgs.unshift(window); |
michael@0 | 1018 | isOK = prompter.promptUsernameAndPassword.apply(null, promptArgs); |
michael@0 | 1019 | is(isOK, false, "checked expected retval"); |
michael@0 | 1020 | is(textVal.value, "usr", "checking expected text value"); |
michael@0 | 1021 | is(passVal.value, "ssh", "checking expected pass value"); |
michael@0 | 1022 | is(checkVal.value, false, "expected checkbox setting"); |
michael@0 | 1023 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1024 | |
michael@0 | 1025 | |
michael@0 | 1026 | // ===== test 18 ===== |
michael@0 | 1027 | // PromptPassword (ok) |
michael@0 | 1028 | testNum++; |
michael@0 | 1029 | startCallbackTimer(); |
michael@0 | 1030 | passVal.value = "ssh"; |
michael@0 | 1031 | checkVal.value = false; |
michael@0 | 1032 | promptArgs = ["TestTitle", "This is the promptPassword text.", passVal, "Check me out!", checkVal]; |
michael@0 | 1033 | if (usePromptService) |
michael@0 | 1034 | promptArgs.unshift(window); |
michael@0 | 1035 | isOK = prompter.promptPassword.apply(null, promptArgs); |
michael@0 | 1036 | is(isOK, true, "checked expected retval"); |
michael@0 | 1037 | is(passVal.value, "newssh", "checking expected pass value"); |
michael@0 | 1038 | is(checkVal.value, true, "expected checkbox setting"); |
michael@0 | 1039 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1040 | |
michael@0 | 1041 | // ===== test 19 ===== |
michael@0 | 1042 | // PromptPassword (cancel) |
michael@0 | 1043 | testNum++; |
michael@0 | 1044 | startCallbackTimer(); |
michael@0 | 1045 | passVal.value = "ssh"; |
michael@0 | 1046 | checkVal.value = false; |
michael@0 | 1047 | promptArgs = ["TestTitle", "This is the promptPassword text.", passVal, "Check me out!", checkVal]; |
michael@0 | 1048 | if (usePromptService) |
michael@0 | 1049 | promptArgs.unshift(window); |
michael@0 | 1050 | isOK = prompter.promptPassword.apply(null, promptArgs); |
michael@0 | 1051 | is(isOK, false, "checked expected retval"); |
michael@0 | 1052 | is(passVal.value, "ssh", "checking expected pass value"); |
michael@0 | 1053 | is(checkVal.value, false, "expected checkbox setting"); |
michael@0 | 1054 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1055 | |
michael@0 | 1056 | // ===== test 20 ===== |
michael@0 | 1057 | // ConfirmEx (ok/cancel, ok) |
michael@0 | 1058 | testNum++; |
michael@0 | 1059 | startCallbackTimer(); |
michael@0 | 1060 | flags = Ci.nsIPromptService.STD_OK_CANCEL_BUTTONS; |
michael@0 | 1061 | promptArgs = ["TestTitle", "This is the confirmEx text.", flags, null, null, null, null, {}]; |
michael@0 | 1062 | if (usePromptService) |
michael@0 | 1063 | promptArgs.unshift(window); |
michael@0 | 1064 | clickedButton = prompter.confirmEx.apply(null, promptArgs); |
michael@0 | 1065 | is(clickedButton, 0, "checked expected button num click"); |
michael@0 | 1066 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1067 | |
michael@0 | 1068 | // ===== test 21 ===== |
michael@0 | 1069 | // ConfirmEx (yes/no, cancel) |
michael@0 | 1070 | testNum++; |
michael@0 | 1071 | startCallbackTimer(); |
michael@0 | 1072 | flags = Ci.nsIPromptService.STD_YES_NO_BUTTONS; |
michael@0 | 1073 | promptArgs = ["TestTitle", "This is the confirmEx text.", flags, null, null, null, null, {}]; |
michael@0 | 1074 | if (usePromptService) |
michael@0 | 1075 | promptArgs.unshift(window); |
michael@0 | 1076 | clickedButton = prompter.confirmEx.apply(null, promptArgs); |
michael@0 | 1077 | is(clickedButton, 1, "checked expected button num click"); |
michael@0 | 1078 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1079 | |
michael@0 | 1080 | // ===== test 22 ===== |
michael@0 | 1081 | // ConfirmEx (buttons from args, checkbox, ok) |
michael@0 | 1082 | testNum++; |
michael@0 | 1083 | startCallbackTimer(); |
michael@0 | 1084 | let b = Ci.nsIPromptService.BUTTON_TITLE_IS_STRING; |
michael@0 | 1085 | flags = b * Ci.nsIPromptService.BUTTON_POS_2 + |
michael@0 | 1086 | b * Ci.nsIPromptService.BUTTON_POS_1 + |
michael@0 | 1087 | b * Ci.nsIPromptService.BUTTON_POS_0; |
michael@0 | 1088 | checkVal.value = false; |
michael@0 | 1089 | promptArgs = ["TestTitle", "This is the confirmEx text.", flags, |
michael@0 | 1090 | "butt0", "butt1", "butt2", "Check me out!", checkVal]; |
michael@0 | 1091 | if (usePromptService) |
michael@0 | 1092 | promptArgs.unshift(window); |
michael@0 | 1093 | clickedButton = prompter.confirmEx.apply(null, promptArgs); |
michael@0 | 1094 | is(clickedButton, 0, "checked expected button num click"); |
michael@0 | 1095 | is(checkVal.value, true, "expected checkbox setting"); |
michael@0 | 1096 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1097 | |
michael@0 | 1098 | // ===== test 23 ===== |
michael@0 | 1099 | // ConfirmEx (buttons from args, checkbox, cancel) |
michael@0 | 1100 | testNum++; |
michael@0 | 1101 | startCallbackTimer(); |
michael@0 | 1102 | let b = Ci.nsIPromptService.BUTTON_TITLE_IS_STRING; |
michael@0 | 1103 | flags = b * Ci.nsIPromptService.BUTTON_POS_2 + |
michael@0 | 1104 | b * Ci.nsIPromptService.BUTTON_POS_1 + |
michael@0 | 1105 | b * Ci.nsIPromptService.BUTTON_POS_0; |
michael@0 | 1106 | flags ^= Ci.nsIPromptService.BUTTON_POS_1_DEFAULT; |
michael@0 | 1107 | checkVal.value = false; |
michael@0 | 1108 | promptArgs = ["TestTitle", "This is the confirmEx text.", flags, |
michael@0 | 1109 | "butt0", "butt1", "butt2", "Check me out!", checkVal]; |
michael@0 | 1110 | if (usePromptService) |
michael@0 | 1111 | promptArgs.unshift(window); |
michael@0 | 1112 | clickedButton = prompter.confirmEx.apply(null, promptArgs); |
michael@0 | 1113 | is(clickedButton, 1, "checked expected button num click"); |
michael@0 | 1114 | is(checkVal.value, true, "expected checkbox setting"); |
michael@0 | 1115 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1116 | |
michael@0 | 1117 | // ===== test 24 ===== |
michael@0 | 1118 | // ConfirmEx (buttons from args, checkbox, button3) |
michael@0 | 1119 | testNum++; |
michael@0 | 1120 | startCallbackTimer(); |
michael@0 | 1121 | let b = Ci.nsIPromptService.BUTTON_TITLE_IS_STRING; |
michael@0 | 1122 | flags = b * Ci.nsIPromptService.BUTTON_POS_2 + |
michael@0 | 1123 | b * Ci.nsIPromptService.BUTTON_POS_1 + |
michael@0 | 1124 | b * Ci.nsIPromptService.BUTTON_POS_0; |
michael@0 | 1125 | flags ^= Ci.nsIPromptService.BUTTON_POS_2_DEFAULT; |
michael@0 | 1126 | checkVal.value = false; |
michael@0 | 1127 | promptArgs = ["TestTitle", "This is the confirmEx text.", flags, |
michael@0 | 1128 | "butt0", "butt1", "butt2", "Check me out!", checkVal]; |
michael@0 | 1129 | if (usePromptService) |
michael@0 | 1130 | promptArgs.unshift(window); |
michael@0 | 1131 | clickedButton = prompter.confirmEx.apply(null, promptArgs); |
michael@0 | 1132 | is(clickedButton, 2, "checked expected button num click"); |
michael@0 | 1133 | is(checkVal.value, true, "expected checkbox setting"); |
michael@0 | 1134 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1135 | |
michael@0 | 1136 | // ===== test 25 ===== |
michael@0 | 1137 | // Alert, no window |
michael@0 | 1138 | // (skipped for tabmodal tests: window is required) |
michael@0 | 1139 | testNum++; |
michael@0 | 1140 | if (!isTabModal) { |
michael@0 | 1141 | startCallbackTimer(); |
michael@0 | 1142 | promptArgs = ["TestTitle", "This is the alert text."]; |
michael@0 | 1143 | if (usePromptService) |
michael@0 | 1144 | promptArgs.unshift(null); |
michael@0 | 1145 | prompter.alert.apply(null, promptArgs); |
michael@0 | 1146 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1147 | } |
michael@0 | 1148 | |
michael@0 | 1149 | |
michael@0 | 1150 | // ===== test 26 ===== |
michael@0 | 1151 | // ConfirmEx (delay, ok) |
michael@0 | 1152 | // (skipped for tabmodal tests: delay not supported) |
michael@0 | 1153 | testNum++; |
michael@0 | 1154 | if (!isTabModal) { |
michael@0 | 1155 | startCallbackTimer(); |
michael@0 | 1156 | flags = (Ci.nsIPromptService.STD_OK_CANCEL_BUTTONS | Ci.nsIPromptService.BUTTON_DELAY_ENABLE); |
michael@0 | 1157 | promptArgs = ["TestTitle", "This is the confirmEx delay text.", flags, null, null, null, null, {}]; |
michael@0 | 1158 | if (usePromptService) |
michael@0 | 1159 | promptArgs.unshift(window); |
michael@0 | 1160 | clickedButton = prompter.confirmEx.apply(null, promptArgs); |
michael@0 | 1161 | is(clickedButton, 0, "checked expected button num click"); |
michael@0 | 1162 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1163 | } |
michael@0 | 1164 | |
michael@0 | 1165 | // promptAuth already tested via password manager but do a few specific things here. |
michael@0 | 1166 | |
michael@0 | 1167 | |
michael@0 | 1168 | var channel = ioService.newChannel("http://example.com", null, null); |
michael@0 | 1169 | var level = Ci.nsIAuthPrompt2.LEVEL_NONE; |
michael@0 | 1170 | var authinfo = { |
michael@0 | 1171 | username : "", |
michael@0 | 1172 | password : "", |
michael@0 | 1173 | domain : "", |
michael@0 | 1174 | flags : Ci.nsIAuthInformation.AUTH_HOST, |
michael@0 | 1175 | authenticationScheme : "basic", |
michael@0 | 1176 | realm : "" |
michael@0 | 1177 | }; |
michael@0 | 1178 | |
michael@0 | 1179 | // ===== test 100 ===== |
michael@0 | 1180 | // promptAuth with empty realm |
michael@0 | 1181 | // (promptAuth is only accessible from the prompt service) |
michael@0 | 1182 | testNum = 100; |
michael@0 | 1183 | if (usePromptService) { |
michael@0 | 1184 | startCallbackTimer(); |
michael@0 | 1185 | checkVal.value = false; |
michael@0 | 1186 | isOK = prompter.promptAuth(window, channel, level, authinfo, "Check me out!", checkVal); |
michael@0 | 1187 | is(isOK, true, "checked expected retval"); |
michael@0 | 1188 | is(authinfo.username, "username", "checking filled username"); |
michael@0 | 1189 | is(authinfo.password, "password", "checking filled password"); |
michael@0 | 1190 | is(checkVal.value, true, "expected checkbox setting"); |
michael@0 | 1191 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1192 | } |
michael@0 | 1193 | |
michael@0 | 1194 | // ===== test 101 ===== |
michael@0 | 1195 | // promptAuth with long realm |
michael@0 | 1196 | // (promptAuth is only accessible from the prompt service) |
michael@0 | 1197 | testNum++; |
michael@0 | 1198 | if (usePromptService) { |
michael@0 | 1199 | startCallbackTimer(); |
michael@0 | 1200 | checkVal.value = false; |
michael@0 | 1201 | var longString = ""; |
michael@0 | 1202 | for (var i = 0; i < 20; i++) |
michael@0 | 1203 | longString += "abcdefghi "; // 200 chars long |
michael@0 | 1204 | authinfo.realm = longString; |
michael@0 | 1205 | authinfo.username = ""; |
michael@0 | 1206 | authinfo.password = ""; |
michael@0 | 1207 | isOK = prompter.promptAuth(window, channel, level, authinfo, "Check me out!", checkVal); |
michael@0 | 1208 | is(isOK, true, "checked expected retval"); |
michael@0 | 1209 | is(authinfo.username, "username", "checking filled username"); |
michael@0 | 1210 | is(authinfo.password, "password", "checking filled password"); |
michael@0 | 1211 | is(checkVal.value, true, "expected checkbox setting"); |
michael@0 | 1212 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1213 | } |
michael@0 | 1214 | } |
michael@0 | 1215 | |
michael@0 | 1216 | let testNum; |
michael@0 | 1217 | let pollTimer; |
michael@0 | 1218 | |
michael@0 | 1219 | /* |
michael@0 | 1220 | * Run the body of the 3 times: |
michael@0 | 1221 | * - 1st pass: with window-modal prompts, using nsIPromptService |
michael@0 | 1222 | * - 2nd pass: still window-modal, using nsIPrompt directly (via nsIPromptFactory) |
michael@0 | 1223 | * - 3rd pass: with tab-modal prompts. Can't opt into these via * nsIPromptService. |
michael@0 | 1224 | */ |
michael@0 | 1225 | |
michael@0 | 1226 | isTabModal = false; usePromptService = true; |
michael@0 | 1227 | runTests(); |
michael@0 | 1228 | |
michael@0 | 1229 | isTabModal = false; usePromptService = false; |
michael@0 | 1230 | runTests(); |
michael@0 | 1231 | |
michael@0 | 1232 | if (getTabModalPromptBox(window)) { |
michael@0 | 1233 | isTabModal = true; usePromptService = false; |
michael@0 | 1234 | runTests(); |
michael@0 | 1235 | } |
michael@0 | 1236 | |
michael@0 | 1237 | </script> |
michael@0 | 1238 | </pre> |
michael@0 | 1239 | </body> |
michael@0 | 1240 | </html> |