Refactoring: Pull all fullscreen code out of Document and into its own helper class
[WebKit-https.git] / PerformanceTests / Media / MSECanPlayThrough.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="media-source-loader.js"></script>
5 <script src="../resources/runner.js"></script>
6 <script>
7 var loader;
8 var video;
9
10 window.addEventListener('load', () => {
11     PerfTestRunner.prepareToMeasureValuesAsync({
12         unit: 'ms',
13         done: function () {
14             if (video) {
15                 video.src = null;
16                 video.load();
17             }
18         }
19     });
20
21     loader = new MediaSourceLoader('test-fragmented-video.json');
22     loader.loadMediaData().then(runTest);
23 });
24
25 function runTest() {   
26     video =  document.createElement('video');
27
28     var startTime = PerfTestRunner.now();
29     var loadPromise = loadMediaDataIntoVideo(video);
30     video.addEventListener('canplaythrough', () => {
31         if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
32             return;
33
34         loadPromise.then(() => {
35             PerfTestRunner.gc();
36             setTimeout(runTest, 0);
37         });
38     });
39 }
40
41 function loadMediaDataIntoVideo(video, segmentCount) {
42     return new Promise((resolve, reject) => {
43         var source = new MediaSource();
44         source.addEventListener('sourceopen', (e) => {
45             var source = e.target;
46             var currentMediaSegment = 0;
47             var sourceBuffer = source.addSourceBuffer(loader.type);
48             sourceBuffer.appendBuffer(loader.initSegment);
49
50             var appendedMediaSegment = false;
51             sourceBuffer.addEventListener('update', () => {
52
53                 if (appendedMediaSegment) {
54                     if (source.readyState !== 'ended') {
55                         source.endOfStream();
56                         resolve();
57                     }
58                     return;
59                 }
60
61                 sourceBuffer.appendBuffer(loader.everyMediaSegment);
62                 appendedMediaSegment = true;
63             });
64             sourceBuffer.addEventListener('error', error => {
65                 reject();
66             });
67         });
68         video.src = URL.createObjectURL(source);
69     });
70 }
71 </script>
72 </head>
73 <body>
74 </body>
75 </html>