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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/test/test_pending_task.h" | 7 #include "base/test/test_pending_task.h" |
8 #include "base/test/test_simple_task_runner.h" | 8 #include "base/test/test_simple_task_runner.h" |
9 #include "device/bluetooth/bluetooth_init_win.h" | 9 #include "device/bluetooth/bluetooth_init_win.h" |
10 #include "device/bluetooth/bluetooth_task_manager_win.h" | 10 #include "device/bluetooth/bluetooth_task_manager_win.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 class BluetoothTaskObserver : public device::BluetoothTaskManagerWin::Observer { | 15 class BluetoothTaskObserver : public device::BluetoothTaskManagerWin::Observer { |
16 public: | 16 public: |
17 BluetoothTaskObserver() { | 17 BluetoothTaskObserver() |
18 Clear(); | 18 : num_adapter_state_changed_(0), |
| 19 num_discovery_started_(0), |
| 20 num_discovery_stopped_(0) { |
19 } | 21 } |
20 | 22 |
21 virtual ~BluetoothTaskObserver() { | 23 virtual ~BluetoothTaskObserver() { |
22 } | 24 } |
23 | 25 |
24 virtual void AdapterStateChanged( | 26 virtual void AdapterStateChanged( |
25 const device::BluetoothTaskManagerWin::AdapterState& state) OVERRIDE { | 27 const device::BluetoothTaskManagerWin::AdapterState& state) OVERRIDE { |
26 num_adapter_state_changed_++; | 28 num_adapter_state_changed_++; |
27 } | 29 } |
28 | 30 |
29 virtual void DiscoveryStarted(bool success) OVERRIDE { | 31 virtual void DiscoveryStarted(bool success) OVERRIDE { |
30 num_discovery_started_++; | 32 num_discovery_started_++; |
31 } | 33 } |
32 | 34 |
33 virtual void DiscoveryStopped() OVERRIDE { | 35 virtual void DiscoveryStopped() OVERRIDE { |
34 num_discovery_stopped_++; | 36 num_discovery_stopped_++; |
35 } | 37 } |
36 | 38 |
37 virtual void DevicesDiscovered( | |
38 const ScopedVector<device::BluetoothTaskManagerWin::DeviceState>& | |
39 devices) OVERRIDE { | |
40 num_devices_discovered_++; | |
41 } | |
42 | |
43 void Clear() { | |
44 num_adapter_state_changed_ = 0; | |
45 num_discovery_started_ = 0; | |
46 num_discovery_stopped_ = 0; | |
47 num_devices_discovered_ = 0; | |
48 } | |
49 | |
50 int num_adapter_state_changed() const { | 39 int num_adapter_state_changed() const { |
51 return num_adapter_state_changed_; | 40 return num_adapter_state_changed_; |
52 } | 41 } |
53 | 42 |
54 int num_discovery_started() const { | 43 int num_discovery_started() const { |
55 return num_discovery_started_; | 44 return num_discovery_started_; |
56 } | 45 } |
57 | 46 |
58 int num_discovery_stopped() const { | 47 int num_discovery_stopped() const { |
59 return num_discovery_stopped_; | 48 return num_discovery_stopped_; |
60 } | 49 } |
61 | 50 |
62 int num_devices_discovered() const { | |
63 return num_devices_discovered_; | |
64 } | |
65 | |
66 private: | 51 private: |
67 int num_adapter_state_changed_; | 52 int num_adapter_state_changed_; |
68 int num_discovery_started_; | 53 int num_discovery_started_; |
69 int num_discovery_stopped_; | 54 int num_discovery_stopped_; |
70 int num_devices_discovered_; | |
71 }; | 55 }; |
72 | 56 |
73 } // namespace | 57 } // namespace |
74 | 58 |
75 namespace device { | 59 namespace device { |
76 | 60 |
77 class BluetoothTaskManagerWinTest : public testing::Test { | 61 class BluetoothTaskManagerWinTest : public testing::Test { |
78 public: | 62 public: |
79 BluetoothTaskManagerWinTest() | 63 BluetoothTaskManagerWinTest() |
80 : ui_task_runner_(new base::TestSimpleTaskRunner()), | 64 : ui_task_runner_(new base::TestSimpleTaskRunner()), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 bluetooth_task_runner_->RunPendingTasks(); | 136 bluetooth_task_runner_->RunPendingTasks(); |
153 ui_task_runner_->RunPendingTasks(); | 137 ui_task_runner_->RunPendingTasks(); |
154 EXPECT_EQ(1, observer_.num_discovery_started()); | 138 EXPECT_EQ(1, observer_.num_discovery_started()); |
155 task_manager_->PostStopDiscoveryTask(); | 139 task_manager_->PostStopDiscoveryTask(); |
156 bluetooth_task_runner_->RunPendingTasks(); | 140 bluetooth_task_runner_->RunPendingTasks(); |
157 ui_task_runner_->RunPendingTasks(); | 141 ui_task_runner_->RunPendingTasks(); |
158 EXPECT_EQ(1, observer_.num_discovery_stopped()); | 142 EXPECT_EQ(1, observer_.num_discovery_stopped()); |
159 } | 143 } |
160 | 144 |
161 } // namespace device | 145 } // namespace device |
OLD | NEW |