5#include <dart/test/cpp/fidl.h>
6#include <fuchsia/tracing/provider/cpp/fidl.h>
7#include <lib/async-loop/testing/cpp/real_loop.h>
8#include <lib/sys/component/cpp/testing/realm_builder.h>
9#include <lib/sys/component/cpp/testing/realm_builder_types.h>
11#include "flutter/fml/logging.h"
12#include "gtest/gtest.h"
18using component_testing::ChildOptions;
19using component_testing::ChildRef;
20using component_testing::Directory;
21using component_testing::ParentRef;
22using component_testing::Protocol;
23using component_testing::RealmBuilder;
24using component_testing::RealmRoot;
25using component_testing::Route;
27constexpr auto kDartRunnerEnvironment =
"dart_runner_env";
29constexpr auto kDartAotRunner =
"dart_aot_runner";
30constexpr auto kDartAotRunnerRef = ChildRef{kDartAotRunner};
31constexpr auto kDartAotRunnerUrl =
32 "fuchsia-pkg://fuchsia.com/oot_dart_aot_runner#meta/"
35constexpr auto kDartAotEchoServer =
"dart_aot_echo_server";
36constexpr auto kDartAotEchoServerRef = ChildRef{kDartAotEchoServer};
37constexpr auto kDartAotEchoServerUrl =
38 "fuchsia-pkg://fuchsia.com/dart_aot_echo_server#meta/"
39 "dart_aot_echo_server.cm";
41class RealmBuilderTest :
public ::loop_fixture::RealLoop,
42 public ::testing::Test {
44 RealmBuilderTest() =
default;
47TEST_F(RealmBuilderTest, DartRunnerStartsUp) {
50 realm_builder.AddChild(kDartAotRunner, kDartAotRunnerUrl);
53 fuchsia::component::decl::Environment dart_runner_environment;
54 dart_runner_environment.set_name(kDartRunnerEnvironment);
55 dart_runner_environment.set_extends(
56 fuchsia::component::decl::EnvironmentExtends::REALM);
57 dart_runner_environment.set_runners({});
58 auto environment_runners = dart_runner_environment.mutable_runners();
60 fuchsia::component::decl::RunnerRegistration dart_aot_runner_reg;
61 dart_aot_runner_reg.set_source(fuchsia::component::decl::Ref::WithChild(
62 fuchsia::component::decl::ChildRef{.name = kDartAotRunner}));
63 dart_aot_runner_reg.set_source_name(kDartAotRunner);
64 dart_aot_runner_reg.set_target_name(kDartAotRunner);
65 environment_runners->push_back(std::move(dart_aot_runner_reg));
67 auto realm_decl = realm_builder.GetRealmDecl();
68 if (!realm_decl.has_environments()) {
69 realm_decl.set_environments({});
71 auto realm_environments = realm_decl.mutable_environments();
72 realm_environments->push_back(std::move(dart_runner_environment));
73 realm_builder.ReplaceRealmDecl(std::move(realm_decl));
76 realm_builder.AddChild(kDartAotEchoServer, kDartAotEchoServerUrl,
77 ChildOptions{.environment = kDartRunnerEnvironment});
80 realm_builder.AddRoute(
81 Route{.capabilities = {Protocol{
"fuchsia.logger.LogSink"},
82 Protocol{
"fuchsia.tracing.provider.Registry"},
83 Protocol{
"fuchsia.posix.socket.Provider"},
84 Protocol{
"fuchsia.intl.PropertyProvider"},
85 Protocol{
"fuchsia.vulkan.loader.Loader"},
86 Protocol{
"fuchsia.inspect.InspectSink"},
87 Directory{
"config-data"}},
88 .source = ParentRef(),
89 .targets = {kDartAotRunnerRef, kDartAotEchoServerRef}});
93 realm_builder.AddRoute(Route{.capabilities = {Protocol{
"dart.test.Echo"}},
94 .source = kDartAotEchoServerRef,
95 .targets = {ParentRef()}});
98 auto realm = realm_builder.Build(dispatcher());
99 FML_LOG(INFO) <<
"Realm built: " << realm.component().GetChildName();
102 fidl::StringPtr response;
104 echo->EchoString(
"hello", &response);
105 ASSERT_EQ(response,
"hello");
static sk_sp< Effect > Create()
#define FML_LOG(severity)
static void Echo(Thread *thread, JSONStream *js)
TEST_F(DisplayListTest, Defaults)