| Flutter Linux Embedder |

Functions
fl_settings_handler_test.cc File Reference
`#include "flutter/shell/platform/linux/fl_settings_handler.h"`
`#include "flutter/shell/platform/embedder/embedder.h"`
`#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"`
`#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"`
`#include "flutter/shell/platform/linux/fl_engine_private.h"`
`#include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h"`
`#include "flutter/shell/platform/linux/testing/mock_settings.h"`
`#include "flutter/testing/testing.h"`
`#include "gmock/gmock.h"`
`#include "gtest/gtest.h"`

Go to the source code of this file.

## Functions
| TEST (FlSettingsHandlerTest, AlwaysUse24HourFormat)
| TEST (FlSettingsHandlerTest, PlatformBrightness)
| TEST (FlSettingsHandlerTest, TextScaleFactor)
| TEST (FlSettingsHandlerTest, AccessibilityFeatures)

## Function Documentation

## ◆ TEST() [1/4]

TEST | ( | FlSettingsHandlerTest | ,
|  | AccessibilityFeatures |
| ) |  |

Definition at line 189 of file fl_settings_handler_test.cc.

189 {
190 g_autoptr(FlDartProject) project = fl_dart_project_new();
191 g_autoptr(FlEngine) engine = fl_engine_new(project);
192
193 g_autoptr(GError) error = nullptr;
194 EXPECT_TRUE(fl_engine_start(engine, &error));
195 EXPECT_EQ(error, nullptr);
196
197 std::vector<FlutterAccessibilityFeature> calls;
198 fl_engine_get_embedder_api(engine)->UpdateAccessibilityFeatures =
199 MOCK_ENGINE_PROC(
200 UpdateAccessibilityFeatures,
201 ([&calls](auto engine, FlutterAccessibilityFeature features) {
202 calls.push_back(features);
203 return kSuccess;
204 }));
205
206 g_autoptr(FlSettingsHandler) handler = fl_settings_handler_new(engine);
207
208 ::testing::NiceMock<flutter::testing::MockSettings> settings;
209
210 EXPECT_CALL(settings, fl_settings_get_enable_animations(
211 ::testing::Eq<FlSettings*>(settings)))
212 .WillOnce(::testing::Return(false))
213 .WillOnce(::testing::Return(true))
214 .WillOnce(::testing::Return(false))
215 .WillOnce(::testing::Return(true));
216
217 EXPECT_CALL(settings, fl_settings_get_high_contrast(
218 ::testing::Eq<FlSettings*>(settings)))
219 .WillOnce(::testing::Return(true))
220 .WillOnce(::testing::Return(false))
221 .WillOnce(::testing::Return(false))
222 .WillOnce(::testing::Return(true));
223
224 fl_settings_handler_start(handler, settings);
225 EXPECT_THAT(calls, ::testing::SizeIs(1));
226 EXPECT_EQ(calls.back(), static_cast<FlutterAccessibilityFeature>(
227 kFlutterAccessibilityFeatureDisableAnimations |
228 kFlutterAccessibilityFeatureHighContrast));
229
230 fl_settings_emit_changed(settings);
231 EXPECT_THAT(calls, ::testing::SizeIs(2));
232 EXPECT_EQ(calls.back(), static_cast<FlutterAccessibilityFeature>(0));
233
234 fl_settings_emit_changed(settings);
235 EXPECT_THAT(calls, ::testing::SizeIs(3));
236 EXPECT_EQ(calls.back(), static_cast<FlutterAccessibilityFeature>(
237 kFlutterAccessibilityFeatureDisableAnimations));
238
239 fl_settings_emit_changed(settings);
240 EXPECT_THAT(calls, ::testing::SizeIs(4));
241 EXPECT_EQ(calls.back(), static_cast<FlutterAccessibilityFeature>(
242 kFlutterAccessibilityFeatureHighContrast));
243 }
g_autoptr
g_autoptr(FlEngine) engine
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:52
fl_engine_get_embedder_api
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:868
fl_engine_start
gboolean fl_engine_start(FlEngine *self, GError **error)
Definition: fl_engine.cc:726
fl_engine_new
G_MODULE_EXPORT FlEngine * fl_engine_new(FlDartProject *project)
Definition: fl_engine.cc:697
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_settings_get_high_contrast
gboolean fl_settings_get_high_contrast(FlSettings *self)
Definition: fl_settings.cc:42
fl_settings_emit_changed
void fl_settings_emit_changed(FlSettings *self)
Definition: fl_settings.cc:50
fl_settings_get_enable_animations
gboolean fl_settings_get_enable_animations(FlSettings *self)
Definition: fl_settings.cc:38
fl_settings_handler_start
void fl_settings_handler_start(FlSettingsHandler *self, FlSettings *settings)
Definition: fl_settings_handler.cc:88
fl_settings_handler_new
FlSettingsHandler * fl_settings_handler_new(FlEngine *engine)
Definition: fl_settings_handler.cc:74

