Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Unified Diff: content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc

Issue 2019853002: bluetooth: Use WebBluetoothDeviceId instead of string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-uuid-typemap
Patch Set: Fix build Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..d8561f7e3ec10dc60031b2a83b50c7cbebc1629c 100644
--- a/content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc
+++ b/content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc
@@ -5,10 +5,12 @@
#include "content/browser/bluetooth/bluetooth_allowed_devices_map.h"
#include "base/strings/string_util.h"
+#include "components/web_bluetooth/web_bluetooth_device_id.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
using device::BluetoothUUID;
+using web_bluetooth::WebBluetoothDeviceId;
namespace content {
namespace {
@@ -53,46 +55,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 +104,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 +125,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 +137,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 +153,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 +169,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 +201,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 +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 WebBluetoothDeviceId 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 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 +338,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 +399,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 +414,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 +432,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

Powered by Google App Engine
This is Rietveld 408576698