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/api/bluetooth_low_energy/bluetooth_low_energ y_api.h" | 6 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h" |
7 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h" | 7 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/browser/extensions/extension_function_test_utils.h" | 9 #include "chrome/browser/extensions/extension_function_test_utils.h" |
10 #include "chrome/browser/extensions/extension_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_test_message_listener.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_device.h" | 12 #include "device/bluetooth/test/mock_bluetooth_device.h" |
13 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h" | 13 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h" |
14 #include "device/bluetooth/test/mock_bluetooth_gatt_service.h" | 14 #include "device/bluetooth/test/mock_bluetooth_gatt_service.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 | 16 |
17 using device::BluetoothUUID; | 17 using device::BluetoothUUID; |
18 using device::BluetoothAdapter; | 18 using device::BluetoothAdapter; |
19 using device::BluetoothDevice; | 19 using device::BluetoothDevice; |
20 using device::BluetoothGattCharacteristic; | 20 using device::BluetoothGattCharacteristic; |
21 using device::BluetoothGattService; | 21 using device::BluetoothGattService; |
22 using device::MockBluetoothAdapter; | 22 using device::MockBluetoothAdapter; |
23 using device::MockBluetoothDevice; | 23 using device::MockBluetoothDevice; |
24 using device::MockBluetoothGattCharacteristic; | 24 using device::MockBluetoothGattCharacteristic; |
25 using device::MockBluetoothGattService; | 25 using device::MockBluetoothGattService; |
26 using testing::Return; | 26 using testing::Return; |
27 using testing::ReturnRef; | |
27 using testing::ReturnRefOfCopy; | 28 using testing::ReturnRefOfCopy; |
29 using testing::SaveArg; | |
28 using testing::_; | 30 using testing::_; |
29 | 31 |
30 namespace utils = extension_function_test_utils; | 32 namespace utils = extension_function_test_utils; |
31 | 33 |
32 namespace { | 34 namespace { |
33 | 35 |
34 const char kTestLeDeviceAddress[] = "11:22:33:44:55:66"; | 36 const char kTestLeDeviceAddress[] = "11:22:33:44:55:66"; |
35 const char kTestLeDeviceName[] = "Test LE Device"; | 37 const char kTestLeDeviceName[] = "Test LE Device"; |
36 | 38 |
37 const char kTestServiceId0[] = "service_id0"; | 39 const char kTestServiceId0[] = "service_id0"; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 scoped_ptr<testing::NiceMock<MockBluetoothGattService> > service0_; | 158 scoped_ptr<testing::NiceMock<MockBluetoothGattService> > service0_; |
157 scoped_ptr<testing::NiceMock<MockBluetoothGattService> > service1_; | 159 scoped_ptr<testing::NiceMock<MockBluetoothGattService> > service1_; |
158 scoped_ptr<testing::NiceMock<MockBluetoothGattCharacteristic> > chrc0_; | 160 scoped_ptr<testing::NiceMock<MockBluetoothGattCharacteristic> > chrc0_; |
159 scoped_ptr<testing::NiceMock<MockBluetoothGattCharacteristic> > chrc1_; | 161 scoped_ptr<testing::NiceMock<MockBluetoothGattCharacteristic> > chrc1_; |
160 scoped_ptr<testing::NiceMock<MockBluetoothGattCharacteristic> > chrc2_; | 162 scoped_ptr<testing::NiceMock<MockBluetoothGattCharacteristic> > chrc2_; |
161 | 163 |
162 private: | 164 private: |
163 scoped_refptr<extensions::Extension> empty_extension_; | 165 scoped_refptr<extensions::Extension> empty_extension_; |
164 }; | 166 }; |
165 | 167 |
168 void WriteValueSuccessCallback(const std::vector<uint8>& value, | |
169 const base::Closure& callback, | |
170 const base::Closure& error_callback) { | |
171 callback.Run(); | |
172 } | |
173 | |
174 void WriteValueErrorCallback(const std::vector<uint8>& value, | |
175 const base::Closure& callback, | |
176 const base::Closure& error_callback) { | |
177 error_callback.Run(); | |
178 } | |
179 | |
166 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) { | 180 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) { |
167 ResultCatcher catcher; | 181 ResultCatcher catcher; |
168 catcher.RestrictToProfile(browser()->profile()); | 182 catcher.RestrictToProfile(browser()->profile()); |
169 | 183 |
170 std::vector<BluetoothGattService*> services; | 184 std::vector<BluetoothGattService*> services; |
171 services.push_back(service0_.get()); | 185 services.push_back(service0_.get()); |
172 services.push_back(service1_.get()); | 186 services.push_back(service1_.get()); |
173 | 187 |
174 EXPECT_CALL(*mock_adapter_, GetDevice(_)) | 188 EXPECT_CALL(*mock_adapter_, GetDevice(_)) |
175 .Times(3) | 189 .Times(3) |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 | 472 |
459 listener.Reply("go"); | 473 listener.Reply("go"); |
460 | 474 |
461 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 475 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
462 | 476 |
463 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); | 477 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); |
464 event_router()->GattServiceRemoved(device_.get(), service0_.get()); | 478 event_router()->GattServiceRemoved(device_.get(), service0_.get()); |
465 event_router()->DeviceRemoved(mock_adapter_, device_.get()); | 479 event_router()->DeviceRemoved(mock_adapter_, device_.get()); |
466 } | 480 } |
467 | 481 |
482 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteCharacteristicValue) { | |
483 ResultCatcher catcher; | |
484 catcher.RestrictToProfile(browser()->profile()); | |
485 | |
486 event_router()->DeviceAdded(mock_adapter_, device_.get()); | |
487 event_router()->GattServiceAdded(device_.get(), service0_.get()); | |
488 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); | |
489 | |
490 EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(3).WillRepeatedly( | |
keybuk
2014/05/06 16:44:19
nit: break across multiple lines
armansito
2014/05/06 19:26:36
Done.
| |
491 Return(device_.get())); | |
492 | |
493 EXPECT_CALL(*device_, GetGattService(kTestServiceId0)) | |
494 .Times(3) | |
495 .WillRepeatedly(Return(service0_.get())); | |
496 | |
497 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) | |
498 .Times(3) | |
499 .WillRepeatedly(Return(chrc0_.get())); | |
500 | |
501 std::vector<uint8> write_value; | |
502 EXPECT_CALL(*chrc0_, WriteRemoteCharacteristic(_, _, _)) | |
503 .Times(2) | |
504 .WillOnce(Invoke(&WriteValueErrorCallback)) | |
505 .WillOnce( | |
506 DoAll(SaveArg<0>(&write_value), Invoke(&WriteValueSuccessCallback))); | |
507 EXPECT_CALL(*chrc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value)); | |
508 | |
509 ExtensionTestMessageListener listener("ready", true); | |
510 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | |
511 "bluetooth_low_energy/write_characteristic_value"))); | |
512 EXPECT_TRUE(listener.WaitUntilSatisfied()); | |
513 | |
514 listener.Reply("go"); | |
515 | |
516 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | |
517 | |
518 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); | |
519 event_router()->GattServiceRemoved(device_.get(), service0_.get()); | |
520 event_router()->DeviceRemoved(mock_adapter_, device_.get()); | |
521 } | |
522 | |
468 } // namespace | 523 } // namespace |
OLD | NEW |