Flutter Engine
flutter::testing::ShellTest Class Reference

#include <shell_test.h>

Inheritance diagram for flutter::testing::ShellTest:
flutter::testing::FixtureTest flutter::testing::ThreadTest 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)
 
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, fml::RefPtr< PlatformMessage > message)
 
std::shared_ptr< txt::FontCollectionGetFontCollection (Shell *shell)
 
- Public Member Functions inherited from flutter::testing::FixtureTest
 FixtureTest ()
 
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 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::FixtureTest
void SetSnapshotsAndAssets (Settings &settings)
 
- Protected Attributes inherited from flutter::testing::FixtureTest
std::shared_ptr< TestDartNativeResolvernative_resolver_
 

Detailed Description

Definition at line 30 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 66 of file shell_test.h.

Member Enumeration Documentation

◆ ServiceProtocolEnum

Constructor & Destructor Documentation

◆ ShellTest()

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

Definition at line 22 of file shell_test.cc.

23  : thread_host_("io.flutter.test." + GetCurrentTestName() + ".",
24  ThreadHost::Type::Platform | ThreadHost::Type::IO |
25  ThreadHost::Type::UI | ThreadHost::Type::GPU) {}
ThreadHost thread_host_
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:12

Member Function Documentation

◆ CreateSettingsForFixture()

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

Reimplemented from flutter::testing::FixtureTest.

Definition at line 273 of file shell_test.cc.

References fml::MessageLoop::AddTaskObserver(), fml::MessageLoop::GetCurrent(), flutter::Settings::isolate_create_callback, flutter::Settings::leak_vm, flutter::testing::FixtureTest::native_resolver_, fml::MessageLoop::RemoveTaskObserver(), flutter::testing::FixtureTest::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().

273  {
274  Settings settings;
275  settings.leak_vm = false;
276  settings.task_observer_add = [](intptr_t key, fml::closure handler) {
278  };
279  settings.task_observer_remove = [](intptr_t key) {
281  };
282  settings.isolate_create_callback = [this]() {
283  native_resolver_->SetNativeResolverForIsolate();
284  };
285 #if OS_FUCHSIA
286  settings.verbose_logging = true;
287 #endif
288  SetSnapshotsAndAssets(settings);
289  return settings;
290 }
void AddTaskObserver(intptr_t key, const fml::closure &callback)
Definition: message_loop.cc:64
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
std::function< void()> closure
Definition: closure.h:14
std::shared_ptr< TestDartNativeResolver > native_resolver_
Definition: fixture_test.h:31
void RemoveTaskObserver(intptr_t key)
Definition: message_loop.cc:68
void SetSnapshotsAndAssets(Settings &settings)
Definition: fixture_test.cc:30

◆ CreateShell() [1/2]

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

Definition at line 306 of file shell_test.cc.

References GetTaskRunnersForFixture().

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

307  {
308  return CreateShell(std::move(settings), GetTaskRunnersForFixture(),
309  simulate_vsync);
310 }
TaskRunners GetTaskRunnersForFixture()
Definition: shell_test.cc:292
std::unique_ptr< Shell > CreateShell(Settings settings, bool simulate_vsync=false)
Definition: shell_test.cc:306

◆ 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 
)

Definition at line 312 of file shell_test.cc.

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

317  {
318  const auto vsync_clock = std::make_shared<ShellTestVsyncClock>();
319  CreateVsyncWaiter create_vsync_waiter = [&]() {
320  if (simulate_vsync) {
321  return static_cast<std::unique_ptr<VsyncWaiter>>(
322  std::make_unique<ShellTestVsyncWaiter>(task_runners, vsync_clock));
323  } else {
324  return static_cast<std::unique_ptr<VsyncWaiter>>(
325  std::make_unique<VsyncWaiterFallback>(task_runners));
326  }
327  };
328  return Shell::Create(
329  task_runners, settings,
330  [vsync_clock, &create_vsync_waiter,
331  shell_test_external_view_embedder](Shell& shell) {
333  shell, shell.GetTaskRunners(), vsync_clock,
334  std::move(create_vsync_waiter),
336  shell_test_external_view_embedder);
337  },
338  [](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
339 }
std::function< std::unique_ptr< VsyncWaiter >()> CreateVsyncWaiter
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)
static std::unique_ptr< Shell > Create(TaskRunners task_runners, Settings settings, const CreateCallback< PlatformView > &on_create_platform_view, const CreateCallback< Rasterizer > &on_create_rasterizer)
Creates a shell instance using the provided settings. The callbacks to create the various shell subco...
Definition: shell.cc:239

