| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 11 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" | 12 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" |
| 12 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" | 13 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" |
| 13 #include "chrome/browser/ui/webui/chromeos/login/oobe_screen.h" | 14 #include "chrome/browser/ui/webui/chromeos/login/oobe_screen.h" |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 #include "device/bluetooth/bluetooth_adapter_factory.h" | 16 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 16 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 17 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 17 #include "device/hid/fake_input_service_linux.h" | 18 #include "device/hid/fake_input_service_linux.h" |
| 18 #include "device/hid/input_service_linux.h" | 19 #include "device/hid/input_service_linux.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo; | 51 typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo; |
| 51 | 52 |
| 52 HidDetectionTest() : weak_ptr_factory_(this) { | 53 HidDetectionTest() : weak_ptr_factory_(this) { |
| 53 InputServiceProxy::SetThreadIdForTesting(content::BrowserThread::UI); | 54 InputServiceProxy::SetThreadIdForTesting(content::BrowserThread::UI); |
| 54 HidDetectionTest::InitInputService(); | 55 HidDetectionTest::InitInputService(); |
| 55 } | 56 } |
| 56 | 57 |
| 57 ~HidDetectionTest() override {} | 58 ~HidDetectionTest() override {} |
| 58 | 59 |
| 59 void InitInputService() { | 60 void InitInputService() { |
| 60 input_service_linux_.reset(new device::FakeInputServiceLinux); | 61 InputServiceLinux::SetForTesting( |
| 61 InputServiceLinux::SetForTesting(input_service_linux_.get()); | 62 base::MakeUnique<device::FakeInputServiceLinux>()); |
| 62 } | 63 } |
| 63 | 64 |
| 64 void SetUpOnMainThread() override { | 65 void SetUpOnMainThread() override { |
| 65 OobeBaseTest::SetUpOnMainThread(); | 66 OobeBaseTest::SetUpOnMainThread(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void SetUpInProcessBrowserTestFixture() override { | 69 void SetUpInProcessBrowserTestFixture() override { |
| 69 OobeBaseTest::SetUpInProcessBrowserTestFixture(); | 70 OobeBaseTest::SetUpInProcessBrowserTestFixture(); |
| 70 | 71 |
| 71 mock_adapter_ = new testing::NiceMock<device::MockBluetoothAdapter>(); | 72 mock_adapter_ = new testing::NiceMock<device::MockBluetoothAdapter>(); |
| 72 SetUpBluetoothMock(mock_adapter_, true); | 73 SetUpBluetoothMock(mock_adapter_, true); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void AddUsbMouse(const std::string& mouse_id) { | 76 void AddUsbMouse(const std::string& mouse_id) { |
| 76 InputDeviceInfo mouse; | 77 InputDeviceInfo mouse; |
| 77 mouse.id = mouse_id; | 78 mouse.id = mouse_id; |
| 78 mouse.subsystem = InputDeviceInfo::SUBSYSTEM_INPUT; | 79 mouse.subsystem = InputDeviceInfo::SUBSYSTEM_INPUT; |
| 79 mouse.type = InputDeviceInfo::TYPE_USB; | 80 mouse.type = InputDeviceInfo::TYPE_USB; |
| 80 mouse.is_mouse = true; | 81 mouse.is_mouse = true; |
| 81 LOG(ERROR) << input_service_linux_.get(); | 82 AddDeviceForTesting(mouse); |
| 82 input_service_linux_->AddDeviceForTesting(mouse); | |
| 83 } | 83 } |
| 84 | 84 |
| 85 void AddUsbKeyboard(const std::string& keyboard_id) { | 85 void AddUsbKeyboard(const std::string& keyboard_id) { |
| 86 InputDeviceInfo keyboard; | 86 InputDeviceInfo keyboard; |
| 87 keyboard.id = keyboard_id; | 87 keyboard.id = keyboard_id; |
| 88 keyboard.subsystem = InputDeviceInfo::SUBSYSTEM_INPUT; | 88 keyboard.subsystem = InputDeviceInfo::SUBSYSTEM_INPUT; |
| 89 keyboard.type = InputDeviceInfo::TYPE_USB; | 89 keyboard.type = InputDeviceInfo::TYPE_USB; |
| 90 keyboard.is_keyboard = true; | 90 keyboard.is_keyboard = true; |
| 91 input_service_linux_->AddDeviceForTesting(keyboard); | 91 AddDeviceForTesting(keyboard); |
| 92 } | 92 } |
| 93 | 93 |
| 94 private: | 94 private: |
| 95 void AddDeviceForTesting(const InputDeviceInfo& info) { |
| 96 static_cast<device::FakeInputServiceLinux*>( |
| 97 device::InputServiceLinux::GetInstance()) |
| 98 ->AddDeviceForTesting(info); |
| 99 } |
| 100 |
| 95 scoped_refptr< | 101 scoped_refptr< |
| 96 testing::NiceMock<device::MockBluetoothAdapter> > mock_adapter_; | 102 testing::NiceMock<device::MockBluetoothAdapter> > mock_adapter_; |
| 97 | 103 |
| 98 std::unique_ptr<device::FakeInputServiceLinux> input_service_linux_; | |
| 99 | |
| 100 base::WeakPtrFactory<HidDetectionTest> weak_ptr_factory_; | 104 base::WeakPtrFactory<HidDetectionTest> weak_ptr_factory_; |
| 101 | 105 |
| 102 DISALLOW_COPY_AND_ASSIGN(HidDetectionTest); | 106 DISALLOW_COPY_AND_ASSIGN(HidDetectionTest); |
| 103 }; | 107 }; |
| 104 | 108 |
| 105 class HidDetectionSkipTest : public HidDetectionTest { | 109 class HidDetectionSkipTest : public HidDetectionTest { |
| 106 public: | 110 public: |
| 107 HidDetectionSkipTest() { | 111 HidDetectionSkipTest() { |
| 108 AddUsbMouse("mouse"); | 112 AddUsbMouse("mouse"); |
| 109 AddUsbKeyboard("keyboard"); | 113 AddUsbKeyboard("keyboard"); |
| 110 } | 114 } |
| 111 | 115 |
| 112 void SetUpOnMainThread() override { | 116 void SetUpOnMainThread() override { |
| 113 HidDetectionTest::SetUpOnMainThread(); | 117 HidDetectionTest::SetUpOnMainThread(); |
| 114 } | 118 } |
| 115 }; | 119 }; |
| 116 | 120 |
| 117 IN_PROC_BROWSER_TEST_F(HidDetectionTest, NoDevicesConnected) { | 121 IN_PROC_BROWSER_TEST_F(HidDetectionTest, NoDevicesConnected) { |
| 118 OobeScreenWaiter(OobeScreen::SCREEN_OOBE_HID_DETECTION).Wait(); | 122 OobeScreenWaiter(OobeScreen::SCREEN_OOBE_HID_DETECTION).Wait(); |
| 119 } | 123 } |
| 120 | 124 |
| 121 IN_PROC_BROWSER_TEST_F(HidDetectionSkipTest, BothDevicesPreConnected) { | 125 IN_PROC_BROWSER_TEST_F(HidDetectionSkipTest, BothDevicesPreConnected) { |
| 122 OobeScreenWaiter(OobeScreen::SCREEN_OOBE_NETWORK).Wait(); | 126 OobeScreenWaiter(OobeScreen::SCREEN_OOBE_NETWORK).Wait(); |
| 123 } | 127 } |
| 124 | 128 |
| 125 } // namespace chromeos | 129 } // namespace chromeos |
| OLD | NEW |