References error, fl_dart_project_new(), fl_engine_get_embedder_api(), fl_engine_new(), fl_engine_start(), fl_settings_emit_changed(), fl_settings_get_enable_animations(), fl_settings_get_high_contrast(), fl_settings_handler_new(), fl_settings_handler_start(), and g_autoptr().

## ◆ TEST() [2/4]

TEST | ( | FlSettingsHandlerTest | ,
|  | AlwaysUse24HourFormat |
| ) |  |

Definition at line 17 of file fl_settings_handler_test.cc.

17 {
18 ::testing::NiceMock<flutter::testing::MockSettings> settings;
19
20 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
21 g_autoptr(FlEngine) engine =
22 fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
23 g_autoptr(FlSettingsHandler) handler = fl_settings_handler_new(engine);
24
25 EXPECT_CALL(settings, fl_settings_get_clock_format(
26 ::testing::Eq<FlSettings*>(settings)))
27 .WillOnce(::testing::Return(FL_CLOCK_FORMAT_12H))
28 .WillOnce(::testing::Return(FL_CLOCK_FORMAT_24H));
29
30 gboolean called = FALSE;
31 fl_mock_binary_messenger_set_json_message_channel(
32 messenger, "flutter/settings",
33 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
34 gpointer user_data) {
35 gboolean* called = static_cast<gboolean*>(user_data);
36 *called = TRUE;
37
38 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_MAP);
39 FlValue* value =
40 fl_value_lookup_string(message, "alwaysUse24HourFormat");
41 EXPECT_NE(value, nullptr);
42 EXPECT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_BOOL);
43 EXPECT_FALSE(fl_value_get_bool(value));
44
45 return fl_value_new_null();
46 },
47 &called);
48 fl_settings_handler_start(handler, settings);
49 EXPECT_TRUE(called);
50
51 called = FALSE;
52 fl_mock_binary_messenger_set_json_message_channel(
53 messenger, "flutter/settings",
54 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
55 gpointer user_data) {
56 gboolean* called = static_cast<gboolean*>(user_data);
57 *called = TRUE;
58
59 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_MAP);
60 FlValue* value =
61 fl_value_lookup_string(message, "alwaysUse24HourFormat");
62 EXPECT_NE(value, nullptr);
63 EXPECT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_BOOL);
64 EXPECT_TRUE(fl_value_get_bool(value));
65
66 return fl_value_new_null();
67 },
68 &called);
69 fl_settings_emit_changed(settings);
70 EXPECT_TRUE(called);
71
72 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
73 }
message
const char * message
Definition: fl_accessibility_handler.cc:21
user_data
const char FlTextDirection FlAssertiveness gpointer user_data
Definition: fl_accessibility_handler.cc:24
fl_binary_messenger_shutdown
void fl_binary_messenger_shutdown(FlBinaryMessenger *self)
Definition: fl_binary_messenger.cc:500
TRUE
return TRUE
Definition: fl_compositor_software.cc:68
fl_engine_new_with_binary_messenger
FlEngine * fl_engine_new_with_binary_messenger(FlBinaryMessenger *binary_messenger)
Definition: fl_engine.cc:701
fl_settings_get_clock_format
FlClockFormat fl_settings_get_clock_format(FlSettings *self)
Definition: fl_settings.cc:30
FL_CLOCK_FORMAT_12H
@ FL_CLOCK_FORMAT_12H
Definition: fl_settings.h:22
FL_CLOCK_FORMAT_24H
@ FL_CLOCK_FORMAT_24H
Definition: fl_settings.h:23
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_value_lookup_string
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
Definition: fl_value.cc:811
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
fl_value_get_bool
G_MODULE_EXPORT bool fl_value_get_bool(FlValue *self)
Definition: fl_value.cc:661
fl_value_new_null
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:251
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
FL_VALUE_TYPE_BOOL
@ FL_VALUE_TYPE_BOOL
Definition: fl_value.h:65
FL_VALUE_TYPE_MAP
@ FL_VALUE_TYPE_MAP
Definition: fl_value.h:74

