Chromium Code Reviews| Index: chromeos/dbus/biod/fake_biod_client.h |
| diff --git a/chromeos/dbus/biod/fake_biod_client.h b/chromeos/dbus/biod/fake_biod_client.h |
| index e4fd8410ce8f81f8ca952890d82e4a988af9cea6..f09255ea1412f1f4c691a8e56230b5d9d1c27ab8 100644 |
| --- a/chromeos/dbus/biod/fake_biod_client.h |
| +++ b/chromeos/dbus/biod/fake_biod_client.h |
| @@ -5,29 +5,57 @@ |
| #ifndef CHROMEOS_DBUS_BIOD_FAKE_BIOD_CLIENT_H_ |
| #define CHROMEOS_DBUS_BIOD_FAKE_BIOD_CLIENT_H_ |
| +#include <map> |
| +#include <string> |
| + |
| #include "base/macros.h" |
| #include "base/observer_list.h" |
| #include "chromeos/chromeos_export.h" |
| #include "chromeos/dbus/biod/biod_client.h" |
| +#include "dbus/object_path.h" |
| namespace dbus { |
| class Bus; |
| -class ObjectPath; |
| } // namespace dbus |
| namespace chromeos { |
| -// A fake implementation of BiodClient. |
| +class FakeBiodClientTest; |
| + |
| +// A fake implementation of BiodClient. It emulates the real Biod daemon by |
| +// providing the same API and storing fingerprints locally. A fingerprint is |
| +// represented by a vector of strings. During enrollment, fake enrollments are |
| +// sent as strings. If they are successful they get push backed to the current |
| +// fingerprint, until a completed enroll scan is sent. An attempt scan is also |
| +// sent with a string. If that string matches any string in the stored |
| +// fingerprint vector, it is considered a match. |
| class CHROMEOS_EXPORT FakeBiodClient : public BiodClient { |
| public: |
| + // The current session of fingerprint storage. The session determines which |
| + // events will be sent from user finger touches. |
| + enum class FingerprintSession { |
|
Daniel Erat
2017/04/07 23:40:56
move this to the private section
sammiequon
2017/04/08 00:43:32
Done.
|
| + NONE, |
| + ENROLL, |
| + AUTH, |
| + }; |
| + |
| FakeBiodClient(); |
| ~FakeBiodClient() override; |
| // Emulates the biod daemon by sending events which the daemon normally sends. |
| // Notifies |observers_| about various events. These will be used in tests. |
| - void SendEnrollScanDone(biod::ScanResult type_result, bool is_complete); |
| - void SendAuthScanDone(biod::ScanResult type_result, |
| - const AuthScanMatches& matches); |
| + |
| + // Emulates a scan that occurs during enrolling a new fingerprint. |
| + // |fingerprint| is the fake data of the finger as a string. If |is_complete| |
| + // is true the enroll session is finished, and the record is stored. |
| + void SendEnrollScanDone(const std::string& fingerprint, |
| + biod::ScanResult type_result, |
| + bool is_complete); |
| + // Emulates a scan that occurs during a authentication session. |fingerprint| |
| + // is a string which represents the finger, and will be compared with all the |
| + // stored fingerprints. |
| + void SendAuthScanDone(const std::string& fingerprint, |
| + biod::ScanResult type_result); |
| void SendSessionFailed(); |
| // BiodClient: |
| @@ -52,7 +80,40 @@ class CHROMEOS_EXPORT FakeBiodClient : public BiodClient { |
| void RequestRecordLabel(const dbus::ObjectPath& record_path, |
| const LabelCallback& callback) override; |
| + // Clears all stored and current records from the fake storage. |
| + void Reset(); |
|
Daniel Erat
2017/04/07 23:40:56
nit: move this above overrides
sammiequon
2017/04/08 00:43:32
Done.
|
| + |
| private: |
| + friend FakeBiodClientTest; |
|
Daniel Erat
2017/04/07 23:40:56
consider not listing the test class as a friend, s
sammiequon
2017/04/08 00:43:32
Acknowledged.
|
| + |
| + // FakeRecord is the definition of a fake stored fingerprint template. |
| + struct FakeRecord { |
| + FakeRecord(); |
| + ~FakeRecord(); |
| + |
| + std::string user_id; |
| + std::string label; |
| + // A fake fingerprint is a vector which consists of all the strings which |
| + // were "pressed" during the enroll session. |
| + std::vector<std::string> fake_fingerprint; |
| + }; |
| + |
| + // The stored fingerprints. |
| + std::map<dbus::ObjectPath, std::unique_ptr<FakeRecord>> records_; |
| + |
| + // Current record in process of getting enrolled and its path. These are |
| + // assigned at the start of an enroll session and freed when the enroll |
| + // session is finished or cancelled. |
| + dbus::ObjectPath current_record_path_; |
| + std::unique_ptr<FakeRecord> current_record_; |
| + |
| + // Unique indentifier that gets updated each time an enroll session is started |
| + // to ensure each record is stored at a different path. |
| + int next_record_unique_id_ = 1; |
| + |
| + // The current session of the fake storage. |
| + FingerprintSession current_session_ = FingerprintSession::NONE; |
| + |
| base::ObserverList<Observer> observers_; |
| DISALLOW_COPY_AND_ASSIGN(FakeBiodClient); |