| 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 "device/bluetooth/bluez/bluetooth_advertisement_bluez.h" | 5 #include "device/bluetooth/bluez/bluetooth_advertisement_bluez.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "device/bluetooth/bluetooth_adapter.h" | 17 #include "device/bluetooth/bluetooth_adapter.h" |
| 18 #include "device/bluetooth/bluetooth_adapter_factory.h" | 18 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 19 #include "device/bluetooth/bluetooth_advertisement.h" | 19 #include "device/bluetooth/bluetooth_advertisement.h" |
| 20 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 20 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 21 #include "device/bluetooth/dbus/fake_bluetooth_le_advertisement_service_provider
.h" | 21 #include "device/bluetooth/dbus/fake_bluetooth_le_advertisement_service_provider
.h" |
| 22 #include "device/bluetooth/dbus/fake_bluetooth_le_advertising_manager_client.h" | |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 23 |
| 25 using device::BluetoothAdapter; | 24 using device::BluetoothAdapter; |
| 26 using device::BluetoothAdapterFactory; | 25 using device::BluetoothAdapterFactory; |
| 27 using device::BluetoothAdvertisement; | 26 using device::BluetoothAdvertisement; |
| 28 | 27 |
| 29 namespace bluez { | 28 namespace bluez { |
| 30 | 29 |
| 31 class TestAdvertisementObserver : public BluetoothAdvertisement::Observer { | 30 class TestAdvertisementObserver : public BluetoothAdvertisement::Observer { |
| 32 public: | 31 public: |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 200 |
| 202 TEST_F(BluetoothAdvertisementBlueZTest, RegisterSucceeded) { | 201 TEST_F(BluetoothAdvertisementBlueZTest, RegisterSucceeded) { |
| 203 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); | 202 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); |
| 204 ExpectSuccess(); | 203 ExpectSuccess(); |
| 205 EXPECT_TRUE(advertisement); | 204 EXPECT_TRUE(advertisement); |
| 206 | 205 |
| 207 UnregisterAdvertisement(advertisement); | 206 UnregisterAdvertisement(advertisement); |
| 208 ExpectSuccess(); | 207 ExpectSuccess(); |
| 209 } | 208 } |
| 210 | 209 |
| 211 TEST_F(BluetoothAdvertisementBlueZTest, DoubleRegisterSucceeded) { | 210 TEST_F(BluetoothAdvertisementBlueZTest, DoubleRegisterFailed) { |
| 212 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); | 211 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); |
| 213 ExpectSuccess(); | 212 ExpectSuccess(); |
| 214 EXPECT_TRUE(advertisement); | 213 EXPECT_TRUE(advertisement); |
| 215 | 214 |
| 216 // Creating a second advertisement should still be fine. | 215 // Creating a second advertisement should give us an error. |
| 217 scoped_refptr<BluetoothAdvertisement> advertisement2 = CreateAdvertisement(); | 216 scoped_refptr<BluetoothAdvertisement> advertisement2 = CreateAdvertisement(); |
| 218 ExpectSuccess(); | |
| 219 EXPECT_TRUE(advertisement2); | |
| 220 } | |
| 221 | |
| 222 TEST_F(BluetoothAdvertisementBlueZTest, RegisterTooManyFailed) { | |
| 223 // Register the maximum available number of advertisements. | |
| 224 constexpr size_t kMaxBluezAdvertisements = | |
| 225 bluez::FakeBluetoothLEAdvertisingManagerClient::kMaxBluezAdvertisements; | |
| 226 | |
| 227 std::vector<scoped_refptr<BluetoothAdvertisement>> advertisements; | |
| 228 scoped_refptr<BluetoothAdvertisement> current_advertisement; | |
| 229 for (size_t i = 0; i < kMaxBluezAdvertisements; i++) { | |
| 230 current_advertisement = CreateAdvertisement(); | |
| 231 ExpectSuccess(); | |
| 232 EXPECT_TRUE(current_advertisement); | |
| 233 advertisements.emplace_back(std::move(current_advertisement)); | |
| 234 } | |
| 235 | |
| 236 // The next advertisement should fail to register. | |
| 237 current_advertisement = CreateAdvertisement(); | |
| 238 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_ALREADY_EXISTS); | 217 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_ALREADY_EXISTS); |
| 239 EXPECT_FALSE(current_advertisement); | 218 EXPECT_FALSE(advertisement2); |
| 240 } | 219 } |
| 241 | 220 |
| 242 TEST_F(BluetoothAdvertisementBlueZTest, DoubleUnregisterFailed) { | 221 TEST_F(BluetoothAdvertisementBlueZTest, DoubleUnregisterFailed) { |
| 243 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); | 222 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); |
| 244 ExpectSuccess(); | 223 ExpectSuccess(); |
| 245 EXPECT_TRUE(advertisement); | 224 EXPECT_TRUE(advertisement); |
| 246 | 225 |
| 247 UnregisterAdvertisement(advertisement); | 226 UnregisterAdvertisement(advertisement); |
| 248 ExpectSuccess(); | 227 ExpectSuccess(); |
| 249 | 228 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 262 TriggerReleased(advertisement); | 241 TriggerReleased(advertisement); |
| 263 EXPECT_TRUE(observer_->released()); | 242 EXPECT_TRUE(observer_->released()); |
| 264 | 243 |
| 265 // Unregistering an advertisement that has been released should give us an | 244 // Unregistering an advertisement that has been released should give us an |
| 266 // error. | 245 // error. |
| 267 UnregisterAdvertisement(advertisement); | 246 UnregisterAdvertisement(advertisement); |
| 268 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_DOES_NOT_EXIST); | 247 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_DOES_NOT_EXIST); |
| 269 } | 248 } |
| 270 | 249 |
| 271 } // namespace bluez | 250 } // namespace bluez |
| OLD | NEW |