Commit 924c7bd1 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Cleanup cast_runner_integration_tests

Moved common code to helper function to reduce code duplication.

Change-Id: I5a9eb369e70e2fcf3ef520004089ece479935654
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2092950
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749377}
parent 847ce08f
......@@ -42,10 +42,16 @@
namespace {
const char kTestServerRoot[] =
constexpr char kTestAppId[] = "00000000";
constexpr char kBlankAppUrl[] = "/defaultresponse";
constexpr char kEchoHeaderPath[] = "/echoheader?Test";
constexpr char kEchoAppPath[] = "/echo.html";
constexpr char kTestServerRoot[] =
FILE_PATH_LITERAL("fuchsia/runners/cast/testdata");
const char kDummyAgentUrl[] =
constexpr char kDummyAgentUrl[] =
"fuchsia-pkg://fuchsia.com/dummy_agent#meta/dummy_agent.cmx";
void ComponentErrorHandler(zx_status_t status) {
......@@ -189,48 +195,6 @@ class CastRunnerIntegrationTest : public testing::Test {
base::RunLoop().RunUntilIdle();
}
fuchsia::sys::ComponentControllerPtr StartCastComponent(
base::StringPiece component_url) {
// Configure the Runner, including a service directory channel to publish
// services to.
fidl::InterfaceHandle<fuchsia::io::Directory> directory;
component_services_.GetOrCreateDirectory("svc")->Serve(
fuchsia::io::OPEN_RIGHT_READABLE | fuchsia::io::OPEN_RIGHT_WRITABLE,
directory.NewRequest().TakeChannel());
fuchsia::sys::StartupInfo startup_info;
startup_info.launch_info.url = component_url.as_string();
fidl::InterfaceHandle<fuchsia::io::Directory> outgoing_directory;
startup_info.launch_info.directory_request =
outgoing_directory.NewRequest().TakeChannel();
fidl::InterfaceHandle<::fuchsia::io::Directory> svc_directory;
CHECK_EQ(fdio_service_connect_at(
outgoing_directory.channel().get(), "svc",
svc_directory.NewRequest().TakeChannel().release()),
ZX_OK);
component_services_client_ =
std::make_unique<sys::ServiceDirectory>(std::move(svc_directory));
// Place the ServiceDirectory in the |flat_namespace|.
startup_info.flat_namespace.paths.emplace_back(
base::fuchsia::kServiceDirectoryPath);
startup_info.flat_namespace.directories.emplace_back(
directory.TakeChannel());
fuchsia::sys::Package package;
package.resolved_url = component_url.as_string();
fuchsia::sys::ComponentControllerPtr component_controller;
cast_runner_ptr_->StartComponent(std::move(package),
std::move(startup_info),
component_controller.NewRequest());
EXPECT_TRUE(component_controller.is_bound());
return component_controller;
}
protected:
explicit CastRunnerIntegrationTest(
fuchsia::web::ContextFeatureFlags feature_flags) {
......@@ -275,14 +239,99 @@ class CastRunnerIntegrationTest : public testing::Test {
return component_state;
}
std::unique_ptr<cr_fuchsia::FakeComponentContext> CreateComponentContext(
const base::StringPiece& component_url) {
return std::make_unique<cr_fuchsia::FakeComponentContext>(
void RegisterAppWithTestData(GURL url) {
fuchsia::web::ContentDirectoryProvider provider;
provider.set_name("testdata");
base::FilePath pkg_path;
CHECK(base::PathService::Get(base::DIR_ASSETS, &pkg_path));
provider.set_directory(base::fuchsia::OpenDirectory(
pkg_path.AppendASCII("fuchsia/runners/cast/testdata")));
std::vector<fuchsia::web::ContentDirectoryProvider> providers;
providers.emplace_back(std::move(provider));
auto app_config =
FakeApplicationConfigManager::CreateConfig(kTestAppId, url);
app_config.set_content_directories_for_isolated_application(
std::move(providers));
app_config_manager_.AddAppConfig(std::move(app_config));
}
void CreateComponentContextAndStartComponent() {
auto component_url = base::StringPrintf("cast:%s", kTestAppId);
CreateComponentContext(component_url);
StartCastComponent(component_url);
WaitComponentCreated();
}
void CreateComponentContext(const base::StringPiece& component_url) {
component_context_ = std::make_unique<cr_fuchsia::FakeComponentContext>(
base::BindRepeating(&CastRunnerIntegrationTest::OnComponentConnect,
base::Unretained(this)),
&component_services_, component_url);
}
void StartCastComponent(base::StringPiece component_url) {
// Configure the Runner, including a service directory channel to publish
// services to.
fidl::InterfaceHandle<fuchsia::io::Directory> directory;
component_services_.GetOrCreateDirectory("svc")->Serve(
fuchsia::io::OPEN_RIGHT_READABLE | fuchsia::io::OPEN_RIGHT_WRITABLE,
directory.NewRequest().TakeChannel());
fuchsia::sys::StartupInfo startup_info;
startup_info.launch_info.url = component_url.as_string();
fidl::InterfaceHandle<fuchsia::io::Directory> outgoing_directory;
startup_info.launch_info.directory_request =
outgoing_directory.NewRequest().TakeChannel();
fidl::InterfaceHandle<::fuchsia::io::Directory> svc_directory;
CHECK_EQ(fdio_service_connect_at(
outgoing_directory.channel().get(), "svc",
svc_directory.NewRequest().TakeChannel().release()),
ZX_OK);
component_services_client_ =
std::make_unique<sys::ServiceDirectory>(std::move(svc_directory));
// Place the ServiceDirectory in the |flat_namespace|.
startup_info.flat_namespace.paths.emplace_back(
base::fuchsia::kServiceDirectoryPath);
startup_info.flat_namespace.directories.emplace_back(
directory.TakeChannel());
fuchsia::sys::Package package;
package.resolved_url = component_url.as_string();
cast_runner_ptr_->StartComponent(std::move(package),
std::move(startup_info),
component_controller_.NewRequest());
component_controller_.set_error_handler(&ComponentErrorHandler);
}
void WaitComponentCreated() {
EXPECT_FALSE(cast_component_);
base::RunLoop run_loop;
cr_fuchsia::ResultReceiver<WebComponent*> component_receiver(
run_loop.QuitClosure());
cast_runner_->SetWebComponentCreatedCallbackForTest(
base::AdaptCallbackForRepeating(
component_receiver.GetReceiveCallback()));
run_loop.Run();
ASSERT_NE(*component_receiver, nullptr);
cast_component_ = reinterpret_cast<CastComponent*>(*component_receiver);
}
void WaitUrlAndTitle(const GURL& url, const std::string& title) {
base::RunLoop run_loop;
cr_fuchsia::TestNavigationListener listener;
fidl::Binding<fuchsia::web::NavigationEventListener> listener_binding(
&listener);
cast_component_->frame()->SetNavigationEventListener(
listener_binding.NewBinding());
listener.RunUntilUrlAndTitleEquals(url, title);
}
base::test::SingleThreadTaskEnvironment task_environment_{
base::test::SingleThreadTaskEnvironment::MainThreadType::IO};
net::EmbeddedTestServer test_server_;
......@@ -294,8 +343,10 @@ class CastRunnerIntegrationTest : public testing::Test {
// Incoming service directory, ComponentContext and per-component state.
sys::OutgoingDirectory component_services_;
std::unique_ptr<cr_fuchsia::FakeComponentContext> component_context_;
fuchsia::sys::ComponentControllerPtr component_controller_;
std::unique_ptr<sys::ServiceDirectory> component_services_client_;
FakeComponentState* component_state_ = nullptr;
CastComponent* cast_component_ = nullptr;
// ServiceDirectory into which the CastRunner will publish itself.
sys::OutgoingDirectory outgoing_directory_;
......@@ -308,33 +359,13 @@ class CastRunnerIntegrationTest : public testing::Test {
// A basic integration test ensuring a basic cast request launches the right
// URL in the Chromium service.
TEST_F(CastRunnerIntegrationTest, BasicRequest) {
const char kBlankAppId[] = "00000000";
const char kBlankAppPath[] = "/defaultresponse";
app_config_manager_.AddAppMapping(kBlankAppId,
test_server_.GetURL(kBlankAppPath), false);
GURL app_url = test_server_.GetURL(kBlankAppUrl);
app_config_manager_.AddApp(kTestAppId, app_url);
auto component_url = base::StringPrintf("cast:%s", kBlankAppId);
// Create a FakeComponentContext and publish it into component_services_.
component_context_ = CreateComponentContext(component_url);
// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller =
StartCastComponent(component_url);
component_controller.set_error_handler(&ComponentErrorHandler);
// Access the NavigationController from the CastComponent. The test will hang
// here if no CastComponent was created.
CreateComponentContextAndStartComponent();
fuchsia::web::NavigationControllerPtr nav_controller;
{
base::RunLoop run_loop;
cr_fuchsia::ResultReceiver<WebComponent*> component(run_loop.QuitClosure());
cast_runner_->SetWebComponentCreatedCallbackForTest(
base::AdaptCallbackForRepeating(component.GetReceiveCallback()));
run_loop.Run();
ASSERT_NE(*component, nullptr);
(*component)->frame()->GetNavigationController(nav_controller.NewRequest());
}
cast_component_->frame()->GetNavigationController(
nav_controller.NewRequest());
// Ensure the NavigationState has the expected URL.
{
......@@ -345,7 +376,7 @@ TEST_F(CastRunnerIntegrationTest, BasicRequest) {
cr_fuchsia::CallbackToFitFunction(nav_entry.GetReceiveCallback()));
run_loop.Run();
ASSERT_TRUE(nav_entry->has_url());
EXPECT_EQ(nav_entry->url(), test_server_.GetURL(kBlankAppPath).spec());
EXPECT_EQ(nav_entry->url(), app_url.spec());
}
EXPECT_FALSE(cast_runner_->is_headless());
......@@ -354,17 +385,12 @@ TEST_F(CastRunnerIntegrationTest, BasicRequest) {
// unbound.
base::RunLoop run_loop;
component_state_->set_on_delete(run_loop.QuitClosure());
component_controller.Unbind();
component_controller_.Unbind();
run_loop.Run();
}
TEST_F(CastRunnerIntegrationTest, ApiBindings) {
const char kBlankAppId[] = "00000000";
const char kBlankAppPath[] = "/echo.html";
auto component_url = base::StringPrintf("cast:%s", kBlankAppId);
app_config_manager_.AddAppMapping(kBlankAppId,
test_server_.GetURL(kBlankAppPath), false);
app_config_manager_.AddApp(kTestAppId, test_server_.GetURL(kEchoAppPath));
std::vector<chromium::cast::ApiBinding> binding_list;
chromium::cast::ApiBinding echo_binding;
......@@ -374,13 +400,7 @@ TEST_F(CastRunnerIntegrationTest, ApiBindings) {
binding_list.emplace_back(std::move(echo_binding));
api_bindings_.set_bindings(std::move(binding_list));
// Create a FakeComponentContext and publish it into component_services_.
component_context_ = CreateComponentContext(component_url);
// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller =
StartCastComponent(component_url);
component_controller.set_error_handler(&ComponentErrorHandler);
CreateComponentContextAndStartComponent();
fuchsia::web::MessagePortPtr port =
api_bindings_.RunUntilMessagePortReceived("echoService").Bind();
......@@ -409,18 +429,13 @@ TEST_F(CastRunnerIntegrationTest, ApiBindings) {
TEST_F(CastRunnerIntegrationTest, IncorrectCastAppId) {
const char kIncorrectComponentUrl[] = "cast:99999999";
// Create a FakeComponentContext and publish it into component_services_.
component_context_ = CreateComponentContext(kIncorrectComponentUrl);
// Launch the a component with an invalid Cast app Id.
fuchsia::sys::ComponentControllerPtr component_controller =
StartCastComponent(kIncorrectComponentUrl);
component_controller.set_error_handler(&ComponentErrorHandler);
CreateComponentContext(kIncorrectComponentUrl);
StartCastComponent(kIncorrectComponentUrl);
// Run the loop until the ComponentController is dropped, or a WebComponent is
// created.
base::RunLoop run_loop;
component_controller.set_error_handler([&run_loop](zx_status_t status) {
component_controller_.set_error_handler([&run_loop](zx_status_t status) {
EXPECT_EQ(status, ZX_ERR_PEER_CLOSED);
run_loop.Quit();
});
......@@ -433,62 +448,31 @@ TEST_F(CastRunnerIntegrationTest, IncorrectCastAppId) {
}
TEST_F(CastRunnerIntegrationTest, UrlRequestRewriteRulesProvider) {
const char kEchoAppId[] = "00000000";
const char kEchoAppPath[] = "/echoheader?Test";
const GURL echo_app_url = test_server_.GetURL(kEchoAppPath);
auto component_url = base::StringPrintf("cast:%s", kEchoAppId);
app_config_manager_.AddAppMapping(kEchoAppId, echo_app_url, false);
GURL echo_app_url = test_server_.GetURL(kEchoHeaderPath);
app_config_manager_.AddApp(kTestAppId, echo_app_url);
// Create a FakeComponentContext and publish it into component_services_.
component_context_ = CreateComponentContext(component_url);
// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller =
StartCastComponent(component_url);
component_controller.set_error_handler(&ComponentErrorHandler);
WebComponent* web_component = nullptr;
{
base::RunLoop run_loop;
cr_fuchsia::ResultReceiver<WebComponent*> web_component_receiver(
run_loop.QuitClosure());
cast_runner_->SetWebComponentCreatedCallbackForTest(
AdaptCallbackForRepeating(web_component_receiver.GetReceiveCallback()));
run_loop.Run();
ASSERT_NE(*web_component_receiver, nullptr);
web_component = *web_component_receiver;
}
CreateComponentContextAndStartComponent();
// Bind a TestNavigationListener to the Frame.
cr_fuchsia::TestNavigationListener navigation_listener;
fidl::Binding<fuchsia::web::NavigationEventListener>
navigation_listener_binding(&navigation_listener);
web_component->frame()->SetNavigationEventListener(
cast_component_->frame()->SetNavigationEventListener(
navigation_listener_binding.NewBinding());
navigation_listener.RunUntilUrlEquals(echo_app_url);
// Check the header was properly set.
base::Optional<base::Value> result = cr_fuchsia::ExecuteJavaScript(
web_component->frame(), "document.body.innerText");
cast_component_->frame(), "document.body.innerText");
ASSERT_TRUE(result);
ASSERT_TRUE(result->is_string());
EXPECT_EQ(result->GetString(), "Value");
}
TEST_F(CastRunnerIntegrationTest, ApplicationControllerBound) {
const char kCastChannelAppId[] = "00000001";
const char kCastChannelAppPath[] = "/defaultresponse";
auto component_url = base::StringPrintf("cast:%s", kCastChannelAppId);
app_config_manager_.AddApp(kTestAppId, test_server_.GetURL(kBlankAppUrl));
app_config_manager_.AddAppMapping(
kCastChannelAppId, test_server_.GetURL(kCastChannelAppPath), false);
// Create a FakeComponentContext and publish it into component_services_.
component_context_ = CreateComponentContext(component_url);
fuchsia::sys::ComponentControllerPtr component_controller =
StartCastComponent(component_url);
CreateComponentContextAndStartComponent();
// Spin the message loop to handle creation of the component state.
base::RunLoop().RunUntilIdle();
......@@ -498,20 +482,13 @@ TEST_F(CastRunnerIntegrationTest, ApplicationControllerBound) {
// Verify an App launched with remote debugging enabled is properly reachable.
TEST_F(CastRunnerIntegrationTest, RemoteDebugging) {
const char kBlankAppId[] = "00000000";
const char kBlankAppPath[] = "/defaultresponse";
const GURL kBlankAppUrl = test_server_.GetURL(kBlankAppPath);
auto component_url = base::StringPrintf("cast:%s", kBlankAppId);
app_config_manager_.AddAppMapping(kBlankAppId, kBlankAppUrl, true);
GURL app_url = test_server_.GetURL(kBlankAppUrl);
auto app_config =
FakeApplicationConfigManager::CreateConfig(kTestAppId, app_url);
app_config.set_enable_remote_debugging(true);
app_config_manager_.AddAppConfig(std::move(app_config));
// Create a FakeComponentContext and publish it into component_services_.
component_context_ = CreateComponentContext(component_url);
// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller =
StartCastComponent(component_url);
component_controller.set_error_handler(&ComponentErrorHandler);
CreateComponentContextAndStartComponent();
// Get the remote debugging port from the Context.
uint16_t remote_debugging_port = 0;
......@@ -537,61 +514,26 @@ TEST_F(CastRunnerIntegrationTest, RemoteDebugging) {
base::Value* devtools_url = devtools_list.GetList()[0].FindPath("url");
ASSERT_TRUE(devtools_url->is_string());
EXPECT_EQ(devtools_url->GetString(), kBlankAppUrl.spec());
EXPECT_EQ(devtools_url->GetString(), app_url.spec());
}
TEST_F(CastRunnerIntegrationTest, IsolatedContext) {
const char kBlankAppId[] = "00000000";
const GURL kContentDirectoryUrl("fuchsia-dir://testdata/echo.html");
auto component_url = base::StringPrintf("cast:%s", kBlankAppId);
EXPECT_EQ(cast_runner_->GetChildCastRunnerCountForTest(), 0u);
fuchsia::web::ContentDirectoryProvider provider;
provider.set_name("testdata");
base::FilePath pkg_path;
CHECK(base::PathService::Get(base::DIR_ASSETS, &pkg_path));
provider.set_directory(base::fuchsia::OpenDirectory(
pkg_path.AppendASCII("fuchsia/runners/cast/testdata")));
std::vector<fuchsia::web::ContentDirectoryProvider> providers;
providers.emplace_back(std::move(provider));
app_config_manager_.AddAppMappingWithContentDirectories(
kBlankAppId, kContentDirectoryUrl, std::move(providers));
// Create a FakeComponentContext and publish it into component_services_.
component_context_ = CreateComponentContext(component_url);
// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller =
StartCastComponent(component_url);
component_controller.set_error_handler(&ComponentErrorHandler);
// Navigate to the page and verify that we read it.
{
base::RunLoop run_loop;
cr_fuchsia::ResultReceiver<WebComponent*> web_component(
run_loop.QuitClosure());
cast_runner_->SetWebComponentCreatedCallbackForTest(
AdaptCallbackForRepeating(web_component.GetReceiveCallback()));
run_loop.Run();
ASSERT_NE(*web_component, nullptr);
RegisterAppWithTestData(kContentDirectoryUrl);
EXPECT_EQ(cast_runner_->GetChildCastRunnerCountForTest(), 1u);
CreateComponentContextAndStartComponent();
EXPECT_EQ(cast_runner_->GetChildCastRunnerCountForTest(), 1u);
cr_fuchsia::TestNavigationListener listener;
fidl::Binding<fuchsia::web::NavigationEventListener> listener_binding(
&listener);
(*web_component)
->frame()
->SetNavigationEventListener(listener_binding.NewBinding());
listener.RunUntilUrlAndTitleEquals(kContentDirectoryUrl, "echo");
}
WaitUrlAndTitle(kContentDirectoryUrl, "echo");
// Verify that the component is torn down when |component_controller| is
// unbound.
base::RunLoop run_loop;
component_state_->set_on_delete(run_loop.QuitClosure());
component_controller.Unbind();
component_controller_.Unbind();
run_loop.Run();
EXPECT_EQ(cast_runner_->GetChildCastRunnerCountForTest(), 0u);
......@@ -599,17 +541,12 @@ TEST_F(CastRunnerIntegrationTest, IsolatedContext) {
// Test the lack of CastAgent service does not cause a CastRunner crash.
TEST_F(CastRunnerIntegrationTest, NoCastAgent) {
const char kEchoAppId[] = "00000000";
const char kEchoAppPath[] = "/echoheader?Test";
const GURL echo_app_url = test_server_.GetURL(kEchoAppPath);
app_config_manager_.AddAppMapping(kEchoAppId, echo_app_url, false);
app_config_manager_.AddApp(kTestAppId, test_server_.GetURL(kEchoHeaderPath));
// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller =
StartCastComponent(base::StringPrintf("cast:%s", kEchoAppId));
StartCastComponent(base::StringPrintf("cast:%s", kTestAppId));
base::RunLoop run_loop;
component_controller.set_error_handler([&run_loop](zx_status_t error) {
component_controller_.set_error_handler([&run_loop](zx_status_t error) {
EXPECT_EQ(error, ZX_ERR_PEER_CLOSED);
run_loop.Quit();
});
......@@ -618,37 +555,15 @@ TEST_F(CastRunnerIntegrationTest, NoCastAgent) {
// Test the CastAgent disconnecting does not cause a CastRunner crash.
TEST_F(CastRunnerIntegrationTest, DisconnectedCastAgent) {
const char kEchoAppId[] = "00000000";
const char kEchoAppPath[] = "/echoheader?Test";
const GURL echo_app_url = test_server_.GetURL(kEchoAppPath);
auto component_url = base::StringPrintf("cast:%s", kEchoAppId);
app_config_manager_.AddAppMapping(kEchoAppId, echo_app_url, false);
app_config_manager_.AddApp(kTestAppId, test_server_.GetURL(kEchoHeaderPath));
component_context_ = CreateComponentContext(component_url);
// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller =
StartCastComponent(component_url);
// Access the NavigationController from the WebComponent. The test will hang
// here if no WebComponent was created.
CreateComponentContextAndStartComponent();
fuchsia::web::NavigationControllerPtr nav_controller;
{
base::RunLoop run_loop;
cr_fuchsia::ResultReceiver<WebComponent*> web_component(
run_loop.QuitClosure());
cast_runner_->SetWebComponentCreatedCallbackForTest(
base::AdaptCallbackForRepeating(web_component.GetReceiveCallback()));
run_loop.Run();
ASSERT_NE(*web_component, nullptr);
(*web_component)
->frame()
->GetNavigationController(nav_controller.NewRequest());
}
cast_component_->frame()->GetNavigationController(
nav_controller.NewRequest());
base::RunLoop run_loop;
component_controller.set_error_handler([&run_loop](zx_status_t error) {
component_controller_.set_error_handler([&run_loop](zx_status_t error) {
EXPECT_EQ(error, ZX_ERR_PEER_CLOSED);
run_loop.Quit();
});
......@@ -665,18 +580,16 @@ TEST_F(CastRunnerIntegrationTest, DisconnectedCastAgent) {
// AppConfigManager is the one used to retrieve the bindings and the rewrite
// rules.
TEST_F(CastRunnerIntegrationTest, ApplicationConfigAgentUrl) {
const char kBlankAppId[] = "00000000";
const char kBlankAppPath[] = "/echo.html";
auto component_url = base::StringPrintf("cast:%s", kBlankAppId);
// These are part of the secondary agent, and CastRunner will contact
// the secondary agent for both of them.
FakeUrlRequestRewriteRulesProvider dummy_url_request_rewrite_rules_provider;
TestApiBindings dummy_agent_api_bindings;
// Indicate that this app is to get bindings from a secondary agent.
app_config_manager_.AddAppMappingWithAgent(
kBlankAppId, test_server_.GetURL(kBlankAppPath), false, kDummyAgentUrl);
auto app_config = FakeApplicationConfigManager::CreateConfig(
kTestAppId, test_server_.GetURL(kEchoAppPath));
app_config.set_agent_url(kDummyAgentUrl);
app_config_manager_.AddAppConfig(std::move(app_config));
// Instantiate the bindings that are returned in the multi-agent scenario. The
// bindings returned for the single-agent scenario are not initialized.
......@@ -689,7 +602,8 @@ TEST_F(CastRunnerIntegrationTest, ApplicationConfigAgentUrl) {
// Assign the bindings to the multi-agent binding.
dummy_agent_api_bindings.set_bindings(std::move(binding_list));
component_context_ = CreateComponentContext(component_url);
auto component_url = base::StringPrintf("cast:%s", kTestAppId);
CreateComponentContext(component_url);
EXPECT_NE(component_context_, nullptr);
component_context_->RegisterCreateComponentStateCallback(
kDummyAgentUrl,
......@@ -701,10 +615,7 @@ TEST_F(CastRunnerIntegrationTest, ApplicationConfigAgentUrl) {
&dummy_url_request_rewrite_rules_provider);
}));
// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller =
StartCastComponent(component_url);
component_controller.set_error_handler(&ComponentErrorHandler);
StartCastComponent(component_url);
base::RunLoop().RunUntilIdle();
......@@ -718,15 +629,13 @@ TEST_F(CastRunnerIntegrationTest, ApplicationConfigAgentUrl) {
// created. Further validate that the primary agent does not provide ApiBindings
// or RewriteRules.
TEST_F(CastRunnerIntegrationTest, ApplicationConfigAgentUrlRewriteOptional) {
const char kBlankAppId[] = "00000000";
const char kBlankAppPath[] = "/echo.html";
const std::string component_url = base::StringPrintf("cast:%s", kBlankAppId);
TestApiBindings dummy_agent_api_bindings;
// Indicate that this app is to get bindings from a secondary agent.
app_config_manager_.AddAppMappingWithAgent(
kBlankAppId, test_server_.GetURL(kBlankAppPath), false, kDummyAgentUrl);
auto app_config = FakeApplicationConfigManager::CreateConfig(
kTestAppId, test_server_.GetURL(kEchoAppPath));
app_config.set_agent_url(kDummyAgentUrl);
app_config_manager_.AddAppConfig(std::move(app_config));
// Instantiate the bindings that are returned in the multi-agent scenario. The
// bindings returned for the single-agent scenario are not initialized.
......@@ -739,7 +648,8 @@ TEST_F(CastRunnerIntegrationTest, ApplicationConfigAgentUrlRewriteOptional) {
// Assign the bindings to the multi-agent binding.
dummy_agent_api_bindings.set_bindings(std::move(binding_list));
component_context_ = CreateComponentContext(component_url);
auto component_url = base::StringPrintf("cast:%s", kTestAppId);
CreateComponentContext(component_url);
EXPECT_NE(component_context_, nullptr);
component_context_->RegisterCreateComponentStateCallback(
kDummyAgentUrl,
......@@ -751,22 +661,8 @@ TEST_F(CastRunnerIntegrationTest, ApplicationConfigAgentUrlRewriteOptional) {
nullptr);
}));
// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller =
StartCastComponent(component_url);
component_controller.set_error_handler(&ComponentErrorHandler);
// Validate that the WebComponent was created successfully when RewriteRules
// are not provided.
{
base::RunLoop run_loop;
cr_fuchsia::ResultReceiver<WebComponent*> web_component(
run_loop.QuitClosure());
cast_runner_->SetWebComponentCreatedCallbackForTest(
base::AdaptCallbackForRepeating(web_component.GetReceiveCallback()));
run_loop.Run();
ASSERT_NE(*web_component, nullptr);
}
StartCastComponent(component_url);
WaitComponentCreated();
base::RunLoop().RunUntilIdle();
......@@ -788,59 +684,27 @@ class HeadlessCastRunnerIntegrationTest : public CastRunnerIntegrationTest {
TEST_F(HeadlessCastRunnerIntegrationTest, Headless) {
ASSERT_TRUE(cast_runner_->is_headless());
const char kAnimationAppId[] = "00000000";
const char kAnimationPath[] = "/css_animation.html";
const GURL animation_url = test_server_.GetURL(kAnimationPath);
auto component_url = base::StringPrintf("cast:%s", kAnimationAppId);
app_config_manager_.AddAppMapping(kAnimationAppId, animation_url, false);
// Create a FakeComponentContext and publish it into component_services_.
component_context_ = CreateComponentContext(component_url);
// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller =
StartCastComponent(component_url);
component_controller.set_error_handler(&ComponentErrorHandler);
CastComponent* component;
// Access the NavigationController from the CastComponent. The test will hang
// here if no CastComponent was created.
fuchsia::web::NavigationControllerPtr nav_controller;
{
base::RunLoop run_loop;
cr_fuchsia::ResultReceiver<WebComponent*> component_receiver(
run_loop.QuitClosure());
cast_runner_->SetWebComponentCreatedCallbackForTest(
base::AdaptCallbackForRepeating(
component_receiver.GetReceiveCallback()));
run_loop.Run();
ASSERT_NE(*component_receiver, nullptr);
component = reinterpret_cast<CastComponent*>(*component_receiver);
}
app_config_manager_.AddApp(kTestAppId, animation_url);
CreateComponentContextAndStartComponent();
auto tokens = scenic::ViewTokenPair::New();
component->CreateView(std::move(tokens.view_holder_token.value), {}, {});
cast_component_->CreateView(std::move(tokens.view_holder_token.value), {},
{});
// Ensure the NavigationState has the expected URL.
{
cr_fuchsia::TestNavigationListener listener;
fidl::Binding<fuchsia::web::NavigationEventListener> listener_binding(
&listener);
component->frame()->SetNavigationEventListener(
listener_binding.NewBinding());
listener.RunUntilUrlAndTitleEquals(animation_url, "animation finished");
}
WaitUrlAndTitle(animation_url, "animation finished");
// Verify that dropping the "view" EventPair is handled by the CastComponent.
{
base::RunLoop run_loop;
component->set_on_headless_disconnect_for_test(run_loop.QuitClosure());
cast_component_->set_on_headless_disconnect_for_test(
run_loop.QuitClosure());
tokens.view_token.value.reset();
run_loop.Run();
}
component_controller.Unbind();
component_controller_.Unbind();
base::RunLoop().RunUntilIdle();
}
......@@ -848,58 +712,23 @@ TEST_F(HeadlessCastRunnerIntegrationTest, Headless) {
TEST_F(HeadlessCastRunnerIntegrationTest, IsolatedAndHeadless) {
ASSERT_TRUE(cast_runner_->is_headless());
const char kBlankAppId[] = "00000000";
const GURL kContentDirectoryUrl("fuchsia-dir://testdata/echo.html");
const std::string component_url = base::StringPrintf("cast:%s", kBlankAppId);
EXPECT_EQ(cast_runner_->GetChildCastRunnerCountForTest(), 0u);
fuchsia::web::ContentDirectoryProvider provider;
provider.set_name("testdata");
base::FilePath pkg_path;
CHECK(base::PathService::Get(base::DIR_ASSETS, &pkg_path));
provider.set_directory(base::fuchsia::OpenDirectory(
pkg_path.AppendASCII("fuchsia/runners/cast/testdata")));
std::vector<fuchsia::web::ContentDirectoryProvider> providers;
providers.emplace_back(std::move(provider));
app_config_manager_.AddAppMappingWithContentDirectories(
kBlankAppId, kContentDirectoryUrl, std::move(providers));
// Create a FakeComponentContext and publish it into component_services_.
component_context_ = CreateComponentContext(component_url);
// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller =
StartCastComponent(component_url);
component_controller.set_error_handler(&ComponentErrorHandler);
// Navigate to the page and verify that we read it.
{
base::RunLoop run_loop;
cr_fuchsia::ResultReceiver<WebComponent*> component(run_loop.QuitClosure());
cast_runner_->SetWebComponentCreatedCallbackForTest(
AdaptCallbackForRepeating(component.GetReceiveCallback()));
run_loop.Run();
ASSERT_NE(*component, nullptr);
RegisterAppWithTestData(kContentDirectoryUrl);
EXPECT_TRUE((*component)->runner()->is_headless());
CreateComponentContextAndStartComponent();
EXPECT_TRUE(cast_component_->runner()->is_headless());
EXPECT_EQ(cast_runner_->GetChildCastRunnerCountForTest(), 1u);
EXPECT_EQ(cast_runner_->GetChildCastRunnerCountForTest(), 1u);
cr_fuchsia::TestNavigationListener listener;
fidl::Binding<fuchsia::web::NavigationEventListener> listener_binding(
&listener);
(*component)
->frame()
->SetNavigationEventListener(listener_binding.NewBinding());
listener.RunUntilUrlAndTitleEquals(kContentDirectoryUrl, "echo");
}
WaitUrlAndTitle(kContentDirectoryUrl, "echo");
// Verify that the component is torn down when |component_controller| is
// unbound.
base::RunLoop run_loop;
component_state_->set_on_delete(run_loop.QuitClosure());
component_controller.Unbind();
component_controller_.Unbind();
run_loop.Run();
EXPECT_EQ(cast_runner_->GetChildCastRunnerCountForTest(), 0u);
......
......@@ -14,10 +14,31 @@ const char kAgentComponentUrl[] =
"fuchsia-pkg://fuchsia.com/cast_agent#meta/cast_agent.cmx";
} // namespace
FakeApplicationConfigManager::FakeApplicationConfigManager() = default;
// static
chromium::cast::ApplicationConfig FakeApplicationConfigManager::CreateConfig(
const std::string& id,
const GURL& url) {
chromium::cast::ApplicationConfig app_config;
app_config.set_id(id);
app_config.set_display_name("Dummy test app");
app_config.set_web_url(url.spec());
app_config.set_agent_url(kAgentComponentUrl);
return app_config;
}
FakeApplicationConfigManager::FakeApplicationConfigManager() = default;
FakeApplicationConfigManager::~FakeApplicationConfigManager() = default;
void FakeApplicationConfigManager::AddAppConfig(
chromium::cast::ApplicationConfig app_config) {
id_to_config_[app_config.id()] = std::move(app_config);
}
void FakeApplicationConfigManager::AddApp(const std::string& id,
const GURL& url) {
AddAppConfig(CreateConfig(id, url));
}
void FakeApplicationConfigManager::GetConfig(std::string id,
GetConfigCallback callback) {
if (id_to_config_.find(id) == id_to_config_.end()) {
......@@ -29,40 +50,3 @@ void FakeApplicationConfigManager::GetConfig(std::string id,
callback(std::move(std::move(id_to_config_[id])));
id_to_config_.erase(id);
}
void FakeApplicationConfigManager::AddAppMapping(const std::string& id,
const GURL& url,
bool enable_remote_debugging) {
AddAppMappingWithAgent(id, url, enable_remote_debugging, kAgentComponentUrl);
}
void FakeApplicationConfigManager::AddAppMappingWithAgent(
const std::string& id,
const GURL& url,
bool enable_remote_debugging,
const std::string& agent_url) {
chromium::cast::ApplicationConfig app_config;
app_config.set_id(id);
app_config.set_display_name("Dummy test app");
app_config.set_web_url(url.spec());
app_config.set_enable_remote_debugging(enable_remote_debugging);
app_config.set_agent_url(agent_url);
id_to_config_[id] = std::move(app_config);
}
void FakeApplicationConfigManager::AddAppMappingWithContentDirectories(
const std::string& id,
const GURL& url,
std::vector<fuchsia::web::ContentDirectoryProvider> directories) {
chromium::cast::ApplicationConfig app_config;
app_config.set_id(id);
app_config.set_display_name("Dummy test app");
app_config.set_web_url(url.spec());
app_config.set_agent_url(kAgentComponentUrl);
if (!directories.empty()) {
app_config.set_content_directories_for_isolated_application(
std::move(directories));
}
id_to_config_[id] = std::move(app_config);
}
......@@ -21,25 +21,17 @@ class FakeApplicationConfigManager
FakeApplicationConfigManager();
~FakeApplicationConfigManager() override;
// Associates a Cast application |id| with a url, to be served from the
// EmbeddedTestServer.
void AddAppMapping(const std::string& id,
const GURL& url,
bool enable_remote_debugging);
// Associates a Cast application |id| with a url and an agent that handles
// its bindings, to be served from the EmbeddedTestServer.
void AddAppMappingWithAgent(const std::string& id,
const GURL& url,
bool enable_remote_debugging,
const std::string& agent_url);
// Associates a Cast application |id| with a url and a set of content
// directories, to be served from the EmbeddedTestServer.
void AddAppMappingWithContentDirectories(
const std::string& id,
const GURL& url,
std::vector<fuchsia::web::ContentDirectoryProvider> directories);
// Creates a config for a dummy application with the specified |id| and |url|.
// Callers should updated the returned config as necessary and then register
// the app by calling AddAppConfig().
static chromium::cast::ApplicationConfig CreateConfig(const std::string& id,
const GURL& url);
// Adds |app_config| to the list of apps.
void AddAppConfig(chromium::cast::ApplicationConfig app_config);
// Associates a Cast application |id| with the |url|.
void AddApp(const std::string& id, const GURL& url);
// chromium::cast::ApplicationConfigManager interface.
void GetConfig(std::string id, GetConfigCallback config_callback) override;
......
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