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

Side by Side Diff: apps/saved_devices_service_unittest.cc

Issue 601073002: Move string descriptor getters from UsbDeviceHandle to UsbDevice. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix function order. Created 6 years, 2 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 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 "apps/saved_devices_service.h" 5 #include "apps/saved_devices_service.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/test/values_test_util.h" 8 #include "base/test/values_test_util.h"
9 #include "chrome/browser/extensions/test_extension_environment.h" 9 #include "chrome/browser/extensions/test_extension_environment.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
11 #include "device/usb/usb_device.h" 11 #include "device/usb/usb_device.h"
12 #include "device/usb/usb_device_handle.h" 12 #include "device/usb/usb_device_handle.h"
13 #include "extensions/browser/extension_prefs.h" 13 #include "extensions/browser/extension_prefs.h"
14 #include "extensions/common/extension.h" 14 #include "extensions/common/extension.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace apps { 18 namespace apps {
19 19
20 namespace { 20 namespace {
21 21
22 using device::UsbDevice; 22 using device::UsbDevice;
23 using device::UsbDeviceHandle; 23 using device::UsbDeviceHandle;
24 using device::UsbEndpointDirection; 24 using device::UsbEndpointDirection;
25 using device::UsbTransferCallback; 25 using device::UsbTransferCallback;
26 using testing::Return; 26 using testing::Return;
27 27
28 class MockUsbDeviceHandle : public UsbDeviceHandle { 28 class MockUsbDevice : public UsbDevice {
29 public: 29 public:
30 MockUsbDeviceHandle(const std::string& serial_number) 30 MockUsbDevice(const std::string& serial_number, uint32 unique_id)
31 : UsbDeviceHandle(), serial_number_(serial_number) {} 31 : UsbDevice(0, 0, unique_id), serial_number_(serial_number) {}
32 32
33 MOCK_CONST_METHOD0(GetDevice, scoped_refptr<UsbDevice>()); 33 MOCK_METHOD0(Open, scoped_refptr<UsbDeviceHandle>());
34 MOCK_METHOD0(Close, void()); 34 MOCK_METHOD1(Close, bool(scoped_refptr<UsbDeviceHandle>));
35 #if defined(OS_CHROMEOS)
36 MOCK_METHOD2(RequestUsbAccess, void(int, const base::Callback<void(bool)>&));
37 #endif
38 MOCK_METHOD0(GetConfiguration, const device::UsbConfigDescriptor&());
39 MOCK_METHOD1(GetManufacturer, bool(base::string16*));
40 MOCK_METHOD1(GetProduct, bool(base::string16*));
35 41
36 MOCK_METHOD10(ControlTransfer, 42 bool GetSerialNumber(base::string16* serial) OVERRIDE {
37 void(UsbEndpointDirection direction,
38 TransferRequestType request_type,
39 TransferRecipient recipient,
40 uint8 request,
41 uint16 value,
42 uint16 index,
43 net::IOBuffer* buffer,
44 size_t length,
45 unsigned int timeout,
46 const UsbTransferCallback& callback));
47
48 MOCK_METHOD6(BulkTransfer,
49 void(UsbEndpointDirection direction,
50 uint8 endpoint,
51 net::IOBuffer* buffer,
52 size_t length,
53 unsigned int timeout,
54 const UsbTransferCallback& callback));
55
56 MOCK_METHOD6(InterruptTransfer,
57 void(UsbEndpointDirection direction,
58 uint8 endpoint,
59 net::IOBuffer* buffer,
60 size_t length,
61 unsigned int timeout,
62 const UsbTransferCallback& callback));
63
64 MOCK_METHOD8(IsochronousTransfer,
65 void(UsbEndpointDirection direction,
66 uint8 endpoint,
67 net::IOBuffer* buffer,
68 size_t length,
69 unsigned int packets,
70 unsigned int packet_length,
71 unsigned int timeout,
72 const UsbTransferCallback& callback));
73
74 MOCK_METHOD0(ResetDevice, bool());
75 MOCK_METHOD1(ClaimInterface, bool(int interface_number));
76 MOCK_METHOD1(ReleaseInterface, bool(int interface_number));
77 MOCK_METHOD2(SetInterfaceAlternateSetting,
78 bool(int interface_number, int alternate_setting));
79 MOCK_METHOD1(GetManufacturer, bool(base::string16* manufacturer));
80 MOCK_METHOD1(GetProduct, bool(base::string16* product));
81
82 bool GetSerial(base::string16* serial) OVERRIDE {
83 if (serial_number_.empty()) { 43 if (serial_number_.empty()) {
84 return false; 44 return false;
85 } 45 }
86 46
87 *serial = base::UTF8ToUTF16(serial_number_); 47 *serial = base::UTF8ToUTF16(serial_number_);
88 return true; 48 return true;
89 } 49 }
90 50
91 private:
92 virtual ~MockUsbDeviceHandle() {}
93
94 const std::string serial_number_;
95 };
96
97 class MockUsbDevice : public UsbDevice {
98 public:
99 MockUsbDevice(const std::string& serial_number, uint32 unique_id)
100 : UsbDevice(0, 0, unique_id), serial_number_(serial_number) {}
101
102 MOCK_METHOD1(Close, bool(scoped_refptr<UsbDeviceHandle>));
103 #if defined(OS_CHROMEOS)
104 MOCK_METHOD2(RequestUsbAccess, void(int, const base::Callback<void(bool)>&));
105 #endif
106 MOCK_METHOD0(GetConfiguration, const device::UsbConfigDescriptor&());
107
108 scoped_refptr<UsbDeviceHandle> Open() OVERRIDE {
109 return new MockUsbDeviceHandle(serial_number_);
110 }
111
112 void NotifyDisconnect() { UsbDevice::NotifyDisconnect(); } 51 void NotifyDisconnect() { UsbDevice::NotifyDisconnect(); }
113 52
114 private: 53 private:
115 virtual ~MockUsbDevice() {} 54 virtual ~MockUsbDevice() {}
116 55
117 const std::string serial_number_; 56 const std::string serial_number_;
118 }; 57 };
119 } 58 }
120 59
121 class SavedDevicesServiceTest : public testing::Test { 60 class SavedDevicesServiceTest : public testing::Test {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 143
205 SavedDevicesService::SavedDevices* saved_devices = 144 SavedDevicesService::SavedDevices* saved_devices =
206 service_->GetOrInsert(extension_->id()); 145 service_->GetOrInsert(extension_->id());
207 ASSERT_TRUE(saved_devices->IsRegistered(device0)); 146 ASSERT_TRUE(saved_devices->IsRegistered(device0));
208 ASSERT_FALSE(saved_devices->IsRegistered(device1)); 147 ASSERT_FALSE(saved_devices->IsRegistered(device1));
209 ASSERT_FALSE(saved_devices->IsRegistered(device2)); 148 ASSERT_FALSE(saved_devices->IsRegistered(device2));
210 ASSERT_FALSE(saved_devices->IsRegistered(device3)); 149 ASSERT_FALSE(saved_devices->IsRegistered(device3));
211 } 150 }
212 151
213 } // namespace apps 152 } // namespace apps
OLDNEW
« no previous file with comments | « apps/saved_devices_service.cc ('k') | chrome/browser/devtools/device/usb/android_usb_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698