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

Side by Side Diff: content/browser/bluetooth/bluetooth_allowed_devices_map_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 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 "content/common/bluetooth/web_bluetooth_device_id.h" 8 #include "content/common/bluetooth/web_bluetooth_device_id.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "url/gurl.h" 10 #include "url/gurl.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 203 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService(
204 kTestOrigin1, device_id, kGlucoseUUID)); 204 kTestOrigin1, device_id, kGlucoseUUID));
205 } 205 }
206 206
207 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) { 207 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) {
208 BluetoothAllowedDevicesMap allowed_devices_map; 208 BluetoothAllowedDevicesMap allowed_devices_map;
209 209
210 // Setup device. 210 // Setup device.
211 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = 211 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options =
212 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 212 blink::mojom::WebBluetoothRequestDeviceOptions::New();
213 blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = 213 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
214 blink::mojom::WebBluetoothScanFilter::New(); 214 blink::mojom::WebBluetoothScanFilter::New();
215 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = 215 scan_filter1->services = std::vector<BluetoothUUID>();
ortuno 2016/11/21 04:42:31 nit: move this to where services is modified.
juncai 2016/11/21 21:27:05 Done.
216 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
216 blink::mojom::WebBluetoothScanFilter::New(); 217 blink::mojom::WebBluetoothScanFilter::New();
218 scan_filter2->services = std::vector<BluetoothUUID>();
217 219
218 scanFilter1->services.push_back(kGlucoseUUID); 220 scan_filter1->services->push_back(kGlucoseUUID);
219 options->filters.push_back(scanFilter1.Clone()); 221 options->filters.push_back(scan_filter1.Clone());
220 222
221 scanFilter2->services.push_back(kHeartRateUUID); 223 scan_filter2->services->push_back(kHeartRateUUID);
222 options->filters.push_back(scanFilter2.Clone()); 224 options->filters.push_back(scan_filter2.Clone());
223 225
224 options->optional_services.push_back(kBatteryServiceUUID); 226 options->optional_services.push_back(kBatteryServiceUUID);
225 options->optional_services.push_back(kHeartRateUUID); 227 options->optional_services.push_back(kHeartRateUUID);
226 228
227 // Add to map. 229 // Add to map.
228 const WebBluetoothDeviceId device_id1 = 230 const WebBluetoothDeviceId device_id1 =
229 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options); 231 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options);
230 232
231 // Access allowed services. 233 // Access allowed services.
232 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 234 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService(
(...skipping 18 matching lines...) Expand all
251 kTestOrigin1, device_id1, kGlucoseUUID)); 253 kTestOrigin1, device_id1, kGlucoseUUID));
252 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 254 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService(
253 kTestOrigin1, device_id1, kHeartRateUUID)); 255 kTestOrigin1, device_id1, kHeartRateUUID));
254 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 256 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService(
255 kTestOrigin1, device_id1, kBatteryServiceUUID)); 257 kTestOrigin1, device_id1, kBatteryServiceUUID));
256 258
257 // Add device back. 259 // Add device back.
258 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = 260 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
259 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 261 blink::mojom::WebBluetoothRequestDeviceOptions::New();
260 262
261 options2->filters.push_back(scanFilter1.Clone()); 263 options2->filters.push_back(scan_filter1.Clone());
262 options2->filters.push_back(scanFilter2.Clone()); 264 options2->filters.push_back(scan_filter2.Clone());
263 265
264 const WebBluetoothDeviceId device_id2 = 266 const WebBluetoothDeviceId device_id2 =
265 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); 267 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2);
266 268
267 // Access allowed services. 269 // Access allowed services.
268 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 270 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService(
269 kTestOrigin1, device_id2)); 271 kTestOrigin1, device_id2));
270 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 272 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
271 kTestOrigin1, device_id2, kGlucoseUUID)); 273 kTestOrigin1, device_id2, kGlucoseUUID));
272 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 274 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
(...skipping 11 matching lines...) Expand all
284 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 286 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService(
285 kTestOrigin1, device_id1, kBatteryServiceUUID)); 287 kTestOrigin1, device_id1, kBatteryServiceUUID));
286 } 288 }
287 289
288 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginTwoDevices) { 290 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginTwoDevices) {
289 BluetoothAllowedDevicesMap allowed_devices_map; 291 BluetoothAllowedDevicesMap allowed_devices_map;
290 292
291 // Setup request for device #1. 293 // Setup request for device #1.
292 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = 294 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 =
293 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 295 blink::mojom::WebBluetoothRequestDeviceOptions::New();
294 blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = 296 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
295 blink::mojom::WebBluetoothScanFilter::New(); 297 blink::mojom::WebBluetoothScanFilter::New();
298 scan_filter1->services = std::vector<BluetoothUUID>();
ortuno 2016/11/21 04:42:31 nit: Group this with the line that modifies servic
juncai 2016/11/21 21:27:05 Done.
296 299
297 scanFilter1->services.push_back(kGlucoseUUID); 300 scan_filter1->services->push_back(kGlucoseUUID);
298 options1->filters.push_back(std::move(scanFilter1)); 301 options1->filters.push_back(std::move(scan_filter1));
299 302
300 options1->optional_services.push_back(kHeartRateUUID); 303 options1->optional_services.push_back(kHeartRateUUID);
301 304
302 // Setup request for device #2. 305 // Setup request for device #2.
303 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = 306 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
304 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 307 blink::mojom::WebBluetoothRequestDeviceOptions::New();
305 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = 308 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
306 blink::mojom::WebBluetoothScanFilter::New(); 309 blink::mojom::WebBluetoothScanFilter::New();
310 scan_filter2->services = std::vector<BluetoothUUID>();
307 311
308 scanFilter2->services.push_back(kBatteryServiceUUID); 312 scan_filter2->services->push_back(kBatteryServiceUUID);
309 options2->filters.push_back(std::move(scanFilter2)); 313 options2->filters.push_back(std::move(scan_filter2));
310 314
311 options2->optional_services.push_back(kBloodPressureUUID); 315 options2->optional_services.push_back(kBloodPressureUUID);
312 316
313 // Add devices to map. 317 // Add devices to map.
314 const WebBluetoothDeviceId& device_id1 = 318 const WebBluetoothDeviceId& device_id1 =
315 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); 319 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1);
316 const WebBluetoothDeviceId& device_id2 = 320 const WebBluetoothDeviceId& device_id2 =
317 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress2, options2); 321 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress2, options2);
318 322
319 // Access allowed services. 323 // Access allowed services.
(...skipping 25 matching lines...) Expand all
345 kTestOrigin1, device_id2, kHeartRateUUID)); 349 kTestOrigin1, device_id2, kHeartRateUUID));
346 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 350 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService(
347 kTestOrigin1, device_id2, kCyclingPowerUUID)); 351 kTestOrigin1, device_id2, kCyclingPowerUUID));
348 } 352 }
349 353
350 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_TwoOriginsOneDevice) { 354 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_TwoOriginsOneDevice) {
351 BluetoothAllowedDevicesMap allowed_devices_map; 355 BluetoothAllowedDevicesMap allowed_devices_map;
352 // Setup request #1 for device. 356 // Setup request #1 for device.
353 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = 357 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 =
354 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 358 blink::mojom::WebBluetoothRequestDeviceOptions::New();
355 blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = 359 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
356 blink::mojom::WebBluetoothScanFilter::New(); 360 blink::mojom::WebBluetoothScanFilter::New();
361 scan_filter1->services = std::vector<BluetoothUUID>();
357 362
358 scanFilter1->services.push_back(kGlucoseUUID); 363 scan_filter1->services->push_back(kGlucoseUUID);
359 options1->filters.push_back(std::move(scanFilter1)); 364 options1->filters.push_back(std::move(scan_filter1));
360 365
361 options1->optional_services.push_back(kHeartRateUUID); 366 options1->optional_services.push_back(kHeartRateUUID);
362 367
363 // Setup request #2 for device. 368 // Setup request #2 for device.
364 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = 369 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
365 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 370 blink::mojom::WebBluetoothRequestDeviceOptions::New();
366 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = 371 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
367 blink::mojom::WebBluetoothScanFilter::New(); 372 blink::mojom::WebBluetoothScanFilter::New();
373 scan_filter2->services = std::vector<BluetoothUUID>();
368 374
369 scanFilter2->services.push_back(kBatteryServiceUUID); 375 scan_filter2->services->push_back(kBatteryServiceUUID);
370 options2->filters.push_back(std::move(scanFilter2)); 376 options2->filters.push_back(std::move(scan_filter2));
371 377
372 options2->optional_services.push_back(kBloodPressureUUID); 378 options2->optional_services.push_back(kBloodPressureUUID);
373 379
374 // Add devices to map. 380 // Add devices to map.
375 const WebBluetoothDeviceId& device_id1 = 381 const WebBluetoothDeviceId& device_id1 =
376 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); 382 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1);
377 const WebBluetoothDeviceId& device_id2 = 383 const WebBluetoothDeviceId& device_id2 =
378 allowed_devices_map.AddDevice(kTestOrigin2, kDeviceAddress1, options2); 384 allowed_devices_map.AddDevice(kTestOrigin2, kDeviceAddress1, options2);
379 385
380 // Access allowed services. 386 // Access allowed services.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 431 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService(
426 kTestOrigin2, device_id1, kBloodPressureUUID)); 432 kTestOrigin2, device_id1, kBloodPressureUUID));
427 } 433 }
428 434
429 TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) { 435 TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) {
430 BluetoothAllowedDevicesMap allowed_devices_map; 436 BluetoothAllowedDevicesMap allowed_devices_map;
431 437
432 // Setup first request. 438 // Setup first request.
433 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = 439 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 =
434 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 440 blink::mojom::WebBluetoothRequestDeviceOptions::New();
435 blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = 441 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
436 blink::mojom::WebBluetoothScanFilter::New(); 442 blink::mojom::WebBluetoothScanFilter::New();
443 scan_filter1->services = std::vector<BluetoothUUID>();
437 444
438 scanFilter1->services.push_back(kGlucoseUUID); 445 scan_filter1->services->push_back(kGlucoseUUID);
439 options1->filters.push_back(std::move(scanFilter1)); 446 options1->filters.push_back(std::move(scan_filter1));
440 447
441 options1->optional_services.push_back(kBatteryServiceUUID); 448 options1->optional_services.push_back(kBatteryServiceUUID);
442 449
443 // Add to map. 450 // Add to map.
444 const WebBluetoothDeviceId device_id1 = 451 const WebBluetoothDeviceId device_id1 =
445 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); 452 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1);
446 453
447 // Setup second request. 454 // Setup second request.
448 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = 455 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
449 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 456 blink::mojom::WebBluetoothRequestDeviceOptions::New();
450 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = 457 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
451 blink::mojom::WebBluetoothScanFilter::New(); 458 blink::mojom::WebBluetoothScanFilter::New();
459 scan_filter2->services = std::vector<BluetoothUUID>();
452 460
453 scanFilter2->services.push_back(kHeartRateUUID); 461 scan_filter2->services->push_back(kHeartRateUUID);
454 options2->filters.push_back(std::move(scanFilter2)); 462 options2->filters.push_back(std::move(scan_filter2));
455 463
456 options2->optional_services.push_back(kBloodPressureUUID); 464 options2->optional_services.push_back(kBloodPressureUUID);
457 465
458 // Add to map again. 466 // Add to map again.
459 const WebBluetoothDeviceId device_id2 = 467 const WebBluetoothDeviceId device_id2 =
460 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); 468 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2);
461 469
462 EXPECT_EQ(device_id1, device_id2); 470 EXPECT_EQ(device_id1, device_id2);
463 471
464 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 472 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService(
(...skipping 11 matching lines...) Expand all
476 TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) { 484 TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) {
477 BluetoothAllowedDevicesMap allowed_devices_map; 485 BluetoothAllowedDevicesMap allowed_devices_map;
478 486
479 const WebBluetoothDeviceId& device_id = allowed_devices_map.AddDevice( 487 const WebBluetoothDeviceId& device_id = allowed_devices_map.AddDevice(
480 kTestOrigin1, kDeviceAddress1, empty_options_); 488 kTestOrigin1, kDeviceAddress1, empty_options_);
481 489
482 EXPECT_TRUE(WebBluetoothDeviceId::IsValid(device_id.str())); 490 EXPECT_TRUE(WebBluetoothDeviceId::IsValid(device_id.str()));
483 } 491 }
484 492
485 } // namespace content 493 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698