Bug 1358116 - Adapt browser_contextmenu* to take account of Screenshots being in the context menu when it is enabled. r?jaws draft
authorMark Banner <standard8@mozilla.com>
Thu, 27 Apr 2017 15:46:32 +0100
changeset 569968 ef7c723811beb2c7aec6d6196f2d9ccdf59ad385
parent 569138 0b77ed3f26c5335503bc16e85b8c067382e7bb1e
child 626360 c65eb2d98f74ab589224a1629e94fed706def535
push id56347
push userbmo:standard8@mozilla.com
push dateFri, 28 Apr 2017 07:11:03 +0000
reviewersjaws
bugs1358116
milestone55.0a1
Bug 1358116 - Adapt browser_contextmenu* to take account of Screenshots being in the context menu when it is enabled. r?jaws MozReview-Commit-ID: 9NJvBLnQ0We
browser/base/content/test/general/browser_contextmenu.js
browser/base/content/test/general/browser_contextmenu_input.js
browser/base/content/test/general/contextmenu_common.js
--- a/browser/base/content/test/general/browser_contextmenu.js
+++ b/browser/base/content/test/general/browser_contextmenu.js
@@ -85,17 +85,19 @@ add_task(function* test_plaintext() {
                     ...(hasPocket ? ["context-pocket", true] : []),
                     "---",                  null,
                     "context-viewbgimage",  false,
                     "context-selectall",    true,
                     "---",                  null,
                     "context-viewsource",   true,
                     "context-viewinfo",     true
                    ];
-  yield test_contextmenu("#test-text", plainTextItems);
+  yield test_contextmenu("#test-text", plainTextItems, {
+    maybeScreenshotsPresent: true
+  });
 });
 
 add_task(function* test_link() {
   yield test_contextmenu("#test-link",
     ["context-openlinkintab", true,
      ...(hasContainers ? ["context-openlinkinusercontext-menu", true] : []),
      // We need a blank entry here because the containers submenu is
      // dynamically generated with no ids.
@@ -134,17 +136,19 @@ add_task(function* test_image() {
   );
 });
 
 add_task(function* test_canvas() {
   yield test_contextmenu("#test-canvas",
     ["context-viewimage",    true,
      "context-saveimage",    true,
      "context-selectall",    true
-    ]
+    ], {
+      maybeScreenshotsPresent: true
+    }
   );
 });
 
 add_task(function* test_video_ok() {
   yield test_contextmenu("#test-video-ok",
     ["context-media-play",         true,
      "context-media-mute",         true,
      "context-media-playbackrate", null,
@@ -428,17 +432,19 @@ add_task(function* test_textarea_spellch
         document.getElementById("spell-add-to-dictionary").doCommand();
       }
     }
   );
   */
 });
 
 add_task(function* test_plaintext2() {
-  yield test_contextmenu("#test-text", plainTextItems);
+  yield test_contextmenu("#test-text", plainTextItems, {
+    maybeScreenshotsPresent: true
+  });
 });
 
 add_task(function* test_undo_add_to_dictionary() {
   todo(false, "spell checker tests are failing, bug 1246296");
 
   /*
   yield test_contextmenu("#test-textarea",
     ["spell-undo-add-to-dictionary", true,
@@ -564,17 +570,18 @@ add_task(function* test_pagemenu() {
     {*postCheckContextMenuFn() {
       let item = contextMenu.getElementsByAttribute("generateditemid", "1")[0];
       ok(item, "Got generated XUL menu item");
       item.doCommand();
       yield ContentTask.spawn(gBrowser.selectedBrowser, null, function*() {
         let pagemenu = content.document.getElementById("test-pagemenu");
         Assert.ok(!pagemenu.hasAttribute("hopeless"), "attribute got removed");
       });
-    }
+    },
+    maybeScreenshotsPresent: true
   });
 });
 
 add_task(function* test_dom_full_screen() {
   yield test_contextmenu("#test-dom-full-screen",
     ["context-navigation",           null,
          ["context-back",            false,
           "context-forward",         false,
@@ -588,16 +595,17 @@ add_task(function* test_dom_full_screen(
      "---",                          null,
      "context-viewbgimage",          false,
      "context-selectall",            true,
      "---",                          null,
      "context-viewsource",           true,
      "context-viewinfo",             true
     ],
     {
+      maybeScreenshotsPresent: true,
       shiftkey: true,
       *preCheckContextMenuFn() {
         yield pushPrefs(["full-screen-api.allow-trusted-requests-only", false],
                         ["full-screen-api.transition-duration.enter", "0 0"],
                         ["full-screen-api.transition-duration.leave", "0 0"])
         yield ContentTask.spawn(gBrowser.selectedBrowser, null, function*() {
           let doc = content.document;
           let win = doc.defaultView;
@@ -633,17 +641,18 @@ add_task(function* test_pagemenu2() {
      ...(hasPocket ? ["context-pocket", true] : []),
      "---",                  null,
      "context-viewbgimage",  false,
      "context-selectall",    true,
      "---",                  null,
      "context-viewsource",   true,
      "context-viewinfo",     true
     ],
-    {shiftkey: true}
+    {maybeScreenshotsPresent: true,
+     shiftkey: true}
   );
 });
 
 add_task(function* test_select_text() {
   yield test_contextmenu("#test-select-text",
     ["context-copy",                        true,
      "context-selectall",                   true,
      "---",                                 null,
@@ -812,16 +821,17 @@ add_task(function* test_click_to_play_bl
      "---",                  null,
      "context-viewbgimage",  false,
      "context-selectall",    true,
      "---",                  null,
      "context-viewsource",   true,
      "context-viewinfo",     true
     ],
     {
+      maybeScreenshotsPresent: true,
       *preCheckContextMenuFn() {
         pushPrefs(["plugins.click_to_play", true]);
         setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
       },
       *postCheckContextMenuFn() {
         getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED;
       }
     }
@@ -917,16 +927,17 @@ add_task(function* test_plaintext_sendpa
                     "---",                  null,
                     "context-viewbgimage",  false,
                     "context-selectall",    true,
                     "---",                  null,
                     "context-viewsource",   true,
                     "context-viewinfo",     true
                    ];
   yield test_contextmenu("#test-text", plainTextItemsWithSendPage, {
+      maybeScreenshotsPresent: true,
       *onContextMenuShown() {
         yield openMenuItemSubmenu("context-sendpagetodevice");
       }
     });
 
   restoreRemoteClients(oldGetter);
 });
 
--- a/browser/base/content/test/general/browser_contextmenu_input.js
+++ b/browser/base/content/test/general/browser_contextmenu_input.js
@@ -169,19 +169,23 @@ add_task(function* test_tel_email_url_nu
     yield test_contextmenu(selector,
       ["context-undo",        false,
        "---",                 null,
        "context-cut",         true,
        "context-copy",        true,
        "context-paste",       null, // ignore clipboard state
        "context-delete",      false,
        "---",                 null,
-       "context-selectall",   null],
-      {skipFocusChange: true}
-    );
+       "context-selectall",   null], {
+      // XXX Bug 1345081. Currently the Screenshots menu option is shown for
+      // various text elements even though it is set to type "page". That bug
+      // should remove the need for next line.
+      maybeScreenshotsPresent: true,
+      skipFocusChange: true
+    });
   }
 });
 
 add_task(function* test_date_time_color_range_month_week_datetimelocal_input() {
   for (let selector of ["#input_date", "#input_time", "#input_color",
                         "#input_range", "#input_month", "#input_week",
                         "#input_datetime-local"]) {
     yield test_contextmenu(selector,
@@ -193,19 +197,23 @@ add_task(function* test_date_time_color_
        "---",                  null,
        "context-savepage",     true,
        ...(hasPocket ? ["context-pocket", true] : []),
        "---",                  null,
        "context-viewbgimage",  false,
        "context-selectall",    null,
        "---",                  null,
        "context-viewsource",   true,
-       "context-viewinfo",     true],
-      {skipFocusChange: true}
-    );
+       "context-viewinfo",     true], {
+      // XXX Bug 1345081. Currently the Screenshots menu option is shown for
+      // various text elements even though it is set to type "page". That bug
+      // should remove the need for next line.
+      maybeScreenshotsPresent: true,
+      skipFocusChange: true
+    });
   }
 });
 
 add_task(function* test_search_input() {
   todo(false, "context-selectall is enabled on osx-e10s, and windows when" +
               " it should be disabled");
   yield test_contextmenu("#input_search",
     ["context-undo",        false,
@@ -229,16 +237,20 @@ add_task(function* test_text_input_reado
   yield test_contextmenu("#input_readonly",
     ["context-undo",        false,
      "---",                 null,
      "context-cut",         true,
      "context-copy",        true,
      "context-paste",       null, // ignore clipboard state
      "context-delete",      false,
      "---",                 null,
-     "context-selectall",   null],
-    {skipFocusChange: true}
-  );
+     "context-selectall",   null], {
+    // XXX Bug 1345081. Currently the Screenshots menu option is shown for
+    // various text elements even though it is set to type "page". That bug
+    // should remove the need for next line.
+    maybeScreenshotsPresent: true,
+    skipFocusChange: true
+  });
 });
 
 add_task(function* test_cleanup() {
   yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
--- a/browser/base/content/test/general/contextmenu_common.js
+++ b/browser/base/content/test/general/contextmenu_common.js
@@ -64,17 +64,20 @@ function getVisibleMenuItems(aMenu, aDat
               items.push("*" + label);
             } else if (isPageMenuItem) {
               items.push("+" + label);
             } else if (item.id.indexOf("spell-check-dictionary-") != 0 &&
                        item.id != "spell-no-suggestions" &&
                        item.id != "spell-add-dictionaries-main" &&
                        item.id != "context-savelinktopocket" &&
                        item.id != "fill-login-saved-passwords" &&
-                       item.id != "fill-login-no-logins") {
+                       item.id != "fill-login-no-logins" &&
+                       // XXX Screenshots doesn't have an access key. This needs
+                       // at least bug 1320462 fixing first.
+                       item.id != "screenshots_mozilla_org_create-screenshot") {
               ok(key, "menuitem " + item.id + " has an access key");
               if (accessKeys[key])
                   ok(false, "menuitem " + item.id + " has same accesskey as " + accessKeys[key]);
               else
                   accessKeys[key] = item.id;
             }
             if (!isGenerated && !isPageMenuItem) {
               items.push(item.id);
@@ -241,16 +244,19 @@ let lastElementSelector = null;
  *        offsetX: horizontal mouse offset from the top-left corner of
  *                 the element, optional
  *        offsetY: vertical mouse offset from the top-left corner of the
  *                 element, optional
  *        centered: if true, mouse position is centered in element, defaults
  *                  to true if offsetX and offsetY are not provided
  *        waitForSpellCheck: wait until spellcheck is initialized before
  *                           starting test
+ *        maybeScreenshotsPresent: if true, the screenshots menu entry is
+ *                                 expected to be present in the menu if
+ *                                 screenshots is enabled, optional
  *        preCheckContextMenuFn: callback to run before opening menu
  *        onContextMenuShown: callback to run when the context menu is shown
  *        postCheckContextMenuFn: callback to run after opening menu
  * @return {Promise} resolved after the test finishes
  */
 function* test_contextmenu(selector, menuItems, options = {}) {
   contextMenu = document.getElementById("contentAreaContextMenu");
   is(contextMenu.state, "closed", "checking if popup is closed");
@@ -310,16 +316,27 @@ function* test_contextmenu(selector, men
 
   if (menuItems) {
     if (Services.prefs.getBoolPref("devtools.inspector.enabled")) {
       let inspectItems = ["---", null,
                           "context-inspect", true];
       menuItems = menuItems.concat(inspectItems);
     }
 
+    if (options.maybeScreenshotsPresent &&
+        !Services.prefs.getBoolPref("extensions.screenshots.disabled", false) &&
+        !Services.prefs.getBoolPref("extensions.screenshots.system-disabled", false)) {
+      let screenshotItems = [
+        "---", null,
+        "screenshots_mozilla_org_create-screenshot", true
+      ];
+
+      menuItems = menuItems.concat(screenshotItems);
+    }
+
     checkContextMenu(menuItems);
   }
 
   let awaitPopupHidden = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden");
 
   if (options.postCheckContextMenuFn) {
     yield options.postCheckContextMenuFn();
     info("Completed postCheckContextMenuFn");