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