OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 <list> | 5 #include <list> |
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/message_loop/message_loop.h" | |
10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
11 #include "base/test/test_io_thread.h" | 10 #include "base/test/scoped_task_environment.h" |
12 #include "base/threading/thread_task_runner_handle.h" | |
13 #include "device/base/mock_device_client.h" | 11 #include "device/base/mock_device_client.h" |
14 #include "device/hid/hid_connection.h" | 12 #include "device/hid/hid_connection.h" |
15 #include "device/hid/hid_device_filter.h" | 13 #include "device/hid/hid_device_filter.h" |
16 #include "device/hid/mock_hid_service.h" | 14 #include "device/hid/mock_hid_service.h" |
17 #include "device/test/test_device_client.h" | 15 #include "device/test/test_device_client.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "u2f_apdu_command.h" | 18 #include "u2f_apdu_command.h" |
21 #include "u2f_apdu_response.h" | 19 #include "u2f_apdu_response.h" |
22 #include "u2f_hid_device.h" | 20 #include "u2f_hid_device.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 | 156 |
159 private: | 157 private: |
160 std::unique_ptr<U2fApduResponse> response_; | 158 std::unique_ptr<U2fApduResponse> response_; |
161 base::Closure closure_; | 159 base::Closure closure_; |
162 U2fDevice::DeviceCallback callback_; | 160 U2fDevice::DeviceCallback callback_; |
163 base::RunLoop run_loop_; | 161 base::RunLoop run_loop_; |
164 }; | 162 }; |
165 | 163 |
166 class U2fHidDeviceTest : public testing::Test { | 164 class U2fHidDeviceTest : public testing::Test { |
167 public: | 165 public: |
168 void SetUp() override { | 166 U2fHidDeviceTest() |
169 message_loop_.reset(new base::MessageLoopForUI()); | 167 : scoped_task_environment_( |
170 io_thread_.reset(new base::TestIOThread(base::TestIOThread::kAutoStart)); | 168 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} |
171 device_client_.reset( | |
172 new device::TestDeviceClient(io_thread_->task_runner())); | |
173 } | |
174 | 169 |
175 protected: | 170 private: |
176 std::unique_ptr<base::MessageLoopForUI> message_loop_; | 171 base::test::ScopedTaskEnvironment scoped_task_environment_; |
mcasas
2017/05/16 21:24:24
nit: probably const.
| |
177 std::unique_ptr<base::TestIOThread> io_thread_; | 172 TestDeviceClient device_client_; |
178 std::unique_ptr<device::TestDeviceClient> device_client_; | |
179 }; | 173 }; |
180 | 174 |
181 TEST_F(U2fHidDeviceTest, TestHidDeviceVersion) { | 175 TEST_F(U2fHidDeviceTest, TestHidDeviceVersion) { |
182 if (!U2fHidDevice::IsTestEnabled()) | 176 if (!U2fHidDevice::IsTestEnabled()) |
183 return; | 177 return; |
184 | 178 |
185 U2fDeviceEnumerate callback; | 179 U2fDeviceEnumerate callback; |
186 HidService* hid_service = DeviceClient::Get()->GetHidService(); | 180 HidService* hid_service = DeviceClient::Get()->GetHidService(); |
187 hid_service->GetDevices(callback.callback()); | 181 hid_service->GetDevices(callback.callback()); |
188 std::list<std::unique_ptr<U2fHidDevice>>& u2f_devices = | 182 std::list<std::unique_ptr<U2fHidDevice>>& u2f_devices = |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 U2fApduResponse::CreateFromMessage(std::vector<uint8_t>({0x0, 0x0}))); | 303 U2fApduResponse::CreateFromMessage(std::vector<uint8_t>({0x0, 0x0}))); |
310 device->DeviceTransact(U2fApduCommand::CreateVersion(), | 304 device->DeviceTransact(U2fApduCommand::CreateVersion(), |
311 base::Bind(&ResponseCallback, &response3)); | 305 base::Bind(&ResponseCallback, &response3)); |
312 EXPECT_EQ(U2fHidDevice::State::DEVICE_ERROR, device->state_); | 306 EXPECT_EQ(U2fHidDevice::State::DEVICE_ERROR, device->state_); |
313 EXPECT_EQ(nullptr, response1); | 307 EXPECT_EQ(nullptr, response1); |
314 EXPECT_EQ(nullptr, response2); | 308 EXPECT_EQ(nullptr, response2); |
315 EXPECT_EQ(nullptr, response3); | 309 EXPECT_EQ(nullptr, response3); |
316 }; | 310 }; |
317 | 311 |
318 } // namespace device | 312 } // namespace device |
OLD | NEW |