Flutter Engine
The Flutter Engine
settings_plugin_unittests.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/windows/settings_plugin.h"
6
7#include "flutter/fml/macros.h"
8#include "flutter/shell/platform/windows/task_runner.h"
9#include "flutter/shell/platform/windows/testing/test_binary_messenger.h"
10#include "gmock/gmock.h"
11#include "gtest/gtest.h"
12
13namespace flutter {
14namespace testing {
15
16namespace {
17
18class MockSettingsPlugin : public SettingsPlugin {
19 public:
20 explicit MockSettingsPlugin(BinaryMessenger* messenger,
21 TaskRunner* task_runner)
22 : SettingsPlugin(messenger, task_runner) {}
23
24 virtual ~MockSettingsPlugin() = default;
25
26 bool is_high_contrast() { return is_high_contrast_; }
27
28 // |SettingsPlugin|
29 MOCK_METHOD(bool, GetAlwaysUse24HourFormat, (), (override));
30 MOCK_METHOD(float, GetTextScaleFactor, (), (override));
31 MOCK_METHOD(PlatformBrightness, GetPreferredBrightness, (), (override));
32
33 MOCK_METHOD(void, WatchPreferredBrightnessChanged, (), (override));
34 MOCK_METHOD(void, WatchTextScaleFactorChanged, (), (override));
35
36 private:
37 FML_DISALLOW_COPY_AND_ASSIGN(MockSettingsPlugin);
38};
39
40} // namespace
41
42TEST(SettingsPluginTest, SendSettingsSendsMessage) {
43 bool message_is_sent = false;
44 TestBinaryMessenger messenger(
45 [&message_is_sent](const std::string& channel, const uint8_t* message,
46 size_t message_size,
47 BinaryReply reply) { message_is_sent = true; });
48 ::testing::NiceMock<MockSettingsPlugin> settings_plugin(&messenger, nullptr);
49
50 settings_plugin.SendSettings();
51
52 EXPECT_TRUE(message_is_sent);
53}
54
55TEST(SettingsPluginTest, SendSettingsGetsSettings) {
56 TestBinaryMessenger messenger([](const std::string& channel,
57 const uint8_t* message, size_t message_size,
58 BinaryReply reply) {});
59 ::testing::NiceMock<MockSettingsPlugin> settings_plugin(&messenger, nullptr);
60
61 EXPECT_CALL(settings_plugin, GetAlwaysUse24HourFormat).Times(1);
62 EXPECT_CALL(settings_plugin, GetTextScaleFactor).Times(1);
63 EXPECT_CALL(settings_plugin, GetPreferredBrightness).Times(1);
64
65 settings_plugin.SendSettings();
66}
67
68TEST(SettingsPluginTest, StartWatchingStartsWatchingChanges) {
69 TestBinaryMessenger messenger([](const std::string& channel,
70 const uint8_t* message, size_t message_size,
71 BinaryReply reply) {});
72 ::testing::NiceMock<MockSettingsPlugin> settings_plugin(&messenger, nullptr);
73
74 EXPECT_CALL(settings_plugin, WatchPreferredBrightnessChanged).Times(1);
75 EXPECT_CALL(settings_plugin, WatchTextScaleFactorChanged).Times(1);
76
77 settings_plugin.StartWatching();
78}
79
80TEST(SettingsPluginTest, HighContrastModeHonored) {
81 int times = 0;
82 TestBinaryMessenger messenger(
83 [&times](const std::string& channel, const uint8_t* message,
84 size_t message_size, BinaryReply reply) {
85 ASSERT_EQ(channel, "flutter/settings");
86 times++;
87 });
88 ::testing::NiceMock<MockSettingsPlugin> settings_plugin(&messenger, nullptr);
89
90 settings_plugin.UpdateHighContrastMode(true);
91 EXPECT_TRUE(settings_plugin.is_high_contrast());
92
93 settings_plugin.UpdateHighContrastMode(false);
94 EXPECT_FALSE(settings_plugin.is_high_contrast());
95
96 EXPECT_EQ(times, 2);
97}
98
99} // namespace testing
100} // namespace flutter
static SkISize times(const SkISize &size, float factor)
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27
Win32Message message
TEST(DisplayListComplexity, EmptyDisplayList)
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678