dom/events/test/test_focus_disabled.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_focus_disabled.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,125 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=375008
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 375008</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.15 +</head>
    1.16 +<body>
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=375008">Mozilla Bug 375008</a>
    1.18 +<p id="display"></p>
    1.19 +<div id="content">
    1.20 +  <div>
    1.21 +    <input id='witness'>
    1.22 +  </div>
    1.23 +
    1.24 +  <div id='not-focusable'>
    1.25 +    <!-- Disabled elements -->
    1.26 +    <button hidden disabled>foo</button>
    1.27 +    <input hidden disabled>
    1.28 +    <fieldset hidden disabled>foo</fieldset>
    1.29 +    <select hidden disabled><option>foo</option></select>
    1.30 +    <textarea hidden disabled></textarea>
    1.31 +    <optgroup hidden disabled><option>foo</option></optgroup>
    1.32 +    <option hidden disabled>foo</option>
    1.33 +  </div>
    1.34 +
    1.35 +  <div id='focusable'>
    1.36 +    <button hidden>foo</button>
    1.37 +    <input hidden>
    1.38 +    <select hidden><option>foo</option></select>
    1.39 +    <textarea hidden></textarea>
    1.40 +
    1.41 +    <!-- Those elements are not focusable by default. -->
    1.42 +    <fieldset tabindex=1 hidden>foo</fieldset>
    1.43 +    <optgroup tabindex=1 hidden><option>foo</option></optgroup>
    1.44 +    <option tabindex=1 hidden>foo</option>
    1.45 +  </div>
    1.46 +
    1.47 +  <!-- Hidden elements, they have a frame but focus will go through them. -->
    1.48 +  <div id='hidden' style='visibility: hidden;'>
    1.49 +    <button hidden>foo</button>
    1.50 +    <input hidden>
    1.51 +    <fieldset hidden>foo</fieldset>
    1.52 +    <select hidden><option>foo</option></select>
    1.53 +    <textarea hidden></textarea>
    1.54 +    <optgroup hidden><option>foo</option></optgroup>
    1.55 +    <option hidden>foo</option>
    1.56 +  </div>
    1.57 +
    1.58 +</div>
    1.59 +<pre id="test">
    1.60 +<script type="application/javascript">
    1.61 +
    1.62 +/** Test for Bug 375008 **/
    1.63 +
    1.64 +/*
    1.65 + * This test is divided in three parts:
    1.66 + * - cases where focus isn't doable but blur should not happen;
    1.67 + * - cases where focus is doable;
    1.68 + * - cases where focus isn't doable but blur should still happen.
    1.69 + */
    1.70 +
    1.71 +SimpleTest.waitForExplicitFinish();
    1.72 +SimpleTest.waitForFocus(function() {
    1.73 +  // On Mac, this preference needs to be turned on to be able to focus all the
    1.74 +  // form controls we want to focus.
    1.75 +  SpecialPowers.pushPrefEnv({"set": [[ "accessibility.mouse_focuses_formcontrol", true ]]},
    1.76 +                            runTest);
    1.77 +});
    1.78 +
    1.79 +function runTest()
    1.80 +{
    1.81 +  var witness = document.getElementById('witness');
    1.82 +  witness.focus();
    1.83 +
    1.84 +  var notFocusableElements = document.getElementById('not-focusable').children;
    1.85 +  for (var i=0; i<notFocusableElements.length; ++i) {
    1.86 +    var element = notFocusableElements[i];
    1.87 +    element.hidden = false;
    1.88 +    synthesizeMouseAtCenter(element, {});
    1.89 +    is(document.activeElement, witness,
    1.90 +       "[" + element.tagName + "] witness should still be focused");
    1.91 +
    1.92 +    // Cleanup.
    1.93 +    element.hidden = true;
    1.94 +    witness.focus();
    1.95 +  }
    1.96 +
    1.97 +  var focusableElements = document.getElementById('focusable').children;
    1.98 +  for (var i=0; i<focusableElements.length; ++i) {
    1.99 +    var element = focusableElements[i];
   1.100 +    element.hidden = false;
   1.101 +    synthesizeMouseAtCenter(element, {});
   1.102 +    is(document.activeElement, element, "focus should have moved to " + element);
   1.103 +
   1.104 +    // Cleanup.
   1.105 +    element.hidden = true;
   1.106 +    witness.focus();
   1.107 +  }
   1.108 +
   1.109 +  var hiddenElements = document.getElementById('hidden').children;
   1.110 +  for (var i=0; i<hiddenElements.length; ++i) {
   1.111 +    var element = hiddenElements[i];
   1.112 +    element.hidden = false;
   1.113 +    synthesizeMouseAtCenter(element, {});
   1.114 +    is(document.activeElement, document.body,
   1.115 +       "focus should have moved to the body");
   1.116 +
   1.117 +    // Cleanup.
   1.118 +    element.hidden = true;
   1.119 +    witness.focus();
   1.120 +  }
   1.121 +
   1.122 +  SimpleTest.finish();
   1.123 +}
   1.124 +
   1.125 +</script>
   1.126 +</pre>
   1.127 +</body>
   1.128 +</html>

mercurial