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