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

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: Remove debug log 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
15 class BluetoothBlacklistTest : public ::testing::Test { 14 class BluetoothBlacklistTest : public ::testing::Test {
16 public: 15 public:
17 BluetoothBlacklistTest() : list_(BluetoothBlacklist::Get()) { 16 BluetoothBlacklistTest() : list_(BluetoothBlacklist::Get()) {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 list_.Add("\r\n0009:e\n\r"); 210 list_.Add("\r\n0009:e\n\r");
212 EXPECT_EQ(++previous_list_size, list_.size()); 211 EXPECT_EQ(++previous_list_size, list_.size());
213 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0009"))); 212 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0009")));
214 } 213 }
215 214
216 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsFalse) { 215 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsFalse) {
217 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 216 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE);
218 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS); 217 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS);
219 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 218 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES);
220 { 219 {
221 std::vector<BluetoothScanFilter> empty_filters; 220 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> empty_filters;
222 EXPECT_FALSE(list_.IsExcluded(empty_filters)); 221 EXPECT_FALSE(list_.IsExcluded(empty_filters));
223 } 222 }
224 { 223 {
225 std::vector<BluetoothScanFilter> single_empty_filter(1); 224 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> single_empty_filter(1);
226 EXPECT_EQ(0u, single_empty_filter[0].services.size()); 225
226 single_empty_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
227 single_empty_filter[0]->services = mojo::Array<mojo::String>();
228
229 EXPECT_EQ(0u, single_empty_filter[0]->services.size());
227 EXPECT_FALSE(list_.IsExcluded(single_empty_filter)); 230 EXPECT_FALSE(list_.IsExcluded(single_empty_filter));
228 } 231 }
229 { 232 {
230 std::vector<BluetoothScanFilter> single_non_matching_filter(1); 233 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>
231 single_non_matching_filter[0].services.push_back(BluetoothUUID("0000")); 234 single_non_matching_filter(1);
235
236 single_non_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
237 single_non_matching_filter[0]->services.push_back(
238 BluetoothUUID("0000").canonical_value());
239
232 EXPECT_FALSE(list_.IsExcluded(single_non_matching_filter)); 240 EXPECT_FALSE(list_.IsExcluded(single_non_matching_filter));
233 } 241 }
234 { 242 {
235 std::vector<BluetoothScanFilter> multiple_non_matching_filter(2); 243 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>
236 multiple_non_matching_filter[0].services.push_back(BluetoothUUID("0000")); 244 multiple_non_matching_filters(2);
237 multiple_non_matching_filter[0].services.push_back(BluetoothUUID("ee01")); 245
238 multiple_non_matching_filter[1].services.push_back(BluetoothUUID("ee02")); 246 multiple_non_matching_filters[0] =
239 multiple_non_matching_filter[1].services.push_back(BluetoothUUID("0003")); 247 blink::mojom::WebBluetoothScanFilter::New();
240 EXPECT_FALSE(list_.IsExcluded(multiple_non_matching_filter)); 248 multiple_non_matching_filters[0]->services.push_back(
249 BluetoothUUID("0000").canonical_value());
Jeffrey Yasskin 2016/05/13 04:41:58 Maybe write a local Canonicalize() function to get
ortuno 2016/05/13 20:11:17 Done.
250 multiple_non_matching_filters[0]->services.push_back(
251 BluetoothUUID("ee01").canonical_value());
252
253 multiple_non_matching_filters[1] =
254 blink::mojom::WebBluetoothScanFilter::New();
255 multiple_non_matching_filters[1]->services.push_back(
256 BluetoothUUID("ee02").canonical_value());
257 multiple_non_matching_filters[1]->services.push_back(
258 BluetoothUUID("0003").canonical_value());
259
260 EXPECT_FALSE(list_.IsExcluded(multiple_non_matching_filters));
241 } 261 }
242 } 262 }
243 263
244 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsTrue) { 264 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsTrue) {
245 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 265 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE);
246 { 266 {
247 std::vector<BluetoothScanFilter> single_matching_filter(1); 267 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> single_matching_filter(
248 single_matching_filter[0].services.push_back(BluetoothUUID("eeee")); 268 1);
269
270 single_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
271 single_matching_filter[0]->services.push_back(
272 BluetoothUUID("eeee").canonical_value());
273
249 EXPECT_TRUE(list_.IsExcluded(single_matching_filter)); 274 EXPECT_TRUE(list_.IsExcluded(single_matching_filter));
250 } 275 }
251 { 276 {
252 std::vector<BluetoothScanFilter> first_matching_filter(2); 277 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> first_matching_filter(
253 first_matching_filter[0].services.push_back(BluetoothUUID("eeee")); 278 2);
254 first_matching_filter[0].services.push_back(BluetoothUUID("0001")); 279
255 first_matching_filter[1].services.push_back(BluetoothUUID("0002")); 280 first_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
256 first_matching_filter[1].services.push_back(BluetoothUUID("0003")); 281 first_matching_filter[0]->services.push_back(
282 BluetoothUUID("eeee").canonical_value());
283 first_matching_filter[0]->services.push_back(
284 BluetoothUUID("0001").canonical_value());
285
286 first_matching_filter[1] = blink::mojom::WebBluetoothScanFilter::New();
287 first_matching_filter[1]->services.push_back(
288 BluetoothUUID("0002").canonical_value());
289 first_matching_filter[1]->services.push_back(
290 BluetoothUUID("0003").canonical_value());
291
257 EXPECT_TRUE(list_.IsExcluded(first_matching_filter)); 292 EXPECT_TRUE(list_.IsExcluded(first_matching_filter));
258 } 293 }
259 { 294 {
260 std::vector<BluetoothScanFilter> last_matching_filter(2); 295 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> last_matching_filter(
261 last_matching_filter[0].services.push_back(BluetoothUUID("0001")); 296 2);
262 last_matching_filter[0].services.push_back(BluetoothUUID("0001")); 297
263 last_matching_filter[1].services.push_back(BluetoothUUID("0002")); 298 last_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
264 last_matching_filter[1].services.push_back(BluetoothUUID("eeee")); 299 last_matching_filter[0]->services.push_back(
300 BluetoothUUID("0001").canonical_value());
301 last_matching_filter[0]->services.push_back(
302 BluetoothUUID("0001").canonical_value());
303
304 last_matching_filter[1] = blink::mojom::WebBluetoothScanFilter::New();
305 last_matching_filter[1]->services.push_back(
306 BluetoothUUID("0002").canonical_value());
307 last_matching_filter[1]->services.push_back(
308 BluetoothUUID("eeee").canonical_value());
309
265 EXPECT_TRUE(list_.IsExcluded(last_matching_filter)); 310 EXPECT_TRUE(list_.IsExcluded(last_matching_filter));
266 } 311 }
267 { 312 {
268 std::vector<BluetoothScanFilter> multiple_matching_filter(2); 313 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>
269 multiple_matching_filter[0].services.push_back(BluetoothUUID("eeee")); 314 multiple_matching_filters(2);
270 multiple_matching_filter[0].services.push_back(BluetoothUUID("eeee")); 315
271 multiple_matching_filter[1].services.push_back(BluetoothUUID("eeee")); 316 multiple_matching_filters[0] = blink::mojom::WebBluetoothScanFilter::New();
272 multiple_matching_filter[1].services.push_back(BluetoothUUID("eeee")); 317 multiple_matching_filters[0]->services.push_back(
273 EXPECT_TRUE(list_.IsExcluded(multiple_matching_filter)); 318 BluetoothUUID("eeee").canonical_value());
319 multiple_matching_filters[0]->services.push_back(
320 BluetoothUUID("eeee").canonical_value());
321
322 multiple_matching_filters[1] = blink::mojom::WebBluetoothScanFilter::New();
323 multiple_matching_filters[1]->services.push_back(
324 BluetoothUUID("eeee").canonical_value());
325 multiple_matching_filters[1]->services.push_back(
326 BluetoothUUID("eeee").canonical_value());
327
328 EXPECT_TRUE(list_.IsExcluded(multiple_matching_filters));
274 } 329 }
275 } 330 }
276 331
277 TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_NonMatching) { 332 TEST_F(BluetoothBlacklistTest, RemoveExcludedUUIDs_NonMatching) {
278 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 333 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE);
279 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS); 334 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS);
280 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 335 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES);
336
337 // options.optional_services should be the same before and after
338 // RemoveExcludedUUIDs().
281 { 339 {
282 std::vector<BluetoothUUID> empty; 340 // Empty optional_services.
283 std::vector<BluetoothUUID> expected_empty; 341 blink::mojom::WebBluetoothRequestDeviceOptions options;
284 list_.RemoveExcludedUuids(&empty); 342 options.optional_services = mojo::Array<mojo::String>();
285 EXPECT_EQ(expected_empty, empty); 343
344 mojo::Array<mojo::String> expected = options.optional_services.Clone();
345
346 list_.RemoveExcludedUUIDs(&options);
347 EXPECT_TRUE(options.optional_services.Equals(expected));
286 } 348 }
287 { 349 {
288 std::vector<BluetoothUUID> single_non_matching; 350 // One non-matching service in optional_services.
289 single_non_matching.push_back(BluetoothUUID("0000")); 351 blink::mojom::WebBluetoothRequestDeviceOptions options;
352 options.optional_services.push_back(
353 BluetoothUUID("0000").canonical_value());
290 354
291 std::vector<BluetoothUUID> expected_copy(single_non_matching); 355 mojo::Array<mojo::String> expected = options.optional_services.Clone();
292 356
293 list_.RemoveExcludedUuids(&single_non_matching); 357 list_.RemoveExcludedUUIDs(&options);
294 EXPECT_EQ(expected_copy, single_non_matching); 358 EXPECT_TRUE(options.optional_services.Equals(expected));
295 } 359 }
296 { 360 {
297 std::vector<BluetoothUUID> multiple_non_matching; 361 // Multiple non-matching services in optional_services.
298 multiple_non_matching.push_back(BluetoothUUID("0000")); 362 blink::mojom::WebBluetoothRequestDeviceOptions options;
299 multiple_non_matching.push_back(BluetoothUUID("ee01")); 363 options.optional_services.push_back(
300 multiple_non_matching.push_back(BluetoothUUID("ee02")); 364 BluetoothUUID("0000").canonical_value());
301 multiple_non_matching.push_back(BluetoothUUID("0003")); 365 options.optional_services.push_back(
366 BluetoothUUID("ee01").canonical_value());
367 options.optional_services.push_back(
368 BluetoothUUID("ee02").canonical_value());
369 options.optional_services.push_back(
370 BluetoothUUID("0003").canonical_value());
302 371
303 std::vector<BluetoothUUID> expected_copy(multiple_non_matching); 372 mojo::Array<mojo::String> expected = options.optional_services.Clone();
304 373
305 list_.RemoveExcludedUuids(&multiple_non_matching); 374 list_.RemoveExcludedUUIDs(&options);
306 EXPECT_EQ(expected_copy, multiple_non_matching); 375 EXPECT_TRUE(options.optional_services.Equals(expected));
307 } 376 }
308 } 377 }
309 378
310 TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_Matching) { 379 TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_Matching) {
311 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 380 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE);
312 list_.Add(BluetoothUUID("eee2"), BluetoothBlacklist::Value::EXCLUDE); 381 list_.Add(BluetoothUUID("eee2"), BluetoothBlacklist::Value::EXCLUDE);
313 list_.Add(BluetoothUUID("eee3"), BluetoothBlacklist::Value::EXCLUDE); 382 list_.Add(BluetoothUUID("eee3"), BluetoothBlacklist::Value::EXCLUDE);
314 list_.Add(BluetoothUUID("eee4"), BluetoothBlacklist::Value::EXCLUDE); 383 list_.Add(BluetoothUUID("eee4"), BluetoothBlacklist::Value::EXCLUDE);
315 { 384 {
316 std::vector<BluetoothUUID> single_matching; 385 // Single matching service in optional_services.
317 single_matching.push_back(BluetoothUUID("eeee")); 386 blink::mojom::WebBluetoothRequestDeviceOptions options;
387 options.optional_services.push_back(
388 BluetoothUUID("eeee").canonical_value());
318 389
319 std::vector<BluetoothUUID> expected_empty; 390 mojo::Array<mojo::String> expected = mojo::Array<mojo::String>();
320 391
321 list_.RemoveExcludedUuids(&single_matching); 392 list_.RemoveExcludedUUIDs(&options);
322 EXPECT_EQ(expected_empty, single_matching); 393
394 EXPECT_TRUE(options.optional_services.Equals(expected));
323 } 395 }
324 { 396 {
325 std::vector<BluetoothUUID> single_matching_of_many; 397 // Single matching of many services in optional_services.
326 single_matching_of_many.push_back(BluetoothUUID("0000")); 398 blink::mojom::WebBluetoothRequestDeviceOptions options;
327 single_matching_of_many.push_back(BluetoothUUID("eeee")); 399 options.optional_services.push_back(
328 single_matching_of_many.push_back(BluetoothUUID("0001")); 400 BluetoothUUID("0000").canonical_value());
401 options.optional_services.push_back(
402 BluetoothUUID("eeee").canonical_value());
403 options.optional_services.push_back(
404 BluetoothUUID("0001").canonical_value());
329 405
330 std::vector<BluetoothUUID> expected; 406 mojo::Array<mojo::String> expected;
331 expected.push_back(BluetoothUUID("0000")); 407 expected.push_back(BluetoothUUID("0000").canonical_value());
332 expected.push_back(BluetoothUUID("0001")); 408 expected.push_back(BluetoothUUID("0001").canonical_value());
333 409
334 list_.RemoveExcludedUuids(&single_matching_of_many); 410 list_.RemoveExcludedUUIDs(&options);
335 EXPECT_EQ(expected, single_matching_of_many); 411 EXPECT_TRUE(options.optional_services.Equals(expected));
336 } 412 }
337 { 413 {
338 std::vector<BluetoothUUID> all_matching_of_many; 414 // All matching of many services in optional_services.
339 all_matching_of_many.push_back(BluetoothUUID("eee2")); 415 blink::mojom::WebBluetoothRequestDeviceOptions options;
340 all_matching_of_many.push_back(BluetoothUUID("eee4")); 416 options.optional_services.push_back(
341 all_matching_of_many.push_back(BluetoothUUID("eee3")); 417 BluetoothUUID("eee2").canonical_value());
342 all_matching_of_many.push_back(BluetoothUUID("eeee")); 418 options.optional_services.push_back(
419 BluetoothUUID("eee4").canonical_value());
420 options.optional_services.push_back(
421 BluetoothUUID("eee3").canonical_value());
422 options.optional_services.push_back(
423 BluetoothUUID("eeee").canonical_value());
343 424
344 std::vector<BluetoothUUID> expected_empty; 425 mojo::Array<mojo::String> expected = mojo::Array<mojo::String>();
345 426
346 list_.RemoveExcludedUuids(&all_matching_of_many); 427 list_.RemoveExcludedUUIDs(&options);
347 EXPECT_EQ(expected_empty, all_matching_of_many); 428 EXPECT_TRUE(options.optional_services.Equals(expected));
348 } 429 }
349 } 430 }
350 431
351 TEST_F(BluetoothBlacklistTest, VerifyDefaultBlacklistSize) { 432 TEST_F(BluetoothBlacklistTest, VerifyDefaultBlacklistSize) {
352 // When adding items to the blacklist the new values should be added in the 433 // When adding items to the blacklist the new values should be added in the
353 // tests below for each exclusion type. 434 // tests below for each exclusion type.
354 EXPECT_EQ(11u, list_.size()); 435 EXPECT_EQ(11u, list_.size());
355 } 436 }
356 437
357 TEST_F(BluetoothBlacklistTest, VerifyDefaultExcludeList) { 438 TEST_F(BluetoothBlacklistTest, VerifyDefaultExcludeList) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a02"))); 470 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a02")));
390 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a03"))); 471 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a03")));
391 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a25"))); 472 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a25")));
392 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2902"))); 473 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2902")));
393 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2903"))); 474 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2903")));
394 EXPECT_TRUE(list_.IsExcludedFromWrites( 475 EXPECT_TRUE(list_.IsExcludedFromWrites(
395 BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c"))); 476 BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c")));
396 } 477 }
397 478
398 } // namespace content 479 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698