Flutter Engine
flutter::testing::ShellTest Class Reference

#include <shell_test.h>

Inheritance diagram for flutter::testing::ShellTest:
flutter::testing::FixtureTest flutter::testing::DartFixture flutter::testing::ThreadTest flutter::testing::FuchsiaShellTest flutter::testing::ImageDisposeTest

Public Types

enum  ServiceProtocolEnum {
  kGetSkSLs,
  kEstimateRasterCacheMemory,
  kSetAssetBundlePath,
  kRunInView
}
 
using LayerTreeBuilder = std::function< void(std::shared_ptr< ContainerLayer > root)>
 

Public Member Functions

 ShellTest ()
 
Settings CreateSettingsForFixture () override
 
std::unique_ptr< ShellCreateShell (Settings settings, bool simulate_vsync=false)
 
std::unique_ptr< ShellCreateShell (Settings settings, TaskRunners task_runners, bool simulate_vsync=false, std::shared_ptr< ShellTestExternalViewEmbedder > shell_test_external_view_embedder=nullptr, bool is_gpu_disabled=false, ShellTestPlatformView::BackendType rendering_backend=ShellTestPlatformView::BackendType::kDefaultBackend, Shell::CreateCallback< PlatformView > platform_view_create_callback=nullptr)
 
void DestroyShell (std::unique_ptr< Shell > shell)
 
void DestroyShell (std::unique_ptr< Shell > shell, TaskRunners task_runners)
 
TaskRunners GetTaskRunnersForFixture ()
 
fml::TimePoint GetLatestFrameTargetTime (Shell *shell) const
 
void SendEnginePlatformMessage (Shell *shell, std::unique_ptr< PlatformMessage > message)
 
std::shared_ptr< txt::FontCollectionGetFontCollection (Shell *shell)
 
- Public Member Functions inherited from flutter::testing::FixtureTest
 FixtureTest ()
 
 FixtureTest (std::string kernel_filename, std::string elf_filename, std::string elf_split_filename)
 
- Public Member Functions inherited from flutter::testing::DartFixture
 DartFixture ()
 
 DartFixture (std::string kernel_filename, std::string elf_filename, std::string elf_split_filename)
 
void AddNativeCallback (std::string name, Dart_NativeFunction callback)
 
- Public Member Functions inherited from flutter::testing::ThreadTest
 ThreadTest ()
 
fml::RefPtr< fml::TaskRunnerGetCurrentTaskRunner ()
 Get the task runner for the thread that the current unit-test is running on. This creates a message loop as necessary. More...
 
fml::RefPtr< fml::TaskRunnerCreateNewThread (std::string name="")
 Creates a new thread, initializes a message loop on it, and, returns its task runner to the unit-test. The message loop is terminated (and its thread joined) when the test ends. This allows tests to create multiple named threads as necessary. More...
 

Static Public Member Functions

static void PlatformViewNotifyCreated (Shell *shell)
 
static void PlatformViewNotifyDestroyed (Shell *shell)
 
static void RunEngine (Shell *shell, RunConfiguration configuration)
 
static void RestartEngine (Shell *shell, RunConfiguration configuration)
 
static void VSyncFlush (Shell *shell, bool &will_draw_new_frame)
 
static void SetViewportMetrics (Shell *shell, double width, double height)
 
static void NotifyIdle (Shell *shell, int64_t deadline)
 
static void PumpOneFrame (Shell *shell, double width=1, double height=1, LayerTreeBuilder={})
 
static void PumpOneFrame (Shell *shell, flutter::ViewportMetrics viewport_metrics, LayerTreeBuilder={})
 
static void DispatchFakePointerData (Shell *shell)
 
static void DispatchPointerData (Shell *shell, std::unique_ptr< PointerDataPacket > packet)
 
static bool GetNeedsReportTimings (Shell *shell)
 
static void SetNeedsReportTimings (Shell *shell, bool value)
 
static void StorePersistentCache (PersistentCache *cache, const SkData &key, const SkData &value)
 
static bool IsAnimatorRunning (Shell *shell)
 
static void OnServiceProtocol (Shell *shell, ServiceProtocolEnum some_protocol, fml::RefPtr< fml::TaskRunner > task_runner, const ServiceProtocol::Handler::ServiceProtocolMap &params, rapidjson::Document *response)
 
