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