ExtensionSyncService: listen for relevant changes instead of being explicitly called...
[chromium-blink-merge.git] / chrome / browser / chromeos / login / hid_detection_browsertest.cc
bloba64fd8cac9a9b1d0837f9c96c4cb9671240467c6
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.
5 #include "base/bind.h"
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;
21 using testing::_;
23 using InputDeviceInfo = InputServiceLinux::InputDeviceInfo;
25 namespace {
27 void SetUpBluetoothMock(
28 scoped_refptr<
29 testing::NiceMock<device::MockBluetoothAdapter> > mock_adapter,
30 bool is_present) {
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()));
42 } // namespace
44 namespace chromeos {
46 class HidDetectionTest : public OobeBaseTest {
47 public:
48 typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo;
50 HidDetectionTest() : weak_ptr_factory_(this) {
51 InputServiceProxy::SetThreadIdForTesting(content::BrowserThread::UI);
52 HidDetectionTest::InitInputService();
55 ~HidDetectionTest() override {}
57 void InitInputService() {
58 input_service_linux_.reset(new device::FakeInputServiceLinux);
59 InputServiceLinux::SetForTesting(input_service_linux_.get());
62 void SetUpOnMainThread() override {
63 OobeBaseTest::SetUpOnMainThread();
66 void SetUpInProcessBrowserTestFixture() override {
67 OobeBaseTest::SetUpInProcessBrowserTestFixture();
69 mock_adapter_ = new testing::NiceMock<device::MockBluetoothAdapter>();
70 SetUpBluetoothMock(mock_adapter_, true);
73 void AddUsbMouse(const std::string& mouse_id) {
74 InputDeviceInfo mouse;
75 mouse.id = mouse_id;
76 mouse.subsystem = InputDeviceInfo::SUBSYSTEM_INPUT;
77 mouse.type = InputDeviceInfo::TYPE_USB;
78 mouse.is_mouse = true;
79 LOG(ERROR) << input_service_linux_.get();
80 input_service_linux_->AddDeviceForTesting(mouse);
83 void AddUsbKeyboard(const std::string& keyboard_id) {
84 InputDeviceInfo keyboard;
85 keyboard.id = keyboard_id;
86 keyboard.subsystem = InputDeviceInfo::SUBSYSTEM_INPUT;
87 keyboard.type = InputDeviceInfo::TYPE_USB;
88 keyboard.is_keyboard = true;
89 input_service_linux_->AddDeviceForTesting(keyboard);
92 private:
93 scoped_refptr<
94 testing::NiceMock<device::MockBluetoothAdapter> > mock_adapter_;
96 scoped_ptr<device::FakeInputServiceLinux> input_service_linux_;
98 base::WeakPtrFactory<HidDetectionTest> weak_ptr_factory_;
100 DISALLOW_COPY_AND_ASSIGN(HidDetectionTest);
103 class HidDetectionSkipTest : public HidDetectionTest {
104 public:
105 HidDetectionSkipTest() {
106 AddUsbMouse("mouse");
107 AddUsbKeyboard("keyboard");
110 void SetUpOnMainThread() override {
111 HidDetectionTest::SetUpOnMainThread();
115 IN_PROC_BROWSER_TEST_F(HidDetectionTest, NoDevicesConnected) {
116 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_HID_DETECTION).Wait();
119 IN_PROC_BROWSER_TEST_F(HidDetectionSkipTest, BothDevicesPreConnected) {
120 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_NETWORK).Wait();
123 } // namespace chromeos