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" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "chromeos/dbus/biod/test_utils.h" |
12 #include "dbus/mock_bus.h" | 13 #include "dbus/mock_bus.h" |
13 #include "dbus/mock_object_proxy.h" | 14 #include "dbus/mock_object_proxy.h" |
14 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 using ::testing::_; | 19 using ::testing::_; |
19 using ::testing::Invoke; | 20 using ::testing::Invoke; |
20 using ::testing::Return; | 21 using ::testing::Return; |
21 | 22 |
22 namespace chromeos { | 23 namespace chromeos { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 // Shorthand for a commonly-used constant. | 27 // Shorthand for a commonly-used constant. |
27 const char* kInterface = biod::kBiometricsManagerInterface; | 28 const char* kInterface = biod::kBiometricsManagerInterface; |
28 | 29 |
29 // Value used to intialize dbus::ObjectPath objects in tests to make it easier | 30 // Value used to intialize dbus::ObjectPath objects in tests to make it easier |
30 // to determine when empty values have been assigned. | 31 // to determine when empty values have been assigned. |
31 const char kInvalidTestPath[] = "/invalid/test/path"; | 32 const char kInvalidTestPath[] = "/invalid/test/path"; |
32 | 33 |
33 // Value used to intialize string objects in tests to make it easier to | 34 // Value used to intialize string objects in tests to make it easier to |
34 // determine when empty values have been assigned. | 35 // determine when empty values have been assigned. |
35 const char kInvalidString[] = "invalidString"; | 36 const char kInvalidString[] = "invalidString"; |
36 | 37 |
37 void CopyObjectPath(dbus::ObjectPath* dest_path, | |
38 const dbus::ObjectPath& src_path) { | |
39 CHECK(dest_path); | |
40 *dest_path = src_path; | |
41 } | |
42 | |
43 void CopyObjectPathArray( | |
44 std::vector<dbus::ObjectPath>* dest_object_paths, | |
45 const std::vector<dbus::ObjectPath>& src_object_paths) { | |
46 CHECK(dest_object_paths); | |
47 *dest_object_paths = src_object_paths; | |
48 } | |
49 | |
50 void CopyString(std::string* dest_str, const std::string& src_str) { | |
51 CHECK(dest_str); | |
52 *dest_str = src_str; | |
53 } | |
54 | |
55 void CopyDBusMethodCallStatus(DBusMethodCallStatus* dest_status, | |
56 DBusMethodCallStatus src_status) { | |
57 CHECK(dest_status); | |
58 *dest_status = src_status; | |
59 } | |
60 | |
61 void CopyBiometricType(biod::BiometricType* dest_type, | |
62 biod::BiometricType src_type) { | |
63 CHECK(dest_type); | |
64 *dest_type = src_type; | |
65 } | |
66 | |
67 // Matcher that verifies that a dbus::Message has member |name|. | 38 // Matcher that verifies that a dbus::Message has member |name|. |
68 MATCHER_P(HasMember, name, "") { | 39 MATCHER_P(HasMember, name, "") { |
69 if (arg->GetMember() != name) { | 40 if (arg->GetMember() != name) { |
70 *result_listener << "has member " << arg->GetMember(); | 41 *result_listener << "has member " << arg->GetMember(); |
71 return false; | 42 return false; |
72 } | 43 } |
73 return true; | 44 return true; |
74 } | 45 } |
75 | 46 |
76 // Runs |callback| with |response|. Needed due to ResponseCallback expecting a | 47 // Runs |callback| with |response|. Needed due to ResponseCallback expecting a |
77 // bare pointer rather than an std::unique_ptr. | 48 // bare pointer rather than an std::unique_ptr. |
78 void RunResponseCallback(dbus::ObjectProxy::ResponseCallback callback, | 49 void RunResponseCallback(dbus::ObjectProxy::ResponseCallback callback, |
79 std::unique_ptr<dbus::Response> response) { | 50 std::unique_ptr<dbus::Response> response) { |
80 callback.Run(response.get()); | 51 callback.Run(response.get()); |
81 } | 52 } |
82 | 53 |
83 // Implementation of BiodClient::Observer. | |
84 class TestBiodObserver : public BiodClient::Observer { | |
85 public: | |
86 TestBiodObserver() {} | |
87 ~TestBiodObserver() override {} | |
88 | |
89 int num_enroll_scans_received() const { return num_enroll_scans_received_; } | |
90 int num_auth_scans_received() const { return num_auth_scans_received_; } | |
91 int num_failures_received() const { return num_failures_received_; } | |
92 | |
93 // BiodClient::Observer: | |
94 void BiodServiceRestarted() override {} | |
95 | |
96 void BiodEnrollScanDoneReceived(biod::ScanResult scan_result, | |
97 bool enroll_sesion_complete) override { | |
98 num_enroll_scans_received_++; | |
99 } | |
100 | |
101 void BiodAuthScanDoneReceived(biod::ScanResult scan_result, | |
102 const AuthScanMatches& matches) override { | |
103 num_auth_scans_received_++; | |
104 } | |
105 | |
106 void BiodSessionFailedReceived() override { num_failures_received_++; } | |
107 | |
108 private: | |
109 int num_enroll_scans_received_ = 0; | |
110 int num_auth_scans_received_ = 0; | |
111 int num_failures_received_ = 0; | |
112 | |
113 DISALLOW_COPY_AND_ASSIGN(TestBiodObserver); | |
114 }; | |
115 | |
116 } // namespace | 54 } // namespace |
117 | 55 |
118 class BiodClientTest : public testing::Test { | 56 class BiodClientTest : public testing::Test { |
119 public: | 57 public: |
120 BiodClientTest() {} | 58 BiodClientTest() {} |
121 ~BiodClientTest() override {} | 59 ~BiodClientTest() override {} |
122 | 60 |
123 void SetUp() override { | 61 void SetUp() override { |
124 dbus::Bus::Options options; | 62 dbus::Bus::Options options; |
125 options.bus_type = dbus::Bus::SYSTEM; | 63 options.bus_type = dbus::Bus::SYSTEM; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 195 |
258 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 196 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
259 dbus::MessageWriter writer(response.get()); | 197 dbus::MessageWriter writer(response.get()); |
260 writer.AppendObjectPath(kFakeObjectPath); | 198 writer.AppendObjectPath(kFakeObjectPath); |
261 | 199 |
262 // Create a fake response with a fake object path. The start enroll | 200 // Create a fake response with a fake object path. The start enroll |
263 // call should return this object path. | 201 // call should return this object path. |
264 AddMethodExpectation(biod::kBiometricsManagerStartEnrollSessionMethod, | 202 AddMethodExpectation(biod::kBiometricsManagerStartEnrollSessionMethod, |
265 std::move(response)); | 203 std::move(response)); |
266 dbus::ObjectPath returned_path(kInvalidTestPath); | 204 dbus::ObjectPath returned_path(kInvalidTestPath); |
267 client_->StartEnrollSession(kFakeId, kFakeLabel, | 205 client_->StartEnrollSession( |
268 base::Bind(&CopyObjectPath, &returned_path)); | 206 kFakeId, kFakeLabel, |
| 207 base::Bind(&test_utils::CopyObjectPath, &returned_path)); |
269 base::RunLoop().RunUntilIdle(); | 208 base::RunLoop().RunUntilIdle(); |
270 EXPECT_EQ(kFakeObjectPath, returned_path); | 209 EXPECT_EQ(kFakeObjectPath, returned_path); |
271 | 210 |
272 // Verify that by sending a empty reponse or a improperly formatted one, the | 211 // Verify that by sending a empty reponse or a improperly formatted one, the |
273 // response is an empty object path. | 212 // response is an empty object path. |
274 AddMethodExpectation(biod::kBiometricsManagerStartEnrollSessionMethod, | 213 AddMethodExpectation(biod::kBiometricsManagerStartEnrollSessionMethod, |
275 nullptr); | 214 nullptr); |
276 returned_path = dbus::ObjectPath(kInvalidTestPath); | 215 returned_path = dbus::ObjectPath(kInvalidTestPath); |
277 client_->StartEnrollSession(kFakeId, kFakeLabel, | 216 client_->StartEnrollSession( |
278 base::Bind(&CopyObjectPath, &returned_path)); | 217 kFakeId, kFakeLabel, |
| 218 base::Bind(&test_utils::CopyObjectPath, &returned_path)); |
279 base::RunLoop().RunUntilIdle(); | 219 base::RunLoop().RunUntilIdle(); |
280 EXPECT_EQ(dbus::ObjectPath(), returned_path); | 220 EXPECT_EQ(dbus::ObjectPath(), returned_path); |
281 | 221 |
282 std::unique_ptr<dbus::Response> bad_response(dbus::Response::CreateEmpty()); | 222 std::unique_ptr<dbus::Response> bad_response(dbus::Response::CreateEmpty()); |
283 dbus::MessageWriter bad_writer(bad_response.get()); | 223 dbus::MessageWriter bad_writer(bad_response.get()); |
284 bad_writer.AppendString(""); | 224 bad_writer.AppendString(""); |
285 AddMethodExpectation(biod::kBiometricsManagerStartEnrollSessionMethod, | 225 AddMethodExpectation(biod::kBiometricsManagerStartEnrollSessionMethod, |
286 std::move(bad_response)); | 226 std::move(bad_response)); |
287 returned_path = dbus::ObjectPath(kInvalidTestPath); | 227 returned_path = dbus::ObjectPath(kInvalidTestPath); |
288 client_->StartEnrollSession(kFakeId, kFakeLabel, | 228 client_->StartEnrollSession( |
289 base::Bind(&CopyObjectPath, &returned_path)); | 229 kFakeId, kFakeLabel, |
| 230 base::Bind(&test_utils::CopyObjectPath, &returned_path)); |
290 base::RunLoop().RunUntilIdle(); | 231 base::RunLoop().RunUntilIdle(); |
291 EXPECT_EQ(dbus::ObjectPath(), returned_path); | 232 EXPECT_EQ(dbus::ObjectPath(), returned_path); |
292 } | 233 } |
293 | 234 |
294 TEST_F(BiodClientTest, TestGetRecordsForUser) { | 235 TEST_F(BiodClientTest, TestGetRecordsForUser) { |
295 const std::string kFakeId("fakeId"); | 236 const std::string kFakeId("fakeId"); |
296 const dbus::ObjectPath kFakeObjectPath(std::string("/fake/object/path")); | 237 const dbus::ObjectPath kFakeObjectPath(std::string("/fake/object/path")); |
297 const dbus::ObjectPath kFakeObjectPath2(std::string("/fake/object/path2")); | 238 const dbus::ObjectPath kFakeObjectPath2(std::string("/fake/object/path2")); |
298 const std::vector<dbus::ObjectPath> kFakeObjectPaths = {kFakeObjectPath, | 239 const std::vector<dbus::ObjectPath> kFakeObjectPaths = {kFakeObjectPath, |
299 kFakeObjectPath2}; | 240 kFakeObjectPath2}; |
300 | 241 |
301 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 242 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
302 dbus::MessageWriter writer(response.get()); | 243 dbus::MessageWriter writer(response.get()); |
303 writer.AppendArrayOfObjectPaths(kFakeObjectPaths); | 244 writer.AppendArrayOfObjectPaths(kFakeObjectPaths); |
304 | 245 |
305 // Create a fake response with an array of fake object paths. The get | 246 // Create a fake response with an array of fake object paths. The get |
306 // records for user call should return this array of object paths. | 247 // records for user call should return this array of object paths. |
307 AddMethodExpectation(biod::kBiometricsManagerGetRecordsForUserMethod, | 248 AddMethodExpectation(biod::kBiometricsManagerGetRecordsForUserMethod, |
308 std::move(response)); | 249 std::move(response)); |
309 std::vector<dbus::ObjectPath> returned_object_paths = { | 250 std::vector<dbus::ObjectPath> returned_object_paths = { |
310 dbus::ObjectPath(kInvalidTestPath)}; | 251 dbus::ObjectPath(kInvalidTestPath)}; |
311 client_->GetRecordsForUser( | 252 client_->GetRecordsForUser( |
312 kFakeId, base::Bind(&CopyObjectPathArray, &returned_object_paths)); | 253 kFakeId, |
| 254 base::Bind(&test_utils::CopyObjectPathArray, &returned_object_paths)); |
313 base::RunLoop().RunUntilIdle(); | 255 base::RunLoop().RunUntilIdle(); |
314 EXPECT_EQ(kFakeObjectPaths, returned_object_paths); | 256 EXPECT_EQ(kFakeObjectPaths, returned_object_paths); |
315 | 257 |
316 // Verify that by sending a empty reponse the response is an empty array of | 258 // Verify that by sending a empty reponse the response is an empty array of |
317 // object paths. | 259 // object paths. |
318 AddMethodExpectation(biod::kBiometricsManagerGetRecordsForUserMethod, | 260 AddMethodExpectation(biod::kBiometricsManagerGetRecordsForUserMethod, |
319 nullptr); | 261 nullptr); |
320 returned_object_paths = {dbus::ObjectPath(kInvalidTestPath)}; | 262 returned_object_paths = {dbus::ObjectPath(kInvalidTestPath)}; |
321 client_->GetRecordsForUser( | 263 client_->GetRecordsForUser( |
322 kFakeId, base::Bind(&CopyObjectPathArray, &returned_object_paths)); | 264 kFakeId, |
| 265 base::Bind(&test_utils::CopyObjectPathArray, &returned_object_paths)); |
323 base::RunLoop().RunUntilIdle(); | 266 base::RunLoop().RunUntilIdle(); |
324 EXPECT_EQ(std::vector<dbus::ObjectPath>(), returned_object_paths); | 267 EXPECT_EQ(std::vector<dbus::ObjectPath>(), returned_object_paths); |
325 } | 268 } |
326 | 269 |
327 TEST_F(BiodClientTest, TestDestroyAllRecords) { | 270 TEST_F(BiodClientTest, TestDestroyAllRecords) { |
328 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 271 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
329 dbus::MessageWriter writer(response.get()); | 272 dbus::MessageWriter writer(response.get()); |
330 | 273 |
331 // Create an empty response to simulate success. | 274 // Create an empty response to simulate success. |
332 AddMethodExpectation(biod::kBiometricsManagerDestroyAllRecordsMethod, | 275 AddMethodExpectation(biod::kBiometricsManagerDestroyAllRecordsMethod, |
333 std::move(response)); | 276 std::move(response)); |
334 DBusMethodCallStatus returned_status = static_cast<DBusMethodCallStatus>(-1); | 277 DBusMethodCallStatus returned_status = static_cast<DBusMethodCallStatus>(-1); |
335 client_->DestroyAllRecords( | 278 client_->DestroyAllRecords( |
336 base::Bind(&CopyDBusMethodCallStatus, &returned_status)); | 279 base::Bind(&test_utils::CopyDBusMethodCallStatus, &returned_status)); |
337 base::RunLoop().RunUntilIdle(); | 280 base::RunLoop().RunUntilIdle(); |
338 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, returned_status); | 281 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, returned_status); |
339 | 282 |
340 // Return a null response to simulate failure. | 283 // Return a null response to simulate failure. |
341 AddMethodExpectation(biod::kBiometricsManagerDestroyAllRecordsMethod, | 284 AddMethodExpectation(biod::kBiometricsManagerDestroyAllRecordsMethod, |
342 nullptr); | 285 nullptr); |
343 returned_status = static_cast<DBusMethodCallStatus>(-1); | 286 returned_status = static_cast<DBusMethodCallStatus>(-1); |
344 client_->DestroyAllRecords( | 287 client_->DestroyAllRecords( |
345 base::Bind(&CopyDBusMethodCallStatus, &returned_status)); | 288 base::Bind(&test_utils::CopyDBusMethodCallStatus, &returned_status)); |
346 base::RunLoop().RunUntilIdle(); | 289 base::RunLoop().RunUntilIdle(); |
347 EXPECT_EQ(DBUS_METHOD_CALL_FAILURE, returned_status); | 290 EXPECT_EQ(DBUS_METHOD_CALL_FAILURE, returned_status); |
348 } | 291 } |
349 | 292 |
350 TEST_F(BiodClientTest, TestStartAuthentication) { | 293 TEST_F(BiodClientTest, TestStartAuthentication) { |
351 const dbus::ObjectPath kFakeObjectPath(std::string("/fake/object/path")); | 294 const dbus::ObjectPath kFakeObjectPath(std::string("/fake/object/path")); |
352 | 295 |
353 // Create a fake response with a fake object path. The start authentication | 296 // Create a fake response with a fake object path. The start authentication |
354 // call should return this object path. | 297 // call should return this object path. |
355 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 298 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
356 dbus::MessageWriter writer(response.get()); | 299 dbus::MessageWriter writer(response.get()); |
357 writer.AppendObjectPath(kFakeObjectPath); | 300 writer.AppendObjectPath(kFakeObjectPath); |
358 | 301 |
359 AddMethodExpectation(biod::kBiometricsManagerStartAuthSessionMethod, | 302 AddMethodExpectation(biod::kBiometricsManagerStartAuthSessionMethod, |
360 std::move(response)); | 303 std::move(response)); |
361 dbus::ObjectPath returned_path(kInvalidTestPath); | 304 dbus::ObjectPath returned_path(kInvalidTestPath); |
362 client_->StartAuthSession(base::Bind(&CopyObjectPath, &returned_path)); | 305 client_->StartAuthSession( |
| 306 base::Bind(&test_utils::CopyObjectPath, &returned_path)); |
363 base::RunLoop().RunUntilIdle(); | 307 base::RunLoop().RunUntilIdle(); |
364 EXPECT_EQ(kFakeObjectPath, returned_path); | 308 EXPECT_EQ(kFakeObjectPath, returned_path); |
365 | 309 |
366 // Verify that by sending a empty reponse or a improperly formatted one, the | 310 // Verify that by sending a empty reponse or a improperly formatted one, the |
367 // response is an empty object path. | 311 // response is an empty object path. |
368 AddMethodExpectation(biod::kBiometricsManagerStartAuthSessionMethod, nullptr); | 312 AddMethodExpectation(biod::kBiometricsManagerStartAuthSessionMethod, nullptr); |
369 returned_path = dbus::ObjectPath(kInvalidTestPath); | 313 returned_path = dbus::ObjectPath(kInvalidTestPath); |
370 client_->StartAuthSession(base::Bind(&CopyObjectPath, &returned_path)); | 314 client_->StartAuthSession( |
| 315 base::Bind(&test_utils::CopyObjectPath, &returned_path)); |
371 base::RunLoop().RunUntilIdle(); | 316 base::RunLoop().RunUntilIdle(); |
372 EXPECT_EQ(dbus::ObjectPath(), returned_path); | 317 EXPECT_EQ(dbus::ObjectPath(), returned_path); |
373 | 318 |
374 std::unique_ptr<dbus::Response> bad_response(dbus::Response::CreateEmpty()); | 319 std::unique_ptr<dbus::Response> bad_response(dbus::Response::CreateEmpty()); |
375 dbus::MessageWriter bad_writer(bad_response.get()); | 320 dbus::MessageWriter bad_writer(bad_response.get()); |
376 bad_writer.AppendString(""); | 321 bad_writer.AppendString(""); |
377 AddMethodExpectation(biod::kBiometricsManagerStartAuthSessionMethod, | 322 AddMethodExpectation(biod::kBiometricsManagerStartAuthSessionMethod, |
378 std::move(bad_response)); | 323 std::move(bad_response)); |
379 returned_path = dbus::ObjectPath(kInvalidTestPath); | 324 returned_path = dbus::ObjectPath(kInvalidTestPath); |
380 client_->StartAuthSession(base::Bind(&CopyObjectPath, &returned_path)); | 325 client_->StartAuthSession( |
| 326 base::Bind(&test_utils::CopyObjectPath, &returned_path)); |
381 base::RunLoop().RunUntilIdle(); | 327 base::RunLoop().RunUntilIdle(); |
382 EXPECT_EQ(dbus::ObjectPath(), returned_path); | 328 EXPECT_EQ(dbus::ObjectPath(), returned_path); |
383 } | 329 } |
384 | 330 |
385 TEST_F(BiodClientTest, TestRequestBiometricType) { | 331 TEST_F(BiodClientTest, TestRequestBiometricType) { |
386 const biod::BiometricType kFakeBiometricType = | 332 const biod::BiometricType kFakeBiometricType = |
387 biod::BIOMETRIC_TYPE_FINGERPRINT; | 333 biod::BIOMETRIC_TYPE_FINGERPRINT; |
388 | 334 |
389 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 335 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
390 dbus::MessageWriter writer(response.get()); | 336 dbus::MessageWriter writer(response.get()); |
391 writer.AppendVariantOfUint32(static_cast<uint32_t>(kFakeBiometricType)); | 337 writer.AppendVariantOfUint32(static_cast<uint32_t>(kFakeBiometricType)); |
392 | 338 |
393 // Create a fake response with biometric type. The get label call should | 339 // Create a fake response with biometric type. The get label call should |
394 // return this exact biometric type. | 340 // return this exact biometric type. |
395 biod::BiometricType returned_biometric_type = biod::BIOMETRIC_TYPE_MAX; | 341 biod::BiometricType returned_biometric_type = biod::BIOMETRIC_TYPE_MAX; |
396 AddMethodExpectation(dbus::kDBusPropertiesGet, std::move(response)); | 342 AddMethodExpectation(dbus::kDBusPropertiesGet, std::move(response)); |
397 client_->RequestType( | 343 client_->RequestType( |
398 base::Bind(&CopyBiometricType, &returned_biometric_type)); | 344 base::Bind(&test_utils::CopyBiometricType, &returned_biometric_type)); |
399 base::RunLoop().RunUntilIdle(); | 345 base::RunLoop().RunUntilIdle(); |
400 EXPECT_EQ(kFakeBiometricType, returned_biometric_type); | 346 EXPECT_EQ(kFakeBiometricType, returned_biometric_type); |
401 | 347 |
402 // Verify that by sending a null reponse, the result is an unknown biometric | 348 // Verify that by sending a null reponse, the result is an unknown biometric |
403 // type. | 349 // type. |
404 returned_biometric_type = biod::BIOMETRIC_TYPE_MAX; | 350 returned_biometric_type = biod::BIOMETRIC_TYPE_MAX; |
405 AddMethodExpectation(dbus::kDBusPropertiesGet, nullptr); | 351 AddMethodExpectation(dbus::kDBusPropertiesGet, nullptr); |
406 client_->RequestType( | 352 client_->RequestType( |
407 base::Bind(&CopyBiometricType, &returned_biometric_type)); | 353 base::Bind(&test_utils::CopyBiometricType, &returned_biometric_type)); |
408 base::RunLoop().RunUntilIdle(); | 354 base::RunLoop().RunUntilIdle(); |
409 EXPECT_EQ(biod::BiometricType::BIOMETRIC_TYPE_UNKNOWN, | 355 EXPECT_EQ(biod::BiometricType::BIOMETRIC_TYPE_UNKNOWN, |
410 returned_biometric_type); | 356 returned_biometric_type); |
411 } | 357 } |
412 | 358 |
413 TEST_F(BiodClientTest, TestRequestRecordLabel) { | 359 TEST_F(BiodClientTest, TestRequestRecordLabel) { |
414 const std::string kFakeLabel("fakeLabel"); | 360 const std::string kFakeLabel("fakeLabel"); |
415 const dbus::ObjectPath kFakeRecordPath(std::string("/fake/record/path")); | 361 const dbus::ObjectPath kFakeRecordPath(std::string("/fake/record/path")); |
416 | 362 |
417 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 363 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
418 dbus::MessageWriter writer(response.get()); | 364 dbus::MessageWriter writer(response.get()); |
419 writer.AppendString(kFakeLabel); | 365 writer.AppendString(kFakeLabel); |
420 | 366 |
421 // Create a fake response with string. The get label call should return this | 367 // Create a fake response with string. The get label call should return this |
422 // exact string. | 368 // exact string. |
423 std::string returned_label = kInvalidString; | 369 std::string returned_label = kInvalidString; |
424 AddMethodExpectation(dbus::kDBusPropertiesGet, std::move(response)); | 370 AddMethodExpectation(dbus::kDBusPropertiesGet, std::move(response)); |
425 client_->RequestRecordLabel(kFakeRecordPath, | 371 client_->RequestRecordLabel( |
426 base::Bind(&CopyString, &returned_label)); | 372 kFakeRecordPath, base::Bind(&test_utils::CopyString, &returned_label)); |
427 base::RunLoop().RunUntilIdle(); | 373 base::RunLoop().RunUntilIdle(); |
428 EXPECT_EQ(kFakeLabel, returned_label); | 374 EXPECT_EQ(kFakeLabel, returned_label); |
429 | 375 |
430 // Verify that by sending a null reponse, the result is an empty string. | 376 // Verify that by sending a null reponse, the result is an empty string. |
431 returned_label = kInvalidString; | 377 returned_label = kInvalidString; |
432 AddMethodExpectation(dbus::kDBusPropertiesGet, nullptr); | 378 AddMethodExpectation(dbus::kDBusPropertiesGet, nullptr); |
433 client_->RequestRecordLabel(kFakeRecordPath, | 379 client_->RequestRecordLabel( |
434 base::Bind(&CopyString, &returned_label)); | 380 kFakeRecordPath, base::Bind(&test_utils::CopyString, &returned_label)); |
435 base::RunLoop().RunUntilIdle(); | 381 base::RunLoop().RunUntilIdle(); |
436 EXPECT_EQ("", returned_label); | 382 EXPECT_EQ("", returned_label); |
437 } | 383 } |
438 | 384 |
439 // Verify when signals are mocked, an observer will catch the signals as | 385 // Verify when signals are mocked, an observer will catch the signals as |
440 // expected. | 386 // expected. |
441 TEST_F(BiodClientTest, TestNotifyObservers) { | 387 TEST_F(BiodClientTest, TestNotifyObservers) { |
442 TestBiodObserver observer; | 388 test_utils::TestBiodObserver observer; |
443 client_->AddObserver(&observer); | 389 client_->AddObserver(&observer); |
444 EXPECT_TRUE(client_->HasObserver(&observer)); | 390 EXPECT_TRUE(client_->HasObserver(&observer)); |
445 | 391 |
446 const biod::ScanResult scan_signal = biod::ScanResult::SCAN_RESULT_SUCCESS; | 392 const biod::ScanResult scan_signal = biod::ScanResult::SCAN_RESULT_SUCCESS; |
447 const bool enroll_session_complete = false; | 393 const bool enroll_session_complete = false; |
448 const AuthScanMatches test_attempt; | 394 const AuthScanMatches test_attempt; |
449 EXPECT_EQ(0, observer.num_enroll_scans_received()); | 395 EXPECT_EQ(0, observer.NumEnrollScansReceived()); |
450 EXPECT_EQ(0, observer.num_auth_scans_received()); | 396 EXPECT_EQ(0, observer.NumAuthScansReceived()); |
451 EXPECT_EQ(0, observer.num_failures_received()); | 397 EXPECT_EQ(0, observer.num_failures_received()); |
452 | 398 |
453 EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete); | 399 EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete); |
454 EXPECT_EQ(1, observer.num_enroll_scans_received()); | 400 EXPECT_EQ(1, observer.NumEnrollScansReceived()); |
455 | 401 |
456 EmitAuthScanDoneSignal(scan_signal, test_attempt); | 402 EmitAuthScanDoneSignal(scan_signal, test_attempt); |
457 EXPECT_EQ(1, observer.num_auth_scans_received()); | 403 EXPECT_EQ(1, observer.NumAuthScansReceived()); |
458 | 404 |
459 EmitScanFailedSignal(); | 405 EmitScanFailedSignal(); |
460 EXPECT_EQ(1, observer.num_failures_received()); | 406 EXPECT_EQ(1, observer.num_failures_received()); |
461 | 407 |
462 client_->RemoveObserver(&observer); | 408 client_->RemoveObserver(&observer); |
463 | 409 |
464 EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete); | 410 EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete); |
465 EmitAuthScanDoneSignal(scan_signal, test_attempt); | 411 EmitAuthScanDoneSignal(scan_signal, test_attempt); |
466 EXPECT_EQ(1, observer.num_enroll_scans_received()); | 412 EXPECT_EQ(1, observer.NumEnrollScansReceived()); |
467 EXPECT_EQ(1, observer.num_auth_scans_received()); | 413 EXPECT_EQ(1, observer.NumAuthScansReceived()); |
468 EXPECT_EQ(1, observer.num_failures_received()); | 414 EXPECT_EQ(1, observer.num_failures_received()); |
469 } | 415 } |
470 } // namespace chromeos | 416 } // namespace chromeos |
OLD | NEW |