| Flutter Linux Embedder |

fl_gnome_settings_test.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
5 #include "flutter/shell/platform/linux/fl_gnome_settings.h"
6 #include "flutter/shell/platform/linux/testing/fl_test.h"
7 #include "flutter/shell/platform/linux/testing/mock_settings.h"
8 #include "flutter/shell/platform/linux/testing/mock_signal_handler.h"
9 #include "flutter/testing/testing.h"
10
11 #include <gio/gio.h>
12 #define G_SETTINGS_ENABLE_BACKEND
13 #include <gio/gsettingsbackend.h>
14
15 #include "gmock/gmock.h"
16 #include "gtest/gtest.h"
17
18 class FlGnomeSettingsTest : public ::testing::Test {
19 protected:
20 void SetUp() override {
21 // force _g_io_modules_ensure_extension_points_registered() to get called
22 g_settings_backend_get_default();
23 }
24 };
25
26 static GSettings* create_settings(const gchar* name, const gchar* schema_id) {
27 g_autofree gchar* path =
28 g_build_filename(flutter::testing::GetFixturesPath(), name, nullptr);
29 g_autoptr(GSettingsSchemaSource) source =
30 g_settings_schema_source_new_from_directory(path, nullptr, false,
31 nullptr);
32 g_autoptr(GSettingsSchema) schema =
33 g_settings_schema_source_lookup(source, schema_id, false);
34 g_autoptr(GSettingsBackend) backend = g_memory_settings_backend_new();
35 return g_settings_new_full(schema, backend, nullptr);
36 }
37
38 TEST_F(FlGnomeSettingsTest, ClockFormat) {
39 g_autoptr(GSettings) interface_settings =
40 create_settings("ubuntu-20.04", "org.gnome.desktop.interface");
41 g_settings_set_string(interface_settings, "clock-format", "24h");
42
43 g_autoptr(FlSettings) settings = FL_SETTINGS(
44 g_object_new(fl_gnome_settings_get_type(), "interface_settings",
45 interface_settings, nullptr));
46 EXPECT_EQ(fl_settings_get_clock_format(settings), FL_CLOCK_FORMAT_24H);
47
48 flutter::testing::MockSignalHandler settings_changed(settings, "changed");
49 EXPECT_SIGNAL(settings_changed).Times(1);
50
51 g_settings_set_string(interface_settings, "clock-format", "12h");
52 EXPECT_EQ(fl_settings_get_clock_format(settings), FL_CLOCK_FORMAT_12H);
53 }
54
55 TEST_F(FlGnomeSettingsTest, GtkTheme) {
56 g_autoptr(GSettings) interface_settings =
57 create_settings("ubuntu-20.04", "org.gnome.desktop.interface");
58 g_settings_set_string(interface_settings, "gtk-theme", "Yaru");
59
60 g_autoptr(FlSettings) settings = FL_SETTINGS(
61 g_object_new(fl_gnome_settings_get_type(), "interface_settings",
62 interface_settings, nullptr));
63 EXPECT_EQ(fl_settings_get_color_scheme(settings), FL_COLOR_SCHEME_LIGHT);
64
65 flutter::testing::MockSignalHandler settings_changed(settings, "changed");
66 EXPECT_SIGNAL(settings_changed).Times(1);
67
68 g_settings_set_string(interface_settings, "gtk-theme", "Yaru-dark");
69 EXPECT_EQ(fl_settings_get_color_scheme(settings), FL_COLOR_SCHEME_DARK);
70 }
71
72 TEST_F(FlGnomeSettingsTest, EnableAnimations) {
73 g_autoptr(FlSettings) settings = fl_gnome_settings_new();
74 EXPECT_TRUE(fl_settings_get_enable_animations(settings));
75 }
76
77 TEST_F(FlGnomeSettingsTest, HighContrast) {
78 g_autoptr(FlSettings) settings = fl_gnome_settings_new();
79 EXPECT_FALSE(fl_settings_get_high_contrast(settings));
80 }
81
82 TEST_F(FlGnomeSettingsTest, TextScalingFactor) {
83 g_autoptr(GSettings) interface_settings =
84 create_settings("ubuntu-20.04", "org.gnome.desktop.interface");
85 g_settings_set_double(interface_settings, "text-scaling-factor", 1.0);
86
87 g_autoptr(FlSettings) settings = FL_SETTINGS(
88 g_object_new(fl_gnome_settings_get_type(), "interface_settings",
89 interface_settings, nullptr));
90 EXPECT_EQ(fl_settings_get_text_scaling_factor(settings), 1.0);
91
92 flutter::testing::MockSignalHandler settings_changed(settings, "changed");
93 EXPECT_SIGNAL(settings_changed).Times(1);
94
95 g_settings_set_double(interface_settings, "text-scaling-factor", 1.5);
96 EXPECT_EQ(fl_settings_get_text_scaling_factor(settings), 1.5);
97 }
98
99 TEST_F(FlGnomeSettingsTest, SignalHandlers) {
100 g_autoptr(GSettings) interface_settings =
101 create_settings("ubuntu-20.04", "org.gnome.desktop.interface");
102
103 g_autoptr(FlSettings) settings = FL_SETTINGS(
104 g_object_new(fl_gnome_settings_get_type(), "interface_settings",
105 interface_settings, nullptr));
106 flutter::testing::MockSignalHandler settings_changed(settings, "changed");
107
108 EXPECT_SIGNAL(settings_changed).Times(3);
109
110 g_settings_set_string(interface_settings, "clock-format", "12h");
111 g_settings_set_string(interface_settings, "gtk-theme", "Yaru-dark");
112 g_settings_set_double(interface_settings, "text-scaling-factor", 1.5);
113
114 EXPECT_SIGNAL(settings_changed).Times(0);
115
116 g_clear_object(&settings);
117
118 // destroyed FlSettings object must have disconnected its signal handlers
119 g_settings_set_string(interface_settings, "clock-format", "24h");
120 g_settings_set_string(interface_settings, "gtk-theme", "Yaru");
121 g_settings_set_double(interface_settings, "text-scaling-factor", 2.0);
122 }
FlGnomeSettingsTest
Definition: fl_gnome_settings_test.cc:18
FlGnomeSettingsTest::SetUp
void SetUp() override
Definition: fl_gnome_settings_test.cc:20
g_autoptr
g_autoptr(GMutexLocker) locker
fl_gnome_settings_new
FlSettings * fl_gnome_settings_new()
Definition: fl_gnome_settings.cc:164
fl_gnome_settings.h
TEST_F
TEST_F(FlGnomeSettingsTest, ClockFormat)
Definition: fl_gnome_settings_test.cc:38
create_settings
static GSettings * create_settings(const gchar *name, const gchar *schema_id)
Definition: fl_gnome_settings_test.cc:26
fl_settings_get_high_contrast
gboolean fl_settings_get_high_contrast(FlSettings *self)
Definition: fl_settings.cc:42
fl_settings_get_text_scaling_factor
gdouble fl_settings_get_text_scaling_factor(FlSettings *self)
Definition: fl_settings.cc:46
fl_settings_get_enable_animations
gboolean fl_settings_get_enable_animations(FlSettings *self)
Definition: fl_settings.cc:38
fl_settings_get_color_scheme
FlColorScheme fl_settings_get_color_scheme(FlSettings *self)
Definition: fl_settings.cc:34
fl_settings_get_clock_format
FlClockFormat fl_settings_get_clock_format(FlSettings *self)
Definition: fl_settings.cc:30
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_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