#ifndef NET_REPORTING_MOCK_PERSISTENT_REPORTING_STORE_H_
#define NET_REPORTING_MOCK_PERSISTENT_REPORTING_STORE_H_
#include <vector>
#include "base/functional/callback.h"
#include "net/base/network_anonymization_key.h"
#include "net/reporting/reporting_cache.h"
#include "net/reporting/reporting_endpoint.h"
#include "url/origin.h"
namespace net {
class MockPersistentReportingStore
: public ReportingCache::PersistentReportingStore {
public:
struct Command {
enum class Type {
LOAD_REPORTING_CLIENTS,
ADD_REPORTING_ENDPOINT,
ADD_REPORTING_ENDPOINT_GROUP,
UPDATE_REPORTING_ENDPOINT_GROUP_ACCESS_TIME,
UPDATE_REPORTING_ENDPOINT_DETAILS,
UPDATE_REPORTING_ENDPOINT_GROUP_DETAILS,
DELETE_REPORTING_ENDPOINT,
DELETE_REPORTING_ENDPOINT_GROUP,
FLUSH
};
Command(Type type, ReportingClientsLoadedCallback loaded_callback);
Command(Type type, const ReportingEndpoint& endpoint);
Command(Type type,
const ReportingEndpointGroupKey& group_key,
const GURL& endpoint_url);
Command(Type type, const CachedReportingEndpointGroup& group);
Command(Type type, const ReportingEndpointGroupKey& group_key);
explicit Command(Type type);
Command(const Command& other);
Command(Command&& other);
~Command();
Type type;
ReportingEndpointGroupKey group_key = ReportingEndpointGroupKey();
GURL url;
ReportingClientsLoadedCallback loaded_callback;
};
using CommandList = std::vector<Command>;
MockPersistentReportingStore();
MockPersistentReportingStore(const MockPersistentReportingStore&) = delete;
MockPersistentReportingStore& operator=(const MockPersistentReportingStore&) =
delete;
~MockPersistentReportingStore() override;
void LoadReportingClients(
ReportingClientsLoadedCallback loaded_callback) override;
void AddReportingEndpoint(const ReportingEndpoint& endpoint) override;
void AddReportingEndpointGroup(
const CachedReportingEndpointGroup& group) override;
void UpdateReportingEndpointGroupAccessTime(
const CachedReportingEndpointGroup& group) override;
void UpdateReportingEndpointDetails(
const ReportingEndpoint& endpoint) override;
void UpdateReportingEndpointGroupDetails(
const CachedReportingEndpointGroup& group) override;
void DeleteReportingEndpoint(const ReportingEndpoint& endpoint) override;
void DeleteReportingEndpointGroup(
const CachedReportingEndpointGroup& group) override;
void Flush() override;
void SetPrestoredClients(std::vector<ReportingEndpoint> endpoints,
std::vector<CachedReportingEndpointGroup> groups);
void FinishLoading(bool load_success);
bool VerifyCommands(const CommandList& expected_commands) const;
int CountCommands(Command::Type t);
void ClearCommands();
CommandList GetAllCommands() const;
int StoredEndpointsCount() const { return endpoint_count_; }
int StoredEndpointGroupsCount() const { return endpoint_group_count_; }
private:
CommandList command_list_;
std::vector<ReportingEndpoint> prestored_endpoints_;
std::vector<CachedReportingEndpointGroup> prestored_endpoint_groups_;
bool load_started_ = false;
int endpoint_count_ = 0;
int endpoint_group_count_ = 0;
int queued_endpoint_count_delta_ = 0;
int queued_endpoint_group_count_delta_ = 0;
};
bool operator==(const MockPersistentReportingStore::Command& lhs,
const MockPersistentReportingStore::Command& rhs);
std::ostream& operator<<(std::ostream& out,
const MockPersistentReportingStore::Command& cmd);
}
#endif