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

Side by Side Diff: device/bluetooth/bluetooth_device_unittest.cc

Issue 1948763003: Adding support for service scan on OS X (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup
Patch Set: Fixing comments 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 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 "device/bluetooth/bluetooth_device.h" 5 #include "device/bluetooth/bluetooth_device.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 device->DisconnectGatt(); 446 device->DisconnectGatt();
447 EXPECT_EQ(1, gatt_connection_attempts_); 447 EXPECT_EQ(1, gatt_connection_attempts_);
448 EXPECT_EQ(1, gatt_disconnection_attempts_); 448 EXPECT_EQ(1, gatt_disconnection_attempts_);
449 SimulateGattDisconnection(device); 449 SimulateGattDisconnection(device);
450 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); 450 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_);
451 for (BluetoothGattConnection* connection : gatt_connections_) 451 for (BluetoothGattConnection* connection : gatt_connections_)
452 EXPECT_FALSE(connection->IsConnected()); 452 EXPECT_FALSE(connection->IsConnected());
453 } 453 }
454 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 454 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
455 455
456 #if defined(OS_ANDROID) 456 #if defined(OS_ANDROID) || defined(OS_MACOSX)
457 // Calls CreateGattConnection & DisconnectGatt, then checks that gatt services 457 // Calls CreateGattConnection & DisconnectGatt, then checks that gatt services
458 // have been cleaned up. 458 // have been cleaned up.
459 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_Cleanup) { 459 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_Cleanup) {
460 if (!PlatformSupportsLowEnergy()) { 460 if (!PlatformSupportsLowEnergy()) {
461 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 461 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
462 return; 462 return;
463 } 463 }
464 InitWithFakeAdapter(); 464 InitWithFakeAdapter();
465 StartLowEnergyDiscoverySession(); 465 StartLowEnergyDiscoverySession();
466 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 466 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
(...skipping 30 matching lines...) Expand all
497 EXPECT_TRUE(device->IsConnected()); 497 EXPECT_TRUE(device->IsConnected());
498 498
499 // Verify that service discovery can be done again 499 // Verify that service discovery can be done again
500 std::vector<std::string> services2; 500 std::vector<std::string> services2;
501 services2.push_back("00000002-0000-1000-8000-00805f9b34fb"); 501 services2.push_back("00000002-0000-1000-8000-00805f9b34fb");
502 SimulateGattServicesDiscovered(device, services2); 502 SimulateGattServicesDiscovered(device, services2);
503 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); 503 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
504 EXPECT_EQ(1u, device->GetGattServices().size()); 504 EXPECT_EQ(1u, device->GetGattServices().size());
505 EXPECT_EQ(2, observer.gatt_services_discovered_count()); 505 EXPECT_EQ(2, observer.gatt_services_discovered_count());
506 } 506 }
507 #endif // defined(OS_ANDROID) 507 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
508 508
509 #if defined(OS_ANDROID) || defined(OS_MACOSX) 509 #if defined(OS_ANDROID) || defined(OS_MACOSX)
510 // Calls CreateGattConnection, but simulate errors connecting. Also, verifies 510 // Calls CreateGattConnection, but simulate errors connecting. Also, verifies
511 // multiple errors should only invoke callbacks once. 511 // multiple errors should only invoke callbacks once.
512 TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) { 512 TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) {
513 if (!PlatformSupportsLowEnergy()) { 513 if (!PlatformSupportsLowEnergy()) {
514 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 514 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
515 return; 515 return;
516 } 516 }
517 InitWithFakeAdapter(); 517 InitWithFakeAdapter();
(...skipping 13 matching lines...) Expand all
531 // http://crbug.com/578191 531 // http://crbug.com/578191
532 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); 532 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_);
533 #else 533 #else
534 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_FAILED, last_connect_error_code_); 534 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_FAILED, last_connect_error_code_);
535 #endif 535 #endif
536 for (BluetoothGattConnection* connection : gatt_connections_) 536 for (BluetoothGattConnection* connection : gatt_connections_)
537 EXPECT_FALSE(connection->IsConnected()); 537 EXPECT_FALSE(connection->IsConnected());
538 } 538 }
539 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 539 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
540 540
541 #if defined(OS_ANDROID) || defined(OS_WIN) 541 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX)
542 TEST_F(BluetoothTest, GattServices_ObserversCalls) { 542 TEST_F(BluetoothTest, GattServices_ObserversCalls) {
543 if (!PlatformSupportsLowEnergy()) { 543 if (!PlatformSupportsLowEnergy()) {
544 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 544 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
545 return; 545 return;
546 } 546 }
547 InitWithFakeAdapter(); 547 InitWithFakeAdapter();
548 StartLowEnergyDiscoverySession(); 548 StartLowEnergyDiscoverySession();
549 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 549 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
550 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 550 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
551 GetConnectErrorCallback(Call::NOT_EXPECTED)); 551 GetConnectErrorCallback(Call::NOT_EXPECTED));
552 TestBluetoothAdapterObserver observer(adapter_); 552 TestBluetoothAdapterObserver observer(adapter_);
553 ResetEventCounts(); 553 ResetEventCounts();
554 SimulateGattConnection(device); 554 SimulateGattConnection(device);
555 EXPECT_EQ(1, gatt_discovery_attempts_); 555 EXPECT_EQ(1, gatt_discovery_attempts_);
556 556
557 std::vector<std::string> services; 557 std::vector<std::string> services;
558 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); 558 services.push_back("00000000-0000-1000-8000-00805f9b34fb");
559 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); 559 services.push_back("00000001-0000-1000-8000-00805f9b34fb");
560 SimulateGattServicesDiscovered(device, services); 560 SimulateGattServicesDiscovered(device, services);
561 561
562 EXPECT_EQ(1, observer.gatt_services_discovered_count()); 562 EXPECT_EQ(1, observer.gatt_services_discovered_count());
563 EXPECT_EQ(2, observer.gatt_service_added_count()); 563 EXPECT_EQ(2, observer.gatt_service_added_count());
564 } 564 }
565 #endif // defined(OS_ANDROID) || defined(OS_WIN) 565 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX)
566 566
567 #if defined(OS_ANDROID) || defined(OS_WIN) 567 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX)
568 TEST_F(BluetoothTest, GetGattServices_and_GetGattService) { 568 TEST_F(BluetoothTest, GetGattServices_and_GetGattService) {
569 if (!PlatformSupportsLowEnergy()) { 569 if (!PlatformSupportsLowEnergy()) {
570 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 570 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
571 return; 571 return;
572 } 572 }
573 InitWithFakeAdapter(); 573 InitWithFakeAdapter();
574 StartLowEnergyDiscoverySession(); 574 StartLowEnergyDiscoverySession();
575 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 575 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
576 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 576 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
577 GetConnectErrorCallback(Call::NOT_EXPECTED)); 577 GetConnectErrorCallback(Call::NOT_EXPECTED));
(...skipping 10 matching lines...) Expand all
588 EXPECT_EQ(3u, device->GetGattServices().size()); 588 EXPECT_EQ(3u, device->GetGattServices().size());
589 589
590 // Test GetGattService: 590 // Test GetGattService:
591 std::string service_id1 = device->GetGattServices()[0]->GetIdentifier(); 591 std::string service_id1 = device->GetGattServices()[0]->GetIdentifier();
592 std::string service_id2 = device->GetGattServices()[1]->GetIdentifier(); 592 std::string service_id2 = device->GetGattServices()[1]->GetIdentifier();
593 std::string service_id3 = device->GetGattServices()[2]->GetIdentifier(); 593 std::string service_id3 = device->GetGattServices()[2]->GetIdentifier();
594 EXPECT_TRUE(device->GetGattService(service_id1)); 594 EXPECT_TRUE(device->GetGattService(service_id1));
595 EXPECT_TRUE(device->GetGattService(service_id2)); 595 EXPECT_TRUE(device->GetGattService(service_id2));
596 EXPECT_TRUE(device->GetGattService(service_id3)); 596 EXPECT_TRUE(device->GetGattService(service_id3));
597 } 597 }
598 #endif // defined(OS_ANDROID) || defined(OS_WIN) 598 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX)
599 599
600 #if defined(OS_ANDROID) 600 #if defined(OS_ANDROID) || defined(OS_MACOSX)
601 TEST_F(BluetoothTest, GetGattServices_DiscoveryError) { 601 TEST_F(BluetoothTest, GetGattServices_DiscoveryError) {
602 if (!PlatformSupportsLowEnergy()) { 602 if (!PlatformSupportsLowEnergy()) {
603 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 603 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
604 return; 604 return;
605 } 605 }
606 InitWithFakeAdapter(); 606 InitWithFakeAdapter();
607 StartLowEnergyDiscoverySession(); 607 StartLowEnergyDiscoverySession();
608 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 608 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
609 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 609 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
610 GetConnectErrorCallback(Call::NOT_EXPECTED)); 610 GetConnectErrorCallback(Call::NOT_EXPECTED));
611 ResetEventCounts(); 611 ResetEventCounts();
612 SimulateGattConnection(device); 612 SimulateGattConnection(device);
613 EXPECT_EQ(1, gatt_discovery_attempts_); 613 EXPECT_EQ(1, gatt_discovery_attempts_);
614 614
615 SimulateGattServicesDiscoveryError(device); 615 SimulateGattServicesDiscoveryError(device);
616 EXPECT_EQ(0u, device->GetGattServices().size()); 616 EXPECT_EQ(0u, device->GetGattServices().size());
617 } 617 }
618 #endif // defined(OS_ANDROID) 618 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
619 619
620 } // namespace device 620 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_mac.mm ('k') | device/bluetooth/bluetooth_low_energy_device_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698