Commit 26561f43 authored by Dale Curtis's avatar Dale Curtis Committed by Commit Bot

Add suspend/resume tests for MSE.

This adds three tests: before metadata, after metadata, and after
have enough. It doesn't clone the have future data test that src=
has since has_future_data == has_enough_data when using MSE.

BUG=756897
TEST=all tests!

Change-Id: I99c2cff3668c471bcd3d3d4549e53690788b0813
Reviewed-on: https://chromium-review.googlesource.com/989073Reviewed-by: default avatarChrome Cunningham <chcunningham@chromium.org>
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548575}
parent e8bea50f
...@@ -266,7 +266,10 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl ...@@ -266,7 +266,10 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
void ActivateViewportIntersectionMonitoring(bool activate) override; void ActivateViewportIntersectionMonitoring(bool activate) override;
void UpdateRemotePlaybackCompatibility(bool is_compatible) override; void UpdateRemotePlaybackCompatibility(bool is_compatible) override;
// Test helper methods for exercising media suspension. // Test helper methods for exercising media suspension. Once called, when
// |target_state| is reached or exceeded the stale flag will be set when
// computing the play state, which will trigger suspend if the player is
// paused; see UpdatePlayState_ComputePlayState() for the exact details.
void ForceStaleStateForTesting(ReadyState target_state) override; void ForceStaleStateForTesting(ReadyState target_state) override;
bool IsSuspendedForTesting() override; bool IsSuspendedForTesting() override;
......
<!DOCTYPE html>
<script src="/w3c/resources/testharness.js"></script>
<script src="/w3c/resources/testharnessreport.js"></script>
<script src="/media-resources/suspend-util.js"></script>
<script src="mediasource-util.js"></script>
<link rel="stylesheet" href="/w3c/resources/testharness.css">
<div id="log"></div>
<script>
mediasource_testafterdataloaded(function(
test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) {
suspendMediaElement(mediaElement, HTMLMediaElement.HAVE_ENOUGH_DATA, function() {
completeTestUponPlayback(test, mediaElement);
});
test.expectEvent(sourceBuffer, 'updateend', 'init append ended.');
var init = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
sourceBuffer.appendBuffer(init);
test.waitForExpectedEvents(function() {
var mediaSegment =
MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
sourceBuffer.appendBuffer(mediaSegment);
});
}, 'Test that a media element using MSE can be resumed after an idle suspend initiated during the HAVE_ENOUGH_DATA ready state.');
</script>
<!DOCTYPE html>
<script src="/w3c/resources/testharness.js"></script>
<script src="/w3c/resources/testharnessreport.js"></script>
<script src="/media-resources/suspend-util.js"></script>
<script src="mediasource-util.js"></script>
<link rel="stylesheet" href="/w3c/resources/testharness.css">
<div id="log"></div>
<script>
mediasource_testafterdataloaded(function(
test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) {
suspendMediaElement(mediaElement, HTMLMediaElement.HAVE_METADATA, function() {
// Upgrade the stale flag to a higher state now to wakeup the element. In
// a normal flow the stale flag can not be set prior to have future data.
completeTestUponPlayback(test, mediaElement);
window.internals.forceStaleStateForMediaElement(
mediaElement, HTMLMediaElement.HAVE_ENOUGH_DATA);
});
test.expectEvent(sourceBuffer, 'updateend', 'init append ended.');
var init = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
sourceBuffer.appendBuffer(init);
test.waitForExpectedEvents(function() {
var mediaSegment =
MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
sourceBuffer.appendBuffer(mediaSegment);
});
}, 'Test that a media element using MSE can be resumed after an idle suspend initiated during the HAVE_METADATA ready state.');
</script>
<!DOCTYPE html>
<script src="/w3c/resources/testharness.js"></script>
<script src="/w3c/resources/testharnessreport.js"></script>
<script src="/media-resources/suspend-util.js"></script>
<script src="mediasource-util.js"></script>
<link rel="stylesheet" href="/w3c/resources/testharness.css">
<div id="log"></div>
<script>
mediasource_testafterdataloaded(function(
test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) {
suspendMediaElement(mediaElement, HTMLMediaElement.HAVE_NOTHING, function() {
// Upgrade the stale flag to a higher state now to wakeup the element. In
// a normal flow the stale flag can not be set prior to have future data.
completeTestUponPlayback(test, mediaElement);
window.internals.forceStaleStateForMediaElement(
mediaElement, HTMLMediaElement.HAVE_ENOUGH_DATA);
});
test.expectEvent(sourceBuffer, 'updateend', 'init append ended.');
var init = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
sourceBuffer.appendBuffer(init);
test.waitForExpectedEvents(function() {
var mediaSegment =
MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
sourceBuffer.appendBuffer(mediaSegment);
});
}, 'Test that a media element using MSE can be resumed after an idle suspend initiated before the HAVE_METADATA ready state.');
</script>
// Requests that |video| suspends upon reaching or exceeding |expectedState|;
// |callback| will be called once the suspend is detected.
function suspendMediaElement(video, expectedState, callback) { function suspendMediaElement(video, expectedState, callback) {
var pollSuspendState = function() { var pollSuspendState = function() {
if (!window.internals.isMediaElementSuspended(video)) { if (!window.internals.isMediaElementSuspended(video)) {
...@@ -12,10 +14,8 @@ function suspendMediaElement(video, expectedState, callback) { ...@@ -12,10 +14,8 @@ function suspendMediaElement(video, expectedState, callback) {
window.internals.forceStaleStateForMediaElement(video, expectedState); window.internals.forceStaleStateForMediaElement(video, expectedState);
} }
function preloadMetadataSuspendTest(t, video, src, expectSuspend) { // Calls play() on |video| and executes t.done() when currentTime > 0.
assert_true(!!window.internals, 'This test requires windows.internals.'); function completeTestUponPlayback(t, video) {
video.onerror = t.unreached_func();
var timeWatcher = t.step_func(function() { var timeWatcher = t.step_func(function() {
if (video.currentTime > 0) { if (video.currentTime > 0) {
assert_false(window.internals.isMediaElementSuspended(video)); assert_false(window.internals.isMediaElementSuspended(video));
...@@ -25,6 +25,14 @@ function preloadMetadataSuspendTest(t, video, src, expectSuspend) { ...@@ -25,6 +25,14 @@ function preloadMetadataSuspendTest(t, video, src, expectSuspend) {
} }
}); });
window.requestAnimationFrame(timeWatcher);
video.play();
}
function preloadMetadataSuspendTest(t, video, src, expectSuspend) {
assert_true(!!window.internals, 'This test requires windows.internals.');
video.onerror = t.unreached_func();
var eventListener = t.step_func(function() { var eventListener = t.step_func(function() {
assert_equals(expectSuspend, assert_equals(expectSuspend,
window.internals.isMediaElementSuspended(video)); window.internals.isMediaElementSuspended(video));
...@@ -33,8 +41,7 @@ function preloadMetadataSuspendTest(t, video, src, expectSuspend) { ...@@ -33,8 +41,7 @@ function preloadMetadataSuspendTest(t, video, src, expectSuspend) {
return; return;
} }
window.requestAnimationFrame(timeWatcher); completeTestUponPlayback(t, video);
video.play();
}); });
video.addEventListener('loadedmetadata', eventListener, false); video.addEventListener('loadedmetadata', eventListener, false);
...@@ -45,21 +52,11 @@ function suspendTest(t, video, src, expectedState) { ...@@ -45,21 +52,11 @@ function suspendTest(t, video, src, expectedState) {
assert_true(!!window.internals, 'This test requires windows.internals.'); assert_true(!!window.internals, 'This test requires windows.internals.');
video.onerror = t.unreached_func(); video.onerror = t.unreached_func();
var timeWatcher = t.step_func(function() {
if (video.currentTime > 0) {
assert_false(window.internals.isMediaElementSuspended(video));
t.done();
} else {
window.requestAnimationFrame(timeWatcher);
}
});
// We can't force a suspend state until loading has started. // We can't force a suspend state until loading has started.
video.addEventListener('loadstart', t.step_func(function() { video.addEventListener('loadstart', t.step_func(function() {
suspendMediaElement(video, expectedState, t.step_func(function() { suspendMediaElement(video, expectedState, t.step_func(function() {
assert_true(window.internals.isMediaElementSuspended(video)); assert_true(window.internals.isMediaElementSuspended(video));
window.requestAnimationFrame(timeWatcher); completeTestUponPlayback(t, video);
video.play();
})); }));
}), false); }), false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment