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

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

Issue 12018024: Implemented Asynchronous Initialization of BluetoothAdapter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Turned adapter_callbacks to a lazy instance. 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 | Annotate | Revision Log
« no previous file with comments | « device/bluetooth/bluetooth_adapter_win.cc ('k') | device/bluetooth/bluetooth_includes_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "device/bluetooth/bluetooth_adapter.h" 9 #include "device/bluetooth/bluetooth_adapter.h"
10 #include "device/bluetooth/bluetooth_adapter_win.h" 10 #include "device/bluetooth/bluetooth_adapter_win.h"
11 #include "device/bluetooth/bluetooth_task_manager_win.h" 11 #include "device/bluetooth/bluetooth_task_manager_win.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace { 14 namespace {
15 15
16 const char kAdapterAddress[] = "Bluetooth Adapter Address"; 16 const char kAdapterAddress[] = "Bluetooth Adapter Address";
17 const char kAdapterName[] = "Bluetooth Adapter Name"; 17 const char kAdapterName[] = "Bluetooth Adapter Name";
18 18
19 } // namespace 19 } // namespace
20 20
21 namespace device { 21 namespace device {
22 22
23 class BluetoothAdapterWinTest : public testing::Test { 23 class BluetoothAdapterWinTest : public testing::Test {
24 public: 24 public:
25 BluetoothAdapterWinTest() 25 BluetoothAdapterWinTest()
26 : adapter_(new BluetoothAdapterWin()), 26 : adapter_(new BluetoothAdapterWin(
27 adapter_win_(static_cast<BluetoothAdapterWin*>(adapter_.get())) { 27 base::Bind(&BluetoothAdapterWinTest::RunInitCallback,
28 base::Unretained(this)))),
29 adapter_win_(static_cast<BluetoothAdapterWin*>(adapter_.get())),
30 init_callback_called_(false) {
31 }
32
33 void RunInitCallback() {
34 init_callback_called_ = true;
28 } 35 }
29 36
30 protected: 37 protected:
31 scoped_refptr<BluetoothAdapter> adapter_; 38 scoped_refptr<BluetoothAdapter> adapter_;
32 BluetoothAdapterWin* adapter_win_; 39 BluetoothAdapterWin* adapter_win_;
40 bool init_callback_called_;
33 }; 41 };
34 42
35 TEST_F(BluetoothAdapterWinTest, AdapterNotPresent) { 43 TEST_F(BluetoothAdapterWinTest, AdapterNotPresent) {
36 BluetoothTaskManagerWin::AdapterState state; 44 BluetoothTaskManagerWin::AdapterState state;
37 adapter_win_->AdapterStateChanged(state); 45 adapter_win_->AdapterStateChanged(state);
38 EXPECT_FALSE(adapter_win_->IsPresent()); 46 EXPECT_FALSE(adapter_win_->IsPresent());
39 } 47 }
40 48
41 TEST_F(BluetoothAdapterWinTest, AdapterPresent) { 49 TEST_F(BluetoothAdapterWinTest, AdapterPresent) {
42 BluetoothTaskManagerWin::AdapterState state; 50 BluetoothTaskManagerWin::AdapterState state;
43 state.address = kAdapterAddress; 51 state.address = kAdapterAddress;
44 state.name = kAdapterName; 52 state.name = kAdapterName;
45 adapter_win_->AdapterStateChanged(state); 53 adapter_win_->AdapterStateChanged(state);
46 EXPECT_TRUE(adapter_win_->IsPresent()); 54 EXPECT_TRUE(adapter_win_->IsPresent());
47 } 55 }
48 56
57 TEST_F(BluetoothAdapterWinTest, AdapterInitialized) {
58 EXPECT_FALSE(adapter_win_->IsInitialized());
59 EXPECT_FALSE(init_callback_called_);
60 BluetoothTaskManagerWin::AdapterState state;
61 adapter_win_->AdapterStateChanged(state);
62 EXPECT_TRUE(adapter_win_->IsInitialized());
63 EXPECT_TRUE(init_callback_called_);
64 }
49 65
50 } // namespace device 66 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_win.cc ('k') | device/bluetooth/bluetooth_includes_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698