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

Side by Side Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc

Issue 1898643002: Refactor device::BluetoothGattXXX classes to split into remote/local. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h" 10 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h"
11 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h" 11 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h"
12 #include "chrome/browser/extensions/extension_apitest.h" 12 #include "chrome/browser/extensions/extension_apitest.h"
13 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 13 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
14 #include "device/bluetooth/test/mock_bluetooth_device.h" 14 #include "device/bluetooth/test/mock_bluetooth_device.h"
15 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h" 15 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h"
16 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" 16 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h"
17 #include "device/bluetooth/test/mock_bluetooth_gatt_descriptor.h" 17 #include "device/bluetooth/test/mock_bluetooth_gatt_descriptor.h"
18 #include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h" 18 #include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h"
19 #include "device/bluetooth/test/mock_bluetooth_gatt_service.h" 19 #include "device/bluetooth/test/mock_bluetooth_gatt_service.h"
20 #include "extensions/common/test_util.h" 20 #include "extensions/common/test_util.h"
21 #include "extensions/test/extension_test_message_listener.h" 21 #include "extensions/test/extension_test_message_listener.h"
22 #include "extensions/test/result_catcher.h" 22 #include "extensions/test/result_catcher.h"
23 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
24 24
25 using device::BluetoothUUID; 25 using device::BluetoothUUID;
26 using device::BluetoothAdapter; 26 using device::BluetoothAdapter;
27 using device::BluetoothDevice; 27 using device::BluetoothDevice;
28 using device::BluetoothGattCharacteristic; 28 using device::BluetoothRemoteGattCharacteristic;
29 using device::BluetoothGattConnection; 29 using device::BluetoothGattConnection;
30 using device::BluetoothGattDescriptor; 30 using device::BluetoothRemoteGattDescriptor;
31 using device::BluetoothGattService; 31 using device::BluetoothRemoteGattService;
32 using device::BluetoothGattNotifySession; 32 using device::BluetoothGattNotifySession;
33 using device::MockBluetoothAdapter; 33 using device::MockBluetoothAdapter;
34 using device::MockBluetoothDevice; 34 using device::MockBluetoothDevice;
35 using device::MockBluetoothGattCharacteristic; 35 using device::MockBluetoothGattCharacteristic;
36 using device::MockBluetoothGattConnection; 36 using device::MockBluetoothGattConnection;
37 using device::MockBluetoothGattDescriptor; 37 using device::MockBluetoothGattDescriptor;
38 using device::MockBluetoothGattService; 38 using device::MockBluetoothGattService;
39 using device::MockBluetoothGattNotifySession; 39 using device::MockBluetoothGattNotifySession;
40 using extensions::BluetoothLowEnergyEventRouter; 40 using extensions::BluetoothLowEnergyEventRouter;
41 using extensions::ResultCatcher; 41 using extensions::ResultCatcher;
(...skipping 15 matching lines...) Expand all
57 57
58 const char kTestServiceId0[] = "service_id0"; 58 const char kTestServiceId0[] = "service_id0";
59 const char kTestServiceUuid0[] = "1234"; 59 const char kTestServiceUuid0[] = "1234";
60 60
61 const char kTestServiceId1[] = "service_id1"; 61 const char kTestServiceId1[] = "service_id1";
62 const char kTestServiceUuid1[] = "5678"; 62 const char kTestServiceUuid1[] = "5678";
63 63
64 // Test characteristic constants. 64 // Test characteristic constants.
65 const char kTestCharacteristicId0[] = "char_id0"; 65 const char kTestCharacteristicId0[] = "char_id0";
66 const char kTestCharacteristicUuid0[] = "1211"; 66 const char kTestCharacteristicUuid0[] = "1211";
67 const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties0 = 67 const BluetoothRemoteGattCharacteristic::Properties
68 BluetoothGattCharacteristic::PROPERTY_BROADCAST | 68 kTestCharacteristicProperties0 =
69 BluetoothGattCharacteristic::PROPERTY_READ | 69 BluetoothRemoteGattCharacteristic::PROPERTY_BROADCAST |
70 BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE | 70 BluetoothRemoteGattCharacteristic::PROPERTY_READ |
71 BluetoothGattCharacteristic::PROPERTY_INDICATE; 71 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE |
72 BluetoothRemoteGattCharacteristic::PROPERTY_INDICATE;
72 const uint8_t kTestCharacteristicDefaultValue0[] = {0x01, 0x02, 0x03, 0x04, 73 const uint8_t kTestCharacteristicDefaultValue0[] = {0x01, 0x02, 0x03, 0x04,
73 0x05}; 74 0x05};
74 75
75 const char kTestCharacteristicId1[] = "char_id1"; 76 const char kTestCharacteristicId1[] = "char_id1";
76 const char kTestCharacteristicUuid1[] = "1212"; 77 const char kTestCharacteristicUuid1[] = "1212";
77 const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties1 = 78 const BluetoothRemoteGattCharacteristic::Properties
78 BluetoothGattCharacteristic::PROPERTY_READ | 79 kTestCharacteristicProperties1 =
79 BluetoothGattCharacteristic::PROPERTY_WRITE | 80 BluetoothRemoteGattCharacteristic::PROPERTY_READ |
80 BluetoothGattCharacteristic::PROPERTY_NOTIFY; 81 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE |
82 BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY;
81 const uint8_t kTestCharacteristicDefaultValue1[] = {0x06, 0x07, 0x08}; 83 const uint8_t kTestCharacteristicDefaultValue1[] = {0x06, 0x07, 0x08};
82 84
83 const char kTestCharacteristicId2[] = "char_id2"; 85 const char kTestCharacteristicId2[] = "char_id2";
84 const char kTestCharacteristicUuid2[] = "1213"; 86 const char kTestCharacteristicUuid2[] = "1213";
85 const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties2 = 87 const BluetoothRemoteGattCharacteristic::Properties
86 BluetoothGattCharacteristic::PROPERTY_NONE; 88 kTestCharacteristicProperties2 =
89 BluetoothRemoteGattCharacteristic::PROPERTY_NONE;
87 90
88 // Test descriptor constants. 91 // Test descriptor constants.
89 const char kTestDescriptorId0[] = "desc_id0"; 92 const char kTestDescriptorId0[] = "desc_id0";
90 const char kTestDescriptorUuid0[] = "1221"; 93 const char kTestDescriptorUuid0[] = "1221";
91 const uint8_t kTestDescriptorDefaultValue0[] = {0x01, 0x02, 0x03}; 94 const uint8_t kTestDescriptorDefaultValue0[] = {0x01, 0x02, 0x03};
92 95
93 const char kTestDescriptorId1[] = "desc_id1"; 96 const char kTestDescriptorId1[] = "desc_id1";
94 const char kTestDescriptorUuid1[] = "1222"; 97 const char kTestDescriptorUuid1[] = "1222";
95 const uint8_t kTestDescriptorDefaultValue1[] = {0x04, 0x05}; 98 const uint8_t kTestDescriptorDefaultValue1[] = {0x04, 0x05};
96 99
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 service1_.reset(new testing::NiceMock<MockBluetoothGattService>( 146 service1_.reset(new testing::NiceMock<MockBluetoothGattService>(
144 device0_.get(), 147 device0_.get(),
145 kTestServiceId1, 148 kTestServiceId1,
146 BluetoothUUID(kTestServiceUuid1), 149 BluetoothUUID(kTestServiceUuid1),
147 false /* is_primary */, 150 false /* is_primary */,
148 false /* is_local */)); 151 false /* is_local */));
149 152
150 // Assign characteristics some random properties and permissions. They don't 153 // Assign characteristics some random properties and permissions. They don't
151 // need to reflect what the characteristic is actually capable of, since 154 // need to reflect what the characteristic is actually capable of, since
152 // the JS API just passes values through from 155 // the JS API just passes values through from
153 // device::BluetoothGattCharacteristic. 156 // device::BluetoothRemoteGattCharacteristic.
154 std::vector<uint8_t> default_value; 157 std::vector<uint8_t> default_value;
155 chrc0_.reset(new testing::NiceMock<MockBluetoothGattCharacteristic>( 158 chrc0_.reset(new testing::NiceMock<MockBluetoothGattCharacteristic>(
156 service0_.get(), 159 service0_.get(), kTestCharacteristicId0,
157 kTestCharacteristicId0, 160 BluetoothUUID(kTestCharacteristicUuid0), false /* is_local */,
158 BluetoothUUID(kTestCharacteristicUuid0),
159 false /* is_local */,
160 kTestCharacteristicProperties0, 161 kTestCharacteristicProperties0,
161 BluetoothGattCharacteristic::PERMISSION_NONE)); 162 BluetoothRemoteGattCharacteristic::PERMISSION_NONE));
162 default_value.assign(kTestCharacteristicDefaultValue0, 163 default_value.assign(kTestCharacteristicDefaultValue0,
163 (kTestCharacteristicDefaultValue0 + 164 (kTestCharacteristicDefaultValue0 +
164 sizeof(kTestCharacteristicDefaultValue0))); 165 sizeof(kTestCharacteristicDefaultValue0)));
165 ON_CALL(*chrc0_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); 166 ON_CALL(*chrc0_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value));
166 167
167 chrc1_.reset(new testing::NiceMock<MockBluetoothGattCharacteristic>( 168 chrc1_.reset(new testing::NiceMock<MockBluetoothGattCharacteristic>(
168 service0_.get(), 169 service0_.get(), kTestCharacteristicId1,
169 kTestCharacteristicId1, 170 BluetoothUUID(kTestCharacteristicUuid1), false /* is_local */,
170 BluetoothUUID(kTestCharacteristicUuid1),
171 false /* is_local */,
172 kTestCharacteristicProperties1, 171 kTestCharacteristicProperties1,
173 BluetoothGattCharacteristic::PERMISSION_NONE)); 172 BluetoothRemoteGattCharacteristic::PERMISSION_NONE));
174 default_value.assign(kTestCharacteristicDefaultValue1, 173 default_value.assign(kTestCharacteristicDefaultValue1,
175 (kTestCharacteristicDefaultValue1 + 174 (kTestCharacteristicDefaultValue1 +
176 sizeof(kTestCharacteristicDefaultValue1))); 175 sizeof(kTestCharacteristicDefaultValue1)));
177 ON_CALL(*chrc1_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); 176 ON_CALL(*chrc1_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value));
178 177
179 chrc2_.reset(new testing::NiceMock<MockBluetoothGattCharacteristic>( 178 chrc2_.reset(new testing::NiceMock<MockBluetoothGattCharacteristic>(
180 service1_.get(), 179 service1_.get(), kTestCharacteristicId2,
181 kTestCharacteristicId2, 180 BluetoothUUID(kTestCharacteristicUuid2), false /* is_local */,
182 BluetoothUUID(kTestCharacteristicUuid2),
183 false /* is_local */,
184 kTestCharacteristicProperties2, 181 kTestCharacteristicProperties2,
185 BluetoothGattCharacteristic::PERMISSION_NONE)); 182 BluetoothRemoteGattCharacteristic::PERMISSION_NONE));
186 183
187 desc0_.reset(new testing::NiceMock<MockBluetoothGattDescriptor>( 184 desc0_.reset(new testing::NiceMock<MockBluetoothGattDescriptor>(
188 chrc0_.get(), 185 chrc0_.get(), kTestDescriptorId0, BluetoothUUID(kTestDescriptorUuid0),
189 kTestDescriptorId0,
190 BluetoothUUID(kTestDescriptorUuid0),
191 false /* is_local */, 186 false /* is_local */,
192 BluetoothGattCharacteristic::PERMISSION_NONE)); 187 BluetoothRemoteGattCharacteristic::PERMISSION_NONE));
193 default_value.assign( 188 default_value.assign(
194 kTestDescriptorDefaultValue0, 189 kTestDescriptorDefaultValue0,
195 (kTestDescriptorDefaultValue0 + sizeof(kTestDescriptorDefaultValue0))); 190 (kTestDescriptorDefaultValue0 + sizeof(kTestDescriptorDefaultValue0)));
196 ON_CALL(*desc0_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); 191 ON_CALL(*desc0_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value));
197 192
198 desc1_.reset(new testing::NiceMock<MockBluetoothGattDescriptor>( 193 desc1_.reset(new testing::NiceMock<MockBluetoothGattDescriptor>(
199 chrc0_.get(), 194 chrc0_.get(), kTestDescriptorId1, BluetoothUUID(kTestDescriptorUuid1),
200 kTestDescriptorId1,
201 BluetoothUUID(kTestDescriptorUuid1),
202 false /* is_local */, 195 false /* is_local */,
203 BluetoothGattCharacteristic::PERMISSION_NONE)); 196 BluetoothRemoteGattCharacteristic::PERMISSION_NONE));
204 default_value.assign( 197 default_value.assign(
205 kTestDescriptorDefaultValue1, 198 kTestDescriptorDefaultValue1,
206 (kTestDescriptorDefaultValue1 + sizeof(kTestDescriptorDefaultValue1))); 199 (kTestDescriptorDefaultValue1 + sizeof(kTestDescriptorDefaultValue1)));
207 ON_CALL(*desc1_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); 200 ON_CALL(*desc1_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value));
208 } 201 }
209 202
210 protected: 203 protected:
211 BluetoothLowEnergyEventRouter* event_router() { 204 BluetoothLowEnergyEventRouter* event_router() {
212 return extensions::BluetoothLowEnergyAPI::Get(browser()->profile()) 205 return extensions::BluetoothLowEnergyAPI::Get(browser()->profile())
213 ->event_router(); 206 ->event_router();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 new testing::NiceMock<MockBluetoothGattConnection>(adapter, 247 new testing::NiceMock<MockBluetoothGattConnection>(adapter,
255 device_address); 248 device_address);
256 EXPECT_CALL(*conn, Disconnect()).Times(expect_disconnect ? 1 : 0); 249 EXPECT_CALL(*conn, Disconnect()).Times(expect_disconnect ? 1 : 0);
257 return conn; 250 return conn;
258 } 251 }
259 252
260 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) { 253 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) {
261 ResultCatcher catcher; 254 ResultCatcher catcher;
262 catcher.RestrictToBrowserContext(browser()->profile()); 255 catcher.RestrictToBrowserContext(browser()->profile());
263 256
264 std::vector<BluetoothGattService*> services; 257 std::vector<BluetoothRemoteGattService*> services;
265 services.push_back(service0_.get()); 258 services.push_back(service0_.get());
266 services.push_back(service1_.get()); 259 services.push_back(service1_.get());
267 260
268 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 261 EXPECT_CALL(*mock_adapter_, GetDevice(_))
269 .Times(3) 262 .Times(3)
270 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL))) 263 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL)))
271 .WillRepeatedly(Return(device0_.get())); 264 .WillRepeatedly(Return(device0_.get()));
272 265
273 EXPECT_CALL(*device0_, GetGattServices()) 266 EXPECT_CALL(*device0_, GetGattServices())
274 .Times(2) 267 .Times(2)
275 .WillOnce(Return(std::vector<BluetoothGattService*>())) 268 .WillOnce(Return(std::vector<BluetoothRemoteGattService*>()))
276 .WillOnce(Return(services)); 269 .WillOnce(Return(services));
277 270
278 // Load and wait for setup. 271 // Load and wait for setup.
279 ExtensionTestMessageListener listener("ready", true); 272 ExtensionTestMessageListener listener("ready", true);
280 listener.set_failure_message("fail"); 273 listener.set_failure_message("fail");
281 ASSERT_TRUE(LoadExtension( 274 ASSERT_TRUE(LoadExtension(
282 test_data_dir_.AppendASCII("bluetooth_low_energy/get_services"))); 275 test_data_dir_.AppendASCII("bluetooth_low_energy/get_services")));
283 EXPECT_TRUE(listener.WaitUntilSatisfied()); 276 EXPECT_TRUE(listener.WaitUntilSatisfied());
284 277
285 listener.Reply("go"); 278 listener.Reply("go");
286 279
287 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 280 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
288 } 281 }
289 282
290 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetService) { 283 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetService) {
291 ResultCatcher catcher; 284 ResultCatcher catcher;
292 catcher.RestrictToBrowserContext(browser()->profile()); 285 catcher.RestrictToBrowserContext(browser()->profile());
293 286
294 event_router()->GattServiceAdded( 287 event_router()->GattServiceAdded(
295 mock_adapter_, device0_.get(), service0_.get()); 288 mock_adapter_, device0_.get(), service0_.get());
296 289
297 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 290 EXPECT_CALL(*mock_adapter_, GetDevice(_))
298 .Times(3) 291 .Times(3)
299 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL))) 292 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL)))
300 .WillRepeatedly(Return(device0_.get())); 293 .WillRepeatedly(Return(device0_.get()));
301 294
302 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 295 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
303 .Times(2) 296 .Times(2)
304 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL))) 297 .WillOnce(Return(static_cast<BluetoothRemoteGattService*>(NULL)))
305 .WillOnce(Return(service0_.get())); 298 .WillOnce(Return(service0_.get()));
306 299
307 // Load and wait for setup. 300 // Load and wait for setup.
308 ExtensionTestMessageListener listener("ready", true); 301 ExtensionTestMessageListener listener("ready", true);
309 listener.set_failure_message("fail"); 302 listener.set_failure_message("fail");
310 ASSERT_TRUE(LoadExtension( 303 ASSERT_TRUE(LoadExtension(
311 test_data_dir_.AppendASCII("bluetooth_low_energy/get_service"))); 304 test_data_dir_.AppendASCII("bluetooth_low_energy/get_service")));
312 EXPECT_TRUE(listener.WaitUntilSatisfied()); 305 EXPECT_TRUE(listener.WaitUntilSatisfied());
313 306
314 listener.Reply("go"); 307 listener.Reply("go");
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 "bluetooth_low_energy/get_included_services"))); 408 "bluetooth_low_energy/get_included_services")));
416 409
417 EXPECT_TRUE(listener.WaitUntilSatisfied()); 410 EXPECT_TRUE(listener.WaitUntilSatisfied());
418 411
419 // Set up for the rest of the calls before replying. Included services can be 412 // Set up for the rest of the calls before replying. Included services can be
420 // returned even if there is no instance ID mapping for them yet, so no need 413 // returned even if there is no instance ID mapping for them yet, so no need
421 // to call GattServiceAdded for |service1_| here. 414 // to call GattServiceAdded for |service1_| here.
422 event_router()->GattServiceAdded( 415 event_router()->GattServiceAdded(
423 mock_adapter_, device0_.get(), service0_.get()); 416 mock_adapter_, device0_.get(), service0_.get());
424 417
425 std::vector<BluetoothGattService*> includes; 418 std::vector<BluetoothRemoteGattService*> includes;
426 includes.push_back(service1_.get()); 419 includes.push_back(service1_.get());
427 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) 420 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0))
428 .Times(2) 421 .Times(2)
429 .WillRepeatedly(Return(device0_.get())); 422 .WillRepeatedly(Return(device0_.get()));
430 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 423 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
431 .Times(2) 424 .Times(2)
432 .WillRepeatedly(Return(service0_.get())); 425 .WillRepeatedly(Return(service0_.get()));
433 EXPECT_CALL(*service0_, GetIncludedServices()) 426 EXPECT_CALL(*service0_, GetIncludedServices())
434 .Times(2) 427 .Times(2)
435 .WillOnce(Return(std::vector<BluetoothGattService*>())) 428 .WillOnce(Return(std::vector<BluetoothRemoteGattService*>()))
436 .WillOnce(Return(includes)); 429 .WillOnce(Return(includes));
437 430
438 listener.Reply("go"); 431 listener.Reply("go");
439 listener.Reset(); 432 listener.Reset();
440 433
441 EXPECT_TRUE(listener.WaitUntilSatisfied()); 434 EXPECT_TRUE(listener.WaitUntilSatisfied());
442 435
443 listener.Reply("go"); 436 listener.Reply("go");
444 437
445 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 438 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
446 event_router()->GattServiceRemoved( 439 event_router()->GattServiceRemoved(
447 mock_adapter_, device0_.get(), service0_.get()); 440 mock_adapter_, device0_.get(), service0_.get());
448 } 441 }
449 442
450 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristics) { 443 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristics) {
451 ResultCatcher catcher; 444 ResultCatcher catcher;
452 catcher.RestrictToBrowserContext(browser()->profile()); 445 catcher.RestrictToBrowserContext(browser()->profile());
453 446
454 std::vector<BluetoothGattCharacteristic*> characteristics; 447 std::vector<BluetoothRemoteGattCharacteristic*> characteristics;
455 characteristics.push_back(chrc0_.get()); 448 characteristics.push_back(chrc0_.get());
456 characteristics.push_back(chrc1_.get()); 449 characteristics.push_back(chrc1_.get());
457 450
458 event_router()->GattServiceAdded( 451 event_router()->GattServiceAdded(
459 mock_adapter_, device0_.get(), service0_.get()); 452 mock_adapter_, device0_.get(), service0_.get());
460 453
461 EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(3).WillRepeatedly( 454 EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(3).WillRepeatedly(
462 Return(device0_.get())); 455 Return(device0_.get()));
463 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 456 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
464 .Times(3) 457 .Times(3)
465 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL))) 458 .WillOnce(Return(static_cast<BluetoothRemoteGattService*>(NULL)))
466 .WillRepeatedly(Return(service0_.get())); 459 .WillRepeatedly(Return(service0_.get()));
467 EXPECT_CALL(*service0_, GetCharacteristics()) 460 EXPECT_CALL(*service0_, GetCharacteristics())
468 .Times(2) 461 .Times(2)
469 .WillOnce(Return(std::vector<BluetoothGattCharacteristic*>())) 462 .WillOnce(Return(std::vector<BluetoothRemoteGattCharacteristic*>()))
470 .WillOnce(Return(characteristics)); 463 .WillOnce(Return(characteristics));
471 464
472 ExtensionTestMessageListener listener("ready", true); 465 ExtensionTestMessageListener listener("ready", true);
473 ASSERT_TRUE(LoadExtension( 466 ASSERT_TRUE(LoadExtension(
474 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristics"))); 467 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristics")));
475 EXPECT_TRUE(listener.WaitUntilSatisfied()); 468 EXPECT_TRUE(listener.WaitUntilSatisfied());
476 469
477 listener.Reply("go"); 470 listener.Reply("go");
478 471
479 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 472 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
480 event_router()->GattServiceRemoved( 473 event_router()->GattServiceRemoved(
481 mock_adapter_, device0_.get(), service0_.get()); 474 mock_adapter_, device0_.get(), service0_.get());
482 } 475 }
483 476
484 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristic) { 477 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristic) {
485 ResultCatcher catcher; 478 ResultCatcher catcher;
486 catcher.RestrictToBrowserContext(browser()->profile()); 479 catcher.RestrictToBrowserContext(browser()->profile());
487 480
488 event_router()->GattServiceAdded( 481 event_router()->GattServiceAdded(
489 mock_adapter_, device0_.get(), service0_.get()); 482 mock_adapter_, device0_.get(), service0_.get());
490 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); 483 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
491 484
492 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 485 EXPECT_CALL(*mock_adapter_, GetDevice(_))
493 .Times(4) 486 .Times(4)
494 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL))) 487 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL)))
495 .WillRepeatedly(Return(device0_.get())); 488 .WillRepeatedly(Return(device0_.get()));
496 489
497 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 490 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
498 .Times(3) 491 .Times(3)
499 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL))) 492 .WillOnce(Return(static_cast<BluetoothRemoteGattService*>(NULL)))
500 .WillRepeatedly(Return(service0_.get())); 493 .WillRepeatedly(Return(service0_.get()));
501 494
502 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 495 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
503 .Times(2) 496 .Times(2)
504 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(NULL))) 497 .WillOnce(Return(static_cast<BluetoothRemoteGattCharacteristic*>(NULL)))
505 .WillOnce(Return(chrc0_.get())); 498 .WillOnce(Return(chrc0_.get()));
506 499
507 // Load the extension and wait for first test. 500 // Load the extension and wait for first test.
508 ExtensionTestMessageListener listener("ready", true); 501 ExtensionTestMessageListener listener("ready", true);
509 listener.set_failure_message("fail"); 502 listener.set_failure_message("fail");
510 ASSERT_TRUE(LoadExtension( 503 ASSERT_TRUE(LoadExtension(
511 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristic"))); 504 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristic")));
512 EXPECT_TRUE(listener.WaitUntilSatisfied()); 505 EXPECT_TRUE(listener.WaitUntilSatisfied());
513 506
514 listener.Reply("go"); 507 listener.Reply("go");
(...skipping 17 matching lines...) Expand all
532 .Times(12) 525 .Times(12)
533 .WillRepeatedly(Return(device0_.get())); 526 .WillRepeatedly(Return(device0_.get()));
534 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 527 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
535 .Times(12) 528 .Times(12)
536 .WillRepeatedly(Return(service0_.get())); 529 .WillRepeatedly(Return(service0_.get()));
537 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 530 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
538 .Times(12) 531 .Times(12)
539 .WillRepeatedly(Return(chrc0_.get())); 532 .WillRepeatedly(Return(chrc0_.get()));
540 EXPECT_CALL(*chrc0_, GetProperties()) 533 EXPECT_CALL(*chrc0_, GetProperties())
541 .Times(12) 534 .Times(12)
542 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_NONE)) 535 .WillOnce(Return(BluetoothRemoteGattCharacteristic::PROPERTY_NONE))
543 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_BROADCAST)) 536 .WillOnce(Return(BluetoothRemoteGattCharacteristic::PROPERTY_BROADCAST))
544 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_READ)) 537 .WillOnce(Return(BluetoothRemoteGattCharacteristic::PROPERTY_READ))
538 .WillOnce(Return(
539 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE))
540 .WillOnce(Return(BluetoothRemoteGattCharacteristic::PROPERTY_WRITE))
541 .WillOnce(Return(BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY))
542 .WillOnce(Return(BluetoothRemoteGattCharacteristic::PROPERTY_INDICATE))
543 .WillOnce(Return(BluetoothRemoteGattCharacteristic::
544 PROPERTY_AUTHENTICATED_SIGNED_WRITES))
545 .WillOnce(Return(
546 BluetoothRemoteGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES))
545 .WillOnce( 547 .WillOnce(
546 Return(BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE)) 548 Return(BluetoothRemoteGattCharacteristic::PROPERTY_RELIABLE_WRITE))
547 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_WRITE))
548 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_NOTIFY))
549 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_INDICATE))
550 .WillOnce(Return( 549 .WillOnce(Return(
551 BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES)) 550 BluetoothRemoteGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES))
552 .WillOnce(
553 Return(BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES))
554 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_RELIABLE_WRITE))
555 .WillOnce(
556 Return(BluetoothGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES))
557 .WillOnce(Return( 551 .WillOnce(Return(
558 BluetoothGattCharacteristic::PROPERTY_BROADCAST | 552 BluetoothRemoteGattCharacteristic::PROPERTY_BROADCAST |
559 BluetoothGattCharacteristic::PROPERTY_READ | 553 BluetoothRemoteGattCharacteristic::PROPERTY_READ |
560 BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE | 554 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE |
561 BluetoothGattCharacteristic::PROPERTY_WRITE | 555 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE |
562 BluetoothGattCharacteristic::PROPERTY_NOTIFY | 556 BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY |
563 BluetoothGattCharacteristic::PROPERTY_INDICATE | 557 BluetoothRemoteGattCharacteristic::PROPERTY_INDICATE |
564 BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES | 558 BluetoothRemoteGattCharacteristic::
565 BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES | 559 PROPERTY_AUTHENTICATED_SIGNED_WRITES |
566 BluetoothGattCharacteristic::PROPERTY_RELIABLE_WRITE | 560 BluetoothRemoteGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES |
567 BluetoothGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES)); 561 BluetoothRemoteGattCharacteristic::PROPERTY_RELIABLE_WRITE |
562 BluetoothRemoteGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES));
568 563
569 ExtensionTestMessageListener listener("ready", true); 564 ExtensionTestMessageListener listener("ready", true);
570 listener.set_failure_message("fail"); 565 listener.set_failure_message("fail");
571 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 566 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
572 "bluetooth_low_energy/characteristic_properties"))); 567 "bluetooth_low_energy/characteristic_properties")));
573 EXPECT_TRUE(listener.WaitUntilSatisfied()); 568 EXPECT_TRUE(listener.WaitUntilSatisfied());
574 569
575 listener.Reply("go"); 570 listener.Reply("go");
576 571
577 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 572 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 .Times(3) 707 .Times(3)
713 .WillRepeatedly(Return(service0_.get())); 708 .WillRepeatedly(Return(service0_.get()));
714 709
715 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 710 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
716 .Times(3) 711 .Times(3)
717 .WillRepeatedly(Return(chrc0_.get())); 712 .WillRepeatedly(Return(chrc0_.get()));
718 713
719 std::vector<uint8_t> value; 714 std::vector<uint8_t> value;
720 EXPECT_CALL(*chrc0_, ReadRemoteCharacteristic(_, _)) 715 EXPECT_CALL(*chrc0_, ReadRemoteCharacteristic(_, _))
721 .Times(2) 716 .Times(2)
722 .WillOnce( 717 .WillOnce(InvokeCallbackArgument<1>(
723 InvokeCallbackArgument<1>(BluetoothGattService::GATT_ERROR_FAILED)) 718 BluetoothRemoteGattService::GATT_ERROR_FAILED))
724 .WillOnce(InvokeCallbackArgument<0>(value)); 719 .WillOnce(InvokeCallbackArgument<0>(value));
725 720
726 ExtensionTestMessageListener listener("ready", true); 721 ExtensionTestMessageListener listener("ready", true);
727 listener.set_failure_message("fail"); 722 listener.set_failure_message("fail");
728 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 723 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
729 "bluetooth_low_energy/read_characteristic_value"))); 724 "bluetooth_low_energy/read_characteristic_value")));
730 listener.WaitUntilSatisfied(); 725 listener.WaitUntilSatisfied();
731 726
732 listener.Reply("go"); 727 listener.Reply("go");
733 728
(...skipping 20 matching lines...) Expand all
754 .Times(3) 749 .Times(3)
755 .WillRepeatedly(Return(service0_.get())); 750 .WillRepeatedly(Return(service0_.get()));
756 751
757 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 752 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
758 .Times(3) 753 .Times(3)
759 .WillRepeatedly(Return(chrc0_.get())); 754 .WillRepeatedly(Return(chrc0_.get()));
760 755
761 std::vector<uint8_t> write_value; 756 std::vector<uint8_t> write_value;
762 EXPECT_CALL(*chrc0_, WriteRemoteCharacteristic(_, _, _)) 757 EXPECT_CALL(*chrc0_, WriteRemoteCharacteristic(_, _, _))
763 .Times(2) 758 .Times(2)
764 .WillOnce( 759 .WillOnce(InvokeCallbackArgument<2>(
765 InvokeCallbackArgument<2>(BluetoothGattService::GATT_ERROR_FAILED)) 760 BluetoothRemoteGattService::GATT_ERROR_FAILED))
766 .WillOnce(DoAll(SaveArg<0>(&write_value), InvokeCallbackArgument<1>())); 761 .WillOnce(DoAll(SaveArg<0>(&write_value), InvokeCallbackArgument<1>()));
767 762
768 EXPECT_CALL(*chrc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value)); 763 EXPECT_CALL(*chrc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value));
769 764
770 ExtensionTestMessageListener listener("ready", true); 765 ExtensionTestMessageListener listener("ready", true);
771 listener.set_failure_message("fail"); 766 listener.set_failure_message("fail");
772 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 767 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
773 "bluetooth_low_energy/write_characteristic_value"))); 768 "bluetooth_low_energy/write_characteristic_value")));
774 EXPECT_TRUE(listener.WaitUntilSatisfied()); 769 EXPECT_TRUE(listener.WaitUntilSatisfied());
775 770
776 listener.Reply("go"); 771 listener.Reply("go");
777 772
778 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 773 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
779 774
780 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); 775 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
781 event_router()->GattServiceRemoved( 776 event_router()->GattServiceRemoved(
782 mock_adapter_, device0_.get(), service0_.get()); 777 mock_adapter_, device0_.get(), service0_.get());
783 } 778 }
784 779
785 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptors) { 780 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptors) {
786 ResultCatcher catcher; 781 ResultCatcher catcher;
787 catcher.RestrictToBrowserContext(browser()->profile()); 782 catcher.RestrictToBrowserContext(browser()->profile());
788 783
789 std::vector<BluetoothGattDescriptor*> descriptors; 784 std::vector<BluetoothRemoteGattDescriptor*> descriptors;
790 descriptors.push_back(desc0_.get()); 785 descriptors.push_back(desc0_.get());
791 descriptors.push_back(desc1_.get()); 786 descriptors.push_back(desc1_.get());
792 787
793 event_router()->GattServiceAdded( 788 event_router()->GattServiceAdded(
794 mock_adapter_, device0_.get(), service0_.get()); 789 mock_adapter_, device0_.get(), service0_.get());
795 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); 790 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
796 791
797 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 792 EXPECT_CALL(*mock_adapter_, GetDevice(_))
798 .Times(3) 793 .Times(3)
799 .WillRepeatedly(Return(device0_.get())); 794 .WillRepeatedly(Return(device0_.get()));
800 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 795 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
801 .Times(3) 796 .Times(3)
802 .WillRepeatedly(Return(service0_.get())); 797 .WillRepeatedly(Return(service0_.get()));
803 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 798 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
804 .Times(3) 799 .Times(3)
805 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(NULL))) 800 .WillOnce(Return(static_cast<BluetoothRemoteGattCharacteristic*>(NULL)))
806 .WillRepeatedly(Return(chrc0_.get())); 801 .WillRepeatedly(Return(chrc0_.get()));
807 EXPECT_CALL(*chrc0_, GetDescriptors()) 802 EXPECT_CALL(*chrc0_, GetDescriptors())
808 .Times(2) 803 .Times(2)
809 .WillOnce(Return(std::vector<BluetoothGattDescriptor*>())) 804 .WillOnce(Return(std::vector<BluetoothRemoteGattDescriptor*>()))
810 .WillOnce(Return(descriptors)); 805 .WillOnce(Return(descriptors));
811 806
812 ExtensionTestMessageListener listener("ready", true); 807 ExtensionTestMessageListener listener("ready", true);
813 listener.set_failure_message("fail"); 808 listener.set_failure_message("fail");
814 ASSERT_TRUE(LoadExtension( 809 ASSERT_TRUE(LoadExtension(
815 test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptors"))); 810 test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptors")));
816 EXPECT_TRUE(listener.WaitUntilSatisfied()); 811 EXPECT_TRUE(listener.WaitUntilSatisfied());
817 812
818 listener.Reply("go"); 813 listener.Reply("go");
819 814
(...skipping 13 matching lines...) Expand all
833 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); 828 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
834 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get()); 829 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get());
835 830
836 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 831 EXPECT_CALL(*mock_adapter_, GetDevice(_))
837 .Times(5) 832 .Times(5)
838 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL))) 833 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL)))
839 .WillRepeatedly(Return(device0_.get())); 834 .WillRepeatedly(Return(device0_.get()));
840 835
841 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 836 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
842 .Times(4) 837 .Times(4)
843 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL))) 838 .WillOnce(Return(static_cast<BluetoothRemoteGattService*>(NULL)))
844 .WillRepeatedly(Return(service0_.get())); 839 .WillRepeatedly(Return(service0_.get()));
845 840
846 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 841 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
847 .Times(3) 842 .Times(3)
848 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(NULL))) 843 .WillOnce(Return(static_cast<BluetoothRemoteGattCharacteristic*>(NULL)))
849 .WillRepeatedly(Return(chrc0_.get())); 844 .WillRepeatedly(Return(chrc0_.get()));
850 845
851 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0)) 846 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0))
852 .Times(2) 847 .Times(2)
853 .WillOnce(Return(static_cast<BluetoothGattDescriptor*>(NULL))) 848 .WillOnce(Return(static_cast<BluetoothRemoteGattDescriptor*>(NULL)))
854 .WillOnce(Return(desc0_.get())); 849 .WillOnce(Return(desc0_.get()));
855 850
856 // Load the extension and wait for first test. 851 // Load the extension and wait for first test.
857 ExtensionTestMessageListener listener("ready", true); 852 ExtensionTestMessageListener listener("ready", true);
858 listener.set_failure_message("fail"); 853 listener.set_failure_message("fail");
859 ASSERT_TRUE(LoadExtension( 854 ASSERT_TRUE(LoadExtension(
860 test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptor"))); 855 test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptor")));
861 EXPECT_TRUE(listener.WaitUntilSatisfied()); 856 EXPECT_TRUE(listener.WaitUntilSatisfied());
862 857
863 listener.Reply("go"); 858 listener.Reply("go");
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 .Times(9) 972 .Times(9)
978 .WillRepeatedly(Return(chrc0_.get())); 973 .WillRepeatedly(Return(chrc0_.get()));
979 974
980 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0)) 975 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0))
981 .Times(9) 976 .Times(9)
982 .WillRepeatedly(Return(desc0_.get())); 977 .WillRepeatedly(Return(desc0_.get()));
983 978
984 std::vector<uint8_t> value; 979 std::vector<uint8_t> value;
985 EXPECT_CALL(*desc0_, ReadRemoteDescriptor(_, _)) 980 EXPECT_CALL(*desc0_, ReadRemoteDescriptor(_, _))
986 .Times(8) 981 .Times(8)
987 .WillOnce(
988 InvokeCallbackArgument<1>(BluetoothGattService::GATT_ERROR_FAILED))
989 .WillOnce(InvokeCallbackArgument<1>( 982 .WillOnce(InvokeCallbackArgument<1>(
990 BluetoothGattService::GATT_ERROR_INVALID_LENGTH)) 983 BluetoothRemoteGattService::GATT_ERROR_FAILED))
991 .WillOnce(InvokeCallbackArgument<1>( 984 .WillOnce(InvokeCallbackArgument<1>(
992 BluetoothGattService::GATT_ERROR_NOT_PERMITTED)) 985 BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH))
993 .WillOnce(InvokeCallbackArgument<1>( 986 .WillOnce(InvokeCallbackArgument<1>(
994 BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED)) 987 BluetoothRemoteGattService::GATT_ERROR_NOT_PERMITTED))
995 .WillOnce(InvokeCallbackArgument<1>( 988 .WillOnce(InvokeCallbackArgument<1>(
996 BluetoothGattService::GATT_ERROR_NOT_PAIRED)) 989 BluetoothRemoteGattService::GATT_ERROR_NOT_AUTHORIZED))
997 .WillOnce(InvokeCallbackArgument<1>( 990 .WillOnce(InvokeCallbackArgument<1>(
998 BluetoothGattService::GATT_ERROR_NOT_SUPPORTED)) 991 BluetoothRemoteGattService::GATT_ERROR_NOT_PAIRED))
999 .WillOnce(InvokeCallbackArgument<1>( 992 .WillOnce(InvokeCallbackArgument<1>(
1000 BluetoothGattService::GATT_ERROR_IN_PROGRESS)) 993 BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED))
994 .WillOnce(InvokeCallbackArgument<1>(
995 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS))
1001 .WillOnce(InvokeCallbackArgument<0>(value)); 996 .WillOnce(InvokeCallbackArgument<0>(value));
1002 997
1003 ExtensionTestMessageListener listener("ready", true); 998 ExtensionTestMessageListener listener("ready", true);
1004 listener.set_failure_message("fail"); 999 listener.set_failure_message("fail");
1005 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 1000 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
1006 "bluetooth_low_energy/read_descriptor_value"))); 1001 "bluetooth_low_energy/read_descriptor_value")));
1007 EXPECT_TRUE(listener.WaitUntilSatisfied()); 1002 EXPECT_TRUE(listener.WaitUntilSatisfied());
1008 1003
1009 listener.Reply("go"); 1004 listener.Reply("go");
1010 1005
(...skipping 26 matching lines...) Expand all
1037 .Times(3) 1032 .Times(3)
1038 .WillRepeatedly(Return(chrc0_.get())); 1033 .WillRepeatedly(Return(chrc0_.get()));
1039 1034
1040 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0)) 1035 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0))
1041 .Times(3) 1036 .Times(3)
1042 .WillRepeatedly(Return(desc0_.get())); 1037 .WillRepeatedly(Return(desc0_.get()));
1043 1038
1044 std::vector<uint8_t> write_value; 1039 std::vector<uint8_t> write_value;
1045 EXPECT_CALL(*desc0_, WriteRemoteDescriptor(_, _, _)) 1040 EXPECT_CALL(*desc0_, WriteRemoteDescriptor(_, _, _))
1046 .Times(2) 1041 .Times(2)
1047 .WillOnce( 1042 .WillOnce(InvokeCallbackArgument<2>(
1048 InvokeCallbackArgument<2>(BluetoothGattService::GATT_ERROR_FAILED)) 1043 BluetoothRemoteGattService::GATT_ERROR_FAILED))
1049 .WillOnce(DoAll(SaveArg<0>(&write_value), InvokeCallbackArgument<1>())); 1044 .WillOnce(DoAll(SaveArg<0>(&write_value), InvokeCallbackArgument<1>()));
1050 1045
1051 EXPECT_CALL(*desc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value)); 1046 EXPECT_CALL(*desc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value));
1052 1047
1053 ExtensionTestMessageListener listener("ready", true); 1048 ExtensionTestMessageListener listener("ready", true);
1054 listener.set_failure_message("fail"); 1049 listener.set_failure_message("fail");
1055 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 1050 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
1056 "bluetooth_low_energy/write_descriptor_value"))); 1051 "bluetooth_low_energy/write_descriptor_value")));
1057 EXPECT_TRUE(listener.WaitUntilSatisfied()); 1052 EXPECT_TRUE(listener.WaitUntilSatisfied());
1058 1053
(...skipping 18 matching lines...) Expand all
1077 1072
1078 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionMethods) { 1073 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionMethods) {
1079 ResultCatcher catcher; 1074 ResultCatcher catcher;
1080 catcher.RestrictToBrowserContext(browser()->profile()); 1075 catcher.RestrictToBrowserContext(browser()->profile());
1081 1076
1082 event_router()->GattServiceAdded( 1077 event_router()->GattServiceAdded(
1083 mock_adapter_, device0_.get(), service0_.get()); 1078 mock_adapter_, device0_.get(), service0_.get());
1084 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); 1079 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
1085 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get()); 1080 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get());
1086 1081
1087 std::vector<BluetoothGattService*> services; 1082 std::vector<BluetoothRemoteGattService*> services;
1088 services.push_back(service0_.get()); 1083 services.push_back(service0_.get());
1089 1084
1090 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 1085 EXPECT_CALL(*mock_adapter_, GetDevice(_))
1091 .WillRepeatedly(Return(device0_.get())); 1086 .WillRepeatedly(Return(device0_.get()));
1092 EXPECT_CALL(*device0_, GetGattServices()).WillOnce(Return(services)); 1087 EXPECT_CALL(*device0_, GetGattServices()).WillOnce(Return(services));
1093 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 1088 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
1094 .WillRepeatedly(Return(service0_.get())); 1089 .WillRepeatedly(Return(service0_.get()));
1095 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 1090 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
1096 .WillRepeatedly(Return(chrc0_.get())); 1091 .WillRepeatedly(Return(chrc0_.get()));
1097 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0)) 1092 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0))
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 MockBluetoothGattNotifySession* session1 = 1286 MockBluetoothGattNotifySession* session1 =
1292 new testing::NiceMock<MockBluetoothGattNotifySession>( 1287 new testing::NiceMock<MockBluetoothGattNotifySession>(
1293 kTestCharacteristicId1); 1288 kTestCharacteristicId1);
1294 1289
1295 EXPECT_CALL(*session1, Stop(_)) 1290 EXPECT_CALL(*session1, Stop(_))
1296 .Times(1) 1291 .Times(1)
1297 .WillOnce(InvokeCallbackArgument<0>()); 1292 .WillOnce(InvokeCallbackArgument<0>());
1298 1293
1299 EXPECT_CALL(*chrc0_, StartNotifySession(_, _)) 1294 EXPECT_CALL(*chrc0_, StartNotifySession(_, _))
1300 .Times(2) 1295 .Times(2)
1301 .WillOnce( 1296 .WillOnce(InvokeCallbackArgument<1>(
1302 InvokeCallbackArgument<1>(BluetoothGattService::GATT_ERROR_FAILED)) 1297 BluetoothRemoteGattService::GATT_ERROR_FAILED))
1303 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattNotifySession>( 1298 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattNotifySession>(
1304 session0)); 1299 session0));
1305 EXPECT_CALL(*chrc1_, StartNotifySession(_, _)) 1300 EXPECT_CALL(*chrc1_, StartNotifySession(_, _))
1306 .Times(1) 1301 .Times(1)
1307 .WillOnce( 1302 .WillOnce(
1308 InvokeCallbackWithScopedPtrArg<0, BluetoothGattNotifySession>( 1303 InvokeCallbackWithScopedPtrArg<0, BluetoothGattNotifySession>(
1309 session1)); 1304 session1));
1310 1305
1311 ExtensionTestMessageListener listener("ready", true); 1306 ExtensionTestMessageListener listener("ready", true);
1312 listener.set_failure_message("fail"); 1307 listener.set_failure_message("fail");
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1363 EXPECT_TRUE(listener.WaitUntilSatisfied()); 1358 EXPECT_TRUE(listener.WaitUntilSatisfied());
1364 1359
1365 listener.Reply("go"); 1360 listener.Reply("go");
1366 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1361 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
1367 1362
1368 event_router()->GattServiceRemoved(mock_adapter_, device0_.get(), 1363 event_router()->GattServiceRemoved(mock_adapter_, device0_.get(),
1369 service0_.get()); 1364 service0_.get());
1370 } 1365 }
1371 1366
1372 } // namespace 1367 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698