OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 DiscoverySessionErrorCallback()); | 427 DiscoverySessionErrorCallback()); |
428 ui_task_runner_->ClearPendingTasks(); | 428 ui_task_runner_->ClearPendingTasks(); |
429 adapter_win_->DiscoveryStarted(false); | 429 adapter_win_->DiscoveryStarted(false); |
430 ui_task_runner_->RunPendingTasks(); | 430 ui_task_runner_->RunPendingTasks(); |
431 EXPECT_EQ(1, num_start_discovery_error_callbacks_); | 431 EXPECT_EQ(1, num_start_discovery_error_callbacks_); |
432 EXPECT_EQ(1, num_stop_discovery_callbacks_); | 432 EXPECT_EQ(1, num_stop_discovery_callbacks_); |
433 EXPECT_EQ(0, observer_.discovering_changed_count()); | 433 EXPECT_EQ(0, observer_.discovering_changed_count()); |
434 } | 434 } |
435 | 435 |
436 TEST_F(BluetoothAdapterWinTest, DevicesPolled) { | 436 TEST_F(BluetoothAdapterWinTest, DevicesPolled) { |
437 BluetoothTaskManagerWin::DeviceState* android_phone_state = | 437 BluetoothTaskManagerWin::DeviceState* android_phone_state( |
438 new BluetoothTaskManagerWin::DeviceState(); | 438 new BluetoothTaskManagerWin::DeviceState()); |
439 MakeDeviceState("phone", "A1:B2:C3:D4:E5:E0", android_phone_state); | 439 MakeDeviceState("phone", "A1:B2:C3:D4:E5:E0", android_phone_state); |
440 BluetoothTaskManagerWin::DeviceState* laptop_state = | 440 BluetoothTaskManagerWin::DeviceState* laptop_state( |
441 new BluetoothTaskManagerWin::DeviceState(); | 441 new BluetoothTaskManagerWin::DeviceState()); |
442 MakeDeviceState("laptop", "A1:B2:C3:D4:E5:E1", laptop_state); | 442 MakeDeviceState("laptop", "A1:B2:C3:D4:E5:E1", laptop_state); |
443 BluetoothTaskManagerWin::DeviceState* iphone_state = | 443 BluetoothTaskManagerWin::DeviceState* iphone_state( |
444 new BluetoothTaskManagerWin::DeviceState(); | 444 new BluetoothTaskManagerWin::DeviceState()); |
445 MakeDeviceState("phone", "A1:B2:C3:D4:E5:E2", iphone_state); | 445 MakeDeviceState("phone", "A1:B2:C3:D4:E5:E2", iphone_state); |
446 ScopedVector<BluetoothTaskManagerWin::DeviceState> devices; | 446 std::vector<std::unique_ptr<BluetoothTaskManagerWin::DeviceState>> devices; |
447 devices.push_back(android_phone_state); | 447 devices.push_back(std::unique_ptr<BluetoothTaskManagerWin::DeviceState>( |
448 devices.push_back(laptop_state); | 448 android_phone_state)); |
449 devices.push_back(iphone_state); | 449 devices.push_back( |
450 std::unique_ptr<BluetoothTaskManagerWin::DeviceState>(laptop_state)); | |
451 devices.push_back( | |
452 std::unique_ptr<BluetoothTaskManagerWin::DeviceState>(iphone_state)); | |
Reilly Grant (use Gerrit)
2016/12/21 22:25:13
auto state = base::MakeUnique<BluetoothTaskManager
dougt
2016/12/22 01:18:02
recall, below I need to access the ptr, so std::mo
| |
450 | 453 |
451 // Add 3 devices | 454 // Add 3 devices |
452 observer_.Reset(); | 455 observer_.Reset(); |
453 adapter_win_->DevicesPolled(devices); | 456 adapter_win_->DevicesPolled(devices); |
454 EXPECT_EQ(3, observer_.device_added_count()); | 457 EXPECT_EQ(3, observer_.device_added_count()); |
455 EXPECT_EQ(0, observer_.device_removed_count()); | 458 EXPECT_EQ(0, observer_.device_removed_count()); |
456 EXPECT_EQ(0, observer_.device_changed_count()); | 459 EXPECT_EQ(0, observer_.device_changed_count()); |
457 | 460 |
458 // Change a device name | 461 // Change a device name |
459 android_phone_state->name = std::string("phone2"); | 462 android_phone_state->name = std::string("phone2"); |
(...skipping 17 matching lines...) Expand all Loading... | |
477 adapter_win_->DevicesPolled(devices); | 480 adapter_win_->DevicesPolled(devices); |
478 EXPECT_EQ(0, observer_.device_added_count()); | 481 EXPECT_EQ(0, observer_.device_added_count()); |
479 EXPECT_EQ(1, observer_.device_removed_count()); | 482 EXPECT_EQ(1, observer_.device_removed_count()); |
480 EXPECT_EQ(0, observer_.device_changed_count()); | 483 EXPECT_EQ(0, observer_.device_changed_count()); |
481 | 484 |
482 // Add a service | 485 // Add a service |
483 BluetoothTaskManagerWin::ServiceRecordState* audio_state = | 486 BluetoothTaskManagerWin::ServiceRecordState* audio_state = |
484 new BluetoothTaskManagerWin::ServiceRecordState(); | 487 new BluetoothTaskManagerWin::ServiceRecordState(); |
485 audio_state->name = kTestAudioSdpName; | 488 audio_state->name = kTestAudioSdpName; |
486 base::HexStringToBytes(kTestAudioSdpBytes, &audio_state->sdp_bytes); | 489 base::HexStringToBytes(kTestAudioSdpBytes, &audio_state->sdp_bytes); |
487 laptop_state->service_record_states.push_back(audio_state); | 490 laptop_state->service_record_states.push_back( |
491 std::unique_ptr<BluetoothTaskManagerWin::ServiceRecordState>( | |
492 audio_state)); | |
Reilly Grant (use Gerrit)
2016/12/21 22:25:13
Use base::WrapUnique() if you really want to conve
dougt
2016/12/22 01:18:02
Done.
| |
488 observer_.Reset(); | 493 observer_.Reset(); |
489 adapter_win_->DevicesPolled(devices); | 494 adapter_win_->DevicesPolled(devices); |
490 EXPECT_EQ(0, observer_.device_added_count()); | 495 EXPECT_EQ(0, observer_.device_added_count()); |
491 EXPECT_EQ(0, observer_.device_removed_count()); | 496 EXPECT_EQ(0, observer_.device_removed_count()); |
492 EXPECT_EQ(1, observer_.device_changed_count()); | 497 EXPECT_EQ(1, observer_.device_changed_count()); |
493 | 498 |
494 // Change a service | 499 // Change a service |
495 audio_state->name = kTestAudioSdpName2; | 500 audio_state->name = kTestAudioSdpName2; |
496 observer_.Reset(); | 501 observer_.Reset(); |
497 adapter_win_->DevicesPolled(devices); | 502 adapter_win_->DevicesPolled(devices); |
498 EXPECT_EQ(0, observer_.device_added_count()); | 503 EXPECT_EQ(0, observer_.device_added_count()); |
499 EXPECT_EQ(0, observer_.device_removed_count()); | 504 EXPECT_EQ(0, observer_.device_removed_count()); |
500 EXPECT_EQ(1, observer_.device_changed_count()); | 505 EXPECT_EQ(1, observer_.device_changed_count()); |
501 | 506 |
502 // Remove a service | 507 // Remove a service |
503 laptop_state->service_record_states.clear(); | 508 laptop_state->service_record_states.clear(); |
504 observer_.Reset(); | 509 observer_.Reset(); |
505 adapter_win_->DevicesPolled(devices); | 510 adapter_win_->DevicesPolled(devices); |
506 EXPECT_EQ(0, observer_.device_added_count()); | 511 EXPECT_EQ(0, observer_.device_added_count()); |
507 EXPECT_EQ(0, observer_.device_removed_count()); | 512 EXPECT_EQ(0, observer_.device_removed_count()); |
508 EXPECT_EQ(1, observer_.device_changed_count()); | 513 EXPECT_EQ(1, observer_.device_changed_count()); |
509 } | 514 } |
510 | 515 |
511 } // namespace device | 516 } // namespace device |
OLD | NEW |