[RWS] Move switch-parsing code to FPSParser; move LocalSetDecl to net/
This centralizes the parsing step with the rest of the parsing code;
and encodes the invariants that GlobalFirstPartySets expects the local
set declaration to satisfy, explicitly, by checking them directly in
the only nontrivial constructor of LocalSetDeclaration.
This makes the interface exposed by GlobalFirstPartySets safer, since
it is now impossible to call ApplyManuallySpecifiedSet with an invalid
map of entries.
It also makes it easier to evolve the internal representation of a
LocalSetDeclaration if needed, since they are now only constructed via
a default ctor or the FPSParser; and their internals are only accessed
by the GlobalFirstPartySets class.
Bug: 1503736
Change-Id: I92eb5c778b0a7aad778aff04a7b92744cdc415a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5042729
Reviewed-by: Shuran Huang <shuuran@chromium.org>
Reviewed-by: Maks Orlovich <morlovich@chromium.org>
Auto-Submit: Chris Fredrickson <cfredric@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Chris Fredrickson <cfredric@chromium.org>
Reviewed-by: Ken Buchanan <kenrb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1227538}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
c51b4723e1
commit
bd490b71bd
content
app
browser
BUILD.gnbrowser_main_loop.cc
first_party_sets
database
first_party_set_parser.ccfirst_party_set_parser.hfirst_party_set_parser_unittest.ccfirst_party_sets_handler_impl.hfirst_party_sets_handler_impl_instance.ccfirst_party_sets_handler_impl_instance.hfirst_party_sets_handler_impl_instance_unittest.ccfirst_party_sets_loader.ccfirst_party_sets_loader.hfirst_party_sets_loader_unittest.cclocal_set_declaration.cclocal_set_declaration.hlocal_set_declaration_unittest.cctest
test
net
BUILD.gn
first_party_sets
services/network/public/cpp
@ -60,7 +60,6 @@
|
||||
#include "content/browser/browser_process_io_thread.h"
|
||||
#include "content/browser/browser_thread_impl.h"
|
||||
#include "content/browser/first_party_sets/first_party_sets_handler_impl.h"
|
||||
#include "content/browser/first_party_sets/local_set_declaration.h"
|
||||
#include "content/browser/gpu/gpu_main_thread_factory.h"
|
||||
#include "content/browser/renderer_host/render_process_host_impl.h"
|
||||
#include "content/browser/scheduler/browser_task_executor.h"
|
||||
@ -104,6 +103,7 @@
|
||||
#include "mojo/public/cpp/system/dynamic_library_support.h"
|
||||
#include "mojo/public/cpp/system/invitation.h"
|
||||
#include "mojo/public/cpp/system/message_pipe.h"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "ppapi/buildflags/buildflags.h"
|
||||
#include "sandbox/policy/sandbox.h"
|
||||
#include "sandbox/policy/sandbox_type.h"
|
||||
@ -1254,7 +1254,7 @@ int ContentMainRunnerImpl::RunBrowser(MainFunctionParams main_params,
|
||||
// Minimal browser mode doesn't initialize First-Party Sets the "usual"
|
||||
// way, so we do it manually.
|
||||
content::FirstPartySetsHandlerImpl::GetInstance()->Init(
|
||||
base::FilePath(), LocalSetDeclaration());
|
||||
base::FilePath(), net::LocalSetDeclaration());
|
||||
}
|
||||
|
||||
discardable_shared_memory_manager_ =
|
||||
|
@ -1002,8 +1002,6 @@ source_set("browser") {
|
||||
"first_party_sets/first_party_sets_loader.h",
|
||||
"first_party_sets/first_party_sets_site_data_remover.cc",
|
||||
"first_party_sets/first_party_sets_site_data_remover.h",
|
||||
"first_party_sets/local_set_declaration.cc",
|
||||
"first_party_sets/local_set_declaration.h",
|
||||
"font_access/font_access_manager.cc",
|
||||
"font_access/font_access_manager.h",
|
||||
"font_access/font_enumeration_cache.cc",
|
||||
|
@ -69,8 +69,8 @@
|
||||
#include "content/browser/compositor/viz_process_transport_factory.h"
|
||||
#include "content/browser/download/save_file_manager.h"
|
||||
#include "content/browser/field_trial_synchronizer.h"
|
||||
#include "content/browser/first_party_sets/first_party_set_parser.h"
|
||||
#include "content/browser/first_party_sets/first_party_sets_handler_impl.h"
|
||||
#include "content/browser/first_party_sets/local_set_declaration.h"
|
||||
#include "content/browser/gpu/browser_gpu_channel_host_factory.h"
|
||||
#include "content/browser/gpu/browser_gpu_client_delegate.h"
|
||||
#include "content/browser/gpu/compositor_util.h"
|
||||
@ -1007,7 +1007,8 @@ int BrowserMainLoop::PreMainMessageLoopRun() {
|
||||
if (result_code_ == RESULT_CODE_NORMAL_EXIT) {
|
||||
FirstPartySetsHandlerImpl::GetInstance()->Init(
|
||||
GetContentClient()->browser()->GetFirstPartySetsDirectory(),
|
||||
LocalSetDeclaration(GetRelatedWebsiteSetSwitch()));
|
||||
FirstPartySetParser::ParseFromCommandLine(
|
||||
GetRelatedWebsiteSetSwitch()));
|
||||
}
|
||||
|
||||
variations::MaybeScheduleFakeCrash();
|
||||
|
@ -24,6 +24,7 @@
|
||||
#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"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "sql/database.h"
|
||||
#include "sql/statement.h"
|
||||
#include "sql/test/test_helpers.h"
|
||||
@ -328,7 +329,7 @@ TEST_F(FirstPartySetsDatabaseTest, PersistSets_NoPreExistingDB) {
|
||||
{net::SchemefulSite(GURL(manual_primary)),
|
||||
net::FirstPartySetEntry(net::SchemefulSite(GURL(manual_primary)),
|
||||
net::SiteType::kPrimary, absl::nullopt)}};
|
||||
global_sets.ApplyManuallySpecifiedSet(manual_sets);
|
||||
global_sets.ApplyManuallySpecifiedSet(net::LocalSetDeclaration(manual_sets));
|
||||
|
||||
net::FirstPartySetsContextConfig config(
|
||||
{{net::SchemefulSite(GURL(site_member1)),
|
||||
@ -442,7 +443,7 @@ TEST_F(FirstPartySetsDatabaseTest, PersistSets_NoPreExistingDB_NoPublicSets) {
|
||||
{net::SchemefulSite(GURL(manual_primary)),
|
||||
net::FirstPartySetEntry(net::SchemefulSite(GURL(manual_primary)),
|
||||
net::SiteType::kPrimary, absl::nullopt)}};
|
||||
global_sets.ApplyManuallySpecifiedSet(manual_sets);
|
||||
global_sets.ApplyManuallySpecifiedSet(net::LocalSetDeclaration(manual_sets));
|
||||
|
||||
net::FirstPartySetsContextConfig config(
|
||||
{{net::SchemefulSite(GURL(site_member1)),
|
||||
@ -588,7 +589,7 @@ TEST_F(FirstPartySetsDatabaseTest, PersistSets_PreExistingDB) {
|
||||
{net::SchemefulSite(GURL(manual_primary)),
|
||||
net::FirstPartySetEntry(net::SchemefulSite(GURL(manual_primary)),
|
||||
net::SiteType::kPrimary, absl::nullopt)}};
|
||||
global_sets.ApplyManuallySpecifiedSet(manual_sets);
|
||||
global_sets.ApplyManuallySpecifiedSet(net::LocalSetDeclaration(manual_sets));
|
||||
|
||||
net::FirstPartySetsContextConfig config(
|
||||
{{net::SchemefulSite(GURL(site_member1)),
|
||||
@ -980,7 +981,7 @@ TEST_F(FirstPartySetsDatabaseTest, GetSets_NoPublicSets) {
|
||||
{manual_primary,
|
||||
net::FirstPartySetEntry(manual_primary, net::SiteType::kPrimary,
|
||||
absl::nullopt)}};
|
||||
global_sets.ApplyManuallySpecifiedSet(manual_sets);
|
||||
global_sets.ApplyManuallySpecifiedSet(net::LocalSetDeclaration(manual_sets));
|
||||
|
||||
OpenDatabase();
|
||||
// Trigger the lazy-initialization and insert data with a invalid version, so
|
||||
@ -1096,7 +1097,7 @@ TEST_F(FirstPartySetsDatabaseTest, PersistSets_FormatCheck) {
|
||||
{manual_primary,
|
||||
net::FirstPartySetEntry(manual_primary, net::SiteType::kPrimary,
|
||||
absl::nullopt)}};
|
||||
global_sets.ApplyManuallySpecifiedSet(manual_sets);
|
||||
global_sets.ApplyManuallySpecifiedSet(net::LocalSetDeclaration(manual_sets));
|
||||
|
||||
net::FirstPartySetsContextConfig config(
|
||||
{{config_site_member1,
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
|
||||
#include "net/base/schemeful_site.h"
|
||||
#include "net/first_party_sets/first_party_set_entry.h"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "url/gurl.h"
|
||||
#include "url/origin.h"
|
||||
@ -769,6 +770,43 @@ FirstPartySetParser::ParseSetsFromEnterprisePolicy(
|
||||
context.warnings());
|
||||
}
|
||||
|
||||
// static
|
||||
net::LocalSetDeclaration FirstPartySetParser::ParseFromCommandLine(
|
||||
const std::string& switch_value) {
|
||||
std::istringstream stream(switch_value);
|
||||
|
||||
SetsAndAliases parsed = ParseSetsFromStream(stream, /*emit_errors=*/true,
|
||||
/*emit_metrics*/ false);
|
||||
|
||||
SetsMap entries = std::move(parsed.first);
|
||||
Aliases aliases = std::move(parsed.second);
|
||||
|
||||
if (entries.empty()) {
|
||||
return net::LocalSetDeclaration();
|
||||
}
|
||||
|
||||
const net::SchemefulSite& primary = entries.begin()->second.primary();
|
||||
|
||||
if (base::ranges::any_of(entries,
|
||||
[&primary](const SetsMap::value_type& pair) {
|
||||
return pair.second.primary() != primary;
|
||||
})) {
|
||||
// More than one set was provided. That is (currently) unsupported.
|
||||
LOG(ERROR) << "Ignoring use-related-website-set switch due to multiple set "
|
||||
"declarations.";
|
||||
return net::LocalSetDeclaration();
|
||||
}
|
||||
|
||||
for (const auto& [alias, canonical] : aliases) {
|
||||
auto it = entries.find(canonical);
|
||||
CHECK(it != entries.end());
|
||||
bool inserted = entries.emplace(alias, it->second).second;
|
||||
CHECK(inserted);
|
||||
}
|
||||
|
||||
return net::LocalSetDeclaration(std::move(entries));
|
||||
}
|
||||
|
||||
std::ostream& operator<<(
|
||||
std::ostream& os,
|
||||
const FirstPartySetParser::ParsedPolicySetLists& lists) {
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "content/public/browser/first_party_sets_handler.h"
|
||||
#include "net/base/schemeful_site.h"
|
||||
#include "net/first_party_sets/first_party_set_entry.h"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace content {
|
||||
@ -83,6 +84,9 @@ class CONTENT_EXPORT FirstPartySetParser {
|
||||
// returns an error.
|
||||
[[nodiscard]] static PolicyParseResult ParseSetsFromEnterprisePolicy(
|
||||
const base::Value::Dict& policy);
|
||||
|
||||
[[nodiscard]] static net::LocalSetDeclaration ParseFromCommandLine(
|
||||
const std::string& switch_value);
|
||||
};
|
||||
|
||||
CONTENT_EXPORT std::ostream& operator<<(
|
||||
|
@ -1623,4 +1623,53 @@ TEST_F(FirstPartySetParserTest,
|
||||
{}));
|
||||
}
|
||||
|
||||
TEST(FirstPartySetParser, ParseFromCommandLine_Invalid_MultipleSets) {
|
||||
EXPECT_THAT(FirstPartySetParser::ParseFromCommandLine(
|
||||
R"({"primary": "https://primary1.test",)"
|
||||
R"("associatedSites": ["https://associated1.test"]})"
|
||||
"\n"
|
||||
R"({"primary": "https://primary2.test",)"
|
||||
R"("associatedSites": ["https://associated2.test"]})"),
|
||||
IsEmpty());
|
||||
}
|
||||
|
||||
TEST(FirstPartySetParser, ParseFromCommandLine_Invalid_Singleton) {
|
||||
EXPECT_THAT(FirstPartySetParser::ParseFromCommandLine(
|
||||
R"({"primary": "https://primary1.test"})"),
|
||||
IsEmpty());
|
||||
}
|
||||
|
||||
TEST(FirstPartySetParser,
|
||||
ParseFromCommandLine_Valid_MultipleSubsetsAndAliases) {
|
||||
net::SchemefulSite primary(GURL("https://primary.test"));
|
||||
net::SchemefulSite associated1(GURL("https://associated1.test"));
|
||||
net::SchemefulSite associated2(GURL("https://associated2.test"));
|
||||
net::SchemefulSite associated2_cctld(GURL("https://associated2.cctld"));
|
||||
net::SchemefulSite service(GURL("https://service.test"));
|
||||
|
||||
EXPECT_THAT(
|
||||
FirstPartySetParser::ParseFromCommandLine(
|
||||
R"({"primary": "https://primary.test",)"
|
||||
R"("associatedSites":)"
|
||||
R"(["https://associated1.test", "https://associated2.test"],)"
|
||||
R"("serviceSites": ["https://service.test"],)"
|
||||
R"("ccTLDs": {)"
|
||||
R"( "https://associated2.test": ["https://associated2.cctld"])"
|
||||
R"(})"
|
||||
R"(})")
|
||||
.entries(),
|
||||
UnorderedElementsAre(
|
||||
Pair(primary, net::FirstPartySetEntry(
|
||||
primary, net::SiteType::kPrimary, absl::nullopt)),
|
||||
Pair(associated1,
|
||||
net::FirstPartySetEntry(primary, net::SiteType::kAssociated, 0)),
|
||||
Pair(associated2,
|
||||
net::FirstPartySetEntry(primary, net::SiteType::kAssociated, 1)),
|
||||
Pair(service, net::FirstPartySetEntry(
|
||||
primary, net::SiteType::kService, absl::nullopt)),
|
||||
Pair(associated2_cctld,
|
||||
net::FirstPartySetEntry(primary, net::SiteType::kAssociated,
|
||||
1))));
|
||||
}
|
||||
|
||||
} // namespace content
|
||||
|
@ -7,10 +7,10 @@
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/functional/callback.h"
|
||||
#include "content/browser/first_party_sets/local_set_declaration.h"
|
||||
#include "content/common/content_export.h"
|
||||
#include "content/public/browser/first_party_sets_handler.h"
|
||||
#include "net/first_party_sets/global_first_party_sets.h"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace content {
|
||||
@ -34,7 +34,7 @@ class CONTENT_EXPORT FirstPartySetsHandlerImpl : public FirstPartySetsHandler {
|
||||
//
|
||||
// Only the first call has any effect.
|
||||
void virtual Init(const base::FilePath& user_data_dir,
|
||||
const LocalSetDeclaration& local_set) = 0;
|
||||
const net::LocalSetDeclaration& local_set) = 0;
|
||||
|
||||
// Returns the fully-parsed and validated global First-Party Sets data.
|
||||
// Returns the data synchronously via an absl::optional if it's already
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "content/browser/first_party_sets/first_party_sets_handler_impl.h"
|
||||
#include "content/browser/first_party_sets/first_party_sets_loader.h"
|
||||
#include "content/browser/first_party_sets/first_party_sets_site_data_remover.h"
|
||||
#include "content/browser/first_party_sets/local_set_declaration.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
#include "content/public/browser/content_browser_client.h"
|
||||
#include "content/public/browser/first_party_sets_handler.h"
|
||||
@ -31,6 +30,7 @@
|
||||
#include "net/first_party_sets/first_party_set_metadata.h"
|
||||
#include "net/first_party_sets/first_party_sets_context_config.h"
|
||||
#include "net/first_party_sets/global_first_party_sets.h"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace net {
|
||||
@ -190,7 +190,7 @@ FirstPartySetsHandlerImplInstance::GetSets(
|
||||
|
||||
void FirstPartySetsHandlerImplInstance::Init(
|
||||
const base::FilePath& user_data_dir,
|
||||
const LocalSetDeclaration& local_set) {
|
||||
const net::LocalSetDeclaration& local_set) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
if (initialized_) {
|
||||
return;
|
||||
|
@ -22,11 +22,11 @@
|
||||
#include "content/browser/first_party_sets/first_party_sets_handler_database_helper.h"
|
||||
#include "content/browser/first_party_sets/first_party_sets_handler_impl.h"
|
||||
#include "content/browser/first_party_sets/first_party_sets_loader.h"
|
||||
#include "content/browser/first_party_sets/local_set_declaration.h"
|
||||
#include "content/common/content_export.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"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace net {
|
||||
@ -62,7 +62,7 @@ class CONTENT_EXPORT FirstPartySetsHandlerImplInstance
|
||||
|
||||
// FirstPartySetsHandlerImpl:
|
||||
void Init(const base::FilePath& user_data_dir,
|
||||
const LocalSetDeclaration& local_set) override;
|
||||
const net::LocalSetDeclaration& local_set) override;
|
||||
[[nodiscard]] absl::optional<net::GlobalFirstPartySets> GetSets(
|
||||
base::OnceCallback<void(net::GlobalFirstPartySets)> callback) override;
|
||||
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "base/test/test_future.h"
|
||||
#include "base/version.h"
|
||||
#include "content/browser/first_party_sets/first_party_set_parser.h"
|
||||
#include "content/browser/first_party_sets/local_set_declaration.h"
|
||||
#include "content/public/browser/first_party_sets_handler.h"
|
||||
#include "content/public/common/content_features.h"
|
||||
#include "content/public/test/browser_task_environment.h"
|
||||
@ -34,6 +33,7 @@
|
||||
#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"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "testing/gmock/include/gmock/gmock-matchers.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
@ -295,7 +295,7 @@ TEST_F(FirstPartySetsHandlerImplDisabledTest, InitImmediately) {
|
||||
// The local set declaration should be ignored, since the handler is disabled.
|
||||
handler().Init(
|
||||
/*user_data_dir=*/{},
|
||||
LocalSetDeclaration(
|
||||
FirstPartySetParser::ParseFromCommandLine(
|
||||
R"({"primary": "https://example.test",)"
|
||||
R"("associatedSites": ["https://associatedsite1.test"]})"));
|
||||
|
||||
@ -334,7 +334,7 @@ TEST_F(FirstPartySetsHandlerImplEnabledTest, EmptyDBPath) {
|
||||
// prevent `on_sets_ready` from being invoked.
|
||||
handler().Init(
|
||||
/*user_data_dir=*/{},
|
||||
LocalSetDeclaration(
|
||||
FirstPartySetParser::ParseFromCommandLine(
|
||||
R"({"primary": "https://example.test",)"
|
||||
R"("associatedSites": ["https://associatedsite1.test"]})"));
|
||||
|
||||
@ -366,7 +366,7 @@ TEST_F(FirstPartySetsHandlerImplEnabledTest,
|
||||
handler().SetPublicFirstPartySets(base::Version("0.0.1"),
|
||||
WritePublicSetsFile(input));
|
||||
|
||||
handler().Init(scoped_dir_.GetPath(), LocalSetDeclaration());
|
||||
handler().Init(scoped_dir_.GetPath(), net::LocalSetDeclaration());
|
||||
ASSERT_THAT(GetSetsAndWait().FindEntries({foo, associated},
|
||||
net::FirstPartySetsContextConfig()),
|
||||
UnorderedElementsAre(
|
||||
@ -413,7 +413,8 @@ TEST_F(FirstPartySetsHandlerImplEnabledTest,
|
||||
R"("associatedSites": ["https://associatedsite.test"]})";
|
||||
ASSERT_TRUE(base::JSONReader::Read(input));
|
||||
|
||||
handler.Init(scoped_dir_.GetPath(), LocalSetDeclaration(input));
|
||||
handler.Init(scoped_dir_.GetPath(),
|
||||
FirstPartySetParser::ParseFromCommandLine(input));
|
||||
|
||||
// Should not yet be recorded.
|
||||
histogram.ExpectTotalCount(kFirstPartySetsClearSiteDataOutcomeHistogram, 0);
|
||||
@ -463,7 +464,7 @@ TEST_F(FirstPartySetsHandlerImplEnabledTest,
|
||||
handler.SetPublicFirstPartySets(base::Version("0.0.1"),
|
||||
WritePublicSetsFile(input));
|
||||
|
||||
handler.Init(scoped_dir_.GetPath(), LocalSetDeclaration());
|
||||
handler.Init(scoped_dir_.GetPath(), net::LocalSetDeclaration());
|
||||
|
||||
EXPECT_THAT(
|
||||
HasEntryInBrowserContextsClearedAndWait(handler, browser_context_id),
|
||||
@ -511,7 +512,7 @@ TEST_F(FirstPartySetsHandlerImplEnabledTest,
|
||||
handler.SetPublicFirstPartySets(base::Version("0.0.2"),
|
||||
WritePublicSetsFile(input));
|
||||
|
||||
handler.Init(scoped_dir_.GetPath(), LocalSetDeclaration());
|
||||
handler.Init(scoped_dir_.GetPath(), net::LocalSetDeclaration());
|
||||
|
||||
// Should not yet be recorded.
|
||||
histogram.ExpectTotalCount(kFirstPartySetsClearSiteDataOutcomeHistogram, 0);
|
||||
@ -559,7 +560,7 @@ TEST_F(FirstPartySetsHandlerImplEnabledTest,
|
||||
WritePublicSetsFile(input));
|
||||
|
||||
handler().Init(
|
||||
/*user_data_dir=*/{}, LocalSetDeclaration());
|
||||
/*user_data_dir=*/{}, net::LocalSetDeclaration());
|
||||
ASSERT_THAT(GetSetsAndWait().FindEntries({foo, associated},
|
||||
net::FirstPartySetsContextConfig()),
|
||||
UnorderedElementsAre(
|
||||
@ -587,7 +588,7 @@ TEST_F(FirstPartySetsHandlerImplEnabledTest,
|
||||
|
||||
base::HistogramTester histogram;
|
||||
|
||||
handler().Init(scoped_dir_.GetPath(), LocalSetDeclaration());
|
||||
handler().Init(scoped_dir_.GetPath(), net::LocalSetDeclaration());
|
||||
|
||||
const std::string browser_context_id = "profile";
|
||||
base::test::TestFuture<net::FirstPartySetsContextConfig,
|
||||
@ -639,7 +640,7 @@ TEST_F(FirstPartySetsHandlerImplEnabledTest,
|
||||
handler().SetPublicFirstPartySets(base::Version("1.2.3"),
|
||||
WritePublicSetsFile(input));
|
||||
|
||||
handler().Init(scoped_dir_.GetPath(), LocalSetDeclaration());
|
||||
handler().Init(scoped_dir_.GetPath(), net::LocalSetDeclaration());
|
||||
|
||||
// Wait until initialization is complete.
|
||||
GetSetsAndWait();
|
||||
@ -666,7 +667,7 @@ TEST_F(FirstPartySetsHandlerImplEnabledTest,
|
||||
base::test::TestFuture<net::GlobalFirstPartySets> future;
|
||||
EXPECT_EQ(handler().GetSets(future.GetCallback()), absl::nullopt);
|
||||
|
||||
handler().Init(scoped_dir_.GetPath(), LocalSetDeclaration());
|
||||
handler().Init(scoped_dir_.GetPath(), net::LocalSetDeclaration());
|
||||
|
||||
const std::string input =
|
||||
R"({"primary": "https://example.test", )"
|
||||
@ -699,7 +700,7 @@ TEST_F(FirstPartySetsHandlerImplEnabledTest,
|
||||
|
||||
TEST_F(FirstPartySetsHandlerImplEnabledTest,
|
||||
ComputeFirstPartySetMetadata_SynchronousResult) {
|
||||
handler().Init(scoped_dir_.GetPath(), LocalSetDeclaration());
|
||||
handler().Init(scoped_dir_.GetPath(), net::LocalSetDeclaration());
|
||||
|
||||
handler().SetPublicFirstPartySets(
|
||||
base::Version("1.2.3"),
|
||||
@ -732,7 +733,7 @@ TEST_F(FirstPartySetsHandlerImplEnabledTest,
|
||||
future.GetCallback());
|
||||
EXPECT_FALSE(future.IsReady());
|
||||
|
||||
handler().Init(scoped_dir_.GetPath(), LocalSetDeclaration());
|
||||
handler().Init(scoped_dir_.GetPath(), net::LocalSetDeclaration());
|
||||
|
||||
handler().SetPublicFirstPartySets(
|
||||
base::Version("1.2.3"),
|
||||
@ -758,7 +759,7 @@ TEST_F(FirstPartySetsHandlerImplEnabledTest,
|
||||
return true;
|
||||
}));
|
||||
|
||||
handler().Init(scoped_dir_.GetPath(), LocalSetDeclaration());
|
||||
handler().Init(scoped_dir_.GetPath(), net::LocalSetDeclaration());
|
||||
|
||||
const std::string input =
|
||||
R"({"primary": "https://example.test", )"
|
||||
@ -793,7 +794,7 @@ TEST_F(FirstPartySetsHandlerImplEnabledTest,
|
||||
net::SchemefulSite associated1(GURL("https://associatedsite1.test"));
|
||||
net::SchemefulSite associated2(GURL("https://associatedsite2.test"));
|
||||
|
||||
handler().Init(scoped_dir_.GetPath(), LocalSetDeclaration());
|
||||
handler().Init(scoped_dir_.GetPath(), net::LocalSetDeclaration());
|
||||
|
||||
const std::string input =
|
||||
R"({"primary": "https://example.test", )"
|
||||
@ -834,7 +835,7 @@ class FirstPartySetsHandlerGetContextConfigForPolicyTest
|
||||
: public FirstPartySetsHandlerImplEnabledTest {
|
||||
public:
|
||||
FirstPartySetsHandlerGetContextConfigForPolicyTest() {
|
||||
handler().Init(scoped_dir_.GetPath(), LocalSetDeclaration());
|
||||
handler().Init(scoped_dir_.GetPath(), net::LocalSetDeclaration());
|
||||
}
|
||||
|
||||
// Writes the public list of First-Party Sets which GetContextConfigForPolicy
|
||||
|
@ -4,11 +4,8 @@
|
||||
|
||||
#include "content/browser/first_party_sets/first_party_sets_loader.h"
|
||||
|
||||
#include <iterator>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/flat_map.h"
|
||||
#include "base/files/file_util.h"
|
||||
@ -17,8 +14,8 @@
|
||||
#include "base/task/thread_pool.h"
|
||||
#include "base/version.h"
|
||||
#include "content/browser/first_party_sets/first_party_set_parser.h"
|
||||
#include "content/browser/first_party_sets/local_set_declaration.h"
|
||||
#include "net/first_party_sets/global_first_party_sets.h"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace content {
|
||||
@ -42,7 +39,7 @@ FirstPartySetsLoader::~FirstPartySetsLoader() {
|
||||
}
|
||||
|
||||
void FirstPartySetsLoader::SetManuallySpecifiedSet(
|
||||
const LocalSetDeclaration& local_set) {
|
||||
const net::LocalSetDeclaration& local_set) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
if (manually_specified_set_.has_value()) {
|
||||
return;
|
||||
@ -119,9 +116,7 @@ void FirstPartySetsLoader::MaybeFinishLoading() {
|
||||
!manually_specified_set_.has_value()) {
|
||||
return;
|
||||
}
|
||||
if (!manually_specified_set_->empty()) {
|
||||
sets_->ApplyManuallySpecifiedSet(manually_specified_set_->GetSet());
|
||||
}
|
||||
sets_->ApplyManuallySpecifiedSet(manually_specified_set_.value());
|
||||
std::move(on_load_complete_).Run(std::move(sets_).value());
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,9 @@
|
||||
#include "base/sequence_checker.h"
|
||||
#include "base/thread_annotations.h"
|
||||
#include "base/timer/elapsed_timer.h"
|
||||
#include "content/browser/first_party_sets/local_set_declaration.h"
|
||||
#include "content/common/content_export.h"
|
||||
#include "net/first_party_sets/global_first_party_sets.h"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace content {
|
||||
@ -36,7 +36,7 @@ class CONTENT_EXPORT FirstPartySetsLoader {
|
||||
|
||||
// Stores the First-Party Set that was provided via the `kUseFirstPartySet`
|
||||
// flag/switch. Only the first call has any effect.
|
||||
void SetManuallySpecifiedSet(const LocalSetDeclaration& local_set);
|
||||
void SetManuallySpecifiedSet(const net::LocalSetDeclaration& local_set);
|
||||
|
||||
// Asynchronously parses and stores the sets from `sets_file`, and merges with
|
||||
// any previously-loaded sets as needed. In case of invalid input, the set of
|
||||
@ -65,7 +65,7 @@ class CONTENT_EXPORT FirstPartySetsLoader {
|
||||
|
||||
// Holds the set that was provided on the command line (if any). This is
|
||||
// nullopt until `SetManuallySpecifiedSet` is called.
|
||||
absl::optional<LocalSetDeclaration> manually_specified_set_
|
||||
absl::optional<net::LocalSetDeclaration> manually_specified_set_
|
||||
GUARDED_BY_CONTEXT(sequence_checker_);
|
||||
|
||||
enum Progress {
|
||||
|
@ -4,18 +4,16 @@
|
||||
|
||||
#include "content/browser/first_party_sets/first_party_sets_loader.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/files/scoped_temp_dir.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "base/test/task_environment.h"
|
||||
#include "base/test/test_future.h"
|
||||
#include "content/browser/first_party_sets/local_set_declaration.h"
|
||||
#include "net/base/schemeful_site.h"
|
||||
#include "net/first_party_sets/first_party_set_entry.h"
|
||||
#include "net/first_party_sets/first_party_sets_context_config.h"
|
||||
#include "net/first_party_sets/global_first_party_sets.h"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "testing/gmock/include/gmock/gmock-matchers.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
@ -62,7 +60,7 @@ class FirstPartySetsLoaderTest : public ::testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(FirstPartySetsLoaderTest, IgnoresInvalidFile) {
|
||||
loader().SetManuallySpecifiedSet(LocalSetDeclaration());
|
||||
loader().SetManuallySpecifiedSet(net::LocalSetDeclaration());
|
||||
SetComponentSets(loader(), base::Version("1.2.3"),
|
||||
"certainly not valid JSON");
|
||||
EXPECT_EQ(WaitAndGetResult().FindEntry(
|
||||
@ -72,7 +70,7 @@ TEST_F(FirstPartySetsLoaderTest, IgnoresInvalidFile) {
|
||||
}
|
||||
|
||||
TEST_F(FirstPartySetsLoaderTest, IgnoresInvalidVersion) {
|
||||
loader().SetManuallySpecifiedSet(LocalSetDeclaration());
|
||||
loader().SetManuallySpecifiedSet(net::LocalSetDeclaration());
|
||||
SetComponentSets(
|
||||
loader(), base::Version(),
|
||||
"{\"primary\": \"https://example.test\",\"associatedSites\": "
|
||||
@ -98,7 +96,7 @@ TEST_F(FirstPartySetsLoaderTest, AcceptsMultipleSets) {
|
||||
"{\"primary\": \"https://foo.test\",\"associatedSites\": "
|
||||
"[\"https://associatedsite2.test\"]}");
|
||||
// Set required input to make sure callback gets called.
|
||||
loader().SetManuallySpecifiedSet(LocalSetDeclaration());
|
||||
loader().SetManuallySpecifiedSet(net::LocalSetDeclaration());
|
||||
|
||||
EXPECT_THAT(
|
||||
WaitAndGetResult().FindEntries({example, associated1, foo, associated2},
|
||||
@ -133,7 +131,7 @@ TEST_F(FirstPartySetsLoaderTest, SetComponentSets_Idempotent) {
|
||||
R"({"primary": "https://foo2.test",)"
|
||||
R"("associatedSites": ["https://associatedsite2.test"]})");
|
||||
// Set required input to make sure callback gets called.
|
||||
loader().SetManuallySpecifiedSet(LocalSetDeclaration());
|
||||
loader().SetManuallySpecifiedSet(net::LocalSetDeclaration());
|
||||
|
||||
// The second call to SetComponentSets should have had no effect.
|
||||
EXPECT_THAT(
|
||||
@ -147,45 +145,60 @@ TEST_F(FirstPartySetsLoaderTest, SetComponentSets_Idempotent) {
|
||||
}
|
||||
|
||||
TEST_F(FirstPartySetsLoaderTest, SetsManuallySpecified) {
|
||||
const net::SchemefulSite bar(GURL("https://bar.test"));
|
||||
const net::SchemefulSite associated1(GURL("https://associatedsite1.test"));
|
||||
const net::SchemefulSite associated2(GURL("https://associatedsite2.test"));
|
||||
|
||||
SetComponentSets(loader(), base::Version("1.2.3"),
|
||||
R"({"primary": "https://example.test", "associatedSites": )"
|
||||
R"(["https://associatedsite1.test"]})");
|
||||
loader().SetManuallySpecifiedSet(LocalSetDeclaration(
|
||||
R"({"primary": "https://bar.test",)"
|
||||
R"("associatedSites": ["https://associatedsite2.test"]})"));
|
||||
loader().SetManuallySpecifiedSet(net::LocalSetDeclaration(
|
||||
base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>({
|
||||
{bar, net::FirstPartySetEntry(bar, net::SiteType::kPrimary,
|
||||
absl::nullopt)},
|
||||
{associated2,
|
||||
net::FirstPartySetEntry(bar, net::SiteType::kAssociated, 0)},
|
||||
})));
|
||||
|
||||
EXPECT_THAT(WaitAndGetResult().FindEntry(
|
||||
net::SchemefulSite(GURL("https://associatedsite2.test")),
|
||||
net::FirstPartySetsContextConfig()),
|
||||
Optional(net::FirstPartySetEntry(
|
||||
net::SchemefulSite(GURL("https://bar.test")),
|
||||
net::SiteType::kAssociated, 0)));
|
||||
EXPECT_THAT(
|
||||
WaitAndGetResult().FindEntry(associated2,
|
||||
net::FirstPartySetsContextConfig()),
|
||||
Optional(net::FirstPartySetEntry(bar, net::SiteType::kAssociated, 0)));
|
||||
}
|
||||
|
||||
TEST_F(FirstPartySetsLoaderTest, SetsManuallySpecified_Idempotent) {
|
||||
loader().SetManuallySpecifiedSet(LocalSetDeclaration(
|
||||
R"({"primary": "https://bar.test",)"
|
||||
R"("associatedSites": ["https://associatedsite1.test"]})"));
|
||||
const net::SchemefulSite bar(GURL("https://bar.test"));
|
||||
const net::SchemefulSite associated1(GURL("https://associatedsite1.test"));
|
||||
const net::SchemefulSite associated2(GURL("https://associatedsite2.test"));
|
||||
|
||||
loader().SetManuallySpecifiedSet(net::LocalSetDeclaration(
|
||||
base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>({
|
||||
{bar, net::FirstPartySetEntry(bar, net::SiteType::kPrimary,
|
||||
absl::nullopt)},
|
||||
{associated1,
|
||||
net::FirstPartySetEntry(bar, net::SiteType::kAssociated, 0)},
|
||||
})));
|
||||
|
||||
// All but the first SetManuallySpecifiedSet call should be ignored.
|
||||
loader().SetManuallySpecifiedSet(LocalSetDeclaration(
|
||||
R"({"primary": "https://bar.test",)"
|
||||
R"("associatedSites": ["https://associatedsite2.test"]})"));
|
||||
loader().SetManuallySpecifiedSet(net::LocalSetDeclaration(
|
||||
base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>({
|
||||
{bar, net::FirstPartySetEntry(bar, net::SiteType::kPrimary,
|
||||
absl::nullopt)},
|
||||
{associated2,
|
||||
net::FirstPartySetEntry(bar, net::SiteType::kAssociated, 0)},
|
||||
})));
|
||||
|
||||
SetComponentSets(loader(), base::Version(), "");
|
||||
|
||||
const net::SchemefulSite associated1(GURL("https://associatedsite1.test"));
|
||||
|
||||
EXPECT_THAT(WaitAndGetResult().FindEntries(
|
||||
{
|
||||
associated1,
|
||||
net::SchemefulSite(GURL("https://associatedsite2.test")),
|
||||
associated2,
|
||||
},
|
||||
net::FirstPartySetsContextConfig()),
|
||||
UnorderedElementsAre(Pair(
|
||||
associated1, net::FirstPartySetEntry(
|
||||
net::SchemefulSite(GURL("https://bar.test")),
|
||||
net::SiteType::kAssociated, 0))));
|
||||
UnorderedElementsAre(
|
||||
Pair(associated1, net::FirstPartySetEntry(
|
||||
bar, net::SiteType::kAssociated, 0))));
|
||||
}
|
||||
|
||||
} // namespace content
|
||||
|
@ -1,89 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "content/browser/first_party_sets/local_set_declaration.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/ranges/algorithm.h"
|
||||
#include "content/browser/first_party_sets/first_party_set_parser.h"
|
||||
#include "net/base/schemeful_site.h"
|
||||
#include "net/first_party_sets/first_party_set_entry.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
namespace {
|
||||
|
||||
absl::optional<FirstPartySetParser::SingleSet> CanonicalizeSet(
|
||||
const std::string& use_first_party_set_flag_value) {
|
||||
std::istringstream stream(use_first_party_set_flag_value);
|
||||
|
||||
FirstPartySetParser::SetsAndAliases parsed =
|
||||
FirstPartySetParser::ParseSetsFromStream(stream, /*emit_errors=*/true,
|
||||
/*emit_metrics*/ false);
|
||||
|
||||
FirstPartySetParser::SetsMap entries = std::move(parsed.first);
|
||||
FirstPartySetParser::Aliases aliases = std::move(parsed.second);
|
||||
|
||||
if (entries.empty()) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
const net::SchemefulSite primary = entries.begin()->second.primary();
|
||||
|
||||
if (base::ranges::any_of(
|
||||
entries,
|
||||
[&primary](const FirstPartySetParser::SetsMap::value_type& pair) {
|
||||
return pair.second.primary() != primary;
|
||||
})) {
|
||||
// More than one set was provided. That is (currently) unsupported.
|
||||
LOG(ERROR) << "Ignoring use-related-website-set switch due to multiple set "
|
||||
"declarations.";
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
for (const auto& [alias, canonical] : aliases) {
|
||||
auto it = entries.find(canonical);
|
||||
CHECK(it != entries.end());
|
||||
bool inserted = entries.emplace(alias, it->second).second;
|
||||
CHECK(inserted);
|
||||
}
|
||||
|
||||
return absl::make_optional(std::move(entries));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
LocalSetDeclaration::LocalSetDeclaration()
|
||||
: LocalSetDeclaration(absl::nullopt) {}
|
||||
|
||||
LocalSetDeclaration::LocalSetDeclaration(
|
||||
const std::string& use_first_party_set_flag_value)
|
||||
: LocalSetDeclaration(CanonicalizeSet(use_first_party_set_flag_value)) {}
|
||||
|
||||
LocalSetDeclaration::LocalSetDeclaration(
|
||||
absl::optional<FirstPartySetParser::SingleSet> parsed_set)
|
||||
: parsed_set_(std::move(parsed_set)) {}
|
||||
|
||||
LocalSetDeclaration::~LocalSetDeclaration() = default;
|
||||
|
||||
LocalSetDeclaration::LocalSetDeclaration(const LocalSetDeclaration&) = default;
|
||||
LocalSetDeclaration& LocalSetDeclaration::operator=(
|
||||
const LocalSetDeclaration&) = default;
|
||||
|
||||
LocalSetDeclaration::LocalSetDeclaration(LocalSetDeclaration&&) = default;
|
||||
LocalSetDeclaration& LocalSetDeclaration::operator=(LocalSetDeclaration&&) =
|
||||
default;
|
||||
|
||||
const FirstPartySetParser::SingleSet& LocalSetDeclaration::GetSet() const {
|
||||
CHECK(!empty());
|
||||
const FirstPartySetParser::SingleSet& set = parsed_set_.value();
|
||||
CHECK(!set.empty());
|
||||
return set;
|
||||
}
|
||||
|
||||
} // namespace content
|
@ -1,48 +0,0 @@
|
||||
// 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 CONTENT_BROWSER_FIRST_PARTY_SETS_LOCAL_SET_DECLARATION_H_
|
||||
#define CONTENT_BROWSER_FIRST_PARTY_SETS_LOCAL_SET_DECLARATION_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "content/browser/first_party_sets/first_party_set_parser.h"
|
||||
#include "content/common/content_export.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
class CONTENT_EXPORT LocalSetDeclaration {
|
||||
public:
|
||||
LocalSetDeclaration();
|
||||
|
||||
explicit LocalSetDeclaration(
|
||||
const std::string& use_first_party_set_flag_value);
|
||||
|
||||
~LocalSetDeclaration();
|
||||
|
||||
LocalSetDeclaration(const LocalSetDeclaration&);
|
||||
LocalSetDeclaration& operator=(const LocalSetDeclaration&);
|
||||
LocalSetDeclaration(LocalSetDeclaration&&);
|
||||
LocalSetDeclaration& operator=(LocalSetDeclaration&&);
|
||||
|
||||
bool empty() const { return !parsed_set_.has_value(); }
|
||||
|
||||
size_t size() const { return empty() ? 0 : GetSet().size(); }
|
||||
|
||||
// Gets the set entries. Must not be called if `empty()` returns true.
|
||||
const FirstPartySetParser::SingleSet& GetSet() const;
|
||||
|
||||
private:
|
||||
explicit LocalSetDeclaration(
|
||||
absl::optional<FirstPartySetParser::SingleSet> parsed_set);
|
||||
|
||||
// Stores the result of parsing the inputs. Specifically, this may be empty if
|
||||
// no set was locally defined; otherwise, it holds the collection of
|
||||
// FirstPartySetEntries and any ccTLD aliases.
|
||||
absl::optional<FirstPartySetParser::SingleSet> parsed_set_;
|
||||
};
|
||||
|
||||
} // namespace content
|
||||
|
||||
#endif // CONTENT_BROWSER_FIRST_PARTY_SETS_LOCAL_SET_DECLARATION_H_
|
@ -1,85 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "content/browser/first_party_sets/local_set_declaration.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "content/browser/first_party_sets/local_set_declaration.h"
|
||||
#include "net/base/schemeful_site.h"
|
||||
#include "net/first_party_sets/first_party_set_entry.h"
|
||||
#include "testing/gmock/include/gmock/gmock-matchers.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
using ::testing::IsEmpty;
|
||||
using ::testing::Pair;
|
||||
using ::testing::UnorderedElementsAre;
|
||||
|
||||
namespace content {
|
||||
|
||||
TEST(LocalSetDeclarationTest, Invalid_EmptyString) {
|
||||
EXPECT_THAT(LocalSetDeclaration(""), IsEmpty());
|
||||
}
|
||||
|
||||
TEST(LocalSetDeclarationTest, Invalid_MultipleSets) {
|
||||
EXPECT_THAT(LocalSetDeclaration(
|
||||
R"({"primary": "https://primary1.test",)"
|
||||
R"("associatedSites": ["https://associated1.test"]})"
|
||||
"\n"
|
||||
R"({"primary": "https://primary2.test",)"
|
||||
R"("associatedSites": ["https://associated2.test"]})"),
|
||||
IsEmpty());
|
||||
}
|
||||
|
||||
TEST(LocalSetDeclarationTest, Valid_Basic) {
|
||||
net::SchemefulSite primary(GURL("https://primary.test"));
|
||||
net::SchemefulSite associated(GURL("https://associated.test"));
|
||||
|
||||
EXPECT_THAT(
|
||||
LocalSetDeclaration(R"({"primary": "https://primary.test",)"
|
||||
R"("associatedSites": ["https://associated.test"]})")
|
||||
.GetSet(),
|
||||
UnorderedElementsAre(
|
||||
Pair(primary, net::FirstPartySetEntry(
|
||||
primary, net::SiteType::kPrimary, absl::nullopt)),
|
||||
Pair(associated, net::FirstPartySetEntry(
|
||||
primary, net::SiteType::kAssociated, 0))));
|
||||
}
|
||||
|
||||
TEST(LocalSetDeclarationTest, Valid_MultipleSubsetsAndAliases) {
|
||||
net::SchemefulSite primary(GURL("https://primary.test"));
|
||||
net::SchemefulSite associated1(GURL("https://associated1.test"));
|
||||
net::SchemefulSite associated2(GURL("https://associated2.test"));
|
||||
net::SchemefulSite associated2_cctld(GURL("https://associated2.cctld"));
|
||||
net::SchemefulSite service(GURL("https://service.test"));
|
||||
|
||||
EXPECT_THAT(
|
||||
LocalSetDeclaration(
|
||||
R"({"primary": "https://primary.test",)"
|
||||
R"("associatedSites":)"
|
||||
R"(["https://associated1.test", "https://associated2.test"],)"
|
||||
R"("serviceSites": ["https://service.test"],)"
|
||||
R"("ccTLDs": {)"
|
||||
R"( "https://associated2.test": ["https://associated2.cctld"])"
|
||||
R"(})"
|
||||
R"(})")
|
||||
.GetSet(),
|
||||
UnorderedElementsAre(
|
||||
Pair(primary, net::FirstPartySetEntry(
|
||||
primary, net::SiteType::kPrimary, absl::nullopt)),
|
||||
Pair(associated1,
|
||||
net::FirstPartySetEntry(primary, net::SiteType::kAssociated, 0)),
|
||||
Pair(associated2,
|
||||
net::FirstPartySetEntry(primary, net::SiteType::kAssociated, 1)),
|
||||
Pair(service, net::FirstPartySetEntry(
|
||||
primary, net::SiteType::kService, absl::nullopt)),
|
||||
Pair(associated2_cctld,
|
||||
net::FirstPartySetEntry(primary, net::SiteType::kAssociated,
|
||||
1))));
|
||||
}
|
||||
|
||||
} // namespace content
|
@ -49,7 +49,7 @@ ScopedMockFirstPartySetsHandler::FindEntry(
|
||||
|
||||
void ScopedMockFirstPartySetsHandler::Init(
|
||||
const base::FilePath& user_data_dir,
|
||||
const LocalSetDeclaration& local_set) {}
|
||||
const net::LocalSetDeclaration& local_set) {}
|
||||
|
||||
[[nodiscard]] absl::optional<net::GlobalFirstPartySets>
|
||||
ScopedMockFirstPartySetsHandler::GetSets(
|
||||
|
@ -6,7 +6,6 @@
|
||||
#define CONTENT_BROWSER_FIRST_PARTY_SETS_TEST_SCOPED_MOCK_FIRST_PARTY_SETS_HANDLER_H_
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
@ -68,7 +67,7 @@ class ScopedMockFirstPartySetsHandler
|
||||
const net::FirstPartySetEntry&)> f) const override;
|
||||
// FirstPartySetsHandlerImpl:
|
||||
void Init(const base::FilePath& user_data_dir,
|
||||
const LocalSetDeclaration& local_set) override;
|
||||
const net::LocalSetDeclaration& local_set) override;
|
||||
[[nodiscard]] absl::optional<net::GlobalFirstPartySets> GetSets(
|
||||
base::OnceCallback<void(net::GlobalFirstPartySets)> callback) override;
|
||||
|
||||
|
@ -2403,7 +2403,6 @@ test("content_unittests") {
|
||||
"../browser/first_party_sets/first_party_sets_handler_database_helper_unittest.cc",
|
||||
"../browser/first_party_sets/first_party_sets_handler_impl_instance_unittest.cc",
|
||||
"../browser/first_party_sets/first_party_sets_loader_unittest.cc",
|
||||
"../browser/first_party_sets/local_set_declaration_unittest.cc",
|
||||
"../browser/font_access/font_access_manager_unittest.cc",
|
||||
"../browser/font_access/font_enumeration_data_source_unittest.cc",
|
||||
"../browser/generic_sensor/web_contents_sensor_provider_proxy_unittest.cc",
|
||||
|
@ -515,6 +515,8 @@ component("net") {
|
||||
"first_party_sets/first_party_sets_context_config.h",
|
||||
"first_party_sets/global_first_party_sets.cc",
|
||||
"first_party_sets/global_first_party_sets.h",
|
||||
"first_party_sets/local_set_declaration.cc",
|
||||
"first_party_sets/local_set_declaration.h",
|
||||
"http/alternative_service.cc",
|
||||
"http/alternative_service.h",
|
||||
"http/bidirectional_stream.cc",
|
||||
@ -2561,6 +2563,7 @@ test("net_unittests") {
|
||||
"first_party_sets/first_party_sets_cache_filter_unittest.cc",
|
||||
"first_party_sets/first_party_sets_context_config_unittest.cc",
|
||||
"first_party_sets/global_first_party_sets_unittest.cc",
|
||||
"first_party_sets/local_set_declaration_unittest.cc",
|
||||
"http/alternative_service_unittest.cc",
|
||||
"http/bidirectional_stream_unittest.cc",
|
||||
"http/broken_alternative_services_unittest.cc",
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "net/first_party_sets/global_first_party_sets.h"
|
||||
|
||||
#include <set>
|
||||
#include <tuple>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
@ -19,6 +18,7 @@
|
||||
#include "net/first_party_sets/first_party_set_entry_override.h"
|
||||
#include "net/first_party_sets/first_party_set_metadata.h"
|
||||
#include "net/first_party_sets/first_party_sets_context_config.h"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace net {
|
||||
@ -183,12 +183,18 @@ FirstPartySetMetadata GlobalFirstPartySets::ComputeMetadata(
|
||||
}
|
||||
|
||||
void GlobalFirstPartySets::ApplyManuallySpecifiedSet(
|
||||
const base::flat_map<SchemefulSite, FirstPartySetEntry>& manual_entries) {
|
||||
const LocalSetDeclaration& local_set_declaration) {
|
||||
CHECK(manual_config_.empty());
|
||||
if (local_set_declaration.empty()) {
|
||||
// Nothing to do.
|
||||
return;
|
||||
}
|
||||
|
||||
// We handle the manually-specified set the same way as we handle
|
||||
// replacement enterprise policy sets.
|
||||
manual_config_ = ComputeConfig(
|
||||
/*replacement_sets=*/{manual_entries}, /*addition_sets=*/{});
|
||||
/*replacement_sets=*/{local_set_declaration.entries()},
|
||||
/*addition_sets=*/{});
|
||||
}
|
||||
|
||||
void GlobalFirstPartySets::UnsafeSetManualConfig(
|
||||
|
@ -5,8 +5,6 @@
|
||||
#ifndef NET_FIRST_PARTY_SETS_GLOBAL_FIRST_PARTY_SETS_H_
|
||||
#define NET_FIRST_PARTY_SETS_GLOBAL_FIRST_PARTY_SETS_H_
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "base/containers/flat_map.h"
|
||||
#include "base/containers/flat_set.h"
|
||||
#include "base/functional/function_ref.h"
|
||||
@ -16,6 +14,7 @@
|
||||
#include "net/first_party_sets/first_party_set_entry.h"
|
||||
#include "net/first_party_sets/first_party_set_entry_override.h"
|
||||
#include "net/first_party_sets/first_party_sets_context_config.h"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace mojo {
|
||||
@ -86,10 +85,9 @@ class NET_EXPORT GlobalFirstPartySets {
|
||||
const FirstPartySetsContextConfig& fps_context_config) const;
|
||||
|
||||
// Modifies this instance such that it will respect the given
|
||||
// manually-specified set. `manual_entries` should contain entries for aliases
|
||||
// as well as "canonical" sites.
|
||||
// manually-specified set.
|
||||
void ApplyManuallySpecifiedSet(
|
||||
const base::flat_map<SchemefulSite, FirstPartySetEntry>& manual_entries);
|
||||
const LocalSetDeclaration& local_set_declaration);
|
||||
|
||||
// Directly sets this instance's manual config. This is unsafe, because it
|
||||
// assumes that the config was computed by this instance (or one with
|
||||
|
@ -4,9 +4,6 @@
|
||||
|
||||
#include "net/first_party_sets/global_first_party_sets.h"
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "base/containers/flat_map.h"
|
||||
#include "base/version.h"
|
||||
#include "net/base/schemeful_site.h"
|
||||
@ -14,6 +11,7 @@
|
||||
#include "net/first_party_sets/first_party_set_entry_override.h"
|
||||
#include "net/first_party_sets/first_party_set_metadata.h"
|
||||
#include "net/first_party_sets/first_party_sets_context_config.h"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "testing/gmock/include/gmock/gmock-matchers.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
@ -101,7 +99,8 @@ TEST_F(GlobalFirstPartySetsTest, Clone) {
|
||||
/*entries=*/
|
||||
{{example, entry}, {member1, member1_entry}},
|
||||
/*aliases=*/{{example_cctld, example}});
|
||||
sets.ApplyManuallySpecifiedSet({{foo, foo_entry}, {member2, member2_entry}});
|
||||
sets.ApplyManuallySpecifiedSet(
|
||||
LocalSetDeclaration({{foo, foo_entry}, {member2, member2_entry}}));
|
||||
|
||||
EXPECT_EQ(sets, sets.Clone());
|
||||
}
|
||||
@ -266,11 +265,11 @@ TEST_F(GlobalFirstPartySetsTest, Empty_NonemptyEntries) {
|
||||
|
||||
TEST_F(GlobalFirstPartySetsTest, Empty_NonemptyManualSet) {
|
||||
GlobalFirstPartySets sets;
|
||||
sets.ApplyManuallySpecifiedSet({
|
||||
sets.ApplyManuallySpecifiedSet(LocalSetDeclaration({
|
||||
{kPrimary,
|
||||
FirstPartySetEntry(kPrimary, SiteType::kPrimary, absl::nullopt)},
|
||||
{kAssociated4, FirstPartySetEntry(kPrimary, SiteType::kAssociated, 0)},
|
||||
});
|
||||
}));
|
||||
EXPECT_FALSE(sets.empty());
|
||||
}
|
||||
|
||||
@ -285,11 +284,11 @@ TEST_F(GlobalFirstPartySetsTest, InvalidPublicSetsVersion_NonemptyManualSet) {
|
||||
},
|
||||
/*aliases=*/{});
|
||||
ASSERT_TRUE(sets.empty());
|
||||
sets.ApplyManuallySpecifiedSet({
|
||||
sets.ApplyManuallySpecifiedSet(LocalSetDeclaration({
|
||||
{kPrimary,
|
||||
FirstPartySetEntry(kPrimary, SiteType::kPrimary, absl::nullopt)},
|
||||
{kAssociated4, FirstPartySetEntry(kPrimary, SiteType::kAssociated, 0)},
|
||||
});
|
||||
}));
|
||||
|
||||
// The manual set should still be available, even though the component was
|
||||
// invalid.
|
||||
@ -307,12 +306,12 @@ TEST_F(GlobalFirstPartySetsTest, InvalidPublicSetsVersion_NonemptyManualSet) {
|
||||
TEST_F(GlobalFirstPartySetsTest,
|
||||
ForEachEffectiveSetEntry_ManualSetAndConfig_FullIteration) {
|
||||
GlobalFirstPartySets global_sets;
|
||||
global_sets.ApplyManuallySpecifiedSet({
|
||||
global_sets.ApplyManuallySpecifiedSet(LocalSetDeclaration({
|
||||
{kPrimary,
|
||||
FirstPartySetEntry(kPrimary, SiteType::kPrimary, absl::nullopt)},
|
||||
{kAssociated4, FirstPartySetEntry(kPrimary, SiteType::kAssociated, 0)},
|
||||
{kAssociated5, FirstPartySetEntry(kPrimary, SiteType::kAssociated, 1)},
|
||||
});
|
||||
}));
|
||||
|
||||
// Modify kPrimary's set by removing kAssociated5 and modifying kAssociated4,
|
||||
// via policy.
|
||||
@ -389,11 +388,11 @@ TEST_F(PopulatedGlobalFirstPartySetsTest,
|
||||
ApplyManuallySpecifiedSet_DeduplicatesPrimaryPrimary) {
|
||||
// kPrimary overlaps as primary of both sets, so the existing set should be
|
||||
// wiped out.
|
||||
global_sets().ApplyManuallySpecifiedSet({
|
||||
global_sets().ApplyManuallySpecifiedSet(LocalSetDeclaration({
|
||||
{kPrimary,
|
||||
FirstPartySetEntry(kPrimary, SiteType::kPrimary, absl::nullopt)},
|
||||
{kAssociated4, FirstPartySetEntry(kPrimary, SiteType::kAssociated, 0)},
|
||||
});
|
||||
}));
|
||||
|
||||
EXPECT_THAT(
|
||||
global_sets().FindEntries(
|
||||
@ -417,11 +416,11 @@ TEST_F(PopulatedGlobalFirstPartySetsTest,
|
||||
ApplyManuallySpecifiedSet_DeduplicatesPrimaryNonprimary) {
|
||||
// kPrimary overlaps as a primary of the public set and non-primary of the CLI
|
||||
// set, so the existing set should be wiped out.
|
||||
global_sets().ApplyManuallySpecifiedSet({
|
||||
global_sets().ApplyManuallySpecifiedSet(LocalSetDeclaration({
|
||||
{kPrimary3,
|
||||
FirstPartySetEntry(kPrimary3, SiteType::kPrimary, absl::nullopt)},
|
||||
{kPrimary, FirstPartySetEntry(kPrimary3, SiteType::kAssociated, 0)},
|
||||
});
|
||||
}));
|
||||
|
||||
EXPECT_THAT(
|
||||
global_sets().FindEntries(
|
||||
@ -447,12 +446,12 @@ TEST_F(PopulatedGlobalFirstPartySetsTest,
|
||||
// kAssociated1 overlaps as a non-primary of the public set and primary of the
|
||||
// CLI set, so the CLI set should steal it and wipe out its alias, but
|
||||
// otherwise leave the set intact.
|
||||
global_sets().ApplyManuallySpecifiedSet({
|
||||
global_sets().ApplyManuallySpecifiedSet(LocalSetDeclaration({
|
||||
{kAssociated1,
|
||||
FirstPartySetEntry(kAssociated1, SiteType::kPrimary, absl::nullopt)},
|
||||
{kAssociated4,
|
||||
FirstPartySetEntry(kAssociated1, SiteType::kAssociated, 0)},
|
||||
});
|
||||
}));
|
||||
|
||||
EXPECT_THAT(
|
||||
global_sets().FindEntries(
|
||||
@ -484,11 +483,11 @@ TEST_F(PopulatedGlobalFirstPartySetsTest,
|
||||
ApplyManuallySpecifiedSet_DeduplicatesNonprimaryNonprimary) {
|
||||
// kAssociated1 overlaps as a non-primary of the public set and non-primary of
|
||||
// the CLI set, so the CLI set should steal it and wipe out its alias.
|
||||
global_sets().ApplyManuallySpecifiedSet({
|
||||
global_sets().ApplyManuallySpecifiedSet(LocalSetDeclaration({
|
||||
{kPrimary3,
|
||||
FirstPartySetEntry(kPrimary3, SiteType::kPrimary, absl::nullopt)},
|
||||
{kAssociated1, FirstPartySetEntry(kPrimary3, SiteType::kAssociated, 0)},
|
||||
});
|
||||
}));
|
||||
|
||||
EXPECT_THAT(
|
||||
global_sets().FindEntries(
|
||||
@ -519,11 +518,11 @@ TEST_F(PopulatedGlobalFirstPartySetsTest,
|
||||
ApplyManuallySpecifiedSet_PrunesInducedSingletons) {
|
||||
// Steal kAssociated3, so that kPrimary2 becomes a singleton, and verify that
|
||||
// kPrimary2 is no longer considered in a set.
|
||||
global_sets().ApplyManuallySpecifiedSet({
|
||||
global_sets().ApplyManuallySpecifiedSet(LocalSetDeclaration({
|
||||
{kPrimary3,
|
||||
FirstPartySetEntry(kPrimary3, SiteType::kPrimary, absl::nullopt)},
|
||||
{kAssociated3, FirstPartySetEntry(kPrimary3, SiteType::kAssociated, 0)},
|
||||
});
|
||||
}));
|
||||
|
||||
EXPECT_THAT(
|
||||
global_sets().FindEntries({kPrimary2}, FirstPartySetsContextConfig()),
|
||||
@ -535,13 +534,13 @@ TEST_F(PopulatedGlobalFirstPartySetsTest,
|
||||
// Both the public sets and the locally-defined set define an alias for
|
||||
// kAssociated1, but both define a different set for that site too. Only the
|
||||
// locally-defined alias should be observable.
|
||||
global_sets().ApplyManuallySpecifiedSet({
|
||||
global_sets().ApplyManuallySpecifiedSet(LocalSetDeclaration({
|
||||
{kPrimary3,
|
||||
FirstPartySetEntry(kPrimary3, SiteType::kPrimary, absl::nullopt)},
|
||||
{kAssociated1, FirstPartySetEntry(kPrimary3, SiteType::kAssociated, 0)},
|
||||
{kAssociated1Cctld2,
|
||||
FirstPartySetEntry(kPrimary3, SiteType::kAssociated, 0)},
|
||||
});
|
||||
}));
|
||||
|
||||
EXPECT_THAT(
|
||||
global_sets().FindEntries(
|
||||
@ -603,11 +602,11 @@ TEST_F(PopulatedGlobalFirstPartySetsTest,
|
||||
ForEachEffectiveSetEntry_PublicSetsWithManualSet_FullIteration) {
|
||||
// Replace kPrimary's set (including the alias and service site) with just
|
||||
// {kPrimary, kAssociated4}.
|
||||
global_sets().ApplyManuallySpecifiedSet({
|
||||
global_sets().ApplyManuallySpecifiedSet(LocalSetDeclaration({
|
||||
{kPrimary,
|
||||
FirstPartySetEntry(kPrimary, SiteType::kPrimary, absl::nullopt)},
|
||||
{kAssociated4, FirstPartySetEntry(kPrimary, SiteType::kAssociated, 0)},
|
||||
});
|
||||
}));
|
||||
|
||||
EXPECT_THAT(
|
||||
CollectEffectiveSetEntries(global_sets(), FirstPartySetsContextConfig()),
|
||||
@ -670,12 +669,12 @@ TEST_F(
|
||||
ForEachEffectiveSetEntry_PublicSetsWithManualSetAndConfig_FullIteration) {
|
||||
// Replace kPrimary's set (including the alias and service site) with just
|
||||
// {kPrimary, kAssociated4, kAssociated5}.
|
||||
global_sets().ApplyManuallySpecifiedSet({
|
||||
global_sets().ApplyManuallySpecifiedSet(LocalSetDeclaration({
|
||||
{kPrimary,
|
||||
FirstPartySetEntry(kPrimary, SiteType::kPrimary, absl::nullopt)},
|
||||
{kAssociated4, FirstPartySetEntry(kPrimary, SiteType::kAssociated, 0)},
|
||||
{kAssociated5, FirstPartySetEntry(kPrimary, SiteType::kAssociated, 1)},
|
||||
});
|
||||
}));
|
||||
|
||||
// Modify kPrimary's set by removing kAssociated2 and adding kAssociated4, via
|
||||
// policy.
|
||||
|
43
net/first_party_sets/local_set_declaration.cc
Normal file
43
net/first_party_sets/local_set_declaration.cc
Normal file
@ -0,0 +1,43 @@
|
||||
// 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.
|
||||
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
|
||||
#include "base/ranges/algorithm.h"
|
||||
#include "net/base/schemeful_site.h"
|
||||
#include "net/first_party_sets/first_party_set_entry.h"
|
||||
|
||||
namespace net {
|
||||
|
||||
LocalSetDeclaration::LocalSetDeclaration() = default;
|
||||
|
||||
LocalSetDeclaration::LocalSetDeclaration(
|
||||
base::flat_map<SchemefulSite, FirstPartySetEntry> set_entries)
|
||||
: entries_(std::move(set_entries)) {
|
||||
if (!entries_.empty()) {
|
||||
// Must not be a singleton set (i.e. must have more than one entry).
|
||||
CHECK_GT(entries_.size(), 1u);
|
||||
|
||||
// All provided entries must have the same primary site. I.e., there must
|
||||
// only be one set.
|
||||
const SchemefulSite& primary = entries_.begin()->second.primary();
|
||||
CHECK(base::ranges::all_of(
|
||||
entries_,
|
||||
[&](const std::pair<SchemefulSite, FirstPartySetEntry>& pair) {
|
||||
return pair.second.primary() == primary;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
LocalSetDeclaration::~LocalSetDeclaration() = default;
|
||||
|
||||
LocalSetDeclaration::LocalSetDeclaration(const LocalSetDeclaration&) = default;
|
||||
LocalSetDeclaration& LocalSetDeclaration::operator=(
|
||||
const LocalSetDeclaration&) = default;
|
||||
|
||||
LocalSetDeclaration::LocalSetDeclaration(LocalSetDeclaration&&) = default;
|
||||
LocalSetDeclaration& LocalSetDeclaration::operator=(LocalSetDeclaration&&) =
|
||||
default;
|
||||
|
||||
} // namespace net
|
58
net/first_party_sets/local_set_declaration.h
Normal file
58
net/first_party_sets/local_set_declaration.h
Normal file
@ -0,0 +1,58 @@
|
||||
// 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 NET_FIRST_PARTY_SETS_LOCAL_SET_DECLARATION_H_
|
||||
#define NET_FIRST_PARTY_SETS_LOCAL_SET_DECLARATION_H_
|
||||
|
||||
#include "base/containers/flat_map.h"
|
||||
#include "net/base/net_export.h"
|
||||
#include "net/base/schemeful_site.h"
|
||||
#include "net/first_party_sets/first_party_set_entry.h"
|
||||
|
||||
namespace net {
|
||||
|
||||
// LocalSetDeclaration represents a Related Website Set that was defined locally
|
||||
// by a web developer (as opposed to being one of the public Related Website
|
||||
// Sets, or a set from the RelatedWebsiteSetsOverrides policy).
|
||||
//
|
||||
// Locally-defined sets take precedence over the public sets (for testing
|
||||
// purposes), but can be overridden by the RelatedWebsiteSetsOverrides policy.
|
||||
//
|
||||
// See `GlobalFirstPartySets` for how overlaps/shadowing between public sets,
|
||||
// locally-defined sets, and enterprise policy sets is handled.
|
||||
class NET_EXPORT LocalSetDeclaration {
|
||||
public:
|
||||
// Constructs an empty (no-op) set declaration.
|
||||
LocalSetDeclaration();
|
||||
|
||||
// Constructs a set declaration with the given entries. All entries must be in
|
||||
// the same set (i.e. they must have the same primary site). The set must not
|
||||
// be a singleton (i.e. must have more than one entry, or must be empty).
|
||||
explicit LocalSetDeclaration(
|
||||
base::flat_map<SchemefulSite, FirstPartySetEntry> set_entries);
|
||||
|
||||
~LocalSetDeclaration();
|
||||
|
||||
LocalSetDeclaration(const LocalSetDeclaration&);
|
||||
LocalSetDeclaration& operator=(const LocalSetDeclaration&);
|
||||
LocalSetDeclaration(LocalSetDeclaration&&);
|
||||
LocalSetDeclaration& operator=(LocalSetDeclaration&&);
|
||||
|
||||
bool empty() const { return entries_.empty(); }
|
||||
|
||||
size_t size() const { return entries_.size(); }
|
||||
|
||||
const base::flat_map<SchemefulSite, FirstPartySetEntry>& entries() const {
|
||||
return entries_;
|
||||
}
|
||||
|
||||
private:
|
||||
// Stores the set of entries and ccTLD aliases. This may be empty if no set
|
||||
// was locally defined.
|
||||
base::flat_map<SchemefulSite, FirstPartySetEntry> entries_;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
|
||||
#endif // NET_FIRST_PARTY_SETS_LOCAL_SET_DECLARATION_H_
|
42
net/first_party_sets/local_set_declaration_unittest.cc
Normal file
42
net/first_party_sets/local_set_declaration_unittest.cc
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.
|
||||
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
|
||||
#include "net/base/schemeful_site.h"
|
||||
#include "net/first_party_sets/first_party_set_entry.h"
|
||||
#include "testing/gmock/include/gmock/gmock-matchers.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
using ::testing::IsEmpty;
|
||||
using ::testing::Pair;
|
||||
using ::testing::UnorderedElementsAre;
|
||||
|
||||
namespace net {
|
||||
|
||||
TEST(LocalSetDeclarationTest, Valid_EmptySet) {
|
||||
EXPECT_THAT(LocalSetDeclaration(), IsEmpty());
|
||||
}
|
||||
|
||||
TEST(LocalSetDeclarationTest, Valid_Basic) {
|
||||
SchemefulSite primary(GURL("https://primary.test"));
|
||||
SchemefulSite associated(GURL("https://associated.test"));
|
||||
|
||||
base::flat_map<SchemefulSite, FirstPartySetEntry> entries({
|
||||
{primary, FirstPartySetEntry(primary, SiteType::kPrimary, absl::nullopt)},
|
||||
{associated, FirstPartySetEntry(primary, SiteType::kAssociated, 0)},
|
||||
});
|
||||
|
||||
EXPECT_THAT(LocalSetDeclaration(entries).entries(),
|
||||
UnorderedElementsAre(
|
||||
Pair(primary, FirstPartySetEntry(primary, SiteType::kPrimary,
|
||||
absl::nullopt)),
|
||||
Pair(associated,
|
||||
FirstPartySetEntry(primary, SiteType::kAssociated, 0))));
|
||||
}
|
||||
|
||||
} // namespace net
|
@ -14,6 +14,7 @@
|
||||
#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"
|
||||
#include "net/first_party_sets/local_set_declaration.h"
|
||||
#include "services/network/public/mojom/first_party_sets.mojom.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
@ -106,9 +107,9 @@ TEST(FirstPartySetsTraitsTest, RoundTrips_GlobalFirstPartySets) {
|
||||
},
|
||||
/*aliases=*/{{b_cctld, b}});
|
||||
|
||||
original.ApplyManuallySpecifiedSet(
|
||||
original.ApplyManuallySpecifiedSet(net::LocalSetDeclaration(
|
||||
{{a, net::FirstPartySetEntry(a, net::SiteType::kPrimary, absl::nullopt)},
|
||||
{b, net::FirstPartySetEntry(a, net::SiteType::kAssociated, 0)}});
|
||||
{b, net::FirstPartySetEntry(a, net::SiteType::kAssociated, 0)}}));
|
||||
|
||||
net::GlobalFirstPartySets round_tripped;
|
||||
|
||||
@ -138,9 +139,9 @@ TEST(FirstPartySetsTraitsTest, GlobalFirstPartySets_InvalidVersion) {
|
||||
},
|
||||
/*aliases=*/{{b_cctld, b}});
|
||||
|
||||
original.ApplyManuallySpecifiedSet(
|
||||
original.ApplyManuallySpecifiedSet(net::LocalSetDeclaration(
|
||||
{{a, net::FirstPartySetEntry(a, net::SiteType::kPrimary, absl::nullopt)},
|
||||
{b, net::FirstPartySetEntry(a, net::SiteType::kAssociated, 0)}});
|
||||
{b, net::FirstPartySetEntry(a, net::SiteType::kAssociated, 0)}}));
|
||||
|
||||
net::GlobalFirstPartySets round_tripped;
|
||||
|
||||
|
Reference in New Issue
Block a user