forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfull-screen-test.js
187 lines (151 loc) · 4.4 KB
/
full-screen-test.js
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
var consoleDiv = null;
var printFullTestDetails = true; // This is optionaly switched of by test whose tested values can differ. (see disableFullTestDetailsPrinting())
var runPixelTests;
logConsole();
if (window.testRunner) {
testRunner.dumpAsText(runPixelTests);
testRunner.waitUntilDone();
}
function runWithKeyDown(fn)
{
// FIXME: WKTR does not yet support the keyDown() message. Do a mouseDown here
// instead until keyDown support is added.
var eventName = !window.testRunner || eventSender.keyDown ? 'keypress' : 'mousedown'
function thunk() {
document.removeEventListener(eventName, thunk, false);
fn();
}
document.addEventListener(eventName, thunk, false);
if (window.testRunner) {
if (eventSender.keyDown)
eventSender.keyDown(" ", []);
else
eventSender.mouseDown();
}
}
function logConsole()
{
if (!consoleDiv && document.body) {
consoleDiv = document.createElement('div');
document.body.appendChild(consoleDiv);
}
return consoleDiv;
}
function testAndEnd(testFuncString)
{
test(testFuncString, true);
}
function test(testFuncString, endit)
{
logResult(eval(testFuncString), "TEST(" + testFuncString + ")");
if (endit)
endTest();
}
function testExpected(testFuncString, expected, comparison)
{
try {
var observed = eval(testFuncString);
} catch (ex) {
consoleWrite(ex);
return;
}
if (comparison === undefined)
comparison = '==';
var success = false;
switch (comparison)
{
case '<': success = observed < expected; break;
case '<=': success = observed <= expected; break;
case '>': success = observed > expected; break;
case '>=': success = observed >= expected; break;
case '!=': success = observed != expected; break;
case '==': success = observed == expected; break;
}
reportExpected(success, testFuncString, comparison, expected, observed)
}
var testNumber = 0;
function reportExpected(success, testFuncString, comparison, expected, observed)
{
testNumber++;
var msg = "Test " + testNumber;
if (printFullTestDetails || !success)
msg = "EXPECTED (<em>" + testFuncString + " </em>" + comparison + " '<em>" + expected + "</em>')";
if (!success)
msg += ", OBSERVED '<em>" + observed + "</em>'";
logResult(success, msg);
}
function run(testFuncString)
{
consoleWrite("RUN(" + testFuncString + ")");
try {
eval(testFuncString);
} catch (ex) {
consoleWrite(ex);
}
}
function waitForEventAndEnd(element, eventName, funcString)
{
waitForEvent(element, eventName, funcString, true)
}
function waitForEventOnce(element, eventName, func, endit)
{
waitForEvent(element, eventName, func, endit, true)
}
function waitForEvent(element, eventName, func, endit, once)
{
function _eventCallback(event)
{
if (once)
element.removeEventListener(eventName, _eventCallback);
consoleWrite("EVENT(" + eventName + ")");
if (func)
func(event);
if (endit)
endTest();
}
element.addEventListener(eventName, _eventCallback);
}
function waitForEventAndTest(element, eventName, testFuncString, endit)
{
function _eventCallback(event)
{
logResult(eval(testFuncString), "EVENT(" + eventName + ") TEST(" + testFuncString + ")");
if (endit)
endTest();
}
element.addEventListener(eventName, _eventCallback);
}
function waitFor(element, type, silent) {
return new Promise(resolve => {
element.addEventListener(type, event => {
if (!silent)
consoleWrite(`EVENT(${event.type})`);
resolve(event);
}, { once: true });
});
}
function waitForEventTestAndEnd(element, eventName, testFuncString)
{
waitForEventAndTest(element, eventName, testFuncString, true);
}
var testEnded = false;
function endTest()
{
consoleWrite("END OF TEST");
testEnded = true;
if (window.testRunner)
testRunner.notifyDone();
}
function logResult(success, text)
{
if (success)
consoleWrite(text + " <span style='color:green'>OK</span>");
else
consoleWrite(text + " <span style='color:red'>FAIL</span>");
}
function consoleWrite(text)
{
if (testEnded)
return;
logConsole().innerHTML += text + "<br>";
}