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

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

Issue 2506813003: Use new wrapper types for web_bluetooth.mojom (Closed)
Patch Set: updated web_bluetooth_impl.cc Created 4 years, 1 month 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 "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;
11 11
12 namespace content { 12 namespace content {
13 13
14 namespace { 14 namespace {
15 15
16 base::Optional<BluetoothUUID> Canonicalize(const std::string& str) { 16 BluetoothUUID Canonicalize(const std::string& str) {
ortuno 2016/11/21 04:42:31 I think we can get rid of this now. Canonicalize i
juncai 2016/11/21 21:27:05 Done.
17 return base::make_optional(device::BluetoothUUID(str)); 17 return device::BluetoothUUID(str);
18 } 18 }
19 19
20 } // namespace 20 } // namespace
21 21
22 class BluetoothBlacklistTest : public ::testing::Test { 22 class BluetoothBlacklistTest : public ::testing::Test {
23 public: 23 public:
24 BluetoothBlacklistTest() : list_(BluetoothBlacklist::Get()) { 24 BluetoothBlacklistTest() : list_(BluetoothBlacklist::Get()) {
25 // Because BluetoothBlacklist is used via a singleton instance, the data 25 // Because BluetoothBlacklist is used via a singleton instance, the data
26 // must be reset for each test. 26 // must be reset for each test.
27 list_.ResetToDefaultValuesForTest(); 27 list_.ResetToDefaultValuesForTest();
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 list_.Add("\r\n0009:e\n\r"); 218 list_.Add("\r\n0009:e\n\r");
219 EXPECT_EQ(++previous_list_size, list_.size()); 219 EXPECT_EQ(++previous_list_size, list_.size());
220 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0009"))); 220 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0009")));
221 } 221 }
222 222
223 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsFalse) { 223 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsFalse) {
224 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 224 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE);
225 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS); 225 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS);
226 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 226 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES);
227 { 227 {
228 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> empty_filters; 228 std::vector<blink::mojom::WebBluetoothScanFilterPtr> empty_filters;
229 EXPECT_FALSE(list_.IsExcluded(empty_filters)); 229 EXPECT_FALSE(list_.IsExcluded(empty_filters));
230 } 230 }
231 { 231 {
232 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> single_empty_filter(1); 232 std::vector<blink::mojom::WebBluetoothScanFilterPtr> single_empty_filter(1);
233 233
234 single_empty_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); 234 single_empty_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
235 single_empty_filter[0]->services = 235 single_empty_filter[0]->services = std::vector<BluetoothUUID>();
236 mojo::Array<base::Optional<BluetoothUUID>>();
237 236
238 EXPECT_EQ(0u, single_empty_filter[0]->services.size()); 237 EXPECT_EQ(0u, single_empty_filter[0]->services->size());
239 EXPECT_FALSE(list_.IsExcluded(single_empty_filter)); 238 EXPECT_FALSE(list_.IsExcluded(single_empty_filter));
240 } 239 }
241 { 240 {
242 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> 241 std::vector<blink::mojom::WebBluetoothScanFilterPtr>
243 single_non_matching_filter(1); 242 single_non_matching_filter(1);
244 243
245 single_non_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); 244 single_non_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
246 single_non_matching_filter[0]->services.push_back(Canonicalize("0000")); 245 single_non_matching_filter[0]->services = std::vector<BluetoothUUID>();
246 single_non_matching_filter[0]->services->push_back(Canonicalize("0000"));
247 247
248 EXPECT_FALSE(list_.IsExcluded(single_non_matching_filter)); 248 EXPECT_FALSE(list_.IsExcluded(single_non_matching_filter));
249 } 249 }
250 { 250 {
251 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> 251 std::vector<blink::mojom::WebBluetoothScanFilterPtr>
252 multiple_non_matching_filters(2); 252 multiple_non_matching_filters(2);
253 253
254 multiple_non_matching_filters[0] = 254 multiple_non_matching_filters[0] =
255 blink::mojom::WebBluetoothScanFilter::New(); 255 blink::mojom::WebBluetoothScanFilter::New();
256 multiple_non_matching_filters[0]->services.push_back(Canonicalize("0000")); 256 multiple_non_matching_filters[0]->services = std::vector<BluetoothUUID>();
257 multiple_non_matching_filters[0]->services.push_back(Canonicalize("ee01")); 257 multiple_non_matching_filters[0]->services->push_back(Canonicalize("0000"));
258 multiple_non_matching_filters[0]->services->push_back(Canonicalize("ee01"));
258 259
259 multiple_non_matching_filters[1] = 260 multiple_non_matching_filters[1] =
260 blink::mojom::WebBluetoothScanFilter::New(); 261 blink::mojom::WebBluetoothScanFilter::New();
261 multiple_non_matching_filters[1]->services.push_back(Canonicalize("ee02")); 262 multiple_non_matching_filters[1]->services = std::vector<BluetoothUUID>();
262 multiple_non_matching_filters[1]->services.push_back(Canonicalize("0003")); 263 multiple_non_matching_filters[1]->services->push_back(Canonicalize("ee02"));
264 multiple_non_matching_filters[1]->services->push_back(Canonicalize("0003"));
263 265
264 EXPECT_FALSE(list_.IsExcluded(multiple_non_matching_filters)); 266 EXPECT_FALSE(list_.IsExcluded(multiple_non_matching_filters));
265 } 267 }
266 } 268 }
267 269
268 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsTrue) { 270 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsTrue) {
269 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 271 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE);
270 { 272 {
271 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> single_matching_filter( 273 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> single_matching_filter(
272 1); 274 1);
273 275
274 single_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); 276 single_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
275 single_matching_filter[0]->services.push_back(Canonicalize("eeee")); 277 single_matching_filter[0]->services = std::vector<BluetoothUUID>();
278 single_matching_filter[0]->services->push_back(Canonicalize("eeee"));
276 279
277 EXPECT_TRUE(list_.IsExcluded(single_matching_filter)); 280 EXPECT_TRUE(list_.IsExcluded(single_matching_filter));
278 } 281 }
279 { 282 {
280 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> first_matching_filter( 283 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> first_matching_filter(
281 2); 284 2);
282 285
283 first_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); 286 first_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
284 first_matching_filter[0]->services.push_back(Canonicalize("eeee")); 287 first_matching_filter[0]->services = std::vector<BluetoothUUID>();
285 first_matching_filter[0]->services.push_back(Canonicalize("0001")); 288 first_matching_filter[0]->services->push_back(Canonicalize("eeee"));
289 first_matching_filter[0]->services->push_back(Canonicalize("0001"));
286 290
287 first_matching_filter[1] = blink::mojom::WebBluetoothScanFilter::New(); 291 first_matching_filter[1] = blink::mojom::WebBluetoothScanFilter::New();
288 first_matching_filter[1]->services.push_back(Canonicalize("0002")); 292 first_matching_filter[1]->services = std::vector<BluetoothUUID>();
289 first_matching_filter[1]->services.push_back(Canonicalize("0003")); 293 first_matching_filter[1]->services->push_back(Canonicalize("0002"));
294 first_matching_filter[1]->services->push_back(Canonicalize("0003"));
290 295
291 EXPECT_TRUE(list_.IsExcluded(first_matching_filter)); 296 EXPECT_TRUE(list_.IsExcluded(first_matching_filter));
292 } 297 }
293 { 298 {
294 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> last_matching_filter( 299 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> last_matching_filter(
295 2); 300 2);
296 301
297 last_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); 302 last_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
298 last_matching_filter[0]->services.push_back(Canonicalize("0001")); 303 last_matching_filter[0]->services = std::vector<BluetoothUUID>();
299 last_matching_filter[0]->services.push_back(Canonicalize("0001")); 304 last_matching_filter[0]->services->push_back(Canonicalize("0001"));
305 last_matching_filter[0]->services->push_back(Canonicalize("0001"));
300 306
301 last_matching_filter[1] = blink::mojom::WebBluetoothScanFilter::New(); 307 last_matching_filter[1] = blink::mojom::WebBluetoothScanFilter::New();
302 last_matching_filter[1]->services.push_back(Canonicalize("0002")); 308 last_matching_filter[1]->services = std::vector<BluetoothUUID>();
303 last_matching_filter[1]->services.push_back(Canonicalize("eeee")); 309 last_matching_filter[1]->services->push_back(Canonicalize("0002"));
310 last_matching_filter[1]->services->push_back(Canonicalize("eeee"));
304 311
305 EXPECT_TRUE(list_.IsExcluded(last_matching_filter)); 312 EXPECT_TRUE(list_.IsExcluded(last_matching_filter));
306 } 313 }
307 { 314 {
308 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> 315 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>
309 multiple_matching_filters(2); 316 multiple_matching_filters(2);
310 317
311 multiple_matching_filters[0] = blink::mojom::WebBluetoothScanFilter::New(); 318 multiple_matching_filters[0] = blink::mojom::WebBluetoothScanFilter::New();
312 multiple_matching_filters[0]->services.push_back(Canonicalize("eeee")); 319 multiple_matching_filters[0]->services = std::vector<BluetoothUUID>();
313 multiple_matching_filters[0]->services.push_back(Canonicalize("eeee")); 320 multiple_matching_filters[0]->services->push_back(Canonicalize("eeee"));
321 multiple_matching_filters[0]->services->push_back(Canonicalize("eeee"));
314 322
315 multiple_matching_filters[1] = blink::mojom::WebBluetoothScanFilter::New(); 323 multiple_matching_filters[1] = blink::mojom::WebBluetoothScanFilter::New();
316 multiple_matching_filters[1]->services.push_back(Canonicalize("eeee")); 324 multiple_matching_filters[1]->services = std::vector<BluetoothUUID>();
317 multiple_matching_filters[1]->services.push_back(Canonicalize("eeee")); 325 multiple_matching_filters[1]->services->push_back(Canonicalize("eeee"));
326 multiple_matching_filters[1]->services->push_back(Canonicalize("eeee"));
318 327
319 EXPECT_TRUE(list_.IsExcluded(multiple_matching_filters)); 328 EXPECT_TRUE(list_.IsExcluded(multiple_matching_filters));
320 } 329 }
321 } 330 }
322 331
323 TEST_F(BluetoothBlacklistTest, RemoveExcludedUUIDs_NonMatching) { 332 TEST_F(BluetoothBlacklistTest, RemoveExcludedUUIDs_NonMatching) {
324 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 333 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE);
325 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS); 334 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS);
326 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 335 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES);
327 336
328 // options.optional_services should be the same before and after 337 // options.optional_services should be the same before and after
329 // RemoveExcludedUUIDs(). 338 // RemoveExcludedUUIDs().
330 { 339 {
331 // Empty optional_services. 340 // Empty optional_services.
332 blink::mojom::WebBluetoothRequestDeviceOptions options; 341 blink::mojom::WebBluetoothRequestDeviceOptions options;
333 options.optional_services = mojo::Array<base::Optional<BluetoothUUID>>();
334 342
335 mojo::Array<base::Optional<BluetoothUUID>> expected = 343 std::vector<BluetoothUUID> expected = options.optional_services;
336 options.optional_services.Clone();
337 344
338 list_.RemoveExcludedUUIDs(&options); 345 list_.RemoveExcludedUUIDs(&options);
339 EXPECT_TRUE(options.optional_services.Equals(expected)); 346 EXPECT_EQ(expected, options.optional_services);
340 } 347 }
341 { 348 {
342 // One non-matching service in optional_services. 349 // One non-matching service in optional_services.
343 blink::mojom::WebBluetoothRequestDeviceOptions options; 350 blink::mojom::WebBluetoothRequestDeviceOptions options;
344 options.optional_services.push_back(Canonicalize("0000")); 351 options.optional_services.push_back(Canonicalize("0000"));
345 352
346 mojo::Array<base::Optional<BluetoothUUID>> expected = 353 std::vector<BluetoothUUID> expected = options.optional_services;
347 options.optional_services.Clone();
348 354
349 list_.RemoveExcludedUUIDs(&options); 355 list_.RemoveExcludedUUIDs(&options);
350 EXPECT_TRUE(options.optional_services.Equals(expected)); 356 EXPECT_EQ(expected, options.optional_services);
351 } 357 }
352 { 358 {
353 // Multiple non-matching services in optional_services. 359 // Multiple non-matching services in optional_services.
354 blink::mojom::WebBluetoothRequestDeviceOptions options; 360 blink::mojom::WebBluetoothRequestDeviceOptions options;
355 options.optional_services.push_back(Canonicalize("0000")); 361 options.optional_services.push_back(Canonicalize("0000"));
356 options.optional_services.push_back(Canonicalize("ee01")); 362 options.optional_services.push_back(Canonicalize("ee01"));
357 options.optional_services.push_back(Canonicalize("ee02")); 363 options.optional_services.push_back(Canonicalize("ee02"));
358 options.optional_services.push_back(Canonicalize("0003")); 364 options.optional_services.push_back(Canonicalize("0003"));
359 365
360 mojo::Array<base::Optional<BluetoothUUID>> expected = 366 std::vector<BluetoothUUID> expected = options.optional_services;
361 options.optional_services.Clone();
362 367
363 list_.RemoveExcludedUUIDs(&options); 368 list_.RemoveExcludedUUIDs(&options);
364 EXPECT_TRUE(options.optional_services.Equals(expected)); 369 EXPECT_EQ(expected, options.optional_services);
365 } 370 }
366 } 371 }
367 372
368 TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_Matching) { 373 TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_Matching) {
369 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 374 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE);
370 list_.Add(BluetoothUUID("eee2"), BluetoothBlacklist::Value::EXCLUDE); 375 list_.Add(BluetoothUUID("eee2"), BluetoothBlacklist::Value::EXCLUDE);
371 list_.Add(BluetoothUUID("eee3"), BluetoothBlacklist::Value::EXCLUDE); 376 list_.Add(BluetoothUUID("eee3"), BluetoothBlacklist::Value::EXCLUDE);
372 list_.Add(BluetoothUUID("eee4"), BluetoothBlacklist::Value::EXCLUDE); 377 list_.Add(BluetoothUUID("eee4"), BluetoothBlacklist::Value::EXCLUDE);
373 { 378 {
374 // Single matching service in optional_services. 379 // Single matching service in optional_services.
375 blink::mojom::WebBluetoothRequestDeviceOptions options; 380 blink::mojom::WebBluetoothRequestDeviceOptions options;
376 options.optional_services.push_back(Canonicalize("eeee")); 381 options.optional_services.push_back(Canonicalize("eeee"));
377 382
378 mojo::Array<base::Optional<BluetoothUUID>> expected; 383 std::vector<BluetoothUUID> expected;
379 384
380 list_.RemoveExcludedUUIDs(&options); 385 list_.RemoveExcludedUUIDs(&options);
381 386
382 EXPECT_TRUE(options.optional_services.Equals(expected)); 387 EXPECT_EQ(expected, options.optional_services);
383 } 388 }
384 { 389 {
385 // Single matching of many services in optional_services. 390 // Single matching of many services in optional_services.
386 blink::mojom::WebBluetoothRequestDeviceOptions options; 391 blink::mojom::WebBluetoothRequestDeviceOptions options;
387 options.optional_services.push_back(Canonicalize("0000")); 392 options.optional_services.push_back(Canonicalize("0000"));
388 options.optional_services.push_back(Canonicalize("eeee")); 393 options.optional_services.push_back(Canonicalize("eeee"));
389 options.optional_services.push_back(Canonicalize("0001")); 394 options.optional_services.push_back(Canonicalize("0001"));
390 395
391 mojo::Array<base::Optional<BluetoothUUID>> expected; 396 std::vector<BluetoothUUID> expected;
392 expected.push_back(Canonicalize("0000")); 397 expected.push_back(Canonicalize("0000"));
393 expected.push_back(Canonicalize("0001")); 398 expected.push_back(Canonicalize("0001"));
394 399
395 list_.RemoveExcludedUUIDs(&options); 400 list_.RemoveExcludedUUIDs(&options);
396 EXPECT_TRUE(options.optional_services.Equals(expected)); 401 EXPECT_EQ(expected, options.optional_services);
397 } 402 }
398 { 403 {
399 // All matching of many services in optional_services. 404 // All matching of many services in optional_services.
400 blink::mojom::WebBluetoothRequestDeviceOptions options; 405 blink::mojom::WebBluetoothRequestDeviceOptions options;
401 options.optional_services.push_back(Canonicalize("eee2")); 406 options.optional_services.push_back(Canonicalize("eee2"));
402 options.optional_services.push_back(Canonicalize("eee4")); 407 options.optional_services.push_back(Canonicalize("eee4"));
403 options.optional_services.push_back(Canonicalize("eee3")); 408 options.optional_services.push_back(Canonicalize("eee3"));
404 options.optional_services.push_back(Canonicalize("eeee")); 409 options.optional_services.push_back(Canonicalize("eeee"));
405 410
406 mojo::Array<base::Optional<BluetoothUUID>> expected; 411 std::vector<BluetoothUUID> expected;
407 412
408 list_.RemoveExcludedUUIDs(&options); 413 list_.RemoveExcludedUUIDs(&options);
409 EXPECT_TRUE(options.optional_services.Equals(expected)); 414 EXPECT_EQ(expected, options.optional_services);
410 } 415 }
411 } 416 }
412 417
413 TEST_F(BluetoothBlacklistTest, VerifyDefaultBlacklistSize) { 418 TEST_F(BluetoothBlacklistTest, VerifyDefaultBlacklistSize) {
414 // REMINDER: ADD new blacklist items to tests below for each exclusion type. 419 // REMINDER: ADD new blacklist items to tests below for each exclusion type.
415 EXPECT_EQ(13u, list_.size()); 420 EXPECT_EQ(13u, list_.size());
416 } 421 }
417 422
418 TEST_F(BluetoothBlacklistTest, VerifyDefaultExcludeList) { 423 TEST_F(BluetoothBlacklistTest, VerifyDefaultExcludeList) {
419 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("1800"))); 424 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("1800")));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 BluetoothUUID("bad1c9a2-9a5b-4015-8b60-1579bbbf2135"))); 483 BluetoothUUID("bad1c9a2-9a5b-4015-8b60-1579bbbf2135")));
479 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2902"))); 484 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2902")));
480 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2903"))); 485 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2903")));
481 EXPECT_TRUE(list_.IsExcludedFromWrites( 486 EXPECT_TRUE(list_.IsExcludedFromWrites(
482 BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c"))); 487 BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c")));
483 EXPECT_FALSE(list_.IsExcludedFromWrites( 488 EXPECT_FALSE(list_.IsExcludedFromWrites(
484 BluetoothUUID("bad3ec61-3cc3-4954-9702-7977df514114"))); 489 BluetoothUUID("bad3ec61-3cc3-4954-9702-7977df514114")));
485 } 490 }
486 491
487 } // namespace content 492 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698