forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_consent_auditor.h
136 lines (107 loc) · 4.47 KB
/
fake_consent_auditor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_CONSENT_AUDITOR_FAKE_CONSENT_AUDITOR_H_
#define COMPONENTS_CONSENT_AUDITOR_FAKE_CONSENT_AUDITOR_H_
#include <string>
#include <vector>
#include "base/macros.h"
#include "components/consent_auditor/consent_auditor.h"
#include "testing/gmock/include/gmock/gmock.h"
using ::testing::Matcher;
namespace consent_auditor {
// TODO(markusheintz): Rename to MockConsentAuditor
class FakeConsentAuditor : public ConsentAuditor {
public:
FakeConsentAuditor();
~FakeConsentAuditor() override;
// ConsentAuditor implementation.
void RecordSyncConsent(
const CoreAccountId& account_id,
const sync_pb::UserConsentTypes::SyncConsent& consent) override;
MOCK_METHOD2(
RecordArcPlayConsent,
void(const CoreAccountId&,
const sync_pb::UserConsentTypes::ArcPlayTermsOfServiceConsent&));
MOCK_METHOD2(
RecordArcBackupAndRestoreConsent,
void(const CoreAccountId&,
const sync_pb::UserConsentTypes::ArcBackupAndRestoreConsent&));
MOCK_METHOD2(
RecordArcGoogleLocationServiceConsent,
void(const CoreAccountId&,
const sync_pb::UserConsentTypes::ArcGoogleLocationServiceConsent&));
void RecordAssistantActivityControlConsent(
const CoreAccountId& account_id,
const sync_pb::UserConsentTypes::AssistantActivityControlConsent& consent)
override;
void RecordAccountPasswordsConsent(
const CoreAccountId& account_id,
const sync_pb::UserConsentTypes::AccountPasswordsConsent& consent)
override;
void RecordLocalConsent(const std::string& feature,
const std::string& description_text,
const std::string& confirmation_text) override;
base::WeakPtr<syncer::ModelTypeControllerDelegate> GetControllerDelegate()
override;
// Methods for fake.
// TODO(markusheintz): Replace the usage of this methods in all tests.
void RecordGaiaConsent(const CoreAccountId& account_id,
consent_auditor::Feature feature,
const std::vector<int>& description_grd_ids,
int confirmation_grd_id,
consent_auditor::ConsentStatus status);
const CoreAccountId& account_id() const { return account_id_; }
const sync_pb::UserConsentTypes::SyncConsent& recorded_sync_consent() const {
return recorded_sync_consent_;
}
const sync_pb::UserConsentTypes::ArcPlayTermsOfServiceConsent&
recorded_play_consent() const {
return recorded_play_consent_;
}
const std::vector<std::vector<int>>& recorded_id_vectors() {
return recorded_id_vectors_;
}
const std::vector<int>& recorded_confirmation_ids() const {
return recorded_confirmation_ids_;
}
const std::vector<Feature>& recorded_features() { return recorded_features_; }
const std::vector<ConsentStatus>& recorded_statuses() {
return recorded_statuses_;
}
private:
CoreAccountId account_id_;
sync_pb::UserConsentTypes::SyncConsent recorded_sync_consent_;
sync_pb::UserConsentTypes_ArcPlayTermsOfServiceConsent recorded_play_consent_;
std::vector<std::vector<int>> recorded_id_vectors_;
std::vector<int> recorded_confirmation_ids_;
std::vector<Feature> recorded_features_;
std::vector<ConsentStatus> recorded_statuses_;
DISALLOW_COPY_AND_ASSIGN(FakeConsentAuditor);
};
MATCHER_P(ArcPlayConsentEq, expected_consent, "") {
const sync_pb::UserConsentTypes::ArcPlayTermsOfServiceConsent&
actual_consent = arg;
if (actual_consent.SerializeAsString() ==
expected_consent.SerializeAsString())
return true;
*result_listener << "ERROR: actual proto does not match the expected proto";
return false;
}
MATCHER_P(ArcGoogleLocationServiceConsentEq, expected_consent, "") {
const sync_pb::UserConsentTypes::ArcGoogleLocationServiceConsent&
actual_consent = arg;
if (actual_consent.SerializeAsString() ==
expected_consent.SerializeAsString())
return true;
*result_listener << "ERROR: actual proto does not match the expected proto";
return false;
}
MATCHER_P(ArcBackupAndRestoreConsentEq, expected_consent, "") {
if (arg.SerializeAsString() == expected_consent.SerializeAsString())
return true;
*result_listener << "ERROR: actual proto does not match the expected proto";
return false;
}
} // namespace consent_auditor
#endif // COMPONENTS_CONSENT_AUDITOR_FAKE_CONSENT_AUDITOR_H_