static int UnreportedTimingsCount (Shell *shell)
 

Additional Inherited Members

- Protected Member Functions inherited from flutter::testing::DartFixture
void SetSnapshotsAndAssets (Settings &settings)
 
- Protected Attributes inherited from flutter::testing::DartFixture
std::shared_ptr< TestDartNativeResolvernative_resolver_
 
ELFAOTSymbols split_aot_symbols_
 
std::string kernel_filename_
 
std::string elf_filename_
 
fml::UniqueFD assets_dir_
 
ELFAOTSymbols aot_symbols_
 

Detailed Description

Definition at line 31 of file shell_test.h.

Member Typedef Documentation

◆ LayerTreeBuilder

Given the root layer, this callback builds the layer tree to be rasterized in PumpOneFrame.

Definition at line 72 of file shell_test.h.

Member Enumeration Documentation

◆ ServiceProtocolEnum

Constructor & Destructor Documentation

◆ ShellTest()

flutter::testing::ShellTest::ShellTest ( )

Definition at line 23 of file shell_test.cc.

24  : thread_host_("io.flutter.test." + GetCurrentTestName() + ".",
25  ThreadHost::Type::Platform | ThreadHost::Type::IO |
26  ThreadHost::Type::UI | ThreadHost::Type::RASTER) {}
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:13
ThreadHost thread_host_

Member Function Documentation

◆ CreateSettingsForFixture()

Settings flutter::testing::ShellTest::CreateSettingsForFixture ( )
overridevirtual

Reimplemented from flutter::testing::DartFixture.

Definition at line 282 of file shell_test.cc.

References fml::MessageLoop::AddTaskObserver(), fml::MessageLoop::GetCurrent(), flutter::Settings::isolate_create_callback, key, flutter::Settings::leak_vm, flutter::testing::DartFixture::native_resolver_, fml::MessageLoop::RemoveTaskObserver(), flutter::testing::DartFixture::SetSnapshotsAndAssets(), flutter::Settings::task_observer_add, flutter::Settings::task_observer_remove, and flutter::Settings::verbose_logging.

Referenced by flutter::testing::TEST_F(), and flutter::testing::TestSimulatedInputEvents().

282  {
283  Settings settings;
284  settings.leak_vm = false;
285  settings.task_observer_add = [](intptr_t key, fml::closure handler) {
287  };
288  settings.task_observer_remove = [](intptr_t key) {
290  };
291  settings.isolate_create_callback = [this]() {
292  native_resolver_->SetNativeResolverForIsolate();
293  };
294 #if OS_FUCHSIA
295  settings.verbose_logging = true;
296 #endif
297  SetSnapshotsAndAssets(settings);
298  return settings;
299 }
std::shared_ptr< TestDartNativeResolver > native_resolver_
Definition: dart_fixture.h:36
void AddTaskObserver(intptr_t key, const fml::closure &callback)
Definition: message_loop.cc:64
void SetSnapshotsAndAssets(Settings &settings)
Definition: dart_fixture.cc:39
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
std::function< void()> closure
Definition: closure.h:14
void RemoveTaskObserver(intptr_t key)
Definition: message_loop.cc:68

◆ CreateShell() [1/2]

std::unique_ptr< Shell > flutter::testing::ShellTest::CreateShell ( Settings  settings,
bool  simulate_vsync = false 
)

Definition at line 315 of file shell_test.cc.

References GetTaskRunnersForFixture().

Referenced by flutter::testing::TEST_F(), and flutter::testing::TestSimulatedInputEvents().

316  {
317  return CreateShell(std::move(settings), GetTaskRunnersForFixture(),
318  simulate_vsync);
319 }
TaskRunners GetTaskRunnersForFixture()
Definition: shell_test.cc:301
std::unique_ptr< Shell > CreateShell(Settings settings, bool simulate_vsync=false)
Definition: shell_test.cc:315

◆ CreateShell() [2/2]

std::unique_ptr< Shell > flutter::testing::ShellTest::CreateShell ( Settings  settings,
TaskRunners  task_runners,
bool  simulate_vsync = false,
std::shared_ptr< ShellTestExternalViewEmbedder shell_test_external_view_embedder = nullptr,
bool  is_gpu_disabled = false,
ShellTestPlatformView::BackendType  rendering_backend = ShellTestPlatformView::BackendType::kDefaultBackend,
Shell::CreateCallback< PlatformView platform_view_create_callback = nullptr 
)

