29 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
31 auto nativeValidateConfiguration =
32 [message_latch](Dart_NativeArguments
args) {
35 ASSERT_NE(configuration->
GetMetrics(0),
nullptr);
40 message_latch->Signal();
43 Settings settings = CreateSettingsForFixture();
45 GetCurrentTaskRunner(),
51 AddNativeCallback(
"ValidateConfiguration",
54 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
56 ASSERT_TRUE(shell->IsSetup());
58 run_configuration.SetEntrypoint(
"validateConfiguration");
60 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
64 message_latch->Wait();
65 DestroyShell(std::move(shell), task_runners);
69 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
71 auto nativeValidateConfiguration =
72 [message_latch](Dart_NativeArguments
args) {
76 ASSERT_NE(configuration->
GetMetrics(0),
nullptr);
79 ASSERT_TRUE(has_view);
85 message_latch->Signal();
88 Settings settings = CreateSettingsForFixture();
90 GetCurrentTaskRunner(),
96 AddNativeCallback(
"ValidateConfiguration",
99 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
101 ASSERT_TRUE(shell->IsSetup());
103 run_configuration.SetEntrypoint(
"validateConfiguration");
105 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
109 message_latch->Wait();
110 DestroyShell(std::move(shell), task_runners);
114 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
116 auto nativeValidateConfiguration =
117 [message_latch](Dart_NativeArguments
args) {
121 ASSERT_EQ(configuration->
GetMetrics(1),
nullptr);
122 ASSERT_EQ(configuration->
GetMetrics(2),
nullptr);
124 message_latch->Signal();
127 Settings settings = CreateSettingsForFixture();
129 GetCurrentTaskRunner(),
135 AddNativeCallback(
"ValidateConfiguration",
138 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
140 ASSERT_TRUE(shell->IsSetup());
142 run_configuration.SetEntrypoint(
"validateConfiguration");
144 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
148 message_latch->Wait();
149 DestroyShell(std::move(shell), task_runners);
153 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
154 bool did_throw =
false;
156 auto finish = [message_latch](Dart_NativeArguments
args) {
157 message_latch->Signal();
161 Settings settings = CreateSettingsForFixture();
163 [&did_throw](
const std::string& exception,
164 const std::string& stack_trace) ->
bool {
170 GetCurrentTaskRunner(),
176 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
178 ASSERT_TRUE(shell->IsSetup());
180 run_configuration.SetEntrypoint(
"customOnErrorTrue");
182 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
186 message_latch->Wait();
191 [&message_latch]() { message_latch->Signal(); });
192 message_latch->Wait();
194 ASSERT_FALSE(did_throw);
195 DestroyShell(std::move(shell), task_runners);
199 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
202 size_t throw_count = 0;
204 auto finish = [message_latch](Dart_NativeArguments
args) {
205 message_latch->Signal();
209 Settings settings = CreateSettingsForFixture();
211 [&ex, &st, &throw_count](
const std::string& exception,
212 const std::string& stack_trace) ->
bool {
220 GetCurrentTaskRunner(),
226 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
228 ASSERT_TRUE(shell->IsSetup());
230 run_configuration.SetEntrypoint(
"customOnErrorFalse");
232 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
236 message_latch->Wait();
241 [&message_latch]() { message_latch->Signal(); });
242 message_latch->Wait();
244 ASSERT_EQ(throw_count, 1ul);
245 ASSERT_EQ(ex,
"Exception: false") << ex;
246 ASSERT_EQ(st.rfind(
"#0 customOnErrorFalse", 0), 0ul) << st;
247 DestroyShell(std::move(shell), task_runners);
251 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
252 std::vector<std::string> errors;
253 size_t throw_count = 0;
255 auto finish = [message_latch](Dart_NativeArguments
args) {
256 message_latch->Signal();
260 Settings settings = CreateSettingsForFixture();
262 [&errors, &throw_count](
const std::string& exception,
263 const std::string& stack_trace) ->
bool {
265 errors.push_back(exception);
266 errors.push_back(stack_trace);
271 GetCurrentTaskRunner(),
277 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
279 ASSERT_TRUE(shell->IsSetup());
281 run_configuration.SetEntrypoint(
"customOnErrorThrow");
283 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
287 message_latch->Wait();
292 [&message_latch]() { message_latch->Signal(); });
293 message_latch->Wait();
295 ASSERT_EQ(throw_count, 2ul);
296 ASSERT_EQ(errors.size(), 4ul);
297 ASSERT_EQ(errors[0],
"Exception: throw2") << errors[0];
298 ASSERT_EQ(errors[1].rfind(
"#0 customOnErrorThrow"), 0ul) << errors[1];
299 ASSERT_EQ(errors[2],
"Exception: throw1") << errors[2];
300 ASSERT_EQ(errors[3].rfind(
"#0 customOnErrorThrow"), 0ul) << errors[3];
302 DestroyShell(std::move(shell), task_runners);
306 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
307 auto finish = [message_latch](Dart_NativeArguments
args) {
309 Dart_PerformanceMode prev =
310 Dart_SetPerformanceMode(Dart_PerformanceMode_Default);
311 ASSERT_EQ(Dart_PerformanceMode_Latency, prev);
312 message_latch->Signal();
316 Settings settings = CreateSettingsForFixture();
319 GetCurrentTaskRunner(),
325 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
327 ASSERT_TRUE(shell->IsSetup());
329 run_configuration.SetEntrypoint(
"setLatencyPerformanceMode");
331 shell->RunEngine(std::move(run_configuration), [&](
auto result) {
335 message_latch->Wait();
336 DestroyShell(std::move(shell), task_runners);
340 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
345 auto nativeValidateConfiguration = [message_latch,
346 &platform](Dart_NativeArguments
args) {
352 Dart_GetField(Dart_RootLibrary(),
tonic::ToDart(
"_beginFrameHijack"));
353 platform->begin_frame_.
Clear();
356 message_latch->Signal();
358 AddNativeCallback(
"ValidateConfiguration",
361 std::vector<int64_t> frame_times;
362 std::vector<uint64_t> frame_numbers;
364 auto frame_latch = std::make_shared<fml::AutoResetWaitableEvent>();
367 auto nativeBeginFrame = [frame_latch, &frame_times,
368 &frame_numbers](Dart_NativeArguments
args) {
369 int64_t microseconds;
370 uint64_t frame_number;
371 Dart_IntegerToInt64(Dart_GetNativeArgument(
args, 0), µseconds);
372 Dart_IntegerToUint64(Dart_GetNativeArgument(
args, 1), &frame_number);
374 frame_times.push_back(microseconds);
375 frame_numbers.push_back(frame_number);
377 if (frame_times.size() == 3) {
378 frame_latch->Signal();
383 Settings settings = CreateSettingsForFixture();
385 GetCurrentTaskRunner(),
391 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
392 ASSERT_TRUE(shell->IsSetup());
395 configuration.SetEntrypoint(
"validateConfiguration");
397 shell->RunEngine(std::move(configuration), [&](
auto result) {
402 message_latch->Wait();
405 shell->GetTaskRunners().GetUITaskRunner(), [platform]() {
406 auto offset = fml::TimeDelta::FromMilliseconds(10);
407 auto zero = fml::TimePoint();
408 auto one = zero + offset;
409 auto two = one + offset;
411 platform->BeginFrame(zero, 1);
412 platform->BeginFrame(two, 2);
413 platform->BeginFrame(one, 3);
418 ASSERT_THAT(frame_times, ::testing::ElementsAre(0, 20000, 20000));
419 ASSERT_THAT(frame_numbers, ::testing::ElementsAre(1, 2, 3));
420 DestroyShell(std::move(shell), task_runners);
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...