Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / test / data / media / html / media_seek.html
blobbc7eb609c8c951d2b9f12b7e9073cdc3630349d8
1 <!-- Used by media_seek_perf to record seek perf metrics. -->
2 <!DOCTYPE html>
3 <html lang="en-US">
4 <head>
5 <title>CNS Seek Tests</title>
6 <script src="utils.js" type="text/javascript"></script>
7 </head>
9 <body>
10 <video controls></video>
11 <div></div>
12 </body>
14 <script type="text/javascript">
15 var video = document.querySelector("video");
16 var logDiv = document.querySelector("div");
17 var ITERATIONS = 3;
19 var SeekTestCase = {
20 SHORT: 0,
21 LONG: 1
24 var CachedState = {
25 UNCACHED: 0,
26 CACHED: 1
29 function log(text) {
30 logDiv.innerText += text + "\n";
33 function resetSeekRecords() {
34 seekRecords = [];
35 for (cache_index in Object.keys(CachedState)) {
36 seekRecords[cache_index] = [];
37 for (seek_index in Object.keys(SeekTestCase)) {
38 seekRecords[cache_index][seek_index] = [];
43 // Called by the PyAuto controller to initiate testing.
44 function startTest(src) {
45 if (window.domAutomationController)
46 window.domAutomationController.send(true);
48 resetSeekRecords();
49 endTest = false;
50 errorMsg = "";
51 timer = new Timer();
53 video.addEventListener("playing", playing);
54 video.addEventListener("seeked", seeked);
55 video.addEventListener("error", error);
56 originalSrc = src;
57 log("Running tests on " + originalSrc);
58 log("Starting seek tests without browser caching:");
59 cacheState = CachedState.UNCACHED;
60 iteration = 0;
61 IterationTest();
64 function IterationTest() {
65 if (iteration < ITERATIONS) {
66 iteration++;
67 log("Test iteration " + iteration);
68 seekState = SeekTestCase.SHORT;
69 video.src = getVideoSrc();
70 video.play();
71 } else if (cacheState == CachedState.UNCACHED) {
72 log("Starting seek tests with browser caching:");
73 cacheState = CachedState.CACHED;
74 iteration = 0;
75 IterationTest();
76 } else {
77 endTest = true;
81 function getVideoSrc() {
82 if (cacheState == CachedState.UNCACHED) {
83 return GenerateUniqueURL(originalSrc);
84 } else {
85 return video.src;
89 function playing() {
90 if (seekState == SeekTestCase.SHORT) {
91 timer.start();
92 video.currentTime = 1;
96 function seeked() {
97 delta = timer.stop();
98 switch (seekState) {
99 case SeekTestCase.SHORT:
100 seekRecords[cacheState][SeekTestCase.SHORT].push(delta);
101 log ("short seek in " + delta + "ms.")
102 seekState = SeekTestCase.LONG;
103 timer.start();
104 video.currentTime = video.duration - 1;
105 break;
106 // Seek to almost end of file (unbuffered area).
107 case SeekTestCase.LONG:
108 seekRecords[cacheState][SeekTestCase.LONG].push(delta);
109 log("long seek in " + delta + "ms.")
110 IterationTest();
111 break;
112 default:
113 end("An un-expected seek occured.");
117 function end(msg) {
118 errorMsg = msg;
119 endTest = true;
120 log(msg);
123 function error(evt) {
124 end("Error loading media: " + evt.target + " " + evt.type + " " +
125 video.error.code);
127 </script>
128 </html>