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

Side by Side Diff: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc

Issue 1156573005: bluetooth: Browser-side implementation of getCharacteristic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-get-primary-service-initial
Patch Set: Use iterator Created 5 years, 6 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 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::BluetoothGattService;
22 using device::BluetoothUUID; 22 using device::BluetoothUUID;
23 using device::MockBluetoothAdapter; 23 using device::MockBluetoothAdapter;
24 using device::MockBluetoothDevice; 24 using device::MockBluetoothDevice;
25 using device::MockBluetoothDiscoverySession; 25 using device::MockBluetoothDiscoverySession;
26 using device::MockBluetoothGattCharacteristic;
26 using device::MockBluetoothGattConnection; 27 using device::MockBluetoothGattConnection;
27 using device::MockBluetoothGattService; 28 using device::MockBluetoothGattService;
28 using testing::Between; 29 using testing::Between;
29 using testing::Invoke; 30 using testing::Invoke;
30 using testing::Return; 31 using testing::Return;
31 using testing::NiceMock; 32 using testing::NiceMock;
32 using testing::_; 33 using testing::_;
33 34
34 namespace { 35 namespace {
35 // Invokes Run() on the k-th argument of the function with no arguments. 36 // Invokes Run() on the k-th argument of the function with no arguments.
(...skipping 21 matching lines...) Expand all
57 // Function to iterate over the adapter's devices and return the one 58 // Function to iterate over the adapter's devices and return the one
58 // that matches the address. 59 // that matches the address.
59 ACTION_P(GetMockDevice, adapter) { 60 ACTION_P(GetMockDevice, adapter) {
60 std::string address = arg0; 61 std::string address = arg0;
61 for (BluetoothDevice* device : adapter->GetMockDevices()) { 62 for (BluetoothDevice* device : adapter->GetMockDevices()) {
62 if (device->GetAddress() == address) 63 if (device->GetAddress() == address)
63 return device; 64 return device;
64 } 65 }
65 return NULL; 66 return NULL;
66 } 67 }
68
69 // Function to iterate over the device's services and return the one
70 // that matches the identifier.
71 ACTION_P(GetMockService, device) {
scheib 2015/06/04 06:30:49 Add GetMockService to MockBluetoothDevice.
ortuno 2015/06/05 19:37:44 Done. I'll move GetMockDevice to MockBluetoothDevi
72 std::string identifier = arg0;
73 for (BluetoothGattService* service : device->GetMockServices()) {
74 if (service->GetIdentifier() == identifier)
75 return service;
76 }
77 return NULL;
67 } 78 }
68 79
80 } // namespace
81
69 namespace content { 82 namespace content {
70 83
71 // static 84 // static
72 scoped_refptr<BluetoothAdapter> 85 scoped_refptr<BluetoothAdapter>
73 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( 86 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter(
74 const std::string& fake_adapter_name) { 87 const std::string& fake_adapter_name) {
75 if (fake_adapter_name == "EmptyAdapter") 88 if (fake_adapter_name == "EmptyAdapter")
76 return GetEmptyAdapter(); 89 return GetEmptyAdapter();
77 else if (fake_adapter_name == "SingleEmptyDeviceAdapter") 90 else if (fake_adapter_name == "SingleEmptyDeviceAdapter")
78 return GetSingleEmptyDeviceAdapter(); 91 return GetSingleEmptyDeviceAdapter();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); 180 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH));
168 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF)); 181 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF));
169 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1)); 182 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1));
170 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2)); 183 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2));
171 184
172 BluetoothDevice::UUIDList list; 185 BluetoothDevice::UUIDList list;
173 list.push_back(BluetoothUUID("1800")); 186 list.push_back(BluetoothUUID("1800"));
174 list.push_back(BluetoothUUID("1801")); 187 list.push_back(BluetoothUUID("1801"));
175 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list)); 188 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list));
176 189
177 empty_device->AddMockService( 190 scoped_ptr<NiceMock<MockBluetoothGattService>> generic_access(
178 GetMockService(empty_device.get(), "1800" /* Generic Access */)); 191 GetService(empty_device.get(), "1800" /* Generic Access */));
179 empty_device->AddMockService( 192 generic_access->AddMockCharacteristic(
180 GetMockService(empty_device.get(), "1801" /* Generic Attribute */)); 193 GetCharacteristic(generic_access.get(), "2A00" /* Device Name */));
194
195 scoped_ptr<NiceMock<MockBluetoothGattService>> generic_attribute(
196 GetService(empty_device.get(), "1801" /* Generic Attribute */));
197 generic_attribute->AddMockCharacteristic(
198 GetCharacteristic(generic_attribute.get(), "2A05" /* Service Changed */));
199
200 empty_device->AddMockService(generic_access.Pass());
201 empty_device->AddMockService(generic_attribute.Pass());
181 202
182 // Using Invoke allows the device returned from this method to be futher 203 // 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 204 // modified and have more services added to it. The call to ::GetGattServices
184 // will invoke ::GetMockServices, returning all services added up to that 205 // will invoke ::GetMockServices, returning all services added up to that
185 // time. 206 // time.
186 ON_CALL(*empty_device, GetGattServices()) 207 ON_CALL(*empty_device, GetGattServices())
187 .WillByDefault( 208 .WillByDefault(
188 Invoke(empty_device.get(), &MockBluetoothDevice::GetMockServices)); 209 Invoke(empty_device.get(), &MockBluetoothDevice::GetMockServices));
189 210
211 // The call to BluetoothDevice::GetService will invoke ::GetMockService
scheib 2015/06/04 06:30:49 GetService -> GetGattService
ortuno 2015/06/05 19:37:44 Done.
212 // which returns a service matching the identifier provided if the service
213 // was added to the mock.
214 ON_CALL(*empty_device, GetGattService(_))
215 .WillByDefault(GetMockService(empty_device.get()));
216
190 return empty_device.Pass(); 217 return empty_device.Pass();
191 } 218 }
192 219
193 // static 220 // static
194 scoped_ptr<NiceMock<MockBluetoothDevice>> 221 scoped_ptr<NiceMock<MockBluetoothDevice>>
195 LayoutTestBluetoothAdapterProvider::GetConnectableDevice( 222 LayoutTestBluetoothAdapterProvider::GetConnectableDevice(
196 MockBluetoothAdapter* adapter) { 223 MockBluetoothAdapter* adapter) {
197 scoped_ptr<NiceMock<MockBluetoothDevice>> device(GetEmptyDevice(adapter)); 224 scoped_ptr<NiceMock<MockBluetoothDevice>> device(GetEmptyDevice(adapter));
198 225
199 BluetoothDevice* device_ptr = device.get(); 226 BluetoothDevice* device_ptr = device.get();
(...skipping 16 matching lines...) Expand all
216 243
217 ON_CALL(*device, CreateGattConnection(_, _)) 244 ON_CALL(*device, CreateGattConnection(_, _))
218 .WillByDefault( 245 .WillByDefault(
219 RunCallback<1 /* error_callback */>(BluetoothDevice::ERROR_FAILED)); 246 RunCallback<1 /* error_callback */>(BluetoothDevice::ERROR_FAILED));
220 247
221 return device.Pass(); 248 return device.Pass();
222 } 249 }
223 250
224 // static 251 // static
225 scoped_ptr<NiceMock<MockBluetoothGattService>> 252 scoped_ptr<NiceMock<MockBluetoothGattService>>
226 LayoutTestBluetoothAdapterProvider::GetMockService(MockBluetoothDevice* device, 253 LayoutTestBluetoothAdapterProvider::GetService(MockBluetoothDevice* device,
227 const std::string& uuid) { 254 const std::string& uuid) {
228 return make_scoped_ptr(new NiceMock<MockBluetoothGattService>( 255 scoped_ptr<NiceMock<MockBluetoothGattService>> service(
229 device, uuid /* identifier */, BluetoothUUID(uuid), true /* is_primary */, 256 new NiceMock<MockBluetoothGattService>(
230 false /* is_local */)); 257 device, uuid /* identifier */, BluetoothUUID(uuid),
258 true /* is_primary */, false /* is_local */));
259
260 ON_CALL(*service, GetCharacteristics())
261 .WillByDefault(Invoke(service.get(),
262 &MockBluetoothGattService::GetMockCharacteristics));
263 return service.Pass();
264 }
265
266 // static
267 scoped_ptr<NiceMock<MockBluetoothGattCharacteristic>>
268 LayoutTestBluetoothAdapterProvider::GetCharacteristic(
269 MockBluetoothGattService* service,
270 const std::string& uuid) {
271 return make_scoped_ptr(new NiceMock<MockBluetoothGattCharacteristic>(
272 service, uuid /* identifier */, BluetoothUUID(uuid), false /* is_local */,
273 NULL /* properties */, NULL /* permissions */));
231 } 274 }
232 275
233 } // namespace content 276 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698