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

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

Issue 270323003: Extracted UsbConfigDescriptor, UsbInterfaceDescriptor and helper classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « components/usb_service/usb_interface_impl.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 "components/usb_service/usb_service.h" 7 #include "components/usb_service/usb_service.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/test/test_utils.h" 9 #include "content/public/test/test_utils.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 content::BrowserThread; 17 using content::BrowserThread;
18 using usb_service::UsbConfigDescriptor; 18 using usb_service::UsbConfigDescriptor;
19 using usb_service::UsbDevice; 19 using usb_service::UsbDevice;
20 using usb_service::UsbDeviceHandle; 20 using usb_service::UsbDeviceHandle;
21 using usb_service::UsbEndpointDirection; 21 using usb_service::UsbEndpointDirection;
22 using usb_service::UsbInterfaceDescriptor;
22 using usb_service::UsbService; 23 using usb_service::UsbService;
23 using usb_service::UsbTransferCallback; 24 using usb_service::UsbTransferCallback;
24 25
25 namespace { 26 namespace {
26 27
27 ACTION_TEMPLATE(InvokeUsbTransferCallback, 28 ACTION_TEMPLATE(InvokeUsbTransferCallback,
28 HAS_1_TEMPLATE_PARAMS(int, k), 29 HAS_1_TEMPLATE_PARAMS(int, k),
29 AND_1_VALUE_PARAMS(p1)) { 30 AND_1_VALUE_PARAMS(p1)) {
30 net::IOBuffer* io_buffer = new net::IOBuffer(1); 31 net::IOBuffer* io_buffer = new net::IOBuffer(1);
31 memset(io_buffer->data(), 0, 1); // Avoid uninitialized reads. 32 memset(io_buffer->data(), 0, 1); // Avoid uninitialized reads.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 89
89 void set_device(UsbDevice* device) { device_ = device; } 90 void set_device(UsbDevice* device) { device_ = device; }
90 91
91 protected: 92 protected:
92 virtual ~MockUsbDeviceHandle() {} 93 virtual ~MockUsbDeviceHandle() {}
93 }; 94 };
94 95
95 class MockUsbConfigDescriptor : public UsbConfigDescriptor { 96 class MockUsbConfigDescriptor : public UsbConfigDescriptor {
96 public: 97 public:
97 MOCK_CONST_METHOD0(GetNumInterfaces, size_t()); 98 MOCK_CONST_METHOD0(GetNumInterfaces, size_t());
99 MOCK_CONST_METHOD1(GetInterface,
100 scoped_refptr<const UsbInterfaceDescriptor>(size_t index));
98 101
99 protected: 102 protected:
100 virtual ~MockUsbConfigDescriptor() {} 103 virtual ~MockUsbConfigDescriptor() {}
101 }; 104 };
102 105
103 class MockUsbDevice : public UsbDevice { 106 class MockUsbDevice : public UsbDevice {
104 public: 107 public:
105 explicit MockUsbDevice(MockUsbDeviceHandle* mock_handle) 108 explicit MockUsbDevice(MockUsbDeviceHandle* mock_handle)
106 : UsbDevice(0, 0, 0), mock_handle_(mock_handle) { 109 : UsbDevice(0, 0, 0), mock_handle_(mock_handle) {
107 mock_handle->set_device(this); 110 mock_handle->set_device(this);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 .WillOnce( 271 .WillOnce(
269 InvokeUsbTransferCallback<5>(usb_service::USB_TRANSFER_TIMEOUT)); 272 InvokeUsbTransferCallback<5>(usb_service::USB_TRANSFER_TIMEOUT));
270 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); 273 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber());
271 ASSERT_TRUE(RunExtensionTest("usb/transfer_failure")); 274 ASSERT_TRUE(RunExtensionTest("usb/transfer_failure"));
272 } 275 }
273 276
274 IN_PROC_BROWSER_TEST_F(UsbApiTest, InvalidLengthTransfer) { 277 IN_PROC_BROWSER_TEST_F(UsbApiTest, InvalidLengthTransfer) {
275 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); 278 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber());
276 ASSERT_TRUE(RunExtensionTest("usb/invalid_length_transfer")); 279 ASSERT_TRUE(RunExtensionTest("usb/invalid_length_transfer"));
277 } 280 }
OLDNEW
« no previous file with comments | « components/usb_service/usb_interface_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698