3
3
// found in the LICENSE file.
4
4
5
5
#include " flutter/shell/platform/linux/fl_settings_plugin.h"
6
+ #include " flutter/shell/platform/embedder/embedder.h"
7
+ #include " flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
8
+ #include " flutter/shell/platform/linux/fl_engine_private.h"
6
9
#include " flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h"
7
10
#include " flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h"
8
11
#include " flutter/shell/platform/linux/public/flutter_linux/fl_value.h"
@@ -39,7 +42,9 @@ TEST(FlSettingsPluginTest, AlwaysUse24HourFormat) {
39
42
g_autoptr (FlBinaryMessenger) messenger =
40
43
fl_binary_messenger_new_mock (&mock_messenger);
41
44
42
- g_autoptr (FlSettingsPlugin) plugin = fl_settings_plugin_new (messenger);
45
+ g_autoptr (FlEngine) engine = FL_ENGINE (g_object_new (
46
+ fl_engine_get_type (), " binary-messenger" , messenger, nullptr ));
47
+ g_autoptr (FlSettingsPlugin) plugin = fl_settings_plugin_new (engine);
43
48
44
49
g_autoptr (FlValue) use_12h = fl_value_new_bool (false );
45
50
g_autoptr (FlValue) use_24h = fl_value_new_bool (true );
@@ -65,7 +70,9 @@ TEST(FlSettingsPluginTest, PlatformBrightness) {
65
70
g_autoptr (FlBinaryMessenger) messenger =
66
71
fl_binary_messenger_new_mock (&mock_messenger);
67
72
68
- g_autoptr (FlSettingsPlugin) plugin = fl_settings_plugin_new (messenger);
73
+ g_autoptr (FlEngine) engine = FL_ENGINE (g_object_new (
74
+ fl_engine_get_type (), " binary-messenger" , messenger, nullptr ));
75
+ g_autoptr (FlSettingsPlugin) plugin = fl_settings_plugin_new (engine);
69
76
70
77
g_autoptr (FlValue) light = fl_value_new_string (" light" );
71
78
g_autoptr (FlValue) dark = fl_value_new_string (" dark" );
@@ -91,7 +98,9 @@ TEST(FlSettingsPluginTest, TextScaleFactor) {
91
98
g_autoptr (FlBinaryMessenger) messenger =
92
99
fl_binary_messenger_new_mock (&mock_messenger);
93
100
94
- g_autoptr (FlSettingsPlugin) plugin = fl_settings_plugin_new (messenger);
101
+ g_autoptr (FlEngine) engine = FL_ENGINE (g_object_new (
102
+ fl_engine_get_type (), " binary-messenger" , messenger, nullptr ));
103
+ g_autoptr (FlSettingsPlugin) plugin = fl_settings_plugin_new (engine);
95
104
96
105
g_autoptr (FlValue) one = fl_value_new_float (1.0 );
97
106
g_autoptr (FlValue) two = fl_value_new_float (2.0 );
@@ -109,3 +118,57 @@ TEST(FlSettingsPluginTest, TextScaleFactor) {
109
118
110
119
fl_settings_emit_changed (settings);
111
120
}
121
+
122
+ // MOCK_ENGINE_PROC is leaky by design
123
+ // NOLINTBEGIN(clang-analyzer-core.StackAddressEscape)
124
+ TEST (FlSettingsPluginTest, AccessibilityFeatures) {
125
+ g_autoptr (FlEngine) engine = make_mock_engine ();
126
+ FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api (engine);
127
+
128
+ std::vector<FlutterAccessibilityFeature> calls;
129
+ embedder_api->UpdateAccessibilityFeatures = MOCK_ENGINE_PROC (
130
+ UpdateAccessibilityFeatures,
131
+ ([&calls](auto engine, FlutterAccessibilityFeature features) {
132
+ calls.push_back (features);
133
+ return kSuccess ;
134
+ }));
135
+
136
+ g_autoptr (FlSettingsPlugin) plugin = fl_settings_plugin_new (engine);
137
+
138
+ ::testing::NiceMock<flutter::testing::MockSettings> settings;
139
+
140
+ EXPECT_CALL (settings, fl_settings_get_enable_animations (
141
+ ::testing::Eq<FlSettings*>(settings)))
142
+ .WillOnce (::testing::Return (false ))
143
+ .WillOnce (::testing::Return (true ))
144
+ .WillOnce (::testing::Return (false ))
145
+ .WillOnce (::testing::Return (true ));
146
+
147
+ EXPECT_CALL (settings, fl_settings_get_high_contrast (
148
+ ::testing::Eq<FlSettings*>(settings)))
149
+ .WillOnce (::testing::Return (true ))
150
+ .WillOnce (::testing::Return (false ))
151
+ .WillOnce (::testing::Return (false ))
152
+ .WillOnce (::testing::Return (true ));
153
+
154
+ fl_settings_plugin_start (plugin, settings);
155
+ EXPECT_THAT (calls, ::testing::SizeIs (1 ));
156
+ EXPECT_EQ (calls.back (), static_cast <FlutterAccessibilityFeature>(
157
+ kFlutterAccessibilityFeatureDisableAnimations |
158
+ kFlutterAccessibilityFeatureHighContrast ));
159
+
160
+ fl_settings_emit_changed (settings);
161
+ EXPECT_THAT (calls, ::testing::SizeIs (2 ));
162
+ EXPECT_EQ (calls.back (), static_cast <FlutterAccessibilityFeature>(0 ));
163
+
164
+ fl_settings_emit_changed (settings);
165
+ EXPECT_THAT (calls, ::testing::SizeIs (3 ));
166
+ EXPECT_EQ (calls.back (), static_cast <FlutterAccessibilityFeature>(
167
+ kFlutterAccessibilityFeatureDisableAnimations ));
168
+
169
+ fl_settings_emit_changed (settings);
170
+ EXPECT_THAT (calls, ::testing::SizeIs (4 ));
171
+ EXPECT_EQ (calls.back (), static_cast <FlutterAccessibilityFeature>(
172
+ kFlutterAccessibilityFeatureHighContrast ));
173
+ }
174
+ // NOLINTEND(clang-analyzer-core.StackAddressEscape)
0 commit comments