Flutter Linux Embedder
fl_settings_plugin_test.cc File Reference
#include "flutter/shell/platform/linux/fl_settings_plugin.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_engine_private.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_value.h"
#include "flutter/shell/platform/linux/testing/fl_test.h"
#include "flutter/shell/platform/linux/testing/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.

Macros

#define EXPECT_SETTING(messenger, key, value)
 

Functions

 MATCHER_P2 (HasSetting, key, value, "")
 
 TEST (FlSettingsPluginTest, AlwaysUse24HourFormat)
 
 TEST (FlSettingsPluginTest, PlatformBrightness)
 
 TEST (FlSettingsPluginTest, TextScaleFactor)
 
 TEST (FlSettingsPluginTest, AccessibilityFeatures)
 

Macro Definition Documentation

◆ EXPECT_SETTING

#define EXPECT_SETTING (   messenger,
  key,
  value 
)
Value:
EXPECT_CALL( \
messenger, \
::testing::Eq<FlBinaryMessenger*>(messenger), \
::testing::StrEq("flutter/settings"), HasSetting(key, value), \
::testing::A<GCancellable*>(), ::testing::A<GAsyncReadyCallback>(), \
::testing::A<gpointer>()))

Definition at line 31 of file fl_settings_plugin_test.cc.

Function Documentation

◆ MATCHER_P2()

MATCHER_P2 ( HasSetting  ,
key  ,
value  ,
""   
)

Definition at line 20 of file fl_settings_plugin_test.cc.

20  {
21  g_autoptr(FlJsonMessageCodec) codec = fl_json_message_codec_new();
22  g_autoptr(FlValue) message =
23  fl_message_codec_decode_message(FL_MESSAGE_CODEC(codec), arg, nullptr);
24  if (fl_value_equal(fl_value_lookup_string(message, key), value)) {
25  return true;
26  }
27  *result_listener << ::testing::PrintToString(message);
28  return false;
29 }

References fl_json_message_codec_new(), fl_message_codec_decode_message(), fl_value_equal(), fl_value_lookup_string(), and value.

◆ TEST() [1/4]

TEST ( FlSettingsPluginTest  ,
AccessibilityFeatures   
)

Definition at line 120 of file fl_settings_plugin_test.cc.

120  {
121  g_autoptr(FlEngine) engine = make_mock_engine();
122  FlutterEngineProcTable* embedder_api = fl_engine_get_embedder_api(engine);
123 
124  std::vector<FlutterAccessibilityFeature> calls;
125  embedder_api->UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
126  UpdateAccessibilityFeatures,
127  ([&calls](auto engine, FlutterAccessibilityFeature features) {
128  calls.push_back(features);
129  return kSuccess;
130  }));
131 
132  g_autoptr(FlSettingsPlugin) plugin = fl_settings_plugin_new(engine);
133 
134  ::testing::NiceMock<flutter::testing::MockSettings> settings;
135 
136  EXPECT_CALL(settings, fl_settings_get_enable_animations(
137  ::testing::Eq<FlSettings*>(settings)))
138  .WillOnce(::testing::Return(false))
139  .WillOnce(::testing::Return(true))
140  .WillOnce(::testing::Return(false))
141  .WillOnce(::testing::Return(true));
142 
143  EXPECT_CALL(settings, fl_settings_get_high_contrast(
144  ::testing::Eq<FlSettings*>(settings)))
145  .WillOnce(::testing::Return(true))
146  .WillOnce(::testing::Return(false))
147  .WillOnce(::testing::Return(false))
148  .WillOnce(::testing::Return(true));
149 
150  fl_settings_plugin_start(plugin, settings);
151  EXPECT_THAT(calls, ::testing::SizeIs(1));
152  EXPECT_EQ(calls.back(), static_cast<FlutterAccessibilityFeature>(
153  kFlutterAccessibilityFeatureDisableAnimations |
154  kFlutterAccessibilityFeatureHighContrast));
155 
156  fl_settings_emit_changed(settings);
157  EXPECT_THAT(calls, ::testing::SizeIs(2));
158  EXPECT_EQ(calls.back(), static_cast<FlutterAccessibilityFeature>(0));
159 
160  fl_settings_emit_changed(settings);
161  EXPECT_THAT(calls, ::testing::SizeIs(3));
162  EXPECT_EQ(calls.back(), static_cast<FlutterAccessibilityFeature>(
163  kFlutterAccessibilityFeatureDisableAnimations));
164 
165  fl_settings_emit_changed(settings);
166  EXPECT_THAT(calls, ::testing::SizeIs(4));
167  EXPECT_EQ(calls.back(), static_cast<FlutterAccessibilityFeature>(
168  kFlutterAccessibilityFeatureHighContrast));
169 }

