[fuchsia] Add a simple console log WebEngine integration test
More tests will be added in future CLs.
Also extracts TestLogListenerSafe for reuse and adds support for
starting WebEngine for tests without redirecting logging as required for
the new test to work.
Bug: 1051533,1133984
Change-Id: I709dcecc82c5c4b5648c2c25a3bbf64dc7090cf4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2440980
Commit-Queue: David Dorwin <[email protected]>
Reviewed-by: Sergey Ulanov <[email protected]>
Reviewed-by: Wez <[email protected]>
Cr-Commit-Position: refs/heads/master@{#814421}
diff --git a/fuchsia/base/context_provider_test_connector.cc b/fuchsia/base/context_provider_test_connector.cc
index 307f0bd..6796771 100644
--- a/fuchsia/base/context_provider_test_connector.cc
+++ b/fuchsia/base/context_provider_test_connector.cc
@@ -17,23 +17,32 @@
namespace cr_fuchsia {
-fidl::InterfaceHandle<fuchsia::io::Directory> StartWebEngineForTests(
+namespace {
+
+// |is_for_logging_test| should only be true when testing WebEngine's logging
+// behavior as it prevents WebEngine logs from being included in the test
+// output. When false, WebEngine logs are not included in the Fuchsia system
+// log.
+fidl::InterfaceHandle<fuchsia::io::Directory> StartWebEngineForTestsInternal(
fidl::InterfaceRequest<fuchsia::sys::ComponentController>
component_controller_request,
- const base::CommandLine& command_line) {
+ const base::CommandLine& command_line,
+ bool is_for_logging_test) {
fuchsia::sys::LaunchInfo launch_info;
launch_info.url =
"fuchsia-pkg://fuchsia.com/web_engine#meta/context_provider.cmx";
launch_info.arguments = command_line.argv();
- // Clone stderr from the current process to WebEngine and ask it to
- // redirects all logs to stderr.
- launch_info.err = fuchsia::sys::FileDescriptor::New();
- launch_info.err->type0 = PA_FD;
- zx_status_t status = fdio_fd_clone(
- STDERR_FILENO, launch_info.err->handle0.reset_and_get_address());
- ZX_CHECK(status == ZX_OK, status);
- launch_info.arguments->push_back("--enable-logging=stderr");
+ if (!is_for_logging_test) {
+ // Clone stderr from the current process to WebEngine and ask it to
+ // redirects all logs to stderr.
+ launch_info.err = fuchsia::sys::FileDescriptor::New();
+ launch_info.err->type0 = PA_FD;
+ zx_status_t status = fdio_fd_clone(
+ STDERR_FILENO, launch_info.err->handle0.reset_and_get_address());
+ ZX_CHECK(status == ZX_OK, status);
+ launch_info.arguments->push_back("--enable-logging=stderr");
+ }
fidl::InterfaceHandle<fuchsia::io::Directory> web_engine_services_dir;
launch_info.directory_request =
@@ -47,13 +56,31 @@
return web_engine_services_dir;
}
+} // namespace
+
+fidl::InterfaceHandle<fuchsia::io::Directory> StartWebEngineForTests(
+ fidl::InterfaceRequest<fuchsia::sys::ComponentController>
+ component_controller_request,
+ const base::CommandLine& command_line) {
+ return StartWebEngineForTestsInternal(std::move(component_controller_request),
+ command_line, false);
+}
+
fuchsia::web::ContextProviderPtr ConnectContextProvider(
fidl::InterfaceRequest<fuchsia::sys::ComponentController>
component_controller_request,
const base::CommandLine& command_line) {
- sys::ServiceDirectory web_engine_service_dir(StartWebEngineForTests(
- std::move(component_controller_request), command_line));
+ sys::ServiceDirectory web_engine_service_dir(StartWebEngineForTestsInternal(
+ std::move(component_controller_request), command_line, false));
return web_engine_service_dir.Connect<fuchsia::web::ContextProvider>();
}
+fuchsia::web::ContextProviderPtr ConnectContextProviderForLoggingTest(
+ fidl::InterfaceRequest<fuchsia::sys::ComponentController>
+ component_controller_request,
+ const base::CommandLine& command_line) {
+ sys::ServiceDirectory web_engine_service_dir(StartWebEngineForTestsInternal(
+ std::move(component_controller_request), command_line, true));
+ return web_engine_service_dir.Connect<fuchsia::web::ContextProvider>();
+}
} // namespace cr_fuchsia