| 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 "components/web_bluetooth/web_bluetooth_device_id.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 10 | 11 |
| 11 using device::BluetoothUUID; | 12 using device::BluetoothUUID; |
| 13 using web_bluetooth::WebBluetoothDeviceId; |
| 12 | 14 |
| 13 namespace content { | 15 namespace content { |
| 14 namespace { | 16 namespace { |
| 15 const url::Origin kTestOrigin1(GURL("https://www.example1.com")); | 17 const url::Origin kTestOrigin1(GURL("https://www.example1.com")); |
| 16 const url::Origin kTestOrigin2(GURL("https://www.example2.com")); | 18 const url::Origin kTestOrigin2(GURL("https://www.example2.com")); |
| 17 | 19 |
| 18 const std::string kDeviceAddress1 = "00:00:00"; | 20 const std::string kDeviceAddress1 = "00:00:00"; |
| 19 const std::string kDeviceAddress2 = "11:11:11"; | 21 const std::string kDeviceAddress2 = "11:11:11"; |
| 20 | 22 |
| 21 const char kGlucoseUUIDString[] = "00001808-0000-1000-8000-00805f9b34fb"; | 23 const char kGlucoseUUIDString[] = "00001808-0000-1000-8000-00805f9b34fb"; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 46 BluetoothAllowedDevicesMap allowed_devices_map; | 48 BluetoothAllowedDevicesMap allowed_devices_map; |
| 47 | 49 |
| 48 EXPECT_DEATH_IF_SUPPORTED(allowed_devices_map.AddDevice( | 50 EXPECT_DEATH_IF_SUPPORTED(allowed_devices_map.AddDevice( |
| 49 url::Origin(), kDeviceAddress1, empty_options_), | 51 url::Origin(), kDeviceAddress1, empty_options_), |
| 50 ""); | 52 ""); |
| 51 } | 53 } |
| 52 | 54 |
| 53 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMap) { | 55 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMap) { |
| 54 BluetoothAllowedDevicesMap allowed_devices_map; | 56 BluetoothAllowedDevicesMap allowed_devices_map; |
| 55 | 57 |
| 56 const std::string& device_id = allowed_devices_map.AddDevice( | 58 const WebBluetoothDeviceId& device_id = allowed_devices_map.AddDevice( |
| 57 kTestOrigin1, kDeviceAddress1, empty_options_); | 59 kTestOrigin1, kDeviceAddress1, empty_options_); |
| 58 | 60 |
| 59 // Test that we can retrieve the device address/id. | 61 // Test that we can retrieve the device address/id. |
| 60 EXPECT_EQ(device_id, | 62 EXPECT_EQ(device_id, |
| 61 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); | 63 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); |
| 62 EXPECT_EQ(kDeviceAddress1, | 64 EXPECT_EQ(kDeviceAddress1, |
| 63 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id)); | 65 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id)); |
| 64 } | 66 } |
| 65 | 67 |
| 66 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMapTwice) { | 68 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMapTwice) { |
| 67 BluetoothAllowedDevicesMap allowed_devices_map; | 69 BluetoothAllowedDevicesMap allowed_devices_map; |
| 68 const std::string& device_id1 = allowed_devices_map.AddDevice( | 70 const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice( |
| 69 kTestOrigin1, kDeviceAddress1, empty_options_); | 71 kTestOrigin1, kDeviceAddress1, empty_options_); |
| 70 const std::string& device_id2 = allowed_devices_map.AddDevice( | 72 const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice( |
| 71 kTestOrigin1, kDeviceAddress1, empty_options_); | 73 kTestOrigin1, kDeviceAddress1, empty_options_); |
| 72 | 74 |
| 73 EXPECT_EQ(device_id1, device_id2); | 75 EXPECT_EQ(device_id1, device_id2); |
| 74 | 76 |
| 75 // Test that we can retrieve the device address/id. | 77 // Test that we can retrieve the device address/id. |
| 76 EXPECT_EQ(device_id1, | 78 EXPECT_EQ(device_id1, |
| 77 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); | 79 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); |
| 78 EXPECT_EQ(kDeviceAddress1, | 80 EXPECT_EQ(kDeviceAddress1, |
| 79 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); | 81 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); |
| 80 } | 82 } |
| 81 | 83 |
| 82 TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromSameOriginToMap) { | 84 TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromSameOriginToMap) { |
| 83 BluetoothAllowedDevicesMap allowed_devices_map; | 85 BluetoothAllowedDevicesMap allowed_devices_map; |
| 84 const std::string& device_id1 = allowed_devices_map.AddDevice( | 86 const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice( |
| 85 kTestOrigin1, kDeviceAddress1, empty_options_); | 87 kTestOrigin1, kDeviceAddress1, empty_options_); |
| 86 const std::string& device_id2 = allowed_devices_map.AddDevice( | 88 const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice( |
| 87 kTestOrigin1, kDeviceAddress2, empty_options_); | 89 kTestOrigin1, kDeviceAddress2, empty_options_); |
| 88 | 90 |
| 89 EXPECT_NE(device_id1, device_id2); | 91 EXPECT_NE(device_id1, device_id2); |
| 90 | 92 |
| 91 // Test that we can retrieve the device address/id. | 93 // Test that we can retrieve the device address/id. |
| 92 EXPECT_EQ(device_id1, | 94 EXPECT_EQ(device_id1, |
| 93 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); | 95 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); |
| 94 EXPECT_EQ(device_id2, | 96 EXPECT_EQ(device_id2, |
| 95 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2)); | 97 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2)); |
| 96 | 98 |
| 97 EXPECT_EQ(kDeviceAddress1, | 99 EXPECT_EQ(kDeviceAddress1, |
| 98 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); | 100 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); |
| 99 EXPECT_EQ(kDeviceAddress2, | 101 EXPECT_EQ(kDeviceAddress2, |
| 100 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2)); | 102 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2)); |
| 101 } | 103 } |
| 102 | 104 |
| 103 TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) { | 105 TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) { |
| 104 BluetoothAllowedDevicesMap allowed_devices_map; | 106 BluetoothAllowedDevicesMap allowed_devices_map; |
| 105 const std::string& device_id1 = allowed_devices_map.AddDevice( | 107 const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice( |
| 106 kTestOrigin1, kDeviceAddress1, empty_options_); | 108 kTestOrigin1, kDeviceAddress1, empty_options_); |
| 107 const std::string& device_id2 = allowed_devices_map.AddDevice( | 109 const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice( |
| 108 kTestOrigin2, kDeviceAddress2, empty_options_); | 110 kTestOrigin2, kDeviceAddress2, empty_options_); |
| 109 | 111 |
| 110 EXPECT_NE(device_id1, device_id2); | 112 EXPECT_NE(device_id1, device_id2); |
| 111 | 113 |
| 112 // Test that the wrong origin doesn't have access to the device. | 114 // Test that the wrong origin doesn't have access to the device. |
| 113 | 115 |
| 114 EXPECT_EQ(base::EmptyString(), | 116 EXPECT_EQ(nullptr, |
| 115 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2)); | 117 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2)); |
| 116 EXPECT_EQ(base::EmptyString(), | 118 EXPECT_EQ(nullptr, |
| 117 allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress1)); | 119 allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress1)); |
| 118 | 120 |
| 119 EXPECT_EQ(base::EmptyString(), | 121 EXPECT_EQ(base::EmptyString(), |
| 120 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2)); | 122 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2)); |
| 121 EXPECT_EQ(base::EmptyString(), | 123 EXPECT_EQ(base::EmptyString(), |
| 122 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id1)); | 124 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id1)); |
| 123 | 125 |
| 124 // Test that we can retrieve the device address/id. | 126 // Test that we can retrieve the device address/id. |
| 125 EXPECT_EQ(device_id1, | 127 EXPECT_EQ(device_id1, |
| 126 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); | 128 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); |
| 127 EXPECT_EQ(device_id2, | 129 EXPECT_EQ(device_id2, |
| 128 allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress2)); | 130 *allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress2)); |
| 129 | 131 |
| 130 EXPECT_EQ(kDeviceAddress1, | 132 EXPECT_EQ(kDeviceAddress1, |
| 131 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); | 133 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); |
| 132 EXPECT_EQ(kDeviceAddress2, | 134 EXPECT_EQ(kDeviceAddress2, |
| 133 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id2)); | 135 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id2)); |
| 134 } | 136 } |
| 135 | 137 |
| 136 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceFromTwoOriginsToMap) { | 138 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceFromTwoOriginsToMap) { |
| 137 BluetoothAllowedDevicesMap allowed_devices_map; | 139 BluetoothAllowedDevicesMap allowed_devices_map; |
| 138 const std::string& device_id1 = allowed_devices_map.AddDevice( | 140 const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice( |
| 139 kTestOrigin1, kDeviceAddress1, empty_options_); | 141 kTestOrigin1, kDeviceAddress1, empty_options_); |
| 140 const std::string& device_id2 = allowed_devices_map.AddDevice( | 142 const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice( |
| 141 kTestOrigin2, kDeviceAddress1, empty_options_); | 143 kTestOrigin2, kDeviceAddress1, empty_options_); |
| 142 | 144 |
| 143 EXPECT_NE(device_id1, device_id2); | 145 EXPECT_NE(device_id1, device_id2); |
| 144 | 146 |
| 145 // Test that the wrong origin doesn't have access to the device. | 147 // Test that the wrong origin doesn't have access to the device. |
| 146 EXPECT_EQ(base::EmptyString(), | 148 EXPECT_EQ(base::EmptyString(), |
| 147 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2)); | 149 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2)); |
| 148 EXPECT_EQ(base::EmptyString(), | 150 EXPECT_EQ(base::EmptyString(), |
| 149 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id1)); | 151 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id1)); |
| 150 } | 152 } |
| 151 | 153 |
| 152 TEST_F(BluetoothAllowedDevicesMapTest, AddRemoveAddDeviceToMap) { | 154 TEST_F(BluetoothAllowedDevicesMapTest, AddRemoveAddDeviceToMap) { |
| 153 BluetoothAllowedDevicesMap allowed_devices_map; | 155 BluetoothAllowedDevicesMap allowed_devices_map; |
| 154 const std::string device_id_first_time = allowed_devices_map.AddDevice( | 156 const WebBluetoothDeviceId device_id_first_time = |
| 155 kTestOrigin1, kDeviceAddress1, empty_options_); | 157 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, |
| 158 empty_options_); |
| 156 | 159 |
| 157 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); | 160 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); |
| 158 | 161 |
| 159 const std::string device_id_second_time = allowed_devices_map.AddDevice( | 162 const WebBluetoothDeviceId device_id_second_time = |
| 160 kTestOrigin1, kDeviceAddress1, empty_options_); | 163 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, |
| 164 empty_options_); |
| 161 | 165 |
| 162 EXPECT_NE(device_id_first_time, device_id_second_time); | 166 EXPECT_NE(device_id_first_time, device_id_second_time); |
| 163 } | 167 } |
| 164 | 168 |
| 165 TEST_F(BluetoothAllowedDevicesMapTest, RemoveDeviceFromMap) { | 169 TEST_F(BluetoothAllowedDevicesMapTest, RemoveDeviceFromMap) { |
| 166 BluetoothAllowedDevicesMap allowed_devices_map; | 170 BluetoothAllowedDevicesMap allowed_devices_map; |
| 167 | 171 |
| 168 const std::string& device_id = allowed_devices_map.AddDevice( | 172 const WebBluetoothDeviceId device_id = allowed_devices_map.AddDevice( |
| 169 kTestOrigin1, kDeviceAddress1, empty_options_); | 173 kTestOrigin1, kDeviceAddress1, empty_options_); |
| 170 | 174 |
| 171 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); | 175 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); |
| 172 | 176 |
| 177 EXPECT_EQ(nullptr, |
| 178 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); |
| 173 EXPECT_EQ(base::EmptyString(), | 179 EXPECT_EQ(base::EmptyString(), |
| 174 allowed_devices_map.GetDeviceId(kTestOrigin1, device_id)); | 180 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id)); |
| 175 EXPECT_EQ(base::EmptyString(), allowed_devices_map.GetDeviceAddress( | |
| 176 kTestOrigin1, kDeviceAddress1)); | |
| 177 } | 181 } |
| 178 | 182 |
| 179 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) { | 183 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) { |
| 180 BluetoothAllowedDevicesMap allowed_devices_map; | 184 BluetoothAllowedDevicesMap allowed_devices_map; |
| 181 | 185 |
| 182 // Setup device. | 186 // Setup device. |
| 183 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = | 187 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = |
| 184 blink::mojom::WebBluetoothRequestDeviceOptions::New(); | 188 blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
| 185 blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = | 189 blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = |
| 186 blink::mojom::WebBluetoothScanFilter::New(); | 190 blink::mojom::WebBluetoothScanFilter::New(); |
| 187 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = | 191 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = |
| 188 blink::mojom::WebBluetoothScanFilter::New(); | 192 blink::mojom::WebBluetoothScanFilter::New(); |
| 189 | 193 |
| 190 scanFilter1->services.push_back(kGlucoseUUID); | 194 scanFilter1->services.push_back(kGlucoseUUID); |
| 191 options->filters.push_back(scanFilter1.Clone()); | 195 options->filters.push_back(scanFilter1.Clone()); |
| 192 | 196 |
| 193 scanFilter2->services.push_back(kHeartRateUUID); | 197 scanFilter2->services.push_back(kHeartRateUUID); |
| 194 options->filters.push_back(scanFilter2.Clone()); | 198 options->filters.push_back(scanFilter2.Clone()); |
| 195 | 199 |
| 196 options->optional_services.push_back(kBatteryServiceUUID); | 200 options->optional_services.push_back(kBatteryServiceUUID); |
| 197 options->optional_services.push_back(kHeartRateUUID); | 201 options->optional_services.push_back(kHeartRateUUID); |
| 198 | 202 |
| 199 // Add to map. | 203 // Add to map. |
| 200 const std::string device_id1 = | 204 const WebBluetoothDeviceId device_id1 = |
| 201 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options); | 205 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options); |
| 202 | 206 |
| 203 // Access allowed services. | 207 // Access allowed services. |
| 204 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 208 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 205 kTestOrigin1, device_id1, kGlucoseUUID)); | 209 kTestOrigin1, device_id1, kGlucoseUUID)); |
| 206 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 210 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 207 kTestOrigin1, device_id1, kHeartRateUUID)); | 211 kTestOrigin1, device_id1, kHeartRateUUID)); |
| 208 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 212 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 209 kTestOrigin1, device_id1, kBatteryServiceUUID)); | 213 kTestOrigin1, device_id1, kBatteryServiceUUID)); |
| 210 | 214 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 222 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( | 226 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 223 kTestOrigin1, device_id1, kBatteryServiceUUID)); | 227 kTestOrigin1, device_id1, kBatteryServiceUUID)); |
| 224 | 228 |
| 225 // Add device back. | 229 // Add device back. |
| 226 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = | 230 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = |
| 227 blink::mojom::WebBluetoothRequestDeviceOptions::New(); | 231 blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
| 228 | 232 |
| 229 options2->filters.push_back(scanFilter1.Clone()); | 233 options2->filters.push_back(scanFilter1.Clone()); |
| 230 options2->filters.push_back(scanFilter2.Clone()); | 234 options2->filters.push_back(scanFilter2.Clone()); |
| 231 | 235 |
| 232 const std::string device_id2 = | 236 const WebBluetoothDeviceId device_id2 = |
| 233 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); | 237 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); |
| 234 | 238 |
| 235 // Access allowed services. | 239 // Access allowed services. |
| 236 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 240 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 237 kTestOrigin1, device_id2, kGlucoseUUID)); | 241 kTestOrigin1, device_id2, kGlucoseUUID)); |
| 238 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 242 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 239 kTestOrigin1, device_id2, kHeartRateUUID)); | 243 kTestOrigin1, device_id2, kHeartRateUUID)); |
| 240 | 244 |
| 241 // Try to access a non-allowed service. | 245 // Try to access a non-allowed service. |
| 242 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( | 246 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 270 blink::mojom::WebBluetoothRequestDeviceOptions::New(); | 274 blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
| 271 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = | 275 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = |
| 272 blink::mojom::WebBluetoothScanFilter::New(); | 276 blink::mojom::WebBluetoothScanFilter::New(); |
| 273 | 277 |
| 274 scanFilter2->services.push_back(kBatteryServiceUUID); | 278 scanFilter2->services.push_back(kBatteryServiceUUID); |
| 275 options2->filters.push_back(std::move(scanFilter2)); | 279 options2->filters.push_back(std::move(scanFilter2)); |
| 276 | 280 |
| 277 options2->optional_services.push_back(kBloodPressureUUID); | 281 options2->optional_services.push_back(kBloodPressureUUID); |
| 278 | 282 |
| 279 // Add devices to map. | 283 // Add devices to map. |
| 280 const std::string& device_id1 = | 284 const WebBluetoothDeviceId& device_id1 = |
| 281 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); | 285 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); |
| 282 const std::string& device_id2 = | 286 const WebBluetoothDeviceId& device_id2 = |
| 283 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress2, options2); | 287 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress2, options2); |
| 284 | 288 |
| 285 // Access allowed services. | 289 // Access allowed services. |
| 286 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 290 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 287 kTestOrigin1, device_id1, kGlucoseUUID)); | 291 kTestOrigin1, device_id1, kGlucoseUUID)); |
| 288 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 292 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 289 kTestOrigin1, device_id1, kHeartRateUUID)); | 293 kTestOrigin1, device_id1, kHeartRateUUID)); |
| 290 | 294 |
| 291 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 295 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 292 kTestOrigin1, device_id2, kBatteryServiceUUID)); | 296 kTestOrigin1, device_id2, kBatteryServiceUUID)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 blink::mojom::WebBluetoothRequestDeviceOptions::New(); | 331 blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
| 328 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = | 332 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = |
| 329 blink::mojom::WebBluetoothScanFilter::New(); | 333 blink::mojom::WebBluetoothScanFilter::New(); |
| 330 | 334 |
| 331 scanFilter2->services.push_back(kBatteryServiceUUID); | 335 scanFilter2->services.push_back(kBatteryServiceUUID); |
| 332 options2->filters.push_back(std::move(scanFilter2)); | 336 options2->filters.push_back(std::move(scanFilter2)); |
| 333 | 337 |
| 334 options2->optional_services.push_back(kBloodPressureUUID); | 338 options2->optional_services.push_back(kBloodPressureUUID); |
| 335 | 339 |
| 336 // Add devices to map. | 340 // Add devices to map. |
| 337 const std::string& device_id1 = | 341 const WebBluetoothDeviceId& device_id1 = |
| 338 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); | 342 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); |
| 339 const std::string& device_id2 = | 343 const WebBluetoothDeviceId& device_id2 = |
| 340 allowed_devices_map.AddDevice(kTestOrigin2, kDeviceAddress1, options2); | 344 allowed_devices_map.AddDevice(kTestOrigin2, kDeviceAddress1, options2); |
| 341 | 345 |
| 342 // Access allowed services. | 346 // Access allowed services. |
| 343 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 347 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 344 kTestOrigin1, device_id1, kGlucoseUUID)); | 348 kTestOrigin1, device_id1, kGlucoseUUID)); |
| 345 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 349 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 346 kTestOrigin1, device_id1, kHeartRateUUID)); | 350 kTestOrigin1, device_id1, kHeartRateUUID)); |
| 347 | 351 |
| 348 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 352 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 349 kTestOrigin2, device_id2, kBatteryServiceUUID)); | 353 kTestOrigin2, device_id2, kBatteryServiceUUID)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 blink::mojom::WebBluetoothRequestDeviceOptions::New(); | 392 blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
| 389 blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = | 393 blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = |
| 390 blink::mojom::WebBluetoothScanFilter::New(); | 394 blink::mojom::WebBluetoothScanFilter::New(); |
| 391 | 395 |
| 392 scanFilter1->services.push_back(kGlucoseUUID); | 396 scanFilter1->services.push_back(kGlucoseUUID); |
| 393 options1->filters.push_back(std::move(scanFilter1)); | 397 options1->filters.push_back(std::move(scanFilter1)); |
| 394 | 398 |
| 395 options1->optional_services.push_back(kBatteryServiceUUID); | 399 options1->optional_services.push_back(kBatteryServiceUUID); |
| 396 | 400 |
| 397 // Add to map. | 401 // Add to map. |
| 398 const std::string device_id1 = | 402 const WebBluetoothDeviceId device_id1 = |
| 399 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); | 403 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); |
| 400 | 404 |
| 401 // Setup second request. | 405 // Setup second request. |
| 402 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = | 406 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = |
| 403 blink::mojom::WebBluetoothRequestDeviceOptions::New(); | 407 blink::mojom::WebBluetoothRequestDeviceOptions::New(); |
| 404 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = | 408 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = |
| 405 blink::mojom::WebBluetoothScanFilter::New(); | 409 blink::mojom::WebBluetoothScanFilter::New(); |
| 406 | 410 |
| 407 scanFilter2->services.push_back(kHeartRateUUID); | 411 scanFilter2->services.push_back(kHeartRateUUID); |
| 408 options2->filters.push_back(std::move(scanFilter2)); | 412 options2->filters.push_back(std::move(scanFilter2)); |
| 409 | 413 |
| 410 options2->optional_services.push_back(kBloodPressureUUID); | 414 options2->optional_services.push_back(kBloodPressureUUID); |
| 411 | 415 |
| 412 // Add to map again. | 416 // Add to map again. |
| 413 const std::string device_id2 = | 417 const WebBluetoothDeviceId device_id2 = |
| 414 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); | 418 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); |
| 415 | 419 |
| 416 EXPECT_EQ(device_id1, device_id2); | 420 EXPECT_EQ(device_id1, device_id2); |
| 417 | 421 |
| 418 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 422 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 419 kTestOrigin1, device_id1, kGlucoseUUID)); | 423 kTestOrigin1, device_id1, kGlucoseUUID)); |
| 420 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 424 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 421 kTestOrigin1, device_id1, kBatteryServiceUUID)); | 425 kTestOrigin1, device_id1, kBatteryServiceUUID)); |
| 422 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 426 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 423 kTestOrigin1, device_id1, kHeartRateUUID)); | 427 kTestOrigin1, device_id1, kHeartRateUUID)); |
| 424 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( | 428 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( |
| 425 kTestOrigin1, device_id1, kBloodPressureUUID)); | 429 kTestOrigin1, device_id1, kBloodPressureUUID)); |
| 426 } | 430 } |
| 427 | 431 |
| 428 TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) { | 432 TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) { |
| 429 BluetoothAllowedDevicesMap allowed_devices_map; | 433 BluetoothAllowedDevicesMap allowed_devices_map; |
| 430 | 434 |
| 431 const std::string& device_id = allowed_devices_map.AddDevice( | 435 const WebBluetoothDeviceId& device_id = allowed_devices_map.AddDevice( |
| 432 kTestOrigin1, kDeviceAddress1, empty_options_); | 436 kTestOrigin1, kDeviceAddress1, empty_options_); |
| 433 | 437 |
| 434 EXPECT_TRUE(device_id.size() == 24) | 438 EXPECT_TRUE(WebBluetoothDeviceId::IsValid(device_id.str())); |
| 435 << "Expected Lenghth of a 128bit string encoded to Base64."; | |
| 436 EXPECT_TRUE((device_id[22] == '=') && (device_id[23] == '=')) | |
| 437 << "Expected padding characters for a 128bit string encoded to Base64."; | |
| 438 } | 439 } |
| 439 | 440 |
| 440 } // namespace content | 441 } // namespace content |
| OLD | NEW |