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

Side by Side Diff: device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc

Issue 1973703002: Implement //device/bt changes for notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@notifications_dbus
Patch Set: Created 4 years, 7 months 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/weak_ptr.h" 5 #include "base/memory/weak_ptr.h"
6 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h" 6 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h"
7 #include "device/bluetooth/test/bluetooth_gatt_server_test.h" 7 #include "device/bluetooth/test/bluetooth_gatt_server_test.h"
8 #include "device/bluetooth/test/bluetooth_test.h" 8 #include "device/bluetooth/test/bluetooth_test.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace device { 11 namespace device {
12 12
13 class BluetoothLocalGattCharacteristicTest : public BluetoothGattServerTest { 13 class BluetoothLocalGattCharacteristicTest : public BluetoothGattServerTest {
14 public: 14 public:
15 void SetUp() override { 15 void SetUp() override {
16 BluetoothGattServerTest::SetUp(); 16 BluetoothGattServerTest::SetUp();
17 17
18 StartGattSetup(); 18 StartGattSetup();
19 read_characteristic_ = BluetoothLocalGattCharacteristic::Create( 19 read_characteristic_ = BluetoothLocalGattCharacteristic::Create(
20 BluetoothUUID(kTestUUIDGenericAttribute), 20 BluetoothUUID(kTestUUIDGenericAttribute),
21 device::BluetoothLocalGattCharacteristic:: 21 device::BluetoothLocalGattCharacteristic::
22 PROPERTY_READ_ENCRYPTED_AUTHENTICATED, 22 PROPERTY_READ_ENCRYPTED_AUTHENTICATED,
23 device::BluetoothLocalGattCharacteristic::Permissions(), 23 device::BluetoothLocalGattCharacteristic::Permissions(),
24 service_.get()); 24 service_.get());
25 write_characteristic_ = BluetoothLocalGattCharacteristic::Create( 25 write_characteristic_ = BluetoothLocalGattCharacteristic::Create(
26 BluetoothUUID(kTestUUIDGenericAttribute), 26 BluetoothUUID(kTestUUIDGenericAttribute),
27 device::BluetoothLocalGattCharacteristic::PROPERTY_RELIABLE_WRITE, 27 device::BluetoothLocalGattCharacteristic::PROPERTY_RELIABLE_WRITE,
28 device::BluetoothLocalGattCharacteristic::Permissions(), 28 device::BluetoothLocalGattCharacteristic::Permissions(),
29 service_.get()); 29 service_.get());
30 notify_characteristic_ = BluetoothLocalGattCharacteristic::Create(
31 BluetoothUUID(kTestUUIDGenericAttribute),
32 device::BluetoothLocalGattCharacteristic::PROPERTY_NOTIFY,
33 device::BluetoothLocalGattCharacteristic::Permissions(),
34 service_.get());
30 EXPECT_LT(0u, read_characteristic_->GetIdentifier().size()); 35 EXPECT_LT(0u, read_characteristic_->GetIdentifier().size());
31 EXPECT_LT(0u, write_characteristic_->GetIdentifier().size()); 36 EXPECT_LT(0u, write_characteristic_->GetIdentifier().size());
37 EXPECT_LT(0u, notify_characteristic_->GetIdentifier().size());
32 CompleteGattSetup(); 38 CompleteGattSetup();
33 } 39 }
34 40
35 protected: 41 protected:
36 base::WeakPtr<BluetoothLocalGattCharacteristic> read_characteristic_; 42 base::WeakPtr<BluetoothLocalGattCharacteristic> read_characteristic_;
37 base::WeakPtr<BluetoothLocalGattCharacteristic> write_characteristic_; 43 base::WeakPtr<BluetoothLocalGattCharacteristic> write_characteristic_;
44 base::WeakPtr<BluetoothLocalGattCharacteristic> notify_characteristic_;
38 }; 45 };
39 46
40 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 47 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
41 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValue) { 48 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValue) {
42 delegate_->value_to_write_ = 0x1337; 49 delegate_->value_to_write_ = 0x1337;
43 SimulateLocalGattCharacteristicValueReadRequest( 50 SimulateLocalGattCharacteristicValueReadRequest(
44 service_.get(), read_characteristic_.get(), 51 service_.get(), read_characteristic_.get(),
45 GetReadValueCallback(Call::EXPECTED), GetCallback(Call::NOT_EXPECTED)); 52 GetReadValueCallback(Call::EXPECTED), GetCallback(Call::NOT_EXPECTED));
46 53
47 EXPECT_EQ(delegate_->value_to_write_, GetInteger(last_read_value_)); 54 EXPECT_EQ(delegate_->value_to_write_, GetInteger(last_read_value_));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 WriteLocalCharacteristicValueWrongPermission) { 108 WriteLocalCharacteristicValueWrongPermission) {
102 const uint64_t kValueToWrite = 0x7331ul; 109 const uint64_t kValueToWrite = 0x7331ul;
103 SimulateLocalGattCharacteristicValueWriteRequest( 110 SimulateLocalGattCharacteristicValueWriteRequest(
104 service_.get(), read_characteristic_.get(), GetValue(kValueToWrite), 111 service_.get(), read_characteristic_.get(), GetValue(kValueToWrite),
105 GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED)); 112 GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED));
106 113
107 EXPECT_NE(kValueToWrite, delegate_->last_written_value_); 114 EXPECT_NE(kValueToWrite, delegate_->last_written_value_);
108 } 115 }
109 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 116 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
110 117
118 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
119 TEST_F(BluetoothLocalGattCharacteristicTest, StartAndStopNotifications) {
scheib 2016/05/12 16:53:19 Test Stop as well?
rkc 2016/05/12 20:12:49 Done.
120 EXPECT_FALSE(SimulateLocalGattCharacteristicNotificationsRequest(
121 service_.get(), read_characteristic_.get(), true));
122 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic(
123 read_characteristic_.get()));
124
125 EXPECT_FALSE(SimulateLocalGattCharacteristicNotificationsRequest(
126 service_.get(), write_characteristic_.get(), true));
127 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic(
128 write_characteristic_.get()));
129
130 EXPECT_TRUE(SimulateLocalGattCharacteristicNotificationsRequest(
131 service_.get(), notify_characteristic_.get(), true));
132 EXPECT_TRUE(delegate_->NotificationStatusForCharacteristic(
133 notify_characteristic_.get()));
134 }
135 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
136
137 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
138 TEST_F(BluetoothLocalGattCharacteristicTest, SendNotifications) {
139 const uint64_t kNewValue = 0x7331ul;
140
141 EXPECT_FALSE(SimulateLocalGattCharacteristicSendValueUpdate(
142 service_.get(), read_characteristic_.get(), GetValue(kNewValue)));
143
144 EXPECT_FALSE(SimulateLocalGattCharacteristicSendValueUpdate(
145 service_.get(), write_characteristic_.get(), GetValue(kNewValue)));
146
147 EXPECT_TRUE(SimulateLocalGattCharacteristicSendValueUpdate(
148 service_.get(), notify_characteristic_.get(), GetValue(kNewValue)));
149 }
150 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
151
111 } // namespace device 152 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698