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

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

Issue 11411130: Implemented BluetoothTaskManagerWin class. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: changed to const char[] Created 7 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
« no previous file with comments | « device/bluetooth/bluetooth_task_manager_win.cc ('k') | device/device.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <deque>
6
7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/test/test_pending_task.h"
10 #include "base/test/test_simple_task_runner.h"
11 #include "device/bluetooth/bluetooth_task_manager_win.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace {
15
16 class BluetoothTaskObserver : public device::BluetoothTaskManagerWin::Observer {
17 public:
18 BluetoothTaskObserver() : num_updates_(0) {
19 }
20
21 virtual ~BluetoothTaskObserver() {
22 }
23
24 virtual void AdapterStateChanged(
25 const device::BluetoothTaskManagerWin::AdapterState& state) {
26 num_updates_++;
27 }
28
29 int num_updates() const {
30 return num_updates_;
31 }
32
33 private:
34 int num_updates_;
35 };
36
37 } // namespace
38
39 namespace device {
40
41 class BluetoothTaskManagerWinTest : public testing::Test {
42 public:
43 BluetoothTaskManagerWinTest()
44 : ui_task_runner_(new base::TestSimpleTaskRunner()),
45 bluetooth_task_runner_(new base::TestSimpleTaskRunner()),
46 task_manager_(new BluetoothTaskManagerWin(ui_task_runner_,
47 bluetooth_task_runner_)),
48 has_bluetooth_stack_(BluetoothTaskManagerWin::HasBluetoothStack()) {
49 }
50
51 virtual void SetUp() {
52 task_manager_->AddObserver(&observer_);
53 task_manager_->Initialize();
54 }
55
56 virtual void TearDown() {
57 task_manager_->RemoveObserver(&observer_);
58 }
59
60 int GetPollingIntervalMs() const {
61 return BluetoothTaskManagerWin::kPollIntervalMs;
62 }
63
64 protected:
65 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_;
66 scoped_refptr<base::TestSimpleTaskRunner> bluetooth_task_runner_;
67 scoped_refptr<BluetoothTaskManagerWin> task_manager_;
68 BluetoothTaskObserver observer_;
69 const bool has_bluetooth_stack_;
70 };
71
72 TEST_F(BluetoothTaskManagerWinTest, StartPolling) {
73 const std::deque<base::TestPendingTask>& pending_tasks =
74 bluetooth_task_runner_->GetPendingTasks();
75 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
76 }
77
78 TEST_F(BluetoothTaskManagerWinTest, PollAdapterIfBluetoothStackIsAvailable) {
79 bluetooth_task_runner_->RunPendingTasks();
80 int num_expected_pending_tasks = has_bluetooth_stack_ ? 1 : 0;
81 EXPECT_EQ(num_expected_pending_tasks,
82 bluetooth_task_runner_->GetPendingTasks().size());
83 }
84
85 TEST_F(BluetoothTaskManagerWinTest, Polling) {
86 if (!has_bluetooth_stack_) {
87 return;
88 }
89
90 int expected_num_updates = 5;
91
92 for (int i = 0; i < expected_num_updates; i++) {
93 bluetooth_task_runner_->RunPendingTasks();
94 }
95
96 EXPECT_EQ(expected_num_updates, ui_task_runner_->GetPendingTasks().size());
97 ui_task_runner_->RunPendingTasks();
98 EXPECT_EQ(expected_num_updates, observer_.num_updates());
99 }
100
101 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_task_manager_win.cc ('k') | device/device.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698