Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 | 1007 |
| 1008 // Initial read should still succeed: | 1008 // Initial read should still succeed: |
| 1009 ResetEventCounts(); | 1009 ResetEventCounts(); |
| 1010 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 1010 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 1011 base::RunLoop().RunUntilIdle(); | 1011 base::RunLoop().RunUntilIdle(); |
| 1012 EXPECT_EQ(1, callback_count_); | 1012 EXPECT_EQ(1, callback_count_); |
| 1013 EXPECT_EQ(0, error_callback_count_); | 1013 EXPECT_EQ(0, error_callback_count_); |
| 1014 } | 1014 } |
| 1015 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1015 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1016 | 1016 |
| 1017 #if defined(OS_ANDROID) || defined(OS_MACOSX) | |
| 1018 // TODO(crbug.com/713991): Enable on windows once it better matches | |
| 1019 // how other platforms set global variables. | |
| 1020 // Tests that a notification arriving during a pending read doesn't | |
| 1021 // cause a crash. | |
| 1022 TEST_F(BluetoothRemoteGattCharacteristicTest, | |
| 1023 Notification_During_ReadRemoteCharacteristic) { | |
| 1024 if (!PlatformSupportsLowEnergy()) { | |
| 1025 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
| 1026 return; | |
| 1027 } | |
| 1028 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | |
| 1029 BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY | | |
| 1030 BluetoothRemoteGattCharacteristic::PROPERTY_READ, | |
| 1031 NotifyValueState::NOTIFY)); | |
| 1032 | |
| 1033 TestBluetoothAdapterObserver observer(adapter_); | |
| 1034 | |
| 1035 characteristic1_->ReadRemoteCharacteristic( | |
| 1036 GetReadValueCallback(Call::EXPECTED), | |
| 1037 GetGattErrorCallback(Call::NOT_EXPECTED)); | |
| 1038 | |
| 1039 std::vector<uint8_t> notification_value = {111}; | |
| 1040 SimulateGattCharacteristicChanged(characteristic1_, notification_value); | |
| 1041 base::RunLoop().RunUntilIdle(); | |
| 1042 | |
| 1043 #if defined(OS_MACOSX) | |
| 1044 // Because macOS uses the same event for notifications and read value | |
| 1045 // responses, we can't know what the event was for. Because there is a pending | |
| 1046 // read request we assume is a read request on macOS. | |
| 1047 EXPECT_EQ(notification_value, last_read_value_); | |
| 1048 EXPECT_EQ(notification_value, characteristic1_->GetValue()); | |
| 1049 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | |
| 1050 #else // !defined(OS_MACOSX) | |
| 1051 EXPECT_EQ(std::vector<uint8_t>(), last_read_value_); | |
| 1052 EXPECT_EQ(notification_value, characteristic1_->GetValue()); | |
| 1053 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | |
| 1054 #endif // defined(OS_MACOSX) | |
| 1055 | |
| 1056 observer.Reset(); | |
| 1057 std::vector<uint8_t> read_value = {222}; | |
| 1058 SimulateGattCharacteristicRead(characteristic1_, read_value); | |
| 1059 base::RunLoop().RunUntilIdle(); | |
| 1060 #if defined(OS_MACOSX) | |
| 1061 // There are no pending read requests anymore so we assume the event | |
| 1062 // was a notification. | |
| 1063 EXPECT_EQ(notification_value, last_read_value_); | |
| 1064 EXPECT_EQ(read_value, characteristic1_->GetValue()); | |
| 1065 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | |
| 1066 #else // !defined(OS_MACOSX) | |
| 1067 EXPECT_EQ(read_value, last_read_value_); | |
| 1068 EXPECT_EQ(read_value, characteristic1_->GetValue()); | |
| 1069 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | |
| 1070 #endif // defined(OS_MACOSX) | |
| 1071 } | |
| 1072 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | |
| 1073 | |
| 1074 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | |
| 1075 // Tests that a notification arriving during a pending read doesn't | |
|
scheib
2017/05/01 17:41:50
write
ortuno
2017/05/01 23:51:23
Done.
| |
| 1076 // cause a crash. | |
| 1077 TEST_F(BluetoothRemoteGattCharacteristicTest, | |
| 1078 Notification_During_WriteRemoteCharacteristic) { | |
| 1079 if (!PlatformSupportsLowEnergy()) { | |
| 1080 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
| 1081 return; | |
| 1082 } | |
| 1083 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | |
| 1084 BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY | | |
| 1085 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE, | |
| 1086 NotifyValueState::NOTIFY)); | |
| 1087 | |
| 1088 TestBluetoothAdapterObserver observer(adapter_); | |
| 1089 | |
| 1090 std::vector<uint8_t> write_value = {111}; | |
| 1091 characteristic1_->WriteRemoteCharacteristic( | |
| 1092 write_value, GetCallback(Call::EXPECTED), | |
| 1093 GetGattErrorCallback(Call::NOT_EXPECTED)); | |
| 1094 | |
| 1095 std::vector<uint8_t> notification_value = {222}; | |
| 1096 SimulateGattCharacteristicChanged(characteristic1_, notification_value); | |
| 1097 base::RunLoop().RunUntilIdle(); | |
| 1098 | |
| 1099 EXPECT_EQ(notification_value, characteristic1_->GetValue()); | |
| 1100 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | |
| 1101 | |
| 1102 observer.Reset(); | |
| 1103 SimulateGattCharacteristicWrite(characteristic1_); | |
| 1104 base::RunLoop().RunUntilIdle(); | |
| 1105 | |
| 1106 EXPECT_EQ(write_value, last_write_value_); | |
| 1107 } | |
| 1108 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | |
| 1109 | |
| 1017 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1110 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 1018 // StartNotifySession fails if characteristic doesn't have Notify or Indicate | 1111 // StartNotifySession fails if characteristic doesn't have Notify or Indicate |
| 1019 // property. | 1112 // property. |
| 1020 TEST_F(BluetoothRemoteGattCharacteristicTest, | 1113 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 1021 StartNotifySession_NoNotifyOrIndicate) { | 1114 StartNotifySession_NoNotifyOrIndicate) { |
| 1022 if (!PlatformSupportsLowEnergy()) { | 1115 if (!PlatformSupportsLowEnergy()) { |
| 1023 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1116 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 1024 return; | 1117 return; |
| 1025 } | 1118 } |
| 1026 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1119 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| (...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2384 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 2477 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 2385 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); | 2478 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 2386 | 2479 |
| 2387 SimulateGattDisconnection(device_); | 2480 SimulateGattDisconnection(device_); |
| 2388 // Don't run the disconnect task. | 2481 // Don't run the disconnect task. |
| 2389 notify_sessions_.clear(); | 2482 notify_sessions_.clear(); |
| 2390 base::RunLoop().RunUntilIdle(); | 2483 base::RunLoop().RunUntilIdle(); |
| 2391 } | 2484 } |
| 2392 #endif | 2485 #endif |
| 2393 } // namespace device | 2486 } // namespace device |
| OLD | NEW |