Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Tests for browser context menu</title>
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
8 <script type="text/javascript" src="head_plain.js"></script>
9 </head>
10 <body>
11 Browser context menu tests.
12 <p id="display"></p>
14 <div id="content">
15 </div>
17 <pre id="test">
18 <script> var perWindowPrivateBrowsing = false; </script>
19 <script type="text/javascript" src="privateBrowsingMode.js"></script>
20 <script type="text/javascript" src="contextmenu_common.js"></script>
21 <script class="testbody" type="text/javascript">
23 SpecialPowers.Cu.import("resource://gre/modules/InlineSpellChecker.jsm", window);
24 SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window);
26 const Ci = SpecialPowers.Ci;
28 function executeCopyCommand(command, expectedValue)
29 {
30 // Just execute the command directly rather than simulating a context menu
31 // press to avoid having to deal with its asynchronous nature
32 SpecialPowers.wrap(subwindow).controllers.getControllerForCommand(command).doCommand(command);
34 // The easiest way to check the clipboard is to paste the contents into a
35 // textbox
36 input.focus();
37 input.value = "";
38 SpecialPowers.wrap(input).controllers.getControllerForCommand("cmd_paste").doCommand("cmd_paste");
39 is(input.value, expectedValue, "paste for command " + command);
40 }
42 function invokeItemAction(generatedItemId)
43 {
44 var item = contextMenu.getElementsByAttribute("generateditemid",
45 generatedItemId)[0];
46 ok(item, "Got generated XUL menu item");
47 item.doCommand();
48 ok(!pagemenu.hasAttribute("hopeless"), "attribute got removed");
49 }
51 function selectText(element) {
52 // Clear any previous selections before selecting new element.
53 subwindow.getSelection().removeAllRanges();
55 var div = subwindow.document.createRange();
56 div.setStartBefore(element);
57 div.setEndAfter(element);
58 subwindow.getSelection().addRange(div);
59 }
61 function selectInputText(element) {
62 // Clear any previous selections before selecting new element.
63 subwindow.getSelection().removeAllRanges();
65 element.select();
66 }
68 /*
69 * runTest
70 *
71 * Called by a popupshowing event handler. Each test checks for expected menu
72 * contents, closes the popup, and finally triggers the popup on a new element
73 * (thus kicking off another cycle).
74 *
75 */
76 function runTest(testNum) {
77 // Seems we need to enable this again, or sendKeyEvent() complaints.
78 ok(true, "Starting test #" + testNum);
80 var inspectItems = [];
81 if (SpecialPowers.getBoolPref("devtools.inspector.enabled")) {
82 inspectItems = ["---", null,
83 "context-inspect", true];
84 }
86 switch (testNum) {
87 case 1:
88 // Invoke context menu for next test.
89 openContextMenuFor(text);
90 break;
92 case 2:
93 // Context menu for plain text
94 plainTextItems = ["context-back", false,
95 "context-forward", false,
96 "context-reload", true,
97 "---", null,
98 "context-bookmarkpage", true,
99 "context-savepage", true,
100 "---", null,
101 "context-viewbgimage", false,
102 "context-selectall", true,
103 "---", null,
104 "context-viewsource", true,
105 "context-viewinfo", true
106 ].concat(inspectItems);
107 checkContextMenu(plainTextItems);
108 closeContextMenu();
109 openContextMenuFor(link); // Invoke context menu for next test.
110 break;
112 case 3:
113 // Context menu for text link
114 if (perWindowPrivateBrowsing) {
115 checkContextMenu(["context-openlinkintab", true,
116 "context-openlink", true,
117 "context-openlinkprivate", true,
118 "---", null,
119 "context-bookmarklink", true,
120 "context-savelink", true,
121 "context-copylink", true,
122 "context-searchselect", true
123 ].concat(inspectItems));
124 } else {
125 checkContextMenu(["context-openlinkintab", true,
126 "context-openlink", true,
127 "---", null,
128 "context-bookmarklink", true,
129 "context-savelink", true,
130 "context-copylink", true,
131 "context-searchselect", true
132 ].concat(inspectItems));
133 }
134 closeContextMenu();
135 openContextMenuFor(mailto); // Invoke context menu for next test.
136 break;
138 case 4:
139 // Context menu for text mailto-link
140 checkContextMenu(["context-copyemail", true,
141 "context-searchselect", true
142 ].concat(inspectItems));
143 closeContextMenu();
144 openContextMenuFor(img); // Invoke context menu for next test.
145 break;
147 case 5:
148 // Context menu for an image
149 checkContextMenu(["context-viewimage", true,
150 "context-copyimage-contents", true,
151 "context-copyimage", true,
152 "---", null,
153 "context-saveimage", true,
154 "context-sendimage", true,
155 "context-setDesktopBackground", true,
156 "context-viewimageinfo", true
157 ].concat(inspectItems));
158 closeContextMenu();
159 openContextMenuFor(canvas); // Invoke context menu for next test.
160 break;
162 case 6:
163 // Context menu for a canvas
164 checkContextMenu(["context-viewimage", true,
165 "context-saveimage", true,
166 "context-bookmarkpage", true,
167 "context-selectall", true
168 ].concat(inspectItems));
169 closeContextMenu();
170 openContextMenuFor(video_ok); // Invoke context menu for next test.
171 break;
173 case 7:
174 // Context menu for a video (with a VALID media source)
175 checkContextMenu(["context-media-play", true,
176 "context-media-mute", true,
177 "context-media-playbackrate", null,
178 ["context-media-playbackrate-050x", true,
179 "context-media-playbackrate-100x", true,
180 "context-media-playbackrate-150x", true,
181 "context-media-playbackrate-200x", true], null,
182 "context-media-hidecontrols", true,
183 "context-video-showstats", true,
184 "context-video-fullscreen", true,
185 "---", null,
186 "context-viewvideo", true,
187 "context-copyvideourl", true,
188 "---", null,
189 "context-savevideo", true,
190 "context-video-saveimage", true,
191 "context-sendvideo", true
192 ].concat(inspectItems));
193 closeContextMenu();
194 openContextMenuFor(audio_in_video); // Invoke context menu for next test.
195 break;
197 case 8:
198 // Context menu for a video (with an audio-only file)
199 checkContextMenu(["context-media-play", true,
200 "context-media-mute", true,
201 "context-media-playbackrate", null,
202 ["context-media-playbackrate-050x", true,
203 "context-media-playbackrate-100x", true,
204 "context-media-playbackrate-150x", true,
205 "context-media-playbackrate-200x", true], null,
206 "context-media-showcontrols", true,
207 "---", null,
208 "context-copyaudiourl", true,
209 "---", null,
210 "context-saveaudio", true,
211 "context-sendaudio", true
212 ].concat(inspectItems));
213 closeContextMenu();
214 openContextMenuFor(video_bad); // Invoke context menu for next test.
215 break;
217 case 9:
218 // Context menu for a video (with an INVALID media source)
219 checkContextMenu(["context-media-play", false,
220 "context-media-mute", false,
221 "context-media-playbackrate", null,
222 ["context-media-playbackrate-050x", false,
223 "context-media-playbackrate-100x", false,
224 "context-media-playbackrate-150x", false,
225 "context-media-playbackrate-200x", false], null,
226 "context-media-hidecontrols", false,
227 "context-video-showstats", false,
228 "context-video-fullscreen", false,
229 "---", null,
230 "context-viewvideo", true,
231 "context-copyvideourl", true,
232 "---", null,
233 "context-savevideo", true,
234 "context-video-saveimage", false,
235 "context-sendvideo", true
236 ].concat(inspectItems));
237 closeContextMenu();
238 openContextMenuFor(video_bad2); // Invoke context menu for next test.
239 break;
241 case 10:
242 // Context menu for a video (with an INVALID media source)
243 checkContextMenu(["context-media-play", false,
244 "context-media-mute", false,
245 "context-media-playbackrate", null,
246 ["context-media-playbackrate-050x", false,
247 "context-media-playbackrate-100x", false,
248 "context-media-playbackrate-150x", false,
249 "context-media-playbackrate-200x", false], null,
250 "context-media-hidecontrols", false,
251 "context-video-showstats", false,
252 "context-video-fullscreen", false,
253 "---", null,
254 "context-viewvideo", false,
255 "context-copyvideourl", false,
256 "---", null,
257 "context-savevideo", false,
258 "context-video-saveimage", false,
259 "context-sendvideo", false
260 ].concat(inspectItems));
261 closeContextMenu();
262 openContextMenuFor(iframe); // Invoke context menu for next test.
263 break;
265 case 11:
266 // Context menu for an iframe
267 checkContextMenu(["context-back", false,
268 "context-forward", false,
269 "context-reload", true,
270 "---", null,
271 "context-bookmarkpage", true,
272 "context-savepage", true,
273 "---", null,
274 "context-viewbgimage", false,
275 "context-selectall", true,
276 "frame", null,
277 ["context-showonlythisframe", true,
278 "context-openframeintab", true,
279 "context-openframe", true,
280 "---", null,
281 "context-reloadframe", true,
282 "---", null,
283 "context-bookmarkframe", true,
284 "context-saveframe", true,
285 "---", null,
286 "context-printframe", true,
287 "---", null,
288 "context-viewframesource", true,
289 "context-viewframeinfo", true], null,
290 "---", null,
291 "context-viewsource", true,
292 "context-viewinfo", true
293 ].concat(inspectItems));
294 closeContextMenu();
295 openContextMenuFor(video_in_iframe); // Invoke context menu for next test.
296 break;
298 case 12:
299 // Context menu for a video in an iframe
300 checkContextMenu(["context-media-play", true,
301 "context-media-mute", true,
302 "context-media-playbackrate", null,
303 ["context-media-playbackrate-050x", true,
304 "context-media-playbackrate-100x", true,
305 "context-media-playbackrate-150x", true,
306 "context-media-playbackrate-200x", true], null,
307 "context-media-hidecontrols", true,
308 "context-video-showstats", true,
309 "context-video-fullscreen", true,
310 "---", null,
311 "context-viewvideo", true,
312 "context-copyvideourl", true,
313 "---", null,
314 "context-savevideo", true,
315 "context-video-saveimage", true,
316 "context-sendvideo", true,
317 "frame", null,
318 ["context-showonlythisframe", true,
319 "context-openframeintab", true,
320 "context-openframe", true,
321 "---", null,
322 "context-reloadframe", true,
323 "---", null,
324 "context-bookmarkframe", true,
325 "context-saveframe", true,
326 "---", null,
327 "context-printframe", true,
328 "---", null,
329 "context-viewframeinfo", true], null].concat(inspectItems));
330 closeContextMenu();
331 openContextMenuFor(image_in_iframe); // Invoke context menu for next test.
332 break;
334 case 13:
335 // Context menu for an image in an iframe
336 checkContextMenu(["context-viewimage", true,
337 "context-copyimage-contents", true,
338 "context-copyimage", true,
339 "---", null,
340 "context-saveimage", true,
341 "context-sendimage", true,
342 "context-setDesktopBackground", true,
343 "context-viewimageinfo", true,
344 "frame", null,
345 ["context-showonlythisframe", true,
346 "context-openframeintab", true,
347 "context-openframe", true,
348 "---", null,
349 "context-reloadframe", true,
350 "---", null,
351 "context-bookmarkframe", true,
352 "context-saveframe", true,
353 "---", null,
354 "context-printframe", true,
355 "---", null,
356 "context-viewframeinfo", true], null].concat(inspectItems));
357 closeContextMenu();
358 openContextMenuFor(textarea, false, true); // Invoke context menu for next test, but wait for the spellcheck.
359 break;
361 case 14:
362 // Context menu for textarea
363 checkContextMenu(["*chubbiness", true, // spelling suggestion
364 "spell-add-to-dictionary", true,
365 "---", null,
366 "context-undo", false,
367 "---", null,
368 "context-cut", false,
369 "context-copy", false,
370 "context-paste", null, // ignore clipboard state
371 "context-delete", false,
372 "---", null,
373 "context-selectall", true,
374 "---", null,
375 "spell-check-enabled", true,
376 "spell-dictionaries", true,
377 ["spell-check-dictionary-en-US", true,
378 "---", null,
379 "spell-add-dictionaries", true], null
380 ].concat(inspectItems));
381 contextMenu.ownerDocument.getElementById("spell-add-to-dictionary").doCommand(); // Add to dictionary
382 closeContextMenu();
383 openContextMenuFor(text); // Invoke context menu for next test.
384 break;
386 case 15:
387 // Re-check context menu for plain text to make sure it hasn't changed
388 checkContextMenu(plainTextItems);
389 closeContextMenu();
390 openContextMenuFor(textarea, false, true); // Invoke context menu for next test.
391 break;
393 case 16:
394 // Context menu for textarea after a word has been added
395 // to the dictionary
396 checkContextMenu(["spell-undo-add-to-dictionary", true,
397 "---", null,
398 "context-undo", false,
399 "---", null,
400 "context-cut", false,
401 "context-copy", false,
402 "context-paste", null, // ignore clipboard state
403 "context-delete", false,
404 "---", null,
405 "context-selectall", true,
406 "---", null,
407 "spell-check-enabled", true,
408 "spell-dictionaries", true,
409 ["spell-check-dictionary-en-US", true,
410 "---", null,
411 "spell-add-dictionaries", true], null
412 ].concat(inspectItems));
413 contextMenu.ownerDocument.getElementById("spell-undo-add-to-dictionary").doCommand(); // Undo add to dictionary
414 closeContextMenu();
415 openContextMenuFor(contenteditable, false, true);
416 break;
418 case 17:
419 // Context menu for contenteditable
420 checkContextMenu(["spell-no-suggestions", false,
421 "spell-add-to-dictionary", true,
422 "---", null,
423 "context-undo", false,
424 "---", null,
425 "context-cut", false,
426 "context-copy", false,
427 "context-paste", null, // ignore clipboard state
428 "context-delete", false,
429 "---", null,
430 "context-selectall", true,
431 "---", null,
432 "spell-check-enabled", true,
433 "spell-dictionaries", true,
434 ["spell-check-dictionary-en-US", true,
435 "---", null,
436 "spell-add-dictionaries", true], null
437 ].concat(inspectItems));
439 closeContextMenu();
440 openContextMenuFor(link); // Invoke context menu for next test.
441 break;
443 case 18:
444 executeCopyCommand("cmd_copyLink", "http://mozilla.com/");
445 closeContextMenu();
446 openContextMenuFor(pagemenu); // Invoke context menu for next test.
447 break;
449 case 19:
450 // Context menu for element with assigned content context menu
451 checkContextMenu(["+Plain item", {type: "", icon: "", checked: false, disabled: false},
452 "+Disabled item", {type: "", icon: "", checked: false, disabled: true},
453 "+Item w/ textContent", {type: "", icon: "", checked: false, disabled: false},
454 "---", null,
455 "+Checkbox", {type: "checkbox", icon: "", checked: true, disabled: false},
456 "---", null,
457 "+Radio1", {type: "checkbox", icon: "", checked: true, disabled: false},
458 "+Radio2", {type: "checkbox", icon: "", checked: false, disabled: false},
459 "+Radio3", {type: "checkbox", icon: "", checked: false, disabled: false},
460 "---", null,
461 "+Item w/ icon", {type: "", icon: "favicon.ico", checked: false, disabled: false},
462 "+Item w/ bad icon", {type: "", icon: "", checked: false, disabled: false},
463 "---", null,
464 "generated-submenu-1", true,
465 ["+Radio1", {type: "checkbox", icon: "", checked: false, disabled: false},
466 "+Radio2", {type: "checkbox", icon: "", checked: true, disabled: false},
467 "+Radio3", {type: "checkbox", icon: "", checked: false, disabled: false},
468 "---", null,
469 "+Checkbox", {type: "checkbox", icon: "", checked: false, disabled: false}], null,
470 "---", null,
471 "context-back", false,
472 "context-forward", false,
473 "context-reload", true,
474 "---", null,
475 "context-bookmarkpage", true,
476 "context-savepage", true,
477 "---", null,
478 "context-viewbgimage", false,
479 "context-selectall", true,
480 "---", null,
481 "context-viewsource", true,
482 "context-viewinfo", true
483 ].concat(inspectItems));
485 invokeItemAction("0");
486 closeContextMenu();
488 // run mozRequestFullScreen on the element we're testing
489 var full_screen_element = subwindow.document.getElementById("test-dom-full-screen");
490 var openDomFullScreen = function() {
491 subwindow.removeEventListener("mozfullscreenchange", openDomFullScreen, false);
492 openContextMenuFor(dom_full_screen, true); // Invoke context menu for next test.
493 }
494 subwindow.addEventListener("mozfullscreenchange", openDomFullScreen, false);
495 SpecialPowers.setBoolPref("full-screen-api.approval-required", false);
496 SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", false);
497 full_screen_element.mozRequestFullScreen();
498 break;
500 case 20:
501 // Context menu for DOM Fullscreen mode (NOTE: this is *NOT* on an img)
502 checkContextMenu(["context-leave-dom-fullscreen", true,
503 "---", null,
504 "context-back", false,
505 "context-forward", false,
506 "context-reload", true,
507 "---", null,
508 "context-bookmarkpage", true,
509 "context-savepage", true,
510 "---", null,
511 "context-viewbgimage", false,
512 "context-selectall", true,
513 "---", null,
514 "context-viewsource", true,
515 "context-viewinfo", true
516 ].concat(inspectItems));
517 closeContextMenu();
518 var full_screen_element = subwindow.document.getElementById("test-dom-full-screen");
519 var openPagemenu = function() {
520 subwindow.removeEventListener("mozfullscreenchange", openPagemenu, false);
521 SpecialPowers.clearUserPref("full-screen-api.approval-required");
522 SpecialPowers.clearUserPref("full-screen-api.allow-trusted-requests-only");
523 openContextMenuFor(pagemenu, true); // Invoke context menu for next test.
524 }
525 subwindow.addEventListener("mozfullscreenchange", openPagemenu, false);
526 subwindow.document.mozCancelFullScreen();
527 break;
529 case 21:
530 // Context menu for element with assigned content context menu
531 // The shift key should bypass content context menu processing
532 checkContextMenu(["context-back", false,
533 "context-forward", false,
534 "context-reload", true,
535 "---", null,
536 "context-bookmarkpage", true,
537 "context-savepage", true,
538 "---", null,
539 "context-viewbgimage", false,
540 "context-selectall", true,
541 "---", null,
542 "context-viewsource", true,
543 "context-viewinfo", true
544 ].concat(inspectItems));
545 closeContextMenu();
546 selectText(selecttext); // Select text prior to opening context menu.
547 openContextMenuFor(selecttext); // Invoke context menu for next test.
548 return;
550 case 22:
551 // Context menu for selected text
552 if (SpecialPowers.Services.appinfo.OS == "Darwin") {
553 // This test is only enabled on Mac due to bug 736399.
554 checkContextMenu(["context-copy", true,
555 "context-selectall", true,
556 "---", null,
557 "context-searchselect", true,
558 "context-viewpartialsource-selection", true
559 ].concat(inspectItems));
560 }
561 closeContextMenu();
562 selectText(selecttextlink); // Select text prior to opening context menu.
563 openContextMenuFor(selecttextlink); // Invoke context menu for next test.
564 return;
566 case 23:
567 // Context menu for selected text which matches valid URL pattern
568 if (SpecialPowers.Services.appinfo.OS == "Darwin") {
569 // This test is only enabled on Mac due to bug 736399.
570 if (perWindowPrivateBrowsing) {
571 checkContextMenu(["context-openlinkincurrent", true,
572 "context-openlinkintab", true,
573 "context-openlink", true,
574 "context-openlinkprivate", true,
575 "---", null,
576 "context-bookmarklink", true,
577 "context-savelink", true,
578 "context-copy", true,
579 "context-selectall", true,
580 "---", null,
581 "context-searchselect", true,
582 "context-viewpartialsource-selection", true
583 ].concat(inspectItems));
584 } else {
585 checkContextMenu(["context-openlinkincurrent", true,
586 "context-openlinkintab", true,
587 "context-openlink", true,
588 "---", null,
589 "context-bookmarklink", true,
590 "context-savelink", true,
591 "context-copy", true,
592 "context-selectall", true,
593 "---", null,
594 "context-searchselect", true,
595 "context-viewpartialsource-selection", true
596 ].concat(inspectItems));
597 }
598 }
599 closeContextMenu();
600 // clear the selection because following tests don't expect any selection
601 subwindow.getSelection().removeAllRanges();
603 openContextMenuFor(imagelink)
604 break;
606 case 24:
607 // Context menu for image link
608 if (perWindowPrivateBrowsing) {
609 checkContextMenu(["context-openlinkintab", true,
610 "context-openlink", true,
611 "context-openlinkprivate", true,
612 "---", null,
613 "context-bookmarklink", true,
614 "context-savelink", true,
615 "context-copylink", true,
616 "---", null,
617 "context-viewimage", true,
618 "context-copyimage-contents", true,
619 "context-copyimage", true,
620 "---", null,
621 "context-saveimage", true,
622 "context-sendimage", true,
623 "context-setDesktopBackground", true,
624 "context-viewimageinfo", true
625 ].concat(inspectItems));
626 } else {
627 checkContextMenu(["context-openlinkintab", true,
628 "context-openlink", true,
629 "---", null,
630 "context-bookmarklink", true,
631 "context-savelink", true,
632 "context-copylink", true,
633 "---", null,
634 "context-viewimage", true,
635 "context-copyimage-contents", true,
636 "context-copyimage", true,
637 "---", null,
638 "context-saveimage", true,
639 "context-sendimage", true,
640 "context-setDesktopBackground", true,
641 "context-viewimageinfo", true
642 ].concat(inspectItems));
643 }
644 closeContextMenu();
645 selectInputText(select_inputtext); // Select text prior to opening context menu.
646 openContextMenuFor(select_inputtext); // Invoke context menu for next test.
647 return;
649 case 25:
650 // Context menu for selected text in input
651 checkContextMenu(["context-undo", false,
652 "---", null,
653 "context-cut", true,
654 "context-copy", true,
655 "context-paste", null, // ignore clipboard state
656 "context-delete", true,
657 "---", null,
658 "context-selectall", true,
659 "context-searchselect",true,
660 "---", null,
661 "spell-check-enabled", true
662 ].concat(inspectItems));
663 closeContextMenu();
664 selectInputText(select_inputtext_password); // Select text prior to opening context menu.
665 openContextMenuFor(select_inputtext_password); // Invoke context menu for next test.
666 return;
668 case 26:
669 // Context menu for selected text in input[type="password"]
670 checkContextMenu(["context-undo", false,
671 "---", null,
672 "context-cut", true,
673 "context-copy", true,
674 "context-paste", null, // ignore clipboard state
675 "context-delete", true,
676 "---", null,
677 "context-selectall", true,
678 "---", null,
679 "spell-check-enabled", true,
680 //spell checker is shown on input[type="password"] on this testcase
681 "spell-dictionaries", true,
682 ["spell-check-dictionary-en-US", true,
683 "---", null,
684 "spell-add-dictionaries", true], null
685 ].concat(inspectItems));
686 closeContextMenu();
687 subwindow.getSelection().removeAllRanges();
688 openContextMenuFor(plugin);
689 return;
691 case 27:
692 // Context menu for click-to-play blocked plugin
693 checkContextMenu(["context-ctp-play", true,
694 "context-ctp-hide", true,
695 "---", null,
696 "context-back", false,
697 "context-forward", false,
698 "context-reload", true,
699 "---", null,
700 "context-bookmarkpage", true,
701 "context-savepage", true,
702 "---", null,
703 "context-viewbgimage", false,
704 "context-selectall", true,
705 "---", null,
706 "context-viewsource", true,
707 "context-viewinfo", true
708 ].concat(inspectItems));
709 closeContextMenu();
710 SpecialPowers.clearUserPref("plugins.click_to_play");
711 getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED;
712 openContextMenuFor(longdesc);
713 return;
715 case 28:
716 // Context menu for an image with longdesc
717 checkContextMenu(["context-viewimage", true,
718 "context-copyimage-contents", true,
719 "context-copyimage", true,
720 "---", null,
721 "context-saveimage", true,
722 "context-sendimage", true,
723 "context-setDesktopBackground", true,
724 "context-viewimageinfo", true,
725 "context-viewimagedesc", true
726 ].concat(inspectItems));
727 closeContextMenu();
728 openContextMenuFor(srcdoc);
729 return;
731 case 29:
732 // Context menu for an iframe with srcdoc attribute set
733 checkContextMenu(["context-back", false,
734 "context-forward", false,
735 "context-reload", true,
736 "---", null,
737 "context-bookmarkpage", true,
738 "context-savepage", true,
739 "---", null,
740 "context-viewbgimage", false,
741 "context-selectall", true,
742 "frame", null,
743 ["context-reloadframe", true,
744 "---", null,
745 "context-saveframe", true,
746 "---", null,
747 "context-printframe", true,
748 "---", null,
749 "context-viewframesource", true,
750 "context-viewframeinfo", true], null,
751 "---", null,
752 "context-viewsource", true,
753 "context-viewinfo", true
754 ].concat(inspectItems));
755 closeContextMenu();
756 openContextMenuFor(inputspellfalse, false, true); // Invoke context menu for next test.
757 break;
759 case 30:
760 // Context menu for text input field with spellcheck=false
761 checkContextMenu(["context-undo", false,
762 "---", null,
763 "context-cut", false,
764 "context-copy", false,
765 "context-paste", null, // ignore clipboard state
766 "context-delete", false,
767 "---", null,
768 "context-selectall", true,
769 "---", null,
770 "spell-add-dictionaries-main", true,
771 ].concat(inspectItems));
773 // finish test
774 subwindow.close();
775 SimpleTest.finish();
776 return;
778 /*
779 * Other things that would be nice to test:
780 * - check state of disabled items
781 * - test execution of menu items (maybe as a separate test?)
782 */
784 default:
785 ok(false, "Unexpected invocation of test #" + testNum);
786 subwindow.close();
787 SimpleTest.finish();
788 return;
789 }
791 }
794 var testNum = 1;
795 var subwindow, chromeWin, contextMenu;
796 var text, link, mailto, input, img, canvas, video_ok, video_bad, video_bad2,
797 iframe, video_in_iframe, image_in_iframe, textarea, contenteditable,
798 pagemenu, dom_full_screen, plainTextItems, audio_in_video,
799 selecttext, selecttextlink, imagelink, select_inputtext, select_inputtext_password,
800 plugin, longdesc, iframe, inputspellfalse;
802 function startTest() {
803 chromeWin = SpecialPowers.wrap(subwindow)
804 .QueryInterface(Ci.nsIInterfaceRequestor)
805 .getInterface(Ci.nsIWebNavigation)
806 .QueryInterface(Ci.nsIDocShellTreeItem)
807 .rootTreeItem
808 .QueryInterface(Ci.nsIInterfaceRequestor)
809 .getInterface(Ci.nsIDOMWindow)
810 .QueryInterface(Ci.nsIDOMChromeWindow);
811 contextMenu = chromeWin.document.getElementById("contentAreaContextMenu");
812 ok(contextMenu, "Got context menu XUL");
814 if (chromeWin.document.getElementById("Browser:Stop").getAttribute("disabled") != "true") {
815 todo(false, "Wait for subwindow to load... (This should usually happen once.)");
816 SimpleTest.executeSoon(startTest);
817 return;
818 }
820 subwindow.allowFullscreen = true;
821 lastElement = null;
823 text = subwindow.document.getElementById("test-text");
824 link = subwindow.document.getElementById("test-link");
825 imagelink = subwindow.document.getElementById("test-image-link");
826 mailto = subwindow.document.getElementById("test-mailto");
827 input = subwindow.document.getElementById("test-input");
828 img = subwindow.document.getElementById("test-image");
829 canvas = subwindow.document.getElementById("test-canvas");
830 video_ok = subwindow.document.getElementById("test-video-ok");
831 audio_in_video = subwindow.document.getElementById("test-audio-in-video");
832 video_bad = subwindow.document.getElementById("test-video-bad");
833 video_bad2 = subwindow.document.getElementById("test-video-bad2");
834 iframe = subwindow.document.getElementById("test-iframe");
835 video_in_iframe = subwindow.document.getElementById("test-video-in-iframe").contentDocument.getElementsByTagName("video")[0];
836 video_in_iframe.pause();
837 image_in_iframe = subwindow.document.getElementById("test-image-in-iframe").contentDocument.getElementsByTagName("img")[0];
838 textarea = subwindow.document.getElementById("test-textarea");
839 contenteditable = subwindow.document.getElementById("test-contenteditable");
840 contenteditable.focus(); // content editable needs to be focused to enable spellcheck
841 inputspellfalse = subwindow.document.getElementById("test-contenteditable-spellcheck-false");
842 inputspellfalse.focus(); // content editable needs to be focused to enable spellcheck
843 pagemenu = subwindow.document.getElementById("test-pagemenu");
844 dom_full_screen = subwindow.document.getElementById("test-dom-full-screen");
845 selecttext = subwindow.document.getElementById("test-select-text");
846 selecttextlink = subwindow.document.getElementById("test-select-text-link");
847 select_inputtext = subwindow.document.getElementById("test-select-input-text");
848 select_inputtext_password = subwindow.document.getElementById("test-select-input-text-type-password");
849 plugin = subwindow.document.getElementById("test-plugin");
850 longdesc = subwindow.document.getElementById("test-longdesc");
851 srcdoc = subwindow.document.getElementById("test-srcdoc");
853 contextMenu.addEventListener("popupshown", function() { runTest(++testNum); }, false);
854 runTest(1);
855 }
857 // We open this in a separate window, because the Mochitests run inside a frame.
858 // The frame causes an extra menu item, and prevents running the test
859 // standalone (ie, clicking the test name in the Mochitest window) to see
860 // success/failure messages.
861 var painted = false, loaded = false;
863 function waitForEvents(event)
864 {
865 if (event.type == "MozAfterPaint")
866 painted = true;
867 else if (event.type == "load")
868 loaded = true;
869 if (painted && loaded) {
870 subwindow.removeEventListener("MozAfterPaint", waitForEvents, false);
871 subwindow.onload = null;
872 startTest();
873 }
874 }
876 const isOSXMtnLion = navigator.userAgent.indexOf("Mac OS X 10.8") != -1;
878 if (isOSXMtnLion) {
879 todo(false, "Mountain Lion doesn't like this test (bug 792304)");
880 } else {
881 SpecialPowers.setBoolPref("plugins.click_to_play", true);
882 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
884 var subwindow = window.open("./subtst_contextmenu.html", "contextmenu-subtext", "width=600,height=800");
885 subwindow.addEventListener("MozAfterPaint", waitForEvents, false);
886 subwindow.onload = waitForEvents;
888 SimpleTest.waitForExplicitFinish();
889 }
890 </script>
891 </pre>
892 </body>
893 </html>