Index: chromeos/dbus/biod/biod_client_unittest.cc |
diff --git a/chromeos/dbus/biod/biod_client_unittest.cc b/chromeos/dbus/biod/biod_client_unittest.cc |
index ec86d098b77081aed6d556f4d4493677ea977746..806114de46e68a276f055d7925cba3debb0a32e2 100644 |
--- a/chromeos/dbus/biod/biod_client_unittest.cc |
+++ b/chromeos/dbus/biod/biod_client_unittest.cc |
@@ -52,6 +52,16 @@ void CopyString(std::string* dest_str, const std::string& src_str) { |
*dest_str = src_str; |
} |
+void CopyDBusMethodCallStatus(DBusMethodCallStatus* dest_status, |
+ DBusMethodCallStatus src_status) { |
+ *dest_status = src_status; |
+} |
+ |
+void CopyBiometricType(biod::BiometricType* dest_type, |
+ biod::BiometricType src_type) { |
+ *dest_type = src_type; |
+} |
+ |
// Matcher that verifies that a dbus::Message has member |name|. |
MATCHER_P(HasMember, name, "") { |
if (arg->GetMember() != name) { |
@@ -135,7 +145,7 @@ class BiodClientTest : public testing::Test { |
protected: |
// Add an expectation for method with |method_name| to be called. When the |
- // method is called the response shoudl match |response|. |
+ // method is called the response should match |response|. |
void AddMethodExpectation(const std::string& method_name, |
std::unique_ptr<dbus::Response> response) { |
ASSERT_FALSE(pending_method_calls_.count(method_name)); |
@@ -144,6 +154,16 @@ class BiodClientTest : public testing::Test { |
.WillOnce(Invoke(this, &BiodClientTest::OnCallMethod)); |
} |
+ void AddMethodWithErrorCallbackExpectation( |
Daniel Erat
2017/04/08 00:12:34
per earlier comment, you probably don't need this
sammiequon
2017/04/08 01:03:30
Done.
|
+ const std::string& method_name, |
+ std::unique_ptr<dbus::Response> response) { |
+ ASSERT_FALSE(pending_method_calls_.count(method_name)); |
+ pending_method_calls_[method_name] = std::move(response); |
+ EXPECT_CALL(*proxy_.get(), |
+ CallMethodWithErrorCallback(HasMember(method_name), _, _, _)) |
+ .WillOnce(Invoke(this, &BiodClientTest::OnCallMethodWithErrorCallback)); |
+ } |
+ |
// Synchronously passes |signal| to |client_|'s handler, simulating the signal |
// from biometrics. |
void EmitSignal(dbus::Signal* signal) { |
@@ -234,6 +254,21 @@ class BiodClientTest : public testing::Test { |
base::Passed(&pending_response))); |
} |
+ void OnCallMethodWithErrorCallback( |
Daniel Erat
2017/04/08 00:12:34
or this
sammiequon
2017/04/08 01:03:30
Done.
|
+ dbus::MethodCall* method_call, |
+ int timeout_ms, |
+ const dbus::ObjectProxy::ResponseCallback& callback, |
+ const dbus::ObjectProxy::ErrorCallback& error_callback) { |
+ auto it = pending_method_calls_.find(method_call->GetMember()); |
+ ASSERT_TRUE(it != pending_method_calls_.end()); |
+ auto pending_response = std::move(it->second); |
+ pending_method_calls_.erase(it); |
+ |
+ message_loop_.task_runner()->PostTask( |
+ FROM_HERE, base::Bind(&RunResponseCallback, callback, |
+ base::Passed(&pending_response))); |
+ } |
+ |
DISALLOW_COPY_AND_ASSIGN(BiodClientTest); |
}; |
@@ -312,6 +347,31 @@ TEST_F(BiodClientTest, TestGetRecordsForUser) { |
EXPECT_EQ(std::vector<dbus::ObjectPath>(), returned_object_paths); |
} |
+TEST_F(BiodClientTest, TestDestroyAllRecords) { |
+ std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
+ dbus::MessageWriter writer(response.get()); |
+ |
+ // Create a fake response with nothing. The destroy all records call should |
+ // return success. |
+ AddMethodWithErrorCallbackExpectation( |
+ biod::kBiometricsManagerDestroyAllRecordsMethod, std::move(response)); |
+ DBusMethodCallStatus returned_status = static_cast<DBusMethodCallStatus>(-1); |
+ client_->DestroyAllRecords( |
+ base::Bind(&CopyDBusMethodCallStatus, &returned_status)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, returned_status); |
+ |
+ // Create a fake response with nothing. The destroy all records call should |
+ // return failure. |
+ AddMethodWithErrorCallbackExpectation( |
+ biod::kBiometricsManagerDestroyAllRecordsMethod, nullptr); |
+ returned_status = static_cast<DBusMethodCallStatus>(-1); |
+ client_->DestroyAllRecords( |
+ base::Bind(&CopyDBusMethodCallStatus, &returned_status)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(DBUS_METHOD_CALL_FAILURE, returned_status); |
+} |
+ |
TEST_F(BiodClientTest, TestStartAuthentication) { |
const dbus::ObjectPath kFakeObjectPath(std::string("/fake/object/path")); |
@@ -347,6 +407,62 @@ TEST_F(BiodClientTest, TestStartAuthentication) { |
EXPECT_EQ(dbus::ObjectPath(), returned_path); |
} |
+TEST_F(BiodClientTest, TestRequestBiometricType) { |
+ const biod::BiometricType kFakeBiometricType = |
+ biod::BiometricType::BIOMETRIC_TYPE_FINGERPRINT; |
+ |
+ std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
+ dbus::MessageWriter writer(response.get()); |
+ writer.AppendVariantOfUint32(static_cast<uint32_t>(kFakeBiometricType)); |
+ |
+ // Create a fake response with biometric type. The get label call should |
+ // return this exact biometric type. |
+ biod::BiometricType returned_biometric_type = |
+ biod::BiometricType::BIOMETRIC_TYPE_MAX; |
+ AddMethodExpectation(dbus::kDBusPropertiesGet, std::move(response)); |
+ client_->RequestType( |
+ base::Bind(&CopyBiometricType, &returned_biometric_type)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(kFakeBiometricType, returned_biometric_type); |
+ |
+ // Verify that by sending a empty reponse the response is an unknown biometric |
+ // type. Also, logs will get printed. |
Daniel Erat
2017/04/08 00:12:35
what's the reason for mentioning that messages wil
sammiequon
2017/04/08 01:03:30
No, I thought it would be a good heads ups for fil
Daniel Erat
2017/04/08 01:06:03
i think that switching to CallMethod (and letting
sammiequon
2017/04/08 01:31:47
I see. I think think spam was the wrong word, it w
|
+ returned_biometric_type = biod::BiometricType::BIOMETRIC_TYPE_MAX; |
+ AddMethodExpectation(dbus::kDBusPropertiesGet, nullptr); |
+ client_->RequestType( |
+ base::Bind(&CopyBiometricType, &returned_biometric_type)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(biod::BiometricType::BIOMETRIC_TYPE_UNKNOWN, |
+ returned_biometric_type); |
+} |
+ |
+TEST_F(BiodClientTest, TestRequestRecordLabel) { |
+ const std::string kFakeLabel("fakeLabel"); |
+ const dbus::ObjectPath kFakeRecordPath(std::string("/fake/record/path")); |
+ |
+ std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
+ dbus::MessageWriter writer(response.get()); |
+ writer.AppendString(kFakeLabel); |
+ |
+ // Create a fake response with string. The get label call should return this |
+ // exact string. |
+ std::string returned_label = kInvalidString; |
+ AddMethodExpectation(dbus::kDBusPropertiesGet, std::move(response)); |
+ client_->RequestRecordLabel(kFakeRecordPath, |
+ base::Bind(&CopyString, &returned_label)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(kFakeLabel, returned_label); |
+ |
+ // Verify that by sending a empty reponse the response is an empty string. |
+ // Also, logs will get printed. |
+ returned_label = kInvalidString; |
+ AddMethodExpectation(dbus::kDBusPropertiesGet, nullptr); |
+ client_->RequestRecordLabel(kFakeRecordPath, |
+ base::Bind(&CopyString, &returned_label)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ("", returned_label); |
+} |
+ |
// Verify when signals are mocked, an observer will catch the signals as |
// expected. |
TEST_F(BiodClientTest, TestNotifyObservers) { |
@@ -378,31 +494,4 @@ TEST_F(BiodClientTest, TestNotifyObservers) { |
EXPECT_EQ(1, observer.num_auth_scans_received()); |
EXPECT_EQ(1, observer.num_failures_received()); |
} |
- |
-TEST_F(BiodClientTest, TestGetRecordLabel) { |
- const std::string kFakeLabel("fakeLabel"); |
- const dbus::ObjectPath kFakeRecordPath(std::string("/fake/record/path")); |
- |
- std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
- dbus::MessageWriter writer(response.get()); |
- writer.AppendString(kFakeLabel); |
- |
- // Create a fake response with string. The get label call should return this |
- // exact string. |
- std::string returned_label = kInvalidString; |
- AddMethodExpectation(dbus::kDBusPropertiesGet, std::move(response)); |
- client_->RequestRecordLabel(kFakeRecordPath, |
- base::Bind(&CopyString, &returned_label)); |
- base::RunLoop().RunUntilIdle(); |
- EXPECT_EQ(kFakeLabel, returned_label); |
- |
- // Verify that by sending a empty reponse the response is an empty string. |
- // Also, logs will get printed. |
- returned_label = kInvalidString; |
- AddMethodExpectation(dbus::kDBusPropertiesGet, nullptr); |
- client_->RequestRecordLabel(kFakeRecordPath, |
- base::Bind(&CopyString, &returned_label)); |
- base::RunLoop().RunUntilIdle(); |
- EXPECT_EQ("", returned_label); |
-} |
} // namespace chromeos |