Definition at line 321 of file shell_test.cc.

References flutter::testing::ShellTestPlatformView::Create(), and flutter::Shell::Create().

329  {
330  const auto vsync_clock = std::make_shared<ShellTestVsyncClock>();
331 
332  CreateVsyncWaiter create_vsync_waiter = [&]() {
333  if (simulate_vsync) {
334  return static_cast<std::unique_ptr<VsyncWaiter>>(
335  std::make_unique<ShellTestVsyncWaiter>(task_runners, vsync_clock));
336  } else {
337  return static_cast<std::unique_ptr<VsyncWaiter>>(
338  std::make_unique<VsyncWaiterFallback>(task_runners, true));
339  }
340  };
341 
342  if (!platform_view_create_callback) {
343  platform_view_create_callback = [vsync_clock, //
344  &create_vsync_waiter, //
345  shell_test_external_view_embedder, //
346  rendering_backend //
347  ](Shell& shell) {
348  return ShellTestPlatformView::Create(shell, //
349  shell.GetTaskRunners(), //
350  vsync_clock, //
351  std::move(create_vsync_waiter), //
352  rendering_backend, //
353  shell_test_external_view_embedder //
354  );
355  };
356  }
357 
358  Shell::CreateCallback<Rasterizer> rasterizer_create_callback =
359  [](Shell& shell) { return std::make_unique<Rasterizer>(shell); };
360 
362  task_runners, //
363  settings, //
364  platform_view_create_callback, //
365  rasterizer_create_callback, //
366  is_gpu_disabled //
367  );
368 }
std::function< std::unique_ptr< VsyncWaiter >()> CreateVsyncWaiter
static std::unique_ptr< Shell > Create(const PlatformData &platform_data, TaskRunners task_runners, Settings settings, const CreateCallback< PlatformView > &on_create_platform_view, const CreateCallback< Rasterizer > &on_create_rasterizer, bool is_gpu_disabled=false)
Creates a shell instance using the provided settings. The callbacks to create the various shell subco...
Definition: shell.cc:126
static std::unique_ptr< ShellTestPlatformView > Create(PlatformView::Delegate &delegate, TaskRunners task_runners, std::shared_ptr< ShellTestVsyncClock > vsync_clock, CreateVsyncWaiter create_vsync_waiter, BackendType backend, std::shared_ptr< ShellTestExternalViewEmbedder > shell_test_external_view_embedder)

◆ DestroyShell() [1/2]

void flutter::testing::ShellTest::DestroyShell ( std::unique_ptr< Shell shell)

Definition at line 370 of file shell_test.cc.

References GetTaskRunnersForFixture().

Referenced by flutter::testing::TEST_F().

370  {
371  DestroyShell(std::move(shell), GetTaskRunnersForFixture());
372 }
void DestroyShell(std::unique_ptr< Shell > shell)
Definition: shell_test.cc:370
TaskRunners GetTaskRunnersForFixture()
Definition: shell_test.cc:301

◆ DestroyShell() [2/2]

void flutter::testing::ShellTest::DestroyShell ( std::unique_ptr< Shell shell,
TaskRunners  task_runners 
)

Definition at line 374 of file shell_test.cc.

