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

Side by Side Diff: device/bluetooth/dbus/fake_bluetooth_device_client.cc

Issue 2783733002: Bluetooth: Add service data unit tests for chromeos (Closed)
Patch Set: comments and rebase Created 3 years, 8 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 "device/bluetooth/dbus/fake_bluetooth_device_client.h" 5 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <sys/socket.h> 9 #include <sys/socket.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 if (iter == properties_map_.end()) { 1544 if (iter == properties_map_.end()) {
1545 VLOG(2) << "Fake device does not exist: " << object_path.value(); 1545 VLOG(2) << "Fake device does not exist: " << object_path.value();
1546 return; 1546 return;
1547 } 1547 }
1548 Properties* properties = iter->second.get(); 1548 Properties* properties = iter->second.get();
1549 DCHECK(properties); 1549 DCHECK(properties);
1550 properties->rssi.set_valid(true); 1550 properties->rssi.set_valid(true);
1551 properties->rssi.ReplaceValue(rssi); 1551 properties->rssi.ReplaceValue(rssi);
1552 } 1552 }
1553 1553
1554 void FakeBluetoothDeviceClient::UpdateServiceData(
1555 const dbus::ObjectPath& object_path,
1556 const std::unordered_map<std::string, std::vector<uint8_t>>& service_data) {
1557 PropertiesMap::const_iterator iter = properties_map_.find(object_path);
1558 if (iter == properties_map_.end()) {
1559 VLOG(2) << "Fake device does not exist: " << object_path.value();
1560 return;
1561 }
1562 Properties* properties = iter->second.get();
1563 DCHECK(properties);
1564 properties->service_data.set_valid(true);
1565
1566 // BlueZ caches all the previously received advertisements. To mimic BlueZ
1567 // caching behavior, merge the new data here with the existing data.
1568 // TODO(crbug.com/707039): once the BlueZ caching behavior is changed, this
1569 // needs to be updated as well.
1570 std::unordered_map<std::string, std::vector<uint8_t>> merged_data =
1571 service_data;
1572 merged_data.insert(properties->service_data.value().begin(),
1573 properties->service_data.value().end());
1574 properties->service_data.ReplaceValue(merged_data);
1575 }
1576
1554 void FakeBluetoothDeviceClient::UpdateConnectionInfo( 1577 void FakeBluetoothDeviceClient::UpdateConnectionInfo(
1555 uint16_t connection_rssi, 1578 uint16_t connection_rssi,
1556 uint16_t transmit_power, 1579 uint16_t transmit_power,
1557 uint16_t max_transmit_power) { 1580 uint16_t max_transmit_power) {
1558 connection_rssi_ = connection_rssi; 1581 connection_rssi_ = connection_rssi;
1559 transmit_power_ = transmit_power; 1582 transmit_power_ = transmit_power;
1560 max_transmit_power_ = max_transmit_power; 1583 max_transmit_power_ = max_transmit_power;
1561 } 1584 }
1562 1585
1563 void FakeBluetoothDeviceClient::PinCodeCallback( 1586 void FakeBluetoothDeviceClient::PinCodeCallback(
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 void FakeBluetoothDeviceClient::RemoveAllDevices() { 1791 void FakeBluetoothDeviceClient::RemoveAllDevices() {
1769 device_list_.clear(); 1792 device_list_.clear();
1770 } 1793 }
1771 1794
1772 void FakeBluetoothDeviceClient::CreateTestDevice( 1795 void FakeBluetoothDeviceClient::CreateTestDevice(
1773 const dbus::ObjectPath& adapter_path, 1796 const dbus::ObjectPath& adapter_path,
1774 const base::Optional<std::string> name, 1797 const base::Optional<std::string> name,
1775 const std::string alias, 1798 const std::string alias,
1776 const std::string device_address, 1799 const std::string device_address,
1777 const std::vector<std::string>& service_uuids, 1800 const std::vector<std::string>& service_uuids,
1778 device::BluetoothTransport type) { 1801 device::BluetoothTransport type,
1802 const std::unordered_map<std::string, std::vector<uint8_t>>& service_data) {
1779 // Create a random device path. 1803 // Create a random device path.
1780 dbus::ObjectPath device_path; 1804 dbus::ObjectPath device_path;
1781 std::string id; 1805 std::string id;
1782 do { 1806 do {
1783 // Construct an id that is valid according to the DBUS specification. 1807 // Construct an id that is valid according to the DBUS specification.
1784 base::Base64Encode(base::RandBytesAsString(10), &id); 1808 base::Base64Encode(base::RandBytesAsString(10), &id);
1785 base::RemoveChars(id, "+/=", &id); 1809 base::RemoveChars(id, "+/=", &id);
1786 device_path = dbus::ObjectPath(adapter_path.value() + "/dev" + id); 1810 device_path = dbus::ObjectPath(adapter_path.value() + "/dev" + id);
1787 } while (std::find(device_list_.begin(), device_list_.end(), device_path) != 1811 } while (std::find(device_list_.begin(), device_list_.end(), device_path) !=
1788 device_list_.end()); 1812 device_list_.end());
(...skipping 22 matching lines...) Expand all
1811 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeLe); 1835 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeLe);
1812 break; 1836 break;
1813 case device::BLUETOOTH_TRANSPORT_DUAL: 1837 case device::BLUETOOTH_TRANSPORT_DUAL:
1814 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeDual); 1838 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeDual);
1815 break; 1839 break;
1816 default: 1840 default:
1817 NOTREACHED(); 1841 NOTREACHED();
1818 } 1842 }
1819 properties->type.set_valid(true); 1843 properties->type.set_valid(true);
1820 1844
1845 if (!service_data.empty()) {
1846 properties->service_data.ReplaceValue(service_data);
1847 properties->service_data.set_valid(true);
1848 }
1849
1821 properties_map_.insert(std::make_pair(device_path, std::move(properties))); 1850 properties_map_.insert(std::make_pair(device_path, std::move(properties)));
1822 device_list_.push_back(device_path); 1851 device_list_.push_back(device_path);
1823 for (auto& observer : observers_) 1852 for (auto& observer : observers_)
1824 observer.DeviceAdded(device_path); 1853 observer.DeviceAdded(device_path);
1825 } 1854 }
1826 1855
1827 } // namespace bluez 1856 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698