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 "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 ::std::tr1::get<k>(args).Run(p1, new net::IOBuffer(1), 1); | 31 ::std::tr1::get<k>(args).Run(p1, new net::IOBuffer(1), 1); |
31 } | 32 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 87 |
87 void set_device(UsbDevice* device) { device_ = device; } | 88 void set_device(UsbDevice* device) { device_ = device; } |
88 | 89 |
89 protected: | 90 protected: |
90 virtual ~MockUsbDeviceHandle() {} | 91 virtual ~MockUsbDeviceHandle() {} |
91 }; | 92 }; |
92 | 93 |
93 class MockUsbConfigDescriptor : public UsbConfigDescriptor { | 94 class MockUsbConfigDescriptor : public UsbConfigDescriptor { |
94 public: | 95 public: |
95 MOCK_CONST_METHOD0(GetNumInterfaces, size_t()); | 96 MOCK_CONST_METHOD0(GetNumInterfaces, size_t()); |
| 97 MOCK_CONST_METHOD1(GetInterface, |
| 98 scoped_refptr<const UsbInterfaceDescriptor>(size_t index)); |
96 | 99 |
97 protected: | 100 protected: |
98 virtual ~MockUsbConfigDescriptor() {} | 101 virtual ~MockUsbConfigDescriptor() {} |
99 }; | 102 }; |
100 | 103 |
101 class MockUsbDevice : public UsbDevice { | 104 class MockUsbDevice : public UsbDevice { |
102 public: | 105 public: |
103 explicit MockUsbDevice(MockUsbDeviceHandle* mock_handle) | 106 explicit MockUsbDevice(MockUsbDeviceHandle* mock_handle) |
104 : UsbDevice(0, 0, 0), mock_handle_(mock_handle) { | 107 : UsbDevice(0, 0, 0), mock_handle_(mock_handle) { |
105 mock_handle->set_device(this); | 108 mock_handle->set_device(this); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 .WillOnce( | 269 .WillOnce( |
267 InvokeUsbTransferCallback<5>(usb_service::USB_TRANSFER_TIMEOUT)); | 270 InvokeUsbTransferCallback<5>(usb_service::USB_TRANSFER_TIMEOUT)); |
268 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); | 271 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); |
269 ASSERT_TRUE(RunExtensionTest("usb/transfer_failure")); | 272 ASSERT_TRUE(RunExtensionTest("usb/transfer_failure")); |
270 } | 273 } |
271 | 274 |
272 IN_PROC_BROWSER_TEST_F(UsbApiTest, InvalidLengthTransfer) { | 275 IN_PROC_BROWSER_TEST_F(UsbApiTest, InvalidLengthTransfer) { |
273 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); | 276 EXPECT_CALL(*mock_device_handle_.get(), Close()).Times(AnyNumber()); |
274 ASSERT_TRUE(RunExtensionTest("usb/invalid_length_transfer")); | 277 ASSERT_TRUE(RunExtensionTest("usb/invalid_length_transfer")); |
275 } | 278 } |
OLD | NEW |