OLD | NEW |
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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 7 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
8 #include "device/bluetooth/test/mock_bluetooth_device.h" | 8 #include "device/bluetooth/test/mock_bluetooth_device.h" |
9 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h" | 9 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h" |
10 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" | 10 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) { | 261 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) { |
262 ResultCatcher catcher; | 262 ResultCatcher catcher; |
263 catcher.RestrictToBrowserContext(browser()->profile()); | 263 catcher.RestrictToBrowserContext(browser()->profile()); |
264 | 264 |
265 std::vector<BluetoothGattService*> services; | 265 std::vector<BluetoothGattService*> services; |
266 services.push_back(service0_.get()); | 266 services.push_back(service0_.get()); |
267 services.push_back(service1_.get()); | 267 services.push_back(service1_.get()); |
268 | 268 |
269 EXPECT_CALL(*mock_adapter_, GetDevice(_)) | 269 EXPECT_CALL(*mock_adapter_, GetDevice(_)) |
270 .Times(3) | 270 .Times(3) |
271 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL))) | 271 .WillOnce(Return(static_cast<BluetoothDevice*>(nullptr))) |
272 .WillRepeatedly(Return(device0_.get())); | 272 .WillRepeatedly(Return(device0_.get())); |
273 | 273 |
274 EXPECT_CALL(*device0_, GetGattServices()) | 274 EXPECT_CALL(*device0_, GetGattServices()) |
275 .Times(2) | 275 .Times(2) |
276 .WillOnce(Return(std::vector<BluetoothGattService*>())) | 276 .WillOnce(Return(std::vector<BluetoothGattService*>())) |
277 .WillOnce(Return(services)); | 277 .WillOnce(Return(services)); |
278 | 278 |
279 // Load and wait for setup. | 279 // Load and wait for setup. |
280 ExtensionTestMessageListener listener("ready", true); | 280 ExtensionTestMessageListener listener("ready", true); |
281 ASSERT_TRUE(LoadExtension( | 281 ASSERT_TRUE(LoadExtension( |
282 test_data_dir_.AppendASCII("bluetooth_low_energy/get_services"))); | 282 test_data_dir_.AppendASCII("bluetooth_low_energy/get_services"))); |
283 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 283 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
284 | 284 |
285 listener.Reply("go"); | 285 listener.Reply("go"); |
286 | 286 |
287 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 287 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
288 } | 288 } |
289 | 289 |
290 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetService) { | 290 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetService) { |
291 ResultCatcher catcher; | 291 ResultCatcher catcher; |
292 catcher.RestrictToBrowserContext(browser()->profile()); | 292 catcher.RestrictToBrowserContext(browser()->profile()); |
293 | 293 |
294 event_router()->GattServiceAdded( | 294 event_router()->GattServiceAdded( |
295 mock_adapter_, device0_.get(), service0_.get()); | 295 mock_adapter_, device0_.get(), service0_.get()); |
296 | 296 |
297 EXPECT_CALL(*mock_adapter_, GetDevice(_)) | 297 EXPECT_CALL(*mock_adapter_, GetDevice(_)) |
298 .Times(3) | 298 .Times(3) |
299 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL))) | 299 .WillOnce(Return(static_cast<BluetoothDevice*>(nullptr))) |
300 .WillRepeatedly(Return(device0_.get())); | 300 .WillRepeatedly(Return(device0_.get())); |
301 | 301 |
302 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) | 302 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) |
303 .Times(2) | 303 .Times(2) |
304 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL))) | 304 .WillOnce(Return(static_cast<BluetoothGattService*>(nullptr))) |
305 .WillOnce(Return(service0_.get())); | 305 .WillOnce(Return(service0_.get())); |
306 | 306 |
307 // Load and wait for setup. | 307 // Load and wait for setup. |
308 ExtensionTestMessageListener listener("ready", true); | 308 ExtensionTestMessageListener listener("ready", true); |
309 ASSERT_TRUE(LoadExtension( | 309 ASSERT_TRUE(LoadExtension( |
310 test_data_dir_.AppendASCII("bluetooth_low_energy/get_service"))); | 310 test_data_dir_.AppendASCII("bluetooth_low_energy/get_service"))); |
311 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 311 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
312 | 312 |
313 listener.Reply("go"); | 313 listener.Reply("go"); |
314 | 314 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 characteristics.push_back(chrc0_.get()); | 449 characteristics.push_back(chrc0_.get()); |
450 characteristics.push_back(chrc1_.get()); | 450 characteristics.push_back(chrc1_.get()); |
451 | 451 |
452 event_router()->GattServiceAdded( | 452 event_router()->GattServiceAdded( |
453 mock_adapter_, device0_.get(), service0_.get()); | 453 mock_adapter_, device0_.get(), service0_.get()); |
454 | 454 |
455 EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(3).WillRepeatedly( | 455 EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(3).WillRepeatedly( |
456 Return(device0_.get())); | 456 Return(device0_.get())); |
457 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) | 457 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) |
458 .Times(3) | 458 .Times(3) |
459 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL))) | 459 .WillOnce(Return(static_cast<BluetoothGattService*>(nullptr))) |
460 .WillRepeatedly(Return(service0_.get())); | 460 .WillRepeatedly(Return(service0_.get())); |
461 EXPECT_CALL(*service0_, GetCharacteristics()) | 461 EXPECT_CALL(*service0_, GetCharacteristics()) |
462 .Times(2) | 462 .Times(2) |
463 .WillOnce(Return(std::vector<BluetoothGattCharacteristic*>())) | 463 .WillOnce(Return(std::vector<BluetoothGattCharacteristic*>())) |
464 .WillOnce(Return(characteristics)); | 464 .WillOnce(Return(characteristics)); |
465 | 465 |
466 ExtensionTestMessageListener listener("ready", true); | 466 ExtensionTestMessageListener listener("ready", true); |
467 ASSERT_TRUE(LoadExtension( | 467 ASSERT_TRUE(LoadExtension( |
468 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristics"))); | 468 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristics"))); |
469 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 469 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
470 | 470 |
471 listener.Reply("go"); | 471 listener.Reply("go"); |
472 | 472 |
473 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 473 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
474 event_router()->GattServiceRemoved( | 474 event_router()->GattServiceRemoved( |
475 mock_adapter_, device0_.get(), service0_.get()); | 475 mock_adapter_, device0_.get(), service0_.get()); |
476 } | 476 } |
477 | 477 |
478 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristic) { | 478 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristic) { |
479 ResultCatcher catcher; | 479 ResultCatcher catcher; |
480 catcher.RestrictToBrowserContext(browser()->profile()); | 480 catcher.RestrictToBrowserContext(browser()->profile()); |
481 | 481 |
482 event_router()->GattServiceAdded( | 482 event_router()->GattServiceAdded( |
483 mock_adapter_, device0_.get(), service0_.get()); | 483 mock_adapter_, device0_.get(), service0_.get()); |
484 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); | 484 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); |
485 | 485 |
486 EXPECT_CALL(*mock_adapter_, GetDevice(_)) | 486 EXPECT_CALL(*mock_adapter_, GetDevice(_)) |
487 .Times(4) | 487 .Times(4) |
488 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL))) | 488 .WillOnce(Return(static_cast<BluetoothDevice*>(nullptr))) |
489 .WillRepeatedly(Return(device0_.get())); | 489 .WillRepeatedly(Return(device0_.get())); |
490 | 490 |
491 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) | 491 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) |
492 .Times(3) | 492 .Times(3) |
493 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL))) | 493 .WillOnce(Return(static_cast<BluetoothGattService*>(nullptr))) |
494 .WillRepeatedly(Return(service0_.get())); | 494 .WillRepeatedly(Return(service0_.get())); |
495 | 495 |
496 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) | 496 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) |
497 .Times(2) | 497 .Times(2) |
498 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(NULL))) | 498 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(nullptr))) |
499 .WillOnce(Return(chrc0_.get())); | 499 .WillOnce(Return(chrc0_.get())); |
500 | 500 |
501 // Load the extension and wait for first test. | 501 // Load the extension and wait for first test. |
502 ExtensionTestMessageListener listener("ready", true); | 502 ExtensionTestMessageListener listener("ready", true); |
503 ASSERT_TRUE(LoadExtension( | 503 ASSERT_TRUE(LoadExtension( |
504 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristic"))); | 504 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristic"))); |
505 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 505 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
506 | 506 |
507 listener.Reply("go"); | 507 listener.Reply("go"); |
508 | 508 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); | 781 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); |
782 | 782 |
783 EXPECT_CALL(*mock_adapter_, GetDevice(_)) | 783 EXPECT_CALL(*mock_adapter_, GetDevice(_)) |
784 .Times(3) | 784 .Times(3) |
785 .WillRepeatedly(Return(device0_.get())); | 785 .WillRepeatedly(Return(device0_.get())); |
786 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) | 786 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) |
787 .Times(3) | 787 .Times(3) |
788 .WillRepeatedly(Return(service0_.get())); | 788 .WillRepeatedly(Return(service0_.get())); |
789 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) | 789 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) |
790 .Times(3) | 790 .Times(3) |
791 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(NULL))) | 791 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(nullptr))) |
792 .WillRepeatedly(Return(chrc0_.get())); | 792 .WillRepeatedly(Return(chrc0_.get())); |
793 EXPECT_CALL(*chrc0_, GetDescriptors()) | 793 EXPECT_CALL(*chrc0_, GetDescriptors()) |
794 .Times(2) | 794 .Times(2) |
795 .WillOnce(Return(std::vector<BluetoothGattDescriptor*>())) | 795 .WillOnce(Return(std::vector<BluetoothGattDescriptor*>())) |
796 .WillOnce(Return(descriptors)); | 796 .WillOnce(Return(descriptors)); |
797 | 797 |
798 ExtensionTestMessageListener listener("ready", true); | 798 ExtensionTestMessageListener listener("ready", true); |
799 ASSERT_TRUE(LoadExtension( | 799 ASSERT_TRUE(LoadExtension( |
800 test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptors"))); | 800 test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptors"))); |
801 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 801 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
(...skipping 11 matching lines...) Expand all Loading... |
813 ResultCatcher catcher; | 813 ResultCatcher catcher; |
814 catcher.RestrictToBrowserContext(browser()->profile()); | 814 catcher.RestrictToBrowserContext(browser()->profile()); |
815 | 815 |
816 event_router()->GattServiceAdded( | 816 event_router()->GattServiceAdded( |
817 mock_adapter_, device0_.get(), service0_.get()); | 817 mock_adapter_, device0_.get(), service0_.get()); |
818 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); | 818 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); |
819 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get()); | 819 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get()); |
820 | 820 |
821 EXPECT_CALL(*mock_adapter_, GetDevice(_)) | 821 EXPECT_CALL(*mock_adapter_, GetDevice(_)) |
822 .Times(5) | 822 .Times(5) |
823 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL))) | 823 .WillOnce(Return(static_cast<BluetoothDevice*>(nullptr))) |
824 .WillRepeatedly(Return(device0_.get())); | 824 .WillRepeatedly(Return(device0_.get())); |
825 | 825 |
826 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) | 826 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) |
827 .Times(4) | 827 .Times(4) |
828 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL))) | 828 .WillOnce(Return(static_cast<BluetoothGattService*>(nullptr))) |
829 .WillRepeatedly(Return(service0_.get())); | 829 .WillRepeatedly(Return(service0_.get())); |
830 | 830 |
831 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) | 831 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) |
832 .Times(3) | 832 .Times(3) |
833 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(NULL))) | 833 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(nullptr))) |
834 .WillRepeatedly(Return(chrc0_.get())); | 834 .WillRepeatedly(Return(chrc0_.get())); |
835 | 835 |
836 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0)) | 836 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0)) |
837 .Times(2) | 837 .Times(2) |
838 .WillOnce(Return(static_cast<BluetoothGattDescriptor*>(NULL))) | 838 .WillOnce(Return(static_cast<BluetoothGattDescriptor*>(nullptr))) |
839 .WillOnce(Return(desc0_.get())); | 839 .WillOnce(Return(desc0_.get())); |
840 | 840 |
841 // Load the extension and wait for first test. | 841 // Load the extension and wait for first test. |
842 ExtensionTestMessageListener listener("ready", true); | 842 ExtensionTestMessageListener listener("ready", true); |
843 ASSERT_TRUE(LoadExtension( | 843 ASSERT_TRUE(LoadExtension( |
844 test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptor"))); | 844 test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptor"))); |
845 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 845 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
846 | 846 |
847 listener.Reply("go"); | 847 listener.Reply("go"); |
848 | 848 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); | 1102 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); |
1103 event_router()->GattServiceRemoved( | 1103 event_router()->GattServiceRemoved( |
1104 mock_adapter_, device0_.get(), service0_.get()); | 1104 mock_adapter_, device0_.get(), service0_.get()); |
1105 } | 1105 } |
1106 | 1106 |
1107 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GattConnection) { | 1107 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GattConnection) { |
1108 ResultCatcher catcher; | 1108 ResultCatcher catcher; |
1109 catcher.RestrictToBrowserContext(browser()->profile()); | 1109 catcher.RestrictToBrowserContext(browser()->profile()); |
1110 | 1110 |
1111 EXPECT_CALL(*mock_adapter_, GetDevice(_)) | 1111 EXPECT_CALL(*mock_adapter_, GetDevice(_)) |
1112 .WillRepeatedly(Return(static_cast<BluetoothDevice*>(NULL))); | 1112 .WillRepeatedly(Return(static_cast<BluetoothDevice*>(nullptr))); |
1113 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) | 1113 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) |
1114 .WillRepeatedly(Return(device0_.get())); | 1114 .WillRepeatedly(Return(device0_.get())); |
1115 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress1)) | 1115 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress1)) |
1116 .WillRepeatedly(Return(device1_.get())); | 1116 .WillRepeatedly(Return(device1_.get())); |
1117 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) | 1117 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) |
1118 .Times(3) | 1118 .Times(3) |
1119 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_FAILED)) | 1119 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_FAILED)) |
1120 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( | 1120 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( |
1121 CreateGattConnection(kTestLeDeviceAddress0, | 1121 CreateGattConnection(kTestLeDeviceAddress0, |
1122 true /* expect_disconnect */))) | 1122 true /* expect_disconnect */))) |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get()); | 1269 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get()); |
1270 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc1_.get()); | 1270 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc1_.get()); |
1271 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); | 1271 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); |
1272 event_router()->GattServiceRemoved( | 1272 event_router()->GattServiceRemoved( |
1273 mock_adapter_, device0_.get(), service1_.get()); | 1273 mock_adapter_, device0_.get(), service1_.get()); |
1274 event_router()->GattServiceRemoved( | 1274 event_router()->GattServiceRemoved( |
1275 mock_adapter_, device0_.get(), service0_.get()); | 1275 mock_adapter_, device0_.get(), service0_.get()); |
1276 } | 1276 } |
1277 | 1277 |
1278 } // namespace | 1278 } // namespace |
OLD | NEW |