1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/base/tests/chrome/test_bug551434.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +<html> 1.5 +<head> 1.6 + <title>Test for Bug 551434</title> 1.7 + <script type="application/javascript" 1.8 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <script type="application/javascript" 1.10 + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.11 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 1.12 +</head> 1.13 +<body> 1.14 +</div> 1.15 +<pre id="test"> 1.16 +<input id="i1" onkeydown="gKeyDown1++; $('i2').focus();" onkeypress="gKeyPress1++;" onkeyup="gKeyUp1++;"/> 1.17 +<input id="i2" onkeydown="gKeyDown2++;" onkeypress="gKeyPress2++;" onkeyup="gKeyUp2++;"/> 1.18 + 1.19 +<input id="i3" onkeydown="gKeyDown3++; frames[0].document.getElementById('i4').focus();" 1.20 + onkeypress="gKeyPress3++;" onkeyup="gKeyUp3++;"/> 1.21 +<iframe id="iframe" src="http://example.org/chrome/layout/base/tests/chrome/bug551434_childframe.html"></iframe> 1.22 + 1.23 +<script class="testbody" type="text/javascript"> 1.24 + 1.25 +SimpleTest.waitForExplicitFinish(); 1.26 + 1.27 +var gKeyDown1 = 0, gKeyPress1 = 0, gKeyUp1 = 0; 1.28 +var gKeyDown2 = 0, gKeyPress2 = 0, gKeyUp2 = 0; 1.29 +var gKeyDown3 = 0, gKeyPress3 = 0, gKeyUp3 = 0; 1.30 + 1.31 +function runTest() 1.32 +{ 1.33 + $("i1").focus(); 1.34 + 1.35 + // key events should not be retargeted when the focus changes to an 1.36 + // element in the same document. 1.37 + synthesizeKey("a", { type: "keydown" }); 1.38 + is(document.activeElement, $("i2"), "input 2 in focused"); 1.39 + 1.40 + synthesizeKey("a", { type: "keypress" }); 1.41 + synthesizeKey("a", { type: "keyup" }); 1.42 + 1.43 + is(gKeyDown1, 1, "keydown on input 1"); 1.44 + is(gKeyPress1, 0, "keypress on input 1"); 1.45 + is(gKeyUp1, 0, "keyup on input 1"); 1.46 + is(gKeyDown2, 0, "keydown on input 2"); 1.47 + is(gKeyPress2, 1, "keypress on input 2"); 1.48 + is(gKeyUp2, 1, "keyup on input 2"); 1.49 + 1.50 + is($("i1").value, "", "input 1 value"); 1.51 + is($("i2").value, "a", "input 2 value"); 1.52 + 1.53 + // key events should however be retargeted when the focus changes to an 1.54 + // element in the a content document from a chrome document. 1.55 + $("i3").focus(); 1.56 + 1.57 + var childWinObj = frames[0].wrappedJSObject; 1.58 + 1.59 + synthesizeKey("b", { type: "keydown" }); 1.60 + synthesizeKey("b", { type: "keypress" }); 1.61 + synthesizeKey("b", { type: "keyup" }); 1.62 + is(gKeyDown3, 1, "keydown on input 3"); 1.63 + is(gKeyPress3, 1, "keypress on input 3"); 1.64 + is(gKeyUp3, 1, "keyup on input 3"); 1.65 + is(childWinObj.gKeyDownChild, 0, "keydown on input 4"); 1.66 + is(childWinObj.gKeyPressChild, 0, "keypress on input 4"); 1.67 + is(childWinObj.gKeyUpChild, 0, "keyup on input 4"); 1.68 + 1.69 + var i4 = frames[0].document.getElementById("i4"); 1.70 + is($("i3").value, "b", "input 3 value"); 1.71 + is(i4.value, "", "input 4 value"); 1.72 + 1.73 + is(document.activeElement, $("iframe"), "parent focus"); 1.74 + is(frames[0].document.activeElement, i4, "child focus"); 1.75 + 1.76 + // key events should also be retargeted when the focus changes to an 1.77 + // element in a chrome document from a content document. 1.78 + i4.addEventListener("keydown", function () $("i3").focus(), false); 1.79 + 1.80 + synthesizeKey("c", { type: "keydown" }); 1.81 + synthesizeKey("c", { type: "keypress" }); 1.82 + synthesizeKey("c", { type: "keyup" }); 1.83 + 1.84 + is(gKeyDown3, 1, "keydown on input 3"); 1.85 + is(gKeyPress3, 1, "keypress on input 3"); 1.86 + is(gKeyUp3, 1, "keyup on input 3"); 1.87 + is(childWinObj.gKeyDownChild, 1, "keydown on input 4"); 1.88 + is(childWinObj.gKeyPressChild, 1, "keypress on input 4"); 1.89 + is(childWinObj.gKeyUpChild, 1, "keyup on input 4"); 1.90 + 1.91 + is($("i3").value, "b", "input 3 value"); 1.92 + is(i4.value, "c", "input 4 value"); 1.93 + 1.94 + is(document.activeElement, $("i3"), "parent focus"); 1.95 + 1.96 + SimpleTest.finish(); 1.97 +} 1.98 + 1.99 +SimpleTest.waitForFocus(runTest); 1.100 + 1.101 +</script> 1.102 +</pre> 1.103 +</body> 1.104 +</html> 1.105 +