| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <numeric> | 7 #include <numeric> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| 10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
| 12 #include "device/core/mock_device_client.h" | 13 #include "device/core/mock_device_client.h" |
| 13 #include "device/usb/mock_usb_device.h" | 14 #include "device/usb/mock_usb_device.h" |
| 14 #include "device/usb/mock_usb_device_handle.h" | 15 #include "device/usb/mock_usb_device_handle.h" |
| 15 #include "device/usb/mock_usb_service.h" | 16 #include "device/usb/mock_usb_service.h" |
| 16 #include "extensions/browser/api/device_permissions_prompt.h" | 17 #include "extensions/browser/api/device_permissions_prompt.h" |
| 17 #include "extensions/browser/api/usb/usb_api.h" | 18 #include "extensions/browser/api/usb/usb_api.h" |
| 18 #include "extensions/shell/browser/shell_extensions_api_client.h" | 19 #include "extensions/shell/browser/shell_extensions_api_client.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 106 } |
| 106 } | 107 } |
| 107 prompt()->Dismissed(); | 108 prompt()->Dismissed(); |
| 108 } | 109 } |
| 109 }; | 110 }; |
| 110 | 111 |
| 111 class TestExtensionsAPIClient : public ShellExtensionsAPIClient { | 112 class TestExtensionsAPIClient : public ShellExtensionsAPIClient { |
| 112 public: | 113 public: |
| 113 TestExtensionsAPIClient() : ShellExtensionsAPIClient() {} | 114 TestExtensionsAPIClient() : ShellExtensionsAPIClient() {} |
| 114 | 115 |
| 115 scoped_ptr<DevicePermissionsPrompt> CreateDevicePermissionsPrompt( | 116 std::unique_ptr<DevicePermissionsPrompt> CreateDevicePermissionsPrompt( |
| 116 content::WebContents* web_contents) const override { | 117 content::WebContents* web_contents) const override { |
| 117 return make_scoped_ptr(new TestDevicePermissionsPrompt(web_contents)); | 118 return base::WrapUnique(new TestDevicePermissionsPrompt(web_contents)); |
| 118 } | 119 } |
| 119 }; | 120 }; |
| 120 | 121 |
| 121 class UsbApiTest : public ShellApiTest { | 122 class UsbApiTest : public ShellApiTest { |
| 122 public: | 123 public: |
| 123 void SetUpOnMainThread() override { | 124 void SetUpOnMainThread() override { |
| 124 ShellApiTest::SetUpOnMainThread(); | 125 ShellApiTest::SetUpOnMainThread(); |
| 125 | 126 |
| 126 // MockDeviceClient replaces ShellDeviceClient. | 127 // MockDeviceClient replaces ShellDeviceClient. |
| 127 device_client_.reset(new MockDeviceClient()); | 128 device_client_.reset(new MockDeviceClient()); |
| 128 | 129 |
| 129 std::vector<UsbConfigDescriptor> configs; | 130 std::vector<UsbConfigDescriptor> configs; |
| 130 configs.emplace_back(1, false, false, 0); | 131 configs.emplace_back(1, false, false, 0); |
| 131 configs.emplace_back(2, false, false, 0); | 132 configs.emplace_back(2, false, false, 0); |
| 132 | 133 |
| 133 mock_device_ = new MockUsbDevice(0, 0, "Test Manufacturer", "Test Device", | 134 mock_device_ = new MockUsbDevice(0, 0, "Test Manufacturer", "Test Device", |
| 134 "ABC123", configs); | 135 "ABC123", configs); |
| 135 mock_device_handle_ = new MockUsbDeviceHandle(mock_device_.get()); | 136 mock_device_handle_ = new MockUsbDeviceHandle(mock_device_.get()); |
| 136 EXPECT_CALL(*mock_device_.get(), Open(_)) | 137 EXPECT_CALL(*mock_device_.get(), Open(_)) |
| 137 .WillRepeatedly(InvokeCallback<0>(mock_device_handle_)); | 138 .WillRepeatedly(InvokeCallback<0>(mock_device_handle_)); |
| 138 device_client_->usb_service()->AddDevice(mock_device_); | 139 device_client_->usb_service()->AddDevice(mock_device_); |
| 139 } | 140 } |
| 140 | 141 |
| 141 protected: | 142 protected: |
| 142 scoped_refptr<MockUsbDeviceHandle> mock_device_handle_; | 143 scoped_refptr<MockUsbDeviceHandle> mock_device_handle_; |
| 143 scoped_refptr<MockUsbDevice> mock_device_; | 144 scoped_refptr<MockUsbDevice> mock_device_; |
| 144 scoped_ptr<MockDeviceClient> device_client_; | 145 std::unique_ptr<MockDeviceClient> device_client_; |
| 145 }; | 146 }; |
| 146 | 147 |
| 147 } // namespace | 148 } // namespace |
| 148 | 149 |
| 149 IN_PROC_BROWSER_TEST_F(UsbApiTest, DeviceHandling) { | 150 IN_PROC_BROWSER_TEST_F(UsbApiTest, DeviceHandling) { |
| 150 EXPECT_CALL(*mock_device_.get(), GetActiveConfiguration()) | 151 EXPECT_CALL(*mock_device_.get(), GetActiveConfiguration()) |
| 151 .WillOnce(Return(&mock_device_->configurations()[0])); | 152 .WillOnce(Return(&mock_device_->configurations()[0])); |
| 152 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(2); | 153 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(2); |
| 153 ASSERT_TRUE(RunAppTest("api_test/usb/device_handling")); | 154 ASSERT_TRUE(RunAppTest("api_test/usb/device_handling")); |
| 154 } | 155 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 277 |
| 277 TestExtensionsAPIClient test_api_client; | 278 TestExtensionsAPIClient test_api_client; |
| 278 ASSERT_TRUE(LoadApp("api_test/usb/get_user_selected_devices")); | 279 ASSERT_TRUE(LoadApp("api_test/usb/get_user_selected_devices")); |
| 279 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); | 280 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); |
| 280 | 281 |
| 281 device_client_->usb_service()->RemoveDevice(mock_device_); | 282 device_client_->usb_service()->RemoveDevice(mock_device_); |
| 282 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); | 283 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); |
| 283 } | 284 } |
| 284 | 285 |
| 285 } // namespace extensions | 286 } // namespace extensions |
| OLD | NEW |