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

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: 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
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 28 matching lines...) Expand all
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) {
119 dbus::Signal signal(kInterface, 117 dbus::Signal signal(kInterface,
120 biod::kBiometricsManagerEnrollScanDoneSignal); 118 biod::kBiometricsManagerEnrollScanDoneSignal);
121 dbus::MessageWriter writer(&signal); 119 dbus::MessageWriter writer(&signal);
122 writer.AppendUint32(static_cast<uint32_t>(scan_result)); 120 biod::EnrollScanDone protobuf;
123 writer.AppendBool(enroll_session_complete); 121 protobuf.set_scan_result(scan_result);
122 protobuf.set_done(enroll_session_complete);
123 writer.AppendProtoAsArrayOfBytes(protobuf);
sammiequon 2017/05/03 19:15:57 i think we should update EmitEnrollScanDoneSignal
xiaoyinh(OOO Sep 11-29) 2017/05/04 00:29:51 Updated, thanks! Please let me know if this is goo
sammiequon 2017/05/04 15:55:54 Thanks! It doesn't test much, but at least this fn
124 EmitSignal(&signal); 124 EmitSignal(&signal);
125 } 125 }
126 126
127 // Passes a auth scan done signal to |client_|. 127 // Passes a auth scan done signal to |client_|.
128 void EmitAuthScanDoneSignal(biod::ScanResult scan_result, 128 void EmitAuthScanDoneSignal(biod::ScanResult scan_result,
129 const AuthScanMatches& matches) { 129 const AuthScanMatches& matches) {
130 dbus::Signal signal(kInterface, biod::kBiometricsManagerAuthScanDoneSignal); 130 dbus::Signal signal(kInterface, biod::kBiometricsManagerAuthScanDoneSignal);
131 dbus::MessageWriter writer(&signal); 131 dbus::MessageWriter writer(&signal);
132 writer.AppendUint32(static_cast<uint32_t>(scan_result)); 132 writer.AppendUint32(static_cast<uint32_t>(scan_result));
133 133
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 417
418 client_->RemoveObserver(&observer); 418 client_->RemoveObserver(&observer);
419 419
420 EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete); 420 EmitEnrollScanDoneSignal(scan_signal, enroll_session_complete);
421 EmitAuthScanDoneSignal(scan_signal, test_attempt); 421 EmitAuthScanDoneSignal(scan_signal, test_attempt);
422 EXPECT_EQ(1, observer.NumEnrollScansReceived()); 422 EXPECT_EQ(1, observer.NumEnrollScansReceived());
423 EXPECT_EQ(1, observer.NumAuthScansReceived()); 423 EXPECT_EQ(1, observer.NumAuthScansReceived());
424 EXPECT_EQ(1, observer.num_failures_received()); 424 EXPECT_EQ(1, observer.num_failures_received());
425 } 425 }
426 } // namespace chromeos 426 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698