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