OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_PROXIMITY_AUTH_MOCK_CRYPTAUTH_CLIENT_H | |
6 #define COMPONENTS_PROXIMITY_AUTH_MOCK_CRYPTAUTH_CLIENT_H | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/observer_list.h" | |
10 #include "components/proximity_auth/cryptauth/cryptauth_client.h" | |
11 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" | |
12 #include "testing/gmock/include/gmock/gmock.h" | |
13 | |
14 namespace proximity_auth { | |
15 | |
16 class MockCryptAuthClient : public CryptAuthClient { | |
17 public: | |
18 MockCryptAuthClient(); | |
19 ~MockCryptAuthClient() override; | |
20 | |
21 // CryptAuthClient: | |
22 MOCK_METHOD3(GetMyDevices, | |
23 void(const cryptauth::GetMyDevicesRequest& request, | |
24 const GetMyDevicesCallback& callback, | |
25 const ErrorCallback& error_callback)); | |
26 MOCK_METHOD3(FindEligibleUnlockDevices, | |
27 void(const cryptauth::FindEligibleUnlockDevicesRequest& request, | |
28 const FindEligibleUnlockDevicesCallback& callback, | |
29 const ErrorCallback& error_callback)); | |
30 MOCK_METHOD3(SendDeviceSyncTickle, | |
31 void(const cryptauth::SendDeviceSyncTickleRequest& request, | |
32 const SendDeviceSyncTickleCallback& callback, | |
33 const ErrorCallback& error_callback)); | |
34 MOCK_METHOD3(ToggleEasyUnlock, | |
35 void(const cryptauth::ToggleEasyUnlockRequest& request, | |
36 const ToggleEasyUnlockCallback& callback, | |
37 const ErrorCallback& error_callback)); | |
38 MOCK_METHOD3(SetupEnrollment, | |
39 void(const cryptauth::SetupEnrollmentRequest& request, | |
40 const SetupEnrollmentCallback& callback, | |
41 const ErrorCallback& error_callback)); | |
42 MOCK_METHOD3(FinishEnrollment, | |
43 void(const cryptauth::FinishEnrollmentRequest& request, | |
44 const FinishEnrollmentCallback& callback, | |
45 const ErrorCallback& error_callback)); | |
46 MOCK_METHOD0(GetAccessTokenUsed, std::string()); | |
47 | |
48 private: | |
49 DISALLOW_COPY_AND_ASSIGN(MockCryptAuthClient); | |
50 }; | |
51 | |
52 class MockCryptAuthClientFactory : public CryptAuthClientFactory { | |
53 public: | |
54 class Observer { | |
55 public: | |
56 // Called with the new instance when it is requested from the factory, | |
57 // allowing expectations to be set. Ownership of |client| will be taken by | |
58 // the caller of CreateInstance(). | |
59 virtual void OnCryptAuthClientCreated(MockCryptAuthClient* client) = 0; | |
60 }; | |
61 | |
62 // Represents the type of mock instances to create. | |
63 enum class MockType { MAKE_NICE_MOCKS, MAKE_STRICT_MOCKS }; | |
64 | |
65 // If |mock_type| is STRICT, then StrictMocks will be created. Otherwise, | |
66 // NiceMocks will be created. | |
67 explicit MockCryptAuthClientFactory(MockType mock_type); | |
68 ~MockCryptAuthClientFactory() override; | |
69 | |
70 // CryptAuthClientFactory: | |
71 std::unique_ptr<CryptAuthClient> CreateInstance() override; | |
72 | |
73 void AddObserver(Observer* observer); | |
74 void RemoveObserver(Observer* observer); | |
75 | |
76 private: | |
77 // Whether to create StrictMocks or NiceMocks. | |
78 const MockType mock_type_; | |
79 | |
80 // Observers of the factory. | |
81 base::ObserverList<Observer> observer_list_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(MockCryptAuthClientFactory); | |
84 }; | |
85 | |
86 } // namespace proximity_auth | |
87 | |
88 #endif // COMPONENTS_PROXIMITY_AUTH_MOCK_CRYPTAUTH_CLIENT_H | |
OLD | NEW |