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

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

Issue 1133173002: Expose TxPower for bluetooth devices during discovery (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added unittests Created 5 years, 7 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_adapter_chromeos.cc ('k') | device/bluetooth/bluetooth_device.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/memory/scoped_vector.h" 5 #include "base/memory/scoped_vector.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chromeos/dbus/dbus_thread_manager.h" 9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" 10 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
(...skipping 2186 matching lines...) Expand 10 before | Expand all | Expand 10 after
2197 // Fetching the value should give the new one. 2197 // Fetching the value should give the new one.
2198 uuids = devices[0]->GetUUIDs(); 2198 uuids = devices[0]->GetUUIDs();
2199 ASSERT_EQ(5U, uuids.size()); 2199 ASSERT_EQ(5U, uuids.size());
2200 EXPECT_EQ(uuids[0], BluetoothUUID("1800")); 2200 EXPECT_EQ(uuids[0], BluetoothUUID("1800"));
2201 EXPECT_EQ(uuids[1], BluetoothUUID("1801")); 2201 EXPECT_EQ(uuids[1], BluetoothUUID("1801"));
2202 EXPECT_EQ(uuids[2], BluetoothUUID("110c")); 2202 EXPECT_EQ(uuids[2], BluetoothUUID("110c"));
2203 EXPECT_EQ(uuids[3], BluetoothUUID("110e")); 2203 EXPECT_EQ(uuids[3], BluetoothUUID("110e"));
2204 EXPECT_EQ(uuids[4], BluetoothUUID("110a")); 2204 EXPECT_EQ(uuids[4], BluetoothUUID("110a"));
2205 } 2205 }
2206 2206
2207 TEST_F(BluetoothChromeOSTest, DeviceInquiryRSSIInvalidated) {
2208 // Simulate invalidation of inquiry RSSI of a device, as it occurs
2209 // when discovery is finished.
2210 GetAdapter();
2211
2212 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2213 ASSERT_EQ(2U, devices.size());
2214 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress,
2215 devices[0]->GetAddress());
2216
2217 FakeBluetoothDeviceClient::Properties* properties =
2218 fake_bluetooth_device_client_->GetProperties(
2219 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath));
2220
2221 // During discovery, rssi is a valid value (-75)
2222 properties->rssi.ReplaceValue(-75);
2223 properties->rssi.set_valid(true);
2224
2225 ASSERT_EQ(-75, devices[0]->GetInquiryRSSI());
2226
2227 // Install an observer; expect the DeviceChanged method to be called when
2228 // we invalidate the RSSI of the device.
2229 TestBluetoothAdapterObserver observer(adapter_);
2230
2231 // When discovery is over, the value should be invalidated.
2232 properties->rssi.set_valid(false);
2233 properties->NotifyPropertyChanged(properties->rssi.name());
2234
2235 EXPECT_EQ(1, observer.device_changed_count());
2236 EXPECT_EQ(devices[0], observer.last_device());
2237
2238 int unknown_power = BluetoothDevice::kUnknownPower;
2239 EXPECT_EQ(unknown_power, devices[0]->GetInquiryRSSI());
2240 }
2241
2242 TEST_F(BluetoothChromeOSTest, DeviceInquiryTxPowerInvalidated) {
2243 // Simulate invalidation of inquiry TxPower of a device, as it occurs
2244 // when discovery is finished.
2245 GetAdapter();
2246
2247 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2248 ASSERT_EQ(2U, devices.size());
2249 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress,
2250 devices[0]->GetAddress());
2251
2252 FakeBluetoothDeviceClient::Properties* properties =
2253 fake_bluetooth_device_client_->GetProperties(
2254 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath));
2255
2256 // During discovery, tx_power is a valid value (0)
2257 properties->tx_power.ReplaceValue(0);
2258 properties->tx_power.set_valid(true);
2259
2260 ASSERT_EQ(0, devices[0]->GetInquiryTxPower());
2261
2262 // Install an observer; expect the DeviceChanged method to be called when
2263 // we invalidate the tx_power of the device.
2264 TestBluetoothAdapterObserver observer(adapter_);
2265
2266 // When discovery is over, the value should be invalidated.
2267 properties->tx_power.set_valid(false);
2268 properties->NotifyPropertyChanged(properties->tx_power.name());
2269
2270 EXPECT_EQ(1, observer.device_changed_count());
2271 EXPECT_EQ(devices[0], observer.last_device());
2272
2273 int unknown_power = BluetoothDevice::kUnknownPower;
2274 EXPECT_EQ(unknown_power, devices[0]->GetInquiryTxPower());
2275 }
2276
2207 TEST_F(BluetoothChromeOSTest, ForgetDevice) { 2277 TEST_F(BluetoothChromeOSTest, ForgetDevice) {
2208 GetAdapter(); 2278 GetAdapter();
2209 2279
2210 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2280 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2211 ASSERT_EQ(2U, devices.size()); 2281 ASSERT_EQ(2U, devices.size());
2212 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, 2282 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress,
2213 devices[0]->GetAddress()); 2283 devices[0]->GetAddress());
2214 2284
2215 std::string address = devices[0]->GetAddress(); 2285 std::string address = devices[0]->GetAddress();
2216 2286
(...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after
4059 adapter_->Shutdown(); 4129 adapter_->Shutdown();
4060 adapter_chrome_os->OnStopDiscoveryError(GetErrorCallback(), "", ""); 4130 adapter_chrome_os->OnStopDiscoveryError(GetErrorCallback(), "", "");
4061 4131
4062 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, 4132 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError,
4063 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. 4133 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession.
4064 EXPECT_EQ(0, callback_count_); 4134 EXPECT_EQ(0, callback_count_);
4065 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); 4135 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_);
4066 } 4136 }
4067 4137
4068 } // namespace chromeos 4138 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_chromeos.cc ('k') | device/bluetooth/bluetooth_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698