Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11743)

Unified Diff: device/bluetooth/bluetooth_gatt_characteristic_unittest.cc

Issue 1422463012: bluetooth: android: Implement StartNotifySession. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed ortuno Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth.gyp ('k') | device/bluetooth/bluetooth_gatt_notify_session_android.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_gatt_characteristic_unittest.cc
diff --git a/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc b/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc
index 095d2b3b8342d799ca2ec37b639977432412afeb..cf2fdddb1eccb0644e659f798de6b9c4fccc3484 100644
--- a/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc
+++ b/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc
@@ -561,4 +561,75 @@ TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_ReadPending) {
}
#endif // defined(OS_ANDROID)
+#if defined(OS_ANDROID)
+// Tests StartNotifySession success.
+TEST_F(BluetoothGattCharacteristicTest, StartNotifySession) {
+ ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
+
+ characteristic1_->StartNotifySession(GetNotifyCallback(),
+ GetGattErrorCallback());
+ EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
+ EXPECT_EQ(0, callback_count_);
+ SimulateGattNotifySessionStarted(characteristic1_);
+ EXPECT_EQ(1, callback_count_);
+ EXPECT_EQ(0, error_callback_count_);
+ ASSERT_EQ(1u, notify_sessions_.size());
+ ASSERT_TRUE(notify_sessions_[0]);
+ EXPECT_EQ(characteristic1_->GetIdentifier(),
+ notify_sessions_[0]->GetCharacteristicIdentifier());
+ EXPECT_TRUE(notify_sessions_[0]->IsActive());
+}
+#endif // defined(OS_ANDROID)
+
+#if defined(OS_ANDROID)
+// Tests StartNotifySession synchronous failure.
+TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_SynchronousError) {
+ ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
+
+ SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce(
+ characteristic1_);
+ characteristic1_->StartNotifySession(GetNotifyCallback(),
+ GetGattErrorCallback());
+ EXPECT_EQ(0, error_callback_count_);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
+ EXPECT_EQ(0, callback_count_);
+ EXPECT_EQ(1, error_callback_count_);
+ ASSERT_EQ(0u, notify_sessions_.size());
+}
+#endif // defined(OS_ANDROID)
+
+#if defined(OS_ANDROID)
+// Tests multiple StartNotifySession success.
+TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) {
+ ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
+
+ characteristic1_->StartNotifySession(GetNotifyCallback(),
+ GetGattErrorCallback());
+ characteristic1_->StartNotifySession(GetNotifyCallback(),
+ GetGattErrorCallback());
+#if defined(OS_ANDROID)
+ // TODO(crbug.com/551634): Decide when implementing IsNotifying if Android
+ // should trust the notification request always worked, or if we should always
+ // redundantly set the value to the OS.
+ EXPECT_EQ(2, gatt_notify_characteristic_attempts_);
+#else
+ EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
+#endif
+ EXPECT_EQ(0, callback_count_);
+ SimulateGattNotifySessionStarted(characteristic1_);
+ EXPECT_EQ(2, callback_count_);
+ EXPECT_EQ(0, error_callback_count_);
+ ASSERT_EQ(2u, notify_sessions_.size());
+ ASSERT_TRUE(notify_sessions_[0]);
+ ASSERT_TRUE(notify_sessions_[1]);
+ EXPECT_EQ(characteristic1_->GetIdentifier(),
+ notify_sessions_[0]->GetCharacteristicIdentifier());
+ EXPECT_EQ(characteristic1_->GetIdentifier(),
+ notify_sessions_[1]->GetCharacteristicIdentifier());
+ EXPECT_TRUE(notify_sessions_[0]->IsActive());
+ EXPECT_TRUE(notify_sessions_[1]->IsActive());
+}
+#endif // defined(OS_ANDROID)
+
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth.gyp ('k') | device/bluetooth/bluetooth_gatt_notify_session_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698