File's structured serialization should serialize lastModified attribute
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / media-source / mediasource-getvideoplaybackquality.html
1 <!DOCTYPE html>
2 <!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
3 <html>
4     <head>
5         <title>HTMLVideoElement.getVideoPlaybackQuality() test cases.</title>
6         <script src="/resources/testharness.js"></script>
7         <script src="/resources/testharnessreport.js"></script>
8         <script src="mediasource-util.js"></script>
9     </head>
10     <body>
11         <div id="log"></div>
12         <script>
13           mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
14           {
15               var previousQuality = mediaElement.getVideoPlaybackQuality();
16               var timeUpdateCount = 0;
17               mediaElement.addEventListener("timeupdate", test.step_func(function (e)
18               {
19                   var videoElement = e.target;
20                   var newQuality = videoElement.getVideoPlaybackQuality();
21                   var now = window.performance.now();
22
23                   assert_not_equals(previousQuality, newQuality,
24                     "New quality object is different from the previous one");
25                   assert_greater_than(newQuality.creationTime, previousQuality.creationTime,
26                     "creationTime increases monotonically");
27                   assert_approx_equals(newQuality.creationTime, now, 100,
28                     "creationTime roughly equals current time");
29
30                   assert_greater_than_equal(newQuality.totalVideoFrames, 0, "totalVideoFrames >= 0");
31                   assert_greater_than_equal(newQuality.totalVideoFrames, previousQuality.totalVideoFrames,
32                     "totalVideoFrames increases monotonically");
33                   assert_less_than(newQuality.totalVideoFrames, 300,
34                     "totalVideoFrames should remain low as duration is less than 10s and framerate less than 30fps");
35
36                   assert_greater_than_equal(newQuality.droppedVideoFrames, 0, "droppedVideoFrames >= 0");
37                   assert_greater_than_equal(newQuality.droppedVideoFrames, previousQuality.droppedVideoFrames,
38                     "droppedVideoFrames increases monotonically");
39                   assert_less_than_equal(newQuality.droppedVideoFrames, newQuality.totalVideoFrames,
40                     "droppedVideoFrames is only a portion of totalVideoFrames");
41
42                   assert_greater_than_equal(newQuality.corruptedVideoFrames, 0, "corruptedVideoFrames >= 0");
43                   assert_greater_than_equal(newQuality.corruptedVideoFrames, previousQuality.corruptedVideoFrames,
44                     "corruptedVideoFrames increases monotonically");
45                   assert_less_than_equal(newQuality.corruptedVideoFrames, newQuality.totalVideoFrames,
46                     "corruptedVideoFrames is only a portion of totalVideoFrames");
47
48                   previousQuality = newQuality;
49                   timeUpdateCount++;
50               }));
51
52               mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'"));
53
54               sourceBuffer.appendBuffer(mediaData);
55               test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
56
57               test.waitForExpectedEvents(function()
58               {
59                   assert_false(sourceBuffer.updating, "updating");
60                   mediaSource.endOfStream();
61                   assert_less_than(mediaSource.duration, 10, "duration");
62                   mediaElement.play();
63                   test.expectEvent(mediaElement, 'ended', 'mediaElement');
64               });
65
66               test.waitForExpectedEvents(function()
67               {
68                   assert_greater_than(timeUpdateCount, 2, "timeUpdateCount");
69                   test.done();
70               });
71           }, "Test HTMLVideoElement.getVideoPlaybackQuality() with MediaSource API");
72
73
74           mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
75           {
76               var previousQuality = mediaElement.getVideoPlaybackQuality();
77               var timeUpdateCount = 0;
78               var startTime = 0;
79               mediaElement.addEventListener("timeupdate", test.step_func(function (e)
80               {
81                   var videoElement = e.target;
82                   var newQuality = videoElement.getVideoPlaybackQuality();
83                   var now = window.performance.now();
84
85                   assert_greater_than_equal(newQuality.totalFrameDelay, 0, "totalFrameDelay >= 0");
86                   assert_greater_than_equal(newQuality.totalFrameDelay, previousQuality.totalFrameDelay,
87                     "totalFrameDelay increases monotonically");
88                   assert_less_than(newQuality.totalFrameDelay, (now - startTime) / 1000,
89                     "totalFrameDelay does not exceed the time elapsed since playback started");
90
91                   previousQuality = newQuality;
92                   timeUpdateCount++;
93               }));
94
95               mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'"));
96
97               sourceBuffer.appendBuffer(mediaData);
98               test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
99               test.waitForExpectedEvents(function()
100               {
101                   assert_false(sourceBuffer.updating, "updating");
102                   mediaSource.endOfStream();
103                   assert_less_than(mediaSource.duration, 10, "duration");
104                   startTime = window.performance.now();
105                   mediaElement.play();
106                   test.expectEvent(mediaElement, 'ended', 'mediaElement');
107               });
108
109               test.waitForExpectedEvents(function()
110               {
111                   assert_greater_than(timeUpdateCount, 2, "timeUpdateCount");
112                   test.done();
113               });
114           }, "Test the totalFrameDelay attribute of HTMLVideoElement.getVideoPlaybackQuality() with MediaSource API");
115         </script>
116     </body>
117 </html>