| Index: content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc
|
| diff --git a/content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc b/content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc
|
| index 58b98d96793fcbdd4e850941c2d158870727bc3a..bb656a1bfc6ef9fbc970c07b2a208342aae48351 100644
|
| --- a/content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc
|
| +++ b/content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc
|
| @@ -5,6 +5,7 @@
|
| #include "content/browser/bluetooth/bluetooth_allowed_devices_map.h"
|
|
|
| #include "base/strings/string_util.h"
|
| +#include "content/common/bluetooth/bluetooth_device_id.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "url/gurl.h"
|
|
|
| @@ -53,46 +54,50 @@ TEST_F(BluetoothAllowedDevicesMapTest, UniqueOriginNotSupported) {
|
| TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMap) {
|
| BluetoothAllowedDevicesMap allowed_devices_map;
|
|
|
| - const std::string& device_id = allowed_devices_map.AddDevice(
|
| + const BluetoothDeviceId& device_id = allowed_devices_map.AddDevice(
|
| kTestOrigin1, kDeviceAddress1, empty_options_);
|
|
|
| // Test that we can retrieve the device address/id.
|
| - EXPECT_EQ(device_id,
|
| - allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1));
|
| + EXPECT_EQ(
|
| + device_id,
|
| + allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1).value());
|
| EXPECT_EQ(kDeviceAddress1,
|
| allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id));
|
| }
|
|
|
| TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMapTwice) {
|
| BluetoothAllowedDevicesMap allowed_devices_map;
|
| - const std::string& device_id1 = allowed_devices_map.AddDevice(
|
| + const BluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice(
|
| kTestOrigin1, kDeviceAddress1, empty_options_);
|
| - const std::string& device_id2 = allowed_devices_map.AddDevice(
|
| + const BluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice(
|
| kTestOrigin1, kDeviceAddress1, empty_options_);
|
|
|
| EXPECT_EQ(device_id1, device_id2);
|
|
|
| // Test that we can retrieve the device address/id.
|
| - EXPECT_EQ(device_id1,
|
| - allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1));
|
| + EXPECT_EQ(
|
| + device_id1,
|
| + allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1).value());
|
| EXPECT_EQ(kDeviceAddress1,
|
| allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1));
|
| }
|
|
|
| TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromSameOriginToMap) {
|
| BluetoothAllowedDevicesMap allowed_devices_map;
|
| - const std::string& device_id1 = allowed_devices_map.AddDevice(
|
| + const BluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice(
|
| kTestOrigin1, kDeviceAddress1, empty_options_);
|
| - const std::string& device_id2 = allowed_devices_map.AddDevice(
|
| + const BluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice(
|
| kTestOrigin1, kDeviceAddress2, empty_options_);
|
|
|
| EXPECT_NE(device_id1, device_id2);
|
|
|
| // Test that we can retrieve the device address/id.
|
| - EXPECT_EQ(device_id1,
|
| - allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1));
|
| - EXPECT_EQ(device_id2,
|
| - allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2));
|
| + EXPECT_EQ(
|
| + device_id1,
|
| + allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1).value());
|
| + EXPECT_EQ(
|
| + device_id2,
|
| + allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2).value());
|
|
|
| EXPECT_EQ(kDeviceAddress1,
|
| allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1));
|
| @@ -102,19 +107,17 @@ TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromSameOriginToMap) {
|
|
|
| TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) {
|
| BluetoothAllowedDevicesMap allowed_devices_map;
|
| - const std::string& device_id1 = allowed_devices_map.AddDevice(
|
| + const BluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice(
|
| kTestOrigin1, kDeviceAddress1, empty_options_);
|
| - const std::string& device_id2 = allowed_devices_map.AddDevice(
|
| + const BluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice(
|
| kTestOrigin2, kDeviceAddress2, empty_options_);
|
|
|
| EXPECT_NE(device_id1, device_id2);
|
|
|
| // Test that the wrong origin doesn't have access to the device.
|
|
|
| - EXPECT_EQ(base::EmptyString(),
|
| - allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2));
|
| - EXPECT_EQ(base::EmptyString(),
|
| - allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress1));
|
| + EXPECT_FALSE(allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2));
|
| + EXPECT_FALSE(allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress1));
|
|
|
| EXPECT_EQ(base::EmptyString(),
|
| allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2));
|
| @@ -122,10 +125,12 @@ TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) {
|
| allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id1));
|
|
|
| // Test that we can retrieve the device address/id.
|
| - EXPECT_EQ(device_id1,
|
| - allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1));
|
| - EXPECT_EQ(device_id2,
|
| - allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress2));
|
| + EXPECT_EQ(
|
| + device_id1,
|
| + allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1).value());
|
| + EXPECT_EQ(
|
| + device_id2,
|
| + allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress2).value());
|
|
|
| EXPECT_EQ(kDeviceAddress1,
|
| allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1));
|
| @@ -135,9 +140,9 @@ TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) {
|
|
|
| TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceFromTwoOriginsToMap) {
|
| BluetoothAllowedDevicesMap allowed_devices_map;
|
| - const std::string& device_id1 = allowed_devices_map.AddDevice(
|
| + const BluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice(
|
| kTestOrigin1, kDeviceAddress1, empty_options_);
|
| - const std::string& device_id2 = allowed_devices_map.AddDevice(
|
| + const BluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice(
|
| kTestOrigin2, kDeviceAddress1, empty_options_);
|
|
|
| EXPECT_NE(device_id1, device_id2);
|
| @@ -151,12 +156,12 @@ TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceFromTwoOriginsToMap) {
|
|
|
| TEST_F(BluetoothAllowedDevicesMapTest, AddRemoveAddDeviceToMap) {
|
| BluetoothAllowedDevicesMap allowed_devices_map;
|
| - const std::string device_id_first_time = allowed_devices_map.AddDevice(
|
| + const BluetoothDeviceId device_id_first_time = allowed_devices_map.AddDevice(
|
| kTestOrigin1, kDeviceAddress1, empty_options_);
|
|
|
| allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1);
|
|
|
| - const std::string device_id_second_time = allowed_devices_map.AddDevice(
|
| + const BluetoothDeviceId device_id_second_time = allowed_devices_map.AddDevice(
|
| kTestOrigin1, kDeviceAddress1, empty_options_);
|
|
|
| EXPECT_NE(device_id_first_time, device_id_second_time);
|
| @@ -165,15 +170,14 @@ TEST_F(BluetoothAllowedDevicesMapTest, AddRemoveAddDeviceToMap) {
|
| TEST_F(BluetoothAllowedDevicesMapTest, RemoveDeviceFromMap) {
|
| BluetoothAllowedDevicesMap allowed_devices_map;
|
|
|
| - const std::string& device_id = allowed_devices_map.AddDevice(
|
| + const BluetoothDeviceId device_id = allowed_devices_map.AddDevice(
|
| kTestOrigin1, kDeviceAddress1, empty_options_);
|
|
|
| allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1);
|
|
|
| + EXPECT_FALSE(allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1));
|
| EXPECT_EQ(base::EmptyString(),
|
| - allowed_devices_map.GetDeviceId(kTestOrigin1, device_id));
|
| - EXPECT_EQ(base::EmptyString(), allowed_devices_map.GetDeviceAddress(
|
| - kTestOrigin1, kDeviceAddress1));
|
| + allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id));
|
| }
|
|
|
| TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) {
|
| @@ -197,7 +201,7 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) {
|
| options->optional_services.push_back(kHeartRateUUID);
|
|
|
| // Add to map.
|
| - const std::string device_id1 =
|
| + const BluetoothDeviceId device_id1 =
|
| allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options);
|
|
|
| // Access allowed services.
|
| @@ -229,7 +233,7 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) {
|
| options2->filters.push_back(scanFilter1.Clone());
|
| options2->filters.push_back(scanFilter2.Clone());
|
|
|
| - const std::string device_id2 =
|
| + const BluetoothDeviceId device_id2 =
|
| allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2);
|
|
|
| // Access allowed services.
|
| @@ -277,9 +281,9 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginTwoDevices) {
|
| options2->optional_services.push_back(kBloodPressureUUID);
|
|
|
| // Add devices to map.
|
| - const std::string& device_id1 =
|
| + const BluetoothDeviceId& device_id1 =
|
| allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1);
|
| - const std::string& device_id2 =
|
| + const BluetoothDeviceId& device_id2 =
|
| allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress2, options2);
|
|
|
| // Access allowed services.
|
| @@ -334,9 +338,9 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_TwoOriginsOneDevice) {
|
| options2->optional_services.push_back(kBloodPressureUUID);
|
|
|
| // Add devices to map.
|
| - const std::string& device_id1 =
|
| + const BluetoothDeviceId& device_id1 =
|
| allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1);
|
| - const std::string& device_id2 =
|
| + const BluetoothDeviceId& device_id2 =
|
| allowed_devices_map.AddDevice(kTestOrigin2, kDeviceAddress1, options2);
|
|
|
| // Access allowed services.
|
| @@ -395,7 +399,7 @@ TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) {
|
| options1->optional_services.push_back(kBatteryServiceUUID);
|
|
|
| // Add to map.
|
| - const std::string device_id1 =
|
| + const BluetoothDeviceId device_id1 =
|
| allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1);
|
|
|
| // Setup second request.
|
| @@ -410,7 +414,7 @@ TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) {
|
| options2->optional_services.push_back(kBloodPressureUUID);
|
|
|
| // Add to map again.
|
| - const std::string device_id2 =
|
| + const BluetoothDeviceId device_id2 =
|
| allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2);
|
|
|
| EXPECT_EQ(device_id1, device_id2);
|
| @@ -428,13 +432,10 @@ TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) {
|
| TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) {
|
| BluetoothAllowedDevicesMap allowed_devices_map;
|
|
|
| - const std::string& device_id = allowed_devices_map.AddDevice(
|
| + const BluetoothDeviceId& device_id = allowed_devices_map.AddDevice(
|
| kTestOrigin1, kDeviceAddress1, empty_options_);
|
|
|
| - EXPECT_TRUE(device_id.size() == 24)
|
| - << "Expected Lenghth of a 128bit string encoded to Base64.";
|
| - EXPECT_TRUE((device_id[22] == '=') && (device_id[23] == '='))
|
| - << "Expected padding characters for a 128bit string encoded to Base64.";
|
| + EXPECT_TRUE(BluetoothDeviceId::IsValid(device_id.str()));
|
| }
|
|
|
| } // namespace content
|
|
|