Flutter Engine
The Flutter Engine
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
18class 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
26static 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
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));
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");
53}
54
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));
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");
70}
71
72TEST_F(FlGnomeSettingsTest, EnableAnimations) {
73 g_autoptr(FlSettings) settings = fl_gnome_settings_new();
75}
76
78 g_autoptr(FlSettings) settings = fl_gnome_settings_new();
80}
81
82TEST_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));
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);
97}
98
99TEST_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}
const char * backend
SkBitmap source
Definition: examples.cpp:28
FlSettings * fl_gnome_settings_new()
TEST_F(FlGnomeSettingsTest, ClockFormat)
static GSettings * create_settings(const gchar *name, const gchar *schema_id)
gboolean fl_settings_get_high_contrast(FlSettings *self)
Definition: fl_settings.cc:42
gdouble fl_settings_get_text_scaling_factor(FlSettings *self)
Definition: fl_settings.cc:46
gboolean fl_settings_get_enable_animations(FlSettings *self)
Definition: fl_settings.cc:38
FlColorScheme fl_settings_get_color_scheme(FlSettings *self)
Definition: fl_settings.cc:34
FlClockFormat fl_settings_get_clock_format(FlSettings *self)
Definition: fl_settings.cc:30
@ FL_COLOR_SCHEME_DARK
Definition: fl_settings.h:38
@ FL_COLOR_SCHEME_LIGHT
Definition: fl_settings.h:37
@ FL_CLOCK_FORMAT_12H
Definition: fl_settings.h:23
@ FL_CLOCK_FORMAT_24H
Definition: fl_settings.h:24
#define EXPECT_SIGNAL(mock)
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
SK_API sk_sp< PrecompileColorFilter > HighContrast()
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678