1 // Copyright 2014 The Chromium 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.
6 #include "base/memory/ref_counted.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/weak_ptr.h"
9 #include "chrome/browser/chromeos/login/test/oobe_base_test.h"
10 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
11 #include "chrome/browser/chromeos/login/ui/oobe_display.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "device/bluetooth/bluetooth_adapter_factory.h"
14 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
15 #include "device/hid/fake_input_service_linux.h"
16 #include "device/hid/input_service_linux.h"
17 #include "testing/gmock/include/gmock/gmock.h"
19 using content::BrowserThread
;
20 using device::InputServiceLinux
;
23 using InputDeviceInfo
= InputServiceLinux::InputDeviceInfo
;
27 void SetUpBluetoothMock(
29 testing::NiceMock
<device::MockBluetoothAdapter
> > mock_adapter
,
31 device::BluetoothAdapterFactory::SetAdapterForTesting(mock_adapter
);
33 EXPECT_CALL(*mock_adapter
, IsPresent())
34 .WillRepeatedly(testing::Return(is_present
));
36 EXPECT_CALL(*mock_adapter
, IsPowered())
37 .WillRepeatedly(testing::Return(true));
38 EXPECT_CALL(*mock_adapter
, GetDevices()).WillRepeatedly(
39 testing::Return(device::BluetoothAdapter::ConstDeviceList()));
46 // Boolean parameter is used to run this test for webview (true) and for
47 // iframe (false) GAIA sign in.
48 class HidDetectionTest
: public OobeBaseTest
,
49 public testing::WithParamInterface
<bool> {
51 typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo
;
53 HidDetectionTest() : weak_ptr_factory_(this) {
54 set_use_webview(GetParam());
55 InputServiceProxy::SetThreadIdForTesting(content::BrowserThread::UI
);
56 HidDetectionTest::InitInputService();
59 ~HidDetectionTest() override
{}
61 void InitInputService() {
62 input_service_linux_
.reset(new device::FakeInputServiceLinux
);
63 InputServiceLinux::SetForTesting(input_service_linux_
.get());
66 void SetUpOnMainThread() override
{
67 OobeBaseTest::SetUpOnMainThread();
70 void SetUpInProcessBrowserTestFixture() override
{
71 OobeBaseTest::SetUpInProcessBrowserTestFixture();
73 mock_adapter_
= new testing::NiceMock
<device::MockBluetoothAdapter
>();
74 SetUpBluetoothMock(mock_adapter_
, true);
77 void AddUsbMouse(const std::string
& mouse_id
) {
78 InputDeviceInfo mouse
;
80 mouse
.subsystem
= InputDeviceInfo::SUBSYSTEM_INPUT
;
81 mouse
.type
= InputDeviceInfo::TYPE_USB
;
82 mouse
.is_mouse
= true;
83 LOG(ERROR
) << input_service_linux_
.get();
84 input_service_linux_
->AddDeviceForTesting(mouse
);
87 void AddUsbKeyboard(const std::string
& keyboard_id
) {
88 InputDeviceInfo keyboard
;
89 keyboard
.id
= keyboard_id
;
90 keyboard
.subsystem
= InputDeviceInfo::SUBSYSTEM_INPUT
;
91 keyboard
.type
= InputDeviceInfo::TYPE_USB
;
92 keyboard
.is_keyboard
= true;
93 input_service_linux_
->AddDeviceForTesting(keyboard
);
98 testing::NiceMock
<device::MockBluetoothAdapter
> > mock_adapter_
;
100 scoped_ptr
<device::FakeInputServiceLinux
> input_service_linux_
;
102 base::WeakPtrFactory
<HidDetectionTest
> weak_ptr_factory_
;
104 DISALLOW_COPY_AND_ASSIGN(HidDetectionTest
);
107 class HidDetectionSkipTest
: public HidDetectionTest
{
109 HidDetectionSkipTest() {
110 AddUsbMouse("mouse");
111 AddUsbKeyboard("keyboard");
114 void SetUpOnMainThread() override
{
115 HidDetectionTest::SetUpOnMainThread();
119 IN_PROC_BROWSER_TEST_P(HidDetectionTest
, NoDevicesConnected
) {
120 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_HID_DETECTION
).Wait();
123 IN_PROC_BROWSER_TEST_P(HidDetectionSkipTest
, BothDevicesPreConnected
) {
124 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_NETWORK
).Wait();
127 INSTANTIATE_TEST_CASE_P(HidDetectionSuite
, HidDetectionTest
, testing::Bool());
128 INSTANTIATE_TEST_CASE_P(HidDetectionSkipSuite
,
129 HidDetectionSkipTest
,
132 } // namespace chromeos