summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_VideoPlaybackQuality.html
blob: be051c0a64b95d34a2f2f0deff6bc27447f2674f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE HTML>
<html>
<head>
  <title>Test basic functionality of VideoPlaybackQuality</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">

SimpleTest.waitForExplicitFinish();

function test() {
  var video = document.createElement("video");
  ok(video.getVideoPlaybackQuality, "getVideoPlaybackQuality should be exposed with pref set");

  var vpq = video.getVideoPlaybackQuality();
  ok(vpq, "getVideoPlaybackQuality should return an object");
  ok(vpq.creationTime <= performance.now(), "creationTime should be in the past");
  is(vpq.totalVideoFrames, 0, "totalVideoFrames should be 0");
  is(vpq.droppedVideoFrames, 0, "droppedVideoFrames should be 0");
  is(vpq.corruptedVideoFrames, 0, "corruptedVideoFrames should be 0");

  var vpq2 = video.getVideoPlaybackQuality();
  ok(vpq !== vpq2, "getVideoPlaybackQuality should return a new object");
  ok(vpq.creationTime <= vpq2.creationTime, "VideoPlaybackQuality objects should have increasing creationTime");

  var audio = document.createElement("audio");
  ok(!audio.getVideoPlaybackQuality, "getVideoPlaybackQuality should not be available on Audio elements");

  video.src = "seek.webm";
  video.play();
  video.addEventListener("ended", function () {
    vpq = video.getVideoPlaybackQuality();
    ok(vpq.creationTime <= performance.now(), "creationTime should be in the past");
    ok(vpq.totalVideoFrames > 0, "totalVideoFrames should be > 0");
    ok(vpq.droppedVideoFrames >= 0, "droppedVideoFrames should be >= 0");
    ok(vpq.droppedVideoFrames <= vpq.totalVideoFrames, "droppedVideoFrames should be <= totalVideoFrames");
    ok(vpq.corruptedVideoFrames >= 0, "corruptedVideoFrames should be >= 0");

    SpecialPowers.pushPrefEnv({"set": [["media.video_stats.enabled", false]]}, function () {
      vpq = video.getVideoPlaybackQuality();
      is(vpq.creationTime, 0, "creationTime should be 0");
      is(vpq.totalVideoFrames, 0, "totalVideoFrames should be 0");
      is(vpq.droppedVideoFrames, 0, "droppedVideoFrames should be 0");
      is(vpq.corruptedVideoFrames, 0, "corruptedVideoFrames should be 0");

      SimpleTest.finish();
    });
  });
}

addLoadEvent(function() {
  SpecialPowers.pushPrefEnv({"set":
    [
      ["media.mediasource.enabled", true],
    ]
  }, test);
});
</script>
</pre>
</body>
</html>