Chromium Code Reviews| 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..e491792216f4c926e86d783c767a2fa659c0bf6e 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)); |
| @@ -258,7 +268,7 @@ TEST_F(BiodClientTest, TestStartEnrollSession) { |
| EXPECT_EQ(kFakeObjectPath, returned_path); |
| // Verify that by sending a empty reponse or a improperly formatted one, the |
| - // response is an empty object path. Also, logs will get printed. |
| + // response is an empty object path. |
| AddMethodExpectation(biod::kBiometricsManagerStartEnrollSessionMethod, |
| nullptr); |
| returned_path = dbus::ObjectPath(kInvalidTestPath); |
| @@ -302,7 +312,7 @@ TEST_F(BiodClientTest, TestGetRecordsForUser) { |
| EXPECT_EQ(kFakeObjectPaths, returned_object_paths); |
| // Verify that by sending a empty reponse the response is an empty array of |
| - // object paths. Also, logs will get printed. |
| + // object paths. |
| AddMethodExpectation(biod::kBiometricsManagerGetRecordsForUserMethod, |
| nullptr); |
| returned_object_paths = {dbus::ObjectPath(kInvalidTestPath)}; |
| @@ -312,6 +322,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 |
|
Daniel Erat
2017/04/08 01:13:32
"Create an empty response to simulate success."
sammiequon
2017/04/08 01:31:48
Done.
|
| + // return success. |
| + AddMethodExpectation(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 |
|
Daniel Erat
2017/04/08 01:13:32
"Return an empty response to simulate failure." wo
sammiequon
2017/04/08 01:31:48
Done.
|
| + // return failure. |
| + AddMethodExpectation(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")); |
| @@ -329,7 +364,7 @@ TEST_F(BiodClientTest, TestStartAuthentication) { |
| EXPECT_EQ(kFakeObjectPath, returned_path); |
| // Verify that by sending a empty reponse or a improperly formatted one, the |
| - // response is an empty object path. Also, logs will get printed. |
| + // response is an empty object path. |
| AddMethodExpectation(biod::kBiometricsManagerStartAuthSessionMethod, nullptr); |
| returned_path = dbus::ObjectPath(kInvalidTestPath); |
| client_->StartAuthSession(base::Bind(&CopyObjectPath, &returned_path)); |
| @@ -347,6 +382,61 @@ TEST_F(BiodClientTest, TestStartAuthentication) { |
| EXPECT_EQ(dbus::ObjectPath(), returned_path); |
| } |
| +TEST_F(BiodClientTest, TestRequestBiometricType) { |
| + const biod::BiometricType kFakeBiometricType = |
| + biod::BiometricType::BIOMETRIC_TYPE_FINGERPRINT; |
|
Daniel Erat
2017/04/08 01:13:32
oh, this isn't actually an enum class, right? i th
sammiequon
2017/04/08 01:31:48
Is it prefer not to. I usually just did it anyways
Daniel Erat
2017/04/08 01:39:23
yep, shorter's better. iirc the BIOMETRIC_TYPE_ pr
sammiequon
2017/04/08 04:43:46
Acknowledged.
|
| + |
| + 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. |
| + 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. |
|
Daniel Erat
2017/04/08 01:13:32
nit: "the response is" -> "the result is" may be c
sammiequon
2017/04/08 01:31:48
Done.
|
| + 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 +468,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 |