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 <stddef.h> | 5 #include <stddef.h> |
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/test/test_pending_task.h" | 9 #include "base/test/test_pending_task.h" |
10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 protected: | 76 protected: |
77 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_; | 77 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_; |
78 scoped_refptr<base::TestSimpleTaskRunner> bluetooth_task_runner_; | 78 scoped_refptr<base::TestSimpleTaskRunner> bluetooth_task_runner_; |
79 scoped_refptr<BluetoothTaskManagerWin> task_manager_; | 79 scoped_refptr<BluetoothTaskManagerWin> task_manager_; |
80 BluetoothTaskObserver observer_; | 80 BluetoothTaskObserver observer_; |
81 const bool has_bluetooth_stack_; | 81 const bool has_bluetooth_stack_; |
82 }; | 82 }; |
83 | 83 |
84 TEST_F(BluetoothTaskManagerWinTest, StartPolling) { | 84 TEST_F(BluetoothTaskManagerWinTest, StartPolling) { |
85 EXPECT_EQ(1u, bluetooth_task_runner_->GetPendingTasks().size()); | 85 EXPECT_EQ(1u, bluetooth_task_runner_->NumPendingTasks()); |
86 } | 86 } |
87 | 87 |
88 TEST_F(BluetoothTaskManagerWinTest, PollAdapterIfBluetoothStackIsAvailable) { | 88 TEST_F(BluetoothTaskManagerWinTest, PollAdapterIfBluetoothStackIsAvailable) { |
89 bluetooth_task_runner_->RunPendingTasks(); | 89 bluetooth_task_runner_->RunPendingTasks(); |
90 size_t num_expected_pending_tasks = has_bluetooth_stack_ ? 1 : 0; | 90 size_t num_expected_pending_tasks = has_bluetooth_stack_ ? 1 : 0; |
91 EXPECT_EQ(num_expected_pending_tasks, | 91 EXPECT_EQ(num_expected_pending_tasks, |
92 bluetooth_task_runner_->GetPendingTasks().size()); | 92 bluetooth_task_runner_->NumPendingTasks()); |
93 } | 93 } |
94 | 94 |
95 TEST_F(BluetoothTaskManagerWinTest, Polling) { | 95 TEST_F(BluetoothTaskManagerWinTest, Polling) { |
96 if (!has_bluetooth_stack_) | 96 if (!has_bluetooth_stack_) |
97 return; | 97 return; |
98 | 98 |
99 int num_polls = 5; | 99 int num_polls = 5; |
100 | 100 |
101 for (int i = 0; i < num_polls; i++) { | 101 for (int i = 0; i < num_polls; i++) { |
102 bluetooth_task_runner_->RunPendingTasks(); | 102 bluetooth_task_runner_->RunPendingTasks(); |
103 } | 103 } |
104 | 104 |
105 ui_task_runner_->RunPendingTasks(); | 105 ui_task_runner_->RunPendingTasks(); |
106 EXPECT_EQ(num_polls, observer_.num_adapter_state_changed()); | 106 EXPECT_EQ(num_polls, observer_.num_adapter_state_changed()); |
107 } | 107 } |
108 | 108 |
109 TEST_F(BluetoothTaskManagerWinTest, SetPowered) { | 109 TEST_F(BluetoothTaskManagerWinTest, SetPowered) { |
110 if (!has_bluetooth_stack_) | 110 if (!has_bluetooth_stack_) |
111 return; | 111 return; |
112 | 112 |
113 bluetooth_task_runner_->ClearPendingTasks(); | 113 bluetooth_task_runner_->ClearPendingTasks(); |
114 base::Closure closure; | 114 base::Closure closure; |
115 task_manager_->PostSetPoweredBluetoothTask(true, closure, closure); | 115 task_manager_->PostSetPoweredBluetoothTask(true, closure, closure); |
116 | 116 |
117 EXPECT_EQ(1u, bluetooth_task_runner_->GetPendingTasks().size()); | 117 EXPECT_EQ(1u, bluetooth_task_runner_->NumPendingTasks()); |
118 bluetooth_task_runner_->RunPendingTasks(); | 118 bluetooth_task_runner_->RunPendingTasks(); |
119 EXPECT_TRUE(ui_task_runner_->GetPendingTasks().size() >= 1); | 119 EXPECT_TRUE(ui_task_runner_->NumPendingTasks() >= 1); |
120 } | 120 } |
121 | 121 |
122 TEST_F(BluetoothTaskManagerWinTest, Discovery) { | 122 TEST_F(BluetoothTaskManagerWinTest, Discovery) { |
123 if (!has_bluetooth_stack_) | 123 if (!has_bluetooth_stack_) |
124 return; | 124 return; |
125 | 125 |
126 bluetooth_task_runner_->RunPendingTasks(); | 126 bluetooth_task_runner_->RunPendingTasks(); |
127 bluetooth_task_runner_->ClearPendingTasks(); | 127 bluetooth_task_runner_->ClearPendingTasks(); |
128 task_manager_->PostStartDiscoveryTask(); | 128 task_manager_->PostStartDiscoveryTask(); |
129 bluetooth_task_runner_->RunPendingTasks(); | 129 bluetooth_task_runner_->RunPendingTasks(); |
130 ui_task_runner_->RunPendingTasks(); | 130 ui_task_runner_->RunPendingTasks(); |
131 EXPECT_EQ(1, observer_.num_discovery_started()); | 131 EXPECT_EQ(1, observer_.num_discovery_started()); |
132 task_manager_->PostStopDiscoveryTask(); | 132 task_manager_->PostStopDiscoveryTask(); |
133 bluetooth_task_runner_->RunPendingTasks(); | 133 bluetooth_task_runner_->RunPendingTasks(); |
134 ui_task_runner_->RunPendingTasks(); | 134 ui_task_runner_->RunPendingTasks(); |
135 EXPECT_EQ(1, observer_.num_discovery_stopped()); | 135 EXPECT_EQ(1, observer_.num_discovery_stopped()); |
136 } | 136 } |
137 | 137 |
138 } // namespace device | 138 } // namespace device |
OLD | NEW |