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