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

Side by Side Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc

Issue 418483003: device/bluetooth: Move GATT observer methods to BluetoothAdapter::Observer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h" 6 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h"
7 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h" 7 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_function_test_utils.h" 9 #include "chrome/browser/extensions/extension_function_test_utils.h"
10 #include "chrome/browser/extensions/extension_test_message_listener.h" 10 #include "chrome/browser/extensions/extension_test_message_listener.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 284
285 listener.Reply("go"); 285 listener.Reply("go");
286 286
287 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 287 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
288 } 288 }
289 289
290 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetService) { 290 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetService) {
291 ResultCatcher catcher; 291 ResultCatcher catcher;
292 catcher.RestrictToProfile(browser()->profile()); 292 catcher.RestrictToProfile(browser()->profile());
293 293
294 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 294 event_router()->GattServiceAdded(
295 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 295 mock_adapter_, device0_.get(), service0_.get());
296 296
297 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 297 EXPECT_CALL(*mock_adapter_, GetDevice(_))
298 .Times(3) 298 .Times(3)
299 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL))) 299 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL)))
300 .WillRepeatedly(Return(device0_.get())); 300 .WillRepeatedly(Return(device0_.get()));
301 301
302 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 302 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
303 .Times(2) 303 .Times(2)
304 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL))) 304 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL)))
305 .WillOnce(Return(service0_.get())); 305 .WillOnce(Return(service0_.get()));
306 306
307 // Load and wait for setup. 307 // Load and wait for setup.
308 ExtensionTestMessageListener listener("ready", true); 308 ExtensionTestMessageListener listener("ready", true);
309 ASSERT_TRUE(LoadExtension( 309 ASSERT_TRUE(LoadExtension(
310 test_data_dir_.AppendASCII("bluetooth_low_energy/get_service"))); 310 test_data_dir_.AppendASCII("bluetooth_low_energy/get_service")));
311 EXPECT_TRUE(listener.WaitUntilSatisfied()); 311 EXPECT_TRUE(listener.WaitUntilSatisfied());
312 312
313 listener.Reply("go"); 313 listener.Reply("go");
314 314
315 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 315 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
316 316
317 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 317 event_router()->GattServiceRemoved(
318 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 318 mock_adapter_, device0_.get(), service0_.get());
319 } 319 }
320 320
321 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ServiceEvents) { 321 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ServiceEvents) {
322 ResultCatcher catcher; 322 ResultCatcher catcher;
323 catcher.RestrictToProfile(browser()->profile()); 323 catcher.RestrictToProfile(browser()->profile());
324 324
325 // Load the extension and let it set up. 325 // Load the extension and let it set up.
326 ExtensionTestMessageListener listener("ready", true); 326 ExtensionTestMessageListener listener("ready", true);
327 ASSERT_TRUE(LoadExtension( 327 ASSERT_TRUE(LoadExtension(
328 test_data_dir_.AppendASCII("bluetooth_low_energy/service_events"))); 328 test_data_dir_.AppendASCII("bluetooth_low_energy/service_events")));
329 329
330 // Cause events to be sent to the extension.
331 event_router()->DeviceAdded(mock_adapter_, device0_.get());
332
333 // These will create the identifier mappings. 330 // These will create the identifier mappings.
334 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 331 event_router()->GattServiceAdded(
335 event_router()->GattServiceAdded(device0_.get(), service1_.get()); 332 mock_adapter_, device0_.get(), service0_.get());
333 event_router()->GattServiceAdded(
334 mock_adapter_, device0_.get(), service1_.get());
336 335
337 // These will send the onServiceAdded event to apps. 336 // These will send the onServiceAdded event to apps.
338 event_router()->GattDiscoveryCompleteForService(service0_.get()); 337 event_router()->GattDiscoveryCompleteForService(mock_adapter_,
339 event_router()->GattDiscoveryCompleteForService(service1_.get()); 338 service0_.get());
339 event_router()->GattDiscoveryCompleteForService(mock_adapter_,
340 service1_.get());
340 341
341 // This will send the onServiceChanged event to apps. 342 // This will send the onServiceChanged event to apps.
342 event_router()->GattServiceChanged(service1_.get()); 343 event_router()->GattServiceChanged(mock_adapter_, service1_.get());
343 344
344 // This will send the onServiceRemoved event to apps. 345 // This will send the onServiceRemoved event to apps.
345 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 346 event_router()->GattServiceRemoved(
347 mock_adapter_, device0_.get(), service0_.get());
346 348
347 EXPECT_TRUE(listener.WaitUntilSatisfied()); 349 EXPECT_TRUE(listener.WaitUntilSatisfied());
348 listener.Reply("go"); 350 listener.Reply("go");
349 351
350 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 352 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
351 event_router()->GattServiceRemoved(device0_.get(), service1_.get()); 353 event_router()->GattServiceRemoved(
352 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 354 mock_adapter_, device0_.get(), service1_.get());
353 } 355 }
354 356
355 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedService) { 357 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedService) {
356 ResultCatcher catcher; 358 ResultCatcher catcher;
357 catcher.RestrictToProfile(browser()->profile()); 359 catcher.RestrictToProfile(browser()->profile());
358 360
359 // Load the extension and let it set up. 361 // Load the extension and let it set up.
360 ASSERT_TRUE(LoadExtension( 362 ASSERT_TRUE(LoadExtension(
361 test_data_dir_.AppendASCII("bluetooth_low_energy/get_removed_service"))); 363 test_data_dir_.AppendASCII("bluetooth_low_energy/get_removed_service")));
362 364
363 // 1. getService success. 365 // 1. getService success.
364 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 366 EXPECT_CALL(*mock_adapter_, GetDevice(_))
365 .Times(1) 367 .Times(1)
366 .WillOnce(Return(device0_.get())); 368 .WillOnce(Return(device0_.get()));
367 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 369 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
368 .Times(1) 370 .Times(1)
369 .WillOnce(Return(service0_.get())); 371 .WillOnce(Return(service0_.get()));
370 372
371 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 373 event_router()->GattServiceAdded(
372 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 374 mock_adapter_, device0_.get(), service0_.get());
373 event_router()->GattDiscoveryCompleteForService(service0_.get()); 375 event_router()->GattDiscoveryCompleteForService(mock_adapter_,
376 service0_.get());
374 377
375 ExtensionTestMessageListener get_service_success_listener("getServiceSuccess", 378 ExtensionTestMessageListener get_service_success_listener("getServiceSuccess",
376 true); 379 true);
377 EXPECT_TRUE(get_service_success_listener.WaitUntilSatisfied()); 380 EXPECT_TRUE(get_service_success_listener.WaitUntilSatisfied());
378 testing::Mock::VerifyAndClearExpectations(mock_adapter_); 381 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
379 testing::Mock::VerifyAndClearExpectations(device0_.get()); 382 testing::Mock::VerifyAndClearExpectations(device0_.get());
380 383
381 // 2. getService fail. 384 // 2. getService fail.
382 EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(0); 385 EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(0);
383 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)).Times(0); 386 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)).Times(0);
384 387
385 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 388 event_router()->GattServiceRemoved(
389 mock_adapter_, device0_.get(), service0_.get());
386 390
387 ExtensionTestMessageListener get_service_fail_listener("getServiceFail", 391 ExtensionTestMessageListener get_service_fail_listener("getServiceFail",
388 true); 392 true);
389 EXPECT_TRUE(get_service_fail_listener.WaitUntilSatisfied()); 393 EXPECT_TRUE(get_service_fail_listener.WaitUntilSatisfied());
390 testing::Mock::VerifyAndClearExpectations(mock_adapter_); 394 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
391 testing::Mock::VerifyAndClearExpectations(device0_.get()); 395 testing::Mock::VerifyAndClearExpectations(device0_.get());
392 396
393 get_service_fail_listener.Reply("go"); 397 get_service_fail_listener.Reply("go");
394 398
395 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 399 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
396 event_router()->DeviceRemoved(mock_adapter_, device0_.get());
397 } 400 }
398 401
399 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetIncludedServices) { 402 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetIncludedServices) {
400 ResultCatcher catcher; 403 ResultCatcher catcher;
401 catcher.RestrictToProfile(browser()->profile()); 404 catcher.RestrictToProfile(browser()->profile());
402 405
403 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 406 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
404 "bluetooth_low_energy/get_included_services"))); 407 "bluetooth_low_energy/get_included_services")));
405 408
406 // Wait for initial call to end with failure as there is no mapping. 409 // Wait for initial call to end with failure as there is no mapping.
407 ExtensionTestMessageListener listener("ready", true); 410 ExtensionTestMessageListener listener("ready", true);
408 EXPECT_TRUE(listener.WaitUntilSatisfied()); 411 EXPECT_TRUE(listener.WaitUntilSatisfied());
409 412
410 // Set up for the rest of the calls before replying. Included services can be 413 // Set up for the rest of the calls before replying. Included services can be
411 // returned even if there is no instance ID mapping for them yet, so no need 414 // returned even if there is no instance ID mapping for them yet, so no need
412 // to call GattServiceAdded for |service1_| here. 415 // to call GattServiceAdded for |service1_| here.
413 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 416 event_router()->GattServiceAdded(
414 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 417 mock_adapter_, device0_.get(), service0_.get());
415 418
416 std::vector<BluetoothGattService*> includes; 419 std::vector<BluetoothGattService*> includes;
417 includes.push_back(service1_.get()); 420 includes.push_back(service1_.get());
418 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) 421 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0))
419 .Times(2) 422 .Times(2)
420 .WillRepeatedly(Return(device0_.get())); 423 .WillRepeatedly(Return(device0_.get()));
421 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 424 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
422 .Times(2) 425 .Times(2)
423 .WillRepeatedly(Return(service0_.get())); 426 .WillRepeatedly(Return(service0_.get()));
424 EXPECT_CALL(*service0_, GetIncludedServices()) 427 EXPECT_CALL(*service0_, GetIncludedServices())
425 .Times(2) 428 .Times(2)
426 .WillOnce(Return(std::vector<BluetoothGattService*>())) 429 .WillOnce(Return(std::vector<BluetoothGattService*>()))
427 .WillOnce(Return(includes)); 430 .WillOnce(Return(includes));
428 431
429 listener.Reply("go"); 432 listener.Reply("go");
430 listener.Reset(); 433 listener.Reset();
431 434
432 EXPECT_TRUE(listener.WaitUntilSatisfied()); 435 EXPECT_TRUE(listener.WaitUntilSatisfied());
433 436
434 listener.Reply("go"); 437 listener.Reply("go");
435 438
436 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 439 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
437 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 440 event_router()->GattServiceRemoved(
438 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 441 mock_adapter_, device0_.get(), service0_.get());
439 } 442 }
440 443
441 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristics) { 444 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristics) {
442 ResultCatcher catcher; 445 ResultCatcher catcher;
443 catcher.RestrictToProfile(browser()->profile()); 446 catcher.RestrictToProfile(browser()->profile());
444 447
445 std::vector<BluetoothGattCharacteristic*> characteristics; 448 std::vector<BluetoothGattCharacteristic*> characteristics;
446 characteristics.push_back(chrc0_.get()); 449 characteristics.push_back(chrc0_.get());
447 characteristics.push_back(chrc1_.get()); 450 characteristics.push_back(chrc1_.get());
448 451
449 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 452 event_router()->GattServiceAdded(
450 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 453 mock_adapter_, device0_.get(), service0_.get());
451 454
452 EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(3).WillRepeatedly( 455 EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(3).WillRepeatedly(
453 Return(device0_.get())); 456 Return(device0_.get()));
454 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 457 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
455 .Times(3) 458 .Times(3)
456 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL))) 459 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL)))
457 .WillRepeatedly(Return(service0_.get())); 460 .WillRepeatedly(Return(service0_.get()));
458 EXPECT_CALL(*service0_, GetCharacteristics()) 461 EXPECT_CALL(*service0_, GetCharacteristics())
459 .Times(2) 462 .Times(2)
460 .WillOnce(Return(std::vector<BluetoothGattCharacteristic*>())) 463 .WillOnce(Return(std::vector<BluetoothGattCharacteristic*>()))
461 .WillOnce(Return(characteristics)); 464 .WillOnce(Return(characteristics));
462 465
463 ExtensionTestMessageListener listener("ready", true); 466 ExtensionTestMessageListener listener("ready", true);
464 ASSERT_TRUE(LoadExtension( 467 ASSERT_TRUE(LoadExtension(
465 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristics"))); 468 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristics")));
466 EXPECT_TRUE(listener.WaitUntilSatisfied()); 469 EXPECT_TRUE(listener.WaitUntilSatisfied());
467 470
468 listener.Reply("go"); 471 listener.Reply("go");
469 472
470 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 473 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
471 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 474 event_router()->GattServiceRemoved(
472 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 475 mock_adapter_, device0_.get(), service0_.get());
473 } 476 }
474 477
475 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristic) { 478 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristic) {
476 ResultCatcher catcher; 479 ResultCatcher catcher;
477 catcher.RestrictToProfile(browser()->profile()); 480 catcher.RestrictToProfile(browser()->profile());
478 481
479 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 482 event_router()->GattServiceAdded(
480 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 483 mock_adapter_, device0_.get(), service0_.get());
481 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 484 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
482 485
483 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 486 EXPECT_CALL(*mock_adapter_, GetDevice(_))
484 .Times(4) 487 .Times(4)
485 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL))) 488 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL)))
486 .WillRepeatedly(Return(device0_.get())); 489 .WillRepeatedly(Return(device0_.get()));
487 490
488 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 491 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
489 .Times(3) 492 .Times(3)
490 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL))) 493 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL)))
491 .WillRepeatedly(Return(service0_.get())); 494 .WillRepeatedly(Return(service0_.get()));
492 495
493 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 496 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
494 .Times(2) 497 .Times(2)
495 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(NULL))) 498 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(NULL)))
496 .WillOnce(Return(chrc0_.get())); 499 .WillOnce(Return(chrc0_.get()));
497 500
498 // Load the extension and wait for first test. 501 // Load the extension and wait for first test.
499 ExtensionTestMessageListener listener("ready", true); 502 ExtensionTestMessageListener listener("ready", true);
500 ASSERT_TRUE(LoadExtension( 503 ASSERT_TRUE(LoadExtension(
501 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristic"))); 504 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristic")));
502 EXPECT_TRUE(listener.WaitUntilSatisfied()); 505 EXPECT_TRUE(listener.WaitUntilSatisfied());
503 506
504 listener.Reply("go"); 507 listener.Reply("go");
505 508
506 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 509 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
507 510
508 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 511 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
509 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 512 event_router()->GattServiceRemoved(
510 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 513 mock_adapter_, device0_.get(), service0_.get());
511 } 514 }
512 515
513 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicProperties) { 516 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicProperties) {
514 ResultCatcher catcher; 517 ResultCatcher catcher;
515 catcher.RestrictToProfile(browser()->profile()); 518 catcher.RestrictToProfile(browser()->profile());
516 519
517 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 520 event_router()->GattServiceAdded(
518 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 521 mock_adapter_, device0_.get(), service0_.get());
519 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 522 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
520 523
521 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 524 EXPECT_CALL(*mock_adapter_, GetDevice(_))
522 .Times(12) 525 .Times(12)
523 .WillRepeatedly(Return(device0_.get())); 526 .WillRepeatedly(Return(device0_.get()));
524 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 527 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
525 .Times(12) 528 .Times(12)
526 .WillRepeatedly(Return(service0_.get())); 529 .WillRepeatedly(Return(service0_.get()));
527 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 530 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
528 .Times(12) 531 .Times(12)
529 .WillRepeatedly(Return(chrc0_.get())); 532 .WillRepeatedly(Return(chrc0_.get()));
(...skipping 28 matching lines...) Expand all
558 561
559 ExtensionTestMessageListener listener("ready", true); 562 ExtensionTestMessageListener listener("ready", true);
560 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 563 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
561 "bluetooth_low_energy/characteristic_properties"))); 564 "bluetooth_low_energy/characteristic_properties")));
562 EXPECT_TRUE(listener.WaitUntilSatisfied()); 565 EXPECT_TRUE(listener.WaitUntilSatisfied());
563 566
564 listener.Reply("go"); 567 listener.Reply("go");
565 568
566 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 569 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
567 570
568 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 571 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
569 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 572 event_router()->GattServiceRemoved(
570 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 573 mock_adapter_, device0_.get(), service0_.get());
571 } 574 }
572 575
573 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedCharacteristic) { 576 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedCharacteristic) {
574 ResultCatcher catcher; 577 ResultCatcher catcher;
575 catcher.RestrictToProfile(browser()->profile()); 578 catcher.RestrictToProfile(browser()->profile());
576 579
577 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 580 EXPECT_CALL(*mock_adapter_, GetDevice(_))
578 .Times(1) 581 .Times(1)
579 .WillOnce(Return(device0_.get())); 582 .WillOnce(Return(device0_.get()));
580 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 583 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
581 .Times(1) 584 .Times(1)
582 .WillOnce(Return(service0_.get())); 585 .WillOnce(Return(service0_.get()));
583 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 586 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
584 .Times(1) 587 .Times(1)
585 .WillOnce(Return(chrc0_.get())); 588 .WillOnce(Return(chrc0_.get()));
586 589
587 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 590 event_router()->GattServiceAdded(
588 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 591 mock_adapter_, device0_.get(), service0_.get());
589 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 592 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
590 593
591 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 594 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
592 "bluetooth_low_energy/get_removed_characteristic"))); 595 "bluetooth_low_energy/get_removed_characteristic")));
593 596
594 ExtensionTestMessageListener listener("ready", true); 597 ExtensionTestMessageListener listener("ready", true);
595 EXPECT_TRUE(listener.WaitUntilSatisfied()); 598 EXPECT_TRUE(listener.WaitUntilSatisfied());
596 testing::Mock::VerifyAndClearExpectations(mock_adapter_); 599 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
597 testing::Mock::VerifyAndClearExpectations(device0_.get()); 600 testing::Mock::VerifyAndClearExpectations(device0_.get());
598 testing::Mock::VerifyAndClearExpectations(service0_.get()); 601 testing::Mock::VerifyAndClearExpectations(service0_.get());
599 602
600 EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(0); 603 EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(0);
601 EXPECT_CALL(*device0_, GetGattService(_)).Times(0); 604 EXPECT_CALL(*device0_, GetGattService(_)).Times(0);
602 EXPECT_CALL(*service0_, GetCharacteristic(_)).Times(0); 605 EXPECT_CALL(*service0_, GetCharacteristic(_)).Times(0);
603 606
604 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 607 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
605 608
606 listener.Reply("go"); 609 listener.Reply("go");
607 listener.Reset(); 610 listener.Reset();
608 EXPECT_TRUE(listener.WaitUntilSatisfied()); 611 EXPECT_TRUE(listener.WaitUntilSatisfied());
609 612
610 listener.Reply("go"); 613 listener.Reply("go");
611 614
612 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 615 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
613 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 616 event_router()->GattServiceRemoved(
614 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 617 mock_adapter_, device0_.get(), service0_.get());
615 } 618 }
616 619
617 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicValueChanged) { 620 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicValueChanged) {
618 ResultCatcher catcher; 621 ResultCatcher catcher;
619 catcher.RestrictToProfile(browser()->profile()); 622 catcher.RestrictToProfile(browser()->profile());
620 623
621 // Cause events to be sent to the extension. 624 // Cause events to be sent to the extension.
622 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 625 event_router()->GattServiceAdded(
623 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 626 mock_adapter_, device0_.get(), service0_.get());
624 event_router()->GattServiceAdded(device0_.get(), service1_.get()); 627 event_router()->GattServiceAdded(
625 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 628 mock_adapter_, device0_.get(), service1_.get());
626 event_router()->GattCharacteristicAdded(service1_.get(), chrc2_.get()); 629 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
630 event_router()->GattCharacteristicAdded(mock_adapter_, chrc2_.get());
627 631
628 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 632 EXPECT_CALL(*mock_adapter_, GetDevice(_))
629 .Times(2) 633 .Times(2)
630 .WillRepeatedly(Return(device0_.get())); 634 .WillRepeatedly(Return(device0_.get()));
631 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 635 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
632 .Times(1) 636 .Times(1)
633 .WillOnce(Return(service0_.get())); 637 .WillOnce(Return(service0_.get()));
634 EXPECT_CALL(*device0_, GetGattService(kTestServiceId1)) 638 EXPECT_CALL(*device0_, GetGattService(kTestServiceId1))
635 .Times(1) 639 .Times(1)
636 .WillOnce(Return(service1_.get())); 640 .WillOnce(Return(service1_.get()));
(...skipping 23 matching lines...) Expand all
660 session1)); 664 session1));
661 665
662 ExtensionTestMessageListener listener("ready", true); 666 ExtensionTestMessageListener listener("ready", true);
663 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 667 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
664 "bluetooth_low_energy/characteristic_value_changed"))); 668 "bluetooth_low_energy/characteristic_value_changed")));
665 669
666 EXPECT_TRUE(listener.WaitUntilSatisfied()); 670 EXPECT_TRUE(listener.WaitUntilSatisfied());
667 671
668 std::vector<uint8> value; 672 std::vector<uint8> value;
669 event_router()->GattCharacteristicValueChanged( 673 event_router()->GattCharacteristicValueChanged(
670 service0_.get(), chrc0_.get(), value); 674 mock_adapter_, chrc0_.get(), value);
671 event_router()->GattCharacteristicValueChanged( 675 event_router()->GattCharacteristicValueChanged(
672 service1_.get(), chrc2_.get(), value); 676 mock_adapter_, chrc2_.get(), value);
673 677
674 listener.Reply("go"); 678 listener.Reply("go");
675 679
676 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 680 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
677 event_router()->GattCharacteristicRemoved(service1_.get(), chrc2_.get()); 681 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get());
678 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 682 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
679 event_router()->GattServiceRemoved(device0_.get(), service1_.get()); 683 event_router()->GattServiceRemoved(
680 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 684 mock_adapter_, device0_.get(), service1_.get());
681 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 685 event_router()->GattServiceRemoved(
686 mock_adapter_, device0_.get(), service0_.get());
682 } 687 }
683 688
684 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadCharacteristicValue) { 689 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadCharacteristicValue) {
685 ResultCatcher catcher; 690 ResultCatcher catcher;
686 catcher.RestrictToProfile(browser()->profile()); 691 catcher.RestrictToProfile(browser()->profile());
687 692
688 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 693 event_router()->GattServiceAdded(
689 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 694 mock_adapter_, device0_.get(), service0_.get());
690 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 695 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
691 696
692 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 697 EXPECT_CALL(*mock_adapter_, GetDevice(_))
693 .Times(3) 698 .Times(3)
694 .WillRepeatedly(Return(device0_.get())); 699 .WillRepeatedly(Return(device0_.get()));
695 700
696 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 701 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
697 .Times(3) 702 .Times(3)
698 .WillRepeatedly(Return(service0_.get())); 703 .WillRepeatedly(Return(service0_.get()));
699 704
700 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 705 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
701 .Times(3) 706 .Times(3)
702 .WillRepeatedly(Return(chrc0_.get())); 707 .WillRepeatedly(Return(chrc0_.get()));
703 708
704 std::vector<uint8> value; 709 std::vector<uint8> value;
705 EXPECT_CALL(*chrc0_, ReadRemoteCharacteristic(_, _)) 710 EXPECT_CALL(*chrc0_, ReadRemoteCharacteristic(_, _))
706 .Times(2) 711 .Times(2)
707 .WillOnce(InvokeCallbackArgument<1>()) 712 .WillOnce(InvokeCallbackArgument<1>())
708 .WillOnce(InvokeCallbackArgument<0>(value)); 713 .WillOnce(InvokeCallbackArgument<0>(value));
709 714
710 ExtensionTestMessageListener listener("ready", true); 715 ExtensionTestMessageListener listener("ready", true);
711 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 716 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
712 "bluetooth_low_energy/read_characteristic_value"))); 717 "bluetooth_low_energy/read_characteristic_value")));
713 EXPECT_TRUE(listener.WaitUntilSatisfied()); 718 EXPECT_TRUE(listener.WaitUntilSatisfied());
714 719
715 listener.Reply("go"); 720 listener.Reply("go");
716 721
717 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 722 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
718 723
719 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 724 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
720 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 725 event_router()->GattServiceRemoved(
721 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 726 mock_adapter_, device0_.get(), service0_.get());
722 } 727 }
723 728
724 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteCharacteristicValue) { 729 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteCharacteristicValue) {
725 ResultCatcher catcher; 730 ResultCatcher catcher;
726 catcher.RestrictToProfile(browser()->profile()); 731 catcher.RestrictToProfile(browser()->profile());
727 732
728 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 733 event_router()->GattServiceAdded(
729 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 734 mock_adapter_, device0_.get(), service0_.get());
730 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 735 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
731 736
732 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 737 EXPECT_CALL(*mock_adapter_, GetDevice(_))
733 .Times(3) 738 .Times(3)
734 .WillRepeatedly(Return(device0_.get())); 739 .WillRepeatedly(Return(device0_.get()));
735 740
736 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 741 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
737 .Times(3) 742 .Times(3)
738 .WillRepeatedly(Return(service0_.get())); 743 .WillRepeatedly(Return(service0_.get()));
739 744
740 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 745 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
(...skipping 10 matching lines...) Expand all
751 756
752 ExtensionTestMessageListener listener("ready", true); 757 ExtensionTestMessageListener listener("ready", true);
753 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 758 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
754 "bluetooth_low_energy/write_characteristic_value"))); 759 "bluetooth_low_energy/write_characteristic_value")));
755 EXPECT_TRUE(listener.WaitUntilSatisfied()); 760 EXPECT_TRUE(listener.WaitUntilSatisfied());
756 761
757 listener.Reply("go"); 762 listener.Reply("go");
758 763
759 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 764 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
760 765
761 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 766 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
762 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 767 event_router()->GattServiceRemoved(
763 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 768 mock_adapter_, device0_.get(), service0_.get());
764 } 769 }
765 770
766 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptors) { 771 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptors) {
767 ResultCatcher catcher; 772 ResultCatcher catcher;
768 catcher.RestrictToProfile(browser()->profile()); 773 catcher.RestrictToProfile(browser()->profile());
769 774
770 std::vector<BluetoothGattDescriptor*> descriptors; 775 std::vector<BluetoothGattDescriptor*> descriptors;
771 descriptors.push_back(desc0_.get()); 776 descriptors.push_back(desc0_.get());
772 descriptors.push_back(desc1_.get()); 777 descriptors.push_back(desc1_.get());
773 778
774 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 779 event_router()->GattServiceAdded(
775 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 780 mock_adapter_, device0_.get(), service0_.get());
776 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 781 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
777 782
778 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 783 EXPECT_CALL(*mock_adapter_, GetDevice(_))
779 .Times(3) 784 .Times(3)
780 .WillRepeatedly(Return(device0_.get())); 785 .WillRepeatedly(Return(device0_.get()));
781 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 786 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
782 .Times(3) 787 .Times(3)
783 .WillRepeatedly(Return(service0_.get())); 788 .WillRepeatedly(Return(service0_.get()));
784 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 789 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
785 .Times(3) 790 .Times(3)
786 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(NULL))) 791 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(NULL)))
787 .WillRepeatedly(Return(chrc0_.get())); 792 .WillRepeatedly(Return(chrc0_.get()));
788 EXPECT_CALL(*chrc0_, GetDescriptors()) 793 EXPECT_CALL(*chrc0_, GetDescriptors())
789 .Times(2) 794 .Times(2)
790 .WillOnce(Return(std::vector<BluetoothGattDescriptor*>())) 795 .WillOnce(Return(std::vector<BluetoothGattDescriptor*>()))
791 .WillOnce(Return(descriptors)); 796 .WillOnce(Return(descriptors));
792 797
793 ExtensionTestMessageListener listener("ready", true); 798 ExtensionTestMessageListener listener("ready", true);
794 ASSERT_TRUE(LoadExtension( 799 ASSERT_TRUE(LoadExtension(
795 test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptors"))); 800 test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptors")));
796 EXPECT_TRUE(listener.WaitUntilSatisfied()); 801 EXPECT_TRUE(listener.WaitUntilSatisfied());
797 802
798 listener.Reply("go"); 803 listener.Reply("go");
799 804
800 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 805 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
801 806
802 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 807 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
803 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 808 event_router()->GattServiceRemoved(
804 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 809 mock_adapter_, device0_.get(), service0_.get());
805 } 810 }
806 811
807 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptor) { 812 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptor) {
808 ResultCatcher catcher; 813 ResultCatcher catcher;
809 catcher.RestrictToProfile(browser()->profile()); 814 catcher.RestrictToProfile(browser()->profile());
810 815
811 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 816 event_router()->GattServiceAdded(
812 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 817 mock_adapter_, device0_.get(), service0_.get());
813 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 818 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
814 event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); 819 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get());
815 820
816 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 821 EXPECT_CALL(*mock_adapter_, GetDevice(_))
817 .Times(5) 822 .Times(5)
818 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL))) 823 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL)))
819 .WillRepeatedly(Return(device0_.get())); 824 .WillRepeatedly(Return(device0_.get()));
820 825
821 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 826 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
822 .Times(4) 827 .Times(4)
823 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL))) 828 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL)))
824 .WillRepeatedly(Return(service0_.get())); 829 .WillRepeatedly(Return(service0_.get()));
(...skipping 11 matching lines...) Expand all
836 // Load the extension and wait for first test. 841 // Load the extension and wait for first test.
837 ExtensionTestMessageListener listener("ready", true); 842 ExtensionTestMessageListener listener("ready", true);
838 ASSERT_TRUE(LoadExtension( 843 ASSERT_TRUE(LoadExtension(
839 test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptor"))); 844 test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptor")));
840 EXPECT_TRUE(listener.WaitUntilSatisfied()); 845 EXPECT_TRUE(listener.WaitUntilSatisfied());
841 846
842 listener.Reply("go"); 847 listener.Reply("go");
843 848
844 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 849 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
845 850
846 event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); 851 event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get());
847 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 852 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
848 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 853 event_router()->GattServiceRemoved(
849 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 854 mock_adapter_, device0_.get(), service0_.get());
850 } 855 }
851 856
852 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedDescriptor) { 857 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedDescriptor) {
853 ResultCatcher catcher; 858 ResultCatcher catcher;
854 catcher.RestrictToProfile(browser()->profile()); 859 catcher.RestrictToProfile(browser()->profile());
855 860
856 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 861 EXPECT_CALL(*mock_adapter_, GetDevice(_))
857 .Times(1) 862 .Times(1)
858 .WillOnce(Return(device0_.get())); 863 .WillOnce(Return(device0_.get()));
859 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 864 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
860 .Times(1) 865 .Times(1)
861 .WillOnce(Return(service0_.get())); 866 .WillOnce(Return(service0_.get()));
862 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 867 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
863 .Times(1) 868 .Times(1)
864 .WillOnce(Return(chrc0_.get())); 869 .WillOnce(Return(chrc0_.get()));
865 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0)) 870 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0))
866 .Times(1) 871 .Times(1)
867 .WillOnce(Return(desc0_.get())); 872 .WillOnce(Return(desc0_.get()));
868 873
869 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 874 event_router()->GattServiceAdded(
870 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 875 mock_adapter_, device0_.get(), service0_.get());
871 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 876 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
872 event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); 877 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get());
873 878
874 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 879 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
875 "bluetooth_low_energy/get_removed_descriptor"))); 880 "bluetooth_low_energy/get_removed_descriptor")));
876 881
877 ExtensionTestMessageListener listener("ready", true); 882 ExtensionTestMessageListener listener("ready", true);
878 EXPECT_TRUE(listener.WaitUntilSatisfied()); 883 EXPECT_TRUE(listener.WaitUntilSatisfied());
879 testing::Mock::VerifyAndClearExpectations(mock_adapter_); 884 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
880 testing::Mock::VerifyAndClearExpectations(device0_.get()); 885 testing::Mock::VerifyAndClearExpectations(device0_.get());
881 testing::Mock::VerifyAndClearExpectations(service0_.get()); 886 testing::Mock::VerifyAndClearExpectations(service0_.get());
882 testing::Mock::VerifyAndClearExpectations(chrc0_.get()); 887 testing::Mock::VerifyAndClearExpectations(chrc0_.get());
883 888
884 EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(0); 889 EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(0);
885 EXPECT_CALL(*device0_, GetGattService(_)).Times(0); 890 EXPECT_CALL(*device0_, GetGattService(_)).Times(0);
886 EXPECT_CALL(*service0_, GetCharacteristic(_)).Times(0); 891 EXPECT_CALL(*service0_, GetCharacteristic(_)).Times(0);
887 EXPECT_CALL(*chrc0_, GetDescriptor(_)).Times(0); 892 EXPECT_CALL(*chrc0_, GetDescriptor(_)).Times(0);
888 893
889 event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); 894 event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get());
890 895
891 listener.Reply("go"); 896 listener.Reply("go");
892 listener.Reset(); 897 listener.Reset();
893 EXPECT_TRUE(listener.WaitUntilSatisfied()); 898 EXPECT_TRUE(listener.WaitUntilSatisfied());
894 899
895 listener.Reply("go"); 900 listener.Reply("go");
896 901
897 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 902 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
898 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 903 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
899 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 904 event_router()->GattServiceRemoved(
900 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 905 mock_adapter_, device0_.get(), service0_.get());
901 } 906 }
902 907
903 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, DescriptorValueChanged) { 908 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, DescriptorValueChanged) {
904 ResultCatcher catcher; 909 ResultCatcher catcher;
905 catcher.RestrictToProfile(browser()->profile()); 910 catcher.RestrictToProfile(browser()->profile());
906 911
907 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 912 event_router()->GattServiceAdded(
908 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 913 mock_adapter_, device0_.get(), service0_.get());
909 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 914 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
910 event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); 915 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get());
911 event_router()->GattDescriptorAdded(chrc0_.get(), desc1_.get()); 916 event_router()->GattDescriptorAdded(mock_adapter_, desc1_.get());
912 917
913 // Load the extension and let it set up. 918 // Load the extension and let it set up.
914 ExtensionTestMessageListener listener("ready", true); 919 ExtensionTestMessageListener listener("ready", true);
915 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 920 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
916 "bluetooth_low_energy/descriptor_value_changed"))); 921 "bluetooth_low_energy/descriptor_value_changed")));
917 922
918 // Cause events to be sent to the extension. 923 // Cause events to be sent to the extension.
919 std::vector<uint8> value; 924 std::vector<uint8> value;
920 event_router()->GattDescriptorValueChanged(chrc0_.get(), desc0_.get(), value); 925 event_router()->GattDescriptorValueChanged(
921 event_router()->GattDescriptorValueChanged(chrc0_.get(), desc1_.get(), value); 926 mock_adapter_, desc0_.get(), value);
927 event_router()->GattDescriptorValueChanged(
928 mock_adapter_, desc1_.get(), value);
922 929
923 EXPECT_TRUE(listener.WaitUntilSatisfied()); 930 EXPECT_TRUE(listener.WaitUntilSatisfied());
924 listener.Reply("go"); 931 listener.Reply("go");
925 932
926 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 933 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
927 event_router()->GattDescriptorRemoved(chrc0_.get(), desc1_.get()); 934 event_router()->GattDescriptorRemoved(mock_adapter_, desc1_.get());
928 event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); 935 event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get());
929 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 936 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
930 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 937 event_router()->GattServiceRemoved(
931 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 938 mock_adapter_, device0_.get(), service0_.get());
932 } 939 }
933 940
934 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadDescriptorValue) { 941 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadDescriptorValue) {
935 ResultCatcher catcher; 942 ResultCatcher catcher;
936 catcher.RestrictToProfile(browser()->profile()); 943 catcher.RestrictToProfile(browser()->profile());
937 944
938 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 945 event_router()->GattServiceAdded(
939 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 946 mock_adapter_, device0_.get(), service0_.get());
940 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 947 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
941 event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); 948 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get());
942 949
943 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 950 EXPECT_CALL(*mock_adapter_, GetDevice(_))
944 .Times(3) 951 .Times(3)
945 .WillRepeatedly(Return(device0_.get())); 952 .WillRepeatedly(Return(device0_.get()));
946 953
947 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 954 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
948 .Times(3) 955 .Times(3)
949 .WillRepeatedly(Return(service0_.get())); 956 .WillRepeatedly(Return(service0_.get()));
950 957
951 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 958 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
(...skipping 12 matching lines...) Expand all
964 971
965 ExtensionTestMessageListener listener("ready", true); 972 ExtensionTestMessageListener listener("ready", true);
966 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 973 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
967 "bluetooth_low_energy/read_descriptor_value"))); 974 "bluetooth_low_energy/read_descriptor_value")));
968 EXPECT_TRUE(listener.WaitUntilSatisfied()); 975 EXPECT_TRUE(listener.WaitUntilSatisfied());
969 976
970 listener.Reply("go"); 977 listener.Reply("go");
971 978
972 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 979 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
973 980
974 event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); 981 event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get());
975 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 982 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
976 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 983 event_router()->GattServiceRemoved(
977 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 984 mock_adapter_, device0_.get(), service0_.get());
978 } 985 }
979 986
980 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteDescriptorValue) { 987 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteDescriptorValue) {
981 ResultCatcher catcher; 988 ResultCatcher catcher;
982 catcher.RestrictToProfile(browser()->profile()); 989 catcher.RestrictToProfile(browser()->profile());
983 990
984 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 991 event_router()->GattServiceAdded(
985 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 992 mock_adapter_, device0_.get(), service0_.get());
986 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 993 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
987 event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); 994 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get());
988 995
989 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 996 EXPECT_CALL(*mock_adapter_, GetDevice(_))
990 .Times(3) 997 .Times(3)
991 .WillRepeatedly(Return(device0_.get())); 998 .WillRepeatedly(Return(device0_.get()));
992 999
993 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 1000 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
994 .Times(3) 1001 .Times(3)
995 .WillRepeatedly(Return(service0_.get())); 1002 .WillRepeatedly(Return(service0_.get()));
996 1003
997 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 1004 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
(...skipping 14 matching lines...) Expand all
1012 1019
1013 ExtensionTestMessageListener listener("ready", true); 1020 ExtensionTestMessageListener listener("ready", true);
1014 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 1021 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
1015 "bluetooth_low_energy/write_descriptor_value"))); 1022 "bluetooth_low_energy/write_descriptor_value")));
1016 EXPECT_TRUE(listener.WaitUntilSatisfied()); 1023 EXPECT_TRUE(listener.WaitUntilSatisfied());
1017 1024
1018 listener.Reply("go"); 1025 listener.Reply("go");
1019 1026
1020 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1027 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
1021 1028
1022 event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); 1029 event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get());
1023 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 1030 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
1024 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 1031 event_router()->GattServiceRemoved(
1025 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 1032 mock_adapter_, device0_.get(), service0_.get());
1026 } 1033 }
1027 1034
1028 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, PermissionDenied) { 1035 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, PermissionDenied) {
1029 ResultCatcher catcher; 1036 ResultCatcher catcher;
1030 catcher.RestrictToProfile(browser()->profile()); 1037 catcher.RestrictToProfile(browser()->profile());
1031 1038
1032 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 1039 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
1033 "bluetooth_low_energy/permission_denied"))); 1040 "bluetooth_low_energy/permission_denied")));
1034 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1041 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
1035 } 1042 }
1036 1043
1037 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionMethods) { 1044 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionMethods) {
1038 ResultCatcher catcher; 1045 ResultCatcher catcher;
1039 catcher.RestrictToProfile(browser()->profile()); 1046 catcher.RestrictToProfile(browser()->profile());
1040 1047
1041 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 1048 event_router()->GattServiceAdded(
1042 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 1049 mock_adapter_, device0_.get(), service0_.get());
1043 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 1050 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
1044 event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); 1051 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get());
1045 1052
1046 std::vector<BluetoothGattService*> services; 1053 std::vector<BluetoothGattService*> services;
1047 services.push_back(service0_.get()); 1054 services.push_back(service0_.get());
1048 1055
1049 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 1056 EXPECT_CALL(*mock_adapter_, GetDevice(_))
1050 .WillRepeatedly(Return(device0_.get())); 1057 .WillRepeatedly(Return(device0_.get()));
1051 EXPECT_CALL(*device0_, GetGattServices()).WillOnce(Return(services)); 1058 EXPECT_CALL(*device0_, GetGattServices()).WillOnce(Return(services));
1052 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 1059 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
1053 .WillRepeatedly(Return(service0_.get())); 1060 .WillRepeatedly(Return(service0_.get()));
1054 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) 1061 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
1055 .WillRepeatedly(Return(chrc0_.get())); 1062 .WillRepeatedly(Return(chrc0_.get()));
1056 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0)) 1063 EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0))
1057 .WillRepeatedly(Return(desc0_.get())); 1064 .WillRepeatedly(Return(desc0_.get()));
1058 1065
1059 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 1066 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
1060 "bluetooth_low_energy/uuid_permission_methods"))); 1067 "bluetooth_low_energy/uuid_permission_methods")));
1061 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1068 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
1062 1069
1063 event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); 1070 event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get());
1064 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 1071 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
1065 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 1072 event_router()->GattServiceRemoved(
1066 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 1073 mock_adapter_, device0_.get(), service0_.get());
1067 } 1074 }
1068 1075
1069 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionEvents) { 1076 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionEvents) {
1070 ResultCatcher catcher; 1077 ResultCatcher catcher;
1071 catcher.RestrictToProfile(browser()->profile()); 1078 catcher.RestrictToProfile(browser()->profile());
1072 1079
1073 ExtensionTestMessageListener listener("ready", true); 1080 ExtensionTestMessageListener listener("ready", true);
1074 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 1081 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
1075 "bluetooth_low_energy/uuid_permission_events"))); 1082 "bluetooth_low_energy/uuid_permission_events")));
1076 1083
1077 // Cause events to be sent to the extension. 1084 // Cause events to be sent to the extension.
1078 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 1085 event_router()->GattServiceAdded(
1079 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 1086 mock_adapter_, device0_.get(), service0_.get());
1080 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 1087 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
1081 event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); 1088 event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get());
1082 1089
1083 std::vector<uint8> value; 1090 std::vector<uint8> value;
1084 event_router()->GattCharacteristicValueChanged( 1091 event_router()->GattCharacteristicValueChanged(
1085 service0_.get(), chrc0_.get(), value); 1092 mock_adapter_, chrc0_.get(), value);
1086 event_router()->GattDescriptorValueChanged(chrc0_.get(), desc0_.get(), value); 1093 event_router()->GattDescriptorValueChanged(
1087 event_router()->GattServiceChanged(service0_.get()); 1094 mock_adapter_, desc0_.get(), value);
1095 event_router()->GattServiceChanged(mock_adapter_, service0_.get());
1088 1096
1089 EXPECT_TRUE(listener.WaitUntilSatisfied()); 1097 EXPECT_TRUE(listener.WaitUntilSatisfied());
1090 listener.Reply("go"); 1098 listener.Reply("go");
1091 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1099 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
1092 1100
1093 event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); 1101 event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get());
1094 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 1102 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
1095 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 1103 event_router()->GattServiceRemoved(
1096 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 1104 mock_adapter_, device0_.get(), service0_.get());
1097 } 1105 }
1098 1106
1099 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GattConnection) { 1107 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GattConnection) {
1100 ResultCatcher catcher; 1108 ResultCatcher catcher;
1101 catcher.RestrictToProfile(browser()->profile()); 1109 catcher.RestrictToProfile(browser()->profile());
1102 1110
1103 event_router()->DeviceAdded(mock_adapter_, device0_.get());
1104 event_router()->DeviceAdded(mock_adapter_, device1_.get());
1105 1111
1106 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 1112 EXPECT_CALL(*mock_adapter_, GetDevice(_))
1107 .WillRepeatedly(Return(static_cast<BluetoothDevice*>(NULL))); 1113 .WillRepeatedly(Return(static_cast<BluetoothDevice*>(NULL)));
1108 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) 1114 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0))
1109 .WillRepeatedly(Return(device0_.get())); 1115 .WillRepeatedly(Return(device0_.get()));
1110 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress1)) 1116 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress1))
1111 .WillRepeatedly(Return(device1_.get())); 1117 .WillRepeatedly(Return(device1_.get()));
1112 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) 1118 EXPECT_CALL(*device0_, CreateGattConnection(_, _))
1113 .Times(3) 1119 .Times(3)
1114 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_FAILED)) 1120 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_FAILED))
1115 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( 1121 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>(
1116 CreateGattConnection(kTestLeDeviceAddress0, 1122 CreateGattConnection(kTestLeDeviceAddress0,
1117 true /* expect_disconnect */))) 1123 true /* expect_disconnect */)))
1118 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( 1124 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>(
1119 CreateGattConnection(kTestLeDeviceAddress0, 1125 CreateGattConnection(kTestLeDeviceAddress0,
1120 false /* expect_disconnect */))); 1126 false /* expect_disconnect */)));
1121 EXPECT_CALL(*device1_, CreateGattConnection(_, _)) 1127 EXPECT_CALL(*device1_, CreateGattConnection(_, _))
1122 .Times(1) 1128 .Times(1)
1123 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( 1129 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>(
1124 CreateGattConnection(kTestLeDeviceAddress1, 1130 CreateGattConnection(kTestLeDeviceAddress1,
1125 true /* expect_disconnect */))); 1131 true /* expect_disconnect */)));
1126 1132
1127 ASSERT_TRUE(LoadExtension( 1133 ASSERT_TRUE(LoadExtension(
1128 test_data_dir_.AppendASCII("bluetooth_low_energy/gatt_connection"))); 1134 test_data_dir_.AppendASCII("bluetooth_low_energy/gatt_connection")));
1129 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1135 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
1130
1131 event_router()->DeviceRemoved(mock_adapter_, device1_.get());
1132 event_router()->DeviceRemoved(mock_adapter_, device0_.get());
1133 } 1136 }
1134 1137
1135 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReconnectAfterDisconnected) { 1138 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReconnectAfterDisconnected) {
1136 ResultCatcher catcher; 1139 ResultCatcher catcher;
1137 catcher.RestrictToProfile(browser()->profile()); 1140 catcher.RestrictToProfile(browser()->profile());
1138 1141
1139 event_router()->DeviceAdded(mock_adapter_, device0_.get());
1140 1142
1141 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) 1143 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0))
1142 .WillRepeatedly(Return(device0_.get())); 1144 .WillRepeatedly(Return(device0_.get()));
1143 1145
1144 MockBluetoothGattConnection* first_conn = 1146 MockBluetoothGattConnection* first_conn =
1145 static_cast<MockBluetoothGattConnection*>(CreateGattConnection( 1147 static_cast<MockBluetoothGattConnection*>(CreateGattConnection(
1146 kTestLeDeviceAddress0, false /* expect_disconnect */)); 1148 kTestLeDeviceAddress0, false /* expect_disconnect */));
1147 EXPECT_CALL(*first_conn, IsConnected()) 1149 EXPECT_CALL(*first_conn, IsConnected())
1148 .Times(2) 1150 .Times(2)
1149 .WillOnce(Return(true)) 1151 .WillOnce(Return(true))
1150 .WillOnce(Return(false)); 1152 .WillOnce(Return(false));
1151 1153
1152 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) 1154 EXPECT_CALL(*device0_, CreateGattConnection(_, _))
1153 .Times(2) 1155 .Times(2)
1154 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( 1156 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>(
1155 first_conn)) 1157 first_conn))
1156 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( 1158 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>(
1157 CreateGattConnection(kTestLeDeviceAddress0, 1159 CreateGattConnection(kTestLeDeviceAddress0,
1158 false /* expect_disconnect */))); 1160 false /* expect_disconnect */)));
1159 1161
1160 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 1162 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
1161 "bluetooth_low_energy/reconnect_after_disconnected"))); 1163 "bluetooth_low_energy/reconnect_after_disconnected")));
1162 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1164 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
1163 1165
1164 event_router()->DeviceRemoved(mock_adapter_, device0_.get());
1165 } 1166 }
1166 1167
1167 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ConnectInProgress) { 1168 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ConnectInProgress) {
1168 ResultCatcher catcher; 1169 ResultCatcher catcher;
1169 catcher.RestrictToProfile(browser()->profile()); 1170 catcher.RestrictToProfile(browser()->profile());
1170 1171
1171 event_router()->DeviceAdded(mock_adapter_, device0_.get());
1172 1172
1173 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) 1173 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0))
1174 .WillRepeatedly(Return(device0_.get())); 1174 .WillRepeatedly(Return(device0_.get()));
1175 1175
1176 BluetoothDevice::GattConnectionCallback connect_callback; 1176 BluetoothDevice::GattConnectionCallback connect_callback;
1177 base::Closure disconnect_callback; 1177 base::Closure disconnect_callback;
1178 1178
1179 testing::NiceMock<MockBluetoothGattConnection>* conn = 1179 testing::NiceMock<MockBluetoothGattConnection>* conn =
1180 new testing::NiceMock<MockBluetoothGattConnection>( 1180 new testing::NiceMock<MockBluetoothGattConnection>(
1181 kTestLeDeviceAddress0); 1181 kTestLeDeviceAddress0);
(...skipping 12 matching lines...) Expand all
1194 1194
1195 listener.WaitUntilSatisfied(); 1195 listener.WaitUntilSatisfied();
1196 connect_callback.Run(conn_ptr.Pass()); 1196 connect_callback.Run(conn_ptr.Pass());
1197 1197
1198 listener.Reset(); 1198 listener.Reset();
1199 listener.WaitUntilSatisfied(); 1199 listener.WaitUntilSatisfied();
1200 disconnect_callback.Run(); 1200 disconnect_callback.Run();
1201 1201
1202 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1202 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
1203 1203
1204 event_router()->DeviceRemoved(mock_adapter_, device0_.get());
1205 } 1204 }
1206 1205
1207 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, StartStopNotifications) { 1206 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, StartStopNotifications) {
1208 ResultCatcher catcher; 1207 ResultCatcher catcher;
1209 catcher.RestrictToProfile(browser()->profile()); 1208 catcher.RestrictToProfile(browser()->profile());
1210 1209
1211 event_router()->DeviceAdded(mock_adapter_, device0_.get()); 1210 event_router()->GattServiceAdded(
1212 event_router()->GattServiceAdded(device0_.get(), service0_.get()); 1211 mock_adapter_, device0_.get(), service0_.get());
1213 event_router()->GattServiceAdded(device0_.get(), service1_.get()); 1212 event_router()->GattServiceAdded(
1214 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); 1213 mock_adapter_, device0_.get(), service1_.get());
1215 event_router()->GattCharacteristicAdded(service0_.get(), chrc1_.get()); 1214 event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get());
1216 event_router()->GattCharacteristicAdded(service1_.get(), chrc2_.get()); 1215 event_router()->GattCharacteristicAdded(mock_adapter_, chrc1_.get());
1216 event_router()->GattCharacteristicAdded(mock_adapter_, chrc2_.get());
1217 1217
1218 EXPECT_CALL(*mock_adapter_, GetDevice(_)) 1218 EXPECT_CALL(*mock_adapter_, GetDevice(_))
1219 .WillRepeatedly(Return(device0_.get())); 1219 .WillRepeatedly(Return(device0_.get()));
1220 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) 1220 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
1221 .WillRepeatedly(Return(service0_.get())); 1221 .WillRepeatedly(Return(service0_.get()));
1222 EXPECT_CALL(*device0_, GetGattService(kTestServiceId1)) 1222 EXPECT_CALL(*device0_, GetGattService(kTestServiceId1))
1223 .WillRepeatedly(Return(service1_.get())); 1223 .WillRepeatedly(Return(service1_.get()));
1224 EXPECT_CALL(*service1_, GetCharacteristic(kTestCharacteristicId2)) 1224 EXPECT_CALL(*service1_, GetCharacteristic(kTestCharacteristicId2))
1225 .Times(1) 1225 .Times(1)
1226 .WillOnce(Return(chrc2_.get())); 1226 .WillOnce(Return(chrc2_.get()));
(...skipping 28 matching lines...) Expand all
1255 session1)); 1255 session1));
1256 1256
1257 ExtensionTestMessageListener listener("ready", true); 1257 ExtensionTestMessageListener listener("ready", true);
1258 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 1258 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
1259 "bluetooth_low_energy/start_stop_notifications"))); 1259 "bluetooth_low_energy/start_stop_notifications")));
1260 1260
1261 EXPECT_TRUE(listener.WaitUntilSatisfied()); 1261 EXPECT_TRUE(listener.WaitUntilSatisfied());
1262 1262
1263 std::vector<uint8> value; 1263 std::vector<uint8> value;
1264 event_router()->GattCharacteristicValueChanged( 1264 event_router()->GattCharacteristicValueChanged(
1265 service0_.get(), chrc0_.get(), value); 1265 mock_adapter_, chrc0_.get(), value);
1266 event_router()->GattCharacteristicValueChanged( 1266 event_router()->GattCharacteristicValueChanged(
1267 service0_.get(), chrc1_.get(), value); 1267 mock_adapter_, chrc1_.get(), value);
1268 event_router()->GattCharacteristicValueChanged( 1268 event_router()->GattCharacteristicValueChanged(
1269 service1_.get(), chrc2_.get(), value); 1269 mock_adapter_, chrc2_.get(), value);
1270 1270
1271 listener.Reply("go"); 1271 listener.Reply("go");
1272 1272
1273 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1273 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
1274 event_router()->GattCharacteristicRemoved(service1_.get(), chrc2_.get()); 1274 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get());
1275 event_router()->GattCharacteristicRemoved(service0_.get(), chrc1_.get()); 1275 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc1_.get());
1276 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); 1276 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
1277 event_router()->GattServiceRemoved(device0_.get(), service1_.get()); 1277 event_router()->GattServiceRemoved(
1278 event_router()->GattServiceRemoved(device0_.get(), service0_.get()); 1278 mock_adapter_, device0_.get(), service1_.get());
1279 event_router()->DeviceRemoved(mock_adapter_, device0_.get()); 1279 event_router()->GattServiceRemoved(
1280 mock_adapter_, device0_.get(), service0_.get());
1280 } 1281 }
1281 1282
1282 } // namespace 1283 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698