tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_select_prevent_default.html (3531B)


      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 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 <script type="application/javascript">
     13  /** Test for Bug 291082 */
     14 
     15 
     16  SimpleTest.waitForExplicitFinish();
     17 
     18  function preventDefault(event) {
     19    event.preventDefault();
     20  }
     21 
     22  function runTest() {
     23    document.getElementById("keydown").addEventListener("keydown", preventDefault);
     24    document.getElementById("keypress").addEventListener("keypress", preventDefault);
     25 
     26    SimpleTest.waitForFocus(function() {
     27      if (navigator.platform.indexOf("Mac") == 0) {
     28        todo(false, "Make this test work on OSX");
     29        SimpleTest.finish();
     30        return;
     31      }
     32      var testData = [ "one", "two", "three", "four", "keydown", "keypress" ];
     33 
     34      // The order of the keys in otherKeys is important for the test to function properly.
     35      var otherKeys = [ "DOWN", "UP", "RIGHT", "LEFT", "PAGE_DOWN", "PAGE_UP",
     36                        "END", "HOME" ];
     37 
     38      testData.forEach(function(id) {
     39        var element = document.getElementById(id);
     40        element.focus();
     41        var previousValue = element.value;
     42        sendChar('2');
     43        is(element.value, previousValue, "value should not have changed (id: " + id + ")");
     44        previousValue = element.value;
     45        otherKeys.forEach(function(key) {
     46          sendKey(key);
     47          // All these preventDefault on key down in various ways.
     48          let shouldchange = id != "keydown" && id != "one" && id != "three";
     49          (shouldchange ? isnot : is)(element.value, previousValue, "value should " + (shouldchange ? "" : "not ") + "have changed while testing key " + key + " (id: " + id + ")");
     50          previousValue = element.value;
     51        });
     52      });
     53      SimpleTest.finish();
     54    });
     55  }
     56 </script>
     57 </head>
     58 <body onload="runTest();">
     59 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=291082">Mozilla Bug 291082</a>
     60 <div>
     61  <ul>
     62    <li>
     63    <select id="one" onkeydown="event.preventDefault();">
     64      <option>0</option>
     65      <option>1</option>
     66      <option>2</option>
     67    </select>
     68    select onkeydown="event.preventDefault();"
     69    </li>
     70    <li>
     71    <select id="two" onkeypress="event.preventDefault();">
     72      <option>0</option>
     73      <option>1</option>
     74      <option>2</option>
     75    </select>
     76    select onkeypress="event.preventDefault();"
     77    </li>
     78    <li onkeydown="event.preventDefault();">
     79    <select id="three">
     80      <option>0</option>
     81      <option>1</option>
     82      <option>2</option>
     83    </select>
     84    li onkeydown="event.preventDefault();"
     85    </li>
     86    <li onkeypress="event.preventDefault();">
     87    <select id="four">
     88      <option>0</option>
     89      <option>1</option>
     90      <option>2</option>
     91    </select>
     92    li onkeypress="event.preventDefault();"
     93    </li>
     94    <li>
     95    <select id="keydown">
     96      <option>0</option>
     97      <option>1</option>
     98      <option>2</option>
     99    </select>
    100    select.addEventListener("keydown", function(event) { event.preventDefault(); });
    101    </li>
    102    <li>
    103    <select id="keypress">
    104      <option>0</option>
    105      <option>1</option>
    106      <option>2</option>
    107      <option>9</option>
    108    </select>
    109    select.addEventListener("keypress", function(event) { event.preventDefault(); });
    110    </li>
    111  </ul>
    112 </div>
    113 <pre id="test">
    114 </pre>
    115 </body>
    116 </html>