◆ DestroyShell() [1/2]

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

Definition at line 340 of file shell_test.cc.

References GetTaskRunnersForFixture().

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

340  {
341  DestroyShell(std::move(shell), GetTaskRunnersForFixture());
342 }
void DestroyShell(std::unique_ptr< Shell > shell)
Definition: shell_test.cc:340
TaskRunners GetTaskRunnersForFixture()
Definition: shell_test.cc:292

◆ DestroyShell() [2/2]

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

Definition at line 344 of file shell_test.cc.

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

345  {
347  fml::TaskRunner::RunNowOrPostTask(task_runners.GetPlatformTaskRunner(),
348  [&shell, &latch]() mutable {
349  shell.reset();
350  latch.Signal();
351  });
352  latch.Wait();
353 }
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 205 of file shell_test.cc.

References DispatchPointerData().

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

205  {
206  auto packet = std::make_unique<PointerDataPacket>(1);
207  DispatchPointerData(shell, std::move(packet));
208 }
static void DispatchPointerData(Shell *shell, std::unique_ptr< PointerDataPacket > packet)
Definition: shell_test.cc:210

◆ DispatchPointerData()

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

Definition at line 210 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().

211  {
213  shell->GetTaskRunners().GetPlatformTaskRunner()->PostTask(
214  [&latch, shell, &packet]() {
215  // Goes through PlatformView to ensure packet is corrected converted.
216  shell->GetPlatformView()->DispatchPointerDataPacket(std::move(packet));
217  latch.Signal();
218  });
219  latch.Wait();
220 }

◆ GetFontCollection()

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

Definition at line 268 of file shell_test.cc.

269  {
270  return shell->weak_engine_->GetFontCollection().GetFontCollection();
271 }

◆ GetLatestFrameTargetTime()

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

Definition at line 302 of file shell_test.cc.

302  {
303  return shell->GetLatestFrameTargetTime();
304 }

◆ GetNeedsReportTimings()

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

Definition at line 230 of file shell_test.cc.

230  {
231  return shell->needs_report_timings_;
232 }

◆ GetTaskRunnersForFixture()

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

Definition at line 292 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().

292  {
293  return {
294  "test",
295  thread_host_.platform_thread->GetTaskRunner(), // platform
296  thread_host_.raster_thread->GetTaskRunner(), // raster
297  thread_host_.ui_thread->GetTaskRunner(), // ui
298  thread_host_.io_thread->GetTaskRunner() // io
299  };
300 }
ThreadHost thread_host_

◆ NotifyIdle()

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

Definition at line 146 of file shell_test.cc.

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

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

146  {
148  shell->GetTaskRunners().GetUITaskRunner()->PostTask(
149  [&latch, engine = shell->weak_engine_, deadline]() {
150  if (engine) {
151  engine->NotifyIdle(deadline);
152  }
153  latch.Signal();
154  });
155  latch.Wait();
156 }

◆ 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 240 of file shell_test.cc.

References fml::TaskRunner::RunNowOrPostTask().

245  {
246  std::promise<bool> finished;
248  task_runner, [shell, some_protocol, params, response, &finished]() {
249  switch (some_protocol) {
250  case ServiceProtocolEnum::kGetSkSLs:
251  shell->OnServiceProtocolGetSkSLs(params, response);
252  break;
253  case ServiceProtocolEnum::kEstimateRasterCacheMemory:
254  shell->OnServiceProtocolEstimateRasterCacheMemory(params, response);
255  break;
256  case ServiceProtocolEnum::kSetAssetBundlePath:
257  shell->OnServiceProtocolSetAssetBundlePath(params, response);
258  break;
259  case ServiceProtocolEnum::kRunInView:
260  shell->OnServiceProtocolRunInView(params, response);
261  break;
262  }
263  finished.set_value(true);
264  });
265  finished.get_future().wait();
266 }
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 42 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::ValidateShell().

