Bug 889201 - Add tests for VideoPlaybackQuality. r=roc

This commit is contained in:
Matthew Gregan 2013-07-05 12:24:55 +12:00
parent b61fe1fbac
commit dbcfe9d22f
5 changed files with 115 additions and 14 deletions

View File

@ -262,24 +262,27 @@ 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 =

View File

@ -141,6 +141,8 @@ MOCHITEST_FILES = \
test_texttrackcue.html \
test_timeupdate_small_files.html \
test_unseekable.html \
test_VideoPlaybackQuality.html \
test_VideoPlaybackQuality_disabled.html \
test_webvtt_disabled.html \
$(NULL)

View File

@ -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>

View File

@ -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>

View File

@ -12,6 +12,7 @@
[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;