Flutter Engine
 
Loading...
Searching...
No Matches
runtime_controller_unittests.cc
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
7
11
12namespace flutter::testing {
13// For namespacing when running tests.
15
17 public:
19 std::vector<SemanticsNodeUpdates> updates;
20 std::vector<CustomAccessibilityActionUpdates> actions;
21 std::string DefaultRouteName() override { return ""; }
22 std::string locale;
23
24 void ScheduleFrame(bool regenerate_layer_trees = true) override {}
25
26 void OnAllViewsRendered() override {}
27
28 void Render(int64_t view_id,
29 std::unique_ptr<flutter::LayerTree> layer_tree,
30 float device_pixel_ratio) override {}
31
35 this->updates.push_back(update);
36 this->actions.push_back(actions);
37 }
38
39 void SetApplicationLocale(std::string locale) override {
40 this->locale = std::move(locale);
41 }
42
43 void SetSemanticsTreeEnabled(bool enabled) override {}
44
46 std::unique_ptr<PlatformMessage> message) override {}
47
48 FontCollection& GetFontCollection() override { return font; }
49
50 std::shared_ptr<AssetManager> GetAssetManager() override { return nullptr; }
51
52 void OnRootIsolateCreated() override {};
53
54 void UpdateIsolateDescription(const std::string isolate_name,
55 int64_t isolate_port) override {};
56
57 void SetNeedsReportTimings(bool value) override {};
58
59 std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
60 const std::vector<std::string>& supported_locale_data) override {
61 return nullptr;
62 }
63
64 void RequestDartDeferredLibrary(intptr_t loading_unit_id) override {}
65
66 void RequestViewFocusChange(const ViewFocusChangeRequest& request) override {}
67
68 std::weak_ptr<PlatformMessageHandler> GetPlatformMessageHandler()
69 const override {
70 return {};
71 }
72
73 void SendChannelUpdate(std::string name, bool listening) override {}
74
75 double GetScaledFontSize(double unscaled_font_size,
76 int configuration_id) const override {
77 return 0.0;
78 }
79};
80
82 public:
84 : context_(context),
85 runtime_controller_(delegate_,
86 nullptr,
87 {},
88 {},
89 {},
90 {},
91 {},
92 nullptr,
93 context_) {}
94
96 ASSERT_TRUE(delegate_.updates.empty());
97 ASSERT_TRUE(delegate_.actions.empty());
98 runtime_controller_.SetSemanticsTreeEnabled(true);
99 runtime_controller_.UpdateSemantics(0, update);
100 ASSERT_FALSE(delegate_.updates.empty());
101 ASSERT_FALSE(delegate_.actions.empty());
102 }
103
105 ASSERT_TRUE(delegate_.locale.empty());
106 runtime_controller_.SetApplicationLocale("es-MX");
107 ASSERT_TRUE(delegate_.locale == "es-MX");
108 }
109
110 private:
111 MockRuntimeDelegate delegate_;
112 UIDartState::Context& context_;
113 RuntimeController runtime_controller_;
114};
115
116TEST_F(RuntimeControllerTest, CanUpdateSemanticsWhenSetSemanticsTreeEnabled) {
117 fml::AutoResetWaitableEvent message_latch;
118 // The code in this test is mostly setup code to get a SemanticsUpdate object.
119 // The real test is in RuntimeControllerTester::CanUpdateSemantics.
120 TaskRunners task_runners("test", // label
121 GetCurrentTaskRunner(), // platform
122 CreateNewThread(), // raster
123 CreateNewThread(), // ui
124 CreateNewThread() // io
125 );
126 UIDartState::Context context(task_runners);
127 auto tester = std::make_shared<RuntimeControllerTester>(context);
128
129 auto native_semantics_update = [tester,
130 &message_latch](Dart_NativeArguments args) {
131 auto handle = Dart_GetNativeArgument(args, 0);
132 intptr_t peer = 0;
133 Dart_Handle result = Dart_GetNativeInstanceField(
134 handle, tonic::DartWrappable::kPeerIndex, &peer);
135 ASSERT_FALSE(Dart_IsError(result));
136 SemanticsUpdate* update = reinterpret_cast<SemanticsUpdate*>(peer);
137
138 tester->CanUpdateSemanticsWhenSetSemanticsTreeEnabled(update);
139 message_latch.Signal();
140 };
141
142 Settings settings = CreateSettingsForFixture();
143 AddNativeCallback("SemanticsUpdate",
144 CREATE_NATIVE_ENTRY(native_semantics_update));
145
146 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
147
148 ASSERT_TRUE(shell->IsSetup());
149 auto configuration = RunConfiguration::InferFromSettings(settings);
150 configuration.SetEntrypoint("sendSemanticsUpdate");
151
152 shell->RunEngine(std::move(configuration), [](auto result) {
153 ASSERT_EQ(result, Engine::RunStatus::Success);
154 });
155
156 message_latch.Wait();
157 DestroyShell(std::move(shell), task_runners);
158}
159
160TEST_F(RuntimeControllerTest, CanSetApplicationLocale) {
161 TaskRunners task_runners("test", // label
162 GetCurrentTaskRunner(), // platform
163 CreateNewThread(), // raster
164 CreateNewThread(), // ui
165 CreateNewThread() // io
166 );
167 UIDartState::Context context(task_runners);
168 auto tester = std::make_shared<RuntimeControllerTester>(context);
169 tester->CanUpdateSetApplicationLocale();
170}
171
172} // namespace flutter::testing
static RunConfiguration InferFromSettings(const Settings &settings, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
void SetSemanticsTreeEnabled(bool enabled) override
Notifies whether Framework starts generating semantics tree.
void UpdateSemantics(int64_t view_id, SemanticsUpdate *update) override
Receives an updated semantics tree from the Framework.
void SetApplicationLocale(std::string locale) override
Framework sets the application locale.
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override
std::weak_ptr< PlatformMessageHandler > GetPlatformMessageHandler() const override
std::unique_ptr< std::vector< std::string > > ComputePlatformResolvedLocale(const std::vector< std::string > &supported_locale_data) override
void RequestViewFocusChange(const ViewFocusChangeRequest &request) override
std::vector< CustomAccessibilityActionUpdates > actions
double GetScaledFontSize(double unscaled_font_size, int configuration_id) const override
void ScheduleFrame(bool regenerate_layer_trees=true) override
std::vector< SemanticsNodeUpdates > updates
std::shared_ptr< AssetManager > GetAssetManager() override
void UpdateIsolateDescription(const std::string isolate_name, int64_t isolate_port) override
void SendChannelUpdate(std::string name, bool listening) override
void HandlePlatformMessage(std::unique_ptr< PlatformMessage > message) override
void UpdateSemantics(int64_t view_id, SemanticsNodeUpdates update, CustomAccessibilityActionUpdates actions) override
void SetApplicationLocale(std::string locale) override
void Render(int64_t view_id, std::unique_ptr< flutter::LayerTree > layer_tree, float device_pixel_ratio) override
void CanUpdateSemanticsWhenSetSemanticsTreeEnabled(SemanticsUpdate *update)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_BEGIN_DECLS GBytes * message
G_BEGIN_DECLS FlutterViewId view_id
TEST_F(DisplayListTest, Defaults)
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27
The subset of state which is owned by the shell or engine and passed through the RuntimeController in...
#define CREATE_NATIVE_ENTRY(native_entry)