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

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

Issue 224893002: device/bluetooth: Rename device::bluetooth_utils::UUID to device::BluetoothUUID (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « device/bluetooth/bluetooth.gyp ('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/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" 8 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
9 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" 9 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h"
10 #include "chromeos/dbus/fake_bluetooth_device_client.h" 10 #include "chromeos/dbus/fake_bluetooth_device_client.h"
11 #include "chromeos/dbus/fake_bluetooth_input_client.h" 11 #include "chromeos/dbus/fake_bluetooth_input_client.h"
12 #include "chromeos/dbus/fake_dbus_thread_manager.h" 12 #include "chromeos/dbus/fake_dbus_thread_manager.h"
13 #include "dbus/object_path.h" 13 #include "dbus/object_path.h"
14 #include "device/bluetooth/bluetooth_adapter.h" 14 #include "device/bluetooth/bluetooth_adapter.h"
15 #include "device/bluetooth/bluetooth_adapter_chromeos.h" 15 #include "device/bluetooth/bluetooth_adapter_chromeos.h"
16 #include "device/bluetooth/bluetooth_adapter_factory.h" 16 #include "device/bluetooth/bluetooth_adapter_factory.h"
17 #include "device/bluetooth/bluetooth_device.h" 17 #include "device/bluetooth/bluetooth_device.h"
18 #include "device/bluetooth/bluetooth_device_chromeos.h" 18 #include "device/bluetooth/bluetooth_device_chromeos.h"
19 #include "device/bluetooth/bluetooth_discovery_session.h" 19 #include "device/bluetooth/bluetooth_discovery_session.h"
20 #include "device/bluetooth/bluetooth_pairing_chromeos.h" 20 #include "device/bluetooth/bluetooth_pairing_chromeos.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "third_party/cros_system_api/dbus/service_constants.h" 22 #include "third_party/cros_system_api/dbus/service_constants.h"
23 23
24 using device::BluetoothAdapter; 24 using device::BluetoothAdapter;
25 using device::BluetoothAdapterFactory; 25 using device::BluetoothAdapterFactory;
26 using device::BluetoothDevice; 26 using device::BluetoothDevice;
27 using device::BluetoothDiscoverySession; 27 using device::BluetoothDiscoverySession;
28 using device::BluetoothUUID;
28 29
29 namespace chromeos { 30 namespace chromeos {
30 31
31 class TestObserver : public BluetoothAdapter::Observer { 32 class TestObserver : public BluetoothAdapter::Observer {
32 public: 33 public:
33 TestObserver(scoped_refptr<BluetoothAdapter> adapter) 34 TestObserver(scoped_refptr<BluetoothAdapter> adapter)
34 : present_changed_count_(0), 35 : present_changed_count_(0),
35 powered_changed_count_(0), 36 powered_changed_count_(0),
36 discoverable_changed_count_(0), 37 discoverable_changed_count_(0),
37 discovering_changed_count_(0), 38 discovering_changed_count_(0),
(...skipping 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 EXPECT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[0]->GetDeviceType()); 1442 EXPECT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[0]->GetDeviceType());
1442 EXPECT_TRUE(devices[0]->IsPaired()); 1443 EXPECT_TRUE(devices[0]->IsPaired());
1443 EXPECT_FALSE(devices[0]->IsConnected()); 1444 EXPECT_FALSE(devices[0]->IsConnected());
1444 EXPECT_FALSE(devices[0]->IsConnecting()); 1445 EXPECT_FALSE(devices[0]->IsConnecting());
1445 1446
1446 // Non HID devices are always connectable. 1447 // Non HID devices are always connectable.
1447 EXPECT_TRUE(devices[0]->IsConnectable()); 1448 EXPECT_TRUE(devices[0]->IsConnectable());
1448 1449
1449 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs(); 1450 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs();
1450 ASSERT_EQ(2U, uuids.size()); 1451 ASSERT_EQ(2U, uuids.size());
1451 EXPECT_EQ(uuids[0], "00001800-0000-1000-8000-00805f9b34fb"); 1452 EXPECT_EQ(uuids[0], BluetoothUUID("1800"));
1452 EXPECT_EQ(uuids[1], "00001801-0000-1000-8000-00805f9b34fb"); 1453 EXPECT_EQ(uuids[1], BluetoothUUID("1801"));
1453 1454
1454 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[0]->GetVendorIDSource()); 1455 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[0]->GetVendorIDSource());
1455 EXPECT_EQ(0x05ac, devices[0]->GetVendorID()); 1456 EXPECT_EQ(0x05ac, devices[0]->GetVendorID());
1456 EXPECT_EQ(0x030d, devices[0]->GetProductID()); 1457 EXPECT_EQ(0x030d, devices[0]->GetProductID());
1457 EXPECT_EQ(0x0306, devices[0]->GetDeviceID()); 1458 EXPECT_EQ(0x0306, devices[0]->GetDeviceID());
1458 } 1459 }
1459 1460
1460 TEST_F(BluetoothChromeOSTest, DeviceClassChanged) { 1461 TEST_F(BluetoothChromeOSTest, DeviceClassChanged) {
1461 // Simulate a change of class of a device, as sometimes occurs 1462 // Simulate a change of class of a device, as sometimes occurs
1462 // during discovery. 1463 // during discovery.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 // Simulate a change of advertised services of a device. 1517 // Simulate a change of advertised services of a device.
1517 GetAdapter(); 1518 GetAdapter();
1518 1519
1519 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 1520 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
1520 ASSERT_EQ(1U, devices.size()); 1521 ASSERT_EQ(1U, devices.size());
1521 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, 1522 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress,
1522 devices[0]->GetAddress()); 1523 devices[0]->GetAddress());
1523 1524
1524 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs(); 1525 BluetoothDevice::UUIDList uuids = devices[0]->GetUUIDs();
1525 ASSERT_EQ(2U, uuids.size()); 1526 ASSERT_EQ(2U, uuids.size());
1526 ASSERT_EQ(uuids[0], "00001800-0000-1000-8000-00805f9b34fb"); 1527 ASSERT_EQ(uuids[0], BluetoothUUID("1800"));
1527 ASSERT_EQ(uuids[1], "00001801-0000-1000-8000-00805f9b34fb"); 1528 ASSERT_EQ(uuids[1], BluetoothUUID("1801"));
1528 1529
1529 // Install an observer; expect the DeviceChanged method to be called when 1530 // Install an observer; expect the DeviceChanged method to be called when
1530 // we change the class of the device. 1531 // we change the class of the device.
1531 TestObserver observer(adapter_); 1532 TestObserver observer(adapter_);
1532 1533
1533 FakeBluetoothDeviceClient::Properties* properties = 1534 FakeBluetoothDeviceClient::Properties* properties =
1534 fake_bluetooth_device_client_->GetProperties( 1535 fake_bluetooth_device_client_->GetProperties(
1535 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath)); 1536 dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath));
1536 1537
1537 uuids.push_back("0000110c-0000-1000-8000-00805f9b34fb"); 1538 std::vector<std::string> new_uuids;
1538 uuids.push_back("0000110e-0000-1000-8000-00805f9b34fb"); 1539 new_uuids.push_back(uuids[0].canonical_value());
1539 uuids.push_back("0000110a-0000-1000-8000-00805f9b34fb"); 1540 new_uuids.push_back(uuids[1].canonical_value());
1541 new_uuids.push_back("0000110c-0000-1000-8000-00805f9b34fb");
1542 new_uuids.push_back("0000110e-0000-1000-8000-00805f9b34fb");
1543 new_uuids.push_back("0000110a-0000-1000-8000-00805f9b34fb");
1540 1544
1541 properties->uuids.ReplaceValue(uuids); 1545 properties->uuids.ReplaceValue(new_uuids);
1542 1546
1543 EXPECT_EQ(1, observer.device_changed_count_); 1547 EXPECT_EQ(1, observer.device_changed_count_);
1544 EXPECT_EQ(devices[0], observer.last_device_); 1548 EXPECT_EQ(devices[0], observer.last_device_);
1545 1549
1546 // Fetching the value should give the new one. 1550 // Fetching the value should give the new one.
1547 uuids = devices[0]->GetUUIDs(); 1551 uuids = devices[0]->GetUUIDs();
1548 ASSERT_EQ(5U, uuids.size()); 1552 ASSERT_EQ(5U, uuids.size());
1549 EXPECT_EQ(uuids[0], "00001800-0000-1000-8000-00805f9b34fb"); 1553 EXPECT_EQ(uuids[0], BluetoothUUID("1800"));
1550 EXPECT_EQ(uuids[1], "00001801-0000-1000-8000-00805f9b34fb"); 1554 EXPECT_EQ(uuids[1], BluetoothUUID("1801"));
1551 EXPECT_EQ(uuids[2], "0000110c-0000-1000-8000-00805f9b34fb"); 1555 EXPECT_EQ(uuids[2], BluetoothUUID("110c"));
1552 EXPECT_EQ(uuids[3], "0000110e-0000-1000-8000-00805f9b34fb"); 1556 EXPECT_EQ(uuids[3], BluetoothUUID("110e"));
1553 EXPECT_EQ(uuids[4], "0000110a-0000-1000-8000-00805f9b34fb"); 1557 EXPECT_EQ(uuids[4], BluetoothUUID("110a"));
1554 } 1558 }
1555 1559
1556 TEST_F(BluetoothChromeOSTest, ForgetDevice) { 1560 TEST_F(BluetoothChromeOSTest, ForgetDevice) {
1557 GetAdapter(); 1561 GetAdapter();
1558 1562
1559 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 1563 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
1560 ASSERT_EQ(1U, devices.size()); 1564 ASSERT_EQ(1U, devices.size());
1561 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, 1565 ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress,
1562 devices[0]->GetAddress()); 1566 devices[0]->GetAddress());
1563 1567
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 1697
1694 // Make sure the trusted property has been set to true. 1698 // Make sure the trusted property has been set to true.
1695 FakeBluetoothDeviceClient::Properties* properties = 1699 FakeBluetoothDeviceClient::Properties* properties =
1696 fake_bluetooth_device_client_->GetProperties( 1700 fake_bluetooth_device_client_->GetProperties(
1697 dbus::ObjectPath(FakeBluetoothDeviceClient::kConnectUnpairablePath)); 1701 dbus::ObjectPath(FakeBluetoothDeviceClient::kConnectUnpairablePath));
1698 EXPECT_TRUE(properties->trusted.value()); 1702 EXPECT_TRUE(properties->trusted.value());
1699 1703
1700 // Verify is a HID device and is not connectable. 1704 // Verify is a HID device and is not connectable.
1701 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 1705 BluetoothDevice::UUIDList uuids = device->GetUUIDs();
1702 ASSERT_EQ(1U, uuids.size()); 1706 ASSERT_EQ(1U, uuids.size());
1703 EXPECT_EQ(uuids[0], "00001124-0000-1000-8000-00805f9b34fb"); 1707 EXPECT_EQ(uuids[0], BluetoothUUID("1124"));
1704 EXPECT_FALSE(device->IsConnectable()); 1708 EXPECT_FALSE(device->IsConnectable());
1705 } 1709 }
1706 1710
1707 TEST_F(BluetoothChromeOSTest, ConnectConnectedDevice) { 1711 TEST_F(BluetoothChromeOSTest, ConnectConnectedDevice) {
1708 GetAdapter(); 1712 GetAdapter();
1709 1713
1710 BluetoothDevice* device = adapter_->GetDevice( 1714 BluetoothDevice* device = adapter_->GetDevice(
1711 FakeBluetoothDeviceClient::kPairedDeviceAddress); 1715 FakeBluetoothDeviceClient::kPairedDeviceAddress);
1712 ASSERT_TRUE(device != NULL); 1716 ASSERT_TRUE(device != NULL);
1713 ASSERT_TRUE(device->IsPaired()); 1717 ASSERT_TRUE(device->IsPaired());
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 EXPECT_EQ(device, observer.last_device_); 1887 EXPECT_EQ(device, observer.last_device_);
1884 1888
1885 EXPECT_TRUE(device->IsConnected()); 1889 EXPECT_TRUE(device->IsConnected());
1886 EXPECT_FALSE(device->IsConnecting()); 1890 EXPECT_FALSE(device->IsConnecting());
1887 1891
1888 EXPECT_TRUE(device->IsPaired()); 1892 EXPECT_TRUE(device->IsPaired());
1889 1893
1890 // Verify is a HID device and is connectable. 1894 // Verify is a HID device and is connectable.
1891 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 1895 BluetoothDevice::UUIDList uuids = device->GetUUIDs();
1892 ASSERT_EQ(1U, uuids.size()); 1896 ASSERT_EQ(1U, uuids.size());
1893 EXPECT_EQ(uuids[0], "00001124-0000-1000-8000-00805f9b34fb"); 1897 EXPECT_EQ(uuids[0], BluetoothUUID("1124"));
1894 EXPECT_TRUE(device->IsConnectable()); 1898 EXPECT_TRUE(device->IsConnectable());
1895 1899
1896 // Make sure the trusted property has been set to true. 1900 // Make sure the trusted property has been set to true.
1897 FakeBluetoothDeviceClient::Properties* properties = 1901 FakeBluetoothDeviceClient::Properties* properties =
1898 fake_bluetooth_device_client_->GetProperties( 1902 fake_bluetooth_device_client_->GetProperties(
1899 dbus::ObjectPath(FakeBluetoothDeviceClient::kLegacyAutopairPath)); 1903 dbus::ObjectPath(FakeBluetoothDeviceClient::kLegacyAutopairPath));
1900 EXPECT_TRUE(properties->trusted.value()); 1904 EXPECT_TRUE(properties->trusted.value());
1901 } 1905 }
1902 1906
1903 TEST_F(BluetoothChromeOSTest, PairDisplayPinCode) { 1907 TEST_F(BluetoothChromeOSTest, PairDisplayPinCode) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1939 EXPECT_EQ(device, observer.last_device_); 1943 EXPECT_EQ(device, observer.last_device_);
1940 1944
1941 EXPECT_TRUE(device->IsConnected()); 1945 EXPECT_TRUE(device->IsConnected());
1942 EXPECT_FALSE(device->IsConnecting()); 1946 EXPECT_FALSE(device->IsConnecting());
1943 1947
1944 EXPECT_TRUE(device->IsPaired()); 1948 EXPECT_TRUE(device->IsPaired());
1945 1949
1946 // Verify is a HID device and is connectable. 1950 // Verify is a HID device and is connectable.
1947 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 1951 BluetoothDevice::UUIDList uuids = device->GetUUIDs();
1948 ASSERT_EQ(1U, uuids.size()); 1952 ASSERT_EQ(1U, uuids.size());
1949 EXPECT_EQ(uuids[0], "00001124-0000-1000-8000-00805f9b34fb"); 1953 EXPECT_EQ(uuids[0], BluetoothUUID("1124"));
1950 EXPECT_TRUE(device->IsConnectable()); 1954 EXPECT_TRUE(device->IsConnectable());
1951 1955
1952 // Make sure the trusted property has been set to true. 1956 // Make sure the trusted property has been set to true.
1953 FakeBluetoothDeviceClient::Properties* properties = 1957 FakeBluetoothDeviceClient::Properties* properties =
1954 fake_bluetooth_device_client_->GetProperties( 1958 fake_bluetooth_device_client_->GetProperties(
1955 dbus::ObjectPath(FakeBluetoothDeviceClient::kDisplayPinCodePath)); 1959 dbus::ObjectPath(FakeBluetoothDeviceClient::kDisplayPinCodePath));
1956 EXPECT_TRUE(properties->trusted.value()); 1960 EXPECT_TRUE(properties->trusted.value());
1957 } 1961 }
1958 1962
1959 TEST_F(BluetoothChromeOSTest, PairDisplayPasskey) { 1963 TEST_F(BluetoothChromeOSTest, PairDisplayPasskey) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2015 EXPECT_EQ(device, observer.last_device_); 2019 EXPECT_EQ(device, observer.last_device_);
2016 2020
2017 EXPECT_TRUE(device->IsConnected()); 2021 EXPECT_TRUE(device->IsConnected());
2018 EXPECT_FALSE(device->IsConnecting()); 2022 EXPECT_FALSE(device->IsConnecting());
2019 2023
2020 EXPECT_TRUE(device->IsPaired()); 2024 EXPECT_TRUE(device->IsPaired());
2021 2025
2022 // Verify is a HID device. 2026 // Verify is a HID device.
2023 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 2027 BluetoothDevice::UUIDList uuids = device->GetUUIDs();
2024 ASSERT_EQ(1U, uuids.size()); 2028 ASSERT_EQ(1U, uuids.size());
2025 EXPECT_EQ(uuids[0], "00001124-0000-1000-8000-00805f9b34fb"); 2029 EXPECT_EQ(uuids[0], BluetoothUUID("1124"));
2026 2030
2027 // And usually not connectable. 2031 // And usually not connectable.
2028 EXPECT_FALSE(device->IsConnectable()); 2032 EXPECT_FALSE(device->IsConnectable());
2029 2033
2030 // Make sure the trusted property has been set to true. 2034 // Make sure the trusted property has been set to true.
2031 FakeBluetoothDeviceClient::Properties* properties = 2035 FakeBluetoothDeviceClient::Properties* properties =
2032 fake_bluetooth_device_client_->GetProperties( 2036 fake_bluetooth_device_client_->GetProperties(
2033 dbus::ObjectPath(FakeBluetoothDeviceClient::kDisplayPasskeyPath)); 2037 dbus::ObjectPath(FakeBluetoothDeviceClient::kDisplayPasskeyPath));
2034 EXPECT_TRUE(properties->trusted.value()); 2038 EXPECT_TRUE(properties->trusted.value());
2035 } 2039 }
(...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after
3161 // Unknown vendor specification identifier. 3165 // Unknown vendor specification identifier.
3162 properties->modalias.ReplaceValue("chrome:v00E0p2400d0400"); 3166 properties->modalias.ReplaceValue("chrome:v00E0p2400d0400");
3163 3167
3164 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); 3168 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource());
3165 EXPECT_EQ(0, device->GetVendorID()); 3169 EXPECT_EQ(0, device->GetVendorID());
3166 EXPECT_EQ(0, device->GetProductID()); 3170 EXPECT_EQ(0, device->GetProductID());
3167 EXPECT_EQ(0, device->GetDeviceID()); 3171 EXPECT_EQ(0, device->GetDeviceID());
3168 } 3172 }
3169 3173
3170 } // namespace chromeos 3174 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth.gyp ('k') | device/bluetooth/bluetooth_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698