Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=348236
5 -->
6 <head>
8 <title>Test for Bug 348236</title>
9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
11 <style type="text/css">
12 #eSelect {
13 position: fixed; top:0; left: 350px; font-size: 24px; width: 100px
14 }
15 #eSelect option {
16 margin: 0; padding: 0; height: 24px
17 }
18 </style>
19 </head>
20 <body>
21 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=348236">Mozilla Bug 348236</a>
22 <p id="display"></p>
23 <div id="content">
25 <select id="eSelect" size="1" onchange="++this.onchangeCount">
26 <option selected>1</option>
27 <option>2</option>
28 <option>3</option>
29 </select>
30 </div>
31 <pre id="test">
32 <script type="text/javascript">
34 /** Test for Bug 348236 **/
36 SimpleTest.waitForExplicitFinish()
37 addLoadEvent(function test() {
39 var
40 CI = SpecialPowers.Components.interfaces,
41 WinUtils = SpecialPowers.getDOMWindowUtils(window),
42 sec = netscape.security,
43 eSelect = $("eSelect"),
44 IDOMEvent = CI.nsIDOMEvent,
45 IDOMKeyEvent = CI.nsIDOMKeyEvent,
46 timeout = 0 // Choose a larger value like 500 ms if you want to see what's happening.
48 function keypressOnSelect(key, modifiers) {
49 WinUtils.focus(eSelect)
50 WinUtils.sendKeyEvent("keyup", key, 0, modifiers)
51 WinUtils.sendKeyEvent("keypress", key, 0, modifiers)
52 WinUtils.sendKeyEvent("keydown", key, 0, modifiers)
53 }
55 function testKey(key, modifiers, keyString, functionToContinue) {
56 var selectGotClick
57 function clickListener() { selectGotClick = true }
58 eSelect.selectedIndex = 0
59 eSelect.onchangeCount = 0
61 // Drop the SELECT down.
62 keypressOnSelect(key, modifiers)
63 // This timeout and the following are necessary to let the sent events take effect.
64 setTimeout(cont1, timeout)
65 function cont1() {
66 // Move the mouse over option 3 (90 = 3 (rows) * 24 (row height) + 18).
67 WinUtils.sendMouseEvent("mousemove", 355, 90, 0, 0, 0, true)
68 setTimeout(cont2, timeout)
69 }
70 function cont2() {
71 // Close the select.
72 keypressOnSelect(key, modifiers)
73 setTimeout(cont3, timeout)
74 }
75 function cont3() {
76 is(eSelect.value, "3", "Select's value should be 3 after hovering over option 3 and pressing " + keyString + ".")
77 is(eSelect.onchangeCount, 1, "Onchange should have fired once.")
79 // Simulate click on area to the left of the select.
80 eSelect.addEventListener("click", clickListener, true)
81 selectGotClick = false
82 WinUtils.sendMouseEvent("mousedown", 320, 0, 0, 0, 0, true)
83 WinUtils.sendMouseEvent("mouseup", 320, 0, 0, 0, 0, true)
84 setTimeout(cont4, timeout)
85 }
86 function cont4() {
87 eSelect.removeEventListener("click", clickListener, true)
88 ok(!selectGotClick, "SELECT must not capture mouse events after closing it with " + keyString + ".")
89 functionToContinue()
90 }
91 }
94 // Quick sanity checks.
95 is(eSelect.value, "1", "SELECT value should be 1 after load.")
96 is(eSelect.selectedIndex, 0, "SELECT selectedIndex should be 0 after load.")
98 // Check if sending key events works.
99 keypressOnSelect(IDOMKeyEvent.DOM_VK_DOWN, 0)
100 is(eSelect.value, "2", "SELECT value should be 2 after pressing Down.")
102 // Test ALT-Down.
103 testKey(IDOMKeyEvent.DOM_VK_DOWN, IDOMEvent.ALT_MASK, "ALT-Down", nextKey1)
104 function nextKey1() {
105 // Test ALT-Up.
106 testKey(IDOMKeyEvent.DOM_VK_UP, IDOMEvent.ALT_MASK, "ALT-Up", nextKey2)
107 }
108 function nextKey2() {
109 // Test the F4 key on OS/2 and Windows.
110 if (/OS\/2|Win/i.test(navigator.platform))
111 testKey(IDOMKeyEvent.DOM_VK_F4, 0, "F4", finished)
112 else
113 finished()
114 }
115 function finished() {
116 // Reset value to get the expected value if we reload the page.
117 eSelect.selectedIndex = 0
118 SimpleTest.finish()
119 }
120 })
122 </script>
123 </pre>
124 </body>
125 </html>