OLD | NEW |
(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 "base/memory/ref_counted.h" |
| 6 #include "base/message_loop.h" |
| 7 #include "base/run_loop.h" |
| 8 #include "content/public/test/test_browser_thread.h" |
| 9 #include "device/bluetooth/bluetooth_task_manager_win.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 class BluetoothTaskObserver : public device::BluetoothTaskManagerWin::Observer { |
| 15 public: |
| 16 BluetoothTaskObserver() : updated_(false) { |
| 17 } |
| 18 |
| 19 virtual ~BluetoothTaskObserver() { |
| 20 } |
| 21 |
| 22 virtual void AdapterStateChanged( |
| 23 const device::BluetoothTaskManagerWin::AdapterState& state) { |
| 24 updated_ = true; |
| 25 } |
| 26 |
| 27 bool updated() const { |
| 28 return updated_; |
| 29 } |
| 30 |
| 31 private: |
| 32 bool updated_; |
| 33 }; |
| 34 |
| 35 } // namespace |
| 36 |
| 37 namespace device { |
| 38 |
| 39 class BluetoothTaskManagerWinTest : public testing::Test { |
| 40 public: |
| 41 BluetoothTaskManagerWinTest() |
| 42 : ui_thread_(content::BrowserThread::UI, &ui_loop_), |
| 43 task_manager_(new BluetoothTaskManagerWin()) { |
| 44 } |
| 45 |
| 46 virtual void SetUp() { |
| 47 task_manager_->AddObserver(&observer_); |
| 48 } |
| 49 |
| 50 virtual void TearDown() { |
| 51 task_manager_->RemoveObserver(&observer_); |
| 52 } |
| 53 |
| 54 protected: |
| 55 MessageLoopForUI ui_loop_; |
| 56 content::TestBrowserThread ui_thread_; |
| 57 scoped_refptr<BluetoothTaskManagerWin> task_manager_; |
| 58 BluetoothTaskObserver observer_; |
| 59 }; |
| 60 |
| 61 TEST_F(BluetoothTaskManagerWinTest, NotifyObserver) { |
| 62 task_manager_->StartThread(); |
| 63 base::RunLoop run_loop; |
| 64 MessageLoop::current()->PostDelayedTask( |
| 65 FROM_HERE, |
| 66 run_loop.QuitClosure(), |
| 67 base::TimeDelta::FromMilliseconds(100)); |
| 68 |
| 69 run_loop.Run(); |
| 70 task_manager_->StopThread(); |
| 71 EXPECT_TRUE(observer_.updated()); |
| 72 } |
| 73 |
| 74 } // namespace device |
OLD | NEW |