fake_consent_auditor.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Copyright 2018 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. #ifndef COMPONENTS_CONSENT_AUDITOR_FAKE_CONSENT_AUDITOR_H_
  5. #define COMPONENTS_CONSENT_AUDITOR_FAKE_CONSENT_AUDITOR_H_
  6. #include <string>
  7. #include <vector>
  8. #include "components/consent_auditor/consent_auditor.h"
  9. #include "components/sync/protocol/user_consent_specifics.pb.h"
  10. #include "components/sync/protocol/user_consent_types.pb.h"
  11. #include "testing/gmock/include/gmock/gmock.h"
  12. using ::testing::Matcher;
  13. namespace consent_auditor {
  14. // TODO(markusheintz): Rename to MockConsentAuditor
  15. class FakeConsentAuditor : public ConsentAuditor {
  16. public:
  17. FakeConsentAuditor();
  18. FakeConsentAuditor(const FakeConsentAuditor&) = delete;
  19. FakeConsentAuditor& operator=(const FakeConsentAuditor&) = delete;
  20. ~FakeConsentAuditor() override;
  21. // ConsentAuditor implementation.
  22. void RecordSyncConsent(
  23. const CoreAccountId& account_id,
  24. const sync_pb::UserConsentTypes::SyncConsent& consent) override;
  25. MOCK_METHOD2(
  26. RecordArcPlayConsent,
  27. void(const CoreAccountId&,
  28. const sync_pb::UserConsentTypes::ArcPlayTermsOfServiceConsent&));
  29. MOCK_METHOD2(
  30. RecordArcBackupAndRestoreConsent,
  31. void(const CoreAccountId&,
  32. const sync_pb::UserConsentTypes::ArcBackupAndRestoreConsent&));
  33. MOCK_METHOD2(
  34. RecordArcGoogleLocationServiceConsent,
  35. void(const CoreAccountId&,
  36. const sync_pb::UserConsentTypes::ArcGoogleLocationServiceConsent&));
  37. void RecordAssistantActivityControlConsent(
  38. const CoreAccountId& account_id,
  39. const sync_pb::UserConsentTypes::AssistantActivityControlConsent& consent)
  40. override;
  41. void RecordAccountPasswordsConsent(
  42. const CoreAccountId& account_id,
  43. const sync_pb::UserConsentTypes::AccountPasswordsConsent& consent)
  44. override;
  45. void RecordAutofillAssistantConsent(
  46. const CoreAccountId& account_id,
  47. const sync_pb::UserConsentTypes::AutofillAssistantConsent& consent)
  48. override;
  49. void RecordLocalConsent(const std::string& feature,
  50. const std::string& description_text,
  51. const std::string& confirmation_text) override;
  52. base::WeakPtr<syncer::ModelTypeControllerDelegate> GetControllerDelegate()
  53. override;
  54. // Methods for fake.
  55. // TODO(markusheintz): Replace the usage of this methods in all tests.
  56. void RecordGaiaConsent(const CoreAccountId& account_id,
  57. consent_auditor::Feature feature,
  58. const std::vector<int>& description_grd_ids,
  59. int confirmation_grd_id,
  60. consent_auditor::ConsentStatus status);
  61. const CoreAccountId& account_id() const { return account_id_; }
  62. const std::vector<sync_pb::UserConsentSpecifics>& recorded_consents() const {
  63. return recorded_consents_;
  64. }
  65. const std::vector<std::vector<int>>& recorded_id_vectors() {
  66. return recorded_id_vectors_;
  67. }
  68. const std::vector<int>& recorded_confirmation_ids() const {
  69. return recorded_confirmation_ids_;
  70. }
  71. const std::vector<Feature>& recorded_features() { return recorded_features_; }
  72. const std::vector<ConsentStatus>& recorded_statuses() {
  73. return recorded_statuses_;
  74. }
  75. private:
  76. CoreAccountId account_id_;
  77. // Holds specific consent information for assistant activity control consent,
  78. // account password consent and autofill assistant consent. Does not (yet)
  79. // contain recorded sync consent.
  80. std::vector<sync_pb::UserConsentSpecifics> recorded_consents_;
  81. std::vector<std::vector<int>> recorded_id_vectors_;
  82. std::vector<int> recorded_confirmation_ids_;
  83. std::vector<Feature> recorded_features_;
  84. std::vector<ConsentStatus> recorded_statuses_;
  85. };
  86. MATCHER_P(ArcPlayConsentEq, expected_consent, "") {
  87. const sync_pb::UserConsentTypes::ArcPlayTermsOfServiceConsent&
  88. actual_consent = arg;
  89. if (actual_consent.SerializeAsString() ==
  90. expected_consent.SerializeAsString())
  91. return true;
  92. *result_listener << "ERROR: actual proto does not match the expected proto";
  93. return false;
  94. }
  95. MATCHER_P(ArcGoogleLocationServiceConsentEq, expected_consent, "") {
  96. const sync_pb::UserConsentTypes::ArcGoogleLocationServiceConsent&
  97. actual_consent = arg;
  98. if (actual_consent.SerializeAsString() ==
  99. expected_consent.SerializeAsString())
  100. return true;
  101. *result_listener << "ERROR: actual proto does not match the expected proto";
  102. return false;
  103. }
  104. MATCHER_P(ArcBackupAndRestoreConsentEq, expected_consent, "") {
  105. if (arg.SerializeAsString() == expected_consent.SerializeAsString())
  106. return true;
  107. *result_listener << "ERROR: actual proto does not match the expected proto";
  108. return false;
  109. }
  110. } // namespace consent_auditor
  111. #endif // COMPONENTS_CONSENT_AUDITOR_FAKE_CONSENT_AUDITOR_H_