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

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

Issue 2037173003: Notify the BluetoothAdapter::Observer when a bluetooth peripheral disconnects on Android and Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 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
« no previous file with comments | « device/bluetooth/bluetooth_device.cc ('k') | device/bluetooth/bluez/bluetooth_adapter_bluez.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 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 151 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
152 GetConnectErrorCallback(Call::NOT_EXPECTED)); 152 GetConnectErrorCallback(Call::NOT_EXPECTED));
153 SimulateGattConnection(device); 153 SimulateGattConnection(device);
154 ASSERT_EQ(1u, gatt_connections_.size()); 154 ASSERT_EQ(1u, gatt_connections_.size());
155 EXPECT_TRUE(device->IsGattConnected()); 155 EXPECT_TRUE(device->IsGattConnected());
156 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); 156 EXPECT_TRUE(gatt_connections_[0]->IsConnected());
157 } 157 }
158 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 158 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
159 159
160 #if defined(OS_ANDROID) || defined(OS_MACOSX) 160 #if defined(OS_ANDROID) || defined(OS_MACOSX)
161 TEST_F(BluetoothTest, DisconnectionNotifiesDeviceChanged) {
162 if (!PlatformSupportsLowEnergy()) {
163 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
164 return;
165 }
166 InitWithFakeAdapter();
167 TestBluetoothAdapterObserver observer(adapter_);
168 StartLowEnergyDiscoverySession();
169 BluetoothDevice* device = SimulateLowEnergyDevice(3);
170 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
171 GetConnectErrorCallback(Call::NOT_EXPECTED));
172 SimulateGattConnection(device);
173 EXPECT_EQ(1, observer.device_changed_count());
174 EXPECT_TRUE(device->IsConnected());
175 EXPECT_TRUE(device->IsGattConnected());
176
177 SimulateGattDisconnection(device);
178 EXPECT_EQ(2, observer.device_changed_count());
179 EXPECT_FALSE(device->IsConnected());
180 EXPECT_FALSE(device->IsGattConnected());
181 }
182 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
183
184 #if defined(OS_ANDROID) || defined(OS_MACOSX)
161 // Creates BluetoothGattConnection instances and tests that the interface 185 // Creates BluetoothGattConnection instances and tests that the interface
162 // functions even when some Disconnect and the BluetoothDevice is destroyed. 186 // functions even when some Disconnect and the BluetoothDevice is destroyed.
163 TEST_F(BluetoothTest, BluetoothGattConnection) { 187 TEST_F(BluetoothTest, BluetoothGattConnection) {
164 if (!PlatformSupportsLowEnergy()) { 188 if (!PlatformSupportsLowEnergy()) {
165 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 189 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
166 return; 190 return;
167 } 191 }
168 InitWithFakeAdapter(); 192 InitWithFakeAdapter();
169 StartLowEnergyDiscoverySession(); 193 StartLowEnergyDiscoverySession();
170 BluetoothDevice* device = SimulateLowEnergyDevice(3); 194 BluetoothDevice* device = SimulateLowEnergyDevice(3);
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 ResetEventCounts(); 635 ResetEventCounts();
612 SimulateGattConnection(device); 636 SimulateGattConnection(device);
613 EXPECT_EQ(1, gatt_discovery_attempts_); 637 EXPECT_EQ(1, gatt_discovery_attempts_);
614 638
615 SimulateGattServicesDiscoveryError(device); 639 SimulateGattServicesDiscoveryError(device);
616 EXPECT_EQ(0u, device->GetGattServices().size()); 640 EXPECT_EQ(0u, device->GetGattServices().size());
617 } 641 }
618 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 642 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
619 643
620 } // namespace device 644 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_device.cc ('k') | device/bluetooth/bluez/bluetooth_adapter_bluez.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698