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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/devtools/device/devtools_android_bridge.h" | 8 #include "chrome/browser/devtools/device/devtools_android_bridge.h" |
9 #include "chrome/browser/devtools/device/usb/android_usb_device.h" | 9 #include "chrome/browser/devtools/device/usb/android_usb_device.h" |
10 #include "chrome/browser/devtools/device/usb/usb_device_provider.h" | 10 #include "chrome/browser/devtools/device/usb/usb_device_provider.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
13 #include "components/usb_service/usb_device.h" | |
14 #include "components/usb_service/usb_device_handle.h" | |
15 #include "components/usb_service/usb_interface.h" | |
16 #include "components/usb_service/usb_service.h" | |
17 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/test/test_utils.h" | 14 #include "content/public/test/test_utils.h" |
| 15 #include "device/usb/usb_device.h" |
| 16 #include "device/usb/usb_device_handle.h" |
| 17 #include "device/usb/usb_interface.h" |
| 18 #include "device/usb/usb_service.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 using content::BrowserThread; | 21 using content::BrowserThread; |
22 using namespace usb_service; | 22 using device::UsbConfigDescriptor; |
| 23 using device::UsbDevice; |
| 24 using device::UsbDeviceHandle; |
| 25 using device::UsbEndpointDescriptor; |
| 26 using device::UsbEndpointDirection; |
| 27 using device::UsbInterfaceDescriptor; |
| 28 using device::UsbInterfaceAltSettingDescriptor; |
| 29 using device::UsbService; |
| 30 using device::UsbSynchronizationType; |
| 31 using device::UsbTransferCallback; |
| 32 using device::UsbTransferType; |
| 33 using device::UsbUsageType; |
23 | 34 |
24 namespace { | 35 namespace { |
25 | 36 |
26 struct AndroidTraits { | 37 struct AndroidTraits { |
27 static const int kClass = 0xff; | 38 static const int kClass = 0xff; |
28 static const int kSubclass = 0x42; | 39 static const int kSubclass = 0x42; |
29 static const int kProtocol = 0x1; | 40 static const int kProtocol = 0x1; |
30 }; | 41 }; |
31 | 42 |
32 struct NonAndroidTraits { | 43 struct NonAndroidTraits { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 virtual size_t GetNumEndpoints() const OVERRIDE { | 151 virtual size_t GetNumEndpoints() const OVERRIDE { |
141 // See IsAndroidInterface function in android_usb_device.cc | 152 // See IsAndroidInterface function in android_usb_device.cc |
142 return 2; | 153 return 2; |
143 } | 154 } |
144 | 155 |
145 virtual scoped_refptr<const UsbEndpointDescriptor> GetEndpoint( | 156 virtual scoped_refptr<const UsbEndpointDescriptor> GetEndpoint( |
146 size_t index) const OVERRIDE { | 157 size_t index) const OVERRIDE { |
147 EXPECT_GT(static_cast<size_t>(2), index); | 158 EXPECT_GT(static_cast<size_t>(2), index); |
148 MockUsbEndpointDescriptor* result = new MockUsbEndpointDescriptor(); | 159 MockUsbEndpointDescriptor* result = new MockUsbEndpointDescriptor(); |
149 result->address_ = index + 1; | 160 result->address_ = index + 1; |
150 result->usb_transfer_type_ = USB_TRANSFER_BULK; | 161 result->usb_transfer_type_ = device::USB_TRANSFER_BULK; |
151 result->direction_ = | 162 result->direction_ = ((index == 0) ? device::USB_DIRECTION_INBOUND |
152 ((index == 0) ? USB_DIRECTION_INBOUND : USB_DIRECTION_OUTBOUND); | 163 : device::USB_DIRECTION_OUTBOUND); |
153 result->maximum_packet_size_ = 1 << 20; // 1Mb maximum packet size | 164 result->maximum_packet_size_ = 1 << 20; // 1Mb maximum packet size |
154 return result; | 165 return result; |
155 } | 166 } |
156 | 167 |
157 virtual int GetInterfaceNumber() const OVERRIDE { return interface_number_; } | 168 virtual int GetInterfaceNumber() const OVERRIDE { return interface_number_; } |
158 | 169 |
159 virtual int GetAlternateSetting() const OVERRIDE { | 170 virtual int GetAlternateSetting() const OVERRIDE { |
160 return alternate_setting_; | 171 return alternate_setting_; |
161 } | 172 } |
162 | 173 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 const size_t length, | 292 const size_t length, |
282 const unsigned int timeout, | 293 const unsigned int timeout, |
283 const UsbTransferCallback& callback) OVERRIDE {} | 294 const UsbTransferCallback& callback) OVERRIDE {} |
284 | 295 |
285 virtual void BulkTransfer(const UsbEndpointDirection direction, | 296 virtual void BulkTransfer(const UsbEndpointDirection direction, |
286 const uint8 endpoint, | 297 const uint8 endpoint, |
287 net::IOBuffer* buffer, | 298 net::IOBuffer* buffer, |
288 const size_t length, | 299 const size_t length, |
289 const unsigned int timeout, | 300 const unsigned int timeout, |
290 const UsbTransferCallback& callback) OVERRIDE { | 301 const UsbTransferCallback& callback) OVERRIDE { |
291 if (direction == USB_DIRECTION_OUTBOUND) { | 302 if (direction == device::USB_DIRECTION_OUTBOUND) { |
292 if (remaining_body_length_ == 0) { | 303 if (remaining_body_length_ == 0) { |
293 std::vector<uint32> header(6); | 304 std::vector<uint32> header(6); |
294 memcpy(&header[0], buffer->data(), length); | 305 memcpy(&header[0], buffer->data(), length); |
295 current_message_ = new AdbMessage(header[0], header[1], header[2], ""); | 306 current_message_ = new AdbMessage(header[0], header[1], header[2], ""); |
296 remaining_body_length_ = header[3]; | 307 remaining_body_length_ = header[3]; |
297 uint32 magic = header[5]; | 308 uint32 magic = header[5]; |
298 if ((current_message_->command ^ 0xffffffff) != magic) { | 309 if ((current_message_->command ^ 0xffffffff) != magic) { |
299 DCHECK(false) << "Header checksum error"; | 310 DCHECK(false) << "Header checksum error"; |
300 return; | 311 return; |
301 } | 312 } |
302 } else { | 313 } else { |
303 DCHECK(current_message_.get()); | 314 DCHECK(current_message_.get()); |
304 current_message_->body += std::string(buffer->data(), length); | 315 current_message_->body += std::string(buffer->data(), length); |
305 remaining_body_length_ -= length; | 316 remaining_body_length_ -= length; |
306 } | 317 } |
307 | 318 |
308 if (remaining_body_length_ == 0) { | 319 if (remaining_body_length_ == 0) { |
309 ProcessIncoming(); | 320 ProcessIncoming(); |
310 } | 321 } |
311 | 322 |
312 base::MessageLoop::current()->PostTask( | 323 base::MessageLoop::current()->PostTask( |
313 FROM_HERE, | 324 FROM_HERE, |
314 base::Bind(callback, | 325 base::Bind(callback, |
315 usb_service::USB_TRANSFER_COMPLETED, | 326 device::USB_TRANSFER_COMPLETED, |
316 scoped_refptr<net::IOBuffer>(), | 327 scoped_refptr<net::IOBuffer>(), |
317 0)); | 328 0)); |
318 | 329 |
319 } else if (direction == USB_DIRECTION_INBOUND) { | 330 } else if (direction == device::USB_DIRECTION_INBOUND) { |
320 queries_.push(Query(callback, make_scoped_refptr(buffer), length)); | 331 queries_.push(Query(callback, make_scoped_refptr(buffer), length)); |
321 ProcessQueries(); | 332 ProcessQueries(); |
322 } | 333 } |
323 } | 334 } |
324 | 335 |
325 template <class D> | 336 template <class D> |
326 void append(D data) { | 337 void append(D data) { |
327 std::copy(reinterpret_cast<char*>(&data), | 338 std::copy(reinterpret_cast<char*>(&data), |
328 (reinterpret_cast<char*>(&data)) + sizeof(D), | 339 (reinterpret_cast<char*>(&data)) + sizeof(D), |
329 std::back_inserter(output_buffer_)); | 340 std::back_inserter(output_buffer_)); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 412 |
402 queries_.pop(); | 413 queries_.pop(); |
403 std::copy(output_buffer_.begin(), | 414 std::copy(output_buffer_.begin(), |
404 output_buffer_.begin() + query.size, | 415 output_buffer_.begin() + query.size, |
405 query.buffer->data()); | 416 query.buffer->data()); |
406 output_buffer_.erase(output_buffer_.begin(), | 417 output_buffer_.erase(output_buffer_.begin(), |
407 output_buffer_.begin() + query.size); | 418 output_buffer_.begin() + query.size); |
408 base::MessageLoop::current()->PostTask( | 419 base::MessageLoop::current()->PostTask( |
409 FROM_HERE, | 420 FROM_HERE, |
410 base::Bind(query.callback, | 421 base::Bind(query.callback, |
411 usb_service::USB_TRANSFER_COMPLETED, | 422 device::USB_TRANSFER_COMPLETED, |
412 query.buffer, | 423 query.buffer, |
413 query.size)); | 424 query.size)); |
414 } | 425 } |
415 | 426 |
416 virtual void InterruptTransfer(const UsbEndpointDirection direction, | 427 virtual void InterruptTransfer(const UsbEndpointDirection direction, |
417 const uint8 endpoint, | 428 const uint8 endpoint, |
418 net::IOBuffer* buffer, | 429 net::IOBuffer* buffer, |
419 const size_t length, | 430 const size_t length, |
420 const unsigned int timeout, | 431 const unsigned int timeout, |
421 const UsbTransferCallback& callback) OVERRIDE { | 432 const UsbTransferCallback& callback) OVERRIDE { |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 runner_->Run(); | 856 runner_->Run(); |
846 EXPECT_EQ(2, listener.invoked_); | 857 EXPECT_EQ(2, listener.invoked_); |
847 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_); | 858 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_); |
848 } | 859 } |
849 | 860 |
850 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) { | 861 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) { |
851 MockCountListenerForCheckingTraits listener(adb_bridge_); | 862 MockCountListenerForCheckingTraits listener(adb_bridge_); |
852 adb_bridge_->AddDeviceCountListener(&listener); | 863 adb_bridge_->AddDeviceCountListener(&listener); |
853 runner_->Run(); | 864 runner_->Run(); |
854 } | 865 } |
OLD | NEW |