layout/base/tests/chrome/test_bug551434.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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++;"/>
    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>
    20 <script class="testbody" type="text/javascript">
    22 SimpleTest.waitForExplicitFinish();
    24 var gKeyDown1 = 0, gKeyPress1 = 0, gKeyUp1 = 0;
    25 var gKeyDown2 = 0, gKeyPress2 = 0, gKeyUp2 = 0;
    26 var gKeyDown3 = 0, gKeyPress3 = 0, gKeyUp3 = 0;
    28 function runTest()
    29 {
    30   $("i1").focus();
    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");
    37   synthesizeKey("a", { type: "keypress" });
    38   synthesizeKey("a", { type: "keyup" });
    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");
    47   is($("i1").value, "", "input 1 value");
    48   is($("i2").value, "a", "input 2 value");
    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();
    54   var childWinObj = frames[0].wrappedJSObject;
    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");
    66   var i4 = frames[0].document.getElementById("i4");
    67   is($("i3").value, "b", "input 3 value");
    68   is(i4.value, "", "input 4 value");
    70   is(document.activeElement, $("iframe"), "parent focus");
    71   is(frames[0].document.activeElement, i4, "child focus");
    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);
    77   synthesizeKey("c", { type: "keydown" });
    78   synthesizeKey("c", { type: "keypress" });
    79   synthesizeKey("c", { type: "keyup" });
    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");
    88   is($("i3").value, "b", "input 3 value");
    89   is(i4.value, "c", "input 4 value");
    91   is(document.activeElement, $("i3"), "parent focus");
    93   SimpleTest.finish();
    94 }
    96 SimpleTest.waitForFocus(runTest);
    98 </script>
    99 </pre>
   100 </body>
   101 </html>

mercurial