summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/bugs/test_bug265203.html
blob: e5fe713f572c4d5e5bbf022c02ff0c04006665a9 (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=265203
-->
<head>
  <title>Test for Bug 265203</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=265203">Mozilla Bug 265203</a>
<p id="display">
<a id="a1" href="http://www.mozilla.org">Mozilla</a><a id="a2" 
 href="http://www.mozilla.org/products/firefox">Firefox</a><br>
<br>
<table cellpadding="2" cellspacing="2" border="1"
 style="text-align: left; width: 100%;">
  <tbody>

    <tr>
      <td style="vertical-align: top;"><a id="a3" href="http://www.mozilla.org">Mozilla</a></td>
      <td style="vertical-align: top;"><a
 href="http://www.mozilla.org/products/firefox">Firefox</a></td>
    </tr>
    <tr>
      <td style="vertical-align: top;"><a href="http://www.mozilla.org">Mozilla</a></td>
      <td style="vertical-align: top;"><a
 href="http://www.mozilla.org/products/firefox">Firefox</a></td>

    </tr>
  </tbody>
</table>
</p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 265203 **/
var gTestStarted = false;
var expectedResult = [ null, 0, null ];
var nextTest;
var test = 0;

function testFocus() {
    var selection = window.getSelection()
    is(selection.focusNode, expectedResult[0],"test" + test + ": " + "caret node");
    is(selection.focusOffset, expectedResult[1],"test" + test + ": " + "caret offset");
    is(document.activeElement, expectedResult[2],"test" + test + ": " + "focused node");
    ++test;
    if (nextTest)
      nextTest();
}

function test0() {
    $("a1").focus();
    expectedResult = [ $("a1"), 0, $("a1") ]
    nextTest = test1;
    testFocus();
}
function test1() {
    synthesizeKey("VK_RIGHT", { });
    synthesizeKey("VK_RIGHT", { });
    synthesizeKey("VK_RIGHT", { });
    synthesizeKey("VK_RIGHT", { });
    synthesizeKey("VK_RIGHT", { });
    synthesizeKey("VK_RIGHT", { });
    synthesizeKey("VK_RIGHT", { });
    expectedResult = [ $("a1").firstChild, 7, $("a2") ]
    nextTest = test2;
    testFocus();
}
function test2() {
    $("a3").focus();
    expectedResult = [ $("a3"), 0, $("a3") ]
    nextTest = test3;
    testFocus();
}
function test3() {
    synthesizeKey("VK_RIGHT", { });
    synthesizeKey("VK_RIGHT", { });
    synthesizeKey("VK_RIGHT", { });
    synthesizeKey("VK_RIGHT", { });
    synthesizeKey("VK_RIGHT", { });
    synthesizeKey("VK_RIGHT", { });
    synthesizeKey("VK_RIGHT", { });
    expectedResult = [ $("a3").firstChild, 7, $("a3") ]
    nextTest = SimpleTest.finish;
    testFocus();
}

function startTest() {
  if (gTestStarted)
    return;
  gTestStarted = true;
  // Turn off spatial navigation because it hijacks VK_RIGHT and VK_LEFT keydown
  // events
  SpecialPowers.pushPrefEnv({"set": [["accessibility.browsewithcaret", true], ["snav.enabled", false]]}, test0);
}

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(startTest);

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