Back out 3be3bb423482 (bug 970746) for mochitest-1 bustage
authorPhil Ringnalda <philringnalda@gmail.com>
Sat, 22 Feb 2014 07:15:44 -0800
changeset 170447 7dd5c624d56359ce5dc68f32bd8057efad964344
parent 170446 3be3bb423482c42d0f077dde03fbfb3289c32cbc
child 170448 88952794447058a184d8ea67f94abd1c7b186cdd
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
bugs970746
milestone30.0a1
backs out3be3bb423482c42d0f077dde03fbfb3289c32cbc
Back out 3be3bb423482 (bug 970746) for mochitest-1 bustage
browser/base/content/browser-context.inc
browser/base/content/nsContextMenu.js
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_bug970746.js
browser/base/content/test/general/browser_bug970746.xhtml
--- a/browser/base/content/browser-context.inc
+++ b/browser/base/content/browser-context.inc
@@ -288,17 +288,17 @@
                 accesskey="&selectAllCmd.accesskey;"
                 command="cmd_selectAll"/>
       <menuseparator id="context-sep-selectall"/>
       <menuitem id="context-keywordfield"
                 label="&keywordfield.label;"
                 accesskey="&keywordfield.accesskey;"
                 oncommand="AddKeywordForSearchField();"/>
       <menuitem id="context-searchselect"
-                oncommand="BrowserSearch.loadSearchFromContext(this.searchTerms);"/>
+                oncommand="BrowserSearch.loadSearchFromContext(getBrowserSelection());"/>
       <menuitem id="context-shareselect"
                 label="&shareSelectCmd.label;"
                 accesskey="&shareSelectCmd.accesskey;"
                 oncommand="gContextMenu.shareSelect(getBrowserSelection());"/>
       <menuseparator id="frame-sep"/>
       <menu id="frame" label="&thisFrameMenu.label;" accesskey="&thisFrameMenu.accesskey;">
         <menupopup>
           <menuitem id="context-showonlythisframe"
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -27,17 +27,17 @@ nsContextMenu.prototype = {
     }
 
     this.isFrameImage = document.getElementById("isFrameImage");
     this.ellipsis = "\u2026";
     try {
       this.ellipsis = gPrefService.getComplexValue("intl.ellipsis",
                                                    Ci.nsIPrefLocalizedString).data;
     } catch (e) { }
