test_keypress_untrusted_event.html (2859B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=622245 5 --> 6 <head> 7 <title>Test for untrusted keypress events</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=622245">Mozilla Bug 622245</a> 13 <p id="display"></p> 14 <div id="content"> 15 <input id="i"><br> 16 <textarea id="t"></textarea><br> 17 <div id="d" contenteditable style="min-height: 1em;"></div> 18 </div> 19 <pre id="test"> 20 <script type="application/javascript"> 21 22 /** Test for Bug 674770 */ 23 SimpleTest.waitForExplicitFinish(); 24 25 var input = document.getElementById("i"); 26 var textarea = document.getElementById("t"); 27 var div = document.getElementById("d"); 28 29 addLoadEvent(function() { 30 input.focus(); 31 32 SimpleTest.executeSoon(function() { 33 input.addEventListener("keypress", 34 function(aEvent) { 35 is(aEvent.target, input, 36 "The keypress event target isn't the input element"); 37 38 SimpleTest.executeSoon(function() { 39 is(input.value, "", 40 "Did keypress event cause modifying the input element?"); 41 textarea.focus(); 42 SimpleTest.executeSoon(runTextareaTest); 43 }); 44 }, {once: true}); 45 var keypress = new KeyboardEvent("keypress", { 46 bubbles: true, 47 cancelable: true, 48 view: document.defaultView, 49 keyCode: 0, 50 charCode:"a".charCodeAt(0), 51 }); 52 input.dispatchEvent(keypress); 53 }); 54 }); 55 56 function runTextareaTest() { 57 textarea.addEventListener("keypress", 58 function(aEvent) { 59 is(aEvent.target, textarea, 60 "The keypress event target isn't the textarea element"); 61 62 SimpleTest.executeSoon(function() { 63 is(textarea.value, "", 64 "Did keypress event cause modifying the textarea element?"); 65 div.focus(); 66 SimpleTest.executeSoon(runContentediableTest); 67 }); 68 }, {once: true}); 69 var keypress = new KeyboardEvent("keypress", { 70 bubbles: true, 71 cancelable: true, 72 view: document.defaultView, 73 keyCode: 0, 74 charCode:"b".charCodeAt(0), 75 }); 76 textarea.dispatchEvent(keypress); 77 } 78 79 function runContentediableTest() { 80 div.addEventListener("keypress", 81 function(aEvent) { 82 is(aEvent.target, div, 83 "The keypress event target isn't the div element"); 84 85 SimpleTest.executeSoon(function() { 86 is(div.innerHTML, "", 87 "Did keypress event cause modifying the div element?"); 88 89 SimpleTest.finish(); 90 }); 91 }, {once: true}); 92 var keypress = new KeyboardEvent("keypress", { 93 bubbles: true, 94 cancelable: true, 95 view: document.defaultView, 96 keyCode: 0, 97 charCode:"c".charCodeAt(0), 98 }); 99 div.dispatchEvent(keypress); 100 } 101 102 </script> 103 </pre> 104 </body> 105 </html>