Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Lei Zhang | 6436192 | 2021-04-21 19:43:39 | [diff] [blame] | 5 | #ifndef NET_COOKIES_COOKIE_STORE_CHANGE_UNITTEST_H_ |
| 6 | #define NET_COOKIES_COOKIE_STORE_CHANGE_UNITTEST_H_ |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 7 | |
| 8 | #include "base/bind.h" |
| 9 | #include "net/cookies/canonical_cookie.h" |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 10 | #include "net/cookies/cookie_change_dispatcher_test_helpers.h" |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 11 | #include "net/cookies/cookie_constants.h" |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 12 | #include "net/cookies/cookie_store.h" |
| 13 | #include "net/cookies/cookie_store_unittest.h" |
| 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | #include "url/gurl.h" |
| 16 | |
| 17 | namespace net { |
| 18 | |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 19 | namespace { |
| 20 | |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 21 | // Used to sort CookieChanges when testing stores without exact change ordering. |
| 22 | // |
| 23 | // The ordering relation must match the order in which the tests below issue |
| 24 | // cookie calls. Changes to this method should be tested by running the tests |
| 25 | // below with CookieMonsterTestTraits::has_exact_change_ordering set to both |
| 26 | // true and false. |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 27 | bool CookieChangeLessThan(const CookieChangeInfo& lhs, |
| 28 | const CookieChangeInfo& rhs) { |
| 29 | if (lhs.cookie.Name() != rhs.cookie.Name()) |
| 30 | return lhs.cookie.Name() < rhs.cookie.Name(); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 31 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 32 | if (lhs.cookie.Value() != rhs.cookie.Value()) |
| 33 | return lhs.cookie.Value() < rhs.cookie.Value(); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 34 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 35 | if (lhs.cookie.Domain() != rhs.cookie.Domain()) |
| 36 | return lhs.cookie.Domain() < rhs.cookie.Domain(); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 37 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 38 | return lhs.cause < rhs.cause; |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | } // namespace |
| 42 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 43 | // Google Test supports at most 50 tests per typed case, so the tests here are |
| 44 | // broken up into multiple cases. |
| 45 | template <class CookieStoreTestTraits> |
| 46 | class CookieStoreChangeTestBase |
| 47 | : public CookieStoreTest<CookieStoreTestTraits> { |
| 48 | protected: |
| 49 | using CookieStoreTest<CookieStoreTestTraits>::FindAndDeleteCookie; |
| 50 | |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 51 | // Drains all pending tasks on the run loop(s) involved in the test. |
| 52 | void DeliverChangeNotifications() { |
| 53 | CookieStoreTestTraits::DeliverChangeNotifications(); |
| 54 | } |
| 55 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 56 | bool FindAndDeleteCookie(CookieStore* cs, |
| 57 | const std::string& domain, |
| 58 | const std::string& name, |
| 59 | const std::string& path) { |
| 60 | for (auto& cookie : this->GetAllCookies(cs)) { |
| 61 | if (cookie.Domain() == domain && cookie.Name() == name && |
| 62 | cookie.Path() == path) { |
| 63 | return this->DeleteCanonicalCookie(cs, cookie); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return false; |
| 68 | } |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 69 | |
| 70 | // Could be static, but it's actually easier to have it be a member function. |
| 71 | ::testing::AssertionResult MatchesCause(CookieChangeCause expected_cause, |
| 72 | CookieChangeCause actual_cause) { |
| 73 | if (!CookieChangeCauseIsDeletion(expected_cause) || |
| 74 | CookieStoreTestTraits::has_exact_change_cause) { |
| 75 | if (expected_cause == actual_cause) |
| 76 | return ::testing::AssertionSuccess(); |
| 77 | return ::testing::AssertionFailure() |
| 78 | << "expected " << expected_cause << " got " << actual_cause; |
| 79 | } |
| 80 | if (CookieChangeCauseIsDeletion(actual_cause)) |
| 81 | return ::testing::AssertionSuccess(); |
| 82 | return ::testing::AssertionFailure() |
| 83 | << "expected a deletion cause, got " << actual_cause; |
| 84 | } |
| 85 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 86 | bool IsExpectedAccessSemantics(net::CookieAccessSemantics expected_semantics, |
| 87 | net::CookieAccessSemantics actual_semantics) { |
| 88 | if (CookieStoreTestTraits::supports_cookie_access_semantics) |
| 89 | return expected_semantics == actual_semantics; |
| 90 | return actual_semantics == net::CookieAccessSemantics::UNKNOWN; |
| 91 | } |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 92 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 93 | static void OnCookieChange(std::vector<CookieChangeInfo>* changes, |
| 94 | const CookieChangeInfo& notification) { |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 95 | if (CookieStoreTestTraits::has_exact_change_ordering) { |
| 96 | changes->push_back(notification); |
| 97 | } else { |
| 98 | // Assumes the vector is sorted before the insertion. If true, the vector |
| 99 | // will remain sorted. |
| 100 | changes->insert(std::upper_bound(changes->begin(), changes->end(), |
| 101 | notification, CookieChangeLessThan), |
| 102 | notification); |
| 103 | } |
| 104 | } |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | template <class CookieStoreTestTraits> |
| 108 | class CookieStoreChangeGlobalTest |
| 109 | : public CookieStoreChangeTestBase<CookieStoreTestTraits> {}; |
Victor Costan | 2309ea0 | 2019-02-13 21:35:47 | [diff] [blame] | 110 | TYPED_TEST_SUITE_P(CookieStoreChangeGlobalTest); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 111 | |
| 112 | template <class CookieStoreTestTraits> |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 113 | class CookieStoreChangeUrlTest |
| 114 | : public CookieStoreChangeTestBase<CookieStoreTestTraits> {}; |
Victor Costan | 2309ea0 | 2019-02-13 21:35:47 | [diff] [blame] | 115 | TYPED_TEST_SUITE_P(CookieStoreChangeUrlTest); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 116 | |
| 117 | template <class CookieStoreTestTraits> |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 118 | class CookieStoreChangeNamedTest |
| 119 | : public CookieStoreChangeTestBase<CookieStoreTestTraits> {}; |
Victor Costan | 2309ea0 | 2019-02-13 21:35:47 | [diff] [blame] | 120 | TYPED_TEST_SUITE_P(CookieStoreChangeNamedTest); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 121 | |
| 122 | TYPED_TEST_P(CookieStoreChangeGlobalTest, NoCookie) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 123 | if (!TypeParam::supports_global_cookie_tracking) |
| 124 | return; |
| 125 | |
| 126 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 127 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 128 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 129 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 130 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 131 | base::Unretained(&cookie_changes))); |
| 132 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 133 | EXPECT_EQ(0u, cookie_changes.size()); |
| 134 | } |
| 135 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 136 | TYPED_TEST_P(CookieStoreChangeGlobalTest, InitialCookie) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 137 | if (!TypeParam::supports_global_cookie_tracking) |
| 138 | return; |
| 139 | |
| 140 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 141 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 142 | this->SetCookie(cs, this->http_www_foo_.url(), "A=B"); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 143 | this->DeliverChangeNotifications(); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 144 | std::unique_ptr<CookieChangeSubscription> subscription( |
| 145 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 146 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 147 | base::Unretained(&cookie_changes)))); |
| 148 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 149 | EXPECT_EQ(0u, cookie_changes.size()); |
| 150 | } |
| 151 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 152 | TYPED_TEST_P(CookieStoreChangeGlobalTest, InsertOne) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 153 | if (!TypeParam::supports_global_cookie_tracking) |
| 154 | return; |
| 155 | |
| 156 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 157 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 158 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 159 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 160 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 161 | base::Unretained(&cookie_changes))); |
| 162 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 163 | ASSERT_EQ(0u, cookie_changes.size()); |
| 164 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 165 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 166 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 167 | |
| 168 | ASSERT_EQ(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 169 | EXPECT_TRUE( |
| 170 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); |
| 171 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 172 | cookie_changes[0].cookie.Domain()); |
| 173 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 174 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | TYPED_TEST_P(CookieStoreChangeGlobalTest, InsertMany) { |
| 178 | if (!TypeParam::supports_global_cookie_tracking) |
| 179 | return; |
| 180 | |
| 181 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 182 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 183 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 184 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 185 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 186 | base::Unretained(&cookie_changes))); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 187 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
| 188 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
| 189 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F")); |
| 190 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "G=H")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 191 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 192 | |
| 193 | // Check that the cookie changes are dispatched before calling GetCookies. |
| 194 | // This is not an ASSERT because the following expectations produce useful |
| 195 | // debugging information if they fail. |
| 196 | EXPECT_EQ(4u, cookie_changes.size()); |
| 197 | EXPECT_EQ("A=B; C=D; E=F", this->GetCookies(cs, this->http_www_foo_.url())); |
| 198 | EXPECT_EQ("G=H", this->GetCookies(cs, this->http_bar_com_.url())); |
| 199 | |
| 200 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 201 | EXPECT_TRUE( |
| 202 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); |
| 203 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 204 | cookie_changes[0].cookie.Domain()); |
| 205 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 206 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 207 | |
| 208 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 209 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 210 | cookie_changes[1].cookie.Domain()); |
| 211 | EXPECT_TRUE( |
| 212 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); |
| 213 | EXPECT_EQ("C", cookie_changes[1].cookie.Name()); |
| 214 | EXPECT_EQ("D", cookie_changes[1].cookie.Value()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 215 | |
| 216 | ASSERT_LE(3u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 217 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 218 | cookie_changes[2].cookie.Domain()); |
| 219 | EXPECT_TRUE( |
| 220 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[2].cause)); |
| 221 | EXPECT_EQ("E", cookie_changes[2].cookie.Name()); |
| 222 | EXPECT_EQ("F", cookie_changes[2].cookie.Value()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 223 | |
| 224 | ASSERT_LE(4u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 225 | EXPECT_EQ(this->http_bar_com_.url().host(), |
| 226 | cookie_changes[3].cookie.Domain()); |
| 227 | EXPECT_TRUE( |
| 228 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[3].cause)); |
| 229 | EXPECT_EQ("G", cookie_changes[3].cookie.Name()); |
| 230 | EXPECT_EQ("H", cookie_changes[3].cookie.Value()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 231 | |
| 232 | EXPECT_EQ(4u, cookie_changes.size()); |
| 233 | } |
| 234 | |
| 235 | TYPED_TEST_P(CookieStoreChangeGlobalTest, DeleteOne) { |
| 236 | if (!TypeParam::supports_global_cookie_tracking) |
| 237 | return; |
| 238 | |
| 239 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 240 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 241 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 242 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 243 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 244 | base::Unretained(&cookie_changes))); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 245 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 246 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 247 | EXPECT_EQ(1u, cookie_changes.size()); |
| 248 | cookie_changes.clear(); |
| 249 | |
| 250 | EXPECT_TRUE( |
| 251 | this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "A")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 252 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 253 | |
| 254 | ASSERT_EQ(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 255 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 256 | cookie_changes[0].cookie.Domain()); |
| 257 | EXPECT_TRUE( |
| 258 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); |
| 259 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 260 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | TYPED_TEST_P(CookieStoreChangeGlobalTest, DeleteTwo) { |
| 264 | if (!TypeParam::supports_global_cookie_tracking) |
| 265 | return; |
| 266 | |
| 267 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 268 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 269 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 270 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 271 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 272 | base::Unretained(&cookie_changes))); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 273 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
| 274 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
| 275 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F")); |
| 276 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "G=H")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 277 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 278 | EXPECT_EQ(4u, cookie_changes.size()); |
| 279 | cookie_changes.clear(); |
| 280 | |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 281 | EXPECT_TRUE( |
| 282 | this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "C")); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 283 | EXPECT_TRUE( |
| 284 | this->FindAndDeleteCookie(cs, this->http_bar_com_.url().host(), "G")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 285 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 286 | |
| 287 | // Check that the cookie changes are dispatched before calling GetCookies. |
| 288 | // This is not an ASSERT because the following expectations produce useful |
| 289 | // debugging information if they fail. |
| 290 | EXPECT_EQ(2u, cookie_changes.size()); |
| 291 | EXPECT_EQ("A=B; E=F", this->GetCookies(cs, this->http_www_foo_.url())); |
| 292 | EXPECT_EQ("", this->GetCookies(cs, this->http_bar_com_.url())); |
| 293 | |
| 294 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 295 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 296 | cookie_changes[0].cookie.Domain()); |
| 297 | EXPECT_TRUE( |
| 298 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); |
| 299 | EXPECT_EQ("C", cookie_changes[0].cookie.Name()); |
| 300 | EXPECT_EQ("D", cookie_changes[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 301 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 302 | ASSERT_EQ(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 303 | EXPECT_EQ(this->http_bar_com_.url().host(), |
| 304 | cookie_changes[1].cookie.Domain()); |
| 305 | EXPECT_TRUE( |
| 306 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[1].cause)); |
| 307 | EXPECT_EQ("G", cookie_changes[1].cookie.Name()); |
| 308 | EXPECT_EQ("H", cookie_changes[1].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 309 | } |
| 310 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 311 | TYPED_TEST_P(CookieStoreChangeGlobalTest, Overwrite) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 312 | if (!TypeParam::supports_global_cookie_tracking) |
| 313 | return; |
| 314 | |
| 315 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 316 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 317 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 318 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 319 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 320 | base::Unretained(&cookie_changes))); |
| 321 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 322 | ASSERT_EQ(0u, cookie_changes.size()); |
| 323 | |
| 324 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 325 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 326 | ASSERT_EQ(1u, cookie_changes.size()); |
| 327 | cookie_changes.clear(); |
| 328 | |
| 329 | // Replacing an existing cookie is actually a two-phase delete + set |
| 330 | // operation, so we get an extra notification. |
| 331 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=C")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 332 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 333 | |
| 334 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 335 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 336 | cookie_changes[0].cookie.Domain()); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 337 | EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 338 | cookie_changes[0].cause)); |
| 339 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 340 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 341 | |
| 342 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 343 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 344 | cookie_changes[1].cookie.Domain()); |
| 345 | EXPECT_TRUE( |
| 346 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); |
| 347 | EXPECT_EQ("A", cookie_changes[1].cookie.Name()); |
| 348 | EXPECT_EQ("C", cookie_changes[1].cookie.Value()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 349 | |
| 350 | EXPECT_EQ(2u, cookie_changes.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 351 | } |
| 352 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 353 | TYPED_TEST_P(CookieStoreChangeGlobalTest, OverwriteWithHttpOnly) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 354 | if (!TypeParam::supports_global_cookie_tracking) |
| 355 | return; |
| 356 | |
| 357 | // Insert a cookie "A" for path "/path1" |
| 358 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 359 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 360 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 361 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 362 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 363 | base::Unretained(&cookie_changes))); |
| 364 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 365 | ASSERT_EQ(0u, cookie_changes.size()); |
| 366 | |
| 367 | EXPECT_TRUE( |
| 368 | this->SetCookie(cs, this->http_www_foo_.url(), "A=B; path=/path1")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 369 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 370 | ASSERT_EQ(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 371 | EXPECT_TRUE( |
| 372 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); |
| 373 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 374 | cookie_changes[0].cookie.Domain()); |
| 375 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 376 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
| 377 | EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 378 | cookie_changes.clear(); |
| 379 | |
| 380 | // Insert a cookie "A" for path "/path1", that is httponly. This should |
| 381 | // overwrite the non-http-only version. |
| 382 | CookieOptions allow_httponly; |
| 383 | allow_httponly.set_include_httponly(); |
Maks Orlovich | 21845bc | 2019-10-21 22:02:23 | [diff] [blame] | 384 | allow_httponly.set_same_site_cookie_context( |
Steven Bingler | 8d76c2a4 | 2020-03-24 17:13:32 | [diff] [blame] | 385 | net::CookieOptions::SameSiteCookieContext::MakeInclusive()); |
Maks Orlovich | 21845bc | 2019-10-21 22:02:23 | [diff] [blame] | 386 | |
Lily Chen | 0f208ea | 2019-08-08 23:37:53 | [diff] [blame] | 387 | EXPECT_TRUE(this->CreateAndSetCookie(cs, this->http_www_foo_.url(), |
| 388 | "A=C; path=/path1; httponly", |
| 389 | allow_httponly)); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 390 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 391 | |
| 392 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 393 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 394 | cookie_changes[0].cookie.Domain()); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 395 | EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 396 | cookie_changes[0].cause)); |
| 397 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 398 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
| 399 | EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 400 | |
| 401 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 402 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 403 | cookie_changes[1].cookie.Domain()); |
| 404 | EXPECT_TRUE( |
| 405 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); |
| 406 | EXPECT_EQ("A", cookie_changes[1].cookie.Name()); |
| 407 | EXPECT_EQ("C", cookie_changes[1].cookie.Value()); |
| 408 | EXPECT_TRUE(cookie_changes[1].cookie.IsHttpOnly()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 409 | |
| 410 | EXPECT_EQ(2u, cookie_changes.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 411 | } |
| 412 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 413 | TYPED_TEST_P(CookieStoreChangeGlobalTest, Deregister) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 414 | if (!TypeParam::supports_global_cookie_tracking) |
| 415 | return; |
| 416 | |
| 417 | CookieStore* cs = this->GetCookieStore(); |
| 418 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 419 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 420 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 421 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 422 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 423 | base::Unretained(&cookie_changes))); |
| 424 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 425 | ASSERT_EQ(0u, cookie_changes.size()); |
| 426 | |
| 427 | // Insert a cookie and make sure it is seen. |
| 428 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 429 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 430 | ASSERT_EQ(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 431 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 432 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 433 | cookie_changes.clear(); |
| 434 | |
| 435 | // De-register the subscription. |
| 436 | subscription.reset(); |
| 437 | |
| 438 | // Insert a second cookie and make sure that it's not visible. |
| 439 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 440 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 441 | |
| 442 | EXPECT_EQ(0u, cookie_changes.size()); |
| 443 | } |
| 444 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 445 | TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterMultiple) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 446 | if (!TypeParam::supports_global_cookie_tracking || |
| 447 | !TypeParam::supports_multiple_tracking_callbacks) |
| 448 | return; |
| 449 | |
| 450 | CookieStore* cs = this->GetCookieStore(); |
| 451 | |
| 452 | // Register two subscriptions. |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 453 | std::vector<CookieChangeInfo> cookie_changes_1; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 454 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 455 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 456 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 457 | base::Unretained(&cookie_changes_1))); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 458 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 459 | std::vector<CookieChangeInfo> cookie_changes_2; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 460 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 461 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 462 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 463 | base::Unretained(&cookie_changes_2))); |
| 464 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 465 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 466 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 467 | |
| 468 | // Insert a cookie and make sure it's seen. |
| 469 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 470 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 471 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 472 | EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); |
| 473 | EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 474 | cookie_changes_1.clear(); |
| 475 | |
| 476 | ASSERT_EQ(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 477 | EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); |
| 478 | EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 479 | cookie_changes_2.clear(); |
| 480 | |
| 481 | // De-register the second subscription. |
| 482 | subscription2.reset(); |
| 483 | |
| 484 | // Insert a second cookie and make sure that it's only visible in one |
| 485 | // change array. |
| 486 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 487 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 488 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 489 | EXPECT_EQ("C", cookie_changes_1[0].cookie.Name()); |
| 490 | EXPECT_EQ("D", cookie_changes_1[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 491 | cookie_changes_1.clear(); |
| 492 | |
| 493 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 494 | } |
| 495 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 496 | // Confirm that a listener does not receive notifications for changes that |
| 497 | // happened right before the subscription was established. |
| 498 | TYPED_TEST_P(CookieStoreChangeGlobalTest, DispatchRace) { |
| 499 | if (!TypeParam::supports_global_cookie_tracking) |
| 500 | return; |
| 501 | |
| 502 | CookieStore* cs = this->GetCookieStore(); |
| 503 | |
| 504 | // This cookie insertion should not be seen. |
| 505 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 506 | // DeliverChangeNotifications() must NOT be called before the subscription is |
| 507 | // established. |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 508 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 509 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 510 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 511 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 512 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 513 | base::Unretained(&cookie_changes))); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 514 | |
| 515 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 516 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 517 | |
| 518 | EXPECT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 519 | EXPECT_EQ("C", cookie_changes[0].cookie.Name()); |
| 520 | EXPECT_EQ("D", cookie_changes[0].cookie.Value()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 521 | |
| 522 | ASSERT_EQ(1u, cookie_changes.size()); |
| 523 | } |
| 524 | |
| 525 | // Confirm that deregistering a subscription blocks the notification if the |
| 526 | // deregistration happened after the change but before the notification was |
| 527 | // received. |
| 528 | TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterRace) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 529 | if (!TypeParam::supports_global_cookie_tracking) |
| 530 | return; |
| 531 | |
| 532 | CookieStore* cs = this->GetCookieStore(); |
| 533 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 534 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 535 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 536 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 537 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 538 | base::Unretained(&cookie_changes))); |
| 539 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 540 | ASSERT_EQ(0u, cookie_changes.size()); |
| 541 | |
| 542 | // Insert a cookie and make sure it's seen. |
| 543 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 544 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 545 | ASSERT_EQ(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 546 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 547 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 548 | cookie_changes.clear(); |
| 549 | |
| 550 | // Insert a cookie, confirm it is not seen, deregister the subscription, run |
| 551 | // until idle, and confirm the cookie is still not seen. |
| 552 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
| 553 | |
| 554 | // Note that by the API contract it's perfectly valid to have received the |
| 555 | // notification immediately, i.e. synchronously with the cookie change. In |
| 556 | // that case, there's nothing to test. |
| 557 | if (1u == cookie_changes.size()) |
| 558 | return; |
| 559 | |
| 560 | // A task was posted by the SetCookie() above, but has not yet arrived. If it |
| 561 | // arrived before the subscription is destroyed, callback execution would be |
| 562 | // valid. Destroy the subscription so as to lose the race and make sure the |
| 563 | // task posted arrives after the subscription was destroyed. |
| 564 | subscription.reset(); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 565 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 566 | ASSERT_EQ(0u, cookie_changes.size()); |
| 567 | } |
| 568 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 569 | TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterRaceMultiple) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 570 | if (!TypeParam::supports_global_cookie_tracking || |
| 571 | !TypeParam::supports_multiple_tracking_callbacks) |
| 572 | return; |
| 573 | |
| 574 | CookieStore* cs = this->GetCookieStore(); |
| 575 | |
| 576 | // Register two subscriptions. |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 577 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 578 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 579 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 580 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 581 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 582 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 583 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 584 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 585 | base::Unretained(&cookie_changes_2))); |
| 586 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 587 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 588 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 589 | |
| 590 | // Insert a cookie and make sure it's seen. |
| 591 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 592 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 593 | |
| 594 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 595 | EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); |
| 596 | EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 597 | cookie_changes_1.clear(); |
| 598 | |
| 599 | ASSERT_EQ(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 600 | EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); |
| 601 | EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 602 | cookie_changes_2.clear(); |
| 603 | |
| 604 | // Insert a cookie, confirm it is not seen, deregister a subscription, run |
| 605 | // until idle, and confirm the cookie is still not seen. |
| 606 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
| 607 | |
| 608 | // Note that by the API contract it's perfectly valid to have received the |
| 609 | // notification immediately, i.e. synchronously with the cookie change. In |
| 610 | // that case, there's nothing to test. |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 611 | if (1u == cookie_changes_2.size()) |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 612 | return; |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 613 | |
| 614 | // A task was posted by the SetCookie() above, but has not yet arrived. If it |
| 615 | // arrived before the subscription is destroyed, callback execution would be |
| 616 | // valid. Destroy one of the subscriptions so as to lose the race and make |
| 617 | // sure the task posted arrives after the subscription was destroyed. |
| 618 | subscription2.reset(); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 619 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 620 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 621 | EXPECT_EQ("C", cookie_changes_1[0].cookie.Name()); |
| 622 | EXPECT_EQ("D", cookie_changes_1[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 623 | |
| 624 | // No late notification was received. |
| 625 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 626 | } |
| 627 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 628 | TYPED_TEST_P(CookieStoreChangeGlobalTest, MultipleSubscriptions) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 629 | if (!TypeParam::supports_global_cookie_tracking || |
| 630 | !TypeParam::supports_multiple_tracking_callbacks) |
| 631 | return; |
| 632 | |
| 633 | CookieStore* cs = this->GetCookieStore(); |
| 634 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 635 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 636 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 637 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 638 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 639 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 640 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 641 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 642 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 643 | base::Unretained(&cookie_changes_2))); |
| 644 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 645 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 646 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 647 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 648 | |
| 649 | ASSERT_EQ(1U, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 650 | EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); |
| 651 | EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 652 | |
| 653 | ASSERT_EQ(1U, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 654 | EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); |
| 655 | EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); |
| 656 | } |
| 657 | |
| 658 | TYPED_TEST_P(CookieStoreChangeGlobalTest, ChangeIncludesCookieAccessSemantics) { |
| 659 | if (!TypeParam::supports_global_cookie_tracking) |
| 660 | return; |
| 661 | |
| 662 | CookieStore* cs = this->GetCookieStore(); |
| 663 | // if !supports_cookie_access_semantics, the delegate will be stored but will |
| 664 | // not be used. |
| 665 | auto access_delegate = std::make_unique<TestCookieAccessDelegate>(); |
| 666 | access_delegate->SetExpectationForCookieDomain("domain1.test", |
| 667 | CookieAccessSemantics::LEGACY); |
| 668 | access_delegate->SetExpectationForCookieDomain( |
| 669 | "domain2.test", CookieAccessSemantics::NONLEGACY); |
| 670 | access_delegate->SetExpectationForCookieDomain( |
| 671 | "domain3.test", CookieAccessSemantics::UNKNOWN); |
| 672 | cs->SetCookieAccessDelegate(std::move(access_delegate)); |
| 673 | |
| 674 | std::vector<CookieChangeInfo> cookie_changes; |
| 675 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 676 | cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating( |
| 677 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 678 | base::Unretained(&cookie_changes))); |
| 679 | |
| 680 | this->CreateAndSetCookie(cs, GURL("http://domain1.test"), "cookie=1", |
| 681 | CookieOptions::MakeAllInclusive()); |
| 682 | this->CreateAndSetCookie(cs, GURL("http://domain2.test"), "cookie=1", |
| 683 | CookieOptions::MakeAllInclusive()); |
| 684 | this->CreateAndSetCookie(cs, GURL("http://domain3.test"), "cookie=1", |
| 685 | CookieOptions::MakeAllInclusive()); |
| 686 | this->CreateAndSetCookie(cs, GURL("http://domain4.test"), "cookie=1", |
| 687 | CookieOptions::MakeAllInclusive()); |
| 688 | this->DeliverChangeNotifications(); |
| 689 | |
| 690 | ASSERT_EQ(4u, cookie_changes.size()); |
| 691 | |
| 692 | EXPECT_EQ("domain1.test", cookie_changes[0].cookie.Domain()); |
| 693 | EXPECT_TRUE(this->IsExpectedAccessSemantics( |
Ayu Ishii | 9f5e72dc | 2020-07-22 19:43:18 | [diff] [blame] | 694 | CookieAccessSemantics::LEGACY, |
| 695 | cookie_changes[0].access_result.access_semantics)); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 696 | EXPECT_EQ("domain2.test", cookie_changes[1].cookie.Domain()); |
| 697 | EXPECT_TRUE(this->IsExpectedAccessSemantics( |
Ayu Ishii | 9f5e72dc | 2020-07-22 19:43:18 | [diff] [blame] | 698 | CookieAccessSemantics::NONLEGACY, |
| 699 | cookie_changes[1].access_result.access_semantics)); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 700 | EXPECT_EQ("domain3.test", cookie_changes[2].cookie.Domain()); |
| 701 | EXPECT_TRUE(this->IsExpectedAccessSemantics( |
Ayu Ishii | 9f5e72dc | 2020-07-22 19:43:18 | [diff] [blame] | 702 | CookieAccessSemantics::UNKNOWN, |
| 703 | cookie_changes[2].access_result.access_semantics)); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 704 | EXPECT_EQ("domain4.test", cookie_changes[3].cookie.Domain()); |
| 705 | EXPECT_TRUE(this->IsExpectedAccessSemantics( |
Ayu Ishii | 9f5e72dc | 2020-07-22 19:43:18 | [diff] [blame] | 706 | CookieAccessSemantics::UNKNOWN, |
| 707 | cookie_changes[3].access_result.access_semantics)); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 708 | } |
| 709 | |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 710 | TYPED_TEST_P(CookieStoreChangeUrlTest, NoCookie) { |
| 711 | if (!TypeParam::supports_url_cookie_tracking) |
| 712 | return; |
| 713 | |
| 714 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 715 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 716 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 717 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 718 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 719 | base::BindRepeating( |
| 720 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 721 | base::Unretained(&cookie_changes))); |
| 722 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 723 | EXPECT_EQ(0u, cookie_changes.size()); |
| 724 | } |
| 725 | |
| 726 | TYPED_TEST_P(CookieStoreChangeUrlTest, InitialCookie) { |
| 727 | if (!TypeParam::supports_url_cookie_tracking) |
| 728 | return; |
| 729 | |
| 730 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 731 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 732 | this->SetCookie(cs, this->http_www_foo_.url(), "A=B"); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 733 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 734 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 735 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 736 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 737 | base::BindRepeating( |
| 738 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 739 | base::Unretained(&cookie_changes))); |
| 740 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 741 | EXPECT_EQ(0u, cookie_changes.size()); |
| 742 | } |
| 743 | |
| 744 | TYPED_TEST_P(CookieStoreChangeUrlTest, InsertOne) { |
| 745 | if (!TypeParam::supports_url_cookie_tracking) |
| 746 | return; |
| 747 | |
| 748 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 749 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 750 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 751 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 752 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 753 | base::BindRepeating( |
| 754 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 755 | base::Unretained(&cookie_changes))); |
| 756 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 757 | ASSERT_EQ(0u, cookie_changes.size()); |
| 758 | |
| 759 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 760 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 761 | ASSERT_EQ(1u, cookie_changes.size()); |
| 762 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 763 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 764 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
| 765 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 766 | cookie_changes[0].cookie.Domain()); |
| 767 | EXPECT_TRUE( |
| 768 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | TYPED_TEST_P(CookieStoreChangeUrlTest, InsertMany) { |
| 772 | if (!TypeParam::supports_url_cookie_tracking) |
| 773 | return; |
| 774 | |
| 775 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 776 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 777 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 778 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 779 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 780 | base::BindRepeating( |
| 781 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 782 | base::Unretained(&cookie_changes))); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 783 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
| 784 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
| 785 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 786 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 787 | |
| 788 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 789 | EXPECT_TRUE( |
| 790 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); |
| 791 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 792 | cookie_changes[0].cookie.Domain()); |
| 793 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 794 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 795 | |
| 796 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 797 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 798 | cookie_changes[1].cookie.Domain()); |
| 799 | EXPECT_TRUE( |
| 800 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); |
| 801 | EXPECT_EQ("C", cookie_changes[1].cookie.Name()); |
| 802 | EXPECT_EQ("D", cookie_changes[1].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 803 | |
| 804 | ASSERT_LE(3u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 805 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 806 | cookie_changes[2].cookie.Domain()); |
| 807 | EXPECT_TRUE( |
| 808 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[2].cause)); |
| 809 | EXPECT_EQ("E", cookie_changes[2].cookie.Name()); |
| 810 | EXPECT_EQ("F", cookie_changes[2].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 811 | |
| 812 | EXPECT_EQ(3u, cookie_changes.size()); |
| 813 | } |
| 814 | |
| 815 | TYPED_TEST_P(CookieStoreChangeUrlTest, InsertFiltering) { |
| 816 | if (!TypeParam::supports_url_cookie_tracking) |
| 817 | return; |
| 818 | |
| 819 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 820 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 821 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 822 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 823 | this->www_foo_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 824 | base::BindRepeating( |
| 825 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 826 | base::Unretained(&cookie_changes))); |
| 827 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 828 | ASSERT_EQ(0u, cookie_changes.size()); |
| 829 | |
| 830 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B; path=/")); |
| 831 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "C=D; path=/")); |
| 832 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F; path=/bar")); |
| 833 | EXPECT_TRUE( |
| 834 | this->SetCookie(cs, this->http_www_foo_.url(), "G=H; path=/foo/bar")); |
| 835 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "I=J; path=/foo")); |
| 836 | EXPECT_TRUE( |
| 837 | this->SetCookie(cs, this->http_www_foo_.url(), "K=L; domain=foo.com")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 838 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 839 | |
| 840 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 841 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 842 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
| 843 | EXPECT_EQ("/", cookie_changes[0].cookie.Path()); |
| 844 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 845 | cookie_changes[0].cookie.Domain()); |
| 846 | EXPECT_TRUE( |
| 847 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 848 | |
| 849 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 850 | EXPECT_EQ("I", cookie_changes[1].cookie.Name()); |
| 851 | EXPECT_EQ("J", cookie_changes[1].cookie.Value()); |
| 852 | EXPECT_EQ("/foo", cookie_changes[1].cookie.Path()); |
| 853 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 854 | cookie_changes[1].cookie.Domain()); |
| 855 | EXPECT_TRUE( |
| 856 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 857 | |
| 858 | ASSERT_LE(3u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 859 | EXPECT_EQ("K", cookie_changes[2].cookie.Name()); |
| 860 | EXPECT_EQ("L", cookie_changes[2].cookie.Value()); |
| 861 | EXPECT_EQ("/", cookie_changes[2].cookie.Path()); |
| 862 | EXPECT_EQ(".foo.com", cookie_changes[2].cookie.Domain()); |
| 863 | EXPECT_TRUE( |
| 864 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[2].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 865 | |
| 866 | EXPECT_EQ(3u, cookie_changes.size()); |
| 867 | } |
| 868 | |
| 869 | TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteOne) { |
| 870 | if (!TypeParam::supports_url_cookie_tracking) |
| 871 | return; |
| 872 | |
| 873 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 874 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 875 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 876 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 877 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 878 | base::BindRepeating( |
| 879 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 880 | base::Unretained(&cookie_changes))); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 881 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 882 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 883 | EXPECT_EQ(1u, cookie_changes.size()); |
| 884 | cookie_changes.clear(); |
| 885 | |
| 886 | EXPECT_TRUE( |
| 887 | this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "A")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 888 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 889 | |
| 890 | ASSERT_EQ(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 891 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 892 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
| 893 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 894 | cookie_changes[0].cookie.Domain()); |
| 895 | ASSERT_TRUE( |
| 896 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteTwo) { |
| 900 | if (!TypeParam::supports_url_cookie_tracking) |
| 901 | return; |
| 902 | |
| 903 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 904 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 905 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 906 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 907 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 908 | base::BindRepeating( |
| 909 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 910 | base::Unretained(&cookie_changes))); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 911 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
| 912 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
| 913 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F")); |
| 914 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "G=H")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 915 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 916 | EXPECT_EQ(4u, cookie_changes.size()); |
| 917 | cookie_changes.clear(); |
| 918 | |
| 919 | EXPECT_TRUE( |
| 920 | this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "C")); |
| 921 | EXPECT_TRUE( |
| 922 | this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "G")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 923 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 924 | |
| 925 | // Check that the cookie changes are dispatched before calling GetCookies. |
| 926 | // This is not an ASSERT because the following expectations produce useful |
| 927 | // debugging information if they fail. |
| 928 | EXPECT_EQ(2u, cookie_changes.size()); |
| 929 | EXPECT_EQ("A=B; E=F", this->GetCookies(cs, this->http_www_foo_.url())); |
| 930 | |
| 931 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 932 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 933 | cookie_changes[0].cookie.Domain()); |
| 934 | EXPECT_TRUE( |
| 935 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); |
| 936 | EXPECT_EQ("C", cookie_changes[0].cookie.Name()); |
| 937 | EXPECT_EQ("D", cookie_changes[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 938 | |
| 939 | ASSERT_EQ(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 940 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 941 | cookie_changes[1].cookie.Domain()); |
| 942 | EXPECT_TRUE( |
| 943 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[1].cause)); |
| 944 | EXPECT_EQ("G", cookie_changes[1].cookie.Name()); |
| 945 | EXPECT_EQ("H", cookie_changes[1].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteFiltering) { |
| 949 | if (!TypeParam::supports_url_cookie_tracking) |
| 950 | return; |
| 951 | |
| 952 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 953 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 954 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 955 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 956 | this->www_foo_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 957 | base::BindRepeating( |
| 958 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 959 | base::Unretained(&cookie_changes))); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 960 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B; path=/")); |
| 961 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "C=D; path=/")); |
| 962 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F; path=/bar")); |
| 963 | EXPECT_TRUE( |
| 964 | this->SetCookie(cs, this->http_www_foo_.url(), "G=H; path=/foo/bar")); |
| 965 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "I=J; path=/foo")); |
| 966 | EXPECT_TRUE( |
| 967 | this->SetCookie(cs, this->http_www_foo_.url(), "K=L; domain=foo.com")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 968 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 969 | EXPECT_EQ(3u, cookie_changes.size()); |
| 970 | cookie_changes.clear(); |
| 971 | |
| 972 | EXPECT_TRUE( |
| 973 | this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "A")); |
| 974 | EXPECT_TRUE( |
| 975 | this->FindAndDeleteCookie(cs, this->http_bar_com_.url().host(), "C")); |
| 976 | EXPECT_TRUE( |
| 977 | this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "E")); |
| 978 | EXPECT_TRUE( |
| 979 | this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "G")); |
| 980 | EXPECT_TRUE( |
| 981 | this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "I")); |
| 982 | EXPECT_TRUE(this->FindAndDeleteCookie(cs, ".foo.com", "K")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 983 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 984 | |
| 985 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 986 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 987 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
| 988 | EXPECT_EQ("/", cookie_changes[0].cookie.Path()); |
| 989 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 990 | cookie_changes[0].cookie.Domain()); |
| 991 | EXPECT_TRUE( |
| 992 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 993 | |
| 994 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 995 | EXPECT_EQ("I", cookie_changes[1].cookie.Name()); |
| 996 | EXPECT_EQ("J", cookie_changes[1].cookie.Value()); |
| 997 | EXPECT_EQ("/foo", cookie_changes[1].cookie.Path()); |
| 998 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 999 | cookie_changes[1].cookie.Domain()); |
| 1000 | EXPECT_TRUE( |
| 1001 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[1].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1002 | |
| 1003 | ASSERT_LE(3u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1004 | EXPECT_EQ("K", cookie_changes[2].cookie.Name()); |
| 1005 | EXPECT_EQ("L", cookie_changes[2].cookie.Value()); |
| 1006 | EXPECT_EQ("/", cookie_changes[2].cookie.Path()); |
| 1007 | EXPECT_EQ(".foo.com", cookie_changes[2].cookie.Domain()); |
| 1008 | EXPECT_TRUE( |
| 1009 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[2].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1010 | |
| 1011 | EXPECT_EQ(3u, cookie_changes.size()); |
| 1012 | } |
| 1013 | |
| 1014 | TYPED_TEST_P(CookieStoreChangeUrlTest, Overwrite) { |
| 1015 | if (!TypeParam::supports_url_cookie_tracking) |
| 1016 | return; |
| 1017 | |
| 1018 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1019 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1020 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1021 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1022 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1023 | base::BindRepeating( |
| 1024 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1025 | base::Unretained(&cookie_changes))); |
| 1026 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1027 | ASSERT_EQ(0u, cookie_changes.size()); |
| 1028 | |
| 1029 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1030 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1031 | ASSERT_EQ(1u, cookie_changes.size()); |
| 1032 | cookie_changes.clear(); |
| 1033 | |
| 1034 | // Replacing an existing cookie is actually a two-phase delete + set |
| 1035 | // operation, so we get an extra notification. |
| 1036 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=C")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1037 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1038 | |
| 1039 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1040 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1041 | cookie_changes[0].cookie.Domain()); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1042 | EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1043 | cookie_changes[0].cause)); |
| 1044 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 1045 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1046 | |
| 1047 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1048 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1049 | cookie_changes[1].cookie.Domain()); |
| 1050 | EXPECT_TRUE( |
| 1051 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); |
| 1052 | EXPECT_EQ("A", cookie_changes[1].cookie.Name()); |
| 1053 | EXPECT_EQ("C", cookie_changes[1].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1054 | |
| 1055 | EXPECT_EQ(2u, cookie_changes.size()); |
| 1056 | } |
| 1057 | |
| 1058 | TYPED_TEST_P(CookieStoreChangeUrlTest, OverwriteFiltering) { |
| 1059 | if (!TypeParam::supports_url_cookie_tracking) |
| 1060 | return; |
| 1061 | |
| 1062 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1063 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1064 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1065 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1066 | this->www_foo_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1067 | base::BindRepeating( |
| 1068 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1069 | base::Unretained(&cookie_changes))); |
| 1070 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1071 | ASSERT_EQ(0u, cookie_changes.size()); |
| 1072 | |
| 1073 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B; path=/")); |
| 1074 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "C=D; path=/")); |
| 1075 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F; path=/bar")); |
| 1076 | EXPECT_TRUE( |
| 1077 | this->SetCookie(cs, this->http_www_foo_.url(), "G=H; path=/foo/bar")); |
| 1078 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "I=J; path=/foo")); |
| 1079 | EXPECT_TRUE( |
| 1080 | this->SetCookie(cs, this->http_www_foo_.url(), "K=L; domain=foo.com")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1081 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1082 | EXPECT_EQ(3u, cookie_changes.size()); |
| 1083 | cookie_changes.clear(); |
| 1084 | |
| 1085 | // Replacing an existing cookie is actually a two-phase delete + set |
| 1086 | // operation, so we get two notifications per overwrite. |
| 1087 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=b; path=/")); |
| 1088 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "C=d; path=/")); |
| 1089 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=f; path=/bar")); |
| 1090 | EXPECT_TRUE( |
| 1091 | this->SetCookie(cs, this->http_www_foo_.url(), "G=h; path=/foo/bar")); |
| 1092 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "I=j; path=/foo")); |
| 1093 | EXPECT_TRUE( |
| 1094 | this->SetCookie(cs, this->http_www_foo_.url(), "K=l; domain=foo.com")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1095 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1096 | |
| 1097 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1098 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 1099 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
| 1100 | EXPECT_EQ("/", cookie_changes[0].cookie.Path()); |
| 1101 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1102 | cookie_changes[0].cookie.Domain()); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1103 | EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1104 | cookie_changes[0].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1105 | |
| 1106 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1107 | EXPECT_EQ("A", cookie_changes[1].cookie.Name()); |
| 1108 | EXPECT_EQ("b", cookie_changes[1].cookie.Value()); |
| 1109 | EXPECT_EQ("/", cookie_changes[1].cookie.Path()); |
| 1110 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1111 | cookie_changes[1].cookie.Domain()); |
| 1112 | EXPECT_EQ(CookieChangeCause::INSERTED, cookie_changes[1].cause); |
| 1113 | EXPECT_TRUE( |
| 1114 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1115 | |
| 1116 | ASSERT_LE(3u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1117 | EXPECT_EQ("I", cookie_changes[2].cookie.Name()); |
| 1118 | EXPECT_EQ("J", cookie_changes[2].cookie.Value()); |
| 1119 | EXPECT_EQ("/foo", cookie_changes[2].cookie.Path()); |
| 1120 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1121 | cookie_changes[2].cookie.Domain()); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1122 | EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1123 | cookie_changes[2].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1124 | |
| 1125 | ASSERT_LE(4u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1126 | EXPECT_EQ("I", cookie_changes[3].cookie.Name()); |
| 1127 | EXPECT_EQ("j", cookie_changes[3].cookie.Value()); |
| 1128 | EXPECT_EQ("/foo", cookie_changes[3].cookie.Path()); |
| 1129 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1130 | cookie_changes[3].cookie.Domain()); |
| 1131 | EXPECT_TRUE( |
| 1132 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[3].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1133 | |
| 1134 | ASSERT_LE(5u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1135 | EXPECT_EQ("K", cookie_changes[4].cookie.Name()); |
| 1136 | EXPECT_EQ("L", cookie_changes[4].cookie.Value()); |
| 1137 | EXPECT_EQ("/", cookie_changes[4].cookie.Path()); |
| 1138 | EXPECT_EQ(".foo.com", cookie_changes[4].cookie.Domain()); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1139 | EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1140 | cookie_changes[4].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1141 | |
| 1142 | ASSERT_LE(6u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1143 | EXPECT_EQ("K", cookie_changes[5].cookie.Name()); |
| 1144 | EXPECT_EQ("l", cookie_changes[5].cookie.Value()); |
| 1145 | EXPECT_EQ("/", cookie_changes[5].cookie.Path()); |
| 1146 | EXPECT_EQ(".foo.com", cookie_changes[5].cookie.Domain()); |
| 1147 | EXPECT_TRUE( |
| 1148 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[5].cause)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1149 | |
| 1150 | EXPECT_EQ(6u, cookie_changes.size()); |
| 1151 | } |
| 1152 | |
| 1153 | TYPED_TEST_P(CookieStoreChangeUrlTest, OverwriteWithHttpOnly) { |
| 1154 | if (!TypeParam::supports_url_cookie_tracking) |
| 1155 | return; |
| 1156 | |
| 1157 | // Insert a cookie "A" for path "/foo". |
| 1158 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1159 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1160 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1161 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1162 | this->www_foo_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1163 | base::BindRepeating( |
| 1164 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1165 | base::Unretained(&cookie_changes))); |
| 1166 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1167 | ASSERT_EQ(0u, cookie_changes.size()); |
| 1168 | |
| 1169 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B; path=/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1170 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1171 | ASSERT_EQ(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1172 | EXPECT_TRUE( |
| 1173 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); |
| 1174 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1175 | cookie_changes[0].cookie.Domain()); |
| 1176 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 1177 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
| 1178 | EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1179 | cookie_changes.clear(); |
| 1180 | |
| 1181 | // Insert a cookie "A" for path "/foo", that is httponly. This should |
| 1182 | // overwrite the non-http-only version. |
| 1183 | CookieOptions allow_httponly; |
| 1184 | allow_httponly.set_include_httponly(); |
Maks Orlovich | 21845bc | 2019-10-21 22:02:23 | [diff] [blame] | 1185 | allow_httponly.set_same_site_cookie_context( |
Steven Bingler | 8d76c2a4 | 2020-03-24 17:13:32 | [diff] [blame] | 1186 | net::CookieOptions::SameSiteCookieContext::MakeInclusive()); |
Maks Orlovich | 21845bc | 2019-10-21 22:02:23 | [diff] [blame] | 1187 | |
Lily Chen | 0f208ea | 2019-08-08 23:37:53 | [diff] [blame] | 1188 | EXPECT_TRUE(this->CreateAndSetCookie(cs, this->http_www_foo_.url(), |
| 1189 | "A=C; path=/foo; httponly", |
| 1190 | allow_httponly)); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1191 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1192 | |
| 1193 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1194 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1195 | cookie_changes[0].cookie.Domain()); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1196 | EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1197 | cookie_changes[0].cause)); |
| 1198 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 1199 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
| 1200 | EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1201 | |
| 1202 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1203 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1204 | cookie_changes[1].cookie.Domain()); |
| 1205 | EXPECT_TRUE( |
| 1206 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); |
| 1207 | EXPECT_EQ("A", cookie_changes[1].cookie.Name()); |
| 1208 | EXPECT_EQ("C", cookie_changes[1].cookie.Value()); |
| 1209 | EXPECT_TRUE(cookie_changes[1].cookie.IsHttpOnly()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1210 | |
| 1211 | EXPECT_EQ(2u, cookie_changes.size()); |
| 1212 | } |
| 1213 | |
| 1214 | TYPED_TEST_P(CookieStoreChangeUrlTest, Deregister) { |
| 1215 | if (!TypeParam::supports_url_cookie_tracking) |
| 1216 | return; |
| 1217 | |
| 1218 | CookieStore* cs = this->GetCookieStore(); |
| 1219 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1220 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1221 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1222 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1223 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1224 | base::BindRepeating( |
| 1225 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1226 | base::Unretained(&cookie_changes))); |
| 1227 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1228 | ASSERT_EQ(0u, cookie_changes.size()); |
| 1229 | |
| 1230 | // Insert a cookie and make sure it is seen. |
| 1231 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1232 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1233 | ASSERT_EQ(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1234 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 1235 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1236 | cookie_changes.clear(); |
| 1237 | |
| 1238 | // De-register the subscription. |
| 1239 | subscription.reset(); |
| 1240 | |
| 1241 | // Insert a second cookie and make sure it's not visible. |
| 1242 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1243 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1244 | |
| 1245 | EXPECT_EQ(0u, cookie_changes.size()); |
| 1246 | } |
| 1247 | |
| 1248 | TYPED_TEST_P(CookieStoreChangeUrlTest, DeregisterMultiple) { |
| 1249 | if (!TypeParam::supports_url_cookie_tracking || |
| 1250 | !TypeParam::supports_multiple_tracking_callbacks) |
| 1251 | return; |
| 1252 | |
| 1253 | CookieStore* cs = this->GetCookieStore(); |
| 1254 | |
| 1255 | // Register two subscriptions. |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1256 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1257 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 1258 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1259 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1260 | base::BindRepeating( |
| 1261 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1262 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1263 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 1264 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1265 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1266 | base::BindRepeating( |
| 1267 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1268 | base::Unretained(&cookie_changes_2))); |
| 1269 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1270 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 1271 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 1272 | |
| 1273 | // Insert a cookie and make sure it's seen. |
| 1274 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1275 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1276 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1277 | EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); |
| 1278 | EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1279 | cookie_changes_1.clear(); |
| 1280 | |
| 1281 | ASSERT_EQ(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1282 | EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); |
| 1283 | EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1284 | cookie_changes_2.clear(); |
| 1285 | |
| 1286 | // De-register the second registration. |
| 1287 | subscription2.reset(); |
| 1288 | |
| 1289 | // Insert a second cookie and make sure that it's only visible in one |
| 1290 | // change array. |
| 1291 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1292 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1293 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1294 | EXPECT_EQ("C", cookie_changes_1[0].cookie.Name()); |
| 1295 | EXPECT_EQ("D", cookie_changes_1[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1296 | |
| 1297 | EXPECT_EQ(0u, cookie_changes_2.size()); |
| 1298 | } |
| 1299 | |
| 1300 | // Confirm that a listener does not receive notifications for changes that |
| 1301 | // happened right before the subscription was established. |
| 1302 | TYPED_TEST_P(CookieStoreChangeUrlTest, DispatchRace) { |
| 1303 | if (!TypeParam::supports_url_cookie_tracking) |
| 1304 | return; |
| 1305 | |
| 1306 | CookieStore* cs = this->GetCookieStore(); |
| 1307 | |
| 1308 | // This cookie insertion should not be seen. |
| 1309 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1310 | // DeliverChangeNotifications() must NOT be called before the subscription is |
| 1311 | // established. |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1312 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1313 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1314 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1315 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1316 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1317 | base::BindRepeating( |
| 1318 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1319 | base::Unretained(&cookie_changes))); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1320 | |
| 1321 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1322 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1323 | |
| 1324 | EXPECT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1325 | EXPECT_EQ("C", cookie_changes[0].cookie.Name()); |
| 1326 | EXPECT_EQ("D", cookie_changes[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1327 | |
| 1328 | ASSERT_EQ(1u, cookie_changes.size()); |
| 1329 | } |
| 1330 | |
| 1331 | // Confirm that deregistering a subscription blocks the notification if the |
| 1332 | // deregistration happened after the change but before the notification was |
| 1333 | // received. |
| 1334 | TYPED_TEST_P(CookieStoreChangeUrlTest, DeregisterRace) { |
| 1335 | if (!TypeParam::supports_url_cookie_tracking) |
| 1336 | return; |
| 1337 | |
| 1338 | CookieStore* cs = this->GetCookieStore(); |
| 1339 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1340 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1341 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1342 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1343 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1344 | base::BindRepeating( |
| 1345 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1346 | base::Unretained(&cookie_changes))); |
| 1347 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1348 | ASSERT_EQ(0u, cookie_changes.size()); |
| 1349 | |
| 1350 | // Insert a cookie and make sure it's seen. |
| 1351 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1352 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1353 | ASSERT_EQ(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1354 | EXPECT_EQ("A", cookie_changes[0].cookie.Name()); |
| 1355 | EXPECT_EQ("B", cookie_changes[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1356 | cookie_changes.clear(); |
| 1357 | |
| 1358 | // Insert a cookie, confirm it is not seen, deregister the subscription, run |
| 1359 | // until idle, and confirm the cookie is still not seen. |
| 1360 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
| 1361 | |
| 1362 | // Note that by the API contract it's perfectly valid to have received the |
| 1363 | // notification immediately, i.e. synchronously with the cookie change. In |
| 1364 | // that case, there's nothing to test. |
| 1365 | if (1u == cookie_changes.size()) |
| 1366 | return; |
| 1367 | |
| 1368 | // A task was posted by the SetCookie() above, but has not yet arrived. If it |
| 1369 | // arrived before the subscription is destroyed, callback execution would be |
| 1370 | // valid. Destroy the subscription so as to lose the race and make sure the |
| 1371 | // task posted arrives after the subscription was destroyed. |
| 1372 | subscription.reset(); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1373 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1374 | ASSERT_EQ(0u, cookie_changes.size()); |
| 1375 | } |
| 1376 | |
| 1377 | TYPED_TEST_P(CookieStoreChangeUrlTest, DeregisterRaceMultiple) { |
| 1378 | if (!TypeParam::supports_url_cookie_tracking || |
| 1379 | !TypeParam::supports_multiple_tracking_callbacks) |
| 1380 | return; |
| 1381 | |
| 1382 | CookieStore* cs = this->GetCookieStore(); |
| 1383 | |
| 1384 | // Register two subscriptions. |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1385 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1386 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 1387 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1388 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1389 | base::BindRepeating( |
| 1390 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1391 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1392 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 1393 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1394 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1395 | base::BindRepeating( |
| 1396 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1397 | base::Unretained(&cookie_changes_2))); |
| 1398 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1399 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 1400 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 1401 | |
| 1402 | // Insert a cookie and make sure it's seen. |
| 1403 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1404 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1405 | |
| 1406 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1407 | EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); |
| 1408 | EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1409 | cookie_changes_1.clear(); |
| 1410 | |
| 1411 | ASSERT_EQ(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1412 | EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); |
| 1413 | EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1414 | cookie_changes_2.clear(); |
| 1415 | |
| 1416 | // Insert a cookie, confirm it is not seen, deregister a subscription, run |
| 1417 | // until idle, and confirm the cookie is still not seen. |
| 1418 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D")); |
| 1419 | |
| 1420 | // Note that by the API contract it's perfectly valid to have received the |
| 1421 | // notification immediately, i.e. synchronously with the cookie change. In |
| 1422 | // that case, there's nothing to test. |
| 1423 | if (1u == cookie_changes_2.size()) |
| 1424 | return; |
| 1425 | |
| 1426 | // A task was posted by the SetCookie() above, but has not yet arrived. If it |
| 1427 | // arrived before the subscription is destroyed, callback execution would be |
| 1428 | // valid. Destroy one of the subscriptions so as to lose the race and make |
| 1429 | // sure the task posted arrives after the subscription was destroyed. |
| 1430 | subscription2.reset(); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1431 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1432 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1433 | EXPECT_EQ("C", cookie_changes_1[0].cookie.Name()); |
| 1434 | EXPECT_EQ("D", cookie_changes_1[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1435 | |
| 1436 | // No late notification was received. |
| 1437 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 1438 | } |
| 1439 | |
| 1440 | TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsDisjoint) { |
| 1441 | if (!TypeParam::supports_url_cookie_tracking) |
| 1442 | return; |
| 1443 | |
| 1444 | CookieStore* cs = this->GetCookieStore(); |
| 1445 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1446 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1447 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 1448 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1449 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1450 | base::BindRepeating( |
| 1451 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1452 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1453 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 1454 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1455 | this->http_bar_com_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1456 | base::BindRepeating( |
| 1457 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1458 | base::Unretained(&cookie_changes_2))); |
| 1459 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1460 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 1461 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 1462 | |
| 1463 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1464 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1465 | EXPECT_EQ(1u, cookie_changes_1.size()); |
| 1466 | EXPECT_EQ(0u, cookie_changes_2.size()); |
| 1467 | |
| 1468 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "C=D")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1469 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1470 | |
| 1471 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1472 | EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); |
| 1473 | EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1474 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1475 | cookie_changes_1[0].cookie.Domain()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1476 | |
| 1477 | ASSERT_EQ(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1478 | EXPECT_EQ("C", cookie_changes_2[0].cookie.Name()); |
| 1479 | EXPECT_EQ("D", cookie_changes_2[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1480 | EXPECT_EQ(this->http_bar_com_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1481 | cookie_changes_2[0].cookie.Domain()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsDomains) { |
| 1485 | if (!TypeParam::supports_url_cookie_tracking) |
| 1486 | return; |
| 1487 | |
| 1488 | CookieStore* cs = this->GetCookieStore(); |
| 1489 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1490 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1491 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 1492 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1493 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1494 | base::BindRepeating( |
| 1495 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1496 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1497 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 1498 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1499 | this->http_bar_com_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1500 | base::BindRepeating( |
| 1501 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1502 | base::Unretained(&cookie_changes_2))); |
| 1503 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1504 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 1505 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 1506 | |
| 1507 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1508 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1509 | EXPECT_EQ(1u, cookie_changes_1.size()); |
| 1510 | EXPECT_EQ(0u, cookie_changes_2.size()); |
| 1511 | |
| 1512 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "C=D")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1513 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1514 | |
| 1515 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1516 | EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); |
| 1517 | EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1518 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1519 | cookie_changes_1[0].cookie.Domain()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1520 | |
| 1521 | ASSERT_EQ(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1522 | EXPECT_EQ("C", cookie_changes_2[0].cookie.Name()); |
| 1523 | EXPECT_EQ("D", cookie_changes_2[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1524 | EXPECT_EQ(this->http_bar_com_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1525 | cookie_changes_2[0].cookie.Domain()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsPaths) { |
| 1529 | if (!TypeParam::supports_url_cookie_tracking) |
| 1530 | return; |
| 1531 | |
| 1532 | CookieStore* cs = this->GetCookieStore(); |
| 1533 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1534 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1535 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 1536 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1537 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1538 | base::BindRepeating( |
| 1539 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1540 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1541 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 1542 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1543 | this->www_foo_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1544 | base::BindRepeating( |
| 1545 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1546 | base::Unretained(&cookie_changes_2))); |
| 1547 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1548 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 1549 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 1550 | |
| 1551 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1552 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1553 | EXPECT_EQ(1u, cookie_changes_1.size()); |
| 1554 | EXPECT_EQ(1u, cookie_changes_2.size()); |
| 1555 | |
| 1556 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D; path=/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1557 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1558 | |
| 1559 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1560 | EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); |
| 1561 | EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); |
| 1562 | EXPECT_EQ("/", cookie_changes_1[0].cookie.Path()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1563 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1564 | cookie_changes_1[0].cookie.Domain()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1565 | |
| 1566 | ASSERT_LE(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1567 | EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); |
| 1568 | EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); |
| 1569 | EXPECT_EQ("/", cookie_changes_2[0].cookie.Path()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1570 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1571 | cookie_changes_2[0].cookie.Domain()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1572 | |
| 1573 | ASSERT_LE(2u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1574 | EXPECT_EQ("C", cookie_changes_2[1].cookie.Name()); |
| 1575 | EXPECT_EQ("D", cookie_changes_2[1].cookie.Value()); |
| 1576 | EXPECT_EQ("/foo", cookie_changes_2[1].cookie.Path()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1577 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1578 | cookie_changes_2[1].cookie.Domain()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1579 | |
| 1580 | EXPECT_EQ(2u, cookie_changes_2.size()); |
| 1581 | } |
| 1582 | |
| 1583 | TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsFiltering) { |
| 1584 | if (!TypeParam::supports_url_cookie_tracking) |
| 1585 | return; |
| 1586 | |
| 1587 | CookieStore* cs = this->GetCookieStore(); |
| 1588 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1589 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
| 1590 | std::vector<CookieChangeInfo> cookie_changes_3; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1591 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 1592 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1593 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1594 | base::BindRepeating( |
| 1595 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1596 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1597 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 1598 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1599 | this->http_bar_com_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1600 | base::BindRepeating( |
| 1601 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1602 | base::Unretained(&cookie_changes_2))); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1603 | std::unique_ptr<CookieChangeSubscription> subscription3 = |
| 1604 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1605 | this->www_foo_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1606 | base::BindRepeating( |
| 1607 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1608 | base::Unretained(&cookie_changes_3))); |
| 1609 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1610 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 1611 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 1612 | EXPECT_EQ(0u, cookie_changes_3.size()); |
| 1613 | |
| 1614 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1615 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1616 | EXPECT_EQ(1u, cookie_changes_1.size()); |
| 1617 | EXPECT_EQ(0u, cookie_changes_2.size()); |
| 1618 | EXPECT_EQ(1u, cookie_changes_3.size()); |
| 1619 | |
| 1620 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "C=D")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1621 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1622 | EXPECT_EQ(1u, cookie_changes_1.size()); |
| 1623 | EXPECT_EQ(1u, cookie_changes_2.size()); |
| 1624 | EXPECT_EQ(1u, cookie_changes_3.size()); |
| 1625 | |
| 1626 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F; path=/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1627 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1628 | |
| 1629 | ASSERT_LE(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1630 | EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); |
| 1631 | EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1632 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1633 | cookie_changes_1[0].cookie.Domain()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1634 | EXPECT_EQ(1u, cookie_changes_1.size()); |
| 1635 | |
| 1636 | ASSERT_LE(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1637 | EXPECT_EQ("C", cookie_changes_2[0].cookie.Name()); |
| 1638 | EXPECT_EQ("D", cookie_changes_2[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1639 | EXPECT_EQ(this->http_bar_com_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1640 | cookie_changes_2[0].cookie.Domain()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1641 | EXPECT_EQ(1u, cookie_changes_2.size()); |
| 1642 | |
| 1643 | ASSERT_LE(1u, cookie_changes_3.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1644 | EXPECT_EQ("A", cookie_changes_3[0].cookie.Name()); |
| 1645 | EXPECT_EQ("B", cookie_changes_3[0].cookie.Value()); |
| 1646 | EXPECT_EQ("/", cookie_changes_3[0].cookie.Path()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1647 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1648 | cookie_changes_3[0].cookie.Domain()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1649 | |
| 1650 | ASSERT_LE(2u, cookie_changes_3.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1651 | EXPECT_EQ("E", cookie_changes_3[1].cookie.Name()); |
| 1652 | EXPECT_EQ("F", cookie_changes_3[1].cookie.Value()); |
| 1653 | EXPECT_EQ("/foo", cookie_changes_3[1].cookie.Path()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1654 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1655 | cookie_changes_3[1].cookie.Domain()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1656 | |
| 1657 | EXPECT_EQ(2u, cookie_changes_3.size()); |
| 1658 | } |
| 1659 | |
| 1660 | TYPED_TEST_P(CookieStoreChangeUrlTest, MultipleSubscriptions) { |
| 1661 | if (!TypeParam::supports_url_cookie_tracking || |
| 1662 | !TypeParam::supports_multiple_tracking_callbacks) |
| 1663 | return; |
| 1664 | |
| 1665 | CookieStore* cs = this->GetCookieStore(); |
| 1666 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1667 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1668 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 1669 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1670 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1671 | base::BindRepeating( |
| 1672 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1673 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1674 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 1675 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1676 | this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1677 | base::BindRepeating( |
| 1678 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1679 | base::Unretained(&cookie_changes_2))); |
| 1680 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1681 | |
| 1682 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1683 | this->DeliverChangeNotifications(); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1684 | |
| 1685 | ASSERT_EQ(1U, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1686 | EXPECT_EQ("A", cookie_changes_1[0].cookie.Name()); |
| 1687 | EXPECT_EQ("B", cookie_changes_1[0].cookie.Value()); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1688 | |
| 1689 | ASSERT_EQ(1U, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1690 | EXPECT_EQ("A", cookie_changes_2[0].cookie.Name()); |
| 1691 | EXPECT_EQ("B", cookie_changes_2[0].cookie.Value()); |
| 1692 | } |
| 1693 | |
| 1694 | TYPED_TEST_P(CookieStoreChangeUrlTest, ChangeIncludesCookieAccessSemantics) { |
| 1695 | if (!TypeParam::supports_url_cookie_tracking) |
| 1696 | return; |
| 1697 | |
| 1698 | CookieStore* cs = this->GetCookieStore(); |
| 1699 | // if !supports_cookie_access_semantics, the delegate will be stored but will |
| 1700 | // not be used. |
| 1701 | auto access_delegate = std::make_unique<TestCookieAccessDelegate>(); |
| 1702 | access_delegate->SetExpectationForCookieDomain("domain1.test", |
| 1703 | CookieAccessSemantics::LEGACY); |
| 1704 | cs->SetCookieAccessDelegate(std::move(access_delegate)); |
| 1705 | |
| 1706 | std::vector<CookieChangeInfo> cookie_changes; |
| 1707 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1708 | cs->GetChangeDispatcher().AddCallbackForUrl( |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1709 | GURL("http://domain1.test"), absl::nullopt /* cookie_partition_key */, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1710 | base::BindRepeating( |
| 1711 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1712 | base::Unretained(&cookie_changes))); |
| 1713 | |
| 1714 | this->CreateAndSetCookie(cs, GURL("http://domain1.test"), "cookie=1", |
| 1715 | CookieOptions::MakeAllInclusive()); |
| 1716 | this->DeliverChangeNotifications(); |
| 1717 | |
| 1718 | ASSERT_EQ(1u, cookie_changes.size()); |
| 1719 | |
| 1720 | EXPECT_EQ("domain1.test", cookie_changes[0].cookie.Domain()); |
| 1721 | EXPECT_TRUE(this->IsExpectedAccessSemantics( |
Ayu Ishii | 9f5e72dc | 2020-07-22 19:43:18 | [diff] [blame] | 1722 | CookieAccessSemantics::LEGACY, |
| 1723 | cookie_changes[0].access_result.access_semantics)); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 1724 | } |
| 1725 | |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1726 | TYPED_TEST_P(CookieStoreChangeUrlTest, PartitionedCookies) { |
| 1727 | if (!TypeParam::supports_url_cookie_tracking || |
| 1728 | !TypeParam::supports_partitioned_cookies) |
| 1729 | return; |
| 1730 | |
| 1731 | CookieStore* cs = this->GetCookieStore(); |
| 1732 | std::vector<CookieChangeInfo> cookie_changes; |
| 1733 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1734 | cs->GetChangeDispatcher().AddCallbackForUrl( |
| 1735 | GURL("https://www.example.com/"), |
Dylan Cutler | 6ac1c67a8 | 2022-03-31 11:36:16 | [diff] [blame] | 1736 | CookiePartitionKey::FromURLForTesting(GURL("https://www.foo.com")), |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1737 | base::BindRepeating( |
| 1738 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1739 | base::Unretained(&cookie_changes))); |
| 1740 | |
| 1741 | // Unpartitioned cookie |
| 1742 | this->CreateAndSetCookie(cs, GURL("https://www.example.com/"), |
| 1743 | "__Host-a=1; Secure; Path=/", |
| 1744 | CookieOptions::MakeAllInclusive()); |
| 1745 | // Partitioned cookie with the same partition key |
| 1746 | this->CreateAndSetCookie( |
| 1747 | cs, GURL("https://www.example.com/"), |
| 1748 | "__Host-b=2; Secure; Path=/; Partitioned", |
| 1749 | CookieOptions::MakeAllInclusive(), absl::nullopt /* server_time */, |
| 1750 | absl::nullopt /* system_time */, |
| 1751 | absl::make_optional( |
| 1752 | CookiePartitionKey::FromURLForTesting(GURL("https://sub.foo.com")))); |
| 1753 | // Partitioned cookie with a different partition key |
| 1754 | this->CreateAndSetCookie( |
| 1755 | cs, GURL("https://www.example.com"), |
| 1756 | "__Host-c=3; Secure; Path=/; Partitioned", |
| 1757 | CookieOptions::MakeAllInclusive(), absl::nullopt /* server_time */, |
| 1758 | absl::nullopt /* system_time */, |
| 1759 | absl::make_optional( |
| 1760 | CookiePartitionKey::FromURLForTesting(GURL("https://www.bar.com")))); |
| 1761 | this->DeliverChangeNotifications(); |
| 1762 | |
| 1763 | ASSERT_EQ(2u, cookie_changes.size()); |
| 1764 | EXPECT_FALSE(cookie_changes[0].cookie.IsPartitioned()); |
| 1765 | EXPECT_EQ("__Host-a", cookie_changes[0].cookie.Name()); |
| 1766 | EXPECT_TRUE(cookie_changes[1].cookie.IsPartitioned()); |
| 1767 | EXPECT_EQ(CookiePartitionKey::FromURLForTesting(GURL("https://www.foo.com")), |
| 1768 | cookie_changes[1].cookie.PartitionKey().value()); |
| 1769 | EXPECT_EQ("__Host-b", cookie_changes[1].cookie.Name()); |
| 1770 | |
| 1771 | // Test that when the partition key parameter is nullopt that all Partitioned |
| 1772 | // cookies do not emit events. |
| 1773 | |
| 1774 | std::vector<CookieChangeInfo> other_cookie_changes; |
| 1775 | std::unique_ptr<CookieChangeSubscription> other_subscription = |
| 1776 | cs->GetChangeDispatcher().AddCallbackForUrl( |
| 1777 | GURL("https://www.example.com/"), |
| 1778 | absl::nullopt /* cookie_partition_key */, |
| 1779 | base::BindRepeating( |
| 1780 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1781 | base::Unretained(&other_cookie_changes))); |
| 1782 | // Update Max-Age: None -> 7200 |
| 1783 | this->CreateAndSetCookie( |
| 1784 | cs, GURL("https://www.example.com"), |
| 1785 | "__Host-b=2; Secure; Path=/; Partitioned; Max-Age=7200", |
| 1786 | CookieOptions::MakeAllInclusive(), absl::nullopt /* server_time */, |
| 1787 | absl::nullopt /* system_time */, |
| 1788 | absl::make_optional( |
| 1789 | CookiePartitionKey::FromURLForTesting(GURL("https://www.foo.com")))); |
| 1790 | this->DeliverChangeNotifications(); |
| 1791 | ASSERT_EQ(0u, other_cookie_changes.size()); |
| 1792 | // Check that the other listener was invoked. |
| 1793 | ASSERT_LT(2u, cookie_changes.size()); |
| 1794 | } |
| 1795 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1796 | TYPED_TEST_P(CookieStoreChangeNamedTest, NoCookie) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1797 | if (!TypeParam::supports_named_cookie_tracking) |
| 1798 | return; |
| 1799 | |
| 1800 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1801 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 1802 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1803 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1804 | this->http_www_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1805 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1806 | base::BindRepeating( |
| 1807 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1808 | base::Unretained(&cookie_changes))); |
| 1809 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1810 | EXPECT_EQ(0u, cookie_changes.size()); |
| 1811 | } |
| 1812 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1813 | TYPED_TEST_P(CookieStoreChangeNamedTest, InitialCookie) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1814 | if (!TypeParam::supports_named_cookie_tracking) |
| 1815 | return; |
| 1816 | |
| 1817 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1818 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1819 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=def"); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1820 | this->DeliverChangeNotifications(); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 1821 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1822 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1823 | this->http_www_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1824 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1825 | base::BindRepeating( |
| 1826 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1827 | base::Unretained(&cookie_changes))); |
| 1828 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1829 | EXPECT_EQ(0u, cookie_changes.size()); |
| 1830 | } |
| 1831 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1832 | TYPED_TEST_P(CookieStoreChangeNamedTest, InsertOne) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1833 | if (!TypeParam::supports_named_cookie_tracking) |
| 1834 | return; |
| 1835 | |
| 1836 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1837 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 1838 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1839 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1840 | this->http_www_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1841 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1842 | base::BindRepeating( |
| 1843 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1844 | base::Unretained(&cookie_changes))); |
| 1845 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1846 | ASSERT_EQ(0u, cookie_changes.size()); |
| 1847 | |
| 1848 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1849 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1850 | ASSERT_EQ(1u, cookie_changes.size()); |
| 1851 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1852 | EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); |
| 1853 | EXPECT_EQ("def", cookie_changes[0].cookie.Value()); |
| 1854 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1855 | cookie_changes[0].cookie.Domain()); |
| 1856 | EXPECT_TRUE( |
| 1857 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1858 | } |
| 1859 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1860 | TYPED_TEST_P(CookieStoreChangeNamedTest, InsertTwo) { |
| 1861 | if (!TypeParam::supports_named_cookie_tracking) |
| 1862 | return; |
| 1863 | |
| 1864 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1865 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1866 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1867 | cs->GetChangeDispatcher().AddCallbackForCookie( |
| 1868 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1869 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1870 | base::BindRepeating( |
| 1871 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1872 | base::Unretained(&cookie_changes))); |
| 1873 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1874 | ASSERT_EQ(0u, cookie_changes.size()); |
| 1875 | |
| 1876 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def")); |
| 1877 | EXPECT_TRUE( |
| 1878 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=hij; path=/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1879 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1880 | |
| 1881 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1882 | EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); |
| 1883 | EXPECT_EQ("def", cookie_changes[0].cookie.Value()); |
| 1884 | EXPECT_EQ("/", cookie_changes[0].cookie.Path()); |
| 1885 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1886 | cookie_changes[0].cookie.Domain()); |
| 1887 | EXPECT_TRUE( |
| 1888 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1889 | |
| 1890 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1891 | EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); |
| 1892 | EXPECT_EQ("hij", cookie_changes[1].cookie.Value()); |
| 1893 | EXPECT_EQ("/foo", cookie_changes[1].cookie.Path()); |
| 1894 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1895 | cookie_changes[1].cookie.Domain()); |
| 1896 | EXPECT_TRUE( |
| 1897 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1898 | |
| 1899 | EXPECT_EQ(2u, cookie_changes.size()); |
| 1900 | } |
| 1901 | |
| 1902 | TYPED_TEST_P(CookieStoreChangeNamedTest, InsertFiltering) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1903 | if (!TypeParam::supports_named_cookie_tracking) |
| 1904 | return; |
| 1905 | |
| 1906 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1907 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 1908 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1909 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1910 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1911 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1912 | base::BindRepeating( |
| 1913 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1914 | base::Unretained(&cookie_changes))); |
| 1915 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1916 | ASSERT_EQ(0u, cookie_changes.size()); |
| 1917 | |
| 1918 | EXPECT_TRUE( |
| 1919 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=def; path=/")); |
| 1920 | EXPECT_TRUE( |
| 1921 | this->SetCookie(cs, this->http_bar_com_.url(), "abc=ghi; path=/")); |
| 1922 | EXPECT_TRUE( |
| 1923 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=jkl; path=/bar")); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1924 | EXPECT_TRUE( |
| 1925 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=mno; path=/foo/bar")); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1926 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "xyz=zyx")); |
| 1927 | EXPECT_TRUE( |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1928 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=pqr; path=/foo")); |
| 1929 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), |
| 1930 | "abc=stu; domain=foo.com")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1931 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1932 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1933 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1934 | EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); |
| 1935 | EXPECT_EQ("def", cookie_changes[0].cookie.Value()); |
| 1936 | EXPECT_EQ("/", cookie_changes[0].cookie.Path()); |
| 1937 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1938 | cookie_changes[0].cookie.Domain()); |
| 1939 | EXPECT_TRUE( |
| 1940 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1941 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1942 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1943 | EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); |
| 1944 | EXPECT_EQ("pqr", cookie_changes[1].cookie.Value()); |
| 1945 | EXPECT_EQ("/foo", cookie_changes[1].cookie.Path()); |
| 1946 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1947 | cookie_changes[1].cookie.Domain()); |
| 1948 | EXPECT_TRUE( |
| 1949 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1950 | |
| 1951 | ASSERT_LE(3u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1952 | EXPECT_EQ("abc", cookie_changes[2].cookie.Name()); |
| 1953 | EXPECT_EQ("stu", cookie_changes[2].cookie.Value()); |
| 1954 | EXPECT_EQ("/", cookie_changes[2].cookie.Path()); |
| 1955 | EXPECT_EQ(".foo.com", cookie_changes[2].cookie.Domain()); |
| 1956 | EXPECT_TRUE( |
| 1957 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[2].cause)); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1958 | |
| 1959 | EXPECT_EQ(3u, cookie_changes.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1960 | } |
| 1961 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1962 | TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteOne) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1963 | if (!TypeParam::supports_named_cookie_tracking) |
| 1964 | return; |
| 1965 | |
| 1966 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1967 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 1968 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 1969 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1970 | this->http_www_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 1971 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1972 | base::BindRepeating( |
| 1973 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 1974 | base::Unretained(&cookie_changes))); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1975 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1976 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1977 | EXPECT_EQ(1u, cookie_changes.size()); |
| 1978 | cookie_changes.clear(); |
| 1979 | |
| 1980 | EXPECT_TRUE( |
| 1981 | this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "abc")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 1982 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1983 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1984 | ASSERT_EQ(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1985 | EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); |
| 1986 | EXPECT_EQ("def", cookie_changes[0].cookie.Value()); |
| 1987 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 1988 | cookie_changes[0].cookie.Domain()); |
| 1989 | EXPECT_TRUE( |
| 1990 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1991 | } |
| 1992 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 1993 | TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteTwo) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 1994 | if (!TypeParam::supports_named_cookie_tracking) |
| 1995 | return; |
| 1996 | |
| 1997 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 1998 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 1999 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 2000 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2001 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2002 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2003 | base::BindRepeating( |
| 2004 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2005 | base::Unretained(&cookie_changes))); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2006 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def")); |
| 2007 | EXPECT_TRUE( |
| 2008 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=hij; path=/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2009 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2010 | EXPECT_EQ(2u, cookie_changes.size()); |
| 2011 | cookie_changes.clear(); |
| 2012 | |
| 2013 | EXPECT_TRUE(this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), |
| 2014 | "abc", "/")); |
| 2015 | EXPECT_TRUE(this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), |
| 2016 | "abc", "/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2017 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2018 | |
| 2019 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2020 | EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); |
| 2021 | EXPECT_EQ("def", cookie_changes[0].cookie.Value()); |
| 2022 | EXPECT_EQ("/", cookie_changes[0].cookie.Path()); |
| 2023 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 2024 | cookie_changes[0].cookie.Domain()); |
| 2025 | EXPECT_TRUE( |
| 2026 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2027 | |
| 2028 | ASSERT_EQ(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2029 | EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); |
| 2030 | EXPECT_EQ("hij", cookie_changes[1].cookie.Value()); |
| 2031 | EXPECT_EQ("/foo", cookie_changes[1].cookie.Path()); |
| 2032 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 2033 | cookie_changes[1].cookie.Domain()); |
| 2034 | EXPECT_TRUE( |
| 2035 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[1].cause)); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteFiltering) { |
| 2039 | if (!TypeParam::supports_named_cookie_tracking) |
| 2040 | return; |
| 2041 | |
| 2042 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2043 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2044 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 2045 | cs->GetChangeDispatcher().AddCallbackForCookie( |
| 2046 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2047 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2048 | base::BindRepeating( |
| 2049 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2050 | base::Unretained(&cookie_changes))); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2051 | EXPECT_TRUE( |
| 2052 | this->SetCookie(cs, this->http_www_foo_.url(), "xyz=zyx; path=/")); |
| 2053 | EXPECT_TRUE( |
| 2054 | this->SetCookie(cs, this->http_bar_com_.url(), "abc=def; path=/")); |
| 2055 | EXPECT_TRUE( |
| 2056 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=hij; path=/foo/bar")); |
| 2057 | EXPECT_TRUE( |
| 2058 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=mno; path=/foo")); |
| 2059 | EXPECT_TRUE( |
| 2060 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=pqr; path=/")); |
| 2061 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), |
| 2062 | "abc=stu; domain=foo.com")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2063 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2064 | EXPECT_EQ(3u, cookie_changes.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2065 | cookie_changes.clear(); |
| 2066 | |
| 2067 | EXPECT_TRUE( |
| 2068 | this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "xyz")); |
| 2069 | EXPECT_TRUE( |
| 2070 | this->FindAndDeleteCookie(cs, this->http_bar_com_.url().host(), "abc")); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2071 | EXPECT_TRUE(this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), |
| 2072 | "abc", "/foo/bar")); |
| 2073 | EXPECT_TRUE(this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), |
| 2074 | "abc", "/foo")); |
| 2075 | EXPECT_TRUE(this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), |
| 2076 | "abc", "/")); |
| 2077 | EXPECT_TRUE(this->FindAndDeleteCookie(cs, ".foo.com", "abc", "/")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2078 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2079 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2080 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2081 | EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); |
| 2082 | EXPECT_EQ("mno", cookie_changes[0].cookie.Value()); |
| 2083 | EXPECT_EQ("/foo", cookie_changes[0].cookie.Path()); |
| 2084 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 2085 | cookie_changes[0].cookie.Domain()); |
| 2086 | EXPECT_TRUE( |
| 2087 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause)); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2088 | |
| 2089 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2090 | EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); |
| 2091 | EXPECT_EQ("pqr", cookie_changes[1].cookie.Value()); |
| 2092 | EXPECT_EQ("/", cookie_changes[1].cookie.Path()); |
| 2093 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 2094 | cookie_changes[1].cookie.Domain()); |
| 2095 | EXPECT_TRUE( |
| 2096 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[1].cause)); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2097 | |
| 2098 | ASSERT_LE(3u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2099 | EXPECT_EQ("abc", cookie_changes[2].cookie.Name()); |
| 2100 | EXPECT_EQ("stu", cookie_changes[2].cookie.Value()); |
| 2101 | EXPECT_EQ("/", cookie_changes[2].cookie.Path()); |
| 2102 | EXPECT_EQ(".foo.com", cookie_changes[2].cookie.Domain()); |
| 2103 | EXPECT_TRUE( |
| 2104 | this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[2].cause)); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2105 | |
| 2106 | EXPECT_EQ(3u, cookie_changes.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2107 | } |
| 2108 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2109 | TYPED_TEST_P(CookieStoreChangeNamedTest, Overwrite) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2110 | if (!TypeParam::supports_named_cookie_tracking) |
| 2111 | return; |
| 2112 | |
| 2113 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2114 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2115 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 2116 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2117 | this->http_www_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2118 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2119 | base::BindRepeating( |
| 2120 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2121 | base::Unretained(&cookie_changes))); |
| 2122 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2123 | ASSERT_EQ(0u, cookie_changes.size()); |
| 2124 | |
| 2125 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2126 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2127 | EXPECT_EQ(1u, cookie_changes.size()); |
| 2128 | cookie_changes.clear(); |
| 2129 | |
| 2130 | // Replacing an existing cookie is actually a two-phase delete + set |
| 2131 | // operation, so we get an extra notification. |
| 2132 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=ghi")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2133 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2134 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2135 | EXPECT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2136 | EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); |
| 2137 | EXPECT_EQ("def", cookie_changes[0].cookie.Value()); |
| 2138 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 2139 | cookie_changes[0].cookie.Domain()); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2140 | EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2141 | cookie_changes[0].cause)); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2142 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2143 | EXPECT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2144 | EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); |
| 2145 | EXPECT_EQ("ghi", cookie_changes[1].cookie.Value()); |
| 2146 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 2147 | cookie_changes[1].cookie.Domain()); |
| 2148 | EXPECT_TRUE( |
| 2149 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2150 | |
| 2151 | EXPECT_EQ(2u, cookie_changes.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2152 | } |
| 2153 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2154 | TYPED_TEST_P(CookieStoreChangeNamedTest, OverwriteFiltering) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2155 | if (!TypeParam::supports_named_cookie_tracking) |
| 2156 | return; |
| 2157 | |
| 2158 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2159 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2160 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 2161 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2162 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2163 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2164 | base::BindRepeating( |
| 2165 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2166 | base::Unretained(&cookie_changes))); |
| 2167 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2168 | ASSERT_EQ(0u, cookie_changes.size()); |
| 2169 | |
| 2170 | EXPECT_TRUE( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2171 | this->SetCookie(cs, this->http_www_foo_.url(), "xyz=zyx1; path=/")); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2172 | EXPECT_TRUE( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2173 | this->SetCookie(cs, this->http_bar_com_.url(), "abc=def1; path=/")); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2174 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2175 | "abc=hij1; path=/foo/bar")); |
| 2176 | EXPECT_TRUE( |
| 2177 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=mno1; path=/foo")); |
| 2178 | EXPECT_TRUE( |
| 2179 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=pqr1; path=/")); |
| 2180 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), |
| 2181 | "abc=stu1; domain=foo.com")); |
| 2182 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2183 | EXPECT_EQ(3u, cookie_changes.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2184 | cookie_changes.clear(); |
| 2185 | |
| 2186 | // Replacing an existing cookie is actually a two-phase delete + set |
| 2187 | // operation, so we get two notifications per overwrite. |
| 2188 | EXPECT_TRUE( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2189 | this->SetCookie(cs, this->http_www_foo_.url(), "xyz=zyx2; path=/")); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2190 | EXPECT_TRUE( |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2191 | this->SetCookie(cs, this->http_bar_com_.url(), "abc=def2; path=/")); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2192 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2193 | "abc=hij2; path=/foo/bar")); |
| 2194 | EXPECT_TRUE( |
| 2195 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=mno2; path=/foo")); |
| 2196 | EXPECT_TRUE( |
| 2197 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=pqr2; path=/")); |
| 2198 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), |
| 2199 | "abc=stu2; domain=foo.com")); |
| 2200 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2201 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2202 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2203 | EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); |
| 2204 | EXPECT_EQ("mno1", cookie_changes[0].cookie.Value()); |
| 2205 | EXPECT_EQ("/foo", cookie_changes[0].cookie.Path()); |
| 2206 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 2207 | cookie_changes[0].cookie.Domain()); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2208 | EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2209 | cookie_changes[0].cause)); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2210 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2211 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2212 | EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); |
| 2213 | EXPECT_EQ("mno2", cookie_changes[1].cookie.Value()); |
| 2214 | EXPECT_EQ("/foo", cookie_changes[1].cookie.Path()); |
| 2215 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 2216 | cookie_changes[1].cookie.Domain()); |
| 2217 | EXPECT_TRUE( |
| 2218 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2219 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2220 | ASSERT_LE(3u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2221 | EXPECT_EQ("abc", cookie_changes[2].cookie.Name()); |
| 2222 | EXPECT_EQ("pqr1", cookie_changes[2].cookie.Value()); |
| 2223 | EXPECT_EQ("/", cookie_changes[2].cookie.Path()); |
| 2224 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 2225 | cookie_changes[2].cookie.Domain()); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2226 | EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2227 | cookie_changes[2].cause)); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2228 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2229 | ASSERT_LE(4u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2230 | EXPECT_EQ("abc", cookie_changes[3].cookie.Name()); |
| 2231 | EXPECT_EQ("pqr2", cookie_changes[3].cookie.Value()); |
| 2232 | EXPECT_EQ("/", cookie_changes[3].cookie.Path()); |
| 2233 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 2234 | cookie_changes[3].cookie.Domain()); |
| 2235 | EXPECT_TRUE( |
| 2236 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[3].cause)); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2237 | |
| 2238 | ASSERT_LE(5u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2239 | EXPECT_EQ("abc", cookie_changes[4].cookie.Name()); |
| 2240 | EXPECT_EQ("stu1", cookie_changes[4].cookie.Value()); |
| 2241 | EXPECT_EQ("/", cookie_changes[4].cookie.Path()); |
| 2242 | EXPECT_EQ(".foo.com", cookie_changes[4].cookie.Domain()); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2243 | EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2244 | cookie_changes[4].cause)); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2245 | |
| 2246 | ASSERT_LE(6u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2247 | EXPECT_EQ("abc", cookie_changes[5].cookie.Name()); |
| 2248 | EXPECT_EQ("stu2", cookie_changes[5].cookie.Value()); |
| 2249 | EXPECT_EQ("/", cookie_changes[5].cookie.Path()); |
| 2250 | EXPECT_EQ(".foo.com", cookie_changes[5].cookie.Domain()); |
| 2251 | EXPECT_TRUE( |
| 2252 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[5].cause)); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2253 | |
| 2254 | EXPECT_EQ(6u, cookie_changes.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2255 | } |
| 2256 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2257 | TYPED_TEST_P(CookieStoreChangeNamedTest, OverwriteWithHttpOnly) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2258 | if (!TypeParam::supports_named_cookie_tracking) |
| 2259 | return; |
| 2260 | |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 2261 | // Insert a cookie "abc" for path "/foo". |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2262 | CookieStore* cs = this->GetCookieStore(); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2263 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2264 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 2265 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2266 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2267 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2268 | base::BindRepeating( |
| 2269 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2270 | base::Unretained(&cookie_changes))); |
| 2271 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2272 | ASSERT_EQ(0u, cookie_changes.size()); |
| 2273 | |
| 2274 | EXPECT_TRUE( |
| 2275 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=def; path=/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2276 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2277 | ASSERT_EQ(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2278 | EXPECT_TRUE( |
| 2279 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause)); |
| 2280 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 2281 | cookie_changes[0].cookie.Domain()); |
| 2282 | EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); |
| 2283 | EXPECT_EQ("def", cookie_changes[0].cookie.Value()); |
| 2284 | EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2285 | cookie_changes.clear(); |
| 2286 | |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 2287 | // Insert a cookie "a" for path "/foo", that is httponly. This should |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2288 | // overwrite the non-http-only version. |
| 2289 | CookieOptions allow_httponly; |
| 2290 | allow_httponly.set_include_httponly(); |
Maks Orlovich | 21845bc | 2019-10-21 22:02:23 | [diff] [blame] | 2291 | allow_httponly.set_same_site_cookie_context( |
Steven Bingler | 8d76c2a4 | 2020-03-24 17:13:32 | [diff] [blame] | 2292 | net::CookieOptions::SameSiteCookieContext::MakeInclusive()); |
Maks Orlovich | 21845bc | 2019-10-21 22:02:23 | [diff] [blame] | 2293 | |
Lily Chen | 0f208ea | 2019-08-08 23:37:53 | [diff] [blame] | 2294 | EXPECT_TRUE(this->CreateAndSetCookie(cs, this->http_www_foo_.url(), |
| 2295 | "abc=hij; path=/foo; httponly", |
| 2296 | allow_httponly)); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2297 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2298 | |
| 2299 | ASSERT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2300 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 2301 | cookie_changes[0].cookie.Domain()); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2302 | EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2303 | cookie_changes[0].cause)); |
| 2304 | EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); |
| 2305 | EXPECT_EQ("def", cookie_changes[0].cookie.Value()); |
| 2306 | EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2307 | |
| 2308 | ASSERT_LE(2u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2309 | EXPECT_EQ(this->http_www_foo_.url().host(), |
| 2310 | cookie_changes[1].cookie.Domain()); |
| 2311 | EXPECT_TRUE( |
| 2312 | this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause)); |
| 2313 | EXPECT_EQ("abc", cookie_changes[1].cookie.Name()); |
| 2314 | EXPECT_EQ("hij", cookie_changes[1].cookie.Value()); |
| 2315 | EXPECT_TRUE(cookie_changes[1].cookie.IsHttpOnly()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2316 | |
| 2317 | EXPECT_EQ(2u, cookie_changes.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2318 | } |
| 2319 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2320 | TYPED_TEST_P(CookieStoreChangeNamedTest, Deregister) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2321 | if (!TypeParam::supports_named_cookie_tracking) |
| 2322 | return; |
| 2323 | |
| 2324 | CookieStore* cs = this->GetCookieStore(); |
| 2325 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2326 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2327 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 2328 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2329 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2330 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2331 | base::BindRepeating( |
| 2332 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2333 | base::Unretained(&cookie_changes))); |
| 2334 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2335 | ASSERT_EQ(0u, cookie_changes.size()); |
| 2336 | |
| 2337 | // Insert a cookie and make sure it is seen. |
| 2338 | EXPECT_TRUE( |
| 2339 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=def; path=/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2340 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2341 | ASSERT_EQ(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2342 | EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); |
| 2343 | EXPECT_EQ("def", cookie_changes[0].cookie.Value()); |
| 2344 | EXPECT_EQ("/foo", cookie_changes[0].cookie.Path()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2345 | cookie_changes.clear(); |
| 2346 | |
| 2347 | // De-register the subscription. |
| 2348 | subscription.reset(); |
| 2349 | |
| 2350 | // Insert a second cookie and make sure it's not visible. |
| 2351 | EXPECT_TRUE( |
| 2352 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=hij; path=/")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2353 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2354 | |
| 2355 | EXPECT_EQ(0u, cookie_changes.size()); |
| 2356 | } |
| 2357 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2358 | TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterMultiple) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2359 | if (!TypeParam::supports_named_cookie_tracking || |
| 2360 | !TypeParam::supports_multiple_tracking_callbacks) |
| 2361 | return; |
| 2362 | |
| 2363 | CookieStore* cs = this->GetCookieStore(); |
| 2364 | |
| 2365 | // Register two subscriptions. |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2366 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2367 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 2368 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2369 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2370 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2371 | base::BindRepeating( |
| 2372 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2373 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2374 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 2375 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2376 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2377 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2378 | base::BindRepeating( |
| 2379 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2380 | base::Unretained(&cookie_changes_2))); |
| 2381 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2382 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 2383 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 2384 | |
| 2385 | // Insert a cookie and make sure it's seen. |
| 2386 | EXPECT_TRUE( |
| 2387 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=def; path=/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2388 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2389 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2390 | EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); |
| 2391 | EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); |
| 2392 | EXPECT_EQ("/foo", cookie_changes_1[0].cookie.Path()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2393 | cookie_changes_1.clear(); |
| 2394 | |
| 2395 | ASSERT_EQ(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2396 | EXPECT_EQ("abc", cookie_changes_2[0].cookie.Name()); |
| 2397 | EXPECT_EQ("def", cookie_changes_2[0].cookie.Value()); |
| 2398 | EXPECT_EQ("/foo", cookie_changes_2[0].cookie.Path()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2399 | cookie_changes_2.clear(); |
| 2400 | |
| 2401 | // De-register the second registration. |
| 2402 | subscription2.reset(); |
| 2403 | |
| 2404 | // Insert a second cookie and make sure that it's only visible in one |
| 2405 | // change array. |
| 2406 | EXPECT_TRUE( |
| 2407 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=hij; path=/")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2408 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2409 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2410 | EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); |
| 2411 | EXPECT_EQ("hij", cookie_changes_1[0].cookie.Value()); |
| 2412 | EXPECT_EQ("/", cookie_changes_1[0].cookie.Path()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2413 | |
| 2414 | EXPECT_EQ(0u, cookie_changes_2.size()); |
| 2415 | } |
| 2416 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2417 | // Confirm that a listener does not receive notifications for changes that |
| 2418 | // happened right before the subscription was established. |
| 2419 | TYPED_TEST_P(CookieStoreChangeNamedTest, DispatchRace) { |
| 2420 | if (!TypeParam::supports_named_cookie_tracking) |
| 2421 | return; |
| 2422 | |
| 2423 | CookieStore* cs = this->GetCookieStore(); |
| 2424 | |
| 2425 | // This cookie insertion should not be seen. |
| 2426 | EXPECT_TRUE( |
| 2427 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=def; path=/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2428 | // DeliverChangeNotifications() must NOT be called before the subscription is |
| 2429 | // established. |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2430 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2431 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2432 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 2433 | cs->GetChangeDispatcher().AddCallbackForCookie( |
| 2434 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2435 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2436 | base::BindRepeating( |
| 2437 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2438 | base::Unretained(&cookie_changes))); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2439 | |
| 2440 | EXPECT_TRUE( |
| 2441 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=hij; path=/")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2442 | this->DeliverChangeNotifications(); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2443 | |
| 2444 | EXPECT_LE(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2445 | EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); |
| 2446 | EXPECT_EQ("hij", cookie_changes[0].cookie.Value()); |
| 2447 | EXPECT_EQ("/", cookie_changes[0].cookie.Path()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2448 | |
| 2449 | ASSERT_EQ(1u, cookie_changes.size()); |
| 2450 | } |
| 2451 | |
| 2452 | // Confirm that deregistering a subscription blocks the notification if the |
| 2453 | // deregistration happened after the change but before the notification was |
| 2454 | // received. |
| 2455 | TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterRace) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2456 | if (!TypeParam::supports_named_cookie_tracking) |
| 2457 | return; |
| 2458 | |
| 2459 | CookieStore* cs = this->GetCookieStore(); |
| 2460 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2461 | std::vector<CookieChangeInfo> cookie_changes; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2462 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 2463 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2464 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2465 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2466 | base::BindRepeating( |
| 2467 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2468 | base::Unretained(&cookie_changes))); |
| 2469 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2470 | ASSERT_EQ(0u, cookie_changes.size()); |
| 2471 | |
| 2472 | // Insert a cookie and make sure it's seen. |
| 2473 | EXPECT_TRUE( |
| 2474 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=def; path=/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2475 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2476 | ASSERT_EQ(1u, cookie_changes.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2477 | EXPECT_EQ("abc", cookie_changes[0].cookie.Name()); |
| 2478 | EXPECT_EQ("def", cookie_changes[0].cookie.Value()); |
| 2479 | EXPECT_EQ("/foo", cookie_changes[0].cookie.Path()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2480 | cookie_changes.clear(); |
| 2481 | |
| 2482 | // Insert a cookie, confirm it is not seen, deregister the subscription, run |
| 2483 | // until idle, and confirm the cookie is still not seen. |
| 2484 | EXPECT_TRUE( |
| 2485 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=hij; path=/")); |
| 2486 | |
| 2487 | // Note that by the API contract it's perfectly valid to have received the |
| 2488 | // notification immediately, i.e. synchronously with the cookie change. In |
| 2489 | // that case, there's nothing to test. |
| 2490 | if (1u == cookie_changes.size()) |
| 2491 | return; |
| 2492 | |
| 2493 | // A task was posted by the SetCookie() above, but has not yet arrived. If it |
| 2494 | // arrived before the subscription is destroyed, callback execution would be |
| 2495 | // valid. Destroy the subscription so as to lose the race and make sure the |
| 2496 | // task posted arrives after the subscription was destroyed. |
| 2497 | subscription.reset(); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2498 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2499 | ASSERT_EQ(0u, cookie_changes.size()); |
| 2500 | } |
| 2501 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2502 | TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterRaceMultiple) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2503 | if (!TypeParam::supports_named_cookie_tracking || |
| 2504 | !TypeParam::supports_multiple_tracking_callbacks) |
| 2505 | return; |
| 2506 | |
| 2507 | CookieStore* cs = this->GetCookieStore(); |
| 2508 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2509 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2510 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 2511 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2512 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2513 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2514 | base::BindRepeating( |
| 2515 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2516 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2517 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 2518 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2519 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2520 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2521 | base::BindRepeating( |
| 2522 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2523 | base::Unretained(&cookie_changes_2))); |
| 2524 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2525 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 2526 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 2527 | |
| 2528 | // Insert a cookie and make sure it's seen. |
| 2529 | EXPECT_TRUE( |
| 2530 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=def; path=/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2531 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2532 | |
| 2533 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2534 | EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); |
| 2535 | EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); |
| 2536 | EXPECT_EQ("/foo", cookie_changes_1[0].cookie.Path()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2537 | cookie_changes_1.clear(); |
| 2538 | |
| 2539 | ASSERT_EQ(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2540 | EXPECT_EQ("abc", cookie_changes_2[0].cookie.Name()); |
| 2541 | EXPECT_EQ("def", cookie_changes_2[0].cookie.Value()); |
| 2542 | EXPECT_EQ("/foo", cookie_changes_2[0].cookie.Path()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2543 | cookie_changes_2.clear(); |
| 2544 | |
| 2545 | // Insert a cookie, confirm it is not seen, deregister a subscription, run |
| 2546 | // until idle, and confirm the cookie is still not seen. |
| 2547 | EXPECT_TRUE( |
| 2548 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=hij; path=/")); |
| 2549 | |
| 2550 | // Note that by the API contract it's perfectly valid to have received the |
| 2551 | // notification immediately, i.e. synchronously with the cookie change. In |
| 2552 | // that case, there's nothing to test. |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2553 | if (1u == cookie_changes_2.size()) |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2554 | return; |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2555 | |
| 2556 | // A task was posted by the SetCookie() above, but has not yet arrived. If it |
| 2557 | // arrived before the subscription is destroyed, callback execution would be |
| 2558 | // valid. Destroy one of the subscriptions so as to lose the race and make |
| 2559 | // sure the task posted arrives after the subscription was destroyed. |
| 2560 | subscription2.reset(); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2561 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2562 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2563 | EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); |
| 2564 | EXPECT_EQ("hij", cookie_changes_1[0].cookie.Value()); |
| 2565 | EXPECT_EQ("/", cookie_changes_1[0].cookie.Path()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2566 | |
| 2567 | // No late notification was received. |
| 2568 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 2569 | } |
| 2570 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2571 | TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsDisjoint) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2572 | if (!TypeParam::supports_named_cookie_tracking) |
| 2573 | return; |
| 2574 | |
| 2575 | CookieStore* cs = this->GetCookieStore(); |
| 2576 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2577 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2578 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 2579 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2580 | this->http_www_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2581 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2582 | base::BindRepeating( |
| 2583 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2584 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2585 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 2586 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2587 | this->http_bar_com_.url(), "ghi", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2588 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2589 | base::BindRepeating( |
| 2590 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2591 | base::Unretained(&cookie_changes_2))); |
| 2592 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2593 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 2594 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 2595 | |
| 2596 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2597 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2598 | EXPECT_EQ(1u, cookie_changes_1.size()); |
| 2599 | EXPECT_EQ(0u, cookie_changes_2.size()); |
| 2600 | |
| 2601 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "ghi=jkl")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2602 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2603 | |
| 2604 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2605 | EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); |
| 2606 | EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2607 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2608 | cookie_changes_1[0].cookie.Domain()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2609 | |
| 2610 | ASSERT_EQ(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2611 | EXPECT_EQ("ghi", cookie_changes_2[0].cookie.Name()); |
| 2612 | EXPECT_EQ("jkl", cookie_changes_2[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2613 | EXPECT_EQ(this->http_bar_com_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2614 | cookie_changes_2[0].cookie.Domain()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2615 | } |
| 2616 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2617 | TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsDomains) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2618 | if (!TypeParam::supports_named_cookie_tracking) |
| 2619 | return; |
| 2620 | |
| 2621 | CookieStore* cs = this->GetCookieStore(); |
| 2622 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2623 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2624 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 2625 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2626 | this->http_www_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2627 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2628 | base::BindRepeating( |
| 2629 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2630 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2631 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 2632 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2633 | this->http_bar_com_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2634 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2635 | base::BindRepeating( |
| 2636 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2637 | base::Unretained(&cookie_changes_2))); |
| 2638 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2639 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 2640 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 2641 | |
| 2642 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2643 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2644 | EXPECT_EQ(1u, cookie_changes_1.size()); |
| 2645 | EXPECT_EQ(0u, cookie_changes_2.size()); |
| 2646 | |
| 2647 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "abc=ghi")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2648 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2649 | |
| 2650 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2651 | EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); |
| 2652 | EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2653 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2654 | cookie_changes_1[0].cookie.Domain()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2655 | |
| 2656 | ASSERT_EQ(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2657 | EXPECT_EQ("abc", cookie_changes_2[0].cookie.Name()); |
| 2658 | EXPECT_EQ("ghi", cookie_changes_2[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2659 | EXPECT_EQ(this->http_bar_com_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2660 | cookie_changes_2[0].cookie.Domain()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2661 | } |
| 2662 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2663 | TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsNames) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2664 | if (!TypeParam::supports_named_cookie_tracking) |
| 2665 | return; |
| 2666 | |
| 2667 | CookieStore* cs = this->GetCookieStore(); |
| 2668 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2669 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2670 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 2671 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2672 | this->http_www_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2673 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2674 | base::BindRepeating( |
| 2675 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2676 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2677 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 2678 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2679 | this->http_www_foo_.url(), "ghi", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2680 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2681 | base::BindRepeating( |
| 2682 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2683 | base::Unretained(&cookie_changes_2))); |
| 2684 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2685 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 2686 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 2687 | |
| 2688 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2689 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2690 | EXPECT_EQ(1u, cookie_changes_1.size()); |
| 2691 | EXPECT_EQ(0u, cookie_changes_2.size()); |
| 2692 | |
| 2693 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "ghi=jkl")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2694 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2695 | |
| 2696 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2697 | EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); |
| 2698 | EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2699 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2700 | cookie_changes_1[0].cookie.Domain()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2701 | |
| 2702 | ASSERT_EQ(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2703 | EXPECT_EQ("ghi", cookie_changes_2[0].cookie.Name()); |
| 2704 | EXPECT_EQ("jkl", cookie_changes_2[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2705 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2706 | cookie_changes_2[0].cookie.Domain()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2707 | } |
| 2708 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2709 | TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsPaths) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2710 | if (!TypeParam::supports_named_cookie_tracking) |
| 2711 | return; |
| 2712 | |
| 2713 | CookieStore* cs = this->GetCookieStore(); |
| 2714 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2715 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2716 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 2717 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2718 | this->http_www_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2719 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2720 | base::BindRepeating( |
| 2721 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2722 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2723 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 2724 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2725 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2726 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2727 | base::BindRepeating( |
| 2728 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2729 | base::Unretained(&cookie_changes_2))); |
| 2730 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2731 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 2732 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 2733 | |
| 2734 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2735 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2736 | EXPECT_EQ(1u, cookie_changes_1.size()); |
| 2737 | EXPECT_EQ(1u, cookie_changes_2.size()); |
| 2738 | |
| 2739 | EXPECT_TRUE( |
| 2740 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=ghi; path=/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2741 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2742 | |
| 2743 | ASSERT_EQ(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2744 | EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); |
| 2745 | EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); |
| 2746 | EXPECT_EQ("/", cookie_changes_1[0].cookie.Path()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2747 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2748 | cookie_changes_1[0].cookie.Domain()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2749 | |
| 2750 | ASSERT_LE(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2751 | EXPECT_EQ("abc", cookie_changes_2[0].cookie.Name()); |
| 2752 | EXPECT_EQ("def", cookie_changes_2[0].cookie.Value()); |
| 2753 | EXPECT_EQ("/", cookie_changes_2[0].cookie.Path()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2754 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2755 | cookie_changes_2[0].cookie.Domain()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2756 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2757 | ASSERT_LE(2u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2758 | EXPECT_EQ("abc", cookie_changes_2[1].cookie.Name()); |
| 2759 | EXPECT_EQ("ghi", cookie_changes_2[1].cookie.Value()); |
| 2760 | EXPECT_EQ("/foo", cookie_changes_2[1].cookie.Path()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2761 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2762 | cookie_changes_2[1].cookie.Domain()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2763 | |
| 2764 | EXPECT_EQ(2u, cookie_changes_2.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2765 | } |
| 2766 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2767 | TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsFiltering) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2768 | if (!TypeParam::supports_named_cookie_tracking) |
| 2769 | return; |
| 2770 | |
| 2771 | CookieStore* cs = this->GetCookieStore(); |
| 2772 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2773 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
| 2774 | std::vector<CookieChangeInfo> cookie_changes_3, cookie_changes_4; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2775 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 2776 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2777 | this->http_www_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2778 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2779 | base::BindRepeating( |
| 2780 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2781 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2782 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 2783 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2784 | this->http_www_foo_.url(), "hij", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2785 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2786 | base::BindRepeating( |
| 2787 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2788 | base::Unretained(&cookie_changes_2))); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2789 | std::unique_ptr<CookieChangeSubscription> subscription3 = |
| 2790 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2791 | this->http_bar_com_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2792 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2793 | base::BindRepeating( |
| 2794 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2795 | base::Unretained(&cookie_changes_3))); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2796 | std::unique_ptr<CookieChangeSubscription> subscription4 = |
| 2797 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2798 | this->www_foo_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2799 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2800 | base::BindRepeating( |
| 2801 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2802 | base::Unretained(&cookie_changes_4))); |
| 2803 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2804 | ASSERT_EQ(0u, cookie_changes_1.size()); |
| 2805 | ASSERT_EQ(0u, cookie_changes_2.size()); |
| 2806 | EXPECT_EQ(0u, cookie_changes_3.size()); |
| 2807 | EXPECT_EQ(0u, cookie_changes_4.size()); |
| 2808 | |
| 2809 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2810 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2811 | EXPECT_EQ(1u, cookie_changes_1.size()); |
| 2812 | EXPECT_EQ(0u, cookie_changes_2.size()); |
| 2813 | EXPECT_EQ(0u, cookie_changes_3.size()); |
| 2814 | EXPECT_EQ(1u, cookie_changes_4.size()); |
| 2815 | |
| 2816 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "xyz=zyx")); |
| 2817 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "hij=mno")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2818 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2819 | EXPECT_EQ(1u, cookie_changes_1.size()); |
| 2820 | EXPECT_EQ(1u, cookie_changes_2.size()); |
| 2821 | EXPECT_EQ(0u, cookie_changes_3.size()); |
| 2822 | EXPECT_EQ(1u, cookie_changes_4.size()); |
| 2823 | |
| 2824 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "hij=pqr")); |
| 2825 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "xyz=zyx")); |
| 2826 | EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "abc=stu")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2827 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2828 | EXPECT_EQ(1u, cookie_changes_1.size()); |
| 2829 | EXPECT_EQ(1u, cookie_changes_2.size()); |
| 2830 | EXPECT_EQ(1u, cookie_changes_3.size()); |
| 2831 | EXPECT_EQ(1u, cookie_changes_4.size()); |
| 2832 | |
| 2833 | EXPECT_TRUE( |
| 2834 | this->SetCookie(cs, this->http_www_foo_.url(), "abc=vwx; path=/foo")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2835 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2836 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2837 | ASSERT_LE(1u, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2838 | EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); |
| 2839 | EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2840 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2841 | cookie_changes_1[0].cookie.Domain()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2842 | EXPECT_EQ(1u, cookie_changes_1.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2843 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2844 | ASSERT_LE(1u, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2845 | EXPECT_EQ("hij", cookie_changes_2[0].cookie.Name()); |
| 2846 | EXPECT_EQ("mno", cookie_changes_2[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2847 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2848 | cookie_changes_2[0].cookie.Domain()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2849 | EXPECT_EQ(1u, cookie_changes_2.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2850 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2851 | ASSERT_LE(1u, cookie_changes_3.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2852 | EXPECT_EQ("abc", cookie_changes_3[0].cookie.Name()); |
| 2853 | EXPECT_EQ("stu", cookie_changes_3[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2854 | EXPECT_EQ(this->http_bar_com_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2855 | cookie_changes_3[0].cookie.Domain()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2856 | EXPECT_EQ(1u, cookie_changes_3.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2857 | |
| 2858 | ASSERT_LE(1u, cookie_changes_4.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2859 | EXPECT_EQ("abc", cookie_changes_4[0].cookie.Name()); |
| 2860 | EXPECT_EQ("def", cookie_changes_4[0].cookie.Value()); |
| 2861 | EXPECT_EQ("/", cookie_changes_4[0].cookie.Path()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2862 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2863 | cookie_changes_4[0].cookie.Domain()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2864 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2865 | ASSERT_LE(2u, cookie_changes_4.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2866 | EXPECT_EQ("abc", cookie_changes_4[1].cookie.Name()); |
| 2867 | EXPECT_EQ("vwx", cookie_changes_4[1].cookie.Value()); |
| 2868 | EXPECT_EQ("/foo", cookie_changes_4[1].cookie.Path()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2869 | EXPECT_EQ(this->http_www_foo_.url().host(), |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2870 | cookie_changes_4[1].cookie.Domain()); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2871 | |
| 2872 | EXPECT_EQ(2u, cookie_changes_4.size()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2873 | } |
| 2874 | |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 2875 | TYPED_TEST_P(CookieStoreChangeNamedTest, MultipleSubscriptions) { |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2876 | if (!TypeParam::supports_named_cookie_tracking || |
| 2877 | !TypeParam::supports_multiple_tracking_callbacks) |
| 2878 | return; |
| 2879 | |
| 2880 | CookieStore* cs = this->GetCookieStore(); |
| 2881 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2882 | std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2; |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2883 | std::unique_ptr<CookieChangeSubscription> subscription1 = |
| 2884 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2885 | this->http_www_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2886 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2887 | base::BindRepeating( |
| 2888 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2889 | base::Unretained(&cookie_changes_1))); |
Victor Costan | 14f47c1 | 2018-03-01 08:02:24 | [diff] [blame] | 2890 | std::unique_ptr<CookieChangeSubscription> subscription2 = |
| 2891 | cs->GetChangeDispatcher().AddCallbackForCookie( |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2892 | this->http_www_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2893 | absl::nullopt /* cookie_partition_key */, |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2894 | base::BindRepeating( |
| 2895 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2896 | base::Unretained(&cookie_changes_2))); |
| 2897 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2898 | |
| 2899 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "xyz=zyx")); |
| 2900 | EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def")); |
Victor Costan | 1dcd675 | 2018-03-16 12:31:36 | [diff] [blame] | 2901 | this->DeliverChangeNotifications(); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2902 | |
| 2903 | ASSERT_EQ(1U, cookie_changes_1.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2904 | EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name()); |
| 2905 | EXPECT_EQ("def", cookie_changes_1[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2906 | cookie_changes_1.clear(); |
| 2907 | |
| 2908 | ASSERT_EQ(1U, cookie_changes_2.size()); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2909 | EXPECT_EQ("abc", cookie_changes_2[0].cookie.Name()); |
| 2910 | EXPECT_EQ("def", cookie_changes_2[0].cookie.Value()); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 2911 | cookie_changes_2.clear(); |
| 2912 | } |
| 2913 | |
Sergey Kuznetsov | 0edf161 | 2018-10-12 14:29:05 | [diff] [blame] | 2914 | TYPED_TEST_P(CookieStoreChangeNamedTest, SubscriptionOutlivesStore) { |
| 2915 | if (!TypeParam::supports_named_cookie_tracking) |
| 2916 | return; |
| 2917 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2918 | std::vector<CookieChangeInfo> cookie_changes; |
Sergey Kuznetsov | 0edf161 | 2018-10-12 14:29:05 | [diff] [blame] | 2919 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 2920 | this->GetCookieStore()->GetChangeDispatcher().AddCallbackForCookie( |
| 2921 | this->http_www_foo_.url(), "abc", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2922 | absl::nullopt /* cookie_partition_key */, |
Sergey Kuznetsov | 0edf161 | 2018-10-12 14:29:05 | [diff] [blame] | 2923 | base::BindRepeating( |
| 2924 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2925 | base::Unretained(&cookie_changes))); |
| 2926 | this->ResetCookieStore(); |
| 2927 | |
| 2928 | // |subscription| outlives cookie_store - crash should not happen. |
| 2929 | subscription.reset(); |
| 2930 | } |
| 2931 | |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2932 | TYPED_TEST_P(CookieStoreChangeNamedTest, ChangeIncludesCookieAccessSemantics) { |
| 2933 | if (!TypeParam::supports_named_cookie_tracking) |
| 2934 | return; |
| 2935 | |
| 2936 | CookieStore* cs = this->GetCookieStore(); |
| 2937 | // if !supports_cookie_access_semantics, the delegate will be stored but will |
| 2938 | // not be used. |
| 2939 | auto access_delegate = std::make_unique<TestCookieAccessDelegate>(); |
| 2940 | access_delegate->SetExpectationForCookieDomain("domain1.test", |
| 2941 | CookieAccessSemantics::LEGACY); |
| 2942 | cs->SetCookieAccessDelegate(std::move(access_delegate)); |
| 2943 | |
| 2944 | std::vector<CookieChangeInfo> cookie_changes; |
| 2945 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 2946 | cs->GetChangeDispatcher().AddCallbackForCookie( |
| 2947 | GURL("http://domain1.test"), "cookie", |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2948 | absl::nullopt /* cookie_partition_key */, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2949 | base::BindRepeating( |
| 2950 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2951 | base::Unretained(&cookie_changes))); |
| 2952 | |
| 2953 | this->CreateAndSetCookie(cs, GURL("http://domain1.test"), "cookie=1", |
| 2954 | CookieOptions::MakeAllInclusive()); |
| 2955 | this->DeliverChangeNotifications(); |
| 2956 | |
| 2957 | ASSERT_EQ(1u, cookie_changes.size()); |
| 2958 | EXPECT_EQ("domain1.test", cookie_changes[0].cookie.Domain()); |
| 2959 | EXPECT_EQ("cookie", cookie_changes[0].cookie.Name()); |
| 2960 | EXPECT_TRUE(this->IsExpectedAccessSemantics( |
Ayu Ishii | 9f5e72dc | 2020-07-22 19:43:18 | [diff] [blame] | 2961 | CookieAccessSemantics::LEGACY, |
| 2962 | cookie_changes[0].access_result.access_semantics)); |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 2963 | } |
| 2964 | |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2965 | TYPED_TEST_P(CookieStoreChangeNamedTest, PartitionedCookies) { |
| 2966 | if (!TypeParam::supports_named_cookie_tracking || |
| 2967 | !TypeParam::supports_partitioned_cookies) |
| 2968 | return; |
| 2969 | |
| 2970 | CookieStore* cs = this->GetCookieStore(); |
| 2971 | std::vector<CookieChangeInfo> cookie_changes; |
| 2972 | std::unique_ptr<CookieChangeSubscription> subscription = |
| 2973 | cs->GetChangeDispatcher().AddCallbackForCookie( |
| 2974 | GURL("https://www.example.com"), "__Host-a", |
Dylan Cutler | 6ac1c67a8 | 2022-03-31 11:36:16 | [diff] [blame] | 2975 | CookiePartitionKey::FromURLForTesting(GURL("https://www.foo.com")), |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 2976 | base::BindRepeating( |
| 2977 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 2978 | base::Unretained(&cookie_changes))); |
| 2979 | |
| 2980 | // Unpartitioned cookie |
| 2981 | this->CreateAndSetCookie(cs, GURL("https://www.example.com"), |
| 2982 | "__Host-a=1; Secure; Path=/", |
| 2983 | CookieOptions::MakeAllInclusive()); |
| 2984 | // Partitioned cookie with the same partition key |
| 2985 | this->CreateAndSetCookie( |
| 2986 | cs, GURL("https://www.example.com"), |
| 2987 | "__Host-a=2; Secure; Path=/; Partitioned", |
| 2988 | CookieOptions::MakeAllInclusive(), absl::nullopt /* server_time */, |
| 2989 | absl::nullopt /* system_time */, |
| 2990 | absl::make_optional( |
| 2991 | CookiePartitionKey::FromURLForTesting(GURL("https://sub.foo.com")))); |
| 2992 | // Partitioned cookie with a different partition key |
| 2993 | this->CreateAndSetCookie( |
| 2994 | cs, GURL("https://www.example.com"), |
| 2995 | "__Host-a=3; Secure; Path=/; Partitioned", |
| 2996 | CookieOptions::MakeAllInclusive(), absl::nullopt /* server_time */, |
| 2997 | absl::nullopt /* system_time */, |
| 2998 | absl::make_optional( |
| 2999 | CookiePartitionKey::FromURLForTesting(GURL("https://www.bar.com")))); |
| 3000 | this->DeliverChangeNotifications(); |
| 3001 | |
| 3002 | ASSERT_EQ(2u, cookie_changes.size()); |
| 3003 | EXPECT_FALSE(cookie_changes[0].cookie.IsPartitioned()); |
| 3004 | EXPECT_EQ("1", cookie_changes[0].cookie.Value()); |
| 3005 | EXPECT_TRUE(cookie_changes[1].cookie.IsPartitioned()); |
| 3006 | EXPECT_EQ(CookiePartitionKey::FromURLForTesting(GURL("https://www.foo.com")), |
| 3007 | cookie_changes[1].cookie.PartitionKey().value()); |
| 3008 | EXPECT_EQ("2", cookie_changes[1].cookie.Value()); |
| 3009 | |
| 3010 | // Test that when the partition key parameter is nullopt that all Partitioned |
| 3011 | // cookies do not emit events. |
| 3012 | std::vector<CookieChangeInfo> other_cookie_changes; |
| 3013 | std::unique_ptr<CookieChangeSubscription> other_subscription = |
| 3014 | cs->GetChangeDispatcher().AddCallbackForCookie( |
| 3015 | GURL("https://www.example.com"), "__Host-a", |
| 3016 | absl::nullopt /* cookie_partition_key */, |
| 3017 | base::BindRepeating( |
| 3018 | &CookieStoreChangeTestBase<TypeParam>::OnCookieChange, |
| 3019 | base::Unretained(&other_cookie_changes))); |
| 3020 | // Update Max-Age: None -> 7200 |
| 3021 | this->CreateAndSetCookie( |
| 3022 | cs, GURL("https://www.example.com"), |
| 3023 | "__Host-a=2; Secure; Path=/; Partitioned; Max-Age=7200", |
| 3024 | CookieOptions::MakeAllInclusive(), absl::nullopt /* server_time */, |
| 3025 | absl::nullopt /* system_time */, |
| 3026 | absl::make_optional( |
| 3027 | CookiePartitionKey::FromURLForTesting(GURL("https://www.foo.com")))); |
| 3028 | this->DeliverChangeNotifications(); |
| 3029 | ASSERT_EQ(0u, other_cookie_changes.size()); |
| 3030 | // Check that the other listener was invoked. |
| 3031 | ASSERT_LT(2u, cookie_changes.size()); |
| 3032 | } |
| 3033 | |
Victor Costan | 2309ea0 | 2019-02-13 21:35:47 | [diff] [blame] | 3034 | REGISTER_TYPED_TEST_SUITE_P(CookieStoreChangeGlobalTest, |
| 3035 | NoCookie, |
| 3036 | InitialCookie, |
| 3037 | InsertOne, |
| 3038 | InsertMany, |
| 3039 | DeleteOne, |
| 3040 | DeleteTwo, |
| 3041 | Overwrite, |
| 3042 | OverwriteWithHttpOnly, |
| 3043 | Deregister, |
| 3044 | DeregisterMultiple, |
| 3045 | DispatchRace, |
| 3046 | DeregisterRace, |
| 3047 | DeregisterRaceMultiple, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 3048 | MultipleSubscriptions, |
| 3049 | ChangeIncludesCookieAccessSemantics); |
Victor Costan | ed602f5 | 2018-03-01 22:48:53 | [diff] [blame] | 3050 | |
Victor Costan | 2309ea0 | 2019-02-13 21:35:47 | [diff] [blame] | 3051 | REGISTER_TYPED_TEST_SUITE_P(CookieStoreChangeUrlTest, |
| 3052 | NoCookie, |
| 3053 | InitialCookie, |
| 3054 | InsertOne, |
| 3055 | InsertMany, |
| 3056 | InsertFiltering, |
| 3057 | DeleteOne, |
| 3058 | DeleteTwo, |
| 3059 | DeleteFiltering, |
| 3060 | Overwrite, |
| 3061 | OverwriteFiltering, |
| 3062 | OverwriteWithHttpOnly, |
| 3063 | Deregister, |
| 3064 | DeregisterMultiple, |
| 3065 | DispatchRace, |
| 3066 | DeregisterRace, |
| 3067 | DeregisterRaceMultiple, |
| 3068 | DifferentSubscriptionsDisjoint, |
| 3069 | DifferentSubscriptionsDomains, |
| 3070 | DifferentSubscriptionsPaths, |
| 3071 | DifferentSubscriptionsFiltering, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 3072 | MultipleSubscriptions, |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 3073 | ChangeIncludesCookieAccessSemantics, |
| 3074 | PartitionedCookies); |
Victor Costan | 2a189167 | 2018-03-02 06:01:53 | [diff] [blame] | 3075 | |
Victor Costan | 2309ea0 | 2019-02-13 21:35:47 | [diff] [blame] | 3076 | REGISTER_TYPED_TEST_SUITE_P(CookieStoreChangeNamedTest, |
| 3077 | NoCookie, |
| 3078 | InitialCookie, |
| 3079 | InsertOne, |
| 3080 | InsertTwo, |
| 3081 | InsertFiltering, |
| 3082 | DeleteOne, |
| 3083 | DeleteTwo, |
| 3084 | DeleteFiltering, |
| 3085 | Overwrite, |
| 3086 | OverwriteFiltering, |
| 3087 | OverwriteWithHttpOnly, |
| 3088 | Deregister, |
| 3089 | DeregisterMultiple, |
| 3090 | DispatchRace, |
| 3091 | DeregisterRace, |
| 3092 | DeregisterRaceMultiple, |
| 3093 | DifferentSubscriptionsDisjoint, |
| 3094 | DifferentSubscriptionsDomains, |
| 3095 | DifferentSubscriptionsNames, |
| 3096 | DifferentSubscriptionsPaths, |
| 3097 | DifferentSubscriptionsFiltering, |
| 3098 | MultipleSubscriptions, |
Lily Chen | 19cced42 | 2019-10-17 21:45:55 | [diff] [blame] | 3099 | SubscriptionOutlivesStore, |
Dylan Cutler | 7f12154 | 2021-09-28 20:41:48 | [diff] [blame] | 3100 | ChangeIncludesCookieAccessSemantics, |
| 3101 | PartitionedCookies); |
Victor Costan | f8cb27d | 2018-02-21 09:16:23 | [diff] [blame] | 3102 | |
| 3103 | } // namespace net |
| 3104 | |
Lei Zhang | 6436192 | 2021-04-21 19:43:39 | [diff] [blame] | 3105 | #endif // NET_COOKIES_COOKIE_STORE_CHANGE_UNITTEST_H_ |