layout/forms/test/test_select_prevent_default.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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

mercurial