File: test_bug551434.html

package info (click to toggle)
firefox 141.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,550,588 kB
  • sloc: cpp: 7,426,506; javascript: 6,367,238; ansic: 3,707,351; python: 1,369,002; xml: 623,983; asm: 426,918; java: 184,324; sh: 64,488; makefile: 19,203; objc: 13,059; perl: 12,955; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,071; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (95 lines) | stat: -rw-r--r-- 3,183 bytes parent folder | download | duplicates (26)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<html>
<head>
  <title>Test for Bug 551434</title>
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
</head>
<body>
</div>
<pre id="test">
<input id="i1" onkeydown="gKeyDown1++; $('i2').focus();" onkeypress="gKeyPress1++;" onkeyup="gKeyUp1++;"/>
<input id="i2" onkeydown="gKeyDown2++;" onkeypress="gKeyPress2++;" onkeyup="gKeyUp2++;"/>

<input id="i3" onkeydown="gKeyDown3++; frames[0].document.getElementById('i4').focus();"
       onkeypress="gKeyPress3++;" onkeyup="gKeyUp3++;"/>
<iframe id="iframe" src="http://example.org/chrome/layout/base/tests/chrome/bug551434_childframe.html"></iframe>

<script class="testbody" type="text/javascript">

SimpleTest.waitForExplicitFinish();

var gKeyDown1 = 0, gKeyPress1 = 0, gKeyUp1 = 0;
var gKeyDown2 = 0, gKeyPress2 = 0, gKeyUp2 = 0;
var gKeyDown3 = 0, gKeyPress3 = 0, gKeyUp3 = 0;

function runTest()
{
  $("i1").focus();

  // key events should not be retargeted when the focus changes to an
  // element in the same document.
  synthesizeKey("a", {type: "keydown"});
  is(document.activeElement, $("i2"), "input 2 in focused");

  synthesizeKey("a", {type: "keyup"});

  is(gKeyDown1, 1, "keydown on input 1");
  is(gKeyPress1, 0, "keypress on input 1");
  is(gKeyUp1, 0, "keyup on input 1");
  is(gKeyDown2, 0, "keydown on input 2");
  is(gKeyPress2, 1, "keypress on input 2");
  is(gKeyUp2, 1, "keyup on input 2");

  is($("i1").value, "", "input 1 value");
  is($("i2").value, "a", "input 2 value");

  // key events should however be retargeted when the focus changes to an
  // element in the a content document from a chrome document.
  $("i3").focus();

  var childWinObj = frames[0].wrappedJSObject;

  sendString("b");
  is(gKeyDown3, 1, "keydown on input 3");
  is(gKeyPress3, 1, "keypress on input 3");
  is(gKeyUp3, 1, "keyup on input 3");
  is(childWinObj.gKeyDownChild, 0, "keydown on input 4");
  is(childWinObj.gKeyPressChild, 0, "keypress on input 4");
  is(childWinObj.gKeyUpChild, 0, "keyup on input 4");

  var i4 = frames[0].document.getElementById("i4");
  is($("i3").value, "b", "input 3 value");
  is(i4.value, "", "input 4 value");

  is(document.activeElement, $("iframe"), "parent focus");
  is(frames[0].document.activeElement, i4, "child focus");

  // key events should also be retargeted when the focus changes to an
  // element in a chrome document from a content document.
  i4.addEventListener("keydown", () => $("i3").focus());

  sendString("c");

  is(gKeyDown3, 1, "keydown on input 3");
  is(gKeyPress3, 1, "keypress on input 3");
  is(gKeyUp3, 1, "keyup on input 3");
  is(childWinObj.gKeyDownChild, 1, "keydown on input 4");
  is(childWinObj.gKeyPressChild, 1, "keypress on input 4");
  is(childWinObj.gKeyUpChild, 1, "keyup on input 4");

  is($("i3").value, "b", "input 3 value");
  is(i4.value, "c", "input 4 value");

  is(document.activeElement, $("i3"), "parent focus");

  SimpleTest.finish();
}

SimpleTest.waitForFocus(runTest);

</script>
</pre>
</body>
</html>