| 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 2118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2129 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 2129 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
| 2130 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); | 2130 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); |
| 2131 | 2131 |
| 2132 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); | 2132 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); |
| 2133 base::RunLoop().RunUntilIdle(); | 2133 base::RunLoop().RunUntilIdle(); |
| 2134 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); | 2134 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); |
| 2135 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); | 2135 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); |
| 2136 } | 2136 } |
| 2137 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 2137 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 2138 | 2138 |
| 2139 #if defined(OS_ANDROID) |
| 2140 // Tests that Characteristic value changes arriving consecutively result in |
| 2141 // two notifications with correct values. |
| 2142 // macOS: Does not apply. All events arrive on the UI Thread. |
| 2143 // TODO(crbug.com/694102): Enable this test on Windows. |
| 2144 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 2145 TwoGattCharacteristicValueChanges) { |
| 2146 if (!PlatformSupportsLowEnergy()) { |
| 2147 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 2148 return; |
| 2149 } |
| 2150 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 2151 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 2152 |
| 2153 TestBluetoothAdapterObserver observer(adapter_); |
| 2154 |
| 2155 std::vector<uint8_t> test_vector1({111}); |
| 2156 std::vector<uint8_t> test_vector2({222}); |
| 2157 |
| 2158 SimulateGattCharacteristicChanged(characteristic1_, test_vector1); |
| 2159 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); |
| 2160 |
| 2161 base::RunLoop().RunUntilIdle(); |
| 2162 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); |
| 2163 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); |
| 2164 EXPECT_EQ(std::vector<std::vector<uint8_t>>({test_vector1, test_vector2}), |
| 2165 observer.previous_characteristic_value_changed_values()); |
| 2166 } |
| 2167 #endif // defined(OS_ANDROID) |
| 2168 |
| 2139 #if defined(OS_ANDROID) || defined(OS_WIN) | 2169 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 2140 // Tests Characteristic Value changing after a Notify Session and objects being | 2170 // Tests Characteristic Value changing after a Notify Session and objects being |
| 2141 // destroyed. | 2171 // destroyed. |
| 2142 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set | 2172 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set |
| 2143 // to nil. | 2173 // to nil. |
| 2144 TEST_F(BluetoothRemoteGattCharacteristicTest, | 2174 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 2145 GattCharacteristicValueChanged_AfterDeleted) { | 2175 GattCharacteristicValueChanged_AfterDeleted) { |
| 2146 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 2176 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 2147 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); | 2177 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); |
| 2148 TestBluetoothAdapterObserver observer(adapter_); | 2178 TestBluetoothAdapterObserver observer(adapter_); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2237 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); | 2267 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); |
| 2238 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); | 2268 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); |
| 2239 | 2269 |
| 2240 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); | 2270 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); |
| 2241 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); | 2271 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); |
| 2242 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); | 2272 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); |
| 2243 } | 2273 } |
| 2244 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 2274 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 2245 | 2275 |
| 2246 } // namespace device | 2276 } // namespace device |
| OLD | NEW |