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