| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "device/core/device_client.h" | 14 #include "device/core/device_client.h" |
| 15 #include "device/devices_app/usb/device_impl.h" | 15 #include "device/devices_app/usb/device_impl.h" |
| 16 #include "device/devices_app/usb/device_manager_impl.h" | 16 #include "device/devices_app/usb/device_manager_impl.h" |
| 17 #include "device/devices_app/usb/public/cpp/device_manager_delegate.h" | |
| 18 #include "device/usb/mock_usb_device.h" | 17 #include "device/usb/mock_usb_device.h" |
| 19 #include "device/usb/mock_usb_device_handle.h" | 18 #include "device/usb/mock_usb_device_handle.h" |
| 20 #include "device/usb/mock_usb_service.h" | 19 #include "device/usb/mock_usb_service.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" | 21 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" |
| 23 | 22 |
| 24 using ::testing::Invoke; | 23 using ::testing::Invoke; |
| 25 using ::testing::_; | 24 using ::testing::_; |
| 26 | 25 |
| 27 namespace device { | 26 namespace device { |
| 28 namespace usb { | 27 namespace usb { |
| 29 | 28 |
| 30 namespace { | 29 namespace { |
| 31 | 30 |
| 32 class TestDeviceManagerDelegate : public DeviceManagerDelegate { | 31 class TestPermissionProvider : public PermissionProvider { |
| 33 public: | 32 public: |
| 34 TestDeviceManagerDelegate() {} | 33 TestPermissionProvider(mojo::InterfaceRequest<PermissionProvider> request) |
| 35 ~TestDeviceManagerDelegate() override {} | 34 : binding_(this, request.Pass()) {} |
| 35 ~TestPermissionProvider() override {} |
| 36 |
| 37 void HasDevicePermission( |
| 38 mojo::Array<mojo::String> requested_guids, |
| 39 const HasDevicePermissionCallback& callback) override { |
| 40 // Permission to access all devices granted. |
| 41 callback.Run(requested_guids.Pass()); |
| 42 } |
| 36 | 43 |
| 37 private: | 44 private: |
| 38 // DeviceManagerDelegate implementation: | 45 mojo::StrongBinding<PermissionProvider> binding_; |
| 39 bool IsDeviceAllowed(const DeviceInfo& device_info) override { return true; } | |
| 40 }; | 46 }; |
| 41 | 47 |
| 42 class TestDeviceClient : public DeviceClient { | 48 class TestDeviceClient : public DeviceClient { |
| 43 public: | 49 public: |
| 44 TestDeviceClient() {} | 50 TestDeviceClient() {} |
| 45 ~TestDeviceClient() override {} | 51 ~TestDeviceClient() override {} |
| 46 | 52 |
| 47 MockUsbService& mock_usb_service() { return mock_usb_service_; } | 53 MockUsbService& mock_usb_service() { return mock_usb_service_; } |
| 48 | 54 |
| 49 private: | 55 private: |
| 50 // DeviceClient implementation: | 56 // DeviceClient implementation: |
| 51 UsbService* GetUsbService() override { return &mock_usb_service_; } | 57 UsbService* GetUsbService() override { return &mock_usb_service_; } |
| 52 | 58 |
| 53 MockUsbService mock_usb_service_; | 59 MockUsbService mock_usb_service_; |
| 54 }; | 60 }; |
| 55 | 61 |
| 56 class USBDeviceManagerImplTest : public testing::Test { | 62 class USBDeviceManagerImplTest : public testing::Test { |
| 57 public: | 63 public: |
| 58 USBDeviceManagerImplTest() | 64 USBDeviceManagerImplTest() |
| 59 : device_client_(new TestDeviceClient), | 65 : device_client_(new TestDeviceClient), |
| 60 message_loop_(new base::MessageLoop) {} | 66 message_loop_(new base::MessageLoop) {} |
| 61 ~USBDeviceManagerImplTest() override {} | 67 ~USBDeviceManagerImplTest() override {} |
| 62 | 68 |
| 63 protected: | 69 protected: |
| 64 MockUsbService& mock_usb_service() { | 70 MockUsbService& mock_usb_service() { |
| 65 return device_client_->mock_usb_service(); | 71 return device_client_->mock_usb_service(); |
| 66 } | 72 } |
| 67 | 73 |
| 68 DeviceManagerPtr ConnectToDeviceManager() { | 74 DeviceManagerPtr ConnectToDeviceManager() { |
| 75 PermissionProviderPtr permission_provider; |
| 76 new TestPermissionProvider(mojo::GetProxy(&permission_provider)); |
| 69 DeviceManagerPtr device_manager; | 77 DeviceManagerPtr device_manager; |
| 70 new DeviceManagerImpl( | 78 new DeviceManagerImpl(mojo::GetProxy(&device_manager), |
| 71 mojo::GetProxy(&device_manager), | 79 permission_provider.Pass(), |
| 72 scoped_ptr<DeviceManagerDelegate>(new TestDeviceManagerDelegate), | 80 base::ThreadTaskRunnerHandle::Get()); |
| 73 base::ThreadTaskRunnerHandle::Get()); | |
| 74 return device_manager.Pass(); | 81 return device_manager.Pass(); |
| 75 } | 82 } |
| 76 | 83 |
| 77 private: | 84 private: |
| 78 scoped_ptr<TestDeviceClient> device_client_; | 85 scoped_ptr<TestDeviceClient> device_client_; |
| 79 scoped_ptr<base::MessageLoop> message_loop_; | 86 scoped_ptr<base::MessageLoop> message_loop_; |
| 80 }; | 87 }; |
| 81 | 88 |
| 82 class MockOpenCallback { | 89 class MockOpenCallback { |
| 83 public: | 90 public: |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 base::RunLoop loop; | 281 base::RunLoop loop; |
| 275 device_manager->GetDeviceChanges(base::Bind(&ExpectDeviceChangesAndThen, | 282 device_manager->GetDeviceChanges(base::Bind(&ExpectDeviceChangesAndThen, |
| 276 added_guids, removed_guids, | 283 added_guids, removed_guids, |
| 277 loop.QuitClosure())); | 284 loop.QuitClosure())); |
| 278 loop.Run(); | 285 loop.Run(); |
| 279 } | 286 } |
| 280 } | 287 } |
| 281 | 288 |
| 282 } // namespace usb | 289 } // namespace usb |
| 283 } // namespace device | 290 } // namespace device |
| OLD | NEW |