Flutter Engine
The 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
8#include "flutter/shell/common/shell.h"
9
10#include <memory>
11
12#include "flutter/common/graphics/persistent_cache.h"
13#include "flutter/common/settings.h"
14#include "flutter/flow/layers/container_layer.h"
15#include "flutter/fml/build_config.h"
16#include "flutter/fml/macros.h"
17#include "flutter/fml/time/time_point.h"
18#include "flutter/lib/ui/volatile_path_tracker.h"
19#include "flutter/lib/ui/window/platform_message.h"
20#include "flutter/shell/common/run_configuration.h"
21#include "flutter/shell/common/shell_test_external_view_embedder.h"
22#include "flutter/shell/common/shell_test_platform_view.h"
23#include "flutter/shell/common/thread_host.h"
24#include "flutter/shell/common/vsync_waiters_test.h"
25#include "flutter/testing/elf_loader.h"
26#include "flutter/testing/fixture_test.h"
27#include "flutter/testing/test_dart_native_resolver.h"
28
29namespace flutter {
30namespace testing {
31
32// The signature of ViewContent::builder.
34 std::function<void(std::shared_ptr<ContainerLayer> root)>;
35struct ViewContent;
36// Defines the content to be rendered to all views of a frame in PumpOneFrame.
37using FrameContent = std::map<int64_t, ViewContent>;
38// Defines the content to be rendered to a view in PumpOneFrame.
41 // Given the root layer, this callback builds the layer tree to be rasterized
42 // in PumpOneFrame.
44
45 // Build a frame with no views. This is useful when PumpOneFrame is used just
46 // to schedule the frame while the frame content is defined by other means.
47 static FrameContent NoViews();
48
49 // Build a frame with a single implicit view with the specific size and no
50 // content.
51 static FrameContent DummyView(double width = 1, double height = 1);
52
53 // Build a frame with a single implicit view with the specific viewport
54 // metrics and no content.
56
57 // Build a frame with a single implicit view with the specific size and
58 // content.
59 static FrameContent ImplicitView(double width,
60 double height,
62};
63
64class ShellTest : public FixtureTest {
65 public:
66 struct Config {
67 // Required.
69 // Defaults to GetTaskRunnersForFixture().
70 std::optional<TaskRunners> task_runners = {};
71 bool is_gpu_disabled = false;
72 // Defaults to calling ShellTestPlatformView::Create with the provided
73 // arguments.
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
95 std::unique_ptr<PlatformMessage> message);
96
97 static void PlatformViewNotifyCreated(
98 Shell* shell); // This creates the surface
100 Shell* shell); // This destroys the surface
101 static void RunEngine(Shell* shell, RunConfiguration configuration);
102 static void RestartEngine(Shell* shell, RunConfiguration configuration);
103
104 /// Issue as many VSYNC as needed to flush the UI tasks so far, and reset
105 /// the content of `will_draw_new_frame` to true if it's not nullptr.
106 static void VSyncFlush(Shell* shell, bool* will_draw_new_frame = nullptr);
107
108 static void SetViewportMetrics(Shell* shell, double width, double height);
109 static void NotifyIdle(Shell* shell, fml::TimeDelta deadline);
110
111 static void PumpOneFrame(Shell* shell);
112 static void PumpOneFrame(Shell* shell, FrameContent frame_content);
113 static void DispatchFakePointerData(Shell* shell);
114 static void DispatchPointerData(Shell* shell,
115 std::unique_ptr<PointerDataPacket> packet);
116 // Declare |UnreportedTimingsCount|, |GetNeedsReportTimings| and
117 // |SetNeedsReportTimings| inside |ShellTest| mainly for easier friend class
118 // declarations as shell unit tests and Shell are in different name spaces.
119
120 static bool GetNeedsReportTimings(Shell* shell);
121 static void SetNeedsReportTimings(Shell* shell, bool value);
122
123 // Declare |StorePersistentCache| inside |ShellTest| so |PersistentCache| can
124 // friend |ShellTest| and allow us to call private |PersistentCache::store| in
125 // unit tests.
127 const SkData& key,
128 const SkData& value);
129
130 static bool IsAnimatorRunning(Shell* shell);
131
139
140 // Helper method to test private method Shell::OnServiceProtocolGetSkSLs.
141 // (ShellTest is a friend class of Shell.) We'll also make sure that it is
142 // running on the correct task_runner.
143 static void OnServiceProtocol(
144 Shell* shell,
145 ServiceProtocolEnum some_protocol,
146 const fml::RefPtr<fml::TaskRunner>& task_runner,
148 rapidjson::Document* response);
149
150 std::shared_ptr<txt::FontCollection> GetFontCollection(Shell* shell);
151
152 // Do not assert |UnreportedTimingsCount| to be positive in any tests.
153 // Otherwise those tests will be flaky as the clearing of unreported timings
154 // is unpredictive.
155 static int UnreportedTimingsCount(Shell* shell);
156
157 static size_t GetLiveTrackedPathCount(
158 const std::shared_ptr<VolatilePathTracker>& tracker);
159
160 static void TurnOffGPU(Shell* shell, bool value);
161
162 private:
163 ThreadHost thread_host_;
164
166};
167
168} // namespace testing
169} // namespace flutter
170
171#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:119
static void PlatformViewNotifyDestroyed(Shell *shell)
Definition shell_test.cc:94
void SendPlatformMessage(Shell *shell, std::unique_ptr< PlatformMessage > message)
Definition shell_test.cc:63
static void PlatformViewNotifyCreated(Shell *shell)
Definition shell_test.cc:84
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 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:68
static void NotifyIdle(Shell *shell, fml::TimeDelta deadline)
static void DispatchFakePointerData(Shell *shell)
fml::TimePoint GetLatestFrameTargetTime(Shell *shell) const
static void SetNeedsReportTimings(Shell *shell, bool value)
static size_t GetLiveTrackedPathCount(const std::shared_ptr< VolatilePathTracker > &tracker)
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)
static void OnServiceProtocol(Shell *shell, ServiceProtocolEnum some_protocol, const fml::RefPtr< fml::TaskRunner > &task_runner, const ServiceProtocol::Handler::ServiceProtocolMap &params, rapidjson::Document *response)
const EmbeddedViewParams * params
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
Win32Message message
std::function< void(std::shared_ptr< ContainerLayer > root)> LayerTreeBuilder
Definition shell_test.h:34
std::map< int64_t, ViewContent > FrameContent
Definition shell_test.h:37
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition switches.h:191
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:74
std::optional< TaskRunners > task_runners
Definition shell_test.h:70
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:40
static FrameContent NoViews()
Definition shell_test.cc:25