1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
/*
* Copyright © Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 or 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mir/input/mousekeys_keymap.h>
#include <mir/shell/accessibility_manager.h>
#include <mir/shell/mousekeys_transformer.h>
#include <miral/mousekeys_config.h>
#include <miral/accessibility_test_server.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
using namespace testing;
struct TestMouseKeysConfig : miral::TestAccessibilityManager
{
miral::MouseKeysConfig config{miral::MouseKeysConfig::enabled()};
};
TEST_F(TestMouseKeysConfig, enabling_mousekeys_from_miral_enables_it_in_the_accessibility_manager)
{
// Once at startup, and twice when we call `set_keymap` below
InSequence seq;
EXPECT_CALL(*accessibility_manager, mousekeys_enabled(true)); // `true` passed to config where its defined
EXPECT_CALL(*accessibility_manager, mousekeys_enabled(true)); // First call below
EXPECT_CALL(*accessibility_manager, mousekeys_enabled(false)); // Second call below
add_server_init(config);
start_server();
config.enable();
config.disable();
}
MATCHER_P(KeymapEq, keymap, "")
{
auto const keymap_to_unordered_map =
[](mir::input::MouseKeysKeymap const& keymap)
{
std::unordered_map<mir::input::XkbSymkey, mir::input::MouseKeysKeymap::Action> key_action_map;
keymap.for_each_key_action_pair([&](auto const key, auto const action)
{ key_action_map.insert({key, action}); });
return key_action_map;
};
auto const arg_key_action_map = keymap_to_unordered_map(arg);
auto const keymap_key_action_map = keymap_to_unordered_map(keymap);
return arg_key_action_map == keymap_key_action_map;
}
TEST_F(TestMouseKeysConfig, mousekeys_config_set_keymap_sets_transformer_keymap)
{
auto const test_keymap = mir::input::MouseKeysKeymap{};
// We don't call `set_keymap` at startup
EXPECT_CALL(accessibility_manager->mousekeys_transformer, keymap(KeymapEq(test_keymap)));
add_server_init(config);
start_server();
config.set_keymap(test_keymap);
}
TEST_F(TestMouseKeysConfig, mousekeys_config_set_acceleration_factors_sets_mousekeys_acceleration_factors)
{
auto const [default_constant, default_linear, default_quadratic] = std::tuple{100.0, 100.0, 30.0};
auto const [constant, linear, quadratic] = std::tuple{1.0, 1.0, 1.0};
InSequence seq;
// Defaults, called on server init
EXPECT_CALL(
accessibility_manager->mousekeys_transformer,
acceleration_factors(default_constant, default_linear, default_quadratic));
EXPECT_CALL(accessibility_manager->mousekeys_transformer, acceleration_factors(constant, linear, quadratic));
add_server_init(config);
start_server();
config.set_acceleration_factors(constant, linear, quadratic);
}
TEST_F(TestMouseKeysConfig, mousekeys_config_set_max_speed_sets_mousekeys_max_speed)
{
auto const [default_max_x, default_max_y] = std::pair{400.0, 400.0};
auto const [max_x, max_y] = std::pair{1.0, 1.0};
InSequence seq;
EXPECT_CALL(accessibility_manager->mousekeys_transformer, max_speed(default_max_x, default_max_y));
EXPECT_CALL(accessibility_manager->mousekeys_transformer, max_speed(max_x, max_y));
add_server_init(config);
start_server();
config.set_max_speed(max_x, max_y);
}
struct EnableMouseKeysOptionTest : public TestMouseKeysConfig, public WithParamInterface<bool>
{
};
TEST_P(EnableMouseKeysOptionTest, enable_mouse_keys_option_overrides_mousekeys_default_enabled_state)
{
auto const enabled = GetParam();
add_to_environment("MIR_SERVER_ENABLE_MOUSE_KEYS", enabled? "1": "0");
if(enabled)
EXPECT_CALL(*accessibility_manager, mousekeys_enabled(true));
else
EXPECT_CALL(*accessibility_manager, mousekeys_enabled(_)).Times(0);
add_server_init(config);
start_server();
}
TEST_P(EnableMouseKeysOptionTest, mouse_keys_is_enabled_on_config_state_if_option_is_not_specified)
{
auto const enabled = GetParam();
if(enabled)
{
EXPECT_CALL(*accessibility_manager, mousekeys_enabled(true));
add_server_init(miral::MouseKeysConfig::enabled());
}
else
{
EXPECT_CALL(*accessibility_manager, mousekeys_enabled(_)).Times(0);
add_server_init(miral::MouseKeysConfig::disabled());
}
start_server();
}
INSTANTIATE_TEST_SUITE_P(TestMouseKeysConfig, EnableMouseKeysOptionTest, ::Values(false, true));
|