Flutter Engine
 
Loading...
Searching...
No Matches
shell_test.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_SHELL_COMMON_SHELL_TEST_H_
6#define FLUTTER_SHELL_COMMON_SHELL_TEST_H_
7
9
10#include <memory>
11
16#include "flutter/fml/macros.h"
27
28namespace flutter {
29namespace testing {
30
31// The signature of ViewContent::builder.
33 std::function<void(std::shared_ptr<ContainerLayer> root)>;
34struct ViewContent;
35// Defines the content to be rendered to all views of a frame in PumpOneFrame.
36using FrameContent = std::map<int64_t, ViewContent>;
37// Defines the content to be rendered to a view in PumpOneFrame.
40 // Given the root layer, this callback builds the layer tree to be rasterized
41 // in PumpOneFrame.
43
44 // Build a frame with no views. This is useful when PumpOneFrame is used just
45 // to schedule the frame while the frame content is defined by other means.
46 static FrameContent NoViews();
47
48 // Build a frame with a single implicit view with the specific size and no
49 // content.
50 static FrameContent DummyView(double width = 1, double height = 1);
51
52 // Build a frame with a single implicit view with the specific viewport
53 // metrics and no content.
55
56 // Build a frame with a single implicit view with the specific size and
57 // content.
58 static FrameContent ImplicitView(double width,
59 double height,
61};
62
63class ShellTest : public FixtureTest {
64 public:
65 struct Config {
66 // Required.
68 // Defaults to GetTaskRunnersForFixture().
69 std::optional<TaskRunners> task_runners = {};
70 bool is_gpu_disabled = false;
71 // Defaults to calling ShellTestPlatformView::Create with the provided
72 // arguments.
74 std::optional<int64_t> engine_id;
75 };
76
77 ShellTest();
78
80 std::unique_ptr<Shell> CreateShell(
81 const Settings& settings,
82 std::optional<TaskRunners> task_runners = {});
83 std::unique_ptr<Shell> CreateShell(const Config& config);
84 void DestroyShell(std::unique_ptr<Shell> shell);
85 void DestroyShell(std::unique_ptr<Shell> shell,
86 const TaskRunners& task_runners);
88
90
91 void SendPlatformMessage(Shell* shell,
92 std::unique_ptr<PlatformMessage> message);
93
94 void SendSemanticsAction(Shell* shell,
95 int64_t view_id,
96 int32_t node_id,
99
101 std::unique_ptr<PlatformMessage> message);
102
103 static void PlatformViewNotifyCreated(
104 Shell* shell); // This creates the surface
105 static void PlatformViewNotifyDestroyed(
106 Shell* shell); // This destroys the surface
107 static void RunEngine(Shell* shell, RunConfiguration configuration);
108 static void RestartEngine(Shell* shell, RunConfiguration configuration);
109
110 /// Issue as many VSYNC as needed to flush the UI tasks so far, and reset
111 /// the content of `will_draw_new_frame` to true if it's not nullptr.
112 static void VSyncFlush(Shell* shell, bool* will_draw_new_frame = nullptr);
113
114 static void SetViewportMetrics(Shell* shell, double width, double height);
115 static void NotifyIdle(Shell* shell, fml::TimeDelta deadline);
116
117 static void PumpOneFrame(Shell* shell);
118 static void PumpOneFrame(Shell* shell, FrameContent frame_content);
119 // Dispatch a PointerHoverEvent with the specified `x` as the pointer
120 // position.
121 static void DispatchFakePointerData(Shell* shell, double x);
122 static void DispatchPointerData(Shell* shell,
123 std::unique_ptr<PointerDataPacket> packet);
124 // Declare |UnreportedTimingsCount|, |GetNeedsReportTimings| and
125 // |SetNeedsReportTimings| inside |ShellTest| mainly for easier friend class
126 // declarations as shell unit tests and Shell are in different name spaces.
127
128 static bool GetNeedsReportTimings(Shell* shell);
129 static void SetNeedsReportTimings(Shell* shell, bool value);
130
131 // Declare |StorePersistentCache| inside |ShellTest| so |PersistentCache| can
132 // friend |ShellTest| and allow us to call private |PersistentCache::store| in
133 // unit tests.
134 static void StorePersistentCache(PersistentCache* cache,
135 const SkData& key,
136 const SkData& value);
137
138 static bool IsAnimatorRunning(Shell* shell);
139
146
147 // Helper method to test private method Shell::OnServiceProtocolGetSkSLs.
148 // (ShellTest is a friend class of Shell.) We'll also make sure that it is
149 // running on the correct task_runner.
150 static void OnServiceProtocol(
151 Shell* shell,
152 ServiceProtocolEnum some_protocol,
153 const fml::RefPtr<fml::TaskRunner>& task_runner,
155 rapidjson::Document* response);
156
157 std::shared_ptr<txt::FontCollection> GetFontCollection(Shell* shell);
158
159 // Do not assert |UnreportedTimingsCount| to be positive in any tests.
160 // Otherwise those tests will be flaky as the clearing of unreported timings
161 // is unpredictive.
162 static int UnreportedTimingsCount(Shell* shell);
163
164 static void TurnOffGPU(Shell* shell, bool value);
165
166 static bool ShouldDiscardLayerTree(Shell* shell,
167 int64_t view_id,
168 const flutter::LayerTree& tree);
169
170 private:
171 ThreadHost thread_host_;
172
174};
175
176} // namespace testing
177} // namespace flutter
178
179#endif // FLUTTER_SHELL_COMMON_SHELL_TEST_H_
Specifies all the configuration required by the runtime library to launch the root isolate....
std::map< std::string_view, std::string_view > ServiceProtocolMap
std::function< std::unique_ptr< T >(Shell &)> CreateCallback
Definition shell.h:121
static void PlatformViewNotifyDestroyed(Shell *shell)
void SendPlatformMessage(Shell *shell, std::unique_ptr< PlatformMessage > message)
Definition shell_test.cc:63
static void PlatformViewNotifyCreated(Shell *shell)
Definition shell_test.cc:93
static void PumpOneFrame(Shell *shell)
static bool IsAnimatorRunning(Shell *shell)
static void TurnOffGPU(Shell *shell, bool value)
static int UnreportedTimingsCount(Shell *shell)
static void RunEngine(Shell *shell, RunConfiguration configuration)
std::shared_ptr< txt::FontCollection > GetFontCollection(Shell *shell)
Settings CreateSettingsForFixture() override
TaskRunners GetTaskRunnersForFixture()
static bool ShouldDiscardLayerTree(Shell *shell, int64_t view_id, const flutter::LayerTree &tree)
static void VSyncFlush(Shell *shell, bool *will_draw_new_frame=nullptr)
std::unique_ptr< Shell > CreateShell(const Settings &settings, std::optional< TaskRunners > task_runners={})
static void DispatchPointerData(Shell *shell, std::unique_ptr< PointerDataPacket > packet)
static bool GetNeedsReportTimings(Shell *shell)
static void RestartEngine(Shell *shell, RunConfiguration configuration)
void SendEnginePlatformMessage(Shell *shell, std::unique_ptr< PlatformMessage > message)
Definition shell_test.cc:77
static void NotifyIdle(Shell *shell, fml::TimeDelta deadline)
fml::TimePoint GetLatestFrameTargetTime(Shell *shell) const
static void SetNeedsReportTimings(Shell *shell, bool value)
static void StorePersistentCache(PersistentCache *cache, const SkData &key, const SkData &value)
static void SetViewportMetrics(Shell *shell, double width, double height)
void DestroyShell(std::unique_ptr< Shell > shell)
void SendSemanticsAction(Shell *shell, int64_t view_id, int32_t node_id, SemanticsAction action, fml::MallocMapping args)
Definition shell_test.cc:68
static void DispatchFakePointerData(Shell *shell, double x)
static void OnServiceProtocol(Shell *shell, ServiceProtocolEnum some_protocol, const fml::RefPtr< fml::TaskRunner > &task_runner, const ServiceProtocol::Handler::ServiceProtocolMap &params, rapidjson::Document *response)
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition mapping.h:144
int32_t x
const EmbeddedViewParams * params
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_BEGIN_DECLS GBytes * message
G_BEGIN_DECLS FlutterViewId view_id
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
std::function< void(std::shared_ptr< ContainerLayer > root)> LayerTreeBuilder
Definition shell_test.h:33
std::map< int64_t, ViewContent > FrameContent
Definition shell_test.h:36
int32_t height
int32_t width
The collection of all the threads used by the engine.
Definition thread_host.h:21
Shell::CreateCallback< PlatformView > platform_view_create_callback
Definition shell_test.h:73
std::optional< TaskRunners > task_runners
Definition shell_test.h:69
std::optional< int64_t > engine_id
Definition shell_test.h:74
static FrameContent ImplicitView(double width, double height, LayerTreeBuilder builder)
Definition shell_test.cc:47
static FrameContent DummyView(double width=1, double height=1)
Definition shell_test.cc:29
flutter::ViewportMetrics viewport_metrics
Definition shell_test.h:39
static FrameContent NoViews()
Definition shell_test.cc:25