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

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

Issue 2614753004: Remove ScopedVector from bluetooth. (Closed)
Patch Set: last win bits Created 3 years, 11 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 (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 <memory>
5 #include <string> 6 #include <string>
7 #include <vector>
6 8
7 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h"
8 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
9 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
10 #include "base/test/test_simple_task_runner.h" 13 #include "base/test/test_simple_task_runner.h"
11 #include "device/bluetooth/bluetooth_adapter.h" 14 #include "device/bluetooth/bluetooth_adapter.h"
12 #include "device/bluetooth/bluetooth_adapter_win.h" 15 #include "device/bluetooth/bluetooth_adapter_win.h"
13 #include "device/bluetooth/bluetooth_device.h" 16 #include "device/bluetooth/bluetooth_device.h"
14 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" 17 #include "device/bluetooth/bluetooth_discovery_session_outcome.h"
15 #include "device/bluetooth/bluetooth_task_manager_win.h" 18 #include "device/bluetooth/bluetooth_task_manager_win.h"
16 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 19 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
17 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 DiscoverySessionErrorCallback()); 430 DiscoverySessionErrorCallback());
428 ui_task_runner_->ClearPendingTasks(); 431 ui_task_runner_->ClearPendingTasks();
429 adapter_win_->DiscoveryStarted(false); 432 adapter_win_->DiscoveryStarted(false);
430 ui_task_runner_->RunPendingTasks(); 433 ui_task_runner_->RunPendingTasks();
431 EXPECT_EQ(1, num_start_discovery_error_callbacks_); 434 EXPECT_EQ(1, num_start_discovery_error_callbacks_);
432 EXPECT_EQ(1, num_stop_discovery_callbacks_); 435 EXPECT_EQ(1, num_stop_discovery_callbacks_);
433 EXPECT_EQ(0, observer_.discovering_changed_count()); 436 EXPECT_EQ(0, observer_.discovering_changed_count());
434 } 437 }
435 438
436 TEST_F(BluetoothAdapterWinTest, DevicesPolled) { 439 TEST_F(BluetoothAdapterWinTest, DevicesPolled) {
437 BluetoothTaskManagerWin::DeviceState* android_phone_state = 440 std::vector<std::unique_ptr<BluetoothTaskManagerWin::DeviceState>> devices;
438 new BluetoothTaskManagerWin::DeviceState(); 441 devices.push_back(base::MakeUnique<BluetoothTaskManagerWin::DeviceState>());
442 devices.push_back(base::MakeUnique<BluetoothTaskManagerWin::DeviceState>());
443 devices.push_back(base::MakeUnique<BluetoothTaskManagerWin::DeviceState>());
444
445 BluetoothTaskManagerWin::DeviceState* android_phone_state = devices[0].get();
446 BluetoothTaskManagerWin::DeviceState* laptop_state = devices[1].get();
447 BluetoothTaskManagerWin::DeviceState* iphone_state = devices[2].get();
439 MakeDeviceState("phone", "A1:B2:C3:D4:E5:E0", android_phone_state); 448 MakeDeviceState("phone", "A1:B2:C3:D4:E5:E0", android_phone_state);
440 BluetoothTaskManagerWin::DeviceState* laptop_state =
441 new BluetoothTaskManagerWin::DeviceState();
442 MakeDeviceState("laptop", "A1:B2:C3:D4:E5:E1", laptop_state); 449 MakeDeviceState("laptop", "A1:B2:C3:D4:E5:E1", laptop_state);
443 BluetoothTaskManagerWin::DeviceState* iphone_state =
444 new BluetoothTaskManagerWin::DeviceState();
445 MakeDeviceState("phone", "A1:B2:C3:D4:E5:E2", iphone_state); 450 MakeDeviceState("phone", "A1:B2:C3:D4:E5:E2", iphone_state);
446 ScopedVector<BluetoothTaskManagerWin::DeviceState> devices;
447 devices.push_back(android_phone_state);
448 devices.push_back(laptop_state);
449 devices.push_back(iphone_state);
450 451
451 // Add 3 devices 452 // Add 3 devices
452 observer_.Reset(); 453 observer_.Reset();
453 adapter_win_->DevicesPolled(devices); 454 adapter_win_->DevicesPolled(devices);
454 EXPECT_EQ(3, observer_.device_added_count()); 455 EXPECT_EQ(3, observer_.device_added_count());
455 EXPECT_EQ(0, observer_.device_removed_count()); 456 EXPECT_EQ(0, observer_.device_removed_count());
456 EXPECT_EQ(0, observer_.device_changed_count()); 457 EXPECT_EQ(0, observer_.device_changed_count());
457 458
458 // Change a device name 459 // Change a device name
459 android_phone_state->name = std::string("phone2"); 460 android_phone_state->name = std::string("phone2");
(...skipping 13 matching lines...) Expand all
473 474
474 // Remove a device 475 // Remove a device
475 devices.erase(devices.begin()); 476 devices.erase(devices.begin());
476 observer_.Reset(); 477 observer_.Reset();
477 adapter_win_->DevicesPolled(devices); 478 adapter_win_->DevicesPolled(devices);
478 EXPECT_EQ(0, observer_.device_added_count()); 479 EXPECT_EQ(0, observer_.device_added_count());
479 EXPECT_EQ(1, observer_.device_removed_count()); 480 EXPECT_EQ(1, observer_.device_removed_count());
480 EXPECT_EQ(0, observer_.device_changed_count()); 481 EXPECT_EQ(0, observer_.device_changed_count());
481 482
482 // Add a service 483 // Add a service
484 laptop_state->service_record_states.push_back(
485 base::MakeUnique<BluetoothTaskManagerWin::ServiceRecordState>());
483 BluetoothTaskManagerWin::ServiceRecordState* audio_state = 486 BluetoothTaskManagerWin::ServiceRecordState* audio_state =
484 new BluetoothTaskManagerWin::ServiceRecordState(); 487 laptop_state->service_record_states.back().get();
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);
488 observer_.Reset(); 490 observer_.Reset();
489 adapter_win_->DevicesPolled(devices); 491 adapter_win_->DevicesPolled(devices);
490 EXPECT_EQ(0, observer_.device_added_count()); 492 EXPECT_EQ(0, observer_.device_added_count());
491 EXPECT_EQ(0, observer_.device_removed_count()); 493 EXPECT_EQ(0, observer_.device_removed_count());
492 EXPECT_EQ(1, observer_.device_changed_count()); 494 EXPECT_EQ(1, observer_.device_changed_count());
493 495
494 // Change a service 496 // Change a service
495 audio_state->name = kTestAudioSdpName2; 497 audio_state->name = kTestAudioSdpName2;
496 observer_.Reset(); 498 observer_.Reset();
497 adapter_win_->DevicesPolled(devices); 499 adapter_win_->DevicesPolled(devices);
498 EXPECT_EQ(0, observer_.device_added_count()); 500 EXPECT_EQ(0, observer_.device_added_count());
499 EXPECT_EQ(0, observer_.device_removed_count()); 501 EXPECT_EQ(0, observer_.device_removed_count());
500 EXPECT_EQ(1, observer_.device_changed_count()); 502 EXPECT_EQ(1, observer_.device_changed_count());
501 503
502 // Remove a service 504 // Remove a service
503 laptop_state->service_record_states.clear(); 505 laptop_state->service_record_states.clear();
504 observer_.Reset(); 506 observer_.Reset();
505 adapter_win_->DevicesPolled(devices); 507 adapter_win_->DevicesPolled(devices);
506 EXPECT_EQ(0, observer_.device_added_count()); 508 EXPECT_EQ(0, observer_.device_added_count());
507 EXPECT_EQ(0, observer_.device_removed_count()); 509 EXPECT_EQ(0, observer_.device_removed_count());
508 EXPECT_EQ(1, observer_.device_changed_count()); 510 EXPECT_EQ(1, observer_.device_changed_count());
509 } 511 }
510 512
511 } // namespace device 513 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_win.cc ('k') | device/bluetooth/bluetooth_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698