|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=375008 |
|
5 --> |
|
6 <head> |
|
7 <meta charset="utf-8"> |
|
8 <title>Test for Bug 375008</title> |
|
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
12 </head> |
|
13 <body> |
|
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=375008">Mozilla Bug 375008</a> |
|
15 <p id="display"></p> |
|
16 <div id="content"> |
|
17 <div> |
|
18 <input id='witness'> |
|
19 </div> |
|
20 |
|
21 <div id='not-focusable'> |
|
22 <!-- Disabled elements --> |
|
23 <button hidden disabled>foo</button> |
|
24 <input hidden disabled> |
|
25 <fieldset hidden disabled>foo</fieldset> |
|
26 <select hidden disabled><option>foo</option></select> |
|
27 <textarea hidden disabled></textarea> |
|
28 <optgroup hidden disabled><option>foo</option></optgroup> |
|
29 <option hidden disabled>foo</option> |
|
30 </div> |
|
31 |
|
32 <div id='focusable'> |
|
33 <button hidden>foo</button> |
|
34 <input hidden> |
|
35 <select hidden><option>foo</option></select> |
|
36 <textarea hidden></textarea> |
|
37 |
|
38 <!-- Those elements are not focusable by default. --> |
|
39 <fieldset tabindex=1 hidden>foo</fieldset> |
|
40 <optgroup tabindex=1 hidden><option>foo</option></optgroup> |
|
41 <option tabindex=1 hidden>foo</option> |
|
42 </div> |
|
43 |
|
44 <!-- Hidden elements, they have a frame but focus will go through them. --> |
|
45 <div id='hidden' style='visibility: hidden;'> |
|
46 <button hidden>foo</button> |
|
47 <input hidden> |
|
48 <fieldset hidden>foo</fieldset> |
|
49 <select hidden><option>foo</option></select> |
|
50 <textarea hidden></textarea> |
|
51 <optgroup hidden><option>foo</option></optgroup> |
|
52 <option hidden>foo</option> |
|
53 </div> |
|
54 |
|
55 </div> |
|
56 <pre id="test"> |
|
57 <script type="application/javascript"> |
|
58 |
|
59 /** Test for Bug 375008 **/ |
|
60 |
|
61 /* |
|
62 * This test is divided in three parts: |
|
63 * - cases where focus isn't doable but blur should not happen; |
|
64 * - cases where focus is doable; |
|
65 * - cases where focus isn't doable but blur should still happen. |
|
66 */ |
|
67 |
|
68 SimpleTest.waitForExplicitFinish(); |
|
69 SimpleTest.waitForFocus(function() { |
|
70 // On Mac, this preference needs to be turned on to be able to focus all the |
|
71 // form controls we want to focus. |
|
72 SpecialPowers.pushPrefEnv({"set": [[ "accessibility.mouse_focuses_formcontrol", true ]]}, |
|
73 runTest); |
|
74 }); |
|
75 |
|
76 function runTest() |
|
77 { |
|
78 var witness = document.getElementById('witness'); |
|
79 witness.focus(); |
|
80 |
|
81 var notFocusableElements = document.getElementById('not-focusable').children; |
|
82 for (var i=0; i<notFocusableElements.length; ++i) { |
|
83 var element = notFocusableElements[i]; |
|
84 element.hidden = false; |
|
85 synthesizeMouseAtCenter(element, {}); |
|
86 is(document.activeElement, witness, |
|
87 "[" + element.tagName + "] witness should still be focused"); |
|
88 |
|
89 // Cleanup. |
|
90 element.hidden = true; |
|
91 witness.focus(); |
|
92 } |
|
93 |
|
94 var focusableElements = document.getElementById('focusable').children; |
|
95 for (var i=0; i<focusableElements.length; ++i) { |
|
96 var element = focusableElements[i]; |
|
97 element.hidden = false; |
|
98 synthesizeMouseAtCenter(element, {}); |
|
99 is(document.activeElement, element, "focus should have moved to " + element); |
|
100 |
|
101 // Cleanup. |
|
102 element.hidden = true; |
|
103 witness.focus(); |
|
104 } |
|
105 |
|
106 var hiddenElements = document.getElementById('hidden').children; |
|
107 for (var i=0; i<hiddenElements.length; ++i) { |
|
108 var element = hiddenElements[i]; |
|
109 element.hidden = false; |
|
110 synthesizeMouseAtCenter(element, {}); |
|
111 is(document.activeElement, document.body, |
|
112 "focus should have moved to the body"); |
|
113 |
|
114 // Cleanup. |
|
115 element.hidden = true; |
|
116 witness.focus(); |
|
117 } |
|
118 |
|
119 SimpleTest.finish(); |
|
120 } |
|
121 |
|
122 </script> |
|
123 </pre> |
|
124 </body> |
|
125 </html> |