browser/base/content/test/general/test_contextmenu.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/test_contextmenu.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,893 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Tests for browser context menu</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +  <script type="text/javascript" src="head_plain.js"></script>
    1.12 +</head>
    1.13 +<body>
    1.14 +Browser context menu tests.
    1.15 +<p id="display"></p>
    1.16 +
    1.17 +<div id="content">
    1.18 +</div>
    1.19 +
    1.20 +<pre id="test">
    1.21 +<script> var perWindowPrivateBrowsing = false; </script>
    1.22 +<script type="text/javascript" src="privateBrowsingMode.js"></script>
    1.23 +<script type="text/javascript" src="contextmenu_common.js"></script>
    1.24 +<script class="testbody" type="text/javascript">
    1.25 +
    1.26 +SpecialPowers.Cu.import("resource://gre/modules/InlineSpellChecker.jsm", window);
    1.27 +SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window);
    1.28 +
    1.29 +const Ci = SpecialPowers.Ci;
    1.30 +
    1.31 +function executeCopyCommand(command, expectedValue)
    1.32 +{
    1.33 +  // Just execute the command directly rather than simulating a context menu
    1.34 +  // press to avoid having to deal with its asynchronous nature
    1.35 +  SpecialPowers.wrap(subwindow).controllers.getControllerForCommand(command).doCommand(command);
    1.36 +
    1.37 +  // The easiest way to check the clipboard is to paste the contents into a
    1.38 +  // textbox
    1.39 +  input.focus();
    1.40 +  input.value = "";
    1.41 +  SpecialPowers.wrap(input).controllers.getControllerForCommand("cmd_paste").doCommand("cmd_paste");
    1.42 +  is(input.value, expectedValue, "paste for command " + command);
    1.43 +}
    1.44 +
    1.45 +function invokeItemAction(generatedItemId)
    1.46 +{
    1.47 +  var item = contextMenu.getElementsByAttribute("generateditemid",
    1.48 +                                                generatedItemId)[0];
    1.49 +  ok(item, "Got generated XUL menu item");
    1.50 +  item.doCommand();
    1.51 +  ok(!pagemenu.hasAttribute("hopeless"), "attribute got removed");
    1.52 +}
    1.53 +
    1.54 +function selectText(element) {
    1.55 +  // Clear any previous selections before selecting new element.
    1.56 +  subwindow.getSelection().removeAllRanges();
    1.57 +
    1.58 +  var div = subwindow.document.createRange();
    1.59 +  div.setStartBefore(element);
    1.60 +  div.setEndAfter(element);
    1.61 +  subwindow.getSelection().addRange(div);
    1.62 +}
    1.63 +
    1.64 +function selectInputText(element) {
    1.65 +  // Clear any previous selections before selecting new element.
    1.66 +  subwindow.getSelection().removeAllRanges();
    1.67 +
    1.68 +  element.select();
    1.69 +}
    1.70 +
    1.71 +/*
    1.72 + * runTest
    1.73 + *
    1.74 + * Called by a popupshowing event handler. Each test checks for expected menu
    1.75 + * contents, closes the popup, and finally triggers the popup on a new element
    1.76 + * (thus kicking off another cycle).
    1.77 + *
    1.78 + */
    1.79 +function runTest(testNum) {
    1.80 +  // Seems we need to enable this again, or sendKeyEvent() complaints.
    1.81 +  ok(true, "Starting test #" + testNum);
    1.82 +
    1.83 +  var inspectItems = [];
    1.84 +  if (SpecialPowers.getBoolPref("devtools.inspector.enabled")) {
    1.85 +    inspectItems = ["---", null,
    1.86 +                    "context-inspect", true];
    1.87 +  }
    1.88 +
    1.89 +  switch (testNum) {
    1.90 +    case 1:
    1.91 +        // Invoke context menu for next test.
    1.92 +        openContextMenuFor(text);
    1.93 +        break;
    1.94 +
    1.95 +    case 2:
    1.96 +        // Context menu for plain text
    1.97 +        plainTextItems = ["context-back",         false,
    1.98 +                          "context-forward",      false,
    1.99 +                          "context-reload",       true,
   1.100 +                          "---",                  null,
   1.101 +                          "context-bookmarkpage", true,
   1.102 +                          "context-savepage",     true,
   1.103 +                          "---",                  null,
   1.104 +                          "context-viewbgimage",  false,
   1.105 +                          "context-selectall",    true,
   1.106 +                          "---",                  null,
   1.107 +                          "context-viewsource",   true,
   1.108 +                          "context-viewinfo",     true
   1.109 +                         ].concat(inspectItems);
   1.110 +        checkContextMenu(plainTextItems);
   1.111 +        closeContextMenu();
   1.112 +        openContextMenuFor(link); // Invoke context menu for next test.
   1.113 +        break;
   1.114 +
   1.115 +    case 3:
   1.116 +        // Context menu for text link
   1.117 +        if (perWindowPrivateBrowsing) {
   1.118 +          checkContextMenu(["context-openlinkintab", true,
   1.119 +                            "context-openlink",      true,
   1.120 +                            "context-openlinkprivate", true,
   1.121 +                            "---",                   null,
   1.122 +                            "context-bookmarklink",  true,
   1.123 +                            "context-savelink",      true,
   1.124 +                            "context-copylink",      true,
   1.125 +                            "context-searchselect",  true
   1.126 +                           ].concat(inspectItems));
   1.127 +        } else {
   1.128 +          checkContextMenu(["context-openlinkintab", true,
   1.129 +                            "context-openlink",      true,
   1.130 +                            "---",                   null,
   1.131 +                            "context-bookmarklink",  true,
   1.132 +                            "context-savelink",      true,
   1.133 +                            "context-copylink",      true,
   1.134 +                            "context-searchselect",  true
   1.135 +                           ].concat(inspectItems));
   1.136 +        }
   1.137 +        closeContextMenu();
   1.138 +        openContextMenuFor(mailto); // Invoke context menu for next test.
   1.139 +        break;
   1.140 +
   1.141 +    case 4:
   1.142 +        // Context menu for text mailto-link
   1.143 +        checkContextMenu(["context-copyemail", true,
   1.144 +                          "context-searchselect", true
   1.145 +                        ].concat(inspectItems));
   1.146 +        closeContextMenu();
   1.147 +        openContextMenuFor(img); // Invoke context menu for next test.
   1.148 +        break;
   1.149 +
   1.150 +    case 5:
   1.151 +        // Context menu for an image
   1.152 +        checkContextMenu(["context-viewimage",            true,
   1.153 +                          "context-copyimage-contents",   true,
   1.154 +                          "context-copyimage",            true,
   1.155 +                          "---",                          null,
   1.156 +                          "context-saveimage",            true,
   1.157 +                          "context-sendimage",            true,
   1.158 +                          "context-setDesktopBackground", true,
   1.159 +                          "context-viewimageinfo",        true
   1.160 +                         ].concat(inspectItems));
   1.161 +        closeContextMenu();
   1.162 +        openContextMenuFor(canvas); // Invoke context menu for next test.
   1.163 +        break;
   1.164 +
   1.165 +    case 6:
   1.166 +        // Context menu for a canvas
   1.167 +        checkContextMenu(["context-viewimage",    true,
   1.168 +                          "context-saveimage",    true,
   1.169 +                          "context-bookmarkpage", true,
   1.170 +                          "context-selectall",    true
   1.171 +                         ].concat(inspectItems));
   1.172 +        closeContextMenu();
   1.173 +        openContextMenuFor(video_ok); // Invoke context menu for next test.
   1.174 +        break;
   1.175 +
   1.176 +    case 7:
   1.177 +        // Context menu for a video (with a VALID media source)
   1.178 +        checkContextMenu(["context-media-play",         true,
   1.179 +                          "context-media-mute",         true,
   1.180 +                          "context-media-playbackrate", null,
   1.181 +                              ["context-media-playbackrate-050x", true,
   1.182 +                               "context-media-playbackrate-100x", true,
   1.183 +                               "context-media-playbackrate-150x", true,
   1.184 +                               "context-media-playbackrate-200x", true], null,
   1.185 +                          "context-media-hidecontrols", true,
   1.186 +                          "context-video-showstats",    true,
   1.187 +                          "context-video-fullscreen",   true,
   1.188 +                          "---",                        null,
   1.189 +                          "context-viewvideo",          true,
   1.190 +                          "context-copyvideourl",       true,
   1.191 +                          "---",                        null,
   1.192 +                          "context-savevideo",          true,
   1.193 +                          "context-video-saveimage",    true,
   1.194 +                          "context-sendvideo",          true
   1.195 +                         ].concat(inspectItems));
   1.196 +        closeContextMenu();
   1.197 +        openContextMenuFor(audio_in_video); // Invoke context menu for next test.
   1.198 +        break;
   1.199 +
   1.200 +    case 8:
   1.201 +        // Context menu for a video (with an audio-only file)
   1.202 +          checkContextMenu(["context-media-play",         true,
   1.203 +                            "context-media-mute",         true,
   1.204 +                            "context-media-playbackrate", null,
   1.205 +                                ["context-media-playbackrate-050x", true,
   1.206 +                                 "context-media-playbackrate-100x", true,
   1.207 +                                 "context-media-playbackrate-150x", true,
   1.208 +                                 "context-media-playbackrate-200x", true], null,
   1.209 +                            "context-media-showcontrols", true,
   1.210 +                            "---",                        null,
   1.211 +                            "context-copyaudiourl",       true,
   1.212 +                            "---",                        null,
   1.213 +                            "context-saveaudio",          true,
   1.214 +                            "context-sendaudio",          true
   1.215 +                           ].concat(inspectItems));
   1.216 +        closeContextMenu();
   1.217 +        openContextMenuFor(video_bad); // Invoke context menu for next test.
   1.218 +        break;
   1.219 +
   1.220 +    case 9:
   1.221 +        // Context menu for a video (with an INVALID media source)
   1.222 +        checkContextMenu(["context-media-play",         false,
   1.223 +                          "context-media-mute",         false,
   1.224 +                          "context-media-playbackrate", null,
   1.225 +                              ["context-media-playbackrate-050x", false,
   1.226 +                               "context-media-playbackrate-100x", false,
   1.227 +                               "context-media-playbackrate-150x", false,
   1.228 +                               "context-media-playbackrate-200x", false], null,
   1.229 +                          "context-media-hidecontrols", false,
   1.230 +                          "context-video-showstats",    false,
   1.231 +                          "context-video-fullscreen",   false,
   1.232 +                          "---",                        null,
   1.233 +                          "context-viewvideo",          true,
   1.234 +                          "context-copyvideourl",       true,
   1.235 +                          "---",                        null,
   1.236 +                          "context-savevideo",          true,
   1.237 +                          "context-video-saveimage",    false,
   1.238 +                          "context-sendvideo",          true
   1.239 +                         ].concat(inspectItems));
   1.240 +        closeContextMenu();
   1.241 +        openContextMenuFor(video_bad2); // Invoke context menu for next test.
   1.242 +        break;
   1.243 +
   1.244 +    case 10:
   1.245 +        // Context menu for a video (with an INVALID media source)
   1.246 +        checkContextMenu(["context-media-play",         false,
   1.247 +                          "context-media-mute",         false,
   1.248 +                          "context-media-playbackrate", null,
   1.249 +                              ["context-media-playbackrate-050x", false,
   1.250 +                               "context-media-playbackrate-100x", false,
   1.251 +                               "context-media-playbackrate-150x", false,
   1.252 +                               "context-media-playbackrate-200x", false], null,
   1.253 +                          "context-media-hidecontrols", false,
   1.254 +                          "context-video-showstats",    false,
   1.255 +                          "context-video-fullscreen",   false,
   1.256 +                          "---",                        null,
   1.257 +                          "context-viewvideo",          false,
   1.258 +                          "context-copyvideourl",       false,
   1.259 +                          "---",                        null,
   1.260 +                          "context-savevideo",          false,
   1.261 +                          "context-video-saveimage",    false,
   1.262 +                          "context-sendvideo",          false
   1.263 +                         ].concat(inspectItems));
   1.264 +        closeContextMenu();
   1.265 +        openContextMenuFor(iframe); // Invoke context menu for next test.
   1.266 +        break;
   1.267 +
   1.268 +    case 11:
   1.269 +        // Context menu for an iframe
   1.270 +        checkContextMenu(["context-back",         false,
   1.271 +                          "context-forward",      false,
   1.272 +                          "context-reload",       true,
   1.273 +                          "---",                  null,
   1.274 +                          "context-bookmarkpage", true,
   1.275 +                          "context-savepage",     true,
   1.276 +                          "---",                  null,
   1.277 +                          "context-viewbgimage",  false,
   1.278 +                          "context-selectall",    true,
   1.279 +                          "frame",                null,
   1.280 +                              ["context-showonlythisframe", true,
   1.281 +                               "context-openframeintab",    true,
   1.282 +                               "context-openframe",         true,
   1.283 +                               "---",                       null,
   1.284 +                               "context-reloadframe",       true,
   1.285 +                               "---",                       null,
   1.286 +                               "context-bookmarkframe",     true,
   1.287 +                               "context-saveframe",         true,
   1.288 +                               "---",                       null,
   1.289 +                               "context-printframe",        true,
   1.290 +                               "---",                       null,
   1.291 +                               "context-viewframesource",   true,
   1.292 +                               "context-viewframeinfo",     true], null,
   1.293 +                          "---",                  null,
   1.294 +                          "context-viewsource",   true,
   1.295 +                          "context-viewinfo",     true
   1.296 +                         ].concat(inspectItems));
   1.297 +        closeContextMenu();
   1.298 +        openContextMenuFor(video_in_iframe); // Invoke context menu for next test.
   1.299 +        break;
   1.300 +
   1.301 +    case 12:
   1.302 +        // Context menu for a video in an iframe
   1.303 +        checkContextMenu(["context-media-play",         true,
   1.304 +                          "context-media-mute",         true,
   1.305 +                          "context-media-playbackrate", null,
   1.306 +                              ["context-media-playbackrate-050x", true,
   1.307 +                               "context-media-playbackrate-100x", true,
   1.308 +                               "context-media-playbackrate-150x", true,
   1.309 +                               "context-media-playbackrate-200x", true], null,
   1.310 +                          "context-media-hidecontrols", true,
   1.311 +                          "context-video-showstats",    true,
   1.312 +                          "context-video-fullscreen",   true,
   1.313 +                          "---",                        null,
   1.314 +                          "context-viewvideo",          true,
   1.315 +                          "context-copyvideourl",       true,
   1.316 +                          "---",                        null,
   1.317 +                          "context-savevideo",          true,
   1.318 +                          "context-video-saveimage",    true,
   1.319 +                          "context-sendvideo",          true,
   1.320 +                          "frame",                null,
   1.321 +                              ["context-showonlythisframe", true,
   1.322 +                               "context-openframeintab",    true,
   1.323 +                               "context-openframe",         true,
   1.324 +                               "---",                       null,
   1.325 +                               "context-reloadframe",       true,
   1.326 +                               "---",                       null,
   1.327 +                               "context-bookmarkframe",     true,
   1.328 +                               "context-saveframe",         true,
   1.329 +                               "---",                       null,
   1.330 +                               "context-printframe",        true,
   1.331 +                               "---",                       null,
   1.332 +                               "context-viewframeinfo",     true], null].concat(inspectItems));
   1.333 +        closeContextMenu();
   1.334 +        openContextMenuFor(image_in_iframe); // Invoke context menu for next test.
   1.335 +        break;
   1.336 +
   1.337 +    case 13:
   1.338 +        // Context menu for an image in an iframe
   1.339 +        checkContextMenu(["context-viewimage",            true,
   1.340 +                          "context-copyimage-contents",   true,
   1.341 +                          "context-copyimage",            true,
   1.342 +                          "---",                          null,
   1.343 +                          "context-saveimage",            true,
   1.344 +                          "context-sendimage",            true,
   1.345 +                          "context-setDesktopBackground", true,
   1.346 +                          "context-viewimageinfo",        true,
   1.347 +                          "frame",                null,
   1.348 +                              ["context-showonlythisframe", true,
   1.349 +                               "context-openframeintab",    true,
   1.350 +                               "context-openframe",         true,
   1.351 +                               "---",                       null,
   1.352 +                               "context-reloadframe",       true,
   1.353 +                               "---",                       null,
   1.354 +                               "context-bookmarkframe",     true,
   1.355 +                               "context-saveframe",         true,
   1.356 +                               "---",                       null,
   1.357 +                               "context-printframe",        true,
   1.358 +                               "---",                       null,
   1.359 +                               "context-viewframeinfo",     true], null].concat(inspectItems));
   1.360 +        closeContextMenu();
   1.361 +        openContextMenuFor(textarea, false, true); // Invoke context menu for next test, but wait for the spellcheck.
   1.362 +        break;
   1.363 +
   1.364 +    case 14:
   1.365 +        // Context menu for textarea
   1.366 +        checkContextMenu(["*chubbiness",         true, // spelling suggestion
   1.367 +                          "spell-add-to-dictionary", true,
   1.368 +                          "---",                 null,
   1.369 +                          "context-undo",        false,
   1.370 +                          "---",                 null,
   1.371 +                          "context-cut",         false,
   1.372 +                          "context-copy",        false,
   1.373 +                          "context-paste",       null, // ignore clipboard state
   1.374 +                          "context-delete",      false,
   1.375 +                          "---",                 null,
   1.376 +                          "context-selectall",   true,
   1.377 +                          "---",                 null,
   1.378 +                          "spell-check-enabled", true,
   1.379 +                          "spell-dictionaries",  true,
   1.380 +                              ["spell-check-dictionary-en-US", true,
   1.381 +                               "---",                          null,
   1.382 +                               "spell-add-dictionaries",       true], null
   1.383 +                         ].concat(inspectItems));
   1.384 +        contextMenu.ownerDocument.getElementById("spell-add-to-dictionary").doCommand(); // Add to dictionary
   1.385 +        closeContextMenu();
   1.386 +        openContextMenuFor(text); // Invoke context menu for next test.
   1.387 +        break;
   1.388 +
   1.389 +    case 15:
   1.390 +        // Re-check context menu for plain text to make sure it hasn't changed
   1.391 +        checkContextMenu(plainTextItems);
   1.392 +        closeContextMenu();
   1.393 +        openContextMenuFor(textarea, false, true); // Invoke context menu for next test.
   1.394 +        break;
   1.395 +
   1.396 +    case 16:
   1.397 +        // Context menu for textarea after a word has been added
   1.398 +        // to the dictionary
   1.399 +        checkContextMenu(["spell-undo-add-to-dictionary", true,
   1.400 +                          "---",                 null,
   1.401 +                          "context-undo",        false,
   1.402 +                          "---",                 null,
   1.403 +                          "context-cut",         false,
   1.404 +                          "context-copy",        false,
   1.405 +                          "context-paste",       null, // ignore clipboard state
   1.406 +                          "context-delete",      false,
   1.407 +                          "---",                 null,
   1.408 +                          "context-selectall",   true,
   1.409 +                          "---",                 null,
   1.410 +                          "spell-check-enabled", true,
   1.411 +                          "spell-dictionaries",  true,
   1.412 +                              ["spell-check-dictionary-en-US", true,
   1.413 +                               "---",                          null,
   1.414 +                               "spell-add-dictionaries",       true], null
   1.415 +                         ].concat(inspectItems));
   1.416 +        contextMenu.ownerDocument.getElementById("spell-undo-add-to-dictionary").doCommand(); // Undo add to dictionary
   1.417 +        closeContextMenu();
   1.418 +        openContextMenuFor(contenteditable, false, true);
   1.419 +        break;
   1.420 +
   1.421 +    case 17:
   1.422 +        // Context menu for contenteditable
   1.423 +        checkContextMenu(["spell-no-suggestions", false,
   1.424 +                          "spell-add-to-dictionary", true,
   1.425 +                          "---",                 null,
   1.426 +                          "context-undo",        false,
   1.427 +                          "---",                 null,
   1.428 +                          "context-cut",         false,
   1.429 +                          "context-copy",        false,
   1.430 +                          "context-paste",       null, // ignore clipboard state
   1.431 +                          "context-delete",      false,
   1.432 +                          "---",                 null,
   1.433 +                          "context-selectall",   true,
   1.434 +                          "---",                 null,
   1.435 +                          "spell-check-enabled", true,
   1.436 +                          "spell-dictionaries",  true,
   1.437 +                              ["spell-check-dictionary-en-US", true,
   1.438 +                               "---",                          null,
   1.439 +                               "spell-add-dictionaries",       true], null
   1.440 +                         ].concat(inspectItems));
   1.441 +
   1.442 +        closeContextMenu();
   1.443 +        openContextMenuFor(link); // Invoke context menu for next test.
   1.444 +        break;
   1.445 +
   1.446 +    case 18:
   1.447 +        executeCopyCommand("cmd_copyLink", "http://mozilla.com/");
   1.448 +        closeContextMenu();
   1.449 +        openContextMenuFor(pagemenu); // Invoke context menu for next test.
   1.450 +        break;
   1.451 +
   1.452 +    case 19:
   1.453 +        // Context menu for element with assigned content context menu
   1.454 +        checkContextMenu(["+Plain item",          {type: "", icon: "", checked: false, disabled: false},
   1.455 +                          "+Disabled item",       {type: "", icon: "", checked: false, disabled: true},
   1.456 +                          "+Item w/ textContent", {type: "", icon: "", checked: false, disabled: false},
   1.457 +                          "---",                  null,
   1.458 +                          "+Checkbox",            {type: "checkbox", icon: "", checked: true, disabled: false},
   1.459 +                          "---",                  null,
   1.460 +                          "+Radio1",              {type: "checkbox", icon: "", checked: true, disabled: false},
   1.461 +                          "+Radio2",              {type: "checkbox", icon: "", checked: false, disabled: false},
   1.462 +                          "+Radio3",              {type: "checkbox", icon: "", checked: false, disabled: false},
   1.463 +                          "---",                  null,
   1.464 +                          "+Item w/ icon",        {type: "", icon: "favicon.ico", checked: false, disabled: false},
   1.465 +                          "+Item w/ bad icon",    {type: "", icon: "", checked: false, disabled: false},
   1.466 +                          "---",                  null,
   1.467 +                          "generated-submenu-1",  true,
   1.468 +                              ["+Radio1",             {type: "checkbox", icon: "", checked: false, disabled: false},
   1.469 +                               "+Radio2",             {type: "checkbox", icon: "", checked: true, disabled: false},
   1.470 +                               "+Radio3",             {type: "checkbox", icon: "", checked: false, disabled: false},
   1.471 +                               "---",                 null,
   1.472 +                               "+Checkbox",           {type: "checkbox", icon: "", checked: false, disabled: false}], null,
   1.473 +                          "---",                  null,
   1.474 +                          "context-back",         false,
   1.475 +                          "context-forward",      false,
   1.476 +                          "context-reload",       true,
   1.477 +                          "---",                  null,
   1.478 +                          "context-bookmarkpage", true,
   1.479 +                          "context-savepage",     true,
   1.480 +                          "---",                  null,
   1.481 +                          "context-viewbgimage",  false,
   1.482 +                          "context-selectall",    true,
   1.483 +                          "---",                  null,
   1.484 +                          "context-viewsource",   true,
   1.485 +                          "context-viewinfo",     true
   1.486 +                         ].concat(inspectItems));
   1.487 +
   1.488 +        invokeItemAction("0");
   1.489 +        closeContextMenu();
   1.490 +
   1.491 +        // run mozRequestFullScreen on the element we're testing
   1.492 +        var full_screen_element = subwindow.document.getElementById("test-dom-full-screen");
   1.493 +        var openDomFullScreen = function() {
   1.494 +            subwindow.removeEventListener("mozfullscreenchange", openDomFullScreen, false);
   1.495 +            openContextMenuFor(dom_full_screen, true); // Invoke context menu for next test.
   1.496 +        }
   1.497 +        subwindow.addEventListener("mozfullscreenchange", openDomFullScreen, false);
   1.498 +        SpecialPowers.setBoolPref("full-screen-api.approval-required", false);
   1.499 +        SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", false);
   1.500 +        full_screen_element.mozRequestFullScreen();
   1.501 +        break;
   1.502 +
   1.503 +    case 20:
   1.504 +        // Context menu for DOM Fullscreen mode (NOTE: this is *NOT* on an img)
   1.505 +        checkContextMenu(["context-leave-dom-fullscreen", true,
   1.506 +                          "---",                          null,
   1.507 +                          "context-back",                 false,
   1.508 +                          "context-forward",              false,
   1.509 +                          "context-reload",               true,
   1.510 +                          "---",                          null,
   1.511 +                          "context-bookmarkpage",         true,
   1.512 +                          "context-savepage",             true,
   1.513 +                          "---",                          null,
   1.514 +                          "context-viewbgimage",          false,
   1.515 +                          "context-selectall",            true,
   1.516 +                          "---",                          null,
   1.517 +                          "context-viewsource",           true,
   1.518 +                          "context-viewinfo",             true
   1.519 +                         ].concat(inspectItems));
   1.520 +        closeContextMenu();
   1.521 +        var full_screen_element = subwindow.document.getElementById("test-dom-full-screen");
   1.522 +        var openPagemenu = function() {
   1.523 +            subwindow.removeEventListener("mozfullscreenchange", openPagemenu, false);
   1.524 +            SpecialPowers.clearUserPref("full-screen-api.approval-required");
   1.525 +            SpecialPowers.clearUserPref("full-screen-api.allow-trusted-requests-only");
   1.526 +            openContextMenuFor(pagemenu, true); // Invoke context menu for next test.
   1.527 +        }
   1.528 +        subwindow.addEventListener("mozfullscreenchange", openPagemenu, false);
   1.529 +        subwindow.document.mozCancelFullScreen();
   1.530 +        break;
   1.531 +
   1.532 +    case 21:
   1.533 +        // Context menu for element with assigned content context menu
   1.534 +        // The shift key should bypass content context menu processing
   1.535 +        checkContextMenu(["context-back",         false,
   1.536 +                          "context-forward",      false,
   1.537 +                          "context-reload",       true,
   1.538 +                          "---",                  null,
   1.539 +                          "context-bookmarkpage", true,
   1.540 +                          "context-savepage",     true,
   1.541 +                          "---",                  null,
   1.542 +                          "context-viewbgimage",  false,
   1.543 +                          "context-selectall",    true,
   1.544 +                          "---",                  null,
   1.545 +                          "context-viewsource",   true,
   1.546 +                          "context-viewinfo",     true
   1.547 +                         ].concat(inspectItems));
   1.548 +        closeContextMenu();
   1.549 +        selectText(selecttext); // Select text prior to opening context menu.
   1.550 +        openContextMenuFor(selecttext); // Invoke context menu for next test.
   1.551 +        return;
   1.552 +
   1.553 +    case 22:
   1.554 +        // Context menu for selected text
   1.555 +        if (SpecialPowers.Services.appinfo.OS == "Darwin") {
   1.556 +          // This test is only enabled on Mac due to bug 736399.
   1.557 +          checkContextMenu(["context-copy",                        true,
   1.558 +                            "context-selectall",                   true,
   1.559 +                            "---",                                 null,
   1.560 +                            "context-searchselect",                true,
   1.561 +                            "context-viewpartialsource-selection", true
   1.562 +                           ].concat(inspectItems));
   1.563 +        }
   1.564 +        closeContextMenu();
   1.565 +        selectText(selecttextlink); // Select text prior to opening context menu.
   1.566 +        openContextMenuFor(selecttextlink); // Invoke context menu for next test.
   1.567 +        return;
   1.568 +
   1.569 +    case 23:
   1.570 +        // Context menu for selected text which matches valid URL pattern
   1.571 +        if (SpecialPowers.Services.appinfo.OS == "Darwin") {
   1.572 +          // This test is only enabled on Mac due to bug 736399.
   1.573 +          if (perWindowPrivateBrowsing) {
   1.574 +            checkContextMenu(["context-openlinkincurrent",           true,
   1.575 +                              "context-openlinkintab",               true,
   1.576 +                              "context-openlink",                    true,
   1.577 +                              "context-openlinkprivate",             true,
   1.578 +                              "---",                                 null,
   1.579 +                              "context-bookmarklink",                true,
   1.580 +                              "context-savelink",                    true,
   1.581 +                              "context-copy",                        true,
   1.582 +                              "context-selectall",                   true,
   1.583 +                              "---",                                 null,
   1.584 +                              "context-searchselect",                true,
   1.585 +                              "context-viewpartialsource-selection", true
   1.586 +                             ].concat(inspectItems));
   1.587 +          } else {
   1.588 +            checkContextMenu(["context-openlinkincurrent",           true,
   1.589 +                              "context-openlinkintab",               true,
   1.590 +                              "context-openlink",                    true,
   1.591 +                              "---",                                 null,
   1.592 +                              "context-bookmarklink",                true,
   1.593 +                              "context-savelink",                    true,
   1.594 +                              "context-copy",                        true,
   1.595 +                              "context-selectall",                   true,
   1.596 +                              "---",                                 null,
   1.597 +                              "context-searchselect",                true,
   1.598 +                              "context-viewpartialsource-selection", true
   1.599 +                             ].concat(inspectItems));
   1.600 +          }
   1.601 +        }
   1.602 +        closeContextMenu();
   1.603 +        // clear the selection because following tests don't expect any selection
   1.604 +        subwindow.getSelection().removeAllRanges();
   1.605 +
   1.606 +        openContextMenuFor(imagelink)
   1.607 +        break;
   1.608 +
   1.609 +    case 24:
   1.610 +        // Context menu for image link
   1.611 +        if (perWindowPrivateBrowsing) {
   1.612 +          checkContextMenu(["context-openlinkintab", true,
   1.613 +                            "context-openlink",      true,
   1.614 +                            "context-openlinkprivate", true,
   1.615 +                            "---",                   null,
   1.616 +                            "context-bookmarklink",  true,
   1.617 +                            "context-savelink",      true,
   1.618 +                            "context-copylink",      true,
   1.619 +                            "---",                   null,
   1.620 +                            "context-viewimage",            true,
   1.621 +                            "context-copyimage-contents",   true,
   1.622 +                            "context-copyimage",            true,
   1.623 +                            "---",                          null,
   1.624 +                            "context-saveimage",            true,
   1.625 +                            "context-sendimage",            true,
   1.626 +                            "context-setDesktopBackground", true,
   1.627 +                            "context-viewimageinfo",        true
   1.628 +                           ].concat(inspectItems));
   1.629 +        } else {
   1.630 +          checkContextMenu(["context-openlinkintab", true,
   1.631 +                            "context-openlink",      true,
   1.632 +                            "---",                   null,
   1.633 +                            "context-bookmarklink",  true,
   1.634 +                            "context-savelink",      true,
   1.635 +                            "context-copylink",      true,
   1.636 +                            "---",                   null,
   1.637 +                            "context-viewimage",            true,
   1.638 +                            "context-copyimage-contents",   true,
   1.639 +                            "context-copyimage",            true,
   1.640 +                            "---",                          null,
   1.641 +                            "context-saveimage",            true,
   1.642 +                            "context-sendimage",            true,
   1.643 +                            "context-setDesktopBackground", true,
   1.644 +                            "context-viewimageinfo",        true
   1.645 +                           ].concat(inspectItems));
   1.646 +        }
   1.647 +        closeContextMenu();
   1.648 +        selectInputText(select_inputtext); // Select text prior to opening context menu.
   1.649 +        openContextMenuFor(select_inputtext); // Invoke context menu for next test.
   1.650 +        return;
   1.651 +
   1.652 +    case 25:
   1.653 +        // Context menu for selected text in input
   1.654 +        checkContextMenu(["context-undo",        false,
   1.655 +                          "---",                 null,
   1.656 +                          "context-cut",         true,
   1.657 +                          "context-copy",        true,
   1.658 +                          "context-paste",       null, // ignore clipboard state
   1.659 +                          "context-delete",      true,
   1.660 +                          "---",                 null,
   1.661 +                          "context-selectall",   true,
   1.662 +                          "context-searchselect",true,
   1.663 +                          "---",                 null,
   1.664 +                          "spell-check-enabled", true
   1.665 +                         ].concat(inspectItems));
   1.666 +        closeContextMenu();
   1.667 +        selectInputText(select_inputtext_password); // Select text prior to opening context menu.
   1.668 +        openContextMenuFor(select_inputtext_password); // Invoke context menu for next test.
   1.669 +        return;
   1.670 +
   1.671 +    case 26:
   1.672 +        // Context menu for selected text in input[type="password"]
   1.673 +        checkContextMenu(["context-undo",        false,
   1.674 +                          "---",                 null,
   1.675 +                          "context-cut",         true,
   1.676 +                          "context-copy",        true,
   1.677 +                          "context-paste",       null, // ignore clipboard state
   1.678 +                          "context-delete",      true,
   1.679 +                          "---",                 null,
   1.680 +                          "context-selectall",   true,
   1.681 +                          "---",                 null,
   1.682 +                          "spell-check-enabled", true,
   1.683 +                          //spell checker is shown on input[type="password"] on this testcase
   1.684 +                          "spell-dictionaries",  true,
   1.685 +                              ["spell-check-dictionary-en-US", true,
   1.686 +                               "---",                          null,
   1.687 +                               "spell-add-dictionaries",       true], null
   1.688 +                         ].concat(inspectItems));
   1.689 +        closeContextMenu();
   1.690 +        subwindow.getSelection().removeAllRanges();
   1.691 +        openContextMenuFor(plugin);
   1.692 +        return;
   1.693 +
   1.694 +    case 27:
   1.695 +        // Context menu for click-to-play blocked plugin
   1.696 +        checkContextMenu(["context-ctp-play",     true,
   1.697 +                          "context-ctp-hide",     true,
   1.698 +                          "---",                  null,
   1.699 +                          "context-back",         false,
   1.700 +                          "context-forward",      false,
   1.701 +                          "context-reload",       true,
   1.702 +                          "---",                  null,
   1.703 +                          "context-bookmarkpage", true,
   1.704 +                          "context-savepage",     true,
   1.705 +                          "---",                  null,
   1.706 +                          "context-viewbgimage",  false,
   1.707 +                          "context-selectall",    true,
   1.708 +                          "---",                  null,
   1.709 +                          "context-viewsource",   true,
   1.710 +                          "context-viewinfo",     true
   1.711 +                         ].concat(inspectItems));
   1.712 +        closeContextMenu();
   1.713 +        SpecialPowers.clearUserPref("plugins.click_to_play");
   1.714 +        getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED;
   1.715 +        openContextMenuFor(longdesc);
   1.716 +        return;
   1.717 +
   1.718 +    case 28:
   1.719 +        // Context menu for an image with longdesc
   1.720 +        checkContextMenu(["context-viewimage",            true,
   1.721 +                          "context-copyimage-contents",   true,
   1.722 +                          "context-copyimage",            true,
   1.723 +                          "---",                          null,
   1.724 +                          "context-saveimage",            true,
   1.725 +                          "context-sendimage",            true,
   1.726 +                          "context-setDesktopBackground", true,
   1.727 +                          "context-viewimageinfo",        true,
   1.728 +                          "context-viewimagedesc",        true
   1.729 +                         ].concat(inspectItems));
   1.730 +        closeContextMenu();
   1.731 +        openContextMenuFor(srcdoc);
   1.732 +        return;
   1.733 +
   1.734 +    case 29:
   1.735 +        // Context menu for an iframe with srcdoc attribute set
   1.736 +        checkContextMenu(["context-back",         false,
   1.737 +                          "context-forward",      false,
   1.738 +                          "context-reload",       true,
   1.739 +                          "---",                  null,
   1.740 +                          "context-bookmarkpage", true,
   1.741 +                          "context-savepage",     true,
   1.742 +                          "---",                  null,
   1.743 +                          "context-viewbgimage",  false,
   1.744 +                          "context-selectall",    true,
   1.745 +                          "frame",                null,
   1.746 +                              ["context-reloadframe",       true,
   1.747 +                               "---",                       null,
   1.748 +                               "context-saveframe",         true,
   1.749 +                               "---",                       null,
   1.750 +                               "context-printframe",        true,
   1.751 +                               "---",                       null,
   1.752 +                               "context-viewframesource",   true,
   1.753 +                               "context-viewframeinfo",     true], null,
   1.754 +                          "---",                  null,
   1.755 +                          "context-viewsource",   true,
   1.756 +                          "context-viewinfo",     true
   1.757 +        ].concat(inspectItems));
   1.758 +        closeContextMenu();
   1.759 +        openContextMenuFor(inputspellfalse, false, true); // Invoke context menu for next test.
   1.760 +        break;
   1.761 +
   1.762 +    case 30:
   1.763 +        // Context menu for text input field with spellcheck=false
   1.764 +        checkContextMenu(["context-undo",        false,
   1.765 +                          "---",                 null,
   1.766 +                          "context-cut",         false,
   1.767 +                          "context-copy",        false,
   1.768 +                          "context-paste",       null, // ignore clipboard state
   1.769 +                          "context-delete",      false,
   1.770 +                          "---",                 null,
   1.771 +                          "context-selectall",   true,
   1.772 +                          "---",                 null,
   1.773 +                          "spell-add-dictionaries-main",  true,
   1.774 +                         ].concat(inspectItems));
   1.775 +
   1.776 +        // finish test
   1.777 +        subwindow.close();
   1.778 +        SimpleTest.finish();
   1.779 +        return;
   1.780 +
   1.781 +    /*
   1.782 +     * Other things that would be nice to test:
   1.783 +     *  - check state of disabled items
   1.784 +     *  - test execution of menu items (maybe as a separate test?)
   1.785 +     */
   1.786 +
   1.787 +    default:
   1.788 +        ok(false, "Unexpected invocation of test #" + testNum);
   1.789 +        subwindow.close();
   1.790 +        SimpleTest.finish();
   1.791 +        return;
   1.792 +  }
   1.793 +
   1.794 +}
   1.795 +
   1.796 +
   1.797 +var testNum = 1;
   1.798 +var subwindow, chromeWin, contextMenu;
   1.799 +var text, link, mailto, input, img, canvas, video_ok, video_bad, video_bad2,
   1.800 +    iframe, video_in_iframe, image_in_iframe, textarea, contenteditable,
   1.801 +    pagemenu, dom_full_screen, plainTextItems, audio_in_video,
   1.802 +    selecttext, selecttextlink, imagelink, select_inputtext, select_inputtext_password,
   1.803 +    plugin, longdesc, iframe, inputspellfalse;
   1.804 +
   1.805 +function startTest() {
   1.806 +    chromeWin = SpecialPowers.wrap(subwindow)
   1.807 +                    .QueryInterface(Ci.nsIInterfaceRequestor)
   1.808 +                    .getInterface(Ci.nsIWebNavigation)
   1.809 +                    .QueryInterface(Ci.nsIDocShellTreeItem)
   1.810 +                    .rootTreeItem
   1.811 +                    .QueryInterface(Ci.nsIInterfaceRequestor)
   1.812 +                    .getInterface(Ci.nsIDOMWindow)
   1.813 +                    .QueryInterface(Ci.nsIDOMChromeWindow);
   1.814 +    contextMenu = chromeWin.document.getElementById("contentAreaContextMenu");
   1.815 +    ok(contextMenu, "Got context menu XUL");
   1.816 +
   1.817 +    if (chromeWin.document.getElementById("Browser:Stop").getAttribute("disabled") != "true") {
   1.818 +      todo(false, "Wait for subwindow to load... (This should usually happen once.)");
   1.819 +      SimpleTest.executeSoon(startTest);
   1.820 +      return;
   1.821 +    }
   1.822 +
   1.823 +    subwindow.allowFullscreen = true;
   1.824 +    lastElement = null;
   1.825 +
   1.826 +    text   = subwindow.document.getElementById("test-text");
   1.827 +    link   = subwindow.document.getElementById("test-link");
   1.828 +    imagelink = subwindow.document.getElementById("test-image-link");
   1.829 +    mailto = subwindow.document.getElementById("test-mailto");
   1.830 +    input  = subwindow.document.getElementById("test-input");
   1.831 +    img    = subwindow.document.getElementById("test-image");
   1.832 +    canvas = subwindow.document.getElementById("test-canvas");
   1.833 +    video_ok   = subwindow.document.getElementById("test-video-ok");
   1.834 +    audio_in_video = subwindow.document.getElementById("test-audio-in-video");
   1.835 +    video_bad  = subwindow.document.getElementById("test-video-bad");
   1.836 +    video_bad2 = subwindow.document.getElementById("test-video-bad2");
   1.837 +    iframe = subwindow.document.getElementById("test-iframe");
   1.838 +    video_in_iframe = subwindow.document.getElementById("test-video-in-iframe").contentDocument.getElementsByTagName("video")[0];
   1.839 +    video_in_iframe.pause();
   1.840 +    image_in_iframe = subwindow.document.getElementById("test-image-in-iframe").contentDocument.getElementsByTagName("img")[0];
   1.841 +    textarea = subwindow.document.getElementById("test-textarea");
   1.842 +    contenteditable = subwindow.document.getElementById("test-contenteditable");
   1.843 +    contenteditable.focus(); // content editable needs to be focused to enable spellcheck
   1.844 +    inputspellfalse = subwindow.document.getElementById("test-contenteditable-spellcheck-false");
   1.845 +    inputspellfalse.focus(); // content editable needs to be focused to enable spellcheck
   1.846 +    pagemenu = subwindow.document.getElementById("test-pagemenu");
   1.847 +    dom_full_screen = subwindow.document.getElementById("test-dom-full-screen");
   1.848 +    selecttext = subwindow.document.getElementById("test-select-text");
   1.849 +    selecttextlink = subwindow.document.getElementById("test-select-text-link");
   1.850 +    select_inputtext = subwindow.document.getElementById("test-select-input-text");
   1.851 +    select_inputtext_password = subwindow.document.getElementById("test-select-input-text-type-password");
   1.852 +    plugin = subwindow.document.getElementById("test-plugin");
   1.853 +    longdesc = subwindow.document.getElementById("test-longdesc");
   1.854 +    srcdoc = subwindow.document.getElementById("test-srcdoc");
   1.855 +
   1.856 +    contextMenu.addEventListener("popupshown", function() { runTest(++testNum); }, false);
   1.857 +    runTest(1);
   1.858 +}
   1.859 +
   1.860 +// We open this in a separate window, because the Mochitests run inside a frame.
   1.861 +// The frame causes an extra menu item, and prevents running the test
   1.862 +// standalone (ie, clicking the test name in the Mochitest window) to see
   1.863 +// success/failure messages.
   1.864 +var painted = false, loaded = false;
   1.865 +
   1.866 +function waitForEvents(event)
   1.867 +{
   1.868 +  if (event.type == "MozAfterPaint")
   1.869 +    painted = true;
   1.870 +  else if (event.type == "load")
   1.871 +    loaded = true;
   1.872 +  if (painted && loaded) {
   1.873 +    subwindow.removeEventListener("MozAfterPaint", waitForEvents, false);
   1.874 +    subwindow.onload = null;
   1.875 +    startTest();
   1.876 +  }
   1.877 +}
   1.878 +
   1.879 +const isOSXMtnLion = navigator.userAgent.indexOf("Mac OS X 10.8") != -1;
   1.880 +
   1.881 +if (isOSXMtnLion) {
   1.882 +  todo(false, "Mountain Lion doesn't like this test (bug 792304)");
   1.883 +} else {
   1.884 +  SpecialPowers.setBoolPref("plugins.click_to_play", true);
   1.885 +  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
   1.886 +
   1.887 +  var subwindow = window.open("./subtst_contextmenu.html", "contextmenu-subtext", "width=600,height=800");
   1.888 +  subwindow.addEventListener("MozAfterPaint", waitForEvents, false);
   1.889 +  subwindow.onload = waitForEvents;
   1.890 +
   1.891 +  SimpleTest.waitForExplicitFinish();
   1.892 +}
   1.893 +</script>
   1.894 +</pre>
   1.895 +</body>
   1.896 +</html>

mercurial