5#define FML_USED_ON_EMBEDDER
7#include "flutter/lib/ui/window/platform_configuration.h"
11#include "flutter/common/task_runners.h"
12#include "flutter/fml/synchronization/waitable_event.h"
13#include "flutter/lib/ui/painting/vertices.h"
14#include "flutter/runtime/dart_vm.h"
15#include "flutter/shell/common/shell_test.h"
16#include "flutter/shell/common/thread_host.h"
17#include "flutter/testing/testing.h"
25 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
27 auto nativeValidateConfiguration =
31 ASSERT_NE(configuration->
GetMetrics(0),
nullptr);
36 message_latch->Signal();
47 AddNativeCallback(
"ValidateConfiguration",
50 std::unique_ptr<Shell>
shell = CreateShell(
settings, task_runners);
52 ASSERT_TRUE(
shell->IsSetup());
54 run_configuration.SetEntrypoint(
"validateConfiguration");
56 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
60 message_latch->Wait();
61 DestroyShell(std::move(
shell), task_runners);
65 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
67 auto nativeValidateConfiguration =
72 ASSERT_NE(configuration->
GetMetrics(0),
nullptr);
75 ASSERT_TRUE(has_view);
81 message_latch->Signal();
92 AddNativeCallback(
"ValidateConfiguration",
95 std::unique_ptr<Shell>
shell = CreateShell(
settings, task_runners);
97 ASSERT_TRUE(
shell->IsSetup());
99 run_configuration.SetEntrypoint(
"validateConfiguration");
101 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
105 message_latch->Wait();
106 DestroyShell(std::move(
shell), task_runners);
110 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
112 auto nativeValidateConfiguration =
117 ASSERT_EQ(configuration->
GetMetrics(1),
nullptr);
118 ASSERT_EQ(configuration->
GetMetrics(2),
nullptr);
120 message_latch->Signal();
131 AddNativeCallback(
"ValidateConfiguration",
134 std::unique_ptr<Shell>
shell = CreateShell(
settings, task_runners);
136 ASSERT_TRUE(
shell->IsSetup());
138 run_configuration.SetEntrypoint(
"validateConfiguration");
140 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
144 message_latch->Wait();
145 DestroyShell(std::move(
shell), task_runners);
149 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
150 bool did_throw =
false;
153 message_latch->Signal();
158 settings.unhandled_exception_callback =
159 [&did_throw](
const std::string& exception,
160 const std::string& stack_trace) ->
bool {
172 std::unique_ptr<Shell>
shell = CreateShell(
settings, task_runners);
174 ASSERT_TRUE(
shell->IsSetup());
176 run_configuration.SetEntrypoint(
"customOnErrorTrue");
178 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
182 message_latch->Wait();
187 [&message_latch]() { message_latch->Signal(); });
188 message_latch->Wait();
190 ASSERT_FALSE(did_throw);
191 DestroyShell(std::move(
shell), task_runners);
195 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
198 size_t throw_count = 0;
201 message_latch->Signal();
206 settings.unhandled_exception_callback =
207 [&ex, &st, &throw_count](
const std::string& exception,
208 const std::string& stack_trace) ->
bool {
222 std::unique_ptr<Shell>
shell = CreateShell(
settings, task_runners);
224 ASSERT_TRUE(
shell->IsSetup());
226 run_configuration.SetEntrypoint(
"customOnErrorFalse");
228 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
232 message_latch->Wait();
237 [&message_latch]() { message_latch->Signal(); });
238 message_latch->Wait();
240 ASSERT_EQ(throw_count, 1ul);
241 ASSERT_EQ(ex,
"Exception: false") << ex;
242 ASSERT_EQ(st.rfind(
"#0 customOnErrorFalse", 0), 0ul) << st;
243 DestroyShell(std::move(
shell), task_runners);
247 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
248 std::vector<std::string>
errors;
249 size_t throw_count = 0;
252 message_latch->Signal();
257 settings.unhandled_exception_callback =
258 [&
errors, &throw_count](
const std::string& exception,
259 const std::string& stack_trace) ->
bool {
261 errors.push_back(exception);
262 errors.push_back(stack_trace);
273 std::unique_ptr<Shell>
shell = CreateShell(
settings, task_runners);
275 ASSERT_TRUE(
shell->IsSetup());
277 run_configuration.SetEntrypoint(
"customOnErrorThrow");
279 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
283 message_latch->Wait();
288 [&message_latch]() { message_latch->Signal(); });
289 message_latch->Wait();
291 ASSERT_EQ(throw_count, 2ul);
292 ASSERT_EQ(
errors.size(), 4ul);
294 ASSERT_EQ(
errors[1].rfind(
"#0 customOnErrorThrow"), 0ul) <<
errors[1];
296 ASSERT_EQ(
errors[3].rfind(
"#0 customOnErrorThrow"), 0ul) <<
errors[3];
298 DestroyShell(std::move(
shell), task_runners);
302 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
308 message_latch->Signal();
321 std::unique_ptr<Shell>
shell = CreateShell(
settings, task_runners);
323 ASSERT_TRUE(
shell->IsSetup());
325 run_configuration.SetEntrypoint(
"setLatencyPerformanceMode");
327 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
331 message_latch->Wait();
332 DestroyShell(std::move(
shell), task_runners);
static float prev(float f)
static RunConfiguration InferFromSettings(const Settings &settings, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
PlatformConfiguration * platform_configuration() const
static UIDartState * Current()
virtual void PostTask(const fml::closure &task) override
@ Dart_PerformanceMode_Default
@ Dart_PerformanceMode_Latency
struct _Dart_NativeArguments * Dart_NativeArguments
DART_EXPORT Dart_PerformanceMode Dart_SetPerformanceMode(Dart_PerformanceMode mode)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
fml::RefPtr< fml::TaskRunner > CreateNewThread(const std::string &name)
fml::RefPtr< fml::TaskRunner > GetCurrentTaskRunner()
TEST_F(DisplayListTest, Defaults)
double device_pixel_ratio
double physical_touch_slop
#define CREATE_NATIVE_ENTRY(native_entry)