References flutter::TaskRunners::GetPlatformTaskRunner(), fml::TaskRunner::RunNowOrPostTask(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

375  {
377  fml::TaskRunner::RunNowOrPostTask(task_runners.GetPlatformTaskRunner(),
378  [&shell, &latch]() mutable {
379  shell.reset();
380  latch.Signal();
381  });
382  latch.Wait();
383 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55

◆ DispatchFakePointerData()

void flutter::testing::ShellTest::DispatchFakePointerData ( Shell shell)
static

Definition at line 214 of file shell_test.cc.

References DispatchPointerData().

Referenced by flutter::testing::TestSimulatedInputEvents().

214  {
215  auto packet = std::make_unique<PointerDataPacket>(1);
216  DispatchPointerData(shell, std::move(packet));
217 }
static void DispatchPointerData(Shell *shell, std::unique_ptr< PointerDataPacket > packet)
Definition: shell_test.cc:219

◆ DispatchPointerData()

void flutter::testing::ShellTest::DispatchPointerData ( Shell shell,
std::unique_ptr< PointerDataPacket packet 
)
static

Definition at line 219 of file shell_test.cc.

References flutter::TaskRunners::GetPlatformTaskRunner(), flutter::Shell::GetPlatformView(), flutter::Shell::GetTaskRunners(), fml::TaskRunner::PostTask(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

Referenced by DispatchFakePointerData(), and flutter::testing::TEST_F().

220  {
222  shell->GetTaskRunners().GetPlatformTaskRunner()->PostTask(
223  [&latch, shell, &packet]() {
224  // Goes through PlatformView to ensure packet is corrected converted.
225  shell->GetPlatformView()->DispatchPointerDataPacket(std::move(packet));
226  latch.Signal();
227  });
228  latch.Wait();
229 }

◆ GetFontCollection()

std::shared_ptr< txt::FontCollection > flutter::testing::ShellTest::GetFontCollection ( Shell shell)

Definition at line 277 of file shell_test.cc.

278  {
279  return shell->weak_engine_->GetFontCollection().GetFontCollection();
280 }

◆ GetLatestFrameTargetTime()

fml::TimePoint flutter::testing::ShellTest::GetLatestFrameTargetTime ( Shell shell) const

Definition at line 311 of file shell_test.cc.

311  {
312  return shell->GetLatestFrameTargetTime();
313 }

◆ GetNeedsReportTimings()

bool flutter::testing::ShellTest::GetNeedsReportTimings ( Shell shell)
static

Definition at line 239 of file shell_test.cc.

239  {
240  return shell->needs_report_timings_;
241 }

◆ GetTaskRunnersForFixture()

TaskRunners flutter::testing::ShellTest::GetTaskRunnersForFixture ( )

Definition at line 301 of file shell_test.cc.

References flutter::ThreadHost::io_thread, flutter::ThreadHost::platform_thread, flutter::ThreadHost::raster_thread, and flutter::ThreadHost::ui_thread.

Referenced by CreateShell(), DestroyShell(), and flutter::testing::TestSimulatedInputEvents().

301  {
302  return {
303  "test",
304  thread_host_.platform_thread->GetTaskRunner(), // platform
305  thread_host_.raster_thread->GetTaskRunner(), // raster
306  thread_host_.ui_thread->GetTaskRunner(), // ui
307  thread_host_.io_thread->GetTaskRunner() // io
308  };
309 }
ThreadHost thread_host_

◆ IsAnimatorRunning()

bool flutter::testing::ShellTest::IsAnimatorRunning ( Shell shell)
static

Definition at line 385 of file shell_test.cc.

References flutter::Shell::GetTaskRunners(), flutter::TaskRunners::GetUITaskRunner(), fml::TaskRunner::RunNowOrPostTask(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

385  {
387  bool running = false;
388  if (!shell) {
389  return running;
390  }
392  shell->GetTaskRunners().GetUITaskRunner(), [shell, &running, &latch]() {
393  if (shell && shell->engine_ && shell->engine_->animator_) {
394  running = !shell->engine_->animator_->paused_;
395  }
396  latch.Signal();
397  });
398  latch.Wait();
399  return running;
400 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55

◆ NotifyIdle()

void flutter::testing::ShellTest::NotifyIdle ( Shell shell,
int64_t  deadline 
)
static

Definition at line 152 of file shell_test.cc.

References engine, flutter::Shell::GetTaskRunners(), flutter::TaskRunners::GetUITaskRunner(), fml::TaskRunner::PostTask(), and fml::AutoResetWaitableEvent::Signal().

152  {
154  shell->GetTaskRunners().GetUITaskRunner()->PostTask(
155  [&latch, engine = shell->weak_engine_, deadline]() {
156  if (engine) {
157  engine->NotifyIdle(deadline);
158  }
159  latch.Signal();
160  });
161  latch.Wait();
162 }

◆ OnServiceProtocol()

void flutter::testing::ShellTest::OnServiceProtocol ( Shell shell,
ServiceProtocolEnum  some_protocol,
fml::RefPtr< fml::TaskRunner task_runner,
const ServiceProtocol::Handler::ServiceProtocolMap params,
rapidjson::Document *  response 
)
static

Definition at line 249 of file shell_test.cc.

References fml::TaskRunner::RunNowOrPostTask().

254  {
255  std::promise<bool> finished;
257  task_runner, [shell, some_protocol, params, response, &finished]() {
258  switch (some_protocol) {
259  case ServiceProtocolEnum::kGetSkSLs:
260  shell->OnServiceProtocolGetSkSLs(params, response);
261  break;
262  case ServiceProtocolEnum::kEstimateRasterCacheMemory:
263  shell->OnServiceProtocolEstimateRasterCacheMemory(params, response);
264  break;
265  case ServiceProtocolEnum::kSetAssetBundlePath:
266  shell->OnServiceProtocolSetAssetBundlePath(params, response);
267  break;
268  case ServiceProtocolEnum::kRunInView:
269  shell->OnServiceProtocolRunInView(params, response);
270  break;
271  }
272  finished.set_value(true);
273  });
274  finished.get_future().wait();
275 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55

◆ PlatformViewNotifyCreated()

void flutter::testing::ShellTest::PlatformViewNotifyCreated ( Shell shell)
static

Definition at line 44 of file shell_test.cc.

References flutter::TaskRunners::GetPlatformTaskRunner(), flutter::Shell::GetPlatformView(), flutter::Shell::GetTaskRunners(), fml::TaskRunner::RunNowOrPostTask(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

Referenced by flutter::testing::TEST_F(), and flutter::testing::ValidateShell().

44  {
47  shell->GetTaskRunners().GetPlatformTaskRunner(), [shell, &latch]() {
48  shell->GetPlatformView()->NotifyCreated();
49  latch.Signal();
50  });
51  latch.Wait();
52 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55

◆ PlatformViewNotifyDestroyed()

void flutter::testing::ShellTest::PlatformViewNotifyDestroyed ( Shell shell)
static

Definition at line 54 of file shell_test.cc.

References flutter::TaskRunners::GetPlatformTaskRunner(), flutter::Shell::GetPlatformView(), flutter::Shell::GetTaskRunners(), fml::TaskRunner::RunNowOrPostTask(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

Referenced by flutter::testing::ValidateDestroyPlatformView().

54  {
57  shell->GetTaskRunners().GetPlatformTaskRunner(), [shell, &latch]() {
58  shell->GetPlatformView()->NotifyDestroyed();
59  latch.Signal();
60  });
61  latch.Wait();
62 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55

◆ PumpOneFrame() [1/2]

void flutter::testing::ShellTest::PumpOneFrame ( Shell shell,
double  width = 1,
double  height = 1,
LayerTreeBuilder  builder = {} 
)
static

Definition at line 164 of file shell_test.cc.

References height, and width.

167  {
168  PumpOneFrame(shell, {1.0, width, height, 22}, std::move(builder));
169 }
static void PumpOneFrame(Shell *shell, double width=1, double height=1, LayerTreeBuilder={})
Definition: shell_test.cc:164
int32_t width
int32_t height

◆ PumpOneFrame() [2/2]

void flutter::testing::ShellTest::PumpOneFrame ( Shell shell,
flutter::ViewportMetrics  viewport_metrics,
LayerTreeBuilder  builder = {} 
)
static

Definition at line 171 of file shell_test.cc.

References flutter::ViewportMetrics::device_pixel_ratio, engine, flutter::Shell::GetTaskRunners(), flutter::TaskRunners::GetUITaskRunner(), flutter::ViewportMetrics::physical_height, flutter::ViewportMetrics::physical_width, fml::TaskRunner::PostTask(), fml::AutoResetWaitableEvent::Reset(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

173  {
174  // Set viewport to nonempty, and call Animator::BeginFrame to make the layer
175  // tree pipeline nonempty. Without either of this, the layer tree below
176  // won't be rasterized.
178  shell->GetTaskRunners().GetUITaskRunner()->PostTask(
179  [&latch, engine = shell->weak_engine_, viewport_metrics]() {
180  engine->SetViewportMetrics(std::move(viewport_metrics));
181  const auto frame_begin_time = fml::TimePoint::Now();
182  const auto frame_end_time =
183  frame_begin_time + fml::TimeDelta::FromSecondsF(1.0 / 60.0);
184  std::unique_ptr<FrameTimingsRecorder> recorder =
185  std::make_unique<FrameTimingsRecorder>();
186  recorder->RecordVsync(frame_begin_time, frame_end_time);
187  engine->animator_->BeginFrame(std::move(recorder));
188  latch.Signal();
189  });
190  latch.Wait();
191 
192  latch.Reset();
193  // Call |Render| to rasterize a layer tree and trigger |OnFrameRasterized|
194  fml::WeakPtr<RuntimeDelegate> runtime_delegate = shell->weak_engine_;
195  shell->GetTaskRunners().GetUITaskRunner()->PostTask(
196  [&latch, runtime_delegate, &builder, viewport_metrics]() {
197  auto layer_tree = std::make_unique<LayerTree>(
198  SkISize::Make(viewport_metrics.physical_width,
199  viewport_metrics.physical_height),
200  static_cast<float>(viewport_metrics.device_pixel_ratio));
201  SkMatrix identity;
202  identity.setIdentity();
203  auto root_layer = std::make_shared<TransformLayer>(identity);
204  layer_tree->set_root_layer(root_layer);
205  if (builder) {
206  builder(root_layer);
207  }
208  runtime_delegate->Render(std::move(layer_tree));
209  latch.Signal();
210  });
211  latch.Wait();
212 }

◆ RestartEngine()

void flutter::testing::ShellTest::RestartEngine ( Shell shell,
RunConfiguration  configuration 
)
static

Definition at line 78 of file shell_test.cc.

References flutter::Shell::GetTaskRunners(), flutter::TaskRunners::GetUITaskRunner(), and fml::TaskRunner::RunNowOrPostTask().

Referenced by flutter::testing::TestSimulatedInputEvents().

78  {
79  std::promise<bool> restarted;
81  shell->GetTaskRunners().GetUITaskRunner(),
82  [shell, &restarted, &configuration]() {
83  restarted.set_value(shell->engine_->Restart(std::move(configuration)));
84  });
85  ASSERT_TRUE(restarted.get_future().get());
86 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55

◆ RunEngine()

void flutter::testing::ShellTest::RunEngine ( Shell shell,
RunConfiguration  configuration 
)
static

Definition at line 64 of file shell_test.cc.

References flutter::TaskRunners::GetPlatformTaskRunner(), flutter::Shell::GetTaskRunners(), flutter::Shell::RunEngine(), fml::TaskRunner::RunNowOrPostTask(), and flutter::Engine::Success.

Referenced by flutter::testing::TEST_F(), and flutter::testing::TestSimulatedInputEvents().

64  {
67  shell->GetTaskRunners().GetPlatformTaskRunner(),
68  [shell, &latch, &configuration]() {
69  shell->RunEngine(std::move(configuration),
70  [&latch](Engine::RunStatus run_status) {
71  ASSERT_EQ(run_status, Engine::RunStatus::Success);
72  latch.Signal();
73  });
74  });
75  latch.Wait();
76 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55
RunStatus
Indicates the result of the call to Engine::Run.
Definition: engine.h:80

◆ SendEnginePlatformMessage()

void flutter::testing::ShellTest::SendEnginePlatformMessage ( Shell shell,
std::unique_ptr< PlatformMessage message 
)

Definition at line 28 of file shell_test.cc.

References engine, flutter::TaskRunners::GetPlatformTaskRunner(), flutter::Shell::GetTaskRunners(), fml::MakeCopyable(), fml::TaskRunner::RunNowOrPostTask(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

30  {
33  shell->GetTaskRunners().GetPlatformTaskRunner(),
35  [shell, &latch, message = std::move(message)]() mutable {
36  if (auto engine = shell->weak_engine_) {
37  engine->HandlePlatformMessage(std::move(message));
38  }
39  latch.Signal();
40  }));
41  latch.Wait();
42 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57

◆ SetNeedsReportTimings()

void flutter::testing::ShellTest::SetNeedsReportTimings ( Shell shell,
bool  value 
)
static

Definition at line 235 of file shell_test.cc.

235  {
236  shell->SetNeedsReportTimings(value);
237 }
uint8_t value

◆ SetViewportMetrics()

void flutter::testing::ShellTest::SetViewportMetrics ( Shell shell,
double  width,
double  height 
)
static

Definition at line 112 of file shell_test.cc.

References engine, flutter::Shell::GetTaskRunners(), flutter::TaskRunners::GetUITaskRunner(), height, fml::TaskRunner::PostTask(), fml::AutoResetWaitableEvent::Signal(), and width.

Referenced by flutter::testing::TEST_F().

112  {
113  flutter::ViewportMetrics viewport_metrics = {
114  1, // device pixel ratio
115  width, // physical width
116  height, // physical height
117  0, // padding top
118  0, // padding right
119  0, // padding bottom
120  0, // padding left
121  0, // view inset top
122  0, // view inset right
123  0, // view inset bottom
124  0, // view inset left
125  0, // gesture inset top
126  0, // gesture inset right
127  0, // gesture inset bottom
128  0, // gesture inset left
129  22 // physical touch slop
130  };
131  // Set viewport to nonempty, and call Animator::BeginFrame to make the layer
132  // tree pipeline nonempty. Without either of this, the layer tree below
133  // won't be rasterized.
135  shell->GetTaskRunners().GetUITaskRunner()->PostTask(
136  [&latch, engine = shell->weak_engine_, viewport_metrics]() {
137  if (engine) {
138  engine->SetViewportMetrics(std::move(viewport_metrics));
139  const auto frame_begin_time = fml::TimePoint::Now();
140  const auto frame_end_time =
141  frame_begin_time + fml::TimeDelta::FromSecondsF(1.0 / 60.0);
142  std::unique_ptr<FrameTimingsRecorder> recorder =
143  std::make_unique<FrameTimingsRecorder>();
144  recorder->RecordVsync(frame_begin_time, frame_end_time);
145  engine->animator_->BeginFrame(std::move(recorder));
146  }
147  latch.Signal();
148  });
149  latch.Wait();
150 }
int32_t width
int32_t height

◆ StorePersistentCache()

void flutter::testing::ShellTest::StorePersistentCache ( PersistentCache cache,
const SkData &  key,
const SkData &  value 
)
static

Definition at line 243 of file shell_test.cc.

245  {
246  cache->store(key, value);
247 }
uint8_t value

◆ UnreportedTimingsCount()

int flutter::testing::ShellTest::UnreportedTimingsCount ( Shell shell)
static

Definition at line 231 of file shell_test.cc.

231  {
232  return shell->unreported_timings_.size();
233 }

◆ VSyncFlush()

void flutter::testing::ShellTest::VSyncFlush ( Shell shell,
bool &  will_draw_new_frame 
)
static

Issue as many VSYNC as needed to flush the UI tasks so far, and reset the will_draw_new_frame to true.

Definition at line 88 of file shell_test.cc.

References fml::TimeDelta::FromMilliseconds(), flutter::TaskRunners::GetPlatformTaskRunner(), flutter::Shell::GetPlatformView(), flutter::Shell::GetTaskRunners(), flutter::TaskRunners::GetUITaskRunner(), fml::TaskRunner::PostTask(), fml::TaskRunner::RunNowOrPostTask(), fml::AutoResetWaitableEvent::Signal(), flutter::testing::ShellTestPlatformView::SimulateVSync(), fml::AutoResetWaitableEvent::Wait(), and fml::AutoResetWaitableEvent::WaitWithTimeout().

Referenced by flutter::testing::TEST_F(), and flutter::testing::TestSimulatedInputEvents().

88  {
91  shell->GetTaskRunners().GetPlatformTaskRunner(),
92  [shell, &will_draw_new_frame, &latch] {
93  // The following UI task ensures that all previous UI tasks are flushed.
95  shell->GetTaskRunners().GetUITaskRunner()->PostTask(
96  [&ui_latch, &will_draw_new_frame]() {
97  will_draw_new_frame = true;
98  ui_latch.Signal();
99  });
100 
101  ShellTestPlatformView* test_platform_view =
102  static_cast<ShellTestPlatformView*>(shell->GetPlatformView().get());
103  do {
104  test_platform_view->SimulateVSync();
105  } while (ui_latch.WaitWithTimeout(fml::TimeDelta::FromMilliseconds(1)));
106 
107  latch.Signal();
108  });
109  latch.Wait();
110 }
bool WaitWithTimeout(TimeDelta timeout)
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55
static constexpr TimeDelta FromMilliseconds(int64_t millis)
Definition: time_delta.h:46

The documentation for this class was generated from the following files: