Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bluetooth_device.h" | 5 #include "device/bluetooth/bluetooth_device.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1476 EXPECT_EQ(BLUETOOTH_TRANSPORT_LE, device->GetType()); | 1476 EXPECT_EQ(BLUETOOTH_TRANSPORT_LE, device->GetType()); |
| 1477 | 1477 |
| 1478 BluetoothDevice* device2 = SimulateLowEnergyDevice(6); | 1478 BluetoothDevice* device2 = SimulateLowEnergyDevice(6); |
| 1479 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType()); | 1479 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType()); |
| 1480 | 1480 |
| 1481 BluetoothDevice* device3 = SimulateClassicDevice(); | 1481 BluetoothDevice* device3 = SimulateClassicDevice(); |
| 1482 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType()); | 1482 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType()); |
| 1483 } | 1483 } |
| 1484 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) | 1484 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 1485 | 1485 |
| 1486 #if defined(OS_ANDROID) || defined(OS_MACOSX) | |
| 1487 TEST_F(BluetoothTest, GetPrimaryServices) { | |
| 1488 if (!PlatformSupportsLowEnergy()) { | |
| 1489 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
| 1490 return; | |
| 1491 } | |
| 1492 InitWithFakeAdapter(); | |
| 1493 StartLowEnergyDiscoverySession(); | |
| 1494 BluetoothDevice* device = SimulateLowEnergyDevice(3); | |
| 1495 EXPECT_FALSE(device->IsConnected()); | |
| 1496 | |
| 1497 // Connect to the device | |
| 1498 ResetEventCounts(); | |
| 1499 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | |
| 1500 GetConnectErrorCallback(Call::NOT_EXPECTED)); | |
| 1501 TestBluetoothAdapterObserver observer(adapter_); | |
| 1502 SimulateGattConnection(device); | |
| 1503 base::RunLoop().RunUntilIdle(); | |
| 1504 EXPECT_TRUE(device->IsConnected()); | |
| 1505 | |
| 1506 // Discover services | |
| 1507 std::vector<std::string> services; | |
| 1508 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | |
| 1509 // 2 duplicate UUIDs creating 2 instances. | |
| 1510 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); | |
| 1511 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); | |
| 1512 SimulateGattServicesDiscovered(device, services); | |
| 1513 base::RunLoop().RunUntilIdle(); | |
| 1514 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); | |
| 1515 | |
| 1516 EXPECT_EQ(3u, device->GetPrimaryServices().size()); | |
| 1517 } | |
| 1518 | |
| 1519 TEST_F(BluetoothTest, GetPrimaryServicesByUUID) { | |
| 1520 if (!PlatformSupportsLowEnergy()) { | |
| 1521 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
| 1522 return; | |
| 1523 } | |
| 1524 InitWithFakeAdapter(); | |
| 1525 StartLowEnergyDiscoverySession(); | |
| 1526 BluetoothDevice* device = SimulateLowEnergyDevice(3); | |
| 1527 EXPECT_FALSE(device->IsConnected()); | |
| 1528 | |
| 1529 // Connect to the device | |
| 1530 ResetEventCounts(); | |
| 1531 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | |
| 1532 GetConnectErrorCallback(Call::NOT_EXPECTED)); | |
| 1533 TestBluetoothAdapterObserver observer(adapter_); | |
| 1534 SimulateGattConnection(device); | |
| 1535 base::RunLoop().RunUntilIdle(); | |
| 1536 EXPECT_TRUE(device->IsConnected()); | |
| 1537 | |
| 1538 // Discover services | |
| 1539 std::vector<std::string> services; | |
| 1540 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | |
| 1541 // 2 duplicate UUIDs creating 2 instances. | |
| 1542 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); | |
| 1543 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); | |
| 1544 SimulateGattServicesDiscovered(device, services); | |
| 1545 base::RunLoop().RunUntilIdle(); | |
| 1546 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); | |
| 1547 | |
| 1548 EXPECT_EQ( | |
| 1549 1u, device->GetPrimaryServicesByUUID(BluetoothUUID(services[0])).size()); | |
| 1550 EXPECT_EQ( | |
| 1551 2u, device->GetPrimaryServicesByUUID(BluetoothUUID(services[1])).size()); | |
| 1552 std::string service_uuid_not_exist_in_setup = | |
| 1553 "00000002-0000-1000-8000-00805f9b34fb"; | |
| 1554 EXPECT_TRUE(device | |
| 1555 ->GetPrimaryServicesByUUID( | |
| 1556 BluetoothUUID(service_uuid_not_exist_in_setup)) | |
| 1557 .empty()); | |
| 1558 } | |
| 1559 | |
| 1560 TEST_F(BluetoothTest, GetCharacteristicsByUUID) { | |
| 1561 if (!PlatformSupportsLowEnergy()) { | |
| 1562 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
| 1563 return; | |
| 1564 } | |
| 1565 InitWithFakeAdapter(); | |
| 1566 StartLowEnergyDiscoverySession(); | |
| 1567 BluetoothDevice* device = SimulateLowEnergyDevice(3); | |
| 1568 EXPECT_FALSE(device->IsConnected()); | |
| 1569 | |
| 1570 // Connect to the device | |
| 1571 ResetEventCounts(); | |
| 1572 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | |
| 1573 GetConnectErrorCallback(Call::NOT_EXPECTED)); | |
| 1574 TestBluetoothAdapterObserver observer(adapter_); | |
| 1575 SimulateGattConnection(device); | |
| 1576 base::RunLoop().RunUntilIdle(); | |
| 1577 EXPECT_TRUE(device->IsConnected()); | |
| 1578 | |
| 1579 // Discover services | |
| 1580 std::vector<std::string> services; | |
| 1581 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | |
| 1582 // 2 duplicate UUIDs creating 2 instances. | |
| 1583 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); | |
| 1584 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); | |
| 1585 SimulateGattServicesDiscovered(device, services); | |
| 1586 base::RunLoop().RunUntilIdle(); | |
| 1587 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); | |
| 1588 | |
| 1589 std::vector<BluetoothRemoteGattService*> primary_services = | |
| 1590 device->GetPrimaryServices(); | |
| 1591 | |
| 1592 std::string characteristic_uuid0 = "00000002-0000-1000-8000-00805f9b34fb"; | |
| 1593 std::string characteristic_uuid1 = "00000003-0000-1000-8000-00805f9b34fb"; | |
| 1594 SimulateGattCharacteristic(primary_services[0], characteristic_uuid0, | |
| 1595 0 /* properties */); | |
| 1596 SimulateGattCharacteristic(primary_services[1], characteristic_uuid1, | |
| 1597 0 /* properties */); | |
| 1598 SimulateGattCharacteristic(primary_services[2], characteristic_uuid1, | |
| 1599 0 /* properties */); | |
| 1600 | |
| 1601 std::string service_instance_id0 = primary_services[0]->GetIdentifier(); | |
| 1602 EXPECT_EQ(1u, | |
| 1603 device | |
| 1604 ->GetCharacteristicsByUUID(service_instance_id0, | |
| 1605 BluetoothUUID(characteristic_uuid0)) | |
| 1606 .size()); | |
| 1607 | |
| 1608 std::string service_instance_id1 = primary_services[1]->GetIdentifier(); | |
| 1609 EXPECT_EQ(1u, | |
| 1610 device | |
| 1611 ->GetCharacteristicsByUUID(service_instance_id1, | |
| 1612 BluetoothUUID(characteristic_uuid1)) | |
| 1613 .size()); | |
| 1614 | |
| 1615 std::string service_instance_id2 = primary_services[2]->GetIdentifier(); | |
| 1616 EXPECT_EQ(1u, | |
| 1617 device | |
| 1618 ->GetCharacteristicsByUUID(service_instance_id2, | |
| 1619 BluetoothUUID(characteristic_uuid1)) | |
| 1620 .size()); | |
| 1621 | |
| 1622 std::string service_instance_id_not_exist_in_setup = | |
| 1623 "01:00:00:90:1E:BE/00000004-0000-1000-8000-00805f9b34fb,0"; | |
|
scheib
2017/03/17 22:10:47
This is a platform specific service identifier (fr
juncai
2017/03/17 23:33:54
Done.
| |
| 1624 EXPECT_TRUE( | |
| 1625 device | |
| 1626 ->GetCharacteristicsByUUID(service_instance_id_not_exist_in_setup, | |
| 1627 BluetoothUUID(characteristic_uuid0)) | |
| 1628 .empty()); | |
| 1629 EXPECT_TRUE( | |
| 1630 device | |
| 1631 ->GetCharacteristicsByUUID(service_instance_id_not_exist_in_setup, | |
| 1632 BluetoothUUID(characteristic_uuid1)) | |
| 1633 .empty()); | |
| 1634 | |
| 1635 std::string characteristic_uuid_not_exist_in_setup = | |
| 1636 "00000005-0000-1000-8000-00805f9b34fb"; | |
| 1637 EXPECT_TRUE(device | |
| 1638 ->GetCharacteristicsByUUID( | |
| 1639 service_instance_id0, | |
| 1640 BluetoothUUID(characteristic_uuid_not_exist_in_setup)) | |
| 1641 .empty()); | |
| 1642 EXPECT_TRUE(device | |
| 1643 ->GetCharacteristicsByUUID( | |
| 1644 service_instance_id1, | |
| 1645 BluetoothUUID(characteristic_uuid_not_exist_in_setup)) | |
| 1646 .empty()); | |
| 1647 EXPECT_TRUE(device | |
| 1648 ->GetCharacteristicsByUUID( | |
| 1649 service_instance_id2, | |
| 1650 BluetoothUUID(characteristic_uuid_not_exist_in_setup)) | |
| 1651 .empty()); | |
| 1652 } | |
| 1653 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | |
| 1654 | |
| 1486 } // namespace device | 1655 } // namespace device |
| OLD | NEW |