References fl_engine_get_embedder_api(), fl_settings_emit_changed(), fl_settings_get_enable_animations(), fl_settings_get_high_contrast(), fl_settings_plugin_new(), fl_settings_plugin_start(), and make_mock_engine().

◆ TEST() [2/4]

TEST ( FlSettingsPluginTest  ,
AlwaysUse24HourFormat   
)

Definition at line 40 of file fl_settings_plugin_test.cc.

40  {
41  ::testing::NiceMock<flutter::testing::MockSettings> settings;
42  ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
43 
44  g_autoptr(FlEngine) engine =
45  FL_ENGINE(g_object_new(fl_engine_get_type(), "binary-messenger",
46  FL_BINARY_MESSENGER(messenger), nullptr));
47  g_autoptr(FlSettingsPlugin) plugin = fl_settings_plugin_new(engine);
48 
49  g_autoptr(FlValue) use_12h = fl_value_new_bool(false);
50  g_autoptr(FlValue) use_24h = fl_value_new_bool(true);
51 
52  EXPECT_CALL(settings, fl_settings_get_clock_format(
53  ::testing::Eq<FlSettings*>(settings)))
54  .WillOnce(::testing::Return(FL_CLOCK_FORMAT_12H))
55  .WillOnce(::testing::Return(FL_CLOCK_FORMAT_24H));
56 
57  EXPECT_SETTING(messenger, "alwaysUse24HourFormat", use_12h);
58 
59  fl_settings_plugin_start(plugin, settings);
60 
61  EXPECT_SETTING(messenger, "alwaysUse24HourFormat", use_24h);
62 
63  fl_settings_emit_changed(settings);
64 }

References EXPECT_SETTING, FL_CLOCK_FORMAT_12H, FL_CLOCK_FORMAT_24H, fl_settings_emit_changed(), fl_settings_get_clock_format(), fl_settings_plugin_new(), fl_settings_plugin_start(), and fl_value_new_bool().

◆ TEST() [3/4]

TEST ( FlSettingsPluginTest  ,
PlatformBrightness   
)

Definition at line 66 of file fl_settings_plugin_test.cc.

66  {
67  ::testing::NiceMock<flutter::testing::MockSettings> settings;
68  ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
69 
70  g_autoptr(FlEngine) engine =
71  FL_ENGINE(g_object_new(fl_engine_get_type(), "binary-messenger",
72  FL_BINARY_MESSENGER(messenger), nullptr));
73  g_autoptr(FlSettingsPlugin) plugin = fl_settings_plugin_new(engine);
74 
75  g_autoptr(FlValue) light = fl_value_new_string("light");
76  g_autoptr(FlValue) dark = fl_value_new_string("dark");
77 
78  EXPECT_CALL(settings, fl_settings_get_color_scheme(
79  ::testing::Eq<FlSettings*>(settings)))
80  .WillOnce(::testing::Return(FL_COLOR_SCHEME_LIGHT))
81  .WillOnce(::testing::Return(FL_COLOR_SCHEME_DARK));
82 
83  EXPECT_SETTING(messenger, "platformBrightness", light);
84 
85  fl_settings_plugin_start(plugin, settings);
86 
87  EXPECT_SETTING(messenger, "platformBrightness", dark);
88 
89  fl_settings_emit_changed(settings);
90 }

References EXPECT_SETTING, FL_COLOR_SCHEME_DARK, FL_COLOR_SCHEME_LIGHT, fl_settings_emit_changed(), fl_settings_get_color_scheme(), fl_settings_plugin_new(), fl_settings_plugin_start(), and fl_value_new_string().

