Commit 74ca9723 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Add WebEngineIntegrationTest.PlayAudio test

The new test plays a short audio file and verifies that the page
finishes playing it.

Bug: 1027048
Change-Id: I58a83098812c0e1b280a7ead5fdc7579b827d368
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1928116Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718248}
parent f504fe3e
......@@ -57,6 +57,13 @@ void TestNavigationListener::RunUntilUrlEquals(const GURL& expected_url) {
RunUntilNavigationStateMatches(state);
}
void TestNavigationListener::RunUntilTitleEquals(
const base::StringPiece expected_title) {
fuchsia::web::NavigationState state;
state.set_title(expected_title.as_string());
RunUntilNavigationStateMatches(state);
}
void TestNavigationListener::RunUntilUrlAndTitleEquals(
const GURL& expected_url,
const base::StringPiece expected_title) {
......
......@@ -30,16 +30,20 @@ class TestNavigationListener : public fuchsia::web::NavigationEventListener {
void RunUntilNavigationStateMatches(
const fuchsia::web::NavigationState& expected_state);
// Calls RunUntilNavigationStateMatches with a NagivationState that has
// Calls RunUntilNavigationStateMatches with a NavigationState that has
// |expected_url|.
void RunUntilUrlEquals(const GURL& expected_url);
// Calls RunUntilNavigationStateMatches with a NagivationState that has
// Calls RunUntilNavigationStateMatches with a NavigationState that has
// |expected_title|.
void RunUntilTitleEquals(const base::StringPiece expected_title);
// Calls RunUntilNavigationStateMatches with a NavigationState that has
// |expected_url| and |expected_title|.
void RunUntilUrlAndTitleEquals(const GURL& expected_url,
base::StringPiece expected_title);
// Calls RunUntilNavigationStateMatches with a NagivationState that has
// Calls RunUntilNavigationStateMatches with a NavigationState that has
// all the expected fields.
void RunUntilUrlTitleBackForwardEquals(const GURL& expected_url,
base::StringPiece expected_title,
......
<html>
<body>
<video></video>
<script>
window.onload = () => {
var video = document.getElementsByTagName("video")[0]
video.onerror = function() { document.title = 'error'; }
video.onended = function() { document.title = 'ended'; }
video.src = './bear-opus.webm';
video.play();
}
</script>
</body>
</html>
......@@ -60,6 +60,22 @@ class WebEngineIntegrationTest : public testing::Test {
return create_params;
}
fuchsia::web::CreateContextParams DefaultContextParamsWithTestData() const {
fuchsia::web::CreateContextParams create_params = DefaultContextParams();
fuchsia::web::ContentDirectoryProvider provider;
provider.set_name("testdata");
base::FilePath pkg_path;
CHECK(base::PathService::Get(base::DIR_ASSETS, &pkg_path));
provider.set_directory(base::fuchsia::OpenDirectory(
pkg_path.AppendASCII("fuchsia/engine/test/data")));
create_params.mutable_content_directories()->emplace_back(
std::move(provider));
return create_params;
}
void CreateContextAndFrame(fuchsia::web::CreateContextParams params) {
web_context_provider_->Create(std::move(params), context_.NewRequest());
context_.set_error_handler([](zx_status_t status) { ADD_FAILURE(); });
......@@ -322,31 +338,45 @@ TEST_F(WebEngineIntegrationTest, ContentDirectoryProvider) {
const GURL kUrl("fuchsia-dir://testdata/title1.html");
constexpr char kTitle[] = "title 1";
fuchsia::web::CreateContextParams create_params = DefaultContextParams();
fuchsia::web::ContentDirectoryProvider provider;
provider.set_name("testdata");
base::FilePath pkg_path;
CHECK(base::PathService::Get(base::DIR_ASSETS, &pkg_path));
provider.set_directory(base::fuchsia::OpenDirectory(
pkg_path.AppendASCII("fuchsia/engine/test/data")));
create_params.mutable_content_directories()->emplace_back(
std::move(provider));
fuchsia::web::CreateContextParams create_params =
DefaultContextParamsWithTestData();
CreateContextAndFrame(std::move(create_params));
fuchsia::web::NavigationControllerPtr controller;
frame_->GetNavigationController(controller.NewRequest());
controller.set_error_handler([](zx_status_t status) { ADD_FAILURE(); });
// Navigate to test1.html and verify that the resource was correctly
// downloaded and interpreted by inspecting the document title.
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
controller.get(), fuchsia::web::LoadUrlParams(), kUrl.spec()));
navigation_controller_.get(), fuchsia::web::LoadUrlParams(),
kUrl.spec()));
cr_fuchsia::TestNavigationListener navigation_listener;
fidl::Binding<fuchsia::web::NavigationEventListener> listener_binding(
&navigation_listener);
frame_->SetNavigationEventListener(listener_binding.NewBinding());
navigation_listener.RunUntilUrlAndTitleEquals(kUrl, kTitle);
}
TEST_F(WebEngineIntegrationTest, PlayAudio) {
fuchsia::web::CreateContextParams create_params =
DefaultContextParamsWithTestData();
auto features = fuchsia::web::ContextFeatureFlags::AUDIO;
if (create_params.has_features())
features |= create_params.features();
create_params.set_features(features);
CreateContextAndFrame(std::move(create_params));
fuchsia::web::LoadUrlParams load_url_params;
// |was_user_activated| needs to be set to ensure the page can play audio
// without user gesture.
load_url_params.set_was_user_activated(true);
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller_.get(), std::move(load_url_params),
"fuchsia-dir://testdata/play_audio.html"));
cr_fuchsia::TestNavigationListener navigation_listener;
fidl::Binding<fuchsia::web::NavigationEventListener> listener_binding(
&navigation_listener);
frame_->SetNavigationEventListener(listener_binding.NewBinding());
navigation_listener.RunUntilTitleEquals("ended");
}
......@@ -10,6 +10,7 @@
"fuchsia.device.NameProvider",
"fuchsia.fonts.Provider",
"fuchsia.logger.LogSink",
"fuchsia.media.Audio",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.posix.socket.Provider",
......
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