|
1 <html> |
|
2 <head> |
|
3 <title>Test for Bug 551434</title> |
|
4 <script type="application/javascript" |
|
5 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <script type="application/javascript" |
|
7 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
|
8 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
|
9 </head> |
|
10 <body> |
|
11 </div> |
|
12 <pre id="test"> |
|
13 <input id="i1" onkeydown="gKeyDown1++; $('i2').focus();" onkeypress="gKeyPress1++;" onkeyup="gKeyUp1++;"/> |
|
14 <input id="i2" onkeydown="gKeyDown2++;" onkeypress="gKeyPress2++;" onkeyup="gKeyUp2++;"/> |
|
15 |
|
16 <input id="i3" onkeydown="gKeyDown3++; frames[0].document.getElementById('i4').focus();" |
|
17 onkeypress="gKeyPress3++;" onkeyup="gKeyUp3++;"/> |
|
18 <iframe id="iframe" src="http://example.org/chrome/layout/base/tests/chrome/bug551434_childframe.html"></iframe> |
|
19 |
|
20 <script class="testbody" type="text/javascript"> |
|
21 |
|
22 SimpleTest.waitForExplicitFinish(); |
|
23 |
|
24 var gKeyDown1 = 0, gKeyPress1 = 0, gKeyUp1 = 0; |
|
25 var gKeyDown2 = 0, gKeyPress2 = 0, gKeyUp2 = 0; |
|
26 var gKeyDown3 = 0, gKeyPress3 = 0, gKeyUp3 = 0; |
|
27 |
|
28 function runTest() |
|
29 { |
|
30 $("i1").focus(); |
|
31 |
|
32 // key events should not be retargeted when the focus changes to an |
|
33 // element in the same document. |
|
34 synthesizeKey("a", { type: "keydown" }); |
|
35 is(document.activeElement, $("i2"), "input 2 in focused"); |
|
36 |
|
37 synthesizeKey("a", { type: "keypress" }); |
|
38 synthesizeKey("a", { type: "keyup" }); |
|
39 |
|
40 is(gKeyDown1, 1, "keydown on input 1"); |
|
41 is(gKeyPress1, 0, "keypress on input 1"); |
|
42 is(gKeyUp1, 0, "keyup on input 1"); |
|
43 is(gKeyDown2, 0, "keydown on input 2"); |
|
44 is(gKeyPress2, 1, "keypress on input 2"); |
|
45 is(gKeyUp2, 1, "keyup on input 2"); |
|
46 |
|
47 is($("i1").value, "", "input 1 value"); |
|
48 is($("i2").value, "a", "input 2 value"); |
|
49 |
|
50 // key events should however be retargeted when the focus changes to an |
|
51 // element in the a content document from a chrome document. |
|
52 $("i3").focus(); |
|
53 |
|
54 var childWinObj = frames[0].wrappedJSObject; |
|
55 |
|
56 synthesizeKey("b", { type: "keydown" }); |
|
57 synthesizeKey("b", { type: "keypress" }); |
|
58 synthesizeKey("b", { type: "keyup" }); |
|
59 is(gKeyDown3, 1, "keydown on input 3"); |
|
60 is(gKeyPress3, 1, "keypress on input 3"); |
|
61 is(gKeyUp3, 1, "keyup on input 3"); |
|
62 is(childWinObj.gKeyDownChild, 0, "keydown on input 4"); |
|
63 is(childWinObj.gKeyPressChild, 0, "keypress on input 4"); |
|
64 is(childWinObj.gKeyUpChild, 0, "keyup on input 4"); |
|
65 |
|
66 var i4 = frames[0].document.getElementById("i4"); |
|
67 is($("i3").value, "b", "input 3 value"); |
|
68 is(i4.value, "", "input 4 value"); |
|
69 |
|
70 is(document.activeElement, $("iframe"), "parent focus"); |
|
71 is(frames[0].document.activeElement, i4, "child focus"); |
|
72 |
|
73 // key events should also be retargeted when the focus changes to an |
|
74 // element in a chrome document from a content document. |
|
75 i4.addEventListener("keydown", function () $("i3").focus(), false); |
|
76 |
|
77 synthesizeKey("c", { type: "keydown" }); |
|
78 synthesizeKey("c", { type: "keypress" }); |
|
79 synthesizeKey("c", { type: "keyup" }); |
|
80 |
|
81 is(gKeyDown3, 1, "keydown on input 3"); |
|
82 is(gKeyPress3, 1, "keypress on input 3"); |
|
83 is(gKeyUp3, 1, "keyup on input 3"); |
|
84 is(childWinObj.gKeyDownChild, 1, "keydown on input 4"); |
|
85 is(childWinObj.gKeyPressChild, 1, "keypress on input 4"); |
|
86 is(childWinObj.gKeyUpChild, 1, "keyup on input 4"); |
|
87 |
|
88 is($("i3").value, "b", "input 3 value"); |
|
89 is(i4.value, "c", "input 4 value"); |
|
90 |
|
91 is(document.activeElement, $("i3"), "parent focus"); |
|
92 |
|
93 SimpleTest.finish(); |
|
94 } |
|
95 |
|
96 SimpleTest.waitForFocus(runTest); |
|
97 |
|
98 </script> |
|
99 </pre> |
|
100 </body> |
|
101 </html> |
|
102 |