◆ TEST() [4/4]

TEST ( FlSettingsPluginTest  ,
TextScaleFactor   
)

Definition at line 92 of file fl_settings_plugin_test.cc.

92  {
93  ::testing::NiceMock<flutter::testing::MockSettings> settings;
94  ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
95 
96  g_autoptr(FlEngine) engine =
97  FL_ENGINE(g_object_new(fl_engine_get_type(), "binary-messenger",
98  FL_BINARY_MESSENGER(messenger), nullptr));
99  g_autoptr(FlSettingsPlugin) plugin = fl_settings_plugin_new(engine);
100 
101  g_autoptr(FlValue) one = fl_value_new_float(1.0);
102  g_autoptr(FlValue) two = fl_value_new_float(2.0);
103 
104  EXPECT_CALL(settings, fl_settings_get_text_scaling_factor(
105  ::testing::Eq<FlSettings*>(settings)))
106  .WillOnce(::testing::Return(1.0))
107  .WillOnce(::testing::Return(2.0));
108 
109  EXPECT_SETTING(messenger, "textScaleFactor", one);
110 
111  fl_settings_plugin_start(plugin, settings);
112 
113  EXPECT_SETTING(messenger, "textScaleFactor", two);
114 
115  fl_settings_emit_changed(settings);
116 }

References EXPECT_SETTING, fl_settings_emit_changed(), fl_settings_get_text_scaling_factor(), fl_settings_plugin_new(), fl_settings_plugin_start(), and fl_value_new_float().

fl_engine_get_embedder_api
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:602
fl_settings_get_color_scheme
FlColorScheme fl_settings_get_color_scheme(FlSettings *self)
Definition: fl_settings.cc:34
FL_CLOCK_FORMAT_12H
@ FL_CLOCK_FORMAT_12H
Definition: fl_settings.h:23
FL_CLOCK_FORMAT_24H
@ FL_CLOCK_FORMAT_24H
Definition: fl_settings.h:24
fl_value_new_bool
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:255
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
fl_json_message_codec_new
G_MODULE_EXPORT FlJsonMessageCodec * fl_json_message_codec_new()
Definition: fl_json_message_codec.cc:306
fl_settings_get_enable_animations
gboolean fl_settings_get_enable_animations(FlSettings *self)
Definition: fl_settings.cc:38
fl_value_lookup_string
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
Definition: fl_value.cc:811
fl_settings_plugin_start
void fl_settings_plugin_start(FlSettingsPlugin *self, FlSettings *settings)
Definition: fl_settings_plugin.cc:112
make_mock_engine
static FlEngine * make_mock_engine()
Definition: fl_event_channel_test.cc:24
EXPECT_SETTING
#define EXPECT_SETTING(messenger, key, value)
Definition: fl_settings_plugin_test.cc:31
fl_message_codec_decode_message
G_MODULE_EXPORT FlValue * fl_message_codec_decode_message(FlMessageCodec *self, GBytes *message, GError **error)
Definition: fl_message_codec.cc:33
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_text_scaling_factor
gdouble fl_settings_get_text_scaling_factor(FlSettings *self)
Definition: fl_settings.cc:46
fl_value_equal
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:471
FL_COLOR_SCHEME_LIGHT
@ FL_COLOR_SCHEME_LIGHT
Definition: fl_settings.h:37
FL_COLOR_SCHEME_DARK
@ FL_COLOR_SCHEME_DARK
Definition: fl_settings.h:38
fl_value_new_float
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
Definition: fl_value.cc:269
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_settings_get_clock_format
FlClockFormat fl_settings_get_clock_format(FlSettings *self)
Definition: fl_settings.cc:30
fl_binary_messenger_send_on_channel
G_MODULE_EXPORT void fl_binary_messenger_send_on_channel(FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_binary_messenger.cc:443
fl_settings_plugin_new
FlSettingsPlugin * fl_settings_plugin_new(FlEngine *engine)
Definition: fl_settings_plugin.cc:94
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276