blob: e16300dfdd0851042d3e23dd8a7c88ec94b95d09 (
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
|
/*
* Original author: Doug Turner <doug.turner@gmail.com>
*
* Contributors:
* * Antonio Gomes <tonikitoo@webkit.org>
**/
var gExpectedResults = 0;
var gIndex = 0;
var gClosureCallback = null;
var gFocusedDocument = 0;
function initTest(table, completedCb) {
gExpectedResults = table;
gIndex = 0;
gClosureCallback = completedCb;
gFocusedDocument = 0;
prepareMove();
}
function prepareMove()
{
// When a table has with "DONE", call the completion callback and end the moves.
if (gExpectedResults[gIndex][0] == "DONE")
if (gClosureCallback) {
gClosureCallback();
return;
}
// When a table has an "", just end the moves.
if (gExpectedResults[gIndex][0] == "")
return;
doMove();
}
function doMove()
{
var direction;
switch (gExpectedResults[gIndex][0]) {
case "Up":
direction = "upArrow";
break;
case "Right":
direction = "rightArrow";
break;
case "Down":
direction = "downArrow";
break;
case "Left":
direction = "leftArrow";
break;
case "Space":
direction = " ";
break;
default:
debug("Action [" + gExpectedResults[gIndex][0] + "] not supported.");
}
if (window.layoutTestController && direction)
eventSender.keyDown(direction);
setTimeout(verifyAndAdvance, 15);
}
function verifyAndAdvance()
{
var direction = gExpectedResults[gIndex][0];
var expectedID = gExpectedResults[gIndex][1];
gFocusedDocument = document;
findFocusedDocument(document);
var i = 0;
var mainFrameHasFocus = true;
for ( ; i < window.frames.length; i++) {
if (window.frames[i].document.hasFocus()) {
mainFrameHasFocus = false;
break;
}
}
shouldBeEqualToString("gFocusedDocument.activeElement.getAttribute(\"id\")", expectedID);
gIndex++;
prepareMove();
}
function findFocusedDocument(currentDocument)
{
var i = 0;
for ( ; i < currentDocument.defaultView.frames.length; i++) {
findFocusedDocument(currentDocument.defaultView.frames[i].document);
if (gFocusedDocument != document)
return;
}
if (currentDocument.hasFocus()) {
gFocusedDocument = currentDocument;
return;
}
}
|