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 kDartJitRunner =
"dart_jit_runner";
30constexpr auto kDartJitRunnerRef = ChildRef{kDartJitRunner};
31constexpr auto kDartJitRunnerUrl =
32 "fuchsia-pkg://fuchsia.com/oot_dart_jit_runner#meta/"
35constexpr auto kDartJitEchoServer =
"dart_jit_echo_server";
36constexpr auto kDartJitEchoServerRef = ChildRef{kDartJitEchoServer};
37constexpr auto kDartJitEchoServerUrl =
38 "fuchsia-pkg://fuchsia.com/dart_jit_echo_server#meta/"
39 "dart_jit_echo_server.cm";
41class RealmBuilderTest :
public ::loop_fixture::RealLoop,
42 public ::testing::Test {
44 RealmBuilderTest() =
default;
47TEST_F(RealmBuilderTest, DartRunnerStartsUp) {
50 realm_builder.AddChild(kDartJitRunner, kDartJitRunnerUrl);
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_jit_runner_reg;
61 dart_jit_runner_reg.set_source(fuchsia::component::decl::Ref::WithChild(
62 fuchsia::component::decl::ChildRef{.name = kDartJitRunner}));
63 dart_jit_runner_reg.set_source_name(kDartJitRunner);
64 dart_jit_runner_reg.set_target_name(kDartJitRunner);
65 environment_runners->push_back(std::move(dart_jit_runner_reg));
66 auto realm_decl = realm_builder.GetRealmDecl();
67 if (!realm_decl.has_environments()) {
68 realm_decl.set_environments({});
70 auto realm_environments = realm_decl.mutable_environments();
71 realm_environments->push_back(std::move(dart_runner_environment));
72 realm_builder.ReplaceRealmDecl(std::move(realm_decl));
75 realm_builder.AddChild(kDartJitEchoServer, kDartJitEchoServerUrl,
76 ChildOptions{.environment = kDartRunnerEnvironment});
79 realm_builder.AddRoute(
80 Route{.capabilities = {Protocol{
"fuchsia.logger.LogSink"},
81 Protocol{
"fuchsia.tracing.provider.Registry"},
82 Protocol{
"fuchsia.posix.socket.Provider"},
83 Protocol{
"fuchsia.intl.PropertyProvider"},
84 Protocol{
"fuchsia.inspect.InspectSink"},
85 Directory{
"config-data"}},
86 .source = ParentRef(),
87 .targets = {kDartJitRunnerRef, kDartJitEchoServerRef}});
91 realm_builder.AddRoute(Route{.capabilities = {Protocol{
"dart.test.Echo"}},
92 .source = kDartJitEchoServerRef,
93 .targets = {ParentRef()}});
96 auto realm = realm_builder.Build(dispatcher());
97 FML_LOG(INFO) <<
"Realm built: " << realm.component().GetChildName();
100 fidl::StringPtr response;
102 echo->EchoString(
"hello", &response);
103 ASSERT_EQ(response,
"hello");
static sk_sp< Effect > Create()
#define FML_LOG(severity)
static void Echo(Thread *thread, JSONStream *js)
TEST_F(DisplayListTest, Defaults)