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

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

Issue 1465863003: bluetooth: Fix crash when trying to read or write when operation pending (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Address scheib's comments Created 5 years 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
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_device_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "device/bluetooth/bluetooth_adapter.h" 8 #include "device/bluetooth/bluetooth_adapter.h"
9 #include "device/bluetooth/bluetooth_device.h" 9 #include "device/bluetooth/bluetooth_device.h"
10 #include "device/bluetooth/bluetooth_discovery_session.h" 10 #include "device/bluetooth/bluetooth_discovery_session.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 void RequestPinCode(BluetoothDevice* device) override {} 132 void RequestPinCode(BluetoothDevice* device) override {}
133 void RequestPasskey(BluetoothDevice* device) override {} 133 void RequestPasskey(BluetoothDevice* device) override {}
134 void DisplayPinCode(BluetoothDevice* device, 134 void DisplayPinCode(BluetoothDevice* device,
135 const std::string& pincode) override {} 135 const std::string& pincode) override {}
136 void DisplayPasskey(BluetoothDevice* device, uint32 passkey) override {} 136 void DisplayPasskey(BluetoothDevice* device, uint32 passkey) override {}
137 void KeysEntered(BluetoothDevice* device, uint32 entered) override {} 137 void KeysEntered(BluetoothDevice* device, uint32 entered) override {}
138 void ConfirmPasskey(BluetoothDevice* device, uint32 passkey) override {} 138 void ConfirmPasskey(BluetoothDevice* device, uint32 passkey) override {}
139 void AuthorizePairing(BluetoothDevice* device) override {} 139 void AuthorizePairing(BluetoothDevice* device) override {}
140 }; 140 };
141 141
142
143 TEST(BluetoothAdapterTest, NoDefaultPairingDelegate) { 142 TEST(BluetoothAdapterTest, NoDefaultPairingDelegate) {
144 scoped_refptr<BluetoothAdapter> adapter = new TestBluetoothAdapter(); 143 scoped_refptr<BluetoothAdapter> adapter = new TestBluetoothAdapter();
145 144
146 // Verify that when there is no registered pairing delegate, NULL is returned. 145 // Verify that when there is no registered pairing delegate, NULL is returned.
147 EXPECT_TRUE(adapter->DefaultPairingDelegate() == NULL); 146 EXPECT_TRUE(adapter->DefaultPairingDelegate() == NULL);
148 } 147 }
149 148
150 TEST(BluetoothAdapterTest, OneDefaultPairingDelegate) { 149 TEST(BluetoothAdapterTest, OneDefaultPairingDelegate) {
151 scoped_refptr<BluetoothAdapter> adapter = new TestBluetoothAdapter(); 150 scoped_refptr<BluetoothAdapter> adapter = new TestBluetoothAdapter();
152 151
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 EXPECT_FALSE(adapter_->IsDiscovering()); 457 EXPECT_FALSE(adapter_->IsDiscovering());
459 458
460 StartLowEnergyDiscoverySession(); 459 StartLowEnergyDiscoverySession();
461 EXPECT_EQ(1, callback_count_); 460 EXPECT_EQ(1, callback_count_);
462 EXPECT_EQ(0, error_callback_count_); 461 EXPECT_EQ(0, error_callback_count_);
463 EXPECT_TRUE(adapter_->IsDiscovering()); 462 EXPECT_TRUE(adapter_->IsDiscovering());
464 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 463 ASSERT_EQ((size_t)1, discovery_sessions_.size());
465 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 464 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
466 465
467 ResetEventCounts(); 466 ResetEventCounts();
468 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 467 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED),
469 EXPECT_EQ(1, callback_count_); 468 GetErrorCallback(Call::NOT_EXPECTED));
470 EXPECT_EQ(0, error_callback_count_);
471 EXPECT_FALSE(adapter_->IsDiscovering()); 469 EXPECT_FALSE(adapter_->IsDiscovering());
472 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 470 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
473 } 471 }
474 #endif // defined(OS_ANDROID) 472 #endif // defined(OS_ANDROID)
475 473
476 #if defined(OS_ANDROID) || defined(OS_MACOSX) 474 #if defined(OS_ANDROID) || defined(OS_MACOSX)
477 // Checks that discovery fails (instead of hanging) when permissions are denied. 475 // Checks that discovery fails (instead of hanging) when permissions are denied.
478 TEST_F(BluetoothTest, NoPermissions) { 476 TEST_F(BluetoothTest, NoPermissions) {
479 if (!PlatformSupportsLowEnergy()) { 477 if (!PlatformSupportsLowEnergy()) {
480 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 478 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
481 return; 479 return;
482 } 480 }
483 InitWithFakeAdapter(); 481 InitWithFakeAdapter();
484 TestBluetoothAdapterObserver observer(adapter_); 482 TestBluetoothAdapterObserver observer(adapter_);
485 483
486 if (!DenyPermission()) { 484 if (!DenyPermission()) {
487 // Platform always gives permission to scan. 485 // Platform always gives permission to scan.
488 return; 486 return;
489 } 487 }
490 488
491 StartLowEnergyDiscoverySession(); 489 StartLowEnergyDiscoverySessionExpectedToFail();
492 490
493 EXPECT_EQ(0, callback_count_); 491 EXPECT_EQ(0, callback_count_);
494 EXPECT_EQ(1, error_callback_count_); 492 EXPECT_EQ(1, error_callback_count_);
495 } 493 }
496 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 494 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
497 495
498 #if defined(OS_ANDROID) || defined(OS_MACOSX) 496 #if defined(OS_ANDROID) || defined(OS_MACOSX)
499 // Discovers a device. 497 // Discovers a device.
500 TEST_F(BluetoothTest, DiscoverLowEnergyDevice) { 498 TEST_F(BluetoothTest, DiscoverLowEnergyDevice) {
501 if (!PlatformSupportsLowEnergy()) { 499 if (!PlatformSupportsLowEnergy()) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 // Start discovery and find a device. 602 // Start discovery and find a device.
605 StartLowEnergyDiscoverySession(); 603 StartLowEnergyDiscoverySession();
606 DiscoverLowEnergyDevice(1); 604 DiscoverLowEnergyDevice(1);
607 DiscoverLowEnergyDevice(4); 605 DiscoverLowEnergyDevice(4);
608 EXPECT_EQ(2, observer.device_added_count()); 606 EXPECT_EQ(2, observer.device_added_count());
609 EXPECT_EQ(2u, adapter_->GetDevices().size()); 607 EXPECT_EQ(2u, adapter_->GetDevices().size());
610 } 608 }
611 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 609 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
612 610
613 } // namespace device 611 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698