test_storage_module.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2020 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_REPORTING_STORAGE_TEST_STORAGE_MODULE_H_
  5. #define COMPONENTS_REPORTING_STORAGE_TEST_STORAGE_MODULE_H_
  6. #include "base/callback.h"
  7. #include "components/reporting/proto/synced/record.pb.h"
  8. #include "components/reporting/proto/synced/record_constants.pb.h"
  9. #include "components/reporting/storage/storage_module_interface.h"
  10. #include "testing/gmock/include/gmock/gmock.h"
  11. #include "testing/gtest/include/gtest/gtest.h"
  12. #include "third_party/abseil-cpp/absl/types/optional.h"
  13. namespace reporting {
  14. namespace test {
  15. class TestStorageModuleStrict : public StorageModuleInterface {
  16. public:
  17. // As opposed to the production |StorageModule|, test module does not need to
  18. // call factory method - it is created directly by constructor.
  19. TestStorageModuleStrict();
  20. MOCK_METHOD(void,
  21. AddRecord,
  22. (Priority priority, Record record, EnqueueCallback callback),
  23. (override));
  24. MOCK_METHOD(void,
  25. Flush,
  26. (Priority priority, FlushCallback callback),
  27. (override));
  28. MOCK_METHOD(void,
  29. ReportSuccess,
  30. (SequenceInformation sequence_information, bool force),
  31. (override));
  32. MOCK_METHOD(void,
  33. UpdateEncryptionKey,
  34. (SignedEncryptionInfo signed_encryption_key),
  35. (override));
  36. const Record& record() const;
  37. Priority priority() const;
  38. protected:
  39. ~TestStorageModuleStrict() override;
  40. private:
  41. void AddRecordSuccessfully(Priority priority,
  42. Record record,
  43. EnqueueCallback callback);
  44. absl::optional<Record> record_;
  45. absl::optional<Priority> priority_;
  46. };
  47. // Most of the time no need to log uninterested calls to |AddRecord|.
  48. typedef ::testing::NiceMock<TestStorageModuleStrict> TestStorageModule;
  49. } // namespace test
  50. } // namespace reporting
  51. #endif // COMPONENTS_REPORTING_STORAGE_TEST_STORAGE_MODULE_H_