Commit af53a26b authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] fix web_engine_integration_tests to use isolated WebEngine

Previously web_engine_integration_tests were using default WebEngine
instance. This approach creates several issues. Particularly WebEngine
that is being tested may not be the latest verstion installed on the
test system. Updated the tests to use Launcher API to start a new
instance of WebEngine. This approach will also allow to pass custom
flags to WebEngine, which will be useful for some tests.

Also fixed initialization order in ContextProviderMain

Change-Id: Id6ffbd9a498fa42531193c5e9c6d01a932591ca7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1938454
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719851}
parent 63d3d7eb
...@@ -316,6 +316,7 @@ test("web_engine_integration_tests") { ...@@ -316,6 +316,7 @@ test("web_engine_integration_tests") {
"//base/test:run_all_unittests", "//base/test:run_all_unittests",
"//fuchsia/base", "//fuchsia/base",
"//fuchsia/base:test_support", "//fuchsia/base:test_support",
"//third_party/fuchsia-sdk/sdk:fuchsia-sys",
"//third_party/fuchsia-sdk/sdk:fuchsia-web", "//third_party/fuchsia-sdk/sdk:fuchsia-web",
] ]
package_deps = [ [ package_deps = [ [
......
...@@ -44,13 +44,16 @@ int ContextProviderMain() { ...@@ -44,13 +44,16 @@ int ContextProviderMain() {
LOG(INFO) << "Starting WebEngine " << GetVersionString(); LOG(INFO) << "Starting WebEngine " << GetVersionString();
ContextProviderImpl context_provider; ContextProviderImpl context_provider;
base::fuchsia::ScopedServiceBinding<fuchsia::web::ContextProvider> binding( base::fuchsia::ScopedServiceBinding<fuchsia::web::ContextProvider> binding(
directory, &context_provider); directory, &context_provider);
directory->ServeFromStartupInfo();
base::fuchsia::ScopedServiceBinding<fuchsia::web::Debug> debug_binding( base::fuchsia::ScopedServiceBinding<fuchsia::web::Debug> debug_binding(
directory->debug_dir(), &context_provider); directory->debug_dir(), &context_provider);
// Serve outgoing directory only after publishing all services.
directory->ServeFromStartupInfo();
base::RunLoop run_loop; base::RunLoop run_loop;
cr_fuchsia::LifecycleImpl lifecycle(directory, run_loop.QuitClosure()); cr_fuchsia::LifecycleImpl lifecycle(directory, run_loop.QuitClosure());
......
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <fuchsia/sys/cpp/fidl.h>
#include <fuchsia/web/cpp/fidl.h> #include <fuchsia/web/cpp/fidl.h>
#include <lib/fdio/directory.h> #include <lib/fdio/directory.h>
#include <lib/fidl/cpp/binding.h> #include <lib/fidl/cpp/binding.h>
#include <lib/sys/cpp/component_context.h> #include <lib/sys/cpp/component_context.h>
#include "base/command_line.h"
#include "base/fuchsia/default_context.h" #include "base/fuchsia/default_context.h"
#include "base/fuchsia/file_utils.h" #include "base/fuchsia/file_utils.h"
#include "base/fuchsia/fuchsia_logging.h" #include "base/fuchsia/fuchsia_logging.h"
...@@ -41,16 +43,34 @@ class WebEngineIntegrationTest : public testing::Test { ...@@ -41,16 +43,34 @@ class WebEngineIntegrationTest : public testing::Test {
~WebEngineIntegrationTest() override = default; ~WebEngineIntegrationTest() override = default;
void SetUp() override { void SetUp() override {
web_context_provider_ = base::fuchsia::ComponentContextForCurrentProcess()
->svc()
->Connect<fuchsia::web::ContextProvider>();
web_context_provider_.set_error_handler(
[](zx_status_t status) { ADD_FAILURE(); });
net::test_server::RegisterDefaultHandlers(&embedded_test_server_); net::test_server::RegisterDefaultHandlers(&embedded_test_server_);
ASSERT_TRUE(embedded_test_server_.Start()); ASSERT_TRUE(embedded_test_server_.Start());
} }
void StartWebEngine(const base::CommandLine& command_line =
base::CommandLine(base::CommandLine::NO_PROGRAM)) {
fuchsia::sys::LaunchInfo launch_info;
launch_info.url = "fuchsia-pkg://fuchsia.com/chromium#meta/chromium.cmx";
launch_info.arguments = command_line.argv();
fidl::InterfaceHandle<fuchsia::io::Directory> web_engine_services_dir;
launch_info.directory_request =
web_engine_services_dir.NewRequest().TakeChannel();
fuchsia::sys::LauncherPtr launcher;
base::fuchsia::ComponentContextForCurrentProcess()->svc()->Connect(
launcher.NewRequest());
launcher->CreateComponent(std::move(launch_info),
web_engine_controller_.NewRequest());
sys::ServiceDirectory web_engine_service_dir(
std::move(web_engine_services_dir));
web_engine_service_dir.Connect(web_context_provider_.NewRequest());
web_context_provider_.set_error_handler(
[](zx_status_t status) { ADD_FAILURE(); });
}
fuchsia::web::CreateContextParams DefaultContextParams() const { fuchsia::web::CreateContextParams DefaultContextParams() const {
fuchsia::web::CreateContextParams create_params; fuchsia::web::CreateContextParams create_params;
auto directory = base::fuchsia::OpenDirectory( auto directory = base::fuchsia::OpenDirectory(
...@@ -127,6 +147,8 @@ class WebEngineIntegrationTest : public testing::Test { ...@@ -127,6 +147,8 @@ class WebEngineIntegrationTest : public testing::Test {
protected: protected:
const base::test::TaskEnvironment task_environment_; const base::test::TaskEnvironment task_environment_;
fidl::InterfaceHandle<fuchsia::sys::ComponentController>
web_engine_controller_;
fuchsia::web::ContextProviderPtr web_context_provider_; fuchsia::web::ContextProviderPtr web_context_provider_;
net::EmbeddedTestServer embedded_test_server_; net::EmbeddedTestServer embedded_test_server_;
...@@ -139,6 +161,8 @@ class WebEngineIntegrationTest : public testing::Test { ...@@ -139,6 +161,8 @@ class WebEngineIntegrationTest : public testing::Test {
}; };
TEST_F(WebEngineIntegrationTest, ValidUserAgent) { TEST_F(WebEngineIntegrationTest, ValidUserAgent) {
StartWebEngine();
const std::string kEchoHeaderPath = const std::string kEchoHeaderPath =
std::string("/echoheader?") + net::HttpRequestHeaders::kUserAgent; std::string("/echoheader?") + net::HttpRequestHeaders::kUserAgent;
const GURL kEchoUserAgentUrl(embedded_test_server_.GetURL(kEchoHeaderPath)); const GURL kEchoUserAgentUrl(embedded_test_server_.GetURL(kEchoHeaderPath));
...@@ -184,6 +208,8 @@ TEST_F(WebEngineIntegrationTest, ValidUserAgent) { ...@@ -184,6 +208,8 @@ TEST_F(WebEngineIntegrationTest, ValidUserAgent) {
} }
TEST_F(WebEngineIntegrationTest, InvalidUserAgent) { TEST_F(WebEngineIntegrationTest, InvalidUserAgent) {
StartWebEngine();
const std::string kEchoHeaderPath = const std::string kEchoHeaderPath =
std::string("/echoheader?") + net::HttpRequestHeaders::kUserAgent; std::string("/echoheader?") + net::HttpRequestHeaders::kUserAgent;
const GURL kEchoUserAgentUrl(embedded_test_server_.GetURL(kEchoHeaderPath)); const GURL kEchoUserAgentUrl(embedded_test_server_.GetURL(kEchoHeaderPath));
...@@ -215,6 +241,8 @@ TEST_F(WebEngineIntegrationTest, InvalidUserAgent) { ...@@ -215,6 +241,8 @@ TEST_F(WebEngineIntegrationTest, InvalidUserAgent) {
// - DevTools becomes available when the first debuggable Frame is created. // - DevTools becomes available when the first debuggable Frame is created.
// - DevTools closes when the last debuggable Frame is closed. // - DevTools closes when the last debuggable Frame is closed.
TEST_F(WebEngineIntegrationTest, RemoteDebuggingPort) { TEST_F(WebEngineIntegrationTest, RemoteDebuggingPort) {
StartWebEngine();
// Create a Context with remote debugging enabled via an ephemeral port. // Create a Context with remote debugging enabled via an ephemeral port.
fuchsia::web::CreateContextParams create_params; fuchsia::web::CreateContextParams create_params;
auto directory = base::fuchsia::OpenDirectory( auto directory = base::fuchsia::OpenDirectory(
...@@ -311,6 +339,8 @@ TEST_F(WebEngineIntegrationTest, RemoteDebuggingPort) { ...@@ -311,6 +339,8 @@ TEST_F(WebEngineIntegrationTest, RemoteDebuggingPort) {
// Check that remote debugging requests for Frames in non-debuggable Contexts // Check that remote debugging requests for Frames in non-debuggable Contexts
// cause an error to be reported. // cause an error to be reported.
TEST_F(WebEngineIntegrationTest, RequestDebuggableFrameInNonDebuggableContext) { TEST_F(WebEngineIntegrationTest, RequestDebuggableFrameInNonDebuggableContext) {
StartWebEngine();
fuchsia::web::CreateContextParams create_params = DefaultContextParams(); fuchsia::web::CreateContextParams create_params = DefaultContextParams();
fuchsia::web::ContextPtr web_context; fuchsia::web::ContextPtr web_context;
...@@ -335,6 +365,8 @@ TEST_F(WebEngineIntegrationTest, RequestDebuggableFrameInNonDebuggableContext) { ...@@ -335,6 +365,8 @@ TEST_F(WebEngineIntegrationTest, RequestDebuggableFrameInNonDebuggableContext) {
// Navigates to a resource served under the "testdata" ContentDirectory. // Navigates to a resource served under the "testdata" ContentDirectory.
TEST_F(WebEngineIntegrationTest, ContentDirectoryProvider) { TEST_F(WebEngineIntegrationTest, ContentDirectoryProvider) {
StartWebEngine();
const GURL kUrl("fuchsia-dir://testdata/title1.html"); const GURL kUrl("fuchsia-dir://testdata/title1.html");
constexpr char kTitle[] = "title 1"; constexpr char kTitle[] = "title 1";
...@@ -356,6 +388,8 @@ TEST_F(WebEngineIntegrationTest, ContentDirectoryProvider) { ...@@ -356,6 +388,8 @@ TEST_F(WebEngineIntegrationTest, ContentDirectoryProvider) {
} }
TEST_F(WebEngineIntegrationTest, PlayAudio) { TEST_F(WebEngineIntegrationTest, PlayAudio) {
StartWebEngine();
fuchsia::web::CreateContextParams create_params = fuchsia::web::CreateContextParams create_params =
DefaultContextParamsWithTestData(); DefaultContextParamsWithTestData();
auto features = fuchsia::web::ContextFeatureFlags::AUDIO; auto features = fuchsia::web::ContextFeatureFlags::AUDIO;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
"fuchsia.netstack.Netstack", "fuchsia.netstack.Netstack",
"fuchsia.posix.socket.Provider", "fuchsia.posix.socket.Provider",
"fuchsia.process.Launcher", "fuchsia.process.Launcher",
"fuchsia.sys.Launcher",
"fuchsia.sysmem.Allocator", "fuchsia.sysmem.Allocator",
"fuchsia.web.ContextProvider" "fuchsia.web.ContextProvider"
] ]
......
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