src/modular/tests/sessionmgr_integration_test.cc
// Create a service in the test harness that is also provided by the session environment. Verify
// story mods get the session's version of the service, even though the test harness's version of
// the service is still accessible outside of the story/session.
Create a service in the test harness that is also provided by the session environment. Verify
story mods get the session's version of the service, even though the test harness's version of
the service is still accessible outside of the story/session.
Create a service in the test harness that is also provided by the session environment . Verify story mods get the session ' s version of the service even though the test harness ' s version of the service is still accessible outside of the story / session .
TEST_F(SessionmgrIntegrationTest, StoryModsGetServicesFromSessionEnvironment) {
  modular_testing::TestHarnessBuilder builder;
  auto session_shell = modular_testing::FakeSessionShell::CreateWithDefaultOptions();
  builder.InterceptSessionShell(session_shell->BuildInterceptOptions());
  IntlPropertyProviderImpl fake_intl_property_provider;
  fidl::BindingSet<fuchsia::intl::PropertyProvider> intl_property_provider_bindings;
  builder.AddService(intl_property_provider_bindings.GetHandler(&fake_intl_property_provider));
  auto fake_module_url = modular_testing::TestHarnessBuilder::GenerateFakeUrl("fake_module");
  modular_testing::FakeModule fake_module{
      {.url = fake_module_url, .sandbox_services = {"fuchsia.intl.PropertyProvider"}}};
  builder.InterceptComponent(fake_module.BuildInterceptOptions());
  builder.BuildAndRun(test_harness());
  ASSERT_FALSE(session_shell->is_running());
  RunLoopUntil([&] { return session_shell->is_running(); });
  fuchsia::modular::Intent intent;
  intent.handler = fake_module_url;
  intent.action = "action";
  modular_testing::AddModToStory(test_harness(), "fake_story", "fake_modname", std::move(intent));
  ASSERT_FALSE(fake_module.is_running());
  RunLoopUntil([&] { return fake_module.is_running(); });
  fuchsia::intl::PropertyProviderPtr module_intl_property_provider;
  auto got_module_intl_property_provider =
      fake_module.component_context()->svc()->Connect<fuchsia::intl::PropertyProvider>(
          module_intl_property_provider.NewRequest());
  EXPECT_EQ(got_module_intl_property_provider, ZX_OK);
  bool got_profile_from_module_callback = false;
  zx_status_t get_profile_from_module_status = ZX_OK;
  module_intl_property_provider->GetProfile(
      [&](fuchsia::intl::Profile new_profile) { got_profile_from_module_callback = true; });
  module_intl_property_provider.set_error_handler(
      [&](zx_status_t status) { get_profile_from_module_status = status; });
  RunLoopUntil(
      [&] { return got_profile_from_module_callback || get_profile_from_module_status != ZX_OK; });
  ASSERT_EQ(get_profile_from_module_status, ZX_OK);
  ASSERT_EQ(fake_intl_property_provider.call_count(), 0);
  fuchsia::intl::PropertyProviderPtr intl_property_provider;
  test_harness()->ConnectToEnvironmentService(fuchsia::intl::PropertyProvider::Name_,
                                              intl_property_provider.NewRequest().TakeChannel());
  bool got_profile_callback = false;
  zx_status_t got_profile_error = ZX_OK;
  intl_property_provider.set_error_handler([&](zx_status_t status) { got_profile_error = status; });
  intl_property_provider->GetProfile(
      [&](fuchsia::intl::Profile new_profile) { got_profile_callback = true; });
  RunLoopUntil([&] { return got_profile_callback || got_profile_error != ZX_OK; });
  ASSERT_EQ(got_profile_error, ZX_OK);
  ASSERT_EQ(fake_intl_property_provider.call_count(), 1);
}
TEST_F ( SessionmgrIntegrationTest , StoryModsGetServicesFromSessionEnvironment ) { modular_testing :: TestHarnessBuilder builder ; auto session_shell = modular_testing :: FakeSessionShell :: CreateWithDefaultOptions ( ) ; builder . InterceptSessionShell ( session_shell -> BuildInterceptOptions ( ) ) ; IntlPropertyProviderImpl fake_intl_property_provider ; fidl :: BindingSet < fuchsia :: intl :: PropertyProvider > intl_property_provider_bindings ; builder . AddService ( intl_property_provider_bindings . GetHandler ( & fake_intl_property_provider ) ) ; auto fake_module_url = modular_testing :: TestHarnessBuilder :: GenerateFakeUrl ( " " ) ; modular_testing :: FakeModule fake_module { { . url = fake_module_url , . sandbox_services = { " " } } } ; builder . InterceptComponent ( fake_module . BuildInterceptOptions ( ) ) ; builder . BuildAndRun ( test_harness ( ) ) ; ASSERT_FALSE ( session_shell -> is_running ( ) ) ; RunLoopUntil ( [ & ] { return session_shell -> is_running ( ) ; } ) ; fuchsia :: modular :: Intent intent ; intent . handler = fake_module_url ; intent . action = " " ; modular_testing :: AddModToStory ( test_harness ( ) , " " , " " , std :: move ( intent ) ) ; ASSERT_FALSE ( fake_module . is_running ( ) ) ; RunLoopUntil ( [ & ] { return fake_module . is_running ( ) ; } ) ; fuchsia :: intl :: PropertyProviderPtr module_intl_property_provider ; auto got_module_intl_property_provider = fake_module . component_context ( ) -> svc ( ) -> Connect < fuchsia :: intl :: PropertyProvider > ( module_intl_property_provider . NewRequest ( ) ) ; EXPECT_EQ ( got_module_intl_property_provider , ZX_OK ) ; bool got_profile_from_module_callback = false ; zx_status_t get_profile_from_module_status = ZX_OK ; module_intl_property_provider -> GetProfile ( [ & ] ( fuchsia :: intl :: Profile new_profile ) { got_profile_from_module_callback = true ; } ) ; module_intl_property_provider . set_error_handler ( [ & ] ( zx_status_t status ) { get_profile_from_module_status = status ; } ) ; RunLoopUntil ( [ & ] { return got_profile_from_module_callback || get_profile_from_module_status != ZX_OK ; } ) ; ASSERT_EQ ( get_profile_from_module_status , ZX_OK ) ; ASSERT_EQ ( fake_intl_property_provider . call_count ( ) , 0 ) ; fuchsia :: intl :: PropertyProviderPtr intl_property_provider ; test_harness ( ) -> ConnectToEnvironmentService ( fuchsia :: intl :: PropertyProvider :: Name_ , intl_property_provider . NewRequest ( ) . TakeChannel ( ) ) ; bool got_profile_callback = false ; zx_status_t got_profile_error = ZX_OK ; intl_property_provider . set_error_handler ( [ & ] ( zx_status_t status ) { got_profile_error = status ; } ) ; intl_property_provider -> GetProfile ( [ & ] ( fuchsia :: intl :: Profile new_profile ) { got_profile_callback = true ; } ) ; RunLoopUntil ( [ & ] { return got_profile_callback || got_profile_error != ZX_OK ; } ) ; ASSERT_EQ ( got_profile_error , ZX_OK ) ; ASSERT_EQ ( fake_intl_property_provider . call_count ( ) , 1 ) ; }
Create a service in the test harness that is also provided by the session environment.
Create a service in the test harness that is also provided by the session environment .
// Add a fake fuchsia::intl::PropertyProvider to the test harness' environment. // Register a fake component to be launched as a story mod // Create the test harness and verify the session shell is up // Add at least one module to the story. This should launch the fake_module. // Request a fuchsia::intl::PropertyProvider from the story mod's component_context(). // It should get the service from the session environment, not the fake // version registered in the test_harness, outside the session. // fake_intl_property_provider.call_count() should still be zero (0). // And yet, the test_harness version of the service is still available, if requested outside of // the session scope. This time fake_intl_property_provider.call_count() should be one (1).