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

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

Issue 180163009: chrome.bluetooth API improvements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address code review feedback, simplify threading model. Created 6 years, 9 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" 6 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
7 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" 7 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h"
8 #include "chromeos/dbus/fake_bluetooth_device_client.h" 8 #include "chromeos/dbus/fake_bluetooth_device_client.h"
9 #include "chromeos/dbus/fake_bluetooth_input_client.h" 9 #include "chromeos/dbus/fake_bluetooth_input_client.h"
10 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" 10 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 void Callback() { 83 void Callback() {
84 ++callback_count_; 84 ++callback_count_;
85 } 85 }
86 86
87 void ErrorCallback() { 87 void ErrorCallback() {
88 ++error_callback_count_; 88 ++error_callback_count_;
89 89
90 message_loop_.Quit(); 90 message_loop_.Quit();
91 } 91 }
92 92
93 void ConnectToProfileErrorCallback(const std::string error) {
94 ErrorCallback();
95 }
96
93 void ProfileCallback(BluetoothProfile* profile) { 97 void ProfileCallback(BluetoothProfile* profile) {
94 ++profile_callback_count_; 98 ++profile_callback_count_;
95 last_profile_ = profile; 99 last_profile_ = profile;
96 } 100 }
97 101
98 void ConnectionCallback(const BluetoothDevice *device, 102 void ConnectionCallback(const BluetoothDevice *device,
99 scoped_refptr<BluetoothSocket> socket) { 103 scoped_refptr<BluetoothSocket> socket) {
100 ++connection_callback_count_; 104 ++connection_callback_count_;
101 last_device_ = device; 105 last_device_ = device;
102 last_socket_ = socket; 106 last_socket_ = socket;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // connection callback to be called with the device we passed and a new 152 // connection callback to be called with the device we passed and a new
149 // socket instance. 153 // socket instance.
150 BluetoothDevice* device = adapter_->GetDevice( 154 BluetoothDevice* device = adapter_->GetDevice(
151 FakeBluetoothDeviceClient::kPairedDeviceAddress); 155 FakeBluetoothDeviceClient::kPairedDeviceAddress);
152 ASSERT_TRUE(device != NULL); 156 ASSERT_TRUE(device != NULL);
153 157
154 device->ConnectToProfile( 158 device->ConnectToProfile(
155 profile, 159 profile,
156 base::Bind(&BluetoothProfileChromeOSTest::Callback, 160 base::Bind(&BluetoothProfileChromeOSTest::Callback,
157 base::Unretained(this)), 161 base::Unretained(this)),
158 base::Bind(&BluetoothProfileChromeOSTest::ErrorCallback, 162 base::Bind(&BluetoothProfileChromeOSTest::ConnectToProfileErrorCallback,
159 base::Unretained(this))); 163 base::Unretained(this)));
160 164
161 message_loop_.Run(); 165 message_loop_.Run();
162 166
163 EXPECT_EQ(1U, callback_count_); 167 EXPECT_EQ(1U, callback_count_);
164 EXPECT_EQ(0U, error_callback_count_); 168 EXPECT_EQ(0U, error_callback_count_);
165 169
166 EXPECT_EQ(1U, connection_callback_count_); 170 EXPECT_EQ(1U, connection_callback_count_);
167 EXPECT_EQ(device, last_device_); 171 EXPECT_EQ(device, last_device_);
168 EXPECT_TRUE(last_socket_.get() != NULL); 172 EXPECT_TRUE(last_socket_.get() != NULL);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 // connection callback to be called with the device we passed and a new 278 // connection callback to be called with the device we passed and a new
275 // socket instance. 279 // socket instance.
276 BluetoothDevice* device = adapter_->GetDevice( 280 BluetoothDevice* device = adapter_->GetDevice(
277 FakeBluetoothDeviceClient::kPairedDeviceAddress); 281 FakeBluetoothDeviceClient::kPairedDeviceAddress);
278 ASSERT_TRUE(device != NULL); 282 ASSERT_TRUE(device != NULL);
279 283
280 device->ConnectToProfile( 284 device->ConnectToProfile(
281 profile, 285 profile,
282 base::Bind(&BluetoothProfileChromeOSTest::Callback, 286 base::Bind(&BluetoothProfileChromeOSTest::Callback,
283 base::Unretained(this)), 287 base::Unretained(this)),
284 base::Bind(&BluetoothProfileChromeOSTest::ErrorCallback, 288 base::Bind(&BluetoothProfileChromeOSTest::ConnectToProfileErrorCallback,
285 base::Unretained(this))); 289 base::Unretained(this)));
286 290
287 message_loop_.Run(); 291 message_loop_.Run();
288 292
289 EXPECT_EQ(1U, callback_count_); 293 EXPECT_EQ(1U, callback_count_);
290 EXPECT_EQ(0U, error_callback_count_); 294 EXPECT_EQ(0U, error_callback_count_);
291 295
292 EXPECT_EQ(1U, connection_callback_count_); 296 EXPECT_EQ(1U, connection_callback_count_);
293 EXPECT_EQ(device, last_device_); 297 EXPECT_EQ(device, last_device_);
294 EXPECT_TRUE(last_socket_.get() != NULL); 298 EXPECT_TRUE(last_socket_.get() != NULL);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 // Unregister the profile, make sure it's no longer registered. 367 // Unregister the profile, make sure it's no longer registered.
364 last_profile_->Unregister(); 368 last_profile_->Unregister();
365 369
366 profile_service_provider = 370 profile_service_provider =
367 fake_bluetooth_profile_manager_client_->GetProfileServiceProvider( 371 fake_bluetooth_profile_manager_client_->GetProfileServiceProvider(
368 FakeBluetoothProfileManagerClient::kRfcommUuid); 372 FakeBluetoothProfileManagerClient::kRfcommUuid);
369 EXPECT_TRUE(profile_service_provider == NULL); 373 EXPECT_TRUE(profile_service_provider == NULL);
370 } 374 }
371 375
372 } // namespace chromeos 376 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698