References fl_binary_messenger_shutdown(), FL_CLOCK_FORMAT_12H, FL_CLOCK_FORMAT_24H, fl_engine_new_with_binary_messenger(), fl_settings_emit_changed(), fl_settings_get_clock_format(), fl_settings_handler_new(), fl_settings_handler_start(), fl_value_get_bool(), fl_value_get_type(), fl_value_lookup_string(), fl_value_new_null(), FL_VALUE_TYPE_BOOL, FL_VALUE_TYPE_MAP, g_autoptr(), message, TRUE, user_data, and value.

## ◆ TEST() [3/4]

TEST | ( | FlSettingsHandlerTest | ,
|  | PlatformBrightness |
| ) |  |

Definition at line 75 of file fl_settings_handler_test.cc.

75 {
76 ::testing::NiceMock<flutter::testing::MockSettings> settings;
77
78 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
79 g_autoptr(FlEngine) engine =
80 fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
81 g_autoptr(FlSettingsHandler) handler = fl_settings_handler_new(engine);
82
83 EXPECT_CALL(settings, fl_settings_get_color_scheme(
84 ::testing::Eq<FlSettings*>(settings)))
85 .WillOnce(::testing::Return(FL_COLOR_SCHEME_LIGHT))
86 .WillOnce(::testing::Return(FL_COLOR_SCHEME_DARK));
87
88 gboolean called = FALSE;
89 fl_mock_binary_messenger_set_json_message_channel(
90 messenger, "flutter/settings",
91 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
92 gpointer user_data) {
93 gboolean* called = static_cast<gboolean*>(user_data);
94 *called = TRUE;
95
96 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_MAP);
97 FlValue* value = fl_value_lookup_string(message, "platformBrightness");
98 EXPECT_NE(value, nullptr);
99 EXPECT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_STRING);
100 EXPECT_STREQ(fl_value_get_string(value), "light");
101
102 return fl_value_new_null();
103 },
104 &called);
105 fl_settings_handler_start(handler, settings);
106 EXPECT_TRUE(called);
107
108 called = FALSE;
109 fl_mock_binary_messenger_set_json_message_channel(
110 messenger, "flutter/settings",
111 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
112 gpointer user_data) {
113 gboolean* called = static_cast<gboolean*>(user_data);
114 *called = TRUE;
115
116 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_MAP);
117 FlValue* value = fl_value_lookup_string(message, "platformBrightness");
118 EXPECT_NE(value, nullptr);
119 EXPECT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_STRING);
120 EXPECT_STREQ(fl_value_get_string(value), "dark");
121
122 return fl_value_new_null();
123 },
124 &called);
125 fl_settings_emit_changed(settings);
126 EXPECT_TRUE(called);
127
128 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
129 }
fl_settings_get_color_scheme
FlColorScheme fl_settings_get_color_scheme(FlSettings *self)
Definition: fl_settings.cc:34
FL_COLOR_SCHEME_DARK
@ FL_COLOR_SCHEME_DARK
Definition: fl_settings.h:35
FL_COLOR_SCHEME_LIGHT
@ FL_COLOR_SCHEME_LIGHT
Definition: fl_settings.h:34
fl_value_get_string
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:68