42  {
45  shell->GetTaskRunners().GetPlatformTaskRunner(), [shell, &latch]() {
46  shell->GetPlatformView()->NotifyCreated();
47  latch.Signal();
48  });
49  latch.Wait();
50 }
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 52 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().

52  {
55  shell->GetTaskRunners().GetPlatformTaskRunner(), [shell, &latch]() {
56  shell->GetPlatformView()->NotifyDestroyed();
57  latch.Signal();
58  });
59  latch.Wait();
60 }
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 158 of file shell_test.cc.

References width.

161  {
162  PumpOneFrame(shell, {1.0, width, height}, std::move(builder));
163 }
static void PumpOneFrame(Shell *shell, double width=1, double height=1, LayerTreeBuilder={})
Definition: shell_test.cc:158
int32_t height
int32_t width

◆ PumpOneFrame() [2/2]

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

Definition at line 165 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().

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

◆ RestartEngine()

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

Definition at line 76 of file shell_test.cc.

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

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

76  {
77  std::promise<bool> restarted;
79  shell->GetTaskRunners().GetUITaskRunner(),
80  [shell, &restarted, &configuration]() {
81  restarted.set_value(shell->engine_->Restart(std::move(configuration)));
82  });
83  ASSERT_TRUE(restarted.get_future().get());
84 }
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 62 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::TestSimulatedInputEvents().

62  {
65  shell->GetTaskRunners().GetPlatformTaskRunner(),
66  [shell, &latch, &configuration]() {
67  shell->RunEngine(std::move(configuration),
68  [&latch](Engine::RunStatus run_status) {
69  ASSERT_EQ(run_status, Engine::RunStatus::Success);
70  latch.Signal();
71  });
72  });
73  latch.Wait();
74 }
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,
fml::RefPtr< PlatformMessage message 
)

Definition at line 27 of file shell_test.cc.

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

29  {
32  shell->GetTaskRunners().GetPlatformTaskRunner(),
33  [shell, &latch, message = std::move(message)]() {
34  if (auto engine = shell->weak_engine_) {
35  engine->HandlePlatformMessage(std::move(message));
36  }
37  latch.Signal();
38  });
39  latch.Wait();
40 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55

◆ SetNeedsReportTimings()

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

Definition at line 226 of file shell_test.cc.

226  {
227  shell->SetNeedsReportTimings(value);
228 }
uint8_t value

◆ SetViewportMetrics()

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

Definition at line 110 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().

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

◆ StorePersistentCache()

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

Definition at line 234 of file shell_test.cc.

236  {
237  cache->store(key, value);
238 }
uint8_t value

◆ UnreportedTimingsCount()

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

Definition at line 222 of file shell_test.cc.

222  {
223  return shell->unreported_timings_.size();
224 }

◆ 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 86 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().

86  {
89  shell->GetTaskRunners().GetPlatformTaskRunner(),
90  [shell, &will_draw_new_frame, &latch] {
91  // The following UI task ensures that all previous UI tasks are flushed.
93  shell->GetTaskRunners().GetUITaskRunner()->PostTask(
94  [&ui_latch, &will_draw_new_frame]() {
95  will_draw_new_frame = true;
96  ui_latch.Signal();
97  });
98 
99  ShellTestPlatformView* test_platform_view =
100  static_cast<ShellTestPlatformView*>(shell->GetPlatformView().get());
101  do {
102  test_platform_view->SimulateVSync();
103  } while (ui_latch.WaitWithTimeout(fml::TimeDelta::FromMilliseconds(1)));
104 
105  latch.Signal();
106  });
107  latch.Wait();
108 }
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: