33// found in the LICENSE file.
44
55#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"
69#include " flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h"
710#include " flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h"
811#include " flutter/shell/platform/linux/public/flutter_linux/fl_value.h"
@@ -39,7 +42,9 @@ TEST(FlSettingsPluginTest, AlwaysUse24HourFormat) {
3942 g_autoptr (FlBinaryMessenger) messenger =
4043 fl_binary_messenger_new_mock (&mock_messenger);
4144
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);
4348
4449 g_autoptr (FlValue) use_12h = fl_value_new_bool (false );
4550 g_autoptr (FlValue) use_24h = fl_value_new_bool (true );
@@ -65,7 +70,9 @@ TEST(FlSettingsPluginTest, PlatformBrightness) {
6570 g_autoptr (FlBinaryMessenger) messenger =
6671 fl_binary_messenger_new_mock (&mock_messenger);
6772
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);
6976
7077 g_autoptr (FlValue) light = fl_value_new_string (" light" );
7178 g_autoptr (FlValue) dark = fl_value_new_string (" dark" );
@@ -91,7 +98,9 @@ TEST(FlSettingsPluginTest, TextScaleFactor) {
9198 g_autoptr (FlBinaryMessenger) messenger =
9299 fl_binary_messenger_new_mock (&mock_messenger);
93100
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);
95104
96105 g_autoptr (FlValue) one = fl_value_new_float (1.0 );
97106 g_autoptr (FlValue) two = fl_value_new_float (2.0 );
@@ -109,3 +118,57 @@ TEST(FlSettingsPluginTest, TextScaleFactor) {
109118
110119 fl_settings_emit_changed (settings);
111120}
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