| 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" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 using device::BluetoothAdapter; | 25 using device::BluetoothAdapter; |
| 25 using device::BluetoothAdapterFactory; | 26 using device::BluetoothAdapterFactory; |
| 26 using device::BluetoothAdvertisement; | 27 using device::BluetoothAdvertisement; |
| 27 | 28 |
| 28 namespace bluez { | 29 namespace bluez { |
| 29 | 30 |
| 30 class TestAdvertisementObserver : public BluetoothAdvertisement::Observer { | 31 class TestAdvertisementObserver : public BluetoothAdvertisement::Observer { |
| 31 public: | 32 public: |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 201 |
| 201 TEST_F(BluetoothAdvertisementBlueZTest, RegisterSucceeded) { | 202 TEST_F(BluetoothAdvertisementBlueZTest, RegisterSucceeded) { |
| 202 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); | 203 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); |
| 203 ExpectSuccess(); | 204 ExpectSuccess(); |
| 204 EXPECT_TRUE(advertisement); | 205 EXPECT_TRUE(advertisement); |
| 205 | 206 |
| 206 UnregisterAdvertisement(advertisement); | 207 UnregisterAdvertisement(advertisement); |
| 207 ExpectSuccess(); | 208 ExpectSuccess(); |
| 208 } | 209 } |
| 209 | 210 |
| 210 TEST_F(BluetoothAdvertisementBlueZTest, DoubleRegisterFailed) { | 211 TEST_F(BluetoothAdvertisementBlueZTest, DoubleRegisterSucceeded) { |
| 211 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); | 212 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); |
| 212 ExpectSuccess(); | 213 ExpectSuccess(); |
| 213 EXPECT_TRUE(advertisement); | 214 EXPECT_TRUE(advertisement); |
| 214 | 215 |
| 215 // Creating a second advertisement should give us an error. | 216 // Creating a second advertisement should still be fine. |
| 216 scoped_refptr<BluetoothAdvertisement> advertisement2 = CreateAdvertisement(); | 217 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(); |
| 217 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_ALREADY_EXISTS); | 238 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_ALREADY_EXISTS); |
| 218 EXPECT_FALSE(advertisement2); | 239 EXPECT_FALSE(current_advertisement); |
| 219 } | 240 } |
| 220 | 241 |
| 221 TEST_F(BluetoothAdvertisementBlueZTest, DoubleUnregisterFailed) { | 242 TEST_F(BluetoothAdvertisementBlueZTest, DoubleUnregisterFailed) { |
| 222 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); | 243 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); |
| 223 ExpectSuccess(); | 244 ExpectSuccess(); |
| 224 EXPECT_TRUE(advertisement); | 245 EXPECT_TRUE(advertisement); |
| 225 | 246 |
| 226 UnregisterAdvertisement(advertisement); | 247 UnregisterAdvertisement(advertisement); |
| 227 ExpectSuccess(); | 248 ExpectSuccess(); |
| 228 | 249 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 241 TriggerReleased(advertisement); | 262 TriggerReleased(advertisement); |
| 242 EXPECT_TRUE(observer_->released()); | 263 EXPECT_TRUE(observer_->released()); |
| 243 | 264 |
| 244 // Unregistering an advertisement that has been released should give us an | 265 // Unregistering an advertisement that has been released should give us an |
| 245 // error. | 266 // error. |
| 246 UnregisterAdvertisement(advertisement); | 267 UnregisterAdvertisement(advertisement); |
| 247 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_DOES_NOT_EXIST); | 268 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_DOES_NOT_EXIST); |
| 248 } | 269 } |
| 249 | 270 |
| 250 } // namespace bluez | 271 } // namespace bluez |
| OLD | NEW |