1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/forms/test/test_select_prevent_default.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=291082 1.8 +--> 1.9 +<head> 1.10 +<meta charset="utf-8"> 1.11 +<title>Test for Bug 291082</title> 1.12 +<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 +<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.14 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.15 +<script type="application/javascript"> 1.16 + /** Test for Bug 291082 **/ 1.17 + 1.18 + 1.19 + // Turn off Spatial Navigation because it hijacks arrow keydown events. 1.20 + SpecialPowers.setBoolPref("snav.enabled", false); 1.21 + 1.22 + SimpleTest.waitForExplicitFinish(); 1.23 + 1.24 + function preventDefault(event) { 1.25 + event.preventDefault(); 1.26 + } 1.27 + 1.28 + function test() { 1.29 + document.getElementById("keydown").addEventListener("keydown", preventDefault); 1.30 + document.getElementById("keypress").addEventListener("keypress", preventDefault); 1.31 + 1.32 + SimpleTest.waitForFocus(function() { 1.33 + var testData = [ "one", "two", "three", "four", "keydown", "keypress" ]; 1.34 + 1.35 + // The order of the keys in otherKeys is important for the test to function properly. 1.36 + var otherKeys = [ "DOWN", "UP", "RIGHT", "LEFT", "PAGE_DOWN", "PAGE_UP", 1.37 + "END", "HOME" ]; 1.38 + 1.39 + testData.forEach(function(id) { 1.40 + var element = document.getElementById(id); 1.41 + element.focus(); 1.42 + var previousValue = element.value; 1.43 + sendChar('2'); 1.44 + is(element.value, previousValue, "value should not have changed (id: " + id + ")"); 1.45 + previousValue = element.value; 1.46 + otherKeys.forEach(function(key) { 1.47 + sendKey(key); 1.48 + isnot(element.value, previousValue, "value should have changed while testing key " + key + " (id: " + id + ")"); 1.49 + previousValue = element.value; 1.50 + }); 1.51 + }); 1.52 + SimpleTest.finish(); 1.53 + }); 1.54 + } 1.55 +</script> 1.56 +</head> 1.57 +<body onload="test();"> 1.58 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=291082">Mozilla Bug 291082</a> 1.59 +<div> 1.60 + <ul> 1.61 + <li> 1.62 + <select id="one" onkeydown="event.preventDefault();"> 1.63 + <option>0</option> 1.64 + <option>1</option> 1.65 + <option>2</option> 1.66 + </select> 1.67 + select onkeydown="event.preventDefault();" 1.68 + </li> 1.69 + <li> 1.70 + <select id="two" onkeypress="event.preventDefault();"> 1.71 + <option>0</option> 1.72 + <option>1</option> 1.73 + <option>2</option> 1.74 + </select> 1.75 + select onkeypress="event.preventDefault();" 1.76 + </li> 1.77 + <li onkeydown="event.preventDefault();"> 1.78 + <select id="three"> 1.79 + <option>0</option> 1.80 + <option>1</option> 1.81 + <option>2</option> 1.82 + </select> 1.83 + li onkeydown="event.preventDefault();" 1.84 + </li> 1.85 + <li onkeypress="event.preventDefault();"> 1.86 + <select id="four"> 1.87 + <option>0</option> 1.88 + <option>1</option> 1.89 + <option>2</option> 1.90 + </select> 1.91 + li onkeypress="event.preventDefault();" 1.92 + </li> 1.93 + <li> 1.94 + <select id="keydown"> 1.95 + <option>0</option> 1.96 + <option>1</option> 1.97 + <option>2</option> 1.98 + </select> 1.99 + select.addEventListener("keydown", function(event) { event.preventDefault(); }); 1.100 + </li> 1.101 + <li> 1.102 + <select id="keypress"> 1.103 + <option>0</option> 1.104 + <option>1</option> 1.105 + <option>2</option> 1.106 + <option>9</option> 1.107 + </select> 1.108 + select.addEventListener("keypress", function(event) { event.preventDefault(); }); 1.109 + </li> 1.110 + </ul> 1.111 +</div> 1.112 +<pre id="test"> 1.113 +</pre> 1.114 +</body> 1.115 +</html>