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 <memory> |
9 | |
10 | #include "flutter/common/settings.h" |
11 | #include "flutter/flow/layers/container_layer.h" |
12 | #include "flutter/fml/build_config.h" |
13 | #include "flutter/fml/macros.h" |
14 | #include "flutter/fml/time/time_point.h" |
15 | #include "flutter/lib/ui/window/platform_message.h" |
16 | #include "flutter/shell/common/persistent_cache.h" |
17 | #include "flutter/shell/common/run_configuration.h" |
18 | #include "flutter/shell/common/shell.h" |
19 | #include "flutter/shell/common/shell_test_external_view_embedder.h" |
20 | #include "flutter/shell/common/thread_host.h" |
21 | #include "flutter/shell/common/vsync_waiters_test.h" |
22 | #include "flutter/testing/elf_loader.h" |
23 | #include "flutter/testing/fixture_test.h" |
24 | #include "flutter/testing/test_dart_native_resolver.h" |
25 | |
26 | namespace flutter { |
27 | namespace testing { |
28 | |
29 | class ShellTest : public FixtureTest { |
30 | public: |
31 | ShellTest(); |
32 | |
33 | Settings CreateSettingsForFixture() override; |
34 | std::unique_ptr<Shell> CreateShell(Settings settings, |
35 | bool simulate_vsync = false); |
36 | std::unique_ptr<Shell> CreateShell( |
37 | Settings settings, |
38 | TaskRunners task_runners, |
39 | bool simulate_vsync = false, |
40 | std::shared_ptr<ShellTestExternalViewEmbedder> |
41 | shell_test_external_view_embedder = nullptr); |
42 | void DestroyShell(std::unique_ptr<Shell> shell); |
43 | void DestroyShell(std::unique_ptr<Shell> shell, TaskRunners task_runners); |
44 | TaskRunners GetTaskRunnersForFixture(); |
45 | |
46 | fml::TimePoint GetLatestFrameTargetTime(Shell* shell) const; |
47 | |
48 | void SendEnginePlatformMessage(Shell* shell, |
49 | fml::RefPtr<PlatformMessage> message); |
50 | |
51 | static void PlatformViewNotifyCreated( |
52 | Shell* shell); // This creates the surface |
53 | static void RunEngine(Shell* shell, RunConfiguration configuration); |
54 | static void RestartEngine(Shell* shell, RunConfiguration configuration); |
55 | |
56 | /// Issue as many VSYNC as needed to flush the UI tasks so far, and reset |
57 | /// the `will_draw_new_frame` to true. |
58 | static void VSyncFlush(Shell* shell, bool& will_draw_new_frame); |
59 | |
60 | /// Given the root layer, this callback builds the layer tree to be rasterized |
61 | /// in PumpOneFrame. |
62 | using LayerTreeBuilder = |
63 | std::function<void(std::shared_ptr<ContainerLayer> root)>; |
64 | static void PumpOneFrame(Shell* shell, |
65 | double width = 1, |
66 | double height = 1, |
67 | LayerTreeBuilder = {}); |
68 | static void PumpOneFrame(Shell* shell, |
69 | flutter::ViewportMetrics viewport_metrics, |
70 | LayerTreeBuilder = {}); |
71 | static void DispatchFakePointerData(Shell* shell); |
72 | static void DispatchPointerData(Shell* shell, |
73 | std::unique_ptr<PointerDataPacket> packet); |
74 | // Declare |UnreportedTimingsCount|, |GetNeedsReportTimings| and |
75 | // |SetNeedsReportTimings| inside |ShellTest| mainly for easier friend class |
76 | // declarations as shell unit tests and Shell are in different name spaces. |
77 | |
78 | static bool GetNeedsReportTimings(Shell* shell); |
79 | static void SetNeedsReportTimings(Shell* shell, bool value); |
80 | |
81 | enum ServiceProtocolEnum { |
82 | kGetSkSLs, |
83 | kEstimateRasterCacheMemory, |
84 | kSetAssetBundlePath, |
85 | kRunInView, |
86 | }; |
87 | |
88 | // Helper method to test private method Shell::OnServiceProtocolGetSkSLs. |
89 | // (ShellTest is a friend class of Shell.) We'll also make sure that it is |
90 | // running on the correct task_runner. |
91 | static void OnServiceProtocol( |
92 | Shell* shell, |
93 | ServiceProtocolEnum some_protocol, |
94 | fml::RefPtr<fml::TaskRunner> task_runner, |
95 | const ServiceProtocol::Handler::ServiceProtocolMap& params, |
96 | rapidjson::Document* response); |
97 | |
98 | std::shared_ptr<txt::FontCollection> GetFontCollection(Shell* shell); |
99 | |
100 | // Do not assert |UnreportedTimingsCount| to be positive in any tests. |
101 | // Otherwise those tests will be flaky as the clearing of unreported timings |
102 | // is unpredictive. |
103 | static int UnreportedTimingsCount(Shell* shell); |
104 | |
105 | private: |
106 | ThreadHost thread_host_; |
107 | |
108 | FML_DISALLOW_COPY_AND_ASSIGN(ShellTest); |
109 | }; |
110 | |
111 | } // namespace testing |
112 | } // namespace flutter |
113 | |
114 | #endif // FLUTTER_SHELL_COMMON_SHELL_TEST_H_ |
115 | |