Skip to content

Commit

Permalink
[Fuchsia] Add WebEngineIntegrationTestBase::LoadUrlAndExpectResponse()
Browse files Browse the repository at this point in the history
Many WebEngine integration tests were creating NavigationController
to call cr_fuchsia::LoadUrlAndExpectResponse(). Added
LoadUrlAndExpectResponse() in WebEngineIntegrationTestBase to avoid
duplicating that code in every test.

Bug: 1199928
Change-Id: I563229380631739168b76e08fcda92df40c74a10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2838447
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#875335}
  • Loading branch information
SergeyUlanov authored and Chromium LUCI CQ committed Apr 22, 2021
1 parent de318c8 commit 73eabc3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 46 deletions.
7 changes: 1 addition & 6 deletions fuchsia/engine/web_engine_integration_logging_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,8 @@ TEST_F(WebEngineIntegrationLoggingTest, SetJavaScriptLogLevel_DEBUG) {
CreateFrameWithParams(std::move(frame_params));
frame_->SetJavaScriptLogLevel(fuchsia::web::ConsoleLogLevel::DEBUG);

// Creating the NavigationController after configuring the Frame ensures that
// Frame calls have completed before NavigationController calls are processed.
auto navigation_controller = CreateNavigationController();

// Navigate to the test page, which will emit console logging.
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller.get(), fuchsia::web::LoadUrlParams(),
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
embedded_test_server_.GetURL(std::string("/") + kLogTestPageFileName)
.spec()));
navigation_listener()->RunUntilTitleEquals("ended");
Expand Down
67 changes: 34 additions & 33 deletions fuchsia/engine/web_engine_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ TEST_F(WebEngineIntegrationTest, RemoteDebuggingPort) {

// Navigate to a URL.
GURL url = embedded_test_server_.GetURL("/defaultresponse");
auto navigation_controller = CreateNavigationController();
ASSERT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller.get(), fuchsia::web::LoadUrlParams(), url.spec()));
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(url.spec()));
navigation_listener()->RunUntilUrlEquals(url);

base::Value devtools_list =
Expand Down Expand Up @@ -229,6 +227,7 @@ TEST_F(WebEngineIntegrationTest, RemoteDebuggingPort) {
// Tear down the debuggable Frame. The remote debugging service should have
// shut down.
base::RunLoop controller_run_loop;
auto navigation_controller = CreateNavigationController();
navigation_controller.set_error_handler(
[&controller_run_loop](zx_status_t) { controller_run_loop.Quit(); });
frame_.Unbind();
Expand Down Expand Up @@ -267,9 +266,7 @@ TEST_F(WebEngineIntegrationTest, ContentDirectoryProvider) {

// Navigate to test1.html and verify that the resource was correctly
// downloaded and interpreted by inspecting the document title.
auto navigation_controller = CreateNavigationController();
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller.get(), fuchsia::web::LoadUrlParams(), kUrl.spec()));
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(kUrl.spec()));
navigation_listener()->RunUntilUrlAndTitleEquals(kUrl, kTitle);
}

Expand All @@ -279,7 +276,9 @@ TEST_F(WebEngineIntegrationMediaTest, PlayAudio) {
static uint16_t kTestMediaSessionId = 43;
frame_->SetMediaSessionId(kTestMediaSessionId);

LoadUrlWithUserActivation("fuchsia-dir://testdata/play_audio.html");
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
"fuchsia-dir://testdata/play_audio.html",
cr_fuchsia::CreateLoadUrlParamsWithUserActivation()));

navigation_listener()->RunUntilTitleEquals("ended");

Expand Down Expand Up @@ -315,7 +314,9 @@ TEST_F(WebEngineIntegrationMediaTest, PlayAudio_NoFlag) {
[&is_requested](auto request) { is_requested = true; }));
ZX_CHECK(status == ZX_OK, status) << "AddPublicService";

LoadUrlWithUserActivation("fuchsia-dir://testdata/play_audio.html");
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
"fuchsia-dir://testdata/play_audio.html",
cr_fuchsia::CreateLoadUrlParamsWithUserActivation()));

