| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 207 |
| 208 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(10); | 208 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(10); |
| 209 | 209 |
| 210 callback_count_ = 0; | 210 callback_count_ = 0; |
| 211 error_callback_count_ = 0; | 211 error_callback_count_ = 0; |
| 212 last_connect_error_ = BluetoothDevice::ERROR_UNKNOWN; | 212 last_connect_error_ = BluetoothDevice::ERROR_UNKNOWN; |
| 213 last_client_error_ = ""; | 213 last_client_error_ = ""; |
| 214 } | 214 } |
| 215 | 215 |
| 216 void TearDown() override { | 216 void TearDown() override { |
| 217 for (ScopedVector<BluetoothDiscoverySession>::iterator iter = | 217 for (auto& session : discovery_sessions_) { |
| 218 discovery_sessions_.begin(); | |
| 219 iter != discovery_sessions_.end(); ++iter) { | |
| 220 BluetoothDiscoverySession* session = *iter; | |
| 221 if (!session->IsActive()) | 218 if (!session->IsActive()) |
| 222 continue; | 219 continue; |
| 223 callback_count_ = 0; | 220 callback_count_ = 0; |
| 224 session->Stop(GetCallback(), GetErrorCallback()); | 221 session->Stop(GetCallback(), GetErrorCallback()); |
| 225 base::RunLoop().Run(); | 222 base::RunLoop().Run(); |
| 226 ASSERT_EQ(1, callback_count_); | 223 ASSERT_EQ(1, callback_count_); |
| 227 } | 224 } |
| 228 discovery_sessions_.clear(); | 225 discovery_sessions_.clear(); |
| 229 adapter_ = nullptr; | 226 adapter_ = nullptr; |
| 230 bluez::BluezDBusManager::Shutdown(); | 227 bluez::BluezDBusManager::Shutdown(); |
| 231 } | 228 } |
| 232 | 229 |
| 233 // Generic callbacks | 230 // Generic callbacks |
| 234 void Callback() { | 231 void Callback() { |
| 235 ++callback_count_; | 232 ++callback_count_; |
| 236 QuitMessageLoop(); | 233 QuitMessageLoop(); |
| 237 } | 234 } |
| 238 | 235 |
| 239 base::Closure GetCallback() { | 236 base::Closure GetCallback() { |
| 240 return base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)); | 237 return base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)); |
| 241 } | 238 } |
| 242 | 239 |
| 243 void AdapterCallback() { QuitMessageLoop(); } | 240 void AdapterCallback() { QuitMessageLoop(); } |
| 244 | 241 |
| 245 void DiscoverySessionCallback( | 242 void DiscoverySessionCallback( |
| 246 std::unique_ptr<BluetoothDiscoverySession> discovery_session) { | 243 std::unique_ptr<BluetoothDiscoverySession> discovery_session) { |
| 247 ++callback_count_; | 244 ++callback_count_; |
| 248 discovery_sessions_.push_back(discovery_session.release()); | 245 discovery_sessions_.push_back(std::move(discovery_session)); |
| 249 QuitMessageLoop(); | 246 QuitMessageLoop(); |
| 250 } | 247 } |
| 251 | 248 |
| 252 void ProfileRegisteredCallback(BluetoothAdapterProfileBlueZ* profile) { | 249 void ProfileRegisteredCallback(BluetoothAdapterProfileBlueZ* profile) { |
| 253 adapter_profile_ = profile; | 250 adapter_profile_ = profile; |
| 254 ++callback_count_; | 251 ++callback_count_; |
| 255 QuitMessageLoop(); | 252 QuitMessageLoop(); |
| 256 } | 253 } |
| 257 | 254 |
| 258 void ErrorCallback() { | 255 void ErrorCallback() { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 protected: | 348 protected: |
| 352 base::MessageLoop message_loop_; | 349 base::MessageLoop message_loop_; |
| 353 bluez::FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_; | 350 bluez::FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_; |
| 354 bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client_; | 351 bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client_; |
| 355 scoped_refptr<BluetoothAdapter> adapter_; | 352 scoped_refptr<BluetoothAdapter> adapter_; |
| 356 | 353 |
| 357 int callback_count_; | 354 int callback_count_; |
| 358 int error_callback_count_; | 355 int error_callback_count_; |
| 359 enum BluetoothDevice::ConnectErrorCode last_connect_error_; | 356 enum BluetoothDevice::ConnectErrorCode last_connect_error_; |
| 360 std::string last_client_error_; | 357 std::string last_client_error_; |
| 361 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; | 358 |
| 359 std::vector<std::unique_ptr<BluetoothDiscoverySession>> discovery_sessions_; |
| 362 BluetoothAdapterProfileBlueZ* adapter_profile_; | 360 BluetoothAdapterProfileBlueZ* adapter_profile_; |
| 363 | 361 |
| 364 private: | 362 private: |
| 365 // Some tests use a message loop since background processing is simulated; | 363 // Some tests use a message loop since background processing is simulated; |
| 366 // break out of those loops. | 364 // break out of those loops. |
| 367 void QuitMessageLoop() { | 365 void QuitMessageLoop() { |
| 368 if (base::MessageLoop::current() && | 366 if (base::MessageLoop::current() && |
| 369 base::MessageLoop::current()->is_running()) { | 367 base::MessageLoop::current()->is_running()) { |
| 370 base::MessageLoop::current()->QuitWhenIdle(); | 368 base::MessageLoop::current()->QuitWhenIdle(); |
| 371 } | 369 } |
| (...skipping 4270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4642 | 4640 |
| 4643 // Check that we can update advertising data flags. | 4641 // Check that we can update advertising data flags. |
| 4644 properties->advertising_data_flags.ReplaceValue(std::vector<uint8_t>({0x23})); | 4642 properties->advertising_data_flags.ReplaceValue(std::vector<uint8_t>({0x23})); |
| 4645 EXPECT_EQ(2, observer.device_changed_count()); | 4643 EXPECT_EQ(2, observer.device_changed_count()); |
| 4646 EXPECT_EQ(device, observer.last_device()); | 4644 EXPECT_EQ(device, observer.last_device()); |
| 4647 EXPECT_TRUE(device->GetAdvertisingDataFlags().has_value()); | 4645 EXPECT_TRUE(device->GetAdvertisingDataFlags().has_value()); |
| 4648 EXPECT_EQ(0x23u, device->GetAdvertisingDataFlags().value()); | 4646 EXPECT_EQ(0x23u, device->GetAdvertisingDataFlags().value()); |
| 4649 } | 4647 } |
| 4650 | 4648 |
| 4651 } // namespace bluez | 4649 } // namespace bluez |
| OLD | NEW |