| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_blocklist.h" | 5 #include "content/browser/bluetooth/bluetooth_blocklist.h" |
| 6 | 6 |
| 7 #include "device/bluetooth/bluetooth_uuid.h" | 7 #include "device/bluetooth/bluetooth_uuid.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 using device::BluetoothUUID; | 10 using device::BluetoothUUID; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 list_.Add("\r\n0009:e\n\r"); | 210 list_.Add("\r\n0009:e\n\r"); |
| 211 EXPECT_EQ(++previous_list_size, list_.size()); | 211 EXPECT_EQ(++previous_list_size, list_.size()); |
| 212 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0009"))); | 212 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0009"))); |
| 213 } | 213 } |
| 214 | 214 |
| 215 TEST_F(BluetoothBlocklistTest, IsExcluded_BluetoothScanFilter_ReturnsFalse) { | 215 TEST_F(BluetoothBlocklistTest, IsExcluded_BluetoothScanFilter_ReturnsFalse) { |
| 216 list_.Add(BluetoothUUID("eeee"), BluetoothBlocklist::Value::EXCLUDE); | 216 list_.Add(BluetoothUUID("eeee"), BluetoothBlocklist::Value::EXCLUDE); |
| 217 list_.Add(BluetoothUUID("ee01"), BluetoothBlocklist::Value::EXCLUDE_READS); | 217 list_.Add(BluetoothUUID("ee01"), BluetoothBlocklist::Value::EXCLUDE_READS); |
| 218 list_.Add(BluetoothUUID("ee02"), BluetoothBlocklist::Value::EXCLUDE_WRITES); | 218 list_.Add(BluetoothUUID("ee02"), BluetoothBlocklist::Value::EXCLUDE_WRITES); |
| 219 { | 219 { |
| 220 std::vector<blink::mojom::WebBluetoothScanFilterPtr> empty_filters; | 220 std::vector<blink::mojom::WebBluetoothLeScanFilterPtr> empty_filters; |
| 221 EXPECT_FALSE(list_.IsExcluded(empty_filters)); | 221 EXPECT_FALSE(list_.IsExcluded(empty_filters)); |
| 222 } | 222 } |
| 223 { | 223 { |
| 224 std::vector<blink::mojom::WebBluetoothScanFilterPtr> | 224 std::vector<blink::mojom::WebBluetoothLeScanFilterPtr> |
| 225 single_filter_with_no_services(1); | 225 single_filter_with_no_services(1); |
| 226 | 226 |
| 227 single_filter_with_no_services[0] = | 227 single_filter_with_no_services[0] = |
| 228 blink::mojom::WebBluetoothScanFilter::New(); | 228 blink::mojom::WebBluetoothLeScanFilter::New(); |
| 229 | 229 |
| 230 EXPECT_FALSE(single_filter_with_no_services[0]->services); | 230 EXPECT_FALSE(single_filter_with_no_services[0]->services); |
| 231 EXPECT_FALSE(list_.IsExcluded(single_filter_with_no_services)); | 231 EXPECT_FALSE(list_.IsExcluded(single_filter_with_no_services)); |
| 232 } | 232 } |
| 233 { | 233 { |
| 234 std::vector<blink::mojom::WebBluetoothScanFilterPtr> single_empty_filter(1); | 234 std::vector<blink::mojom::WebBluetoothLeScanFilterPtr> single_empty_filter( |
| 235 1); |
| 235 | 236 |
| 236 single_empty_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); | 237 single_empty_filter[0] = blink::mojom::WebBluetoothLeScanFilter::New(); |
| 237 single_empty_filter[0]->services.emplace(); | 238 single_empty_filter[0]->services.emplace(); |
| 238 | 239 |
| 239 EXPECT_EQ(0u, single_empty_filter[0]->services->size()); | 240 EXPECT_EQ(0u, single_empty_filter[0]->services->size()); |
| 240 EXPECT_FALSE(list_.IsExcluded(single_empty_filter)); | 241 EXPECT_FALSE(list_.IsExcluded(single_empty_filter)); |
| 241 } | 242 } |
| 242 { | 243 { |
| 243 std::vector<blink::mojom::WebBluetoothScanFilterPtr> | 244 std::vector<blink::mojom::WebBluetoothLeScanFilterPtr> |
| 244 single_non_matching_filter(1); | 245 single_non_matching_filter(1); |
| 245 | 246 |
| 246 single_non_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); | 247 single_non_matching_filter[0] = |
| 248 blink::mojom::WebBluetoothLeScanFilter::New(); |
| 247 single_non_matching_filter[0]->services.emplace(); | 249 single_non_matching_filter[0]->services.emplace(); |
| 248 single_non_matching_filter[0]->services->push_back(BluetoothUUID("0000")); | 250 single_non_matching_filter[0]->services->push_back(BluetoothUUID("0000")); |
| 249 | 251 |
| 250 EXPECT_FALSE(list_.IsExcluded(single_non_matching_filter)); | 252 EXPECT_FALSE(list_.IsExcluded(single_non_matching_filter)); |
| 251 } | 253 } |
| 252 { | 254 { |
| 253 std::vector<blink::mojom::WebBluetoothScanFilterPtr> | 255 std::vector<blink::mojom::WebBluetoothLeScanFilterPtr> |
| 254 multiple_non_matching_filters(2); | 256 multiple_non_matching_filters(2); |
| 255 | 257 |
| 256 multiple_non_matching_filters[0] = | 258 multiple_non_matching_filters[0] = |
| 257 blink::mojom::WebBluetoothScanFilter::New(); | 259 blink::mojom::WebBluetoothLeScanFilter::New(); |
| 258 multiple_non_matching_filters[0]->services.emplace(); | 260 multiple_non_matching_filters[0]->services.emplace(); |
| 259 multiple_non_matching_filters[0]->services->push_back( | 261 multiple_non_matching_filters[0]->services->push_back( |
| 260 BluetoothUUID("0000")); | 262 BluetoothUUID("0000")); |
| 261 multiple_non_matching_filters[0]->services->push_back( | 263 multiple_non_matching_filters[0]->services->push_back( |
| 262 BluetoothUUID("ee01")); | 264 BluetoothUUID("ee01")); |
| 263 | 265 |
| 264 multiple_non_matching_filters[1] = | 266 multiple_non_matching_filters[1] = |
| 265 blink::mojom::WebBluetoothScanFilter::New(); | 267 blink::mojom::WebBluetoothLeScanFilter::New(); |
| 266 multiple_non_matching_filters[1]->services.emplace(); | 268 multiple_non_matching_filters[1]->services.emplace(); |
| 267 multiple_non_matching_filters[1]->services->push_back( | 269 multiple_non_matching_filters[1]->services->push_back( |
| 268 BluetoothUUID("ee02")); | 270 BluetoothUUID("ee02")); |
| 269 multiple_non_matching_filters[1]->services->push_back( | 271 multiple_non_matching_filters[1]->services->push_back( |
| 270 BluetoothUUID("0003")); | 272 BluetoothUUID("0003")); |
| 271 | 273 |
| 272 EXPECT_FALSE(list_.IsExcluded(multiple_non_matching_filters)); | 274 EXPECT_FALSE(list_.IsExcluded(multiple_non_matching_filters)); |
| 273 } | 275 } |
| 274 } | 276 } |
| 275 | 277 |
| 276 TEST_F(BluetoothBlocklistTest, IsExcluded_BluetoothScanFilter_ReturnsTrue) { | 278 TEST_F(BluetoothBlocklistTest, IsExcluded_BluetoothScanFilter_ReturnsTrue) { |
| 277 list_.Add(BluetoothUUID("eeee"), BluetoothBlocklist::Value::EXCLUDE); | 279 list_.Add(BluetoothUUID("eeee"), BluetoothBlocklist::Value::EXCLUDE); |
| 278 { | 280 { |
| 279 std::vector<blink::mojom::WebBluetoothScanFilterPtr> single_matching_filter( | 281 std::vector<blink::mojom::WebBluetoothLeScanFilterPtr> |
| 280 1); | 282 single_matching_filter(1); |
| 281 | 283 |
| 282 single_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); | 284 single_matching_filter[0] = blink::mojom::WebBluetoothLeScanFilter::New(); |
| 283 single_matching_filter[0]->services.emplace(); | 285 single_matching_filter[0]->services.emplace(); |
| 284 single_matching_filter[0]->services->push_back(BluetoothUUID("eeee")); | 286 single_matching_filter[0]->services->push_back(BluetoothUUID("eeee")); |
| 285 | 287 |
| 286 EXPECT_TRUE(list_.IsExcluded(single_matching_filter)); | 288 EXPECT_TRUE(list_.IsExcluded(single_matching_filter)); |
| 287 } | 289 } |
| 288 { | 290 { |
| 289 std::vector<blink::mojom::WebBluetoothScanFilterPtr> first_matching_filter( | 291 std::vector<blink::mojom::WebBluetoothLeScanFilterPtr> |
| 290 2); | 292 first_matching_filter(2); |
| 291 | 293 |
| 292 first_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); | 294 first_matching_filter[0] = blink::mojom::WebBluetoothLeScanFilter::New(); |
| 293 first_matching_filter[0]->services.emplace(); | 295 first_matching_filter[0]->services.emplace(); |
| 294 first_matching_filter[0]->services->push_back(BluetoothUUID("eeee")); | 296 first_matching_filter[0]->services->push_back(BluetoothUUID("eeee")); |
| 295 first_matching_filter[0]->services->push_back(BluetoothUUID("0001")); | 297 first_matching_filter[0]->services->push_back(BluetoothUUID("0001")); |
| 296 | 298 |
| 297 first_matching_filter[1] = blink::mojom::WebBluetoothScanFilter::New(); | 299 first_matching_filter[1] = blink::mojom::WebBluetoothLeScanFilter::New(); |
| 298 first_matching_filter[1]->services.emplace(); | 300 first_matching_filter[1]->services.emplace(); |
| 299 first_matching_filter[1]->services->push_back(BluetoothUUID("0002")); | 301 first_matching_filter[1]->services->push_back(BluetoothUUID("0002")); |
| 300 first_matching_filter[1]->services->push_back(BluetoothUUID("0003")); | 302 first_matching_filter[1]->services->push_back(BluetoothUUID("0003")); |
| 301 | 303 |
| 302 EXPECT_TRUE(list_.IsExcluded(first_matching_filter)); | 304 EXPECT_TRUE(list_.IsExcluded(first_matching_filter)); |
| 303 } | 305 } |
| 304 { | 306 { |
| 305 std::vector<blink::mojom::WebBluetoothScanFilterPtr> last_matching_filter( | 307 std::vector<blink::mojom::WebBluetoothLeScanFilterPtr> last_matching_filter( |
| 306 2); | 308 2); |
| 307 | 309 |
| 308 last_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); | 310 last_matching_filter[0] = blink::mojom::WebBluetoothLeScanFilter::New(); |
| 309 last_matching_filter[0]->services.emplace(); | 311 last_matching_filter[0]->services.emplace(); |
| 310 last_matching_filter[0]->services->push_back(BluetoothUUID("0001")); | 312 last_matching_filter[0]->services->push_back(BluetoothUUID("0001")); |
| 311 last_matching_filter[0]->services->push_back(BluetoothUUID("0001")); | 313 last_matching_filter[0]->services->push_back(BluetoothUUID("0001")); |
| 312 | 314 |
| 313 last_matching_filter[1] = blink::mojom::WebBluetoothScanFilter::New(); | 315 last_matching_filter[1] = blink::mojom::WebBluetoothLeScanFilter::New(); |
| 314 last_matching_filter[1]->services.emplace(); | 316 last_matching_filter[1]->services.emplace(); |
| 315 last_matching_filter[1]->services->push_back(BluetoothUUID("0002")); | 317 last_matching_filter[1]->services->push_back(BluetoothUUID("0002")); |
| 316 last_matching_filter[1]->services->push_back(BluetoothUUID("eeee")); | 318 last_matching_filter[1]->services->push_back(BluetoothUUID("eeee")); |
| 317 | 319 |
| 318 EXPECT_TRUE(list_.IsExcluded(last_matching_filter)); | 320 EXPECT_TRUE(list_.IsExcluded(last_matching_filter)); |
| 319 } | 321 } |
| 320 { | 322 { |
| 321 std::vector<blink::mojom::WebBluetoothScanFilterPtr> | 323 std::vector<blink::mojom::WebBluetoothLeScanFilterPtr> |
| 322 multiple_matching_filters(2); | 324 multiple_matching_filters(2); |
| 323 | 325 |
| 324 multiple_matching_filters[0] = blink::mojom::WebBluetoothScanFilter::New(); | 326 multiple_matching_filters[0] = |
| 327 blink::mojom::WebBluetoothLeScanFilter::New(); |
| 325 multiple_matching_filters[0]->services.emplace(); | 328 multiple_matching_filters[0]->services.emplace(); |
| 326 multiple_matching_filters[0]->services->push_back(BluetoothUUID("eeee")); | 329 multiple_matching_filters[0]->services->push_back(BluetoothUUID("eeee")); |
| 327 multiple_matching_filters[0]->services->push_back(BluetoothUUID("eeee")); | 330 multiple_matching_filters[0]->services->push_back(BluetoothUUID("eeee")); |
| 328 | 331 |
| 329 multiple_matching_filters[1] = blink::mojom::WebBluetoothScanFilter::New(); | 332 multiple_matching_filters[1] = |
| 333 blink::mojom::WebBluetoothLeScanFilter::New(); |
| 330 multiple_matching_filters[1]->services.emplace(); | 334 multiple_matching_filters[1]->services.emplace(); |
| 331 multiple_matching_filters[1]->services->push_back(BluetoothUUID("eeee")); | 335 multiple_matching_filters[1]->services->push_back(BluetoothUUID("eeee")); |
| 332 multiple_matching_filters[1]->services->push_back(BluetoothUUID("eeee")); | 336 multiple_matching_filters[1]->services->push_back(BluetoothUUID("eeee")); |
| 333 | 337 |
| 334 EXPECT_TRUE(list_.IsExcluded(multiple_matching_filters)); | 338 EXPECT_TRUE(list_.IsExcluded(multiple_matching_filters)); |
| 335 } | 339 } |
| 336 } | 340 } |
| 337 | 341 |
| 338 TEST_F(BluetoothBlocklistTest, RemoveExcludedUUIDs_NonMatching) { | 342 TEST_F(BluetoothBlocklistTest, RemoveExcludedUUIDs_NonMatching) { |
| 339 list_.Add(BluetoothUUID("eeee"), BluetoothBlocklist::Value::EXCLUDE); | 343 list_.Add(BluetoothUUID("eeee"), BluetoothBlocklist::Value::EXCLUDE); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 BluetoothUUID("bad1c9a2-9a5b-4015-8b60-1579bbbf2135"))); | 493 BluetoothUUID("bad1c9a2-9a5b-4015-8b60-1579bbbf2135"))); |
| 490 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2902"))); | 494 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2902"))); |
| 491 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2903"))); | 495 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2903"))); |
| 492 EXPECT_TRUE(list_.IsExcludedFromWrites( | 496 EXPECT_TRUE(list_.IsExcludedFromWrites( |
| 493 BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c"))); | 497 BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c"))); |
| 494 EXPECT_FALSE(list_.IsExcludedFromWrites( | 498 EXPECT_FALSE(list_.IsExcludedFromWrites( |
| 495 BluetoothUUID("bad3ec61-3cc3-4954-9702-7977df514114"))); | 499 BluetoothUUID("bad3ec61-3cc3-4954-9702-7977df514114"))); |
| 496 } | 500 } |
| 497 | 501 |
| 498 } // namespace content | 502 } // namespace content |
| OLD | NEW |