OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/bluetooth/bluetooth_allowed_devices_map.h" | 5 #include "content/browser/bluetooth/bluetooth_allowed_devices_map.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "content/common/bluetooth/bluetooth_scan_filter.h" | 8 #include "content/common/bluetooth/bluetooth_scan_filter.h" |
9 #include "device/bluetooth/bluetooth_uuid.h" | 9 #include "device/bluetooth/bluetooth_uuid.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( | 343 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
344 kTestOrigin2, device_id1, kGlucoseUUIDString)); | 344 kTestOrigin2, device_id1, kGlucoseUUIDString)); |
345 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( | 345 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
346 kTestOrigin2, device_id1, kHeartRateUUIDString)); | 346 kTestOrigin2, device_id1, kHeartRateUUIDString)); |
347 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( | 347 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
348 kTestOrigin2, device_id1, kBatteryServiceUUIDString)); | 348 kTestOrigin2, device_id1, kBatteryServiceUUIDString)); |
349 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( | 349 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
350 kTestOrigin2, device_id1, kBloodPressureUUIDString)); | 350 kTestOrigin2, device_id1, kBloodPressureUUIDString)); |
351 } | 351 } |
352 | 352 |
| 353 TEST(BluetoothAllowedDevicesMapTest, MergeServices) { |
| 354 BluetoothAllowedDevicesMap allowed_devices_map; |
| 355 |
| 356 // Setup first request. |
| 357 BluetoothScanFilter scanFilter1; |
| 358 scanFilter1.services.push_back(kGlucoseUUID); |
| 359 std::vector<BluetoothScanFilter> filters1; |
| 360 filters1.push_back(scanFilter1); |
| 361 std::vector<BluetoothUUID> optional_services1; |
| 362 optional_services1.push_back(kBatteryServiceUUID); |
| 363 |
| 364 // Add to map. |
| 365 const std::string device_id1 = allowed_devices_map.AddDevice( |
| 366 kTestOrigin1, kDeviceAddress1, filters1, optional_services1); |
| 367 |
| 368 // Setup second request. |
| 369 BluetoothScanFilter scanFilter2; |
| 370 scanFilter2.services.push_back(kHeartRateUUID); |
| 371 std::vector<BluetoothScanFilter> filters2; |
| 372 filters2.push_back(scanFilter2); |
| 373 std::vector<BluetoothUUID> optional_services2; |
| 374 optional_services2.push_back(kBloodPressureUUID); |
| 375 |
| 376 // Add to map again. |
| 377 const std::string device_id2 = allowed_devices_map.AddDevice( |
| 378 kTestOrigin1, kDeviceAddress1, filters2, optional_services2); |
| 379 |
| 380 EXPECT_EQ(device_id1, device_id2); |
| 381 |
| 382 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 383 kTestOrigin1, device_id1, kGlucoseUUIDString)); |
| 384 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 385 kTestOrigin1, device_id1, kBatteryServiceUUIDString)); |
| 386 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 387 kTestOrigin1, device_id1, kHeartRateUUIDString)); |
| 388 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 389 kTestOrigin1, device_id1, kBloodPressureUUIDString)); |
| 390 } |
| 391 |
353 TEST(BluetoothAllowedDevicesMapTest, CorrectIdFormat) { | 392 TEST(BluetoothAllowedDevicesMapTest, CorrectIdFormat) { |
354 BluetoothAllowedDevicesMap allowed_devices_map; | 393 BluetoothAllowedDevicesMap allowed_devices_map; |
355 | 394 |
356 const std::string& device_id = allowed_devices_map.AddDevice( | 395 const std::string& device_id = allowed_devices_map.AddDevice( |
357 kTestOrigin1, kDeviceAddress1, kEmptyFilters, kEmptyOptionalServices); | 396 kTestOrigin1, kDeviceAddress1, kEmptyFilters, kEmptyOptionalServices); |
358 | 397 |
359 EXPECT_TRUE(device_id.size() == 24) | 398 EXPECT_TRUE(device_id.size() == 24) |
360 << "Expected Lenghth of a 128bit string encoded to Base64."; | 399 << "Expected Lenghth of a 128bit string encoded to Base64."; |
361 EXPECT_TRUE((device_id[22] == '=') && (device_id[23] == '=')) | 400 EXPECT_TRUE((device_id[22] == '=') && (device_id[23] == '=')) |
362 << "Expected padding characters for a 128bit string encoded to Base64."; | 401 << "Expected padding characters for a 128bit string encoded to Base64."; |
363 } | 402 } |
364 | 403 |
365 } // namespace content | 404 } // namespace content |
OLD | NEW |