navigation_listener()->RunUntilTitleEquals("error");
EXPECT_FALSE(is_requested);
Expand All @@ -324,7 +325,9 @@ TEST_F(WebEngineIntegrationMediaTest, PlayAudio_NoFlag) {
TEST_F(WebEngineIntegrationMediaTest, PlayVideo) {
CreateContextAndFrame(ContextParamsWithAudioAndTestData());

LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
"fuchsia-dir://testdata/play_video.html?autoplay",
cr_fuchsia::CreateLoadUrlParamsWithUserActivation()));

navigation_listener()->RunUntilTitleEquals("ended");
}
Expand All @@ -337,9 +340,7 @@ void WebEngineIntegrationTest::RunPermissionTest(bool grant) {
"fuchsia-dir://testdata/");
}

auto navigation_controller = CreateNavigationController();
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller.get(), fuchsia::web::LoadUrlParams(),
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
"fuchsia-dir://testdata/check_mic_permission.html"));

navigation_listener()->RunUntilTitleEquals(grant ? "granted" : "denied");
Expand All @@ -359,9 +360,7 @@ TEST_F(WebEngineIntegrationMediaTest, MicrophoneAccess_WithPermission) {
GrantPermission(fuchsia::web::PermissionType::MICROPHONE,
embedded_test_server_.GetURL("/").GetOrigin().spec());

auto navigation_controller = CreateNavigationController();
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller.get(), fuchsia::web::LoadUrlParams(),
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
embedded_test_server_.GetURL("/mic.html").spec()));

navigation_listener()->RunUntilTitleEquals("ended");
Expand All @@ -370,9 +369,7 @@ TEST_F(WebEngineIntegrationMediaTest, MicrophoneAccess_WithPermission) {
TEST_F(WebEngineIntegrationMediaTest, MicrophoneAccess_WithoutPermission) {
CreateContextAndFrame(ContextParamsWithAudioAndTestData());

auto navigation_controller = CreateNavigationController();
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller.get(), fuchsia::web::LoadUrlParams(),
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
embedded_test_server_.GetURL("/mic.html?NoPermission").spec()));

navigation_listener()->RunUntilTitleEquals("ended-NotFoundError");
Expand All @@ -383,7 +380,9 @@ TEST_F(WebEngineIntegrationMediaTest, SetBlockMediaLoading_Blocked) {

frame_->SetBlockMediaLoading(true);

LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
"fuchsia-dir://testdata/play_video.html?autoplay",
cr_fuchsia::CreateLoadUrlParamsWithUserActivation()));

// Check different indicators that media has not loaded and is not playing.
navigation_listener()->RunUntilTitleEquals("stalled");
Expand All @@ -400,7 +399,9 @@ TEST_F(WebEngineIntegrationMediaTest, SetBlockMediaLoading_AfterUnblock) {

frame_->SetBlockMediaLoading(true);

LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
"fuchsia-dir://testdata/play_video.html?autoplay",
cr_fuchsia::CreateLoadUrlParamsWithUserActivation()));

// Check that media loading has been blocked.
navigation_listener()->RunUntilTitleEquals("stalled");
Expand All @@ -418,7 +419,9 @@ TEST_F(WebEngineIntegrationMediaTest,
SetBlockMediaLoading_SetBlockedAfterLoading) {
CreateContextAndFrame(ContextParamsWithAudioAndTestData());

LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html");
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
"fuchsia-dir://testdata/play_video.html",
cr_fuchsia::CreateLoadUrlParamsWithUserActivation()));

navigation_listener()->RunUntilTitleEquals("loaded");
frame_->SetBlockMediaLoading(true);
Expand All @@ -429,9 +432,7 @@ TEST_F(WebEngineIntegrationMediaTest,
TEST_F(WebEngineIntegrationTest, WebGLContextAbsentWithoutVulkanFeature) {
CreateContextAndFrame(TestContextParams());

auto navigation_controller = CreateNavigationController();
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller.get(), fuchsia::web::LoadUrlParams(),
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
embedded_test_server_.GetURL("/webgl_presence.html").spec()));

