• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/first_party_sets/sets_mutation.h"
6 
7 #include "net/base/schemeful_site.h"
8 #include "net/first_party_sets/first_party_set_entry.h"
9 #include "testing/gmock/include/gmock/gmock-matchers.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/abseil-cpp/absl/types/optional.h"
13 #include "url/gurl.h"
14 
15 using ::testing::Pair;
16 using ::testing::UnorderedElementsAre;
17 
18 namespace net {
19 
TEST(SetsMutationTest,Valid)20 TEST(SetsMutationTest, Valid) {
21   const SchemefulSite primary1(GURL("https://primary1.test"));
22   const SchemefulSite associated1(GURL("https://associated1.test"));
23   const SchemefulSite primary2(GURL("https://primary2.test"));
24   const SchemefulSite associated2(GURL("https://associated2.test"));
25 
26   std::ignore = SetsMutation(
27       /*replacement_sets=*/
28       {
29           {
30               {primary1,
31                FirstPartySetEntry(primary1, SiteType::kPrimary, absl::nullopt)},
32               {associated1,
33                FirstPartySetEntry(primary1, SiteType::kAssociated, 0)},
34           },
35           {
36               {primary2,
37                FirstPartySetEntry(primary2, SiteType::kPrimary, absl::nullopt)},
38               {associated2,
39                FirstPartySetEntry(primary2, SiteType::kAssociated, 0)},
40           },
41       },
42       /*addition_sets=*/{});
43 
44   std::ignore = SetsMutation(
45       /*replacement_sets=*/{},
46       /*addition_sets=*/{
47           {
48               {primary1,
49                FirstPartySetEntry(primary1, SiteType::kPrimary, absl::nullopt)},
50               {associated1,
51                FirstPartySetEntry(primary1, SiteType::kAssociated, 0)},
52           },
53           {
54               {primary2,
55                FirstPartySetEntry(primary2, SiteType::kPrimary, absl::nullopt)},
56               {associated2,
57                FirstPartySetEntry(primary2, SiteType::kAssociated, 0)},
58           },
59       });
60 
61   std::ignore = SetsMutation(
62       /*replacement_sets=*/
63       {
64           {
65               {primary1,
66                FirstPartySetEntry(primary1, SiteType::kPrimary, absl::nullopt)},
67               {associated1,
68                FirstPartySetEntry(primary1, SiteType::kAssociated, 0)},
69           },
70       },
71       /*addition_sets=*/{
72           {
73               {primary2,
74                FirstPartySetEntry(primary2, SiteType::kPrimary, absl::nullopt)},
75               {associated2,
76                FirstPartySetEntry(primary2, SiteType::kAssociated, 0)},
77           },
78       });
79 }
80 
81 #if defined(GTEST_HAS_DEATH_TEST)
TEST(SetsMutationTest,Nondisjoint_death)82 TEST(SetsMutationTest, Nondisjoint_death) {
83   const SchemefulSite primary1(GURL("https://primary1.test"));
84   const SchemefulSite associated1(GURL("https://associated1.test"));
85   const SchemefulSite primary2(GURL("https://primary2.test"));
86   const SchemefulSite associated2(GURL("https://associated2.test"));
87 
88   EXPECT_DEATH(
89       {
90         SetsMutation(
91             /*replacement_sets=*/
92             {
93                 {
94                     {primary1, FirstPartySetEntry(primary1, SiteType::kPrimary,
95                                                   absl::nullopt)},
96                     {associated1,
97                      FirstPartySetEntry(primary1, SiteType::kAssociated, 0)},
98                 },
99                 {
100                     {primary2, FirstPartySetEntry(primary2, SiteType::kPrimary,
101                                                   absl::nullopt)},
102                     {associated1,
103                      FirstPartySetEntry(primary2, SiteType::kAssociated, 0)},
104                     {associated2,
105                      FirstPartySetEntry(primary2, SiteType::kAssociated, 0)},
106                 },
107             },
108             /*addition_sets=*/{});
109       },
110       "");
111 }
112 #endif  // defined(GTEST_HAS_DEATH_TEST)
113 
114 }  // namespace net
115