toolkit/content/tests/chrome/test_popup_keys.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_popup_keys.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +
     1.8 +<window title="Menu ignorekeys Test"
     1.9 +        onkeydown="keyDown()"
    1.10 +        onload="setTimeout(runTests, 0);"
    1.11 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.12 +
    1.13 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
    1.14 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>      
    1.15 +
    1.16 +<!--
    1.17 +  This test checks that the ignorekeys attribute can be used on a menu to
    1.18 +  disable key navigation. The test is performed twice by opening the menu,
    1.19 +  simulating a cursor down key, and closing the popup. When keys are enabled,
    1.20 +  the first item on the menu should be highlighted, otherwise the first item
    1.21 +  should not be highlighted.
    1.22 +  -->
    1.23 +
    1.24 +<menupopup id="popup" onpopupshown="popupShown()" onpopuphidden="popupHidden()">
    1.25 +  <menuitem id="i1" label="One" onDOMAttrModified="attrModified(event)"/>
    1.26 +  <menuitem id="i2" label="Two"/>
    1.27 +  <menuitem id="i3" label="Three"/>
    1.28 +  <menuitem id="i4" label="Four"/>
    1.29 +</menupopup>
    1.30 +
    1.31 +<script class="testbody" type="application/javascript">
    1.32 +<![CDATA[
    1.33 +
    1.34 +SimpleTest.waitForExplicitFinish();
    1.35 +
    1.36 +var gIgnoreKeys = false;
    1.37 +var gIgnoreAttrChange = false;
    1.38 +
    1.39 +function runTests()
    1.40 +{
    1.41 +  var popup = $("popup");
    1.42 +  popup.enableKeyboardNavigator(false);
    1.43 +  is(popup.getAttribute("ignorekeys"), "true", "keys disabled");
    1.44 +  popup.enableKeyboardNavigator(true);
    1.45 +  is(popup.hasAttribute("ignorekeys"), false, "keys enabled");
    1.46 +  popup.openPopup(null, "after_start");
    1.47 +}
    1.48 +
    1.49 +function popupShown()
    1.50 +{
    1.51 +  synthesizeKey("VK_DOWN", { });
    1.52 +  if (gIgnoreKeys) {
    1.53 +    var popup = $("popup");
    1.54 +    setTimeout(function() { popup.hidePopup() }, 1000);
    1.55 +  }
    1.56 +}
    1.57 +
    1.58 +function popupHidden()
    1.59 +{
    1.60 +  if (gIgnoreKeys) {
    1.61 +    SimpleTest.finish();
    1.62 +  }
    1.63 +  else {
    1.64 +    // try the test again with ignorekeys set
    1.65 +    gIgnoreKeys = true;
    1.66 +    var popup = $("popup");
    1.67 +    popup.setAttribute("ignorekeys", "true");
    1.68 +    // clear this first to avoid confusion
    1.69 +    gIgnoreAttrChange = true;
    1.70 +    $("i1").removeAttribute("_moz-menuactive")
    1.71 +    gIgnoreAttrChange = false;
    1.72 +    popup.openPopup(null, "after_start");
    1.73 +  }
    1.74 +}
    1.75 +
    1.76 +function attrModified(event)
    1.77 +{
    1.78 +  if (gIgnoreAttrChange || event.attrName != "_moz-menuactive")
    1.79 +    return;
    1.80 +
    1.81 +  // the attribute should not be changed when ignorekeys is enabled
    1.82 +  if (gIgnoreKeys) {
    1.83 +    ok(false, "move key with keys disabled");
    1.84 +  }
    1.85 +  else {
    1.86 +    is($("i1").getAttribute("_moz-menuactive"), "true", "move key with keys enabled");
    1.87 +    $("popup").hidePopup();
    1.88 +  }
    1.89 +}
    1.90 +
    1.91 +function keyDown()
    1.92 +{
    1.93 +  // when keys are enabled, the menu should have stopped propagation of the
    1.94 +  // event, so a bubbling listener for a keydown event should only occur
    1.95 +  // when keys are disabled.
    1.96 +  ok(gIgnoreKeys, "key listener fired with keys " +
    1.97 +                  (gIgnoreKeys ? "disabled" : "enabled"));
    1.98 +}
    1.99 +
   1.100 +]]>
   1.101 +</script>
   1.102 +
   1.103 +<body xmlns="http://www.w3.org/1999/xhtml">
   1.104 +<p id="display">
   1.105 +</p>
   1.106 +<div id="content" style="display: none">
   1.107 +</div>
   1.108 +<pre id="test">
   1.109 +</pre>
   1.110 +</body>
   1.111 +
   1.112 +</window>

mercurial