navigation_listener()->RunUntilLoaded();
Expand All @@ -455,9 +456,7 @@ TEST_F(MAYBE_VulkanWebEngineIntegrationTest,
create_params.set_features(fuchsia::web::ContextFeatureFlags::VULKAN);
CreateContextAndFrame(std::move(create_params));

auto navigation_controller = CreateNavigationController();
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller.get(), fuchsia::web::LoadUrlParams(),
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
embedded_test_server_.GetURL("/webgl_presence.html").spec()));

navigation_listener()->RunUntilLoaded();
Expand Down Expand Up @@ -489,10 +488,8 @@ void WebEngineIntegrationCameraTest::RunCameraTest(bool grant_permission) {

const char* url =
grant_permission ? "/camera.html" : "/camera.html?NoPermission";
auto navigation_controller = CreateNavigationController();
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller.get(), fuchsia::web::LoadUrlParams(),
embedded_test_server_.GetURL(url).spec()));
ASSERT_NO_FATAL_FAILURE(
LoadUrlAndExpectResponse(embedded_test_server_.GetURL(url).spec()));

navigation_listener()->RunUntilTitleEquals("ended");
}
Expand Down Expand Up @@ -535,7 +532,9 @@ TEST_F(MAYBE_VulkanWebEngineIntegrationTest,
fuchsia::web::ContextFeatureFlags::AUDIO);
CreateContextAndFrame(std::move(create_params));

LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
"fuchsia-dir://testdata/play_video.html?autoplay",
cr_fuchsia::CreateLoadUrlParamsWithUserActivation()));
navigation_listener()->RunUntilTitleEquals("ended");

EXPECT_TRUE(is_requested);
Expand All @@ -556,7 +555,9 @@ TEST_F(WebEngineIntegrationMediaTest, HardwareVideoDecoderFlag_NotProvided) {
ContextParamsWithAudioAndTestData();
CreateContextAndFrame(std::move(create_params));

LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
"fuchsia-dir://testdata/play_video.html?autoplay",
cr_fuchsia::CreateLoadUrlParamsWithUserActivation()));

navigation_listener()->RunUntilTitleEquals("ended");

Expand Down
17 changes: 11 additions & 6 deletions fuchsia/engine/web_engine_integration_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,17 @@ void WebEngineIntegrationTestBase::CreateContextAndFrameAndLoadUrl(
navigation_listener_->RunUntilUrlEquals(url);
}

void WebEngineIntegrationTestBase::LoadUrlWithUserActivation(
base::StringPiece url) {
auto navigation_controller = CreateNavigationController();
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller.get(),
cr_fuchsia::CreateLoadUrlParamsWithUserActivation(), url));
void WebEngineIntegrationTestBase::LoadUrlAndExpectResponse(
base::StringPiece url,
fuchsia::web::LoadUrlParams load_url_params) {
// Connect a new NavigationController to ensure that LoadUrl() is processed
// after all other messages previously sent to the frame.
fuchsia::web::NavigationControllerPtr navigation_controller;
frame_->GetNavigationController(navigation_controller.NewRequest());
navigation_controller.set_error_handler(
[](zx_status_t status) { ADD_FAILURE(); });
ASSERT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
navigation_controller.get(), std::move(load_url_params), url));
}

void WebEngineIntegrationTestBase::GrantPermission(
Expand Down
4 changes: 3 additions & 1 deletion fuchsia/engine/web_engine_integration_test_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ class WebEngineIntegrationTestBase : public testing::Test {
void CreateContextAndFrameAndLoadUrl(fuchsia::web::CreateContextParams params,
const GURL& url);

void LoadUrlWithUserActivation(base::StringPiece url);
void LoadUrlAndExpectResponse(
base::StringPiece url,
fuchsia::web::LoadUrlParams load_url_params = {});

void GrantPermission(fuchsia::web::PermissionType type,
const std::string& origin);
Expand Down

0 comments on commit 73eabc3

Please sign in to comment.