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

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

Issue 1256313002: bluetooth: android: Implement & test CreateGattConnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated patchset dependency Created 5 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "device/bluetooth/bluetooth_device.h" 5 #include "device/bluetooth/bluetooth_device.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 10 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 118 }
119 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 119 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
120 120
121 // TODO(scheib): Test with a device with no name. http://crbug.com/506415 121 // TODO(scheib): Test with a device with no name. http://crbug.com/506415
122 // BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which 122 // BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which
123 // requires string resources to be loaded. For that, something like 123 // requires string resources to be loaded. For that, something like
124 // InitSharedInstance must be run. See unittest files that call that. It will 124 // InitSharedInstance must be run. See unittest files that call that. It will
125 // also require build configuration to generate string resources into a .pak 125 // also require build configuration to generate string resources into a .pak
126 // file. 126 // file.
127 127
128 #if defined(OS_ANDROID)
129 // Basic CreateGattConnection test.
130 TEST_F(BluetoothTest, CreateGattConnection) {
131 InitWithFakeAdapter();
132 TestBluetoothAdapterObserver observer(adapter_);
133
134 // Get a device.
135 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(),
136 GetErrorCallback());
137 base::RunLoop().RunUntilIdle();
138 DiscoverLowEnergyDevice(3);
139 base::RunLoop().RunUntilIdle();
140 BluetoothDevice* device = observer.last_device();
141
142 callback_count_ = error_callback_count_ = 0;
143 device->CreateGattConnection(GetGattConnectionCallback(),
Jeffrey Yasskin 2015/08/20 21:35:14 Can we also see some more complex interleavings of
scheib 2015/09/13 02:41:01 Done.
144 GetConnectErrorCallback());
145 CompleteGattConnection(device);
146 EXPECT_EQ(1, callback_count_--);
Jeffrey Yasskin 2015/08/20 21:35:14 I'd rather assign callback_count_ on a separate li
scheib 2015/09/13 02:41:01 I think this makes the test harder to read, but OK
147 EXPECT_EQ(0, error_callback_count_);
148 ASSERT_EQ(1u, gatt_connections_.size());
149 EXPECT_TRUE(device->IsGattConnected());
150
151 // Connect again once already connected.
152 device->CreateGattConnection(GetGattConnectionCallback(),
153 GetConnectErrorCallback());
154 EXPECT_EQ(1, callback_count_--);
155 EXPECT_EQ(0, error_callback_count_);
156 ASSERT_EQ(2u, gatt_connections_.size());
157 }
158 #endif // defined(OS_ANDROID)
159
128 } // namespace device 160 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698