#include "ui/events/ozone/evdev/input_controller_evdev.h"
#include <memory>
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/ozone/evdev/input_device_settings_evdev.h"
namespace ui {
TEST(InputControllerEvdevTest, AccelerationSuspension) {
InputControllerEvdev controller(nullptr, nullptr, nullptr);
controller.SetMouseAcceleration(std::nullopt, true);
controller.SetPointingStickAcceleration(std::nullopt, true);
EXPECT_TRUE(controller.GetInputDeviceSettings()
.GetMouseSettings()
.acceleration_enabled);
EXPECT_TRUE(controller.GetInputDeviceSettings()
.GetPointingStickSettings()
.acceleration_enabled);
EXPECT_FALSE(controller.GetInputDeviceSettings().suspend_acceleration);
controller.SuspendMouseAcceleration();
EXPECT_TRUE(controller.GetInputDeviceSettings()
.GetMouseSettings()
.acceleration_enabled);
EXPECT_TRUE(controller.GetInputDeviceSettings()
.GetPointingStickSettings()
.acceleration_enabled);
EXPECT_TRUE(controller.GetInputDeviceSettings().suspend_acceleration);
controller.EndMouseAccelerationSuspension();
EXPECT_TRUE(controller.GetInputDeviceSettings()
.GetMouseSettings()
.acceleration_enabled);
EXPECT_TRUE(controller.GetInputDeviceSettings()
.GetPointingStickSettings()
.acceleration_enabled);
EXPECT_FALSE(controller.GetInputDeviceSettings().suspend_acceleration);
}
TEST(InputControllerEvdevTest, DisableInputDevices) {
InputControllerEvdev controller(nullptr, nullptr, nullptr);
EXPECT_TRUE(controller.AreInputDevicesEnabled());
auto first_scoped_disable_input_devices = controller.DisableInputDevices();
EXPECT_FALSE(controller.AreInputDevicesEnabled());
EXPECT_FALSE(controller.GetInputDeviceSettings().enable_devices);
auto second_scoped_disable_input_devices = controller.DisableInputDevices();
auto third_scoped_disable_input_devices = controller.DisableInputDevices();
EXPECT_FALSE(controller.AreInputDevicesEnabled());
first_scoped_disable_input_devices.reset();
EXPECT_FALSE(controller.AreInputDevicesEnabled());
third_scoped_disable_input_devices.reset();
EXPECT_FALSE(controller.AreInputDevicesEnabled());
second_scoped_disable_input_devices.reset();
EXPECT_TRUE(controller.AreInputDevicesEnabled());
}
TEST(InputControllerEvdevTest, ScopedDisableInputDevicesCanOutliveController) {
std::unique_ptr<ScopedDisableInputDevices> scoped_disabler;
{
InputControllerEvdev controller(nullptr, nullptr, nullptr);
scoped_disabler = controller.DisableInputDevices();
}
scoped_disabler.reset();
}
}