4296f0d3cd9a8eb964c0ff41a69468b525a3f142
[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
22                   assert_not_equals(previousQuality, newQuality, "Verify new object");
23                   assert_greater_than(newQuality.creationTime, previousQuality.creationTime, "creationTime");
24
25                   assert_greater_than_equal(newQuality.totalVideoFrames, 0, "totalVideoFrames >= 0");
26                   assert_greater_than_equal(newQuality.totalVideoFrames, previousQuality.totalVideoFrames, "totalVideoFrames");
27
28                   assert_greater_than_equal(newQuality.droppedVideoFrames, 0, "droppedVideoFrames >= 0");
29                   assert_greater_than_equal(newQuality.droppedVideoFrames, previousQuality.droppedVideoFrames, "droppedVideoFrames");
30
31                   assert_greater_than_equal(newQuality.corruptedVideoFrames, 0, "corruptedVideoFrames >= 0");
32                   assert_greater_than_equal(newQuality.corruptedVideoFrames, previousQuality.corruptedVideoFrames, "corruptedVideoFrames");
33                   previousQuality = newQuality;
34                   timeUpdateCount++;
35               }));
36
37               mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'"));
38
39               test.expectEvent(sourceBuffer, 'updatestart', 'sourceBuffer');
40               test.expectEvent(sourceBuffer, 'update', 'sourceBuffer');
41               test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
42               sourceBuffer.appendBuffer(mediaData);
43
44               test.waitForExpectedEvents(function()
45               {
46                   assert_false(sourceBuffer.updating, "updating");
47
48                   sourceBuffer.remove(1, Infinity);
49
50                   assert_true(sourceBuffer.updating, "updating");
51                   test.expectEvent(sourceBuffer, 'updatestart', 'sourceBuffer');
52                   test.expectEvent(sourceBuffer, 'update', 'sourceBuffer');
53                   test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
54               });
55
56               test.waitForExpectedEvents(function()
57               {
58                   assert_false(sourceBuffer.updating, "updating");
59                   assert_greater_than(mediaSource.duration, 1, "duration");
60
61                   mediaSource.duration = 1;
62
63                   test.expectEvent(mediaElement, "durationchange");
64               });
65
66               test.waitForExpectedEvents(function()
67               {
68                   mediaSource.endOfStream();
69                   mediaElement.play();
70                   test.expectEvent(mediaElement, 'ended', 'mediaElement');
71               });
72
73               test.waitForExpectedEvents(function()
74               {
75                   assert_greater_than(timeUpdateCount, 2, "timeUpdateCount");
76                   test.done();
77               });
78           }, "Test HTMLVideoElement.getVideoPlaybackQuality() with MediaSource API");
79         </script>
80     </body>
81 </html>