Add some performance tests for various aspects of media loading and playback.
[WebKit-https.git] / PerformanceTests / Media / StandardCanPlayThrough.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../resources/runner.js"></script>
5 <script>
6 var video;
7 var url;
8
9 window.addEventListener('load', () => {
10     PerfTestRunner.prepareToMeasureValuesAsync({
11         unit: 'ms',
12         done: function () {
13             if (video) {
14                 video.src = null;
15                 video.load();
16             }
17         }
18     });
19
20     loadMediaData('test.mp4').then((blob) => {
21         url = URL.createObjectURL(blob);
22         runTest();
23     });
24 });
25
26 function loadMediaData(url) {
27     return new Promise((resolve, reject) => {
28         var request = new XMLHttpRequest();
29         request.open('GET', url, true);
30         request.responseType = 'blob';
31         request.addEventListener('load', (event) => {
32             resolve(event.target.response);
33         });
34         request.addEventListener('error', (event) => {
35             reject(event.error);
36         });
37         request.send();
38     })
39 }
40
41 function runTest() {   
42     video =  document.createElement('video');
43
44     var startTime = PerfTestRunner.now();
45     video.src = url;
46     video.addEventListener('canplaythrough', () => {
47         if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
48             return;
49
50         PerfTestRunner.gc();
51         setTimeout(runTest, 0);
52     });
53 }
54
55 </script>
56 </head>
57 <body>
58     <button onclick="pauseAll()">pause</button><button onclick="playAll()">play</button><br>
59 </body>
60 </html>