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

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: Fix histograms.xml and bad_messages.h merge conflict 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 }
67 } 68
69 } // namespace
68 70
69 namespace content { 71 namespace content {
70 72
71 // static 73 // static
72 scoped_refptr<BluetoothAdapter> 74 scoped_refptr<BluetoothAdapter>
73 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( 75 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter(
74 const std::string& fake_adapter_name) { 76 const std::string& fake_adapter_name) {
75 if (fake_adapter_name == "EmptyAdapter") 77 if (fake_adapter_name == "EmptyAdapter")
76 return GetEmptyAdapter(); 78 return GetEmptyAdapter();
77 else if (fake_adapter_name == "SingleEmptyDeviceAdapter") 79 else if (fake_adapter_name == "SingleEmptyDeviceAdapter")
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); 169 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH));
168 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF)); 170 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF));
169 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1)); 171 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1));
170 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2)); 172 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2));
171 173
172 BluetoothDevice::UUIDList list; 174 BluetoothDevice::UUIDList list;
173 list.push_back(BluetoothUUID("1800")); 175 list.push_back(BluetoothUUID("1800"));
174 list.push_back(BluetoothUUID("1801")); 176 list.push_back(BluetoothUUID("1801"));
175 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list)); 177 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list));
176 178
177 empty_device->AddMockService( 179 scoped_ptr<NiceMock<MockBluetoothGattService>> generic_access(
178 GetMockService(empty_device.get(), "1800" /* Generic Access */)); 180 GetGattService(empty_device.get(), "1800" /* Generic Access */));
179 empty_device->AddMockService( 181 generic_access->AddMockCharacteristic(
180 GetMockService(empty_device.get(), "1801" /* Generic Attribute */)); 182 GetGattCharacteristic(generic_access.get(), "2A00" /* Device Name */));
183
184 scoped_ptr<NiceMock<MockBluetoothGattService>> generic_attribute(
185 GetGattService(empty_device.get(), "1801" /* Generic Attribute */));
186 generic_attribute->AddMockCharacteristic(GetGattCharacteristic(
187 generic_attribute.get(), "2A05" /* Service Changed */));
188
189 empty_device->AddMockService(generic_access.Pass());
190 empty_device->AddMockService(generic_attribute.Pass());
181 191
182 // Using Invoke allows the device returned from this method to be futher 192 // 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 193 // modified and have more services added to it. The call to ::GetGattServices
184 // will invoke ::GetMockServices, returning all services added up to that 194 // will invoke ::GetMockServices, returning all services added up to that
185 // time. 195 // time.
186 ON_CALL(*empty_device, GetGattServices()) 196 ON_CALL(*empty_device, GetGattServices())
187 .WillByDefault( 197 .WillByDefault(
188 Invoke(empty_device.get(), &MockBluetoothDevice::GetMockServices)); 198 Invoke(empty_device.get(), &MockBluetoothDevice::GetMockServices));
189 199
200 // The call to BluetoothDevice::GetGattService will invoke ::GetMockService
201 // which returns a service matching the identifier provided if the service
202 // was added to the mock.
203 ON_CALL(*empty_device, GetGattService(_))
204 .WillByDefault(
205 Invoke(empty_device.get(), &MockBluetoothDevice::GetMockService));
206
190 return empty_device.Pass(); 207 return empty_device.Pass();
191 } 208 }
192 209
193 // static 210 // static
194 scoped_ptr<NiceMock<MockBluetoothDevice>> 211 scoped_ptr<NiceMock<MockBluetoothDevice>>
195 LayoutTestBluetoothAdapterProvider::GetConnectableDevice( 212 LayoutTestBluetoothAdapterProvider::GetConnectableDevice(
196 MockBluetoothAdapter* adapter) { 213 MockBluetoothAdapter* adapter) {
197 scoped_ptr<NiceMock<MockBluetoothDevice>> device(GetEmptyDevice(adapter)); 214 scoped_ptr<NiceMock<MockBluetoothDevice>> device(GetEmptyDevice(adapter));
198 215
199 BluetoothDevice* device_ptr = device.get(); 216 BluetoothDevice* device_ptr = device.get();
(...skipping 16 matching lines...) Expand all
216 233
217 ON_CALL(*device, CreateGattConnection(_, _)) 234 ON_CALL(*device, CreateGattConnection(_, _))
218 .WillByDefault( 235 .WillByDefault(
219 RunCallback<1 /* error_callback */>(BluetoothDevice::ERROR_FAILED)); 236 RunCallback<1 /* error_callback */>(BluetoothDevice::ERROR_FAILED));
220 237
221 return device.Pass(); 238 return device.Pass();
222 } 239 }
223 240
224 // static 241 // static
225 scoped_ptr<NiceMock<MockBluetoothGattService>> 242 scoped_ptr<NiceMock<MockBluetoothGattService>>
226 LayoutTestBluetoothAdapterProvider::GetMockService(MockBluetoothDevice* device, 243 LayoutTestBluetoothAdapterProvider::GetGattService(MockBluetoothDevice* device,
227 const std::string& uuid) { 244 const std::string& uuid) {
228 return make_scoped_ptr(new NiceMock<MockBluetoothGattService>( 245 scoped_ptr<NiceMock<MockBluetoothGattService>> service(
229 device, uuid /* identifier */, BluetoothUUID(uuid), true /* is_primary */, 246 new NiceMock<MockBluetoothGattService>(
230 false /* is_local */)); 247 device, uuid /* identifier */, BluetoothUUID(uuid),
248 true /* is_primary */, false /* is_local */));
249
250 ON_CALL(*service, GetCharacteristics())
251 .WillByDefault(Invoke(service.get(),
252 &MockBluetoothGattService::GetMockCharacteristics));
253 return service.Pass();
254 }
255
256 // static
257 scoped_ptr<NiceMock<MockBluetoothGattCharacteristic>>
258 LayoutTestBluetoothAdapterProvider::GetGattCharacteristic(
259 MockBluetoothGattService* service,
260 const std::string& uuid) {
261 return make_scoped_ptr(new NiceMock<MockBluetoothGattCharacteristic>(
262 service, uuid /* identifier */, BluetoothUUID(uuid), false /* is_local */,
263 NULL /* properties */, NULL /* permissions */));
231 } 264 }
232 265
233 } // namespace content 266 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698