Bug 1115002 - Pressing context menu should close the search panel. r=Florian, a=lmandel
authorAbdelrhman Ahmed <a.ahmed1026@gmail.com>
Tue, 03 Feb 2015 13:57:04 +0100
changeset 249593 b85afc7a726a69f6dfad86a7c80d85ae490751b4
parent 249592 fb3d1ebbb61010fa3ed947c77eb99d88f2453acb
child 249594 f1c0a517ebc7238470e34a41434fec1de0989876
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFlorian, lmandel
bugs1115002
milestone37.0a2
Bug 1115002 - Pressing context menu should close the search panel. r=Florian, a=lmandel
browser/components/search/content/search.xml
browser/components/search/test/browser_searchbar_openpopup.js
--- a/browser/components/search/content/search.xml
+++ b/browser/components/search/content/search.xml
@@ -805,16 +805,17 @@
 
         // Add items to context menu and attach controller to handle them
         var textBox = document.getAnonymousElementByAttribute(this,
                                               "anonid", "textbox-input-box");
         var cxmenu = document.getAnonymousElementByAttribute(textBox,
                                           "anonid", "input-box-contextmenu");
         var pasteAndSearch;
         cxmenu.addEventListener("popupshowing", function() {
+          BrowserSearch.searchBar._textbox.closePopup();
           if (!pasteAndSearch)
             return;
           var controller = document.commandDispatcher.getControllerForCommand("cmd_paste");
           var enabled = controller.isCommandEnabled("cmd_paste");
           if (enabled)
             pasteAndSearch.removeAttribute("disabled");
           else
             pasteAndSearch.setAttribute("disabled", "true");
--- a/browser/components/search/test/browser_searchbar_openpopup.js
+++ b/browser/components/search/test/browser_searchbar_openpopup.js
@@ -224,16 +224,47 @@ add_task(function* escape_closes_popup()
 
   promise = promiseEvent(searchPopup, "popuphidden");
   EventUtils.synthesizeKey("VK_ESCAPE", {});
   yield promise;
 
   textbox.value = "";
 });
 
+// Pressing contextmenu should close the popup.
+add_task(function* contextmenu_closes_popup() {
+  gURLBar.focus();
+  textbox.value = "foo";
+
+  let promise = promiseEvent(searchPopup, "popupshown");
+  EventUtils.synthesizeMouseAtCenter(textbox, {});
+  yield promise;
+  isnot(searchPopup.getAttribute("showonlysettings"), "true", "Should show the full popup");
+
+  is(Services.focus.focusedElement, textbox.inputField, "Should have focused the search bar");
+  is(textbox.selectionStart, 0, "Should have selected all of the text");
+  is(textbox.selectionEnd, 3, "Should have selected all of the text");
+
+  promise = promiseEvent(searchPopup, "popuphidden");
+
+  //synthesizeKey does not work with VK_CONTEXT_MENU (bug 1127368)
+  EventUtils.synthesizeMouseAtCenter(textbox, { type: "contextmenu", button: null });
+
+  yield promise;
+
+  let contextPopup =
+    document.getAnonymousElementByAttribute(textbox.inputField.parentNode,
+                                            "anonid", "input-box-contextmenu");
+  promise = promiseEvent(contextPopup, "popuphidden");
+  contextPopup.hidePopup();
+  yield promise;
+
+  textbox.value = "";
+});
+
 // Tabbing to the search box should open the popup if it contains text.
 add_task(function* tab_opens_popup() {
   gURLBar.focus();
   textbox.value = "foo";
 
   let promise = promiseEvent(searchPopup, "popupshown");
   EventUtils.synthesizeKey("VK_TAB", {});
   yield promise;