Bug 1181560 - ensure previous menus get closed when opening new ones, r=Enn, a=sylvestre
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 14 Jul 2015 18:06:45 +0100
changeset 296289 1467488dd1cb8ec2b18dd71414e7c5ea727e67b9
parent 296288 a80ec0b5f87562c45f88d59a0f45bf26319e39d3
child 296290 91a9dd45c0716010dd61ff71f8901355014a1bf8
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEnn, sylvestre
bugs1181560
milestone43.0a2
Bug 1181560 - ensure previous menus get closed when opening new ones, r=Enn, a=sylvestre
layout/xul/nsMenuFrame.cpp
layout/xul/test/chrome.ini
layout/xul/test/test_submenuClose.xul
--- a/layout/xul/nsMenuFrame.cpp
+++ b/layout/xul/nsMenuFrame.cpp
@@ -420,16 +420,17 @@ nsMenuFrame::HandleEvent(nsPresContext* 
     // We have children.
     // Don't prevent the default action here, since that will also cancel
     // potential drag starts.
     if (!menuParent || menuParent->IsMenuBar()) {
       ToggleMenuState();
     }
     else {
       if (!IsOpen()) {
+        menuParent->ChangeMenuItem(this, false, false);
         OpenMenu(false);
       }
     }
   }
   else if (
 #ifndef NSCONTEXTMENUISMOUSEUP
            (aEvent->mMessage == eMouseUp &&
             aEvent->AsMouseEvent()->button == WidgetMouseEvent::eRightButton) &&
--- a/layout/xul/test/chrome.ini
+++ b/layout/xul/test/chrome.ini
@@ -17,10 +17,11 @@ skip-if = buildapp == 'mulet'
 skip-if = buildapp == 'mulet'
 [test_bug987230.xul]
 skip-if = os == 'linux' # No native mousedown event on Linux
 [test_popupReflowPos.xul]
 [test_popupSizeTo.xul]
 [test_popupZoom.xul]
 [test_resizer.xul]
 [test_stack.xul]
+[test_submenuClose.xul]
 [test_windowminmaxsize.xul]
 skip-if = buildapp == 'mulet'
new file mode 100644
--- /dev/null
+++ b/layout/xul/test/test_submenuClose.xul
@@ -0,0 +1,91 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1181560
+-->
+<window title="Mozilla Bug 1181560"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        onload="SimpleTest.waitForFocus(nextTest, window)">
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+
+  <!-- test results are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1181560"
+     target="_blank">Mozilla Bug 1181560</a>
+  </body>
+
+  <vbox>
+    <menubar>
+      <menu id="menu" label="MyMenu">
+        <menupopup>
+          <menuitem label="A"/>
+          <menu id="b" label="B">
+            <menupopup>
+              <menuitem label="B1"/>
+            </menupopup>
+          </menu>
+          <menu id="c" label="C">
+            <menupopup>
+              <menuitem label="C1"/>
+            </menupopup>
+          </menu>
+        </menupopup>
+      </menu>
+    </menubar>
+  </vbox>
+
+  <!-- test code goes here -->
+  <script type="application/javascript">
+  <![CDATA[
+  /** Test for Bug 1181560 **/
+  SimpleTest.waitForExplicitFinish();
+
+  let menuB, menuC, mainMenu, menuBOpen, menuCOpen;
+  let menuBOpenCount = 0;
+
+  function handleBOpens() {
+    menuBOpenCount++;
+    menuBOpen = true;
+    ok(!menuCOpen, "Menu C should not be open when menu B has opened");
+    if (menuBOpenCount >= 2) {
+      SimpleTest.finish();
+      return;
+    }
+    sendKey("LEFT", window);
+    sendKey("DOWN", window);
+    sendKey("RIGHT", window);
+  }
+
+  function handleBCloses() {
+    menuBOpen = false;
+  }
+
+  function handleCOpens() {
+    menuCOpen = true;
+    ok(!menuBOpen, "Menu B should not be open when menu C has opened");
+    synthesizeMouseAtCenter(menuB, {}, window);
+  }
+
+  function handleCCloses() {
+    menuCOpen = false;
+  }
+
+  function nextTest(e) {
+    mainMenu = document.getElementById("menu");
+    menuB = document.getElementById("b");
+    menuC = document.getElementById("c");
+    menuB.firstChild.addEventListener("popupshown", handleBOpens, false);
+    menuB.firstChild.addEventListener("popuphidden", handleBCloses, false);
+    menuC.firstChild.addEventListener("popupshown", handleCOpens, false);
+    menuC.firstChild.addEventListener("popuphidden", handleCCloses, false);
+    mainMenu.addEventListener("popupshown", ev => {
+      synthesizeMouseAtCenter(menuB, {}, window);
+    });
+    mainMenu.open = true;
+  }
+  ]]>
+  </script>
+</window>