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

Side by Side Diff: device/bluetooth/bluez/bluetooth_bluez_unittest.cc

Issue 2211473003: Remove calls to deprecated MessageLoop methods on Windows and Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR gab #18 + fix build error Created 4 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 215
216 void TearDown() override { 216 void TearDown() override {
217 for (ScopedVector<BluetoothDiscoverySession>::iterator iter = 217 for (ScopedVector<BluetoothDiscoverySession>::iterator iter =
218 discovery_sessions_.begin(); 218 discovery_sessions_.begin();
219 iter != discovery_sessions_.end(); ++iter) { 219 iter != discovery_sessions_.end(); ++iter) {
220 BluetoothDiscoverySession* session = *iter; 220 BluetoothDiscoverySession* session = *iter;
221 if (!session->IsActive()) 221 if (!session->IsActive())
222 continue; 222 continue;
223 callback_count_ = 0; 223 callback_count_ = 0;
224 session->Stop(GetCallback(), GetErrorCallback()); 224 session->Stop(GetCallback(), GetErrorCallback());
225 message_loop_.Run(); 225 base::RunLoop().Run();
226 ASSERT_EQ(1, callback_count_); 226 ASSERT_EQ(1, callback_count_);
227 } 227 }
228 discovery_sessions_.clear(); 228 discovery_sessions_.clear();
229 adapter_ = nullptr; 229 adapter_ = nullptr;
230 bluez::BluezDBusManager::Shutdown(); 230 bluez::BluezDBusManager::Shutdown();
231 } 231 }
232 232
233 // Generic callbacks 233 // Generic callbacks
234 void Callback() { 234 void Callback() {
235 ++callback_count_; 235 ++callback_count_;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 299
300 void ErrorCompletionCallback(const std::string& error_message) { 300 void ErrorCompletionCallback(const std::string& error_message) {
301 ++error_callback_count_; 301 ++error_callback_count_;
302 QuitMessageLoop(); 302 QuitMessageLoop();
303 } 303 }
304 304
305 // Call to fill the adapter_ member with a BluetoothAdapter instance. 305 // Call to fill the adapter_ member with a BluetoothAdapter instance.
306 void GetAdapter() { 306 void GetAdapter() {
307 adapter_ = new BluetoothAdapterBlueZ(base::Bind( 307 adapter_ = new BluetoothAdapterBlueZ(base::Bind(
308 &BluetoothBlueZTest::AdapterCallback, base::Unretained(this))); 308 &BluetoothBlueZTest::AdapterCallback, base::Unretained(this)));
309 base::MessageLoop::current()->Run(); 309 base::RunLoop().Run();
310 ASSERT_TRUE(adapter_.get() != nullptr); 310 ASSERT_TRUE(adapter_.get() != nullptr);
311 ASSERT_TRUE(adapter_->IsInitialized()); 311 ASSERT_TRUE(adapter_->IsInitialized());
312 } 312 }
313 313
314 // Run a discovery phase until the named device is detected, or if the named 314 // Run a discovery phase until the named device is detected, or if the named
315 // device is not created, the discovery process ends without finding it. 315 // device is not created, the discovery process ends without finding it.
316 // 316 //
317 // The correct behavior of discovery is tested by the "Discovery" test case 317 // The correct behavior of discovery is tested by the "Discovery" test case
318 // without using this function. 318 // without using this function.
319 void DiscoverDevice(const std::string& address) { 319 void DiscoverDevice(const std::string& address) {
320 ASSERT_TRUE(adapter_.get() != nullptr); 320 ASSERT_TRUE(adapter_.get() != nullptr);
321 ASSERT_TRUE(base::MessageLoop::current() != nullptr); 321 ASSERT_TRUE(base::MessageLoop::current() != nullptr);
322 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 322 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
323 323
324 TestBluetoothAdapterObserver observer(adapter_); 324 TestBluetoothAdapterObserver observer(adapter_);
325 325
326 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 326 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
327 adapter_->StartDiscoverySession( 327 adapter_->StartDiscoverySession(
328 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 328 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
329 base::Unretained(this)), 329 base::Unretained(this)),
330 GetErrorCallback()); 330 GetErrorCallback());
331 base::MessageLoop::current()->Run(); 331 base::RunLoop().Run();
332 ASSERT_EQ(2, callback_count_); 332 ASSERT_EQ(2, callback_count_);
333 ASSERT_EQ(0, error_callback_count_); 333 ASSERT_EQ(0, error_callback_count_);
334 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 334 ASSERT_EQ((size_t)1, discovery_sessions_.size());
335 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 335 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
336 callback_count_ = 0; 336 callback_count_ = 0;
337 337
338 ASSERT_TRUE(adapter_->IsPowered()); 338 ASSERT_TRUE(adapter_->IsPowered());
339 ASSERT_TRUE(adapter_->IsDiscovering()); 339 ASSERT_TRUE(adapter_->IsDiscovering());
340 340
341 while (!observer.device_removed_count() && 341 while (!observer.device_removed_count() &&
342 observer.last_device_address() != address) 342 observer.last_device_address() != address)
343 base::MessageLoop::current()->Run(); 343 base::RunLoop().Run();
344 344
345 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 345 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
346 base::MessageLoop::current()->Run(); 346 base::RunLoop().Run();
347 ASSERT_EQ(1, callback_count_); 347 ASSERT_EQ(1, callback_count_);
348 ASSERT_EQ(0, error_callback_count_); 348 ASSERT_EQ(0, error_callback_count_);
349 callback_count_ = 0; 349 callback_count_ = 0;
350 350
351 ASSERT_FALSE(adapter_->IsDiscovering()); 351 ASSERT_FALSE(adapter_->IsDiscovering());
352 } 352 }
353 353
354 // Run a discovery phase so we have devices that can be paired with. 354 // Run a discovery phase so we have devices that can be paired with.
355 void DiscoverDevices() { 355 void DiscoverDevices() {
356 // Pass an invalid address for the device so that the discovery process 356 // Pass an invalid address for the device so that the discovery process
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 } 716 }
717 717
718 TEST_F(BluetoothBlueZTest, StopDiscovery) { 718 TEST_F(BluetoothBlueZTest, StopDiscovery) {
719 GetAdapter(); 719 GetAdapter();
720 720
721 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 721 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
722 adapter_->StartDiscoverySession( 722 adapter_->StartDiscoverySession(
723 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 723 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
724 base::Unretained(this)), 724 base::Unretained(this)),
725 GetErrorCallback()); 725 GetErrorCallback());
726 message_loop_.Run(); 726 base::RunLoop().Run();
727 EXPECT_EQ(2, callback_count_); 727 EXPECT_EQ(2, callback_count_);
728 EXPECT_EQ(0, error_callback_count_); 728 EXPECT_EQ(0, error_callback_count_);
729 callback_count_ = 0; 729 callback_count_ = 0;
730 730
731 ASSERT_TRUE(adapter_->IsPowered()); 731 ASSERT_TRUE(adapter_->IsPowered());
732 ASSERT_TRUE(adapter_->IsDiscovering()); 732 ASSERT_TRUE(adapter_->IsDiscovering());
733 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 733 ASSERT_EQ((size_t)1, discovery_sessions_.size());
734 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 734 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
735 735
736 // Install an observer; aside from the callback, expect the 736 // Install an observer; aside from the callback, expect the
737 // AdapterDiscoveringChanged method to be called and no longer to be 737 // AdapterDiscoveringChanged method to be called and no longer to be
738 // discovering, 738 // discovering,
739 TestBluetoothAdapterObserver observer(adapter_); 739 TestBluetoothAdapterObserver observer(adapter_);
740 740
741 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 741 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
742 message_loop_.Run(); 742 base::RunLoop().Run();
743 EXPECT_EQ(1, callback_count_); 743 EXPECT_EQ(1, callback_count_);
744 EXPECT_EQ(0, error_callback_count_); 744 EXPECT_EQ(0, error_callback_count_);
745 745
746 EXPECT_EQ(1, observer.discovering_changed_count()); 746 EXPECT_EQ(1, observer.discovering_changed_count());
747 EXPECT_FALSE(observer.last_discovering()); 747 EXPECT_FALSE(observer.last_discovering());
748 748
749 EXPECT_FALSE(adapter_->IsDiscovering()); 749 EXPECT_FALSE(adapter_->IsDiscovering());
750 discovery_sessions_.clear(); 750 discovery_sessions_.clear();
751 callback_count_ = 0; 751 callback_count_ = 0;
752 752
753 // Test that the Stop callbacks get called even if the 753 // Test that the Stop callbacks get called even if the
754 // BluetoothDiscoverySession objects gets deleted 754 // BluetoothDiscoverySession objects gets deleted
755 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 755 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
756 adapter_->StartDiscoverySession( 756 adapter_->StartDiscoverySession(
757 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 757 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
758 base::Unretained(this)), 758 base::Unretained(this)),
759 GetErrorCallback()); 759 GetErrorCallback());
760 message_loop_.Run(); 760 base::RunLoop().Run();
761 EXPECT_EQ(2, callback_count_); 761 EXPECT_EQ(2, callback_count_);
762 EXPECT_EQ(0, error_callback_count_); 762 EXPECT_EQ(0, error_callback_count_);
763 callback_count_ = 0; 763 callback_count_ = 0;
764 ASSERT_TRUE(adapter_->IsPowered()); 764 ASSERT_TRUE(adapter_->IsPowered());
765 ASSERT_TRUE(adapter_->IsDiscovering()); 765 ASSERT_TRUE(adapter_->IsDiscovering());
766 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 766 ASSERT_EQ((size_t)1, discovery_sessions_.size());
767 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 767 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
768 768
769 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 769 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
770 discovery_sessions_.clear(); 770 discovery_sessions_.clear();
771 771
772 message_loop_.Run(); 772 base::RunLoop().Run();
773 EXPECT_EQ(1, callback_count_); 773 EXPECT_EQ(1, callback_count_);
774 EXPECT_EQ(0, error_callback_count_); 774 EXPECT_EQ(0, error_callback_count_);
775 } 775 }
776 776
777 TEST_F(BluetoothBlueZTest, Discovery) { 777 TEST_F(BluetoothBlueZTest, Discovery) {
778 // Test a simulated discovery session. 778 // Test a simulated discovery session.
779 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 779 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
780 GetAdapter(); 780 GetAdapter();
781 781
782 TestBluetoothAdapterObserver observer(adapter_); 782 TestBluetoothAdapterObserver observer(adapter_);
783 783
784 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 784 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
785 adapter_->StartDiscoverySession( 785 adapter_->StartDiscoverySession(
786 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 786 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
787 base::Unretained(this)), 787 base::Unretained(this)),
788 GetErrorCallback()); 788 GetErrorCallback());
789 message_loop_.Run(); 789 base::RunLoop().Run();
790 EXPECT_EQ(2, callback_count_); 790 EXPECT_EQ(2, callback_count_);
791 EXPECT_EQ(0, error_callback_count_); 791 EXPECT_EQ(0, error_callback_count_);
792 callback_count_ = 0; 792 callback_count_ = 0;
793 793
794 ASSERT_TRUE(adapter_->IsPowered()); 794 ASSERT_TRUE(adapter_->IsPowered());
795 ASSERT_TRUE(adapter_->IsDiscovering()); 795 ASSERT_TRUE(adapter_->IsDiscovering());
796 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 796 ASSERT_EQ((size_t)1, discovery_sessions_.size());
797 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 797 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
798 798
799 // First two devices to appear. 799 // First two devices to appear.
800 message_loop_.Run(); 800 base::RunLoop().Run();
801 801
802 EXPECT_EQ(2, observer.device_added_count()); 802 EXPECT_EQ(2, observer.device_added_count());
803 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, 803 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress,
804 observer.last_device_address()); 804 observer.last_device_address());
805 805
806 // Next we should get another two devices... 806 // Next we should get another two devices...
807 message_loop_.Run(); 807 base::RunLoop().Run();
808 EXPECT_EQ(4, observer.device_added_count()); 808 EXPECT_EQ(4, observer.device_added_count());
809 809
810 // Okay, let's run forward until a device is actually removed... 810 // Okay, let's run forward until a device is actually removed...
811 while (!observer.device_removed_count()) 811 while (!observer.device_removed_count())
812 message_loop_.Run(); 812 base::RunLoop().Run();
813 813
814 EXPECT_EQ(1, observer.device_removed_count()); 814 EXPECT_EQ(1, observer.device_removed_count());
815 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress, 815 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress,
816 observer.last_device_address()); 816 observer.last_device_address());
817 } 817 }
818 818
819 TEST_F(BluetoothBlueZTest, PoweredAndDiscovering) { 819 TEST_F(BluetoothBlueZTest, PoweredAndDiscovering) {
820 GetAdapter(); 820 GetAdapter();
821 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 821 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
822 adapter_->StartDiscoverySession( 822 adapter_->StartDiscoverySession(
823 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 823 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
824 base::Unretained(this)), 824 base::Unretained(this)),
825 GetErrorCallback()); 825 GetErrorCallback());
826 message_loop_.Run(); 826 base::RunLoop().Run();
827 EXPECT_EQ(2, callback_count_); 827 EXPECT_EQ(2, callback_count_);
828 EXPECT_EQ(0, error_callback_count_); 828 EXPECT_EQ(0, error_callback_count_);
829 callback_count_ = 0; 829 callback_count_ = 0;
830 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 830 ASSERT_EQ((size_t)1, discovery_sessions_.size());
831 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 831 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
832 832
833 // Stop the timers that the simulation uses 833 // Stop the timers that the simulation uses
834 fake_bluetooth_device_client_->EndDiscoverySimulation( 834 fake_bluetooth_device_client_->EndDiscoverySimulation(
835 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath)); 835 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath));
836 836
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 EXPECT_FALSE(adapter_->IsDiscovering()); 897 EXPECT_FALSE(adapter_->IsDiscovering());
898 898
899 // Request device discovery 3 times. 899 // Request device discovery 3 times.
900 for (int i = 0; i < 3; i++) { 900 for (int i = 0; i < 3; i++) {
901 adapter_->StartDiscoverySession( 901 adapter_->StartDiscoverySession(
902 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 902 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
903 base::Unretained(this)), 903 base::Unretained(this)),
904 GetErrorCallback()); 904 GetErrorCallback());
905 } 905 }
906 // Run only once, as there should have been one D-Bus call. 906 // Run only once, as there should have been one D-Bus call.
907 message_loop_.Run(); 907 base::RunLoop().Run();
908 908
909 // The observer should have received the discovering changed event exactly 909 // The observer should have received the discovering changed event exactly
910 // once, the success callback should have been called 3 times and the adapter 910 // once, the success callback should have been called 3 times and the adapter
911 // should be discovering. 911 // should be discovering.
912 EXPECT_EQ(1, observer.discovering_changed_count()); 912 EXPECT_EQ(1, observer.discovering_changed_count());
913 EXPECT_EQ(3, callback_count_); 913 EXPECT_EQ(3, callback_count_);
914 EXPECT_EQ(0, error_callback_count_); 914 EXPECT_EQ(0, error_callback_count_);
915 EXPECT_TRUE(observer.last_discovering()); 915 EXPECT_TRUE(observer.last_discovering());
916 EXPECT_TRUE(adapter_->IsDiscovering()); 916 EXPECT_TRUE(adapter_->IsDiscovering());
917 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 917 ASSERT_EQ((size_t)3, discovery_sessions_.size());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 EXPECT_EQ(0, error_callback_count_); 950 EXPECT_EQ(0, error_callback_count_);
951 EXPECT_TRUE(observer.last_discovering()); 951 EXPECT_TRUE(observer.last_discovering());
952 EXPECT_TRUE(adapter_->IsDiscovering()); 952 EXPECT_TRUE(adapter_->IsDiscovering());
953 ASSERT_EQ((size_t)6, discovery_sessions_.size()); 953 ASSERT_EQ((size_t)6, discovery_sessions_.size());
954 954
955 // Request to stop discovery 4 times. 955 // Request to stop discovery 4 times.
956 for (int i = 2; i < 6; i++) { 956 for (int i = 2; i < 6; i++) {
957 discovery_sessions_[i]->Stop(GetCallback(), GetErrorCallback()); 957 discovery_sessions_[i]->Stop(GetCallback(), GetErrorCallback());
958 } 958 }
959 // Run only once, as there should have been one D-Bus call. 959 // Run only once, as there should have been one D-Bus call.
960 message_loop_.Run(); 960 base::RunLoop().Run();
961 961
962 // The observer should have received the discovering changed event exactly 962 // The observer should have received the discovering changed event exactly
963 // once, the success callback should have been called 4 times and the adapter 963 // once, the success callback should have been called 4 times and the adapter
964 // should no longer be discovering. 964 // should no longer be discovering.
965 EXPECT_EQ(2, observer.discovering_changed_count()); 965 EXPECT_EQ(2, observer.discovering_changed_count());
966 EXPECT_EQ(12, callback_count_); 966 EXPECT_EQ(12, callback_count_);
967 EXPECT_EQ(0, error_callback_count_); 967 EXPECT_EQ(0, error_callback_count_);
968 EXPECT_FALSE(observer.last_discovering()); 968 EXPECT_FALSE(observer.last_discovering());
969 EXPECT_FALSE(adapter_->IsDiscovering()); 969 EXPECT_FALSE(adapter_->IsDiscovering());
970 970
(...skipping 30 matching lines...) Expand all
1001 EXPECT_FALSE(adapter_->IsDiscovering()); 1001 EXPECT_FALSE(adapter_->IsDiscovering());
1002 1002
1003 // Request device discovery 3 times. 1003 // Request device discovery 3 times.
1004 for (int i = 0; i < 3; i++) { 1004 for (int i = 0; i < 3; i++) {
1005 adapter_->StartDiscoverySession( 1005 adapter_->StartDiscoverySession(
1006 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1006 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1007 base::Unretained(this)), 1007 base::Unretained(this)),
1008 GetErrorCallback()); 1008 GetErrorCallback());
1009 } 1009 }
1010 // Run only once, as there should have been one D-Bus call. 1010 // Run only once, as there should have been one D-Bus call.
1011 message_loop_.Run(); 1011 base::RunLoop().Run();
1012 1012
1013 // The observer should have received the discovering changed event exactly 1013 // The observer should have received the discovering changed event exactly
1014 // once, the success callback should have been called 3 times and the adapter 1014 // once, the success callback should have been called 3 times and the adapter
1015 // should be discovering. 1015 // should be discovering.
1016 EXPECT_EQ(1, observer.discovering_changed_count()); 1016 EXPECT_EQ(1, observer.discovering_changed_count());
1017 EXPECT_EQ(3, callback_count_); 1017 EXPECT_EQ(3, callback_count_);
1018 EXPECT_EQ(0, error_callback_count_); 1018 EXPECT_EQ(0, error_callback_count_);
1019 EXPECT_TRUE(observer.last_discovering()); 1019 EXPECT_TRUE(observer.last_discovering());
1020 EXPECT_TRUE(adapter_->IsDiscovering()); 1020 EXPECT_TRUE(adapter_->IsDiscovering());
1021 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1021 ASSERT_EQ((size_t)3, discovery_sessions_.size());
(...skipping 13 matching lines...) Expand all
1035 // Even though bluez::FakeBluetoothAdapterClient does its own reference 1035 // Even though bluez::FakeBluetoothAdapterClient does its own reference
1036 // counting and 1036 // counting and
1037 // we called 3 BluetoothAdapter::StartDiscoverySession 3 times, the 1037 // we called 3 BluetoothAdapter::StartDiscoverySession 3 times, the
1038 // bluez::FakeBluetoothAdapterClient's count should be only 1 and a single 1038 // bluez::FakeBluetoothAdapterClient's count should be only 1 and a single
1039 // call to 1039 // call to
1040 // bluez::FakeBluetoothAdapterClient::StopDiscovery should work. 1040 // bluez::FakeBluetoothAdapterClient::StopDiscovery should work.
1041 fake_bluetooth_adapter_client_->StopDiscovery( 1041 fake_bluetooth_adapter_client_->StopDiscovery(
1042 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 1042 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
1043 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, 1043 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
1044 base::Unretained(this))); 1044 base::Unretained(this)));
1045 message_loop_.Run(); 1045 base::RunLoop().Run();
1046 EXPECT_EQ(2, observer.discovering_changed_count()); 1046 EXPECT_EQ(2, observer.discovering_changed_count());
1047 EXPECT_EQ(4, callback_count_); 1047 EXPECT_EQ(4, callback_count_);
1048 EXPECT_EQ(0, error_callback_count_); 1048 EXPECT_EQ(0, error_callback_count_);
1049 EXPECT_FALSE(observer.last_discovering()); 1049 EXPECT_FALSE(observer.last_discovering());
1050 EXPECT_FALSE(adapter_->IsDiscovering()); 1050 EXPECT_FALSE(adapter_->IsDiscovering());
1051 1051
1052 // All discovery session instances should have been updated. 1052 // All discovery session instances should have been updated.
1053 for (int i = 0; i < 3; i++) 1053 for (int i = 0; i < 3; i++)
1054 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); 1054 EXPECT_FALSE(discovery_sessions_[i]->IsActive());
1055 discovery_sessions_.clear(); 1055 discovery_sessions_.clear();
1056 1056
1057 // It should be possible to successfully start discovery. 1057 // It should be possible to successfully start discovery.
1058 for (int i = 0; i < 2; i++) { 1058 for (int i = 0; i < 2; i++) {
1059 adapter_->StartDiscoverySession( 1059 adapter_->StartDiscoverySession(
1060 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1060 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1061 base::Unretained(this)), 1061 base::Unretained(this)),
1062 GetErrorCallback()); 1062 GetErrorCallback());
1063 } 1063 }
1064 // Run only once, as there should have been one D-Bus call. 1064 // Run only once, as there should have been one D-Bus call.
1065 message_loop_.Run(); 1065 base::RunLoop().Run();
1066 EXPECT_EQ(3, observer.discovering_changed_count()); 1066 EXPECT_EQ(3, observer.discovering_changed_count());
1067 EXPECT_EQ(6, callback_count_); 1067 EXPECT_EQ(6, callback_count_);
1068 EXPECT_EQ(0, error_callback_count_); 1068 EXPECT_EQ(0, error_callback_count_);
1069 EXPECT_TRUE(observer.last_discovering()); 1069 EXPECT_TRUE(observer.last_discovering());
1070 EXPECT_TRUE(adapter_->IsDiscovering()); 1070 EXPECT_TRUE(adapter_->IsDiscovering());
1071 ASSERT_EQ((size_t)2, discovery_sessions_.size()); 1071 ASSERT_EQ((size_t)2, discovery_sessions_.size());
1072 1072
1073 for (int i = 0; i < 2; i++) 1073 for (int i = 0; i < 2; i++)
1074 EXPECT_TRUE(discovery_sessions_[i]->IsActive()); 1074 EXPECT_TRUE(discovery_sessions_[i]->IsActive());
1075 1075
(...skipping 25 matching lines...) Expand all
1101 1101
1102 // Start and stop discovery. At this point, bluez::FakeBluetoothAdapterClient 1102 // Start and stop discovery. At this point, bluez::FakeBluetoothAdapterClient
1103 // has 1103 // has
1104 // a reference count that is equal to 1. Pretend that this was done by an 1104 // a reference count that is equal to 1. Pretend that this was done by an
1105 // application other than us. Starting and stopping discovery will succeed 1105 // application other than us. Starting and stopping discovery will succeed
1106 // but it won't cause the discovery state to change. 1106 // but it won't cause the discovery state to change.
1107 adapter_->StartDiscoverySession( 1107 adapter_->StartDiscoverySession(
1108 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1108 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1109 base::Unretained(this)), 1109 base::Unretained(this)),
1110 GetErrorCallback()); 1110 GetErrorCallback());
1111 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. 1111 base::RunLoop()
1112 .Run(); // Run the loop, as there should have been a D-Bus call.
Reilly Grant (use Gerrit) 2016/08/05 18:24:45 This and below is an unfortunately wrapping. Can y
fdoray 2016/08/05 23:41:36 Done.
1112 EXPECT_EQ(5, observer.discovering_changed_count()); 1113 EXPECT_EQ(5, observer.discovering_changed_count());
1113 EXPECT_EQ(7, callback_count_); 1114 EXPECT_EQ(7, callback_count_);
1114 EXPECT_EQ(0, error_callback_count_); 1115 EXPECT_EQ(0, error_callback_count_);
1115 EXPECT_TRUE(observer.last_discovering()); 1116 EXPECT_TRUE(observer.last_discovering());
1116 EXPECT_TRUE(adapter_->IsDiscovering()); 1117 EXPECT_TRUE(adapter_->IsDiscovering());
1117 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1118 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1118 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1119 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1119 1120
1120 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 1121 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
1121 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. 1122 base::RunLoop()
1123 .Run(); // Run the loop, as there should have been a D-Bus call.
1122 EXPECT_EQ(5, observer.discovering_changed_count()); 1124 EXPECT_EQ(5, observer.discovering_changed_count());
1123 EXPECT_EQ(8, callback_count_); 1125 EXPECT_EQ(8, callback_count_);
1124 EXPECT_EQ(0, error_callback_count_); 1126 EXPECT_EQ(0, error_callback_count_);
1125 EXPECT_TRUE(observer.last_discovering()); 1127 EXPECT_TRUE(observer.last_discovering());
1126 EXPECT_TRUE(adapter_->IsDiscovering()); 1128 EXPECT_TRUE(adapter_->IsDiscovering());
1127 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 1129 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
1128 discovery_sessions_.clear(); 1130 discovery_sessions_.clear();
1129 1131
1130 // Start discovery again. 1132 // Start discovery again.
1131 adapter_->StartDiscoverySession( 1133 adapter_->StartDiscoverySession(
1132 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1134 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1133 base::Unretained(this)), 1135 base::Unretained(this)),
1134 GetErrorCallback()); 1136 GetErrorCallback());
1135 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. 1137 base::RunLoop()
1138 .Run(); // Run the loop, as there should have been a D-Bus call.
1136 EXPECT_EQ(5, observer.discovering_changed_count()); 1139 EXPECT_EQ(5, observer.discovering_changed_count());
1137 EXPECT_EQ(9, callback_count_); 1140 EXPECT_EQ(9, callback_count_);
1138 EXPECT_EQ(0, error_callback_count_); 1141 EXPECT_EQ(0, error_callback_count_);
1139 EXPECT_TRUE(observer.last_discovering()); 1142 EXPECT_TRUE(observer.last_discovering());
1140 EXPECT_TRUE(adapter_->IsDiscovering()); 1143 EXPECT_TRUE(adapter_->IsDiscovering());
1141 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1144 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1142 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1145 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1143 1146
1144 // Stop discovery via D-Bus. The fake client's reference count will drop but 1147 // Stop discovery via D-Bus. The fake client's reference count will drop but
1145 // the discovery state won't change since our BluetoothAdapter also just 1148 // the discovery state won't change since our BluetoothAdapter also just
1146 // requested it via D-Bus. 1149 // requested it via D-Bus.
1147 fake_bluetooth_adapter_client_->StopDiscovery( 1150 fake_bluetooth_adapter_client_->StopDiscovery(
1148 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 1151 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
1149 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, 1152 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
1150 base::Unretained(this))); 1153 base::Unretained(this)));
1151 message_loop_.Run(); 1154 base::RunLoop().Run();
1152 EXPECT_EQ(5, observer.discovering_changed_count()); 1155 EXPECT_EQ(5, observer.discovering_changed_count());
1153 EXPECT_EQ(10, callback_count_); 1156 EXPECT_EQ(10, callback_count_);
1154 EXPECT_EQ(0, error_callback_count_); 1157 EXPECT_EQ(0, error_callback_count_);
1155 EXPECT_TRUE(observer.last_discovering()); 1158 EXPECT_TRUE(observer.last_discovering());
1156 EXPECT_TRUE(adapter_->IsDiscovering()); 1159 EXPECT_TRUE(adapter_->IsDiscovering());
1157 1160
1158 // Now end the discovery session. This should change the adapter's discovery 1161 // Now end the discovery session. This should change the adapter's discovery
1159 // state. 1162 // state.
1160 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 1163 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
1161 message_loop_.Run(); 1164 base::RunLoop().Run();
1162 EXPECT_EQ(6, observer.discovering_changed_count()); 1165 EXPECT_EQ(6, observer.discovering_changed_count());
1163 EXPECT_EQ(11, callback_count_); 1166 EXPECT_EQ(11, callback_count_);
1164 EXPECT_EQ(0, error_callback_count_); 1167 EXPECT_EQ(0, error_callback_count_);
1165 EXPECT_FALSE(observer.last_discovering()); 1168 EXPECT_FALSE(observer.last_discovering());
1166 EXPECT_FALSE(adapter_->IsDiscovering()); 1169 EXPECT_FALSE(adapter_->IsDiscovering());
1167 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 1170 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
1168 } 1171 }
1169 1172
1170 TEST_F(BluetoothBlueZTest, InvalidatedDiscoverySessions) { 1173 TEST_F(BluetoothBlueZTest, InvalidatedDiscoverySessions) {
1171 GetAdapter(); 1174 GetAdapter();
(...skipping 10 matching lines...) Expand all
1182 EXPECT_FALSE(adapter_->IsDiscovering()); 1185 EXPECT_FALSE(adapter_->IsDiscovering());
1183 1186
1184 // Request device discovery 3 times. 1187 // Request device discovery 3 times.
1185 for (int i = 0; i < 3; i++) { 1188 for (int i = 0; i < 3; i++) {
1186 adapter_->StartDiscoverySession( 1189 adapter_->StartDiscoverySession(
1187 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1190 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1188 base::Unretained(this)), 1191 base::Unretained(this)),
1189 GetErrorCallback()); 1192 GetErrorCallback());
1190 } 1193 }
1191 // Run only once, as there should have been one D-Bus call. 1194 // Run only once, as there should have been one D-Bus call.
1192 message_loop_.Run(); 1195 base::RunLoop().Run();
1193 1196
1194 // The observer should have received the discovering changed event exactly 1197 // The observer should have received the discovering changed event exactly
1195 // once, the success callback should have been called 3 times and the adapter 1198 // once, the success callback should have been called 3 times and the adapter
1196 // should be discovering. 1199 // should be discovering.
1197 EXPECT_EQ(1, observer.discovering_changed_count()); 1200 EXPECT_EQ(1, observer.discovering_changed_count());
1198 EXPECT_EQ(3, callback_count_); 1201 EXPECT_EQ(3, callback_count_);
1199 EXPECT_EQ(0, error_callback_count_); 1202 EXPECT_EQ(0, error_callback_count_);
1200 EXPECT_TRUE(observer.last_discovering()); 1203 EXPECT_TRUE(observer.last_discovering());
1201 EXPECT_TRUE(adapter_->IsDiscovering()); 1204 EXPECT_TRUE(adapter_->IsDiscovering());
1202 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1205 ASSERT_EQ((size_t)3, discovery_sessions_.size());
(...skipping 16 matching lines...) Expand all
1219 EXPECT_TRUE(adapter_->IsDiscovering()); 1222 EXPECT_TRUE(adapter_->IsDiscovering());
1220 1223
1221 // Stop device discovery behind the adapter. The one active discovery session 1224 // Stop device discovery behind the adapter. The one active discovery session
1222 // should become inactive, but more importantly, we shouldn't run into any 1225 // should become inactive, but more importantly, we shouldn't run into any
1223 // memory errors as the sessions that we explicitly deleted should get 1226 // memory errors as the sessions that we explicitly deleted should get
1224 // cleaned up. 1227 // cleaned up.
1225 fake_bluetooth_adapter_client_->StopDiscovery( 1228 fake_bluetooth_adapter_client_->StopDiscovery(
1226 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 1229 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
1227 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, 1230 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
1228 base::Unretained(this))); 1231 base::Unretained(this)));
1229 message_loop_.Run(); 1232 base::RunLoop().Run();
1230 EXPECT_EQ(2, observer.discovering_changed_count()); 1233 EXPECT_EQ(2, observer.discovering_changed_count());
1231 EXPECT_EQ(4, callback_count_); 1234 EXPECT_EQ(4, callback_count_);
1232 EXPECT_EQ(0, error_callback_count_); 1235 EXPECT_EQ(0, error_callback_count_);
1233 EXPECT_FALSE(observer.last_discovering()); 1236 EXPECT_FALSE(observer.last_discovering());
1234 EXPECT_FALSE(adapter_->IsDiscovering()); 1237 EXPECT_FALSE(adapter_->IsDiscovering());
1235 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 1238 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
1236 } 1239 }
1237 1240
1238 TEST_F(BluetoothBlueZTest, QueuedDiscoveryRequests) { 1241 TEST_F(BluetoothBlueZTest, QueuedDiscoveryRequests) {
1239 GetAdapter(); 1242 GetAdapter();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 } 1280 }
1278 EXPECT_EQ(0, callback_count_); 1281 EXPECT_EQ(0, callback_count_);
1279 EXPECT_EQ(0, error_callback_count_); 1282 EXPECT_EQ(0, error_callback_count_);
1280 EXPECT_EQ(1, observer.discovering_changed_count()); 1283 EXPECT_EQ(1, observer.discovering_changed_count());
1281 EXPECT_TRUE(observer.last_discovering()); 1284 EXPECT_TRUE(observer.last_discovering());
1282 EXPECT_TRUE(adapter_->IsDiscovering()); 1285 EXPECT_TRUE(adapter_->IsDiscovering());
1283 EXPECT_TRUE(discovery_sessions_.empty()); 1286 EXPECT_TRUE(discovery_sessions_.empty());
1284 1287
1285 // Process the pending call. The queued calls should execute and the discovery 1288 // Process the pending call. The queued calls should execute and the discovery
1286 // session reference count should increase. 1289 // session reference count should increase.
1287 message_loop_.Run(); 1290 base::RunLoop().Run();
1288 EXPECT_EQ(3, callback_count_); 1291 EXPECT_EQ(3, callback_count_);
1289 EXPECT_EQ(0, error_callback_count_); 1292 EXPECT_EQ(0, error_callback_count_);
1290 EXPECT_EQ(1, observer.discovering_changed_count()); 1293 EXPECT_EQ(1, observer.discovering_changed_count());
1291 EXPECT_TRUE(observer.last_discovering()); 1294 EXPECT_TRUE(observer.last_discovering());
1292 EXPECT_TRUE(adapter_->IsDiscovering()); 1295 EXPECT_TRUE(adapter_->IsDiscovering());
1293 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1296 ASSERT_EQ((size_t)3, discovery_sessions_.size());
1294 1297
1295 // Verify the reference count by removing sessions 3 times. The last request 1298 // Verify the reference count by removing sessions 3 times. The last request
1296 // should remain pending. 1299 // should remain pending.
1297 for (int i = 0; i < 3; i++) { 1300 for (int i = 0; i < 3; i++) {
(...skipping 23 matching lines...) Expand all
1321 base::Unretained(this)), 1324 base::Unretained(this)),
1322 GetErrorCallback()); 1325 GetErrorCallback());
1323 EXPECT_EQ(5, callback_count_); 1326 EXPECT_EQ(5, callback_count_);
1324 EXPECT_EQ(1, error_callback_count_); 1327 EXPECT_EQ(1, error_callback_count_);
1325 EXPECT_EQ(2, observer.discovering_changed_count()); 1328 EXPECT_EQ(2, observer.discovering_changed_count());
1326 EXPECT_FALSE(observer.last_discovering()); 1329 EXPECT_FALSE(observer.last_discovering());
1327 EXPECT_FALSE(adapter_->IsDiscovering()); 1330 EXPECT_FALSE(adapter_->IsDiscovering());
1328 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1331 ASSERT_EQ((size_t)3, discovery_sessions_.size());
1329 1332
1330 // Run the pending request. 1333 // Run the pending request.
1331 message_loop_.Run(); 1334 base::RunLoop().Run();
1332 EXPECT_EQ(6, callback_count_); 1335 EXPECT_EQ(6, callback_count_);
1333 EXPECT_EQ(1, error_callback_count_); 1336 EXPECT_EQ(1, error_callback_count_);
1334 EXPECT_EQ(3, observer.discovering_changed_count()); 1337 EXPECT_EQ(3, observer.discovering_changed_count());
1335 EXPECT_TRUE(observer.last_discovering()); 1338 EXPECT_TRUE(observer.last_discovering());
1336 EXPECT_TRUE(adapter_->IsDiscovering()); 1339 EXPECT_TRUE(adapter_->IsDiscovering());
1337 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1340 ASSERT_EQ((size_t)3, discovery_sessions_.size());
1338 EXPECT_FALSE(discovery_sessions_[2]->IsActive()); 1341 EXPECT_FALSE(discovery_sessions_[2]->IsActive());
1339 1342
1340 // The queued request to start discovery should have been issued but is still 1343 // The queued request to start discovery should have been issued but is still
1341 // pending. Run the loop and verify. 1344 // pending. Run the loop and verify.
1342 message_loop_.Run(); 1345 base::RunLoop().Run();
1343 EXPECT_EQ(7, callback_count_); 1346 EXPECT_EQ(7, callback_count_);
1344 EXPECT_EQ(1, error_callback_count_); 1347 EXPECT_EQ(1, error_callback_count_);
1345 EXPECT_EQ(3, observer.discovering_changed_count()); 1348 EXPECT_EQ(3, observer.discovering_changed_count());
1346 EXPECT_TRUE(observer.last_discovering()); 1349 EXPECT_TRUE(observer.last_discovering());
1347 EXPECT_TRUE(adapter_->IsDiscovering()); 1350 EXPECT_TRUE(adapter_->IsDiscovering());
1348 ASSERT_EQ((size_t)4, discovery_sessions_.size()); 1351 ASSERT_EQ((size_t)4, discovery_sessions_.size());
1349 EXPECT_TRUE(discovery_sessions_[3]->IsActive()); 1352 EXPECT_TRUE(discovery_sessions_[3]->IsActive());
1350 } 1353 }
1351 1354
1352 TEST_F(BluetoothBlueZTest, StartDiscoverySession) { 1355 TEST_F(BluetoothBlueZTest, StartDiscoverySession) {
(...skipping 10 matching lines...) Expand all
1363 EXPECT_EQ(0, observer.discovering_changed_count()); 1366 EXPECT_EQ(0, observer.discovering_changed_count());
1364 EXPECT_FALSE(observer.last_discovering()); 1367 EXPECT_FALSE(observer.last_discovering());
1365 EXPECT_FALSE(adapter_->IsDiscovering()); 1368 EXPECT_FALSE(adapter_->IsDiscovering());
1366 EXPECT_TRUE(discovery_sessions_.empty()); 1369 EXPECT_TRUE(discovery_sessions_.empty());
1367 1370
1368 // Request a new discovery session. 1371 // Request a new discovery session.
1369 adapter_->StartDiscoverySession( 1372 adapter_->StartDiscoverySession(
1370 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1373 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1371 base::Unretained(this)), 1374 base::Unretained(this)),
1372 GetErrorCallback()); 1375 GetErrorCallback());
1373 message_loop_.Run(); 1376 base::RunLoop().Run();
1374 EXPECT_EQ(1, observer.discovering_changed_count()); 1377 EXPECT_EQ(1, observer.discovering_changed_count());
1375 EXPECT_EQ(1, callback_count_); 1378 EXPECT_EQ(1, callback_count_);
1376 EXPECT_EQ(0, error_callback_count_); 1379 EXPECT_EQ(0, error_callback_count_);
1377 EXPECT_TRUE(observer.last_discovering()); 1380 EXPECT_TRUE(observer.last_discovering());
1378 EXPECT_TRUE(adapter_->IsDiscovering()); 1381 EXPECT_TRUE(adapter_->IsDiscovering());
1379 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1382 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1380 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1383 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1381 1384
1382 // Start another session. A new one should be returned in the callback, which 1385 // Start another session. A new one should be returned in the callback, which
1383 // in turn will destroy the previous session. Adapter should still be 1386 // in turn will destroy the previous session. Adapter should still be
1384 // discovering and the reference count should be 1. 1387 // discovering and the reference count should be 1.
1385 adapter_->StartDiscoverySession( 1388 adapter_->StartDiscoverySession(
1386 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1389 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1387 base::Unretained(this)), 1390 base::Unretained(this)),
1388 GetErrorCallback()); 1391 GetErrorCallback());
1389 message_loop_.Run(); 1392 base::RunLoop().Run();
1390 EXPECT_EQ(1, observer.discovering_changed_count()); 1393 EXPECT_EQ(1, observer.discovering_changed_count());
1391 EXPECT_EQ(2, callback_count_); 1394 EXPECT_EQ(2, callback_count_);
1392 EXPECT_EQ(0, error_callback_count_); 1395 EXPECT_EQ(0, error_callback_count_);
1393 EXPECT_TRUE(observer.last_discovering()); 1396 EXPECT_TRUE(observer.last_discovering());
1394 EXPECT_TRUE(adapter_->IsDiscovering()); 1397 EXPECT_TRUE(adapter_->IsDiscovering());
1395 ASSERT_EQ((size_t)2, discovery_sessions_.size()); 1398 ASSERT_EQ((size_t)2, discovery_sessions_.size());
1396 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1399 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1397 1400
1398 // Request a new session. 1401 // Request a new session.
1399 adapter_->StartDiscoverySession( 1402 adapter_->StartDiscoverySession(
1400 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1403 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1401 base::Unretained(this)), 1404 base::Unretained(this)),
1402 GetErrorCallback()); 1405 GetErrorCallback());
1403 message_loop_.Run(); 1406 base::RunLoop().Run();
1404 EXPECT_EQ(1, observer.discovering_changed_count()); 1407 EXPECT_EQ(1, observer.discovering_changed_count());
1405 EXPECT_EQ(3, callback_count_); 1408 EXPECT_EQ(3, callback_count_);
1406 EXPECT_EQ(0, error_callback_count_); 1409 EXPECT_EQ(0, error_callback_count_);
1407 EXPECT_TRUE(observer.last_discovering()); 1410 EXPECT_TRUE(observer.last_discovering());
1408 EXPECT_TRUE(adapter_->IsDiscovering()); 1411 EXPECT_TRUE(adapter_->IsDiscovering());
1409 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1412 ASSERT_EQ((size_t)3, discovery_sessions_.size());
1410 EXPECT_TRUE(discovery_sessions_[1]->IsActive()); 1413 EXPECT_TRUE(discovery_sessions_[1]->IsActive());
1411 EXPECT_NE(discovery_sessions_[0], discovery_sessions_[1]); 1414 EXPECT_NE(discovery_sessions_[0], discovery_sessions_[1]);
1412 1415
1413 // Stop the previous discovery session. The session should end but discovery 1416 // Stop the previous discovery session. The session should end but discovery
1414 // should continue. 1417 // should continue.
1415 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 1418 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
1416 message_loop_.Run(); 1419 base::RunLoop().Run();
1417 EXPECT_EQ(1, observer.discovering_changed_count()); 1420 EXPECT_EQ(1, observer.discovering_changed_count());
1418 EXPECT_EQ(4, callback_count_); 1421 EXPECT_EQ(4, callback_count_);
1419 EXPECT_EQ(0, error_callback_count_); 1422 EXPECT_EQ(0, error_callback_count_);
1420 EXPECT_TRUE(observer.last_discovering()); 1423 EXPECT_TRUE(observer.last_discovering());
1421 EXPECT_TRUE(adapter_->IsDiscovering()); 1424 EXPECT_TRUE(adapter_->IsDiscovering());
1422 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1425 ASSERT_EQ((size_t)3, discovery_sessions_.size());
1423 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 1426 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
1424 EXPECT_TRUE(discovery_sessions_[1]->IsActive()); 1427 EXPECT_TRUE(discovery_sessions_[1]->IsActive());
1425 1428
1426 // Delete the current active session. Discovery should eventually stop. 1429 // Delete the current active session. Discovery should eventually stop.
1427 discovery_sessions_.clear(); 1430 discovery_sessions_.clear();
1428 while (observer.last_discovering()) 1431 while (observer.last_discovering())
1429 message_loop_.RunUntilIdle(); 1432 base::RunLoop().RunUntilIdle();
1430 1433
1431 EXPECT_EQ(2, observer.discovering_changed_count()); 1434 EXPECT_EQ(2, observer.discovering_changed_count());
1432 EXPECT_EQ(4, callback_count_); 1435 EXPECT_EQ(4, callback_count_);
1433 EXPECT_EQ(0, error_callback_count_); 1436 EXPECT_EQ(0, error_callback_count_);
1434 EXPECT_FALSE(observer.last_discovering()); 1437 EXPECT_FALSE(observer.last_discovering());
1435 EXPECT_FALSE(adapter_->IsDiscovering()); 1438 EXPECT_FALSE(adapter_->IsDiscovering());
1436 } 1439 }
1437 1440
1438 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscovery) { 1441 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscovery) {
1439 // Test a simulated discovery session. 1442 // Test a simulated discovery session.
1440 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1443 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1441 GetAdapter(); 1444 GetAdapter();
1442 1445
1443 TestBluetoothAdapterObserver observer(adapter_); 1446 TestBluetoothAdapterObserver observer(adapter_);
1444 1447
1445 BluetoothDiscoveryFilter* df = 1448 BluetoothDiscoveryFilter* df =
1446 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); 1449 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE);
1447 df->SetRSSI(-60); 1450 df->SetRSSI(-60);
1448 df->AddUUID(BluetoothUUID("1000")); 1451 df->AddUUID(BluetoothUUID("1000"));
1449 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1452 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1450 1453
1451 adapter_->SetPowered( 1454 adapter_->SetPowered(
1452 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1455 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1453 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1456 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1454 adapter_->StartDiscoverySessionWithFilter( 1457 adapter_->StartDiscoverySessionWithFilter(
1455 std::move(discovery_filter), 1458 std::move(discovery_filter),
1456 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1459 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1457 base::Unretained(this)), 1460 base::Unretained(this)),
1458 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1461 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1459 message_loop_.Run(); 1462 base::RunLoop().Run();
1460 EXPECT_EQ(2, callback_count_); 1463 EXPECT_EQ(2, callback_count_);
1461 EXPECT_EQ(0, error_callback_count_); 1464 EXPECT_EQ(0, error_callback_count_);
1462 callback_count_ = 0; 1465 callback_count_ = 0;
1463 1466
1464 ASSERT_TRUE(adapter_->IsPowered()); 1467 ASSERT_TRUE(adapter_->IsPowered());
1465 ASSERT_TRUE(adapter_->IsDiscovering()); 1468 ASSERT_TRUE(adapter_->IsDiscovering());
1466 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1469 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1467 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 1470 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
1468 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); 1471 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter()));
1469 1472
1470 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1473 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1471 EXPECT_NE(nullptr, filter); 1474 EXPECT_NE(nullptr, filter);
1472 EXPECT_EQ("le", *filter->transport); 1475 EXPECT_EQ("le", *filter->transport);
1473 EXPECT_EQ(-60, *filter->rssi); 1476 EXPECT_EQ(-60, *filter->rssi);
1474 EXPECT_EQ(nullptr, filter->pathloss.get()); 1477 EXPECT_EQ(nullptr, filter->pathloss.get());
1475 std::vector<std::string> uuids = *filter->uuids; 1478 std::vector<std::string> uuids = *filter->uuids;
1476 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 1479 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
1477 1480
1478 discovery_sessions_[0]->Stop( 1481 discovery_sessions_[0]->Stop(
1479 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1482 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1480 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1483 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1481 1484
1482 message_loop_.Run(); 1485 base::RunLoop().Run();
1483 1486
1484 EXPECT_EQ(1, callback_count_); 1487 EXPECT_EQ(1, callback_count_);
1485 EXPECT_EQ(0, error_callback_count_); 1488 EXPECT_EQ(0, error_callback_count_);
1486 1489
1487 ASSERT_TRUE(adapter_->IsPowered()); 1490 ASSERT_TRUE(adapter_->IsPowered());
1488 ASSERT_FALSE(adapter_->IsDiscovering()); 1491 ASSERT_FALSE(adapter_->IsDiscovering());
1489 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1492 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1490 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); 1493 ASSERT_FALSE(discovery_sessions_[0]->IsActive());
1491 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), 1494 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(),
1492 (BluetoothDiscoveryFilter*)nullptr); 1495 (BluetoothDiscoveryFilter*)nullptr);
(...skipping 22 matching lines...) Expand all
1515 callback_count_ = 0; 1518 callback_count_ = 0;
1516 1519
1517 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail(); 1520 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail();
1518 1521
1519 adapter_->StartDiscoverySessionWithFilter( 1522 adapter_->StartDiscoverySessionWithFilter(
1520 std::move(discovery_filter), 1523 std::move(discovery_filter),
1521 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1524 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1522 base::Unretained(this)), 1525 base::Unretained(this)),
1523 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1526 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1524 1527
1525 message_loop_.Run(); 1528 base::RunLoop().Run();
1526 1529
1527 EXPECT_EQ(1, error_callback_count_); 1530 EXPECT_EQ(1, error_callback_count_);
1528 error_callback_count_ = 0; 1531 error_callback_count_ = 0;
1529 1532
1530 ASSERT_TRUE(adapter_->IsPowered()); 1533 ASSERT_TRUE(adapter_->IsPowered());
1531 ASSERT_FALSE(adapter_->IsDiscovering()); 1534 ASSERT_FALSE(adapter_->IsDiscovering());
1532 ASSERT_EQ((size_t)0, discovery_sessions_.size()); 1535 ASSERT_EQ((size_t)0, discovery_sessions_.size());
1533 1536
1534 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1537 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1535 EXPECT_EQ(nullptr, filter); 1538 EXPECT_EQ(nullptr, filter);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1576 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1574 1577
1575 adapter_->StartDiscoverySessionWithFilter( 1578 adapter_->StartDiscoverySessionWithFilter(
1576 std::move(discovery_filter2), 1579 std::move(discovery_filter2),
1577 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1580 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1578 base::Unretained(this)), 1581 base::Unretained(this)),
1579 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1582 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1580 1583
1581 // Run requests, on DBus level there should be call SetDiscoveryFilter, then 1584 // Run requests, on DBus level there should be call SetDiscoveryFilter, then
1582 // StartDiscovery, then SetDiscoveryFilter again. 1585 // StartDiscovery, then SetDiscoveryFilter again.
1583 message_loop_.Run(); 1586 base::RunLoop().Run();
1584 message_loop_.Run(); 1587 base::RunLoop().Run();
1585 1588
1586 EXPECT_EQ(2, callback_count_); 1589 EXPECT_EQ(2, callback_count_);
1587 EXPECT_EQ(0, error_callback_count_); 1590 EXPECT_EQ(0, error_callback_count_);
1588 callback_count_ = 0; 1591 callback_count_ = 0;
1589 1592
1590 ASSERT_TRUE(adapter_->IsPowered()); 1593 ASSERT_TRUE(adapter_->IsPowered());
1591 ASSERT_TRUE(adapter_->IsDiscovering()); 1594 ASSERT_TRUE(adapter_->IsDiscovering());
1592 ASSERT_EQ((size_t)2, discovery_sessions_.size()); 1595 ASSERT_EQ((size_t)2, discovery_sessions_.size());
1593 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 1596 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
1594 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); 1597 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter()));
(...skipping 10 matching lines...) Expand all
1605 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002")); 1608 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002"));
1606 1609
1607 discovery_sessions_[0]->Stop( 1610 discovery_sessions_[0]->Stop(
1608 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1611 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1609 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1612 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1610 1613
1611 discovery_sessions_[1]->Stop( 1614 discovery_sessions_[1]->Stop(
1612 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1615 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1613 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1616 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1614 1617
1615 message_loop_.Run(); 1618 base::RunLoop().Run();
1616 1619
1617 EXPECT_EQ(2, callback_count_); 1620 EXPECT_EQ(2, callback_count_);
1618 EXPECT_EQ(0, error_callback_count_); 1621 EXPECT_EQ(0, error_callback_count_);
1619 1622
1620 ASSERT_TRUE(adapter_->IsPowered()); 1623 ASSERT_TRUE(adapter_->IsPowered());
1621 ASSERT_FALSE(adapter_->IsDiscovering()); 1624 ASSERT_FALSE(adapter_->IsDiscovering());
1622 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); 1625 ASSERT_FALSE(discovery_sessions_[0]->IsActive());
1623 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), 1626 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(),
1624 (BluetoothDiscoveryFilter*)nullptr); 1627 (BluetoothDiscoveryFilter*)nullptr);
1625 ASSERT_FALSE(discovery_sessions_[1]->IsActive()); 1628 ASSERT_FALSE(discovery_sessions_[1]->IsActive());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1671 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1669 base::Unretained(this)), 1672 base::Unretained(this)),
1670 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1673 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1671 1674
1672 adapter_->StartDiscoverySessionWithFilter( 1675 adapter_->StartDiscoverySessionWithFilter(
1673 std::move(discovery_filter2), 1676 std::move(discovery_filter2),
1674 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1677 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1675 base::Unretained(this)), 1678 base::Unretained(this)),
1676 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1679 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1677 1680
1678 message_loop_.Run(); 1681 base::RunLoop().Run();
1679 1682
1680 // First request to SetDiscoveryFilter should fail, resulting in no session 1683 // First request to SetDiscoveryFilter should fail, resulting in no session
1681 // being created. 1684 // being created.
1682 EXPECT_EQ(0, callback_count_); 1685 EXPECT_EQ(0, callback_count_);
1683 EXPECT_EQ(1, error_callback_count_); 1686 EXPECT_EQ(1, error_callback_count_);
1684 error_callback_count_ = 0; 1687 error_callback_count_ = 0;
1685 1688
1686 ASSERT_TRUE(adapter_->IsPowered()); 1689 ASSERT_TRUE(adapter_->IsPowered());
1687 ASSERT_FALSE(adapter_->IsDiscovering()); 1690 ASSERT_FALSE(adapter_->IsDiscovering());
1688 ASSERT_EQ((size_t)0, discovery_sessions_.size()); 1691 ASSERT_EQ((size_t)0, discovery_sessions_.size());
1689 1692
1690 message_loop_.Run(); 1693 base::RunLoop().Run();
1691 1694
1692 // Second request should succeed 1695 // Second request should succeed
1693 EXPECT_EQ(1, callback_count_); 1696 EXPECT_EQ(1, callback_count_);
1694 EXPECT_EQ(0, error_callback_count_); 1697 EXPECT_EQ(0, error_callback_count_);
1695 callback_count_ = 0; 1698 callback_count_ = 0;
1696 1699
1697 ASSERT_TRUE(adapter_->IsDiscovering()); 1700 ASSERT_TRUE(adapter_->IsDiscovering());
1698 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1701 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1699 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 1702 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
1700 ASSERT_TRUE(df2->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); 1703 ASSERT_TRUE(df2->Equals(*discovery_sessions_[0]->GetDiscoveryFilter()));
1701 1704
1702 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1705 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1703 EXPECT_NE(nullptr, filter); 1706 EXPECT_NE(nullptr, filter);
1704 EXPECT_EQ("bredr", *filter->transport); 1707 EXPECT_EQ("bredr", *filter->transport);
1705 EXPECT_EQ(-65, *filter->rssi); 1708 EXPECT_EQ(-65, *filter->rssi);
1706 EXPECT_EQ(nullptr, filter->pathloss.get()); 1709 EXPECT_EQ(nullptr, filter->pathloss.get());
1707 auto uuids = *filter->uuids; 1710 auto uuids = *filter->uuids;
1708 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002")); 1711 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002"));
1709 1712
1710 discovery_sessions_[0]->Stop( 1713 discovery_sessions_[0]->Stop(
1711 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1714 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1712 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1715 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1713 1716
1714 message_loop_.Run(); 1717 base::RunLoop().Run();
1715 1718
1716 EXPECT_EQ(1, callback_count_); 1719 EXPECT_EQ(1, callback_count_);
1717 EXPECT_EQ(0, error_callback_count_); 1720 EXPECT_EQ(0, error_callback_count_);
1718 1721
1719 ASSERT_TRUE(adapter_->IsPowered()); 1722 ASSERT_TRUE(adapter_->IsPowered());
1720 ASSERT_FALSE(adapter_->IsDiscovering()); 1723 ASSERT_FALSE(adapter_->IsDiscovering());
1721 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); 1724 ASSERT_FALSE(discovery_sessions_[0]->IsActive());
1722 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), 1725 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(),
1723 (BluetoothDiscoveryFilter*)nullptr); 1726 (BluetoothDiscoveryFilter*)nullptr);
1724 1727
1725 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1728 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1726 EXPECT_EQ(nullptr, filter); 1729 EXPECT_EQ(nullptr, filter);
1727 } 1730 }
1728 1731
1729 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterAfterStartDiscovery) { 1732 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterAfterStartDiscovery) {
1730 // Test a simulated discovery session. 1733 // Test a simulated discovery session.
1731 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1734 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1732 GetAdapter(); 1735 GetAdapter();
1733 1736
1734 TestBluetoothAdapterObserver observer(adapter_); 1737 TestBluetoothAdapterObserver observer(adapter_);
1735 1738
1736 adapter_->SetPowered( 1739 adapter_->SetPowered(
1737 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1740 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1738 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1741 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1739 adapter_->StartDiscoverySession( 1742 adapter_->StartDiscoverySession(
1740 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1743 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1741 base::Unretained(this)), 1744 base::Unretained(this)),
1742 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1745 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1743 message_loop_.Run(); 1746 base::RunLoop().Run();
1744 EXPECT_EQ(2, callback_count_); 1747 EXPECT_EQ(2, callback_count_);
1745 EXPECT_EQ(0, error_callback_count_); 1748 EXPECT_EQ(0, error_callback_count_);
1746 callback_count_ = 0; 1749 callback_count_ = 0;
1747 1750
1748 ASSERT_TRUE(adapter_->IsPowered()); 1751 ASSERT_TRUE(adapter_->IsPowered());
1749 ASSERT_TRUE(adapter_->IsDiscovering()); 1752 ASSERT_TRUE(adapter_->IsDiscovering());
1750 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1753 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1751 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 1754 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
1752 EXPECT_EQ(1, observer.discovering_changed_count()); 1755 EXPECT_EQ(1, observer.discovering_changed_count());
1753 observer.Reset(); 1756 observer.Reset();
1754 1757
1755 auto null_instance = std::unique_ptr<BluetoothDiscoveryFilter>(); 1758 auto null_instance = std::unique_ptr<BluetoothDiscoveryFilter>();
1756 null_instance.reset(); 1759 null_instance.reset();
1757 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), null_instance.get()); 1760 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), null_instance.get());
1758 1761
1759 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1762 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1760 EXPECT_EQ(nullptr, filter); 1763 EXPECT_EQ(nullptr, filter);
1761 1764
1762 BluetoothDiscoveryFilter* df = 1765 BluetoothDiscoveryFilter* df =
1763 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); 1766 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE);
1764 df->SetRSSI(-60); 1767 df->SetRSSI(-60);
1765 df->AddUUID(BluetoothUUID("1000")); 1768 df->AddUUID(BluetoothUUID("1000"));
1766 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1769 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1767 1770
1768 discovery_sessions_[0]->SetDiscoveryFilter( 1771 discovery_sessions_[0]->SetDiscoveryFilter(
1769 std::move(discovery_filter), 1772 std::move(discovery_filter),
1770 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1773 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1771 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1774 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1772 1775
1773 message_loop_.Run(); 1776 base::RunLoop().Run();
1774 EXPECT_EQ(1, callback_count_); 1777 EXPECT_EQ(1, callback_count_);
1775 EXPECT_EQ(0, error_callback_count_); 1778 EXPECT_EQ(0, error_callback_count_);
1776 callback_count_ = 0; 1779 callback_count_ = 0;
1777 1780
1778 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); 1781 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter()));
1779 1782
1780 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1783 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1781 EXPECT_NE(nullptr, filter); 1784 EXPECT_NE(nullptr, filter);
1782 EXPECT_EQ("le", *filter->transport); 1785 EXPECT_EQ("le", *filter->transport);
1783 EXPECT_EQ(-60, *filter->rssi); 1786 EXPECT_EQ(-60, *filter->rssi);
1784 EXPECT_EQ(nullptr, filter->pathloss.get()); 1787 EXPECT_EQ(nullptr, filter->pathloss.get());
1785 std::vector<std::string> uuids = *filter->uuids; 1788 std::vector<std::string> uuids = *filter->uuids;
1786 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 1789 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
1787 1790
1788 discovery_sessions_[0]->Stop( 1791 discovery_sessions_[0]->Stop(
1789 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1792 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1790 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1793 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1791 1794
1792 message_loop_.Run(); 1795 base::RunLoop().Run();
1793 1796
1794 EXPECT_EQ(1, callback_count_); 1797 EXPECT_EQ(1, callback_count_);
1795 EXPECT_EQ(0, error_callback_count_); 1798 EXPECT_EQ(0, error_callback_count_);
1796 1799
1797 ASSERT_TRUE(adapter_->IsPowered()); 1800 ASSERT_TRUE(adapter_->IsPowered());
1798 ASSERT_FALSE(adapter_->IsDiscovering()); 1801 ASSERT_FALSE(adapter_->IsDiscovering());
1799 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1802 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1800 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); 1803 ASSERT_FALSE(discovery_sessions_[0]->IsActive());
1801 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), 1804 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(),
1802 (BluetoothDiscoveryFilter*)nullptr); 1805 (BluetoothDiscoveryFilter*)nullptr);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 df->AddUUID(BluetoothUUID("1003")); 1846 df->AddUUID(BluetoothUUID("1003"));
1844 discovery_filter.reset(df); 1847 discovery_filter.reset(df);
1845 } 1848 }
1846 1849
1847 adapter_->StartDiscoverySessionWithFilter( 1850 adapter_->StartDiscoverySessionWithFilter(
1848 std::move(discovery_filter), 1851 std::move(discovery_filter),
1849 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1852 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1850 base::Unretained(this)), 1853 base::Unretained(this)),
1851 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1854 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1852 1855
1853 message_loop_.Run(); 1856 base::RunLoop().Run();
1854 1857
1855 if (i == 0) { 1858 if (i == 0) {
1856 EXPECT_EQ(1, observer.discovering_changed_count()); 1859 EXPECT_EQ(1, observer.discovering_changed_count());
1857 observer.Reset(); 1860 observer.Reset();
1858 1861
1859 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1862 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1860 EXPECT_EQ("le", *filter->transport); 1863 EXPECT_EQ("le", *filter->transport);
1861 EXPECT_EQ(-85, *filter->rssi); 1864 EXPECT_EQ(-85, *filter->rssi);
1862 EXPECT_EQ(nullptr, filter->pathloss.get()); 1865 EXPECT_EQ(nullptr, filter->pathloss.get());
1863 std::vector<std::string> uuids = *filter->uuids; 1866 std::vector<std::string> uuids = *filter->uuids;
(...skipping 26 matching lines...) Expand all
1890 EXPECT_EQ(0, error_callback_count_); 1893 EXPECT_EQ(0, error_callback_count_);
1891 EXPECT_TRUE(adapter_->IsDiscovering()); 1894 EXPECT_TRUE(adapter_->IsDiscovering());
1892 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1895 ASSERT_EQ((size_t)3, discovery_sessions_.size());
1893 1896
1894 callback_count_ = 0; 1897 callback_count_ = 0;
1895 // Request to stop discovery twice. 1898 // Request to stop discovery twice.
1896 for (int i = 0; i < 2; i++) { 1899 for (int i = 0; i < 2; i++) {
1897 discovery_sessions_[i]->Stop( 1900 discovery_sessions_[i]->Stop(
1898 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 1901 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1899 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1902 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1900 message_loop_.Run(); 1903 base::RunLoop().Run();
1901 1904
1902 if (i == 0) { 1905 if (i == 0) {
1903 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1906 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1904 EXPECT_EQ("le", *filter->transport); 1907 EXPECT_EQ("le", *filter->transport);
1905 EXPECT_EQ(-65, *filter->rssi); 1908 EXPECT_EQ(-65, *filter->rssi);
1906 EXPECT_EQ(nullptr, filter->pathloss.get()); 1909 EXPECT_EQ(nullptr, filter->pathloss.get());
1907 std::vector<std::string> uuids = *filter->uuids; 1910 std::vector<std::string> uuids = *filter->uuids;
1908 EXPECT_EQ(3UL, uuids.size()); 1911 EXPECT_EQ(3UL, uuids.size());
1909 EXPECT_EQ(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 1912 EXPECT_EQ(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
1910 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); 1913 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001"));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1968 discovery_filter.reset(df); 1971 discovery_filter.reset(df);
1969 } 1972 }
1970 1973
1971 adapter_->StartDiscoverySessionWithFilter( 1974 adapter_->StartDiscoverySessionWithFilter(
1972 std::move(discovery_filter), 1975 std::move(discovery_filter),
1973 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 1976 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1974 base::Unretained(this)), 1977 base::Unretained(this)),
1975 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 1978 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1976 1979
1977 // each result in 1 requests. 1980 // each result in 1 requests.
1978 message_loop_.Run(); 1981 base::RunLoop().Run();
1979 1982
1980 if (i == 0) { 1983 if (i == 0) {
1981 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1984 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1982 EXPECT_EQ("le", *filter->transport); 1985 EXPECT_EQ("le", *filter->transport);
1983 EXPECT_EQ(-85, *filter->rssi); 1986 EXPECT_EQ(-85, *filter->rssi);
1984 EXPECT_EQ(nullptr, filter->pathloss.get()); 1987 EXPECT_EQ(nullptr, filter->pathloss.get());
1985 std::vector<std::string> uuids = *filter->uuids; 1988 std::vector<std::string> uuids = *filter->uuids;
1986 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 1989 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
1987 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1003")); 1990 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1003"));
1988 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); 1991 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020"));
(...skipping 20 matching lines...) Expand all
2009 callback_count_ = 0; 2012 callback_count_ = 0;
2010 // Request to stop discovery 4 times. 2013 // Request to stop discovery 4 times.
2011 for (int i = 2; i < 6; i++) { 2014 for (int i = 2; i < 6; i++) {
2012 discovery_sessions_[i]->Stop( 2015 discovery_sessions_[i]->Stop(
2013 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 2016 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
2014 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 2017 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2015 2018
2016 // filter no 2 is same as filter no 5, so removing it shouldn't cause any 2019 // filter no 2 is same as filter no 5, so removing it shouldn't cause any
2017 // filter update 2020 // filter update
2018 if (i != 2 && i != 5) 2021 if (i != 2 && i != 5)
2019 message_loop_.Run(); 2022 base::RunLoop().Run();
2020 } 2023 }
2021 // Run only once, as there should have been one D-Bus call. 2024 // Run only once, as there should have been one D-Bus call.
2022 message_loop_.Run(); 2025 base::RunLoop().Run();
2023 2026
2024 // The success callback should have been called 4 times and the adapter should 2027 // The success callback should have been called 4 times and the adapter should
2025 // no longer be discovering. 2028 // no longer be discovering.
2026 EXPECT_EQ(4, callback_count_); 2029 EXPECT_EQ(4, callback_count_);
2027 EXPECT_EQ(0, error_callback_count_); 2030 EXPECT_EQ(0, error_callback_count_);
2028 EXPECT_FALSE(adapter_->IsDiscovering()); 2031 EXPECT_FALSE(adapter_->IsDiscovering());
2029 EXPECT_EQ(1, observer.discovering_changed_count()); 2032 EXPECT_EQ(1, observer.discovering_changed_count());
2030 2033
2031 // All discovery sessions should be inactive. 2034 // All discovery sessions should be inactive.
2032 for (int i = 0; i < 6; i++) 2035 for (int i = 0; i < 6; i++)
(...skipping 16 matching lines...) Expand all
2049 df->SetRSSI(-15); 2052 df->SetRSSI(-15);
2050 df->AddUUID(BluetoothUUID("1000")); 2053 df->AddUUID(BluetoothUUID("1000"));
2051 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 2054 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
2052 2055
2053 adapter_->StartDiscoverySessionWithFilter( 2056 adapter_->StartDiscoverySessionWithFilter(
2054 std::move(discovery_filter), 2057 std::move(discovery_filter),
2055 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 2058 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2056 base::Unretained(this)), 2059 base::Unretained(this)),
2057 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 2060 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2058 2061
2059 message_loop_.Run(); 2062 base::RunLoop().Run();
2060 2063
2061 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 2064 auto* filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2062 EXPECT_EQ("le", *filter->transport); 2065 EXPECT_EQ("le", *filter->transport);
2063 EXPECT_EQ(-15, *filter->rssi); 2066 EXPECT_EQ(-15, *filter->rssi);
2064 EXPECT_EQ(nullptr, filter->pathloss.get()); 2067 EXPECT_EQ(nullptr, filter->pathloss.get());
2065 std::vector<std::string> uuids = *filter->uuids; 2068 std::vector<std::string> uuids = *filter->uuids;
2066 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 2069 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
2067 2070
2068 df = new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE); 2071 df = new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE);
2069 df->SetRSSI(-60); 2072 df->SetRSSI(-60);
2070 df->AddUUID(BluetoothUUID("1020")); 2073 df->AddUUID(BluetoothUUID("1020"));
2071 df->AddUUID(BluetoothUUID("1001")); 2074 df->AddUUID(BluetoothUUID("1001"));
2072 discovery_filter = std::unique_ptr<BluetoothDiscoveryFilter>(df); 2075 discovery_filter = std::unique_ptr<BluetoothDiscoveryFilter>(df);
2073 2076
2074 adapter_->StartDiscoverySessionWithFilter( 2077 adapter_->StartDiscoverySessionWithFilter(
2075 std::move(discovery_filter), 2078 std::move(discovery_filter),
2076 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 2079 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2077 base::Unretained(this)), 2080 base::Unretained(this)),
2078 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 2081 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2079 2082
2080 message_loop_.Run(); 2083 base::RunLoop().Run();
2081 2084
2082 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 2085 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2083 EXPECT_EQ("le", *filter->transport); 2086 EXPECT_EQ("le", *filter->transport);
2084 EXPECT_EQ(-60, *filter->rssi); 2087 EXPECT_EQ(-60, *filter->rssi);
2085 EXPECT_EQ(nullptr, filter->pathloss.get()); 2088 EXPECT_EQ(nullptr, filter->pathloss.get());
2086 uuids = *filter->uuids; 2089 uuids = *filter->uuids;
2087 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 2090 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
2088 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); 2091 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001"));
2089 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); 2092 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020"));
2090 2093
2091 BluetoothDiscoveryFilter* df3 = 2094 BluetoothDiscoveryFilter* df3 =
2092 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_CLASSIC); 2095 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_CLASSIC);
2093 df3->SetRSSI(-65); 2096 df3->SetRSSI(-65);
2094 df3->AddUUID(BluetoothUUID("1020")); 2097 df3->AddUUID(BluetoothUUID("1020"));
2095 df3->AddUUID(BluetoothUUID("1003")); 2098 df3->AddUUID(BluetoothUUID("1003"));
2096 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3); 2099 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3);
2097 2100
2098 adapter_->StartDiscoverySessionWithFilter( 2101 adapter_->StartDiscoverySessionWithFilter(
2099 std::move(discovery_filter3), 2102 std::move(discovery_filter3),
2100 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 2103 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2101 base::Unretained(this)), 2104 base::Unretained(this)),
2102 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 2105 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2103 2106
2104 message_loop_.Run(); 2107 base::RunLoop().Run();
2105 2108
2106 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 2109 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2107 EXPECT_EQ("auto", *filter->transport); 2110 EXPECT_EQ("auto", *filter->transport);
2108 EXPECT_EQ(-65, *filter->rssi); 2111 EXPECT_EQ(-65, *filter->rssi);
2109 EXPECT_EQ(nullptr, filter->pathloss.get()); 2112 EXPECT_EQ(nullptr, filter->pathloss.get());
2110 uuids = *filter->uuids; 2113 uuids = *filter->uuids;
2111 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 2114 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
2112 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); 2115 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001"));
2113 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1003")); 2116 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1003"));
2114 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); 2117 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020"));
2115 2118
2116 // start additionally classic scan 2119 // start additionally classic scan
2117 adapter_->StartDiscoverySession( 2120 adapter_->StartDiscoverySession(
2118 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 2121 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2119 base::Unretained(this)), 2122 base::Unretained(this)),
2120 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 2123 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2121 2124
2122 message_loop_.Run(); 2125 base::RunLoop().Run();
2123 2126
2124 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 2127 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2125 EXPECT_EQ("auto", *filter->transport); 2128 EXPECT_EQ("auto", *filter->transport);
2126 EXPECT_EQ(nullptr, filter->rssi.get()); 2129 EXPECT_EQ(nullptr, filter->rssi.get());
2127 EXPECT_EQ(nullptr, filter->pathloss.get()); 2130 EXPECT_EQ(nullptr, filter->pathloss.get());
2128 EXPECT_EQ(nullptr, filter->uuids.get()); 2131 EXPECT_EQ(nullptr, filter->uuids.get());
2129 2132
2130 // Request to stop discovery 4 times. 2133 // Request to stop discovery 4 times.
2131 for (int i = 3; i >= 0; i--) { 2134 for (int i = 3; i >= 0; i--) {
2132 discovery_sessions_[i]->Stop( 2135 discovery_sessions_[i]->Stop(
2133 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)), 2136 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
2134 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this))); 2137 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2135 2138
2136 // Every session stopping would trigger filter update 2139 // Every session stopping would trigger filter update
2137 message_loop_.Run(); 2140 base::RunLoop().Run();
2138 } 2141 }
2139 } 2142 }
2140 2143
2141 TEST_F(BluetoothBlueZTest, DeviceProperties) { 2144 TEST_F(BluetoothBlueZTest, DeviceProperties) {
2142 GetAdapter(); 2145 GetAdapter();
2143 2146
2144 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2147 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2145 ASSERT_EQ(2U, devices.size()); 2148 ASSERT_EQ(2U, devices.size());
2146 2149
2147 int idx = GetDeviceIndexByAddress( 2150 int idx = GetDeviceIndexByAddress(
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
2838 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); 2841 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
2839 device->Pair(&pairing_delegate, GetCallback(), 2842 device->Pair(&pairing_delegate, GetCallback(),
2840 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 2843 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2841 base::Unretained(this))); 2844 base::Unretained(this)));
2842 EXPECT_EQ(1, pairing_delegate.call_count_); 2845 EXPECT_EQ(1, pairing_delegate.call_count_);
2843 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 2846 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
2844 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); 2847 EXPECT_EQ(123456U, pairing_delegate.last_passkey_);
2845 2848
2846 // Confirm the passkey. 2849 // Confirm the passkey.
2847 device->ConfirmPairing(); 2850 device->ConfirmPairing();
2848 message_loop_.Run(); 2851 base::RunLoop().Run();
2849 EXPECT_EQ(1, callback_count_); 2852 EXPECT_EQ(1, callback_count_);
2850 EXPECT_EQ(0, error_callback_count_); 2853 EXPECT_EQ(0, error_callback_count_);
2851 2854
2852 // Make sure the paired property has been set to true. 2855 // Make sure the paired property has been set to true.
2853 properties = fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2856 properties = fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2854 bluez::FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDevicePath)); 2857 bluez::FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDevicePath));
2855 EXPECT_TRUE(properties->paired.value()); 2858 EXPECT_TRUE(properties->paired.value());
2856 } 2859 }
2857 2860
2858 TEST_F(BluetoothBlueZTest, PairAlreadyPairedDevice) { 2861 TEST_F(BluetoothBlueZTest, PairAlreadyPairedDevice) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2904 TestBluetoothAdapterObserver observer(adapter_); 2907 TestBluetoothAdapterObserver observer(adapter_);
2905 2908
2906 TestPairingDelegate pairing_delegate; 2909 TestPairingDelegate pairing_delegate;
2907 device->Connect(&pairing_delegate, GetCallback(), 2910 device->Connect(&pairing_delegate, GetCallback(),
2908 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 2911 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2909 base::Unretained(this))); 2912 base::Unretained(this)));
2910 2913
2911 EXPECT_EQ(0, pairing_delegate.call_count_); 2914 EXPECT_EQ(0, pairing_delegate.call_count_);
2912 EXPECT_TRUE(device->IsConnecting()); 2915 EXPECT_TRUE(device->IsConnecting());
2913 2916
2914 message_loop_.Run(); 2917 base::RunLoop().Run();
2915 2918
2916 EXPECT_EQ(1, callback_count_); 2919 EXPECT_EQ(1, callback_count_);
2917 EXPECT_EQ(0, error_callback_count_); 2920 EXPECT_EQ(0, error_callback_count_);
2918 2921
2919 // Two changes for connecting, one change for connected, one for paired, 2922 // Two changes for connecting, one change for connected, one for paired,
2920 // two for trusted (after pairing and connection), and one for the reconnect 2923 // two for trusted (after pairing and connection), and one for the reconnect
2921 // mode (IsConnectable). 2924 // mode (IsConnectable).
2922 EXPECT_EQ(7, observer.device_changed_count()); 2925 EXPECT_EQ(7, observer.device_changed_count());
2923 EXPECT_EQ(device, observer.last_device()); 2926 EXPECT_EQ(device, observer.last_device());
2924 2927
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2957 TestPairingDelegate pairing_delegate; 2960 TestPairingDelegate pairing_delegate;
2958 device->Connect(&pairing_delegate, GetCallback(), 2961 device->Connect(&pairing_delegate, GetCallback(),
2959 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 2962 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2960 base::Unretained(this))); 2963 base::Unretained(this)));
2961 2964
2962 EXPECT_EQ(1, pairing_delegate.call_count_); 2965 EXPECT_EQ(1, pairing_delegate.call_count_);
2963 EXPECT_EQ(1, pairing_delegate.display_pincode_count_); 2966 EXPECT_EQ(1, pairing_delegate.display_pincode_count_);
2964 EXPECT_EQ("123456", pairing_delegate.last_pincode_); 2967 EXPECT_EQ("123456", pairing_delegate.last_pincode_);
2965 EXPECT_TRUE(device->IsConnecting()); 2968 EXPECT_TRUE(device->IsConnecting());
2966 2969
2967 message_loop_.Run(); 2970 base::RunLoop().Run();
2968 2971
2969 EXPECT_EQ(1, callback_count_); 2972 EXPECT_EQ(1, callback_count_);
2970 EXPECT_EQ(0, error_callback_count_); 2973 EXPECT_EQ(0, error_callback_count_);
2971 2974
2972 // Two changes for connecting, one change for connected, one for paired, 2975 // Two changes for connecting, one change for connected, one for paired,
2973 // two for trusted (after pairing and connection), and one for the reconnect 2976 // two for trusted (after pairing and connection), and one for the reconnect
2974 // mode (IsConnectable). 2977 // mode (IsConnectable).
2975 EXPECT_EQ(7, observer.device_changed_count()); 2978 EXPECT_EQ(7, observer.device_changed_count());
2976 EXPECT_EQ(device, observer.last_device()); 2979 EXPECT_EQ(device, observer.last_device());
2977 2980
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3017 EXPECT_EQ(2, pairing_delegate.call_count_); 3020 EXPECT_EQ(2, pairing_delegate.call_count_);
3018 EXPECT_EQ(1, pairing_delegate.display_passkey_count_); 3021 EXPECT_EQ(1, pairing_delegate.display_passkey_count_);
3019 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); 3022 EXPECT_EQ(123456U, pairing_delegate.last_passkey_);
3020 EXPECT_EQ(1, pairing_delegate.keys_entered_count_); 3023 EXPECT_EQ(1, pairing_delegate.keys_entered_count_);
3021 EXPECT_EQ(0U, pairing_delegate.last_entered_); 3024 EXPECT_EQ(0U, pairing_delegate.last_entered_);
3022 3025
3023 EXPECT_TRUE(device->IsConnecting()); 3026 EXPECT_TRUE(device->IsConnecting());
3024 3027
3025 // One call to KeysEntered() for each key, including [enter]. 3028 // One call to KeysEntered() for each key, including [enter].
3026 for (int i = 1; i <= 7; ++i) { 3029 for (int i = 1; i <= 7; ++i) {
3027 message_loop_.Run(); 3030 base::RunLoop().Run();
3028 3031
3029 EXPECT_EQ(2 + i, pairing_delegate.call_count_); 3032 EXPECT_EQ(2 + i, pairing_delegate.call_count_);
3030 EXPECT_EQ(1 + i, pairing_delegate.keys_entered_count_); 3033 EXPECT_EQ(1 + i, pairing_delegate.keys_entered_count_);
3031 EXPECT_EQ(static_cast<uint32_t>(i), pairing_delegate.last_entered_); 3034 EXPECT_EQ(static_cast<uint32_t>(i), pairing_delegate.last_entered_);
3032 } 3035 }
3033 3036
3034 message_loop_.Run(); 3037 base::RunLoop().Run();
3035 3038
3036 // 8 KeysEntered notifications (0 to 7, inclusive) and one aditional call for 3039 // 8 KeysEntered notifications (0 to 7, inclusive) and one aditional call for
3037 // DisplayPasskey(). 3040 // DisplayPasskey().
3038 EXPECT_EQ(9, pairing_delegate.call_count_); 3041 EXPECT_EQ(9, pairing_delegate.call_count_);
3039 EXPECT_EQ(8, pairing_delegate.keys_entered_count_); 3042 EXPECT_EQ(8, pairing_delegate.keys_entered_count_);
3040 EXPECT_EQ(7U, pairing_delegate.last_entered_); 3043 EXPECT_EQ(7U, pairing_delegate.last_entered_);
3041 3044
3042 EXPECT_EQ(1, callback_count_); 3045 EXPECT_EQ(1, callback_count_);
3043 EXPECT_EQ(0, error_callback_count_); 3046 EXPECT_EQ(0, error_callback_count_);
3044 3047
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3086 device->Connect(&pairing_delegate, GetCallback(), 3089 device->Connect(&pairing_delegate, GetCallback(),
3087 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3090 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3088 base::Unretained(this))); 3091 base::Unretained(this)));
3089 3092
3090 EXPECT_EQ(1, pairing_delegate.call_count_); 3093 EXPECT_EQ(1, pairing_delegate.call_count_);
3091 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); 3094 EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
3092 EXPECT_TRUE(device->IsConnecting()); 3095 EXPECT_TRUE(device->IsConnecting());
3093 3096
3094 // Set the PIN. 3097 // Set the PIN.
3095 device->SetPinCode("1234"); 3098 device->SetPinCode("1234");
3096 message_loop_.Run(); 3099 base::RunLoop().Run();
3097 3100
3098 EXPECT_EQ(1, callback_count_); 3101 EXPECT_EQ(1, callback_count_);
3099 EXPECT_EQ(0, error_callback_count_); 3102 EXPECT_EQ(0, error_callback_count_);
3100 3103
3101 // Two changes for connecting, one change for connected, one for paired and 3104 // Two changes for connecting, one change for connected, one for paired and
3102 // two for trusted (after pairing and connection). 3105 // two for trusted (after pairing and connection).
3103 EXPECT_EQ(6, observer.device_changed_count()); 3106 EXPECT_EQ(6, observer.device_changed_count());
3104 EXPECT_EQ(device, observer.last_device()); 3107 EXPECT_EQ(device, observer.last_device());
3105 3108
3106 EXPECT_TRUE(device->IsConnected()); 3109 EXPECT_TRUE(device->IsConnected());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3141 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3144 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3142 base::Unretained(this))); 3145 base::Unretained(this)));
3143 3146
3144 EXPECT_EQ(1, pairing_delegate.call_count_); 3147 EXPECT_EQ(1, pairing_delegate.call_count_);
3145 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 3148 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
3146 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); 3149 EXPECT_EQ(123456U, pairing_delegate.last_passkey_);
3147 EXPECT_TRUE(device->IsConnecting()); 3150 EXPECT_TRUE(device->IsConnecting());
3148 3151
3149 // Confirm the passkey. 3152 // Confirm the passkey.
3150 device->ConfirmPairing(); 3153 device->ConfirmPairing();
3151 message_loop_.Run(); 3154 base::RunLoop().Run();
3152 3155
3153 EXPECT_EQ(1, callback_count_); 3156 EXPECT_EQ(1, callback_count_);
3154 EXPECT_EQ(0, error_callback_count_); 3157 EXPECT_EQ(0, error_callback_count_);
3155 3158
3156 // Two changes for connecting, one change for connected, one for paired and 3159 // Two changes for connecting, one change for connected, one for paired and
3157 // two for trusted (after pairing and connection). 3160 // two for trusted (after pairing and connection).
3158 EXPECT_EQ(6, observer.device_changed_count()); 3161 EXPECT_EQ(6, observer.device_changed_count());
3159 EXPECT_EQ(device, observer.last_device()); 3162 EXPECT_EQ(device, observer.last_device());
3160 3163
3161 EXPECT_TRUE(device->IsConnected()); 3164 EXPECT_TRUE(device->IsConnected());
(...skipping 30 matching lines...) Expand all
3192 device->Connect(&pairing_delegate, GetCallback(), 3195 device->Connect(&pairing_delegate, GetCallback(),
3193 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3196 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3194 base::Unretained(this))); 3197 base::Unretained(this)));
3195 3198
3196 EXPECT_EQ(1, pairing_delegate.call_count_); 3199 EXPECT_EQ(1, pairing_delegate.call_count_);
3197 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 3200 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
3198 EXPECT_TRUE(device->IsConnecting()); 3201 EXPECT_TRUE(device->IsConnecting());
3199 3202
3200 // Set the Passkey. 3203 // Set the Passkey.
3201 device->SetPasskey(1234); 3204 device->SetPasskey(1234);
3202 message_loop_.Run(); 3205 base::RunLoop().Run();
3203 3206
3204 EXPECT_EQ(1, callback_count_); 3207 EXPECT_EQ(1, callback_count_);
3205 EXPECT_EQ(0, error_callback_count_); 3208 EXPECT_EQ(0, error_callback_count_);
3206 3209
3207 // Two changes for connecting, one change for connected, one for paired and 3210 // Two changes for connecting, one change for connected, one for paired and
3208 // two for trusted (after pairing and connection). 3211 // two for trusted (after pairing and connection).
3209 EXPECT_EQ(6, observer.device_changed_count()); 3212 EXPECT_EQ(6, observer.device_changed_count());
3210 EXPECT_EQ(device, observer.last_device()); 3213 EXPECT_EQ(device, observer.last_device());
3211 3214
3212 EXPECT_TRUE(device->IsConnected()); 3215 EXPECT_TRUE(device->IsConnected());
(...skipping 26 matching lines...) Expand all
3239 3242
3240 TestBluetoothAdapterObserver observer(adapter_); 3243 TestBluetoothAdapterObserver observer(adapter_);
3241 3244
3242 TestPairingDelegate pairing_delegate; 3245 TestPairingDelegate pairing_delegate;
3243 device->Connect(&pairing_delegate, GetCallback(), 3246 device->Connect(&pairing_delegate, GetCallback(),
3244 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3247 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3245 base::Unretained(this))); 3248 base::Unretained(this)));
3246 3249
3247 EXPECT_EQ(0, pairing_delegate.call_count_); 3250 EXPECT_EQ(0, pairing_delegate.call_count_);
3248 3251
3249 message_loop_.Run(); 3252 base::RunLoop().Run();
3250 3253
3251 EXPECT_EQ(1, callback_count_); 3254 EXPECT_EQ(1, callback_count_);
3252 EXPECT_EQ(0, error_callback_count_); 3255 EXPECT_EQ(0, error_callback_count_);
3253 3256
3254 // Two changes for connecting, one change for connected, one for paired and 3257 // Two changes for connecting, one change for connected, one for paired and
3255 // two for trusted (after pairing and connection). 3258 // two for trusted (after pairing and connection).
3256 EXPECT_EQ(6, observer.device_changed_count()); 3259 EXPECT_EQ(6, observer.device_changed_count());
3257 EXPECT_EQ(device, observer.last_device()); 3260 EXPECT_EQ(device, observer.last_device());
3258 3261
3259 EXPECT_TRUE(device->IsConnected()); 3262 EXPECT_TRUE(device->IsConnected());
(...skipping 26 matching lines...) Expand all
3286 3289
3287 TestPairingDelegate pairing_delegate; 3290 TestPairingDelegate pairing_delegate;
3288 device->Connect(&pairing_delegate, GetCallback(), 3291 device->Connect(&pairing_delegate, GetCallback(),
3289 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3292 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3290 base::Unretained(this))); 3293 base::Unretained(this)));
3291 3294
3292 EXPECT_EQ(0, pairing_delegate.call_count_); 3295 EXPECT_EQ(0, pairing_delegate.call_count_);
3293 EXPECT_TRUE(device->IsConnecting()); 3296 EXPECT_TRUE(device->IsConnecting());
3294 3297
3295 // Run the loop to get the error.. 3298 // Run the loop to get the error..
3296 message_loop_.Run(); 3299 base::RunLoop().Run();
3297 3300
3298 EXPECT_EQ(0, callback_count_); 3301 EXPECT_EQ(0, callback_count_);
3299 EXPECT_EQ(1, error_callback_count_); 3302 EXPECT_EQ(1, error_callback_count_);
3300 3303
3301 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); 3304 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_);
3302 3305
3303 EXPECT_FALSE(device->IsConnected()); 3306 EXPECT_FALSE(device->IsConnected());
3304 EXPECT_FALSE(device->IsConnecting()); 3307 EXPECT_FALSE(device->IsConnecting());
3305 EXPECT_FALSE(device->IsPaired()); 3308 EXPECT_FALSE(device->IsPaired());
3306 } 3309 }
(...skipping 14 matching lines...) Expand all
3321 3324
3322 TestPairingDelegate pairing_delegate; 3325 TestPairingDelegate pairing_delegate;
3323 device->Connect(&pairing_delegate, GetCallback(), 3326 device->Connect(&pairing_delegate, GetCallback(),
3324 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3327 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3325 base::Unretained(this))); 3328 base::Unretained(this)));
3326 3329
3327 EXPECT_EQ(0, pairing_delegate.call_count_); 3330 EXPECT_EQ(0, pairing_delegate.call_count_);
3328 EXPECT_TRUE(device->IsConnecting()); 3331 EXPECT_TRUE(device->IsConnecting());
3329 3332
3330 // Run the loop to get the error.. 3333 // Run the loop to get the error..
3331 message_loop_.Run(); 3334 base::RunLoop().Run();
3332 3335
3333 EXPECT_EQ(0, callback_count_); 3336 EXPECT_EQ(0, callback_count_);
3334 EXPECT_EQ(1, error_callback_count_); 3337 EXPECT_EQ(1, error_callback_count_);
3335 3338
3336 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_TIMEOUT, last_connect_error_); 3339 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_TIMEOUT, last_connect_error_);
3337 3340
3338 EXPECT_FALSE(device->IsConnected()); 3341 EXPECT_FALSE(device->IsConnected());
3339 EXPECT_FALSE(device->IsConnecting()); 3342 EXPECT_FALSE(device->IsConnecting());
3340 EXPECT_FALSE(device->IsPaired()); 3343 EXPECT_FALSE(device->IsPaired());
3341 } 3344 }
(...skipping 14 matching lines...) Expand all
3356 TestBluetoothAdapterObserver observer(adapter_); 3359 TestBluetoothAdapterObserver observer(adapter_);
3357 3360
3358 TestPairingDelegate pairing_delegate; 3361 TestPairingDelegate pairing_delegate;
3359 device->Connect(&pairing_delegate, GetCallback(), 3362 device->Connect(&pairing_delegate, GetCallback(),
3360 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3363 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3361 base::Unretained(this))); 3364 base::Unretained(this)));
3362 3365
3363 EXPECT_EQ(0, pairing_delegate.call_count_); 3366 EXPECT_EQ(0, pairing_delegate.call_count_);
3364 EXPECT_TRUE(device->IsConnecting()); 3367 EXPECT_TRUE(device->IsConnecting());
3365 3368
3366 message_loop_.Run(); 3369 base::RunLoop().Run();
3367 3370
3368 EXPECT_EQ(0, callback_count_); 3371 EXPECT_EQ(0, callback_count_);
3369 EXPECT_EQ(1, error_callback_count_); 3372 EXPECT_EQ(1, error_callback_count_);
3370 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); 3373 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_);
3371 3374
3372 // Two changes for connecting, one for paired and one for trusted after 3375 // Two changes for connecting, one for paired and one for trusted after
3373 // pairing. The device should not be connected. 3376 // pairing. The device should not be connected.
3374 EXPECT_EQ(4, observer.device_changed_count()); 3377 EXPECT_EQ(4, observer.device_changed_count());
3375 EXPECT_EQ(device, observer.last_device()); 3378 EXPECT_EQ(device, observer.last_device());
3376 3379
(...skipping 28 matching lines...) Expand all
3405 device->Connect(&pairing_delegate, GetCallback(), 3408 device->Connect(&pairing_delegate, GetCallback(),
3406 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3409 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3407 base::Unretained(this))); 3410 base::Unretained(this)));
3408 3411
3409 EXPECT_EQ(1, pairing_delegate.call_count_); 3412 EXPECT_EQ(1, pairing_delegate.call_count_);
3410 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); 3413 EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
3411 EXPECT_TRUE(device->IsConnecting()); 3414 EXPECT_TRUE(device->IsConnecting());
3412 3415
3413 // Reject the pairing. 3416 // Reject the pairing.
3414 device->RejectPairing(); 3417 device->RejectPairing();
3415 message_loop_.Run(); 3418 base::RunLoop().Run();
3416 3419
3417 EXPECT_EQ(0, callback_count_); 3420 EXPECT_EQ(0, callback_count_);
3418 EXPECT_EQ(1, error_callback_count_); 3421 EXPECT_EQ(1, error_callback_count_);
3419 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); 3422 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_);
3420 3423
3421 // Should be no changes except connecting going true and false. 3424 // Should be no changes except connecting going true and false.
3422 EXPECT_EQ(2, observer.device_changed_count()); 3425 EXPECT_EQ(2, observer.device_changed_count());
3423 EXPECT_FALSE(device->IsConnected()); 3426 EXPECT_FALSE(device->IsConnected());
3424 EXPECT_FALSE(device->IsConnecting()); 3427 EXPECT_FALSE(device->IsConnecting());
3425 EXPECT_FALSE(device->IsPaired()); 3428 EXPECT_FALSE(device->IsPaired());
(...skipping 17 matching lines...) Expand all
3443 device->Connect(&pairing_delegate, GetCallback(), 3446 device->Connect(&pairing_delegate, GetCallback(),
3444 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3447 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3445 base::Unretained(this))); 3448 base::Unretained(this)));
3446 3449
3447 EXPECT_EQ(1, pairing_delegate.call_count_); 3450 EXPECT_EQ(1, pairing_delegate.call_count_);
3448 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); 3451 EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
3449 EXPECT_TRUE(device->IsConnecting()); 3452 EXPECT_TRUE(device->IsConnecting());
3450 3453
3451 // Cancel the pairing. 3454 // Cancel the pairing.
3452 device->CancelPairing(); 3455 device->CancelPairing();
3453 message_loop_.Run(); 3456 base::RunLoop().Run();
3454 3457
3455 EXPECT_EQ(0, callback_count_); 3458 EXPECT_EQ(0, callback_count_);
3456 EXPECT_EQ(1, error_callback_count_); 3459 EXPECT_EQ(1, error_callback_count_);
3457 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); 3460 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
3458 3461
3459 // Should be no changes except connecting going true and false. 3462 // Should be no changes except connecting going true and false.
3460 EXPECT_EQ(2, observer.device_changed_count()); 3463 EXPECT_EQ(2, observer.device_changed_count());
3461 EXPECT_FALSE(device->IsConnected()); 3464 EXPECT_FALSE(device->IsConnected());
3462 EXPECT_FALSE(device->IsConnecting()); 3465 EXPECT_FALSE(device->IsConnecting());
3463 EXPECT_FALSE(device->IsPaired()); 3466 EXPECT_FALSE(device->IsPaired());
(...skipping 17 matching lines...) Expand all
3481 device->Connect(&pairing_delegate, GetCallback(), 3484 device->Connect(&pairing_delegate, GetCallback(),
3482 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3485 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3483 base::Unretained(this))); 3486 base::Unretained(this)));
3484 3487
3485 EXPECT_EQ(1, pairing_delegate.call_count_); 3488 EXPECT_EQ(1, pairing_delegate.call_count_);
3486 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 3489 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
3487 EXPECT_TRUE(device->IsConnecting()); 3490 EXPECT_TRUE(device->IsConnecting());
3488 3491
3489 // Reject the pairing. 3492 // Reject the pairing.
3490 device->RejectPairing(); 3493 device->RejectPairing();
3491 message_loop_.Run(); 3494 base::RunLoop().Run();
3492 3495
3493 EXPECT_EQ(0, callback_count_); 3496 EXPECT_EQ(0, callback_count_);
3494 EXPECT_EQ(1, error_callback_count_); 3497 EXPECT_EQ(1, error_callback_count_);
3495 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); 3498 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_);
3496 3499
3497 // Should be no changes except connecting going true and false. 3500 // Should be no changes except connecting going true and false.
3498 EXPECT_EQ(2, observer.device_changed_count()); 3501 EXPECT_EQ(2, observer.device_changed_count());
3499 EXPECT_FALSE(device->IsConnected()); 3502 EXPECT_FALSE(device->IsConnected());
3500 EXPECT_FALSE(device->IsConnecting()); 3503 EXPECT_FALSE(device->IsConnecting());
3501 EXPECT_FALSE(device->IsPaired()); 3504 EXPECT_FALSE(device->IsPaired());
(...skipping 17 matching lines...) Expand all
3519 device->Connect(&pairing_delegate, GetCallback(), 3522 device->Connect(&pairing_delegate, GetCallback(),
3520 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3523 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3521 base::Unretained(this))); 3524 base::Unretained(this)));
3522 3525
3523 EXPECT_EQ(1, pairing_delegate.call_count_); 3526 EXPECT_EQ(1, pairing_delegate.call_count_);
3524 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 3527 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
3525 EXPECT_TRUE(device->IsConnecting()); 3528 EXPECT_TRUE(device->IsConnecting());
3526 3529
3527 // Cancel the pairing. 3530 // Cancel the pairing.
3528 device->CancelPairing(); 3531 device->CancelPairing();
3529 message_loop_.Run(); 3532 base::RunLoop().Run();
3530 3533
3531 EXPECT_EQ(0, callback_count_); 3534 EXPECT_EQ(0, callback_count_);
3532 EXPECT_EQ(1, error_callback_count_); 3535 EXPECT_EQ(1, error_callback_count_);
3533 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); 3536 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
3534 3537
3535 // Should be no changes except connecting going true and false. 3538 // Should be no changes except connecting going true and false.
3536 EXPECT_EQ(2, observer.device_changed_count()); 3539 EXPECT_EQ(2, observer.device_changed_count());
3537 EXPECT_FALSE(device->IsConnected()); 3540 EXPECT_FALSE(device->IsConnected());
3538 EXPECT_FALSE(device->IsConnecting()); 3541 EXPECT_FALSE(device->IsConnecting());
3539 EXPECT_FALSE(device->IsPaired()); 3542 EXPECT_FALSE(device->IsPaired());
(...skipping 17 matching lines...) Expand all
3557 device->Connect(&pairing_delegate, GetCallback(), 3560 device->Connect(&pairing_delegate, GetCallback(),
3558 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3561 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3559 base::Unretained(this))); 3562 base::Unretained(this)));
3560 3563
3561 EXPECT_EQ(1, pairing_delegate.call_count_); 3564 EXPECT_EQ(1, pairing_delegate.call_count_);
3562 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 3565 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
3563 EXPECT_TRUE(device->IsConnecting()); 3566 EXPECT_TRUE(device->IsConnecting());
3564 3567
3565 // Reject the pairing. 3568 // Reject the pairing.
3566 device->RejectPairing(); 3569 device->RejectPairing();
3567 message_loop_.Run(); 3570 base::RunLoop().Run();
3568 3571
3569 EXPECT_EQ(0, callback_count_); 3572 EXPECT_EQ(0, callback_count_);
3570 EXPECT_EQ(1, error_callback_count_); 3573 EXPECT_EQ(1, error_callback_count_);
3571 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); 3574 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_);
3572 3575
3573 // Should be no changes except connecting going true and false. 3576 // Should be no changes except connecting going true and false.
3574 EXPECT_EQ(2, observer.device_changed_count()); 3577 EXPECT_EQ(2, observer.device_changed_count());
3575 EXPECT_FALSE(device->IsConnected()); 3578 EXPECT_FALSE(device->IsConnected());
3576 EXPECT_FALSE(device->IsConnecting()); 3579 EXPECT_FALSE(device->IsConnecting());
3577 EXPECT_FALSE(device->IsPaired()); 3580 EXPECT_FALSE(device->IsPaired());
(...skipping 17 matching lines...) Expand all
3595 device->Connect(&pairing_delegate, GetCallback(), 3598 device->Connect(&pairing_delegate, GetCallback(),
3596 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3599 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3597 base::Unretained(this))); 3600 base::Unretained(this)));
3598 3601
3599 EXPECT_EQ(1, pairing_delegate.call_count_); 3602 EXPECT_EQ(1, pairing_delegate.call_count_);
3600 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 3603 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
3601 EXPECT_TRUE(device->IsConnecting()); 3604 EXPECT_TRUE(device->IsConnecting());
3602 3605
3603 // Cancel the pairing. 3606 // Cancel the pairing.
3604 device->CancelPairing(); 3607 device->CancelPairing();
3605 message_loop_.Run(); 3608 base::RunLoop().Run();
3606 3609
3607 EXPECT_EQ(0, callback_count_); 3610 EXPECT_EQ(0, callback_count_);
3608 EXPECT_EQ(1, error_callback_count_); 3611 EXPECT_EQ(1, error_callback_count_);
3609 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); 3612 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
3610 3613
3611 // Should be no changes except connecting going true and false. 3614 // Should be no changes except connecting going true and false.
3612 EXPECT_EQ(2, observer.device_changed_count()); 3615 EXPECT_EQ(2, observer.device_changed_count());
3613 EXPECT_FALSE(device->IsConnected()); 3616 EXPECT_FALSE(device->IsConnected());
3614 EXPECT_FALSE(device->IsConnecting()); 3617 EXPECT_FALSE(device->IsConnecting());
3615 EXPECT_FALSE(device->IsPaired()); 3618 EXPECT_FALSE(device->IsPaired());
(...skipping 16 matching lines...) Expand all
3632 TestPairingDelegate pairing_delegate; 3635 TestPairingDelegate pairing_delegate;
3633 device->Connect(&pairing_delegate, GetCallback(), 3636 device->Connect(&pairing_delegate, GetCallback(),
3634 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, 3637 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3635 base::Unretained(this))); 3638 base::Unretained(this)));
3636 3639
3637 EXPECT_EQ(0, pairing_delegate.call_count_); 3640 EXPECT_EQ(0, pairing_delegate.call_count_);
3638 EXPECT_TRUE(device->IsConnecting()); 3641 EXPECT_TRUE(device->IsConnecting());
3639 3642
3640 // Cancel the pairing. 3643 // Cancel the pairing.
3641 device->CancelPairing(); 3644 device->CancelPairing();
3642 message_loop_.Run(); 3645 base::RunLoop().Run();
3643 3646
3644 EXPECT_EQ(0, callback_count_); 3647 EXPECT_EQ(0, callback_count_);
3645 EXPECT_EQ(1, error_callback_count_); 3648 EXPECT_EQ(1, error_callback_count_);
3646 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); 3649 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
3647 3650
3648 // Should be no changes except connecting going true and false. 3651 // Should be no changes except connecting going true and false.
3649 EXPECT_EQ(2, observer.device_changed_count()); 3652 EXPECT_EQ(2, observer.device_changed_count());
3650 EXPECT_FALSE(device->IsConnected()); 3653 EXPECT_FALSE(device->IsConnected());
3651 EXPECT_FALSE(device->IsConnecting()); 3654 EXPECT_FALSE(device->IsConnecting());
3652 EXPECT_FALSE(device->IsPaired()); 3655 EXPECT_FALSE(device->IsPaired());
(...skipping 22 matching lines...) Expand all
3675 fake_bluetooth_device_client_->SimulatePairing( 3678 fake_bluetooth_device_client_->SimulatePairing(
3676 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), 3679 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath),
3677 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, 3680 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3678 base::Unretained(this))); 3681 base::Unretained(this)));
3679 3682
3680 EXPECT_EQ(1, pairing_delegate.call_count_); 3683 EXPECT_EQ(1, pairing_delegate.call_count_);
3681 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); 3684 EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
3682 3685
3683 // Set the PIN. 3686 // Set the PIN.
3684 device->SetPinCode("1234"); 3687 device->SetPinCode("1234");
3685 message_loop_.Run(); 3688 base::RunLoop().Run();
3686 3689
3687 EXPECT_EQ(1, callback_count_); 3690 EXPECT_EQ(1, callback_count_);
3688 EXPECT_EQ(0, error_callback_count_); 3691 EXPECT_EQ(0, error_callback_count_);
3689 3692
3690 // One change for paired, and one for trusted. 3693 // One change for paired, and one for trusted.
3691 EXPECT_EQ(2, observer.device_changed_count()); 3694 EXPECT_EQ(2, observer.device_changed_count());
3692 EXPECT_EQ(device, observer.last_device()); 3695 EXPECT_EQ(device, observer.last_device());
3693 3696
3694 EXPECT_TRUE(device->IsPaired()); 3697 EXPECT_TRUE(device->IsPaired());
3695 3698
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3729 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), 3732 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath),
3730 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, 3733 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3731 base::Unretained(this))); 3734 base::Unretained(this)));
3732 3735
3733 EXPECT_EQ(1, pairing_delegate.call_count_); 3736 EXPECT_EQ(1, pairing_delegate.call_count_);
3734 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 3737 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
3735 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); 3738 EXPECT_EQ(123456U, pairing_delegate.last_passkey_);
3736 3739
3737 // Confirm the passkey. 3740 // Confirm the passkey.
3738 device->ConfirmPairing(); 3741 device->ConfirmPairing();
3739 message_loop_.Run(); 3742 base::RunLoop().Run();
3740 3743
3741 EXPECT_EQ(1, callback_count_); 3744 EXPECT_EQ(1, callback_count_);
3742 EXPECT_EQ(0, error_callback_count_); 3745 EXPECT_EQ(0, error_callback_count_);
3743 3746
3744 // One change for paired, and one for trusted. 3747 // One change for paired, and one for trusted.
3745 EXPECT_EQ(2, observer.device_changed_count()); 3748 EXPECT_EQ(2, observer.device_changed_count());
3746 EXPECT_EQ(device, observer.last_device()); 3749 EXPECT_EQ(device, observer.last_device());
3747 3750
3748 EXPECT_TRUE(device->IsPaired()); 3751 EXPECT_TRUE(device->IsPaired());
3749 3752
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3782 fake_bluetooth_device_client_->SimulatePairing( 3785 fake_bluetooth_device_client_->SimulatePairing(
3783 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), 3786 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath),
3784 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, 3787 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3785 base::Unretained(this))); 3788 base::Unretained(this)));
3786 3789
3787 EXPECT_EQ(1, pairing_delegate.call_count_); 3790 EXPECT_EQ(1, pairing_delegate.call_count_);
3788 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 3791 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
3789 3792
3790 // Set the Passkey. 3793 // Set the Passkey.
3791 device->SetPasskey(1234); 3794 device->SetPasskey(1234);
3792 message_loop_.Run(); 3795 base::RunLoop().Run();
3793 3796
3794 EXPECT_EQ(1, callback_count_); 3797 EXPECT_EQ(1, callback_count_);
3795 EXPECT_EQ(0, error_callback_count_); 3798 EXPECT_EQ(0, error_callback_count_);
3796 3799
3797 // One change for paired, and one for trusted. 3800 // One change for paired, and one for trusted.
3798 EXPECT_EQ(2, observer.device_changed_count()); 3801 EXPECT_EQ(2, observer.device_changed_count());
3799 EXPECT_EQ(device, observer.last_device()); 3802 EXPECT_EQ(device, observer.last_device());
3800 3803
3801 EXPECT_TRUE(device->IsPaired()); 3804 EXPECT_TRUE(device->IsPaired());
3802 3805
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3836 fake_bluetooth_device_client_->SimulatePairing( 3839 fake_bluetooth_device_client_->SimulatePairing(
3837 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, 3840 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true,
3838 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, 3841 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3839 base::Unretained(this))); 3842 base::Unretained(this)));
3840 3843
3841 EXPECT_EQ(1, pairing_delegate.call_count_); 3844 EXPECT_EQ(1, pairing_delegate.call_count_);
3842 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_); 3845 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_);
3843 3846
3844 // Confirm the pairing. 3847 // Confirm the pairing.
3845 device->ConfirmPairing(); 3848 device->ConfirmPairing();
3846 message_loop_.Run(); 3849 base::RunLoop().Run();
3847 3850
3848 EXPECT_EQ(1, callback_count_); 3851 EXPECT_EQ(1, callback_count_);
3849 EXPECT_EQ(0, error_callback_count_); 3852 EXPECT_EQ(0, error_callback_count_);
3850 3853
3851 // One change for paired, and one for trusted. 3854 // One change for paired, and one for trusted.
3852 EXPECT_EQ(2, observer.device_changed_count()); 3855 EXPECT_EQ(2, observer.device_changed_count());
3853 EXPECT_EQ(device, observer.last_device()); 3856 EXPECT_EQ(device, observer.last_device());
3854 3857
3855 EXPECT_TRUE(device->IsPaired()); 3858 EXPECT_TRUE(device->IsPaired());
3856 3859
(...skipping 24 matching lines...) Expand all
3881 ASSERT_TRUE(device != nullptr); 3884 ASSERT_TRUE(device != nullptr);
3882 ASSERT_FALSE(device->IsPaired()); 3885 ASSERT_FALSE(device->IsPaired());
3883 3886
3884 TestBluetoothAdapterObserver observer(adapter_); 3887 TestBluetoothAdapterObserver observer(adapter_);
3885 3888
3886 fake_bluetooth_device_client_->SimulatePairing( 3889 fake_bluetooth_device_client_->SimulatePairing(
3887 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), 3890 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath),
3888 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, 3891 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3889 base::Unretained(this))); 3892 base::Unretained(this)));
3890 3893
3891 message_loop_.Run(); 3894 base::RunLoop().Run();
3892 3895
3893 EXPECT_EQ(0, callback_count_); 3896 EXPECT_EQ(0, callback_count_);
3894 EXPECT_EQ(1, error_callback_count_); 3897 EXPECT_EQ(1, error_callback_count_);
3895 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); 3898 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_);
3896 3899
3897 // No changes should be observer. 3900 // No changes should be observer.
3898 EXPECT_EQ(0, observer.device_changed_count()); 3901 EXPECT_EQ(0, observer.device_changed_count());
3899 3902
3900 EXPECT_FALSE(device->IsPaired()); 3903 EXPECT_FALSE(device->IsPaired());
3901 3904
(...skipping 18 matching lines...) Expand all
3920 ASSERT_TRUE(device != nullptr); 3923 ASSERT_TRUE(device != nullptr);
3921 ASSERT_FALSE(device->IsPaired()); 3924 ASSERT_FALSE(device->IsPaired());
3922 3925
3923 TestBluetoothAdapterObserver observer(adapter_); 3926 TestBluetoothAdapterObserver observer(adapter_);
3924 3927
3925 fake_bluetooth_device_client_->SimulatePairing( 3928 fake_bluetooth_device_client_->SimulatePairing(
3926 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), 3929 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath),
3927 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, 3930 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3928 base::Unretained(this))); 3931 base::Unretained(this)));
3929 3932
3930 message_loop_.Run(); 3933 base::RunLoop().Run();
3931 3934
3932 EXPECT_EQ(0, callback_count_); 3935 EXPECT_EQ(0, callback_count_);
3933 EXPECT_EQ(1, error_callback_count_); 3936 EXPECT_EQ(1, error_callback_count_);
3934 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); 3937 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_);
3935 3938
3936 // No changes should be observer. 3939 // No changes should be observer.
3937 EXPECT_EQ(0, observer.device_changed_count()); 3940 EXPECT_EQ(0, observer.device_changed_count());
3938 3941
3939 EXPECT_FALSE(device->IsPaired()); 3942 EXPECT_FALSE(device->IsPaired());
3940 3943
(...skipping 18 matching lines...) Expand all
3959 ASSERT_TRUE(device != nullptr); 3962 ASSERT_TRUE(device != nullptr);
3960 ASSERT_FALSE(device->IsPaired()); 3963 ASSERT_FALSE(device->IsPaired());
3961 3964
3962 TestBluetoothAdapterObserver observer(adapter_); 3965 TestBluetoothAdapterObserver observer(adapter_);
3963 3966
3964 fake_bluetooth_device_client_->SimulatePairing( 3967 fake_bluetooth_device_client_->SimulatePairing(
3965 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), 3968 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath),
3966 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, 3969 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3967 base::Unretained(this))); 3970 base::Unretained(this)));
3968 3971
3969 message_loop_.Run(); 3972 base::RunLoop().Run();
3970 3973
3971 EXPECT_EQ(0, callback_count_); 3974 EXPECT_EQ(0, callback_count_);
3972 EXPECT_EQ(1, error_callback_count_); 3975 EXPECT_EQ(1, error_callback_count_);
3973 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); 3976 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_);
3974 3977
3975 // No changes should be observer. 3978 // No changes should be observer.
3976 EXPECT_EQ(0, observer.device_changed_count()); 3979 EXPECT_EQ(0, observer.device_changed_count());
3977 3980
3978 EXPECT_FALSE(device->IsPaired()); 3981 EXPECT_FALSE(device->IsPaired());
3979 3982
(...skipping 18 matching lines...) Expand all
3998 ASSERT_TRUE(device != nullptr); 4001 ASSERT_TRUE(device != nullptr);
3999 ASSERT_FALSE(device->IsPaired()); 4002 ASSERT_FALSE(device->IsPaired());
4000 4003
4001 TestBluetoothAdapterObserver observer(adapter_); 4004 TestBluetoothAdapterObserver observer(adapter_);
4002 4005
4003 fake_bluetooth_device_client_->SimulatePairing( 4006 fake_bluetooth_device_client_->SimulatePairing(
4004 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, 4007 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true,
4005 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback, 4008 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
4006 base::Unretained(this))); 4009 base::Unretained(this)));
4007 4010
4008 message_loop_.Run(); 4011 base::RunLoop().Run();
4009 4012
4010 EXPECT_EQ(0, callback_count_); 4013 EXPECT_EQ(0, callback_count_);
4011 EXPECT_EQ(1, error_callback_count_); 4014 EXPECT_EQ(1, error_callback_count_);
4012 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); 4015 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_);
4013 4016
4014 // No changes should be observer. 4017 // No changes should be observer.
4015 EXPECT_EQ(0, observer.device_changed_count()); 4018 EXPECT_EQ(0, observer.device_changed_count());
4016 4019
4017 EXPECT_FALSE(device->IsPaired()); 4020 EXPECT_FALSE(device->IsPaired());
4018 4021
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
4181 // Verifies Shutdown shuts down the adapter as expected. 4184 // Verifies Shutdown shuts down the adapter as expected.
4182 TEST_F(BluetoothBlueZTest, Shutdown) { 4185 TEST_F(BluetoothBlueZTest, Shutdown) {
4183 // Set up adapter. Set powered & discoverable, start discovery. 4186 // Set up adapter. Set powered & discoverable, start discovery.
4184 GetAdapter(); 4187 GetAdapter();
4185 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 4188 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
4186 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); 4189 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
4187 adapter_->StartDiscoverySession( 4190 adapter_->StartDiscoverySession(
4188 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback, 4191 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
4189 base::Unretained(this)), 4192 base::Unretained(this)),
4190 GetErrorCallback()); 4193 GetErrorCallback());
4191 base::MessageLoop::current()->Run(); 4194 base::RunLoop().Run();
4192 ASSERT_EQ(3, callback_count_); 4195 ASSERT_EQ(3, callback_count_);
4193 ASSERT_EQ(0, error_callback_count_); 4196 ASSERT_EQ(0, error_callback_count_);
4194 callback_count_ = 0; 4197 callback_count_ = 0;
4195 4198
4196 TestPairingDelegate pairing_delegate; 4199 TestPairingDelegate pairing_delegate;
4197 adapter_->AddPairingDelegate( 4200 adapter_->AddPairingDelegate(
4198 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); 4201 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
4199 4202
4200 // Validate running adapter state. 4203 // Validate running adapter state.
4201 EXPECT_NE("", adapter_->GetAddress()); 4204 EXPECT_NE("", adapter_->GetAddress());
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
4497 adapter_->Shutdown(); 4500 adapter_->Shutdown();
4498 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); 4501 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", "");
4499 4502
4500 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, 4503 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError,
4501 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. 4504 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession.
4502 EXPECT_EQ(0, callback_count_); 4505 EXPECT_EQ(0, callback_count_);
4503 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); 4506 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_);
4504 } 4507 }
4505 4508
4506 } // namespace bluez 4509 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698