Commit ae340b4d authored by Wez's avatar Wez Committed by Commit Bot

[Fuchsia] Clean up CastRunner integration tests.

Move StartCastComponent() into the test fixture, and break out the
CastChannel implementation to a separate helper class, for clarity.

Also fixes WebComponent to be usable even if the caller does not
provide a service-directory request handle to CreateComponent().

Bug: 918724, 893229
Change-Id: I9fafd6536d550240d79ee7baa7f4e653db823066
Reviewed-on: https://chromium-review.googlesource.com/c/1474647Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Auto-Submit: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#633847}
parent bfbbace0
...@@ -89,14 +89,11 @@ source_set("cast_runner_test_core") { ...@@ -89,14 +89,11 @@ source_set("cast_runner_test_core") {
sources = [ sources = [
"cast/fake_application_config_manager.cc", "cast/fake_application_config_manager.cc",
"cast/fake_application_config_manager.h", "cast/fake_application_config_manager.h",
"cast/test_common.cc",
"cast/test_common.h",
] ]
public_deps = [ public_deps = [
"//base", "//base",
"//fuchsia:cast_fidl", "//fuchsia:cast_fidl",
"//net:test_support", "//url",
"//third_party/fuchsia-sdk/sdk:sys",
] ]
visibility = [ ":*" ] visibility = [ ":*" ]
} }
......
...@@ -82,11 +82,6 @@ void CastRunner::GetConfigCallback( ...@@ -82,11 +82,6 @@ void CastRunner::GetConfigCallback(
chromium::cast::ApplicationConfigPtr app_config) { chromium::cast::ApplicationConfigPtr app_config) {
if (!app_config) { if (!app_config) {
DLOG(WARNING) << "No ApplicationConfig was found."; DLOG(WARNING) << "No ApplicationConfig was found.";
// For test purposes, we need to call RegisterComponent even if there is no
// URL to launch.
// TODO: Replace this hack, e.g. with an test-specific callback.
RegisterComponent(std::unique_ptr<WebComponent>(nullptr));
return; return;
} }
......
// Copyright 2018 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.
#include "fuchsia/runners/cast/test_common.h"
#include <lib/fidl/cpp/binding.h>
#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/fuchsia/fuchsia_logging.h"
#include "base/fuchsia/service_directory.h"
#include "base/run_loop.h"
fidl::InterfaceHandle<fuchsia::io::Directory> StartCastComponent(
const base::StringPiece& cast_url,
fuchsia::sys::RunnerPtr* sys_runner,
fidl::InterfaceRequest<fuchsia::sys::ComponentController>
component_controller_request,
fidl::Binding<chromium::cast::CastChannel>* cast_channel_binding) {
// Construct, bind, and populate a ServiceDirectory for publishing
// the CastChannel service to the CastComponent.
fidl::InterfaceHandle<fuchsia::io::Directory> directory;
base::fuchsia::ServiceDirectory cast_channel_directory(
directory.NewRequest());
base::RunLoop service_connect_runloop;
cast_channel_directory.AddService(base::BindRepeating(
[](base::RepeatingClosure on_connect_cb,
fidl::Binding<chromium::cast::CastChannel>* cast_channel_binding_,
fidl::InterfaceRequest<chromium::cast::CastChannel> request) {
cast_channel_binding_->Bind(std::move(request));
on_connect_cb.Run();
},
base::Passed(service_connect_runloop.QuitClosure()),
base::Unretained(cast_channel_binding)));
// Configure the Runner, including a service directory channel to publish
// services to.
fuchsia::sys::StartupInfo startup_info;
startup_info.launch_info.url = cast_url.as_string();
fidl::InterfaceHandle<fuchsia::io::Directory> component_services;
startup_info.launch_info.directory_request =
component_services.NewRequest().TakeChannel();
// Publish the ServiceDirectory into the FlatNamespace for CastChannel to be
// picked up from.
startup_info.flat_namespace.paths.emplace_back("/svc");
startup_info.flat_namespace.directories.emplace_back(directory.TakeChannel());
fuchsia::sys::Package package;
package.resolved_url = cast_url.as_string();
sys_runner->get()->StartComponent(std::move(package), std::move(startup_info),
std::move(component_controller_request));
// Process the runloop until the CastChannel FIDL service is connected.
service_connect_runloop.Run();
// Prepare the service directory for clean teardown.
cast_channel_directory.RemoveAllServices();
return component_services;
}
// Copyright 2018 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.
#ifndef FUCHSIA_RUNNERS_CAST_TEST_COMMON_H_
#define FUCHSIA_RUNNERS_CAST_TEST_COMMON_H_
#include <fuchsia/sys/cpp/fidl.h>
#include <lib/fidl/cpp/binding.h>
#include "base/strings/string_piece.h"
#include "fuchsia/fidl/chromium/cast/cpp/fidl.h"
namespace fuchsia {
namespace io {
class Directory;
}
} // namespace fuchsia
// Starts a Cast component from the runner |sys_runner| with the URL |cast_url|
// and returns the outgoing service directory client channel.
// The Cast component will connect to the CastChannel FIDL service bound at
// |cast_channel_binding|.
// Blocks until |cast_channel_binding| is bound.
fidl::InterfaceHandle<fuchsia::io::Directory> StartCastComponent(
const base::StringPiece& cast_url,
fuchsia::sys::RunnerPtr* sys_runner,
fidl::InterfaceRequest<fuchsia::sys::ComponentController>
component_controller_request,
fidl::Binding<chromium::cast::CastChannel>* cast_channel_binding);
#endif // FUCHSIA_RUNNERS_CAST_TEST_COMMON_H_
...@@ -61,15 +61,18 @@ WebComponent::WebComponent( ...@@ -61,15 +61,18 @@ WebComponent::WebComponent(
// Create the underlying Frame and get its NavigationController. // Create the underlying Frame and get its NavigationController.
runner_->context()->CreateFrame(frame_.NewRequest()); runner_->context()->CreateFrame(frame_.NewRequest());
// Publish ViewProvider before returning control to the message-loop, to if (startup_context()->public_services()) {
// ensure that it is available before the ServiceDirectory starts processing // Publish ViewProvider before returning control to the message-loop, to
// requests. // ensure that it is available before the ServiceDirectory starts processing
view_provider_binding_ = std::make_unique< // requests.
base::fuchsia::ScopedServiceBinding<fuchsia::ui::app::ViewProvider>>( view_provider_binding_ = std::make_unique<
startup_context()->public_services(), this); base::fuchsia::ScopedServiceBinding<fuchsia::ui::app::ViewProvider>>(
legacy_view_provider_binding_ = std::make_unique< startup_context()->public_services(), this);
base::fuchsia::ScopedServiceBinding<fuchsia::ui::viewsv1::ViewProvider>>( legacy_view_provider_binding_ =
startup_context()->public_services(), this); std::make_unique<base::fuchsia::ScopedServiceBinding<
fuchsia::ui::viewsv1::ViewProvider>>(
startup_context()->public_services(), this);
}
} }
void WebComponent::Kill() { void WebComponent::Kill() {
......
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