Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Side by Side Diff: chromeos/dbus/biod/biod_client_unittest.cc

Issue 2858003002: Roll src/third_party/cros_system_api/ c6eab9e4d..6139ae009 + API change (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/dbus/biod/biod_client.cc ('k') | chromeos/dbus/biod/fake_biod_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/strings/stringprintf.h"
13 #include "chromeos/dbus/biod/messages.pb.h"
12 #include "chromeos/dbus/biod/test_utils.h" 14 #include "chromeos/dbus/biod/test_utils.h"
13 #include "dbus/mock_bus.h" 15 #include "dbus/mock_bus.h"
14 #include "dbus/mock_object_proxy.h" 16 #include "dbus/mock_object_proxy.h"
15 #include "dbus/object_path.h" 17 #include "dbus/object_path.h"
16 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 20
19 using ::testing::_; 21 using ::testing::_;
20 using ::testing::Invoke; 22 using ::testing::Invoke;
21 using ::testing::Return; 23 using ::testing::Return;
22 24
23 namespace chromeos { 25 namespace chromeos {
24 26
25 namespace { 27 namespace {
26 28
27 // Shorthand for a commonly-used constant. 29 // Shorthand for a commonly-used constant.
28 const char* kInterface = biod::kBiometricsManagerInterface; 30 const char* kInterface = biod::kBiometricsManagerInterface;
29 31
30 // Value used to intialize dbus::ObjectPath objects in tests to make it easier 32 // Value used to intialize dbus::ObjectPath objects in tests to make it easier
31 // to determine when empty values have been assigned. 33 // to determine when empty values have been assigned.
32 const char kInvalidTestPath[] = "/invalid/test/path"; 34 const char kInvalidTestPath[] = "/invalid/test/path";
33 35
34 // Value used to intialize string objects in tests to make it easier to 36 // Value used to intialize string objects in tests to make it easier to
35 // determine when empty values have been assigned. 37 // determine when empty values have been assigned.
36 const char kInvalidString[] = "invalidString"; 38 const char kInvalidString[] = "invalidString";
37 39
38 // TODO(xiaoyinh@): Use the constant from service_constants.h
39 // crbug.com/713420
40 const char kBiometricsManagerPath[] =
41 "/org/chromium/BiometricsDaemon/FpcBiometricsManager";
42
43 // Matcher that verifies that a dbus::Message has member |name|. 40 // Matcher that verifies that a dbus::Message has member |name|.
44 MATCHER_P(HasMember, name, "") { 41 MATCHER_P(HasMember, name, "") {
45 if (arg->GetMember() != name) { 42 if (arg->GetMember() != name) {
46 *result_listener << "has member " << arg->GetMember(); 43 *result_listener << "has member " << arg->GetMember();
47 return false; 44 return false;
48 } 45 }
49 return true; 46 return true;
50 } 47 }
51 48
52 // Runs |callback| with |response|. Needed due to ResponseCallback expecting a 49 // Runs |callback| with |response|. Needed due to ResponseCallback expecting a
53 // bare pointer rather than an std::unique_ptr. 50 // bare pointer rather than an std::unique_ptr.
54 void RunResponseCallback(dbus::ObjectProxy::ResponseCallback callback, 51 void RunResponseCallback(dbus::ObjectProxy::ResponseCallback callback,
55 std::unique_ptr<dbus::Response> response) { 52 std::unique_ptr<dbus::Response> response) {
56 callback.Run(response.get()); 53 callback.Run(response.get());
57 } 54 }
58 55
59 } // namespace 56 } // namespace
60 57
61 class BiodClientTest : public testing::Test { 58 class BiodClientTest : public testing::Test {
62 public: 59 public:
63 BiodClientTest() {} 60 BiodClientTest() {}
64 ~BiodClientTest() override {} 61 ~BiodClientTest() override {}
65 62
66 void SetUp() override { 63 void SetUp() override {
67 dbus::Bus::Options options; 64 dbus::Bus::Options options;
68 options.bus_type = dbus::Bus::SYSTEM; 65 options.bus_type = dbus::Bus::SYSTEM;
69 bus_ = new dbus::MockBus(options); 66 bus_ = new dbus::MockBus(options);
70 67
71 proxy_ = 68 dbus::ObjectPath fpc_bio_path = dbus::ObjectPath(base::StringPrintf(
72 new dbus::MockObjectProxy(bus_.get(), biod::kBiodServiceName, 69 "%s/%s", biod::kBiodServicePath, biod::kFpcBiometricsManagerName));
73 dbus::ObjectPath(kBiometricsManagerPath)); 70 proxy_ = new dbus::MockObjectProxy(bus_.get(), biod::kBiodServiceName,
71 fpc_bio_path);
74 72
75 // |client_|'s Init() method should request a proxy for communicating with 73 // |client_|'s Init() method should request a proxy for communicating with
76 // biometrics api. 74 // biometrics api.
77 EXPECT_CALL(*bus_.get(), GetObjectProxy(biod::kBiodServiceName, _)) 75 EXPECT_CALL(*bus_.get(), GetObjectProxy(biod::kBiodServiceName, _))
78 .WillRepeatedly(Return(proxy_.get())); 76 .WillRepeatedly(Return(proxy_.get()));
79 77
80 // Save |client_|'s signal callback. 78 // Save |client_|'s signal callback.
81 EXPECT_CALL(*proxy_.get(), ConnectToSignal(kInterface, _, _, _)) 79 EXPECT_CALL(*proxy_.get(), ConnectToSignal(kInterface, _, _, _))
82 .WillRepeatedly(Invoke(this, &BiodClientTest::ConnectToSignal)); 80 .WillRepeatedly(Invoke(this, &BiodClientTest::ConnectToSignal));
83 81
(...skipping 24 matching lines...) Expand all
108 void EmitSignal(dbus::Signal* signal) { 106 void EmitSignal(dbus::Signal* signal) {
109 const std::string signal_name = signal->GetMember(); 107 const std::string signal_name = signal->GetMember();
110 const auto it = signal_callbacks_.find(signal_name); 108 const auto it = signal_callbacks_.find(signal_name);
111 ASSERT_TRUE(it != signal_callbacks_.end()) 109 ASSERT_TRUE(it != signal_callbacks_.end())
112 << "Client didn't register for signal " << signal_name; 110 << "Client didn't register for signal " << signal_name;
113 it->second.Run(signal); 111 it->second.Run(signal);
114 } 112 }
115 113
116 // Passes a enroll scan done signal to |client_|. 114 // Passes a enroll scan done signal to |client_|.
117 void EmitEnrollScanDoneSignal(biod::ScanResult scan_result, 115 void EmitEnrollScanDoneSignal(biod::ScanResult scan_result,
118 bool enroll_session_complete) { 116 bool enroll_session_complete,
117 int percent_complete) {
119 dbus::Signal signal(kInterface, 118 dbus::Signal signal(kInterface,
120 biod::kBiometricsManagerEnrollScanDoneSignal); 119 biod::kBiometricsManagerEnrollScanDoneSignal);
121 dbus::MessageWriter writer(&signal); 120 dbus::MessageWriter writer(&signal);
122 writer.AppendUint32(static_cast<uint32_t>(scan_result)); 121 biod::EnrollScanDone protobuf;
123 writer.AppendBool(enroll_session_complete); 122 protobuf.set_scan_result(scan_result);
123 protobuf.set_done(enroll_session_complete);
124 protobuf.set_percent_complete(percent_complete);
125 writer.AppendProtoAsArrayOfBytes(protobuf);
124 EmitSignal(&signal); 126 EmitSignal(&signal);
125 } 127 }
126 128
127 // Passes a auth scan done signal to |client_|. 129 // Passes a auth scan done signal to |client_|.
128 void EmitAuthScanDoneSignal(biod::ScanResult scan_result, 130 void EmitAuthScanDoneSignal(biod::ScanResult scan_result,
129 const AuthScanMatches& matches) { 131 const AuthScanMatches& matches) {
130 dbus::Signal signal(kInterface, biod::kBiometricsManagerAuthScanDoneSignal); 132 dbus::Signal signal(kInterface, biod::kBiometricsManagerAuthScanDoneSignal);
131 dbus::MessageWriter writer(&signal); 133 dbus::MessageWriter writer(&signal);
132 writer.AppendUint32(static_cast<uint32_t>(scan_result)); 134 writer.AppendUint32(static_cast<uint32_t>(scan_result));
133 135
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 396
395 // Verify when signals are mocked, an observer will catch the signals as 397 // Verify when signals are mocked, an observer will catch the signals as
396 // expected. 398 // expected.
397 TEST_F(BiodClientTest, TestNotifyObservers) { 399 TEST_F(BiodClientTest, TestNotifyObservers) {
398 test_utils::TestBiodObserver observer; 400 test_utils::TestBiodObserver observer;
399 client_->AddObserver(&observer); 401 client_->AddObserver(&observer);
400 EXPECT_TRUE(client_->HasObserver(&observer)); 402 EXPECT_TRUE(client_->HasObserver(&observer));
401 403
402 const biod::ScanResult scan_signal = biod::ScanResult::SCAN_RESULT_SUCCESS; 404 const biod::ScanResult scan_signal = biod::ScanResult::SCAN_RESULT_SUCCESS;
403 const bool enroll_session_complete = false; 405 const bool enroll_session_complete = false;
406 const int percent_complete = 0;
404 const AuthScanMatches test_attempt; 407 const AuthScanMatches test_attempt;
405 EXPECT_EQ(0, observer.NumEnrollScansReceived()); 408 EXPECT_EQ(0, observer.NumEnrollScansReceived());
406 EXPECT_EQ(0, observer.NumAuthScansReceived()); 409 EXPECT_EQ(0, observer.NumAuthScansReceived());
407 EXPECT_EQ(0, observer.num_failures_received()); 410 EXPECT_EQ(0, observer.num_failures_received());
408 411
409 EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete); 412 EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete,
413 percent_complete);
410 EXPECT_EQ(1, observer.NumEnrollScansReceived()); 414 EXPECT_EQ(1, observer.NumEnrollScansReceived());
411 415
412 EmitAuthScanDoneSignal(scan_signal, test_attempt); 416 EmitAuthScanDoneSignal(scan_signal, test_attempt);
413 EXPECT_EQ(1, observer.NumAuthScansReceived()); 417 EXPECT_EQ(1, observer.NumAuthScansReceived());
414 418
415 EmitScanFailedSignal(); 419 EmitScanFailedSignal();
416 EXPECT_EQ(1, observer.num_failures_received()); 420 EXPECT_EQ(1, observer.num_failures_received());
417 421
418 client_->RemoveObserver(&observer); 422 client_->RemoveObserver(&observer);
419 423
420 EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete); 424 EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete,
425 percent_complete);
421 EmitAuthScanDoneSignal(scan_signal, test_attempt); 426 EmitAuthScanDoneSignal(scan_signal, test_attempt);
422 EXPECT_EQ(1, observer.NumEnrollScansReceived()); 427 EXPECT_EQ(1, observer.NumEnrollScansReceived());
423 EXPECT_EQ(1, observer.NumAuthScansReceived()); 428 EXPECT_EQ(1, observer.NumAuthScansReceived());
424 EXPECT_EQ(1, observer.num_failures_received()); 429 EXPECT_EQ(1, observer.num_failures_received());
425 } 430 }
426 } // namespace chromeos 431 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/biod/biod_client.cc ('k') | chromeos/dbus/biod/fake_biod_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698