| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/chromeos/device/input_service_test_helper.h" | 5 #include "chrome/browser/chromeos/device/input_service_test_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "chrome/browser/chromeos/device/input_service_proxy.h" | 10 #include "chrome/browser/chromeos/device/input_service_proxy.h" |
| 11 #include "content/public/browser/browser_thread.h" | |
| 12 #include "device/hid/fake_input_service_linux.h" | 11 #include "device/hid/fake_input_service_linux.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 13 |
| 15 using content::BrowserThread; | |
| 16 using device::InputServiceLinux; | 14 using device::InputServiceLinux; |
| 17 using device::FakeInputServiceLinux; | 15 using device::FakeInputServiceLinux; |
| 18 | 16 |
| 19 namespace chromeos { | 17 namespace chromeos { |
| 20 | 18 |
| 21 namespace { | 19 namespace { |
| 22 | 20 |
| 23 void InitInputServiceOnFileThread() { | 21 void InitInputServiceOnInputServiceSequence() { |
| 24 InputServiceLinux::SetForTesting(base::MakeUnique<FakeInputServiceLinux>()); | 22 InputServiceLinux::SetForTesting(base::MakeUnique<FakeInputServiceLinux>()); |
| 25 } | 23 } |
| 26 | 24 |
| 27 void AddDeviceOnFileThread(const InputDeviceInfo& device) { | 25 void AddDeviceOnInputServiceSequence(const InputDeviceInfo& device) { |
| 28 FakeInputServiceLinux* service = | 26 FakeInputServiceLinux* service = |
| 29 static_cast<FakeInputServiceLinux*>(InputServiceLinux::GetInstance()); | 27 static_cast<FakeInputServiceLinux*>(InputServiceLinux::GetInstance()); |
| 30 service->AddDeviceForTesting(device); | 28 service->AddDeviceForTesting(device); |
| 31 } | 29 } |
| 32 | 30 |
| 33 void RemoveDeviceOnFileThread(const std::string& id) { | 31 void RemoveDeviceOnInputServiceSequence(const std::string& id) { |
| 34 FakeInputServiceLinux* service = | 32 FakeInputServiceLinux* service = |
| 35 static_cast<FakeInputServiceLinux*>(InputServiceLinux::GetInstance()); | 33 static_cast<FakeInputServiceLinux*>(InputServiceLinux::GetInstance()); |
| 36 service->RemoveDeviceForTesting(id); | 34 service->RemoveDeviceForTesting(id); |
| 37 } | 35 } |
| 38 | 36 |
| 39 } // namespace | 37 } // namespace |
| 40 | 38 |
| 41 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
| 42 // TestObserver | 40 // TestObserver |
| 43 | 41 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 }; | 109 }; |
| 112 | 110 |
| 113 //////////////////////////////////////////////////////////////////////////////// | 111 //////////////////////////////////////////////////////////////////////////////// |
| 114 // InputServiceTestHelper | 112 // InputServiceTestHelper |
| 115 | 113 |
| 116 // static | 114 // static |
| 117 const char InputServiceTestHelper::kKeyboardId[] = "keyboard"; | 115 const char InputServiceTestHelper::kKeyboardId[] = "keyboard"; |
| 118 const char InputServiceTestHelper::kMouseId[] = "mouse"; | 116 const char InputServiceTestHelper::kMouseId[] = "mouse"; |
| 119 | 117 |
| 120 InputServiceTestHelper::InputServiceTestHelper() : observer_(new TestObserver) { | 118 InputServiceTestHelper::InputServiceTestHelper() : observer_(new TestObserver) { |
| 121 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 119 InputServiceProxy::GetInputServiceTaskRunner()->PostTask( |
| 122 base::Bind(&InitInputServiceOnFileThread)); | 120 FROM_HERE, base::BindOnce(&InitInputServiceOnInputServiceSequence)); |
| 123 } | 121 } |
| 124 | 122 |
| 125 InputServiceTestHelper::~InputServiceTestHelper() {} | 123 InputServiceTestHelper::~InputServiceTestHelper() {} |
| 126 | 124 |
| 127 void InputServiceTestHelper::SetProxy(InputServiceProxy* proxy) { | 125 void InputServiceTestHelper::SetProxy(InputServiceProxy* proxy) { |
| 128 proxy_ = proxy; | 126 proxy_ = proxy; |
| 129 proxy_->AddObserver(observer_.get()); | 127 proxy_->AddObserver(observer_.get()); |
| 130 } | 128 } |
| 131 | 129 |
| 132 void InputServiceTestHelper::ClearProxy() { | 130 void InputServiceTestHelper::ClearProxy() { |
| 133 proxy_->RemoveObserver(observer_.get()); | 131 proxy_->RemoveObserver(observer_.get()); |
| 134 proxy_ = nullptr; | 132 proxy_ = nullptr; |
| 135 } | 133 } |
| 136 | 134 |
| 137 void InputServiceTestHelper::AddDeviceToService(bool is_mouse, | 135 void InputServiceTestHelper::AddDeviceToService(bool is_mouse, |
| 138 InputDeviceInfo::Type type) { | 136 InputDeviceInfo::Type type) { |
| 139 InputDeviceInfo device; | 137 InputDeviceInfo device; |
| 140 device.id = is_mouse ? kMouseId : kKeyboardId; | 138 device.id = is_mouse ? kMouseId : kKeyboardId; |
| 141 device.subsystem = InputDeviceInfo::SUBSYSTEM_INPUT; | 139 device.subsystem = InputDeviceInfo::SUBSYSTEM_INPUT; |
| 142 device.type = type; | 140 device.type = type; |
| 143 device.is_mouse = is_mouse; | 141 device.is_mouse = is_mouse; |
| 144 device.is_keyboard = !is_mouse; | 142 device.is_keyboard = !is_mouse; |
| 145 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 143 InputServiceProxy::GetInputServiceTaskRunner()->PostTask( |
| 146 base::Bind(&AddDeviceOnFileThread, device)); | 144 FROM_HERE, base::BindOnce(&AddDeviceOnInputServiceSequence, device)); |
| 147 observer_->WaitForDeviceAddition(device); | 145 observer_->WaitForDeviceAddition(device); |
| 148 } | 146 } |
| 149 | 147 |
| 150 void InputServiceTestHelper::RemoveDeviceFromService(bool is_mouse) { | 148 void InputServiceTestHelper::RemoveDeviceFromService(bool is_mouse) { |
| 151 std::string id = is_mouse ? kMouseId : kKeyboardId; | 149 std::string id = is_mouse ? kMouseId : kKeyboardId; |
| 152 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 150 InputServiceProxy::GetInputServiceTaskRunner()->PostTask( |
| 153 base::Bind(&RemoveDeviceOnFileThread, id)); | 151 FROM_HERE, base::BindOnce(&RemoveDeviceOnInputServiceSequence, id)); |
| 154 observer_->WaitForDeviceRemoval(id); | 152 observer_->WaitForDeviceRemoval(id); |
| 155 } | 153 } |
| 156 | 154 |
| 157 } // namespace chromeos | 155 } // namespace chromeos |
| OLD | NEW |