summaryrefslogtreecommitdiffstats
path: root/dom/events/test/test_focus_disabled.html
blob: 52748226aaaadf47078abc6b6bd6ce8d6f95ca9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=375008
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 375008</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=375008">Mozilla Bug 375008</a>
<p id="display"></p>
<div id="content">
  <div id='not-focusable'>
    <!-- Disabled elements -->
    <button hidden disabled>foo</button>
    <input hidden disabled>
    <fieldset hidden disabled>foo</fieldset>
    <select hidden disabled><option>foo</option></select>
    <textarea hidden disabled></textarea>
    <optgroup hidden disabled><option>foo</option></optgroup>
    <option hidden disabled>foo</option>
  </div>

  <div id='focusable'>
    <button hidden>foo</button>
    <input hidden>
    <select hidden><option>foo</option></select>
    <textarea hidden></textarea>

    <!-- Those elements are not focusable by default. -->
    <fieldset tabindex=1 hidden>foo</fieldset>
    <optgroup tabindex=1 hidden><option>foo</option></optgroup>
    <option tabindex=1 hidden>foo</option>
  </div>

  <!-- Hidden elements, they have a frame but focus will go through them. -->
  <div id='hidden' style='visibility: hidden;'>
    <button hidden>foo</button>
    <input hidden>
    <fieldset hidden>foo</fieldset>
    <select hidden><option>foo</option></select>
    <textarea hidden></textarea>
    <optgroup hidden><option>foo</option></optgroup>
    <option hidden>foo</option>
  </div>

  <div>
    <input id='witness'>
  </div>

</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 375008 **/

/*
 * This test is divided in three parts:
 * - cases where focus isn't doable but blur should not happen;
 * - cases where focus is doable;
 * - cases where focus isn't doable but blur should still happen.
 */

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
  // On Mac, this preference needs to be turned on to be able to focus all the
  // form controls we want to focus.
  SpecialPowers.pushPrefEnv({"set": [[ "accessibility.mouse_focuses_formcontrol", true ]]},
                            runTest);
});

function runTest()
{
  var witness = document.getElementById('witness');
  witness.focus();

  var notFocusableElements = document.getElementById('not-focusable').children;
  for (var i=0; i<notFocusableElements.length; ++i) {
    var element = notFocusableElements[i];
    element.hidden = false;
    synthesizeMouseAtCenter(element, {});
    is(document.activeElement, witness,
       "[" + element.tagName + "] witness should still be focused");

    // Cleanup.
    element.hidden = true;
    witness.focus();
  }

  var focusableElements = document.getElementById('focusable').children;
  for (var i=0; i<focusableElements.length; ++i) {
    var element = focusableElements[i];
    element.hidden = false;
    synthesizeMouseAtCenter(element, {});
    is(document.activeElement, element, "focus should have moved to " + element);

    // Cleanup.
    element.hidden = true;
    witness.focus();
  }

  var hiddenElements = document.getElementById('hidden').children;
  for (var i=0; i<hiddenElements.length; ++i) {
    var element = hiddenElements[i];
    element.hidden = false;
    synthesizeMouseAtCenter(element, {});
    is(document.activeElement, document.body,
       "focus should have moved to the body");

    // Cleanup.
    element.hidden = true;
    witness.focus();
  }

  SimpleTest.finish();
}

</script>
</pre>
</body>
</html>