diff --git a/build/config/fuchsia/generate_runner_scripts.gni b/build/config/fuchsia/generate_runner_scripts.gni index 5bdf91b175b2e..933d8e66cbc4f 100644 --- a/build/config/fuchsia/generate_runner_scripts.gni +++ b/build/config/fuchsia/generate_runner_scripts.gni @@ -26,9 +26,12 @@ declare_args() { # package_name_override: Specifies the name of the generated package, if its # name is different than the |package| target name. This value must match # package_name_override in the |package| target. -# package_deps: An array of [package, package_name_override] array pairs -# which specify additional dependency packages to be installed -# prior to execution. +# archive_name_override: Specifies the filename of the archive file (FAR) +# which contains the package's data. +# If left unset, defaults to |package_name_override|. +# Defaults to the package's name. +# package_deps: An array of [package, archive_basename] pairs that specify +# additional dependency packages to be installed prior to execution. # runner_script: The runner script implementation to use, relative to # "build/fuchsia". Defaults to "test_runner.py". # install_only: If true, executing the script will only install the package @@ -36,20 +39,29 @@ declare_args() { template("fuchsia_package_runner") { forward_variables_from(invoker, [ "runner_script" ]) + # Compute the package name. if (defined(invoker.package_name_override)) { - _pkg_shortname = invoker.package_name_override + _package_name = invoker.package_name_override } else { - _pkg_shortname = get_label_info(invoker.package, "name") + _package_name = get_label_info(invoker.package, "name") + } + + # Compute the archive (FAR) filename. + if (defined(invoker.archive_name_override)) { + _archive_shortname = invoker.archive_name_override + } else { + _archive_shortname = _package_name } _pkg_dir = "$root_out_dir/gen/" + get_label_info(invoker.package, "dir") + - "/" + _pkg_shortname - _manifest_path = "$_pkg_dir/${_pkg_shortname}.archive_manifest" - _package_path = "$_pkg_dir/${_pkg_shortname}.far" + "/" + _archive_shortname + _manifest_path = "$_pkg_dir/${_archive_shortname}.archive_manifest" + _package_path = "$_pkg_dir/${_archive_shortname}.far" - generated_run_pkg_script_path = "$root_build_dir/bin/run_${_pkg_shortname}" + generated_run_pkg_script_path = + "$root_build_dir/bin/run_${_archive_shortname}" generated_install_pkg_script_path = - "$root_build_dir/bin/install_$_pkg_shortname" + "$root_build_dir/bin/install_${_archive_shortname}" _generate_runner_target = "${target_name}__generate_runner" _generate_installer_target = "${target_name}__generate_installer" @@ -143,7 +155,7 @@ template("fuchsia_package_runner") { "--target-cpu", target_cpu, "--package-name", - _pkg_shortname, + _package_name, ] if (defined(invoker.use_test_server) && invoker.use_test_server) { diff --git a/build/config/fuchsia/package.gni b/build/config/fuchsia/package.gni index 7ceb141e36018..d7c0e29604781 100644 --- a/build/config/fuchsia/package.gni +++ b/build/config/fuchsia/package.gni @@ -10,6 +10,9 @@ import("//build/config/sysroot.gni") # Parameters are: # package_name_override: Specifies the name of the package to generate, # if different than |target_name|. +# archive_filename_override: Specifies the filename of the generated FAR. +# If left unset, defaults to |package_name_override|. +# Defaults to the target name. # binary: The executable target which should be launched. # manifest: A path to the manifest that will be used. # "testonly" targets default to using @@ -33,6 +36,12 @@ template("fuchsia_package") { package_name = invoker.target_name } + if (defined(archive_name_override)) { + archive_filename = archive_name_override + } else { + archive_filename = package_name + } + if (!defined(manifest)) { assert(testonly == true) @@ -45,13 +54,13 @@ template("fuchsia_package") { _pm_tool_path = "${fuchsia_sdk}/tools/pm" - _pkg_out_dir = "${target_gen_dir}/${pkg.package_name}" - _runtime_deps_file = "$_pkg_out_dir/${pkg.package_name}.runtime_deps" - _archive_manifest = "$_pkg_out_dir/${pkg.package_name}.archive_manifest" + _pkg_out_dir = "${target_gen_dir}/${pkg.archive_filename}" + _runtime_deps_file = "$_pkg_out_dir/${pkg.archive_filename}.runtime_deps" + _archive_manifest = "$_pkg_out_dir/${pkg.archive_filename}.archive_manifest" _build_ids_file = "$_pkg_out_dir/ids.txt" _meta_far_file = "$_pkg_out_dir/meta.far" _combined_far_file = "$_pkg_out_dir/${pkg.package_name}-0.far" - _final_far_file = "$_pkg_out_dir/${pkg.package_name}.far" + _final_far_file = "$_pkg_out_dir/${pkg.archive_filename}.far" _package_info_path = "$_pkg_out_dir/package" if (defined(pkg.component_name_override)) { diff --git a/fuchsia/BUILD.gn b/fuchsia/BUILD.gn index 0ce74d9947f55..1816eeccfaa52 100644 --- a/fuchsia/BUILD.gn +++ b/fuchsia/BUILD.gn @@ -4,7 +4,9 @@ assert(is_fuchsia) +import("//build/buildflag_header.gni") import("//build/config/fuchsia/fidl_library.gni") +import("//fuchsia/release_channel.gni") fidl_library("cast_fidl") { library_name = "cast" diff --git a/fuchsia/base/BUILD.gn b/fuchsia/base/BUILD.gn index 8aebb702769d6..a76ad8b45c88d 100644 --- a/fuchsia/base/BUILD.gn +++ b/fuchsia/base/BUILD.gn @@ -4,8 +4,10 @@ assert(is_fuchsia) +import("//build/buildflag_header.gni") import("//build/config/fuchsia/fidl_library.gni") import("//build/config/fuchsia/generate_runner_scripts.gni") +import("//fuchsia/release_channel.gni") import("//testing/test.gni") # Integration helpers for commonly used fuchsia.* APIs. @@ -58,9 +60,18 @@ source_set("message_port") { ] } +# Used to propagate release-qualified package names to integration test code. +buildflag_header("release_channel_buildflags") { + header = "release_channel.h" + flags = [ "FUCHSIA_RELEASE_CHANNEL_SUFFIX=\"$release_channel_suffix\"" ] + visibility = [ "//fuchsia/*" ] +} + source_set("test_support") { testonly = true sources = [ + "context_provider_test_connector.cc", + "context_provider_test_connector.h", "fake_component_context.cc", "fake_component_context.h", "fit_adapter.h", @@ -77,6 +88,7 @@ source_set("test_support") { public_deps = [ ":base", ":modular", + ":release_channel_buildflags", "//base", "//net", "//net:test_support", diff --git a/fuchsia/engine/test/context_provider_test_connector.cc b/fuchsia/base/context_provider_test_connector.cc similarity index 79% rename from fuchsia/engine/test/context_provider_test_connector.cc rename to fuchsia/base/context_provider_test_connector.cc index 82a49aa9b1a1b..a438b1de5be2d 100644 --- a/fuchsia/engine/test/context_provider_test_connector.cc +++ b/fuchsia/base/context_provider_test_connector.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "fuchsia/engine/test/context_provider_test_connector.h" +#include "fuchsia/base/context_provider_test_connector.h" #include <unistd.h> @@ -15,14 +15,19 @@ #include "base/fuchsia/default_context.h" #include "base/fuchsia/fuchsia_logging.h" #include "base/logging.h" +#include "base/strings/strcat.h" +#include "fuchsia/base/release_channel.h" -fuchsia::web::ContextProviderPtr StartWebEngineForTests( +namespace cr_fuchsia { + +fuchsia::web::ContextProviderPtr ConnectContextProvider( fidl::InterfaceRequest<fuchsia::sys::ComponentController> component_controller_request, const base::CommandLine& command_line) { fuchsia::sys::LaunchInfo launch_info; - launch_info.url = - "fuchsia-pkg://fuchsia.com/web_engine#meta/context_provider.cmx"; + launch_info.url = base::StrCat({"fuchsia-pkg://fuchsia.com/web_engine", + BUILDFLAG(FUCHSIA_RELEASE_CHANNEL_SUFFIX), + "#meta/context_provider.cmx"}); launch_info.arguments = command_line.argv(); // Clone stderr from the current process to WebEngine and ask it to @@ -51,3 +56,5 @@ fuchsia::web::ContextProviderPtr StartWebEngineForTests( web_engine_service_dir.Connect(context_provider.NewRequest()); return context_provider; } + +} // namespace cr_fuchsia diff --git a/fuchsia/engine/test/context_provider_test_connector.h b/fuchsia/base/context_provider_test_connector.h similarity index 59% rename from fuchsia/engine/test/context_provider_test_connector.h rename to fuchsia/base/context_provider_test_connector.h index cc8d7f76220d7..632c6f9c611f7 100644 --- a/fuchsia/engine/test/context_provider_test_connector.h +++ b/fuchsia/base/context_provider_test_connector.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef FUCHSIA_ENGINE_TEST_CONTEXT_PROVIDER_TEST_CONNECTOR_H_ -#define FUCHSIA_ENGINE_TEST_CONTEXT_PROVIDER_TEST_CONNECTOR_H_ +#ifndef FUCHSIA_BASE_CONTEXT_PROVIDER_TEST_CONNECTOR_H_ +#define FUCHSIA_BASE_CONTEXT_PROVIDER_TEST_CONNECTOR_H_ #include <fuchsia/sys/cpp/fidl.h> #include <fuchsia/web/cpp/fidl.h> @@ -11,10 +11,15 @@ #include "base/command_line.h" -fuchsia::web::ContextProviderPtr StartWebEngineForTests( +namespace cr_fuchsia { + +// TODO(crbug.com/1046615): Use test manifests for package specification. +fuchsia::web::ContextProviderPtr ConnectContextProvider( fidl::InterfaceRequest<fuchsia::sys::ComponentController> component_controller_request, const base::CommandLine& command_line = base::CommandLine(base::CommandLine::NO_PROGRAM)); -#endif // FUCHSIA_ENGINE_TEST_CONTEXT_PROVIDER_TEST_CONNECTOR_H_ +} // namespace cr_fuchsia + +#endif // FUCHSIA_BASE_CONTEXT_PROVIDER_TEST_CONNECTOR_H_ diff --git a/fuchsia/engine/BUILD.gn b/fuchsia/engine/BUILD.gn index 0d58355058a51..4c0bb6a6dc75f 100644 --- a/fuchsia/engine/BUILD.gn +++ b/fuchsia/engine/BUILD.gn @@ -6,6 +6,7 @@ assert(is_fuchsia) import("//build/config/fuchsia/generate_runner_scripts.gni") import("//build/config/fuchsia/symbol_archive.gni") +import("//fuchsia/release_channel.gni") import("//mojo/public/tools/bindings/mojom.gni") import("//testing/test.gni") import("//tools/grit/repack.gni") @@ -205,6 +206,8 @@ fuchsia_package("web_engine") { binary = ":web_engine_exe" manifest = "context_provider.cmx" component_name_override = "context_provider" + package_name_override = "web_engine${release_channel_suffix}" + archive_name_override = "web_engine" excluded_files = [ "lib/libswiftshader_libEGL.so", @@ -300,8 +303,6 @@ test("web_engine_unittests") { test("web_engine_integration_tests") { manifest = "web_engine_integration_tests.cmx" sources = [ - "test/context_provider_test_connector.cc", - "test/context_provider_test_connector.h", "test_debug_listener.cc", "test_debug_listener.h", "web_engine_debug_integration_test.cc", @@ -318,7 +319,7 @@ test("web_engine_integration_tests") { ] package_deps = [ [ ":web_engine", - "web_engine", + "web_engine${release_channel_suffix}", ] ] } diff --git a/fuchsia/engine/web_engine_debug_integration_test.cc b/fuchsia/engine/web_engine_debug_integration_test.cc index 8e0ae2dbc91e1..4c8befde076e2 100644 --- a/fuchsia/engine/web_engine_debug_integration_test.cc +++ b/fuchsia/engine/web_engine_debug_integration_test.cc @@ -13,12 +13,12 @@ #include "base/fuchsia/file_utils.h" #include "base/macros.h" #include "base/test/task_environment.h" +#include "fuchsia/base/context_provider_test_connector.h" #include "fuchsia/base/fit_adapter.h" #include "fuchsia/base/frame_test_util.h" #include "fuchsia/base/result_receiver.h" #include "fuchsia/base/test_devtools_list_fetcher.h" #include "fuchsia/base/test_navigation_listener.h" -#include "fuchsia/engine/test/context_provider_test_connector.h" #include "fuchsia/engine/test_debug_listener.h" #include "net/test/embedded_test_server/embedded_test_server.h" #include "testing/gtest/include/gtest/gtest.h" @@ -38,7 +38,7 @@ class WebEngineDebugIntegrationTest : public testing::Test { void SetUp() override { web_context_provider_ = - StartWebEngineForTests(web_engine_controller_.NewRequest()); + cr_fuchsia::ConnectContextProvider(web_engine_controller_.NewRequest()); web_context_provider_.set_error_handler( [](zx_status_t status) { ADD_FAILURE(); }); diff --git a/fuchsia/engine/web_engine_integration_test.cc b/fuchsia/engine/web_engine_integration_test.cc index dca654e27c9f2..d6505e0ec66a2 100644 --- a/fuchsia/engine/web_engine_integration_test.cc +++ b/fuchsia/engine/web_engine_integration_test.cc @@ -17,12 +17,12 @@ #include "base/macros.h" #include "base/path_service.h" #include "base/test/task_environment.h" +#include "fuchsia/base/context_provider_test_connector.h" #include "fuchsia/base/fit_adapter.h" #include "fuchsia/base/frame_test_util.h" #include "fuchsia/base/result_receiver.h" #include "fuchsia/base/test_devtools_list_fetcher.h" #include "fuchsia/base/test_navigation_listener.h" -#include "fuchsia/engine/test/context_provider_test_connector.h" #include "net/http/http_request_headers.h" #include "net/test/embedded_test_server/default_handlers.h" #include "net/test/embedded_test_server/embedded_test_server.h" @@ -51,7 +51,7 @@ class WebEngineIntegrationTest : public testing::Test { void StartWebEngine() { web_context_provider_ = - StartWebEngineForTests(web_engine_controller_.NewRequest()); + cr_fuchsia::ConnectContextProvider(web_engine_controller_.NewRequest()); web_context_provider_.set_error_handler( [](zx_status_t status) { ADD_FAILURE(); }); } diff --git a/fuchsia/release_channel.gni b/fuchsia/release_channel.gni new file mode 100644 index 0000000000000..1bab7421f82f3 --- /dev/null +++ b/fuchsia/release_channel.gni @@ -0,0 +1,15 @@ +# Copyright 2020 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +declare_args() { + # Specifies the name of the release channel for specific packages + # (web_engine, web_runner, cast_runner) when buildng on a release bot. + fuchsia_release_channel = "" +} + +if (fuchsia_release_channel != "") { + release_channel_suffix = "-${fuchsia_release_channel}" +} else { + release_channel_suffix = "" +} diff --git a/fuchsia/runners/BUILD.gn b/fuchsia/runners/BUILD.gn index f7d563f81b3a0..17cf87c9eed06 100644 --- a/fuchsia/runners/BUILD.gn +++ b/fuchsia/runners/BUILD.gn @@ -7,6 +7,7 @@ assert(is_fuchsia) import("//build/buildflag_header.gni") import("//build/config/fuchsia/generate_runner_scripts.gni") import("//build/config/fuchsia/symbol_archive.gni") +import("//fuchsia/release_channel.gni") import("//testing/test.gni") declare_args() { @@ -14,6 +15,9 @@ declare_args() { web_runner_remote_debugging_port = 0 } +_cast_runner_package_name = "cast_runner${release_channel_suffix}" +_web_runner_package_name = "web_runner${release_channel_suffix}" + buildflag_header("buildflags") { header = "buildflags.h" flags = @@ -89,13 +93,14 @@ executable("cast_runner_exe") { fuchsia_package("cast_runner_pkg") { binary = ":cast_runner_exe" - package_name_override = "cast_runner" + package_name_override = _cast_runner_package_name + archive_name_override = "cast_runner" manifest = "cast/cast_runner.cmx" } fuchsia_package_runner("cast_runner") { package = ":cast_runner_pkg" - package_name_override = "cast_runner" + archive_name_override = "cast_runner" install_only = true package_deps = [ [ "//fuchsia/engine:web_engine", @@ -193,13 +198,14 @@ executable("web_runner_exe") { fuchsia_package("web_runner_pkg") { binary = ":web_runner_exe" - package_name_override = "web_runner" + package_name_override = _web_runner_package_name + archive_name_override = "web_runner" manifest = "web/web_runner.cmx" } fuchsia_package_runner("web_runner") { package = ":web_runner_pkg" - package_name_override = "web_runner" + archive_name_override = "web_runner" install_only = true package_deps = [ [ "//fuchsia/engine:web_engine", diff --git a/fuchsia/runners/cast/cast_runner_integration_test.cc b/fuchsia/runners/cast/cast_runner_integration_test.cc index ff6b320067b7e..9043464e7c2ba 100644 --- a/fuchsia/runners/cast/cast_runner_integration_test.cc +++ b/fuchsia/runners/cast/cast_runner_integration_test.cc @@ -20,6 +20,7 @@ #include "base/test/task_environment.h" #include "base/threading/sequenced_task_runner_handle.h" #include "fuchsia/base/agent_impl.h" +#include "fuchsia/base/context_provider_test_connector.h" #include "fuchsia/base/fake_component_context.h" #include "fuchsia/base/fit_adapter.h" #include "fuchsia/base/frame_test_util.h" @@ -246,6 +247,9 @@ class CastRunnerIntegrationTest : public testing::Test { cast_runner_ = std::make_unique<CastRunner>( std::move(create_context_params), &outgoing_directory_); + cast_runner_->SetContextProviderForTest(cr_fuchsia::ConnectContextProvider( + context_provider_controller_.NewRequest())); + // Connect to the CastRunner's fuchsia.sys.Runner interface. fidl::InterfaceHandle<fuchsia::io::Directory> directory; outgoing_directory_.GetOrCreateDirectory("svc")->Serve( @@ -299,6 +303,7 @@ class CastRunnerIntegrationTest : public testing::Test { std::unique_ptr<CastRunner> cast_runner_; fuchsia::sys::RunnerPtr cast_runner_ptr_; + fuchsia::sys::ComponentControllerPtr context_provider_controller_; }; // A basic integration test ensuring a basic cast request launches the right diff --git a/fuchsia/runners/common/web_content_runner.cc b/fuchsia/runners/common/web_content_runner.cc index 1c7391404a81f..dafab2e674e38 100644 --- a/fuchsia/runners/common/web_content_runner.cc +++ b/fuchsia/runners/common/web_content_runner.cc @@ -38,19 +38,14 @@ WebContentRunner::WebContentRunner(fuchsia::web::ContextPtr context, WebContentRunner::~WebContentRunner() = default; -// static fuchsia::web::ContextPtr WebContentRunner::CreateWebContext( fuchsia::web::CreateContextParams create_params) { - auto web_context_provider = base::fuchsia::ComponentContextForCurrentProcess() - ->svc() - ->Connect<fuchsia::web::ContextProvider>(); - fuchsia::web::ContextPtr web_context; - web_context_provider->Create(std::move(create_params), + GetContextProvider()->Create(std::move(create_params), web_context.NewRequest()); web_context.set_error_handler([](zx_status_t status) { - // If the browser instance died, then exit everything and do not attempt - // to recover. appmgr will relaunch the runner when it is needed again. + // If the browser instance died, then exit everything and do not attempt to + // recover. appmgr will relaunch the runner when it is needed again. ZX_LOG(ERROR, status) << "Connection to Context lost."; }); @@ -103,3 +98,18 @@ void WebContentRunner::RegisterComponent( components_.insert(std::move(component)); } + +void WebContentRunner::SetContextProviderForTest( + fuchsia::web::ContextProviderPtr context_provider) { + DCHECK(context_provider); + context_provider_ = std::move(context_provider); +} + +fuchsia::web::ContextProvider* WebContentRunner::GetContextProvider() { + if (!context_provider_) { + context_provider_ = base::fuchsia::ComponentContextForCurrentProcess() + ->svc() + ->Connect<fuchsia::web::ContextProvider>(); + } + return context_provider_.get(); +} diff --git a/fuchsia/runners/common/web_content_runner.h b/fuchsia/runners/common/web_content_runner.h index d90ea83dafba6..49fbf2fbde82b 100644 --- a/fuchsia/runners/common/web_content_runner.h +++ b/fuchsia/runners/common/web_content_runner.h @@ -35,7 +35,9 @@ class WebContentRunner : public fuchsia::sys::Runner { ~WebContentRunner() override; - static fuchsia::web::ContextPtr CreateWebContext( + // TODO(crbug.com/1046615): Make this static when the injected ContextProvider + // goes away. + fuchsia::web::ContextPtr CreateWebContext( fuchsia::web::CreateContextParams create_params); // Gets a pointer to this runner's Context, creating one if needed. @@ -61,6 +63,11 @@ class WebContentRunner : public fuchsia::sys::Runner { // Registers a WebComponent, or specialization, with this Runner. void RegisterComponent(std::unique_ptr<WebComponent> component); + // Overrides the environment's the ContextProvider to use. + // TODO(crbug.com/1046615): Use test manifests for package specification. + void SetContextProviderForTest( + fuchsia::web::ContextProviderPtr context_provider); + protected: base::RepeatingCallback<void(WebComponent*)> web_component_created_callback_for_test() const { @@ -70,10 +77,13 @@ class WebContentRunner : public fuchsia::sys::Runner { fuchsia::web::CreateContextParams create_params_; private: + fuchsia::web::ContextProvider* GetContextProvider(); + // If set, invoked whenever a WebComponent is created. base::RepeatingCallback<void(WebComponent*)> web_component_created_callback_for_test_; + fuchsia::web::ContextProviderPtr context_provider_; fuchsia::web::ContextPtr context_; std::set<std::unique_ptr<WebComponent>, base::UniquePtrComparator> components_;