| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/dbus/biod/biod_client.h" | 5 #include "chromeos/dbus/biod/biod_client.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // Shorthand for a commonly-used constant. | 26 // Shorthand for a commonly-used constant. |
| 27 const char* kInterface = biod::kBiometricsManagerInterface; | 27 const char* kInterface = biod::kBiometricsManagerInterface; |
| 28 | 28 |
| 29 // Value used to intialize dbus::ObjectPath objects in tests to make it easier | 29 // Value used to intialize dbus::ObjectPath objects in tests to make it easier |
| 30 // to determine when empty values have been assigned. | 30 // to determine when empty values have been assigned. |
| 31 const char kInvalidTestPath[] = "/invalid/test/path"; | 31 const char kInvalidTestPath[] = "/invalid/test/path"; |
| 32 | 32 |
| 33 // Value used to intialize string objects in tests to make it easier to |
| 34 // determine when empty values have been assigned. |
| 35 const char kInvalidString[] = "invalidString"; |
| 36 |
| 33 void CopyObjectPath(dbus::ObjectPath* dest_path, | 37 void CopyObjectPath(dbus::ObjectPath* dest_path, |
| 34 const dbus::ObjectPath& src_path) { | 38 const dbus::ObjectPath& src_path) { |
| 35 CHECK(dest_path); | 39 CHECK(dest_path); |
| 36 *dest_path = src_path; | 40 *dest_path = src_path; |
| 37 } | 41 } |
| 38 | 42 |
| 39 void CopyObjectPathArray( | 43 void CopyObjectPathArray( |
| 40 std::vector<dbus::ObjectPath>* dest_object_paths, | 44 std::vector<dbus::ObjectPath>* dest_object_paths, |
| 41 const std::vector<dbus::ObjectPath>& src_object_paths) { | 45 const std::vector<dbus::ObjectPath>& src_object_paths) { |
| 42 CHECK(dest_object_paths); | 46 CHECK(dest_object_paths); |
| 43 *dest_object_paths = src_object_paths; | 47 *dest_object_paths = src_object_paths; |
| 44 } | 48 } |
| 45 | 49 |
| 50 void CopyString(std::string* dest_str, const std::string& src_str) { |
| 51 CHECK(dest_str); |
| 52 *dest_str = src_str; |
| 53 } |
| 54 |
| 46 // Matcher that verifies that a dbus::Message has member |name|. | 55 // Matcher that verifies that a dbus::Message has member |name|. |
| 47 MATCHER_P(HasMember, name, "") { | 56 MATCHER_P(HasMember, name, "") { |
| 48 if (arg->GetMember() != name) { | 57 if (arg->GetMember() != name) { |
| 49 *result_listener << "has member " << arg->GetMember(); | 58 *result_listener << "has member " << arg->GetMember(); |
| 50 return false; | 59 return false; |
| 51 } | 60 } |
| 52 return true; | 61 return true; |
| 53 } | 62 } |
| 54 | 63 |
| 55 // Runs |callback| with |response|. Needed due to ResponseCallback expecting a | 64 // Runs |callback| with |response|. Needed due to ResponseCallback expecting a |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 dbus::Bus::Options options; | 112 dbus::Bus::Options options; |
| 104 options.bus_type = dbus::Bus::SYSTEM; | 113 options.bus_type = dbus::Bus::SYSTEM; |
| 105 bus_ = new dbus::MockBus(options); | 114 bus_ = new dbus::MockBus(options); |
| 106 | 115 |
| 107 proxy_ = | 116 proxy_ = |
| 108 new dbus::MockObjectProxy(bus_.get(), biod::kBiodServiceName, | 117 new dbus::MockObjectProxy(bus_.get(), biod::kBiodServiceName, |
| 109 dbus::ObjectPath(biod::kBiodServicePath)); | 118 dbus::ObjectPath(biod::kBiodServicePath)); |
| 110 | 119 |
| 111 // |client_|'s Init() method should request a proxy for communicating with | 120 // |client_|'s Init() method should request a proxy for communicating with |
| 112 // biometrics api. | 121 // biometrics api. |
| 113 EXPECT_CALL(*bus_.get(), | 122 EXPECT_CALL(*bus_.get(), GetObjectProxy(biod::kBiodServiceName, _)) |
| 114 GetObjectProxy(biod::kBiodServiceName, | |
| 115 dbus::ObjectPath(biod::kBiodServicePath))) | |
| 116 .WillRepeatedly(Return(proxy_.get())); | 123 .WillRepeatedly(Return(proxy_.get())); |
| 117 | 124 |
| 118 // Save |client_|'s signal callback. | 125 // Save |client_|'s signal callback. |
| 119 EXPECT_CALL(*proxy_.get(), ConnectToSignal(kInterface, _, _, _)) | 126 EXPECT_CALL(*proxy_.get(), ConnectToSignal(kInterface, _, _, _)) |
| 120 .WillRepeatedly(Invoke(this, &BiodClientTest::ConnectToSignal)); | 127 .WillRepeatedly(Invoke(this, &BiodClientTest::ConnectToSignal)); |
| 121 | 128 |
| 122 client_.reset(BiodClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION)); | 129 client_.reset(BiodClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION)); |
| 123 client_->Init(bus_.get()); | 130 client_->Init(bus_.get()); |
| 124 | 131 |
| 125 // Execute callbacks posted by Init(). | 132 // Execute callbacks posted by Init(). |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 const dbus::ObjectPath kFakeObjectPath(std::string("/fake/object/path")); | 284 const dbus::ObjectPath kFakeObjectPath(std::string("/fake/object/path")); |
| 278 const dbus::ObjectPath kFakeObjectPath2(std::string("/fake/object/path2")); | 285 const dbus::ObjectPath kFakeObjectPath2(std::string("/fake/object/path2")); |
| 279 const std::vector<dbus::ObjectPath> kFakeObjectPaths = {kFakeObjectPath, | 286 const std::vector<dbus::ObjectPath> kFakeObjectPaths = {kFakeObjectPath, |
| 280 kFakeObjectPath2}; | 287 kFakeObjectPath2}; |
| 281 | 288 |
| 282 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 289 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 283 dbus::MessageWriter writer(response.get()); | 290 dbus::MessageWriter writer(response.get()); |
| 284 writer.AppendArrayOfObjectPaths(kFakeObjectPaths); | 291 writer.AppendArrayOfObjectPaths(kFakeObjectPaths); |
| 285 | 292 |
| 286 // Create a fake response with an array of fake object paths. The get | 293 // Create a fake response with an array of fake object paths. The get |
| 287 // enrollments call should return this array of object paths. | 294 // records for user call should return this array of object paths. |
| 288 AddMethodExpectation(biod::kBiometricsManagerGetRecordsForUserMethod, | 295 AddMethodExpectation(biod::kBiometricsManagerGetRecordsForUserMethod, |
| 289 std::move(response)); | 296 std::move(response)); |
| 290 std::vector<dbus::ObjectPath> returned_object_paths = { | 297 std::vector<dbus::ObjectPath> returned_object_paths = { |
| 291 dbus::ObjectPath(kInvalidTestPath)}; | 298 dbus::ObjectPath(kInvalidTestPath)}; |
| 292 client_->GetRecordsForUser( | 299 client_->GetRecordsForUser( |
| 293 kFakeId, base::Bind(&CopyObjectPathArray, &returned_object_paths)); | 300 kFakeId, base::Bind(&CopyObjectPathArray, &returned_object_paths)); |
| 294 base::RunLoop().RunUntilIdle(); | 301 base::RunLoop().RunUntilIdle(); |
| 295 EXPECT_EQ(kFakeObjectPaths, returned_object_paths); | 302 EXPECT_EQ(kFakeObjectPaths, returned_object_paths); |
| 296 | 303 |
| 297 // Verify that by sending a empty reponse the response is an empty array of | 304 // Verify that by sending a empty reponse the response is an empty array of |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 EXPECT_EQ(1, observer.num_failures_received()); | 371 EXPECT_EQ(1, observer.num_failures_received()); |
| 365 | 372 |
| 366 client_->RemoveObserver(&observer); | 373 client_->RemoveObserver(&observer); |
| 367 | 374 |
| 368 EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete); | 375 EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete); |
| 369 EmitAuthScanDoneSignal(scan_signal, test_attempt); | 376 EmitAuthScanDoneSignal(scan_signal, test_attempt); |
| 370 EXPECT_EQ(1, observer.num_enroll_scans_received()); | 377 EXPECT_EQ(1, observer.num_enroll_scans_received()); |
| 371 EXPECT_EQ(1, observer.num_auth_scans_received()); | 378 EXPECT_EQ(1, observer.num_auth_scans_received()); |
| 372 EXPECT_EQ(1, observer.num_failures_received()); | 379 EXPECT_EQ(1, observer.num_failures_received()); |
| 373 } | 380 } |
| 381 |
| 382 TEST_F(BiodClientTest, TestGetRecordLabel) { |
| 383 const std::string kFakeLabel("fakeLabel"); |
| 384 const dbus::ObjectPath kFakeRecordPath(std::string("/fake/record/path")); |
| 385 |
| 386 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 387 dbus::MessageWriter writer(response.get()); |
| 388 writer.AppendString(kFakeLabel); |
| 389 |
| 390 // Create a fake response with string. The get label call should return this |
| 391 // exact string. |
| 392 std::string returned_label = kInvalidString; |
| 393 AddMethodExpectation(dbus::kDBusPropertiesGet, std::move(response)); |
| 394 client_->RequestRecordLabel(kFakeRecordPath, |
| 395 base::Bind(&CopyString, &returned_label)); |
| 396 base::RunLoop().RunUntilIdle(); |
| 397 EXPECT_EQ(kFakeLabel, returned_label); |
| 398 |
| 399 // Verify that by sending a empty reponse the response is an empty string. |
| 400 // Also, logs will get printed. |
| 401 returned_label = kInvalidString; |
| 402 AddMethodExpectation(dbus::kDBusPropertiesGet, nullptr); |
| 403 client_->RequestRecordLabel(kFakeRecordPath, |
| 404 base::Bind(&CopyString, &returned_label)); |
| 405 base::RunLoop().RunUntilIdle(); |
| 406 EXPECT_EQ("", returned_label); |
| 407 } |
| 374 } // namespace chromeos | 408 } // namespace chromeos |
| OLD | NEW |