--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -19,16 +19,18 @@ support-files =
browser_star_hsts.sjs
browser_tab_dragdrop2_frame1.xul
browser_web_channel.html
bug592338.html
bug792517-2.html
bug792517.html
bug792517.sjs
bug839103.css
+ contextmenu_common.js
+ ctxmenu-image.png
discovery.html
domplate_test.js
download_page.html
dummy_page.html
feed_tab.html
file_bug550565_favicon.ico
file_bug550565_popup.html
file_bug822367_1.html
@@ -283,16 +285,18 @@ tags = mcb
skip-if = os == 'win' || e10s # Bug 1159268 - Need a content-process safe version of synthesizeWheel
[browser_bug1064280_changeUrlInPinnedTab.js]
[browser_bug1070778.js]
[browser_accesskeys.js]
[browser_canonizeURL.js]
skip-if = e10s # Bug 1094510 - test hits the network in e10s mode only
[browser_clipboard.js]
[browser_contentAreaClick.js]
+[browser_contextmenu.js]
+skip-if = toolkit == "gtk2" || toolkit == "gtk3" # disabled on Linux due to bug 513558
[browser_contextSearchTabPosition.js]
skip-if = os == "mac" || e10s # bug 967013; e10s: bug 1094761 - test hits the network in e10s, causing next test to crash
[browser_ctrlTab.js]
[browser_datachoices_notification.js]
skip-if = !datareporting
[browser_devedition.js]
[browser_devices_get_user_media.js]
skip-if = buildapp == 'mulet' || (os == "linux" && debug) # linux: bug 976544
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_contextmenu.js
@@ -0,0 +1,872 @@
+"use strict";
+
+let tab;
+let contextMenu;
+let inspectItems = [];
+let loginFillItems = [
+ "---", null,
+ "fill-login", null,
+ [
+ "fill-login-no-logins", false,
+ "---", null,
+ "fill-login-saved-passwords", true
+ ], null,
+];
+
+add_task(function* test_setup() {
+ const example_base = "http://example.com/browser/browser/base/content/test/general/";
+ const url = example_base + "subtst_contextmenu.html";
+ tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, url);
+
+ const chrome_base = "chrome://mochitests/content/browser/browser/base/content/test/general/";
+ const contextmenu_common = chrome_base + "contextmenu_common.js";
+ Services.scriptloader.loadSubScript(contextmenu_common, this);
+
+ if (SpecialPowers.getBoolPref("devtools.inspector.enabled")) {
+ inspectItems = ["---", null,
+ "context-inspect", true];
+ }
+
+ yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+ let doc = content.document;
+ let videoIframe = doc.querySelector("#test-video-in-iframe");
+ let video = videoIframe.contentDocument.querySelector("video");
+ video.pause();
+ yield ContentTaskUtils.waitForCondition(() => video.paused, "iframe video should be paused");
+ });
+});
+
+let plainTextItems;
+add_task(function* test_plaintext() {
+ plainTextItems = ["context-navigation", null,
+ ["context-back", false,
+ "context-forward", false,
+ "context-reload", true,
+ "context-bookmarkpage", true], null,
+ "---", null,
+ "context-savepage", true,
+ "---", null,
+ "context-viewbgimage", false,
+ "context-selectall", true,
+ "---", null,
+ "context-viewsource", true,
+ "context-viewinfo", true
+ ].concat(inspectItems);
+ yield test_contextmenu("#test-text", plainTextItems);
+});
+
+add_task(function* test_link() {
+ yield test_contextmenu("#test-link",
+ ["context-openlinkintab", true,
+ "context-openlink", true,
+ "context-openlinkprivate", true,
+ "---", null,
+ "context-bookmarklink", true,
+ "context-savelink", true,
+ "context-copylink", true,
+ "context-searchselect", true
+ ].concat(inspectItems)
+ );
+});
+
+add_task(function* test_mailto() {
+ yield test_contextmenu("#test-mailto",
+ ["context-copyemail", true,
+ "context-searchselect", true
+ ].concat(inspectItems)
+ );
+});
+
+add_task(function* test_image() {
+ yield test_contextmenu("#test-image",
+ ["context-viewimage", true,
+ "context-copyimage-contents", true,
+ "context-copyimage", true,
+ "---", null,
+ "context-saveimage", true,
+ "context-sendimage", true,
+ "context-setDesktopBackground", true,
+ "context-viewimageinfo", true
+ ].concat(inspectItems)
+ );
+});
+
+add_task(function* test_canvas() {
+ yield test_contextmenu("#test-canvas",
+ ["context-viewimage", true,
+ "context-saveimage", true,
+ "context-selectall", true
+ ].concat(inspectItems)
+ );
+});
+
+add_task(function* test_video_ok() {
+ yield test_contextmenu("#test-video-ok",
+ ["context-media-play", true,
+ "context-media-mute", true,
+ "context-media-playbackrate", null,
+ ["context-media-playbackrate-050x", true,
+ "context-media-playbackrate-100x", true,
+ "context-media-playbackrate-150x", true,
+ "context-media-playbackrate-200x", true], null,
+ "context-media-hidecontrols", true,
+ "context-video-showstats", true,
+ "context-video-fullscreen", true,
+ "---", null,
+ "context-viewvideo", true,
+ "context-copyvideourl", true,
+ "---", null,
+ "context-savevideo", true,
+ "context-video-saveimage", true,
+ "context-sendvideo", true,
+ "context-castvideo", null,
+ [], null
+ ].concat(inspectItems)
+ );
+});
+
+add_task(function* test_audio_in_video() {
+ yield test_contextmenu("#test-audio-in-video",
+ ["context-media-play", true,
+ "context-media-mute", true,
+ "context-media-playbackrate", null,
+ ["context-media-playbackrate-050x", true,
+ "context-media-playbackrate-100x", true,
+ "context-media-playbackrate-150x", true,
+ "context-media-playbackrate-200x", true], null,
+ "context-media-showcontrols", true,
+ "---", null,
+ "context-copyaudiourl", true,
+ "---", null,
+ "context-saveaudio", true,
+ "context-sendaudio", true
+ ].concat(inspectItems)
+ );
+});
+
+add_task(function* test_video_bad() {
+ yield test_contextmenu("#test-video-bad",
+ ["context-media-play", false,
+ "context-media-mute", false,
+ "context-media-playbackrate", null,
+ ["context-media-playbackrate-050x", false,
+ "context-media-playbackrate-100x", false,
+ "context-media-playbackrate-150x", false,
+ "context-media-playbackrate-200x", false], null,
+ "context-media-hidecontrols", false,
+ "context-video-showstats", false,
+ "context-video-fullscreen", false,
+ "---", null,
+ "context-viewvideo", true,
+ "context-copyvideourl", true,
+ "---", null,
+ "context-savevideo", true,
+ "context-video-saveimage", false,
+ "context-sendvideo", true,
+ "context-castvideo", null,
+ [], null
+ ].concat(inspectItems)
+ );
+});
+
+add_task(function* test_video_bad2() {
+ yield test_contextmenu("#test-video-bad2",
+ ["context-media-play", false,
+ "context-media-mute", false,
+ "context-media-playbackrate", null,
+ ["context-media-playbackrate-050x", false,
+ "context-media-playbackrate-100x", false,
+ "context-media-playbackrate-150x", false,
+ "context-media-playbackrate-200x", false], null,
+ "context-media-hidecontrols", false,
+ "context-video-showstats", false,
+ "context-video-fullscreen", false,
+ "---", null,
+ "context-viewvideo", false,
+ "context-copyvideourl", false,
+ "---", null,
+ "context-savevideo", false,
+ "context-video-saveimage", false,
+ "context-sendvideo", false,
+ "context-castvideo", null,
+ [], null
+ ].concat(inspectItems)
+ );
+});
+
+add_task(function* test_iframe() {
+ yield test_contextmenu("#test-iframe",
+ ["context-navigation", null,
+ ["context-back", false,
+ "context-forward", false,
+ "context-reload", true,
+ "context-bookmarkpage", true], null,
+ "---", null,
+ "context-savepage", true,
+ "---", null,
+ "context-viewbgimage", false,
+ "context-selectall", true,
+ "frame", null,
+ ["context-showonlythisframe", true,
+ "context-openframeintab", true,
+ "context-openframe", true,
+ "---", null,
+ "context-reloadframe", true,
+ "---", null,
+ "context-bookmarkframe", true,
+ "context-saveframe", true,
+ "---", null,
+ "context-printframe", true,
+ "---", null,
+ "context-viewframesource", true,
+ "context-viewframeinfo", true], null,
+ "---", null,
+ "context-viewsource", true,
+ "context-viewinfo", true
+ ].concat(inspectItems)
+ );
+});
+
+add_task(function* test_video_in_iframe() {
+ yield test_contextmenu("#test-video-in-iframe",
+ ["context-media-play", true,
+ "context-media-mute", true,
+ "context-media-playbackrate", null,
+ ["context-media-playbackrate-050x", true,
+ "context-media-playbackrate-100x", true,
+ "context-media-playbackrate-150x", true,
+ "context-media-playbackrate-200x", true], null,
+ "context-media-hidecontrols", true,
+ "context-video-showstats", true,
+ "context-video-fullscreen", true,
+ "---", null,
+ "context-viewvideo", true,
+ "context-copyvideourl", true,
+ "---", null,
+ "context-savevideo", true,
+ "context-video-saveimage", true,
+ "context-sendvideo", true,
+ "context-castvideo", null,
+ [], null,
+ "frame", null,
+ ["context-showonlythisframe", true,
+ "context-openframeintab", true,
+ "context-openframe", true,
+ "---", null,
+ "context-reloadframe", true,
+ "---", null,
+ "context-bookmarkframe", true,
+ "context-saveframe", true,
+ "---", null,
+ "context-printframe", true,
+ "---", null,
+ "context-viewframeinfo", true], null].concat(inspectItems)
+ );
+});
+
+add_task(function* test_image_in_iframe() {
+ yield test_contextmenu("#test-image-in-iframe",
+ ["context-viewimage", true,
+ "context-copyimage-contents", true,
+ "context-copyimage", true,
+ "---", null,
+ "context-saveimage", true,
+ "context-sendimage", true,
+ "context-setDesktopBackground", true,
+ "context-viewimageinfo", true,
+ "frame", null,
+ ["context-showonlythisframe", true,
+ "context-openframeintab", true,
+ "context-openframe", true,
+ "---", null,
+ "context-reloadframe", true,
+ "---", null,
+ "context-bookmarkframe", true,
+ "context-saveframe", true,
+ "---", null,
+ "context-printframe", true,
+ "---", null,
+ "context-viewframeinfo", true], null].concat(inspectItems)
+ );
+});
+
+add_task(function* test_textarea() {
+ // Disabled since the spell checker completes before
+ // this test is started.
+ todo(false, "spell checker tests are failing");
+ return;
+
+ yield test_contextmenu("#test-textarea",
+ ["context-undo", false,
+ "---", null,
+ "context-cut", true,
+ "context-copy", true,
+ "context-paste", null,
+ "context-delete", false,
+ "---", null,
+ "context-selectall", true,
+ "---", null,
+ "spell-add-dictionaries-main", true,
+ ].concat(inspectItems),
+ {
+ offsetX: 6,
+ offsetY: 6
+ }
+ );
+});
+
+add_task(function* test_textarea_spellcheck() {
+ // Disabled since the spell checker completes before
+ // this test is started.
+ todo(false, "spell checker tests are failing");
+ return;
+
+ yield test_contextmenu("#test-textarea",
+ ["*chubbiness", true, // spelling suggestion
+ "spell-add-to-dictionary", true,
+ "---", null,
+ "context-undo", false,
+ "---", null,
+ "context-cut", true,
+ "context-copy", true,
+ "context-paste", null, // ignore clipboard state
+ "context-delete", false,
+ "---", null,
+ "context-selectall", true,
+ "---", null,
+ "spell-check-enabled", true,
+ "spell-dictionaries", true,
+ ["spell-check-dictionary-en-US", true,
+ "---", null,
+ "spell-add-dictionaries", true], null
+ ].concat(inspectItems),
+ {
+ waitForSpellCheck: true,
+ offsetX: 6,
+ offsetY: 6
+ }
+ );
+
+ // XXXjaws todo, will need to add this to the test_contextmenu function
+ // as a postCheckContextMenuFn.
+ document.getElementById("spell-add-to-dictionary").doCommand(); // Add to dictionary
+});
+
+add_task(function* test_plaintext2() {
+ yield test_contextmenu("#test-text", plainTextItems);
+});
+
+add_task(function* test_undo_add_to_dictionary() {
+ // Disabled since the spell checker completes before
+ // this test is started.
+ todo(false, "spell checker tests are failing");
+ return;
+
+ yield test_contextmenu("#test-textarea",
+ ["spell-undo-add-to-dictionary", true,
+ "---", null,
+ "context-undo", false,
+ "---", null,
+ "context-cut", true,
+ "context-copy", true,
+ "context-paste", null, // ignore clipboard state
+ "context-delete", false,
+ "---", null,
+ "context-selectall", true,
+ "---", null,
+ "spell-check-enabled", true,
+ "spell-dictionaries", true,
+ ["spell-check-dictionary-en-US", true,
+ "---", null,
+ "spell-add-dictionaries", true], null
+ ].concat(inspectItems),
+ {waitForSpellCheck: true}
+ );
+ document.getElementById("spell-undo-add-to-dictionary").doCommand(); // Undo add to dictionary
+});
+
+add_task(function* test_contenteditable() {
+ yield test_contextmenu("#test-contenteditable",
+ ["spell-no-suggestions", false,
+ "spell-add-to-dictionary", true,
+ "---", null,
+ "context-undo", false,
+ "---", null,
+ "context-cut", true,
+ "context-copy", true,
+ "context-paste", null, // ignore clipboard state
+ "context-delete", false,
+ "---", null,
+ "context-selectall", true,
+ "---", null,
+ "spell-check-enabled", true,
+ "spell-dictionaries", true,
+ ["spell-check-dictionary-en-US", true,
+ "---", null,
+ "spell-add-dictionaries", true], null
+ ].concat(inspectItems),
+ {waitForSpellCheck: true}
+ );
+});
+
+add_task(function* test_copylinkcommand() {
+ yield test_contextmenu("#test-link", null, {
+ postCheckContextMenuFn: function*() {
+ document.commandDispatcher
+ .getControllerForCommand("cmd_copyLink")
+ .doCommand("cmd_copyLink");
+
+ // The easiest way to check the clipboard is to paste the contents
+ // into a textbox.
+ yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+ let doc = content.document;
+ let input = doc.getElementById("test-input");
+ input.focus();
+ input.value = "";
+ });
+ document.commandDispatcher
+ .getControllerForCommand("cmd_paste")
+ .doCommand("cmd_paste");
+ yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+ let doc = content.document;
+ let input = doc.getElementById("test-input");
+ is(input.value, "http://mozilla.com/", "paste for command cmd_paste");
+ });
+ }
+ });
+});
+
+add_task(function* test_pagemenu() {
+ yield test_contextmenu("#test-pagemenu",
+ ["context-navigation", null,
+ ["context-back", false,
+ "context-forward", false,
+ "context-reload", true,
+ "context-bookmarkpage", true], null,
+ "---", null,
+ "+Plain item", {type: "", icon: "", checked: false, disabled: false},
+ "+Disabled item", {type: "", icon: "", checked: false, disabled: true},
+ "+Item w/ textContent", {type: "", icon: "", checked: false, disabled: false},
+ "---", null,
+ "+Checkbox", {type: "checkbox", icon: "", checked: true, disabled: false},
+ "---", null,
+ "+Radio1", {type: "checkbox", icon: "", checked: true, disabled: false},
+ "+Radio2", {type: "checkbox", icon: "", checked: false, disabled: false},
+ "+Radio3", {type: "checkbox", icon: "", checked: false, disabled: false},
+ "---", null,
+ "+Item w/ icon", {type: "", icon: "favicon.ico", checked: false, disabled: false},
+ "+Item w/ bad icon", {type: "", icon: "", checked: false, disabled: false},
+ "---", null,
+ "generated-submenu-1", true,
+ ["+Radio1", {type: "checkbox", icon: "", checked: false, disabled: false},
+ "+Radio2", {type: "checkbox", icon: "", checked: true, disabled: false},
+ "+Radio3", {type: "checkbox", icon: "", checked: false, disabled: false},
+ "---", null,
+ "+Checkbox", {type: "checkbox", icon: "", checked: false, disabled: false}], null,
+ "---", null,
+ "context-savepage", true,
+ "---", null,
+ "context-viewbgimage", false,
+ "context-selectall", true,
+ "---", null,
+ "context-viewsource", true,
+ "context-viewinfo", true
+ ].concat(inspectItems),
+ {postCheckContextMenuFn: function*() {
+ let item = contextMenu.getElementsByAttribute("generateditemid", "1")[0];
+ ok(item, "Got generated XUL menu item");
+ item.doCommand();
+ yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+ let pagemenu = content.document.getElementById("test-pagemenu");
+ ok(!pagemenu.hasAttribute("hopeless"), "attribute got removed");
+ });
+ }
+ });
+});
+
+add_task(function* test_dom_full_screen() {
+ yield test_contextmenu("#test-dom-full-screen",
+ ["context-navigation", null,
+ ["context-back", false,
+ "context-forward", false,
+ "context-reload", true,
+ "context-bookmarkpage", true], null,
+ "---", null,
+ "context-leave-dom-fullscreen", true,
+ "---", null,
+ "context-savepage", true,
+ "---", null,
+ "context-viewbgimage", false,
+ "context-selectall", true,
+ "---", null,
+ "context-viewsource", true,
+ "context-viewinfo", true
+ ].concat(inspectItems),
+ {
+ shiftkey: true,
+ preCheckContextMenuFn: function*() {
+ Services.prefs.setBoolPref("full-screen-api.allow-trusted-requests-only", false);
+ Services.prefs.setCharPref("full-screen-api.transition-duration.enter", "0 0");
+ Services.prefs.setCharPref("full-screen-api.transition-duration.leave", "0 0");
+ yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+ let doc = content.document;
+ let win = doc.defaultView;
+ let full_screen_element = doc.getElementById("test-dom-full-screen");
+ let awaitFullScreenChange =
+ ContentTaskUtils.waitForEvent(win, "mozfullscreenchange");
+ full_screen_element.mozRequestFullScreen();
+ yield awaitFullScreenChange;
+ });
+ },
+ postCheckContextMenuFn: function*() {
+ Services.prefs.clearUserPref("full-screen-api.allow-trusted-requests-only");
+ Services.prefs.clearUserPref("full-screen-api.transition-duration.enter");
+ Services.prefs.clearUserPref("full-screen-api.transition-duration.leave");
+ yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+ let win = content.document.defaultView;
+ let awaitFullScreenChange =
+ ContentTaskUtils.waitForEvent(win, "mozfullscreenchange");
+ content.document.mozCancelFullScreen();
+ yield awaitFullScreenChange;
+ });
+ }
+ }
+ );
+});
+
+add_task(function* test_pagemenu2() {
+ yield test_contextmenu("#test-text",
+ ["context-navigation", null,
+ ["context-back", false,
+ "context-forward", false,
+ "context-reload", true,
+ "context-bookmarkpage", true], null,
+ "---", null,
+ "context-savepage", true,
+ "---", null,
+ "context-viewbgimage", false,
+ "context-selectall", true,
+ "---", null,
+ "context-viewsource", true,
+ "context-viewinfo", true
+ ].concat(inspectItems),
+ {shiftkey: true}
+ );
+});
+
+add_task(function* test_select_text() {
+ if (Services.appinfo.OS != "Darwin") {
+ todo(false, "This test is only enabled on Mac due to bug 736399.")
+ return;
+ }
+
+ yield test_contextmenu("#test-select-text",
+ ["context-copy", true,
+ "context-selectall", true,
+ "---", null,
+ "context-searchselect", true,
+ "context-viewpartialsource-selection", true
+ ].concat(inspectItems),
+ {
+ preCheckContextMenuFn: function*() {
+ selectText("#test-select-text");
+ }
+ }
+ );
+});
+
+add_task(function* test_select_text_link() {
+ if (Services.appinfo.OS != "Darwin") {
+ todo(false, "This test is only enabled on Mac due to bug 736399.")
+ return;
+ }
+
+ yield test_contextmenu("#test-select-text-link",
+ ["context-openlinkincurrent", true,
+ "context-openlinkintab", true,
+ "context-openlink", true,
+ "context-openlinkprivate", true,
+ "---", null,
+ "context-bookmarklink", true,
+ "context-savelink", true,
+ "context-copy", true,
+ "context-selectall", true,
+ "---", null,
+ "context-searchselect", true,
+ "context-viewpartialsource-selection", true
+ ].concat(inspectItems),
+ {
+ preCheckContextMenuFn: function*() {
+ selectText("#test-select-text-link");
+ },
+ postCheckContextMenuFn: function*() {
+ ContentTask.spawn(tab.linkedBrowser, null, function*() {
+ let win = content.document.defaultView;
+ win.getSelection().removeAllRanges();
+ });
+ }
+ }
+ );
+});
+
+add_task(function* test_imagelink() {
+ yield test_contextmenu("#test-image-link",
+ ["context-openlinkintab", true,
+ "context-openlink", true,
+ "context-openlinkprivate", true,
+ "---", null,
+ "context-bookmarklink", true,
+ "context-savelink", true,
+ "context-copylink", true,
+ "---", null,
+ "context-viewimage", true,
+ "context-copyimage-contents", true,
+ "context-copyimage", true,
+ "---", null,
+ "context-saveimage", true,
+ "context-sendimage", true,
+ "context-setDesktopBackground", true,
+ "context-viewimageinfo", true
+ ].concat(inspectItems)
+ );
+});
+
+add_task(function* test_select_input_text() {
+ yield test_contextmenu("#test-select-input-text",
+ ["context-undo", false,
+ "---", null,
+ "context-cut", true,
+ "context-copy", true,
+ "context-paste", null, // ignore clipboard state
+ "context-delete", true,
+ "---", null,
+ "context-selectall", true,
+ "context-searchselect",true,
+ "---", null,
+ "spell-check-enabled", true
+ ].concat(loginFillItems)
+ .concat(inspectItems),
+ {
+ preCheckContextMenuFn: function*() {
+ yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+ let doc = content.document;
+ let win = doc.defaultView;
+ win.getSelection().removeAllRanges();
+ let element = doc.querySelector("#test-select-input-text");
+ element.select();
+ });
+ }
+ }
+ );
+});
+
+add_task(function* test_select_input_text_password() {
+ yield test_contextmenu("#test-select-input-text-type-password",
+ ["context-undo", false,
+ "---", null,
+ "context-cut", true,
+ "context-copy", true,
+ "context-paste", null, // ignore clipboard state
+ "context-delete", true,
+ "---", null,
+ "context-selectall", true,
+ "---", null,
+ "spell-check-enabled", true,
+ //spell checker is shown on input[type="password"] on this testcase
+ "spell-dictionaries", true,
+ ["spell-check-dictionary-en-US", true,
+ "---", null,
+ "spell-add-dictionaries", true], null
+ ].concat(loginFillItems)
+ .concat(inspectItems),
+ {
+ preCheckContextMenuFn: function*() {
+ yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+ let doc = content.document;
+ let win = doc.defaultView;
+ win.getSelection().removeAllRanges();
+ let element = doc.querySelector("#test-select-input-text-type-password");
+ element.select();
+ });
+ },
+ postCheckContextMenuFn: function*() {
+ yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+ let win = content.document.defaultView;
+ win.getSelection().removeAllRanges();
+ });
+ }
+ }
+ );
+});
+
+add_task(function* test_click_to_play_blocked_plugin() {
+ yield test_contextmenu("#test-plugin",
+ ["context-navigation", null,
+ ["context-back", false,
+ "context-forward", false,
+ "context-reload", true,
+ "context-bookmarkpage", true], null,
+ "---", null,
+ "context-ctp-play", true,
+ "context-ctp-hide", true,
+ "---", null,
+ "context-savepage", true,
+ "---", null,
+ "context-viewbgimage", false,
+ "context-selectall", true,
+ "---", null,
+ "context-viewsource", true,
+ "context-viewinfo", true
+ ].concat(inspectItems),
+ {
+ preCheckContextMenuFn: function*() {
+ Services.prefs.setBoolPref("plugins.click_to_play", true);
+ setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
+ },
+ postCheckContextMenuFn: function*() {
+ Services.prefs.clearUserPref("plugins.click_to_play");
+ getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED;
+ }
+ }
+ );
+});
+
+add_task(function* test_longdesc() {
+ yield test_contextmenu("#test-longdesc",
+ ["context-viewimage", true,
+ "context-copyimage-contents", true,
+ "context-copyimage", true,
+ "---", null,
+ "context-saveimage", true,
+ "context-sendimage", true,
+ "context-setDesktopBackground", true,
+ "context-viewimageinfo", true,
+ "context-viewimagedesc", true
+ ].concat(inspectItems)
+ );
+});
+
+add_task(function* test_srcdoc() {
+ yield test_contextmenu("#test-srcdoc",
+ ["context-navigation", null,
+ ["context-back", false,
+ "context-forward", false,
+ "context-reload", true,
+ "context-bookmarkpage", true], null,
+ "---", null,
+ "context-savepage", true,
+ "---", null,
+ "context-viewbgimage", false,
+ "context-selectall", true,
+ "frame", null,
+ ["context-reloadframe", true,
+ "---", null,
+ "context-saveframe", true,
+ "---", null,
+ "context-printframe", true,
+ "---", null,
+ "context-viewframesource", true,
+ "context-viewframeinfo", true], null,
+ "---", null,
+ "context-viewsource", true,
+ "context-viewinfo", true
+ ].concat(inspectItems)
+ );
+});
+
+add_task(function* test_input_spell_false() {
+ yield test_contextmenu("#test-contenteditable-spellcheck-false",
+ ["context-undo", false,
+ "---", null,
+ "context-cut", true,
+ "context-copy", true,
+ "context-paste", null, // ignore clipboard state
+ "context-delete", false,
+ "---", null,
+ "context-selectall", true,
+ "---", null,
+ "spell-add-dictionaries-main", true,
+ ].concat(inspectItems)
+ );
+});
+
+add_task(function* test_cleanup() {
+ gBrowser.removeTab(tab);
+ tab = null;
+});
+
+let lastElementSelector = null;
+function* test_contextmenu(selector, menuItems, options={}) {
+ contextMenu = document.getElementById("contentAreaContextMenu")
+ is(contextMenu.state, "closed", "checking if popup is closed");
+
+ // Default to centered if no positioning is defined.
+ if (!options.offsetX && !options.offsetY) {
+ options.centered = true;
+ }
+
+ yield ContentTask.spawn(tab.linkedBrowser,
+ {lastElementSelector, selector},
+ function*({lastElementSelector, selector}) {
+ if (lastElementSelector) {
+ let lastElement = content.document.querySelector(lastElementSelector);
+ lastElement.blur();
+ }
+ let element = content.document.querySelector(selector);
+ element.focus();
+ });
+ lastElementSelector = selector;
+ info(`Moved focus to ${selector}`);
+
+ if (options.waitForSpellCheck) {
+ info("Waiting for spell check");
+ yield ContentTask.spawn(tab.linkedBrowser, selector, function*(selector) {
+ let {onSpellCheck} = Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", {});
+ let element = content.document.querySelector(selector);
+ yield new Promise(resolve => onSpellCheck(element, resolve));
+ info("Spell check running");
+ });
+ }
+
+ if (options.preCheckContextMenuFn) {
+ yield options.preCheckContextMenuFn();
+ info("Completed preCheckContextMenuFn");
+ }
+
+ let awaitPopupShown = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
+ yield BrowserTestUtils.synthesizeMouse(selector, options.offsetX || 0, options.offsetY || 0, {
+ type: "contextmenu",
+ button: 2,
+ shiftkey: options.shiftkey,
+ centered: options.centered
+ },
+ tab.linkedBrowser);
+ yield awaitPopupShown;
+ info("Popup Shown");
+
+ if (menuItems) {
+ checkContextMenu(menuItems);
+ }
+
+ if (options.postCheckContextMenuFn) {
+ yield options.postCheckContextMenuFn();
+ info("Completed postCheckContextMenuFn");
+ }
+
+ let awaitPopupHidden = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden");
+ contextMenu.hidePopup();
+ yield awaitPopupHidden;
+}
+
+function selectText(selector) {
+ yield ContentTask.spawn(function*() {
+ let doc = content.document;
+ let win = doc.defaultView;
+ win.getSelection().removeAllRanges();
+ let div = doc.createRange();
+ let element = doc.querySelector(selector);
+ div.setStartBefore(element);
+ div.setEndAfter(element);
+ win.getSelection().addRange(div);
+ });
+}
--- a/browser/base/content/test/general/mochitest.ini
+++ b/browser/base/content/test/general/mochitest.ini
@@ -23,18 +23,16 @@ support-files =
offlineEvent.cacheManifest
offlineEvent.cacheManifest^headers^
offlineEvent.html
subtst_contextmenu.html
video.ogg
[test_bug364677.html]
[test_bug395533.html]
-[test_contextmenu.html]
-skip-if = toolkit == "gtk2" || toolkit == "gtk3" || (os == 'mac' && os_version != '10.6') || e10s # disabled on Linux due to bug 513558, on Mac after 10.6 due to bug 792304
[test_contextmenu_input.html]
skip-if = toolkit == "gtk2" || toolkit == "gtk3" || e10s # disabled on Linux due to bug 513558
[test_feed_discovery.html]
skip-if = e10s
[test_offlineNotification.html]
skip-if = buildapp == 'mulet' || e10s # Bug 1066070 - I don't think either popup notifications nor addon install stuff works?
[test_offline_gzip.html]
skip-if = buildapp == 'mulet' || e10s # Bug 1066070 - I don't think either popup notifications nor addon install stuff works?
deleted file mode 100644
--- a/browser/base/content/test/general/test_contextmenu.html
+++ /dev/null
@@ -1,880 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<head>
- <title>Tests for browser context menu</title>
- <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
- <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
- <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
- <script type="text/javascript" src="head_plain.js"></script>
-</head>
-<body>
-Browser context menu tests.
-<p id="display"></p>
-
-<div id="content">
-</div>
-
-<pre id="test">
-<script type="text/javascript" src="contextmenu_common.js"></script>
-<script class="testbody" type="text/javascript">
-
-SpecialPowers.Cu.import("resource://gre/modules/InlineSpellChecker.jsm", window);
-
-const Ci = SpecialPowers.Ci;
-
-function executeCopyCommand(command, expectedValue)
-{
- // Just execute the command directly rather than simulating a context menu
- // press to avoid having to deal with its asynchronous nature
- SpecialPowers.wrap(subwindow).controllers.getControllerForCommand(command).doCommand(command);
-
- // The easiest way to check the clipboard is to paste the contents into a
- // textbox
- input.focus();
- input.value = "";
- SpecialPowers.wrap(input).controllers.getControllerForCommand("cmd_paste").doCommand("cmd_paste");
- is(input.value, expectedValue, "paste for command " + command);
-}
-
-function invokeItemAction(generatedItemId)
-{
- var item = contextMenu.getElementsByAttribute("generateditemid",
- generatedItemId)[0];
- ok(item, "Got generated XUL menu item");
- item.doCommand();
- ok(!pagemenu.hasAttribute("hopeless"), "attribute got removed");
-}
-
-function selectText(element) {
- // Clear any previous selections before selecting new element.
- subwindow.getSelection().removeAllRanges();
-
- var div = subwindow.document.createRange();
- div.setStartBefore(element);
- div.setEndAfter(element);
- subwindow.getSelection().addRange(div);
-}
-
-function selectInputText(element) {
- // Clear any previous selections before selecting new element.
- subwindow.getSelection().removeAllRanges();
-
- element.select();
-}
-
-/*
- * runTest
- *
- * Called by a popupshowing event handler. Each test checks for expected menu
- * contents, closes the popup, and finally triggers the popup on a new element
- * (thus kicking off another cycle).
- *
- */
-function runTest(testNum) {
- // Seems we need to enable this again, or sendKeyEvent() complaints.
- ok(true, "Starting test #" + testNum);
-
- var inspectItems = [];
- if (SpecialPowers.getBoolPref("devtools.inspector.enabled")) {
- inspectItems = ["---", null,
- "context-inspect", true];
- }
-
- var loginFillItems = [
- "---", null,
- "fill-login", null,
- [
- "fill-login-no-logins", false,
- "---", null,
- "fill-login-saved-passwords", true
- ], null,
- ];
-
- var tests = [
- function () {
- // Invoke context menu for next test.
- openContextMenuFor(text);
- },
-
- function () {
- // Context menu for plain text
- plainTextItems = ["context-navigation", null,
- ["context-back", false,
- "context-forward", false,
- "context-reload", true,
- "context-bookmarkpage", true], null,
- "---", null,
- "context-savepage", true,
- "---", null,
- "context-viewbgimage", false,
- "context-selectall", true,
- "---", null,
- "context-viewsource", true,
- "context-viewinfo", true
- ].concat(inspectItems);
- checkContextMenu(plainTextItems);
- closeContextMenu();
- openContextMenuFor(link); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for text link
- checkContextMenu(["context-openlinkintab", true,
- "context-openlink", true,
- "context-openlinkprivate", true,
- "---", null,
- "context-bookmarklink", true,
- "context-savelink", true,
- "context-copylink", true,
- "context-searchselect", true
- ].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(mailto); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for text mailto-link
- checkContextMenu(["context-copyemail", true,
- "context-searchselect", true
- ].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(img); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for an image
- checkContextMenu(["context-viewimage", true,
- "context-copyimage-contents", true,
- "context-copyimage", true,
- "---", null,
- "context-saveimage", true,
- "context-sendimage", true,
- "context-setDesktopBackground", true,
- "context-viewimageinfo", true
- ].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(canvas); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for a canvas
- checkContextMenu(["context-viewimage", true,
- "context-saveimage", true,
- "context-selectall", true
- ].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(video_ok); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for a video (with a VALID media source)
- checkContextMenu(["context-media-play", true,
- "context-media-mute", true,
- "context-media-playbackrate", null,
- ["context-media-playbackrate-050x", true,
- "context-media-playbackrate-100x", true,
- "context-media-playbackrate-150x", true,
- "context-media-playbackrate-200x", true], null,
- "context-media-hidecontrols", true,
- "context-video-showstats", true,
- "context-video-fullscreen", true,
- "---", null,
- "context-viewvideo", true,
- "context-copyvideourl", true,
- "---", null,
- "context-savevideo", true,
- "context-video-saveimage", true,
- "context-sendvideo", true,
- "context-castvideo", null,
- [], null
- ].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(audio_in_video); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for a video (with an audio-only file)
- checkContextMenu(["context-media-play", true,
- "context-media-mute", true,
- "context-media-playbackrate", null,
- ["context-media-playbackrate-050x", true,
- "context-media-playbackrate-100x", true,
- "context-media-playbackrate-150x", true,
- "context-media-playbackrate-200x", true], null,
- "context-media-showcontrols", true,
- "---", null,
- "context-copyaudiourl", true,
- "---", null,
- "context-saveaudio", true,
- "context-sendaudio", true
- ].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(video_bad); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for a video (with an INVALID media source)
- checkContextMenu(["context-media-play", false,
- "context-media-mute", false,
- "context-media-playbackrate", null,
- ["context-media-playbackrate-050x", false,
- "context-media-playbackrate-100x", false,
- "context-media-playbackrate-150x", false,
- "context-media-playbackrate-200x", false], null,
- "context-media-hidecontrols", false,
- "context-video-showstats", false,
- "context-video-fullscreen", false,
- "---", null,
- "context-viewvideo", true,
- "context-copyvideourl", true,
- "---", null,
- "context-savevideo", true,
- "context-video-saveimage", false,
- "context-sendvideo", true,
- "context-castvideo", null,
- [], null
- ].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(video_bad2); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for a video (with an INVALID media source)
- checkContextMenu(["context-media-play", false,
- "context-media-mute", false,
- "context-media-playbackrate", null,
- ["context-media-playbackrate-050x", false,
- "context-media-playbackrate-100x", false,
- "context-media-playbackrate-150x", false,
- "context-media-playbackrate-200x", false], null,
- "context-media-hidecontrols", false,
- "context-video-showstats", false,
- "context-video-fullscreen", false,
- "---", null,
- "context-viewvideo", false,
- "context-copyvideourl", false,
- "---", null,
- "context-savevideo", false,
- "context-video-saveimage", false,
- "context-sendvideo", false,
- "context-castvideo", null,
- [], null
- ].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(iframe); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for an iframe
- checkContextMenu(["context-navigation", null,
- ["context-back", false,
- "context-forward", false,
- "context-reload", true,
- "context-bookmarkpage", true], null,
- "---", null,
- "context-savepage", true,
- "---", null,
- "context-viewbgimage", false,
- "context-selectall", true,
- "frame", null,
- ["context-showonlythisframe", true,
- "context-openframeintab", true,
- "context-openframe", true,
- "---", null,
- "context-reloadframe", true,
- "---", null,
- "context-bookmarkframe", true,
- "context-saveframe", true,
- "---", null,
- "context-printframe", true,
- "---", null,
- "context-viewframesource", true,
- "context-viewframeinfo", true], null,
- "---", null,
- "context-viewsource", true,
- "context-viewinfo", true
- ].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(video_in_iframe); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for a video in an iframe
- checkContextMenu(["context-media-play", true,
- "context-media-mute", true,
- "context-media-playbackrate", null,
- ["context-media-playbackrate-050x", true,
- "context-media-playbackrate-100x", true,
- "context-media-playbackrate-150x", true,
- "context-media-playbackrate-200x", true], null,
- "context-media-hidecontrols", true,
- "context-video-showstats", true,
- "context-video-fullscreen", true,
- "---", null,
- "context-viewvideo", true,
- "context-copyvideourl", true,
- "---", null,
- "context-savevideo", true,
- "context-video-saveimage", true,
- "context-sendvideo", true,
- "context-castvideo", null,
- [], null,
- "frame", null,
- ["context-showonlythisframe", true,
- "context-openframeintab", true,
- "context-openframe", true,
- "---", null,
- "context-reloadframe", true,
- "---", null,
- "context-bookmarkframe", true,
- "context-saveframe", true,
- "---", null,
- "context-printframe", true,
- "---", null,
- "context-viewframeinfo", true], null].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(image_in_iframe); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for an image in an iframe
- checkContextMenu(["context-viewimage", true,
- "context-copyimage-contents", true,
- "context-copyimage", true,
- "---", null,
- "context-saveimage", true,
- "context-sendimage", true,
- "context-setDesktopBackground", true,
- "context-viewimageinfo", true,
- "frame", null,
- ["context-showonlythisframe", true,
- "context-openframeintab", true,
- "context-openframe", true,
- "---", null,
- "context-reloadframe", true,
- "---", null,
- "context-bookmarkframe", true,
- "context-saveframe", true,
- "---", null,
- "context-printframe", true,
- "---", null,
- "context-viewframeinfo", true], null].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(textarea); // Invoke context menu for next test
- },
-
- function () {
- // Context menu for textarea before spell check initialization finishes
- checkContextMenu(["context-undo", false,
- "---", null,
- "context-cut", true,
- "context-copy", true,
- "context-paste", null,
- "context-delete", false,
- "---", null,
- "context-selectall", true,
- "---", null,
- "spell-add-dictionaries-main", true,
- ].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(textarea, false, true); // Invoke context menu for next test, but wait for the spellcheck.
- },
-
- function () {
- // Context menu for textarea after spell check initialization finishes
- checkContextMenu(["*chubbiness", true, // spelling suggestion
- "spell-add-to-dictionary", true,
- "---", null,
- "context-undo", false,
- "---", null,
- "context-cut", true,
- "context-copy", true,
- "context-paste", null, // ignore clipboard state
- "context-delete", false,
- "---", null,
- "context-selectall", true,
- "---", null,
- "spell-check-enabled", true,
- "spell-dictionaries", true,
- ["spell-check-dictionary-en-US", true,
- "---", null,
- "spell-add-dictionaries", true], null
- ].concat(inspectItems));
- contextMenu.ownerDocument.getElementById("spell-add-to-dictionary").doCommand(); // Add to dictionary
- closeContextMenu();
- openContextMenuFor(text); // Invoke context menu for next test.
- },
-
- function () {
- // Re-check context menu for plain text to make sure it hasn't changed
- checkContextMenu(plainTextItems);
- closeContextMenu();
- openContextMenuFor(textarea, false, true); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for textarea after a word has been added
- // to the dictionary
- checkContextMenu(["spell-undo-add-to-dictionary", true,
- "---", null,
- "context-undo", false,
- "---", null,
- "context-cut", true,
- "context-copy", true,
- "context-paste", null, // ignore clipboard state
- "context-delete", false,
- "---", null,
- "context-selectall", true,
- "---", null,
- "spell-check-enabled", true,
- "spell-dictionaries", true,
- ["spell-check-dictionary-en-US", true,
- "---", null,
- "spell-add-dictionaries", true], null
- ].concat(inspectItems));
- contextMenu.ownerDocument.getElementById("spell-undo-add-to-dictionary").doCommand(); // Undo add to dictionary
- closeContextMenu();
- openContextMenuFor(contenteditable, false, true);
- },
-
- function () {
- // Context menu for contenteditable
- checkContextMenu(["spell-no-suggestions", false,
- "spell-add-to-dictionary", true,
- "---", null,
- "context-undo", false,
- "---", null,
- "context-cut", true,
- "context-copy", true,
- "context-paste", null, // ignore clipboard state
- "context-delete", false,
- "---", null,
- "context-selectall", true,
- "---", null,
- "spell-check-enabled", true,
- "spell-dictionaries", true,
- ["spell-check-dictionary-en-US", true,
- "---", null,
- "spell-add-dictionaries", true], null
- ].concat(inspectItems));
-
- closeContextMenu();
- openContextMenuFor(link); // Invoke context menu for next test.
- },
-
- function () {
- executeCopyCommand("cmd_copyLink", "http://mozilla.com/");
- closeContextMenu();
- openContextMenuFor(pagemenu); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for element with assigned content context menu
- checkContextMenu(["context-navigation", null,
- ["context-back", false,
- "context-forward", false,
- "context-reload", true,
- "context-bookmarkpage", true], null,
- "---", null,
- "+Plain item", {type: "", icon: "", checked: false, disabled: false},
- "+Disabled item", {type: "", icon: "", checked: false, disabled: true},
- "+Item w/ textContent", {type: "", icon: "", checked: false, disabled: false},
- "---", null,
- "+Checkbox", {type: "checkbox", icon: "", checked: true, disabled: false},
- "---", null,
- "+Radio1", {type: "checkbox", icon: "", checked: true, disabled: false},
- "+Radio2", {type: "checkbox", icon: "", checked: false, disabled: false},
- "+Radio3", {type: "checkbox", icon: "", checked: false, disabled: false},
- "---", null,
- "+Item w/ icon", {type: "", icon: "favicon.ico", checked: false, disabled: false},
- "+Item w/ bad icon", {type: "", icon: "", checked: false, disabled: false},
- "---", null,
- "generated-submenu-1", true,
- ["+Radio1", {type: "checkbox", icon: "", checked: false, disabled: false},
- "+Radio2", {type: "checkbox", icon: "", checked: true, disabled: false},
- "+Radio3", {type: "checkbox", icon: "", checked: false, disabled: false},
- "---", null,
- "+Checkbox", {type: "checkbox", icon: "", checked: false, disabled: false}], null,
- "---", null,
- "context-savepage", true,
- "---", null,
- "context-viewbgimage", false,
- "context-selectall", true,
- "---", null,
- "context-viewsource", true,
- "context-viewinfo", true
- ].concat(inspectItems));
-
- invokeItemAction("1");
- closeContextMenu();
-
- // run mozRequestFullScreen on the element we're testing
- var full_screen_element = subwindow.document.getElementById("test-dom-full-screen");
- var openDomFullScreen = function() {
- subwindow.removeEventListener("mozfullscreenchange", openDomFullScreen, false);
- openContextMenuFor(dom_full_screen, true); // Invoke context menu for next test.
- }
- subwindow.addEventListener("mozfullscreenchange", openDomFullScreen, false);
- SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", false);
- SpecialPowers.setCharPref("full-screen-api.transition-duration.enter", "0 0");
- SpecialPowers.setCharPref("full-screen-api.transition-duration.leave", "0 0");
- full_screen_element.mozRequestFullScreen();
- },
-
- function () {
- // Context menu for DOM Fullscreen mode (NOTE: this is *NOT* on an img)
- checkContextMenu(["context-navigation", null,
- ["context-back", false,
- "context-forward", false,
- "context-reload", true,
- "context-bookmarkpage", true], null,
- "---", null,
- "context-leave-dom-fullscreen", true,
- "---", null,
- "context-savepage", true,
- "---", null,
- "context-viewbgimage", false,
- "context-selectall", true,
- "---", null,
- "context-viewsource", true,
- "context-viewinfo", true
- ].concat(inspectItems));
- closeContextMenu();
- var full_screen_element = subwindow.document.getElementById("test-dom-full-screen");
- var openPagemenu = function() {
- subwindow.removeEventListener("mozfullscreenchange", openPagemenu, false);
- SpecialPowers.clearUserPref("full-screen-api.allow-trusted-requests-only");
- SpecialPowers.clearUserPref("full-screen-api.transition-duration.enter", "0 0");
- SpecialPowers.clearUserPref("full-screen-api.transition-duration.leave", "0 0");
- openContextMenuFor(pagemenu, true); // Invoke context menu for next test.
- }
- subwindow.addEventListener("mozfullscreenchange", openPagemenu, false);
- subwindow.document.mozCancelFullScreen();
- },
-
- function () {
- // Context menu for element with assigned content context menu
- // The shift key should bypass content context menu processing
- checkContextMenu(["context-navigation", null,
- ["context-back", false,
- "context-forward", false,
- "context-reload", true,
- "context-bookmarkpage", true], null,
- "---", null,
- "context-savepage", true,
- "---", null,
- "context-viewbgimage", false,
- "context-selectall", true,
- "---", null,
- "context-viewsource", true,
- "context-viewinfo", true
- ].concat(inspectItems));
- closeContextMenu();
- selectText(selecttext); // Select text prior to opening context menu.
- openContextMenuFor(selecttext); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for selected text
- if (SpecialPowers.Services.appinfo.OS == "Darwin") {
- // This test is only enabled on Mac due to bug 736399.
- checkContextMenu(["context-copy", true,
- "context-selectall", true,
- "---", null,
- "context-searchselect", true,
- "context-viewpartialsource-selection", true
- ].concat(inspectItems));
- }
- closeContextMenu();
- selectText(selecttextlink); // Select text prior to opening context menu.
- openContextMenuFor(selecttextlink); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for selected text which matches valid URL pattern
- if (SpecialPowers.Services.appinfo.OS == "Darwin") {
- // This test is only enabled on Mac due to bug 736399.
- checkContextMenu(["context-openlinkincurrent", true,
- "context-openlinkintab", true,
- "context-openlink", true,
- "context-openlinkprivate", true,
- "---", null,
- "context-bookmarklink", true,
- "context-savelink", true,
- "context-copy", true,
- "context-selectall", true,
- "---", null,
- "context-searchselect", true,
- "context-viewpartialsource-selection", true
- ].concat(inspectItems));
- }
- closeContextMenu();
- // clear the selection because following tests don't expect any selection
- subwindow.getSelection().removeAllRanges();
-
- openContextMenuFor(imagelink)
- },
-
- function () {
- // Context menu for image link
- checkContextMenu(["context-openlinkintab", true,
- "context-openlink", true,
- "context-openlinkprivate", true,
- "---", null,
- "context-bookmarklink", true,
- "context-savelink", true,
- "context-copylink", true,
- "---", null,
- "context-viewimage", true,
- "context-copyimage-contents", true,
- "context-copyimage", true,
- "---", null,
- "context-saveimage", true,
- "context-sendimage", true,
- "context-setDesktopBackground", true,
- "context-viewimageinfo", true
- ].concat(inspectItems));
- closeContextMenu();
- selectInputText(select_inputtext); // Select text prior to opening context menu.
- openContextMenuFor(select_inputtext); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for selected text in input
- checkContextMenu(["context-undo", false,
- "---", null,
- "context-cut", true,
- "context-copy", true,
- "context-paste", null, // ignore clipboard state
- "context-delete", true,
- "---", null,
- "context-selectall", true,
- "context-searchselect",true,
- "---", null,
- "spell-check-enabled", true
- ].concat(loginFillItems)
- .concat(inspectItems));
- closeContextMenu();
- selectInputText(select_inputtext_password); // Select text prior to opening context menu.
- openContextMenuFor(select_inputtext_password); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for selected text in input[type="password"]
- checkContextMenu(["context-undo", false,
- "---", null,
- "context-cut", true,
- "context-copy", true,
- "context-paste", null, // ignore clipboard state
- "context-delete", true,
- "---", null,
- "context-selectall", true,
- "---", null,
- "spell-check-enabled", true,
- //spell checker is shown on input[type="password"] on this testcase
- "spell-dictionaries", true,
- ["spell-check-dictionary-en-US", true,
- "---", null,
- "spell-add-dictionaries", true], null
- ].concat(loginFillItems)
- .concat(inspectItems));
- closeContextMenu();
- subwindow.getSelection().removeAllRanges();
- openContextMenuFor(plugin);
- },
-
- function () {
- // Context menu for click-to-play blocked plugin
- checkContextMenu(["context-navigation", null,
- ["context-back", false,
- "context-forward", false,
- "context-reload", true,
- "context-bookmarkpage", true], null,
- "---", null,
- "context-ctp-play", true,
- "context-ctp-hide", true,
- "---", null,
- "context-savepage", true,
- "---", null,
- "context-viewbgimage", false,
- "context-selectall", true,
- "---", null,
- "context-viewsource", true,
- "context-viewinfo", true
- ].concat(inspectItems));
- closeContextMenu();
- SpecialPowers.clearUserPref("plugins.click_to_play");
- getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED;
- openContextMenuFor(longdesc);
- },
-
- function () {
- // Context menu for an image with longdesc
- checkContextMenu(["context-viewimage", true,
- "context-copyimage-contents", true,
- "context-copyimage", true,
- "---", null,
- "context-saveimage", true,
- "context-sendimage", true,
- "context-setDesktopBackground", true,
- "context-viewimageinfo", true,
- "context-viewimagedesc", true
- ].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(srcdoc);
- },
-
- function () {
- // Context menu for an iframe with srcdoc attribute set
- checkContextMenu(["context-navigation", null,
- ["context-back", false,
- "context-forward", false,
- "context-reload", true,
- "context-bookmarkpage", true], null,
- "---", null,
- "context-savepage", true,
- "---", null,
- "context-viewbgimage", false,
- "context-selectall", true,
- "frame", null,
- ["context-reloadframe", true,
- "---", null,
- "context-saveframe", true,
- "---", null,
- "context-printframe", true,
- "---", null,
- "context-viewframesource", true,
- "context-viewframeinfo", true], null,
- "---", null,
- "context-viewsource", true,
- "context-viewinfo", true
- ].concat(inspectItems));
- closeContextMenu();
- openContextMenuFor(inputspellfalse, false, true); // Invoke context menu for next test.
- },
-
- function () {
- // Context menu for text input field with spellcheck=false
- checkContextMenu(["context-undo", false,
- "---", null,
- "context-cut", true,
- "context-copy", true,
- "context-paste", null, // ignore clipboard state
- "context-delete", false,
- "---", null,
- "context-selectall", true,
- "---", null,
- "spell-add-dictionaries-main", true,
- ].concat(inspectItems));
-
- // finish test
- subwindow.close();
- SimpleTest.finish();
- },
- ];
-
- /*
- * Other things that would be nice to test:
- * - check state of disabled items
- * - test execution of menu items (maybe as a separate test?)
- */
-
- tests[testNum]();
-}
-
-
-var testNum;
-var subwindow, chromeWin, contextMenu;
-var text, link, mailto, input, img, canvas, video_ok, video_bad, video_bad2,
- iframe, video_in_iframe, image_in_iframe, textarea, contenteditable,
- pagemenu, dom_full_screen, plainTextItems, audio_in_video,
- selecttext, selecttextlink, imagelink, select_inputtext, select_inputtext_password,
- plugin, longdesc, iframe, inputspellfalse;
-
-function startTest() {
- chromeWin = SpecialPowers.wrap(subwindow)
- .QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIWebNavigation)
- .QueryInterface(Ci.nsIDocShellTreeItem)
- .rootTreeItem
- .QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindow)
- .QueryInterface(Ci.nsIDOMChromeWindow);
- contextMenu = chromeWin.document.getElementById("contentAreaContextMenu");
- ok(contextMenu, "Got context menu XUL");
-
- if (chromeWin.document.getElementById("Browser:Stop").getAttribute("disabled") != "true") {
- todo(false, "Wait for subwindow to load... (This should usually happen once.)");
- SimpleTest.executeSoon(startTest);
- return;
- }
-
- subwindow.allowFullscreen = true;
- lastElement = null;
-
- text = subwindow.document.getElementById("test-text");
- link = subwindow.document.getElementById("test-link");
- imagelink = subwindow.document.getElementById("test-image-link");
- mailto = subwindow.document.getElementById("test-mailto");
- input = subwindow.document.getElementById("test-input");
- img = subwindow.document.getElementById("test-image");
- canvas = subwindow.document.getElementById("test-canvas");
- video_ok = subwindow.document.getElementById("test-video-ok");
- audio_in_video = subwindow.document.getElementById("test-audio-in-video");
- video_bad = subwindow.document.getElementById("test-video-bad");
- video_bad2 = subwindow.document.getElementById("test-video-bad2");
- iframe = subwindow.document.getElementById("test-iframe");
- video_in_iframe = subwindow.document.getElementById("test-video-in-iframe").contentDocument.getElementsByTagName("video")[0];
- video_in_iframe.pause();
- image_in_iframe = subwindow.document.getElementById("test-image-in-iframe").contentDocument.getElementsByTagName("img")[0];
- textarea = subwindow.document.getElementById("test-textarea");
- contenteditable = subwindow.document.getElementById("test-contenteditable");
- contenteditable.focus(); // content editable needs to be focused to enable spellcheck
- inputspellfalse = subwindow.document.getElementById("test-contenteditable-spellcheck-false");
- inputspellfalse.focus(); // content editable needs to be focused to enable spellcheck
- pagemenu = subwindow.document.getElementById("test-pagemenu");
- dom_full_screen = subwindow.document.getElementById("test-dom-full-screen");
- selecttext = subwindow.document.getElementById("test-select-text");
- selecttextlink = subwindow.document.getElementById("test-select-text-link");
- select_inputtext = subwindow.document.getElementById("test-select-input-text");
- select_inputtext_password = subwindow.document.getElementById("test-select-input-text-type-password");
- plugin = subwindow.document.getElementById("test-plugin");
- longdesc = subwindow.document.getElementById("test-longdesc");
- srcdoc = subwindow.document.getElementById("test-srcdoc");
-
- contextMenu.addEventListener("popupshown", function() { runTest(++testNum); }, false);
- testNum = 0;
- runTest(testNum);
-}
-
-// We open this in a separate window, because the Mochitests run inside a frame.
-// The frame causes an extra menu item, and prevents running the test
-// standalone (ie, clicking the test name in the Mochitest window) to see
-// success/failure messages.
-var painted = false, loaded = false;
-
-function waitForEvents(event)
-{
- if (event.type == "MozAfterPaint")
- painted = true;
- else if (event.type == "load")
- loaded = true;
- if (painted && loaded) {
- subwindow.removeEventListener("MozAfterPaint", waitForEvents, false);
- subwindow.onload = null;
- SimpleTest.waitForFocus(startTest, subwindow);
- }
-}
-
-SpecialPowers.setBoolPref("plugins.click_to_play", true);
-setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
-
-var subwindow = window.open("./subtst_contextmenu.html", "contextmenu-subtext", "width=600,height=800");
-subwindow.addEventListener("MozAfterPaint", waitForEvents, false);
-subwindow.onload = waitForEvents;
-
-SimpleTest.waitForExplicitFinish();
-</script>
-</pre>
-</body>
-</html>
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -490,16 +490,18 @@ this.BrowserTestUtils = {
if (typeof target == "function") {
targetFn = target.toString();
target = null;
} else if (typeof target != "string") {
cpowObject = target;
target = null;
}
+ Services.console.logStringMessage(`selecting ${target} at ${offsetX}, ${offsetY} (centered: ${event.centered})`);
+
mm.sendAsyncMessage("Test:SynthesizeMouse",
{target, targetFn, x: offsetX, y: offsetY, event: event},
{object: cpowObject});
});
},
/**
* Version of synthesizeMouse that uses the center of the target as the mouse