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 925d1a1393f6f1b71027714da501aa7354da4c09..eab3493fa4ca6be7d17cdd5ec6cd8fe8fdecd8ab 100644 |
--- a/content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc |
+++ b/content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc |
@@ -5,8 +5,6 @@ |
#include "content/browser/bluetooth/bluetooth_allowed_devices_map.h" |
#include "base/strings/string_util.h" |
-#include "content/common/bluetooth/bluetooth_scan_filter.h" |
-#include "device/bluetooth/bluetooth_uuid.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "url/gurl.h" |
@@ -20,28 +18,38 @@ const url::Origin kTestOrigin2(GURL("https://www.example2.com")); |
const std::string kDeviceAddress1 = "00:00:00"; |
const std::string kDeviceAddress2 = "11:11:11"; |
-const char kGlucoseUUIDString[] = "00001808-0000-1000-8000-00805f9b34fb"; |
-const char kHeartRateUUIDString[] = "0000180d-0000-1000-8000-00805f9b34fb"; |
-const char kBatteryServiceUUIDString[] = "0000180f-0000-1000-8000-00805f9b34fb"; |
-const char kBloodPressureUUIDString[] = "00001813-0000-1000-8000-00805f9b34fb"; |
-const char kCyclingPowerUUIDString[] = "00001818-0000-1000-8000-00805f9b34fb"; |
-const BluetoothUUID kGlucoseUUID(kGlucoseUUIDString); |
-const BluetoothUUID kHeartRateUUID(kHeartRateUUIDString); |
-const BluetoothUUID kBatteryServiceUUID(kBatteryServiceUUIDString); |
-const BluetoothUUID kBloodPressureUUID(kBloodPressureUUIDString); |
-const BluetoothUUID kCyclingPowerUUID(kCyclingPowerUUIDString); |
- |
-const std::vector<content::BluetoothScanFilter> kEmptyFilters = |
- std::vector<BluetoothScanFilter>(); |
-const std::vector<device::BluetoothUUID> kEmptyOptionalServices = |
- std::vector<device::BluetoothUUID>(); |
+const char kGlucoseUUID[] = "00001808-0000-1000-8000-00805f9b34fb"; |
+const char kHeartRateUUID[] = "0000180d-0000-1000-8000-00805f9b34fb"; |
+const char kBatteryServiceUUID[] = "0000180f-0000-1000-8000-00805f9b34fb"; |
+const char kBloodPressureUUID[] = "00001813-0000-1000-8000-00805f9b34fb"; |
+const char kCyclingPowerUUID[] = "00001818-0000-1000-8000-00805f9b34fb"; |
+ |
+class BluetoothAllowedDevicesMapTest : public testing::Test { |
+ protected: |
+ BluetoothAllowedDevicesMapTest() { |
+ empty_options_ = blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
+ } |
+ |
+ ~BluetoothAllowedDevicesMapTest() override {} |
+ |
+ blink::mojom::WebBluetoothRequestDeviceOptionsPtr empty_options_; |
+}; |
+ |
} // namespace |
-TEST(BluetoothAllowedDevicesMapTest, AddDeviceToMap) { |
+TEST_F(BluetoothAllowedDevicesMapTest, UniqueOriginNotSupported) { |
+ BluetoothAllowedDevicesMap allowed_devices_map; |
+ |
+ EXPECT_DEATH_IF_SUPPORTED(allowed_devices_map.AddDevice( |
+ url::Origin(), kDeviceAddress1, empty_options_), |
+ ""); |
+} |
+ |
+TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMap) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
const std::string& device_id = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, kEmptyFilters, kEmptyOptionalServices); |
+ kTestOrigin1, kDeviceAddress1, empty_options_); |
// Test that we can retrieve the device address/id. |
EXPECT_EQ(device_id, |
@@ -50,12 +58,12 @@ TEST(BluetoothAllowedDevicesMapTest, AddDeviceToMap) { |
allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id)); |
} |
-TEST(BluetoothAllowedDevicesMapTest, AddDeviceToMapTwice) { |
+TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMapTwice) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
const std::string& device_id1 = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, kEmptyFilters, kEmptyOptionalServices); |
+ kTestOrigin1, kDeviceAddress1, empty_options_); |
const std::string& device_id2 = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, kEmptyFilters, kEmptyOptionalServices); |
+ kTestOrigin1, kDeviceAddress1, empty_options_); |
EXPECT_EQ(device_id1, device_id2); |
@@ -66,12 +74,12 @@ TEST(BluetoothAllowedDevicesMapTest, AddDeviceToMapTwice) { |
allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); |
} |
-TEST(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromSameOriginToMap) { |
+TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromSameOriginToMap) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
const std::string& device_id1 = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, kEmptyFilters, kEmptyOptionalServices); |
+ kTestOrigin1, kDeviceAddress1, empty_options_); |
const std::string& device_id2 = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress2, kEmptyFilters, kEmptyOptionalServices); |
+ kTestOrigin1, kDeviceAddress2, empty_options_); |
EXPECT_NE(device_id1, device_id2); |
@@ -87,12 +95,12 @@ TEST(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromSameOriginToMap) { |
allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2)); |
} |
-TEST(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) { |
+TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
const std::string& device_id1 = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, kEmptyFilters, kEmptyOptionalServices); |
+ kTestOrigin1, kDeviceAddress1, empty_options_); |
const std::string& device_id2 = allowed_devices_map.AddDevice( |
- kTestOrigin2, kDeviceAddress2, kEmptyFilters, kEmptyOptionalServices); |
+ kTestOrigin2, kDeviceAddress2, empty_options_); |
EXPECT_NE(device_id1, device_id2); |
@@ -120,12 +128,12 @@ TEST(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) { |
allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id2)); |
} |
-TEST(BluetoothAllowedDevicesMapTest, AddDeviceFromTwoOriginsToMap) { |
+TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceFromTwoOriginsToMap) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
const std::string& device_id1 = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, kEmptyFilters, kEmptyOptionalServices); |
+ kTestOrigin1, kDeviceAddress1, empty_options_); |
const std::string& device_id2 = allowed_devices_map.AddDevice( |
- kTestOrigin2, kDeviceAddress1, kEmptyFilters, kEmptyOptionalServices); |
+ kTestOrigin2, kDeviceAddress1, empty_options_); |
EXPECT_NE(device_id1, device_id2); |
@@ -136,24 +144,24 @@ TEST(BluetoothAllowedDevicesMapTest, AddDeviceFromTwoOriginsToMap) { |
allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id1)); |
} |
-TEST(BluetoothAllowedDevicesMapTest, AddRemoveAddDeviceToMap) { |
+TEST_F(BluetoothAllowedDevicesMapTest, AddRemoveAddDeviceToMap) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
const std::string device_id_first_time = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, kEmptyFilters, kEmptyOptionalServices); |
+ kTestOrigin1, kDeviceAddress1, empty_options_); |
allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); |
const std::string device_id_second_time = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, kEmptyFilters, kEmptyOptionalServices); |
+ kTestOrigin1, kDeviceAddress1, empty_options_); |
EXPECT_NE(device_id_first_time, device_id_second_time); |
} |
-TEST(BluetoothAllowedDevicesMapTest, RemoveDeviceFromMap) { |
+TEST_F(BluetoothAllowedDevicesMapTest, RemoveDeviceFromMap) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
const std::string& device_id = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, kEmptyFilters, kEmptyOptionalServices); |
+ kTestOrigin1, kDeviceAddress1, empty_options_); |
allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); |
@@ -163,237 +171,260 @@ TEST(BluetoothAllowedDevicesMapTest, RemoveDeviceFromMap) { |
kTestOrigin1, kDeviceAddress1)); |
} |
-TEST(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) { |
+TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
// Setup device. |
- BluetoothScanFilter scanFilter1; |
- scanFilter1.services.push_back(kGlucoseUUID); |
- BluetoothScanFilter scanFilter2; |
- scanFilter2.services.push_back(kHeartRateUUID); |
+ blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = |
+ blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
+ blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = |
+ blink::mojom::WebBluetoothScanFilter::New(); |
+ blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = |
+ blink::mojom::WebBluetoothScanFilter::New(); |
+ |
+ scanFilter1->services.push_back(kGlucoseUUID); |
+ options->filters.push_back(scanFilter1.Clone()); |
- std::vector<BluetoothScanFilter> filters; |
- filters.push_back(scanFilter1); |
- filters.push_back(scanFilter2); |
+ scanFilter2->services.push_back(kHeartRateUUID); |
+ options->filters.push_back(scanFilter2.Clone()); |
- std::vector<BluetoothUUID> optional_services; |
- optional_services.push_back(kBatteryServiceUUID); |
- optional_services.push_back(kHeartRateUUID); |
+ options->optional_services.push_back(kBatteryServiceUUID); |
+ options->optional_services.push_back(kHeartRateUUID); |
// Add to map. |
- const std::string device_id1 = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, filters, optional_services); |
+ const std::string device_id1 = |
+ allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options); |
// Access allowed services. |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kGlucoseUUIDString)); |
+ kTestOrigin1, device_id1, kGlucoseUUID)); |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kHeartRateUUIDString)); |
+ kTestOrigin1, device_id1, kHeartRateUUID)); |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kBatteryServiceUUIDString)); |
+ kTestOrigin1, device_id1, kBatteryServiceUUID)); |
// Try to access a non-allowed service. |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kBloodPressureUUIDString)); |
+ kTestOrigin1, device_id1, kBloodPressureUUID)); |
// Try to access allowed services after removing device. |
allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kGlucoseUUIDString)); |
+ kTestOrigin1, device_id1, kGlucoseUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kHeartRateUUIDString)); |
+ kTestOrigin1, device_id1, kHeartRateUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kBatteryServiceUUIDString)); |
+ kTestOrigin1, device_id1, kBatteryServiceUUID)); |
// Add device back. |
- const std::string device_id2 = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, filters, kEmptyOptionalServices); |
+ blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = |
+ blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
+ |
+ options2->filters.push_back(scanFilter1.Clone()); |
+ options2->filters.push_back(scanFilter2.Clone()); |
+ |
+ const std::string device_id2 = |
+ allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); |
// Access allowed services. |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id2, kGlucoseUUIDString)); |
+ kTestOrigin1, device_id2, kGlucoseUUID)); |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id2, kHeartRateUUIDString)); |
+ kTestOrigin1, device_id2, kHeartRateUUID)); |
// Try to access a non-allowed service. |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id2, kBatteryServiceUUIDString)); |
+ kTestOrigin1, device_id2, kBatteryServiceUUID)); |
// Try to access services from old device. |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kGlucoseUUIDString)); |
+ kTestOrigin1, device_id1, kGlucoseUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kHeartRateUUIDString)); |
+ kTestOrigin1, device_id1, kHeartRateUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kBatteryServiceUUIDString)); |
+ kTestOrigin1, device_id1, kBatteryServiceUUID)); |
} |
-TEST(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginTwoDevices) { |
+TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginTwoDevices) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
// Setup request for device #1. |
- BluetoothScanFilter scanFilter1; |
- scanFilter1.services.push_back(kGlucoseUUID); |
- std::vector<BluetoothScanFilter> filters1; |
- filters1.push_back(scanFilter1); |
+ blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = |
+ blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
+ blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = |
+ blink::mojom::WebBluetoothScanFilter::New(); |
+ |
+ scanFilter1->services.push_back(kGlucoseUUID); |
+ options1->filters.push_back(std::move(scanFilter1)); |
- std::vector<BluetoothUUID> optional_services1; |
- optional_services1.push_back(kHeartRateUUID); |
+ options1->optional_services.push_back(kHeartRateUUID); |
// Setup request for device #2. |
- BluetoothScanFilter scanFilter2; |
- scanFilter2.services.push_back(kBatteryServiceUUID); |
- std::vector<BluetoothScanFilter> filters2; |
- filters2.push_back(scanFilter2); |
+ blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = |
+ blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
+ blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = |
+ blink::mojom::WebBluetoothScanFilter::New(); |
- std::vector<BluetoothUUID> optional_services2; |
- optional_services2.push_back(kBloodPressureUUID); |
+ scanFilter2->services.push_back(kBatteryServiceUUID); |
+ options2->filters.push_back(std::move(scanFilter2)); |
+ |
+ options2->optional_services.push_back(kBloodPressureUUID); |
// Add devices to map. |
- const std::string& device_id1 = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, filters1, optional_services1); |
- const std::string& device_id2 = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress2, filters2, optional_services2); |
+ const std::string& device_id1 = |
+ allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); |
+ const std::string& device_id2 = |
+ allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress2, options2); |
// Access allowed services. |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kGlucoseUUIDString)); |
+ kTestOrigin1, device_id1, kGlucoseUUID)); |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kHeartRateUUIDString)); |
+ kTestOrigin1, device_id1, kHeartRateUUID)); |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id2, kBatteryServiceUUIDString)); |
+ kTestOrigin1, device_id2, kBatteryServiceUUID)); |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id2, kBloodPressureUUIDString)); |
+ kTestOrigin1, device_id2, kBloodPressureUUID)); |
// Try to access non-allowed services. |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kBatteryServiceUUIDString)); |
+ kTestOrigin1, device_id1, kBatteryServiceUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kBloodPressureUUIDString)); |
+ kTestOrigin1, device_id1, kBloodPressureUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kCyclingPowerUUIDString)); |
+ kTestOrigin1, device_id1, kCyclingPowerUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id2, kGlucoseUUIDString)); |
+ kTestOrigin1, device_id2, kGlucoseUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id2, kHeartRateUUIDString)); |
+ kTestOrigin1, device_id2, kHeartRateUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id2, kCyclingPowerUUIDString)); |
+ kTestOrigin1, device_id2, kCyclingPowerUUID)); |
} |
-TEST(BluetoothAllowedDevicesMapTest, AllowedServices_TwoOriginsOneDevice) { |
+TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_TwoOriginsOneDevice) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
// Setup request #1 for device. |
- BluetoothScanFilter scanFilter1; |
- scanFilter1.services.push_back(kGlucoseUUID); |
- std::vector<BluetoothScanFilter> filters1; |
- filters1.push_back(scanFilter1); |
+ blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = |
+ blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
+ blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = |
+ blink::mojom::WebBluetoothScanFilter::New(); |
- std::vector<BluetoothUUID> optional_services1; |
- optional_services1.push_back(kHeartRateUUID); |
+ scanFilter1->services.push_back(kGlucoseUUID); |
+ options1->filters.push_back(std::move(scanFilter1)); |
+ |
+ options1->optional_services.push_back(kHeartRateUUID); |
// Setup request #2 for device. |
- BluetoothScanFilter scanFilter2; |
- scanFilter2.services.push_back(kBatteryServiceUUID); |
- std::vector<BluetoothScanFilter> filters2; |
- filters2.push_back(scanFilter2); |
+ blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = |
+ blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
+ blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = |
+ blink::mojom::WebBluetoothScanFilter::New(); |
+ |
+ scanFilter2->services.push_back(kBatteryServiceUUID); |
+ options2->filters.push_back(std::move(scanFilter2)); |
- std::vector<BluetoothUUID> optional_services2; |
- optional_services2.push_back(kBloodPressureUUID); |
+ options2->optional_services.push_back(kBloodPressureUUID); |
// Add devices to map. |
- const std::string& device_id1 = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, filters1, optional_services1); |
- const std::string& device_id2 = allowed_devices_map.AddDevice( |
- kTestOrigin2, kDeviceAddress1, filters2, optional_services2); |
+ const std::string& device_id1 = |
+ allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); |
+ const std::string& device_id2 = |
+ allowed_devices_map.AddDevice(kTestOrigin2, kDeviceAddress1, options2); |
// Access allowed services. |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kGlucoseUUIDString)); |
+ kTestOrigin1, device_id1, kGlucoseUUID)); |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kHeartRateUUIDString)); |
+ kTestOrigin1, device_id1, kHeartRateUUID)); |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin2, device_id2, kBatteryServiceUUIDString)); |
+ kTestOrigin2, device_id2, kBatteryServiceUUID)); |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin2, device_id2, kBloodPressureUUIDString)); |
+ kTestOrigin2, device_id2, kBloodPressureUUID)); |
// Try to access non-allowed services. |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kBatteryServiceUUIDString)); |
+ kTestOrigin1, device_id1, kBatteryServiceUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kBloodPressureUUIDString)); |
+ kTestOrigin1, device_id1, kBloodPressureUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id2, kGlucoseUUIDString)); |
+ kTestOrigin1, device_id2, kGlucoseUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id2, kHeartRateUUIDString)); |
+ kTestOrigin1, device_id2, kHeartRateUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id2, kBatteryServiceUUIDString)); |
+ kTestOrigin1, device_id2, kBatteryServiceUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id2, kBloodPressureUUIDString)); |
+ kTestOrigin1, device_id2, kBloodPressureUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin2, device_id2, kGlucoseUUIDString)); |
+ kTestOrigin2, device_id2, kGlucoseUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin2, device_id2, kHeartRateUUIDString)); |
+ kTestOrigin2, device_id2, kHeartRateUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin2, device_id1, kGlucoseUUIDString)); |
+ kTestOrigin2, device_id1, kGlucoseUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin2, device_id1, kHeartRateUUIDString)); |
+ kTestOrigin2, device_id1, kHeartRateUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin2, device_id1, kBatteryServiceUUIDString)); |
+ kTestOrigin2, device_id1, kBatteryServiceUUID)); |
EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin2, device_id1, kBloodPressureUUIDString)); |
+ kTestOrigin2, device_id1, kBloodPressureUUID)); |
} |
-TEST(BluetoothAllowedDevicesMapTest, MergeServices) { |
+TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
// Setup first request. |
- BluetoothScanFilter scanFilter1; |
- scanFilter1.services.push_back(kGlucoseUUID); |
- std::vector<BluetoothScanFilter> filters1; |
- filters1.push_back(scanFilter1); |
- std::vector<BluetoothUUID> optional_services1; |
- optional_services1.push_back(kBatteryServiceUUID); |
+ blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = |
+ blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
+ blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = |
+ blink::mojom::WebBluetoothScanFilter::New(); |
+ |
+ scanFilter1->services.push_back(kGlucoseUUID); |
+ options1->filters.push_back(std::move(scanFilter1)); |
+ |
+ options1->optional_services.push_back(kBatteryServiceUUID); |
// Add to map. |
- const std::string device_id1 = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, filters1, optional_services1); |
+ const std::string device_id1 = |
+ allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); |
// Setup second request. |
- BluetoothScanFilter scanFilter2; |
- scanFilter2.services.push_back(kHeartRateUUID); |
- std::vector<BluetoothScanFilter> filters2; |
- filters2.push_back(scanFilter2); |
- std::vector<BluetoothUUID> optional_services2; |
- optional_services2.push_back(kBloodPressureUUID); |
+ blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = |
+ blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
+ blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = |
+ blink::mojom::WebBluetoothScanFilter::New(); |
+ |
+ scanFilter2->services.push_back(kHeartRateUUID); |
+ options2->filters.push_back(std::move(scanFilter2)); |
+ |
+ options2->optional_services.push_back(kBloodPressureUUID); |
// Add to map again. |
- const std::string device_id2 = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, filters2, optional_services2); |
+ const std::string device_id2 = |
+ allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); |
EXPECT_EQ(device_id1, device_id2); |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kGlucoseUUIDString)); |
+ kTestOrigin1, device_id1, kGlucoseUUID)); |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kBatteryServiceUUIDString)); |
+ kTestOrigin1, device_id1, kBatteryServiceUUID)); |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kHeartRateUUIDString)); |
+ kTestOrigin1, device_id1, kHeartRateUUID)); |
EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
- kTestOrigin1, device_id1, kBloodPressureUUIDString)); |
+ kTestOrigin1, device_id1, kBloodPressureUUID)); |
} |
-TEST(BluetoothAllowedDevicesMapTest, CorrectIdFormat) { |
+TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) { |
BluetoothAllowedDevicesMap allowed_devices_map; |
const std::string& device_id = allowed_devices_map.AddDevice( |
- kTestOrigin1, kDeviceAddress1, kEmptyFilters, kEmptyOptionalServices); |
+ kTestOrigin1, kDeviceAddress1, empty_options_); |
EXPECT_TRUE(device_id.size() == 24) |
<< "Expected Lenghth of a 128bit string encoded to Base64."; |