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..1fc110d966d7df04878e51ca60172c311f0acb0b 100644 |
--- a/chromeos/dbus/biod/biod_client_unittest.cc |
+++ b/chromeos/dbus/biod/biod_client_unittest.cc |
@@ -9,6 +9,7 @@ |
#include "base/bind.h" |
#include "base/run_loop.h" |
+#include "chromeos/dbus/biod/biod_test_utils.h" |
#include "dbus/mock_bus.h" |
#include "dbus/mock_object_proxy.h" |
#include "dbus/object_path.h" |
@@ -34,24 +35,6 @@ const char kInvalidTestPath[] = "/invalid/test/path"; |
// determine when empty values have been assigned. |
const char kInvalidString[] = "invalidString"; |
-void CopyObjectPath(dbus::ObjectPath* dest_path, |
- const dbus::ObjectPath& src_path) { |
- CHECK(dest_path); |
- *dest_path = src_path; |
-} |
- |
-void CopyObjectPathArray( |
- std::vector<dbus::ObjectPath>* dest_object_paths, |
- const std::vector<dbus::ObjectPath>& src_object_paths) { |
- CHECK(dest_object_paths); |
- *dest_object_paths = src_object_paths; |
-} |
- |
-void CopyString(std::string* dest_str, const std::string& src_str) { |
- CHECK(dest_str); |
- *dest_str = src_str; |
-} |
- |
// Matcher that verifies that a dbus::Message has member |name|. |
MATCHER_P(HasMember, name, "") { |
if (arg->GetMember() != name) { |
@@ -68,39 +51,6 @@ void RunResponseCallback(dbus::ObjectProxy::ResponseCallback callback, |
callback.Run(response.get()); |
} |
-// Implementation of BiodClient::Observer. |
-class TestBiodObserver : public BiodClient::Observer { |
- public: |
- TestBiodObserver() {} |
- ~TestBiodObserver() override {} |
- |
- int num_enroll_scans_received() const { return num_enroll_scans_received_; } |
- int num_auth_scans_received() const { return num_auth_scans_received_; } |
- int num_failures_received() const { return num_failures_received_; } |
- |
- // BiodClient::Observer: |
- void BiodServiceRestarted() override {} |
- |
- void BiodEnrollScanDoneReceived(biod::ScanResult scan_result, |
- bool enroll_sesion_complete) override { |
- num_enroll_scans_received_++; |
- } |
- |
- void BiodAuthScanDoneReceived(biod::ScanResult scan_result, |
- const AuthScanMatches& matches) override { |
- num_auth_scans_received_++; |
- } |
- |
- void BiodSessionFailedReceived() override { num_failures_received_++; } |
- |
- private: |
- int num_enroll_scans_received_ = 0; |
- int num_auth_scans_received_ = 0; |
- int num_failures_received_ = 0; |
- |
- DISALLOW_COPY_AND_ASSIGN(TestBiodObserver); |
-}; |
- |
} // namespace |
class BiodClientTest : public testing::Test { |
@@ -252,8 +202,9 @@ TEST_F(BiodClientTest, TestStartEnrollSession) { |
AddMethodExpectation(biod::kBiometricsManagerStartEnrollSessionMethod, |
std::move(response)); |
dbus::ObjectPath returned_path(kInvalidTestPath); |
- client_->StartEnrollSession(kFakeId, kFakeLabel, |
- base::Bind(&CopyObjectPath, &returned_path)); |
+ client_->StartEnrollSession( |
+ kFakeId, kFakeLabel, |
+ base::Bind(&test_utils::CopyObjectPath, &returned_path)); |
base::RunLoop().RunUntilIdle(); |
EXPECT_EQ(kFakeObjectPath, returned_path); |
@@ -262,8 +213,9 @@ TEST_F(BiodClientTest, TestStartEnrollSession) { |
AddMethodExpectation(biod::kBiometricsManagerStartEnrollSessionMethod, |
nullptr); |
returned_path = dbus::ObjectPath(kInvalidTestPath); |
- client_->StartEnrollSession(kFakeId, kFakeLabel, |
- base::Bind(&CopyObjectPath, &returned_path)); |
+ client_->StartEnrollSession( |
+ kFakeId, kFakeLabel, |
+ base::Bind(&test_utils::CopyObjectPath, &returned_path)); |
base::RunLoop().RunUntilIdle(); |
EXPECT_EQ(dbus::ObjectPath(), returned_path); |
@@ -273,8 +225,9 @@ TEST_F(BiodClientTest, TestStartEnrollSession) { |
AddMethodExpectation(biod::kBiometricsManagerStartEnrollSessionMethod, |
std::move(bad_response)); |
returned_path = dbus::ObjectPath(kInvalidTestPath); |
- client_->StartEnrollSession(kFakeId, kFakeLabel, |
- base::Bind(&CopyObjectPath, &returned_path)); |
+ client_->StartEnrollSession( |
+ kFakeId, kFakeLabel, |
+ base::Bind(&test_utils::CopyObjectPath, &returned_path)); |
base::RunLoop().RunUntilIdle(); |
EXPECT_EQ(dbus::ObjectPath(), returned_path); |
} |
@@ -297,7 +250,8 @@ TEST_F(BiodClientTest, TestGetRecordsForUser) { |
std::vector<dbus::ObjectPath> returned_object_paths = { |
dbus::ObjectPath(kInvalidTestPath)}; |
client_->GetRecordsForUser( |
- kFakeId, base::Bind(&CopyObjectPathArray, &returned_object_paths)); |
+ kFakeId, |
+ base::Bind(&test_utils::CopyObjectPathArray, &returned_object_paths)); |
base::RunLoop().RunUntilIdle(); |
EXPECT_EQ(kFakeObjectPaths, returned_object_paths); |
@@ -307,7 +261,8 @@ TEST_F(BiodClientTest, TestGetRecordsForUser) { |
nullptr); |
returned_object_paths = {dbus::ObjectPath(kInvalidTestPath)}; |
client_->GetRecordsForUser( |
- kFakeId, base::Bind(&CopyObjectPathArray, &returned_object_paths)); |
+ kFakeId, |
+ base::Bind(&test_utils::CopyObjectPathArray, &returned_object_paths)); |
base::RunLoop().RunUntilIdle(); |
EXPECT_EQ(std::vector<dbus::ObjectPath>(), returned_object_paths); |
} |
@@ -324,7 +279,8 @@ TEST_F(BiodClientTest, TestStartAuthentication) { |
AddMethodExpectation(biod::kBiometricsManagerStartAuthSessionMethod, |
std::move(response)); |
dbus::ObjectPath returned_path(kInvalidTestPath); |
- client_->StartAuthSession(base::Bind(&CopyObjectPath, &returned_path)); |
+ client_->StartAuthSession( |
+ base::Bind(&test_utils::CopyObjectPath, &returned_path)); |
base::RunLoop().RunUntilIdle(); |
EXPECT_EQ(kFakeObjectPath, returned_path); |
@@ -332,7 +288,8 @@ TEST_F(BiodClientTest, TestStartAuthentication) { |
// response is an empty object path. Also, logs will get printed. |
AddMethodExpectation(biod::kBiometricsManagerStartAuthSessionMethod, nullptr); |
returned_path = dbus::ObjectPath(kInvalidTestPath); |
- client_->StartAuthSession(base::Bind(&CopyObjectPath, &returned_path)); |
+ client_->StartAuthSession( |
+ base::Bind(&test_utils::CopyObjectPath, &returned_path)); |
base::RunLoop().RunUntilIdle(); |
EXPECT_EQ(dbus::ObjectPath(), returned_path); |
@@ -342,7 +299,8 @@ TEST_F(BiodClientTest, TestStartAuthentication) { |
AddMethodExpectation(biod::kBiometricsManagerStartAuthSessionMethod, |
std::move(bad_response)); |
returned_path = dbus::ObjectPath(kInvalidTestPath); |
- client_->StartAuthSession(base::Bind(&CopyObjectPath, &returned_path)); |
+ client_->StartAuthSession( |
+ base::Bind(&test_utils::CopyObjectPath, &returned_path)); |
base::RunLoop().RunUntilIdle(); |
EXPECT_EQ(dbus::ObjectPath(), returned_path); |
} |
@@ -350,22 +308,22 @@ TEST_F(BiodClientTest, TestStartAuthentication) { |
// Verify when signals are mocked, an observer will catch the signals as |
// expected. |
TEST_F(BiodClientTest, TestNotifyObservers) { |
- TestBiodObserver observer; |
+ test_utils::TestBiodObserver observer; |
client_->AddObserver(&observer); |
EXPECT_TRUE(client_->HasObserver(&observer)); |
const biod::ScanResult scan_signal = biod::ScanResult::SCAN_RESULT_SUCCESS; |
const bool enroll_session_complete = false; |
const AuthScanMatches test_attempt; |
- EXPECT_EQ(0, observer.num_enroll_scans_received()); |
- EXPECT_EQ(0, observer.num_auth_scans_received()); |
+ EXPECT_EQ(0, observer.NumEnrollScansReceived()); |
+ EXPECT_EQ(0, observer.NumAuthScansReceived()); |
EXPECT_EQ(0, observer.num_failures_received()); |
EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete); |
- EXPECT_EQ(1, observer.num_enroll_scans_received()); |
+ EXPECT_EQ(1, observer.NumEnrollScansReceived()); |
EmitAuthScanDoneSignal(scan_signal, test_attempt); |
- EXPECT_EQ(1, observer.num_auth_scans_received()); |
+ EXPECT_EQ(1, observer.NumAuthScansReceived()); |
EmitScanFailedSignal(); |
EXPECT_EQ(1, observer.num_failures_received()); |
@@ -374,8 +332,8 @@ TEST_F(BiodClientTest, TestNotifyObservers) { |
EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete); |
EmitAuthScanDoneSignal(scan_signal, test_attempt); |
- EXPECT_EQ(1, observer.num_enroll_scans_received()); |
- EXPECT_EQ(1, observer.num_auth_scans_received()); |
+ EXPECT_EQ(1, observer.NumEnrollScansReceived()); |
+ EXPECT_EQ(1, observer.NumAuthScansReceived()); |
EXPECT_EQ(1, observer.num_failures_received()); |
} |
@@ -391,8 +349,8 @@ TEST_F(BiodClientTest, TestGetRecordLabel) { |
// exact string. |
std::string returned_label = kInvalidString; |
AddMethodExpectation(dbus::kDBusPropertiesGet, std::move(response)); |
- client_->RequestRecordLabel(kFakeRecordPath, |
- base::Bind(&CopyString, &returned_label)); |
+ client_->RequestRecordLabel( |
+ kFakeRecordPath, base::Bind(&test_utils::CopyLabel, &returned_label)); |
base::RunLoop().RunUntilIdle(); |
EXPECT_EQ(kFakeLabel, returned_label); |
@@ -400,8 +358,8 @@ TEST_F(BiodClientTest, TestGetRecordLabel) { |
// Also, logs will get printed. |
returned_label = kInvalidString; |
AddMethodExpectation(dbus::kDBusPropertiesGet, nullptr); |
- client_->RequestRecordLabel(kFakeRecordPath, |
- base::Bind(&CopyString, &returned_label)); |
+ client_->RequestRecordLabel( |
+ kFakeRecordPath, base::Bind(&test_utils::CopyLabel, &returned_label)); |
base::RunLoop().RunUntilIdle(); |
EXPECT_EQ("", returned_label); |
} |