From d0261a05aa4025319b8455c6f7e33ecb5ebda8dd Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 11 Nov 2024 14:24:02 -0800 Subject: [PATCH 1/5] [engine] force semantics action to post a task. --- shell/common/shell.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 60779793529a2..c6078f78c7de6 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -1122,8 +1122,7 @@ void Shell::OnPlatformViewDispatchSemanticsAction(int32_t node_id, FML_DCHECK(is_set_up_); FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread()); - fml::TaskRunner::RunNowOrPostTask( - task_runners_.GetUITaskRunner(), + task_runners_.GetUITaskRunner()->PostTask( fml::MakeCopyable([engine = engine_->GetWeakPtr(), node_id, action, args = std::move(args)]() mutable { if (engine) { From 71d5a88e17c016053b388ad5a0e48222a6bcfe82 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 11 Nov 2024 15:25:30 -0800 Subject: [PATCH 2/5] testing. --- shell/common/fixtures/shell_test.dart | 11 +++++++++ shell/common/shell_test.cc | 8 ++++++ shell/common/shell_test.h | 5 ++++ shell/common/shell_unittests.cc | 35 +++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/shell/common/fixtures/shell_test.dart b/shell/common/fixtures/shell_test.dart index 9826d58b95a65..60727567e5737 100644 --- a/shell/common/fixtures/shell_test.dart +++ b/shell/common/fixtures/shell_test.dart @@ -4,6 +4,7 @@ // ignore_for_file: avoid_print +import 'dart:async'; import 'dart:convert' show json, utf8; import 'dart:isolate'; import 'dart:typed_data'; @@ -629,3 +630,13 @@ void renderWarmUpView1and2() { } }); } + +@pragma('vm:entry-point') +void testSemanticsActions() { + PlatformDispatcher.instance.onSemanticsActionEvent = (SemanticsActionEvent action) async { + await null; + Future.value().then((_) { + notifyNative(); + }); + }; +} diff --git a/shell/common/shell_test.cc b/shell/common/shell_test.cc index 48a18b830f9ce..800d3d11c6d5c 100644 --- a/shell/common/shell_test.cc +++ b/shell/common/shell_test.cc @@ -65,6 +65,14 @@ void ShellTest::SendPlatformMessage(Shell* shell, shell->OnPlatformViewDispatchPlatformMessage(std::move(message)); } +void ShellTest::SendSemanticsAction(Shell* shell, + int32_t node_id, + SemanticsAction action, + fml::MallocMapping args) { + shell->OnPlatformViewDispatchSemanticsAction(node_id, action, + std::move(args)); +} + void ShellTest::SendEnginePlatformMessage( Shell* shell, std::unique_ptr message) { diff --git a/shell/common/shell_test.h b/shell/common/shell_test.h index 4fb758e55b90b..e980474364ad3 100644 --- a/shell/common/shell_test.h +++ b/shell/common/shell_test.h @@ -90,6 +90,11 @@ class ShellTest : public FixtureTest { void SendPlatformMessage(Shell* shell, std::unique_ptr message); + void SendSemanticsAction(Shell* shell, + int32_t node_id, + SemanticsAction action, + fml::MallocMapping args); + void SendEnginePlatformMessage(Shell* shell, std::unique_ptr message); diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index 2149c25f5a279..7f796141f8644 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "fml/mapping.h" +#include "lib/ui/semantics/semantics_node.h" #define FML_USED_ON_EMBEDDER #include @@ -4311,6 +4313,39 @@ TEST_F(ShellTest, NavigationMessageDispachedImmediately) { ASSERT_FALSE(DartVMRef::IsInstanceRunning()); } +TEST_F(ShellTest, SemanticsActionsPostTask) { + Settings settings = CreateSettingsForFixture(); + ThreadHost thread_host("io.flutter.test." + GetCurrentTestName() + ".", + ThreadHost::Type::kPlatform); + auto task_runner = thread_host.platform_thread->GetTaskRunner(); + TaskRunners task_runners("test", task_runner, task_runner, task_runner, + task_runner); + + EXPECT_EQ(task_runners.GetPlatformTaskRunner(), + task_runners.GetUITaskRunner()); + auto shell = CreateShell(settings); + auto configuration = RunConfiguration::InferFromSettings(settings); + configuration.SetEntrypoint("testSemanticsActions"); + + RunEngine(shell.get(), std::move(configuration)); + + SendSemanticsAction(shell.get(), 0, SemanticsAction::kTap, + fml::MallocMapping(nullptr, 0)); + + // Fulfill native function for the second Shell's entrypoint. + fml::CountDownLatch latch(1); + AddNativeCallback( + // The Dart native function names aren't very consistent but this is + // just the native function name of the second vm entrypoint in the + // fixture. + "NotifyNative", + CREATE_NATIVE_ENTRY([&](auto args) { latch.CountDown(); })); + latch.Wait(); + + DestroyShell(std::move(shell), task_runners); + ASSERT_FALSE(DartVMRef::IsInstanceRunning()); +} + TEST_F(ShellTest, DiesIfSoftwareRenderingAndImpellerAreEnabledDeathTest) { #if defined(OS_FUCHSIA) GTEST_SKIP() << "Fuchsia"; From 2f5d3aee977225fa5e6e1f05a1ea2e5b9720082d Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 11 Nov 2024 15:44:37 -0800 Subject: [PATCH 3/5] fix include order. --- shell/common/shell_unittests.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index 7f796141f8644..5a63903bbcaa2 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "fml/mapping.h" -#include "lib/ui/semantics/semantics_node.h" #define FML_USED_ON_EMBEDDER #include @@ -47,8 +45,10 @@ #include "flutter/shell/common/vsync_waiters_test.h" #include "flutter/shell/version/version.h" #include "flutter/testing/testing.h" +#include "fml/mapping.h" #include "gmock/gmock.h" #include "impeller/core/runtime_types.h" +#include "lib/ui/semantics/semantics_node.h" #include "third_party/rapidjson/include/rapidjson/writer.h" #include "third_party/skia/include/codec/SkCodecAnimation.h" #include "third_party/tonic/converter/dart_converter.h" From c572fc29125a1822f9be3a3227a762cdb44a2400 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Tue, 12 Nov 2024 09:51:19 -0800 Subject: [PATCH 4/5] post from correct thread. --- shell/common/shell_unittests.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index 5a63903bbcaa2..aa5b5cc90dd59 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -4329,8 +4329,10 @@ TEST_F(ShellTest, SemanticsActionsPostTask) { RunEngine(shell.get(), std::move(configuration)); - SendSemanticsAction(shell.get(), 0, SemanticsAction::kTap, - fml::MallocMapping(nullptr, 0)); + task_runners.GetPlatformTaskRunner()->PostTask([&] { + SendSemanticsAction(shell.get(), 0, SemanticsAction::kTap, + fml::MallocMapping(nullptr, 0)); + }); // Fulfill native function for the second Shell's entrypoint. fml::CountDownLatch latch(1); From 509cb8e86758d721af280833bfa3840ee2967d3e Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Tue, 12 Nov 2024 15:24:08 -0800 Subject: [PATCH 5/5] fix test. --- shell/common/shell_unittests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index aa5b5cc90dd59..1875eac3aaef9 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -4323,7 +4323,7 @@ TEST_F(ShellTest, SemanticsActionsPostTask) { EXPECT_EQ(task_runners.GetPlatformTaskRunner(), task_runners.GetUITaskRunner()); - auto shell = CreateShell(settings); + auto shell = CreateShell(settings, task_runners); auto configuration = RunConfiguration::InferFromSettings(settings); configuration.SetEntrypoint("testSemanticsActions");