Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: extensions/browser/api/usb/usb_apitest.cc

Issue 567003002: Revert of Convert device::UsbConfigDescriptor and friends to structs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/api/usb/usb_api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 13
14 using testing::AnyNumber; 14 using testing::AnyNumber;
15 using testing::_; 15 using testing::_;
16 using testing::Return; 16 using testing::Return;
17 using testing::ReturnRef;
18 using content::BrowserThread; 17 using content::BrowserThread;
19 using device::UsbConfigDescriptor; 18 using device::UsbConfigDescriptor;
20 using device::UsbDevice; 19 using device::UsbDevice;
21 using device::UsbDeviceHandle; 20 using device::UsbDeviceHandle;
22 using device::UsbEndpointDirection; 21 using device::UsbEndpointDirection;
23 using device::UsbInterfaceDescriptor; 22 using device::UsbInterfaceDescriptor;
24 using device::UsbService; 23 using device::UsbService;
25 using device::UsbTransferCallback; 24 using device::UsbTransferCallback;
26 25
27 namespace { 26 namespace {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 99 }
101 100
102 void set_device(UsbDevice* device) { device_ = device; } 101 void set_device(UsbDevice* device) { device_ = device; }
103 102
104 protected: 103 protected:
105 UsbDevice* device_; 104 UsbDevice* device_;
106 105
107 virtual ~MockUsbDeviceHandle() {} 106 virtual ~MockUsbDeviceHandle() {}
108 }; 107 };
109 108
109 class MockUsbConfigDescriptor : public UsbConfigDescriptor {
110 public:
111 MOCK_CONST_METHOD0(GetNumInterfaces, size_t());
112 MOCK_CONST_METHOD1(GetInterface,
113 scoped_refptr<const UsbInterfaceDescriptor>(size_t index));
114
115 protected:
116 virtual ~MockUsbConfigDescriptor() {}
117 };
118
110 class MockUsbDevice : public UsbDevice { 119 class MockUsbDevice : public UsbDevice {
111 public: 120 public:
112 explicit MockUsbDevice(MockUsbDeviceHandle* mock_handle) 121 explicit MockUsbDevice(MockUsbDeviceHandle* mock_handle)
113 : UsbDevice(0, 0, 0), mock_handle_(mock_handle) { 122 : UsbDevice(0, 0, 0), mock_handle_(mock_handle) {
114 mock_handle->set_device(this); 123 mock_handle->set_device(this);
115 } 124 }
116 125
117 virtual scoped_refptr<UsbDeviceHandle> Open() OVERRIDE { 126 virtual scoped_refptr<UsbDeviceHandle> Open() OVERRIDE {
118 return mock_handle_; 127 return mock_handle_;
119 } 128 }
120 129
121 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) OVERRIDE { 130 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) OVERRIDE {
122 EXPECT_TRUE(false) << "Should not be reached"; 131 EXPECT_TRUE(false) << "Should not be reached";
123 return false; 132 return false;
124 } 133 }
125 134
126 #if defined(OS_CHROMEOS) 135 #if defined(OS_CHROMEOS)
127 virtual void RequestUsbAccess( 136 virtual void RequestUsbAccess(
128 int interface_id, 137 int interface_id,
129 const base::Callback<void(bool success)>& callback) OVERRIDE { 138 const base::Callback<void(bool success)>& callback) OVERRIDE {
130 BrowserThread::PostTask( 139 BrowserThread::PostTask(
131 BrowserThread::FILE, FROM_HERE, base::Bind(callback, true)); 140 BrowserThread::FILE, FROM_HERE, base::Bind(callback, true));
132 } 141 }
133 #endif // OS_CHROMEOS 142 #endif // OS_CHROMEOS
134 143
135 MOCK_METHOD0(GetConfiguration, const UsbConfigDescriptor&()); 144 MOCK_METHOD0(ListInterfaces, scoped_refptr<UsbConfigDescriptor>());
136 145
137 private: 146 private:
138 MockUsbDeviceHandle* mock_handle_; 147 MockUsbDeviceHandle* mock_handle_;
139 virtual ~MockUsbDevice() {} 148 virtual ~MockUsbDevice() {}
140 }; 149 };
141 150
142 class MockUsbService : public UsbService { 151 class MockUsbService : public UsbService {
143 public: 152 public:
144 explicit MockUsbService(scoped_refptr<UsbDevice> device) : device_(device) {} 153 explicit MockUsbService(scoped_refptr<UsbDevice> device) : device_(device) {}
145 154
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 EXPECT_CALL(*mock_device_handle_.get(), ResetDevice()) 218 EXPECT_CALL(*mock_device_handle_.get(), ResetDevice())
210 .WillOnce(Return(true)) 219 .WillOnce(Return(true))
211 .WillOnce(Return(false)); 220 .WillOnce(Return(false));
212 EXPECT_CALL(*mock_device_handle_.get(), 221 EXPECT_CALL(*mock_device_handle_.get(),
213 InterruptTransfer(device::USB_DIRECTION_OUTBOUND, 2, _, 1, _, _)) 222 InterruptTransfer(device::USB_DIRECTION_OUTBOUND, 2, _, 1, _, _))
214 .WillOnce(InvokeUsbTransferCallback<5>(device::USB_TRANSFER_COMPLETED)); 223 .WillOnce(InvokeUsbTransferCallback<5>(device::USB_TRANSFER_COMPLETED));
215 ASSERT_TRUE(RunExtensionTest("usb/reset_device")); 224 ASSERT_TRUE(RunExtensionTest("usb/reset_device"));
216 } 225 }
217 226
218 IN_PROC_BROWSER_TEST_F(UsbApiTest, ListInterfaces) { 227 IN_PROC_BROWSER_TEST_F(UsbApiTest, ListInterfaces) {
219 UsbConfigDescriptor config_descriptor; 228 scoped_refptr<MockUsbConfigDescriptor> mock_descriptor =
229 new MockUsbConfigDescriptor();
220 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); 230 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber());
221 EXPECT_CALL(*mock_device_.get(), GetConfiguration()) 231 EXPECT_CALL(*mock_descriptor.get(), GetNumInterfaces()).WillOnce(Return(0));
222 .WillOnce(ReturnRef(config_descriptor)); 232 EXPECT_CALL(*mock_device_.get(), ListInterfaces())
233 .WillOnce(Return(mock_descriptor));
223 ASSERT_TRUE(RunExtensionTest("usb/list_interfaces")); 234 ASSERT_TRUE(RunExtensionTest("usb/list_interfaces"));
224 } 235 }
225 236
226 IN_PROC_BROWSER_TEST_F(UsbApiTest, TransferEvent) { 237 IN_PROC_BROWSER_TEST_F(UsbApiTest, TransferEvent) {
227 EXPECT_CALL(*mock_device_handle_.get(), 238 EXPECT_CALL(*mock_device_handle_.get(),
228 ControlTransfer(device::USB_DIRECTION_OUTBOUND, 239 ControlTransfer(device::USB_DIRECTION_OUTBOUND,
229 UsbDeviceHandle::STANDARD, 240 UsbDeviceHandle::STANDARD,
230 UsbDeviceHandle::DEVICE, 241 UsbDeviceHandle::DEVICE,
231 1, 242 1,
232 2, 243 2,
(...skipping 30 matching lines...) Expand all
263 .WillOnce(InvokeUsbTransferCallback<5>(device::USB_TRANSFER_ERROR)) 274 .WillOnce(InvokeUsbTransferCallback<5>(device::USB_TRANSFER_ERROR))
264 .WillOnce(InvokeUsbTransferCallback<5>(device::USB_TRANSFER_TIMEOUT)); 275 .WillOnce(InvokeUsbTransferCallback<5>(device::USB_TRANSFER_TIMEOUT));
265 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); 276 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber());
266 ASSERT_TRUE(RunExtensionTest("usb/transfer_failure")); 277 ASSERT_TRUE(RunExtensionTest("usb/transfer_failure"));
267 } 278 }
268 279
269 IN_PROC_BROWSER_TEST_F(UsbApiTest, InvalidLengthTransfer) { 280 IN_PROC_BROWSER_TEST_F(UsbApiTest, InvalidLengthTransfer) {
270 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); 281 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber());
271 ASSERT_TRUE(RunExtensionTest("usb/invalid_length_transfer")); 282 ASSERT_TRUE(RunExtensionTest("usb/invalid_length_transfer"));
272 } 283 }
OLDNEW
« no previous file with comments | « extensions/browser/api/usb/usb_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698