1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/html/tests/test_keypress_untrusted_event.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=622245 1.8 +--> 1.9 +<head> 1.10 + <title>Test for untrusted keypress events</title> 1.11 + <script type="application/javascript" src="/MochiKit/packed.js"></script> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=622245">Mozilla Bug 622245</a> 1.17 +<p id="display"></p> 1.18 +<div id="content"> 1.19 +<input id="i"><br> 1.20 +<textarea id="t"></textarea><br> 1.21 +<div id="d" contenteditable style="min-height: 1em;"></div> 1.22 +</div> 1.23 +<pre id="test"> 1.24 +<script type="application/javascript"> 1.25 + 1.26 +/** Test for Bug 674770 **/ 1.27 +SimpleTest.waitForExplicitFinish(); 1.28 + 1.29 +var input = document.getElementById("i"); 1.30 +var textarea = document.getElementById("t"); 1.31 +var div = document.getElementById("d"); 1.32 + 1.33 +addLoadEvent(function() { 1.34 + input.focus(); 1.35 + 1.36 + SimpleTest.executeSoon(function() { 1.37 + input.addEventListener("keypress", 1.38 + function(aEvent) { 1.39 + input.removeEventListener("keypress", arguments.callee, false); 1.40 + is(aEvent.target, input, 1.41 + "The keypress event target isn't the input element"); 1.42 + 1.43 + SimpleTest.executeSoon(function() { 1.44 + is(input.value, "", 1.45 + "Did keypress event cause modifying the input element?"); 1.46 + textarea.focus(); 1.47 + SimpleTest.executeSoon(runTextareaTest); 1.48 + }); 1.49 + }, false); 1.50 + var keypress = document.createEvent("KeyboardEvent"); 1.51 + keypress.initKeyEvent("keypress", true, true, document.defaultView, 1.52 + false, false, false, false, 0, "a".charCodeAt(0)); 1.53 + input.dispatchEvent(keypress); 1.54 + }); 1.55 +}); 1.56 + 1.57 +function runTextareaTest() 1.58 +{ 1.59 + textarea.addEventListener("keypress", 1.60 + function(aEvent) { 1.61 + textarea.removeEventListener("keypress", arguments.callee, false); 1.62 + is(aEvent.target, textarea, 1.63 + "The keypress event target isn't the textarea element"); 1.64 + 1.65 + SimpleTest.executeSoon(function() { 1.66 + is(textarea.value, "", 1.67 + "Did keypress event cause modifying the textarea element?"); 1.68 + div.focus(); 1.69 + SimpleTest.executeSoon(runContentediableTest); 1.70 + }); 1.71 + }, false); 1.72 + var keypress = document.createEvent("KeyboardEvent"); 1.73 + keypress.initKeyEvent("keypress", true, true, document.defaultView, 1.74 + false, false, false, false, 0, "b".charCodeAt(0)); 1.75 + textarea.dispatchEvent(keypress); 1.76 +} 1.77 + 1.78 +function runContentediableTest() 1.79 +{ 1.80 + div.addEventListener("keypress", 1.81 + function(aEvent) { 1.82 + div.removeEventListener("keypress", arguments.callee, false); 1.83 + is(aEvent.target, div, 1.84 + "The keypress event target isn't the div element"); 1.85 + 1.86 + SimpleTest.executeSoon(function() { 1.87 + is(div.innerHTML, "", 1.88 + "Did keypress event cause modifying the div element?"); 1.89 + 1.90 + SimpleTest.finish(); 1.91 + }); 1.92 + }, false); 1.93 + var keypress = document.createEvent("KeyboardEvent"); 1.94 + keypress.initKeyEvent("keypress", true, true, document.defaultView, 1.95 + false, false, false, false, 0, "c".charCodeAt(0)); 1.96 + div.dispatchEvent(keypress); 1.97 +} 1.98 + 1.99 +</script> 1.100 +</pre> 1.101 +</body> 1.102 +</html>