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

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

Issue 268713013: Move chrome.usb to //extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/api/usb/usb_api.h"
6 #include "chrome/browser/extensions/extension_apitest.h" 5 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/ui/browser.h" 6 #include "chrome/browser/ui/browser.h"
8 #include "content/public/browser/browser_thread.h" 7 #include "content/public/browser/browser_thread.h"
8 #include "extensions/browser/api/usb/usb_api.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
11 11
12 using testing::AnyNumber; 12 using testing::AnyNumber;
13 using testing::_; 13 using testing::_;
14 using testing::Return; 14 using testing::Return;
15 using content::BrowserThread; 15 using content::BrowserThread;
16 using usb_service::UsbConfigDescriptor; 16 using usb_service::UsbConfigDescriptor;
17 using usb_service::UsbDevice; 17 using usb_service::UsbDevice;
18 using usb_service::UsbDeviceHandle; 18 using usb_service::UsbDeviceHandle;
19 using usb_service::UsbEndpointDirection; 19 using usb_service::UsbEndpointDirection;
20 using usb_service::UsbTransferCallback; 20 using usb_service::UsbTransferCallback;
21 21
22 namespace { 22 namespace {
23 23
24 ACTION_TEMPLATE(InvokeUsbTransferCallback, 24 ACTION_TEMPLATE(InvokeUsbTransferCallback,
25 HAS_1_TEMPLATE_PARAMS(int, k), 25 HAS_1_TEMPLATE_PARAMS(int, k),
26 AND_1_VALUE_PARAMS(p1)) { 26 AND_1_VALUE_PARAMS(p1)) {
27 ::std::tr1::get<k>(args).Run(p1, new net::IOBuffer(1), 1); 27 ::std::tr1::get<k>(args).Run(p1, new net::IOBuffer(1), 1);
28 } 28 }
29 29
30 // MSVC erroneously thinks that at least one of the arguments for the transfer 30 // MSVC erroneously thinks that at least one of the arguments for the transfer
31 // methods differ by const or volatility and emits a warning about the old 31 // methods differ by const or volatility and emits a warning about the old
32 // standards-noncompliant behaviour of their compiler. 32 // standards-noncompliant behaviour of their compiler.
33 #if defined(OS_WIN) 33 #if defined(OS_WIN)
34 #pragma warning(push) 34 #pragma warning(push)
35 #pragma warning(disable:4373) 35 #pragma warning(disable : 4373)
36 #endif 36 #endif
37 37
38 class MockUsbDeviceHandle : public UsbDeviceHandle { 38 class MockUsbDeviceHandle : public UsbDeviceHandle {
39 public: 39 public:
40 MockUsbDeviceHandle() : UsbDeviceHandle() {} 40 MockUsbDeviceHandle() : UsbDeviceHandle() {}
41 41
42 MOCK_METHOD0(Close, void()); 42 MOCK_METHOD0(Close, void());
43 43
44 MOCK_METHOD10(ControlTransfer, void(const UsbEndpointDirection direction, 44 MOCK_METHOD10(ControlTransfer,
45 const TransferRequestType request_type, const TransferRecipient recipient, 45 void(const UsbEndpointDirection direction,
46 const uint8 request, const uint16 value, const uint16 index, 46 const TransferRequestType request_type,
47 net::IOBuffer* buffer, const size_t length, const unsigned int timeout, 47 const TransferRecipient recipient,
48 const UsbTransferCallback& callback)); 48 const uint8 request,
49 const uint16 value,
50 const uint16 index,
51 net::IOBuffer* buffer,
52 const size_t length,
53 const unsigned int timeout,
54 const UsbTransferCallback& callback));
49 55
50 MOCK_METHOD6(BulkTransfer, void(const UsbEndpointDirection direction, 56 MOCK_METHOD6(BulkTransfer,
51 const uint8 endpoint, net::IOBuffer* buffer, const size_t length, 57 void(const UsbEndpointDirection direction,
52 const unsigned int timeout, const UsbTransferCallback& callback)); 58 const uint8 endpoint,
59 net::IOBuffer* buffer,
60 const size_t length,
61 const unsigned int timeout,
62 const UsbTransferCallback& callback));
53 63
54 MOCK_METHOD6(InterruptTransfer, void(const UsbEndpointDirection direction, 64 MOCK_METHOD6(InterruptTransfer,
55 const uint8 endpoint, net::IOBuffer* buffer, const size_t length, 65 void(const UsbEndpointDirection direction,
56 const unsigned int timeout, const UsbTransferCallback& callback)); 66 const uint8 endpoint,
67 net::IOBuffer* buffer,
68 const size_t length,
69 const unsigned int timeout,
70 const UsbTransferCallback& callback));
57 71
58 MOCK_METHOD8(IsochronousTransfer, void(const UsbEndpointDirection direction, 72 MOCK_METHOD8(IsochronousTransfer,
59 const uint8 endpoint, net::IOBuffer* buffer, const size_t length, 73 void(const UsbEndpointDirection direction,
60 const unsigned int packets, const unsigned int packet_length, 74 const uint8 endpoint,
61 const unsigned int timeout, const UsbTransferCallback& callback)); 75 net::IOBuffer* buffer,
76 const size_t length,
77 const unsigned int packets,
78 const unsigned int packet_length,
79 const unsigned int timeout,
80 const UsbTransferCallback& callback));
62 81
63 MOCK_METHOD0(ResetDevice, bool()); 82 MOCK_METHOD0(ResetDevice, bool());
64 83
65 void set_device(UsbDevice* device) { device_ = device; } 84 void set_device(UsbDevice* device) { device_ = device; }
66 85
67 protected: 86 protected:
68 virtual ~MockUsbDeviceHandle() {} 87 virtual ~MockUsbDeviceHandle() {}
69 }; 88 };
70 89
71 class MockUsbDevice : public UsbDevice { 90 class MockUsbDevice : public UsbDevice {
72 public: 91 public:
73 explicit MockUsbDevice(MockUsbDeviceHandle* mock_handle) 92 explicit MockUsbDevice(MockUsbDeviceHandle* mock_handle)
74 : UsbDevice(), 93 : UsbDevice(), mock_handle_(mock_handle) {
75 mock_handle_(mock_handle) {
76 mock_handle->set_device(this); 94 mock_handle->set_device(this);
77 } 95 }
78 96
79 virtual scoped_refptr<UsbDeviceHandle> Open() OVERRIDE { 97 virtual scoped_refptr<UsbDeviceHandle> Open() OVERRIDE {
80 return mock_handle_; 98 return mock_handle_;
81 } 99 }
82 100
83 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) OVERRIDE { 101 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) OVERRIDE {
84 EXPECT_TRUE(false) << "Should not be reached"; 102 EXPECT_TRUE(false) << "Should not be reached";
85 return false; 103 return false;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 .WillOnce(Return(scoped_refptr<UsbConfigDescriptor>())); 152 .WillOnce(Return(scoped_refptr<UsbConfigDescriptor>()));
135 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); 153 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber());
136 ASSERT_TRUE(RunExtensionTest("usb/list_interfaces")); 154 ASSERT_TRUE(RunExtensionTest("usb/list_interfaces"));
137 } 155 }
138 156
139 IN_PROC_BROWSER_TEST_F(UsbApiTest, TransferEvent) { 157 IN_PROC_BROWSER_TEST_F(UsbApiTest, TransferEvent) {
140 EXPECT_CALL(*mock_device_handle_.get(), 158 EXPECT_CALL(*mock_device_handle_.get(),
141 ControlTransfer(usb_service::USB_DIRECTION_OUTBOUND, 159 ControlTransfer(usb_service::USB_DIRECTION_OUTBOUND,
142 UsbDeviceHandle::STANDARD, 160 UsbDeviceHandle::STANDARD,
143 UsbDeviceHandle::DEVICE, 161 UsbDeviceHandle::DEVICE,
144 1, 2, 3, _, 1, _, _)) 162 1,
163 2,
164 3,
165 _,
166 1,
167 _,
168 _))
145 .WillOnce( 169 .WillOnce(
146 InvokeUsbTransferCallback<9>(usb_service::USB_TRANSFER_COMPLETED)); 170 InvokeUsbTransferCallback<9>(usb_service::USB_TRANSFER_COMPLETED));
147 EXPECT_CALL(*mock_device_handle_.get(), 171 EXPECT_CALL(*mock_device_handle_.get(),
148 BulkTransfer(usb_service::USB_DIRECTION_OUTBOUND, 1, _, 1, _, _)) 172 BulkTransfer(usb_service::USB_DIRECTION_OUTBOUND, 1, _, 1, _, _))
149 .WillOnce( 173 .WillOnce(
150 InvokeUsbTransferCallback<5>(usb_service::USB_TRANSFER_COMPLETED)); 174 InvokeUsbTransferCallback<5>(usb_service::USB_TRANSFER_COMPLETED));
151 EXPECT_CALL( 175 EXPECT_CALL(
152 *mock_device_handle_.get(), 176 *mock_device_handle_.get(),
153 InterruptTransfer(usb_service::USB_DIRECTION_OUTBOUND, 2, _, 1, _, _)) 177 InterruptTransfer(usb_service::USB_DIRECTION_OUTBOUND, 2, _, 1, _, _))
154 .WillOnce( 178 .WillOnce(
(...skipping 23 matching lines...) Expand all
178 .WillOnce( 202 .WillOnce(
179 InvokeUsbTransferCallback<5>(usb_service::USB_TRANSFER_TIMEOUT)); 203 InvokeUsbTransferCallback<5>(usb_service::USB_TRANSFER_TIMEOUT));
180 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); 204 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber());
181 ASSERT_TRUE(RunExtensionTest("usb/transfer_failure")); 205 ASSERT_TRUE(RunExtensionTest("usb/transfer_failure"));
182 } 206 }
183 207
184 IN_PROC_BROWSER_TEST_F(UsbApiTest, InvalidLengthTransfer) { 208 IN_PROC_BROWSER_TEST_F(UsbApiTest, InvalidLengthTransfer) {
185 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); 209 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber());
186 ASSERT_TRUE(RunExtensionTest("usb/invalid_length_transfer")); 210 ASSERT_TRUE(RunExtensionTest("usb/invalid_length_transfer"));
187 } 211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698