OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid
er.h" | 5 #include "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid
er.h" |
6 | 6 |
7 #include "device/bluetooth/bluetooth_adapter.h" | 7 #include "device/bluetooth/bluetooth_adapter.h" |
8 #include "device/bluetooth/bluetooth_device.h" | 8 #include "device/bluetooth/bluetooth_device.h" |
9 #include "device/bluetooth/bluetooth_discovery_session.h" | 9 #include "device/bluetooth/bluetooth_discovery_session.h" |
10 #include "device/bluetooth/bluetooth_uuid.h" | 10 #include "device/bluetooth/bluetooth_uuid.h" |
11 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 11 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
12 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" | 12 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" |
13 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" | 13 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 | 15 |
16 using device::BluetoothAdapter; | 16 using device::BluetoothAdapter; |
17 using device::BluetoothAdapterFactory; | 17 using device::BluetoothAdapterFactory; |
18 using device::BluetoothDevice; | 18 using device::BluetoothDevice; |
19 using device::BluetoothDiscoverySession; | 19 using device::BluetoothDiscoverySession; |
20 using device::BluetoothGattConnection; | 20 using device::BluetoothGattConnection; |
| 21 using device::BluetoothGattService; |
21 using device::BluetoothUUID; | 22 using device::BluetoothUUID; |
22 using device::MockBluetoothAdapter; | 23 using device::MockBluetoothAdapter; |
23 using device::MockBluetoothDevice; | 24 using device::MockBluetoothDevice; |
24 using device::MockBluetoothDiscoverySession; | 25 using device::MockBluetoothDiscoverySession; |
25 using device::MockBluetoothGattConnection; | 26 using device::MockBluetoothGattConnection; |
| 27 using device::MockBluetoothGattService; |
26 using testing::Between; | 28 using testing::Between; |
27 using testing::Invoke; | 29 using testing::Invoke; |
28 using testing::Return; | 30 using testing::Return; |
29 using testing::NiceMock; | 31 using testing::NiceMock; |
30 using testing::_; | 32 using testing::_; |
31 | 33 |
32 namespace { | 34 namespace { |
33 // Invokes Run() on the k-th argument of the function with no arguments. | 35 // Invokes Run() on the k-th argument of the function with no arguments. |
34 ACTION_TEMPLATE(RunCallback, | 36 ACTION_TEMPLATE(RunCallback, |
35 HAS_1_TEMPLATE_PARAMS(int, k), | 37 HAS_1_TEMPLATE_PARAMS(int, k), |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 ON_CALL(*empty_device, GetVendorIDSource()) | 166 ON_CALL(*empty_device, GetVendorIDSource()) |
165 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); | 167 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); |
166 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF)); | 168 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF)); |
167 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1)); | 169 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1)); |
168 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2)); | 170 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2)); |
169 | 171 |
170 BluetoothDevice::UUIDList list; | 172 BluetoothDevice::UUIDList list; |
171 list.push_back(BluetoothUUID("1800")); | 173 list.push_back(BluetoothUUID("1800")); |
172 list.push_back(BluetoothUUID("1801")); | 174 list.push_back(BluetoothUUID("1801")); |
173 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list)); | 175 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list)); |
| 176 |
| 177 empty_device->AddMockService( |
| 178 GetMockService(empty_device.get(), "1800" /* Generic Access */)); |
| 179 empty_device->AddMockService( |
| 180 GetMockService(empty_device.get(), "1801" /* Generic Attribute */)); |
| 181 |
| 182 // Using Invoke allows the device returned from this method to be futher |
| 183 // modified and have more services added to it. The call to ::GetGattServices |
| 184 // will invoke ::GetMockServices, returning all services added up to that |
| 185 // time. |
| 186 ON_CALL(*empty_device, GetGattServices()) |
| 187 .WillByDefault( |
| 188 Invoke(empty_device.get(), &MockBluetoothDevice::GetMockServices)); |
| 189 |
174 return empty_device.Pass(); | 190 return empty_device.Pass(); |
175 } | 191 } |
176 | 192 |
177 // static | 193 // static |
178 scoped_ptr<NiceMock<MockBluetoothDevice>> | 194 scoped_ptr<NiceMock<MockBluetoothDevice>> |
179 LayoutTestBluetoothAdapterProvider::GetConnectableDevice( | 195 LayoutTestBluetoothAdapterProvider::GetConnectableDevice( |
180 MockBluetoothAdapter* adapter) { | 196 MockBluetoothAdapter* adapter) { |
181 scoped_ptr<NiceMock<MockBluetoothDevice>> device(GetEmptyDevice(adapter)); | 197 scoped_ptr<NiceMock<MockBluetoothDevice>> device(GetEmptyDevice(adapter)); |
182 | 198 |
183 BluetoothDevice* device_ptr = device.get(); | 199 BluetoothDevice* device_ptr = device.get(); |
(...skipping 14 matching lines...) Expand all Loading... |
198 MockBluetoothAdapter* adapter) { | 214 MockBluetoothAdapter* adapter) { |
199 scoped_ptr<NiceMock<MockBluetoothDevice>> device(GetEmptyDevice(adapter)); | 215 scoped_ptr<NiceMock<MockBluetoothDevice>> device(GetEmptyDevice(adapter)); |
200 | 216 |
201 ON_CALL(*device, CreateGattConnection(_, _)) | 217 ON_CALL(*device, CreateGattConnection(_, _)) |
202 .WillByDefault( | 218 .WillByDefault( |
203 RunCallback<1 /* error_callback */>(BluetoothDevice::ERROR_FAILED)); | 219 RunCallback<1 /* error_callback */>(BluetoothDevice::ERROR_FAILED)); |
204 | 220 |
205 return device.Pass(); | 221 return device.Pass(); |
206 } | 222 } |
207 | 223 |
| 224 // static |
| 225 scoped_ptr<NiceMock<MockBluetoothGattService>> |
| 226 LayoutTestBluetoothAdapterProvider::GetMockService(MockBluetoothDevice* device, |
| 227 const std::string& uuid) { |
| 228 return make_scoped_ptr(new NiceMock<MockBluetoothGattService>( |
| 229 device, uuid /* identifier */, BluetoothUUID(uuid), true /* is_primary */, |
| 230 false /* is_local */)); |
| 231 } |
| 232 |
208 } // namespace content | 233 } // namespace content |
OLD | NEW |