missive_client_test_observer.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2022 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 CHROMEOS_DBUS_MISSIVE_MISSIVE_CLIENT_TEST_OBSERVER_H_
  5. #define CHROMEOS_DBUS_MISSIVE_MISSIVE_CLIENT_TEST_OBSERVER_H_
  6. #include <tuple>
  7. #include "base/test/repeating_test_future.h"
  8. #include "chromeos/dbus/missive/missive_client.h"
  9. #include "components/reporting/proto/synced/record.pb.h"
  10. #include "components/reporting/proto/synced/record_constants.pb.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. namespace chromeos {
  13. // Test helper class that observe |FakeMissiveClient| events.
  14. class MissiveClientTestObserver
  15. : public MissiveClient::TestInterface::Observer {
  16. public:
  17. // If |destination| is specified, the observer will capture only enqueued
  18. // records with the specified |destination|, otherwise, all records will be
  19. // captured.
  20. explicit MissiveClientTestObserver(
  21. absl::optional<::reporting::Destination> destination = absl::nullopt);
  22. MissiveClientTestObserver(const MissiveClientTestObserver&) = delete;
  23. MissiveClientTestObserver operator=(const MissiveClientTestObserver&) =
  24. delete;
  25. ~MissiveClientTestObserver() override;
  26. void OnRecordEnqueued(::reporting::Priority priority,
  27. const ::reporting::Record& record) override;
  28. // Wait for next |::reporting::Record| to be enqueued, remove it, and return
  29. // it along with the corresponding |::reporting::Priority|. Returns
  30. // immediately if a record is present in the queue. Times out if a
  31. // record does not arrive after a period of time.
  32. std::tuple<::reporting::Priority, ::reporting::Record>
  33. GetNextEnqueuedRecord();
  34. // Returns true immediately if there any records in the queue. Return false
  35. // otherwise. Does not wait for new records to arrive. Intended to be called
  36. // after GetNextEnqueuedRecord().
  37. bool HasNewEnqueuedRecords();
  38. private:
  39. base::test::RepeatingTestFuture<::reporting::Priority, ::reporting::Record>
  40. enqueued_records_;
  41. const absl::optional<::reporting::Destination> destination_;
  42. };
  43. } // namespace chromeos
  44. #endif // CHROMEOS_DBUS_MISSIVE_MISSIVE_CLIENT_TEST_OBSERVER_H_