OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
17 #include "device/bluetooth/bluetooth_adapter.h" | 17 #include "device/bluetooth/bluetooth_adapter.h" |
18 #include "device/bluetooth/bluetooth_adapter_factory.h" | 18 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 19 #include "device/bluetooth/bluetooth_common.h" |
19 #include "device/bluetooth/bluetooth_device.h" | 20 #include "device/bluetooth/bluetooth_device.h" |
20 #include "device/bluetooth/bluetooth_discovery_session.h" | 21 #include "device/bluetooth/bluetooth_discovery_session.h" |
21 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" | 22 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" |
22 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" | 23 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" |
23 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h" | 24 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h" |
24 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 25 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
25 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" | 26 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" |
26 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" | 27 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" |
27 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" | 28 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
28 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" | 29 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" |
(...skipping 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 EXPECT_FALSE(adapter_->IsDiscovering()); | 1435 EXPECT_FALSE(adapter_->IsDiscovering()); |
1435 } | 1436 } |
1436 | 1437 |
1437 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscovery) { | 1438 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscovery) { |
1438 // Test a simulated discovery session. | 1439 // Test a simulated discovery session. |
1439 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 1440 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
1440 GetAdapter(); | 1441 GetAdapter(); |
1441 | 1442 |
1442 TestBluetoothAdapterObserver observer(adapter_); | 1443 TestBluetoothAdapterObserver observer(adapter_); |
1443 | 1444 |
1444 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1445 BluetoothDiscoveryFilter* df = |
1445 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1446 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); |
1446 df->SetRSSI(-60); | 1447 df->SetRSSI(-60); |
1447 df->AddUUID(BluetoothUUID("1000")); | 1448 df->AddUUID(BluetoothUUID("1000")); |
1448 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); | 1449 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); |
1449 | 1450 |
1450 adapter_->SetPowered( | 1451 adapter_->SetPowered( |
1451 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), | 1452 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1452 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); | 1453 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1453 adapter_->StartDiscoverySessionWithFilter( | 1454 adapter_->StartDiscoverySessionWithFilter( |
1454 std::move(discovery_filter), | 1455 std::move(discovery_filter), |
1455 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, | 1456 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1494 EXPECT_EQ(nullptr, filter); | 1495 EXPECT_EQ(nullptr, filter); |
1495 } | 1496 } |
1496 | 1497 |
1497 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscoveryFail) { | 1498 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscoveryFail) { |
1498 // Test a simulated discovery session. | 1499 // Test a simulated discovery session. |
1499 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 1500 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
1500 GetAdapter(); | 1501 GetAdapter(); |
1501 | 1502 |
1502 TestBluetoothAdapterObserver observer(adapter_); | 1503 TestBluetoothAdapterObserver observer(adapter_); |
1503 | 1504 |
1504 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1505 BluetoothDiscoveryFilter* df = |
1505 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1506 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); |
1506 df->SetRSSI(-60); | 1507 df->SetRSSI(-60); |
1507 df->AddUUID(BluetoothUUID("1000")); | 1508 df->AddUUID(BluetoothUUID("1000")); |
1508 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); | 1509 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); |
1509 | 1510 |
1510 adapter_->SetPowered( | 1511 adapter_->SetPowered( |
1511 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), | 1512 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1512 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); | 1513 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1513 EXPECT_EQ(1, callback_count_); | 1514 EXPECT_EQ(1, callback_count_); |
1514 callback_count_ = 0; | 1515 callback_count_ = 0; |
1515 | 1516 |
(...skipping 21 matching lines...) Expand all Loading... |
1537 // This test queues two requests to StartDiscovery with pre set filter. This | 1538 // This test queues two requests to StartDiscovery with pre set filter. This |
1538 // should result in SetDiscoveryFilter, then StartDiscovery, and SetDiscovery | 1539 // should result in SetDiscoveryFilter, then StartDiscovery, and SetDiscovery |
1539 // DBus calls | 1540 // DBus calls |
1540 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscovery) { | 1541 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscovery) { |
1541 // Test a simulated discovery session. | 1542 // Test a simulated discovery session. |
1542 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 1543 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
1543 GetAdapter(); | 1544 GetAdapter(); |
1544 | 1545 |
1545 TestBluetoothAdapterObserver observer(adapter_); | 1546 TestBluetoothAdapterObserver observer(adapter_); |
1546 | 1547 |
1547 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1548 BluetoothDiscoveryFilter* df = |
1548 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1549 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); |
1549 df->SetRSSI(-60); | 1550 df->SetRSSI(-60); |
1550 df->AddUUID(BluetoothUUID("1000")); | 1551 df->AddUUID(BluetoothUUID("1000")); |
1551 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); | 1552 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); |
1552 | 1553 |
1553 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( | 1554 BluetoothDiscoveryFilter* df2 = |
1554 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); | 1555 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_CLASSIC); |
1555 df2->SetRSSI(-65); | 1556 df2->SetRSSI(-65); |
1556 df2->AddUUID(BluetoothUUID("1002")); | 1557 df2->AddUUID(BluetoothUUID("1002")); |
1557 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); | 1558 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); |
1558 | 1559 |
1559 adapter_->SetPowered( | 1560 adapter_->SetPowered( |
1560 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), | 1561 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1561 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); | 1562 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1562 | 1563 |
1563 EXPECT_EQ(1, callback_count_); | 1564 EXPECT_EQ(1, callback_count_); |
1564 EXPECT_EQ(0, error_callback_count_); | 1565 EXPECT_EQ(0, error_callback_count_); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 // Call StartFilteredDiscovery twice (2nd time while 1st call is still pending). | 1633 // Call StartFilteredDiscovery twice (2nd time while 1st call is still pending). |
1633 // Make the first SetDiscoveryFilter fail and the second one succeed. It should | 1634 // Make the first SetDiscoveryFilter fail and the second one succeed. It should |
1634 // end up with one active discovery session. | 1635 // end up with one active discovery session. |
1635 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscoveryFail) { | 1636 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscoveryFail) { |
1636 // Test a simulated discovery session. | 1637 // Test a simulated discovery session. |
1637 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); | 1638 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); |
1638 GetAdapter(); | 1639 GetAdapter(); |
1639 | 1640 |
1640 TestBluetoothAdapterObserver observer(adapter_); | 1641 TestBluetoothAdapterObserver observer(adapter_); |
1641 | 1642 |
1642 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1643 BluetoothDiscoveryFilter* df = |
1643 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1644 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); |
1644 df->SetRSSI(-60); | 1645 df->SetRSSI(-60); |
1645 df->AddUUID(BluetoothUUID("1000")); | 1646 df->AddUUID(BluetoothUUID("1000")); |
1646 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); | 1647 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); |
1647 | 1648 |
1648 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( | 1649 BluetoothDiscoveryFilter* df2 = |
1649 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); | 1650 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_CLASSIC); |
1650 df2->SetRSSI(-65); | 1651 df2->SetRSSI(-65); |
1651 df2->AddUUID(BluetoothUUID("1002")); | 1652 df2->AddUUID(BluetoothUUID("1002")); |
1652 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); | 1653 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); |
1653 | 1654 |
1654 adapter_->SetPowered( | 1655 adapter_->SetPowered( |
1655 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), | 1656 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1656 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); | 1657 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1657 | 1658 |
1658 EXPECT_EQ(1, callback_count_); | 1659 EXPECT_EQ(1, callback_count_); |
1659 EXPECT_EQ(0, error_callback_count_); | 1660 EXPECT_EQ(0, error_callback_count_); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1751 EXPECT_EQ(1, observer.discovering_changed_count()); | 1752 EXPECT_EQ(1, observer.discovering_changed_count()); |
1752 observer.Reset(); | 1753 observer.Reset(); |
1753 | 1754 |
1754 auto null_instance = std::unique_ptr<BluetoothDiscoveryFilter>(); | 1755 auto null_instance = std::unique_ptr<BluetoothDiscoveryFilter>(); |
1755 null_instance.reset(); | 1756 null_instance.reset(); |
1756 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), null_instance.get()); | 1757 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), null_instance.get()); |
1757 | 1758 |
1758 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 1759 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
1759 EXPECT_EQ(nullptr, filter); | 1760 EXPECT_EQ(nullptr, filter); |
1760 | 1761 |
1761 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1762 BluetoothDiscoveryFilter* df = |
1762 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1763 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); |
1763 df->SetRSSI(-60); | 1764 df->SetRSSI(-60); |
1764 df->AddUUID(BluetoothUUID("1000")); | 1765 df->AddUUID(BluetoothUUID("1000")); |
1765 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); | 1766 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); |
1766 | 1767 |
1767 discovery_sessions_[0]->SetDiscoveryFilter( | 1768 discovery_sessions_[0]->SetDiscoveryFilter( |
1768 std::move(discovery_filter), | 1769 std::move(discovery_filter), |
1769 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), | 1770 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
1770 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); | 1771 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
1771 | 1772 |
1772 message_loop_.Run(); | 1773 message_loop_.Run(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 EXPECT_EQ(0, error_callback_count_); | 1816 EXPECT_EQ(0, error_callback_count_); |
1816 EXPECT_TRUE(adapter_->IsPowered()); | 1817 EXPECT_TRUE(adapter_->IsPowered()); |
1817 callback_count_ = 0; | 1818 callback_count_ = 0; |
1818 | 1819 |
1819 TestBluetoothAdapterObserver observer(adapter_); | 1820 TestBluetoothAdapterObserver observer(adapter_); |
1820 | 1821 |
1821 // Request device discovery with pre-set filter 3 times. | 1822 // Request device discovery with pre-set filter 3 times. |
1822 for (int i = 0; i < 3; i++) { | 1823 for (int i = 0; i < 3; i++) { |
1823 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter; | 1824 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter; |
1824 if (i == 0) { | 1825 if (i == 0) { |
1825 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1826 BluetoothDiscoveryFilter* df = |
1826 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1827 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); |
1827 df->SetRSSI(-85); | 1828 df->SetRSSI(-85); |
1828 df->AddUUID(BluetoothUUID("1000")); | 1829 df->AddUUID(BluetoothUUID("1000")); |
1829 discovery_filter.reset(df); | 1830 discovery_filter.reset(df); |
1830 } else if (i == 1) { | 1831 } else if (i == 1) { |
1831 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1832 BluetoothDiscoveryFilter* df = |
1832 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1833 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); |
1833 df->SetRSSI(-60); | 1834 df->SetRSSI(-60); |
1834 df->AddUUID(BluetoothUUID("1020")); | 1835 df->AddUUID(BluetoothUUID("1020")); |
1835 df->AddUUID(BluetoothUUID("1001")); | 1836 df->AddUUID(BluetoothUUID("1001")); |
1836 discovery_filter.reset(df); | 1837 discovery_filter.reset(df); |
1837 } else if (i == 2) { | 1838 } else if (i == 2) { |
1838 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1839 BluetoothDiscoveryFilter* df = |
1839 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1840 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); |
1840 df->SetRSSI(-65); | 1841 df->SetRSSI(-65); |
1841 df->AddUUID(BluetoothUUID("1020")); | 1842 df->AddUUID(BluetoothUUID("1020")); |
1842 df->AddUUID(BluetoothUUID("1003")); | 1843 df->AddUUID(BluetoothUUID("1003")); |
1843 discovery_filter.reset(df); | 1844 discovery_filter.reset(df); |
1844 } | 1845 } |
1845 | 1846 |
1846 adapter_->StartDiscoverySessionWithFilter( | 1847 adapter_->StartDiscoverySessionWithFilter( |
1847 std::move(discovery_filter), | 1848 std::move(discovery_filter), |
1848 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, | 1849 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1849 base::Unretained(this)), | 1850 base::Unretained(this)), |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1939 EXPECT_FALSE(discovery_sessions_[1]->IsActive()); | 1940 EXPECT_FALSE(discovery_sessions_[1]->IsActive()); |
1940 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); | 1941 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); |
1941 | 1942 |
1942 callback_count_ = 0; | 1943 callback_count_ = 0; |
1943 | 1944 |
1944 // Request device discovery 3 times. | 1945 // Request device discovery 3 times. |
1945 for (int i = 0; i < 3; i++) { | 1946 for (int i = 0; i < 3; i++) { |
1946 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter; | 1947 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter; |
1947 | 1948 |
1948 if (i == 0) { | 1949 if (i == 0) { |
1949 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1950 BluetoothDiscoveryFilter* df = |
1950 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1951 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); |
1951 df->SetRSSI(-85); | 1952 df->SetRSSI(-85); |
1952 df->AddUUID(BluetoothUUID("1000")); | 1953 df->AddUUID(BluetoothUUID("1000")); |
1953 discovery_filter.reset(df); | 1954 discovery_filter.reset(df); |
1954 } else if (i == 1) { | 1955 } else if (i == 1) { |
1955 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1956 BluetoothDiscoveryFilter* df = |
1956 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1957 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); |
1957 df->SetRSSI(-60); | 1958 df->SetRSSI(-60); |
1958 df->AddUUID(BluetoothUUID("1020")); | 1959 df->AddUUID(BluetoothUUID("1020")); |
1959 df->AddUUID(BluetoothUUID("1001")); | 1960 df->AddUUID(BluetoothUUID("1001")); |
1960 discovery_filter.reset(df); | 1961 discovery_filter.reset(df); |
1961 } else if (i == 2) { | 1962 } else if (i == 2) { |
1962 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 1963 BluetoothDiscoveryFilter* df = |
1963 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 1964 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); |
1964 df->SetRSSI(-65); | 1965 df->SetRSSI(-65); |
1965 df->AddUUID(BluetoothUUID("1020")); | 1966 df->AddUUID(BluetoothUUID("1020")); |
1966 df->AddUUID(BluetoothUUID("1003")); | 1967 df->AddUUID(BluetoothUUID("1003")); |
1967 discovery_filter.reset(df); | 1968 discovery_filter.reset(df); |
1968 } | 1969 } |
1969 | 1970 |
1970 adapter_->StartDiscoverySessionWithFilter( | 1971 adapter_->StartDiscoverySessionWithFilter( |
1971 std::move(discovery_filter), | 1972 std::move(discovery_filter), |
1972 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, | 1973 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
1973 base::Unretained(this)), | 1974 base::Unretained(this)), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2036 } | 2037 } |
2037 | 2038 |
2038 // This unit test asserts that filter merging logic works correctly for filtered | 2039 // This unit test asserts that filter merging logic works correctly for filtered |
2039 // discovery requests done via the BluetoothAdapter. | 2040 // discovery requests done via the BluetoothAdapter. |
2040 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterMergingTest) { | 2041 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterMergingTest) { |
2041 GetAdapter(); | 2042 GetAdapter(); |
2042 adapter_->SetPowered( | 2043 adapter_->SetPowered( |
2043 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), | 2044 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), |
2044 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); | 2045 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
2045 | 2046 |
2046 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( | 2047 BluetoothDiscoveryFilter* df = |
2047 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 2048 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); |
2048 df->SetRSSI(-15); | 2049 df->SetRSSI(-15); |
2049 df->AddUUID(BluetoothUUID("1000")); | 2050 df->AddUUID(BluetoothUUID("1000")); |
2050 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); | 2051 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); |
2051 | 2052 |
2052 adapter_->StartDiscoverySessionWithFilter( | 2053 adapter_->StartDiscoverySessionWithFilter( |
2053 std::move(discovery_filter), | 2054 std::move(discovery_filter), |
2054 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, | 2055 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
2055 base::Unretained(this)), | 2056 base::Unretained(this)), |
2056 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); | 2057 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
2057 | 2058 |
2058 message_loop_.Run(); | 2059 message_loop_.Run(); |
2059 | 2060 |
2060 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 2061 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
2061 EXPECT_EQ("le", *filter->transport); | 2062 EXPECT_EQ("le", *filter->transport); |
2062 EXPECT_EQ(-15, *filter->rssi); | 2063 EXPECT_EQ(-15, *filter->rssi); |
2063 EXPECT_EQ(nullptr, filter->pathloss.get()); | 2064 EXPECT_EQ(nullptr, filter->pathloss.get()); |
2064 std::vector<std::string> uuids = *filter->uuids; | 2065 std::vector<std::string> uuids = *filter->uuids; |
2065 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); | 2066 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); |
2066 | 2067 |
2067 df = new BluetoothDiscoveryFilter( | 2068 df = new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); |
2068 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | |
2069 df->SetRSSI(-60); | 2069 df->SetRSSI(-60); |
2070 df->AddUUID(BluetoothUUID("1020")); | 2070 df->AddUUID(BluetoothUUID("1020")); |
2071 df->AddUUID(BluetoothUUID("1001")); | 2071 df->AddUUID(BluetoothUUID("1001")); |
2072 discovery_filter = std::unique_ptr<BluetoothDiscoveryFilter>(df); | 2072 discovery_filter = std::unique_ptr<BluetoothDiscoveryFilter>(df); |
2073 | 2073 |
2074 adapter_->StartDiscoverySessionWithFilter( | 2074 adapter_->StartDiscoverySessionWithFilter( |
2075 std::move(discovery_filter), | 2075 std::move(discovery_filter), |
2076 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, | 2076 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
2077 base::Unretained(this)), | 2077 base::Unretained(this)), |
2078 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); | 2078 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
2079 | 2079 |
2080 message_loop_.Run(); | 2080 message_loop_.Run(); |
2081 | 2081 |
2082 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); | 2082 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); |
2083 EXPECT_EQ("le", *filter->transport); | 2083 EXPECT_EQ("le", *filter->transport); |
2084 EXPECT_EQ(-60, *filter->rssi); | 2084 EXPECT_EQ(-60, *filter->rssi); |
2085 EXPECT_EQ(nullptr, filter->pathloss.get()); | 2085 EXPECT_EQ(nullptr, filter->pathloss.get()); |
2086 uuids = *filter->uuids; | 2086 uuids = *filter->uuids; |
2087 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); | 2087 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); |
2088 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); | 2088 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); |
2089 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); | 2089 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); |
2090 | 2090 |
2091 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter( | 2091 BluetoothDiscoveryFilter* df3 = |
2092 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); | 2092 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_CLASSIC); |
2093 df3->SetRSSI(-65); | 2093 df3->SetRSSI(-65); |
2094 df3->AddUUID(BluetoothUUID("1020")); | 2094 df3->AddUUID(BluetoothUUID("1020")); |
2095 df3->AddUUID(BluetoothUUID("1003")); | 2095 df3->AddUUID(BluetoothUUID("1003")); |
2096 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3); | 2096 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3); |
2097 | 2097 |
2098 adapter_->StartDiscoverySessionWithFilter( | 2098 adapter_->StartDiscoverySessionWithFilter( |
2099 std::move(discovery_filter3), | 2099 std::move(discovery_filter3), |
2100 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, | 2100 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, |
2101 base::Unretained(this)), | 2101 base::Unretained(this)), |
2102 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); | 2102 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); |
(...skipping 2378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4481 adapter_->Shutdown(); | 4481 adapter_->Shutdown(); |
4482 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); | 4482 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); |
4483 | 4483 |
4484 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, | 4484 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, |
4485 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. | 4485 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. |
4486 EXPECT_EQ(0, callback_count_); | 4486 EXPECT_EQ(0, callback_count_); |
4487 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); | 4487 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); |
4488 } | 4488 } |
4489 | 4489 |
4490 } // namespace bluez | 4490 } // namespace bluez |
OLD | NEW |