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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth_task_manager_win.cc ('k') | device/device.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_task_manager_win_unittest.cc
diff --git a/device/bluetooth/bluetooth_task_manager_win_unittest.cc b/device/bluetooth/bluetooth_task_manager_win_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b4721ca7ba600dc8fa418cb5046dcad4c7de4a87
--- /dev/null
+++ b/device/bluetooth/bluetooth_task_manager_win_unittest.cc
@@ -0,0 +1,101 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <deque>
+
+#include "base/bind.h"
+#include "base/memory/ref_counted.h"
+#include "base/test/test_pending_task.h"
+#include "base/test/test_simple_task_runner.h"
+#include "device/bluetooth/bluetooth_task_manager_win.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class BluetoothTaskObserver : public device::BluetoothTaskManagerWin::Observer {
+ public:
+ BluetoothTaskObserver() : num_updates_(0) {
+ }
+
+ virtual ~BluetoothTaskObserver() {
+ }
+
+ virtual void AdapterStateChanged(
+ const device::BluetoothTaskManagerWin::AdapterState& state) {
+ num_updates_++;
+ }
+
+ int num_updates() const {
+ return num_updates_;
+ }
+
+ private:
+ int num_updates_;
+};
+
+} // namespace
+
+namespace device {
+
+class BluetoothTaskManagerWinTest : public testing::Test {
+ public:
+ BluetoothTaskManagerWinTest()
+ : ui_task_runner_(new base::TestSimpleTaskRunner()),
+ bluetooth_task_runner_(new base::TestSimpleTaskRunner()),
+ task_manager_(new BluetoothTaskManagerWin(ui_task_runner_,
+ bluetooth_task_runner_)),
+ has_bluetooth_stack_(BluetoothTaskManagerWin::HasBluetoothStack()) {
+ }
+
+ virtual void SetUp() {
+ task_manager_->AddObserver(&observer_);
+ task_manager_->Initialize();
+ }
+
+ virtual void TearDown() {
+ task_manager_->RemoveObserver(&observer_);
+ }
+
+ int GetPollingIntervalMs() const {
+ return BluetoothTaskManagerWin::kPollIntervalMs;
+ }
+
+ protected:
+ scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_;
+ scoped_refptr<base::TestSimpleTaskRunner> bluetooth_task_runner_;
+ scoped_refptr<BluetoothTaskManagerWin> task_manager_;
+ BluetoothTaskObserver observer_;
+ const bool has_bluetooth_stack_;
+};
+
+TEST_F(BluetoothTaskManagerWinTest, StartPolling) {
+ const std::deque<base::TestPendingTask>& pending_tasks =
+ bluetooth_task_runner_->GetPendingTasks();
+ EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
+}
+
+TEST_F(BluetoothTaskManagerWinTest, PollAdapterIfBluetoothStackIsAvailable) {
+ bluetooth_task_runner_->RunPendingTasks();
+ int num_expected_pending_tasks = has_bluetooth_stack_ ? 1 : 0;
+ EXPECT_EQ(num_expected_pending_tasks,
+ bluetooth_task_runner_->GetPendingTasks().size());
+}
+
+TEST_F(BluetoothTaskManagerWinTest, Polling) {
+ if (!has_bluetooth_stack_) {
+ return;
+ }
+
+ int expected_num_updates = 5;
+
+ for (int i = 0; i < expected_num_updates; i++) {
+ bluetooth_task_runner_->RunPendingTasks();
+ }
+
+ EXPECT_EQ(expected_num_updates, ui_task_runner_->GetPendingTasks().size());
+ ui_task_runner_->RunPendingTasks();
+ EXPECT_EQ(expected_num_updates, observer_.num_updates());
+}
+
+} // namespace device
« 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