layout/forms/test/test_bug348236.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/forms/test/test_bug348236.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,125 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=348236
     1.8 +-->
     1.9 +<head>
    1.10 +
    1.11 +  <title>Test for Bug 348236</title>
    1.12 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.14 +  <style type="text/css">
    1.15 +  #eSelect {
    1.16 +    position: fixed; top:0; left: 350px; font-size: 24px; width: 100px
    1.17 +  }
    1.18 +  #eSelect option {
    1.19 +    margin: 0; padding: 0; height: 24px
    1.20 +  }
    1.21 +  </style>
    1.22 +</head>
    1.23 +<body>
    1.24 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=348236">Mozilla Bug 348236</a>
    1.25 +<p id="display"></p>
    1.26 +<div id="content">
    1.27 +
    1.28 +  <select id="eSelect" size="1" onchange="++this.onchangeCount">
    1.29 +    <option selected>1</option>
    1.30 +    <option>2</option>
    1.31 +    <option>3</option>
    1.32 +  </select>
    1.33 +</div>
    1.34 +<pre id="test">
    1.35 +<script type="text/javascript">
    1.36 +
    1.37 +  /** Test for Bug 348236 **/
    1.38 +
    1.39 +SimpleTest.waitForExplicitFinish()
    1.40 +addLoadEvent(function test() {
    1.41 +
    1.42 +    var
    1.43 +        CI = SpecialPowers.Components.interfaces,
    1.44 +        WinUtils = SpecialPowers.getDOMWindowUtils(window),
    1.45 +        sec = netscape.security,
    1.46 +        eSelect = $("eSelect"),
    1.47 +        IDOMEvent = CI.nsIDOMEvent,
    1.48 +        IDOMKeyEvent = CI.nsIDOMKeyEvent,
    1.49 +        timeout = 0 // Choose a larger value like 500 ms if you want to see what's happening.
    1.50 +
    1.51 +    function keypressOnSelect(key, modifiers) {
    1.52 +        WinUtils.focus(eSelect)
    1.53 +        WinUtils.sendKeyEvent("keyup", key, 0, modifiers)
    1.54 +        WinUtils.sendKeyEvent("keypress", key, 0, modifiers)
    1.55 +        WinUtils.sendKeyEvent("keydown", key, 0, modifiers)
    1.56 +    }
    1.57 +
    1.58 +    function testKey(key, modifiers, keyString, functionToContinue) {
    1.59 +        var selectGotClick
    1.60 +        function clickListener() { selectGotClick = true }
    1.61 +        eSelect.selectedIndex = 0
    1.62 +        eSelect.onchangeCount = 0
    1.63 +
    1.64 +        // Drop the SELECT down.
    1.65 +        keypressOnSelect(key, modifiers)
    1.66 +        // This timeout and the following are necessary to let the sent events take effect.
    1.67 +        setTimeout(cont1, timeout)
    1.68 +        function cont1() {
    1.69 +            // Move the mouse over option 3 (90 = 3 (rows) * 24 (row height) + 18).
    1.70 +            WinUtils.sendMouseEvent("mousemove", 355, 90, 0, 0, 0, true)
    1.71 +            setTimeout(cont2, timeout)
    1.72 +        }
    1.73 +        function cont2() {
    1.74 +            // Close the select.
    1.75 +            keypressOnSelect(key, modifiers)
    1.76 +            setTimeout(cont3, timeout)
    1.77 +        }
    1.78 +        function cont3() {
    1.79 +            is(eSelect.value, "3", "Select's value should be 3 after hovering over option 3 and pressing " + keyString + ".")
    1.80 +            is(eSelect.onchangeCount, 1, "Onchange should have fired once.")
    1.81 +
    1.82 +            // Simulate click on area to the left of the select.
    1.83 +            eSelect.addEventListener("click", clickListener, true)
    1.84 +            selectGotClick = false
    1.85 +            WinUtils.sendMouseEvent("mousedown", 320, 0, 0, 0, 0, true)
    1.86 +            WinUtils.sendMouseEvent("mouseup", 320, 0, 0, 0, 0, true)
    1.87 +            setTimeout(cont4, timeout)
    1.88 +        }
    1.89 +        function cont4() {
    1.90 +            eSelect.removeEventListener("click", clickListener, true)
    1.91 +            ok(!selectGotClick, "SELECT must not capture mouse events after closing it with " + keyString + ".")
    1.92 +            functionToContinue()
    1.93 +        }
    1.94 +    }
    1.95 +
    1.96 +
    1.97 +    // Quick sanity checks.
    1.98 +    is(eSelect.value, "1", "SELECT value should be 1 after load.")
    1.99 +    is(eSelect.selectedIndex, 0, "SELECT selectedIndex should be 0 after load.")
   1.100 +
   1.101 +    // Check if sending key events works.
   1.102 +    keypressOnSelect(IDOMKeyEvent.DOM_VK_DOWN, 0)
   1.103 +    is(eSelect.value, "2", "SELECT value should be 2 after pressing Down.")
   1.104 +      
   1.105 +    // Test ALT-Down.
   1.106 +    testKey(IDOMKeyEvent.DOM_VK_DOWN, IDOMEvent.ALT_MASK, "ALT-Down", nextKey1)
   1.107 +    function nextKey1() {
   1.108 +        // Test ALT-Up.
   1.109 +        testKey(IDOMKeyEvent.DOM_VK_UP, IDOMEvent.ALT_MASK, "ALT-Up", nextKey2)
   1.110 +    }
   1.111 +    function nextKey2() {
   1.112 +        // Test the F4 key on OS/2 and Windows.
   1.113 +        if (/OS\/2|Win/i.test(navigator.platform))
   1.114 +            testKey(IDOMKeyEvent.DOM_VK_F4, 0, "F4", finished)
   1.115 +        else
   1.116 +            finished()
   1.117 +    }
   1.118 +    function finished() {
   1.119 +    // Reset value to get the expected value if we reload the page.
   1.120 +        eSelect.selectedIndex = 0
   1.121 +        SimpleTest.finish()
   1.122 +    }
   1.123 +})
   1.124 +
   1.125 +</script>
   1.126 +</pre>
   1.127 +</body>
   1.128 +</html>

mercurial