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..1c4b18ebbcd34908dd1c850d7904e1a690122791 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/web_bluetooth_device_id.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "url/gurl.h" |
@@ -53,46 +54,46 @@ TEST_F(BluetoothAllowedDevicesMapTest, UniqueOriginNotSupported) { |
TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMap) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
- const std::string& device_id = allowed_devices_map.AddDevice( |
+ const WebBluetoothDeviceId& 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)); |
+ *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); |
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 WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice( |
kTestOrigin1, kDeviceAddress1, empty_options_); |
- const std::string& device_id2 = allowed_devices_map.AddDevice( |
+ const WebBluetoothDeviceId& 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)); |
+ *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); |
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 WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice( |
kTestOrigin1, kDeviceAddress1, empty_options_); |
- const std::string& device_id2 = allowed_devices_map.AddDevice( |
+ const WebBluetoothDeviceId& 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)); |
+ *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); |
EXPECT_EQ(device_id2, |
- allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2)); |
+ *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2)); |
EXPECT_EQ(kDeviceAddress1, |
allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); |
@@ -102,18 +103,18 @@ TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromSameOriginToMap) { |
TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
- const std::string& device_id1 = allowed_devices_map.AddDevice( |
+ const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice( |
kTestOrigin1, kDeviceAddress1, empty_options_); |
- const std::string& device_id2 = allowed_devices_map.AddDevice( |
+ const WebBluetoothDeviceId& 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(), |
+ EXPECT_EQ(nullptr, |
allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2)); |
- EXPECT_EQ(base::EmptyString(), |
+ EXPECT_EQ(nullptr, |
allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress1)); |
EXPECT_EQ(base::EmptyString(), |
@@ -123,9 +124,9 @@ TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) { |
// Test that we can retrieve the device address/id. |
EXPECT_EQ(device_id1, |
- allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); |
+ *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); |
EXPECT_EQ(device_id2, |
- allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress2)); |
+ *allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress2)); |
EXPECT_EQ(kDeviceAddress1, |
allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); |
@@ -135,9 +136,9 @@ TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) { |
TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceFromTwoOriginsToMap) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
- const std::string& device_id1 = allowed_devices_map.AddDevice( |
+ const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice( |
kTestOrigin1, kDeviceAddress1, empty_options_); |
- const std::string& device_id2 = allowed_devices_map.AddDevice( |
+ const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice( |
kTestOrigin2, kDeviceAddress1, empty_options_); |
EXPECT_NE(device_id1, device_id2); |
@@ -151,13 +152,15 @@ TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceFromTwoOriginsToMap) { |
TEST_F(BluetoothAllowedDevicesMapTest, AddRemoveAddDeviceToMap) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
- const std::string device_id_first_time = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, empty_options_); |
+ const WebBluetoothDeviceId 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( |
- kTestOrigin1, kDeviceAddress1, empty_options_); |
+ const WebBluetoothDeviceId device_id_second_time = |
+ allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, |
+ empty_options_); |
EXPECT_NE(device_id_first_time, device_id_second_time); |
} |
@@ -165,15 +168,15 @@ TEST_F(BluetoothAllowedDevicesMapTest, AddRemoveAddDeviceToMap) { |
TEST_F(BluetoothAllowedDevicesMapTest, RemoveDeviceFromMap) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
- const std::string& device_id = allowed_devices_map.AddDevice( |
+ const WebBluetoothDeviceId device_id = allowed_devices_map.AddDevice( |
kTestOrigin1, kDeviceAddress1, empty_options_); |
allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); |
+ EXPECT_EQ(nullptr, |
+ 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 +200,7 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) { |
options->optional_services.push_back(kHeartRateUUID); |
// Add to map. |
- const std::string device_id1 = |
+ const WebBluetoothDeviceId device_id1 = |
allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options); |
// Access allowed services. |
@@ -229,7 +232,7 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) { |
options2->filters.push_back(scanFilter1.Clone()); |
options2->filters.push_back(scanFilter2.Clone()); |
- const std::string device_id2 = |
+ const WebBluetoothDeviceId device_id2 = |
allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); |
// Access allowed services. |
@@ -277,9 +280,9 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginTwoDevices) { |
options2->optional_services.push_back(kBloodPressureUUID); |
// Add devices to map. |
- const std::string& device_id1 = |
+ const WebBluetoothDeviceId& device_id1 = |
allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); |
- const std::string& device_id2 = |
+ const WebBluetoothDeviceId& device_id2 = |
allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress2, options2); |
// Access allowed services. |
@@ -334,9 +337,9 @@ TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_TwoOriginsOneDevice) { |
options2->optional_services.push_back(kBloodPressureUUID); |
// Add devices to map. |
- const std::string& device_id1 = |
+ const WebBluetoothDeviceId& device_id1 = |
allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); |
- const std::string& device_id2 = |
+ const WebBluetoothDeviceId& device_id2 = |
allowed_devices_map.AddDevice(kTestOrigin2, kDeviceAddress1, options2); |
// Access allowed services. |
@@ -395,7 +398,7 @@ TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) { |
options1->optional_services.push_back(kBatteryServiceUUID); |
// Add to map. |
- const std::string device_id1 = |
+ const WebBluetoothDeviceId device_id1 = |
allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); |
// Setup second request. |
@@ -410,7 +413,7 @@ TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) { |
options2->optional_services.push_back(kBloodPressureUUID); |
// Add to map again. |
- const std::string device_id2 = |
+ const WebBluetoothDeviceId device_id2 = |
allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); |
EXPECT_EQ(device_id1, device_id2); |
@@ -428,13 +431,10 @@ TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) { |
TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
- const std::string& device_id = allowed_devices_map.AddDevice( |
+ const WebBluetoothDeviceId& 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(WebBluetoothDeviceId::IsValid(device_id.str())); |
} |
} // namespace content |