layout/forms/test/test_select_prevent_default.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=291082
     5 -->
     6 <head>
     7 <meta charset="utf-8">
     8 <title>Test for Bug 291082</title>
     9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    12 <script type="application/javascript">
    13   /** Test for Bug 291082 **/
    16   // Turn off Spatial Navigation because it hijacks arrow keydown events.
    17   SpecialPowers.setBoolPref("snav.enabled", false);
    19   SimpleTest.waitForExplicitFinish();
    21   function preventDefault(event) {
    22     event.preventDefault();
    23   }
    25   function test() {
    26     document.getElementById("keydown").addEventListener("keydown", preventDefault);
    27     document.getElementById("keypress").addEventListener("keypress", preventDefault);
    29     SimpleTest.waitForFocus(function() {
    30       var testData = [ "one", "two", "three", "four", "keydown", "keypress" ];
    32       // The order of the keys in otherKeys is important for the test to function properly.
    33       var otherKeys = [ "DOWN", "UP", "RIGHT", "LEFT", "PAGE_DOWN", "PAGE_UP",
    34                         "END", "HOME" ];
    36       testData.forEach(function(id) {
    37         var element = document.getElementById(id);
    38         element.focus();
    39         var previousValue = element.value;
    40         sendChar('2');
    41         is(element.value, previousValue, "value should not have changed (id: " + id + ")");
    42         previousValue = element.value;
    43         otherKeys.forEach(function(key) {
    44           sendKey(key);
    45           isnot(element.value, previousValue, "value should have changed while testing key " + key + " (id: " + id + ")");
    46           previousValue = element.value;
    47           });
    48         });
    49       SimpleTest.finish();
    50     });
    51   }
    52 </script>
    53 </head>
    54 <body onload="test();">
    55 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=291082">Mozilla Bug 291082</a>
    56 <div>
    57   <ul>
    58     <li>
    59     <select id="one" onkeydown="event.preventDefault();">
    60       <option>0</option>
    61       <option>1</option>
    62       <option>2</option>
    63     </select>
    64     select onkeydown="event.preventDefault();"
    65     </li>
    66     <li>
    67     <select id="two" onkeypress="event.preventDefault();">
    68       <option>0</option>
    69       <option>1</option>
    70       <option>2</option>
    71     </select>
    72     select onkeypress="event.preventDefault();"
    73     </li>
    74     <li onkeydown="event.preventDefault();">
    75     <select id="three">
    76       <option>0</option>
    77       <option>1</option>
    78       <option>2</option>
    79     </select>
    80     li onkeydown="event.preventDefault();"
    81     </li>
    82     <li onkeypress="event.preventDefault();">
    83     <select id="four">
    84       <option>0</option>
    85       <option>1</option>
    86       <option>2</option>
    87     </select>
    88     li onkeypress="event.preventDefault();"
    89     </li>
    90     <li>
    91     <select id="keydown">
    92       <option>0</option>
    93       <option>1</option>
    94       <option>2</option>
    95     </select>
    96     select.addEventListener("keydown", function(event) { event.preventDefault(); });
    97     </li>
    98     <li>
    99     <select id="keypress">
   100       <option>0</option>
   101       <option>1</option>
   102       <option>2</option>
   103       <option>9</option>
   104     </select>
   105     select.addEventListener("keypress", function(event) { event.preventDefault(); });
   106     </li>
   107   </ul>
   108 </div>
   109 <pre id="test">
   110 </pre>
   111 </body>
   112 </html>

mercurial