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 "chrome/browser/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
6 #include "chrome/browser/ui/browser.h" | 6 #include "chrome/browser/ui/browser.h" |
7 #include "content/public/browser/browser_thread.h" | 7 #include "content/public/browser/browser_thread.h" |
8 #include "content/public/test/test_utils.h" | 8 #include "content/public/test/test_utils.h" |
9 #include "device/usb/usb_service.h" | 9 #include "device/usb/usb_service.h" |
10 #include "extensions/browser/api/usb/usb_api.h" | 10 #include "extensions/browser/api/usb/usb_api.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 void(const UsbEndpointDirection direction, | 80 void(const UsbEndpointDirection direction, |
81 const uint8 endpoint, | 81 const uint8 endpoint, |
82 net::IOBuffer* buffer, | 82 net::IOBuffer* buffer, |
83 const size_t length, | 83 const size_t length, |
84 const unsigned int packets, | 84 const unsigned int packets, |
85 const unsigned int packet_length, | 85 const unsigned int packet_length, |
86 const unsigned int timeout, | 86 const unsigned int timeout, |
87 const UsbTransferCallback& callback)); | 87 const UsbTransferCallback& callback)); |
88 | 88 |
89 MOCK_METHOD0(ResetDevice, bool()); | 89 MOCK_METHOD0(ResetDevice, bool()); |
| 90 MOCK_METHOD2(GetStringDescriptor, bool(uint8_t, base::string16*)); |
90 MOCK_METHOD1(ClaimInterface, bool(const int interface_number)); | 91 MOCK_METHOD1(ClaimInterface, bool(const int interface_number)); |
91 MOCK_METHOD1(ReleaseInterface, bool(const int interface_number)); | 92 MOCK_METHOD1(ReleaseInterface, bool(const int interface_number)); |
92 MOCK_METHOD2(SetInterfaceAlternateSetting, | 93 MOCK_METHOD2(SetInterfaceAlternateSetting, |
93 bool(const int interface_number, const int alternate_setting)); | 94 bool(const int interface_number, const int alternate_setting)); |
94 MOCK_METHOD1(GetManufacturer, bool(base::string16* manufacturer)); | |
95 MOCK_METHOD1(GetProduct, bool(base::string16* product)); | |
96 MOCK_METHOD1(GetSerial, bool(base::string16* serial)); | |
97 | 95 |
98 virtual scoped_refptr<UsbDevice> GetDevice() const OVERRIDE { | 96 virtual scoped_refptr<UsbDevice> GetDevice() const OVERRIDE { |
99 return device_; | 97 return device_; |
100 } | 98 } |
101 | 99 |
102 void set_device(UsbDevice* device) { device_ = device; } | 100 void set_device(UsbDevice* device) { device_ = device; } |
103 | 101 |
104 protected: | 102 protected: |
105 UsbDevice* device_; | 103 UsbDevice* device_; |
106 | 104 |
(...skipping 19 matching lines...) Expand all Loading... |
126 #if defined(OS_CHROMEOS) | 124 #if defined(OS_CHROMEOS) |
127 virtual void RequestUsbAccess( | 125 virtual void RequestUsbAccess( |
128 int interface_id, | 126 int interface_id, |
129 const base::Callback<void(bool success)>& callback) OVERRIDE { | 127 const base::Callback<void(bool success)>& callback) OVERRIDE { |
130 BrowserThread::PostTask( | 128 BrowserThread::PostTask( |
131 BrowserThread::FILE, FROM_HERE, base::Bind(callback, true)); | 129 BrowserThread::FILE, FROM_HERE, base::Bind(callback, true)); |
132 } | 130 } |
133 #endif // OS_CHROMEOS | 131 #endif // OS_CHROMEOS |
134 | 132 |
135 MOCK_METHOD0(GetConfiguration, const UsbConfigDescriptor&()); | 133 MOCK_METHOD0(GetConfiguration, const UsbConfigDescriptor&()); |
| 134 MOCK_METHOD1(GetManufacturer, bool(base::string16* manufacturer)); |
| 135 MOCK_METHOD1(GetProduct, bool(base::string16* product)); |
| 136 MOCK_METHOD1(GetSerialNumber, bool(base::string16* serial_number)); |
136 | 137 |
137 private: | 138 private: |
138 MockUsbDeviceHandle* mock_handle_; | 139 MockUsbDeviceHandle* mock_handle_; |
139 virtual ~MockUsbDevice() {} | 140 virtual ~MockUsbDevice() {} |
140 }; | 141 }; |
141 | 142 |
142 class MockUsbService : public UsbService { | 143 class MockUsbService : public UsbService { |
143 public: | 144 public: |
144 explicit MockUsbService(scoped_refptr<UsbDevice> device) : device_(device) {} | 145 explicit MockUsbService(scoped_refptr<UsbDevice> device) : device_(device) {} |
145 | 146 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 .WillOnce(InvokeUsbTransferCallback<5>(device::USB_TRANSFER_ERROR)) | 264 .WillOnce(InvokeUsbTransferCallback<5>(device::USB_TRANSFER_ERROR)) |
264 .WillOnce(InvokeUsbTransferCallback<5>(device::USB_TRANSFER_TIMEOUT)); | 265 .WillOnce(InvokeUsbTransferCallback<5>(device::USB_TRANSFER_TIMEOUT)); |
265 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); | 266 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); |
266 ASSERT_TRUE(RunExtensionTest("usb/transfer_failure")); | 267 ASSERT_TRUE(RunExtensionTest("usb/transfer_failure")); |
267 } | 268 } |
268 | 269 |
269 IN_PROC_BROWSER_TEST_F(UsbApiTest, InvalidLengthTransfer) { | 270 IN_PROC_BROWSER_TEST_F(UsbApiTest, InvalidLengthTransfer) { |
270 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); | 271 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); |
271 ASSERT_TRUE(RunExtensionTest("usb/invalid_length_transfer")); | 272 ASSERT_TRUE(RunExtensionTest("usb/invalid_length_transfer")); |
272 } | 273 } |
OLD | NEW |