Commit 529188b8 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: adds InputDeviceClientTestApi

It's used for poking at InputDeviceClient. As Chrome/Ash use
DeviceDataManager in classic mode InputDeviceClientTestApi handles
both. That is, if DeviceDataManager exists it pokes at it, otherwise
InputDeviceClient.

BUG=776514
TEST=test only changes

Change-Id: I4e46dbe74dbce4a37d2b4e054b8fec88d4b5a048
Reviewed-on: https://chromium-review.googlesource.com/829713Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524447}
parent b01b47e4
......@@ -1582,6 +1582,7 @@ test("ash_unittests") {
"//device/bluetooth",
"//mojo/edk/system",
"//net:net",
"//services/ui/public/cpp/input_devices:test_support",
"//services/ui/public/interfaces",
"//skia",
"//testing/gmock",
......
......@@ -24,8 +24,8 @@
#include "base/test/simple_test_tick_clock.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_power_manager_client.h"
#include "services/ui/public/cpp/input_devices/input_device_client_test_api.h"
#include "ui/events/devices/stylus_state.h"
#include "ui/events/test/device_data_manager_test_api.h"
namespace ash {
......@@ -199,12 +199,7 @@ class LockScreenNoteDisplayStateHandlerTest : public AshTestBase {
};
TEST_F(LockScreenNoteDisplayStateHandlerTest, EjectWhenScreenOn) {
// ui::test::DeviceDataManagerTestAPI only works in classic ash.
// TODO(tbarzic): Fix this in mus/mash.
if (Shell::GetAshConfig() != Config::CLASSIC)
return;
ui::test::DeviceDataManagerTestAPI devices_test_api;
ui::InputDeviceClientTestApi devices_test_api;
devices_test_api.NotifyObserversStylusStateChanged(ui::StylusState::REMOVED);
base::RunLoop().RunUntilIdle();
......@@ -225,14 +220,9 @@ TEST_F(LockScreenNoteDisplayStateHandlerTest, EjectWhenScreenOn) {
}
TEST_F(LockScreenNoteDisplayStateHandlerTest, EjectWhenScreenOff) {
// ui::test::DeviceDataManagerTestAPI only works in classic ash.
// TODO(tbarzic): Fix this in mus/mash.
if (Shell::GetAshConfig() != Config::CLASSIC)
return;
TurnScreenOffForUserInactivity();
ui::test::DeviceDataManagerTestAPI devices_test_api;
ui::InputDeviceClientTestApi devices_test_api;
devices_test_api.NotifyObserversStylusStateChanged(ui::StylusState::REMOVED);
base::RunLoop().RunUntilIdle();
......@@ -257,11 +247,6 @@ TEST_F(LockScreenNoteDisplayStateHandlerTest, EjectWhenScreenOff) {
TEST_F(LockScreenNoteDisplayStateHandlerTest,
EjectWhenScreenOffAndNoteNotAvailable) {
// ui::test::DeviceDataManagerTestAPI only works in classic ash.
// TODO(tbarzic): Fix this in mus/mash.
if (Shell::GetAshConfig() != Config::CLASSIC)
return;
TurnScreenOffForUserInactivity();
Shell::Get()->tray_action()->UpdateLockScreenNoteState(
......@@ -270,7 +255,7 @@ TEST_F(LockScreenNoteDisplayStateHandlerTest,
EXPECT_FALSE(power_manager_client_->backlights_forced_off());
EXPECT_TRUE(power_manager_observer_->brightness_changes().empty());
ui::test::DeviceDataManagerTestAPI devices_test_api;
ui::InputDeviceClientTestApi devices_test_api;
devices_test_api.NotifyObserversStylusStateChanged(ui::StylusState::REMOVED);
base::RunLoop().RunUntilIdle();
......@@ -297,14 +282,9 @@ TEST_F(LockScreenNoteDisplayStateHandlerTest,
}
TEST_F(LockScreenNoteDisplayStateHandlerTest, TurnScreenOnWhenAppLaunchFails) {
// ui::test::DeviceDataManagerTestAPI only works in classic ash.
// TODO(tbarzic): Fix this in mus/mash.
if (Shell::GetAshConfig() != Config::CLASSIC)
return;
TurnScreenOffForUserInactivity();
ui::test::DeviceDataManagerTestAPI devices_test_api;
ui::InputDeviceClientTestApi devices_test_api;
devices_test_api.NotifyObserversStylusStateChanged(ui::StylusState::REMOVED);
base::RunLoop().RunUntilIdle();
......@@ -333,11 +313,6 @@ TEST_F(LockScreenNoteDisplayStateHandlerTest, TurnScreenOnWhenAppLaunchFails) {
// before lock screen note display state handler requests backlights to be
// forced off (i.e. that backlights are continuosly kept forced off).
TEST_F(LockScreenNoteDisplayStateHandlerTest, EjectWhileScreenForcedOff) {
// ui::test::DeviceDataManagerTestAPI only works in classic ash.
// TODO(tbarzic): Fix this in mus/mash.
if (Shell::GetAshConfig() != Config::CLASSIC)
return;
SimulatePowerButtonPress();
ASSERT_TRUE(power_manager_client_->backlights_forced_off());
......@@ -345,7 +320,7 @@ TEST_F(LockScreenNoteDisplayStateHandlerTest, EjectWhileScreenForcedOff) {
power_manager_observer_->brightness_changes());
power_manager_observer_->ClearBrightnessChanges();
ui::test::DeviceDataManagerTestAPI devices_test_api;
ui::InputDeviceClientTestApi devices_test_api;
devices_test_api.NotifyObserversStylusStateChanged(ui::StylusState::REMOVED);
base::RunLoop().RunUntilIdle();
......@@ -367,14 +342,9 @@ TEST_F(LockScreenNoteDisplayStateHandlerTest, EjectWhileScreenForcedOff) {
}
TEST_F(LockScreenNoteDisplayStateHandlerTest, DisplayNotTurnedOffIndefinitely) {
// ui::test::DeviceDataManagerTestAPI only works in classic ash.
// TODO(tbarzic): Fix this in mus/mash.
if (Shell::GetAshConfig() != Config::CLASSIC)
return;
TurnScreenOffForUserInactivity();
ui::test::DeviceDataManagerTestAPI devices_test_api;
ui::InputDeviceClientTestApi devices_test_api;
devices_test_api.NotifyObserversStylusStateChanged(ui::StylusState::REMOVED);
base::RunLoop().RunUntilIdle();
......@@ -408,11 +378,6 @@ TEST_F(LockScreenNoteDisplayStateHandlerTest, DisplayNotTurnedOffIndefinitely) {
// display configuration to off is still in progress.
TEST_F(LockScreenNoteDisplayStateHandlerTest,
StylusEjectWhileForcingDisplayOff) {
// ui::test::DeviceDataManagerTestAPI only works in classic ash.
// TODO(tbarzic): Fix this in mus/mash.
if (Shell::GetAshConfig() != Config::CLASSIC)
return;
power_manager_client_
->set_enqueue_brightness_changes_on_backlights_forced_off(true);
......@@ -421,7 +386,7 @@ TEST_F(LockScreenNoteDisplayStateHandlerTest,
EXPECT_TRUE(power_manager_observer_->brightness_changes().empty());
EXPECT_EQ(1u, power_manager_client_->pending_brightness_changes().size());
ui::test::DeviceDataManagerTestAPI devices_test_api;
ui::InputDeviceClientTestApi devices_test_api;
devices_test_api.NotifyObserversStylusStateChanged(ui::StylusState::REMOVED);
base::RunLoop().RunUntilIdle();
......@@ -455,11 +420,6 @@ TEST_F(LockScreenNoteDisplayStateHandlerTest,
}
TEST_F(LockScreenNoteDisplayStateHandlerTest, ScreenA11yAlerts) {
// ui::test::DeviceDataManagerTestAPI only works in classic ash.
// TODO(tbarzic): Fix this in mus/mash.
if (Shell::GetAshConfig() != Config::CLASSIC)
return;
TestAccessibilityControllerClient a11y_client;
AccessibilityController* a11y_controller =
Shell::Get()->accessibility_controller();
......@@ -472,7 +432,7 @@ TEST_F(LockScreenNoteDisplayStateHandlerTest, ScreenA11yAlerts) {
EXPECT_EQ(mojom::AccessibilityAlert::SCREEN_OFF,
a11y_client.last_a11y_alert());
ui::test::DeviceDataManagerTestAPI devices_test_api;
ui::InputDeviceClientTestApi devices_test_api;
devices_test_api.NotifyObserversStylusStateChanged(ui::StylusState::REMOVED);
base::RunLoop().RunUntilIdle();
......
......@@ -11,8 +11,8 @@
#include "ash/test/ash_test_base.h"
#include "base/macros.h"
#include "base/test/simple_test_tick_clock.h"
#include "services/ui/public/cpp/input_devices/input_device_client_test_api.h"
#include "ui/events/devices/touchscreen_device.h"
#include "ui/events/test/device_data_manager_test_api.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification.h"
......@@ -184,11 +184,6 @@ TEST_F(PeripheralBatteryNotifierTest, DISABLED_DeviceRemove) {
}
TEST_F(PeripheralBatteryNotifierTest, StylusNotification) {
// DeviceDataManager is nullptr when the config is not classic.
// TODO(sammiequon): Make this work for mash.
if (Shell::GetAshConfig() != Config::CLASSIC)
return;
const std::string kTestStylusBatteryPath =
"/sys/class/power_supply/hid-AAAA:BBBB:CCCC.DDDD-battery";
const std::string kTestStylusName = "test_stylus";
......@@ -199,8 +194,7 @@ TEST_F(PeripheralBatteryNotifierTest, StylusNotification) {
1 /* touch_points */, true /* has_stylus */);
stylus.sys_path = base::FilePath(kTestStylusBatteryPath);
ui::test::DeviceDataManagerTestAPI test_api;
test_api.SetTouchscreenDevices({stylus});
ui::InputDeviceClientTestApi().SetTouchscreenDevices({stylus});
message_center::MessageCenter* message_center =
message_center::MessageCenter::Get();
......
......@@ -55,10 +55,10 @@
#include "extensions/common/api/app_runtime.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/value_builder.h"
#include "services/ui/public/cpp/input_devices/input_device_client_test_api.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window.h"
#include "ui/events/devices/input_device_manager.h"
#include "ui/events/test/device_data_manager_test_api.h"
using ash::mojom::CloseLockScreenNoteReason;
using ash::mojom::LockScreenNoteOrigin;
......@@ -495,8 +495,8 @@ class LockScreenAppStateTest : public BrowserWithTestWindowTest {
void SetStylusEnabled() {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
ash::switches::kAshForceEnableStylusTools);
ui::test::DeviceDataManagerTestAPI devices_test_api;
devices_test_api.NotifyObserversTouchscreenDeviceConfigurationChanged();
ui::InputDeviceClientTestApi()
.NotifyObserversTouchscreenDeviceConfigurationChanged();
}
void InitExtensionSystem(Profile* profile) {
......
......@@ -14,9 +14,12 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/screen.h"
#include "ui/display/test/test_screen.h"
#include "ui/events/test/device_data_manager_test_api.h"
#include "ui/gfx/geometry/size.h"
#if defined(USE_OZONE) || defined(USE_X11)
#include "services/ui/public/cpp/input_devices/input_device_client_test_api.h"
#endif
namespace {
const char kTouchEventFeatureDetectionEnabledHistogramName[] =
......@@ -30,8 +33,9 @@ class ChromeBrowserMainExtraPartsMetricsTest : public testing::Test {
~ChromeBrowserMainExtraPartsMetricsTest() override;
protected:
// Test API wrapping |device_data_manager_|.
ui::test::DeviceDataManagerTestAPI device_data_manager_test_api_;
#if defined(USE_OZONE) || defined(USE_X11)
ui::InputDeviceClientTestApi input_device_client_test_api_;
#endif
private:
// Provides a message loop and allows the use of the task scheduler
......@@ -84,7 +88,7 @@ TEST_F(ChromeBrowserMainExtraPartsMetricsTest,
VerifyTouchEventsEnabledIsRecordedAfterPostBrowserStart) {
base::HistogramTester histogram_tester;
device_data_manager_test_api_.OnDeviceListsComplete();
input_device_client_test_api_.OnDeviceListsComplete();
ChromeBrowserMainExtraPartsMetrics test_target;
......@@ -101,7 +105,7 @@ TEST_F(ChromeBrowserMainExtraPartsMetricsTest,
ChromeBrowserMainExtraPartsMetrics test_target;
test_target.PostBrowserStart();
device_data_manager_test_api_.NotifyObserversDeviceListsComplete();
input_device_client_test_api_.NotifyObserversDeviceListsComplete();
histogram_tester.ExpectTotalCount(
kTouchEventFeatureDetectionEnabledHistogramName, 1);
}
......@@ -114,8 +118,8 @@ TEST_F(ChromeBrowserMainExtraPartsMetricsTest,
ChromeBrowserMainExtraPartsMetrics test_target;
test_target.PostBrowserStart();
device_data_manager_test_api_.NotifyObserversDeviceListsComplete();
device_data_manager_test_api_.NotifyObserversDeviceListsComplete();
input_device_client_test_api_.NotifyObserversDeviceListsComplete();
input_device_client_test_api_.NotifyObserversDeviceListsComplete();
histogram_tester.ExpectTotalCount(
kTouchEventFeatureDetectionEnabledHistogramName, 1);
}
......
......@@ -13,9 +13,9 @@
#include "base/observer_list.h"
#include "chromeos/chromeos_switches.h"
#include "content/public/test/test_web_ui.h"
#include "services/ui/public/cpp/input_devices/input_device_client_test_api.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/devices/input_device.h"
#include "ui/events/test/device_data_manager_test_api.h"
namespace chromeos {
namespace settings {
......@@ -38,7 +38,7 @@ class KeyboardHandlerTest : public testing::Test {
handler_.AllowJavascriptForTesting();
// Make sure that we start out without any keyboards reported.
device_test_api_.SetKeyboardDevices(std::vector<ui::InputDevice>());
input_device_client_test_api_.SetKeyboardDevices({});
}
protected:
......@@ -87,7 +87,7 @@ class KeyboardHandlerTest : public testing::Test {
return has_diamond_key;
}
ui::test::DeviceDataManagerTestAPI device_test_api_;
ui::InputDeviceClientTestApi input_device_client_test_api_;
content::TestWebUI web_ui_;
TestKeyboardHandler handler_;
KeyboardHandler::TestAPI handler_test_api_;
......@@ -116,7 +116,7 @@ TEST_F(KeyboardHandlerTest, ExternalKeyboard) {
// An internal keyboard shouldn't change the defaults.
base::CommandLine::ForCurrentProcess()->AppendSwitch(
chromeos::switches::kHasChromeOSKeyboard);
device_test_api_.SetKeyboardDevices(std::vector<ui::InputDevice>{
input_device_client_test_api_.SetKeyboardDevices(std::vector<ui::InputDevice>{
{1, ui::INPUT_DEVICE_INTERNAL, "internal keyboard"}});
handler_test_api_.Initialize();
EXPECT_FALSE(HasCapsLock());
......@@ -124,15 +124,17 @@ TEST_F(KeyboardHandlerTest, ExternalKeyboard) {
// Simulate an external keyboard being connected. We should assume there's a
// Caps Lock key now.
device_test_api_.SetKeyboardDevices(std::vector<ui::InputDevice>{
input_device_client_test_api_.SetKeyboardDevices(std::vector<ui::InputDevice>{
{1, ui::INPUT_DEVICE_EXTERNAL, "external keyboard"}});
device_test_api_.NotifyObserversKeyboardDeviceConfigurationChanged();
input_device_client_test_api_
.NotifyObserversKeyboardDeviceConfigurationChanged();
EXPECT_TRUE(HasCapsLock());
EXPECT_FALSE(HasDiamondKey());
// Disconnect the external keyboard and check that the key goes away.
device_test_api_.SetKeyboardDevices(std::vector<ui::InputDevice>());
device_test_api_.NotifyObserversKeyboardDeviceConfigurationChanged();
input_device_client_test_api_.SetKeyboardDevices({});
input_device_client_test_api_
.NotifyObserversKeyboardDeviceConfigurationChanged();
EXPECT_FALSE(HasCapsLock());
EXPECT_FALSE(HasDiamondKey());
}
......
......@@ -3073,6 +3073,11 @@ test("unit_tests") {
"//ash/strings",
]
}
if (use_x11 || use_ozone) {
deps += [ "//services/ui/public/cpp/input_devices:test_support" ]
}
if (enable_background_contents) {
sources +=
[ "../browser/background/background_contents_service_unittest.cc" ]
......
......@@ -30,6 +30,24 @@ source_set("input_devices") {
}
}
source_set("test_support") {
sources = [
"input_device_client_test_api.cc",
"input_device_client_test_api.h",
]
deps = [
"//base",
"//services/service_manager/public/cpp",
"//ui/events/devices",
]
public_deps = [
":input_devices",
"//services/ui/public/interfaces/input_devices",
]
}
if (is_chromeos) {
source_set("input_device_controller") {
sources = [
......
......@@ -86,8 +86,7 @@ mojom::InputDeviceObserverMojoPtr InputDeviceClient::GetIntefacePtr() {
void InputDeviceClient::OnKeyboardDeviceConfigurationChanged(
const std::vector<ui::InputDevice>& devices) {
keyboard_devices_ = devices;
for (auto& observer : observers_)
observer.OnKeyboardDeviceConfigurationChanged();
NotifyObserversKeyboardDeviceConfigurationChanged();
}
void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged(
......@@ -103,8 +102,7 @@ void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged(
observer.OnTouchDeviceAssociationChanged();
} else {
are_touchscreen_target_displays_valid_ = false;
for (auto& observer : observers_)
observer.OnTouchscreenDeviceConfigurationChanged();
NotifyObserversTouchscreenDeviceConfigurationChanged();
}
}
......@@ -137,8 +135,7 @@ void InputDeviceClient::OnDeviceListsComplete(
touchscreen_devices_ = touchscreen_devices;
are_touchscreen_target_displays_valid_ =
are_touchscreen_target_displays_valid;
for (auto& observer : observers_)
observer.OnTouchscreenDeviceConfigurationChanged();
NotifyObserversTouchscreenDeviceConfigurationChanged();
}
if (!mouse_devices.empty())
OnMouseDeviceConfigurationChanged(mouse_devices);
......@@ -147,8 +144,7 @@ void InputDeviceClient::OnDeviceListsComplete(
if (!device_lists_complete_) {
device_lists_complete_ = true;
for (auto& observer : observers_)
observer.OnDeviceListsComplete();
NotifyObserversDeviceListsComplete();
}
}
......@@ -157,4 +153,19 @@ void InputDeviceClient::OnStylusStateChanged(StylusState state) {
observer.OnStylusStateChanged(state);
}
void InputDeviceClient::NotifyObserversDeviceListsComplete() {
for (auto& observer : observers_)
observer.OnDeviceListsComplete();
}
void InputDeviceClient::NotifyObserversKeyboardDeviceConfigurationChanged() {
for (auto& observer : observers_)
observer.OnKeyboardDeviceConfigurationChanged();
}
void InputDeviceClient::NotifyObserversTouchscreenDeviceConfigurationChanged() {
for (auto& observer : observers_)
observer.OnTouchscreenDeviceConfigurationChanged();
}
} // namespace ui
......@@ -74,6 +74,12 @@ class InputDeviceClient : public mojom::InputDeviceObserverMojo,
void OnStylusStateChanged(StylusState state) override;
private:
friend class InputDeviceClientTestApi;
void NotifyObserversDeviceListsComplete();
void NotifyObserversKeyboardDeviceConfigurationChanged();
void NotifyObserversTouchscreenDeviceConfigurationChanged();
mojo::Binding<mojom::InputDeviceObserverMojo> binding_;
bool is_input_device_manager_;
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/ui/public/cpp/input_devices/input_device_client_test_api.h"
#include "services/ui/public/cpp/input_devices/input_device_client.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/devices/input_device.h"
#include "ui/events/devices/touchscreen_device.h"
namespace ui {
InputDeviceClientTestApi::InputDeviceClientTestApi() = default;
InputDeviceClientTestApi::~InputDeviceClientTestApi() = default;
void InputDeviceClientTestApi::NotifyObserversDeviceListsComplete() {
if (DeviceDataManager::instance_)
DeviceDataManager::instance_->NotifyObserversDeviceListsComplete();
else
GetInputDeviceClient()->NotifyObserversDeviceListsComplete();
}
void InputDeviceClientTestApi::
NotifyObserversKeyboardDeviceConfigurationChanged() {
if (DeviceDataManager::instance_)
DeviceDataManager::instance_
->NotifyObserversKeyboardDeviceConfigurationChanged();
else
GetInputDeviceClient()->NotifyObserversKeyboardDeviceConfigurationChanged();
}
void InputDeviceClientTestApi::NotifyObserversStylusStateChanged(
StylusState stylus_state) {
if (DeviceDataManager::instance_) {
DeviceDataManager::instance_->NotifyObserversStylusStateChanged(
stylus_state);
} else {
GetInputDeviceClient()->OnStylusStateChanged(stylus_state);
}
}
void InputDeviceClientTestApi::
NotifyObserversTouchscreenDeviceConfigurationChanged() {
if (DeviceDataManager::instance_) {
DeviceDataManager::instance_
->NotifyObserversTouchscreenDeviceConfigurationChanged();
} else {
GetInputDeviceClient()
->NotifyObserversTouchscreenDeviceConfigurationChanged();
}
}
void InputDeviceClientTestApi::OnDeviceListsComplete() {
if (DeviceDataManager::instance_)
DeviceDataManager::instance_->OnDeviceListsComplete();
else
GetInputDeviceClient()->OnDeviceListsComplete({}, {}, {}, {}, false);
}
void InputDeviceClientTestApi::SetKeyboardDevices(
const std::vector<InputDevice>& devices) {
if (DeviceDataManager::instance_)
DeviceDataManager::instance_->keyboard_devices_ = devices;
else
GetInputDeviceClient()->keyboard_devices_ = devices;
}
void InputDeviceClientTestApi::SetTouchscreenDevices(
const std::vector<TouchscreenDevice>& devices) {
if (DeviceDataManager::instance_)
DeviceDataManager::instance_->touchscreen_devices_ = devices;
else
GetInputDeviceClient()->touchscreen_devices_ = devices;
}
InputDeviceClient* InputDeviceClientTestApi::GetInputDeviceClient() {
if (DeviceDataManager::instance_ || !InputDeviceManager::HasInstance())
return nullptr;
return static_cast<InputDeviceClient*>(InputDeviceManager::GetInstance());
}
} // namespace ui
// Copyright 2015 The Chromium Authors. All rights reserved.
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_EVENTS_TEST_DEVICE_DATA_MANAGER_TEST_API_H_
#define UI_EVENTS_TEST_DEVICE_DATA_MANAGER_TEST_API_H_
#ifndef SERVICES_UI_PUBLIC_CPP_INPUT_DEVICES_INPUT_DEVICE_CLIENT_TEST_API_H_
#define SERVICES_UI_PUBLIC_CPP_INPUT_DEVICES_INPUT_DEVICE_CLIENT_TEST_API_H_
#include <memory>
#include <vector>
#include "base/macros.h"
#include "ui/events/devices/events_devices_export.h"
namespace gfx {
class Transform;
}
namespace ui {
class DeviceDataManager;
class InputDeviceClient;
enum class StylusState;
struct InputDevice;
struct TouchscreenDevice;
namespace test {
// Test API class to access internals of the DeviceDataManager class.
class DeviceDataManagerTestAPI {
// Test interfaces for calling private functions of InputDeviceClient. Until
// Chrome OS has been converted to InputDeviceClient this uses DeviceDataManager
// if it exists.
//
// Usage depends upon exactly what you want to do, but often times you will
// configure the set of devices (keyboards and/or touchscreens) and then call
// OnDeviceListsComplete().
class InputDeviceClientTestApi {
public:
// Constructs a test api that provides access to the global DeviceDataManager
// instance that is accessible by DeviceDataManager::GetInstance().
DeviceDataManagerTestAPI();
~DeviceDataManagerTestAPI();
InputDeviceClientTestApi();
~InputDeviceClientTestApi();
// Wrapper functions to DeviceDataManager.
void NotifyObserversTouchscreenDeviceConfigurationChanged();
void NotifyObserversKeyboardDeviceConfigurationChanged();
void NotifyObserversMouseDeviceConfigurationChanged();
void NotifyObserversTouchpadDeviceConfigurationChanged();
void NotifyObserversDeviceListsComplete();
void NotifyObserversKeyboardDeviceConfigurationChanged();
void NotifyObserversStylusStateChanged(StylusState stylus_state);
void NotifyObserversTouchscreenDeviceConfigurationChanged();
void OnDeviceListsComplete();
// Methods for updating DeviceDataManager's device lists. Notify* methods must
// be invoked separately to notify observers after making changes.
void SetTouchscreenDevices(const std::vector<TouchscreenDevice>& devices);
void SetKeyboardDevices(const std::vector<InputDevice>& devices);
void SetMouseDevices(const std::vector<InputDevice>& devices);
void SetTouchpadDevices(const std::vector<InputDevice>& devices);
void SetTouchscreenDevices(const std::vector<TouchscreenDevice>& devices);
void UpdateTouchInfoForDisplay(int64_t target_display_id,
int touch_device_id,
const gfx::Transform& touch_transformer);
InputDeviceClient* GetInputDeviceClient();
private:
DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerTestAPI);
DISALLOW_COPY_AND_ASSIGN(InputDeviceClientTestApi);
};
} // namespace test
} // namespace ui
#endif // UI_EVENTS_TEST_DEVICE_DATA_MANAGER_TEST_API_H_
#endif // SERVICES_UI_PUBLIC_CPP_INPUT_DEVICES_INPUT_DEVICE_CLIENT_TEST_API_H_
......@@ -16,9 +16,5 @@ specific_include_rules = {
],
"touch_transform_controller_unittest.cc": [
"+ui/events/devices/device_data_manager.h",
"+ui/events/test/device_data_manager_test_api.h",
],
"touch_device_manager_test_api.cc": [
"+ui/events/devices/touchscreen_device.h",
],
}
......@@ -291,7 +291,6 @@ static_library("test_support") {
sources = [
"test/cocoa_test_event_utils.h",
"test/cocoa_test_event_utils.mm",
"test/device_data_manager_test_api.h",
"test/event_generator.cc",
"test/event_generator.h",
"test/events_test_utils.cc",
......@@ -355,13 +354,6 @@ static_library("test_support") {
if (use_x11 || ozone_platform_x11) {
deps += [ "//ui/events/x" ]
}
if (use_x11 || use_ozone) {
sources += [ "test/device_data_manager_test_api_impl.cc" ]
deps += [ "//ui/events/devices" ]
} else {
sources += [ "test/device_data_manager_test_api_stub.cc" ]
}
}
if (!is_ios) {
......
......@@ -21,10 +21,8 @@
namespace ui {
namespace test {
class DeviceDataManagerTestAPI;
} // namespace test
class DeviceDataManagerTest;
class InputDeviceClientTestApi;
class InputDeviceEventObserver;
// Keeps track of device mappings and event transformations.
......@@ -87,7 +85,8 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager
void OnStylusStateChanged(StylusState state) override;
private:
friend class test::DeviceDataManagerTestAPI;
friend class DeviceDataManagerTest;
friend class InputDeviceClientTestApi;
void ClearTouchDeviceAssociations();
void UpdateTouchInfoFromTransform(
......
......@@ -12,11 +12,9 @@
#include "ui/events/devices/input_device_event_observer.h"
#include "ui/events/devices/touch_device_transform.h"
#include "ui/events/devices/touchscreen_device.h"
#include "ui/events/test/device_data_manager_test_api.h"
#include "ui/gfx/transform.h"
namespace ui {
namespace {
class DeviceDataManagerTest : public testing::Test {
public:
......@@ -27,12 +25,15 @@ class DeviceDataManagerTest : public testing::Test {
void SetUp() override { DeviceDataManager::CreateInstance(); }
void TearDown() override { DeviceDataManager::DeleteInstance(); }
protected:
void CallOnDeviceListsComplete() {
DeviceDataManager::GetInstance()->OnDeviceListsComplete();
}
private:
DISALLOW_COPY_AND_ASSIGN(DeviceDataManagerTest);
};
} // namespace
TEST_F(DeviceDataManagerTest, DisplayIdUpdated) {
DeviceDataManager* device_data_manager = DeviceDataManager::GetInstance();
std::vector<TouchscreenDevice> touchscreen_devices(1);
......@@ -85,7 +86,7 @@ TEST_F(DeviceDataManagerTest, AreTouchscreenTargetDisplaysValid) {
ScopedObserver<DeviceDataManager, InputDeviceEventObserver> scoped_observer(
&observer);
scoped_observer.Add(device_data_manager);
test::DeviceDataManagerTestAPI().OnDeviceListsComplete();
CallOnDeviceListsComplete();
EXPECT_FALSE(device_data_manager->AreTouchscreenTargetDisplaysValid());
EXPECT_EQ(0, observer.on_touch_device_associations_changed_call_count());
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/events/test/device_data_manager_test_api.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/gfx/transform.h"
namespace ui {
namespace test {
DeviceDataManagerTestAPI::DeviceDataManagerTestAPI() {
}
DeviceDataManagerTestAPI::~DeviceDataManagerTestAPI() {
}
void DeviceDataManagerTestAPI::
NotifyObserversTouchscreenDeviceConfigurationChanged() {
DeviceDataManager::GetInstance()
->NotifyObserversTouchscreenDeviceConfigurationChanged();
}
void DeviceDataManagerTestAPI::
NotifyObserversKeyboardDeviceConfigurationChanged() {
DeviceDataManager::GetInstance()
->NotifyObserversKeyboardDeviceConfigurationChanged();
}
void DeviceDataManagerTestAPI::
NotifyObserversMouseDeviceConfigurationChanged() {
DeviceDataManager::GetInstance()
->NotifyObserversMouseDeviceConfigurationChanged();
}
void DeviceDataManagerTestAPI::
NotifyObserversTouchpadDeviceConfigurationChanged() {
DeviceDataManager::GetInstance()
->NotifyObserversTouchpadDeviceConfigurationChanged();
}
void DeviceDataManagerTestAPI::NotifyObserversDeviceListsComplete() {
DeviceDataManager::GetInstance()->NotifyObserversDeviceListsComplete();
}
void DeviceDataManagerTestAPI::NotifyObserversStylusStateChanged(
StylusState stylus_state) {
DeviceDataManager::GetInstance()->NotifyObserversStylusStateChanged(
stylus_state);
}
void DeviceDataManagerTestAPI::OnDeviceListsComplete() {
DeviceDataManager::GetInstance()->OnDeviceListsComplete();
}
void DeviceDataManagerTestAPI::SetTouchscreenDevices(
const std::vector<TouchscreenDevice>& devices) {
DeviceDataManager::GetInstance()->touchscreen_devices_ = devices;
}
void DeviceDataManagerTestAPI::SetKeyboardDevices(
const std::vector<InputDevice>& devices) {
DeviceDataManager::GetInstance()->keyboard_devices_ = devices;
}
void DeviceDataManagerTestAPI::SetMouseDevices(
const std::vector<InputDevice>& devices) {
DeviceDataManager::GetInstance()->mouse_devices_ = devices;
}
void DeviceDataManagerTestAPI::SetTouchpadDevices(
const std::vector<InputDevice>& devices) {
DeviceDataManager::GetInstance()->touchpad_devices_ = devices;
}
} // namespace test
} // namespace ui
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/events/test/device_data_manager_test_api.h"
#include "base/logging.h"
namespace ui {
namespace test {
DeviceDataManagerTestAPI::DeviceDataManagerTestAPI() {
}
DeviceDataManagerTestAPI::~DeviceDataManagerTestAPI() {
}
void DeviceDataManagerTestAPI::
NotifyObserversTouchscreenDeviceConfigurationChanged() {
NOTREACHED();
}
void DeviceDataManagerTestAPI::
NotifyObserversKeyboardDeviceConfigurationChanged() {
NOTREACHED();
}
void DeviceDataManagerTestAPI::
NotifyObserversMouseDeviceConfigurationChanged() {
NOTREACHED();
}
void DeviceDataManagerTestAPI::
NotifyObserversTouchpadDeviceConfigurationChanged() {
NOTREACHED();
}
void DeviceDataManagerTestAPI::NotifyObserversDeviceListsComplete() {
NOTREACHED();
}
void DeviceDataManagerTestAPI::NotifyObserversStylusStateChanged(
StylusState stylus_state) {
NOTREACHED();
}
void DeviceDataManagerTestAPI::OnDeviceListsComplete() {
NOTREACHED();
}
void DeviceDataManagerTestAPI::SetTouchscreenDevices(
const std::vector<TouchscreenDevice>& devices) {
NOTREACHED();
}
void DeviceDataManagerTestAPI::SetKeyboardDevices(
const std::vector<InputDevice>& devices) {
NOTREACHED();
}
void DeviceDataManagerTestAPI::SetMouseDevices(
const std::vector<InputDevice>& devices) {
NOTREACHED();
}
void DeviceDataManagerTestAPI::SetTouchpadDevices(
const std::vector<InputDevice>& devices) {
NOTREACHED();
}
} // namespace test
} // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment