Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Replace an unnecessary util function with PostSync #45190

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions shell/common/shell_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4391,17 +4391,6 @@ static void ParseViewIdsCallback(const Dart_NativeArguments& args,
ASSERT_EQ(exception, nullptr);
}

// Run the given task in the platform runner, and blocks until its finished.
static void RunOnPlatformTaskRunner(Shell& shell, const fml::closure& task) {
fml::AutoResetWaitableEvent latch;
fml::TaskRunner::RunNowOrPostTask(
shell.GetTaskRunners().GetPlatformTaskRunner(), [&task, &latch]() {
task();
latch.Signal();
});
latch.Wait();
}

TEST_F(ShellTest, ShellStartsWithImplicitView) {
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
Settings settings = CreateSettingsForFixture();
Expand Down Expand Up @@ -4472,21 +4461,22 @@ TEST_F(ShellTest, ShellCanAddViewOrRemoveView) {
ASSERT_EQ(viewIds.size(), 1u);
ASSERT_EQ(viewIds[0], 0ll);

RunOnPlatformTaskRunner(*shell,
[&shell] { shell->AddView(2, ViewportMetrics{}); });
PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(),
[&shell] { shell->AddView(2, ViewportMetrics{}); });
reportLatch.Wait();
ASSERT_TRUE(hasImplicitView);
ASSERT_EQ(viewIds.size(), 2u);
ASSERT_EQ(viewIds[1], 2ll);

RunOnPlatformTaskRunner(*shell, [&shell] { shell->RemoveView(2); });
PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(),
[&shell] { shell->RemoveView(2); });
reportLatch.Wait();
ASSERT_TRUE(hasImplicitView);
ASSERT_EQ(viewIds.size(), 1u);
ASSERT_EQ(viewIds[0], 0ll);

RunOnPlatformTaskRunner(*shell,
[&shell] { shell->AddView(4, ViewportMetrics{}); });
PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(),
[&shell] { shell->AddView(4, ViewportMetrics{}); });
reportLatch.Wait();
ASSERT_TRUE(hasImplicitView);
ASSERT_EQ(viewIds.size(), 2u);
Expand Down Expand Up @@ -4531,7 +4521,7 @@ TEST_F(ShellTest, ShellFlushesPlatformStatesByMain) {
std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
ASSERT_TRUE(shell);

RunOnPlatformTaskRunner(*shell, [&shell] {
PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
auto platform_view = shell->GetPlatformView();
// The construtor for ViewportMetrics{_, width, _, _, _} (only the 2nd
// argument matters in this test).
Expand Down