| OLD | NEW |
| 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" | 5 #include "chrome/browser/extensions/api/usb/usb_api.h" |
| 6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
| 7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/usb/usb_service.h" | 8 #include "chrome/browser/usb/usb_service.h" |
| 9 #include "chrome/browser/usb/usb_service_factory.h" | 9 #include "chrome/browser/usb/usb_service_factory.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 ::std::tr1::get<k>(args).Run(p1); | 32 ::std::tr1::get<k>(args).Run(p1); |
| 33 } | 33 } |
| 34 | 34 |
| 35 // MSVC erroneously thinks that at least one of the arguments for the transfer | 35 // MSVC erroneously thinks that at least one of the arguments for the transfer |
| 36 // methods differ by const or volatility and emits a warning about the old | 36 // methods differ by const or volatility and emits a warning about the old |
| 37 // standards-noncompliant behaviour of their compiler. | 37 // standards-noncompliant behaviour of their compiler. |
| 38 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
| 39 #pragma warning(push) | 39 #pragma warning(push) |
| 40 #pragma warning(disable:4373) | 40 #pragma warning(disable:4373) |
| 41 #endif | 41 #endif |
| 42 class MockUsbDevice : public UsbDevice { | 42 class MockUsbDevice : public UsbDeviceHandle { |
| 43 public: | 43 public: |
| 44 MockUsbDevice() : UsbDevice() {} | 44 MockUsbDevice() : UsbDeviceHandle() {} |
| 45 | 45 |
| 46 MOCK_METHOD1(Close, void(const base::Callback<void()>& callback)); | 46 MOCK_METHOD1(Close, void(const base::Callback<void()>& callback)); |
| 47 | 47 |
| 48 MOCK_METHOD10(ControlTransfer, void(const UsbEndpointDirection direction, | 48 MOCK_METHOD10(ControlTransfer, void(const UsbEndpointDirection direction, |
| 49 const TransferRequestType request_type, const TransferRecipient recipient, | 49 const TransferRequestType request_type, const TransferRecipient recipient, |
| 50 const uint8 request, const uint16 value, const uint16 index, | 50 const uint8 request, const uint16 value, const uint16 index, |
| 51 net::IOBuffer* buffer, const size_t length, const unsigned int timeout, | 51 net::IOBuffer* buffer, const size_t length, const unsigned int timeout, |
| 52 const UsbTransferCallback& callback)); | 52 const UsbTransferCallback& callback)); |
| 53 | 53 |
| 54 MOCK_METHOD6(BulkTransfer, void(const UsbEndpointDirection direction, | 54 MOCK_METHOD6(BulkTransfer, void(const UsbEndpointDirection direction, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 IN_PROC_BROWSER_TEST_F(UsbApiTest, ListInterfaces) { | 109 IN_PROC_BROWSER_TEST_F(UsbApiTest, ListInterfaces) { |
| 110 EXPECT_CALL(*mock_device_.get(), ListInterfaces(_, _)) | 110 EXPECT_CALL(*mock_device_.get(), ListInterfaces(_, _)) |
| 111 .WillOnce(InvokeUsbResultCallback<1>(false)); | 111 .WillOnce(InvokeUsbResultCallback<1>(false)); |
| 112 EXPECT_CALL(*mock_device_.get(), Close(_)).Times(AnyNumber()); | 112 EXPECT_CALL(*mock_device_.get(), Close(_)).Times(AnyNumber()); |
| 113 ASSERT_TRUE(RunExtensionTest("usb/list_interfaces")); | 113 ASSERT_TRUE(RunExtensionTest("usb/list_interfaces")); |
| 114 } | 114 } |
| 115 | 115 |
| 116 IN_PROC_BROWSER_TEST_F(UsbApiTest, TransferEvent) { | 116 IN_PROC_BROWSER_TEST_F(UsbApiTest, TransferEvent) { |
| 117 EXPECT_CALL(*mock_device_.get(), | 117 EXPECT_CALL(*mock_device_.get(), |
| 118 ControlTransfer(USB_DIRECTION_OUTBOUND, | 118 ControlTransfer(USB_DIRECTION_OUTBOUND, |
| 119 UsbDevice::STANDARD, | 119 UsbDeviceHandle::STANDARD, |
| 120 UsbDevice::DEVICE, | 120 UsbDeviceHandle::DEVICE, |
| 121 1, | 121 1, |
| 122 2, | 122 2, |
| 123 3, | 123 3, |
| 124 _, | 124 _, |
| 125 1, | 125 1, |
| 126 _, | 126 _, |
| 127 _)) | 127 _)) |
| 128 .WillOnce(InvokeUsbTransferCallback<9>(USB_TRANSFER_COMPLETED)); | 128 .WillOnce(InvokeUsbTransferCallback<9>(USB_TRANSFER_COMPLETED)); |
| 129 EXPECT_CALL(*mock_device_.get(), | 129 EXPECT_CALL(*mock_device_.get(), |
| 130 BulkTransfer(USB_DIRECTION_OUTBOUND, 1, _, 1, _, _)) | 130 BulkTransfer(USB_DIRECTION_OUTBOUND, 1, _, 1, _, _)) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 153 .WillOnce(InvokeUsbTransferCallback<5>(USB_TRANSFER_TIMEOUT)); | 153 .WillOnce(InvokeUsbTransferCallback<5>(USB_TRANSFER_TIMEOUT)); |
| 154 EXPECT_CALL(*mock_device_.get(), Close(_)).Times(AnyNumber()); | 154 EXPECT_CALL(*mock_device_.get(), Close(_)).Times(AnyNumber()); |
| 155 ASSERT_TRUE(RunExtensionTest("usb/transfer_failure")); | 155 ASSERT_TRUE(RunExtensionTest("usb/transfer_failure")); |
| 156 } | 156 } |
| 157 | 157 |
| 158 IN_PROC_BROWSER_TEST_F(UsbApiTest, InvalidLengthTransfer) { | 158 IN_PROC_BROWSER_TEST_F(UsbApiTest, InvalidLengthTransfer) { |
| 159 EXPECT_CALL(*mock_device_.get(), Close(_)).Times(AnyNumber()); | 159 EXPECT_CALL(*mock_device_.get(), Close(_)).Times(AnyNumber()); |
| 160 ASSERT_TRUE(RunExtensionTest("usb/invalid_length_transfer")); | 160 ASSERT_TRUE(RunExtensionTest("usb/invalid_length_transfer")); |
| 161 } | 161 } |
| 162 | 162 |
| OLD | NEW |