layout/forms/test/test_bug411236.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:96c50e362201
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=411236
5 -->
6 <head>
7 <title>Test for Bug 411236</title>
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
10 </head>
11 <body>
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=411236">Mozilla Bug 411236</a>
13 <p id="display"></p>
14 <div id="content">
15 <input type="file" onfocus="window.oTarget = event.originalTarget;"
16 onclick="window.fileInputGotClick = true; return false;"
17 id="fileinput">
18 </div>
19 <pre id="test">
20 <script class="testbody" type="text/javascript">
21
22 /** Test for Bug 411236 **/
23
24 window.oTarget = null;
25 window.fileInputGotClick = false;
26
27 function tab() {
28 var utils = SpecialPowers.DOMWindowUtils;
29 // Send tab key events.
30 var key = SpecialPowers.Ci.nsIDOMKeyEvent.DOM_VK_TAB;
31 utils.sendKeyEvent("keydown", key, 0, 0);
32 utils.sendKeyEvent("keypress", key, 0, 0);
33 utils.sendKeyEvent("keyup", key, 0, 0);
34 }
35
36 function test() {
37 // Try to find the 'Browse...' using tabbing.
38 var i = 0;
39 while (!window.oTarget && i < 100) {
40 ++i;
41 tab();
42 }
43
44 if (i >= 100) {
45 ok(false, "Couldn't find an input element!");
46 SimpleTest.finish();
47 return;
48 }
49
50 ok(window.oTarget instanceof HTMLButtonElement, "Should have focused an input element!")
51 ok(SpecialPowers.wrap(window.oTarget).type == "button", "Should have focused 'Browse...' button!");
52 var e = document.createEvent("mouseevents");
53 e.initMouseEvent("click", true, true, window, 0, 1, 1, 1, 1,
54 false, false, false, false, 0, null);
55 SpecialPowers.wrap(window.oTarget).dispatchEvent(e);
56 ok(window.fileInputGotClick,
57 "File input should have got a click event, but not open the file dialog.");
58 SimpleTest.finish();
59 }
60
61 function beginTest() {
62 // accessibility.tabfocus must be set to value 7 before running test also
63 // on a mac.
64 SpecialPowers.pushPrefEnv({"set": [["accessibility.tabfocus", 7]]}, do_test);
65 }
66
67 function do_test() {
68 window.focus();
69 document.getElementById('fileinput').focus();
70 setTimeout(test, 100);
71 }
72
73 SimpleTest.waitForExplicitFinish();
74 addLoadEvent(beginTest);
75
76 </script>
77 </pre>
78 </body>
79 </html>

mercurial