Bug 889201 - Add tests for VideoPlaybackQuality. r=roc
authorMatthew Gregan <kinetik@flim.org>
Thu, 11 Jul 2013 15:52:22 +1200
changeset 138446 3d800f929d54b1bfceb0f729db02a1ca40f09d11
parent 138445 e166f90a128f053755d71857ab6410c91f27b7fa
child 138447 ba887369ea3e08a1bb514f656c63a2bd7eaa4f0b
child 138461 c89e5b9fe9358d2da2cc8a7ae961a6a8a7fa87ae
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersroc
bugs889201
milestone25.0a1
Bug 889201 - Add tests for VideoPlaybackQuality. r=roc
content/html/content/src/HTMLVideoElement.cpp
content/media/test/Makefile.in
content/media/test/test_VideoPlaybackQuality.html
content/media/test/test_VideoPlaybackQuality_disabled.html
dom/webidl/VideoPlaybackQuality.webidl
--- a/content/html/content/src/HTMLVideoElement.cpp
+++ b/content/html/content/src/HTMLVideoElement.cpp
@@ -257,34 +257,37 @@ HTMLVideoElement::NotifyOwnerDocumentAct
   HTMLMediaElement::NotifyOwnerDocumentActivityChanged();
   WakeLockUpdate();
 }
 
 already_AddRefed<VideoPlaybackQuality>
 HTMLVideoElement::GetVideoPlaybackQuality()
 {
   DOMHighResTimeStamp creationTime = 0;
-  nsPIDOMWindow* window = OwnerDoc()->GetInnerWindow();
-  if (window) {
-    nsPerformance* perf = window->GetPerformance();
-    if (perf) {
-      creationTime = perf->GetDOMTiming()->TimeStampToDOMHighRes(TimeStamp::Now());
-    }
-  }
-
   uint64_t totalFrames = 0;
   uint64_t droppedFrames = 0;
   uint64_t corruptedFrames = 0;
   double playbackJitter = 0.0;
-  if (mDecoder && sVideoStatsEnabled) {
-    MediaDecoder::FrameStatistics& stats = mDecoder->GetFrameStatistics();
-    totalFrames = stats.GetParsedFrames();
-    droppedFrames = totalFrames - stats.GetPresentedFrames();
-    corruptedFrames = totalFrames - stats.GetDecodedFrames();
-    playbackJitter = stats.GetPlaybackJitter();
+
+  if (sVideoStatsEnabled) {
+    nsPIDOMWindow* window = OwnerDoc()->GetInnerWindow();
+    if (window) {
+      nsPerformance* perf = window->GetPerformance();
+      if (perf) {
+        creationTime = perf->GetDOMTiming()->TimeStampToDOMHighRes(TimeStamp::Now());
+      }
+    }
+
+    if (mDecoder) {
+      MediaDecoder::FrameStatistics& stats = mDecoder->GetFrameStatistics();
+      totalFrames = stats.GetParsedFrames();
+      droppedFrames = totalFrames - stats.GetPresentedFrames();
+      corruptedFrames = totalFrames - stats.GetDecodedFrames();
+      playbackJitter = stats.GetPlaybackJitter();
+    }
   }
 
   nsRefPtr<VideoPlaybackQuality> playbackQuality =
     new VideoPlaybackQuality(this, creationTime, totalFrames, droppedFrames,
                              corruptedFrames, playbackJitter);
   return playbackQuality.forget();
 }
 
--- a/content/media/test/Makefile.in
+++ b/content/media/test/Makefile.in
@@ -135,16 +135,18 @@ MOCHITEST_FILES = \
 		test_streams_autoplay.html \
 		test_streams_gc.html \
 		test_streams_tracks.html \
 		$(filter disabled-for-intermittent-failures--bug-608634, test_error_in_video_document.html) \
 		test_texttrack.html \
 		test_texttrackcue.html \
 		test_timeupdate_small_files.html \
 		test_unseekable.html \
+		test_VideoPlaybackQuality.html \
+		test_VideoPlaybackQuality_disabled.html \
 		test_webvtt_disabled.html \
 		$(NULL)
 
 # Disabled on Windows for frequent intermittent failures
 ifneq ($(OS_ARCH), WINNT)
 MOCHITEST_FILES += \
 		test_streams_element_capture.html \
 		test_streams_element_capture_reset.html \
new file mode 100644
--- /dev/null
+++ b/content/media/test/test_VideoPlaybackQuality.html
@@ -0,0 +1,62 @@
+<!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");
+  is(vpq.playbackJitter, 0, "playbackJitter 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.corruptedVideoFrames >= 0, "corruptedVideoFrames should be >= 0");
+    ok(vpq.playbackJitter >= 0, "playbackJitter 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");
+      is(vpq.playbackJitter, 0, "playbackJitter should be 0");
+
+      SimpleTest.finish();
+    });
+  });
+}
+
+addLoadEvent(function() {
+  SpecialPowers.pushPrefEnv({"set": [["media.mediasource.enabled", true]]}, test);
+});
+</script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/content/media/test/test_VideoPlaybackQuality_disabled.html
@@ -0,0 +1,33 @@
+<!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 hidden behind a pref");
+  var accessThrows = false;
+  try {
+    video.getVideoPlaybackQuality();
+  } catch (e) {
+    accessThrows = true;
+  }
+  ok(accessThrows, "getVideoPlaybackQuality should be hidden behind a pref");
+  SimpleTest.finish();
+}
+
+addLoadEvent(function() {
+  SpecialPowers.pushPrefEnv({"set": [["media.mediasource.enabled", false]]}, test);
+});
+</script>
+</pre>
+</body>
+</html>
--- a/dom/webidl/VideoPlaybackQuality.webidl
+++ b/dom/webidl/VideoPlaybackQuality.webidl
@@ -7,14 +7,15 @@
  * http://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 [Pref="media.mediasource.enabled"]
 interface VideoPlaybackQuality {
+  readonly attribute DOMHighResTimeStamp creationTime;
   readonly attribute unsigned long totalVideoFrames;
   readonly attribute unsigned long droppedVideoFrames;
   readonly attribute unsigned long corruptedVideoFrames;
   readonly attribute double playbackJitter;
 };