|
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 type="application/javascript" src="/MochiKit/packed.js"></script> |
|
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=622245">Mozilla Bug 622245</a> |
|
14 <p id="display"></p> |
|
15 <div id="content"> |
|
16 <input id="i"><br> |
|
17 <textarea id="t"></textarea><br> |
|
18 <div id="d" contenteditable style="min-height: 1em;"></div> |
|
19 </div> |
|
20 <pre id="test"> |
|
21 <script type="application/javascript"> |
|
22 |
|
23 /** Test for Bug 674770 **/ |
|
24 SimpleTest.waitForExplicitFinish(); |
|
25 |
|
26 var input = document.getElementById("i"); |
|
27 var textarea = document.getElementById("t"); |
|
28 var div = document.getElementById("d"); |
|
29 |
|
30 addLoadEvent(function() { |
|
31 input.focus(); |
|
32 |
|
33 SimpleTest.executeSoon(function() { |
|
34 input.addEventListener("keypress", |
|
35 function(aEvent) { |
|
36 input.removeEventListener("keypress", arguments.callee, false); |
|
37 is(aEvent.target, input, |
|
38 "The keypress event target isn't the input element"); |
|
39 |
|
40 SimpleTest.executeSoon(function() { |
|
41 is(input.value, "", |
|
42 "Did keypress event cause modifying the input element?"); |
|
43 textarea.focus(); |
|
44 SimpleTest.executeSoon(runTextareaTest); |
|
45 }); |
|
46 }, false); |
|
47 var keypress = document.createEvent("KeyboardEvent"); |
|
48 keypress.initKeyEvent("keypress", true, true, document.defaultView, |
|
49 false, false, false, false, 0, "a".charCodeAt(0)); |
|
50 input.dispatchEvent(keypress); |
|
51 }); |
|
52 }); |
|
53 |
|
54 function runTextareaTest() |
|
55 { |
|
56 textarea.addEventListener("keypress", |
|
57 function(aEvent) { |
|
58 textarea.removeEventListener("keypress", arguments.callee, false); |
|
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 }, false); |
|
69 var keypress = document.createEvent("KeyboardEvent"); |
|
70 keypress.initKeyEvent("keypress", true, true, document.defaultView, |
|
71 false, false, false, false, 0, "b".charCodeAt(0)); |
|
72 textarea.dispatchEvent(keypress); |
|
73 } |
|
74 |
|
75 function runContentediableTest() |
|
76 { |
|
77 div.addEventListener("keypress", |
|
78 function(aEvent) { |
|
79 div.removeEventListener("keypress", arguments.callee, false); |
|
80 is(aEvent.target, div, |
|
81 "The keypress event target isn't the div element"); |
|
82 |
|
83 SimpleTest.executeSoon(function() { |
|
84 is(div.innerHTML, "", |
|
85 "Did keypress event cause modifying the div element?"); |
|
86 |
|
87 SimpleTest.finish(); |
|
88 }); |
|
89 }, false); |
|
90 var keypress = document.createEvent("KeyboardEvent"); |
|
91 keypress.initKeyEvent("keypress", true, true, document.defaultView, |
|
92 false, false, false, false, 0, "c".charCodeAt(0)); |
|
93 div.dispatchEvent(keypress); |
|
94 } |
|
95 |
|
96 </script> |
|
97 </pre> |
|
98 </body> |
|
99 </html> |