summaryrefslogtreecommitdiff
path: root/chromium/net/first_party_sets/first_party_sets_context_config_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/net/first_party_sets/first_party_sets_context_config_unittest.cc')
-rw-r--r--chromium/net/first_party_sets/first_party_sets_context_config_unittest.cc96
1 files changed, 96 insertions, 0 deletions
diff --git a/chromium/net/first_party_sets/first_party_sets_context_config_unittest.cc b/chromium/net/first_party_sets/first_party_sets_context_config_unittest.cc
new file mode 100644
index 00000000000..743a5e5d667
--- /dev/null
+++ b/chromium/net/first_party_sets/first_party_sets_context_config_unittest.cc
@@ -0,0 +1,96 @@
+// 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/first_party_sets_context_config.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 "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::Optional;
+
+namespace net {
+
+TEST(FirstPartySetsContextConfigTest, FindOverride_empty) {
+ EXPECT_EQ(FirstPartySetsContextConfig().FindOverride(
+ SchemefulSite(GURL("https://example.test"))),
+ absl::nullopt);
+}
+
+TEST(FirstPartySetsContextConfigTest, FindOverride_irrelevant) {
+ SchemefulSite example(GURL("https://example.test"));
+ FirstPartySetEntry entry(example, SiteType::kPrimary, absl::nullopt);
+ SchemefulSite foo(GURL("https://foo.test"));
+
+ EXPECT_EQ(FirstPartySetsContextConfig({{example, entry}}).FindOverride(foo),
+ absl::nullopt);
+}
+
+TEST(FirstPartySetsContextConfigTest, FindOverride_deletion) {
+ SchemefulSite example(GURL("https://example.test"));
+
+ EXPECT_THAT(FirstPartySetsContextConfig({{example, absl::nullopt}})
+ .FindOverride(example),
+ Optional(absl::nullopt));
+}
+
+TEST(FirstPartySetsContextConfigTest, FindOverride_modification) {
+ SchemefulSite example(GURL("https://example.test"));
+ FirstPartySetEntry entry(example, SiteType::kPrimary, absl::nullopt);
+
+ EXPECT_THAT(
+ FirstPartySetsContextConfig({{example, entry}}).FindOverride(example),
+ Optional(Optional(entry)));
+}
+
+TEST(FirstPartySetsContextConfigTest, Contains) {
+ SchemefulSite example(GURL("https://example.test"));
+ SchemefulSite decoy(GURL("https://decoy.test"));
+
+ FirstPartySetsContextConfig config({{example, absl::nullopt}});
+
+ EXPECT_TRUE(config.Contains(example));
+ EXPECT_FALSE(config.Contains(decoy));
+}
+
+TEST(FirstPartySetsContextConfigTest, ForEachCustomizationEntry_FullIteration) {
+ SchemefulSite example(GURL("https://example.test"));
+ SchemefulSite foo(GURL("https://foo.test"));
+
+ FirstPartySetsContextConfig config(
+ {{example, absl::nullopt}, {foo, absl::nullopt}});
+
+ int count = 0;
+ EXPECT_TRUE(config.ForEachCustomizationEntry(
+ [&](const SchemefulSite& site,
+ const absl::optional<FirstPartySetEntry>& entry) {
+ ++count;
+ return true;
+ }));
+ EXPECT_EQ(count, 2);
+}
+
+TEST(FirstPartySetsContextConfigTest, ForEachCustomizationEntry_EarlyReturn) {
+ SchemefulSite example(GURL("https://example.test"));
+ SchemefulSite foo(GURL("https://foo.test"));
+
+ FirstPartySetsContextConfig config(
+ {{example, absl::nullopt}, {foo, absl::nullopt}});
+
+ int count = 0;
+ EXPECT_FALSE(config.ForEachCustomizationEntry(
+ [&](const SchemefulSite& site,
+ const absl::optional<FirstPartySetEntry>& entry) {
+ ++count;
+ return count < 1;
+ }));
+ EXPECT_EQ(count, 1);
+}
+
+} // namespace net