Refactoring: Pull all fullscreen code out of Document and into its own helper class
[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     if (navigator.userAgent.match(/iPod|iPhone|iPad/) && !window.MSStream) {
45         video.setAttribute('muted', 'true');
46         video.setAttribute('autoplay', 'allowed');
47     }
48
49     var startTime = PerfTestRunner.now();
50     video.src = url;
51     video.addEventListener('canplaythrough', () => {
52         if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
53             return;
54
55         PerfTestRunner.gc();
56         setTimeout(runTest, 0);
57     });
58 }
59
60 </script>
61 </head>
62 <body>
63     <button onclick="pauseAll()">pause</button><button onclick="playAll()">play</button><br>
64 </body>
65 </html>