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

Side by Side Diff: content/browser/bluetooth/bluetooth_blacklist_unittest.cc

Issue 1922923002: bluetooth: Move requestDevice to mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-tests-request-device
Patch Set: Rebase Created 4 years, 7 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 unified diff | Download patch
OLDNEW
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_blacklist.h" 5 #include "content/browser/bluetooth/bluetooth_blacklist.h"
6 6
7 #include "content/common/bluetooth/bluetooth_scan_filter.h"
8 #include "device/bluetooth/bluetooth_uuid.h" 7 #include "device/bluetooth/bluetooth_uuid.h"
9 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
10 9
11 using device::BluetoothUUID; 10 using device::BluetoothUUID;
12 11
13 namespace content { 12 namespace content {
14 13
14 namespace {
15
16 std::string Canonicalize(const std::string& string) {
17 return device::BluetoothUUID(string).canonical_value();
18 }
19
20 } // namespace
21
15 class BluetoothBlacklistTest : public ::testing::Test { 22 class BluetoothBlacklistTest : public ::testing::Test {
16 public: 23 public:
17 BluetoothBlacklistTest() : list_(BluetoothBlacklist::Get()) { 24 BluetoothBlacklistTest() : list_(BluetoothBlacklist::Get()) {
18 // Because BluetoothBlacklist is used via a singleton instance, the data 25 // Because BluetoothBlacklist is used via a singleton instance, the data
19 // must be reset for each test. 26 // must be reset for each test.
20 list_.ResetToDefaultValuesForTest(); 27 list_.ResetToDefaultValuesForTest();
21 } 28 }
22 BluetoothBlacklist& list_; 29 BluetoothBlacklist& list_;
23 }; 30 };
24 31
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 list_.Add("\r\n0009:e\n\r"); 218 list_.Add("\r\n0009:e\n\r");
212 EXPECT_EQ(++previous_list_size, list_.size()); 219 EXPECT_EQ(++previous_list_size, list_.size());
213 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0009"))); 220 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0009")));
214 } 221 }
215 222
216 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsFalse) { 223 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsFalse) {
217 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 224 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE);
218 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS); 225 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS);
219 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 226 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES);
220 { 227 {
221 std::vector<BluetoothScanFilter> empty_filters; 228 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> empty_filters;
222 EXPECT_FALSE(list_.IsExcluded(empty_filters)); 229 EXPECT_FALSE(list_.IsExcluded(empty_filters));
223 } 230 }
224 { 231 {
225 std::vector<BluetoothScanFilter> single_empty_filter(1); 232 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> single_empty_filter(1);
226 EXPECT_EQ(0u, single_empty_filter[0].services.size()); 233
234 single_empty_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
235 single_empty_filter[0]->services = mojo::Array<mojo::String>();
236
237 EXPECT_EQ(0u, single_empty_filter[0]->services.size());
227 EXPECT_FALSE(list_.IsExcluded(single_empty_filter)); 238 EXPECT_FALSE(list_.IsExcluded(single_empty_filter));
228 } 239 }
229 { 240 {
230 std::vector<BluetoothScanFilter> single_non_matching_filter(1); 241 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>
231 single_non_matching_filter[0].services.push_back(BluetoothUUID("0000")); 242 single_non_matching_filter(1);
243
244 single_non_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
245 single_non_matching_filter[0]->services.push_back(Canonicalize("0000"));
246
232 EXPECT_FALSE(list_.IsExcluded(single_non_matching_filter)); 247 EXPECT_FALSE(list_.IsExcluded(single_non_matching_filter));
233 } 248 }
234 { 249 {
235 std::vector<BluetoothScanFilter> multiple_non_matching_filter(2); 250 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>
236 multiple_non_matching_filter[0].services.push_back(BluetoothUUID("0000")); 251 multiple_non_matching_filters(2);
237 multiple_non_matching_filter[0].services.push_back(BluetoothUUID("ee01")); 252
238 multiple_non_matching_filter[1].services.push_back(BluetoothUUID("ee02")); 253 multiple_non_matching_filters[0] =
239 multiple_non_matching_filter[1].services.push_back(BluetoothUUID("0003")); 254 blink::mojom::WebBluetoothScanFilter::New();
240 EXPECT_FALSE(list_.IsExcluded(multiple_non_matching_filter)); 255 multiple_non_matching_filters[0]->services.push_back(Canonicalize("0000"));
256 multiple_non_matching_filters[0]->services.push_back(Canonicalize("ee01"));
257
258 multiple_non_matching_filters[1] =
259 blink::mojom::WebBluetoothScanFilter::New();
260 multiple_non_matching_filters[1]->services.push_back(Canonicalize("ee02"));
261 multiple_non_matching_filters[1]->services.push_back(Canonicalize("0003"));
262
263 EXPECT_FALSE(list_.IsExcluded(multiple_non_matching_filters));
241 } 264 }
242 } 265 }
243 266
244 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsTrue) { 267 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsTrue) {
245 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 268 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE);
246 { 269 {
247 std::vector<BluetoothScanFilter> single_matching_filter(1); 270 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> single_matching_filter(
248 single_matching_filter[0].services.push_back(BluetoothUUID("eeee")); 271 1);
272
273 single_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
274 single_matching_filter[0]->services.push_back(Canonicalize("eeee"));
275
249 EXPECT_TRUE(list_.IsExcluded(single_matching_filter)); 276 EXPECT_TRUE(list_.IsExcluded(single_matching_filter));
250 } 277 }
251 { 278 {
252 std::vector<BluetoothScanFilter> first_matching_filter(2); 279 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> first_matching_filter(
253 first_matching_filter[0].services.push_back(BluetoothUUID("eeee")); 280 2);
254 first_matching_filter[0].services.push_back(BluetoothUUID("0001")); 281
255 first_matching_filter[1].services.push_back(BluetoothUUID("0002")); 282 first_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
256 first_matching_filter[1].services.push_back(BluetoothUUID("0003")); 283 first_matching_filter[0]->services.push_back(Canonicalize("eeee"));
284 first_matching_filter[0]->services.push_back(Canonicalize("0001"));
285
286 first_matching_filter[1] = blink::mojom::WebBluetoothScanFilter::New();
287 first_matching_filter[1]->services.push_back(Canonicalize("0002"));
288 first_matching_filter[1]->services.push_back(Canonicalize("0003"));
289
257 EXPECT_TRUE(list_.IsExcluded(first_matching_filter)); 290 EXPECT_TRUE(list_.IsExcluded(first_matching_filter));
258 } 291 }
259 { 292 {
260 std::vector<BluetoothScanFilter> last_matching_filter(2); 293 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> last_matching_filter(
261 last_matching_filter[0].services.push_back(BluetoothUUID("0001")); 294 2);
262 last_matching_filter[0].services.push_back(BluetoothUUID("0001")); 295
263 last_matching_filter[1].services.push_back(BluetoothUUID("0002")); 296 last_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
264 last_matching_filter[1].services.push_back(BluetoothUUID("eeee")); 297 last_matching_filter[0]->services.push_back(Canonicalize("0001"));
298 last_matching_filter[0]->services.push_back(Canonicalize("0001"));
299
300 last_matching_filter[1] = blink::mojom::WebBluetoothScanFilter::New();
301 last_matching_filter[1]->services.push_back(Canonicalize("0002"));
302 last_matching_filter[1]->services.push_back(Canonicalize("eeee"));
303
265 EXPECT_TRUE(list_.IsExcluded(last_matching_filter)); 304 EXPECT_TRUE(list_.IsExcluded(last_matching_filter));
266 } 305 }
267 { 306 {
268 std::vector<BluetoothScanFilter> multiple_matching_filter(2); 307 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>
269 multiple_matching_filter[0].services.push_back(BluetoothUUID("eeee")); 308 multiple_matching_filters(2);
270 multiple_matching_filter[0].services.push_back(BluetoothUUID("eeee")); 309
271 multiple_matching_filter[1].services.push_back(BluetoothUUID("eeee")); 310 multiple_matching_filters[0] = blink::mojom::WebBluetoothScanFilter::New();
272 multiple_matching_filter[1].services.push_back(BluetoothUUID("eeee")); 311 multiple_matching_filters[0]->services.push_back(Canonicalize("eeee"));
273 EXPECT_TRUE(list_.IsExcluded(multiple_matching_filter)); 312 multiple_matching_filters[0]->services.push_back(Canonicalize("eeee"));
313
314 multiple_matching_filters[1] = blink::mojom::WebBluetoothScanFilter::New();
315 multiple_matching_filters[1]->services.push_back(Canonicalize("eeee"));
316 multiple_matching_filters[1]->services.push_back(Canonicalize("eeee"));
317
318 EXPECT_TRUE(list_.IsExcluded(multiple_matching_filters));
274 } 319 }
275 } 320 }
276 321
277 TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_NonMatching) { 322 TEST_F(BluetoothBlacklistTest, RemoveExcludedUUIDs_NonMatching) {
278 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 323 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE);
279 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS); 324 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS);
280 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 325 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES);
326
327 // options.optional_services should be the same before and after
328 // RemoveExcludedUUIDs().
281 { 329 {
282 std::vector<BluetoothUUID> empty; 330 // Empty optional_services.
283 std::vector<BluetoothUUID> expected_empty; 331 blink::mojom::WebBluetoothRequestDeviceOptions options;
284 list_.RemoveExcludedUuids(&empty); 332 options.optional_services = mojo::Array<mojo::String>();
285 EXPECT_EQ(expected_empty, empty); 333
334 mojo::Array<mojo::String> expected = options.optional_services.Clone();
335
336 list_.RemoveExcludedUUIDs(&options);
337 EXPECT_TRUE(options.optional_services.Equals(expected));
286 } 338 }
287 { 339 {
288 std::vector<BluetoothUUID> single_non_matching; 340 // One non-matching service in optional_services.
289 single_non_matching.push_back(BluetoothUUID("0000")); 341 blink::mojom::WebBluetoothRequestDeviceOptions options;
342 options.optional_services.push_back(Canonicalize("0000"));
290 343
291 std::vector<BluetoothUUID> expected_copy(single_non_matching); 344 mojo::Array<mojo::String> expected = options.optional_services.Clone();
292 345
293 list_.RemoveExcludedUuids(&single_non_matching); 346 list_.RemoveExcludedUUIDs(&options);
294 EXPECT_EQ(expected_copy, single_non_matching); 347 EXPECT_TRUE(options.optional_services.Equals(expected));
295 } 348 }
296 { 349 {
297 std::vector<BluetoothUUID> multiple_non_matching; 350 // Multiple non-matching services in optional_services.
298 multiple_non_matching.push_back(BluetoothUUID("0000")); 351 blink::mojom::WebBluetoothRequestDeviceOptions options;
299 multiple_non_matching.push_back(BluetoothUUID("ee01")); 352 options.optional_services.push_back(Canonicalize("0000"));
300 multiple_non_matching.push_back(BluetoothUUID("ee02")); 353 options.optional_services.push_back(Canonicalize("ee01"));
301 multiple_non_matching.push_back(BluetoothUUID("0003")); 354 options.optional_services.push_back(Canonicalize("ee02"));
355 options.optional_services.push_back(Canonicalize("0003"));
302 356
303 std::vector<BluetoothUUID> expected_copy(multiple_non_matching); 357 mojo::Array<mojo::String> expected = options.optional_services.Clone();
304 358
305 list_.RemoveExcludedUuids(&multiple_non_matching); 359 list_.RemoveExcludedUUIDs(&options);
306 EXPECT_EQ(expected_copy, multiple_non_matching); 360 EXPECT_TRUE(options.optional_services.Equals(expected));
307 } 361 }
308 } 362 }
309 363
310 TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_Matching) { 364 TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_Matching) {
311 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 365 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE);
312 list_.Add(BluetoothUUID("eee2"), BluetoothBlacklist::Value::EXCLUDE); 366 list_.Add(BluetoothUUID("eee2"), BluetoothBlacklist::Value::EXCLUDE);
313 list_.Add(BluetoothUUID("eee3"), BluetoothBlacklist::Value::EXCLUDE); 367 list_.Add(BluetoothUUID("eee3"), BluetoothBlacklist::Value::EXCLUDE);
314 list_.Add(BluetoothUUID("eee4"), BluetoothBlacklist::Value::EXCLUDE); 368 list_.Add(BluetoothUUID("eee4"), BluetoothBlacklist::Value::EXCLUDE);
315 { 369 {
316 std::vector<BluetoothUUID> single_matching; 370 // Single matching service in optional_services.
317 single_matching.push_back(BluetoothUUID("eeee")); 371 blink::mojom::WebBluetoothRequestDeviceOptions options;
372 options.optional_services.push_back(Canonicalize("eeee"));
318 373
319 std::vector<BluetoothUUID> expected_empty; 374 mojo::Array<mojo::String> expected = mojo::Array<mojo::String>();
320 375
321 list_.RemoveExcludedUuids(&single_matching); 376 list_.RemoveExcludedUUIDs(&options);
322 EXPECT_EQ(expected_empty, single_matching); 377
378 EXPECT_TRUE(options.optional_services.Equals(expected));
323 } 379 }
324 { 380 {
325 std::vector<BluetoothUUID> single_matching_of_many; 381 // Single matching of many services in optional_services.
326 single_matching_of_many.push_back(BluetoothUUID("0000")); 382 blink::mojom::WebBluetoothRequestDeviceOptions options;
327 single_matching_of_many.push_back(BluetoothUUID("eeee")); 383 options.optional_services.push_back(Canonicalize("0000"));
328 single_matching_of_many.push_back(BluetoothUUID("0001")); 384 options.optional_services.push_back(Canonicalize("eeee"));
385 options.optional_services.push_back(Canonicalize("0001"));
329 386
330 std::vector<BluetoothUUID> expected; 387 mojo::Array<mojo::String> expected;
331 expected.push_back(BluetoothUUID("0000")); 388 expected.push_back(Canonicalize("0000"));
332 expected.push_back(BluetoothUUID("0001")); 389 expected.push_back(Canonicalize("0001"));
333 390
334 list_.RemoveExcludedUuids(&single_matching_of_many); 391 list_.RemoveExcludedUUIDs(&options);
335 EXPECT_EQ(expected, single_matching_of_many); 392 EXPECT_TRUE(options.optional_services.Equals(expected));
336 } 393 }
337 { 394 {
338 std::vector<BluetoothUUID> all_matching_of_many; 395 // All matching of many services in optional_services.
339 all_matching_of_many.push_back(BluetoothUUID("eee2")); 396 blink::mojom::WebBluetoothRequestDeviceOptions options;
340 all_matching_of_many.push_back(BluetoothUUID("eee4")); 397 options.optional_services.push_back(Canonicalize("eee2"));
341 all_matching_of_many.push_back(BluetoothUUID("eee3")); 398 options.optional_services.push_back(Canonicalize("eee4"));
342 all_matching_of_many.push_back(BluetoothUUID("eeee")); 399 options.optional_services.push_back(Canonicalize("eee3"));
400 options.optional_services.push_back(Canonicalize("eeee"));
343 401
344 std::vector<BluetoothUUID> expected_empty; 402 mojo::Array<mojo::String> expected = mojo::Array<mojo::String>();
345 403
346 list_.RemoveExcludedUuids(&all_matching_of_many); 404 list_.RemoveExcludedUUIDs(&options);
347 EXPECT_EQ(expected_empty, all_matching_of_many); 405 EXPECT_TRUE(options.optional_services.Equals(expected));
348 } 406 }
349 } 407 }
350 408
351 TEST_F(BluetoothBlacklistTest, VerifyDefaultBlacklistSize) { 409 TEST_F(BluetoothBlacklistTest, VerifyDefaultBlacklistSize) {
352 // When adding items to the blacklist the new values should be added in the 410 // When adding items to the blacklist the new values should be added in the
353 // tests below for each exclusion type. 411 // tests below for each exclusion type.
354 EXPECT_EQ(11u, list_.size()); 412 EXPECT_EQ(11u, list_.size());
355 } 413 }
356 414
357 TEST_F(BluetoothBlacklistTest, VerifyDefaultExcludeList) { 415 TEST_F(BluetoothBlacklistTest, VerifyDefaultExcludeList) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a02"))); 447 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a02")));
390 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a03"))); 448 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a03")));
391 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a25"))); 449 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a25")));
392 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2902"))); 450 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2902")));
393 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2903"))); 451 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2903")));
394 EXPECT_TRUE(list_.IsExcludedFromWrites( 452 EXPECT_TRUE(list_.IsExcludedFromWrites(
395 BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c"))); 453 BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c")));
396 } 454 }
397 455
398 } // namespace content 456 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698