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

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

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "chromeos/dbus/fake_bluetooth_le_advertisement_service_provider.h"
14 #include "device/bluetooth/bluetooth_adapter.h" 12 #include "device/bluetooth/bluetooth_adapter.h"
15 #include "device/bluetooth/bluetooth_adapter_factory.h" 13 #include "device/bluetooth/bluetooth_adapter_factory.h"
16 #include "device/bluetooth/bluetooth_advertisement.h" 14 #include "device/bluetooth/bluetooth_advertisement.h"
17 #include "device/bluetooth/bluetooth_advertisement_chromeos.h" 15 #include "device/bluetooth/bluetooth_advertisement_chromeos.h"
16 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
17 #include "device/bluetooth/dbus/fake_bluetooth_le_advertisement_service_provider .h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using device::BluetoothAdapter; 20 using device::BluetoothAdapter;
21 using device::BluetoothAdapterFactory; 21 using device::BluetoothAdapterFactory;
22 using device::BluetoothAdvertisement; 22 using device::BluetoothAdvertisement;
23 23
24 namespace chromeos { 24 namespace chromeos {
25 25
26 class TestAdvertisementObserver : public BluetoothAdvertisement::Observer { 26 class TestAdvertisementObserver : public BluetoothAdvertisement::Observer {
27 public: 27 public:
(...skipping 17 matching lines...) Expand all
45 private: 45 private:
46 bool released_; 46 bool released_;
47 scoped_refptr<BluetoothAdvertisement> advertisement_; 47 scoped_refptr<BluetoothAdvertisement> advertisement_;
48 48
49 DISALLOW_COPY_AND_ASSIGN(TestAdvertisementObserver); 49 DISALLOW_COPY_AND_ASSIGN(TestAdvertisementObserver);
50 }; 50 };
51 51
52 class BluetoothAdvertisementChromeOSTest : public testing::Test { 52 class BluetoothAdvertisementChromeOSTest : public testing::Test {
53 public: 53 public:
54 void SetUp() override { 54 void SetUp() override {
55 DBusThreadManager::Initialize(); 55 bluez::BluezDBusManager::Initialize(NULL, true);
56 56
57 callback_count_ = 0; 57 callback_count_ = 0;
58 error_callback_count_ = 0; 58 error_callback_count_ = 0;
59 59
60 last_callback_count_ = 0; 60 last_callback_count_ = 0;
61 last_error_callback_count_ = 0; 61 last_error_callback_count_ = 0;
62 62
63 last_error_code_ = BluetoothAdvertisement::INVALID_ADVERTISEMENT_ERROR_CODE; 63 last_error_code_ = BluetoothAdvertisement::INVALID_ADVERTISEMENT_ERROR_CODE;
64 64
65 GetAdapter(); 65 GetAdapter();
66 } 66 }
67 67
68 void TearDown() override { 68 void TearDown() override {
69 observer_.reset(); 69 observer_.reset();
70 // The adapter should outlive the advertisement. 70 // The adapter should outlive the advertisement.
71 advertisement_ = nullptr; 71 advertisement_ = nullptr;
72 adapter_ = nullptr; 72 adapter_ = nullptr;
73 DBusThreadManager::Shutdown(); 73 bluez::BluezDBusManager::Shutdown();
74 } 74 }
75 75
76 // Gets the existing Bluetooth adapter. 76 // Gets the existing Bluetooth adapter.
77 void GetAdapter() { 77 void GetAdapter() {
78 BluetoothAdapterFactory::GetAdapter( 78 BluetoothAdapterFactory::GetAdapter(
79 base::Bind(&BluetoothAdvertisementChromeOSTest::GetAdapterCallback, 79 base::Bind(&BluetoothAdvertisementChromeOSTest::GetAdapterCallback,
80 base::Unretained(this))); 80 base::Unretained(this)));
81 } 81 }
82 82
83 // Called whenever BluetoothAdapter is retrieved successfully. 83 // Called whenever BluetoothAdapter is retrieved successfully.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 base::Bind( 127 base::Bind(
128 &BluetoothAdvertisementChromeOSTest::AdvertisementErrorCallback, 128 &BluetoothAdvertisementChromeOSTest::AdvertisementErrorCallback,
129 base::Unretained(this))); 129 base::Unretained(this)));
130 130
131 message_loop_.RunUntilIdle(); 131 message_loop_.RunUntilIdle();
132 } 132 }
133 133
134 void TriggerReleased(scoped_refptr<BluetoothAdvertisement> advertisement) { 134 void TriggerReleased(scoped_refptr<BluetoothAdvertisement> advertisement) {
135 BluetoothAdvertisementChromeOS* adv = 135 BluetoothAdvertisementChromeOS* adv =
136 static_cast<BluetoothAdvertisementChromeOS*>(advertisement.get()); 136 static_cast<BluetoothAdvertisementChromeOS*>(advertisement.get());
137 FakeBluetoothLEAdvertisementServiceProvider* provider = 137 bluez::FakeBluetoothLEAdvertisementServiceProvider* provider =
138 static_cast<FakeBluetoothLEAdvertisementServiceProvider*>( 138 static_cast<bluez::FakeBluetoothLEAdvertisementServiceProvider*>(
139 adv->provider()); 139 adv->provider());
140 provider->Release(); 140 provider->Release();
141 } 141 }
142 142
143 // Called whenever RegisterAdvertisement is completed successfully. 143 // Called whenever RegisterAdvertisement is completed successfully.
144 void RegisterCallback(scoped_refptr<BluetoothAdvertisement> advertisement) { 144 void RegisterCallback(scoped_refptr<BluetoothAdvertisement> advertisement) {
145 ++callback_count_; 145 ++callback_count_;
146 advertisement_ = advertisement; 146 advertisement_ = advertisement;
147 147
148 ASSERT_NE(advertisement_.get(), nullptr); 148 ASSERT_NE(advertisement_.get(), nullptr);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 TriggerReleased(advertisement); 233 TriggerReleased(advertisement);
234 EXPECT_TRUE(observer_->released()); 234 EXPECT_TRUE(observer_->released());
235 235
236 // Unregistering an advertisement that has been released should give us an 236 // Unregistering an advertisement that has been released should give us an
237 // error. 237 // error.
238 UnregisterAdvertisement(advertisement); 238 UnregisterAdvertisement(advertisement);
239 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_DOES_NOT_EXIST); 239 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_DOES_NOT_EXIST);
240 } 240 }
241 241
242 } // namespace chromeos 242 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_advertisement_chromeos.cc ('k') | device/bluetooth/bluetooth_audio_sink_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698