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
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_FIRST_PARTY_SETS_SCOPED_MOCK_FIRST_PARTY_SETS_HANDLER_H_
#define CHROME_BROWSER_FIRST_PARTY_SETS_SCOPED_MOCK_FIRST_PARTY_SETS_HANDLER_H_
#include <optional>
#include <string>
#include <utility>
#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/types/optional_ref.h"
#include "content/public/browser/first_party_sets_handler.h"
#include "net/first_party_sets/first_party_sets_cache_filter.h"
#include "net/first_party_sets/first_party_sets_context_config.h"
#include "net/first_party_sets/global_first_party_sets.h"
namespace base {
class Version;
class File;
class Value;
} // namespace base
namespace content {
class BrowserContext;
} // namespace content
namespace first_party_sets {
// Used to create a dummy FirstPartySetsHandler implementation for testing
// purposes. Enabled by default.
//
// Uses an RAII-pattern to install itself as the global singleton in the ctor,
// and remove itself in the dtor.
class ScopedMockFirstPartySetsHandler : public content::FirstPartySetsHandler {
public:
ScopedMockFirstPartySetsHandler();
~ScopedMockFirstPartySetsHandler() override;
// FirstPartySetsHandler:
bool IsEnabled() const override;
void SetPublicFirstPartySets(const base::Version& version,
base::File sets_file) override;
std::optional<net::FirstPartySetEntry> FindEntry(
const net::SchemefulSite& site,
const net::FirstPartySetsContextConfig& config) const override;
void GetContextConfigForPolicy(
base::optional_ref<const base::Value::Dict> policy,
base::OnceCallback<void(net::FirstPartySetsContextConfig)> callback)
override;
void ClearSiteDataOnChangedSetsForContext(
base::RepeatingCallback<content::BrowserContext*()>
browser_context_getter,
const std::string& browser_context_id,
net::FirstPartySetsContextConfig context_config,
base::OnceCallback<void(net::FirstPartySetsContextConfig,
net::FirstPartySetsCacheFilter)> callback)
override;
void ComputeFirstPartySetMetadata(
const net::SchemefulSite& site,
base::optional_ref<const net::SchemefulSite> top_frame_site,
const net::FirstPartySetsContextConfig& config,
base::OnceCallback<void(net::FirstPartySetMetadata)> callback) override;
bool ForEachEffectiveSetEntry(
const net::FirstPartySetsContextConfig& config,
base::FunctionRef<bool(const net::SchemefulSite&,
const net::FirstPartySetEntry&)> f) const override;
// Helper functions for tests to set up context.
void SetContextConfig(net::FirstPartySetsContextConfig config);
void SetCacheFilter(net::FirstPartySetsCacheFilter cache_filter);
void SetGlobalSets(net::GlobalFirstPartySets global_sets);
void set_invoke_callbacks_asynchronously(bool asynchronous) {
invoke_callbacks_asynchronously_ = asynchronous;
}
private:
raw_ptr<content::FirstPartySetsHandler> previous_;
net::GlobalFirstPartySets global_sets_;
net::FirstPartySetsContextConfig config_;
net::FirstPartySetsCacheFilter cache_filter_;
bool invoke_callbacks_asynchronously_ = false;
};
} // namespace first_party_sets
#endif // CHROME_BROWSER_FIRST_PARTY_SETS_SCOPED_MOCK_FIRST_PARTY_SETS_HANDLER_H_
|