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

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

Issue 935383003: Fix BluetoothAdapterProfileChromeOS lifecycle management (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "chromeos/dbus/bluetooth_profile_service_provider.h" 7 #include "chromeos/dbus/bluetooth_profile_service_provider.h"
8 #include "chromeos/dbus/dbus_thread_manager.h" 8 #include "chromeos/dbus/dbus_thread_manager.h"
9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 new FakeBluetoothProfileManagerClient)); 56 new FakeBluetoothProfileManagerClient));
57 57
58 // Grab a pointer to the adapter. 58 // Grab a pointer to the adapter.
59 device::BluetoothAdapterFactory::GetAdapter( 59 device::BluetoothAdapterFactory::GetAdapter(
60 base::Bind(&BluetoothAdapterProfileChromeOSTest::AdapterCallback, 60 base::Bind(&BluetoothAdapterProfileChromeOSTest::AdapterCallback,
61 base::Unretained(this))); 61 base::Unretained(this)));
62 ASSERT_TRUE(adapter_.get() != nullptr); 62 ASSERT_TRUE(adapter_.get() != nullptr);
63 ASSERT_TRUE(adapter_->IsInitialized()); 63 ASSERT_TRUE(adapter_->IsInitialized());
64 ASSERT_TRUE(adapter_->IsPresent()); 64 ASSERT_TRUE(adapter_->IsPresent());
65 65
66 adapter_ptr_factory_ = new base::WeakPtrFactory<BluetoothAdapterChromeOS>(
67 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()));
68
66 // Turn on the adapter. 69 // Turn on the adapter.
67 adapter_->SetPowered(true, base::Bind(&base::DoNothing), 70 adapter_->SetPowered(true, base::Bind(&base::DoNothing),
68 base::Bind(&base::DoNothing)); 71 base::Bind(&base::DoNothing));
69 ASSERT_TRUE(adapter_->IsPowered()); 72 ASSERT_TRUE(adapter_->IsPowered());
70 } 73 }
71 74
72 void TearDown() override { 75 void TearDown() override {
73 adapter_ = nullptr; 76 adapter_ = nullptr;
74 DBusThreadManager::Shutdown(); 77 DBusThreadManager::Shutdown();
75 } 78 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 134
132 void DBusErrorCallback(const std::string& error_name, 135 void DBusErrorCallback(const std::string& error_name,
133 const std::string& error_message) { 136 const std::string& error_message) {
134 VLOG(1) << "DBus Connect Error: " << error_name << " - " << error_message; 137 VLOG(1) << "DBus Connect Error: " << error_name << " - " << error_message;
135 ++error_callback_count_; 138 ++error_callback_count_;
136 } 139 }
137 140
138 protected: 141 protected:
139 base::MessageLoop message_loop_; 142 base::MessageLoop message_loop_;
140 143
144 base::WeakPtrFactory<BluetoothAdapterChromeOS>* adapter_ptr_factory_;
141 scoped_refptr<BluetoothAdapter> adapter_; 145 scoped_refptr<BluetoothAdapter> adapter_;
142 146
143 unsigned int success_callback_count_; 147 unsigned int success_callback_count_;
144 unsigned int error_callback_count_; 148 unsigned int error_callback_count_;
145 }; 149 };
146 150
147 TEST_F(BluetoothAdapterProfileChromeOSTest, DelegateCount) { 151 TEST_F(BluetoothAdapterProfileChromeOSTest, DelegateCount) {
148 BluetoothUUID uuid(FakeBluetoothProfileManagerClient::kRfcommUuid); 152 BluetoothUUID uuid(FakeBluetoothProfileManagerClient::kRfcommUuid);
149 BluetoothProfileManagerClient::Options options; 153 BluetoothProfileManagerClient::Options options;
150 154
151 options.require_authentication.reset(new bool(false)); 155 options.require_authentication.reset(new bool(false));
152 156
153 profile_ = BluetoothAdapterProfileChromeOS::Register( 157 profile_ = BluetoothAdapterProfileChromeOS::Register(
154 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()), uuid, options, 158 adapter_ptr_factory_->GetWeakPtr(), uuid, options,
155 base::Bind(&base::DoNothing), base::Bind(&DoNothingDBusErrorCallback)); 159 base::Bind(&base::DoNothing), base::Bind(&DoNothingDBusErrorCallback));
156 160
157 message_loop_.RunUntilIdle(); 161 message_loop_.RunUntilIdle();
158 162
159 EXPECT_TRUE(profile_); 163 EXPECT_TRUE(profile_);
160 164
161 EXPECT_EQ(0U, profile_->DelegateCount()); 165 EXPECT_EQ(0U, profile_->DelegateCount());
162 166
163 profile_->SetDelegate(fake_delegate_paired_.device_path_, 167 profile_->SetDelegate(fake_delegate_paired_.device_path_,
164 &fake_delegate_paired_); 168 &fake_delegate_paired_);
(...skipping 13 matching lines...) Expand all
178 delete profile_; 182 delete profile_;
179 }; 183 };
180 184
181 TEST_F(BluetoothAdapterProfileChromeOSTest, BlackHole) { 185 TEST_F(BluetoothAdapterProfileChromeOSTest, BlackHole) {
182 BluetoothUUID uuid(FakeBluetoothProfileManagerClient::kRfcommUuid); 186 BluetoothUUID uuid(FakeBluetoothProfileManagerClient::kRfcommUuid);
183 BluetoothProfileManagerClient::Options options; 187 BluetoothProfileManagerClient::Options options;
184 188
185 options.require_authentication.reset(new bool(false)); 189 options.require_authentication.reset(new bool(false));
186 190
187 profile_ = BluetoothAdapterProfileChromeOS::Register( 191 profile_ = BluetoothAdapterProfileChromeOS::Register(
188 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()), uuid, options, 192 adapter_ptr_factory_->GetWeakPtr(), uuid, options,
189 base::Bind( 193 base::Bind(
190 &BluetoothAdapterProfileChromeOSTest::DBusConnectSuccessCallback, 194 &BluetoothAdapterProfileChromeOSTest::DBusConnectSuccessCallback,
191 base::Unretained(this)), 195 base::Unretained(this)),
192 base::Bind(&BluetoothAdapterProfileChromeOSTest::DBusErrorCallback, 196 base::Bind(&BluetoothAdapterProfileChromeOSTest::DBusErrorCallback,
193 base::Unretained(this))); 197 base::Unretained(this)));
194 198
195 message_loop_.RunUntilIdle(); 199 message_loop_.RunUntilIdle();
196 200
197 EXPECT_TRUE(profile_); 201 EXPECT_TRUE(profile_);
198 EXPECT_EQ(1U, success_callback_count_); 202 EXPECT_EQ(1U, success_callback_count_);
(...skipping 18 matching lines...) Expand all
217 delete profile_; 221 delete profile_;
218 }; 222 };
219 223
220 TEST_F(BluetoothAdapterProfileChromeOSTest, Routing) { 224 TEST_F(BluetoothAdapterProfileChromeOSTest, Routing) {
221 BluetoothUUID uuid(FakeBluetoothProfileManagerClient::kRfcommUuid); 225 BluetoothUUID uuid(FakeBluetoothProfileManagerClient::kRfcommUuid);
222 BluetoothProfileManagerClient::Options options; 226 BluetoothProfileManagerClient::Options options;
223 227
224 options.require_authentication.reset(new bool(false)); 228 options.require_authentication.reset(new bool(false));
225 229
226 profile_ = BluetoothAdapterProfileChromeOS::Register( 230 profile_ = BluetoothAdapterProfileChromeOS::Register(
227 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()), uuid, options, 231 adapter_ptr_factory_->GetWeakPtr(), uuid, options,
228 base::Bind( 232 base::Bind(
229 &BluetoothAdapterProfileChromeOSTest::DBusConnectSuccessCallback, 233 &BluetoothAdapterProfileChromeOSTest::DBusConnectSuccessCallback,
230 base::Unretained(this)), 234 base::Unretained(this)),
231 base::Bind(&BluetoothAdapterProfileChromeOSTest::DBusErrorCallback, 235 base::Bind(&BluetoothAdapterProfileChromeOSTest::DBusErrorCallback,
232 base::Unretained(this))); 236 base::Unretained(this)));
233 237
234 message_loop_.RunUntilIdle(); 238 message_loop_.RunUntilIdle();
235 239
236 ASSERT_TRUE(profile_); 240 ASSERT_TRUE(profile_);
237 241
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 292
289 EXPECT_EQ(4U, success_callback_count_); 293 EXPECT_EQ(4U, success_callback_count_);
290 EXPECT_EQ(0U, error_callback_count_); 294 EXPECT_EQ(0U, error_callback_count_);
291 295
292 EXPECT_EQ(1U, fake_delegate_listen_.connections_); 296 EXPECT_EQ(1U, fake_delegate_listen_.connections_);
293 297
294 delete profile_; 298 delete profile_;
295 }; 299 };
296 300
297 } // namespace chromeos 301 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698