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

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

Issue 1367663002: Add Linux support for the Bluetooth API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor_dbus
Patch Set: Created 5 years, 2 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 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 "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 "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "dbus/object_path.h" 9 #include "dbus/object_path.h"
10 #include "device/bluetooth/bluetooth_adapter.h" 10 #include "device/bluetooth/bluetooth_adapter.h"
11 #include "device/bluetooth/bluetooth_adapter_chromeos.h" 11 #include "device/bluetooth/bluetooth_adapter_bluez.h"
12 #include "device/bluetooth/bluetooth_adapter_factory.h" 12 #include "device/bluetooth/bluetooth_adapter_factory.h"
13 #include "device/bluetooth/bluetooth_device.h" 13 #include "device/bluetooth/bluetooth_device.h"
14 #include "device/bluetooth/bluetooth_device_chromeos.h" 14 #include "device/bluetooth/bluetooth_device_bluez.h"
15 #include "device/bluetooth/bluetooth_discovery_session.h" 15 #include "device/bluetooth/bluetooth_discovery_session.h"
16 #include "device/bluetooth/bluetooth_pairing_chromeos.h" 16 #include "device/bluetooth/bluetooth_pairing_bluez.h"
17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" 17 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
18 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" 18 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
19 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" 19 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h"
20 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" 20 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
21 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" 21 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h"
22 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" 22 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h"
23 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 23 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/cros_system_api/dbus/service_constants.h" 25 #include "third_party/cros_system_api/dbus/service_constants.h"
26 26
27 using device::BluetoothAdapter; 27 using device::BluetoothAdapter;
28 using device::BluetoothAdapterFactory; 28 using device::BluetoothAdapterFactory;
29 using device::BluetoothAudioSink; 29 using device::BluetoothAudioSink;
30 using device::BluetoothDevice; 30 using device::BluetoothDevice;
31 using device::BluetoothDiscoveryFilter; 31 using device::BluetoothDiscoveryFilter;
32 using device::BluetoothDiscoverySession; 32 using device::BluetoothDiscoverySession;
33 using device::BluetoothUUID; 33 using device::BluetoothUUID;
34 using device::TestBluetoothAdapterObserver; 34 using device::TestBluetoothAdapterObserver;
35 35
36 namespace chromeos { 36 namespace bluez {
37 37
38 namespace { 38 namespace {
39 39
40 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the 40 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the
41 // connection info to the bound argument. 41 // connection info to the bound argument.
42 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out, 42 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out,
43 const BluetoothDevice::ConnectionInfo& conn_info) { 43 const BluetoothDevice::ConnectionInfo& conn_info) {
44 *out = conn_info; 44 *out = conn_info;
45 }; 45 };
46 46
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // Some tests use a message loop since background processing is simulated; 144 // Some tests use a message loop since background processing is simulated;
145 // break out of those loops. 145 // break out of those loops.
146 void QuitMessageLoop() { 146 void QuitMessageLoop() {
147 if (base::MessageLoop::current() && 147 if (base::MessageLoop::current() &&
148 base::MessageLoop::current()->is_running()) { 148 base::MessageLoop::current()->is_running()) {
149 base::MessageLoop::current()->Quit(); 149 base::MessageLoop::current()->Quit();
150 } 150 }
151 } 151 }
152 }; 152 };
153 153
154 class BluetoothChromeOSTest : public testing::Test { 154 class BluetoothBlueZTest : public testing::Test {
155 public: 155 public:
156 void SetUp() override { 156 void SetUp() override {
157 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter = 157 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter =
158 bluez::BluezDBusManager::GetSetterForTesting(); 158 bluez::BluezDBusManager::GetSetterForTesting();
159 // We need to initialize BluezDBusManager early to prevent 159 // We need to initialize BluezDBusManager early to prevent
160 // Bluetooth*::Create() methods from picking the real instead of fake 160 // Bluetooth*::Create() methods from picking the real instead of fake
161 // implementations. 161 // implementations.
162 fake_bluetooth_adapter_client_ = new bluez::FakeBluetoothAdapterClient; 162 fake_bluetooth_adapter_client_ = new bluez::FakeBluetoothAdapterClient;
163 dbus_setter->SetBluetoothAdapterClient( 163 dbus_setter->SetBluetoothAdapterClient(
164 scoped_ptr<bluez::BluetoothAdapterClient>( 164 scoped_ptr<bluez::BluetoothAdapterClient>(
(...skipping 15 matching lines...) Expand all
180 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(10); 180 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(10);
181 181
182 callback_count_ = 0; 182 callback_count_ = 0;
183 error_callback_count_ = 0; 183 error_callback_count_ = 0;
184 last_connect_error_ = BluetoothDevice::ERROR_UNKNOWN; 184 last_connect_error_ = BluetoothDevice::ERROR_UNKNOWN;
185 last_client_error_ = ""; 185 last_client_error_ = "";
186 } 186 }
187 187
188 void TearDown() override { 188 void TearDown() override {
189 for (ScopedVector<BluetoothDiscoverySession>::iterator iter = 189 for (ScopedVector<BluetoothDiscoverySession>::iterator iter =
190 discovery_sessions_.begin(); 190 discovery_sessions_.begin();
191 iter != discovery_sessions_.end(); 191 iter != discovery_sessions_.end(); ++iter) {
192 ++iter) {
193 BluetoothDiscoverySession* session = *iter; 192 BluetoothDiscoverySession* session = *iter;
194 if (!session->IsActive()) 193 if (!session->IsActive())
195 continue; 194 continue;
196 callback_count_ = 0; 195 callback_count_ = 0;
197 session->Stop(GetCallback(), GetErrorCallback()); 196 session->Stop(GetCallback(), GetErrorCallback());
198 message_loop_.Run(); 197 message_loop_.Run();
199 ASSERT_EQ(1, callback_count_); 198 ASSERT_EQ(1, callback_count_);
200 } 199 }
201 discovery_sessions_.clear(); 200 discovery_sessions_.clear();
202 adapter_ = nullptr; 201 adapter_ = nullptr;
203 bluez::BluezDBusManager::Shutdown(); 202 bluez::BluezDBusManager::Shutdown();
204 } 203 }
205 204
206 // Generic callbacks 205 // Generic callbacks
207 void Callback() { 206 void Callback() {
208 ++callback_count_; 207 ++callback_count_;
209 QuitMessageLoop(); 208 QuitMessageLoop();
210 } 209 }
211 210
212 base::Closure GetCallback() { 211 base::Closure GetCallback() {
213 return base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)); 212 return base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this));
214 } 213 }
215 214
216 void DiscoverySessionCallback( 215 void DiscoverySessionCallback(
217 scoped_ptr<BluetoothDiscoverySession> discovery_session) { 216 scoped_ptr<BluetoothDiscoverySession> discovery_session) {
218 ++callback_count_; 217 ++callback_count_;
219 discovery_sessions_.push_back(discovery_session.release()); 218 discovery_sessions_.push_back(discovery_session.release());
220 QuitMessageLoop(); 219 QuitMessageLoop();
221 } 220 }
222 221
223 void AudioSinkAcquiredCallback(scoped_refptr<BluetoothAudioSink>) { 222 void AudioSinkAcquiredCallback(scoped_refptr<BluetoothAudioSink>) {
224 ++callback_count_; 223 ++callback_count_;
225 QuitMessageLoop(); 224 QuitMessageLoop();
226 } 225 }
227 226
228 void ProfileRegisteredCallback(BluetoothAdapterProfileChromeOS* profile) { 227 void ProfileRegisteredCallback(BluetoothAdapterProfileBlueZ* profile) {
229 adapter_profile_ = profile; 228 adapter_profile_ = profile;
230 ++callback_count_; 229 ++callback_count_;
231 QuitMessageLoop(); 230 QuitMessageLoop();
232 } 231 }
233 232
234 void ErrorCallback() { 233 void ErrorCallback() {
235 ++error_callback_count_; 234 ++error_callback_count_;
236 QuitMessageLoop(); 235 QuitMessageLoop();
237 } 236 }
238 237
239 void DiscoveryErrorCallback(device::UMABluetoothDiscoverySessionOutcome) { 238 void DiscoveryErrorCallback(device::UMABluetoothDiscoverySessionOutcome) {
240 ErrorCallback(); 239 ErrorCallback();
241 } 240 }
242 241
243 base::Closure GetErrorCallback() { 242 base::Closure GetErrorCallback() {
244 return base::Bind(&BluetoothChromeOSTest::ErrorCallback, 243 return base::Bind(&BluetoothBlueZTest::ErrorCallback,
245 base::Unretained(this)); 244 base::Unretained(this));
246 } 245 }
247 246
248 base::Callback<void(device::UMABluetoothDiscoverySessionOutcome)> 247 base::Callback<void(device::UMABluetoothDiscoverySessionOutcome)>
249 GetDiscoveryErrorCallback() { 248 GetDiscoveryErrorCallback() {
250 return base::Bind(&BluetoothChromeOSTest::DiscoveryErrorCallback, 249 return base::Bind(&BluetoothBlueZTest::DiscoveryErrorCallback,
251 base::Unretained(this)); 250 base::Unretained(this));
252 } 251 }
253 252
254 void DBusErrorCallback(const std::string& error_name, 253 void DBusErrorCallback(const std::string& error_name,
255 const std::string& error_message) { 254 const std::string& error_message) {
256 ++error_callback_count_; 255 ++error_callback_count_;
257 last_client_error_ = error_name; 256 last_client_error_ = error_name;
258 QuitMessageLoop(); 257 QuitMessageLoop();
259 } 258 }
260 259
261 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) { 260 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) {
262 ++error_callback_count_; 261 ++error_callback_count_;
263 last_connect_error_ = error; 262 last_connect_error_ = error;
264 } 263 }
265 264
266 void AudioSinkErrorCallback(BluetoothAudioSink::ErrorCode) { 265 void AudioSinkErrorCallback(BluetoothAudioSink::ErrorCode) {
267 ++error_callback_count_; 266 ++error_callback_count_;
268 QuitMessageLoop(); 267 QuitMessageLoop();
269 } 268 }
270 269
271 void ErrorCompletionCallback(const std::string& error_message) { 270 void ErrorCompletionCallback(const std::string& error_message) {
272 ++error_callback_count_; 271 ++error_callback_count_;
273 QuitMessageLoop(); 272 QuitMessageLoop();
274 } 273 }
275 274
276 // Call to fill the adapter_ member with a BluetoothAdapter instance. 275 // Call to fill the adapter_ member with a BluetoothAdapter instance.
277 void GetAdapter() { 276 void GetAdapter() {
278 adapter_ = new BluetoothAdapterChromeOS(); 277 adapter_ = new BluetoothAdapterBlueZ();
279 ASSERT_TRUE(adapter_.get() != nullptr); 278 ASSERT_TRUE(adapter_.get() != nullptr);
280 ASSERT_TRUE(adapter_->IsInitialized()); 279 ASSERT_TRUE(adapter_->IsInitialized());
281 } 280 }
282 281
283 // Run a discovery phase until the named device is detected, or if the named 282 // Run a discovery phase until the named device is detected, or if the named
284 // device is not created, the discovery process ends without finding it. 283 // device is not created, the discovery process ends without finding it.
285 // 284 //
286 // The correct behavior of discovery is tested by the "Discovery" test case 285 // The correct behavior of discovery is tested by the "Discovery" test case
287 // without using this function. 286 // without using this function.
288 void DiscoverDevice(const std::string& address) { 287 void DiscoverDevice(const std::string& address) {
289 ASSERT_TRUE(adapter_.get() != nullptr); 288 ASSERT_TRUE(adapter_.get() != nullptr);
290 ASSERT_TRUE(base::MessageLoop::current() != nullptr); 289 ASSERT_TRUE(base::MessageLoop::current() != nullptr);
291 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 290 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
292 291
293 TestBluetoothAdapterObserver observer(adapter_); 292 TestBluetoothAdapterObserver observer(adapter_);
294 293
295 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 294 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
296 adapter_->StartDiscoverySession( 295 adapter_->StartDiscoverySession(
297 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 296 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
298 base::Unretained(this)), 297 base::Unretained(this)),
299 GetErrorCallback()); 298 GetErrorCallback());
300 base::MessageLoop::current()->Run(); 299 base::MessageLoop::current()->Run();
301 ASSERT_EQ(2, callback_count_); 300 ASSERT_EQ(2, callback_count_);
302 ASSERT_EQ(0, error_callback_count_); 301 ASSERT_EQ(0, error_callback_count_);
303 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 302 ASSERT_EQ((size_t)1, discovery_sessions_.size());
304 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 303 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
305 callback_count_ = 0; 304 callback_count_ = 0;
306 305
307 ASSERT_TRUE(adapter_->IsPowered()); 306 ASSERT_TRUE(adapter_->IsPowered());
(...skipping 23 matching lines...) Expand all
331 base::MessageLoop message_loop_; 330 base::MessageLoop message_loop_;
332 bluez::FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_; 331 bluez::FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_;
333 bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client_; 332 bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client_;
334 scoped_refptr<BluetoothAdapter> adapter_; 333 scoped_refptr<BluetoothAdapter> adapter_;
335 334
336 int callback_count_; 335 int callback_count_;
337 int error_callback_count_; 336 int error_callback_count_;
338 enum BluetoothDevice::ConnectErrorCode last_connect_error_; 337 enum BluetoothDevice::ConnectErrorCode last_connect_error_;
339 std::string last_client_error_; 338 std::string last_client_error_;
340 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; 339 ScopedVector<BluetoothDiscoverySession> discovery_sessions_;
341 BluetoothAdapterProfileChromeOS* adapter_profile_; 340 BluetoothAdapterProfileBlueZ* adapter_profile_;
342 341
343 private: 342 private:
344 // Some tests use a message loop since background processing is simulated; 343 // Some tests use a message loop since background processing is simulated;
345 // break out of those loops. 344 // break out of those loops.
346 void QuitMessageLoop() { 345 void QuitMessageLoop() {
347 if (base::MessageLoop::current() && 346 if (base::MessageLoop::current() &&
348 base::MessageLoop::current()->is_running()) { 347 base::MessageLoop::current()->is_running()) {
349 base::MessageLoop::current()->Quit(); 348 base::MessageLoop::current()->Quit();
350 } 349 }
351 } 350 }
352 }; 351 };
353 352
354 TEST_F(BluetoothChromeOSTest, AlreadyPresent) { 353 TEST_F(BluetoothBlueZTest, AlreadyPresent) {
355 GetAdapter(); 354 GetAdapter();
356 355
357 // This verifies that the class gets the list of adapters when created; 356 // This verifies that the class gets the list of adapters when created;
358 // and initializes with an existing adapter if there is one. 357 // and initializes with an existing adapter if there is one.
359 EXPECT_TRUE(adapter_->IsPresent()); 358 EXPECT_TRUE(adapter_->IsPresent());
360 EXPECT_FALSE(adapter_->IsPowered()); 359 EXPECT_FALSE(adapter_->IsPowered());
361 EXPECT_EQ(bluez::FakeBluetoothAdapterClient::kAdapterAddress, 360 EXPECT_EQ(bluez::FakeBluetoothAdapterClient::kAdapterAddress,
362 adapter_->GetAddress()); 361 adapter_->GetAddress());
363 EXPECT_FALSE(adapter_->IsDiscovering()); 362 EXPECT_FALSE(adapter_->IsDiscovering());
364 363
365 // There should be a device 364 // There should be a device
366 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 365 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
367 EXPECT_EQ(2U, devices.size()); 366 EXPECT_EQ(2U, devices.size());
368 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 367 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
369 devices[0]->GetAddress()); 368 devices[0]->GetAddress());
370 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, 369 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress,
371 devices[1]->GetAddress()); 370 devices[1]->GetAddress());
372 } 371 }
373 372
374 TEST_F(BluetoothChromeOSTest, BecomePresent) { 373 TEST_F(BluetoothBlueZTest, BecomePresent) {
375 fake_bluetooth_adapter_client_->SetVisible(false); 374 fake_bluetooth_adapter_client_->SetVisible(false);
376 GetAdapter(); 375 GetAdapter();
377 ASSERT_FALSE(adapter_->IsPresent()); 376 ASSERT_FALSE(adapter_->IsPresent());
378 377
379 // Install an observer; expect the AdapterPresentChanged to be called 378 // Install an observer; expect the AdapterPresentChanged to be called
380 // with true, and IsPresent() to return true. 379 // with true, and IsPresent() to return true.
381 TestBluetoothAdapterObserver observer(adapter_); 380 TestBluetoothAdapterObserver observer(adapter_);
382 381
383 fake_bluetooth_adapter_client_->SetVisible(true); 382 fake_bluetooth_adapter_client_->SetVisible(true);
384 383
385 EXPECT_EQ(1, observer.present_changed_count()); 384 EXPECT_EQ(1, observer.present_changed_count());
386 EXPECT_TRUE(observer.last_present()); 385 EXPECT_TRUE(observer.last_present());
387 386
388 EXPECT_TRUE(adapter_->IsPresent()); 387 EXPECT_TRUE(adapter_->IsPresent());
389 388
390 // We should have had a device announced. 389 // We should have had a device announced.
391 EXPECT_EQ(2, observer.device_added_count()); 390 EXPECT_EQ(2, observer.device_added_count());
392 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, 391 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress,
393 observer.last_device_address()); 392 observer.last_device_address());
394 393
395 // Other callbacks shouldn't be called if the values are false. 394 // Other callbacks shouldn't be called if the values are false.
396 EXPECT_EQ(0, observer.powered_changed_count()); 395 EXPECT_EQ(0, observer.powered_changed_count());
397 EXPECT_EQ(0, observer.discovering_changed_count()); 396 EXPECT_EQ(0, observer.discovering_changed_count());
398 EXPECT_FALSE(adapter_->IsPowered()); 397 EXPECT_FALSE(adapter_->IsPowered());
399 EXPECT_FALSE(adapter_->IsDiscovering()); 398 EXPECT_FALSE(adapter_->IsDiscovering());
400 } 399 }
401 400
402 TEST_F(BluetoothChromeOSTest, BecomeNotPresent) { 401 TEST_F(BluetoothBlueZTest, BecomeNotPresent) {
403 GetAdapter(); 402 GetAdapter();
404 ASSERT_TRUE(adapter_->IsPresent()); 403 ASSERT_TRUE(adapter_->IsPresent());
405 404
406 // Install an observer; expect the AdapterPresentChanged to be called 405 // Install an observer; expect the AdapterPresentChanged to be called
407 // with false, and IsPresent() to return false. 406 // with false, and IsPresent() to return false.
408 TestBluetoothAdapterObserver observer(adapter_); 407 TestBluetoothAdapterObserver observer(adapter_);
409 408
410 fake_bluetooth_adapter_client_->SetVisible(false); 409 fake_bluetooth_adapter_client_->SetVisible(false);
411 410
412 EXPECT_EQ(1, observer.present_changed_count()); 411 EXPECT_EQ(1, observer.present_changed_count());
413 EXPECT_FALSE(observer.last_present()); 412 EXPECT_FALSE(observer.last_present());
414 413
415 EXPECT_FALSE(adapter_->IsPresent()); 414 EXPECT_FALSE(adapter_->IsPresent());
416 415
417 // We should have had a device removed. 416 // We should have had a device removed.
418 EXPECT_EQ(2, observer.device_removed_count()); 417 EXPECT_EQ(2, observer.device_removed_count());
419 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, 418 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress,
420 observer.last_device_address()); 419 observer.last_device_address());
421 420
422 // Other callbacks shouldn't be called since the values are false. 421 // Other callbacks shouldn't be called since the values are false.
423 EXPECT_EQ(0, observer.powered_changed_count()); 422 EXPECT_EQ(0, observer.powered_changed_count());
424 EXPECT_EQ(0, observer.discovering_changed_count()); 423 EXPECT_EQ(0, observer.discovering_changed_count());
425 EXPECT_FALSE(adapter_->IsPowered()); 424 EXPECT_FALSE(adapter_->IsPowered());
426 EXPECT_FALSE(adapter_->IsDiscovering()); 425 EXPECT_FALSE(adapter_->IsDiscovering());
427 } 426 }
428 427
429 TEST_F(BluetoothChromeOSTest, SecondAdapter) { 428 TEST_F(BluetoothBlueZTest, SecondAdapter) {
430 GetAdapter(); 429 GetAdapter();
431 ASSERT_TRUE(adapter_->IsPresent()); 430 ASSERT_TRUE(adapter_->IsPresent());
432 431
433 // Install an observer, then add a second adapter. Nothing should change, 432 // Install an observer, then add a second adapter. Nothing should change,
434 // we ignore the second adapter. 433 // we ignore the second adapter.
435 TestBluetoothAdapterObserver observer(adapter_); 434 TestBluetoothAdapterObserver observer(adapter_);
436 435
437 fake_bluetooth_adapter_client_->SetSecondVisible(true); 436 fake_bluetooth_adapter_client_->SetSecondVisible(true);
438 437
439 EXPECT_EQ(0, observer.present_changed_count()); 438 EXPECT_EQ(0, observer.present_changed_count());
(...skipping 25 matching lines...) Expand all
465 observer.Reset(); 464 observer.Reset();
466 465
467 // Removing the second adapter shouldn't set anything either. 466 // Removing the second adapter shouldn't set anything either.
468 fake_bluetooth_adapter_client_->SetSecondVisible(false); 467 fake_bluetooth_adapter_client_->SetSecondVisible(false);
469 468
470 EXPECT_EQ(0, observer.device_removed_count()); 469 EXPECT_EQ(0, observer.device_removed_count());
471 EXPECT_EQ(0, observer.powered_changed_count()); 470 EXPECT_EQ(0, observer.powered_changed_count());
472 EXPECT_EQ(0, observer.discovering_changed_count()); 471 EXPECT_EQ(0, observer.discovering_changed_count());
473 } 472 }
474 473
475 TEST_F(BluetoothChromeOSTest, BecomePowered) { 474 TEST_F(BluetoothBlueZTest, BecomePowered) {
476 GetAdapter(); 475 GetAdapter();
477 ASSERT_FALSE(adapter_->IsPowered()); 476 ASSERT_FALSE(adapter_->IsPowered());
478 477
479 // Install an observer; expect the AdapterPoweredChanged to be called 478 // Install an observer; expect the AdapterPoweredChanged to be called
480 // with true, and IsPowered() to return true. 479 // with true, and IsPowered() to return true.
481 TestBluetoothAdapterObserver observer(adapter_); 480 TestBluetoothAdapterObserver observer(adapter_);
482 481
483 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 482 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
484 EXPECT_EQ(1, callback_count_); 483 EXPECT_EQ(1, callback_count_);
485 EXPECT_EQ(0, error_callback_count_); 484 EXPECT_EQ(0, error_callback_count_);
486 485
487 EXPECT_EQ(1, observer.powered_changed_count()); 486 EXPECT_EQ(1, observer.powered_changed_count());
488 EXPECT_TRUE(observer.last_powered()); 487 EXPECT_TRUE(observer.last_powered());
489 488
490 EXPECT_TRUE(adapter_->IsPowered()); 489 EXPECT_TRUE(adapter_->IsPowered());
491 } 490 }
492 491
493 TEST_F(BluetoothChromeOSTest, BecomeNotPowered) { 492 TEST_F(BluetoothBlueZTest, BecomeNotPowered) {
494 GetAdapter(); 493 GetAdapter();
495 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 494 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
496 EXPECT_EQ(1, callback_count_); 495 EXPECT_EQ(1, callback_count_);
497 EXPECT_EQ(0, error_callback_count_); 496 EXPECT_EQ(0, error_callback_count_);
498 callback_count_ = 0; 497 callback_count_ = 0;
499 498
500 ASSERT_TRUE(adapter_->IsPowered()); 499 ASSERT_TRUE(adapter_->IsPowered());
501 500
502 // Install an observer; expect the AdapterPoweredChanged to be called 501 // Install an observer; expect the AdapterPoweredChanged to be called
503 // with false, and IsPowered() to return false. 502 // with false, and IsPowered() to return false.
504 TestBluetoothAdapterObserver observer(adapter_); 503 TestBluetoothAdapterObserver observer(adapter_);
505 504
506 adapter_->SetPowered(false, GetCallback(), GetErrorCallback()); 505 adapter_->SetPowered(false, GetCallback(), GetErrorCallback());
507 EXPECT_EQ(1, callback_count_); 506 EXPECT_EQ(1, callback_count_);
508 EXPECT_EQ(0, error_callback_count_); 507 EXPECT_EQ(0, error_callback_count_);
509 508
510 EXPECT_EQ(1, observer.powered_changed_count()); 509 EXPECT_EQ(1, observer.powered_changed_count());
511 EXPECT_FALSE(observer.last_powered()); 510 EXPECT_FALSE(observer.last_powered());
512 511
513 EXPECT_FALSE(adapter_->IsPowered()); 512 EXPECT_FALSE(adapter_->IsPowered());
514 } 513 }
515 514
516 TEST_F(BluetoothChromeOSTest, SetPoweredWhenNotPresent) { 515 TEST_F(BluetoothBlueZTest, SetPoweredWhenNotPresent) {
517 GetAdapter(); 516 GetAdapter();
518 ASSERT_TRUE(adapter_->IsPresent()); 517 ASSERT_TRUE(adapter_->IsPresent());
519 518
520 // Install an observer; expect the AdapterPresentChanged to be called 519 // Install an observer; expect the AdapterPresentChanged to be called
521 // with false, and IsPresent() to return false. 520 // with false, and IsPresent() to return false.
522 TestBluetoothAdapterObserver observer(adapter_); 521 TestBluetoothAdapterObserver observer(adapter_);
523 522
524 fake_bluetooth_adapter_client_->SetVisible(false); 523 fake_bluetooth_adapter_client_->SetVisible(false);
525 524
526 EXPECT_EQ(1, observer.present_changed_count()); 525 EXPECT_EQ(1, observer.present_changed_count());
527 EXPECT_FALSE(observer.last_present()); 526 EXPECT_FALSE(observer.last_present());
528 527
529 EXPECT_FALSE(adapter_->IsPresent()); 528 EXPECT_FALSE(adapter_->IsPresent());
530 EXPECT_FALSE(adapter_->IsPowered()); 529 EXPECT_FALSE(adapter_->IsPowered());
531 530
532 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 531 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
533 EXPECT_EQ(0, callback_count_); 532 EXPECT_EQ(0, callback_count_);
534 EXPECT_EQ(1, error_callback_count_); 533 EXPECT_EQ(1, error_callback_count_);
535 534
536 EXPECT_EQ(0, observer.powered_changed_count()); 535 EXPECT_EQ(0, observer.powered_changed_count());
537 EXPECT_FALSE(observer.last_powered()); 536 EXPECT_FALSE(observer.last_powered());
538 537
539 EXPECT_FALSE(adapter_->IsPowered()); 538 EXPECT_FALSE(adapter_->IsPowered());
540 } 539 }
541 540
542 TEST_F(BluetoothChromeOSTest, ChangeAdapterName) { 541 TEST_F(BluetoothBlueZTest, ChangeAdapterName) {
543 GetAdapter(); 542 GetAdapter();
544 543
545 static const std::string new_name(".__."); 544 static const std::string new_name(".__.");
546 545
547 adapter_->SetName(new_name, GetCallback(), GetErrorCallback()); 546 adapter_->SetName(new_name, GetCallback(), GetErrorCallback());
548 EXPECT_EQ(1, callback_count_); 547 EXPECT_EQ(1, callback_count_);
549 EXPECT_EQ(0, error_callback_count_); 548 EXPECT_EQ(0, error_callback_count_);
550 549
551 EXPECT_EQ(new_name, adapter_->GetName()); 550 EXPECT_EQ(new_name, adapter_->GetName());
552 } 551 }
553 552
554 TEST_F(BluetoothChromeOSTest, ChangeAdapterNameWhenNotPresent) { 553 TEST_F(BluetoothBlueZTest, ChangeAdapterNameWhenNotPresent) {
555 GetAdapter(); 554 GetAdapter();
556 ASSERT_TRUE(adapter_->IsPresent()); 555 ASSERT_TRUE(adapter_->IsPresent());
557 556
558 // Install an observer; expect the AdapterPresentChanged to be called 557 // Install an observer; expect the AdapterPresentChanged to be called
559 // with false, and IsPresent() to return false. 558 // with false, and IsPresent() to return false.
560 TestBluetoothAdapterObserver observer(adapter_); 559 TestBluetoothAdapterObserver observer(adapter_);
561 560
562 fake_bluetooth_adapter_client_->SetVisible(false); 561 fake_bluetooth_adapter_client_->SetVisible(false);
563 562
564 EXPECT_EQ(1, observer.present_changed_count()); 563 EXPECT_EQ(1, observer.present_changed_count());
565 EXPECT_FALSE(observer.last_present()); 564 EXPECT_FALSE(observer.last_present());
566 565
567 EXPECT_FALSE(adapter_->IsPresent()); 566 EXPECT_FALSE(adapter_->IsPresent());
568 EXPECT_FALSE(adapter_->IsPowered()); 567 EXPECT_FALSE(adapter_->IsPowered());
569 568
570 adapter_->SetName("^o^", GetCallback(), GetErrorCallback()); 569 adapter_->SetName("^o^", GetCallback(), GetErrorCallback());
571 EXPECT_EQ(0, callback_count_); 570 EXPECT_EQ(0, callback_count_);
572 EXPECT_EQ(1, error_callback_count_); 571 EXPECT_EQ(1, error_callback_count_);
573 572
574 EXPECT_EQ("", adapter_->GetName()); 573 EXPECT_EQ("", adapter_->GetName());
575 } 574 }
576 575
577 TEST_F(BluetoothChromeOSTest, BecomeDiscoverable) { 576 TEST_F(BluetoothBlueZTest, BecomeDiscoverable) {
578 GetAdapter(); 577 GetAdapter();
579 ASSERT_FALSE(adapter_->IsDiscoverable()); 578 ASSERT_FALSE(adapter_->IsDiscoverable());
580 579
581 // Install an observer; expect the AdapterDiscoverableChanged to be called 580 // Install an observer; expect the AdapterDiscoverableChanged to be called
582 // with true, and IsDiscoverable() to return true. 581 // with true, and IsDiscoverable() to return true.
583 TestBluetoothAdapterObserver observer(adapter_); 582 TestBluetoothAdapterObserver observer(adapter_);
584 583
585 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); 584 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
586 EXPECT_EQ(1, callback_count_); 585 EXPECT_EQ(1, callback_count_);
587 EXPECT_EQ(0, error_callback_count_); 586 EXPECT_EQ(0, error_callback_count_);
588 587
589 EXPECT_EQ(1, observer.discoverable_changed_count()); 588 EXPECT_EQ(1, observer.discoverable_changed_count());
590 589
591 EXPECT_TRUE(adapter_->IsDiscoverable()); 590 EXPECT_TRUE(adapter_->IsDiscoverable());
592 } 591 }
593 592
594 TEST_F(BluetoothChromeOSTest, BecomeNotDiscoverable) { 593 TEST_F(BluetoothBlueZTest, BecomeNotDiscoverable) {
595 GetAdapter(); 594 GetAdapter();
596 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); 595 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
597 EXPECT_EQ(1, callback_count_); 596 EXPECT_EQ(1, callback_count_);
598 EXPECT_EQ(0, error_callback_count_); 597 EXPECT_EQ(0, error_callback_count_);
599 callback_count_ = 0; 598 callback_count_ = 0;
600 599
601 ASSERT_TRUE(adapter_->IsDiscoverable()); 600 ASSERT_TRUE(adapter_->IsDiscoverable());
602 601
603 // Install an observer; expect the AdapterDiscoverableChanged to be called 602 // Install an observer; expect the AdapterDiscoverableChanged to be called
604 // with false, and IsDiscoverable() to return false. 603 // with false, and IsDiscoverable() to return false.
605 TestBluetoothAdapterObserver observer(adapter_); 604 TestBluetoothAdapterObserver observer(adapter_);
606 605
607 adapter_->SetDiscoverable(false, GetCallback(), GetErrorCallback()); 606 adapter_->SetDiscoverable(false, GetCallback(), GetErrorCallback());
608 EXPECT_EQ(1, callback_count_); 607 EXPECT_EQ(1, callback_count_);
609 EXPECT_EQ(0, error_callback_count_); 608 EXPECT_EQ(0, error_callback_count_);
610 609
611 EXPECT_EQ(1, observer.discoverable_changed_count()); 610 EXPECT_EQ(1, observer.discoverable_changed_count());
612 611
613 EXPECT_FALSE(adapter_->IsDiscoverable()); 612 EXPECT_FALSE(adapter_->IsDiscoverable());
614 } 613 }
615 614
616 TEST_F(BluetoothChromeOSTest, SetDiscoverableWhenNotPresent) { 615 TEST_F(BluetoothBlueZTest, SetDiscoverableWhenNotPresent) {
617 GetAdapter(); 616 GetAdapter();
618 ASSERT_TRUE(adapter_->IsPresent()); 617 ASSERT_TRUE(adapter_->IsPresent());
619 ASSERT_FALSE(adapter_->IsDiscoverable()); 618 ASSERT_FALSE(adapter_->IsDiscoverable());
620 619
621 // Install an observer; expect the AdapterDiscoverableChanged to be called 620 // Install an observer; expect the AdapterDiscoverableChanged to be called
622 // with true, and IsDiscoverable() to return true. 621 // with true, and IsDiscoverable() to return true.
623 TestBluetoothAdapterObserver observer(adapter_); 622 TestBluetoothAdapterObserver observer(adapter_);
624 623
625 fake_bluetooth_adapter_client_->SetVisible(false); 624 fake_bluetooth_adapter_client_->SetVisible(false);
626 625
627 EXPECT_EQ(1, observer.present_changed_count()); 626 EXPECT_EQ(1, observer.present_changed_count());
628 EXPECT_FALSE(observer.last_present()); 627 EXPECT_FALSE(observer.last_present());
629 628
630 EXPECT_FALSE(adapter_->IsPresent()); 629 EXPECT_FALSE(adapter_->IsPresent());
631 EXPECT_FALSE(adapter_->IsDiscoverable()); 630 EXPECT_FALSE(adapter_->IsDiscoverable());
632 631
633 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); 632 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
634 EXPECT_EQ(0, callback_count_); 633 EXPECT_EQ(0, callback_count_);
635 EXPECT_EQ(1, error_callback_count_); 634 EXPECT_EQ(1, error_callback_count_);
636 635
637 EXPECT_EQ(0, observer.discoverable_changed_count()); 636 EXPECT_EQ(0, observer.discoverable_changed_count());
638 637
639 EXPECT_FALSE(adapter_->IsDiscoverable()); 638 EXPECT_FALSE(adapter_->IsDiscoverable());
640 } 639 }
641 640
642 TEST_F(BluetoothChromeOSTest, StopDiscovery) { 641 TEST_F(BluetoothBlueZTest, StopDiscovery) {
643 GetAdapter(); 642 GetAdapter();
644 643
645 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 644 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
646 adapter_->StartDiscoverySession( 645 adapter_->StartDiscoverySession(
647 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 646 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
648 base::Unretained(this)), 647 base::Unretained(this)),
649 GetErrorCallback()); 648 GetErrorCallback());
650 message_loop_.Run(); 649 message_loop_.Run();
651 EXPECT_EQ(2, callback_count_); 650 EXPECT_EQ(2, callback_count_);
652 EXPECT_EQ(0, error_callback_count_); 651 EXPECT_EQ(0, error_callback_count_);
653 callback_count_ = 0; 652 callback_count_ = 0;
654 653
655 ASSERT_TRUE(adapter_->IsPowered()); 654 ASSERT_TRUE(adapter_->IsPowered());
656 ASSERT_TRUE(adapter_->IsDiscovering()); 655 ASSERT_TRUE(adapter_->IsDiscovering());
657 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 656 ASSERT_EQ((size_t)1, discovery_sessions_.size());
(...skipping 13 matching lines...) Expand all
671 EXPECT_FALSE(observer.last_discovering()); 670 EXPECT_FALSE(observer.last_discovering());
672 671
673 EXPECT_FALSE(adapter_->IsDiscovering()); 672 EXPECT_FALSE(adapter_->IsDiscovering());
674 discovery_sessions_.clear(); 673 discovery_sessions_.clear();
675 callback_count_ = 0; 674 callback_count_ = 0;
676 675
677 // Test that the Stop callbacks get called even if the 676 // Test that the Stop callbacks get called even if the
678 // BluetoothDiscoverySession objects gets deleted 677 // BluetoothDiscoverySession objects gets deleted
679 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 678 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
680 adapter_->StartDiscoverySession( 679 adapter_->StartDiscoverySession(
681 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 680 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
682 base::Unretained(this)), 681 base::Unretained(this)),
683 GetErrorCallback()); 682 GetErrorCallback());
684 message_loop_.Run(); 683 message_loop_.Run();
685 EXPECT_EQ(2, callback_count_); 684 EXPECT_EQ(2, callback_count_);
686 EXPECT_EQ(0, error_callback_count_); 685 EXPECT_EQ(0, error_callback_count_);
687 callback_count_ = 0; 686 callback_count_ = 0;
688 ASSERT_TRUE(adapter_->IsPowered()); 687 ASSERT_TRUE(adapter_->IsPowered());
689 ASSERT_TRUE(adapter_->IsDiscovering()); 688 ASSERT_TRUE(adapter_->IsDiscovering());
690 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 689 ASSERT_EQ((size_t)1, discovery_sessions_.size());
691 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 690 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
692 691
693 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 692 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
694 discovery_sessions_.clear(); 693 discovery_sessions_.clear();
695 694
696 message_loop_.Run(); 695 message_loop_.Run();
697 EXPECT_EQ(1, callback_count_); 696 EXPECT_EQ(1, callback_count_);
698 EXPECT_EQ(0, error_callback_count_); 697 EXPECT_EQ(0, error_callback_count_);
699 } 698 }
700 699
701 TEST_F(BluetoothChromeOSTest, Discovery) { 700 TEST_F(BluetoothBlueZTest, Discovery) {
702 // Test a simulated discovery session. 701 // Test a simulated discovery session.
703 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 702 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
704 GetAdapter(); 703 GetAdapter();
705 704
706 TestBluetoothAdapterObserver observer(adapter_); 705 TestBluetoothAdapterObserver observer(adapter_);
707 706
708 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 707 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
709 adapter_->StartDiscoverySession( 708 adapter_->StartDiscoverySession(
710 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 709 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
711 base::Unretained(this)), 710 base::Unretained(this)),
712 GetErrorCallback()); 711 GetErrorCallback());
713 message_loop_.Run(); 712 message_loop_.Run();
714 EXPECT_EQ(2, callback_count_); 713 EXPECT_EQ(2, callback_count_);
715 EXPECT_EQ(0, error_callback_count_); 714 EXPECT_EQ(0, error_callback_count_);
716 callback_count_ = 0; 715 callback_count_ = 0;
717 716
718 ASSERT_TRUE(adapter_->IsPowered()); 717 ASSERT_TRUE(adapter_->IsPowered());
719 ASSERT_TRUE(adapter_->IsDiscovering()); 718 ASSERT_TRUE(adapter_->IsDiscovering());
720 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 719 ASSERT_EQ((size_t)1, discovery_sessions_.size());
(...skipping 12 matching lines...) Expand all
733 732
734 // Okay, let's run forward until a device is actually removed... 733 // Okay, let's run forward until a device is actually removed...
735 while (!observer.device_removed_count()) 734 while (!observer.device_removed_count())
736 message_loop_.Run(); 735 message_loop_.Run();
737 736
738 EXPECT_EQ(1, observer.device_removed_count()); 737 EXPECT_EQ(1, observer.device_removed_count());
739 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress, 738 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress,
740 observer.last_device_address()); 739 observer.last_device_address());
741 } 740 }
742 741
743 TEST_F(BluetoothChromeOSTest, PoweredAndDiscovering) { 742 TEST_F(BluetoothBlueZTest, PoweredAndDiscovering) {
744 GetAdapter(); 743 GetAdapter();
745 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 744 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
746 adapter_->StartDiscoverySession( 745 adapter_->StartDiscoverySession(
747 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 746 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
748 base::Unretained(this)), 747 base::Unretained(this)),
749 GetErrorCallback()); 748 GetErrorCallback());
750 message_loop_.Run(); 749 message_loop_.Run();
751 EXPECT_EQ(2, callback_count_); 750 EXPECT_EQ(2, callback_count_);
752 EXPECT_EQ(0, error_callback_count_); 751 EXPECT_EQ(0, error_callback_count_);
753 callback_count_ = 0; 752 callback_count_ = 0;
754 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 753 ASSERT_EQ((size_t)1, discovery_sessions_.size());
755 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 754 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
756 755
757 // Stop the timers that the simulation uses 756 // Stop the timers that the simulation uses
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 EXPECT_FALSE(observer.last_powered()); 798 EXPECT_FALSE(observer.last_powered());
800 EXPECT_FALSE(adapter_->IsPowered()); 799 EXPECT_FALSE(adapter_->IsPowered());
801 800
802 EXPECT_EQ(1, observer.discovering_changed_count()); 801 EXPECT_EQ(1, observer.discovering_changed_count());
803 EXPECT_FALSE(observer.last_discovering()); 802 EXPECT_FALSE(observer.last_discovering());
804 EXPECT_FALSE(adapter_->IsDiscovering()); 803 EXPECT_FALSE(adapter_->IsDiscovering());
805 } 804 }
806 805
807 // This unit test asserts that the basic reference counting logic works 806 // This unit test asserts that the basic reference counting logic works
808 // correctly for discovery requests done via the BluetoothAdapter. 807 // correctly for discovery requests done via the BluetoothAdapter.
809 TEST_F(BluetoothChromeOSTest, MultipleDiscoverySessions) { 808 TEST_F(BluetoothBlueZTest, MultipleDiscoverySessions) {
810 GetAdapter(); 809 GetAdapter();
811 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 810 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
812 EXPECT_EQ(1, callback_count_); 811 EXPECT_EQ(1, callback_count_);
813 EXPECT_EQ(0, error_callback_count_); 812 EXPECT_EQ(0, error_callback_count_);
814 EXPECT_TRUE(adapter_->IsPowered()); 813 EXPECT_TRUE(adapter_->IsPowered());
815 callback_count_ = 0; 814 callback_count_ = 0;
816 815
817 TestBluetoothAdapterObserver observer(adapter_); 816 TestBluetoothAdapterObserver observer(adapter_);
818 817
819 EXPECT_EQ(0, observer.discovering_changed_count()); 818 EXPECT_EQ(0, observer.discovering_changed_count());
820 EXPECT_FALSE(observer.last_discovering()); 819 EXPECT_FALSE(observer.last_discovering());
821 EXPECT_FALSE(adapter_->IsDiscovering()); 820 EXPECT_FALSE(adapter_->IsDiscovering());
822 821
823 // Request device discovery 3 times. 822 // Request device discovery 3 times.
824 for (int i = 0; i < 3; i++) { 823 for (int i = 0; i < 3; i++) {
825 adapter_->StartDiscoverySession( 824 adapter_->StartDiscoverySession(
826 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 825 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
827 base::Unretained(this)), 826 base::Unretained(this)),
828 GetErrorCallback()); 827 GetErrorCallback());
829 } 828 }
830 // Run only once, as there should have been one D-Bus call. 829 // Run only once, as there should have been one D-Bus call.
831 message_loop_.Run(); 830 message_loop_.Run();
832 831
833 // The observer should have received the discovering changed event exactly 832 // The observer should have received the discovering changed event exactly
834 // once, the success callback should have been called 3 times and the adapter 833 // once, the success callback should have been called 3 times and the adapter
835 // should be discovering. 834 // should be discovering.
836 EXPECT_EQ(1, observer.discovering_changed_count()); 835 EXPECT_EQ(1, observer.discovering_changed_count());
(...skipping 17 matching lines...) Expand all
854 EXPECT_TRUE(observer.last_discovering()); 853 EXPECT_TRUE(observer.last_discovering());
855 EXPECT_TRUE(adapter_->IsDiscovering()); 854 EXPECT_TRUE(adapter_->IsDiscovering());
856 EXPECT_TRUE(adapter_->IsDiscovering()); 855 EXPECT_TRUE(adapter_->IsDiscovering());
857 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 856 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
858 EXPECT_FALSE(discovery_sessions_[1]->IsActive()); 857 EXPECT_FALSE(discovery_sessions_[1]->IsActive());
859 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); 858 EXPECT_TRUE(discovery_sessions_[2]->IsActive());
860 859
861 // Request device discovery 3 times. 860 // Request device discovery 3 times.
862 for (int i = 0; i < 3; i++) { 861 for (int i = 0; i < 3; i++) {
863 adapter_->StartDiscoverySession( 862 adapter_->StartDiscoverySession(
864 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 863 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
865 base::Unretained(this)), 864 base::Unretained(this)),
866 GetErrorCallback()); 865 GetErrorCallback());
867 } 866 }
868 867
869 // The observer should have received no additional discovering changed events, 868 // The observer should have received no additional discovering changed events,
870 // the success callback should have been called 3 times and the adapter should 869 // the success callback should have been called 3 times and the adapter should
871 // still be discovering. 870 // still be discovering.
872 EXPECT_EQ(1, observer.discovering_changed_count()); 871 EXPECT_EQ(1, observer.discovering_changed_count());
873 EXPECT_EQ(8, callback_count_); 872 EXPECT_EQ(8, callback_count_);
874 EXPECT_EQ(0, error_callback_count_); 873 EXPECT_EQ(0, error_callback_count_);
(...skipping 28 matching lines...) Expand all
903 EXPECT_EQ(2, observer.discovering_changed_count()); 902 EXPECT_EQ(2, observer.discovering_changed_count());
904 EXPECT_EQ(12, callback_count_); 903 EXPECT_EQ(12, callback_count_);
905 EXPECT_EQ(1, error_callback_count_); 904 EXPECT_EQ(1, error_callback_count_);
906 EXPECT_FALSE(observer.last_discovering()); 905 EXPECT_FALSE(observer.last_discovering());
907 EXPECT_FALSE(adapter_->IsDiscovering()); 906 EXPECT_FALSE(adapter_->IsDiscovering());
908 } 907 }
909 908
910 // This unit test asserts that the reference counting logic works correctly in 909 // This unit test asserts that the reference counting logic works correctly in
911 // the cases when the adapter gets reset and D-Bus calls are made outside of 910 // the cases when the adapter gets reset and D-Bus calls are made outside of
912 // the BluetoothAdapter. 911 // the BluetoothAdapter.
913 TEST_F(BluetoothChromeOSTest, 912 TEST_F(BluetoothBlueZTest, UnexpectedChangesDuringMultipleDiscoverySessions) {
914 UnexpectedChangesDuringMultipleDiscoverySessions) {
915 GetAdapter(); 913 GetAdapter();
916 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 914 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
917 EXPECT_EQ(1, callback_count_); 915 EXPECT_EQ(1, callback_count_);
918 EXPECT_EQ(0, error_callback_count_); 916 EXPECT_EQ(0, error_callback_count_);
919 EXPECT_TRUE(adapter_->IsPowered()); 917 EXPECT_TRUE(adapter_->IsPowered());
920 callback_count_ = 0; 918 callback_count_ = 0;
921 919
922 TestBluetoothAdapterObserver observer(adapter_); 920 TestBluetoothAdapterObserver observer(adapter_);
923 921
924 EXPECT_EQ(0, observer.discovering_changed_count()); 922 EXPECT_EQ(0, observer.discovering_changed_count());
925 EXPECT_FALSE(observer.last_discovering()); 923 EXPECT_FALSE(observer.last_discovering());
926 EXPECT_FALSE(adapter_->IsDiscovering()); 924 EXPECT_FALSE(adapter_->IsDiscovering());
927 925
928 // Request device discovery 3 times. 926 // Request device discovery 3 times.
929 for (int i = 0; i < 3; i++) { 927 for (int i = 0; i < 3; i++) {
930 adapter_->StartDiscoverySession( 928 adapter_->StartDiscoverySession(
931 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 929 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
932 base::Unretained(this)), 930 base::Unretained(this)),
933 GetErrorCallback()); 931 GetErrorCallback());
934 } 932 }
935 // Run only once, as there should have been one D-Bus call. 933 // Run only once, as there should have been one D-Bus call.
936 message_loop_.Run(); 934 message_loop_.Run();
937 935
938 // The observer should have received the discovering changed event exactly 936 // The observer should have received the discovering changed event exactly
939 // once, the success callback should have been called 3 times and the adapter 937 // once, the success callback should have been called 3 times and the adapter
940 // should be discovering. 938 // should be discovering.
941 EXPECT_EQ(1, observer.discovering_changed_count()); 939 EXPECT_EQ(1, observer.discovering_changed_count());
(...skipping 16 matching lines...) Expand all
958 // Stop device discovery behind the adapter. The adapter and the observer 956 // Stop device discovery behind the adapter. The adapter and the observer
959 // should be notified of the change and the reference count should be reset. 957 // should be notified of the change and the reference count should be reset.
960 // Even though bluez::FakeBluetoothAdapterClient does its own reference 958 // Even though bluez::FakeBluetoothAdapterClient does its own reference
961 // counting and 959 // counting and
962 // we called 3 BluetoothAdapter::StartDiscoverySession 3 times, the 960 // we called 3 BluetoothAdapter::StartDiscoverySession 3 times, the
963 // bluez::FakeBluetoothAdapterClient's count should be only 1 and a single 961 // bluez::FakeBluetoothAdapterClient's count should be only 1 and a single
964 // call to 962 // call to
965 // bluez::FakeBluetoothAdapterClient::StopDiscovery should work. 963 // bluez::FakeBluetoothAdapterClient::StopDiscovery should work.
966 fake_bluetooth_adapter_client_->StopDiscovery( 964 fake_bluetooth_adapter_client_->StopDiscovery(
967 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 965 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
968 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 966 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
969 base::Unretained(this))); 967 base::Unretained(this)));
970 message_loop_.Run(); 968 message_loop_.Run();
971 EXPECT_EQ(2, observer.discovering_changed_count()); 969 EXPECT_EQ(2, observer.discovering_changed_count());
972 EXPECT_EQ(4, callback_count_); 970 EXPECT_EQ(4, callback_count_);
973 EXPECT_EQ(0, error_callback_count_); 971 EXPECT_EQ(0, error_callback_count_);
974 EXPECT_FALSE(observer.last_discovering()); 972 EXPECT_FALSE(observer.last_discovering());
975 EXPECT_FALSE(adapter_->IsDiscovering()); 973 EXPECT_FALSE(adapter_->IsDiscovering());
976 974
977 // All discovery session instances should have been updated. 975 // All discovery session instances should have been updated.
978 for (int i = 0; i < 3; i++) 976 for (int i = 0; i < 3; i++)
979 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); 977 EXPECT_FALSE(discovery_sessions_[i]->IsActive());
980 discovery_sessions_.clear(); 978 discovery_sessions_.clear();
981 979
982 // It should be possible to successfully start discovery. 980 // It should be possible to successfully start discovery.
983 for (int i = 0; i < 2; i++) { 981 for (int i = 0; i < 2; i++) {
984 adapter_->StartDiscoverySession( 982 adapter_->StartDiscoverySession(
985 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 983 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
986 base::Unretained(this)), 984 base::Unretained(this)),
987 GetErrorCallback()); 985 GetErrorCallback());
988 } 986 }
989 // Run only once, as there should have been one D-Bus call. 987 // Run only once, as there should have been one D-Bus call.
990 message_loop_.Run(); 988 message_loop_.Run();
991 EXPECT_EQ(3, observer.discovering_changed_count()); 989 EXPECT_EQ(3, observer.discovering_changed_count());
992 EXPECT_EQ(6, callback_count_); 990 EXPECT_EQ(6, callback_count_);
993 EXPECT_EQ(0, error_callback_count_); 991 EXPECT_EQ(0, error_callback_count_);
994 EXPECT_TRUE(observer.last_discovering()); 992 EXPECT_TRUE(observer.last_discovering());
995 EXPECT_TRUE(adapter_->IsDiscovering()); 993 EXPECT_TRUE(adapter_->IsDiscovering());
(...skipping 27 matching lines...) Expand all
1023 EXPECT_EQ(0, error_callback_count_); 1021 EXPECT_EQ(0, error_callback_count_);
1024 EXPECT_TRUE(observer.last_discovering()); 1022 EXPECT_TRUE(observer.last_discovering());
1025 EXPECT_TRUE(adapter_->IsDiscovering()); 1023 EXPECT_TRUE(adapter_->IsDiscovering());
1026 1024
1027 // Start and stop discovery. At this point, bluez::FakeBluetoothAdapterClient 1025 // Start and stop discovery. At this point, bluez::FakeBluetoothAdapterClient
1028 // has 1026 // has
1029 // a reference count that is equal to 1. Pretend that this was done by an 1027 // a reference count that is equal to 1. Pretend that this was done by an
1030 // application other than us. Starting and stopping discovery will succeed 1028 // application other than us. Starting and stopping discovery will succeed
1031 // but it won't cause the discovery state to change. 1029 // but it won't cause the discovery state to change.
1032 adapter_->StartDiscoverySession( 1030 adapter_->StartDiscoverySession(
1033 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1031 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1034 base::Unretained(this)), 1032 base::Unretained(this)),
1035 GetErrorCallback()); 1033 GetErrorCallback());
1036 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. 1034 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call.
1037 EXPECT_EQ(5, observer.discovering_changed_count()); 1035 EXPECT_EQ(5, observer.discovering_changed_count());
1038 EXPECT_EQ(7, callback_count_); 1036 EXPECT_EQ(7, callback_count_);
1039 EXPECT_EQ(0, error_callback_count_); 1037 EXPECT_EQ(0, error_callback_count_);
1040 EXPECT_TRUE(observer.last_discovering()); 1038 EXPECT_TRUE(observer.last_discovering());
1041 EXPECT_TRUE(adapter_->IsDiscovering()); 1039 EXPECT_TRUE(adapter_->IsDiscovering());
1042 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1040 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1043 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1041 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1044 1042
1045 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 1043 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
1046 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. 1044 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call.
1047 EXPECT_EQ(5, observer.discovering_changed_count()); 1045 EXPECT_EQ(5, observer.discovering_changed_count());
1048 EXPECT_EQ(8, callback_count_); 1046 EXPECT_EQ(8, callback_count_);
1049 EXPECT_EQ(0, error_callback_count_); 1047 EXPECT_EQ(0, error_callback_count_);
1050 EXPECT_TRUE(observer.last_discovering()); 1048 EXPECT_TRUE(observer.last_discovering());
1051 EXPECT_TRUE(adapter_->IsDiscovering()); 1049 EXPECT_TRUE(adapter_->IsDiscovering());
1052 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 1050 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
1053 discovery_sessions_.clear(); 1051 discovery_sessions_.clear();
1054 1052
1055 // Start discovery again. 1053 // Start discovery again.
1056 adapter_->StartDiscoverySession( 1054 adapter_->StartDiscoverySession(
1057 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1055 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1058 base::Unretained(this)), 1056 base::Unretained(this)),
1059 GetErrorCallback()); 1057 GetErrorCallback());
1060 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. 1058 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call.
1061 EXPECT_EQ(5, observer.discovering_changed_count()); 1059 EXPECT_EQ(5, observer.discovering_changed_count());
1062 EXPECT_EQ(9, callback_count_); 1060 EXPECT_EQ(9, callback_count_);
1063 EXPECT_EQ(0, error_callback_count_); 1061 EXPECT_EQ(0, error_callback_count_);
1064 EXPECT_TRUE(observer.last_discovering()); 1062 EXPECT_TRUE(observer.last_discovering());
1065 EXPECT_TRUE(adapter_->IsDiscovering()); 1063 EXPECT_TRUE(adapter_->IsDiscovering());
1066 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1064 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1067 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1065 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1068 1066
1069 // Stop discovery via D-Bus. The fake client's reference count will drop but 1067 // Stop discovery via D-Bus. The fake client's reference count will drop but
1070 // the discovery state won't change since our BluetoothAdapter also just 1068 // the discovery state won't change since our BluetoothAdapter also just
1071 // requested it via D-Bus. 1069 // requested it via D-Bus.
1072 fake_bluetooth_adapter_client_->StopDiscovery( 1070 fake_bluetooth_adapter_client_->StopDiscovery(
1073 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 1071 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
1074 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 1072 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
1075 base::Unretained(this))); 1073 base::Unretained(this)));
1076 message_loop_.Run(); 1074 message_loop_.Run();
1077 EXPECT_EQ(5, observer.discovering_changed_count()); 1075 EXPECT_EQ(5, observer.discovering_changed_count());
1078 EXPECT_EQ(10, callback_count_); 1076 EXPECT_EQ(10, callback_count_);
1079 EXPECT_EQ(0, error_callback_count_); 1077 EXPECT_EQ(0, error_callback_count_);
1080 EXPECT_TRUE(observer.last_discovering()); 1078 EXPECT_TRUE(observer.last_discovering());
1081 EXPECT_TRUE(adapter_->IsDiscovering()); 1079 EXPECT_TRUE(adapter_->IsDiscovering());
1082 1080
1083 // Now end the discovery session. This should change the adapter's discovery 1081 // Now end the discovery session. This should change the adapter's discovery
1084 // state. 1082 // state.
1085 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 1083 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
1086 message_loop_.Run(); 1084 message_loop_.Run();
1087 EXPECT_EQ(6, observer.discovering_changed_count()); 1085 EXPECT_EQ(6, observer.discovering_changed_count());
1088 EXPECT_EQ(11, callback_count_); 1086 EXPECT_EQ(11, callback_count_);
1089 EXPECT_EQ(0, error_callback_count_); 1087 EXPECT_EQ(0, error_callback_count_);
1090 EXPECT_FALSE(observer.last_discovering()); 1088 EXPECT_FALSE(observer.last_discovering());
1091 EXPECT_FALSE(adapter_->IsDiscovering()); 1089 EXPECT_FALSE(adapter_->IsDiscovering());
1092 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 1090 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
1093 } 1091 }
1094 1092
1095 TEST_F(BluetoothChromeOSTest, InvalidatedDiscoverySessions) { 1093 TEST_F(BluetoothBlueZTest, InvalidatedDiscoverySessions) {
1096 GetAdapter(); 1094 GetAdapter();
1097 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 1095 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
1098 EXPECT_EQ(1, callback_count_); 1096 EXPECT_EQ(1, callback_count_);
1099 EXPECT_EQ(0, error_callback_count_); 1097 EXPECT_EQ(0, error_callback_count_);
1100 EXPECT_TRUE(adapter_->IsPowered()); 1098 EXPECT_TRUE(adapter_->IsPowered());
1101 callback_count_ = 0; 1099 callback_count_ = 0;
1102 1100
1103 TestBluetoothAdapterObserver observer(adapter_); 1101 TestBluetoothAdapterObserver observer(adapter_);
1104 1102
1105 EXPECT_EQ(0, observer.discovering_changed_count()); 1103 EXPECT_EQ(0, observer.discovering_changed_count());
1106 EXPECT_FALSE(observer.last_discovering()); 1104 EXPECT_FALSE(observer.last_discovering());
1107 EXPECT_FALSE(adapter_->IsDiscovering()); 1105 EXPECT_FALSE(adapter_->IsDiscovering());
1108 1106
1109 // Request device discovery 3 times. 1107 // Request device discovery 3 times.
1110 for (int i = 0; i < 3; i++) { 1108 for (int i = 0; i < 3; i++) {
1111 adapter_->StartDiscoverySession( 1109 adapter_->StartDiscoverySession(
1112 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1110 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1113 base::Unretained(this)), 1111 base::Unretained(this)),
1114 GetErrorCallback()); 1112 GetErrorCallback());
1115 } 1113 }
1116 // Run only once, as there should have been one D-Bus call. 1114 // Run only once, as there should have been one D-Bus call.
1117 message_loop_.Run(); 1115 message_loop_.Run();
1118 1116
1119 // The observer should have received the discovering changed event exactly 1117 // The observer should have received the discovering changed event exactly
1120 // once, the success callback should have been called 3 times and the adapter 1118 // once, the success callback should have been called 3 times and the adapter
1121 // should be discovering. 1119 // should be discovering.
1122 EXPECT_EQ(1, observer.discovering_changed_count()); 1120 EXPECT_EQ(1, observer.discovering_changed_count());
(...skipping 19 matching lines...) Expand all
1142 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1140 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1143 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1141 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1144 EXPECT_TRUE(adapter_->IsDiscovering()); 1142 EXPECT_TRUE(adapter_->IsDiscovering());
1145 1143
1146 // Stop device discovery behind the adapter. The one active discovery session 1144 // Stop device discovery behind the adapter. The one active discovery session
1147 // should become inactive, but more importantly, we shouldn't run into any 1145 // should become inactive, but more importantly, we shouldn't run into any
1148 // memory errors as the sessions that we explicitly deleted should get 1146 // memory errors as the sessions that we explicitly deleted should get
1149 // cleaned up. 1147 // cleaned up.
1150 fake_bluetooth_adapter_client_->StopDiscovery( 1148 fake_bluetooth_adapter_client_->StopDiscovery(
1151 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 1149 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
1152 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 1150 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
1153 base::Unretained(this))); 1151 base::Unretained(this)));
1154 message_loop_.Run(); 1152 message_loop_.Run();
1155 EXPECT_EQ(2, observer.discovering_changed_count()); 1153 EXPECT_EQ(2, observer.discovering_changed_count());
1156 EXPECT_EQ(4, callback_count_); 1154 EXPECT_EQ(4, callback_count_);
1157 EXPECT_EQ(0, error_callback_count_); 1155 EXPECT_EQ(0, error_callback_count_);
1158 EXPECT_FALSE(observer.last_discovering()); 1156 EXPECT_FALSE(observer.last_discovering());
1159 EXPECT_FALSE(adapter_->IsDiscovering()); 1157 EXPECT_FALSE(adapter_->IsDiscovering());
1160 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 1158 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
1161 } 1159 }
1162 1160
1163 TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) { 1161 TEST_F(BluetoothBlueZTest, QueuedDiscoveryRequests) {
1164 GetAdapter(); 1162 GetAdapter();
1165 1163
1166 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 1164 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
1167 EXPECT_EQ(1, callback_count_); 1165 EXPECT_EQ(1, callback_count_);
1168 EXPECT_EQ(0, error_callback_count_); 1166 EXPECT_EQ(0, error_callback_count_);
1169 EXPECT_TRUE(adapter_->IsPowered()); 1167 EXPECT_TRUE(adapter_->IsPowered());
1170 callback_count_ = 0; 1168 callback_count_ = 0;
1171 1169
1172 TestBluetoothAdapterObserver observer(adapter_); 1170 TestBluetoothAdapterObserver observer(adapter_);
1173 1171
1174 EXPECT_EQ(0, observer.discovering_changed_count()); 1172 EXPECT_EQ(0, observer.discovering_changed_count());
1175 EXPECT_FALSE(observer.last_discovering()); 1173 EXPECT_FALSE(observer.last_discovering());
1176 EXPECT_FALSE(adapter_->IsDiscovering()); 1174 EXPECT_FALSE(adapter_->IsDiscovering());
1177 1175
1178 // Request to start discovery. The call should be pending. 1176 // Request to start discovery. The call should be pending.
1179 adapter_->StartDiscoverySession( 1177 adapter_->StartDiscoverySession(
1180 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1178 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1181 base::Unretained(this)), 1179 base::Unretained(this)),
1182 GetErrorCallback()); 1180 GetErrorCallback());
1183 EXPECT_EQ(0, callback_count_); 1181 EXPECT_EQ(0, callback_count_);
1184 1182
1185 fake_bluetooth_device_client_->EndDiscoverySimulation( 1183 fake_bluetooth_device_client_->EndDiscoverySimulation(
1186 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath)); 1184 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath));
1187 1185
1188 // The underlying adapter has started discovery, but our call hasn't returned 1186 // The underlying adapter has started discovery, but our call hasn't returned
1189 // yet. 1187 // yet.
1190 EXPECT_EQ(1, observer.discovering_changed_count()); 1188 EXPECT_EQ(1, observer.discovering_changed_count());
1191 EXPECT_TRUE(observer.last_discovering()); 1189 EXPECT_TRUE(observer.last_discovering());
1192 EXPECT_TRUE(adapter_->IsDiscovering()); 1190 EXPECT_TRUE(adapter_->IsDiscovering());
1193 EXPECT_TRUE(discovery_sessions_.empty()); 1191 EXPECT_TRUE(discovery_sessions_.empty());
1194 1192
1195 // Request to start discovery twice. These should get queued and there should 1193 // Request to start discovery twice. These should get queued and there should
1196 // be no change in state. 1194 // be no change in state.
1197 for (int i = 0; i < 2; i++) { 1195 for (int i = 0; i < 2; i++) {
1198 adapter_->StartDiscoverySession( 1196 adapter_->StartDiscoverySession(
1199 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1197 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1200 base::Unretained(this)), 1198 base::Unretained(this)),
1201 GetErrorCallback()); 1199 GetErrorCallback());
1202 } 1200 }
1203 EXPECT_EQ(0, callback_count_); 1201 EXPECT_EQ(0, callback_count_);
1204 EXPECT_EQ(0, error_callback_count_); 1202 EXPECT_EQ(0, error_callback_count_);
1205 EXPECT_EQ(1, observer.discovering_changed_count()); 1203 EXPECT_EQ(1, observer.discovering_changed_count());
1206 EXPECT_TRUE(observer.last_discovering()); 1204 EXPECT_TRUE(observer.last_discovering());
1207 EXPECT_TRUE(adapter_->IsDiscovering()); 1205 EXPECT_TRUE(adapter_->IsDiscovering());
1208 EXPECT_TRUE(discovery_sessions_.empty()); 1206 EXPECT_TRUE(discovery_sessions_.empty());
1209 1207
(...skipping 25 matching lines...) Expand all
1235 discovery_sessions_[2]->Stop(GetCallback(), GetErrorCallback()); 1233 discovery_sessions_[2]->Stop(GetCallback(), GetErrorCallback());
1236 EXPECT_EQ(5, callback_count_); 1234 EXPECT_EQ(5, callback_count_);
1237 EXPECT_EQ(1, error_callback_count_); 1235 EXPECT_EQ(1, error_callback_count_);
1238 EXPECT_EQ(2, observer.discovering_changed_count()); 1236 EXPECT_EQ(2, observer.discovering_changed_count());
1239 EXPECT_FALSE(observer.last_discovering()); 1237 EXPECT_FALSE(observer.last_discovering());
1240 EXPECT_FALSE(adapter_->IsDiscovering()); 1238 EXPECT_FALSE(adapter_->IsDiscovering());
1241 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); 1239 EXPECT_TRUE(discovery_sessions_[2]->IsActive());
1242 1240
1243 // Request to start should get queued. 1241 // Request to start should get queued.
1244 adapter_->StartDiscoverySession( 1242 adapter_->StartDiscoverySession(
1245 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1243 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1246 base::Unretained(this)), 1244 base::Unretained(this)),
1247 GetErrorCallback()); 1245 GetErrorCallback());
1248 EXPECT_EQ(5, callback_count_); 1246 EXPECT_EQ(5, callback_count_);
1249 EXPECT_EQ(1, error_callback_count_); 1247 EXPECT_EQ(1, error_callback_count_);
1250 EXPECT_EQ(2, observer.discovering_changed_count()); 1248 EXPECT_EQ(2, observer.discovering_changed_count());
1251 EXPECT_FALSE(observer.last_discovering()); 1249 EXPECT_FALSE(observer.last_discovering());
1252 EXPECT_FALSE(adapter_->IsDiscovering()); 1250 EXPECT_FALSE(adapter_->IsDiscovering());
1253 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1251 ASSERT_EQ((size_t)3, discovery_sessions_.size());
1254 1252
1255 // Run the pending request. 1253 // Run the pending request.
(...skipping 11 matching lines...) Expand all
1267 message_loop_.Run(); 1265 message_loop_.Run();
1268 EXPECT_EQ(7, callback_count_); 1266 EXPECT_EQ(7, callback_count_);
1269 EXPECT_EQ(1, error_callback_count_); 1267 EXPECT_EQ(1, error_callback_count_);
1270 EXPECT_EQ(3, observer.discovering_changed_count()); 1268 EXPECT_EQ(3, observer.discovering_changed_count());
1271 EXPECT_TRUE(observer.last_discovering()); 1269 EXPECT_TRUE(observer.last_discovering());
1272 EXPECT_TRUE(adapter_->IsDiscovering()); 1270 EXPECT_TRUE(adapter_->IsDiscovering());
1273 ASSERT_EQ((size_t)4, discovery_sessions_.size()); 1271 ASSERT_EQ((size_t)4, discovery_sessions_.size());
1274 EXPECT_TRUE(discovery_sessions_[3]->IsActive()); 1272 EXPECT_TRUE(discovery_sessions_[3]->IsActive());
1275 } 1273 }
1276 1274
1277 TEST_F(BluetoothChromeOSTest, StartDiscoverySession) { 1275 TEST_F(BluetoothBlueZTest, StartDiscoverySession) {
1278 GetAdapter(); 1276 GetAdapter();
1279 1277
1280 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 1278 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
1281 EXPECT_EQ(1, callback_count_); 1279 EXPECT_EQ(1, callback_count_);
1282 EXPECT_EQ(0, error_callback_count_); 1280 EXPECT_EQ(0, error_callback_count_);
1283 EXPECT_TRUE(adapter_->IsPowered()); 1281 EXPECT_TRUE(adapter_->IsPowered());
1284 callback_count_ = 0; 1282 callback_count_ = 0;
1285 1283
1286 TestBluetoothAdapterObserver observer(adapter_); 1284 TestBluetoothAdapterObserver observer(adapter_);
1287 1285
1288 EXPECT_EQ(0, observer.discovering_changed_count()); 1286 EXPECT_EQ(0, observer.discovering_changed_count());
1289 EXPECT_FALSE(observer.last_discovering()); 1287 EXPECT_FALSE(observer.last_discovering());
1290 EXPECT_FALSE(adapter_->IsDiscovering()); 1288 EXPECT_FALSE(adapter_->IsDiscovering());
1291 EXPECT_TRUE(discovery_sessions_.empty()); 1289 EXPECT_TRUE(discovery_sessions_.empty());
1292 1290
1293 // Request a new discovery session. 1291 // Request a new discovery session.
1294 adapter_->StartDiscoverySession( 1292 adapter_->StartDiscoverySession(
1295 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1293 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1296 base::Unretained(this)), 1294 base::Unretained(this)),
1297 GetErrorCallback()); 1295 GetErrorCallback());
1298 message_loop_.Run(); 1296 message_loop_.Run();
1299 EXPECT_EQ(1, observer.discovering_changed_count()); 1297 EXPECT_EQ(1, observer.discovering_changed_count());
1300 EXPECT_EQ(1, callback_count_); 1298 EXPECT_EQ(1, callback_count_);
1301 EXPECT_EQ(0, error_callback_count_); 1299 EXPECT_EQ(0, error_callback_count_);
1302 EXPECT_TRUE(observer.last_discovering()); 1300 EXPECT_TRUE(observer.last_discovering());
1303 EXPECT_TRUE(adapter_->IsDiscovering()); 1301 EXPECT_TRUE(adapter_->IsDiscovering());
1304 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1302 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1305 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1303 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1306 1304
1307 // Start another session. A new one should be returned in the callback, which 1305 // Start another session. A new one should be returned in the callback, which
1308 // in turn will destroy the previous session. Adapter should still be 1306 // in turn will destroy the previous session. Adapter should still be
1309 // discovering and the reference count should be 1. 1307 // discovering and the reference count should be 1.
1310 adapter_->StartDiscoverySession( 1308 adapter_->StartDiscoverySession(
1311 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1309 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1312 base::Unretained(this)), 1310 base::Unretained(this)),
1313 GetErrorCallback()); 1311 GetErrorCallback());
1314 message_loop_.Run(); 1312 message_loop_.Run();
1315 EXPECT_EQ(1, observer.discovering_changed_count()); 1313 EXPECT_EQ(1, observer.discovering_changed_count());
1316 EXPECT_EQ(2, callback_count_); 1314 EXPECT_EQ(2, callback_count_);
1317 EXPECT_EQ(0, error_callback_count_); 1315 EXPECT_EQ(0, error_callback_count_);
1318 EXPECT_TRUE(observer.last_discovering()); 1316 EXPECT_TRUE(observer.last_discovering());
1319 EXPECT_TRUE(adapter_->IsDiscovering()); 1317 EXPECT_TRUE(adapter_->IsDiscovering());
1320 ASSERT_EQ((size_t)2, discovery_sessions_.size()); 1318 ASSERT_EQ((size_t)2, discovery_sessions_.size());
1321 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1319 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1322 1320
1323 // Request a new session. 1321 // Request a new session.
1324 adapter_->StartDiscoverySession( 1322 adapter_->StartDiscoverySession(
1325 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1323 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1326 base::Unretained(this)), 1324 base::Unretained(this)),
1327 GetErrorCallback()); 1325 GetErrorCallback());
1328 message_loop_.Run(); 1326 message_loop_.Run();
1329 EXPECT_EQ(1, observer.discovering_changed_count()); 1327 EXPECT_EQ(1, observer.discovering_changed_count());
1330 EXPECT_EQ(3, callback_count_); 1328 EXPECT_EQ(3, callback_count_);
1331 EXPECT_EQ(0, error_callback_count_); 1329 EXPECT_EQ(0, error_callback_count_);
1332 EXPECT_TRUE(observer.last_discovering()); 1330 EXPECT_TRUE(observer.last_discovering());
1333 EXPECT_TRUE(adapter_->IsDiscovering()); 1331 EXPECT_TRUE(adapter_->IsDiscovering());
1334 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1332 ASSERT_EQ((size_t)3, discovery_sessions_.size());
1335 EXPECT_TRUE(discovery_sessions_[1]->IsActive()); 1333 EXPECT_TRUE(discovery_sessions_[1]->IsActive());
(...skipping 17 matching lines...) Expand all
1353 while (observer.last_discovering()) 1351 while (observer.last_discovering())
1354 message_loop_.RunUntilIdle(); 1352 message_loop_.RunUntilIdle();
1355 1353
1356 EXPECT_EQ(2, observer.discovering_changed_count()); 1354 EXPECT_EQ(2, observer.discovering_changed_count());
1357 EXPECT_EQ(4, callback_count_); 1355 EXPECT_EQ(4, callback_count_);
1358 EXPECT_EQ(0, error_callback_count_); 1356 EXPECT_EQ(0, error_callback_count_);
1359 EXPECT_FALSE(observer.last_discovering()); 1357 EXPECT_FALSE(observer.last_discovering());
1360 EXPECT_FALSE(adapter_->IsDiscovering()); 1358 EXPECT_FALSE(adapter_->IsDiscovering());
1361 } 1359 }
1362 1360
1363 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterBeforeStartDiscovery) { 1361 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscovery) {
1364 // Test a simulated discovery session. 1362 // Test a simulated discovery session.
1365 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1363 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1366 GetAdapter(); 1364 GetAdapter();
1367 1365
1368 TestBluetoothAdapterObserver observer(adapter_); 1366 TestBluetoothAdapterObserver observer(adapter_);
1369 1367
1370 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1368 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1371 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1369 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1372 df->SetRSSI(-60); 1370 df->SetRSSI(-60);
1373 df->AddUUID(BluetoothUUID("1000")); 1371 df->AddUUID(BluetoothUUID("1000"));
1374 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1372 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1375 1373
1376 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1374 adapter_->SetPowered(
1377 base::Unretained(this)), 1375 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1378 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1376 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1379 base::Unretained(this)));
1380 adapter_->StartDiscoverySessionWithFilter( 1377 adapter_->StartDiscoverySessionWithFilter(
1381 discovery_filter.Pass(), 1378 discovery_filter.Pass(),
1382 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1379 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1383 base::Unretained(this)), 1380 base::Unretained(this)),
1384 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1381 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1385 base::Unretained(this)));
1386 message_loop_.Run(); 1382 message_loop_.Run();
1387 EXPECT_EQ(2, callback_count_); 1383 EXPECT_EQ(2, callback_count_);
1388 EXPECT_EQ(0, error_callback_count_); 1384 EXPECT_EQ(0, error_callback_count_);
1389 callback_count_ = 0; 1385 callback_count_ = 0;
1390 1386
1391 ASSERT_TRUE(adapter_->IsPowered()); 1387 ASSERT_TRUE(adapter_->IsPowered());
1392 ASSERT_TRUE(adapter_->IsDiscovering()); 1388 ASSERT_TRUE(adapter_->IsDiscovering());
1393 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1389 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1394 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 1390 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
1395 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); 1391 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter()));
1396 1392
1397 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1393 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1398 EXPECT_NE(nullptr, filter); 1394 EXPECT_NE(nullptr, filter);
1399 EXPECT_EQ("le", *filter->transport); 1395 EXPECT_EQ("le", *filter->transport);
1400 EXPECT_EQ(-60, *filter->rssi); 1396 EXPECT_EQ(-60, *filter->rssi);
1401 EXPECT_EQ(nullptr, filter->pathloss.get()); 1397 EXPECT_EQ(nullptr, filter->pathloss.get());
1402 std::vector<std::string> uuids = *filter->uuids; 1398 std::vector<std::string> uuids = *filter->uuids;
1403 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 1399 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
1404 1400
1405 discovery_sessions_[0]->Stop( 1401 discovery_sessions_[0]->Stop(
1406 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1402 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1407 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1403 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1408 base::Unretained(this)));
1409 1404
1410 message_loop_.Run(); 1405 message_loop_.Run();
1411 1406
1412 EXPECT_EQ(1, callback_count_); 1407 EXPECT_EQ(1, callback_count_);
1413 EXPECT_EQ(0, error_callback_count_); 1408 EXPECT_EQ(0, error_callback_count_);
1414 1409
1415 ASSERT_TRUE(adapter_->IsPowered()); 1410 ASSERT_TRUE(adapter_->IsPowered());
1416 ASSERT_FALSE(adapter_->IsDiscovering()); 1411 ASSERT_FALSE(adapter_->IsDiscovering());
1417 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1412 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1418 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); 1413 ASSERT_FALSE(discovery_sessions_[0]->IsActive());
1419 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), 1414 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(),
1420 (BluetoothDiscoveryFilter*)nullptr); 1415 (BluetoothDiscoveryFilter*)nullptr);
1421 1416
1422 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1417 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1423 EXPECT_EQ(nullptr, filter); 1418 EXPECT_EQ(nullptr, filter);
1424 } 1419 }
1425 1420
1426 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterBeforeStartDiscoveryFail) { 1421 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscoveryFail) {
1427 // Test a simulated discovery session. 1422 // Test a simulated discovery session.
1428 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1423 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1429 GetAdapter(); 1424 GetAdapter();
1430 1425
1431 TestBluetoothAdapterObserver observer(adapter_); 1426 TestBluetoothAdapterObserver observer(adapter_);
1432 1427
1433 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1428 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1434 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1429 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1435 df->SetRSSI(-60); 1430 df->SetRSSI(-60);
1436 df->AddUUID(BluetoothUUID("1000")); 1431 df->AddUUID(BluetoothUUID("1000"));
1437 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1432 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1438 1433
1439 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1434 adapter_->SetPowered(
1440 base::Unretained(this)), 1435 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1441 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1436 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1442 base::Unretained(this)));
1443 EXPECT_EQ(1, callback_count_); 1437 EXPECT_EQ(1, callback_count_);
1444 callback_count_ = 0; 1438 callback_count_ = 0;
1445 1439
1446 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail(); 1440 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail();
1447 1441
1448 adapter_->StartDiscoverySessionWithFilter( 1442 adapter_->StartDiscoverySessionWithFilter(
1449 discovery_filter.Pass(), 1443 discovery_filter.Pass(),
1450 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1444 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1451 base::Unretained(this)), 1445 base::Unretained(this)),
1452 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1446 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1453 base::Unretained(this)));
1454 1447
1455 message_loop_.Run(); 1448 message_loop_.Run();
1456 1449
1457 EXPECT_EQ(1, error_callback_count_); 1450 EXPECT_EQ(1, error_callback_count_);
1458 error_callback_count_ = 0; 1451 error_callback_count_ = 0;
1459 1452
1460 ASSERT_TRUE(adapter_->IsPowered()); 1453 ASSERT_TRUE(adapter_->IsPowered());
1461 ASSERT_FALSE(adapter_->IsDiscovering()); 1454 ASSERT_FALSE(adapter_->IsDiscovering());
1462 ASSERT_EQ((size_t)0, discovery_sessions_.size()); 1455 ASSERT_EQ((size_t)0, discovery_sessions_.size());
1463 1456
1464 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1457 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1465 EXPECT_EQ(nullptr, filter); 1458 EXPECT_EQ(nullptr, filter);
1466 } 1459 }
1467 1460
1468 // This test queues two requests to StartDiscovery with pre set filter. This 1461 // This test queues two requests to StartDiscovery with pre set filter. This
1469 // should result in SetDiscoveryFilter, then StartDiscovery, and SetDiscovery 1462 // should result in SetDiscoveryFilter, then StartDiscovery, and SetDiscovery
1470 // DBus calls 1463 // DBus calls
1471 TEST_F(BluetoothChromeOSTest, QueuedSetDiscoveryFilterBeforeStartDiscovery) { 1464 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscovery) {
1472 // Test a simulated discovery session. 1465 // Test a simulated discovery session.
1473 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1466 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1474 GetAdapter(); 1467 GetAdapter();
1475 1468
1476 TestBluetoothAdapterObserver observer(adapter_); 1469 TestBluetoothAdapterObserver observer(adapter_);
1477 1470
1478 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1471 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1479 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1472 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1480 df->SetRSSI(-60); 1473 df->SetRSSI(-60);
1481 df->AddUUID(BluetoothUUID("1000")); 1474 df->AddUUID(BluetoothUUID("1000"));
1482 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1475 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1483 1476
1484 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( 1477 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter(
1485 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); 1478 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC);
1486 df2->SetRSSI(-65); 1479 df2->SetRSSI(-65);
1487 df2->AddUUID(BluetoothUUID("1002")); 1480 df2->AddUUID(BluetoothUUID("1002"));
1488 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); 1481 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2);
1489 1482
1490 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1483 adapter_->SetPowered(
1491 base::Unretained(this)), 1484 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1492 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1485 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1493 base::Unretained(this)));
1494 1486
1495 EXPECT_EQ(1, callback_count_); 1487 EXPECT_EQ(1, callback_count_);
1496 EXPECT_EQ(0, error_callback_count_); 1488 EXPECT_EQ(0, error_callback_count_);
1497 callback_count_ = 0; 1489 callback_count_ = 0;
1498 1490
1499 // Queue two requests to start discovery session with filter. 1491 // Queue two requests to start discovery session with filter.
1500 adapter_->StartDiscoverySessionWithFilter( 1492 adapter_->StartDiscoverySessionWithFilter(
1501 discovery_filter.Pass(), 1493 discovery_filter.Pass(),
1502 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1494 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1503 base::Unretained(this)), 1495 base::Unretained(this)),
1504 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1496 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1505 base::Unretained(this)));
1506 1497
1507 adapter_->StartDiscoverySessionWithFilter( 1498 adapter_->StartDiscoverySessionWithFilter(
1508 discovery_filter2.Pass(), 1499 discovery_filter2.Pass(),
1509 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1500 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1510 base::Unretained(this)), 1501 base::Unretained(this)),
1511 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1502 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1512 base::Unretained(this)));
1513 1503
1514 // Run requests, on DBus level there should be call SetDiscoveryFilter, then 1504 // Run requests, on DBus level there should be call SetDiscoveryFilter, then
1515 // StartDiscovery, then SetDiscoveryFilter again. 1505 // StartDiscovery, then SetDiscoveryFilter again.
1516 message_loop_.Run(); 1506 message_loop_.Run();
1517 message_loop_.Run(); 1507 message_loop_.Run();
1518 1508
1519 EXPECT_EQ(2, callback_count_); 1509 EXPECT_EQ(2, callback_count_);
1520 EXPECT_EQ(0, error_callback_count_); 1510 EXPECT_EQ(0, error_callback_count_);
1521 callback_count_ = 0; 1511 callback_count_ = 0;
1522 1512
1523 ASSERT_TRUE(adapter_->IsPowered()); 1513 ASSERT_TRUE(adapter_->IsPowered());
1524 ASSERT_TRUE(adapter_->IsDiscovering()); 1514 ASSERT_TRUE(adapter_->IsDiscovering());
1525 ASSERT_EQ((size_t)2, discovery_sessions_.size()); 1515 ASSERT_EQ((size_t)2, discovery_sessions_.size());
1526 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 1516 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
1527 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); 1517 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter()));
1528 ASSERT_TRUE(discovery_sessions_[1]->IsActive()); 1518 ASSERT_TRUE(discovery_sessions_[1]->IsActive());
1529 ASSERT_TRUE(df2->Equals(*discovery_sessions_[1]->GetDiscoveryFilter())); 1519 ASSERT_TRUE(df2->Equals(*discovery_sessions_[1]->GetDiscoveryFilter()));
1530 1520
1531 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1521 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1532 EXPECT_NE(nullptr, filter); 1522 EXPECT_NE(nullptr, filter);
1533 EXPECT_EQ("auto", *filter->transport); 1523 EXPECT_EQ("auto", *filter->transport);
1534 EXPECT_EQ(-65, *filter->rssi); 1524 EXPECT_EQ(-65, *filter->rssi);
1535 EXPECT_EQ(nullptr, filter->pathloss.get()); 1525 EXPECT_EQ(nullptr, filter->pathloss.get());
1536 auto uuids = *filter->uuids; 1526 auto uuids = *filter->uuids;
1537 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 1527 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
1538 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002")); 1528 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002"));
1539 1529
1540 discovery_sessions_[0]->Stop( 1530 discovery_sessions_[0]->Stop(
1541 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1531 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1542 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1532 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1543 base::Unretained(this)));
1544 1533
1545 discovery_sessions_[1]->Stop( 1534 discovery_sessions_[1]->Stop(
1546 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1535 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1547 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1536 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1548 base::Unretained(this)));
1549 1537
1550 message_loop_.Run(); 1538 message_loop_.Run();
1551 1539
1552 EXPECT_EQ(2, callback_count_); 1540 EXPECT_EQ(2, callback_count_);
1553 EXPECT_EQ(0, error_callback_count_); 1541 EXPECT_EQ(0, error_callback_count_);
1554 1542
1555 ASSERT_TRUE(adapter_->IsPowered()); 1543 ASSERT_TRUE(adapter_->IsPowered());
1556 ASSERT_FALSE(adapter_->IsDiscovering()); 1544 ASSERT_FALSE(adapter_->IsDiscovering());
1557 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); 1545 ASSERT_FALSE(discovery_sessions_[0]->IsActive());
1558 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), 1546 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(),
1559 (BluetoothDiscoveryFilter*)nullptr); 1547 (BluetoothDiscoveryFilter*)nullptr);
1560 ASSERT_FALSE(discovery_sessions_[1]->IsActive()); 1548 ASSERT_FALSE(discovery_sessions_[1]->IsActive());
1561 ASSERT_EQ(discovery_sessions_[1]->GetDiscoveryFilter(), 1549 ASSERT_EQ(discovery_sessions_[1]->GetDiscoveryFilter(),
1562 (BluetoothDiscoveryFilter*)nullptr); 1550 (BluetoothDiscoveryFilter*)nullptr);
1563 1551
1564 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1552 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1565 EXPECT_EQ(nullptr, filter); 1553 EXPECT_EQ(nullptr, filter);
1566 } 1554 }
1567 1555
1568 // Call StartFilteredDiscovery twice (2nd time while 1st call is still pending). 1556 // Call StartFilteredDiscovery twice (2nd time while 1st call is still pending).
1569 // Make the first SetDiscoveryFilter fail and the second one succeed. It should 1557 // Make the first SetDiscoveryFilter fail and the second one succeed. It should
1570 // end up with one active discovery session. 1558 // end up with one active discovery session.
1571 TEST_F(BluetoothChromeOSTest, 1559 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscoveryFail) {
1572 QueuedSetDiscoveryFilterBeforeStartDiscoveryFail) {
1573 // Test a simulated discovery session. 1560 // Test a simulated discovery session.
1574 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1561 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1575 GetAdapter(); 1562 GetAdapter();
1576 1563
1577 TestBluetoothAdapterObserver observer(adapter_); 1564 TestBluetoothAdapterObserver observer(adapter_);
1578 1565
1579 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1566 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1580 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1567 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1581 df->SetRSSI(-60); 1568 df->SetRSSI(-60);
1582 df->AddUUID(BluetoothUUID("1000")); 1569 df->AddUUID(BluetoothUUID("1000"));
1583 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1570 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1584 1571
1585 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( 1572 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter(
1586 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); 1573 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC);
1587 df2->SetRSSI(-65); 1574 df2->SetRSSI(-65);
1588 df2->AddUUID(BluetoothUUID("1002")); 1575 df2->AddUUID(BluetoothUUID("1002"));
1589 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); 1576 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2);
1590 1577
1591 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1578 adapter_->SetPowered(
1592 base::Unretained(this)), 1579 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1593 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1580 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1594 base::Unretained(this)));
1595 1581
1596 EXPECT_EQ(1, callback_count_); 1582 EXPECT_EQ(1, callback_count_);
1597 EXPECT_EQ(0, error_callback_count_); 1583 EXPECT_EQ(0, error_callback_count_);
1598 callback_count_ = 0; 1584 callback_count_ = 0;
1599 1585
1600 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail(); 1586 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail();
1601 1587
1602 // Queue two requests to start discovery session with filter. 1588 // Queue two requests to start discovery session with filter.
1603 adapter_->StartDiscoverySessionWithFilter( 1589 adapter_->StartDiscoverySessionWithFilter(
1604 discovery_filter.Pass(), 1590 discovery_filter.Pass(),
1605 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1591 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1606 base::Unretained(this)), 1592 base::Unretained(this)),
1607 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1593 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1608 base::Unretained(this)));
1609 1594
1610 adapter_->StartDiscoverySessionWithFilter( 1595 adapter_->StartDiscoverySessionWithFilter(
1611 discovery_filter2.Pass(), 1596 discovery_filter2.Pass(),
1612 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1597 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1613 base::Unretained(this)), 1598 base::Unretained(this)),
1614 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1599 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1615 base::Unretained(this)));
1616 1600
1617 message_loop_.Run(); 1601 message_loop_.Run();
1618 1602
1619 // First request to SetDiscoveryFilter should fail, resulting in no session 1603 // First request to SetDiscoveryFilter should fail, resulting in no session
1620 // being created. 1604 // being created.
1621 EXPECT_EQ(0, callback_count_); 1605 EXPECT_EQ(0, callback_count_);
1622 EXPECT_EQ(1, error_callback_count_); 1606 EXPECT_EQ(1, error_callback_count_);
1623 error_callback_count_ = 0; 1607 error_callback_count_ = 0;
1624 1608
1625 ASSERT_TRUE(adapter_->IsPowered()); 1609 ASSERT_TRUE(adapter_->IsPowered());
(...skipping 14 matching lines...) Expand all
1640 1624
1641 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1625 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1642 EXPECT_NE(nullptr, filter); 1626 EXPECT_NE(nullptr, filter);
1643 EXPECT_EQ("bredr", *filter->transport); 1627 EXPECT_EQ("bredr", *filter->transport);
1644 EXPECT_EQ(-65, *filter->rssi); 1628 EXPECT_EQ(-65, *filter->rssi);
1645 EXPECT_EQ(nullptr, filter->pathloss.get()); 1629 EXPECT_EQ(nullptr, filter->pathloss.get());
1646 auto uuids = *filter->uuids; 1630 auto uuids = *filter->uuids;
1647 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002")); 1631 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002"));
1648 1632
1649 discovery_sessions_[0]->Stop( 1633 discovery_sessions_[0]->Stop(
1650 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1634 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1651 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1635 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1652 base::Unretained(this)));
1653 1636
1654 message_loop_.Run(); 1637 message_loop_.Run();
1655 1638
1656 EXPECT_EQ(1, callback_count_); 1639 EXPECT_EQ(1, callback_count_);
1657 EXPECT_EQ(0, error_callback_count_); 1640 EXPECT_EQ(0, error_callback_count_);
1658 1641
1659 ASSERT_TRUE(adapter_->IsPowered()); 1642 ASSERT_TRUE(adapter_->IsPowered());
1660 ASSERT_FALSE(adapter_->IsDiscovering()); 1643 ASSERT_FALSE(adapter_->IsDiscovering());
1661 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); 1644 ASSERT_FALSE(discovery_sessions_[0]->IsActive());
1662 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), 1645 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(),
1663 (BluetoothDiscoveryFilter*)nullptr); 1646 (BluetoothDiscoveryFilter*)nullptr);
1664 1647
1665 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1648 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1666 EXPECT_EQ(nullptr, filter); 1649 EXPECT_EQ(nullptr, filter);
1667 } 1650 }
1668 1651
1669 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterAfterStartDiscovery) { 1652 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterAfterStartDiscovery) {
1670 // Test a simulated discovery session. 1653 // Test a simulated discovery session.
1671 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1654 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1672 GetAdapter(); 1655 GetAdapter();
1673 1656
1674 TestBluetoothAdapterObserver observer(adapter_); 1657 TestBluetoothAdapterObserver observer(adapter_);
1675 1658
1676 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1659 adapter_->SetPowered(
1677 base::Unretained(this)), 1660 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1678 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1661 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1679 base::Unretained(this)));
1680 adapter_->StartDiscoverySession( 1662 adapter_->StartDiscoverySession(
1681 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1663 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1682 base::Unretained(this)), 1664 base::Unretained(this)),
1683 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1665 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1684 base::Unretained(this)));
1685 message_loop_.Run(); 1666 message_loop_.Run();
1686 EXPECT_EQ(2, callback_count_); 1667 EXPECT_EQ(2, callback_count_);
1687 EXPECT_EQ(0, error_callback_count_); 1668 EXPECT_EQ(0, error_callback_count_);
1688 callback_count_ = 0; 1669 callback_count_ = 0;
1689 1670
1690 ASSERT_TRUE(adapter_->IsPowered()); 1671 ASSERT_TRUE(adapter_->IsPowered());
1691 ASSERT_TRUE(adapter_->IsDiscovering()); 1672 ASSERT_TRUE(adapter_->IsDiscovering());
1692 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1673 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1693 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 1674 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
1694 EXPECT_EQ(1, observer.discovering_changed_count()); 1675 EXPECT_EQ(1, observer.discovering_changed_count());
1695 observer.Reset(); 1676 observer.Reset();
1696 1677
1697 auto null_instance = scoped_ptr<BluetoothDiscoveryFilter>(); 1678 auto null_instance = scoped_ptr<BluetoothDiscoveryFilter>();
1698 null_instance.reset(); 1679 null_instance.reset();
1699 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), null_instance.get()); 1680 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), null_instance.get());
1700 1681
1701 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1682 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1702 EXPECT_EQ(nullptr, filter); 1683 EXPECT_EQ(nullptr, filter);
1703 1684
1704 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1685 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1705 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1686 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1706 df->SetRSSI(-60); 1687 df->SetRSSI(-60);
1707 df->AddUUID(BluetoothUUID("1000")); 1688 df->AddUUID(BluetoothUUID("1000"));
1708 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1689 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1709 1690
1710 discovery_sessions_[0]->SetDiscoveryFilter( 1691 discovery_sessions_[0]->SetDiscoveryFilter(
1711 discovery_filter.Pass(), 1692 discovery_filter.Pass(),
1712 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1693 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1713 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1694 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1714 base::Unretained(this)));
1715 1695
1716 message_loop_.Run(); 1696 message_loop_.Run();
1717 EXPECT_EQ(1, callback_count_); 1697 EXPECT_EQ(1, callback_count_);
1718 EXPECT_EQ(0, error_callback_count_); 1698 EXPECT_EQ(0, error_callback_count_);
1719 callback_count_ = 0; 1699 callback_count_ = 0;
1720 1700
1721 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); 1701 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter()));
1722 1702
1723 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1703 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1724 EXPECT_NE(nullptr, filter); 1704 EXPECT_NE(nullptr, filter);
1725 EXPECT_EQ("le", *filter->transport); 1705 EXPECT_EQ("le", *filter->transport);
1726 EXPECT_EQ(-60, *filter->rssi); 1706 EXPECT_EQ(-60, *filter->rssi);
1727 EXPECT_EQ(nullptr, filter->pathloss.get()); 1707 EXPECT_EQ(nullptr, filter->pathloss.get());
1728 std::vector<std::string> uuids = *filter->uuids; 1708 std::vector<std::string> uuids = *filter->uuids;
1729 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 1709 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
1730 1710
1731 discovery_sessions_[0]->Stop( 1711 discovery_sessions_[0]->Stop(
1732 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1712 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1733 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1713 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1734 base::Unretained(this)));
1735 1714
1736 message_loop_.Run(); 1715 message_loop_.Run();
1737 1716
1738 EXPECT_EQ(1, callback_count_); 1717 EXPECT_EQ(1, callback_count_);
1739 EXPECT_EQ(0, error_callback_count_); 1718 EXPECT_EQ(0, error_callback_count_);
1740 1719
1741 ASSERT_TRUE(adapter_->IsPowered()); 1720 ASSERT_TRUE(adapter_->IsPowered());
1742 ASSERT_FALSE(adapter_->IsDiscovering()); 1721 ASSERT_FALSE(adapter_->IsDiscovering());
1743 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1722 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1744 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); 1723 ASSERT_FALSE(discovery_sessions_[0]->IsActive());
1745 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), 1724 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(),
1746 (BluetoothDiscoveryFilter*)nullptr); 1725 (BluetoothDiscoveryFilter*)nullptr);
1747 1726
1748 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1727 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1749 EXPECT_EQ(nullptr, filter); 1728 EXPECT_EQ(nullptr, filter);
1750 } 1729 }
1751 1730
1752 // This unit test asserts that the basic reference counting, and filter merging 1731 // This unit test asserts that the basic reference counting, and filter merging
1753 // works correctly for discovery requests done via the BluetoothAdapter. 1732 // works correctly for discovery requests done via the BluetoothAdapter.
1754 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterBeforeStartDiscoveryMultiple) { 1733 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscoveryMultiple) {
1755 GetAdapter(); 1734 GetAdapter();
1756 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1735 adapter_->SetPowered(
1757 base::Unretained(this)), 1736 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1758 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1737 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1759 base::Unretained(this)));
1760 EXPECT_EQ(1, callback_count_); 1738 EXPECT_EQ(1, callback_count_);
1761 EXPECT_EQ(0, error_callback_count_); 1739 EXPECT_EQ(0, error_callback_count_);
1762 EXPECT_TRUE(adapter_->IsPowered()); 1740 EXPECT_TRUE(adapter_->IsPowered());
1763 callback_count_ = 0; 1741 callback_count_ = 0;
1764 1742
1765 TestBluetoothAdapterObserver observer(adapter_); 1743 TestBluetoothAdapterObserver observer(adapter_);
1766 1744
1767 // Request device discovery with pre-set filter 3 times. 1745 // Request device discovery with pre-set filter 3 times.
1768 for (int i = 0; i < 3; i++) { 1746 for (int i = 0; i < 3; i++) {
1769 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter; 1747 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter;
(...skipping 14 matching lines...) Expand all
1784 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1762 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1785 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1763 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1786 df->SetRSSI(-65); 1764 df->SetRSSI(-65);
1787 df->AddUUID(BluetoothUUID("1020")); 1765 df->AddUUID(BluetoothUUID("1020"));
1788 df->AddUUID(BluetoothUUID("1003")); 1766 df->AddUUID(BluetoothUUID("1003"));
1789 discovery_filter.reset(df); 1767 discovery_filter.reset(df);
1790 } 1768 }
1791 1769
1792 adapter_->StartDiscoverySessionWithFilter( 1770 adapter_->StartDiscoverySessionWithFilter(
1793 discovery_filter.Pass(), 1771 discovery_filter.Pass(),
1794 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1772 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1795 base::Unretained(this)), 1773 base::Unretained(this)),
1796 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1774 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1797 base::Unretained(this)));
1798 1775
1799 message_loop_.Run(); 1776 message_loop_.Run();
1800 1777
1801 if (i == 0) { 1778 if (i == 0) {
1802 EXPECT_EQ(1, observer.discovering_changed_count()); 1779 EXPECT_EQ(1, observer.discovering_changed_count());
1803 observer.Reset(); 1780 observer.Reset();
1804 1781
1805 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1782 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1806 EXPECT_EQ("le", *filter->transport); 1783 EXPECT_EQ("le", *filter->transport);
1807 EXPECT_EQ(-85, *filter->rssi); 1784 EXPECT_EQ(-85, *filter->rssi);
(...skipping 26 matching lines...) Expand all
1834 // be discovering. 1811 // be discovering.
1835 EXPECT_EQ(3, callback_count_); 1812 EXPECT_EQ(3, callback_count_);
1836 EXPECT_EQ(0, error_callback_count_); 1813 EXPECT_EQ(0, error_callback_count_);
1837 EXPECT_TRUE(adapter_->IsDiscovering()); 1814 EXPECT_TRUE(adapter_->IsDiscovering());
1838 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1815 ASSERT_EQ((size_t)3, discovery_sessions_.size());
1839 1816
1840 callback_count_ = 0; 1817 callback_count_ = 0;
1841 // Request to stop discovery twice. 1818 // Request to stop discovery twice.
1842 for (int i = 0; i < 2; i++) { 1819 for (int i = 0; i < 2; i++) {
1843 discovery_sessions_[i]->Stop( 1820 discovery_sessions_[i]->Stop(
1844 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1821 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1845 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1822 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1846 base::Unretained(this)));
1847 message_loop_.Run(); 1823 message_loop_.Run();
1848 1824
1849 if (i == 0) { 1825 if (i == 0) {
1850 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1826 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1851 EXPECT_EQ("le", *filter->transport); 1827 EXPECT_EQ("le", *filter->transport);
1852 EXPECT_EQ(-65, *filter->rssi); 1828 EXPECT_EQ(-65, *filter->rssi);
1853 EXPECT_EQ(nullptr, filter->pathloss.get()); 1829 EXPECT_EQ(nullptr, filter->pathloss.get());
1854 std::vector<std::string> uuids = *filter->uuids; 1830 std::vector<std::string> uuids = *filter->uuids;
1855 EXPECT_EQ(3UL, uuids.size()); 1831 EXPECT_EQ(3UL, uuids.size());
1856 EXPECT_EQ(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 1832 EXPECT_EQ(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1886 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1911 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1887 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1912 df->SetRSSI(-65); 1888 df->SetRSSI(-65);
1913 df->AddUUID(BluetoothUUID("1020")); 1889 df->AddUUID(BluetoothUUID("1020"));
1914 df->AddUUID(BluetoothUUID("1003")); 1890 df->AddUUID(BluetoothUUID("1003"));
1915 discovery_filter.reset(df); 1891 discovery_filter.reset(df);
1916 } 1892 }
1917 1893
1918 adapter_->StartDiscoverySessionWithFilter( 1894 adapter_->StartDiscoverySessionWithFilter(
1919 discovery_filter.Pass(), 1895 discovery_filter.Pass(),
1920 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1896 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1921 base::Unretained(this)), 1897 base::Unretained(this)),
1922 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1898 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1923 base::Unretained(this)));
1924 1899
1925 // each result in 1 requests. 1900 // each result in 1 requests.
1926 message_loop_.Run(); 1901 message_loop_.Run();
1927 1902
1928 if (i == 0) { 1903 if (i == 0) {
1929 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1904 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1930 EXPECT_EQ("le", *filter->transport); 1905 EXPECT_EQ("le", *filter->transport);
1931 EXPECT_EQ(-85, *filter->rssi); 1906 EXPECT_EQ(-85, *filter->rssi);
1932 EXPECT_EQ(nullptr, filter->pathloss.get()); 1907 EXPECT_EQ(nullptr, filter->pathloss.get());
1933 std::vector<std::string> uuids = *filter->uuids; 1908 std::vector<std::string> uuids = *filter->uuids;
(...skipping 17 matching lines...) Expand all
1951 // still be discovering. 1926 // still be discovering.
1952 EXPECT_EQ(3, callback_count_); 1927 EXPECT_EQ(3, callback_count_);
1953 EXPECT_EQ(0, error_callback_count_); 1928 EXPECT_EQ(0, error_callback_count_);
1954 EXPECT_TRUE(adapter_->IsDiscovering()); 1929 EXPECT_TRUE(adapter_->IsDiscovering());
1955 ASSERT_EQ((size_t)6, discovery_sessions_.size()); 1930 ASSERT_EQ((size_t)6, discovery_sessions_.size());
1956 1931
1957 callback_count_ = 0; 1932 callback_count_ = 0;
1958 // Request to stop discovery 4 times. 1933 // Request to stop discovery 4 times.
1959 for (int i = 2; i < 6; i++) { 1934 for (int i = 2; i < 6; i++) {
1960 discovery_sessions_[i]->Stop( 1935 discovery_sessions_[i]->Stop(
1961 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1936 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1962 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1937 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1963 base::Unretained(this)));
1964 1938
1965 // filter no 2 is same as filter no 5, so removing it shouldn't cause any 1939 // filter no 2 is same as filter no 5, so removing it shouldn't cause any
1966 // filter update 1940 // filter update
1967 if (i != 2 && i != 5) 1941 if (i != 2 && i != 5)
1968 message_loop_.Run(); 1942 message_loop_.Run();
1969 } 1943 }
1970 // Run only once, as there should have been one D-Bus call. 1944 // Run only once, as there should have been one D-Bus call.
1971 message_loop_.Run(); 1945 message_loop_.Run();
1972 1946
1973 // The success callback should have been called 4 times and the adapter should 1947 // The success callback should have been called 4 times and the adapter should
1974 // no longer be discovering. 1948 // no longer be discovering.
1975 EXPECT_EQ(4, callback_count_); 1949 EXPECT_EQ(4, callback_count_);
1976 EXPECT_EQ(0, error_callback_count_); 1950 EXPECT_EQ(0, error_callback_count_);
1977 EXPECT_FALSE(adapter_->IsDiscovering()); 1951 EXPECT_FALSE(adapter_->IsDiscovering());
1978 EXPECT_EQ(1, observer.discovering_changed_count()); 1952 EXPECT_EQ(1, observer.discovering_changed_count());
1979 1953
1980 // All discovery sessions should be inactive. 1954 // All discovery sessions should be inactive.
1981 for (int i = 0; i < 6; i++) 1955 for (int i = 0; i < 6; i++)
1982 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); 1956 EXPECT_FALSE(discovery_sessions_[i]->IsActive());
1983 1957
1984 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1958 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1985 EXPECT_EQ(nullptr, filter); 1959 EXPECT_EQ(nullptr, filter);
1986 } 1960 }
1987 1961
1988 // This unit test asserts that filter merging logic works correctly for filtered 1962 // This unit test asserts that filter merging logic works correctly for filtered
1989 // discovery requests done via the BluetoothAdapter. 1963 // discovery requests done via the BluetoothAdapter.
1990 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterMergingTest) { 1964 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterMergingTest) {
1991 GetAdapter(); 1965 GetAdapter();
1992 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1966 adapter_->SetPowered(
1993 base::Unretained(this)), 1967 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1994 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1968 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1995 base::Unretained(this)));
1996 1969
1997 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1970 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1998 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1971 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1999 df->SetRSSI(-15); 1972 df->SetRSSI(-15);
2000 df->AddUUID(BluetoothUUID("1000")); 1973 df->AddUUID(BluetoothUUID("1000"));
2001 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1974 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
2002 1975
2003 adapter_->StartDiscoverySessionWithFilter( 1976 adapter_->StartDiscoverySessionWithFilter(
2004 discovery_filter.Pass(), 1977 discovery_filter.Pass(),
2005 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1978 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2006 base::Unretained(this)), 1979 base::Unretained(this)),
2007 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1980 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2008 base::Unretained(this)));
2009 1981
2010 message_loop_.Run(); 1982 message_loop_.Run();
2011 1983
2012 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1984 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2013 EXPECT_EQ("le", *filter->transport); 1985 EXPECT_EQ("le", *filter->transport);
2014 EXPECT_EQ(-15, *filter->rssi); 1986 EXPECT_EQ(-15, *filter->rssi);
2015 EXPECT_EQ(nullptr, filter->pathloss.get()); 1987 EXPECT_EQ(nullptr, filter->pathloss.get());
2016 std::vector<std::string> uuids = *filter->uuids; 1988 std::vector<std::string> uuids = *filter->uuids;
2017 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 1989 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
2018 1990
2019 df = new BluetoothDiscoveryFilter( 1991 df = new BluetoothDiscoveryFilter(
2020 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1992 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
2021 df->SetRSSI(-60); 1993 df->SetRSSI(-60);
2022 df->AddUUID(BluetoothUUID("1020")); 1994 df->AddUUID(BluetoothUUID("1020"));
2023 df->AddUUID(BluetoothUUID("1001")); 1995 df->AddUUID(BluetoothUUID("1001"));
2024 discovery_filter = scoped_ptr<BluetoothDiscoveryFilter>(df); 1996 discovery_filter = scoped_ptr<BluetoothDiscoveryFilter>(df);
2025 1997
2026 adapter_->StartDiscoverySessionWithFilter( 1998 adapter_->StartDiscoverySessionWithFilter(
2027 discovery_filter.Pass(), 1999 discovery_filter.Pass(),
2028 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 2000 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2029 base::Unretained(this)), 2001 base::Unretained(this)),
2030 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 2002 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2031 base::Unretained(this)));
2032 2003
2033 message_loop_.Run(); 2004 message_loop_.Run();
2034 2005
2035 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 2006 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2036 EXPECT_EQ("le", *filter->transport); 2007 EXPECT_EQ("le", *filter->transport);
2037 EXPECT_EQ(-60, *filter->rssi); 2008 EXPECT_EQ(-60, *filter->rssi);
2038 EXPECT_EQ(nullptr, filter->pathloss.get()); 2009 EXPECT_EQ(nullptr, filter->pathloss.get());
2039 uuids = *filter->uuids; 2010 uuids = *filter->uuids;
2040 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 2011 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
2041 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); 2012 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001"));
2042 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); 2013 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020"));
2043 2014
2044 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter( 2015 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter(
2045 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); 2016 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC);
2046 df3->SetRSSI(-65); 2017 df3->SetRSSI(-65);
2047 df3->AddUUID(BluetoothUUID("1020")); 2018 df3->AddUUID(BluetoothUUID("1020"));
2048 df3->AddUUID(BluetoothUUID("1003")); 2019 df3->AddUUID(BluetoothUUID("1003"));
2049 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3); 2020 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3);
2050 2021
2051 adapter_->StartDiscoverySessionWithFilter( 2022 adapter_->StartDiscoverySessionWithFilter(
2052 discovery_filter3.Pass(), 2023 discovery_filter3.Pass(),
2053 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 2024 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2054 base::Unretained(this)), 2025 base::Unretained(this)),
2055 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 2026 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2056 base::Unretained(this)));
2057 2027
2058 message_loop_.Run(); 2028 message_loop_.Run();
2059 2029
2060 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 2030 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2061 EXPECT_EQ("auto", *filter->transport); 2031 EXPECT_EQ("auto", *filter->transport);
2062 EXPECT_EQ(-65, *filter->rssi); 2032 EXPECT_EQ(-65, *filter->rssi);
2063 EXPECT_EQ(nullptr, filter->pathloss.get()); 2033 EXPECT_EQ(nullptr, filter->pathloss.get());
2064 uuids = *filter->uuids; 2034 uuids = *filter->uuids;
2065 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 2035 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
2066 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); 2036 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001"));
2067 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1003")); 2037 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1003"));
2068 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); 2038 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020"));
2069 2039
2070 // start additionally classic scan 2040 // start additionally classic scan
2071 adapter_->StartDiscoverySession( 2041 adapter_->StartDiscoverySession(
2072 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 2042 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2073 base::Unretained(this)), 2043 base::Unretained(this)),
2074 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 2044 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2075 base::Unretained(this)));
2076 2045
2077 message_loop_.Run(); 2046 message_loop_.Run();
2078 2047
2079 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 2048 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2080 EXPECT_EQ("auto", *filter->transport); 2049 EXPECT_EQ("auto", *filter->transport);
2081 EXPECT_EQ(nullptr, filter->rssi.get()); 2050 EXPECT_EQ(nullptr, filter->rssi.get());
2082 EXPECT_EQ(nullptr, filter->pathloss.get()); 2051 EXPECT_EQ(nullptr, filter->pathloss.get());
2083 EXPECT_EQ(nullptr, filter->uuids.get()); 2052 EXPECT_EQ(nullptr, filter->uuids.get());
2084 2053
2085 // Request to stop discovery 4 times. 2054 // Request to stop discovery 4 times.
2086 for (int i = 3; i >= 0; i--) { 2055 for (int i = 3; i >= 0; i--) {
2087 discovery_sessions_[i]->Stop( 2056 discovery_sessions_[i]->Stop(
2088 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 2057 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
2089 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 2058 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2090 base::Unretained(this)));
2091 2059
2092 // Every session stopping would trigger filter update 2060 // Every session stopping would trigger filter update
2093 message_loop_.Run(); 2061 message_loop_.Run();
2094 } 2062 }
2095 } 2063 }
2096 2064
2097 TEST_F(BluetoothChromeOSTest, DeviceProperties) { 2065 TEST_F(BluetoothBlueZTest, DeviceProperties) {
2098 GetAdapter(); 2066 GetAdapter();
2099 2067
2100 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2068 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2101 ASSERT_EQ(2U, devices.size()); 2069 ASSERT_EQ(2U, devices.size());
2102 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2070 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
2103 devices[0]->GetAddress()); 2071 devices[0]->GetAddress());
2104 2072
2105 // Verify the other device properties. 2073 // Verify the other device properties.
2106 EXPECT_EQ( 2074 EXPECT_EQ(
2107 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceName), 2075 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceName),
(...skipping 10 matching lines...) Expand all
2118 ASSERT_EQ(2U, uuids.size()); 2086 ASSERT_EQ(2U, uuids.size());
2119 EXPECT_EQ(uuids[0], BluetoothUUID("1800")); 2087 EXPECT_EQ(uuids[0], BluetoothUUID("1800"));
2120 EXPECT_EQ(uuids[1], BluetoothUUID("1801")); 2088 EXPECT_EQ(uuids[1], BluetoothUUID("1801"));
2121 2089
2122 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[0]->GetVendorIDSource()); 2090 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[0]->GetVendorIDSource());
2123 EXPECT_EQ(0x05ac, devices[0]->GetVendorID()); 2091 EXPECT_EQ(0x05ac, devices[0]->GetVendorID());
2124 EXPECT_EQ(0x030d, devices[0]->GetProductID()); 2092 EXPECT_EQ(0x030d, devices[0]->GetProductID());
2125 EXPECT_EQ(0x0306, devices[0]->GetDeviceID()); 2093 EXPECT_EQ(0x0306, devices[0]->GetDeviceID());
2126 } 2094 }
2127 2095
2128 TEST_F(BluetoothChromeOSTest, DeviceClassChanged) { 2096 TEST_F(BluetoothBlueZTest, DeviceClassChanged) {
2129 // Simulate a change of class of a device, as sometimes occurs 2097 // Simulate a change of class of a device, as sometimes occurs
2130 // during discovery. 2098 // during discovery.
2131 GetAdapter(); 2099 GetAdapter();
2132 2100
2133 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2101 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2134 ASSERT_EQ(2U, devices.size()); 2102 ASSERT_EQ(2U, devices.size());
2135 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2103 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
2136 devices[0]->GetAddress()); 2104 devices[0]->GetAddress());
2137 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[0]->GetDeviceType()); 2105 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[0]->GetDeviceType());
2138 2106
2139 // Install an observer; expect the DeviceChanged method to be called when 2107 // Install an observer; expect the DeviceChanged method to be called when
2140 // we change the class of the device. 2108 // we change the class of the device.
2141 TestBluetoothAdapterObserver observer(adapter_); 2109 TestBluetoothAdapterObserver observer(adapter_);
2142 2110
2143 bluez::FakeBluetoothDeviceClient::Properties* properties = 2111 bluez::FakeBluetoothDeviceClient::Properties* properties =
2144 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2112 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2145 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 2113 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
2146 2114
2147 properties->bluetooth_class.ReplaceValue(0x002580); 2115 properties->bluetooth_class.ReplaceValue(0x002580);
2148 2116
2149 EXPECT_EQ(1, observer.device_changed_count()); 2117 EXPECT_EQ(1, observer.device_changed_count());
2150 EXPECT_EQ(devices[0], observer.last_device()); 2118 EXPECT_EQ(devices[0], observer.last_device());
2151 2119
2152 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[0]->GetDeviceType()); 2120 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[0]->GetDeviceType());
2153 } 2121 }
2154 2122
2155 TEST_F(BluetoothChromeOSTest, DeviceNameChanged) { 2123 TEST_F(BluetoothBlueZTest, DeviceNameChanged) {
2156 // Simulate a change of name of a device. 2124 // Simulate a change of name of a device.
2157 GetAdapter(); 2125 GetAdapter();
2158 2126
2159 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2127 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2160 ASSERT_EQ(2U, devices.size()); 2128 ASSERT_EQ(2U, devices.size());
2161 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2129 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
2162 devices[0]->GetAddress()); 2130 devices[0]->GetAddress());
2163 ASSERT_EQ( 2131 ASSERT_EQ(
2164 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceName), 2132 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceName),
2165 devices[0]->GetName()); 2133 devices[0]->GetName());
2166 2134
2167 // Install an observer; expect the DeviceChanged method to be called when 2135 // Install an observer; expect the DeviceChanged method to be called when
2168 // we change the alias of the device. 2136 // we change the alias of the device.
2169 TestBluetoothAdapterObserver observer(adapter_); 2137 TestBluetoothAdapterObserver observer(adapter_);
2170 2138
2171 bluez::FakeBluetoothDeviceClient::Properties* properties = 2139 bluez::FakeBluetoothDeviceClient::Properties* properties =
2172 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2140 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2173 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 2141 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
2174 2142
2175 static const std::string new_name("New Device Name"); 2143 static const std::string new_name("New Device Name");
2176 properties->alias.ReplaceValue(new_name); 2144 properties->alias.ReplaceValue(new_name);
2177 2145
2178 EXPECT_EQ(1, observer.device_changed_count()); 2146 EXPECT_EQ(1, observer.device_changed_count());
2179 EXPECT_EQ(devices[0], observer.last_device()); 2147 EXPECT_EQ(devices[0], observer.last_device());
2180 2148
2181 EXPECT_EQ(base::UTF8ToUTF16(new_name), devices[0]->GetName()); 2149 EXPECT_EQ(base::UTF8ToUTF16(new_name), devices[0]->GetName());
2182 } 2150 }
2183 2151
2184 TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) { 2152 TEST_F(BluetoothBlueZTest, DeviceUuidsChanged) {
2185 // Simulate a change of advertised services of a device. 2153 // Simulate a change of advertised services of a device.
2186 GetAdapter(); 2154 GetAdapter();
2187 2155
2188 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2156 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2189 ASSERT_EQ(2U, devices.size()); 2157 ASSERT_EQ(2U, devices.size());
2190 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2158 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
2191 devices[0]->GetAddress()); 2159 devices[0]->GetAddress());
2192 2160
2193 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs(); 2161 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs();
2194 ASSERT_EQ(2U, uuids.size()); 2162 ASSERT_EQ(2U, uuids.size());
(...skipping 23 matching lines...) Expand all
2218 // Fetching the value should give the new one. 2186 // Fetching the value should give the new one.
2219 uuids = devices[0]->GetUUIDs(); 2187 uuids = devices[0]->GetUUIDs();
2220 ASSERT_EQ(5U, uuids.size()); 2188 ASSERT_EQ(5U, uuids.size());
2221 EXPECT_EQ(uuids[0], BluetoothUUID("1800")); 2189 EXPECT_EQ(uuids[0], BluetoothUUID("1800"));
2222 EXPECT_EQ(uuids[1], BluetoothUUID("1801")); 2190 EXPECT_EQ(uuids[1], BluetoothUUID("1801"));
2223 EXPECT_EQ(uuids[2], BluetoothUUID("110c")); 2191 EXPECT_EQ(uuids[2], BluetoothUUID("110c"));
2224 EXPECT_EQ(uuids[3], BluetoothUUID("110e")); 2192 EXPECT_EQ(uuids[3], BluetoothUUID("110e"));
2225 EXPECT_EQ(uuids[4], BluetoothUUID("110a")); 2193 EXPECT_EQ(uuids[4], BluetoothUUID("110a"));
2226 } 2194 }
2227 2195
2228 TEST_F(BluetoothChromeOSTest, DeviceInquiryRSSIInvalidated) { 2196 TEST_F(BluetoothBlueZTest, DeviceInquiryRSSIInvalidated) {
2229 // Simulate invalidation of inquiry RSSI of a device, as it occurs 2197 // Simulate invalidation of inquiry RSSI of a device, as it occurs
2230 // when discovery is finished. 2198 // when discovery is finished.
2231 GetAdapter(); 2199 GetAdapter();
2232 2200
2233 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2201 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2234 ASSERT_EQ(2U, devices.size()); 2202 ASSERT_EQ(2U, devices.size());
2235 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2203 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
2236 devices[0]->GetAddress()); 2204 devices[0]->GetAddress());
2237 2205
2238 bluez::FakeBluetoothDeviceClient::Properties* properties = 2206 bluez::FakeBluetoothDeviceClient::Properties* properties =
(...skipping 14 matching lines...) Expand all
2253 properties->rssi.set_valid(false); 2221 properties->rssi.set_valid(false);
2254 properties->NotifyPropertyChanged(properties->rssi.name()); 2222 properties->NotifyPropertyChanged(properties->rssi.name());
2255 2223
2256 EXPECT_EQ(1, observer.device_changed_count()); 2224 EXPECT_EQ(1, observer.device_changed_count());
2257 EXPECT_EQ(devices[0], observer.last_device()); 2225 EXPECT_EQ(devices[0], observer.last_device());
2258 2226
2259 int unknown_power = BluetoothDevice::kUnknownPower; 2227 int unknown_power = BluetoothDevice::kUnknownPower;
2260 EXPECT_EQ(unknown_power, devices[0]->GetInquiryRSSI()); 2228 EXPECT_EQ(unknown_power, devices[0]->GetInquiryRSSI());
2261 } 2229 }
2262 2230
2263 TEST_F(BluetoothChromeOSTest, DeviceInquiryTxPowerInvalidated) { 2231 TEST_F(BluetoothBlueZTest, DeviceInquiryTxPowerInvalidated) {
2264 // Simulate invalidation of inquiry TxPower of a device, as it occurs 2232 // Simulate invalidation of inquiry TxPower of a device, as it occurs
2265 // when discovery is finished. 2233 // when discovery is finished.
2266 GetAdapter(); 2234 GetAdapter();
2267 2235
2268 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2236 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2269 ASSERT_EQ(2U, devices.size()); 2237 ASSERT_EQ(2U, devices.size());
2270 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2238 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
2271 devices[0]->GetAddress()); 2239 devices[0]->GetAddress());
2272 2240
2273 bluez::FakeBluetoothDeviceClient::Properties* properties = 2241 bluez::FakeBluetoothDeviceClient::Properties* properties =
(...skipping 14 matching lines...) Expand all
2288 properties->tx_power.set_valid(false); 2256 properties->tx_power.set_valid(false);
2289 properties->NotifyPropertyChanged(properties->tx_power.name()); 2257 properties->NotifyPropertyChanged(properties->tx_power.name());
2290 2258
2291 EXPECT_EQ(1, observer.device_changed_count()); 2259 EXPECT_EQ(1, observer.device_changed_count());
2292 EXPECT_EQ(devices[0], observer.last_device()); 2260 EXPECT_EQ(devices[0], observer.last_device());
2293 2261
2294 int unknown_power = BluetoothDevice::kUnknownPower; 2262 int unknown_power = BluetoothDevice::kUnknownPower;
2295 EXPECT_EQ(unknown_power, devices[0]->GetInquiryTxPower()); 2263 EXPECT_EQ(unknown_power, devices[0]->GetInquiryTxPower());
2296 } 2264 }
2297 2265
2298 TEST_F(BluetoothChromeOSTest, ForgetDevice) { 2266 TEST_F(BluetoothBlueZTest, ForgetDevice) {
2299 GetAdapter(); 2267 GetAdapter();
2300 2268
2301 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2269 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2302 ASSERT_EQ(2U, devices.size()); 2270 ASSERT_EQ(2U, devices.size());
2303 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2271 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
2304 devices[0]->GetAddress()); 2272 devices[0]->GetAddress());
2305 2273
2306 std::string address = devices[0]->GetAddress(); 2274 std::string address = devices[0]->GetAddress();
2307 2275
2308 // Install an observer; expect the DeviceRemoved method to be called 2276 // Install an observer; expect the DeviceRemoved method to be called
2309 // with the device we remove. 2277 // with the device we remove.
2310 TestBluetoothAdapterObserver observer(adapter_); 2278 TestBluetoothAdapterObserver observer(adapter_);
2311 2279
2312 devices[0]->Forget(GetErrorCallback()); 2280 devices[0]->Forget(GetErrorCallback());
2313 EXPECT_EQ(0, error_callback_count_); 2281 EXPECT_EQ(0, error_callback_count_);
2314 2282
2315 EXPECT_EQ(1, observer.device_removed_count()); 2283 EXPECT_EQ(1, observer.device_removed_count());
2316 EXPECT_EQ(address, observer.last_device_address()); 2284 EXPECT_EQ(address, observer.last_device_address());
2317 2285
2318 // GetDevices shouldn't return the device either. 2286 // GetDevices shouldn't return the device either.
2319 devices = adapter_->GetDevices(); 2287 devices = adapter_->GetDevices();
2320 ASSERT_EQ(1U, devices.size()); 2288 ASSERT_EQ(1U, devices.size());
2321 } 2289 }
2322 2290
2323 TEST_F(BluetoothChromeOSTest, ForgetUnpairedDevice) { 2291 TEST_F(BluetoothBlueZTest, ForgetUnpairedDevice) {
2324 GetAdapter(); 2292 GetAdapter();
2325 DiscoverDevices(); 2293 DiscoverDevices();
2326 2294
2327 BluetoothDevice* device = adapter_->GetDevice( 2295 BluetoothDevice* device = adapter_->GetDevice(
2328 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); 2296 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress);
2329 ASSERT_TRUE(device != nullptr); 2297 ASSERT_TRUE(device != nullptr);
2330 ASSERT_FALSE(device->IsPaired()); 2298 ASSERT_FALSE(device->IsPaired());
2331 2299
2332 // Connect the device so it becomes trusted and remembered. 2300 // Connect the device so it becomes trusted and remembered.
2333 device->Connect(nullptr, GetCallback(), 2301 device->Connect(nullptr, GetCallback(),
2334 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2302 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2335 base::Unretained(this))); 2303 base::Unretained(this)));
2336 2304
2337 ASSERT_EQ(1, callback_count_); 2305 ASSERT_EQ(1, callback_count_);
2338 ASSERT_EQ(0, error_callback_count_); 2306 ASSERT_EQ(0, error_callback_count_);
2339 callback_count_ = 0; 2307 callback_count_ = 0;
2340 2308
2341 ASSERT_TRUE(device->IsConnected()); 2309 ASSERT_TRUE(device->IsConnected());
2342 ASSERT_FALSE(device->IsConnecting()); 2310 ASSERT_FALSE(device->IsConnecting());
2343 2311
2344 // Make sure the trusted property has been set to true. 2312 // Make sure the trusted property has been set to true.
(...skipping 12 matching lines...) Expand all
2357 EXPECT_EQ(1, observer.device_removed_count()); 2325 EXPECT_EQ(1, observer.device_removed_count());
2358 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress, 2326 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress,
2359 observer.last_device_address()); 2327 observer.last_device_address());
2360 2328
2361 // GetDevices shouldn't return the device either. 2329 // GetDevices shouldn't return the device either.
2362 device = adapter_->GetDevice( 2330 device = adapter_->GetDevice(
2363 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); 2331 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress);
2364 EXPECT_FALSE(device != nullptr); 2332 EXPECT_FALSE(device != nullptr);
2365 } 2333 }
2366 2334
2367 TEST_F(BluetoothChromeOSTest, ConnectPairedDevice) { 2335 TEST_F(BluetoothBlueZTest, ConnectPairedDevice) {
2368 GetAdapter(); 2336 GetAdapter();
2369 2337
2370 BluetoothDevice* device = adapter_->GetDevice( 2338 BluetoothDevice* device = adapter_->GetDevice(
2371 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2339 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2372 ASSERT_TRUE(device != nullptr); 2340 ASSERT_TRUE(device != nullptr);
2373 ASSERT_TRUE(device->IsPaired()); 2341 ASSERT_TRUE(device->IsPaired());
2374 2342
2375 TestBluetoothAdapterObserver observer(adapter_); 2343 TestBluetoothAdapterObserver observer(adapter_);
2376 2344
2377 // Connect without a pairing delegate; since the device is already Paired 2345 // Connect without a pairing delegate; since the device is already Paired
2378 // this should succeed and the device should become connected. 2346 // this should succeed and the device should become connected.
2379 device->Connect(nullptr, GetCallback(), 2347 device->Connect(nullptr, GetCallback(),
2380 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2348 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2381 base::Unretained(this))); 2349 base::Unretained(this)));
2382 2350
2383 EXPECT_EQ(1, callback_count_); 2351 EXPECT_EQ(1, callback_count_);
2384 EXPECT_EQ(0, error_callback_count_); 2352 EXPECT_EQ(0, error_callback_count_);
2385 2353
2386 // Two changes for connecting, one for connected and one for for trusted 2354 // Two changes for connecting, one for connected and one for for trusted
2387 // after connecting. 2355 // after connecting.
2388 EXPECT_EQ(4, observer.device_changed_count()); 2356 EXPECT_EQ(4, observer.device_changed_count());
2389 EXPECT_EQ(device, observer.last_device()); 2357 EXPECT_EQ(device, observer.last_device());
2390 2358
2391 EXPECT_TRUE(device->IsConnected()); 2359 EXPECT_TRUE(device->IsConnected());
2392 EXPECT_FALSE(device->IsConnecting()); 2360 EXPECT_FALSE(device->IsConnecting());
2393 } 2361 }
2394 2362
2395 TEST_F(BluetoothChromeOSTest, ConnectUnpairableDevice) { 2363 TEST_F(BluetoothBlueZTest, ConnectUnpairableDevice) {
2396 GetAdapter(); 2364 GetAdapter();
2397 DiscoverDevices(); 2365 DiscoverDevices();
2398 2366
2399 BluetoothDevice* device = adapter_->GetDevice( 2367 BluetoothDevice* device = adapter_->GetDevice(
2400 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); 2368 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress);
2401 ASSERT_TRUE(device != nullptr); 2369 ASSERT_TRUE(device != nullptr);
2402 ASSERT_FALSE(device->IsPaired()); 2370 ASSERT_FALSE(device->IsPaired());
2403 2371
2404 TestBluetoothAdapterObserver observer(adapter_); 2372 TestBluetoothAdapterObserver observer(adapter_);
2405 2373
2406 // Connect without a pairing delegate; since the device does not require 2374 // Connect without a pairing delegate; since the device does not require
2407 // pairing, this should succeed and the device should become connected. 2375 // pairing, this should succeed and the device should become connected.
2408 device->Connect(nullptr, GetCallback(), 2376 device->Connect(nullptr, GetCallback(),
2409 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2377 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2410 base::Unretained(this))); 2378 base::Unretained(this)));
2411 2379
2412 EXPECT_EQ(1, callback_count_); 2380 EXPECT_EQ(1, callback_count_);
2413 EXPECT_EQ(0, error_callback_count_); 2381 EXPECT_EQ(0, error_callback_count_);
2414 2382
2415 // Two changes for connecting, one for connected, one for for trusted after 2383 // Two changes for connecting, one for connected, one for for trusted after
2416 // connection, and one for the reconnect mode (IsConnectable). 2384 // connection, and one for the reconnect mode (IsConnectable).
2417 EXPECT_EQ(5, observer.device_changed_count()); 2385 EXPECT_EQ(5, observer.device_changed_count());
2418 EXPECT_EQ(device, observer.last_device()); 2386 EXPECT_EQ(device, observer.last_device());
2419 2387
2420 EXPECT_TRUE(device->IsConnected()); 2388 EXPECT_TRUE(device->IsConnected());
2421 EXPECT_FALSE(device->IsConnecting()); 2389 EXPECT_FALSE(device->IsConnecting());
2422 2390
2423 // Make sure the trusted property has been set to true. 2391 // Make sure the trusted property has been set to true.
2424 bluez::FakeBluetoothDeviceClient::Properties* properties = 2392 bluez::FakeBluetoothDeviceClient::Properties* properties =
2425 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2393 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2426 bluez::FakeBluetoothDeviceClient::kConnectUnpairablePath)); 2394 bluez::FakeBluetoothDeviceClient::kConnectUnpairablePath));
2427 EXPECT_TRUE(properties->trusted.value()); 2395 EXPECT_TRUE(properties->trusted.value());
2428 2396
2429 // Verify is a HID device and is not connectable. 2397 // Verify is a HID device and is not connectable.
2430 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 2398 BluetoothDevice::UUIDList uuids = device->GetUUIDs();
2431 ASSERT_EQ(1U, uuids.size()); 2399 ASSERT_EQ(1U, uuids.size());
2432 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); 2400 EXPECT_EQ(uuids[0], BluetoothUUID("1124"));
2433 EXPECT_FALSE(device->IsConnectable()); 2401 EXPECT_FALSE(device->IsConnectable());
2434 } 2402 }
2435 2403
2436 TEST_F(BluetoothChromeOSTest, ConnectConnectedDevice) { 2404 TEST_F(BluetoothBlueZTest, ConnectConnectedDevice) {
2437 GetAdapter(); 2405 GetAdapter();
2438 2406
2439 BluetoothDevice* device = adapter_->GetDevice( 2407 BluetoothDevice* device = adapter_->GetDevice(
2440 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2408 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2441 ASSERT_TRUE(device != nullptr); 2409 ASSERT_TRUE(device != nullptr);
2442 ASSERT_TRUE(device->IsPaired()); 2410 ASSERT_TRUE(device->IsPaired());
2443 2411
2444 device->Connect(nullptr, GetCallback(), 2412 device->Connect(nullptr, GetCallback(),
2445 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2413 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2446 base::Unretained(this))); 2414 base::Unretained(this)));
2447 2415
2448 ASSERT_EQ(1, callback_count_); 2416 ASSERT_EQ(1, callback_count_);
2449 ASSERT_EQ(0, error_callback_count_); 2417 ASSERT_EQ(0, error_callback_count_);
2450 callback_count_ = 0; 2418 callback_count_ = 0;
2451 2419
2452 ASSERT_TRUE(device->IsConnected()); 2420 ASSERT_TRUE(device->IsConnected());
2453 2421
2454 // Connect again; since the device is already Connected, this shouldn't do 2422 // Connect again; since the device is already Connected, this shouldn't do
2455 // anything to initiate the connection. 2423 // anything to initiate the connection.
2456 TestBluetoothAdapterObserver observer(adapter_); 2424 TestBluetoothAdapterObserver observer(adapter_);
2457 2425
2458 device->Connect(nullptr, GetCallback(), 2426 device->Connect(nullptr, GetCallback(),
2459 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2427 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2460 base::Unretained(this))); 2428 base::Unretained(this)));
2461 2429
2462 EXPECT_EQ(1, callback_count_); 2430 EXPECT_EQ(1, callback_count_);
2463 EXPECT_EQ(0, error_callback_count_); 2431 EXPECT_EQ(0, error_callback_count_);
2464 2432
2465 // The observer will be called because Connecting will toggle true and false, 2433 // The observer will be called because Connecting will toggle true and false,
2466 // and the trusted property will be updated to true. 2434 // and the trusted property will be updated to true.
2467 EXPECT_EQ(3, observer.device_changed_count()); 2435 EXPECT_EQ(3, observer.device_changed_count());
2468 2436
2469 EXPECT_TRUE(device->IsConnected()); 2437 EXPECT_TRUE(device->IsConnected());
2470 EXPECT_FALSE(device->IsConnecting()); 2438 EXPECT_FALSE(device->IsConnecting());
2471 } 2439 }
2472 2440
2473 TEST_F(BluetoothChromeOSTest, ConnectDeviceFails) { 2441 TEST_F(BluetoothBlueZTest, ConnectDeviceFails) {
2474 GetAdapter(); 2442 GetAdapter();
2475 DiscoverDevices(); 2443 DiscoverDevices();
2476 2444
2477 BluetoothDevice* device = adapter_->GetDevice( 2445 BluetoothDevice* device = adapter_->GetDevice(
2478 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); 2446 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress);
2479 ASSERT_TRUE(device != nullptr); 2447 ASSERT_TRUE(device != nullptr);
2480 ASSERT_FALSE(device->IsPaired()); 2448 ASSERT_FALSE(device->IsPaired());
2481 2449
2482 TestBluetoothAdapterObserver observer(adapter_); 2450 TestBluetoothAdapterObserver observer(adapter_);
2483 2451
2484 // Connect without a pairing delegate; since the device requires pairing, 2452 // Connect without a pairing delegate; since the device requires pairing,
2485 // this should fail with an error. 2453 // this should fail with an error.
2486 device->Connect(nullptr, GetCallback(), 2454 device->Connect(nullptr, GetCallback(),
2487 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2455 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2488 base::Unretained(this))); 2456 base::Unretained(this)));
2489 2457
2490 EXPECT_EQ(0, callback_count_); 2458 EXPECT_EQ(0, callback_count_);
2491 EXPECT_EQ(1, error_callback_count_); 2459 EXPECT_EQ(1, error_callback_count_);
2492 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); 2460 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_);
2493 2461
2494 EXPECT_EQ(2, observer.device_changed_count()); 2462 EXPECT_EQ(2, observer.device_changed_count());
2495 2463
2496 EXPECT_FALSE(device->IsConnected()); 2464 EXPECT_FALSE(device->IsConnected());
2497 EXPECT_FALSE(device->IsConnecting()); 2465 EXPECT_FALSE(device->IsConnecting());
2498 } 2466 }
2499 2467
2500 TEST_F(BluetoothChromeOSTest, DisconnectDevice) { 2468 TEST_F(BluetoothBlueZTest, DisconnectDevice) {
2501 GetAdapter(); 2469 GetAdapter();
2502 2470
2503 BluetoothDevice* device = adapter_->GetDevice( 2471 BluetoothDevice* device = adapter_->GetDevice(
2504 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2472 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2505 ASSERT_TRUE(device != nullptr); 2473 ASSERT_TRUE(device != nullptr);
2506 ASSERT_TRUE(device->IsPaired()); 2474 ASSERT_TRUE(device->IsPaired());
2507 2475
2508 device->Connect(nullptr, GetCallback(), 2476 device->Connect(nullptr, GetCallback(),
2509 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2477 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2510 base::Unretained(this))); 2478 base::Unretained(this)));
2511 2479
2512 ASSERT_EQ(1, callback_count_); 2480 ASSERT_EQ(1, callback_count_);
2513 ASSERT_EQ(0, error_callback_count_); 2481 ASSERT_EQ(0, error_callback_count_);
2514 callback_count_ = 0; 2482 callback_count_ = 0;
2515 2483
2516 ASSERT_TRUE(device->IsConnected()); 2484 ASSERT_TRUE(device->IsConnected());
2517 ASSERT_FALSE(device->IsConnecting()); 2485 ASSERT_FALSE(device->IsConnecting());
2518 2486
2519 // Disconnect the device, we should see the observer method fire and the 2487 // Disconnect the device, we should see the observer method fire and the
2520 // device get dropped. 2488 // device get dropped.
2521 TestBluetoothAdapterObserver observer(adapter_); 2489 TestBluetoothAdapterObserver observer(adapter_);
2522 2490
2523 device->Disconnect(GetCallback(), GetErrorCallback()); 2491 device->Disconnect(GetCallback(), GetErrorCallback());
2524 2492
2525 EXPECT_EQ(1, callback_count_); 2493 EXPECT_EQ(1, callback_count_);
2526 EXPECT_EQ(0, error_callback_count_); 2494 EXPECT_EQ(0, error_callback_count_);
2527 2495
2528 EXPECT_EQ(1, observer.device_changed_count()); 2496 EXPECT_EQ(1, observer.device_changed_count());
2529 EXPECT_EQ(device, observer.last_device()); 2497 EXPECT_EQ(device, observer.last_device());
2530 2498
2531 EXPECT_FALSE(device->IsConnected()); 2499 EXPECT_FALSE(device->IsConnected());
2532 } 2500 }
2533 2501
2534 TEST_F(BluetoothChromeOSTest, DisconnectUnconnectedDevice) { 2502 TEST_F(BluetoothBlueZTest, DisconnectUnconnectedDevice) {
2535 GetAdapter(); 2503 GetAdapter();
2536 2504
2537 BluetoothDevice* device = adapter_->GetDevice( 2505 BluetoothDevice* device = adapter_->GetDevice(
2538 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2506 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2539 ASSERT_TRUE(device != nullptr); 2507 ASSERT_TRUE(device != nullptr);
2540 ASSERT_TRUE(device->IsPaired()); 2508 ASSERT_TRUE(device->IsPaired());
2541 ASSERT_FALSE(device->IsConnected()); 2509 ASSERT_FALSE(device->IsConnected());
2542 2510
2543 // Disconnect the device, we should see the observer method fire and the 2511 // Disconnect the device, we should see the observer method fire and the
2544 // device get dropped. 2512 // device get dropped.
2545 TestBluetoothAdapterObserver observer(adapter_); 2513 TestBluetoothAdapterObserver observer(adapter_);
2546 2514
2547 device->Disconnect(GetCallback(), GetErrorCallback()); 2515 device->Disconnect(GetCallback(), GetErrorCallback());
2548 2516
2549 EXPECT_EQ(0, callback_count_); 2517 EXPECT_EQ(0, callback_count_);
2550 EXPECT_EQ(1, error_callback_count_); 2518 EXPECT_EQ(1, error_callback_count_);
2551 2519
2552 EXPECT_EQ(0, observer.device_changed_count()); 2520 EXPECT_EQ(0, observer.device_changed_count());
2553 2521
2554 EXPECT_FALSE(device->IsConnected()); 2522 EXPECT_FALSE(device->IsConnected());
2555 } 2523 }
2556 2524
2557 TEST_F(BluetoothChromeOSTest, PairLegacyAutopair) { 2525 TEST_F(BluetoothBlueZTest, PairLegacyAutopair) {
2558 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2526 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2559 2527
2560 GetAdapter(); 2528 GetAdapter();
2561 DiscoverDevices(); 2529 DiscoverDevices();
2562 2530
2563 // The Legacy Autopair device requires no PIN or Passkey to pair because 2531 // The Legacy Autopair device requires no PIN or Passkey to pair because
2564 // the daemon provides 0000 to the device for us. 2532 // the daemon provides 0000 to the device for us.
2565 BluetoothDevice* device = adapter_->GetDevice( 2533 BluetoothDevice* device = adapter_->GetDevice(
2566 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); 2534 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress);
2567 ASSERT_TRUE(device != nullptr); 2535 ASSERT_TRUE(device != nullptr);
2568 ASSERT_FALSE(device->IsPaired()); 2536 ASSERT_FALSE(device->IsPaired());
2569 2537
2570 TestBluetoothAdapterObserver observer(adapter_); 2538 TestBluetoothAdapterObserver observer(adapter_);
2571 2539
2572 TestPairingDelegate pairing_delegate; 2540 TestPairingDelegate pairing_delegate;
2573 device->Connect(&pairing_delegate, GetCallback(), 2541 device->Connect(&pairing_delegate, GetCallback(),
2574 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2542 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2575 base::Unretained(this))); 2543 base::Unretained(this)));
2576 2544
2577 EXPECT_EQ(0, pairing_delegate.call_count_); 2545 EXPECT_EQ(0, pairing_delegate.call_count_);
2578 EXPECT_TRUE(device->IsConnecting()); 2546 EXPECT_TRUE(device->IsConnecting());
2579 2547
2580 message_loop_.Run(); 2548 message_loop_.Run();
2581 2549
2582 EXPECT_EQ(1, callback_count_); 2550 EXPECT_EQ(1, callback_count_);
2583 EXPECT_EQ(0, error_callback_count_); 2551 EXPECT_EQ(0, error_callback_count_);
2584 2552
(...skipping 14 matching lines...) Expand all
2599 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); 2567 EXPECT_EQ(uuids[0], BluetoothUUID("1124"));
2600 EXPECT_TRUE(device->IsConnectable()); 2568 EXPECT_TRUE(device->IsConnectable());
2601 2569
2602 // Make sure the trusted property has been set to true. 2570 // Make sure the trusted property has been set to true.
2603 bluez::FakeBluetoothDeviceClient::Properties* properties = 2571 bluez::FakeBluetoothDeviceClient::Properties* properties =
2604 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2572 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2605 bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath)); 2573 bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath));
2606 EXPECT_TRUE(properties->trusted.value()); 2574 EXPECT_TRUE(properties->trusted.value());
2607 } 2575 }
2608 2576
2609 TEST_F(BluetoothChromeOSTest, PairDisplayPinCode) { 2577 TEST_F(BluetoothBlueZTest, PairDisplayPinCode) {
2610 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2578 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2611 2579
2612 GetAdapter(); 2580 GetAdapter();
2613 DiscoverDevices(); 2581 DiscoverDevices();
2614 2582
2615 // Requires that we display a randomly generated PIN on the screen. 2583 // Requires that we display a randomly generated PIN on the screen.
2616 BluetoothDevice* device = adapter_->GetDevice( 2584 BluetoothDevice* device = adapter_->GetDevice(
2617 bluez::FakeBluetoothDeviceClient::kDisplayPinCodeAddress); 2585 bluez::FakeBluetoothDeviceClient::kDisplayPinCodeAddress);
2618 ASSERT_TRUE(device != nullptr); 2586 ASSERT_TRUE(device != nullptr);
2619 ASSERT_FALSE(device->IsPaired()); 2587 ASSERT_FALSE(device->IsPaired());
2620 2588
2621 TestBluetoothAdapterObserver observer(adapter_); 2589 TestBluetoothAdapterObserver observer(adapter_);
2622 2590
2623 TestPairingDelegate pairing_delegate; 2591 TestPairingDelegate pairing_delegate;
2624 device->Connect(&pairing_delegate, GetCallback(), 2592 device->Connect(&pairing_delegate, GetCallback(),
2625 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2593 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2626 base::Unretained(this))); 2594 base::Unretained(this)));
2627 2595
2628 EXPECT_EQ(1, pairing_delegate.call_count_); 2596 EXPECT_EQ(1, pairing_delegate.call_count_);
2629 EXPECT_EQ(1, pairing_delegate.display_pincode_count_); 2597 EXPECT_EQ(1, pairing_delegate.display_pincode_count_);
2630 EXPECT_EQ("123456", pairing_delegate.last_pincode_); 2598 EXPECT_EQ("123456", pairing_delegate.last_pincode_);
2631 EXPECT_TRUE(device->IsConnecting()); 2599 EXPECT_TRUE(device->IsConnecting());
2632 2600
2633 message_loop_.Run(); 2601 message_loop_.Run();
2634 2602
2635 EXPECT_EQ(1, callback_count_); 2603 EXPECT_EQ(1, callback_count_);
(...skipping 16 matching lines...) Expand all
2652 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); 2620 EXPECT_EQ(uuids[0], BluetoothUUID("1124"));
2653 EXPECT_TRUE(device->IsConnectable()); 2621 EXPECT_TRUE(device->IsConnectable());
2654 2622
2655 // Make sure the trusted property has been set to true. 2623 // Make sure the trusted property has been set to true.
2656 bluez::FakeBluetoothDeviceClient::Properties* properties = 2624 bluez::FakeBluetoothDeviceClient::Properties* properties =
2657 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2625 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2658 bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath)); 2626 bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath));
2659 EXPECT_TRUE(properties->trusted.value()); 2627 EXPECT_TRUE(properties->trusted.value());
2660 } 2628 }
2661 2629
2662 TEST_F(BluetoothChromeOSTest, PairDisplayPasskey) { 2630 TEST_F(BluetoothBlueZTest, PairDisplayPasskey) {
2663 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2631 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2664 2632
2665 GetAdapter(); 2633 GetAdapter();
2666 DiscoverDevices(); 2634 DiscoverDevices();
2667 2635
2668 // Requires that we display a randomly generated Passkey on the screen, 2636 // Requires that we display a randomly generated Passkey on the screen,
2669 // and notifies us as it's typed in. 2637 // and notifies us as it's typed in.
2670 BluetoothDevice* device = adapter_->GetDevice( 2638 BluetoothDevice* device = adapter_->GetDevice(
2671 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyAddress); 2639 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyAddress);
2672 ASSERT_TRUE(device != nullptr); 2640 ASSERT_TRUE(device != nullptr);
2673 ASSERT_FALSE(device->IsPaired()); 2641 ASSERT_FALSE(device->IsPaired());
2674 2642
2675 TestBluetoothAdapterObserver observer(adapter_); 2643 TestBluetoothAdapterObserver observer(adapter_);
2676 2644
2677 TestPairingDelegate pairing_delegate; 2645 TestPairingDelegate pairing_delegate;
2678 device->Connect(&pairing_delegate, GetCallback(), 2646 device->Connect(&pairing_delegate, GetCallback(),
2679 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2647 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2680 base::Unretained(this))); 2648 base::Unretained(this)));
2681 2649
2682 // One call for DisplayPasskey() and one for KeysEntered(). 2650 // One call for DisplayPasskey() and one for KeysEntered().
2683 EXPECT_EQ(2, pairing_delegate.call_count_); 2651 EXPECT_EQ(2, pairing_delegate.call_count_);
2684 EXPECT_EQ(1, pairing_delegate.display_passkey_count_); 2652 EXPECT_EQ(1, pairing_delegate.display_passkey_count_);
2685 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); 2653 EXPECT_EQ(123456U, pairing_delegate.last_passkey_);
2686 EXPECT_EQ(1, pairing_delegate.keys_entered_count_); 2654 EXPECT_EQ(1, pairing_delegate.keys_entered_count_);
2687 EXPECT_EQ(0U, pairing_delegate.last_entered_); 2655 EXPECT_EQ(0U, pairing_delegate.last_entered_);
2688 2656
2689 EXPECT_TRUE(device->IsConnecting()); 2657 EXPECT_TRUE(device->IsConnecting());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2727 // And usually not connectable. 2695 // And usually not connectable.
2728 EXPECT_FALSE(device->IsConnectable()); 2696 EXPECT_FALSE(device->IsConnectable());
2729 2697
2730 // Make sure the trusted property has been set to true. 2698 // Make sure the trusted property has been set to true.
2731 bluez::FakeBluetoothDeviceClient::Properties* properties = 2699 bluez::FakeBluetoothDeviceClient::Properties* properties =
2732 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2700 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2733 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyPath)); 2701 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyPath));
2734 EXPECT_TRUE(properties->trusted.value()); 2702 EXPECT_TRUE(properties->trusted.value());
2735 } 2703 }
2736 2704
2737 TEST_F(BluetoothChromeOSTest, PairRequestPinCode) { 2705 TEST_F(BluetoothBlueZTest, PairRequestPinCode) {
2738 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2706 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2739 2707
2740 GetAdapter(); 2708 GetAdapter();
2741 DiscoverDevices(); 2709 DiscoverDevices();
2742 2710
2743 // Requires that the user enters a PIN for them. 2711 // Requires that the user enters a PIN for them.
2744 BluetoothDevice* device = adapter_->GetDevice( 2712 BluetoothDevice* device = adapter_->GetDevice(
2745 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); 2713 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress);
2746 ASSERT_TRUE(device != nullptr); 2714 ASSERT_TRUE(device != nullptr);
2747 ASSERT_FALSE(device->IsPaired()); 2715 ASSERT_FALSE(device->IsPaired());
2748 2716
2749 TestBluetoothAdapterObserver observer(adapter_); 2717 TestBluetoothAdapterObserver observer(adapter_);
2750 2718
2751 TestPairingDelegate pairing_delegate; 2719 TestPairingDelegate pairing_delegate;
2752 device->Connect(&pairing_delegate, GetCallback(), 2720 device->Connect(&pairing_delegate, GetCallback(),
2753 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2721 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2754 base::Unretained(this))); 2722 base::Unretained(this)));
2755 2723
2756 EXPECT_EQ(1, pairing_delegate.call_count_); 2724 EXPECT_EQ(1, pairing_delegate.call_count_);
2757 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); 2725 EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
2758 EXPECT_TRUE(device->IsConnecting()); 2726 EXPECT_TRUE(device->IsConnecting());
2759 2727
2760 // Set the PIN. 2728 // Set the PIN.
2761 device->SetPinCode("1234"); 2729 device->SetPinCode("1234");
2762 message_loop_.Run(); 2730 message_loop_.Run();
2763 2731
(...skipping 17 matching lines...) Expand all
2781 // Non HID devices are always connectable. 2749 // Non HID devices are always connectable.
2782 EXPECT_TRUE(device->IsConnectable()); 2750 EXPECT_TRUE(device->IsConnectable());
2783 2751
2784 // Make sure the trusted property has been set to true. 2752 // Make sure the trusted property has been set to true.
2785 bluez::FakeBluetoothDeviceClient::Properties* properties = 2753 bluez::FakeBluetoothDeviceClient::Properties* properties =
2786 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2754 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2787 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); 2755 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath));
2788 EXPECT_TRUE(properties->trusted.value()); 2756 EXPECT_TRUE(properties->trusted.value());
2789 } 2757 }
2790 2758
2791 TEST_F(BluetoothChromeOSTest, PairConfirmPasskey) { 2759 TEST_F(BluetoothBlueZTest, PairConfirmPasskey) {
2792 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2760 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2793 2761
2794 GetAdapter(); 2762 GetAdapter();
2795 DiscoverDevices(); 2763 DiscoverDevices();
2796 2764
2797 // Requests that we confirm a displayed passkey. 2765 // Requests that we confirm a displayed passkey.
2798 BluetoothDevice* device = adapter_->GetDevice( 2766 BluetoothDevice* device = adapter_->GetDevice(
2799 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); 2767 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress);
2800 ASSERT_TRUE(device != nullptr); 2768 ASSERT_TRUE(device != nullptr);
2801 ASSERT_FALSE(device->IsPaired()); 2769 ASSERT_FALSE(device->IsPaired());
2802 2770
2803 TestBluetoothAdapterObserver observer(adapter_); 2771 TestBluetoothAdapterObserver observer(adapter_);
2804 2772
2805 TestPairingDelegate pairing_delegate; 2773 TestPairingDelegate pairing_delegate;
2806 device->Connect(&pairing_delegate, GetCallback(), 2774 device->Connect(&pairing_delegate, GetCallback(),
2807 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2775 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2808 base::Unretained(this))); 2776 base::Unretained(this)));
2809 2777
2810 EXPECT_EQ(1, pairing_delegate.call_count_); 2778 EXPECT_EQ(1, pairing_delegate.call_count_);
2811 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 2779 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
2812 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); 2780 EXPECT_EQ(123456U, pairing_delegate.last_passkey_);
2813 EXPECT_TRUE(device->IsConnecting()); 2781 EXPECT_TRUE(device->IsConnecting());
2814 2782
2815 // Confirm the passkey. 2783 // Confirm the passkey.
2816 device->ConfirmPairing(); 2784 device->ConfirmPairing();
2817 message_loop_.Run(); 2785 message_loop_.Run();
(...skipping 14 matching lines...) Expand all
2832 // Non HID devices are always connectable. 2800 // Non HID devices are always connectable.
2833 EXPECT_TRUE(device->IsConnectable()); 2801 EXPECT_TRUE(device->IsConnectable());
2834 2802
2835 // Make sure the trusted property has been set to true. 2803 // Make sure the trusted property has been set to true.
2836 bluez::FakeBluetoothDeviceClient::Properties* properties = 2804 bluez::FakeBluetoothDeviceClient::Properties* properties =
2837 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2805 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2838 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); 2806 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath));
2839 EXPECT_TRUE(properties->trusted.value()); 2807 EXPECT_TRUE(properties->trusted.value());
2840 } 2808 }
2841 2809
2842 TEST_F(BluetoothChromeOSTest, PairRequestPasskey) { 2810 TEST_F(BluetoothBlueZTest, PairRequestPasskey) {
2843 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2811 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2844 2812
2845 GetAdapter(); 2813 GetAdapter();
2846 DiscoverDevices(); 2814 DiscoverDevices();
2847 2815
2848 // Requires that the user enters a Passkey, this would be some kind of 2816 // Requires that the user enters a Passkey, this would be some kind of
2849 // device that has a display, but doesn't use "just works" - maybe a car? 2817 // device that has a display, but doesn't use "just works" - maybe a car?
2850 BluetoothDevice* device = adapter_->GetDevice( 2818 BluetoothDevice* device = adapter_->GetDevice(
2851 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); 2819 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress);
2852 ASSERT_TRUE(device != nullptr); 2820 ASSERT_TRUE(device != nullptr);
2853 ASSERT_FALSE(device->IsPaired()); 2821 ASSERT_FALSE(device->IsPaired());
2854 2822
2855 TestBluetoothAdapterObserver observer(adapter_); 2823 TestBluetoothAdapterObserver observer(adapter_);
2856 2824
2857 TestPairingDelegate pairing_delegate; 2825 TestPairingDelegate pairing_delegate;
2858 device->Connect(&pairing_delegate, GetCallback(), 2826 device->Connect(&pairing_delegate, GetCallback(),
2859 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2827 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2860 base::Unretained(this))); 2828 base::Unretained(this)));
2861 2829
2862 EXPECT_EQ(1, pairing_delegate.call_count_); 2830 EXPECT_EQ(1, pairing_delegate.call_count_);
2863 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 2831 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
2864 EXPECT_TRUE(device->IsConnecting()); 2832 EXPECT_TRUE(device->IsConnecting());
2865 2833
2866 // Set the Passkey. 2834 // Set the Passkey.
2867 device->SetPasskey(1234); 2835 device->SetPasskey(1234);
2868 message_loop_.Run(); 2836 message_loop_.Run();
2869 2837
(...skipping 13 matching lines...) Expand all
2883 // Non HID devices are always connectable. 2851 // Non HID devices are always connectable.
2884 EXPECT_TRUE(device->IsConnectable()); 2852 EXPECT_TRUE(device->IsConnectable());
2885 2853
2886 // Make sure the trusted property has been set to true. 2854 // Make sure the trusted property has been set to true.
2887 bluez::FakeBluetoothDeviceClient::Properties* properties = 2855 bluez::FakeBluetoothDeviceClient::Properties* properties =
2888 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2856 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2889 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); 2857 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath));
2890 EXPECT_TRUE(properties->trusted.value()); 2858 EXPECT_TRUE(properties->trusted.value());
2891 } 2859 }
2892 2860
2893 TEST_F(BluetoothChromeOSTest, PairJustWorks) { 2861 TEST_F(BluetoothBlueZTest, PairJustWorks) {
2894 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2862 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2895 2863
2896 GetAdapter(); 2864 GetAdapter();
2897 DiscoverDevices(); 2865 DiscoverDevices();
2898 2866
2899 // Uses just-works pairing, since this is an outgoing pairing, no delegate 2867 // Uses just-works pairing, since this is an outgoing pairing, no delegate
2900 // interaction is required. 2868 // interaction is required.
2901 BluetoothDevice* device = 2869 BluetoothDevice* device =
2902 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); 2870 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress);
2903 ASSERT_TRUE(device != nullptr); 2871 ASSERT_TRUE(device != nullptr);
2904 ASSERT_FALSE(device->IsPaired()); 2872 ASSERT_FALSE(device->IsPaired());
2905 2873
2906 TestBluetoothAdapterObserver observer(adapter_); 2874 TestBluetoothAdapterObserver observer(adapter_);
2907 2875
2908 TestPairingDelegate pairing_delegate; 2876 TestPairingDelegate pairing_delegate;
2909 device->Connect(&pairing_delegate, GetCallback(), 2877 device->Connect(&pairing_delegate, GetCallback(),
2910 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2878 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2911 base::Unretained(this))); 2879 base::Unretained(this)));
2912 2880
2913 EXPECT_EQ(0, pairing_delegate.call_count_); 2881 EXPECT_EQ(0, pairing_delegate.call_count_);
2914 2882
2915 message_loop_.Run(); 2883 message_loop_.Run();
2916 2884
2917 EXPECT_EQ(1, callback_count_); 2885 EXPECT_EQ(1, callback_count_);
2918 EXPECT_EQ(0, error_callback_count_); 2886 EXPECT_EQ(0, error_callback_count_);
2919 2887
2920 // Two changes for connecting, one change for connected, one for paired and 2888 // Two changes for connecting, one change for connected, one for paired and
2921 // two for trusted (after pairing and connection). 2889 // two for trusted (after pairing and connection).
2922 EXPECT_EQ(6, observer.device_changed_count()); 2890 EXPECT_EQ(6, observer.device_changed_count());
2923 EXPECT_EQ(device, observer.last_device()); 2891 EXPECT_EQ(device, observer.last_device());
2924 2892
2925 EXPECT_TRUE(device->IsConnected()); 2893 EXPECT_TRUE(device->IsConnected());
2926 EXPECT_FALSE(device->IsConnecting()); 2894 EXPECT_FALSE(device->IsConnecting());
2927 2895
2928 EXPECT_TRUE(device->IsPaired()); 2896 EXPECT_TRUE(device->IsPaired());
2929 2897
2930 // Non HID devices are always connectable. 2898 // Non HID devices are always connectable.
2931 EXPECT_TRUE(device->IsConnectable()); 2899 EXPECT_TRUE(device->IsConnectable());
2932 2900
2933 // Make sure the trusted property has been set to true. 2901 // Make sure the trusted property has been set to true.
2934 bluez::FakeBluetoothDeviceClient::Properties* properties = 2902 bluez::FakeBluetoothDeviceClient::Properties* properties =
2935 fake_bluetooth_device_client_->GetProperties( 2903 fake_bluetooth_device_client_->GetProperties(
2936 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); 2904 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath));
2937 EXPECT_TRUE(properties->trusted.value()); 2905 EXPECT_TRUE(properties->trusted.value());
2938 } 2906 }
2939 2907
2940 TEST_F(BluetoothChromeOSTest, PairUnpairableDeviceFails) { 2908 TEST_F(BluetoothBlueZTest, PairUnpairableDeviceFails) {
2941 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2909 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2942 2910
2943 GetAdapter(); 2911 GetAdapter();
2944 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); 2912 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress);
2945 2913
2946 BluetoothDevice* device = adapter_->GetDevice( 2914 BluetoothDevice* device = adapter_->GetDevice(
2947 bluez::FakeBluetoothDeviceClient::kUnpairableDeviceAddress); 2915 bluez::FakeBluetoothDeviceClient::kUnpairableDeviceAddress);
2948 ASSERT_TRUE(device != nullptr); 2916 ASSERT_TRUE(device != nullptr);
2949 ASSERT_FALSE(device->IsPaired()); 2917 ASSERT_FALSE(device->IsPaired());
2950 2918
2951 TestBluetoothAdapterObserver observer(adapter_); 2919 TestBluetoothAdapterObserver observer(adapter_);
2952 2920
2953 TestPairingDelegate pairing_delegate; 2921 TestPairingDelegate pairing_delegate;
2954 device->Connect(&pairing_delegate, GetCallback(), 2922 device->Connect(&pairing_delegate, GetCallback(),
2955 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2923 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2956 base::Unretained(this))); 2924 base::Unretained(this)));
2957 2925
2958 EXPECT_EQ(0, pairing_delegate.call_count_); 2926 EXPECT_EQ(0, pairing_delegate.call_count_);
2959 EXPECT_TRUE(device->IsConnecting()); 2927 EXPECT_TRUE(device->IsConnecting());
2960 2928
2961 // Run the loop to get the error.. 2929 // Run the loop to get the error..
2962 message_loop_.Run(); 2930 message_loop_.Run();
2963 2931
2964 EXPECT_EQ(0, callback_count_); 2932 EXPECT_EQ(0, callback_count_);
2965 EXPECT_EQ(1, error_callback_count_); 2933 EXPECT_EQ(1, error_callback_count_);
2966 2934
2967 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); 2935 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_);
2968 2936
2969 EXPECT_FALSE(device->IsConnected()); 2937 EXPECT_FALSE(device->IsConnected());
2970 EXPECT_FALSE(device->IsConnecting()); 2938 EXPECT_FALSE(device->IsConnecting());
2971 EXPECT_FALSE(device->IsPaired()); 2939 EXPECT_FALSE(device->IsPaired());
2972 } 2940 }
2973 2941
2974 TEST_F(BluetoothChromeOSTest, PairingFails) { 2942 TEST_F(BluetoothBlueZTest, PairingFails) {
2975 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2943 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2976 2944
2977 GetAdapter(); 2945 GetAdapter();
2978 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress); 2946 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress);
2979 2947
2980 // The vanishing device times out during pairing 2948 // The vanishing device times out during pairing
2981 BluetoothDevice* device = adapter_->GetDevice( 2949 BluetoothDevice* device = adapter_->GetDevice(
2982 bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress); 2950 bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress);
2983 ASSERT_TRUE(device != nullptr); 2951 ASSERT_TRUE(device != nullptr);
2984 ASSERT_FALSE(device->IsPaired()); 2952 ASSERT_FALSE(device->IsPaired());
2985 2953
2986 TestBluetoothAdapterObserver observer(adapter_); 2954 TestBluetoothAdapterObserver observer(adapter_);
2987 2955
2988 TestPairingDelegate pairing_delegate; 2956 TestPairingDelegate pairing_delegate;
2989 device->Connect(&pairing_delegate, GetCallback(), 2957 device->Connect(&pairing_delegate, GetCallback(),
2990 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2958 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2991 base::Unretained(this))); 2959 base::Unretained(this)));
2992 2960
2993 EXPECT_EQ(0, pairing_delegate.call_count_); 2961 EXPECT_EQ(0, pairing_delegate.call_count_);
2994 EXPECT_TRUE(device->IsConnecting()); 2962 EXPECT_TRUE(device->IsConnecting());
2995 2963
2996 // Run the loop to get the error.. 2964 // Run the loop to get the error..
2997 message_loop_.Run(); 2965 message_loop_.Run();
2998 2966
2999 EXPECT_EQ(0, callback_count_); 2967 EXPECT_EQ(0, callback_count_);
3000 EXPECT_EQ(1, error_callback_count_); 2968 EXPECT_EQ(1, error_callback_count_);
3001 2969
3002 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_TIMEOUT, last_connect_error_); 2970 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_TIMEOUT, last_connect_error_);
3003 2971
3004 EXPECT_FALSE(device->IsConnected()); 2972 EXPECT_FALSE(device->IsConnected());
3005 EXPECT_FALSE(device->IsConnecting()); 2973 EXPECT_FALSE(device->IsConnecting());
3006 EXPECT_FALSE(device->IsPaired()); 2974 EXPECT_FALSE(device->IsPaired());
3007 } 2975 }
3008 2976
3009 TEST_F(BluetoothChromeOSTest, PairingFailsAtConnection) { 2977 TEST_F(BluetoothBlueZTest, PairingFailsAtConnection) {
3010 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2978 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3011 2979
3012 GetAdapter(); 2980 GetAdapter();
3013 DiscoverDevices(); 2981 DiscoverDevices();
3014 2982
3015 // Everything seems to go according to plan with the unconnectable device; 2983 // Everything seems to go according to plan with the unconnectable device;
3016 // it pairs, but then you can't make connections to it after. 2984 // it pairs, but then you can't make connections to it after.
3017 BluetoothDevice* device = adapter_->GetDevice( 2985 BluetoothDevice* device = adapter_->GetDevice(
3018 bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); 2986 bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress);
3019 ASSERT_TRUE(device != nullptr); 2987 ASSERT_TRUE(device != nullptr);
3020 ASSERT_FALSE(device->IsPaired()); 2988 ASSERT_FALSE(device->IsPaired());
3021 2989
3022 TestBluetoothAdapterObserver observer(adapter_); 2990 TestBluetoothAdapterObserver observer(adapter_);
3023 2991
3024 TestPairingDelegate pairing_delegate; 2992 TestPairingDelegate pairing_delegate;
3025 device->Connect(&pairing_delegate, GetCallback(), 2993 device->Connect(&pairing_delegate, GetCallback(),
3026 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2994 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3027 base::Unretained(this))); 2995 base::Unretained(this)));
3028 2996
3029 EXPECT_EQ(0, pairing_delegate.call_count_); 2997 EXPECT_EQ(0, pairing_delegate.call_count_);
3030 EXPECT_TRUE(device->IsConnecting()); 2998 EXPECT_TRUE(device->IsConnecting());
3031 2999
3032 message_loop_.Run(); 3000 message_loop_.Run();
3033 3001
3034 EXPECT_EQ(0, callback_count_); 3002 EXPECT_EQ(0, callback_count_);
3035 EXPECT_EQ(1, error_callback_count_); 3003 EXPECT_EQ(1, error_callback_count_);
3036 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); 3004 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_);
3037 3005
3038 // Two changes for connecting, one for paired and one for trusted after 3006 // Two changes for connecting, one for paired and one for trusted after
3039 // pairing. The device should not be connected. 3007 // pairing. The device should not be connected.
3040 EXPECT_EQ(4, observer.device_changed_count()); 3008 EXPECT_EQ(4, observer.device_changed_count());
3041 EXPECT_EQ(device, observer.last_device()); 3009 EXPECT_EQ(device, observer.last_device());
3042 3010
3043 EXPECT_FALSE(device->IsConnected()); 3011 EXPECT_FALSE(device->IsConnected());
3044 EXPECT_FALSE(device->IsConnecting()); 3012 EXPECT_FALSE(device->IsConnecting());
3045 3013
3046 EXPECT_TRUE(device->IsPaired()); 3014 EXPECT_TRUE(device->IsPaired());
3047 3015
3048 // Make sure the trusted property has been set to true still (since pairing 3016 // Make sure the trusted property has been set to true still (since pairing
3049 // worked). 3017 // worked).
3050 bluez::FakeBluetoothDeviceClient::Properties* properties = 3018 bluez::FakeBluetoothDeviceClient::Properties* properties =
3051 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3019 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3052 bluez::FakeBluetoothDeviceClient::kUnconnectableDevicePath)); 3020 bluez::FakeBluetoothDeviceClient::kUnconnectableDevicePath));
3053 EXPECT_TRUE(properties->trusted.value()); 3021 EXPECT_TRUE(properties->trusted.value());
3054 } 3022 }
3055 3023
3056 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPinCode) { 3024 TEST_F(BluetoothBlueZTest, PairingRejectedAtPinCode) {
3057 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3025 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3058 3026
3059 GetAdapter(); 3027 GetAdapter();
3060 DiscoverDevices(); 3028 DiscoverDevices();
3061 3029
3062 // Reject the pairing after we receive a request for the PIN code. 3030 // Reject the pairing after we receive a request for the PIN code.
3063 BluetoothDevice* device = adapter_->GetDevice( 3031 BluetoothDevice* device = adapter_->GetDevice(
3064 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); 3032 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress);
3065 ASSERT_TRUE(device != nullptr); 3033 ASSERT_TRUE(device != nullptr);
3066 ASSERT_FALSE(device->IsPaired()); 3034 ASSERT_FALSE(device->IsPaired());
3067 3035
3068 TestBluetoothAdapterObserver observer(adapter_); 3036 TestBluetoothAdapterObserver observer(adapter_);
3069 3037
3070 TestPairingDelegate pairing_delegate; 3038 TestPairingDelegate pairing_delegate;
3071 device->Connect(&pairing_delegate, GetCallback(), 3039 device->Connect(&pairing_delegate, GetCallback(),
3072 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3040 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3073 base::Unretained(this))); 3041 base::Unretained(this)));
3074 3042
3075 EXPECT_EQ(1, pairing_delegate.call_count_); 3043 EXPECT_EQ(1, pairing_delegate.call_count_);
3076 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); 3044 EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
3077 EXPECT_TRUE(device->IsConnecting()); 3045 EXPECT_TRUE(device->IsConnecting());
3078 3046
3079 // Reject the pairing. 3047 // Reject the pairing.
3080 device->RejectPairing(); 3048 device->RejectPairing();
3081 message_loop_.Run(); 3049 message_loop_.Run();
3082 3050
3083 EXPECT_EQ(0, callback_count_); 3051 EXPECT_EQ(0, callback_count_);
3084 EXPECT_EQ(1, error_callback_count_); 3052 EXPECT_EQ(1, error_callback_count_);
3085 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); 3053 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_);
3086 3054
3087 // Should be no changes except connecting going true and false. 3055 // Should be no changes except connecting going true and false.
3088 EXPECT_EQ(2, observer.device_changed_count()); 3056 EXPECT_EQ(2, observer.device_changed_count());
3089 EXPECT_FALSE(device->IsConnected()); 3057 EXPECT_FALSE(device->IsConnected());
3090 EXPECT_FALSE(device->IsConnecting()); 3058 EXPECT_FALSE(device->IsConnecting());
3091 EXPECT_FALSE(device->IsPaired()); 3059 EXPECT_FALSE(device->IsPaired());
3092 } 3060 }
3093 3061
3094 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPinCode) { 3062 TEST_F(BluetoothBlueZTest, PairingCancelledAtPinCode) {
3095 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3063 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3096 3064
3097 GetAdapter(); 3065 GetAdapter();
3098 DiscoverDevices(); 3066 DiscoverDevices();
3099 3067
3100 // Cancel the pairing after we receive a request for the PIN code. 3068 // Cancel the pairing after we receive a request for the PIN code.
3101 BluetoothDevice* device = adapter_->GetDevice( 3069 BluetoothDevice* device = adapter_->GetDevice(
3102 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); 3070 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress);
3103 ASSERT_TRUE(device != nullptr); 3071 ASSERT_TRUE(device != nullptr);
3104 ASSERT_FALSE(device->IsPaired()); 3072 ASSERT_FALSE(device->IsPaired());
3105 3073
3106 TestBluetoothAdapterObserver observer(adapter_); 3074 TestBluetoothAdapterObserver observer(adapter_);
3107 3075
3108 TestPairingDelegate pairing_delegate; 3076 TestPairingDelegate pairing_delegate;
3109 device->Connect(&pairing_delegate, GetCallback(), 3077 device->Connect(&pairing_delegate, GetCallback(),
3110 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3078 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3111 base::Unretained(this))); 3079 base::Unretained(this)));
3112 3080
3113 EXPECT_EQ(1, pairing_delegate.call_count_); 3081 EXPECT_EQ(1, pairing_delegate.call_count_);
3114 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); 3082 EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
3115 EXPECT_TRUE(device->IsConnecting()); 3083 EXPECT_TRUE(device->IsConnecting());
3116 3084
3117 // Cancel the pairing. 3085 // Cancel the pairing.
3118 device->CancelPairing(); 3086 device->CancelPairing();
3119 message_loop_.Run(); 3087 message_loop_.Run();
3120 3088
3121 EXPECT_EQ(0, callback_count_); 3089 EXPECT_EQ(0, callback_count_);
3122 EXPECT_EQ(1, error_callback_count_); 3090 EXPECT_EQ(1, error_callback_count_);
3123 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); 3091 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
3124 3092
3125 // Should be no changes except connecting going true and false. 3093 // Should be no changes except connecting going true and false.
3126 EXPECT_EQ(2, observer.device_changed_count()); 3094 EXPECT_EQ(2, observer.device_changed_count());
3127 EXPECT_FALSE(device->IsConnected()); 3095 EXPECT_FALSE(device->IsConnected());
3128 EXPECT_FALSE(device->IsConnecting()); 3096 EXPECT_FALSE(device->IsConnecting());
3129 EXPECT_FALSE(device->IsPaired()); 3097 EXPECT_FALSE(device->IsPaired());
3130 } 3098 }
3131 3099
3132 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPasskey) { 3100 TEST_F(BluetoothBlueZTest, PairingRejectedAtPasskey) {
3133 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3101 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3134 3102
3135 GetAdapter(); 3103 GetAdapter();
3136 DiscoverDevices(); 3104 DiscoverDevices();
3137 3105
3138 // Reject the pairing after we receive a request for the passkey. 3106 // Reject the pairing after we receive a request for the passkey.
3139 BluetoothDevice* device = adapter_->GetDevice( 3107 BluetoothDevice* device = adapter_->GetDevice(
3140 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); 3108 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress);
3141 ASSERT_TRUE(device != nullptr); 3109 ASSERT_TRUE(device != nullptr);
3142 ASSERT_FALSE(device->IsPaired()); 3110 ASSERT_FALSE(device->IsPaired());
3143 3111
3144 TestBluetoothAdapterObserver observer(adapter_); 3112 TestBluetoothAdapterObserver observer(adapter_);
3145 3113
3146 TestPairingDelegate pairing_delegate; 3114 TestPairingDelegate pairing_delegate;
3147 device->Connect(&pairing_delegate, GetCallback(), 3115 device->Connect(&pairing_delegate, GetCallback(),
3148 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3116 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3149 base::Unretained(this))); 3117 base::Unretained(this)));
3150 3118
3151 EXPECT_EQ(1, pairing_delegate.call_count_); 3119 EXPECT_EQ(1, pairing_delegate.call_count_);
3152 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 3120 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
3153 EXPECT_TRUE(device->IsConnecting()); 3121 EXPECT_TRUE(device->IsConnecting());
3154 3122
3155 // Reject the pairing. 3123 // Reject the pairing.
3156 device->RejectPairing(); 3124 device->RejectPairing();
3157 message_loop_.Run(); 3125 message_loop_.Run();
3158 3126
3159 EXPECT_EQ(0, callback_count_); 3127 EXPECT_EQ(0, callback_count_);
3160 EXPECT_EQ(1, error_callback_count_); 3128 EXPECT_EQ(1, error_callback_count_);
3161 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); 3129 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_);
3162 3130
3163 // Should be no changes except connecting going true and false. 3131 // Should be no changes except connecting going true and false.
3164 EXPECT_EQ(2, observer.device_changed_count()); 3132 EXPECT_EQ(2, observer.device_changed_count());
3165 EXPECT_FALSE(device->IsConnected()); 3133 EXPECT_FALSE(device->IsConnected());
3166 EXPECT_FALSE(device->IsConnecting()); 3134 EXPECT_FALSE(device->IsConnecting());
3167 EXPECT_FALSE(device->IsPaired()); 3135 EXPECT_FALSE(device->IsPaired());
3168 } 3136 }
3169 3137
3170 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPasskey) { 3138 TEST_F(BluetoothBlueZTest, PairingCancelledAtPasskey) {
3171 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3139 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3172 3140
3173 GetAdapter(); 3141 GetAdapter();
3174 DiscoverDevices(); 3142 DiscoverDevices();
3175 3143
3176 // Cancel the pairing after we receive a request for the passkey. 3144 // Cancel the pairing after we receive a request for the passkey.
3177 BluetoothDevice* device = adapter_->GetDevice( 3145 BluetoothDevice* device = adapter_->GetDevice(
3178 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); 3146 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress);
3179 ASSERT_TRUE(device != nullptr); 3147 ASSERT_TRUE(device != nullptr);
3180 ASSERT_FALSE(device->IsPaired()); 3148 ASSERT_FALSE(device->IsPaired());
3181 3149
3182 TestBluetoothAdapterObserver observer(adapter_); 3150 TestBluetoothAdapterObserver observer(adapter_);
3183 3151
3184 TestPairingDelegate pairing_delegate; 3152 TestPairingDelegate pairing_delegate;
3185 device->Connect(&pairing_delegate, GetCallback(), 3153 device->Connect(&pairing_delegate, GetCallback(),
3186 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3154 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3187 base::Unretained(this))); 3155 base::Unretained(this)));
3188 3156
3189 EXPECT_EQ(1, pairing_delegate.call_count_); 3157 EXPECT_EQ(1, pairing_delegate.call_count_);
3190 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 3158 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
3191 EXPECT_TRUE(device->IsConnecting()); 3159 EXPECT_TRUE(device->IsConnecting());
3192 3160
3193 // Cancel the pairing. 3161 // Cancel the pairing.
3194 device->CancelPairing(); 3162 device->CancelPairing();
3195 message_loop_.Run(); 3163 message_loop_.Run();
3196 3164
3197 EXPECT_EQ(0, callback_count_); 3165 EXPECT_EQ(0, callback_count_);
3198 EXPECT_EQ(1, error_callback_count_); 3166 EXPECT_EQ(1, error_callback_count_);
3199 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); 3167 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
3200 3168
3201 // Should be no changes except connecting going true and false. 3169 // Should be no changes except connecting going true and false.
3202 EXPECT_EQ(2, observer.device_changed_count()); 3170 EXPECT_EQ(2, observer.device_changed_count());
3203 EXPECT_FALSE(device->IsConnected()); 3171 EXPECT_FALSE(device->IsConnected());
3204 EXPECT_FALSE(device->IsConnecting()); 3172 EXPECT_FALSE(device->IsConnecting());
3205 EXPECT_FALSE(device->IsPaired()); 3173 EXPECT_FALSE(device->IsPaired());
3206 } 3174 }
3207 3175
3208 TEST_F(BluetoothChromeOSTest, PairingRejectedAtConfirmation) { 3176 TEST_F(BluetoothBlueZTest, PairingRejectedAtConfirmation) {
3209 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3177 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3210 3178
3211 GetAdapter(); 3179 GetAdapter();
3212 DiscoverDevices(); 3180 DiscoverDevices();
3213 3181
3214 // Reject the pairing after we receive a request for passkey confirmation. 3182 // Reject the pairing after we receive a request for passkey confirmation.
3215 BluetoothDevice* device = adapter_->GetDevice( 3183 BluetoothDevice* device = adapter_->GetDevice(
3216 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); 3184 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress);
3217 ASSERT_TRUE(device != nullptr); 3185 ASSERT_TRUE(device != nullptr);
3218 ASSERT_FALSE(device->IsPaired()); 3186 ASSERT_FALSE(device->IsPaired());
3219 3187
3220 TestBluetoothAdapterObserver observer(adapter_); 3188 TestBluetoothAdapterObserver observer(adapter_);
3221 3189
3222 TestPairingDelegate pairing_delegate; 3190 TestPairingDelegate pairing_delegate;
3223 device->Connect(&pairing_delegate, GetCallback(), 3191 device->Connect(&pairing_delegate, GetCallback(),
3224 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3192 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3225 base::Unretained(this))); 3193 base::Unretained(this)));
3226 3194
3227 EXPECT_EQ(1, pairing_delegate.call_count_); 3195 EXPECT_EQ(1, pairing_delegate.call_count_);
3228 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 3196 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
3229 EXPECT_TRUE(device->IsConnecting()); 3197 EXPECT_TRUE(device->IsConnecting());
3230 3198
3231 // Reject the pairing. 3199 // Reject the pairing.
3232 device->RejectPairing(); 3200 device->RejectPairing();
3233 message_loop_.Run(); 3201 message_loop_.Run();
3234 3202
3235 EXPECT_EQ(0, callback_count_); 3203 EXPECT_EQ(0, callback_count_);
3236 EXPECT_EQ(1, error_callback_count_); 3204 EXPECT_EQ(1, error_callback_count_);
3237 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); 3205 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_);
3238 3206
3239 // Should be no changes except connecting going true and false. 3207 // Should be no changes except connecting going true and false.
3240 EXPECT_EQ(2, observer.device_changed_count()); 3208 EXPECT_EQ(2, observer.device_changed_count());
3241 EXPECT_FALSE(device->IsConnected()); 3209 EXPECT_FALSE(device->IsConnected());
3242 EXPECT_FALSE(device->IsConnecting()); 3210 EXPECT_FALSE(device->IsConnecting());
3243 EXPECT_FALSE(device->IsPaired()); 3211 EXPECT_FALSE(device->IsPaired());
3244 } 3212 }
3245 3213
3246 TEST_F(BluetoothChromeOSTest, PairingCancelledAtConfirmation) { 3214 TEST_F(BluetoothBlueZTest, PairingCancelledAtConfirmation) {
3247 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3215 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3248 3216
3249 GetAdapter(); 3217 GetAdapter();
3250 DiscoverDevices(); 3218 DiscoverDevices();
3251 3219
3252 // Cancel the pairing after we receive a request for the passkey. 3220 // Cancel the pairing after we receive a request for the passkey.
3253 BluetoothDevice* device = adapter_->GetDevice( 3221 BluetoothDevice* device = adapter_->GetDevice(
3254 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); 3222 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress);
3255 ASSERT_TRUE(device != nullptr); 3223 ASSERT_TRUE(device != nullptr);
3256 ASSERT_FALSE(device->IsPaired()); 3224 ASSERT_FALSE(device->IsPaired());
3257 3225
3258 TestBluetoothAdapterObserver observer(adapter_); 3226 TestBluetoothAdapterObserver observer(adapter_);
3259 3227
3260 TestPairingDelegate pairing_delegate; 3228 TestPairingDelegate pairing_delegate;
3261 device->Connect(&pairing_delegate, GetCallback(), 3229 device->Connect(&pairing_delegate, GetCallback(),
3262 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3230 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3263 base::Unretained(this))); 3231 base::Unretained(this)));
3264 3232
3265 EXPECT_EQ(1, pairing_delegate.call_count_); 3233 EXPECT_EQ(1, pairing_delegate.call_count_);
3266 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 3234 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
3267 EXPECT_TRUE(device->IsConnecting()); 3235 EXPECT_TRUE(device->IsConnecting());
3268 3236
3269 // Cancel the pairing. 3237 // Cancel the pairing.
3270 device->CancelPairing(); 3238 device->CancelPairing();
3271 message_loop_.Run(); 3239 message_loop_.Run();
3272 3240
3273 EXPECT_EQ(0, callback_count_); 3241 EXPECT_EQ(0, callback_count_);
3274 EXPECT_EQ(1, error_callback_count_); 3242 EXPECT_EQ(1, error_callback_count_);
3275 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); 3243 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
3276 3244
3277 // Should be no changes except connecting going true and false. 3245 // Should be no changes except connecting going true and false.
3278 EXPECT_EQ(2, observer.device_changed_count()); 3246 EXPECT_EQ(2, observer.device_changed_count());
3279 EXPECT_FALSE(device->IsConnected()); 3247 EXPECT_FALSE(device->IsConnected());
3280 EXPECT_FALSE(device->IsConnecting()); 3248 EXPECT_FALSE(device->IsConnecting());
3281 EXPECT_FALSE(device->IsPaired()); 3249 EXPECT_FALSE(device->IsPaired());
3282 } 3250 }
3283 3251
3284 TEST_F(BluetoothChromeOSTest, PairingCancelledInFlight) { 3252 TEST_F(BluetoothBlueZTest, PairingCancelledInFlight) {
3285 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3253 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3286 3254
3287 GetAdapter(); 3255 GetAdapter();
3288 DiscoverDevices(); 3256 DiscoverDevices();
3289 3257
3290 // Cancel the pairing while we're waiting for the remote host. 3258 // Cancel the pairing while we're waiting for the remote host.
3291 BluetoothDevice* device = adapter_->GetDevice( 3259 BluetoothDevice* device = adapter_->GetDevice(
3292 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); 3260 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress);
3293 ASSERT_TRUE(device != nullptr); 3261 ASSERT_TRUE(device != nullptr);
3294 ASSERT_FALSE(device->IsPaired()); 3262 ASSERT_FALSE(device->IsPaired());
3295 3263
3296 TestBluetoothAdapterObserver observer(adapter_); 3264 TestBluetoothAdapterObserver observer(adapter_);
3297 3265
3298 TestPairingDelegate pairing_delegate; 3266 TestPairingDelegate pairing_delegate;
3299 device->Connect(&pairing_delegate, GetCallback(), 3267 device->Connect(&pairing_delegate, GetCallback(),
3300 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3268 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3301 base::Unretained(this))); 3269 base::Unretained(this)));
3302 3270
3303 EXPECT_EQ(0, pairing_delegate.call_count_); 3271 EXPECT_EQ(0, pairing_delegate.call_count_);
3304 EXPECT_TRUE(device->IsConnecting()); 3272 EXPECT_TRUE(device->IsConnecting());
3305 3273
3306 // Cancel the pairing. 3274 // Cancel the pairing.
3307 device->CancelPairing(); 3275 device->CancelPairing();
3308 message_loop_.Run(); 3276 message_loop_.Run();
3309 3277
3310 EXPECT_EQ(0, callback_count_); 3278 EXPECT_EQ(0, callback_count_);
3311 EXPECT_EQ(1, error_callback_count_); 3279 EXPECT_EQ(1, error_callback_count_);
3312 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); 3280 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
3313 3281
3314 // Should be no changes except connecting going true and false. 3282 // Should be no changes except connecting going true and false.
3315 EXPECT_EQ(2, observer.device_changed_count()); 3283 EXPECT_EQ(2, observer.device_changed_count());
3316 EXPECT_FALSE(device->IsConnected()); 3284 EXPECT_FALSE(device->IsConnected());
3317 EXPECT_FALSE(device->IsConnecting()); 3285 EXPECT_FALSE(device->IsConnecting());
3318 EXPECT_FALSE(device->IsPaired()); 3286 EXPECT_FALSE(device->IsPaired());
3319 } 3287 }
3320 3288
3321 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPinCode) { 3289 TEST_F(BluetoothBlueZTest, IncomingPairRequestPinCode) {
3322 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3290 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3323 3291
3324 GetAdapter(); 3292 GetAdapter();
3325 3293
3326 TestPairingDelegate pairing_delegate; 3294 TestPairingDelegate pairing_delegate;
3327 adapter_->AddPairingDelegate( 3295 adapter_->AddPairingDelegate(
3328 &pairing_delegate, 3296 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3329 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3330 3297
3331 // Requires that we provide a PIN code. 3298 // Requires that we provide a PIN code.
3332 fake_bluetooth_device_client_->CreateDevice( 3299 fake_bluetooth_device_client_->CreateDevice(
3333 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3300 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3334 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); 3301 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath));
3335 BluetoothDevice* device = adapter_->GetDevice( 3302 BluetoothDevice* device = adapter_->GetDevice(
3336 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); 3303 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress);
3337 ASSERT_TRUE(device != nullptr); 3304 ASSERT_TRUE(device != nullptr);
3338 ASSERT_FALSE(device->IsPaired()); 3305 ASSERT_FALSE(device->IsPaired());
3339 3306
3340 TestBluetoothAdapterObserver observer(adapter_); 3307 TestBluetoothAdapterObserver observer(adapter_);
3341 3308
3342 fake_bluetooth_device_client_->SimulatePairing( 3309 fake_bluetooth_device_client_->SimulatePairing(
3343 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), 3310 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath),
3344 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3311 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3345 base::Unretained(this))); 3312 base::Unretained(this)));
3346 3313
3347 EXPECT_EQ(1, pairing_delegate.call_count_); 3314 EXPECT_EQ(1, pairing_delegate.call_count_);
3348 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); 3315 EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
3349 3316
3350 // Set the PIN. 3317 // Set the PIN.
3351 device->SetPinCode("1234"); 3318 device->SetPinCode("1234");
3352 message_loop_.Run(); 3319 message_loop_.Run();
3353 3320
3354 EXPECT_EQ(1, callback_count_); 3321 EXPECT_EQ(1, callback_count_);
3355 EXPECT_EQ(0, error_callback_count_); 3322 EXPECT_EQ(0, error_callback_count_);
3356 3323
3357 // One change for paired, and one for trusted. 3324 // One change for paired, and one for trusted.
3358 EXPECT_EQ(2, observer.device_changed_count()); 3325 EXPECT_EQ(2, observer.device_changed_count());
3359 EXPECT_EQ(device, observer.last_device()); 3326 EXPECT_EQ(device, observer.last_device());
3360 3327
3361 EXPECT_TRUE(device->IsPaired()); 3328 EXPECT_TRUE(device->IsPaired());
3362 3329
3363 // Make sure the trusted property has been set to true. 3330 // Make sure the trusted property has been set to true.
3364 bluez::FakeBluetoothDeviceClient::Properties* properties = 3331 bluez::FakeBluetoothDeviceClient::Properties* properties =
3365 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3332 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3366 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); 3333 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath));
3367 ASSERT_TRUE(properties->trusted.value()); 3334 ASSERT_TRUE(properties->trusted.value());
3368 3335
3369 // No pairing context should remain on the device. 3336 // No pairing context should remain on the device.
3370 BluetoothDeviceChromeOS* device_chromeos = 3337 BluetoothDeviceBlueZ* device_bluez =
3371 static_cast<BluetoothDeviceChromeOS*>(device); 3338 static_cast<BluetoothDeviceBlueZ*>(device);
3372 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3339 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3373 } 3340 }
3374 3341
3375 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskey) { 3342 TEST_F(BluetoothBlueZTest, IncomingPairConfirmPasskey) {
3376 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3343 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3377 3344
3378 GetAdapter(); 3345 GetAdapter();
3379 3346
3380 TestPairingDelegate pairing_delegate; 3347 TestPairingDelegate pairing_delegate;
3381 adapter_->AddPairingDelegate( 3348 adapter_->AddPairingDelegate(
3382 &pairing_delegate, 3349 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3383 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3384 3350
3385 // Requests that we confirm a displayed passkey. 3351 // Requests that we confirm a displayed passkey.
3386 fake_bluetooth_device_client_->CreateDevice( 3352 fake_bluetooth_device_client_->CreateDevice(
3387 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3353 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3388 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); 3354 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath));
3389 BluetoothDevice* device = adapter_->GetDevice( 3355 BluetoothDevice* device = adapter_->GetDevice(
3390 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); 3356 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress);
3391 ASSERT_TRUE(device != nullptr); 3357 ASSERT_TRUE(device != nullptr);
3392 ASSERT_FALSE(device->IsPaired()); 3358 ASSERT_FALSE(device->IsPaired());
3393 3359
3394 TestBluetoothAdapterObserver observer(adapter_); 3360 TestBluetoothAdapterObserver observer(adapter_);
3395 3361
3396 fake_bluetooth_device_client_->SimulatePairing( 3362 fake_bluetooth_device_client_->SimulatePairing(
3397 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), 3363 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath),
3398 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3364 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3399 base::Unretained(this))); 3365 base::Unretained(this)));
3400 3366
3401 EXPECT_EQ(1, pairing_delegate.call_count_); 3367 EXPECT_EQ(1, pairing_delegate.call_count_);
3402 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 3368 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
3403 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); 3369 EXPECT_EQ(123456U, pairing_delegate.last_passkey_);
3404 3370
3405 // Confirm the passkey. 3371 // Confirm the passkey.
3406 device->ConfirmPairing(); 3372 device->ConfirmPairing();
3407 message_loop_.Run(); 3373 message_loop_.Run();
3408 3374
3409 EXPECT_EQ(1, callback_count_); 3375 EXPECT_EQ(1, callback_count_);
3410 EXPECT_EQ(0, error_callback_count_); 3376 EXPECT_EQ(0, error_callback_count_);
3411 3377
3412 // One change for paired, and one for trusted. 3378 // One change for paired, and one for trusted.
3413 EXPECT_EQ(2, observer.device_changed_count()); 3379 EXPECT_EQ(2, observer.device_changed_count());
3414 EXPECT_EQ(device, observer.last_device()); 3380 EXPECT_EQ(device, observer.last_device());
3415 3381
3416 EXPECT_TRUE(device->IsPaired()); 3382 EXPECT_TRUE(device->IsPaired());
3417 3383
3418 // Make sure the trusted property has been set to true. 3384 // Make sure the trusted property has been set to true.
3419 bluez::FakeBluetoothDeviceClient::Properties* properties = 3385 bluez::FakeBluetoothDeviceClient::Properties* properties =
3420 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3386 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3421 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); 3387 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath));
3422 ASSERT_TRUE(properties->trusted.value()); 3388 ASSERT_TRUE(properties->trusted.value());
3423 3389
3424 // No pairing context should remain on the device. 3390 // No pairing context should remain on the device.
3425 BluetoothDeviceChromeOS* device_chromeos = 3391 BluetoothDeviceBlueZ* device_bluez =
3426 static_cast<BluetoothDeviceChromeOS*>(device); 3392 static_cast<BluetoothDeviceBlueZ*>(device);
3427 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3393 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3428 } 3394 }
3429 3395
3430 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskey) { 3396 TEST_F(BluetoothBlueZTest, IncomingPairRequestPasskey) {
3431 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3397 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3432 3398
3433 GetAdapter(); 3399 GetAdapter();
3434 3400
3435 TestPairingDelegate pairing_delegate; 3401 TestPairingDelegate pairing_delegate;
3436 adapter_->AddPairingDelegate( 3402 adapter_->AddPairingDelegate(
3437 &pairing_delegate, 3403 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3438 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3439 3404
3440 // Requests that we provide a Passkey. 3405 // Requests that we provide a Passkey.
3441 fake_bluetooth_device_client_->CreateDevice( 3406 fake_bluetooth_device_client_->CreateDevice(
3442 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3407 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3443 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); 3408 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath));
3444 BluetoothDevice* device = adapter_->GetDevice( 3409 BluetoothDevice* device = adapter_->GetDevice(
3445 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); 3410 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress);
3446 ASSERT_TRUE(device != nullptr); 3411 ASSERT_TRUE(device != nullptr);
3447 ASSERT_FALSE(device->IsPaired()); 3412 ASSERT_FALSE(device->IsPaired());
3448 3413
3449 TestBluetoothAdapterObserver observer(adapter_); 3414 TestBluetoothAdapterObserver observer(adapter_);
3450 3415
3451 fake_bluetooth_device_client_->SimulatePairing( 3416 fake_bluetooth_device_client_->SimulatePairing(
3452 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), 3417 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath),
3453 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3418 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3454 base::Unretained(this))); 3419 base::Unretained(this)));
3455 3420
3456 EXPECT_EQ(1, pairing_delegate.call_count_); 3421 EXPECT_EQ(1, pairing_delegate.call_count_);
3457 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 3422 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
3458 3423
3459 // Set the Passkey. 3424 // Set the Passkey.
3460 device->SetPasskey(1234); 3425 device->SetPasskey(1234);
3461 message_loop_.Run(); 3426 message_loop_.Run();
3462 3427
3463 EXPECT_EQ(1, callback_count_); 3428 EXPECT_EQ(1, callback_count_);
3464 EXPECT_EQ(0, error_callback_count_); 3429 EXPECT_EQ(0, error_callback_count_);
3465 3430
3466 // One change for paired, and one for trusted. 3431 // One change for paired, and one for trusted.
3467 EXPECT_EQ(2, observer.device_changed_count()); 3432 EXPECT_EQ(2, observer.device_changed_count());
3468 EXPECT_EQ(device, observer.last_device()); 3433 EXPECT_EQ(device, observer.last_device());
3469 3434
3470 EXPECT_TRUE(device->IsPaired()); 3435 EXPECT_TRUE(device->IsPaired());
3471 3436
3472 // Make sure the trusted property has been set to true. 3437 // Make sure the trusted property has been set to true.
3473 bluez::FakeBluetoothDeviceClient::Properties* properties = 3438 bluez::FakeBluetoothDeviceClient::Properties* properties =
3474 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3439 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3475 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); 3440 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath));
3476 ASSERT_TRUE(properties->trusted.value()); 3441 ASSERT_TRUE(properties->trusted.value());
3477 3442
3478 // No pairing context should remain on the device. 3443 // No pairing context should remain on the device.
3479 BluetoothDeviceChromeOS* device_chromeos = 3444 BluetoothDeviceBlueZ* device_bluez =
3480 static_cast<BluetoothDeviceChromeOS*>(device); 3445 static_cast<BluetoothDeviceBlueZ*>(device);
3481 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3446 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3482 } 3447 }
3483 3448
3484 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorks) { 3449 TEST_F(BluetoothBlueZTest, IncomingPairJustWorks) {
3485 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3450 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3486 3451
3487 GetAdapter(); 3452 GetAdapter();
3488 3453
3489 TestPairingDelegate pairing_delegate; 3454 TestPairingDelegate pairing_delegate;
3490 adapter_->AddPairingDelegate( 3455 adapter_->AddPairingDelegate(
3491 &pairing_delegate, 3456 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3492 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3493 3457
3494 // Uses just-works pairing so, sinec this an incoming pairing, require 3458 // Uses just-works pairing so, sinec this an incoming pairing, require
3495 // authorization from the user. 3459 // authorization from the user.
3496 fake_bluetooth_device_client_->CreateDevice( 3460 fake_bluetooth_device_client_->CreateDevice(
3497 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3461 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3498 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); 3462 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath));
3499 BluetoothDevice* device = 3463 BluetoothDevice* device =
3500 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); 3464 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress);
3501 ASSERT_TRUE(device != nullptr); 3465 ASSERT_TRUE(device != nullptr);
3502 ASSERT_FALSE(device->IsPaired()); 3466 ASSERT_FALSE(device->IsPaired());
3503 3467
3504 TestBluetoothAdapterObserver observer(adapter_); 3468 TestBluetoothAdapterObserver observer(adapter_);
3505 3469
3506 fake_bluetooth_device_client_->SimulatePairing( 3470 fake_bluetooth_device_client_->SimulatePairing(
3507 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, 3471 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true,
3508 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3472 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3509 base::Unretained(this))); 3473 base::Unretained(this)));
3510 3474
3511 EXPECT_EQ(1, pairing_delegate.call_count_); 3475 EXPECT_EQ(1, pairing_delegate.call_count_);
3512 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_); 3476 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_);
3513 3477
3514 // Confirm the pairing. 3478 // Confirm the pairing.
3515 device->ConfirmPairing(); 3479 device->ConfirmPairing();
3516 message_loop_.Run(); 3480 message_loop_.Run();
3517 3481
3518 EXPECT_EQ(1, callback_count_); 3482 EXPECT_EQ(1, callback_count_);
3519 EXPECT_EQ(0, error_callback_count_); 3483 EXPECT_EQ(0, error_callback_count_);
3520 3484
3521 // One change for paired, and one for trusted. 3485 // One change for paired, and one for trusted.
3522 EXPECT_EQ(2, observer.device_changed_count()); 3486 EXPECT_EQ(2, observer.device_changed_count());
3523 EXPECT_EQ(device, observer.last_device()); 3487 EXPECT_EQ(device, observer.last_device());
3524 3488
3525 EXPECT_TRUE(device->IsPaired()); 3489 EXPECT_TRUE(device->IsPaired());
3526 3490
3527 // Make sure the trusted property has been set to true. 3491 // Make sure the trusted property has been set to true.
3528 bluez::FakeBluetoothDeviceClient::Properties* properties = 3492 bluez::FakeBluetoothDeviceClient::Properties* properties =
3529 fake_bluetooth_device_client_->GetProperties( 3493 fake_bluetooth_device_client_->GetProperties(
3530 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); 3494 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath));
3531 ASSERT_TRUE(properties->trusted.value()); 3495 ASSERT_TRUE(properties->trusted.value());
3532 3496
3533 // No pairing context should remain on the device. 3497 // No pairing context should remain on the device.
3534 BluetoothDeviceChromeOS* device_chromeos = 3498 BluetoothDeviceBlueZ* device_bluez =
3535 static_cast<BluetoothDeviceChromeOS*>(device); 3499 static_cast<BluetoothDeviceBlueZ*>(device);
3536 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3500 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3537 } 3501 }
3538 3502
3539 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPinCodeWithoutDelegate) { 3503 TEST_F(BluetoothBlueZTest, IncomingPairRequestPinCodeWithoutDelegate) {
3540 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3504 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3541 3505
3542 GetAdapter(); 3506 GetAdapter();
3543 3507
3544 // Requires that we provide a PIN Code, without a pairing delegate, 3508 // Requires that we provide a PIN Code, without a pairing delegate,
3545 // that will be rejected. 3509 // that will be rejected.
3546 fake_bluetooth_device_client_->CreateDevice( 3510 fake_bluetooth_device_client_->CreateDevice(
3547 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3511 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3548 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); 3512 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath));
3549 BluetoothDevice* device = adapter_->GetDevice( 3513 BluetoothDevice* device = adapter_->GetDevice(
3550 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); 3514 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress);
3551 ASSERT_TRUE(device != nullptr); 3515 ASSERT_TRUE(device != nullptr);
3552 ASSERT_FALSE(device->IsPaired()); 3516 ASSERT_FALSE(device->IsPaired());
3553 3517
3554 TestBluetoothAdapterObserver observer(adapter_); 3518 TestBluetoothAdapterObserver observer(adapter_);
3555 3519
3556 fake_bluetooth_device_client_->SimulatePairing( 3520 fake_bluetooth_device_client_->SimulatePairing(
3557 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), 3521 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath),
3558 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3522 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3559 base::Unretained(this))); 3523 base::Unretained(this)));
3560 3524
3561 message_loop_.Run(); 3525 message_loop_.Run();
3562 3526
3563 EXPECT_EQ(0, callback_count_); 3527 EXPECT_EQ(0, callback_count_);
3564 EXPECT_EQ(1, error_callback_count_); 3528 EXPECT_EQ(1, error_callback_count_);
3565 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); 3529 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_);
3566 3530
3567 // No changes should be observer. 3531 // No changes should be observer.
3568 EXPECT_EQ(0, observer.device_changed_count()); 3532 EXPECT_EQ(0, observer.device_changed_count());
3569 3533
3570 EXPECT_FALSE(device->IsPaired()); 3534 EXPECT_FALSE(device->IsPaired());
3571 3535
3572 // No pairing context should remain on the device. 3536 // No pairing context should remain on the device.
3573 BluetoothDeviceChromeOS* device_chromeos = 3537 BluetoothDeviceBlueZ* device_bluez =
3574 static_cast<BluetoothDeviceChromeOS*>(device); 3538 static_cast<BluetoothDeviceBlueZ*>(device);
3575 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3539 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3576 } 3540 }
3577 3541
3578 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskeyWithoutDelegate) { 3542 TEST_F(BluetoothBlueZTest, IncomingPairConfirmPasskeyWithoutDelegate) {
3579 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3543 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3580 3544
3581 GetAdapter(); 3545 GetAdapter();
3582 3546
3583 // Requests that we confirm a displayed passkey, without a pairing delegate, 3547 // Requests that we confirm a displayed passkey, without a pairing delegate,
3584 // that will be rejected. 3548 // that will be rejected.
3585 fake_bluetooth_device_client_->CreateDevice( 3549 fake_bluetooth_device_client_->CreateDevice(
3586 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3550 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3587 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); 3551 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath));
3588 BluetoothDevice* device = adapter_->GetDevice( 3552 BluetoothDevice* device = adapter_->GetDevice(
3589 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); 3553 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress);
3590 ASSERT_TRUE(device != nullptr); 3554 ASSERT_TRUE(device != nullptr);
3591 ASSERT_FALSE(device->IsPaired()); 3555 ASSERT_FALSE(device->IsPaired());
3592 3556
3593 TestBluetoothAdapterObserver observer(adapter_); 3557 TestBluetoothAdapterObserver observer(adapter_);
3594 3558
3595 fake_bluetooth_device_client_->SimulatePairing( 3559 fake_bluetooth_device_client_->SimulatePairing(
3596 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), 3560 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath),
3597 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3561 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3598 base::Unretained(this))); 3562 base::Unretained(this)));
3599 3563
3600 message_loop_.Run(); 3564 message_loop_.Run();
3601 3565
3602 EXPECT_EQ(0, callback_count_); 3566 EXPECT_EQ(0, callback_count_);
3603 EXPECT_EQ(1, error_callback_count_); 3567 EXPECT_EQ(1, error_callback_count_);
3604 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); 3568 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_);
3605 3569
3606 // No changes should be observer. 3570 // No changes should be observer.
3607 EXPECT_EQ(0, observer.device_changed_count()); 3571 EXPECT_EQ(0, observer.device_changed_count());
3608 3572
3609 EXPECT_FALSE(device->IsPaired()); 3573 EXPECT_FALSE(device->IsPaired());
3610 3574
3611 // No pairing context should remain on the device. 3575 // No pairing context should remain on the device.
3612 BluetoothDeviceChromeOS* device_chromeos = 3576 BluetoothDeviceBlueZ* device_bluez =
3613 static_cast<BluetoothDeviceChromeOS*>(device); 3577 static_cast<BluetoothDeviceBlueZ*>(device);
3614 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3578 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3615 } 3579 }
3616 3580
3617 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskeyWithoutDelegate) { 3581 TEST_F(BluetoothBlueZTest, IncomingPairRequestPasskeyWithoutDelegate) {
3618 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3582 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3619 3583
3620 GetAdapter(); 3584 GetAdapter();
3621 3585
3622 // Requests that we provide a displayed passkey, without a pairing delegate, 3586 // Requests that we provide a displayed passkey, without a pairing delegate,
3623 // that will be rejected. 3587 // that will be rejected.
3624 fake_bluetooth_device_client_->CreateDevice( 3588 fake_bluetooth_device_client_->CreateDevice(
3625 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3589 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3626 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); 3590 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath));
3627 BluetoothDevice* device = adapter_->GetDevice( 3591 BluetoothDevice* device = adapter_->GetDevice(
3628 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); 3592 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress);
3629 ASSERT_TRUE(device != nullptr); 3593 ASSERT_TRUE(device != nullptr);
3630 ASSERT_FALSE(device->IsPaired()); 3594 ASSERT_FALSE(device->IsPaired());
3631 3595
3632 TestBluetoothAdapterObserver observer(adapter_); 3596 TestBluetoothAdapterObserver observer(adapter_);
3633 3597
3634 fake_bluetooth_device_client_->SimulatePairing( 3598 fake_bluetooth_device_client_->SimulatePairing(
3635 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), 3599 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath),
3636 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3600 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3637 base::Unretained(this))); 3601 base::Unretained(this)));
3638 3602
3639 message_loop_.Run(); 3603 message_loop_.Run();
3640 3604
3641 EXPECT_EQ(0, callback_count_); 3605 EXPECT_EQ(0, callback_count_);
3642 EXPECT_EQ(1, error_callback_count_); 3606 EXPECT_EQ(1, error_callback_count_);
3643 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); 3607 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_);
3644 3608
3645 // No changes should be observer. 3609 // No changes should be observer.
3646 EXPECT_EQ(0, observer.device_changed_count()); 3610 EXPECT_EQ(0, observer.device_changed_count());
3647 3611
3648 EXPECT_FALSE(device->IsPaired()); 3612 EXPECT_FALSE(device->IsPaired());
3649 3613
3650 // No pairing context should remain on the device. 3614 // No pairing context should remain on the device.
3651 BluetoothDeviceChromeOS* device_chromeos = 3615 BluetoothDeviceBlueZ* device_bluez =
3652 static_cast<BluetoothDeviceChromeOS*>(device); 3616 static_cast<BluetoothDeviceBlueZ*>(device);
3653 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3617 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3654 } 3618 }
3655 3619
3656 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorksWithoutDelegate) { 3620 TEST_F(BluetoothBlueZTest, IncomingPairJustWorksWithoutDelegate) {
3657 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3621 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3658 3622
3659 GetAdapter(); 3623 GetAdapter();
3660 3624
3661 // Uses just-works pairing and thus requires authorization for incoming 3625 // Uses just-works pairing and thus requires authorization for incoming
3662 // pairings, without a pairing delegate, that will be rejected. 3626 // pairings, without a pairing delegate, that will be rejected.
3663 fake_bluetooth_device_client_->CreateDevice( 3627 fake_bluetooth_device_client_->CreateDevice(
3664 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3628 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3665 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); 3629 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath));
3666 BluetoothDevice* device = 3630 BluetoothDevice* device =
3667 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); 3631 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress);
3668 ASSERT_TRUE(device != nullptr); 3632 ASSERT_TRUE(device != nullptr);
3669 ASSERT_FALSE(device->IsPaired()); 3633 ASSERT_FALSE(device->IsPaired());
3670 3634
3671 TestBluetoothAdapterObserver observer(adapter_); 3635 TestBluetoothAdapterObserver observer(adapter_);
3672 3636
3673 fake_bluetooth_device_client_->SimulatePairing( 3637 fake_bluetooth_device_client_->SimulatePairing(
3674 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, 3638 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true,
3675 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3639 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3676 base::Unretained(this))); 3640 base::Unretained(this)));
3677 3641
3678 message_loop_.Run(); 3642 message_loop_.Run();
3679 3643
3680 EXPECT_EQ(0, callback_count_); 3644 EXPECT_EQ(0, callback_count_);
3681 EXPECT_EQ(1, error_callback_count_); 3645 EXPECT_EQ(1, error_callback_count_);
3682 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); 3646 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_);
3683 3647
3684 // No changes should be observer. 3648 // No changes should be observer.
3685 EXPECT_EQ(0, observer.device_changed_count()); 3649 EXPECT_EQ(0, observer.device_changed_count());
3686 3650
3687 EXPECT_FALSE(device->IsPaired()); 3651 EXPECT_FALSE(device->IsPaired());
3688 3652
3689 // No pairing context should remain on the device. 3653 // No pairing context should remain on the device.
3690 BluetoothDeviceChromeOS* device_chromeos = 3654 BluetoothDeviceBlueZ* device_bluez =
3691 static_cast<BluetoothDeviceChromeOS*>(device); 3655 static_cast<BluetoothDeviceBlueZ*>(device);
3692 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3656 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3693 } 3657 }
3694 3658
3695 TEST_F(BluetoothChromeOSTest, RemovePairingDelegateDuringPairing) { 3659 TEST_F(BluetoothBlueZTest, RemovePairingDelegateDuringPairing) {
3696 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3660 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3697 3661
3698 GetAdapter(); 3662 GetAdapter();
3699 3663
3700 TestPairingDelegate pairing_delegate; 3664 TestPairingDelegate pairing_delegate;
3701 adapter_->AddPairingDelegate( 3665 adapter_->AddPairingDelegate(
3702 &pairing_delegate, 3666 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3703 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3704 3667
3705 // Requests that we provide a Passkey. 3668 // Requests that we provide a Passkey.
3706 fake_bluetooth_device_client_->CreateDevice( 3669 fake_bluetooth_device_client_->CreateDevice(
3707 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3670 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3708 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); 3671 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath));
3709 BluetoothDevice* device = adapter_->GetDevice( 3672 BluetoothDevice* device = adapter_->GetDevice(
3710 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); 3673 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress);
3711 ASSERT_TRUE(device != nullptr); 3674 ASSERT_TRUE(device != nullptr);
3712 ASSERT_FALSE(device->IsPaired()); 3675 ASSERT_FALSE(device->IsPaired());
3713 3676
3714 TestBluetoothAdapterObserver observer(adapter_); 3677 TestBluetoothAdapterObserver observer(adapter_);
3715 3678
3716 fake_bluetooth_device_client_->SimulatePairing( 3679 fake_bluetooth_device_client_->SimulatePairing(
3717 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), 3680 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath),
3718 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3681 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3719 base::Unretained(this))); 3682 base::Unretained(this)));
3720 3683
3721 EXPECT_EQ(1, pairing_delegate.call_count_); 3684 EXPECT_EQ(1, pairing_delegate.call_count_);
3722 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 3685 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
3723 3686
3724 // A pairing context should now be set on the device. 3687 // A pairing context should now be set on the device.
3725 BluetoothDeviceChromeOS* device_chromeos = 3688 BluetoothDeviceBlueZ* device_bluez =
3726 static_cast<BluetoothDeviceChromeOS*>(device); 3689 static_cast<BluetoothDeviceBlueZ*>(device);
3727 ASSERT_TRUE(device_chromeos->GetPairing() != nullptr); 3690 ASSERT_TRUE(device_bluez->GetPairing() != nullptr);
3728 3691
3729 // Removing the pairing delegate should remove that pairing context. 3692 // Removing the pairing delegate should remove that pairing context.
3730 adapter_->RemovePairingDelegate(&pairing_delegate); 3693 adapter_->RemovePairingDelegate(&pairing_delegate);
3731 3694
3732 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3695 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3733 3696
3734 // Set the Passkey, this should now have no effect since the pairing has 3697 // Set the Passkey, this should now have no effect since the pairing has
3735 // been, in-effect, cancelled 3698 // been, in-effect, cancelled
3736 device->SetPasskey(1234); 3699 device->SetPasskey(1234);
3737 3700
3738 EXPECT_EQ(0, callback_count_); 3701 EXPECT_EQ(0, callback_count_);
3739 EXPECT_EQ(0, error_callback_count_); 3702 EXPECT_EQ(0, error_callback_count_);
3740 EXPECT_EQ(0, observer.device_changed_count()); 3703 EXPECT_EQ(0, observer.device_changed_count());
3741 3704
3742 EXPECT_FALSE(device->IsPaired()); 3705 EXPECT_FALSE(device->IsPaired());
3743 } 3706 }
3744 3707
3745 TEST_F(BluetoothChromeOSTest, DeviceId) { 3708 TEST_F(BluetoothBlueZTest, DeviceId) {
3746 GetAdapter(); 3709 GetAdapter();
3747 3710
3748 // Use the built-in paired device for this test, grab its Properties 3711 // Use the built-in paired device for this test, grab its Properties
3749 // structure so we can adjust the underlying modalias property. 3712 // structure so we can adjust the underlying modalias property.
3750 BluetoothDevice* device = adapter_->GetDevice( 3713 BluetoothDevice* device = adapter_->GetDevice(
3751 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 3714 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
3752 bluez::FakeBluetoothDeviceClient::Properties* properties = 3715 bluez::FakeBluetoothDeviceClient::Properties* properties =
3753 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3716 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3754 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 3717 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
3755 3718
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3790 3753
3791 // Unknown vendor specification identifier. 3754 // Unknown vendor specification identifier.
3792 properties->modalias.ReplaceValue("chrome:v00E0p2400d0400"); 3755 properties->modalias.ReplaceValue("chrome:v00E0p2400d0400");
3793 3756
3794 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); 3757 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource());
3795 EXPECT_EQ(0, device->GetVendorID()); 3758 EXPECT_EQ(0, device->GetVendorID());
3796 EXPECT_EQ(0, device->GetProductID()); 3759 EXPECT_EQ(0, device->GetProductID());
3797 EXPECT_EQ(0, device->GetDeviceID()); 3760 EXPECT_EQ(0, device->GetDeviceID());
3798 } 3761 }
3799 3762
3800 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForDisconnectedDevice) { 3763 TEST_F(BluetoothBlueZTest, GetConnectionInfoForDisconnectedDevice) {
3801 GetAdapter(); 3764 GetAdapter();
3802 BluetoothDevice* device = adapter_->GetDevice( 3765 BluetoothDevice* device = adapter_->GetDevice(
3803 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 3766 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
3804 3767
3805 // Calling GetConnectionInfo for an unconnected device should return a result 3768 // Calling GetConnectionInfo for an unconnected device should return a result
3806 // in which all fields are filled with BluetoothDevice::kUnknownPower. 3769 // in which all fields are filled with BluetoothDevice::kUnknownPower.
3807 BluetoothDevice::ConnectionInfo conn_info(0, 0, 0); 3770 BluetoothDevice::ConnectionInfo conn_info(0, 0, 0);
3808 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); 3771 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info));
3809 int unknown_power = BluetoothDevice::kUnknownPower; 3772 int unknown_power = BluetoothDevice::kUnknownPower;
3810 EXPECT_NE(0, unknown_power); 3773 EXPECT_NE(0, unknown_power);
3811 EXPECT_EQ(unknown_power, conn_info.rssi); 3774 EXPECT_EQ(unknown_power, conn_info.rssi);
3812 EXPECT_EQ(unknown_power, conn_info.transmit_power); 3775 EXPECT_EQ(unknown_power, conn_info.transmit_power);
3813 EXPECT_EQ(unknown_power, conn_info.max_transmit_power); 3776 EXPECT_EQ(unknown_power, conn_info.max_transmit_power);
3814 } 3777 }
3815 3778
3816 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) { 3779 TEST_F(BluetoothBlueZTest, GetConnectionInfoForConnectedDevice) {
3817 GetAdapter(); 3780 GetAdapter();
3818 BluetoothDevice* device = adapter_->GetDevice( 3781 BluetoothDevice* device = adapter_->GetDevice(
3819 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 3782 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
3820 3783
3821 device->Connect(nullptr, GetCallback(), 3784 device->Connect(nullptr, GetCallback(),
3822 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3785 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3823 base::Unretained(this))); 3786 base::Unretained(this)));
3824 EXPECT_TRUE(device->IsConnected()); 3787 EXPECT_TRUE(device->IsConnected());
3825 3788
3826 // Calling GetConnectionInfo for a connected device should return valid 3789 // Calling GetConnectionInfo for a connected device should return valid
3827 // results. 3790 // results.
3828 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); 3791 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4);
3829 BluetoothDevice::ConnectionInfo conn_info; 3792 BluetoothDevice::ConnectionInfo conn_info;
3830 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); 3793 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info));
3831 EXPECT_EQ(-10, conn_info.rssi); 3794 EXPECT_EQ(-10, conn_info.rssi);
3832 EXPECT_EQ(3, conn_info.transmit_power); 3795 EXPECT_EQ(3, conn_info.transmit_power);
3833 EXPECT_EQ(4, conn_info.max_transmit_power); 3796 EXPECT_EQ(4, conn_info.max_transmit_power);
3834 } 3797 }
3835 3798
3836 // Verifies Shutdown shuts down the adapter as expected. 3799 // Verifies Shutdown shuts down the adapter as expected.
3837 TEST_F(BluetoothChromeOSTest, Shutdown) { 3800 TEST_F(BluetoothBlueZTest, Shutdown) {
3838 // Set up adapter. Set powered & discoverable, start discovery. 3801 // Set up adapter. Set powered & discoverable, start discovery.
3839 GetAdapter(); 3802 GetAdapter();
3840 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 3803 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
3841 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); 3804 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
3842 adapter_->StartDiscoverySession( 3805 adapter_->StartDiscoverySession(
3843 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 3806 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
3844 base::Unretained(this)), 3807 base::Unretained(this)),
3845 GetErrorCallback()); 3808 GetErrorCallback());
3846 base::MessageLoop::current()->Run(); 3809 base::MessageLoop::current()->Run();
3847 ASSERT_EQ(3, callback_count_); 3810 ASSERT_EQ(3, callback_count_);
3848 ASSERT_EQ(0, error_callback_count_); 3811 ASSERT_EQ(0, error_callback_count_);
3849 callback_count_ = 0; 3812 callback_count_ = 0;
3850 3813
3851 TestPairingDelegate pairing_delegate; 3814 TestPairingDelegate pairing_delegate;
3852 adapter_->AddPairingDelegate( 3815 adapter_->AddPairingDelegate(
3853 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); 3816 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3854 3817
3855 // Validate running adapter state. 3818 // Validate running adapter state.
3856 EXPECT_NE("", adapter_->GetAddress()); 3819 EXPECT_NE("", adapter_->GetAddress());
3857 EXPECT_NE("", adapter_->GetName()); 3820 EXPECT_NE("", adapter_->GetName());
3858 EXPECT_TRUE(adapter_->IsInitialized()); 3821 EXPECT_TRUE(adapter_->IsInitialized());
3859 EXPECT_TRUE(adapter_->IsPresent()); 3822 EXPECT_TRUE(adapter_->IsPresent());
3860 EXPECT_TRUE(adapter_->IsPowered()); 3823 EXPECT_TRUE(adapter_->IsPowered());
3861 EXPECT_TRUE(adapter_->IsDiscoverable()); 3824 EXPECT_TRUE(adapter_->IsDiscoverable());
3862 EXPECT_TRUE(adapter_->IsDiscovering()); 3825 EXPECT_TRUE(adapter_->IsDiscovering());
3863 EXPECT_EQ(2U, adapter_->GetDevices().size()); 3826 EXPECT_EQ(2U, adapter_->GetDevices().size());
3864 EXPECT_NE(nullptr, 3827 EXPECT_NE(nullptr,
3865 adapter_->GetDevice( 3828 adapter_->GetDevice(
3866 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); 3829 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress));
3867 EXPECT_NE(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( 3830 EXPECT_NE(dbus::ObjectPath(""),
3868 adapter_.get())->object_path()); 3831 static_cast<BluetoothAdapterBlueZ*>(adapter_.get())->object_path());
3869 3832
3870 // Shutdown 3833 // Shutdown
3871 adapter_->Shutdown(); 3834 adapter_->Shutdown();
3872 3835
3873 // Validate post shutdown state by calling all BluetoothAdapterChromeOS 3836 // Validate post shutdown state by calling all BluetoothAdapterBlueZ
3874 // members, in declaration order: 3837 // members, in declaration order:
3875 3838
3876 adapter_->Shutdown(); 3839 adapter_->Shutdown();
3877 // DeleteOnCorrectThread omitted as we don't want to delete in this test. 3840 // DeleteOnCorrectThread omitted as we don't want to delete in this test.
3878 { 3841 {
3879 TestBluetoothAdapterObserver observer(adapter_); // Calls AddObserver 3842 TestBluetoothAdapterObserver observer(adapter_); // Calls AddObserver
3880 } // ~TestBluetoothAdapterObserver calls RemoveObserver. 3843 } // ~TestBluetoothAdapterObserver calls RemoveObserver.
3881 EXPECT_EQ("", adapter_->GetAddress()); 3844 EXPECT_EQ("", adapter_->GetAddress());
3882 EXPECT_EQ("", adapter_->GetName()); 3845 EXPECT_EQ("", adapter_->GetName());
3883 3846
(...skipping 15 matching lines...) Expand all
3899 EXPECT_EQ(0, callback_count_); 3862 EXPECT_EQ(0, callback_count_);
3900 EXPECT_EQ(1, error_callback_count_--) << "SetDiscoverable error"; 3863 EXPECT_EQ(1, error_callback_count_--) << "SetDiscoverable error";
3901 3864
3902 EXPECT_FALSE(adapter_->IsDiscovering()); 3865 EXPECT_FALSE(adapter_->IsDiscovering());
3903 // CreateRfcommService will DCHECK after Shutdown(). 3866 // CreateRfcommService will DCHECK after Shutdown().
3904 // CreateL2capService will DCHECK after Shutdown(). 3867 // CreateL2capService will DCHECK after Shutdown().
3905 3868
3906 BluetoothAudioSink::Options audio_sink_options; 3869 BluetoothAudioSink::Options audio_sink_options;
3907 adapter_->RegisterAudioSink( 3870 adapter_->RegisterAudioSink(
3908 audio_sink_options, 3871 audio_sink_options,
3909 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, 3872 base::Bind(&BluetoothBlueZTest::AudioSinkAcquiredCallback,
3910 base::Unretained(this)), 3873 base::Unretained(this)),
3911 base::Bind(&BluetoothChromeOSTest::AudioSinkErrorCallback, 3874 base::Bind(&BluetoothBlueZTest::AudioSinkErrorCallback,
3912 base::Unretained(this))); 3875 base::Unretained(this)));
3913 EXPECT_EQ(0, callback_count_); 3876 EXPECT_EQ(0, callback_count_);
3914 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; 3877 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error";
3915 3878
3916 BluetoothAdapterChromeOS* adapter_chrome_os = 3879 BluetoothAdapterBlueZ* adapter_chrome_os =
3917 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); 3880 static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
3918 EXPECT_EQ(nullptr, 3881 EXPECT_EQ(nullptr,
3919 adapter_chrome_os->GetDeviceWithPath(dbus::ObjectPath(""))); 3882 adapter_chrome_os->GetDeviceWithPath(dbus::ObjectPath("")));
3920 3883
3921 // Notify methods presume objects exist that are owned by the adapter and 3884 // Notify methods presume objects exist that are owned by the adapter and
3922 // destroyed in Shutdown(). Mocks are not attempted here that won't exist, 3885 // destroyed in Shutdown(). Mocks are not attempted here that won't exist,
3923 // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size()); 3886 // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size());
3924 // NotifyDeviceChanged 3887 // NotifyDeviceChanged
3925 // NotifyGattServiceAdded 3888 // NotifyGattServiceAdded
3926 // NotifyGattServiceRemoved 3889 // NotifyGattServiceRemoved
3927 // NotifyGattServiceChanged 3890 // NotifyGattServiceChanged
3928 // NotifyGattDiscoveryComplete 3891 // NotifyGattDiscoveryComplete
3929 // NotifyGattCharacteristicAdded 3892 // NotifyGattCharacteristicAdded
3930 // NotifyGattCharacteristicRemoved 3893 // NotifyGattCharacteristicRemoved
3931 // NotifyGattDescriptorAdded 3894 // NotifyGattDescriptorAdded
3932 // NotifyGattDescriptorRemoved 3895 // NotifyGattDescriptorRemoved
3933 // NotifyGattCharacteristicValueChanged 3896 // NotifyGattCharacteristicValueChanged
3934 // NotifyGattDescriptorValueChanged 3897 // NotifyGattDescriptorValueChanged
3935 3898
3936 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path()); 3899 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path());
3937 3900
3938 adapter_profile_ = nullptr; 3901 adapter_profile_ = nullptr;
3939 3902
3940 FakeBluetoothProfileServiceProviderDelegate profile_delegate; 3903 FakeBluetoothProfileServiceProviderDelegate profile_delegate;
3941 adapter_chrome_os->UseProfile( 3904 adapter_chrome_os->UseProfile(
3942 BluetoothUUID(), dbus::ObjectPath(""), 3905 BluetoothUUID(), dbus::ObjectPath(""),
3943 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, 3906 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate,
3944 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, 3907 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback,
3945 base::Unretained(this)), 3908 base::Unretained(this)),
3946 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, 3909 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback,
3947 base::Unretained(this))); 3910 base::Unretained(this)));
3948 3911
3949 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; 3912 EXPECT_FALSE(adapter_profile_) << "UseProfile error";
3950 EXPECT_EQ(0, callback_count_) << "UseProfile error"; 3913 EXPECT_EQ(0, callback_count_) << "UseProfile error";
3951 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; 3914 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error";
3952 3915
3953 // Protected and private methods: 3916 // Protected and private methods:
3954 3917
3955 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate); 3918 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate);
3956 // AdapterAdded() invalid post Shutdown because it calls SetAdapter. 3919 // AdapterAdded() invalid post Shutdown because it calls SetAdapter.
3957 adapter_chrome_os->AdapterRemoved(dbus::ObjectPath("x")); 3920 adapter_chrome_os->AdapterRemoved(dbus::ObjectPath("x"));
3958 adapter_chrome_os->AdapterPropertyChanged(dbus::ObjectPath("x"), ""); 3921 adapter_chrome_os->AdapterPropertyChanged(dbus::ObjectPath("x"), "");
3959 adapter_chrome_os->DeviceAdded(dbus::ObjectPath("")); 3922 adapter_chrome_os->DeviceAdded(dbus::ObjectPath(""));
3960 adapter_chrome_os->DeviceRemoved(dbus::ObjectPath("")); 3923 adapter_chrome_os->DeviceRemoved(dbus::ObjectPath(""));
3961 adapter_chrome_os->DevicePropertyChanged(dbus::ObjectPath(""), ""); 3924 adapter_chrome_os->DevicePropertyChanged(dbus::ObjectPath(""), "");
3962 adapter_chrome_os->InputPropertyChanged(dbus::ObjectPath(""), ""); 3925 adapter_chrome_os->InputPropertyChanged(dbus::ObjectPath(""), "");
3963 // bluez::BluetoothAgentServiceProvider::Delegate omitted, dbus will be 3926 // bluez::BluetoothAgentServiceProvider::Delegate omitted, dbus will be
3964 // shutdown, 3927 // shutdown,
3965 // with the exception of Released. 3928 // with the exception of Released.
3966 adapter_chrome_os->Released(); 3929 adapter_chrome_os->Released();
3967 3930
3968 adapter_chrome_os->OnRegisterAgent(); 3931 adapter_chrome_os->OnRegisterAgent();
3969 adapter_chrome_os->OnRegisterAgentError("", ""); 3932 adapter_chrome_os->OnRegisterAgentError("", "");
3970 adapter_chrome_os->OnRequestDefaultAgent(); 3933 adapter_chrome_os->OnRequestDefaultAgent();
3971 adapter_chrome_os->OnRequestDefaultAgentError("", ""); 3934 adapter_chrome_os->OnRequestDefaultAgentError("", "");
3972 3935
3973 adapter_chrome_os->OnRegisterAudioSink( 3936 adapter_chrome_os->OnRegisterAudioSink(
3974 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, 3937 base::Bind(&BluetoothBlueZTest::AudioSinkAcquiredCallback,
3975 base::Unretained(this)), 3938 base::Unretained(this)),
3976 base::Bind(&BluetoothChromeOSTest::AudioSinkErrorCallback, 3939 base::Bind(&BluetoothBlueZTest::AudioSinkErrorCallback,
3977 base::Unretained(this)), 3940 base::Unretained(this)),
3978 scoped_refptr<device::BluetoothAudioSink>()); 3941 scoped_refptr<device::BluetoothAudioSink>());
3979 EXPECT_EQ(0, callback_count_); 3942 EXPECT_EQ(0, callback_count_);
3980 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; 3943 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error";
3981 3944
3982 // GetPairing will DCHECK after Shutdown(). 3945 // GetPairing will DCHECK after Shutdown().
3983 // SetAdapter will DCHECK after Shutdown(). 3946 // SetAdapter will DCHECK after Shutdown().
3984 // SetDefaultAdapterName will DCHECK after Shutdown(). 3947 // SetDefaultAdapterName will DCHECK after Shutdown().
3985 // RemoveAdapter will DCHECK after Shutdown(). 3948 // RemoveAdapter will DCHECK after Shutdown().
3986 adapter_chrome_os->PoweredChanged(false); 3949 adapter_chrome_os->PoweredChanged(false);
(...skipping 25 matching lines...) Expand all
4012 // OnStopDiscovery tested in Shutdown_OnStopDiscovery 3975 // OnStopDiscovery tested in Shutdown_OnStopDiscovery
4013 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError 3976 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError
4014 3977
4015 adapter_profile_ = nullptr; 3978 adapter_profile_ = nullptr;
4016 3979
4017 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require 3980 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require
4018 // UseProfile to be set first, do so again here just before calling them. 3981 // UseProfile to be set first, do so again here just before calling them.
4019 adapter_chrome_os->UseProfile( 3982 adapter_chrome_os->UseProfile(
4020 BluetoothUUID(), dbus::ObjectPath(""), 3983 BluetoothUUID(), dbus::ObjectPath(""),
4021 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, 3984 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate,
4022 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, 3985 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback,
4023 base::Unretained(this)), 3986 base::Unretained(this)),
4024 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, 3987 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback,
4025 base::Unretained(this))); 3988 base::Unretained(this)));
4026 3989
4027 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; 3990 EXPECT_FALSE(adapter_profile_) << "UseProfile error";
4028 EXPECT_EQ(0, callback_count_) << "UseProfile error"; 3991 EXPECT_EQ(0, callback_count_) << "UseProfile error";
4029 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; 3992 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error";
4030 3993
4031 adapter_chrome_os->SetProfileDelegate( 3994 adapter_chrome_os->SetProfileDelegate(
4032 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate, 3995 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate,
4033 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, 3996 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback,
4034 base::Unretained(this)), 3997 base::Unretained(this)),
4035 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, 3998 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback,
4036 base::Unretained(this))); 3999 base::Unretained(this)));
4037 EXPECT_EQ(0, callback_count_) << "SetProfileDelegate error"; 4000 EXPECT_EQ(0, callback_count_) << "SetProfileDelegate error";
4038 EXPECT_EQ(1, error_callback_count_--) << "SetProfileDelegate error"; 4001 EXPECT_EQ(1, error_callback_count_--) << "SetProfileDelegate error";
4039 4002
4040 adapter_chrome_os->OnRegisterProfileError(BluetoothUUID(), "", ""); 4003 adapter_chrome_os->OnRegisterProfileError(BluetoothUUID(), "", "");
4041 EXPECT_EQ(0, callback_count_) << "OnRegisterProfileError error"; 4004 EXPECT_EQ(0, callback_count_) << "OnRegisterProfileError error";
4042 EXPECT_EQ(0, error_callback_count_) << "OnRegisterProfileError error"; 4005 EXPECT_EQ(0, error_callback_count_) << "OnRegisterProfileError error";
4043 4006
4044 adapter_chrome_os->ProcessQueuedDiscoveryRequests(); 4007 adapter_chrome_os->ProcessQueuedDiscoveryRequests();
4045 4008
4046 // From BluetoothAdapater: 4009 // From BluetoothAdapater:
4047 4010
4048 adapter_->StartDiscoverySession( 4011 adapter_->StartDiscoverySession(
4049 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 4012 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
4050 base::Unretained(this)), 4013 base::Unretained(this)),
4051 GetErrorCallback()); 4014 GetErrorCallback());
4052 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; 4015 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error";
4053 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error"; 4016 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error";
4054 4017
4055 EXPECT_EQ(0U, adapter_->GetDevices().size()); 4018 EXPECT_EQ(0U, adapter_->GetDevices().size());
4056 EXPECT_EQ(nullptr, 4019 EXPECT_EQ(nullptr,
4057 adapter_->GetDevice( 4020 adapter_->GetDevice(
4058 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); 4021 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress));
4059 TestPairingDelegate pairing_delegate2; 4022 TestPairingDelegate pairing_delegate2;
4060 adapter_->AddPairingDelegate( 4023 adapter_->AddPairingDelegate(
4061 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); 4024 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
4062 adapter_->RemovePairingDelegate(&pairing_delegate2); 4025 adapter_->RemovePairingDelegate(&pairing_delegate2);
4063 } 4026 }
4064 4027
4065 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. 4028 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery.
4066 TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscovery) { 4029 TEST_F(BluetoothBlueZTest, Shutdown_OnStartDiscovery) {
4067 const int kNumberOfDiscoverySessions = 10; 4030 const int kNumberOfDiscoverySessions = 10;
4068 GetAdapter(); 4031 GetAdapter();
4069 BluetoothAdapterChromeOS* adapter_chrome_os = 4032 BluetoothAdapterBlueZ* adapter_chrome_os =
4070 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); 4033 static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
4071 4034
4072 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { 4035 for (int i = 0; i < kNumberOfDiscoverySessions; i++) {
4073 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), 4036 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(),
4074 GetDiscoveryErrorCallback()); 4037 GetDiscoveryErrorCallback());
4075 } 4038 }
4076 adapter_->Shutdown(); 4039 adapter_->Shutdown();
4077 adapter_chrome_os->OnStartDiscovery(GetCallback(), 4040 adapter_chrome_os->OnStartDiscovery(GetCallback(),
4078 GetDiscoveryErrorCallback()); 4041 GetDiscoveryErrorCallback());
4079 4042
4080 EXPECT_EQ(0, callback_count_); 4043 EXPECT_EQ(0, callback_count_);
4081 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); 4044 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_);
4082 } 4045 }
4083 4046
4084 // Verifies post-Shutdown of discovery sessions and OnStartDiscoveryError. 4047 // Verifies post-Shutdown of discovery sessions and OnStartDiscoveryError.
4085 TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscoveryError) { 4048 TEST_F(BluetoothBlueZTest, Shutdown_OnStartDiscoveryError) {
4086 const int kNumberOfDiscoverySessions = 10; 4049 const int kNumberOfDiscoverySessions = 10;
4087 GetAdapter(); 4050 GetAdapter();
4088 BluetoothAdapterChromeOS* adapter_chrome_os = 4051 BluetoothAdapterBlueZ* adapter_chrome_os =
4089 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); 4052 static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
4090 4053
4091 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { 4054 for (int i = 0; i < kNumberOfDiscoverySessions; i++) {
4092 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), 4055 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(),
4093 GetDiscoveryErrorCallback()); 4056 GetDiscoveryErrorCallback());
4094 } 4057 }
4095 adapter_->Shutdown(); 4058 adapter_->Shutdown();
4096 adapter_chrome_os->OnStartDiscoveryError(GetCallback(), 4059 adapter_chrome_os->OnStartDiscoveryError(GetCallback(),
4097 GetDiscoveryErrorCallback(), "", ""); 4060 GetDiscoveryErrorCallback(), "", "");
4098 4061
4099 EXPECT_EQ(0, callback_count_); 4062 EXPECT_EQ(0, callback_count_);
4100 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); 4063 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_);
4101 } 4064 }
4102 4065
4103 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. 4066 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery.
4104 TEST_F(BluetoothChromeOSTest, Shutdown_OnStopDiscovery) { 4067 TEST_F(BluetoothBlueZTest, Shutdown_OnStopDiscovery) {
4105 const int kNumberOfDiscoverySessions = 10; 4068 const int kNumberOfDiscoverySessions = 10;
4106 GetAdapter(); 4069 GetAdapter();
4107 BluetoothAdapterChromeOS* adapter_chrome_os = 4070 BluetoothAdapterBlueZ* adapter_chrome_os =
4108 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); 4071 static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
4109 4072
4110 // In order to queue up discovery sessions before an OnStopDiscovery call 4073 // In order to queue up discovery sessions before an OnStopDiscovery call
4111 // RemoveDiscoverySession must be called, so Add, Start, and Remove: 4074 // RemoveDiscoverySession must be called, so Add, Start, and Remove:
4112 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), 4075 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(),
4113 GetDiscoveryErrorCallback()); 4076 GetDiscoveryErrorCallback());
4114 adapter_chrome_os->OnStartDiscovery(GetCallback(), 4077 adapter_chrome_os->OnStartDiscovery(GetCallback(),
4115 GetDiscoveryErrorCallback()); 4078 GetDiscoveryErrorCallback());
4116 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(), 4079 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(),
4117 GetDiscoveryErrorCallback()); 4080 GetDiscoveryErrorCallback());
4118 callback_count_ = 0; 4081 callback_count_ = 0;
4119 error_callback_count_ = 0; 4082 error_callback_count_ = 0;
4120 // Can now queue discovery sessions while waiting for OnStopDiscovery. 4083 // Can now queue discovery sessions while waiting for OnStopDiscovery.
4121 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { 4084 for (int i = 0; i < kNumberOfDiscoverySessions; i++) {
4122 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), 4085 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(),
4123 GetDiscoveryErrorCallback()); 4086 GetDiscoveryErrorCallback());
4124 } 4087 }
4125 adapter_->Shutdown(); 4088 adapter_->Shutdown();
4126 adapter_chrome_os->OnStopDiscovery(GetCallback()); 4089 adapter_chrome_os->OnStopDiscovery(GetCallback());
4127 4090
4128 // 1 successful stopped discovery from RemoveDiscoverySession, and 4091 // 1 successful stopped discovery from RemoveDiscoverySession, and
4129 // kNumberOfDiscoverySessions errors from AddDiscoverySession/OnStopDiscovery. 4092 // kNumberOfDiscoverySessions errors from AddDiscoverySession/OnStopDiscovery.
4130 EXPECT_EQ(1, callback_count_); 4093 EXPECT_EQ(1, callback_count_);
4131 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); 4094 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_);
4132 } 4095 }
4133 4096
4134 // Verifies post-Shutdown of discovery sessions and OnStopDiscoveryError. 4097 // Verifies post-Shutdown of discovery sessions and OnStopDiscoveryError.
4135 TEST_F(BluetoothChromeOSTest, Shutdown_OnStopDiscoveryError) { 4098 TEST_F(BluetoothBlueZTest, Shutdown_OnStopDiscoveryError) {
4136 const int kNumberOfDiscoverySessions = 10; 4099 const int kNumberOfDiscoverySessions = 10;
4137 GetAdapter(); 4100 GetAdapter();
4138 BluetoothAdapterChromeOS* adapter_chrome_os = 4101 BluetoothAdapterBlueZ* adapter_chrome_os =
4139 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); 4102 static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
4140 4103
4141 // In order to queue up discovery sessions before an OnStopDiscoveryError call 4104 // In order to queue up discovery sessions before an OnStopDiscoveryError call
4142 // RemoveDiscoverySession must be called, so Add, Start, and Remove: 4105 // RemoveDiscoverySession must be called, so Add, Start, and Remove:
4143 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), 4106 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(),
4144 GetDiscoveryErrorCallback()); 4107 GetDiscoveryErrorCallback());
4145 adapter_chrome_os->OnStartDiscovery(GetCallback(), 4108 adapter_chrome_os->OnStartDiscovery(GetCallback(),
4146 GetDiscoveryErrorCallback()); 4109 GetDiscoveryErrorCallback());
4147 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(), 4110 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(),
4148 GetDiscoveryErrorCallback()); 4111 GetDiscoveryErrorCallback());
4149 callback_count_ = 0; 4112 callback_count_ = 0;
4150 error_callback_count_ = 0; 4113 error_callback_count_ = 0;
4151 // Can now queue discovery sessions while waiting for OnStopDiscoveryError. 4114 // Can now queue discovery sessions while waiting for OnStopDiscoveryError.
4152 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { 4115 for (int i = 0; i < kNumberOfDiscoverySessions; i++) {
4153 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), 4116 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(),
4154 GetDiscoveryErrorCallback()); 4117 GetDiscoveryErrorCallback());
4155 } 4118 }
4156 adapter_->Shutdown(); 4119 adapter_->Shutdown();
4157 adapter_chrome_os->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); 4120 adapter_chrome_os->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", "");
4158 4121
4159 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, 4122 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError,
4160 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. 4123 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession.
4161 EXPECT_EQ(0, callback_count_); 4124 EXPECT_EQ(0, callback_count_);
4162 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); 4125 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_);
4163 } 4126 }
4164 4127
4165 } // namespace chromeos 4128 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698