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

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

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

Powered by Google App Engine
This is Rietveld 408576698