-
+    this.isTextSelected = this.isTextSelection();
     this.isContentSelected = this.isContentSelection();
     this.onPlainTextLink = false;
 
     // Initialize (disable/remove) menu items.
     this.initItems();
   },
 
   hiding: function CM_hiding() {
@@ -263,44 +263,41 @@ nsContextMenu.prototype = {
     document.getElementById("context-viewbgimage")
             .disabled = !this.hasBGImage;
 
     this.showItem("context-viewimageinfo", this.onImage);
     this.showItem("context-viewimagedesc", this.onImage && this.imageDescURL !== "");
   },
 
   initMiscItems: function CM_initMiscItems() {
+    var isTextSelected = this.isTextSelected;
+
     // Use "Bookmark This Link" if on a link.
     this.showItem("context-bookmarkpage",
                   !(this.isContentSelected || this.onTextInput || this.onLink ||
                     this.onImage || this.onVideo || this.onAudio || this.onSocial));
     this.showItem("context-bookmarklink", (this.onLink && !this.onMailtoLink &&
                                            !this.onSocial) || this.onPlainTextLink);
+    this.showItem("context-searchselect", isTextSelected);
     this.showItem("context-keywordfield",
                   this.onTextInput && this.onKeywordField);
     this.showItem("frame", this.inFrame);
 
-    let showSearchSelect = this.isTextSelected || this.onLink;
-    this.showItem("context-searchselect", showSearchSelect);
-    if (showSearchSelect) {
-      this.formatSearchContextItem();
-    }
-
     // srcdoc cannot be opened separately due to concerns about web
     // content with about:srcdoc in location bar masquerading as trusted
     // chrome/addon content.
     // No need to also test for this.inFrame as this is checked in the parent
     // submenu.
     this.showItem("context-showonlythisframe", !this.inSrcdocFrame);
     this.showItem("context-openframeintab", !this.inSrcdocFrame);
     this.showItem("context-openframe", !this.inSrcdocFrame);
     this.showItem("context-bookmarkframe", !this.inSrcdocFrame);
     this.showItem("open-frame-sep", !this.inSrcdocFrame);
 
-    this.showItem("frame-sep", this.inFrame && this.isTextSelected);
+    this.showItem("frame-sep", this.inFrame && isTextSelected);
 
     // Hide menu entries for images, show otherwise
     if (this.inFrame) {
       if (mimeTypeIsTextBased(this.target.ownerDocument.contentType))
         this.isFrameImage.removeAttribute('hidden');
       else
         this.isFrameImage.setAttribute('hidden', 'true');
     }
@@ -538,18 +535,16 @@ nsContextMenu.prototype = {
     this.inSrcdocFrame     = false;
     this.inSyntheticDoc    = false;
     this.hasBGImage        = false;
     this.bgImageURL        = "";
     this.onEditableArea    = false;
     this.isDesignMode      = false;
     this.onCTPPlugin       = false;
     this.canSpellCheck     = false;
-    this.textSelected      = getBrowserSelection();
-    this.isTextSelected    = this.textSelected.length != 0;
 
     // Remember the node that was clicked.
     this.target = aNode;
 
     // If this is a remote context menu event, use the information from
     // gContextMenuContentData instead.
     if (this.isRemote) {
       this.browser = gContextMenuContentData.browser;
@@ -1436,16 +1431,49 @@ nsContextMenu.prototype = {
         if (!text || !text.match(/\S/))
           text = this.linkURL;
       }
     }
 
     return text;
   },
 
+  // Get selected text. Only display the first 15 chars.
+  isTextSelection: function() {
+    // Get 16 characters, so that we can trim the selection if it's greater
+    // than 15 chars
+    var selectedText = getBrowserSelection(16);
+
+    if (!selectedText)
+      return false;
+
+    if (selectedText.length > 15)
+      selectedText = selectedText.substr(0,15) + this.ellipsis;
+
+    // Use the current engine if the search bar is visible, the default
+    // engine otherwise.
+    var engineName = "";
+    var ss = Cc["@mozilla.org/browser/search-service;1"].
+             getService(Ci.nsIBrowserSearchService);
+    if (isElementVisible(BrowserSearch.searchBar))
+      engineName = ss.currentEngine.name;
+    else
+      engineName = ss.defaultEngine.name;
+
+    // format "Search <engine> for <selection>" string to show in menu
+    var menuLabel = gNavigatorBundle.getFormattedString("contextMenuSearch",
+                                                        [engineName,
+                                                         selectedText]);
+    document.getElementById("context-searchselect").label = menuLabel;
+    document.getElementById("context-searchselect").accessKey =
+             gNavigatorBundle.getString("contextMenuSearch.accesskey"); 
+
+    return true;
+  },
+
   // Returns true if anything is selected.
   isContentSelection: function() {
     return !document.commandDispatcher.focusedWindow.getSelection().isCollapsed;
   },
 
   toString: function () {
     return "contextMenu.target     = " + this.target + "\n" +
            "contextMenu.onImage    = " + this.onImage + "\n" +
@@ -1649,39 +1677,10 @@ nsContextMenu.prototype = {
                     getService(Ci.nsIClipboardHelper);
     clipboard.copyString(this.mediaURL, document);
   },
 
   get imageURL() {
     if (this.onImage)
       return this.mediaURL;
     return "";
-  },
-
-  // Formats the 'Search <engine> for "<selection or link text>"' context menu.
-  formatSearchContextItem: function() {
-    var menuItem = document.getElementById("context-searchselect");
-    var selectedText = this.onLink ? this.linkText() : this.textSelected;
-
-    // Store searchTerms in context menu item so we know what to search onclick
-    menuItem.searchTerms = selectedText;
-
-    if (selectedText.length > 15)
-      selectedText = selectedText.substr(0,15) + this.ellipsis;
-
-    // Use the current engine if the search bar is visible, the default
-    // engine otherwise.
-    var engineName = "";
-    var ss = Cc["@mozilla.org/browser/search-service;1"].
-             getService(Ci.nsIBrowserSearchService);
-    if (isElementVisible(BrowserSearch.searchBar))
-      engineName = ss.currentEngine.name;
-    else
-      engineName = ss.defaultEngine.name;
-
-    // format "Search <engine> for <selection>" string to show in menu
-    var menuLabel = gNavigatorBundle.getFormattedString("contextMenuSearch",
-                                                        [engineName,
-                                                         selectedText]);
-    menuItem.label = menuLabel;
-    menuItem.accessKey = gNavigatorBundle.getString("contextMenuSearch.accesskey");
   }
 };
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -102,17 +102,16 @@ support-files =
   zoom_test.html
   test_no_mcb_on_http_site_img.html
   test_no_mcb_on_http_site_img.css
   test_no_mcb_on_http_site_font.html
   test_no_mcb_on_http_site_font.css
   test_no_mcb_on_http_site_font2.html
   test_no_mcb_on_http_site_font2.css
   xul_tooltiptext.xhtml
-  browser_bug970746.xhtml
 
 [browser_CTP_context_menu.js]
 skip-if = toolkit == "gtk2" || toolkit == "gtk3"   # browser_CTP_context_menu.js fails intermittently on Linux (bug 909342)
 [browser_CTP_crashreporting.js]
 run-if = crashreporter
 [browser_CTP_data_urls.js]
 [browser_CTP_drag_drop.js]
 [browser_CTP_multi_allow.js]
@@ -242,17 +241,16 @@ skip-if = os == "mac" # Intermittent fai
 [browser_bug820497.js]
 [browser_bug822367.js]
 [browser_bug832435.js]
 [browser_bug839103.js]
 [browser_bug880101.js]
 [browser_bug882977.js]
 [browser_bug902156.js]
 [browser_bug906190.js]
-[browser_bug970746.js]
 [browser_canonizeURL.js]
 [browser_clearplugindata.js]
 [browser_contentAreaClick.js]
 [browser_contextSearchTabPosition.js]
 skip-if = os == "mac" # bug 967013, bug 926729
 [browser_ctrlTab.js]
 [browser_customize_popupNotification.js]
 [browser_datareporting_notification.js]
deleted file mode 100644
--- a/browser/base/content/test/general/browser_bug970746.js
+++ /dev/null
@@ -1,104 +0,0 @@
-/* Make sure context menu includes option to search hyperlink text on search engine */
-
-function test() {
-  waitForExplicitFinish();
-
-  gBrowser.selectedTab = gBrowser.addTab();
-  
-  gBrowser.selectedBrowser.addEventListener("load", function() {
-    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
-
-    let doc = gBrowser.contentDocument;
-    let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
-    let ellipsis = "\u2026";
-
-    // Tests if the "Search <engine> for '<some terms>'" context menu item is shown for the
-    // given query string of an element. Tests to make sure label includes the proper search terms.
-    //
-    // Options:
-    // 
-    //   id: The id of the element to test.
-    //   isSelected: Flag to enable selection (text hilight) the contents of the element
-    //   shouldBeShown: The display state of the menu item
-    //   expectedLabelContents: The menu item label should contain a portion of this string.
-    //                          Will only be tested if shouldBeShown is true.
-
-    let testElement = function(opts) {
-      let element = doc.getElementById(opts.id);
-      document.popupNode = element;
-
-      let selection = content.getSelection();
-      selection.removeAllRanges();
-
-      if(opts.isSelected) {
-        selection.selectAllChildren(element);
-      }
-
-      let contextMenu = new nsContextMenu(contentAreaContextMenu);
-      let menuItem = document.getElementById("context-searchselect");
-
-      is(document.getElementById("context-searchselect").hidden, !opts.shouldBeShown, "search context menu item is shown for  '#" + opts.id + "' and selected is '" + opts.isSelected + "'");
-
-      if(opts.shouldBeShown) {
-        ok(menuItem.label.contains(opts.expectedLabelContents), "Menu item text '" + menuItem.label  + "' contains the correct search terms '" + opts.expectedLabelContents  + "'");
-      }
-    }
-
-    testElement({
-      id: "link",
-      isSelected: true,
-      shouldBeShown: true,
-      expectedLabelContents: "I'm a link!",
-    });
-    testElement({
-      id: "link",
-      isSelected: false,
-      shouldBeShown: true,
-      expectedLabelContents: "I'm a link!",
-    });
-
-    testElement({
-      id: "longLink",
-      isSelected: true,
-      shouldBeShown: true,
-      expectedLabelContents: "I'm a really lo" + ellipsis,
-    });
-    testElement({
-      id: "longLink",
-      isSelected: false,
-      shouldBeShown: true,
-      expectedLabelContents: "I'm a really lo" + ellipsis,
-    });
-
-    testElement({
-      id: "plainText",
-      isSelected: true,
-      shouldBeShown: true,
-      expectedLabelContents: "Right clicking " + ellipsis,
-    });
-    testElement({
-      id: "plainText",
-      isSelected: false,
-      shouldBeShown: false,
-    });
-
-    testElement({
-      id: "mixedContent",
-      isSelected: true,
-      shouldBeShown: true,
-      expectedLabelContents: "I'm some text, " + ellipsis,
-    });
-    testElement({
-      id: "mixedContent",
-      isSelected: false,
-      shouldBeShown: false,
-    });
-
-    // cleanup
-    document.popupNode = null;
-    gBrowser.removeCurrentTab();
-    finish();
-  }, true);
-
-  content.location = "http://mochi.test:8888/browser/browser/base/content/test/general/browser_bug970746.xhtml";
-}
\ No newline at end of file
deleted file mode 100644
--- a/browser/base/content/test/general/browser_bug970746.xhtml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<html xmlns="http://www.w3.org/1999/xhtml">
-	<body>
-		<a href="http://mozilla.org" id="link">I'm a link!</a>
-		<a href="http://mozilla.org" id="longLink">I'm a really long link and I should be truncated.</a>
-
-		<span id="plainText">
-			Right clicking me when I'm selected should show the menu item.
-		</span>
-		<span id="mixedContent">
-			I'm some text, and <a href="http://mozilla.org">I'm a link!</a>
-		</span>
-	</body>
-</html>
\ No newline at end of file