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

Side by Side 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 unified diff | Download patch
OLDNEW
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 "device/bluetooth/bluetooth_gatt_characteristic.h" 5 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "device/bluetooth/bluetooth_gatt_service.h" 8 #include "device/bluetooth/bluetooth_gatt_service.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 last_gatt_error_code_); 554 last_gatt_error_code_);
555 555
556 // Initial read should still succeed: 556 // Initial read should still succeed:
557 ResetEventCounts(); 557 ResetEventCounts();
558 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 558 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
559 EXPECT_EQ(1, callback_count_); 559 EXPECT_EQ(1, callback_count_);
560 EXPECT_EQ(0, error_callback_count_); 560 EXPECT_EQ(0, error_callback_count_);
561 } 561 }
562 #endif // defined(OS_ANDROID) 562 #endif // defined(OS_ANDROID)
563 563
564 #if defined(OS_ANDROID)
565 // Tests StartNotifySession success.
566 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession) {
567 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
568
569 characteristic1_->StartNotifySession(GetNotifyCallback(),
570 GetGattErrorCallback());
571 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
572 EXPECT_EQ(0, callback_count_);
573 SimulateGattNotifySessionStarted(characteristic1_);
574 EXPECT_EQ(1, callback_count_);
575 EXPECT_EQ(0, error_callback_count_);
576 ASSERT_EQ(1u, notify_sessions_.size());
577 ASSERT_TRUE(notify_sessions_[0]);
578 EXPECT_EQ(characteristic1_->GetIdentifier(),
579 notify_sessions_[0]->GetCharacteristicIdentifier());
580 EXPECT_TRUE(notify_sessions_[0]->IsActive());
581 }
582 #endif // defined(OS_ANDROID)
583
584 #if defined(OS_ANDROID)
585 // Tests StartNotifySession synchronous failure.
586 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_SynchronousError) {
587 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
588
589 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce(
590 characteristic1_);
591 characteristic1_->StartNotifySession(GetNotifyCallback(),
592 GetGattErrorCallback());
593 EXPECT_EQ(0, error_callback_count_);
594 base::RunLoop().RunUntilIdle();
595 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
596 EXPECT_EQ(0, callback_count_);
597 EXPECT_EQ(1, error_callback_count_);
598 ASSERT_EQ(0u, notify_sessions_.size());
599 }
600 #endif // defined(OS_ANDROID)
601
602 #if defined(OS_ANDROID)
603 // Tests multiple StartNotifySession success.
604 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) {
605 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
606
607 characteristic1_->StartNotifySession(GetNotifyCallback(),
608 GetGattErrorCallback());
609 characteristic1_->StartNotifySession(GetNotifyCallback(),
610 GetGattErrorCallback());
611 #if defined(OS_ANDROID)
612 // TODO(crbug.com/551634): Decide when implementing IsNotifying if Android
613 // should trust the notification request always worked, or if we should always
614 // redundantly set the value to the OS.
615 EXPECT_EQ(2, gatt_notify_characteristic_attempts_);
616 #else
617 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
618 #endif
619 EXPECT_EQ(0, callback_count_);
620 SimulateGattNotifySessionStarted(characteristic1_);
621 EXPECT_EQ(2, callback_count_);
622 EXPECT_EQ(0, error_callback_count_);
623 ASSERT_EQ(2u, notify_sessions_.size());
624 ASSERT_TRUE(notify_sessions_[0]);
625 ASSERT_TRUE(notify_sessions_[1]);
626 EXPECT_EQ(characteristic1_->GetIdentifier(),
627 notify_sessions_[0]->GetCharacteristicIdentifier());
628 EXPECT_EQ(characteristic1_->GetIdentifier(),
629 notify_sessions_[1]->GetCharacteristicIdentifier());
630 EXPECT_TRUE(notify_sessions_[0]->IsActive());
631 EXPECT_TRUE(notify_sessions_[1]->IsActive());
632 }
633 #endif // defined(OS_ANDROID)
634
564 } // namespace device 635 } // namespace device
OLDNEW
« 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