References fl_binary_messenger_shutdown(), FL_COLOR_SCHEME_DARK, FL_COLOR_SCHEME_LIGHT, fl_engine_new_with_binary_messenger(), fl_settings_emit_changed(), fl_settings_get_color_scheme(), fl_settings_handler_new(), fl_settings_handler_start(), fl_value_get_string(), fl_value_get_type(), fl_value_lookup_string(), fl_value_new_null(), FL_VALUE_TYPE_MAP, FL_VALUE_TYPE_STRING, g_autoptr(), message, TRUE, user_data, and value.

## ◆ TEST() [4/4]

TEST | ( | FlSettingsHandlerTest | ,
|  | TextScaleFactor |
| ) |  |

Definition at line 131 of file fl_settings_handler_test.cc.

131 {
132 ::testing::NiceMock<flutter::testing::MockSettings> settings;
133
134 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
135 g_autoptr(FlEngine) engine =
136 fl_engine_new_with_binary_messenger(FL_BINARY_MESSENGER(messenger));
137 g_autoptr(FlSettingsHandler) handler = fl_settings_handler_new(engine);
138
139 EXPECT_CALL(settings, fl_settings_get_text_scaling_factor(
140 ::testing::Eq<FlSettings*>(settings)))
141 .WillOnce(::testing::Return(1.0))
142 .WillOnce(::testing::Return(2.0));
143
144 gboolean called = FALSE;
145 fl_mock_binary_messenger_set_json_message_channel(
146 messenger, "flutter/settings",
147 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
148 gpointer user_data) {
149 gboolean* called = static_cast<gboolean*>(user_data);
150 *called = TRUE;
151
152 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_MAP);
153 FlValue* value = fl_value_lookup_string(message, "textScaleFactor");
154 EXPECT_NE(value, nullptr);
155 EXPECT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
156 EXPECT_EQ(fl_value_get_float(value), 1.0);
157
158 return fl_value_new_null();
159 },
160 &called);
161 fl_settings_handler_start(handler, settings);
162 EXPECT_TRUE(called);
163
164 called = FALSE;
165 fl_mock_binary_messenger_set_json_message_channel(
166 messenger, "flutter/settings",
167 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
168 gpointer user_data) {
169 gboolean* called = static_cast<gboolean*>(user_data);
170 *called = TRUE;
171
172 EXPECT_EQ(fl_value_get_type(message), FL_VALUE_TYPE_MAP);
173 FlValue* value = fl_value_lookup_string(message, "textScaleFactor");
174 EXPECT_NE(value, nullptr);
175 EXPECT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
176 EXPECT_EQ(fl_value_get_float(value), 2.0);
177
178 return fl_value_new_null();
179 },
180 &called);
181 fl_settings_emit_changed(settings);
182 EXPECT_TRUE(called);
183
184 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
185 }
fl_settings_get_text_scaling_factor
gdouble fl_settings_get_text_scaling_factor(FlSettings *self)
Definition: fl_settings.cc:46
fl_value_get_float
G_MODULE_EXPORT double fl_value_get_float(FlValue *self)
Definition: fl_value.cc:675
FL_VALUE_TYPE_FLOAT
@ FL_VALUE_TYPE_FLOAT
Definition: fl_value.h:67

References fl_binary_messenger_shutdown(), fl_engine_new_with_binary_messenger(), fl_settings_emit_changed(), fl_settings_get_text_scaling_factor(), fl_settings_handler_new(), fl_settings_handler_start(), fl_value_get_float(), fl_value_get_type(), fl_value_lookup_string(), fl_value_new_null(), FL_VALUE_TYPE_FLOAT, FL_VALUE_TYPE_MAP, g_autoptr(), message, TRUE, user_data, and value.