Commit 6438cf1f authored by Dale Curtis's avatar Dale Curtis Committed by Commit Bot

Simplify suspend/resume testing by having WMP suspend based on state.

This removes the need for stalled loading to force states on the WMPI
pipeline by instead having WMPI suspend once it reaches one of the
target states.

This provides equivalent coverage with much faster testing.

BUG=819194,817705,756897
TEST=no more flaky tests.

Change-Id: I1fa9e1ff6d165ed7921abf62127d3c2cd89f5707
Reviewed-on: https://chromium-review.googlesource.com/980802Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546704}
parent dae40d73
......@@ -2519,8 +2519,12 @@ WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote,
PlayState result;
bool must_suspend = delegate_->IsFrameClosed();
bool is_stale = stale_state_override_for_testing_.value_or(
delegate_->IsStale(delegate_id_));
bool is_stale = delegate_->IsStale(delegate_id_);
if (stale_state_override_for_testing_.has_value() &&
ready_state_ >= stale_state_override_for_testing_.value()) {
is_stale = true;
}
// This includes both data source (before pipeline startup) and pipeline
// errors.
......@@ -2794,8 +2798,8 @@ void WebMediaPlayerImpl::UpdateRemotePlaybackCompatibility(bool is_compatible) {
client_->RemotePlaybackCompatibilityChanged(loaded_url_, is_compatible);
}
void WebMediaPlayerImpl::ForceStaleStateForTesting() {
stale_state_override_for_testing_.emplace(true);
void WebMediaPlayerImpl::ForceStaleStateForTesting(ReadyState target_state) {
stale_state_override_for_testing_.emplace(target_state);
UpdatePlayState();
}
......
......@@ -266,7 +266,7 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
void UpdateRemotePlaybackCompatibility(bool is_compatible) override;
// Test helper methods for exercising media suspension.
void ForceStaleStateForTesting() override;
void ForceStaleStateForTesting(ReadyState target_state) override;
bool IsSuspendedForTesting() override;
// Called from WebMediaPlayerCast.
......@@ -880,7 +880,7 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
mojom::MediaMetricsProviderPtr media_metrics_provider_;
base::Optional<bool> stale_state_override_for_testing_;
base::Optional<ReadyState> stale_state_override_for_testing_;
// True if we attempt to start the media pipeline in a suspended state for
// preload=metadata. Cleared upon pipeline startup.
......
......@@ -70,6 +70,3 @@ crbug.com/803276 inspector-protocol/memory/sampling-native-snapshot.js [ Skip ]
crbug.com/803276 virtual/sampling-heap-profiler/inspector-protocol/memory/sampling-native-profile.js [ Skip ]
crbug.com/803276 virtual/sampling-heap-profiler/inspector-protocol/memory/sampling-native-snapshot.js [ Skip ]
# Tests timing out sometimes on WebKit Linux Trusty ASAN/MSAN
crbug.com/681919 [ Linux ] http/tests/media/media-src-suspend-after-have-metadata.html [ Timeout Pass ]
crbug.com/681919 [ Linux ] http/tests/media/media-src-suspend-before-have-metadata.html [ Timeout Pass ]
......@@ -98,6 +98,3 @@ crbug.com/803276 inspector-protocol/memory/sampling-native-snapshot.js [ Skip ]
crbug.com/803276 virtual/sampling-heap-profiler/inspector-protocol/memory/sampling-native-profile.js [ Skip ]
crbug.com/803276 virtual/sampling-heap-profiler/inspector-protocol/memory/sampling-native-snapshot.js [ Skip ]
# Tests timing out sometimes on WebKit Linux Trusty ASAN/MSAN
crbug.com/681919 [ Linux ] http/tests/media/media-src-suspend-after-have-metadata.html [ Timeout Pass ]
crbug.com/681919 [ Linux ] http/tests/media/media-src-suspend-before-have-metadata.html [ Timeout Pass ]
......@@ -146,9 +146,6 @@ crbug.com/680917 http/tests/devtools/audits2/ [ Slow ]
# These tests are intentionally SLOW because of throttled loading.
crbug.com/73609 http/tests/media/video-play-stall.html [ Slow ]
crbug.com/73609 http/tests/media/video-preload-metadata.html [ Slow ]
crbug.com/694855 http/tests/media/media-src-suspend-after-have-metadata.html [ Slow ]
crbug.com/694855 http/tests/media/media-src-suspend-after-have-future-data.html [ Slow ]
crbug.com/694855 http/tests/media/media-src-suspend-before-have-metadata.html [ Slow ]
# Many of the virtual animations tests are slow.
crbug.com/311482 virtual/threaded/animations/prefixed/keyframes-unprefixed-03.html [ Slow ]
......
......@@ -3346,10 +3346,6 @@ crbug.com/806249 virtual/unified-autoplay/external/wpt/feature-policy/picture-in
# Sheriff 2018-03-05
crbug.com/818650 [ Linux ] fast/speech/scripted/speechrecognition-restart-onend.html [ Crash Pass ]
# Sheriff 2018-03-06
crbug.com/681919 [ Linux Debug ] http/tests/media/media-src-suspend-after-have-metadata.html [ Timeout Pass ]
crbug.com/681919 [ Linux Debug ] http/tests/media/media-src-suspend-before-have-metadata.html [ Timeout Pass ]
# Sheriff 2018-03-07
crbug.com/819778 [ Linux ] external/wpt/css/cssom-view/interfaces.html [ Pass Timeout ]
......
<!DOCTYPE html>
<title>Verify that a media element can be resumed after an idle suspend initiated during the HAVE_FUTURE_DATA ready state.</title>
<script src="/w3c/resources/testharness.js"></script>
<script src="/w3c/resources/testharnessreport.js"></script>
<script src="/media-resources/suspend-util.js"></script>
<video></video>
<script>
async_test(function(t) {
var video = document.querySelector('video');
// preload=auto must be set to ensure canplay and canplaythrough are separate.
video.preload = 'auto';
// Use a .webm to ensure metadata is near the beginning of the file; throttle
// limit is set just after metadata block to avoid test timeouts.
var mediaFile = 'http://127.0.0.1:8000/media/video-throttled-load.cgi?' +
'nph=1&name=resources/media-source/webm/test.webm' +
'&throttle=25&type=video/webm&limit=50000&avoidCache=' +
Math.random();
suspendTest(t, video, mediaFile, 'canplay',
HTMLMediaElement.HAVE_FUTURE_DATA);
});
</script>
<!DOCTYPE html>
<title>Verify that a media element can be resumed after an idle suspend initiated during the HAVE_METADATA ready state.</title>
<script src="/w3c/resources/testharness.js"></script>
<script src="/w3c/resources/testharnessreport.js"></script>
<script src="/media-resources/suspend-util.js"></script>
<video></video>
<script>
async_test(function(t) {
var video = document.querySelector('video');
// Use a .webm to ensure metadata is near the beginning of the file; throttle
// limit is set just after metadata block to avoid test timeouts.
var mediaFile = 'http://127.0.0.1:8000/media/video-throttled-load.cgi?' +
'nph=1&name=resources/media-source/webm/test.webm' +
'&throttle=60&type=video/webm&limit=42000&avoidCache=' +
Math.random();
suspendTest(t, document.querySelector('video'), mediaFile, 'loadedmetadata',
HTMLMediaElement.HAVE_METADATA);
});
</script>
<!DOCTYPE html>
<title>Verify that a media element can be resumed after an idle suspend initiated before the HAVE_METADATA ready state.</title>
<script src="/w3c/resources/testharness.js"></script>
<script src="/w3c/resources/testharnessreport.js"></script>
<script src="/media-resources/suspend-util.js"></script>
<video></video>
<script>
async_test(function(t) {
// Use a .webm to ensure metadata is near the beginning of the file; throttle
// limit is set just after metadata block to avoid test timeouts.
var mediaFile = 'http://127.0.0.1:8000/media/video-throttled-load.cgi?' +
'nph=1&name=resources/media-source/webm/test.webm' +
'&throttle=60&type=video/webm&limit=42000&avoidCache=' +
Math.random();
suspendTest(t, document.querySelector('video'), mediaFile, 'loadstart',
HTMLMediaElement.HAVE_NOTHING);
});
</script>
......@@ -7,6 +7,6 @@
<script>
async_test(function(t) {
suspendTest(t, document.querySelector('video'), 'content/test.webm',
'canplaythrough', HTMLMediaElement.HAVE_ENOUGH_DATA);
HTMLMediaElement.HAVE_ENOUGH_DATA);
});
</script>
<!DOCTYPE html>
<title>Verify that a media element can be resumed after an idle suspend initiated during the HAVE_FUTURE_DATA ready state.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="suspend-util.js"></script>
<video></video>
<script>
async_test(function(t) {
suspendTest(t, document.querySelector('video'), 'content/test.webm',
HTMLMediaElement.HAVE_FUTURE_DATA);
});
</script>
<!DOCTYPE html>
<title>Verify that a media element can be resumed after an idle suspend initiated during the HAVE_METADATA ready state.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="suspend-util.js"></script>
<video></video>
<script>
async_test(function(t) {
suspendTest(t, document.querySelector('video'), 'content/test.webm',
HTMLMediaElement.HAVE_METADATA);
});
</script>
<!DOCTYPE html>
<title>Verify that a media element can be resumed after an idle suspend initiated before the HAVE_METADATA ready state.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="suspend-util.js"></script>
<video></video>
<script>
async_test(function(t) {
suspendTest(t, document.querySelector('video'), 'content/test.webm',
HTMLMediaElement.HAVE_NOTHING);
});
</script>
function suspendMediaElement(video, callback) {
function suspendMediaElement(video, expectedState, callback) {
var pollSuspendState = function() {
if (!window.internals.isMediaElementSuspended(video)) {
window.requestAnimationFrame(pollSuspendState);
......@@ -9,7 +9,7 @@ function suspendMediaElement(video, callback) {
};
window.requestAnimationFrame(pollSuspendState);
window.internals.forceStaleStateForMediaElement(video);
window.internals.forceStaleStateForMediaElement(video, expectedState);
}
function preloadMetadataSuspendTest(t, video, src, expectSuspend) {
......@@ -41,7 +41,7 @@ function preloadMetadataSuspendTest(t, video, src, expectSuspend) {
video.src = src;
}
function suspendTest(t, video, src, eventName, expectedState) {
function suspendTest(t, video, src, expectedState) {
assert_true(!!window.internals, 'This test requires windows.internals.');
video.onerror = t.unreached_func();
......@@ -54,17 +54,14 @@ function suspendTest(t, video, src, eventName, expectedState) {
}
});
var eventListener = t.step_func(function() {
assert_equals(video.readyState, expectedState);
suspendMediaElement(video, t.step_func(function() {
// We can't force a suspend state until loading has started.
video.addEventListener('loadstart', t.step_func(function() {
suspendMediaElement(video, expectedState, t.step_func(function() {
assert_true(window.internals.isMediaElementSuspended(video));
window.requestAnimationFrame(timeWatcher);
video.play();
}));
}), false);
video.removeEventListener(eventName, eventListener, false);
});
video.addEventListener(eventName, eventListener, false);
video.src = src;
}
......@@ -2496,11 +2496,21 @@ void Internals::setPersistent(HTMLVideoElement* video_element,
video_element->OnBecamePersistentVideo(persistent);
}
void Internals::forceStaleStateForMediaElement(
HTMLMediaElement* media_element) {
void Internals::forceStaleStateForMediaElement(HTMLMediaElement* media_element,
int target_state) {
DCHECK(media_element);
if (auto wmp = media_element->GetWebMediaPlayer())
wmp->ForceStaleStateForTesting();
// Even though this is an internals method, the checks are necessary to
// prevent fuzzers from taking this path and generating useless noise.
if (target_state < static_cast<int>(WebMediaPlayer::kReadyStateHaveNothing) ||
target_state >
static_cast<int>(WebMediaPlayer::kReadyStateHaveEnoughData)) {
return;
}
if (auto wmp = media_element->GetWebMediaPlayer()) {
wmp->ForceStaleStateForTesting(
static_cast<WebMediaPlayer::ReadyState>(target_state));
}
}
bool Internals::isMediaElementSuspended(HTMLMediaElement* media_element) {
......
......@@ -392,7 +392,7 @@ class Internals final : public ScriptWrappable {
void mediaPlayerPlayingRemotelyChanged(HTMLMediaElement*, bool);
void setMediaElementNetworkState(HTMLMediaElement*, int state);
void setPersistent(HTMLVideoElement*, bool);
void forceStaleStateForMediaElement(HTMLMediaElement*);
void forceStaleStateForMediaElement(HTMLMediaElement*, int target_state);
bool isMediaElementSuspended(HTMLMediaElement*);
void registerURLSchemeAsBypassingContentSecurityPolicy(const String& scheme);
......
......@@ -238,7 +238,7 @@ enum EffectiveConnectionType {
void mediaPlayerPlayingRemotelyChanged(HTMLMediaElement mediaElement, boolean remote);
void setMediaElementNetworkState(HTMLMediaElement element, long state);
void setPersistent(HTMLVideoElement video, boolean persistent);
void forceStaleStateForMediaElement(HTMLMediaElement mediaElement);
void forceStaleStateForMediaElement(HTMLMediaElement mediaElement, long state);
boolean isMediaElementSuspended(HTMLMediaElement mediaElement);
void registerURLSchemeAsBypassingContentSecurityPolicy(DOMString scheme);
......
......@@ -328,7 +328,7 @@ class WebMediaPlayer {
virtual void OnDisplayTypeChanged(DisplayType) {}
// Test helper methods for exercising media suspension.
virtual void ForceStaleStateForTesting() {}
virtual void ForceStaleStateForTesting(ReadyState target_state) {}
virtual bool IsSuspendedForTesting() { return 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