Commit 92842b6a authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Add WebEngineIntegrationTests.PlayVideo test

Previously there were tests that play audio and tests that play video,
but no tests were playing a file with both audio and video. Also video
was not played to the end. Added PlayVideo test that plays
bear-vp9-opus.webm to the end. Also updated SetBlockMediaLoading tests
to share play_video.html and reduce amount of duplicated code.

Bug: b/153914562
Change-Id: Iba492ec252f692f7aa3f93c319d858a91bb38278
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2219404
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773338}
parent 88278d2e
......@@ -16,7 +16,10 @@
bear.onpause = function () { isPlaying = false; }
bear.onplay = function() { document.title = 'playing'; }
bear.onstalled = function() { document.title = 'stalled'; }
bear.src = 'bear-vp8a.webm';
bear.onended = function() { document.title = 'ended'; }
bear.src = 'bear-vp9-opus.webm';
document.body.appendChild(bear);
</script>
</body>
</html>
......@@ -121,6 +121,31 @@ class WebEngineIntegrationTest : public testing::Test {
return create_params;
}
// Returns CreateContextParams that has AUDIO feature enabled with an injected
// FakeAudioConsumerService.
fuchsia::web::CreateContextParams ContextParamsWithAudio() {
// Use a FilteredServiceDirectory in order to inject a fake AudioConsumer
// service.
fuchsia::web::CreateContextParams create_params =
ContextParamsWithFilteredServiceDirectory();
fake_audio_consumer_service_ =
std::make_unique<media::FakeAudioConsumerService>(
filtered_service_directory_->outgoing_directory()
->GetOrCreateDirectory("svc"));
create_params.set_features(fuchsia::web::ContextFeatureFlags::AUDIO);
return create_params;
}
fuchsia::web::CreateContextParams ContextParamsWithAudioAndTestData() {
fuchsia::web::CreateContextParams create_params = ContextParamsWithAudio();
create_params.mutable_content_directories()->push_back(
CreateTestDataDirectoryProvider());
return create_params;
}
void CreateNavigationListener() {
// Attach a navigation listener, to monitor the state of the Frame.
navigation_listener_ =
......@@ -170,6 +195,12 @@ class WebEngineIntegrationTest : public testing::Test {
navigation_listener_->RunUntilUrlEquals(url);
}
void LoadUrlWithUserActivation(base::StringPiece url) {
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(),
cr_fuchsia::CreateLoadUrlParamsWithUserActivation(), url));
}
void GrantPermission(fuchsia::web::PermissionType type,
const std::string& origin) {
fuchsia::web::PermissionDescriptor permission;
......@@ -218,6 +249,8 @@ class WebEngineIntegrationTest : public testing::Test {
std::unique_ptr<base::fuchsia::FilteredServiceDirectory>
filtered_service_directory_;
std::unique_ptr<media::FakeAudioConsumerService> fake_audio_consumer_service_;
DISALLOW_COPY_AND_ASSIGN(WebEngineIntegrationTest);
};
......@@ -470,41 +503,36 @@ TEST_F(WebEngineIntegrationTest, ContentDirectoryProvider) {
TEST_F(WebEngineIntegrationTest, PlayAudio) {
StartWebEngine();
// Use a FilteredServiceDirectory in order to inject a fake AudioConsumer
// service.
fuchsia::web::CreateContextParams create_params =
ContextParamsWithFilteredServiceDirectory();
media::FakeAudioConsumerService fake_audio_consumer_service(
filtered_service_directory_->outgoing_directory()->GetOrCreateDirectory(
"svc"));
create_params.mutable_content_directories()->push_back(
CreateTestDataDirectoryProvider());
create_params.set_features(fuchsia::web::ContextFeatureFlags::AUDIO);
CreateContextAndFrame(std::move(create_params));
CreateContextAndFrame(ContextParamsWithAudioAndTestData());
static uint16_t kTestMediaSessionId = 43;
frame_->SetMediaSessionId(kTestMediaSessionId);
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(),
cr_fuchsia::CreateLoadUrlParamsWithUserActivation(),
"fuchsia-dir://testdata/play_audio.html"));
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_audio.html");
navigation_listener_->RunUntilTitleEquals("ended");
ASSERT_EQ(fake_audio_consumer_service.num_instances(), 1U);
ASSERT_EQ(fake_audio_consumer_service_->num_instances(), 1U);
auto pos = fake_audio_consumer_service.instance(0)->GetMediaPosition();
auto pos = fake_audio_consumer_service_->instance(0)->GetMediaPosition();
EXPECT_GT(pos, base::TimeDelta::FromSecondsD(2.0));
EXPECT_LT(pos, base::TimeDelta::FromSecondsD(2.5));
EXPECT_EQ(fake_audio_consumer_service.instance(0)->session_id(),
EXPECT_EQ(fake_audio_consumer_service_->instance(0)->session_id(),
kTestMediaSessionId);
EXPECT_EQ(fake_audio_consumer_service.instance(0)->volume(), 1.0);
EXPECT_FALSE(fake_audio_consumer_service.instance(0)->is_muted());
EXPECT_EQ(fake_audio_consumer_service_->instance(0)->volume(), 1.0);
EXPECT_FALSE(fake_audio_consumer_service_->instance(0)->is_muted());
}
TEST_F(WebEngineIntegrationTest, PlayVideo) {
StartWebEngine();
CreateContextAndFrame(ContextParamsWithAudioAndTestData());
frame_->SetBlockMediaLoading(false);
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
navigation_listener_->RunUntilTitleEquals("ended");
}
void WebEngineIntegrationTest::RunPermissionTest(bool grant) {
......@@ -536,10 +564,7 @@ TEST_F(WebEngineIntegrationTest, PermissionGranted) {
TEST_F(WebEngineIntegrationTest, MicrophoneAccess_WithPermission) {
StartWebEngine();
fuchsia::web::CreateContextParams create_params = DefaultContextParams();
create_params.set_features(fuchsia::web::ContextFeatureFlags::AUDIO);
CreateContextAndFrame(std::move(create_params));
CreateContextAndFrame(ContextParamsWithAudio());
GrantPermission(fuchsia::web::PermissionType::MICROPHONE,
embedded_test_server_.GetURL("/").GetOrigin().spec());
......@@ -553,10 +578,7 @@ TEST_F(WebEngineIntegrationTest, MicrophoneAccess_WithPermission) {
TEST_F(WebEngineIntegrationTest, MicrophoneAccess_WithoutPermission) {
StartWebEngine();
fuchsia::web::CreateContextParams create_params = DefaultContextParams();
create_params.set_features(fuchsia::web::ContextFeatureFlags::AUDIO);
CreateContextAndFrame(std::move(create_params));
CreateContextAndFrame(ContextParamsWithAudio());
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(), fuchsia::web::LoadUrlParams(),
......@@ -567,19 +589,11 @@ TEST_F(WebEngineIntegrationTest, MicrophoneAccess_WithoutPermission) {
TEST_F(WebEngineIntegrationTest, SetBlockMediaLoading_Blocked) {
StartWebEngine();
fuchsia::web::CreateContextParams create_params =
DefaultContextParamsWithTestData();
auto features = fuchsia::web::ContextFeatureFlags::AUDIO;
create_params.set_features(features);
CreateContextAndFrame(std::move(create_params));
CreateContextAndFrame(ContextParamsWithAudioAndTestData());
frame_->SetBlockMediaLoading(true);
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(),
cr_fuchsia::CreateLoadUrlParamsWithUserActivation(),
"fuchsia-dir://testdata/play_vp8.html?autoplay"));
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
// Check different indicators that media has not loaded and is not playing.
navigation_listener_->RunUntilTitleEquals("stalled");
......@@ -593,19 +607,11 @@ TEST_F(WebEngineIntegrationTest, SetBlockMediaLoading_Blocked) {
// it begins playing, since autoplay=true.
TEST_F(WebEngineIntegrationTest, SetBlockMediaLoading_AfterUnblock) {
StartWebEngine();
fuchsia::web::CreateContextParams create_params =
DefaultContextParamsWithTestData();
auto features = fuchsia::web::ContextFeatureFlags::AUDIO;
create_params.set_features(features);
CreateContextAndFrame(std::move(create_params));
CreateContextAndFrame(ContextParamsWithAudioAndTestData());
frame_->SetBlockMediaLoading(true);
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(),
cr_fuchsia::CreateLoadUrlParamsWithUserActivation(),
"fuchsia-dir://testdata/play_vp8.html?autoplay"));
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
// Check that media loading has been blocked.
navigation_listener_->RunUntilTitleEquals("stalled");
......@@ -621,17 +627,9 @@ TEST_F(WebEngineIntegrationTest, SetBlockMediaLoading_AfterUnblock) {
// element has started loading that media will play when play() is called.
TEST_F(WebEngineIntegrationTest, SetBlockMediaLoading_SetBlockedAfterLoading) {
StartWebEngine();
CreateContextAndFrame(ContextParamsWithAudioAndTestData());
fuchsia::web::CreateContextParams create_params =
DefaultContextParamsWithTestData();
auto features = fuchsia::web::ContextFeatureFlags::AUDIO;
create_params.set_features(features);
CreateContextAndFrame(std::move(create_params));
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(),
cr_fuchsia::CreateLoadUrlParamsWithUserActivation(),
"fuchsia-dir://testdata/play_vp8.html"));
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html");
navigation_listener_->RunUntilTitleEquals("loaded");
frame_->SetBlockMediaLoading(true);
......
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