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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 .Times(3) | 712 .Times(3) |
713 .WillRepeatedly(Return(service0_.get())); | 713 .WillRepeatedly(Return(service0_.get())); |
714 | 714 |
715 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) | 715 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) |
716 .Times(3) | 716 .Times(3) |
717 .WillRepeatedly(Return(chrc0_.get())); | 717 .WillRepeatedly(Return(chrc0_.get())); |
718 | 718 |
719 std::vector<uint8> value; | 719 std::vector<uint8> value; |
720 EXPECT_CALL(*chrc0_, ReadRemoteCharacteristic(_, _)) | 720 EXPECT_CALL(*chrc0_, ReadRemoteCharacteristic(_, _)) |
721 .Times(2) | 721 .Times(2) |
722 .WillOnce(InvokeCallbackArgument<1>( | 722 .WillOnce( |
723 BluetoothGattService::GattErrorCode::GATT_ERROR_FAILED)) | 723 InvokeCallbackArgument<1>(BluetoothGattService::GATT_ERROR_FAILED)) |
724 .WillOnce(InvokeCallbackArgument<0>(value)); | 724 .WillOnce(InvokeCallbackArgument<0>(value)); |
725 | 725 |
726 ExtensionTestMessageListener listener("ready", true); | 726 ExtensionTestMessageListener listener("ready", true); |
727 listener.set_failure_message("fail"); | 727 listener.set_failure_message("fail"); |
728 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 728 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
729 "bluetooth_low_energy/read_characteristic_value"))); | 729 "bluetooth_low_energy/read_characteristic_value"))); |
730 listener.WaitUntilSatisfied(); | 730 listener.WaitUntilSatisfied(); |
731 | 731 |
732 listener.Reply("go"); | 732 listener.Reply("go"); |
733 | 733 |
(...skipping 20 matching lines...) Expand all Loading... |
754 .Times(3) | 754 .Times(3) |
755 .WillRepeatedly(Return(service0_.get())); | 755 .WillRepeatedly(Return(service0_.get())); |
756 | 756 |
757 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) | 757 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) |
758 .Times(3) | 758 .Times(3) |
759 .WillRepeatedly(Return(chrc0_.get())); | 759 .WillRepeatedly(Return(chrc0_.get())); |
760 | 760 |
761 std::vector<uint8> write_value; | 761 std::vector<uint8> write_value; |
762 EXPECT_CALL(*chrc0_, WriteRemoteCharacteristic(_, _, _)) | 762 EXPECT_CALL(*chrc0_, WriteRemoteCharacteristic(_, _, _)) |
763 .Times(2) | 763 .Times(2) |
764 .WillOnce(InvokeCallbackArgument<2>( | 764 .WillOnce( |
765 BluetoothGattService::GattErrorCode::GATT_ERROR_FAILED)) | 765 InvokeCallbackArgument<2>(BluetoothGattService::GATT_ERROR_FAILED)) |
766 .WillOnce(DoAll(SaveArg<0>(&write_value), InvokeCallbackArgument<1>())); | 766 .WillOnce(DoAll(SaveArg<0>(&write_value), InvokeCallbackArgument<1>())); |
767 | 767 |
768 EXPECT_CALL(*chrc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value)); | 768 EXPECT_CALL(*chrc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value)); |
769 | 769 |
770 ExtensionTestMessageListener listener("ready", true); | 770 ExtensionTestMessageListener listener("ready", true); |
771 listener.set_failure_message("fail"); | 771 listener.set_failure_message("fail"); |
772 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 772 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
773 "bluetooth_low_energy/write_characteristic_value"))); | 773 "bluetooth_low_energy/write_characteristic_value"))); |
774 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 774 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
775 | 775 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadDescriptorValue) { | 959 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadDescriptorValue) { |
960 ResultCatcher catcher; | 960 ResultCatcher catcher; |
961 catcher.RestrictToBrowserContext(browser()->profile()); | 961 catcher.RestrictToBrowserContext(browser()->profile()); |
962 | 962 |
963 event_router()->GattServiceAdded( | 963 event_router()->GattServiceAdded( |
964 mock_adapter_, device0_.get(), service0_.get()); | 964 mock_adapter_, device0_.get(), service0_.get()); |
965 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); | 965 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); |
966 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get()); | 966 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get()); |
967 | 967 |
968 EXPECT_CALL(*mock_adapter_, GetDevice(_)) | 968 EXPECT_CALL(*mock_adapter_, GetDevice(_)) |
969 .Times(3) | 969 .Times(9) |
970 .WillRepeatedly(Return(device0_.get())); | 970 .WillRepeatedly(Return(device0_.get())); |
971 | 971 |
972 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) | 972 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) |
973 .Times(3) | 973 .Times(9) |
974 .WillRepeatedly(Return(service0_.get())); | 974 .WillRepeatedly(Return(service0_.get())); |
975 | 975 |
976 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) | 976 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) |
977 .Times(3) | 977 .Times(9) |
978 .WillRepeatedly(Return(chrc0_.get())); | 978 .WillRepeatedly(Return(chrc0_.get())); |
979 | 979 |
980 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0)) | 980 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0)) |
981 .Times(3) | 981 .Times(9) |
982 .WillRepeatedly(Return(desc0_.get())); | 982 .WillRepeatedly(Return(desc0_.get())); |
983 | 983 |
984 std::vector<uint8> value; | 984 std::vector<uint8> value; |
985 EXPECT_CALL(*desc0_, ReadRemoteDescriptor(_, _)) | 985 EXPECT_CALL(*desc0_, ReadRemoteDescriptor(_, _)) |
986 .Times(2) | 986 .Times(8) |
| 987 .WillOnce( |
| 988 InvokeCallbackArgument<1>(BluetoothGattService::GATT_ERROR_FAILED)) |
987 .WillOnce(InvokeCallbackArgument<1>( | 989 .WillOnce(InvokeCallbackArgument<1>( |
988 BluetoothGattService::GattErrorCode::GATT_ERROR_FAILED)) | 990 BluetoothGattService::GATT_ERROR_INVALID_LENGTH)) |
| 991 .WillOnce(InvokeCallbackArgument<1>( |
| 992 BluetoothGattService::GATT_ERROR_NOT_PERMITTED)) |
| 993 .WillOnce(InvokeCallbackArgument<1>( |
| 994 BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED)) |
| 995 .WillOnce(InvokeCallbackArgument<1>( |
| 996 BluetoothGattService::GATT_ERROR_NOT_PAIRED)) |
| 997 .WillOnce(InvokeCallbackArgument<1>( |
| 998 BluetoothGattService::GATT_ERROR_NOT_SUPPORTED)) |
| 999 .WillOnce(InvokeCallbackArgument<1>( |
| 1000 BluetoothGattService::GATT_ERROR_IN_PROGRESS)) |
989 .WillOnce(InvokeCallbackArgument<0>(value)); | 1001 .WillOnce(InvokeCallbackArgument<0>(value)); |
990 | 1002 |
991 ExtensionTestMessageListener listener("ready", true); | 1003 ExtensionTestMessageListener listener("ready", true); |
992 listener.set_failure_message("fail"); | 1004 listener.set_failure_message("fail"); |
993 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 1005 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
994 "bluetooth_low_energy/read_descriptor_value"))); | 1006 "bluetooth_low_energy/read_descriptor_value"))); |
995 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 1007 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
996 | 1008 |
997 listener.Reply("go"); | 1009 listener.Reply("go"); |
998 | 1010 |
(...skipping 26 matching lines...) Expand all Loading... |
1025 .Times(3) | 1037 .Times(3) |
1026 .WillRepeatedly(Return(chrc0_.get())); | 1038 .WillRepeatedly(Return(chrc0_.get())); |
1027 | 1039 |
1028 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0)) | 1040 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0)) |
1029 .Times(3) | 1041 .Times(3) |
1030 .WillRepeatedly(Return(desc0_.get())); | 1042 .WillRepeatedly(Return(desc0_.get())); |
1031 | 1043 |
1032 std::vector<uint8> write_value; | 1044 std::vector<uint8> write_value; |
1033 EXPECT_CALL(*desc0_, WriteRemoteDescriptor(_, _, _)) | 1045 EXPECT_CALL(*desc0_, WriteRemoteDescriptor(_, _, _)) |
1034 .Times(2) | 1046 .Times(2) |
1035 .WillOnce(InvokeCallbackArgument<2>( | 1047 .WillOnce( |
1036 BluetoothGattService::GattErrorCode::GATT_ERROR_FAILED)) | 1048 InvokeCallbackArgument<2>(BluetoothGattService::GATT_ERROR_FAILED)) |
1037 .WillOnce(DoAll(SaveArg<0>(&write_value), InvokeCallbackArgument<1>())); | 1049 .WillOnce(DoAll(SaveArg<0>(&write_value), InvokeCallbackArgument<1>())); |
1038 | 1050 |
1039 EXPECT_CALL(*desc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value)); | 1051 EXPECT_CALL(*desc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value)); |
1040 | 1052 |
1041 ExtensionTestMessageListener listener("ready", true); | 1053 ExtensionTestMessageListener listener("ready", true); |
1042 listener.set_failure_message("fail"); | 1054 listener.set_failure_message("fail"); |
1043 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 1055 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
1044 "bluetooth_low_energy/write_descriptor_value"))); | 1056 "bluetooth_low_energy/write_descriptor_value"))); |
1045 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 1057 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
1046 | 1058 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 ResultCatcher catcher; | 1143 ResultCatcher catcher; |
1132 catcher.RestrictToBrowserContext(browser()->profile()); | 1144 catcher.RestrictToBrowserContext(browser()->profile()); |
1133 | 1145 |
1134 EXPECT_CALL(*mock_adapter_, GetDevice(_)) | 1146 EXPECT_CALL(*mock_adapter_, GetDevice(_)) |
1135 .WillRepeatedly(Return(static_cast<BluetoothDevice*>(NULL))); | 1147 .WillRepeatedly(Return(static_cast<BluetoothDevice*>(NULL))); |
1136 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) | 1148 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) |
1137 .WillRepeatedly(Return(device0_.get())); | 1149 .WillRepeatedly(Return(device0_.get())); |
1138 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress1)) | 1150 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress1)) |
1139 .WillRepeatedly(Return(device1_.get())); | 1151 .WillRepeatedly(Return(device1_.get())); |
1140 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) | 1152 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) |
1141 .Times(3) | 1153 .Times(9) |
1142 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_FAILED)) | 1154 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_FAILED)) |
| 1155 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_INPROGRESS)) |
| 1156 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_FAILED)) |
| 1157 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_REJECTED)) |
| 1158 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_CANCELED)) |
| 1159 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_TIMEOUT)) |
| 1160 .WillOnce( |
| 1161 InvokeCallbackArgument<1>(BluetoothDevice::ERROR_UNSUPPORTED_DEVICE)) |
1143 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( | 1162 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( |
1144 CreateGattConnection(kTestLeDeviceAddress0, | 1163 CreateGattConnection(kTestLeDeviceAddress0, |
1145 true /* expect_disconnect */))) | 1164 true /* expect_disconnect */))) |
1146 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( | 1165 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( |
1147 CreateGattConnection(kTestLeDeviceAddress0, | 1166 CreateGattConnection(kTestLeDeviceAddress0, |
1148 false /* expect_disconnect */))); | 1167 false /* expect_disconnect */))); |
1149 EXPECT_CALL(*device1_, CreateGattConnection(_, _)) | 1168 EXPECT_CALL(*device1_, CreateGattConnection(_, _)) |
1150 .Times(1) | 1169 .Times(1) |
1151 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( | 1170 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( |
1152 CreateGattConnection(kTestLeDeviceAddress1, | 1171 CreateGattConnection(kTestLeDeviceAddress1, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 MockBluetoothGattNotifySession* session1 = | 1276 MockBluetoothGattNotifySession* session1 = |
1258 new testing::NiceMock<MockBluetoothGattNotifySession>( | 1277 new testing::NiceMock<MockBluetoothGattNotifySession>( |
1259 kTestCharacteristicId1); | 1278 kTestCharacteristicId1); |
1260 | 1279 |
1261 EXPECT_CALL(*session1, Stop(_)) | 1280 EXPECT_CALL(*session1, Stop(_)) |
1262 .Times(1) | 1281 .Times(1) |
1263 .WillOnce(InvokeCallbackArgument<0>()); | 1282 .WillOnce(InvokeCallbackArgument<0>()); |
1264 | 1283 |
1265 EXPECT_CALL(*chrc0_, StartNotifySession(_, _)) | 1284 EXPECT_CALL(*chrc0_, StartNotifySession(_, _)) |
1266 .Times(2) | 1285 .Times(2) |
1267 .WillOnce(InvokeCallbackArgument<1>( | 1286 .WillOnce( |
1268 BluetoothGattService::GattErrorCode::GATT_ERROR_FAILED)) | 1287 InvokeCallbackArgument<1>(BluetoothGattService::GATT_ERROR_FAILED)) |
1269 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattNotifySession>( | 1288 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattNotifySession>( |
1270 session0)); | 1289 session0)); |
1271 EXPECT_CALL(*chrc1_, StartNotifySession(_, _)) | 1290 EXPECT_CALL(*chrc1_, StartNotifySession(_, _)) |
1272 .Times(1) | 1291 .Times(1) |
1273 .WillOnce( | 1292 .WillOnce( |
1274 InvokeCallbackWithScopedPtrArg<0, BluetoothGattNotifySession>( | 1293 InvokeCallbackWithScopedPtrArg<0, BluetoothGattNotifySession>( |
1275 session1)); | 1294 session1)); |
1276 | 1295 |
1277 ExtensionTestMessageListener listener("ready", true); | 1296 ExtensionTestMessageListener listener("ready", true); |
1278 listener.set_failure_message("fail"); | 1297 listener.set_failure_message("fail"); |
(...skipping 16 matching lines...) Expand all Loading... |
1295 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get()); | 1314 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get()); |
1296 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc1_.get()); | 1315 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc1_.get()); |
1297 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); | 1316 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); |
1298 event_router()->GattServiceRemoved( | 1317 event_router()->GattServiceRemoved( |
1299 mock_adapter_, device0_.get(), service1_.get()); | 1318 mock_adapter_, device0_.get(), service1_.get()); |
1300 event_router()->GattServiceRemoved( | 1319 event_router()->GattServiceRemoved( |
1301 mock_adapter_, device0_.get(), service0_.get()); | 1320 mock_adapter_, device0_.get(), service0_.get()); |
1302 } | 1321 } |
1303 | 1322 |
1304 } // namespace | 1323 } // namespace |
OLD | NEW |