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..b334275bc89efe0dc0e1426d9b894b6237486d76 |
--- /dev/null |
+++ b/device/bluetooth/bluetooth_task_manager_win_unittest.cc |
@@ -0,0 +1,74 @@ |
+// 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 "base/memory/ref_counted.h" |
+#include "base/message_loop.h" |
+#include "base/run_loop.h" |
+#include "content/public/test/test_browser_thread.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() : updated_(false) { |
+ } |
+ |
+ virtual ~BluetoothTaskObserver() { |
+ } |
+ |
+ virtual void AdapterStateChanged( |
+ const device::BluetoothTaskManagerWin::AdapterState& state) { |
+ updated_ = true; |
+ } |
+ |
+ bool updated() const { |
+ return updated_; |
+ } |
+ |
+ private: |
+ bool updated_; |
+}; |
+ |
+} // namespace |
+ |
+namespace device { |
+ |
+class BluetoothTaskManagerWinTest : public testing::Test { |
+ public: |
+ BluetoothTaskManagerWinTest() |
+ : ui_thread_(content::BrowserThread::UI, &ui_loop_), |
+ task_manager_(new BluetoothTaskManagerWin()) { |
+ } |
+ |
+ virtual void SetUp() { |
+ task_manager_->AddObserver(&observer_); |
+ } |
+ |
+ virtual void TearDown() { |
+ task_manager_->RemoveObserver(&observer_); |
+ } |
+ |
+ protected: |
+ MessageLoopForUI ui_loop_; |
+ content::TestBrowserThread ui_thread_; |
+ scoped_refptr<BluetoothTaskManagerWin> task_manager_; |
+ BluetoothTaskObserver observer_; |
+}; |
+ |
+TEST_F(BluetoothTaskManagerWinTest, NotifyObserver) { |
+ task_manager_->StartThread(); |
+ base::RunLoop run_loop; |
+ MessageLoop::current()->PostDelayedTask( |
+ FROM_HERE, |
+ run_loop.QuitClosure(), |
+ base::TimeDelta::FromMilliseconds(100)); |
+ |
+ run_loop.Run(); |
+ task_manager_->StopThread(); |
+ EXPECT_TRUE(observer_.updated()); |
+} |
+ |
+} // namespace device |