OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/scoped_vector.h" | 5 #include "base/memory/scoped_vector.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "chromeos/dbus/dbus_thread_manager.h" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
946 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); | 946 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); |
947 characteristic->ReadRemoteCharacteristic( | 947 characteristic->ReadRemoteCharacteristic( |
948 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | 948 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, |
949 base::Unretained(this)), | 949 base::Unretained(this)), |
950 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 950 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, |
951 base::Unretained(this))); | 951 base::Unretained(this))); |
952 EXPECT_EQ(2, success_callback_count_); | 952 EXPECT_EQ(2, success_callback_count_); |
953 EXPECT_EQ(4, error_callback_count_); | 953 EXPECT_EQ(4, error_callback_count_); |
954 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); | 954 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); |
955 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); | 955 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); |
956 | |
957 // Test long-running actions. | |
958 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(1); | |
959 characteristic = service->GetCharacteristic( | |
960 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() | |
961 .value()); | |
962 ASSERT_TRUE(characteristic); | |
963 EXPECT_EQ( | |
964 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() | |
965 .value(), | |
966 characteristic->GetIdentifier()); | |
967 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); | |
968 characteristic->ReadRemoteCharacteristic( | |
969 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | |
970 base::Unretained(this)), | |
971 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | |
972 base::Unretained(this))); | |
armansito
2014/10/01 20:08:22
Add new line before comments, here and below.
Marie Janssen
2014/10/01 22:22:22
Done.
| |
973 // Callback counts shouldn't change, this one will be delayed until after | |
974 // tne next one. | |
975 EXPECT_EQ(2, success_callback_count_); | |
976 EXPECT_EQ(4, error_callback_count_); | |
977 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); | |
978 // Next read should error because IN_PROGRESS | |
979 characteristic->ReadRemoteCharacteristic( | |
980 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | |
981 base::Unretained(this)), | |
982 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | |
983 base::Unretained(this))); | |
984 EXPECT_EQ(5, error_callback_count_); | |
985 EXPECT_EQ(BluetoothGattService::GattErrorCode::GATT_ERROR_IN_PROGRESS, | |
armansito
2014/10/01 20:08:22
Interesting, this works in C++? BluetoothGattServi
Marie Janssen
2014/10/01 22:22:22
Done.
| |
986 last_service_error_); | |
987 // But previous call finished. | |
988 EXPECT_EQ(3, success_callback_count_); | |
989 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count_); | |
990 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); | |
991 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(0); | |
992 | |
993 // Test unauthorized actions. | |
994 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(false); | |
995 characteristic->ReadRemoteCharacteristic( | |
996 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | |
997 base::Unretained(this)), | |
998 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | |
999 base::Unretained(this))); | |
1000 EXPECT_EQ(3, success_callback_count_); | |
1001 EXPECT_EQ(6, error_callback_count_); | |
1002 EXPECT_EQ(BluetoothGattService::GattErrorCode::GATT_ERROR_NOT_AUTHORIZED, | |
1003 last_service_error_); | |
1004 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count_); | |
1005 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(true); | |
956 } | 1006 } |
957 | 1007 |
958 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicProperties) { | 1008 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicProperties) { |
959 fake_bluetooth_device_client_->CreateDevice( | 1009 fake_bluetooth_device_client_->CreateDevice( |
960 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 1010 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
961 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 1011 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); |
962 BluetoothDevice* device = adapter_->GetDevice( | 1012 BluetoothDevice* device = adapter_->GetDevice( |
963 FakeBluetoothDeviceClient::kLowEnergyAddress); | 1013 FakeBluetoothDeviceClient::kLowEnergyAddress); |
964 ASSERT_TRUE(device); | 1014 ASSERT_TRUE(device); |
965 | 1015 |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1355 | 1405 |
1356 EXPECT_EQ(1, success_callback_count_); | 1406 EXPECT_EQ(1, success_callback_count_); |
1357 EXPECT_EQ(0, error_callback_count_); | 1407 EXPECT_EQ(0, error_callback_count_); |
1358 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); | 1408 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); |
1359 EXPECT_TRUE(characteristic->IsNotifying()); | 1409 EXPECT_TRUE(characteristic->IsNotifying()); |
1360 EXPECT_EQ(1U, update_sessions_.size()); | 1410 EXPECT_EQ(1U, update_sessions_.size()); |
1361 EXPECT_TRUE(update_sessions_[0]->IsActive()); | 1411 EXPECT_TRUE(update_sessions_[0]->IsActive()); |
1362 } | 1412 } |
1363 | 1413 |
1364 } // namespace chromeos | 1414 } // namespace chromeos |
OLD | NEW |