Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(707)

Side by Side Diff: third_party/WebKit/LayoutTests/media/video-test.js

Issue 2259203002: Remove video-test.js file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/media/media-fragments/media-fragments.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 var video = null;
3 var mediaElement = document; // If not set, an event from any element will trigg er a waitForEvent() callback.
4 var consoleDiv = null;
5 var printFullTestDetails = true; // This is optionaly switched of by test whose tested values can differ. (see disableFullTestDetailsPrinting())
6 var Failed = false;
7
8 var track = null; // Current TextTrack being tested.
9 var cues = null; // Current TextTrackCueList being tested.
10 var numberOfTrackTests = 0;
11 var numberOfTracksLoaded = 0;
12
13 findMediaElement();
14 logConsole();
15
16 if (window.testRunner) {
17 // Some track element rendering tests require text pixel dump.
18 if (typeof requirePixelDump == "undefined")
19 testRunner.dumpAsText();
20
21 testRunner.waitUntilDone();
22 }
23
24 function disableFullTestDetailsPrinting()
25 {
26 printFullTestDetails = false;
27 }
28
29 function enableFullTestDetailsPrinting()
30 {
31 printFullTestDetails = true;
32 }
33
34 function logConsole()
35 {
36 if (!consoleDiv && document.body) {
37 consoleDiv = document.createElement('div');
38 document.body.appendChild(consoleDiv);
39 }
40 return consoleDiv;
41 }
42
43 function findMediaElement()
44 {
45 try {
46 video = document.getElementsByTagName('video')[0];
47 if (video)
48 mediaElement = video;
49 else {
50 audio = document.getElementsByTagName('audio')[0];
51 if (audio)
52 mediaElement = audio;
53 }
54 } catch (ex) { }
55 }
56
57 function testAndEnd(testFuncString)
58 {
59 test(testFuncString, true);
60 }
61
62 function test(testFuncString, endit)
63 {
64 logResult(eval(testFuncString), "TEST(" + testFuncString + ")");
65 if (endit)
66 endTest();
67 }
68
69 function testExpected(testFuncString, expected, comparison)
70 {
71 try {
72 var observed = eval(testFuncString);
73 } catch (ex) {
74 consoleWrite(ex);
75 return;
76 }
77
78 if (comparison === undefined)
79 comparison = '==';
80
81 var success = false;
82 switch (comparison)
83 {
84 case '<': success = observed < expected; break;
85 case '<=': success = observed <= expected; break;
86 case '>': success = observed > expected; break;
87 case '>=': success = observed >= expected; break;
88 case '!=': success = observed != expected; break;
89 case '==': success = observed == expected; break;
90 case '===': success = observed === expected; break;
91 }
92
93 reportExpected(success, testFuncString, comparison, expected, observed)
94 }
95
96 function testArraysEqual(testFuncString, expected)
97 {
98 var observed;
99 try {
100 observed = eval(testFuncString);
101 } catch (ex) {
102 consoleWrite(ex);
103 return;
104 }
105
106 testExpected(testFuncString + ".length", expected.length);
107
108 for (var i = 0; i < observed.length; i++) {
109 testExpected(testFuncString + "[" + i + "]", expected[i]);
110 }
111 }
112
113 var testNumber = 0;
114
115 function reportExpected(success, testFuncString, comparison, expected, observed)
116 {
117 testNumber++;
118
119 var msg = "Test " + testNumber;
120
121 if (printFullTestDetails || !success)
122 msg = "EXPECTED (<em>" + testFuncString + " </em>" + comparison + " '<em >" + expected + "</em>')";
123
124 if (!success)
125 msg += ", OBSERVED '<em>" + observed + "</em>'";
126
127 logResult(success, msg);
128 }
129
130 function runSilently(testFuncString)
131 {
132 if (printFullTestDetails)
133 consoleWrite("RUN(" + testFuncString + ")");
134 try {
135 eval(testFuncString);
136 } catch (ex) {
137 if (!printFullTestDetails) {
138 // No details were printed previous, give some now.
139 // This will be helpful in case of error.
140 logResult(Failed, "Error in RUN(" + testFuncString + "):");
141 }
142 logResult(Failed, "<span style='color:red'>"+ex+"</span>");
143 }
144 }
145
146 function run(testFuncString)
147 {
148 consoleWrite("RUN(" + testFuncString + ")");
149 try {
150 eval(testFuncString);
151 } catch (ex) {
152 consoleWrite(ex);
153 }
154 }
155
156 function waitForEventOnce(eventName, func, endit, doNotLog)
157 {
158 waitForEvent(eventName, func, endit, true, null, doNotLog)
159 }
160
161 function waitForEventAndEnd(eventName, funcString)
162 {
163 waitForEvent(eventName, funcString, true, false, null, false)
164 }
165
166 function waitForEvent(eventName, func, endit, oneTimeOnly, element, doNotLog)
167 {
168 if (!element)
169 element = mediaElement;
170
171 function _eventCallback(event)
172 {
173 if (oneTimeOnly)
174 element.removeEventListener(eventName, _eventCallback, true);
175
176 if (!doNotLog)
177 consoleWrite("EVENT(" + eventName + ")");
178
179 if (func)
180 func(event);
181
182 if (endit)
183 endTest();
184 }
185
186 element.addEventListener(eventName, _eventCallback, true);
187 }
188
189 function waitForEventTestAndEnd(eventName, testFuncString)
190 {
191 waitForEventAndTest(eventName, testFuncString, true);
192 }
193
194 function waitForEventAndFail(eventName)
195 {
196 waitForEventAndTest(eventName, "false", true);
197 }
198
199 function waitForEventAndTest(eventName, testFuncString, endit)
200 {
201 function _eventCallback(event)
202 {
203 logResult(eval(testFuncString), "EVENT(" + eventName + ") TEST(" + testF uncString + ")");
204 if (endit)
205 endTest();
206 }
207
208 mediaElement.addEventListener(eventName, _eventCallback, true);
209 }
210
211 function testDOMException(testString, exceptionString)
212 {
213 try {
214 eval(testString);
215 } catch (ex) {
216 var exception = ex;
217 }
218 logResult(exception instanceof DOMException && exception.code === eval(excep tionString),
219 "TEST(" + testString + ") THROWS(" + exceptionString + ": " + exception. message + ")");
220 }
221
222 function testException(testString, exceptionString) {
223 try {
224 eval(testString);
225 } catch (ex) {
226 var exception = ex;
227 }
228 logResult(exception !== undefined && exception == eval(exceptionString),
229 "TEST(" + testString + ") THROWS(" + exceptionString + ")");
230 }
231
232 var testEnded = false;
233
234 function endTest()
235 {
236 consoleWrite("END OF TEST");
237 testEnded = true;
238 if (window.testRunner)
239 testRunner.notifyDone();
240 }
241
242 function endTestLater()
243 {
244 setTimeout(endTest, 250);
245 }
246
247 function failTestIn(ms)
248 {
249 setTimeout(function () {
250 consoleWrite("FAIL: did not end fast enough");
251 endTest();
252 }, ms);
253 }
254
255 function failTest(text)
256 {
257 logResult(Failed, text);
258 endTest();
259 }
260
261 function logResult(success, text)
262 {
263 if (success)
264 consoleWrite(text + " <span style='color:green'>OK</span>");
265 else
266 consoleWrite(text + " <span style='color:red'>FAIL</span>");
267 }
268
269 function consoleWrite(text)
270 {
271 if (testEnded)
272 return;
273 var span = document.createElement("span");
274 logConsole().appendChild(span);
275 span.innerHTML = text + '<br>';
276 }
277
278 function relativeURL(url)
279 {
280 return url.substr(url.lastIndexOf('/media/')+7);
281 }
282
283
284 function isInTimeRanges(ranges, time)
285 {
286 var i = 0;
287 for (i = 0; i < ranges.length; ++i) {
288 if (time >= ranges.start(i) && time <= ranges.end(i)) {
289 return true;
290 }
291 }
292 return false;
293 }
294
295 function testTracks(expected)
296 {
297 tracks = video.textTracks;
298 testExpected("tracks.length", expected.length);
299
300 for (var i = 0; i < tracks.length; i++) {
301 consoleWrite("<br>*** Testing text track " + i);
302
303 track = tracks[i];
304 for (j = 0; j < expected.tests.length; j++) {
305 var test = expected.tests[j];
306 testExpected("track." + test.property, test.values[i]);
307 }
308 }
309 }
310
311 function testCues(index, expected)
312 {
313 consoleWrite("<br>*** Testing text track " + index);
314
315 cues = video.textTracks[index].cues;
316 testExpected("cues.length", expected.length);
317 for (var i = 0; i < cues.length; i++) {
318 for (j = 0; j < expected.tests.length; j++) {
319 var test = expected.tests[j];
320 testExpected("cues[" + i + "]." + test.property, test.values[i]);
321 }
322 }
323 }
324
325 function allTestsEnded()
326 {
327 numberOfTrackTests--;
328 if (numberOfTrackTests == 0)
329 endTest();
330 }
331
332 function enableAllTextTracks()
333 {
334 findMediaElement();
335 for (var i = 0; i < video.textTracks.length; i++) {
336 if (video.textTracks[i].mode == "disabled")
337 video.textTracks[i].mode = "hidden";
338 }
339 }
340
341 var requiredEvents = [];
342
343 function waitForEventsAndCall(eventList, func)
344 {
345 function _eventCallback(event)
346 {
347 if (!requiredEvents.length)
348 return;
349
350 var index = requiredEvents.indexOf(event.type);
351 if (index < 0)
352 return;
353
354 requiredEvents.splice(index, 1);
355 if (requiredEvents.length)
356 return;
357
358 func();
359 }
360
361 requiredEvents = [];
362 for (var i = 0; i < eventList.length; i++) {
363 requiredEvents[i] = eventList[i][1];
364 eventList[i][0].addEventListener(requiredEvents[i], _eventCallback, true );
365 }
366 }
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/media/media-fragments/media-fragments.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698