7 #include "flutter/fml/macros.h"
9 #include "flutter/shell/platform/windows/testing/test_binary_messenger.h"
10 #include "gmock/gmock.h"
11 #include "gtest/gtest.h"
18 class MockSettingsPlugin :
public SettingsPlugin {
20 explicit MockSettingsPlugin(BinaryMessenger* messenger,
21 TaskRunner* task_runner)
22 : SettingsPlugin(messenger, task_runner) {}
24 virtual ~MockSettingsPlugin() =
default;
26 bool is_high_contrast() {
return is_high_contrast_; }
29 MOCK_METHOD(
bool, GetAlwaysUse24HourFormat, (), (
override));
30 MOCK_METHOD(
float, GetTextScaleFactor, (), (
override));
31 MOCK_METHOD(PlatformBrightness, GetPreferredBrightness, (), (
override));
33 MOCK_METHOD(
void, WatchPreferredBrightnessChanged, (), (
override));
34 MOCK_METHOD(
void, WatchTextScaleFactorChanged, (), (
override));
37 FML_DISALLOW_COPY_AND_ASSIGN(MockSettingsPlugin);
42 TEST(SettingsPluginTest, SendSettingsSendsMessage) {
43 bool message_is_sent =
false;
44 TestBinaryMessenger messenger(
45 [&message_is_sent](
const std::string& channel,
const uint8_t*
message,
48 ::testing::NiceMock<MockSettingsPlugin> settings_plugin(&messenger,
nullptr);
50 settings_plugin.SendSettings();
52 EXPECT_TRUE(message_is_sent);
55 TEST(SettingsPluginTest, SendSettingsGetsSettings) {
56 TestBinaryMessenger messenger([](
const std::string& channel,
57 const uint8_t*
message,
size_t message_size,
59 ::testing::NiceMock<MockSettingsPlugin> settings_plugin(&messenger,
nullptr);
61 EXPECT_CALL(settings_plugin, GetAlwaysUse24HourFormat).Times(1);
62 EXPECT_CALL(settings_plugin, GetTextScaleFactor).Times(1);
63 EXPECT_CALL(settings_plugin, GetPreferredBrightness).Times(1);
65 settings_plugin.SendSettings();
68 TEST(SettingsPluginTest, StartWatchingStartsWatchingChanges) {
69 TestBinaryMessenger messenger([](
const std::string& channel,
70 const uint8_t*
message,
size_t message_size,
72 ::testing::NiceMock<MockSettingsPlugin> settings_plugin(&messenger,
nullptr);
74 EXPECT_CALL(settings_plugin, WatchPreferredBrightnessChanged).Times(1);
75 EXPECT_CALL(settings_plugin, WatchTextScaleFactorChanged).Times(1);
77 settings_plugin.StartWatching();
80 TEST(SettingsPluginTest, HighContrastModeHonored) {
82 TestBinaryMessenger messenger(
83 [×](
const std::string& channel,
const uint8_t*
message,
85 ASSERT_EQ(channel,
"flutter/settings");
88 ::testing::NiceMock<MockSettingsPlugin> settings_plugin(&messenger,
nullptr);
90 settings_plugin.UpdateHighContrastMode(
true);
91 EXPECT_TRUE(settings_plugin.is_high_contrast());
93 settings_plugin.UpdateHighContrastMode(
false);
94 EXPECT_FALSE(settings_plugin.is_high_contrast());