- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / media / html / media_seek.html
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>
8
9   <body>
10     <video controls></video>
11     <div></div>
12   </body>
13
14   <script type="text/javascript">
15     var video = document.querySelector("video");
16     var logDiv = document.querySelector("div");
17     var ITERATIONS = 3;
18
19     var SeekTestCase = {
20       SHORT: 0,
21       LONG: 1
22     }
23
24     var CachedState = {
25       UNCACHED: 0,
26       CACHED: 1
27     }
28
29     function log(text) {
30       logDiv.innerText += text + "\n";
31     }
32
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] = [];
39         }
40       }
41     }
42
43     // Called by the PyAuto controller to initiate testing.
44     function startTest(src) {
45       if (window.domAutomationController)
46         window.domAutomationController.send(true);
47
48       resetSeekRecords();
49       endTest = false;
50       errorMsg = "";
51       timer = new Timer();
52
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();
62     }
63
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;
78       }
79     }
80
81     function getVideoSrc() {
82       if (cacheState == CachedState.UNCACHED) {
83         return GenerateUniqueURL(originalSrc);
84       } else {
85         return video.src;
86       }
87     }
88
89     function playing() {
90       if (seekState == SeekTestCase.SHORT) {
91         timer.start();
92         video.currentTime = 1;
93       }
94     }
95
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.");
114       }
115     }
116
117     function end(msg) {
118       errorMsg = msg;
119       endTest = true;
120       log(msg);
121     }
122
123     function error(evt) {
124       end("Error loading media: " + evt.target + " " + evt.type + " " +
125           video.error.code);
126     }
127   </script>
128 </html>