| 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 "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 120 |
| 121 class UsbApiTest : public ShellApiTest { | 121 class UsbApiTest : public ShellApiTest { |
| 122 public: | 122 public: |
| 123 void SetUpOnMainThread() override { | 123 void SetUpOnMainThread() override { |
| 124 ShellApiTest::SetUpOnMainThread(); | 124 ShellApiTest::SetUpOnMainThread(); |
| 125 | 125 |
| 126 // MockDeviceClient replaces ShellDeviceClient. | 126 // MockDeviceClient replaces ShellDeviceClient. |
| 127 device_client_.reset(new MockDeviceClient()); | 127 device_client_.reset(new MockDeviceClient()); |
| 128 | 128 |
| 129 std::vector<UsbConfigDescriptor> configs; | 129 std::vector<UsbConfigDescriptor> configs; |
| 130 UsbConfigDescriptor config; | 130 configs.emplace_back(1, false, false, 0); |
| 131 config.configuration_value = 1; | 131 configs.emplace_back(2, false, false, 0); |
| 132 configs.push_back(config); | |
| 133 config.configuration_value = 2; | |
| 134 configs.push_back(config); | |
| 135 | 132 |
| 136 mock_device_ = new MockUsbDevice(0, 0, "Test Manufacturer", "Test Device", | 133 mock_device_ = new MockUsbDevice(0, 0, "Test Manufacturer", "Test Device", |
| 137 "ABC123", configs); | 134 "ABC123", configs); |
| 138 mock_device_handle_ = new MockUsbDeviceHandle(mock_device_.get()); | 135 mock_device_handle_ = new MockUsbDeviceHandle(mock_device_.get()); |
| 139 EXPECT_CALL(*mock_device_.get(), Open(_)) | 136 EXPECT_CALL(*mock_device_.get(), Open(_)) |
| 140 .WillRepeatedly(InvokeCallback<0>(mock_device_handle_)); | 137 .WillRepeatedly(InvokeCallback<0>(mock_device_handle_)); |
| 141 device_client_->usb_service()->AddDevice(mock_device_); | 138 device_client_->usb_service()->AddDevice(mock_device_); |
| 142 } | 139 } |
| 143 | 140 |
| 144 protected: | 141 protected: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 161 EXPECT_CALL(*mock_device_handle_.get(), ResetDevice(_)) | 158 EXPECT_CALL(*mock_device_handle_.get(), ResetDevice(_)) |
| 162 .WillOnce(InvokeCallback<0>(true)) | 159 .WillOnce(InvokeCallback<0>(true)) |
| 163 .WillOnce(InvokeCallback<0>(false)); | 160 .WillOnce(InvokeCallback<0>(false)); |
| 164 EXPECT_CALL(*mock_device_handle_.get(), | 161 EXPECT_CALL(*mock_device_handle_.get(), |
| 165 GenericTransfer(device::USB_DIRECTION_OUTBOUND, 2, _, 1, _, _)) | 162 GenericTransfer(device::USB_DIRECTION_OUTBOUND, 2, _, 1, _, _)) |
| 166 .WillOnce(InvokeUsbTransferCallback<5>(device::USB_TRANSFER_COMPLETED)); | 163 .WillOnce(InvokeUsbTransferCallback<5>(device::USB_TRANSFER_COMPLETED)); |
| 167 ASSERT_TRUE(RunAppTest("api_test/usb/reset_device")); | 164 ASSERT_TRUE(RunAppTest("api_test/usb/reset_device")); |
| 168 } | 165 } |
| 169 | 166 |
| 170 IN_PROC_BROWSER_TEST_F(UsbApiTest, SetConfiguration) { | 167 IN_PROC_BROWSER_TEST_F(UsbApiTest, SetConfiguration) { |
| 171 UsbConfigDescriptor config_descriptor; | 168 UsbConfigDescriptor config_descriptor(1, false, false, 0); |
| 172 EXPECT_CALL(*mock_device_handle_.get(), SetConfiguration(1, _)) | 169 EXPECT_CALL(*mock_device_handle_.get(), SetConfiguration(1, _)) |
| 173 .WillOnce(InvokeCallback<1>(true)); | 170 .WillOnce(InvokeCallback<1>(true)); |
| 174 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(1); | 171 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(1); |
| 175 EXPECT_CALL(*mock_device_.get(), GetActiveConfiguration()) | 172 EXPECT_CALL(*mock_device_.get(), GetActiveConfiguration()) |
| 176 .WillOnce(Return(nullptr)) | 173 .WillOnce(Return(nullptr)) |
| 177 .WillOnce(Return(&config_descriptor)); | 174 .WillOnce(Return(&config_descriptor)); |
| 178 ASSERT_TRUE(RunAppTest("api_test/usb/set_configuration")); | 175 ASSERT_TRUE(RunAppTest("api_test/usb/set_configuration")); |
| 179 } | 176 } |
| 180 | 177 |
| 181 IN_PROC_BROWSER_TEST_F(UsbApiTest, ListInterfaces) { | 178 IN_PROC_BROWSER_TEST_F(UsbApiTest, ListInterfaces) { |
| 182 UsbConfigDescriptor config_descriptor; | 179 UsbConfigDescriptor config_descriptor(1, false, false, 0); |
| 183 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(1); | 180 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(1); |
| 184 EXPECT_CALL(*mock_device_.get(), GetActiveConfiguration()) | 181 EXPECT_CALL(*mock_device_.get(), GetActiveConfiguration()) |
| 185 .WillOnce(Return(&config_descriptor)); | 182 .WillOnce(Return(&config_descriptor)); |
| 186 ASSERT_TRUE(RunAppTest("api_test/usb/list_interfaces")); | 183 ASSERT_TRUE(RunAppTest("api_test/usb/list_interfaces")); |
| 187 } | 184 } |
| 188 | 185 |
| 189 IN_PROC_BROWSER_TEST_F(UsbApiTest, TransferEvent) { | 186 IN_PROC_BROWSER_TEST_F(UsbApiTest, TransferEvent) { |
| 190 EXPECT_CALL(*mock_device_handle_.get(), | 187 EXPECT_CALL(*mock_device_handle_.get(), |
| 191 ControlTransfer(device::USB_DIRECTION_OUTBOUND, | 188 ControlTransfer(device::USB_DIRECTION_OUTBOUND, |
| 192 UsbDeviceHandle::STANDARD, | 189 UsbDeviceHandle::STANDARD, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 276 |
| 280 TestExtensionsAPIClient test_api_client; | 277 TestExtensionsAPIClient test_api_client; |
| 281 ASSERT_TRUE(LoadApp("api_test/usb/get_user_selected_devices")); | 278 ASSERT_TRUE(LoadApp("api_test/usb/get_user_selected_devices")); |
| 282 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); | 279 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); |
| 283 | 280 |
| 284 device_client_->usb_service()->RemoveDevice(mock_device_); | 281 device_client_->usb_service()->RemoveDevice(mock_device_); |
| 285 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); | 282 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); |
| 286 } | 283 } |
| 287 | 284 |
| 288 } // namespace extensions | 285 } // namespace extensions |
| OLD | NEW |