| 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..0d950d781854e92fa4408476d464765c3ef5e687 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/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());
|
| }
|
|
|
| @@ -389,20 +347,20 @@ TEST_F(BiodClientTest, TestGetRecordLabel) {
|
|
|
| // Create a fake response with string. The get label call should return this
|
| // exact string.
|
| - std::string returned_label = kInvalidString;
|
| + std::string returned_str = kInvalidString;
|
| AddMethodExpectation(dbus::kDBusPropertiesGet, std::move(response));
|
| - client_->RequestRecordLabel(kFakeRecordPath,
|
| - base::Bind(&CopyString, &returned_label));
|
| + client_->RequestRecordLabel(
|
| + kFakeRecordPath, base::Bind(&test_utils::CopyString, &returned_str));
|
| base::RunLoop().RunUntilIdle();
|
| - EXPECT_EQ(kFakeLabel, returned_label);
|
| + EXPECT_EQ(kFakeLabel, returned_str);
|
|
|
| // Verify that by sending a empty reponse the response is an empty string.
|
| // Also, logs will get printed.
|
| - returned_label = kInvalidString;
|
| + returned_str = kInvalidString;
|
| AddMethodExpectation(dbus::kDBusPropertiesGet, nullptr);
|
| - client_->RequestRecordLabel(kFakeRecordPath,
|
| - base::Bind(&CopyString, &returned_label));
|
| + client_->RequestRecordLabel(
|
| + kFakeRecordPath, base::Bind(&test_utils::CopyString, &returned_str));
|
| base::RunLoop().RunUntilIdle();
|
| - EXPECT_EQ("", returned_label);
|
| + EXPECT_EQ("", returned_str);
|
| }
|
| } // namespace chromeos
|
|
|