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 "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
9 | 12 |
| 13 #if defined(OS_ANDROID) |
| 14 #include "device/bluetooth/test/bluetooth_test_android.h" |
| 15 #endif |
| 16 |
10 namespace device { | 17 namespace device { |
11 | 18 |
12 TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_AcceptsAllValidFormats) { | 19 TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_AcceptsAllValidFormats) { |
13 // There are three valid separators (':', '-', and none). | 20 // There are three valid separators (':', '-', and none). |
14 // Case shouldn't matter. | 21 // Case shouldn't matter. |
15 const char* const kValidFormats[] = { | 22 const char* const kValidFormats[] = { |
16 "1A:2B:3C:4D:5E:6F", | 23 "1A:2B:3C:4D:5E:6F", |
17 "1a:2B:3c:4D:5e:6F", | 24 "1a:2B:3c:4D:5e:6F", |
18 "1a:2b:3c:4d:5e:6f", | 25 "1a:2b:3c:4d:5e:6f", |
19 "1A-2B-3C-4D-5E-6F", | 26 "1A-2B-3C-4D-5E-6F", |
(...skipping 29 matching lines...) Expand all Loading... |
49 "1:A2:B3:C4:D5:E6F", | 56 "1:A2:B3:C4:D5:E6F", |
50 }; | 57 }; |
51 | 58 |
52 for (size_t i = 0; i < arraysize(kValidFormats); ++i) { | 59 for (size_t i = 0; i < arraysize(kValidFormats); ++i) { |
53 SCOPED_TRACE(std::string("Input format: '") + kValidFormats[i] + "'"); | 60 SCOPED_TRACE(std::string("Input format: '") + kValidFormats[i] + "'"); |
54 EXPECT_EQ(std::string(), | 61 EXPECT_EQ(std::string(), |
55 BluetoothDevice::CanonicalizeAddress(kValidFormats[i])); | 62 BluetoothDevice::CanonicalizeAddress(kValidFormats[i])); |
56 } | 63 } |
57 } | 64 } |
58 | 65 |
| 66 #if defined(OS_ANDROID) |
| 67 // Verifies basic device properties, e.g. GetAddress, GetName, ... |
| 68 TEST_F(BluetoothTest, DeviceProperties) { |
| 69 InitWithFakeAdapter(); |
| 70 TestBluetoothAdapterObserver observer(adapter_); |
| 71 |
| 72 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), |
| 73 GetErrorCallback()); |
| 74 base::RunLoop().RunUntilIdle(); |
| 75 DiscoverLowEnergyDevice(1); |
| 76 base::RunLoop().RunUntilIdle(); |
| 77 BluetoothDevice* device = observer.last_device(); |
| 78 ASSERT_TRUE(device); |
| 79 EXPECT_EQ(0x1F00u, device->GetBluetoothClass()); |
| 80 EXPECT_EQ("A1:B2:C3:DD:DD:DD", device->GetAddress()); |
| 81 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); |
| 82 EXPECT_EQ(0, device->GetVendorID()); |
| 83 EXPECT_EQ(0, device->GetProductID()); |
| 84 EXPECT_EQ(0, device->GetDeviceID()); |
| 85 EXPECT_EQ(base::UTF8ToUTF16("FakeBluetoothDevice"), device->GetName()); |
| 86 EXPECT_EQ(true, device->IsPaired()); |
| 87 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 88 EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID("1800"))); |
| 89 EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID("1801"))); |
| 90 } |
| 91 #endif // defined(OS_ANDROID) |
| 92 |
| 93 #if defined(OS_ANDROID) |
| 94 // Device with no advertised Service UUIDs. |
| 95 TEST_F(BluetoothTest, DeviceNoUUIDs) { |
| 96 InitWithFakeAdapter(); |
| 97 TestBluetoothAdapterObserver observer(adapter_); |
| 98 |
| 99 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), |
| 100 GetErrorCallback()); |
| 101 base::RunLoop().RunUntilIdle(); |
| 102 DiscoverLowEnergyDevice(3); |
| 103 base::RunLoop().RunUntilIdle(); |
| 104 BluetoothDevice* device = observer.last_device(); |
| 105 ASSERT_TRUE(device); |
| 106 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 107 EXPECT_EQ(0u, uuids.size()); |
| 108 } |
| 109 #endif // defined(OS_ANDROID) |
| 110 |
| 111 // TODO(scheib): Test with a device with no name. http://crbug.com/506415 |
| 112 // BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which |
| 113 // requires string resources to be loaded. For that, something like |
| 114 // InitSharedInstance must be run. See unittest files that call that. It will |
| 115 // also require build configuration to generate string resources into a .pak |
| 116 // file. |
| 117 |
59 } // namespace device | 118 } // namespace device |
OLD | NEW |