Index: device/bluetooth/test/bluetooth_test.cc |
diff --git a/device/bluetooth/test/bluetooth_test.cc b/device/bluetooth/test/bluetooth_test.cc |
index c80b8244ad883a7805e49d09d60e74c8af70e35b..a6ca93dabb79ea56122f56de5cda622688c5c770 100644 |
--- a/device/bluetooth/test/bluetooth_test.cc |
+++ b/device/bluetooth/test/bluetooth_test.cc |
@@ -34,10 +34,24 @@ void BluetoothTestBase::StartLowEnergyDiscoverySession() { |
adapter_->StartDiscoverySessionWithFilter( |
make_scoped_ptr(new BluetoothDiscoveryFilter( |
BluetoothDiscoveryFilter::Transport::TRANSPORT_LE)), |
- GetDiscoverySessionCallback(), GetErrorCallback()); |
+ GetDiscoverySessionCallback(Call::EXPECTED), |
+ GetErrorCallback(Call::NOT_EXPECTED)); |
base::RunLoop().RunUntilIdle(); |
} |
+void BluetoothTestBase::StartLowEnergyDiscoverySessionExpectedToFail() { |
+ adapter_->StartDiscoverySessionWithFilter( |
+ make_scoped_ptr(new BluetoothDiscoveryFilter( |
+ BluetoothDiscoveryFilter::Transport::TRANSPORT_LE)), |
+ GetDiscoverySessionCallback(Call::NOT_EXPECTED), |
+ GetErrorCallback(Call::EXPECTED)); |
+ base::RunLoop().RunUntilIdle(); |
+} |
+ |
+void BluetoothTestBase::TearDown() { |
scheib
2015/11/20 23:08:20
Let's also verify that the success callbacks made
ortuno
2015/11/21 01:12:49
Done.
|
+ EXPECT_FALSE(unexpected_callback_); |
+} |
+ |
bool BluetoothTestBase::DenyPermission() { |
return false; |
} |
@@ -52,98 +66,139 @@ void BluetoothTestBase::DeleteDevice(BluetoothDevice* device) { |
adapter_->DeleteDeviceForTesting(device->GetAddress()); |
} |
-void BluetoothTestBase::Callback() { |
+void BluetoothTestBase::Callback(Call expected) { |
+ if (expected == Call::NOT_EXPECTED) { |
+ unexpected_callback_ = true; |
+ return; |
scheib
2015/11/20 23:08:20
I think we want the counters always accurate, even
ortuno
2015/11/21 01:12:49
Done.
|
+ } |
++callback_count_; |
} |
void BluetoothTestBase::DiscoverySessionCallback( |
+ Call expected, |
scoped_ptr<BluetoothDiscoverySession> discovery_session) { |
+ if (expected == Call::NOT_EXPECTED) { |
+ unexpected_callback_ = true; |
+ return; |
+ } |
++callback_count_; |
discovery_sessions_.push_back(discovery_session.release()); |
} |
void BluetoothTestBase::GattConnectionCallback( |
+ Call expected, |
scoped_ptr<BluetoothGattConnection> connection) { |
+ if (expected == Call::NOT_EXPECTED) { |
+ unexpected_callback_ = true; |
+ return; |
+ } |
++callback_count_; |
gatt_connections_.push_back(connection.release()); |
} |
void BluetoothTestBase::NotifyCallback( |
+ Call expected, |
scoped_ptr<BluetoothGattNotifySession> notify_session) { |
+ if (expected == Call::NOT_EXPECTED) { |
+ unexpected_callback_ = true; |
+ return; |
+ } |
++callback_count_; |
notify_sessions_.push_back(notify_session.release()); |
} |
-void BluetoothTestBase::ReadValueCallback(const std::vector<uint8>& value) { |
+void BluetoothTestBase::ReadValueCallback(Call expected, |
+ const std::vector<uint8>& value) { |
+ if (expected == Call::NOT_EXPECTED) { |
+ unexpected_callback_ = true; |
+ return; |
+ } |
++callback_count_; |
last_read_value_ = value; |
} |
-void BluetoothTestBase::ErrorCallback() { |
+void BluetoothTestBase::ErrorCallback(Call expected) { |
+ if (expected == Call::NOT_EXPECTED) { |
+ unexpected_callback_ = true; |
+ return; |
+ } |
++error_callback_count_; |
} |
void BluetoothTestBase::ConnectErrorCallback( |
+ Call expected, |
enum BluetoothDevice::ConnectErrorCode error_code) { |
+ if (expected == Call::NOT_EXPECTED) { |
+ unexpected_callback_ = true; |
+ return; |
+ } |
++error_callback_count_; |
last_connect_error_code_ = error_code; |
} |
void BluetoothTestBase::GattErrorCallback( |
+ Call expected, |
BluetoothGattService::GattErrorCode error_code) { |
+ if (expected == Call::NOT_EXPECTED) { |
+ unexpected_callback_ = true; |
+ return; |
+ } |
++error_callback_count_; |
last_gatt_error_code_ = error_code; |
} |
-base::Closure BluetoothTestBase::GetCallback() { |
- return base::Bind(&BluetoothTestBase::Callback, weak_factory_.GetWeakPtr()); |
+base::Closure BluetoothTestBase::GetCallback(Call expected) { |
+ return base::Bind(&BluetoothTestBase::Callback, weak_factory_.GetWeakPtr(), |
+ expected); |
} |
BluetoothAdapter::DiscoverySessionCallback |
-BluetoothTestBase::GetDiscoverySessionCallback() { |
+BluetoothTestBase::GetDiscoverySessionCallback(Call expected) { |
return base::Bind(&BluetoothTestBase::DiscoverySessionCallback, |
- weak_factory_.GetWeakPtr()); |
+ weak_factory_.GetWeakPtr(), expected); |
} |
BluetoothDevice::GattConnectionCallback |
-BluetoothTestBase::GetGattConnectionCallback() { |
+BluetoothTestBase::GetGattConnectionCallback(Call expected) { |
return base::Bind(&BluetoothTestBase::GattConnectionCallback, |
- weak_factory_.GetWeakPtr()); |
+ weak_factory_.GetWeakPtr(), expected); |
} |
BluetoothGattCharacteristic::NotifySessionCallback |
-BluetoothTestBase::GetNotifyCallback() { |
+BluetoothTestBase::GetNotifyCallback(Call expected) { |
return base::Bind(&BluetoothTestBase::NotifyCallback, |
- weak_factory_.GetWeakPtr()); |
+ weak_factory_.GetWeakPtr(), expected); |
} |
BluetoothGattCharacteristic::ValueCallback |
-BluetoothTestBase::GetReadValueCallback() { |
+BluetoothTestBase::GetReadValueCallback(Call expected) { |
return base::Bind(&BluetoothTestBase::ReadValueCallback, |
- weak_factory_.GetWeakPtr()); |
+ weak_factory_.GetWeakPtr(), expected); |
} |
-BluetoothAdapter::ErrorCallback BluetoothTestBase::GetErrorCallback() { |
+BluetoothAdapter::ErrorCallback BluetoothTestBase::GetErrorCallback( |
+ Call expected) { |
return base::Bind(&BluetoothTestBase::ErrorCallback, |
- weak_factory_.GetWeakPtr()); |
+ weak_factory_.GetWeakPtr(), expected); |
} |
BluetoothDevice::ConnectErrorCallback |
-BluetoothTestBase::GetConnectErrorCallback() { |
+BluetoothTestBase::GetConnectErrorCallback(Call expected) { |
return base::Bind(&BluetoothTestBase::ConnectErrorCallback, |
- weak_factory_.GetWeakPtr()); |
+ weak_factory_.GetWeakPtr(), expected); |
} |
base::Callback<void(BluetoothGattService::GattErrorCode)> |
-BluetoothTestBase::GetGattErrorCallback() { |
+BluetoothTestBase::GetGattErrorCallback(Call expected) { |
return base::Bind(&BluetoothTestBase::GattErrorCallback, |
- weak_factory_.GetWeakPtr()); |
+ weak_factory_.GetWeakPtr(), expected); |
} |
void BluetoothTestBase::ResetEventCounts() { |
last_connect_error_code_ = BluetoothDevice::ERROR_UNKNOWN; |
callback_count_ = 0; |
error_callback_count_ = 0; |
+ unexpected_callback_ = false; |
gatt_connection_attempts_ = 0; |
gatt_disconnection_attempts_ = 0; |
gatt_discovery_attempts_ = 0; |