layout/base/tests/chrome/test_bug551434.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial