blob: 3106ab5b054c8d91fb3aa22c4440c29110d2620a [file] [log] [blame]
Victor Costanf8cb27d2018-02-21 09:16:231// 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 Zhang64361922021-04-21 19:43:395#ifndef NET_COOKIES_COOKIE_STORE_CHANGE_UNITTEST_H_
6#define NET_COOKIES_COOKIE_STORE_CHANGE_UNITTEST_H_
Victor Costanf8cb27d2018-02-21 09:16:237
8#include "base/bind.h"
9#include "net/cookies/canonical_cookie.h"
Victor Costan1dcd6752018-03-16 12:31:3610#include "net/cookies/cookie_change_dispatcher_test_helpers.h"
Lily Chen19cced422019-10-17 21:45:5511#include "net/cookies/cookie_constants.h"
Victor Costanf8cb27d2018-02-21 09:16:2312#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
17namespace net {
18
Victor Costanf8cb27d2018-02-21 09:16:2319namespace {
20
Victor Costan1dcd6752018-03-16 12:31:3621// 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 Chen19cced422019-10-17 21:45:5527bool 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 Costan1dcd6752018-03-16 12:31:3631
Lily Chen19cced422019-10-17 21:45:5532 if (lhs.cookie.Value() != rhs.cookie.Value())
33 return lhs.cookie.Value() < rhs.cookie.Value();
Victor Costan1dcd6752018-03-16 12:31:3634
Lily Chen19cced422019-10-17 21:45:5535 if (lhs.cookie.Domain() != rhs.cookie.Domain())
36 return lhs.cookie.Domain() < rhs.cookie.Domain();
Victor Costan1dcd6752018-03-16 12:31:3637
Lily Chen19cced422019-10-17 21:45:5538 return lhs.cause < rhs.cause;
Victor Costanf8cb27d2018-02-21 09:16:2339}
40
41} // namespace
42
Victor Costaned602f52018-03-01 22:48:5343// Google Test supports at most 50 tests per typed case, so the tests here are
44// broken up into multiple cases.
45template <class CookieStoreTestTraits>
46class CookieStoreChangeTestBase
47 : public CookieStoreTest<CookieStoreTestTraits> {
48 protected:
49 using CookieStoreTest<CookieStoreTestTraits>::FindAndDeleteCookie;
50
Victor Costan1dcd6752018-03-16 12:31:3651 // Drains all pending tasks on the run loop(s) involved in the test.
52 void DeliverChangeNotifications() {
53 CookieStoreTestTraits::DeliverChangeNotifications();
54 }
55
Victor Costaned602f52018-03-01 22:48:5356 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 Costan1dcd6752018-03-16 12:31:3669
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 Chen19cced422019-10-17 21:45:5586 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 Costan1dcd6752018-03-16 12:31:3692
Lily Chen19cced422019-10-17 21:45:5593 static void OnCookieChange(std::vector<CookieChangeInfo>* changes,
94 const CookieChangeInfo& notification) {
Victor Costan1dcd6752018-03-16 12:31:3695 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 Costaned602f52018-03-01 22:48:53105};
106
107template <class CookieStoreTestTraits>
108class CookieStoreChangeGlobalTest
109 : public CookieStoreChangeTestBase<CookieStoreTestTraits> {};
Victor Costan2309ea02019-02-13 21:35:47110TYPED_TEST_SUITE_P(CookieStoreChangeGlobalTest);
Victor Costaned602f52018-03-01 22:48:53111
112template <class CookieStoreTestTraits>
Victor Costan2a1891672018-03-02 06:01:53113class CookieStoreChangeUrlTest
114 : public CookieStoreChangeTestBase<CookieStoreTestTraits> {};
Victor Costan2309ea02019-02-13 21:35:47115TYPED_TEST_SUITE_P(CookieStoreChangeUrlTest);
Victor Costan2a1891672018-03-02 06:01:53116
117template <class CookieStoreTestTraits>
Victor Costaned602f52018-03-01 22:48:53118class CookieStoreChangeNamedTest
119 : public CookieStoreChangeTestBase<CookieStoreTestTraits> {};
Victor Costan2309ea02019-02-13 21:35:47120TYPED_TEST_SUITE_P(CookieStoreChangeNamedTest);
Victor Costaned602f52018-03-01 22:48:53121
122TYPED_TEST_P(CookieStoreChangeGlobalTest, NoCookie) {
Victor Costanf8cb27d2018-02-21 09:16:23123 if (!TypeParam::supports_global_cookie_tracking)
124 return;
125
126 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55127 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:24128 std::unique_ptr<CookieChangeSubscription> subscription =
129 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36130 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
131 base::Unretained(&cookie_changes)));
132 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23133 EXPECT_EQ(0u, cookie_changes.size());
134}
135
Victor Costaned602f52018-03-01 22:48:53136TYPED_TEST_P(CookieStoreChangeGlobalTest, InitialCookie) {
Victor Costanf8cb27d2018-02-21 09:16:23137 if (!TypeParam::supports_global_cookie_tracking)
138 return;
139
140 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55141 std::vector<CookieChangeInfo> cookie_changes;
Victor Costaned602f52018-03-01 22:48:53142 this->SetCookie(cs, this->http_www_foo_.url(), "A=B");
Victor Costan1dcd6752018-03-16 12:31:36143 this->DeliverChangeNotifications();
Victor Costan14f47c12018-03-01 08:02:24144 std::unique_ptr<CookieChangeSubscription> subscription(
145 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36146 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
147 base::Unretained(&cookie_changes))));
148 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23149 EXPECT_EQ(0u, cookie_changes.size());
150}
151
Victor Costaned602f52018-03-01 22:48:53152TYPED_TEST_P(CookieStoreChangeGlobalTest, InsertOne) {
Victor Costanf8cb27d2018-02-21 09:16:23153 if (!TypeParam::supports_global_cookie_tracking)
154 return;
155
156 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55157 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:24158 std::unique_ptr<CookieChangeSubscription> subscription =
159 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36160 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
161 base::Unretained(&cookie_changes)));
162 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23163 ASSERT_EQ(0u, cookie_changes.size());
164
Victor Costaned602f52018-03-01 22:48:53165 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
Victor Costan1dcd6752018-03-16 12:31:36166 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:53167
168 ASSERT_EQ(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55169 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 Costaned602f52018-03-01 22:48:53175}
176
177TYPED_TEST_P(CookieStoreChangeGlobalTest, InsertMany) {
178 if (!TypeParam::supports_global_cookie_tracking)
179 return;
180
181 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55182 std::vector<CookieChangeInfo> cookie_changes;
Victor Costaned602f52018-03-01 22:48:53183 std::unique_ptr<CookieChangeSubscription> subscription =
184 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36185 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
186 base::Unretained(&cookie_changes)));
Victor Costaned602f52018-03-01 22:48:53187 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 Costan1dcd6752018-03-16 12:31:36191 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:53192
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 Chen19cced422019-10-17 21:45:55201 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 Costaned602f52018-03-01 22:48:53207
208 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55209 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 Costaned602f52018-03-01 22:48:53215
216 ASSERT_LE(3u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55217 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 Costaned602f52018-03-01 22:48:53223
224 ASSERT_LE(4u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55225 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 Costaned602f52018-03-01 22:48:53231
232 EXPECT_EQ(4u, cookie_changes.size());
233}
234
235TYPED_TEST_P(CookieStoreChangeGlobalTest, DeleteOne) {
236 if (!TypeParam::supports_global_cookie_tracking)
237 return;
238
239 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55240 std::vector<CookieChangeInfo> cookie_changes;
Victor Costaned602f52018-03-01 22:48:53241 std::unique_ptr<CookieChangeSubscription> subscription =
242 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36243 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
244 base::Unretained(&cookie_changes)));
Victor Costaned602f52018-03-01 22:48:53245 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
Victor Costan1dcd6752018-03-16 12:31:36246 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:53247 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 Costan1dcd6752018-03-16 12:31:36252 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:53253
254 ASSERT_EQ(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55255 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 Costaned602f52018-03-01 22:48:53261}
262
263TYPED_TEST_P(CookieStoreChangeGlobalTest, DeleteTwo) {
264 if (!TypeParam::supports_global_cookie_tracking)
265 return;
266
267 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55268 std::vector<CookieChangeInfo> cookie_changes;
Victor Costaned602f52018-03-01 22:48:53269 std::unique_ptr<CookieChangeSubscription> subscription =
270 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36271 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
272 base::Unretained(&cookie_changes)));
Victor Costaned602f52018-03-01 22:48:53273 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 Costan1dcd6752018-03-16 12:31:36277 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:53278 EXPECT_EQ(4u, cookie_changes.size());
279 cookie_changes.clear();
280
Victor Costanf8cb27d2018-02-21 09:16:23281 EXPECT_TRUE(
282 this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "C"));
Victor Costaned602f52018-03-01 22:48:53283 EXPECT_TRUE(
284 this->FindAndDeleteCookie(cs, this->http_bar_com_.url().host(), "G"));
Victor Costan1dcd6752018-03-16 12:31:36285 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:53286
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 Chen19cced422019-10-17 21:45:55295 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 Costanf8cb27d2018-02-21 09:16:23301
Victor Costaned602f52018-03-01 22:48:53302 ASSERT_EQ(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55303 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 Costanf8cb27d2018-02-21 09:16:23309}
310
Victor Costaned602f52018-03-01 22:48:53311TYPED_TEST_P(CookieStoreChangeGlobalTest, Overwrite) {
Victor Costanf8cb27d2018-02-21 09:16:23312 if (!TypeParam::supports_global_cookie_tracking)
313 return;
314
315 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55316 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:24317 std::unique_ptr<CookieChangeSubscription> subscription =
318 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36319 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
320 base::Unretained(&cookie_changes)));
321 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23322 ASSERT_EQ(0u, cookie_changes.size());
323
324 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
Victor Costan1dcd6752018-03-16 12:31:36325 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23326 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 Costan1dcd6752018-03-16 12:31:36332 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:53333
334 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55335 EXPECT_EQ(this->http_www_foo_.url().host(),
336 cookie_changes[0].cookie.Domain());
Victor Costan1dcd6752018-03-16 12:31:36337 EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
Lily Chen19cced422019-10-17 21:45:55338 cookie_changes[0].cause));
339 EXPECT_EQ("A", cookie_changes[0].cookie.Name());
340 EXPECT_EQ("B", cookie_changes[0].cookie.Value());
Victor Costaned602f52018-03-01 22:48:53341
342 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55343 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 Costaned602f52018-03-01 22:48:53349
350 EXPECT_EQ(2u, cookie_changes.size());
Victor Costanf8cb27d2018-02-21 09:16:23351}
352
Victor Costaned602f52018-03-01 22:48:53353TYPED_TEST_P(CookieStoreChangeGlobalTest, OverwriteWithHttpOnly) {
Victor Costanf8cb27d2018-02-21 09:16:23354 if (!TypeParam::supports_global_cookie_tracking)
355 return;
356
357 // Insert a cookie "A" for path "/path1"
358 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55359 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:24360 std::unique_ptr<CookieChangeSubscription> subscription =
361 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36362 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
363 base::Unretained(&cookie_changes)));
364 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23365 ASSERT_EQ(0u, cookie_changes.size());
366
367 EXPECT_TRUE(
368 this->SetCookie(cs, this->http_www_foo_.url(), "A=B; path=/path1"));
Victor Costan1dcd6752018-03-16 12:31:36369 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23370 ASSERT_EQ(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55371 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 Costanf8cb27d2018-02-21 09:16:23378 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 Orlovich21845bc2019-10-21 22:02:23384 allow_httponly.set_same_site_cookie_context(
Steven Bingler8d76c2a42020-03-24 17:13:32385 net::CookieOptions::SameSiteCookieContext::MakeInclusive());
Maks Orlovich21845bc2019-10-21 22:02:23386
Lily Chen0f208ea2019-08-08 23:37:53387 EXPECT_TRUE(this->CreateAndSetCookie(cs, this->http_www_foo_.url(),
388 "A=C; path=/path1; httponly",
389 allow_httponly));
Victor Costan1dcd6752018-03-16 12:31:36390 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:53391
392 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55393 EXPECT_EQ(this->http_www_foo_.url().host(),
394 cookie_changes[0].cookie.Domain());
Victor Costan1dcd6752018-03-16 12:31:36395 EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
Lily Chen19cced422019-10-17 21:45:55396 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 Costaned602f52018-03-01 22:48:53400
401 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55402 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 Costaned602f52018-03-01 22:48:53409
410 EXPECT_EQ(2u, cookie_changes.size());
Victor Costanf8cb27d2018-02-21 09:16:23411}
412
Victor Costaned602f52018-03-01 22:48:53413TYPED_TEST_P(CookieStoreChangeGlobalTest, Deregister) {
Victor Costanf8cb27d2018-02-21 09:16:23414 if (!TypeParam::supports_global_cookie_tracking)
415 return;
416
417 CookieStore* cs = this->GetCookieStore();
418
Lily Chen19cced422019-10-17 21:45:55419 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:24420 std::unique_ptr<CookieChangeSubscription> subscription =
421 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36422 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
423 base::Unretained(&cookie_changes)));
424 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23425 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 Costan1dcd6752018-03-16 12:31:36429 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23430 ASSERT_EQ(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55431 EXPECT_EQ("A", cookie_changes[0].cookie.Name());
432 EXPECT_EQ("B", cookie_changes[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:23433 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 Costan1dcd6752018-03-16 12:31:36440 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23441
442 EXPECT_EQ(0u, cookie_changes.size());
443}
444
Victor Costaned602f52018-03-01 22:48:53445TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterMultiple) {
Victor Costanf8cb27d2018-02-21 09:16:23446 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 Chen19cced422019-10-17 21:45:55453 std::vector<CookieChangeInfo> cookie_changes_1;
Victor Costan14f47c12018-03-01 08:02:24454 std::unique_ptr<CookieChangeSubscription> subscription1 =
455 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36456 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
457 base::Unretained(&cookie_changes_1)));
Victor Costanf8cb27d2018-02-21 09:16:23458
Lily Chen19cced422019-10-17 21:45:55459 std::vector<CookieChangeInfo> cookie_changes_2;
Victor Costan14f47c12018-03-01 08:02:24460 std::unique_ptr<CookieChangeSubscription> subscription2 =
461 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36462 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
463 base::Unretained(&cookie_changes_2)));
464 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23465 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 Costan1dcd6752018-03-16 12:31:36470 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23471 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:55472 EXPECT_EQ("A", cookie_changes_1[0].cookie.Name());
473 EXPECT_EQ("B", cookie_changes_1[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:23474 cookie_changes_1.clear();
475
476 ASSERT_EQ(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:55477 EXPECT_EQ("A", cookie_changes_2[0].cookie.Name());
478 EXPECT_EQ("B", cookie_changes_2[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:23479 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 Costan1dcd6752018-03-16 12:31:36487 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23488 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:55489 EXPECT_EQ("C", cookie_changes_1[0].cookie.Name());
490 EXPECT_EQ("D", cookie_changes_1[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:23491 cookie_changes_1.clear();
492
493 ASSERT_EQ(0u, cookie_changes_2.size());
494}
495
Victor Costaned602f52018-03-01 22:48:53496// Confirm that a listener does not receive notifications for changes that
497// happened right before the subscription was established.
498TYPED_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 Costan1dcd6752018-03-16 12:31:36506 // DeliverChangeNotifications() must NOT be called before the subscription is
507 // established.
Victor Costaned602f52018-03-01 22:48:53508
Lily Chen19cced422019-10-17 21:45:55509 std::vector<CookieChangeInfo> cookie_changes;
Victor Costaned602f52018-03-01 22:48:53510 std::unique_ptr<CookieChangeSubscription> subscription =
511 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36512 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
513 base::Unretained(&cookie_changes)));
Victor Costaned602f52018-03-01 22:48:53514
515 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D"));
Victor Costan1dcd6752018-03-16 12:31:36516 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:53517
518 EXPECT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55519 EXPECT_EQ("C", cookie_changes[0].cookie.Name());
520 EXPECT_EQ("D", cookie_changes[0].cookie.Value());
Victor Costaned602f52018-03-01 22:48:53521
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.
528TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterRace) {
Victor Costanf8cb27d2018-02-21 09:16:23529 if (!TypeParam::supports_global_cookie_tracking)
530 return;
531
532 CookieStore* cs = this->GetCookieStore();
533
Lily Chen19cced422019-10-17 21:45:55534 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:24535 std::unique_ptr<CookieChangeSubscription> subscription =
536 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36537 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
538 base::Unretained(&cookie_changes)));
539 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23540 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 Costan1dcd6752018-03-16 12:31:36544 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23545 ASSERT_EQ(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55546 EXPECT_EQ("A", cookie_changes[0].cookie.Name());
547 EXPECT_EQ("B", cookie_changes[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:23548 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 Costan1dcd6752018-03-16 12:31:36565 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23566 ASSERT_EQ(0u, cookie_changes.size());
567}
568
Victor Costaned602f52018-03-01 22:48:53569TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterRaceMultiple) {
Victor Costanf8cb27d2018-02-21 09:16:23570 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 Chen19cced422019-10-17 21:45:55577 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan14f47c12018-03-01 08:02:24578 std::unique_ptr<CookieChangeSubscription> subscription1 =
579 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36580 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
581 base::Unretained(&cookie_changes_1)));
Victor Costan14f47c12018-03-01 08:02:24582 std::unique_ptr<CookieChangeSubscription> subscription2 =
583 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36584 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
585 base::Unretained(&cookie_changes_2)));
586 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23587 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 Costan1dcd6752018-03-16 12:31:36592 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23593
594 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:55595 EXPECT_EQ("A", cookie_changes_1[0].cookie.Name());
596 EXPECT_EQ("B", cookie_changes_1[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:23597 cookie_changes_1.clear();
598
599 ASSERT_EQ(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:55600 EXPECT_EQ("A", cookie_changes_2[0].cookie.Name());
601 EXPECT_EQ("B", cookie_changes_2[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:23602 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 Costaned602f52018-03-01 22:48:53611 if (1u == cookie_changes_2.size())
Victor Costanf8cb27d2018-02-21 09:16:23612 return;
Victor Costanf8cb27d2018-02-21 09:16:23613
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 Costan1dcd6752018-03-16 12:31:36619 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23620 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:55621 EXPECT_EQ("C", cookie_changes_1[0].cookie.Name());
622 EXPECT_EQ("D", cookie_changes_1[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:23623
624 // No late notification was received.
625 ASSERT_EQ(0u, cookie_changes_2.size());
626}
627
Victor Costaned602f52018-03-01 22:48:53628TYPED_TEST_P(CookieStoreChangeGlobalTest, MultipleSubscriptions) {
Victor Costanf8cb27d2018-02-21 09:16:23629 if (!TypeParam::supports_global_cookie_tracking ||
630 !TypeParam::supports_multiple_tracking_callbacks)
631 return;
632
633 CookieStore* cs = this->GetCookieStore();
634
Lily Chen19cced422019-10-17 21:45:55635 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan14f47c12018-03-01 08:02:24636 std::unique_ptr<CookieChangeSubscription> subscription1 =
637 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36638 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
639 base::Unretained(&cookie_changes_1)));
Victor Costan14f47c12018-03-01 08:02:24640 std::unique_ptr<CookieChangeSubscription> subscription2 =
641 cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
Victor Costan1dcd6752018-03-16 12:31:36642 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
643 base::Unretained(&cookie_changes_2)));
644 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23645
Victor Costaned602f52018-03-01 22:48:53646 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
Victor Costan1dcd6752018-03-16 12:31:36647 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:23648
649 ASSERT_EQ(1U, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:55650 EXPECT_EQ("A", cookie_changes_1[0].cookie.Name());
651 EXPECT_EQ("B", cookie_changes_1[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:23652
653 ASSERT_EQ(1U, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:55654 EXPECT_EQ("A", cookie_changes_2[0].cookie.Name());
655 EXPECT_EQ("B", cookie_changes_2[0].cookie.Value());
656}
657
658TYPED_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 Ishii9f5e72dc2020-07-22 19:43:18694 CookieAccessSemantics::LEGACY,
695 cookie_changes[0].access_result.access_semantics));
Lily Chen19cced422019-10-17 21:45:55696 EXPECT_EQ("domain2.test", cookie_changes[1].cookie.Domain());
697 EXPECT_TRUE(this->IsExpectedAccessSemantics(
Ayu Ishii9f5e72dc2020-07-22 19:43:18698 CookieAccessSemantics::NONLEGACY,
699 cookie_changes[1].access_result.access_semantics));
Lily Chen19cced422019-10-17 21:45:55700 EXPECT_EQ("domain3.test", cookie_changes[2].cookie.Domain());
701 EXPECT_TRUE(this->IsExpectedAccessSemantics(
Ayu Ishii9f5e72dc2020-07-22 19:43:18702 CookieAccessSemantics::UNKNOWN,
703 cookie_changes[2].access_result.access_semantics));
Lily Chen19cced422019-10-17 21:45:55704 EXPECT_EQ("domain4.test", cookie_changes[3].cookie.Domain());
705 EXPECT_TRUE(this->IsExpectedAccessSemantics(
Ayu Ishii9f5e72dc2020-07-22 19:43:18706 CookieAccessSemantics::UNKNOWN,
707 cookie_changes[3].access_result.access_semantics));
Victor Costanf8cb27d2018-02-21 09:16:23708}
709
Victor Costan2a1891672018-03-02 06:01:53710TYPED_TEST_P(CookieStoreChangeUrlTest, NoCookie) {
711 if (!TypeParam::supports_url_cookie_tracking)
712 return;
713
714 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55715 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:53716 std::unique_ptr<CookieChangeSubscription> subscription =
717 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:48718 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:36719 base::BindRepeating(
720 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
721 base::Unretained(&cookie_changes)));
722 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53723 EXPECT_EQ(0u, cookie_changes.size());
724}
725
726TYPED_TEST_P(CookieStoreChangeUrlTest, InitialCookie) {
727 if (!TypeParam::supports_url_cookie_tracking)
728 return;
729
730 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55731 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:53732 this->SetCookie(cs, this->http_www_foo_.url(), "A=B");
Victor Costan1dcd6752018-03-16 12:31:36733 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53734 std::unique_ptr<CookieChangeSubscription> subscription =
735 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:48736 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:36737 base::BindRepeating(
738 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
739 base::Unretained(&cookie_changes)));
740 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53741 EXPECT_EQ(0u, cookie_changes.size());
742}
743
744TYPED_TEST_P(CookieStoreChangeUrlTest, InsertOne) {
745 if (!TypeParam::supports_url_cookie_tracking)
746 return;
747
748 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55749 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:53750 std::unique_ptr<CookieChangeSubscription> subscription =
751 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:48752 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:36753 base::BindRepeating(
754 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
755 base::Unretained(&cookie_changes)));
756 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53757 ASSERT_EQ(0u, cookie_changes.size());
758
759 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
Victor Costan1dcd6752018-03-16 12:31:36760 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53761 ASSERT_EQ(1u, cookie_changes.size());
762
Lily Chen19cced422019-10-17 21:45:55763 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 Costan2a1891672018-03-02 06:01:53769}
770
771TYPED_TEST_P(CookieStoreChangeUrlTest, InsertMany) {
772 if (!TypeParam::supports_url_cookie_tracking)
773 return;
774
775 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55776 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:53777 std::unique_ptr<CookieChangeSubscription> subscription =
778 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:48779 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:36780 base::BindRepeating(
781 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
782 base::Unretained(&cookie_changes)));
Victor Costan2a1891672018-03-02 06:01:53783 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 Costan1dcd6752018-03-16 12:31:36786 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53787
788 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55789 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 Costan2a1891672018-03-02 06:01:53795
796 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55797 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 Costan2a1891672018-03-02 06:01:53803
804 ASSERT_LE(3u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55805 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 Costan2a1891672018-03-02 06:01:53811
812 EXPECT_EQ(3u, cookie_changes.size());
813}
814
815TYPED_TEST_P(CookieStoreChangeUrlTest, InsertFiltering) {
816 if (!TypeParam::supports_url_cookie_tracking)
817 return;
818
819 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55820 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:53821 std::unique_ptr<CookieChangeSubscription> subscription =
822 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:48823 this->www_foo_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:36824 base::BindRepeating(
825 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
826 base::Unretained(&cookie_changes)));
827 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53828 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 Costan1dcd6752018-03-16 12:31:36838 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53839
840 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55841 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 Costan2a1891672018-03-02 06:01:53848
849 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55850 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 Costan2a1891672018-03-02 06:01:53857
858 ASSERT_LE(3u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55859 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 Costan2a1891672018-03-02 06:01:53865
866 EXPECT_EQ(3u, cookie_changes.size());
867}
868
869TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteOne) {
870 if (!TypeParam::supports_url_cookie_tracking)
871 return;
872
873 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55874 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:53875 std::unique_ptr<CookieChangeSubscription> subscription =
876 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:48877 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:36878 base::BindRepeating(
879 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
880 base::Unretained(&cookie_changes)));
Victor Costan2a1891672018-03-02 06:01:53881 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
Victor Costan1dcd6752018-03-16 12:31:36882 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53883 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 Costan1dcd6752018-03-16 12:31:36888 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53889
890 ASSERT_EQ(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55891 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 Costan2a1891672018-03-02 06:01:53897}
898
899TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteTwo) {
900 if (!TypeParam::supports_url_cookie_tracking)
901 return;
902
903 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55904 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:53905 std::unique_ptr<CookieChangeSubscription> subscription =
906 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:48907 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:36908 base::BindRepeating(
909 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
910 base::Unretained(&cookie_changes)));
Victor Costan2a1891672018-03-02 06:01:53911 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 Costan1dcd6752018-03-16 12:31:36915 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53916 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 Costan1dcd6752018-03-16 12:31:36923 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53924
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 Chen19cced422019-10-17 21:45:55932 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 Costan2a1891672018-03-02 06:01:53938
939 ASSERT_EQ(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55940 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 Costan2a1891672018-03-02 06:01:53946}
947
948TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteFiltering) {
949 if (!TypeParam::supports_url_cookie_tracking)
950 return;
951
952 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:55953 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:53954 std::unique_ptr<CookieChangeSubscription> subscription =
955 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:48956 this->www_foo_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:36957 base::BindRepeating(
958 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
959 base::Unretained(&cookie_changes)));
Victor Costan2a1891672018-03-02 06:01:53960 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 Costan1dcd6752018-03-16 12:31:36968 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53969 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 Costan1dcd6752018-03-16 12:31:36983 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:53984
985 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55986 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 Costan2a1891672018-03-02 06:01:53993
994 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:55995 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 Costan2a1891672018-03-02 06:01:531002
1003 ASSERT_LE(3u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551004 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 Costan2a1891672018-03-02 06:01:531010
1011 EXPECT_EQ(3u, cookie_changes.size());
1012}
1013
1014TYPED_TEST_P(CookieStoreChangeUrlTest, Overwrite) {
1015 if (!TypeParam::supports_url_cookie_tracking)
1016 return;
1017
1018 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:551019 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:531020 std::unique_ptr<CookieChangeSubscription> subscription =
1021 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481022 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361023 base::BindRepeating(
1024 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1025 base::Unretained(&cookie_changes)));
1026 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531027 ASSERT_EQ(0u, cookie_changes.size());
1028
1029 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
Victor Costan1dcd6752018-03-16 12:31:361030 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531031 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 Costan1dcd6752018-03-16 12:31:361037 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531038
1039 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551040 EXPECT_EQ(this->http_www_foo_.url().host(),
1041 cookie_changes[0].cookie.Domain());
Victor Costan1dcd6752018-03-16 12:31:361042 EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
Lily Chen19cced422019-10-17 21:45:551043 cookie_changes[0].cause));
1044 EXPECT_EQ("A", cookie_changes[0].cookie.Name());
1045 EXPECT_EQ("B", cookie_changes[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531046
1047 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551048 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 Costan2a1891672018-03-02 06:01:531054
1055 EXPECT_EQ(2u, cookie_changes.size());
1056}
1057
1058TYPED_TEST_P(CookieStoreChangeUrlTest, OverwriteFiltering) {
1059 if (!TypeParam::supports_url_cookie_tracking)
1060 return;
1061
1062 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:551063 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:531064 std::unique_ptr<CookieChangeSubscription> subscription =
1065 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481066 this->www_foo_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361067 base::BindRepeating(
1068 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1069 base::Unretained(&cookie_changes)));
1070 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531071 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 Costan1dcd6752018-03-16 12:31:361081 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531082 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 Costan1dcd6752018-03-16 12:31:361095 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531096
1097 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551098 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 Costan1dcd6752018-03-16 12:31:361103 EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
Lily Chen19cced422019-10-17 21:45:551104 cookie_changes[0].cause));
Victor Costan2a1891672018-03-02 06:01:531105
1106 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551107 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 Costan2a1891672018-03-02 06:01:531115
1116 ASSERT_LE(3u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551117 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 Costan1dcd6752018-03-16 12:31:361122 EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
Lily Chen19cced422019-10-17 21:45:551123 cookie_changes[2].cause));
Victor Costan2a1891672018-03-02 06:01:531124
1125 ASSERT_LE(4u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551126 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 Costan2a1891672018-03-02 06:01:531133
1134 ASSERT_LE(5u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551135 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 Costan1dcd6752018-03-16 12:31:361139 EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
Lily Chen19cced422019-10-17 21:45:551140 cookie_changes[4].cause));
Victor Costan2a1891672018-03-02 06:01:531141
1142 ASSERT_LE(6u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551143 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 Costan2a1891672018-03-02 06:01:531149
1150 EXPECT_EQ(6u, cookie_changes.size());
1151}
1152
1153TYPED_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 Chen19cced422019-10-17 21:45:551159 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:531160 std::unique_ptr<CookieChangeSubscription> subscription =
1161 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481162 this->www_foo_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361163 base::BindRepeating(
1164 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1165 base::Unretained(&cookie_changes)));
1166 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531167 ASSERT_EQ(0u, cookie_changes.size());
1168
1169 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B; path=/foo"));
Victor Costan1dcd6752018-03-16 12:31:361170 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531171 ASSERT_EQ(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551172 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 Costan2a1891672018-03-02 06:01:531179 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 Orlovich21845bc2019-10-21 22:02:231185 allow_httponly.set_same_site_cookie_context(
Steven Bingler8d76c2a42020-03-24 17:13:321186 net::CookieOptions::SameSiteCookieContext::MakeInclusive());
Maks Orlovich21845bc2019-10-21 22:02:231187
Lily Chen0f208ea2019-08-08 23:37:531188 EXPECT_TRUE(this->CreateAndSetCookie(cs, this->http_www_foo_.url(),
1189 "A=C; path=/foo; httponly",
1190 allow_httponly));
Victor Costan1dcd6752018-03-16 12:31:361191 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531192
1193 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551194 EXPECT_EQ(this->http_www_foo_.url().host(),
1195 cookie_changes[0].cookie.Domain());
Victor Costan1dcd6752018-03-16 12:31:361196 EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
Lily Chen19cced422019-10-17 21:45:551197 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 Costan2a1891672018-03-02 06:01:531201
1202 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551203 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 Costan2a1891672018-03-02 06:01:531210
1211 EXPECT_EQ(2u, cookie_changes.size());
1212}
1213
1214TYPED_TEST_P(CookieStoreChangeUrlTest, Deregister) {
1215 if (!TypeParam::supports_url_cookie_tracking)
1216 return;
1217
1218 CookieStore* cs = this->GetCookieStore();
1219
Lily Chen19cced422019-10-17 21:45:551220 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:531221 std::unique_ptr<CookieChangeSubscription> subscription =
1222 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481223 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361224 base::BindRepeating(
1225 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1226 base::Unretained(&cookie_changes)));
1227 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531228 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 Costan1dcd6752018-03-16 12:31:361232 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531233 ASSERT_EQ(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551234 EXPECT_EQ("A", cookie_changes[0].cookie.Name());
1235 EXPECT_EQ("B", cookie_changes[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531236 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 Costan1dcd6752018-03-16 12:31:361243 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531244
1245 EXPECT_EQ(0u, cookie_changes.size());
1246}
1247
1248TYPED_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 Chen19cced422019-10-17 21:45:551256 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan2a1891672018-03-02 06:01:531257 std::unique_ptr<CookieChangeSubscription> subscription1 =
1258 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481259 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361260 base::BindRepeating(
1261 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1262 base::Unretained(&cookie_changes_1)));
Victor Costan2a1891672018-03-02 06:01:531263 std::unique_ptr<CookieChangeSubscription> subscription2 =
1264 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481265 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361266 base::BindRepeating(
1267 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1268 base::Unretained(&cookie_changes_2)));
1269 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531270 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 Costan1dcd6752018-03-16 12:31:361275 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531276 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:551277 EXPECT_EQ("A", cookie_changes_1[0].cookie.Name());
1278 EXPECT_EQ("B", cookie_changes_1[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531279 cookie_changes_1.clear();
1280
1281 ASSERT_EQ(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:551282 EXPECT_EQ("A", cookie_changes_2[0].cookie.Name());
1283 EXPECT_EQ("B", cookie_changes_2[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531284 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 Costan1dcd6752018-03-16 12:31:361292 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531293 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:551294 EXPECT_EQ("C", cookie_changes_1[0].cookie.Name());
1295 EXPECT_EQ("D", cookie_changes_1[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531296
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.
1302TYPED_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 Costan1dcd6752018-03-16 12:31:361310 // DeliverChangeNotifications() must NOT be called before the subscription is
1311 // established.
Victor Costan2a1891672018-03-02 06:01:531312
Lily Chen19cced422019-10-17 21:45:551313 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:531314 std::unique_ptr<CookieChangeSubscription> subscription =
1315 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481316 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361317 base::BindRepeating(
1318 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1319 base::Unretained(&cookie_changes)));
Victor Costan2a1891672018-03-02 06:01:531320
1321 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D"));
Victor Costan1dcd6752018-03-16 12:31:361322 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531323
1324 EXPECT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551325 EXPECT_EQ("C", cookie_changes[0].cookie.Name());
1326 EXPECT_EQ("D", cookie_changes[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531327
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.
1334TYPED_TEST_P(CookieStoreChangeUrlTest, DeregisterRace) {
1335 if (!TypeParam::supports_url_cookie_tracking)
1336 return;
1337
1338 CookieStore* cs = this->GetCookieStore();
1339
Lily Chen19cced422019-10-17 21:45:551340 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan2a1891672018-03-02 06:01:531341 std::unique_ptr<CookieChangeSubscription> subscription =
1342 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481343 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361344 base::BindRepeating(
1345 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1346 base::Unretained(&cookie_changes)));
1347 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531348 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 Costan1dcd6752018-03-16 12:31:361352 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531353 ASSERT_EQ(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551354 EXPECT_EQ("A", cookie_changes[0].cookie.Name());
1355 EXPECT_EQ("B", cookie_changes[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531356 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 Costan1dcd6752018-03-16 12:31:361373 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531374 ASSERT_EQ(0u, cookie_changes.size());
1375}
1376
1377TYPED_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 Chen19cced422019-10-17 21:45:551385 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan2a1891672018-03-02 06:01:531386 std::unique_ptr<CookieChangeSubscription> subscription1 =
1387 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481388 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361389 base::BindRepeating(
1390 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1391 base::Unretained(&cookie_changes_1)));
Victor Costan2a1891672018-03-02 06:01:531392 std::unique_ptr<CookieChangeSubscription> subscription2 =
1393 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481394 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361395 base::BindRepeating(
1396 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1397 base::Unretained(&cookie_changes_2)));
1398 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531399 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 Costan1dcd6752018-03-16 12:31:361404 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531405
1406 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:551407 EXPECT_EQ("A", cookie_changes_1[0].cookie.Name());
1408 EXPECT_EQ("B", cookie_changes_1[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531409 cookie_changes_1.clear();
1410
1411 ASSERT_EQ(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:551412 EXPECT_EQ("A", cookie_changes_2[0].cookie.Name());
1413 EXPECT_EQ("B", cookie_changes_2[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531414 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 Costan1dcd6752018-03-16 12:31:361431 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531432 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:551433 EXPECT_EQ("C", cookie_changes_1[0].cookie.Name());
1434 EXPECT_EQ("D", cookie_changes_1[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531435
1436 // No late notification was received.
1437 ASSERT_EQ(0u, cookie_changes_2.size());
1438}
1439
1440TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsDisjoint) {
1441 if (!TypeParam::supports_url_cookie_tracking)
1442 return;
1443
1444 CookieStore* cs = this->GetCookieStore();
1445
Lily Chen19cced422019-10-17 21:45:551446 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan2a1891672018-03-02 06:01:531447 std::unique_ptr<CookieChangeSubscription> subscription1 =
1448 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481449 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361450 base::BindRepeating(
1451 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1452 base::Unretained(&cookie_changes_1)));
Victor Costan2a1891672018-03-02 06:01:531453 std::unique_ptr<CookieChangeSubscription> subscription2 =
1454 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481455 this->http_bar_com_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361456 base::BindRepeating(
1457 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1458 base::Unretained(&cookie_changes_2)));
1459 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531460 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 Costan1dcd6752018-03-16 12:31:361464 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531465 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 Costan1dcd6752018-03-16 12:31:361469 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531470
1471 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:551472 EXPECT_EQ("A", cookie_changes_1[0].cookie.Name());
1473 EXPECT_EQ("B", cookie_changes_1[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531474 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:551475 cookie_changes_1[0].cookie.Domain());
Victor Costan2a1891672018-03-02 06:01:531476
1477 ASSERT_EQ(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:551478 EXPECT_EQ("C", cookie_changes_2[0].cookie.Name());
1479 EXPECT_EQ("D", cookie_changes_2[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531480 EXPECT_EQ(this->http_bar_com_.url().host(),
Lily Chen19cced422019-10-17 21:45:551481 cookie_changes_2[0].cookie.Domain());
Victor Costan2a1891672018-03-02 06:01:531482}
1483
1484TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsDomains) {
1485 if (!TypeParam::supports_url_cookie_tracking)
1486 return;
1487
1488 CookieStore* cs = this->GetCookieStore();
1489
Lily Chen19cced422019-10-17 21:45:551490 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan2a1891672018-03-02 06:01:531491 std::unique_ptr<CookieChangeSubscription> subscription1 =
1492 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481493 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361494 base::BindRepeating(
1495 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1496 base::Unretained(&cookie_changes_1)));
Victor Costan2a1891672018-03-02 06:01:531497 std::unique_ptr<CookieChangeSubscription> subscription2 =
1498 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481499 this->http_bar_com_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361500 base::BindRepeating(
1501 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1502 base::Unretained(&cookie_changes_2)));
1503 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531504 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 Costan1dcd6752018-03-16 12:31:361508 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531509 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 Costan1dcd6752018-03-16 12:31:361513 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531514
1515 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:551516 EXPECT_EQ("A", cookie_changes_1[0].cookie.Name());
1517 EXPECT_EQ("B", cookie_changes_1[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531518 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:551519 cookie_changes_1[0].cookie.Domain());
Victor Costan2a1891672018-03-02 06:01:531520
1521 ASSERT_EQ(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:551522 EXPECT_EQ("C", cookie_changes_2[0].cookie.Name());
1523 EXPECT_EQ("D", cookie_changes_2[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531524 EXPECT_EQ(this->http_bar_com_.url().host(),
Lily Chen19cced422019-10-17 21:45:551525 cookie_changes_2[0].cookie.Domain());
Victor Costan2a1891672018-03-02 06:01:531526}
1527
1528TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsPaths) {
1529 if (!TypeParam::supports_url_cookie_tracking)
1530 return;
1531
1532 CookieStore* cs = this->GetCookieStore();
1533
Lily Chen19cced422019-10-17 21:45:551534 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan2a1891672018-03-02 06:01:531535 std::unique_ptr<CookieChangeSubscription> subscription1 =
1536 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481537 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361538 base::BindRepeating(
1539 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1540 base::Unretained(&cookie_changes_1)));
Victor Costan2a1891672018-03-02 06:01:531541 std::unique_ptr<CookieChangeSubscription> subscription2 =
1542 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481543 this->www_foo_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361544 base::BindRepeating(
1545 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1546 base::Unretained(&cookie_changes_2)));
1547 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531548 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 Costan1dcd6752018-03-16 12:31:361552 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531553 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 Costan1dcd6752018-03-16 12:31:361557 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531558
1559 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:551560 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 Costan2a1891672018-03-02 06:01:531563 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:551564 cookie_changes_1[0].cookie.Domain());
Victor Costan2a1891672018-03-02 06:01:531565
1566 ASSERT_LE(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:551567 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 Costan2a1891672018-03-02 06:01:531570 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:551571 cookie_changes_2[0].cookie.Domain());
Victor Costan2a1891672018-03-02 06:01:531572
1573 ASSERT_LE(2u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:551574 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 Costan2a1891672018-03-02 06:01:531577 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:551578 cookie_changes_2[1].cookie.Domain());
Victor Costan2a1891672018-03-02 06:01:531579
1580 EXPECT_EQ(2u, cookie_changes_2.size());
1581}
1582
1583TYPED_TEST_P(CookieStoreChangeUrlTest, DifferentSubscriptionsFiltering) {
1584 if (!TypeParam::supports_url_cookie_tracking)
1585 return;
1586
1587 CookieStore* cs = this->GetCookieStore();
1588
Lily Chen19cced422019-10-17 21:45:551589 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
1590 std::vector<CookieChangeInfo> cookie_changes_3;
Victor Costan2a1891672018-03-02 06:01:531591 std::unique_ptr<CookieChangeSubscription> subscription1 =
1592 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481593 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361594 base::BindRepeating(
1595 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1596 base::Unretained(&cookie_changes_1)));
Victor Costan2a1891672018-03-02 06:01:531597 std::unique_ptr<CookieChangeSubscription> subscription2 =
1598 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481599 this->http_bar_com_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361600 base::BindRepeating(
1601 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1602 base::Unretained(&cookie_changes_2)));
Victor Costan2a1891672018-03-02 06:01:531603 std::unique_ptr<CookieChangeSubscription> subscription3 =
1604 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481605 this->www_foo_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361606 base::BindRepeating(
1607 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1608 base::Unretained(&cookie_changes_3)));
1609 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531610 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 Costan1dcd6752018-03-16 12:31:361615 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531616 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 Costan1dcd6752018-03-16 12:31:361621 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531622 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 Costan1dcd6752018-03-16 12:31:361627 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531628
1629 ASSERT_LE(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:551630 EXPECT_EQ("A", cookie_changes_1[0].cookie.Name());
1631 EXPECT_EQ("B", cookie_changes_1[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531632 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:551633 cookie_changes_1[0].cookie.Domain());
Victor Costan2a1891672018-03-02 06:01:531634 EXPECT_EQ(1u, cookie_changes_1.size());
1635
1636 ASSERT_LE(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:551637 EXPECT_EQ("C", cookie_changes_2[0].cookie.Name());
1638 EXPECT_EQ("D", cookie_changes_2[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531639 EXPECT_EQ(this->http_bar_com_.url().host(),
Lily Chen19cced422019-10-17 21:45:551640 cookie_changes_2[0].cookie.Domain());
Victor Costan2a1891672018-03-02 06:01:531641 EXPECT_EQ(1u, cookie_changes_2.size());
1642
1643 ASSERT_LE(1u, cookie_changes_3.size());
Lily Chen19cced422019-10-17 21:45:551644 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 Costan2a1891672018-03-02 06:01:531647 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:551648 cookie_changes_3[0].cookie.Domain());
Victor Costan2a1891672018-03-02 06:01:531649
1650 ASSERT_LE(2u, cookie_changes_3.size());
Lily Chen19cced422019-10-17 21:45:551651 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 Costan2a1891672018-03-02 06:01:531654 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:551655 cookie_changes_3[1].cookie.Domain());
Victor Costan2a1891672018-03-02 06:01:531656
1657 EXPECT_EQ(2u, cookie_changes_3.size());
1658}
1659
1660TYPED_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 Chen19cced422019-10-17 21:45:551667 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan2a1891672018-03-02 06:01:531668 std::unique_ptr<CookieChangeSubscription> subscription1 =
1669 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481670 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361671 base::BindRepeating(
1672 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1673 base::Unretained(&cookie_changes_1)));
Victor Costan2a1891672018-03-02 06:01:531674 std::unique_ptr<CookieChangeSubscription> subscription2 =
1675 cs->GetChangeDispatcher().AddCallbackForUrl(
Dylan Cutler7f121542021-09-28 20:41:481676 this->http_www_foo_.url(), absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361677 base::BindRepeating(
1678 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1679 base::Unretained(&cookie_changes_2)));
1680 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531681
1682 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
Victor Costan1dcd6752018-03-16 12:31:361683 this->DeliverChangeNotifications();
Victor Costan2a1891672018-03-02 06:01:531684
1685 ASSERT_EQ(1U, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:551686 EXPECT_EQ("A", cookie_changes_1[0].cookie.Name());
1687 EXPECT_EQ("B", cookie_changes_1[0].cookie.Value());
Victor Costan2a1891672018-03-02 06:01:531688
1689 ASSERT_EQ(1U, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:551690 EXPECT_EQ("A", cookie_changes_2[0].cookie.Name());
1691 EXPECT_EQ("B", cookie_changes_2[0].cookie.Value());
1692}
1693
1694TYPED_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 Cutler7f121542021-09-28 20:41:481709 GURL("http://domain1.test"), absl::nullopt /* cookie_partition_key */,
Lily Chen19cced422019-10-17 21:45:551710 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 Ishii9f5e72dc2020-07-22 19:43:181722 CookieAccessSemantics::LEGACY,
1723 cookie_changes[0].access_result.access_semantics));
Victor Costan2a1891672018-03-02 06:01:531724}
1725
Dylan Cutler7f121542021-09-28 20:41:481726TYPED_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 Cutler6ac1c67a82022-03-31 11:36:161736 CookiePartitionKey::FromURLForTesting(GURL("https://www.foo.com")),
Dylan Cutler7f121542021-09-28 20:41:481737 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 Costaned602f52018-03-01 22:48:531796TYPED_TEST_P(CookieStoreChangeNamedTest, NoCookie) {
Victor Costanf8cb27d2018-02-21 09:16:231797 if (!TypeParam::supports_named_cookie_tracking)
1798 return;
1799
1800 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:551801 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:241802 std::unique_ptr<CookieChangeSubscription> subscription =
1803 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:231804 this->http_www_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:481805 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361806 base::BindRepeating(
1807 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1808 base::Unretained(&cookie_changes)));
1809 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:231810 EXPECT_EQ(0u, cookie_changes.size());
1811}
1812
Victor Costaned602f52018-03-01 22:48:531813TYPED_TEST_P(CookieStoreChangeNamedTest, InitialCookie) {
Victor Costanf8cb27d2018-02-21 09:16:231814 if (!TypeParam::supports_named_cookie_tracking)
1815 return;
1816
1817 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:551818 std::vector<CookieChangeInfo> cookie_changes;
Victor Costanf8cb27d2018-02-21 09:16:231819 this->SetCookie(cs, this->http_www_foo_.url(), "abc=def");
Victor Costan1dcd6752018-03-16 12:31:361820 this->DeliverChangeNotifications();
Victor Costan14f47c12018-03-01 08:02:241821 std::unique_ptr<CookieChangeSubscription> subscription =
1822 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:231823 this->http_www_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:481824 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361825 base::BindRepeating(
1826 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1827 base::Unretained(&cookie_changes)));
1828 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:231829 EXPECT_EQ(0u, cookie_changes.size());
1830}
1831
Victor Costaned602f52018-03-01 22:48:531832TYPED_TEST_P(CookieStoreChangeNamedTest, InsertOne) {
Victor Costanf8cb27d2018-02-21 09:16:231833 if (!TypeParam::supports_named_cookie_tracking)
1834 return;
1835
1836 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:551837 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:241838 std::unique_ptr<CookieChangeSubscription> subscription =
1839 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:231840 this->http_www_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:481841 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361842 base::BindRepeating(
1843 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1844 base::Unretained(&cookie_changes)));
1845 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:231846 ASSERT_EQ(0u, cookie_changes.size());
1847
1848 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def"));
Victor Costan1dcd6752018-03-16 12:31:361849 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:231850 ASSERT_EQ(1u, cookie_changes.size());
1851
Lily Chen19cced422019-10-17 21:45:551852 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 Costanf8cb27d2018-02-21 09:16:231858}
1859
Victor Costaned602f52018-03-01 22:48:531860TYPED_TEST_P(CookieStoreChangeNamedTest, InsertTwo) {
1861 if (!TypeParam::supports_named_cookie_tracking)
1862 return;
1863
1864 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:551865 std::vector<CookieChangeInfo> cookie_changes;
Victor Costaned602f52018-03-01 22:48:531866 std::unique_ptr<CookieChangeSubscription> subscription =
1867 cs->GetChangeDispatcher().AddCallbackForCookie(
1868 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:481869 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361870 base::BindRepeating(
1871 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1872 base::Unretained(&cookie_changes)));
1873 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:531874 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 Costan1dcd6752018-03-16 12:31:361879 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:531880
1881 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551882 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 Costaned602f52018-03-01 22:48:531889
1890 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551891 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 Costaned602f52018-03-01 22:48:531898
1899 EXPECT_EQ(2u, cookie_changes.size());
1900}
1901
1902TYPED_TEST_P(CookieStoreChangeNamedTest, InsertFiltering) {
Victor Costanf8cb27d2018-02-21 09:16:231903 if (!TypeParam::supports_named_cookie_tracking)
1904 return;
1905
1906 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:551907 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:241908 std::unique_ptr<CookieChangeSubscription> subscription =
1909 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:231910 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:481911 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361912 base::BindRepeating(
1913 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1914 base::Unretained(&cookie_changes)));
1915 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:231916 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 Costaned602f52018-03-01 22:48:531924 EXPECT_TRUE(
1925 this->SetCookie(cs, this->http_www_foo_.url(), "abc=mno; path=/foo/bar"));
Victor Costanf8cb27d2018-02-21 09:16:231926 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "xyz=zyx"));
1927 EXPECT_TRUE(
Victor Costaned602f52018-03-01 22:48:531928 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 Costan1dcd6752018-03-16 12:31:361931 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:231932
Victor Costaned602f52018-03-01 22:48:531933 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551934 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 Costanf8cb27d2018-02-21 09:16:231941
Victor Costaned602f52018-03-01 22:48:531942 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551943 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 Costaned602f52018-03-01 22:48:531950
1951 ASSERT_LE(3u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551952 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 Costaned602f52018-03-01 22:48:531958
1959 EXPECT_EQ(3u, cookie_changes.size());
Victor Costanf8cb27d2018-02-21 09:16:231960}
1961
Victor Costaned602f52018-03-01 22:48:531962TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteOne) {
Victor Costanf8cb27d2018-02-21 09:16:231963 if (!TypeParam::supports_named_cookie_tracking)
1964 return;
1965
1966 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:551967 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:241968 std::unique_ptr<CookieChangeSubscription> subscription =
1969 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:231970 this->http_www_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:481971 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:361972 base::BindRepeating(
1973 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
1974 base::Unretained(&cookie_changes)));
Victor Costanf8cb27d2018-02-21 09:16:231975 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def"));
Victor Costan1dcd6752018-03-16 12:31:361976 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:231977 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 Costan1dcd6752018-03-16 12:31:361982 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:231983
Victor Costaned602f52018-03-01 22:48:531984 ASSERT_EQ(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:551985 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 Costanf8cb27d2018-02-21 09:16:231991}
1992
Victor Costaned602f52018-03-01 22:48:531993TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteTwo) {
Victor Costanf8cb27d2018-02-21 09:16:231994 if (!TypeParam::supports_named_cookie_tracking)
1995 return;
1996
1997 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:551998 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:241999 std::unique_ptr<CookieChangeSubscription> subscription =
2000 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costaned602f52018-03-01 22:48:532001 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482002 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362003 base::BindRepeating(
2004 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2005 base::Unretained(&cookie_changes)));
Victor Costaned602f52018-03-01 22:48:532006 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 Costan1dcd6752018-03-16 12:31:362009 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:532010 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 Costan1dcd6752018-03-16 12:31:362017 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:532018
2019 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552020 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 Costaned602f52018-03-01 22:48:532027
2028 ASSERT_EQ(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552029 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 Costaned602f52018-03-01 22:48:532036}
2037
2038TYPED_TEST_P(CookieStoreChangeNamedTest, DeleteFiltering) {
2039 if (!TypeParam::supports_named_cookie_tracking)
2040 return;
2041
2042 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:552043 std::vector<CookieChangeInfo> cookie_changes;
Victor Costaned602f52018-03-01 22:48:532044 std::unique_ptr<CookieChangeSubscription> subscription =
2045 cs->GetChangeDispatcher().AddCallbackForCookie(
2046 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482047 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362048 base::BindRepeating(
2049 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2050 base::Unretained(&cookie_changes)));
Victor Costaned602f52018-03-01 22:48:532051 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 Costan1dcd6752018-03-16 12:31:362063 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:532064 EXPECT_EQ(3u, cookie_changes.size());
Victor Costanf8cb27d2018-02-21 09:16:232065 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 Costaned602f52018-03-01 22:48:532071 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 Costan1dcd6752018-03-16 12:31:362078 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232079
Victor Costaned602f52018-03-01 22:48:532080 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552081 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 Costaned602f52018-03-01 22:48:532088
2089 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552090 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 Costaned602f52018-03-01 22:48:532097
2098 ASSERT_LE(3u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552099 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 Costaned602f52018-03-01 22:48:532105
2106 EXPECT_EQ(3u, cookie_changes.size());
Victor Costanf8cb27d2018-02-21 09:16:232107}
2108
Victor Costaned602f52018-03-01 22:48:532109TYPED_TEST_P(CookieStoreChangeNamedTest, Overwrite) {
Victor Costanf8cb27d2018-02-21 09:16:232110 if (!TypeParam::supports_named_cookie_tracking)
2111 return;
2112
2113 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:552114 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:242115 std::unique_ptr<CookieChangeSubscription> subscription =
2116 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232117 this->http_www_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482118 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362119 base::BindRepeating(
2120 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2121 base::Unretained(&cookie_changes)));
2122 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232123 ASSERT_EQ(0u, cookie_changes.size());
2124
2125 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "abc=def"));
Victor Costan1dcd6752018-03-16 12:31:362126 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232127 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 Costan1dcd6752018-03-16 12:31:362133 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232134
Victor Costaned602f52018-03-01 22:48:532135 EXPECT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552136 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 Costan1dcd6752018-03-16 12:31:362140 EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
Lily Chen19cced422019-10-17 21:45:552141 cookie_changes[0].cause));
Victor Costanf8cb27d2018-02-21 09:16:232142
Victor Costaned602f52018-03-01 22:48:532143 EXPECT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552144 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 Costaned602f52018-03-01 22:48:532150
2151 EXPECT_EQ(2u, cookie_changes.size());
Victor Costanf8cb27d2018-02-21 09:16:232152}
2153
Victor Costaned602f52018-03-01 22:48:532154TYPED_TEST_P(CookieStoreChangeNamedTest, OverwriteFiltering) {
Victor Costanf8cb27d2018-02-21 09:16:232155 if (!TypeParam::supports_named_cookie_tracking)
2156 return;
2157
2158 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:552159 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:242160 std::unique_ptr<CookieChangeSubscription> subscription =
2161 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232162 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482163 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362164 base::BindRepeating(
2165 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2166 base::Unretained(&cookie_changes)));
2167 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232168 ASSERT_EQ(0u, cookie_changes.size());
2169
2170 EXPECT_TRUE(
Victor Costan1dcd6752018-03-16 12:31:362171 this->SetCookie(cs, this->http_www_foo_.url(), "xyz=zyx1; path=/"));
Victor Costanf8cb27d2018-02-21 09:16:232172 EXPECT_TRUE(
Victor Costan1dcd6752018-03-16 12:31:362173 this->SetCookie(cs, this->http_bar_com_.url(), "abc=def1; path=/"));
Victor Costaned602f52018-03-01 22:48:532174 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(),
Victor Costan1dcd6752018-03-16 12:31:362175 "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 Costaned602f52018-03-01 22:48:532183 EXPECT_EQ(3u, cookie_changes.size());
Victor Costanf8cb27d2018-02-21 09:16:232184 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 Costan1dcd6752018-03-16 12:31:362189 this->SetCookie(cs, this->http_www_foo_.url(), "xyz=zyx2; path=/"));
Victor Costanf8cb27d2018-02-21 09:16:232190 EXPECT_TRUE(
Victor Costan1dcd6752018-03-16 12:31:362191 this->SetCookie(cs, this->http_bar_com_.url(), "abc=def2; path=/"));
Victor Costaned602f52018-03-01 22:48:532192 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(),
Victor Costan1dcd6752018-03-16 12:31:362193 "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 Costanf8cb27d2018-02-21 09:16:232201
Victor Costaned602f52018-03-01 22:48:532202 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552203 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 Costan1dcd6752018-03-16 12:31:362208 EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
Lily Chen19cced422019-10-17 21:45:552209 cookie_changes[0].cause));
Victor Costanf8cb27d2018-02-21 09:16:232210
Victor Costaned602f52018-03-01 22:48:532211 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552212 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 Costanf8cb27d2018-02-21 09:16:232219
Victor Costaned602f52018-03-01 22:48:532220 ASSERT_LE(3u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552221 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 Costan1dcd6752018-03-16 12:31:362226 EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
Lily Chen19cced422019-10-17 21:45:552227 cookie_changes[2].cause));
Victor Costanf8cb27d2018-02-21 09:16:232228
Victor Costaned602f52018-03-01 22:48:532229 ASSERT_LE(4u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552230 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 Costaned602f52018-03-01 22:48:532237
2238 ASSERT_LE(5u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552239 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 Costan1dcd6752018-03-16 12:31:362243 EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
Lily Chen19cced422019-10-17 21:45:552244 cookie_changes[4].cause));
Victor Costaned602f52018-03-01 22:48:532245
2246 ASSERT_LE(6u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552247 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 Costaned602f52018-03-01 22:48:532253
2254 EXPECT_EQ(6u, cookie_changes.size());
Victor Costanf8cb27d2018-02-21 09:16:232255}
2256
Victor Costaned602f52018-03-01 22:48:532257TYPED_TEST_P(CookieStoreChangeNamedTest, OverwriteWithHttpOnly) {
Victor Costanf8cb27d2018-02-21 09:16:232258 if (!TypeParam::supports_named_cookie_tracking)
2259 return;
2260
Victor Costan2a1891672018-03-02 06:01:532261 // Insert a cookie "abc" for path "/foo".
Victor Costanf8cb27d2018-02-21 09:16:232262 CookieStore* cs = this->GetCookieStore();
Lily Chen19cced422019-10-17 21:45:552263 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:242264 std::unique_ptr<CookieChangeSubscription> subscription =
2265 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232266 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482267 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362268 base::BindRepeating(
2269 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2270 base::Unretained(&cookie_changes)));
2271 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232272 ASSERT_EQ(0u, cookie_changes.size());
2273
2274 EXPECT_TRUE(
2275 this->SetCookie(cs, this->http_www_foo_.url(), "abc=def; path=/foo"));
Victor Costan1dcd6752018-03-16 12:31:362276 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232277 ASSERT_EQ(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552278 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 Costanf8cb27d2018-02-21 09:16:232285 cookie_changes.clear();
2286
Victor Costan2a1891672018-03-02 06:01:532287 // Insert a cookie "a" for path "/foo", that is httponly. This should
Victor Costanf8cb27d2018-02-21 09:16:232288 // overwrite the non-http-only version.
2289 CookieOptions allow_httponly;
2290 allow_httponly.set_include_httponly();
Maks Orlovich21845bc2019-10-21 22:02:232291 allow_httponly.set_same_site_cookie_context(
Steven Bingler8d76c2a42020-03-24 17:13:322292 net::CookieOptions::SameSiteCookieContext::MakeInclusive());
Maks Orlovich21845bc2019-10-21 22:02:232293
Lily Chen0f208ea2019-08-08 23:37:532294 EXPECT_TRUE(this->CreateAndSetCookie(cs, this->http_www_foo_.url(),
2295 "abc=hij; path=/foo; httponly",
2296 allow_httponly));
Victor Costan1dcd6752018-03-16 12:31:362297 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:532298
2299 ASSERT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552300 EXPECT_EQ(this->http_www_foo_.url().host(),
2301 cookie_changes[0].cookie.Domain());
Victor Costan1dcd6752018-03-16 12:31:362302 EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
Lily Chen19cced422019-10-17 21:45:552303 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 Costaned602f52018-03-01 22:48:532307
2308 ASSERT_LE(2u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552309 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 Costaned602f52018-03-01 22:48:532316
2317 EXPECT_EQ(2u, cookie_changes.size());
Victor Costanf8cb27d2018-02-21 09:16:232318}
2319
Victor Costaned602f52018-03-01 22:48:532320TYPED_TEST_P(CookieStoreChangeNamedTest, Deregister) {
Victor Costanf8cb27d2018-02-21 09:16:232321 if (!TypeParam::supports_named_cookie_tracking)
2322 return;
2323
2324 CookieStore* cs = this->GetCookieStore();
2325
Lily Chen19cced422019-10-17 21:45:552326 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:242327 std::unique_ptr<CookieChangeSubscription> subscription =
2328 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232329 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482330 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362331 base::BindRepeating(
2332 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2333 base::Unretained(&cookie_changes)));
2334 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232335 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 Costan1dcd6752018-03-16 12:31:362340 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232341 ASSERT_EQ(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552342 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 Costanf8cb27d2018-02-21 09:16:232345 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 Costan1dcd6752018-03-16 12:31:362353 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232354
2355 EXPECT_EQ(0u, cookie_changes.size());
2356}
2357
Victor Costaned602f52018-03-01 22:48:532358TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterMultiple) {
Victor Costanf8cb27d2018-02-21 09:16:232359 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 Chen19cced422019-10-17 21:45:552366 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan14f47c12018-03-01 08:02:242367 std::unique_ptr<CookieChangeSubscription> subscription1 =
2368 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232369 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482370 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362371 base::BindRepeating(
2372 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2373 base::Unretained(&cookie_changes_1)));
Victor Costan14f47c12018-03-01 08:02:242374 std::unique_ptr<CookieChangeSubscription> subscription2 =
2375 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232376 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482377 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362378 base::BindRepeating(
2379 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2380 base::Unretained(&cookie_changes_2)));
2381 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232382 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 Costan1dcd6752018-03-16 12:31:362388 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232389 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:552390 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 Costanf8cb27d2018-02-21 09:16:232393 cookie_changes_1.clear();
2394
2395 ASSERT_EQ(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:552396 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 Costanf8cb27d2018-02-21 09:16:232399 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 Costan1dcd6752018-03-16 12:31:362408 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232409 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:552410 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 Costanf8cb27d2018-02-21 09:16:232413
2414 EXPECT_EQ(0u, cookie_changes_2.size());
2415}
2416
Victor Costaned602f52018-03-01 22:48:532417// Confirm that a listener does not receive notifications for changes that
2418// happened right before the subscription was established.
2419TYPED_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 Costan1dcd6752018-03-16 12:31:362428 // DeliverChangeNotifications() must NOT be called before the subscription is
2429 // established.
Victor Costaned602f52018-03-01 22:48:532430
Lily Chen19cced422019-10-17 21:45:552431 std::vector<CookieChangeInfo> cookie_changes;
Victor Costaned602f52018-03-01 22:48:532432 std::unique_ptr<CookieChangeSubscription> subscription =
2433 cs->GetChangeDispatcher().AddCallbackForCookie(
2434 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482435 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362436 base::BindRepeating(
2437 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2438 base::Unretained(&cookie_changes)));
Victor Costaned602f52018-03-01 22:48:532439
2440 EXPECT_TRUE(
2441 this->SetCookie(cs, this->http_www_foo_.url(), "abc=hij; path=/"));
Victor Costan1dcd6752018-03-16 12:31:362442 this->DeliverChangeNotifications();
Victor Costaned602f52018-03-01 22:48:532443
2444 EXPECT_LE(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552445 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 Costaned602f52018-03-01 22:48:532448
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.
2455TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterRace) {
Victor Costanf8cb27d2018-02-21 09:16:232456 if (!TypeParam::supports_named_cookie_tracking)
2457 return;
2458
2459 CookieStore* cs = this->GetCookieStore();
2460
Lily Chen19cced422019-10-17 21:45:552461 std::vector<CookieChangeInfo> cookie_changes;
Victor Costan14f47c12018-03-01 08:02:242462 std::unique_ptr<CookieChangeSubscription> subscription =
2463 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232464 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482465 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362466 base::BindRepeating(
2467 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2468 base::Unretained(&cookie_changes)));
2469 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232470 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 Costan1dcd6752018-03-16 12:31:362475 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232476 ASSERT_EQ(1u, cookie_changes.size());
Lily Chen19cced422019-10-17 21:45:552477 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 Costanf8cb27d2018-02-21 09:16:232480 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 Costan1dcd6752018-03-16 12:31:362498 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232499 ASSERT_EQ(0u, cookie_changes.size());
2500}
2501
Victor Costaned602f52018-03-01 22:48:532502TYPED_TEST_P(CookieStoreChangeNamedTest, DeregisterRaceMultiple) {
Victor Costanf8cb27d2018-02-21 09:16:232503 if (!TypeParam::supports_named_cookie_tracking ||
2504 !TypeParam::supports_multiple_tracking_callbacks)
2505 return;
2506
2507 CookieStore* cs = this->GetCookieStore();
2508
Lily Chen19cced422019-10-17 21:45:552509 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan14f47c12018-03-01 08:02:242510 std::unique_ptr<CookieChangeSubscription> subscription1 =
2511 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232512 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482513 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362514 base::BindRepeating(
2515 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2516 base::Unretained(&cookie_changes_1)));
Victor Costan14f47c12018-03-01 08:02:242517 std::unique_ptr<CookieChangeSubscription> subscription2 =
2518 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232519 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482520 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362521 base::BindRepeating(
2522 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2523 base::Unretained(&cookie_changes_2)));
2524 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232525 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 Costan1dcd6752018-03-16 12:31:362531 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232532
2533 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:552534 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 Costanf8cb27d2018-02-21 09:16:232537 cookie_changes_1.clear();
2538
2539 ASSERT_EQ(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:552540 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 Costanf8cb27d2018-02-21 09:16:232543 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 Costaned602f52018-03-01 22:48:532553 if (1u == cookie_changes_2.size())
Victor Costanf8cb27d2018-02-21 09:16:232554 return;
Victor Costanf8cb27d2018-02-21 09:16:232555
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 Costan1dcd6752018-03-16 12:31:362561 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232562 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:552563 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 Costanf8cb27d2018-02-21 09:16:232566
2567 // No late notification was received.
2568 ASSERT_EQ(0u, cookie_changes_2.size());
2569}
2570
Victor Costaned602f52018-03-01 22:48:532571TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsDisjoint) {
Victor Costanf8cb27d2018-02-21 09:16:232572 if (!TypeParam::supports_named_cookie_tracking)
2573 return;
2574
2575 CookieStore* cs = this->GetCookieStore();
2576
Lily Chen19cced422019-10-17 21:45:552577 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan14f47c12018-03-01 08:02:242578 std::unique_ptr<CookieChangeSubscription> subscription1 =
2579 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232580 this->http_www_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482581 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362582 base::BindRepeating(
2583 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2584 base::Unretained(&cookie_changes_1)));
Victor Costan14f47c12018-03-01 08:02:242585 std::unique_ptr<CookieChangeSubscription> subscription2 =
2586 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232587 this->http_bar_com_.url(), "ghi",
Dylan Cutler7f121542021-09-28 20:41:482588 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362589 base::BindRepeating(
2590 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2591 base::Unretained(&cookie_changes_2)));
2592 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232593 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 Costan1dcd6752018-03-16 12:31:362597 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232598 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 Costan1dcd6752018-03-16 12:31:362602 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232603
2604 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:552605 EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name());
2606 EXPECT_EQ("def", cookie_changes_1[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:232607 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:552608 cookie_changes_1[0].cookie.Domain());
Victor Costanf8cb27d2018-02-21 09:16:232609
2610 ASSERT_EQ(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:552611 EXPECT_EQ("ghi", cookie_changes_2[0].cookie.Name());
2612 EXPECT_EQ("jkl", cookie_changes_2[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:232613 EXPECT_EQ(this->http_bar_com_.url().host(),
Lily Chen19cced422019-10-17 21:45:552614 cookie_changes_2[0].cookie.Domain());
Victor Costanf8cb27d2018-02-21 09:16:232615}
2616
Victor Costaned602f52018-03-01 22:48:532617TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsDomains) {
Victor Costanf8cb27d2018-02-21 09:16:232618 if (!TypeParam::supports_named_cookie_tracking)
2619 return;
2620
2621 CookieStore* cs = this->GetCookieStore();
2622
Lily Chen19cced422019-10-17 21:45:552623 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan14f47c12018-03-01 08:02:242624 std::unique_ptr<CookieChangeSubscription> subscription1 =
2625 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232626 this->http_www_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482627 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362628 base::BindRepeating(
2629 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2630 base::Unretained(&cookie_changes_1)));
Victor Costan14f47c12018-03-01 08:02:242631 std::unique_ptr<CookieChangeSubscription> subscription2 =
2632 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232633 this->http_bar_com_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482634 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362635 base::BindRepeating(
2636 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2637 base::Unretained(&cookie_changes_2)));
2638 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232639 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 Costan1dcd6752018-03-16 12:31:362643 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232644 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 Costan1dcd6752018-03-16 12:31:362648 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232649
2650 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:552651 EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name());
2652 EXPECT_EQ("def", cookie_changes_1[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:232653 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:552654 cookie_changes_1[0].cookie.Domain());
Victor Costanf8cb27d2018-02-21 09:16:232655
2656 ASSERT_EQ(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:552657 EXPECT_EQ("abc", cookie_changes_2[0].cookie.Name());
2658 EXPECT_EQ("ghi", cookie_changes_2[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:232659 EXPECT_EQ(this->http_bar_com_.url().host(),
Lily Chen19cced422019-10-17 21:45:552660 cookie_changes_2[0].cookie.Domain());
Victor Costanf8cb27d2018-02-21 09:16:232661}
2662
Victor Costaned602f52018-03-01 22:48:532663TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsNames) {
Victor Costanf8cb27d2018-02-21 09:16:232664 if (!TypeParam::supports_named_cookie_tracking)
2665 return;
2666
2667 CookieStore* cs = this->GetCookieStore();
2668
Lily Chen19cced422019-10-17 21:45:552669 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan14f47c12018-03-01 08:02:242670 std::unique_ptr<CookieChangeSubscription> subscription1 =
2671 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232672 this->http_www_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482673 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362674 base::BindRepeating(
2675 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2676 base::Unretained(&cookie_changes_1)));
Victor Costan14f47c12018-03-01 08:02:242677 std::unique_ptr<CookieChangeSubscription> subscription2 =
2678 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232679 this->http_www_foo_.url(), "ghi",
Dylan Cutler7f121542021-09-28 20:41:482680 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362681 base::BindRepeating(
2682 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2683 base::Unretained(&cookie_changes_2)));
2684 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232685 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 Costan1dcd6752018-03-16 12:31:362689 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232690 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 Costan1dcd6752018-03-16 12:31:362694 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232695
2696 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:552697 EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name());
2698 EXPECT_EQ("def", cookie_changes_1[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:232699 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:552700 cookie_changes_1[0].cookie.Domain());
Victor Costanf8cb27d2018-02-21 09:16:232701
2702 ASSERT_EQ(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:552703 EXPECT_EQ("ghi", cookie_changes_2[0].cookie.Name());
2704 EXPECT_EQ("jkl", cookie_changes_2[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:232705 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:552706 cookie_changes_2[0].cookie.Domain());
Victor Costanf8cb27d2018-02-21 09:16:232707}
2708
Victor Costaned602f52018-03-01 22:48:532709TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsPaths) {
Victor Costanf8cb27d2018-02-21 09:16:232710 if (!TypeParam::supports_named_cookie_tracking)
2711 return;
2712
2713 CookieStore* cs = this->GetCookieStore();
2714
Lily Chen19cced422019-10-17 21:45:552715 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan14f47c12018-03-01 08:02:242716 std::unique_ptr<CookieChangeSubscription> subscription1 =
2717 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232718 this->http_www_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482719 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362720 base::BindRepeating(
2721 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2722 base::Unretained(&cookie_changes_1)));
Victor Costan14f47c12018-03-01 08:02:242723 std::unique_ptr<CookieChangeSubscription> subscription2 =
2724 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232725 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482726 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362727 base::BindRepeating(
2728 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2729 base::Unretained(&cookie_changes_2)));
2730 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232731 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 Costan1dcd6752018-03-16 12:31:362735 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232736 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 Costan1dcd6752018-03-16 12:31:362741 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232742
2743 ASSERT_EQ(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:552744 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 Costanf8cb27d2018-02-21 09:16:232747 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:552748 cookie_changes_1[0].cookie.Domain());
Victor Costanf8cb27d2018-02-21 09:16:232749
2750 ASSERT_LE(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:552751 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 Costanf8cb27d2018-02-21 09:16:232754 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:552755 cookie_changes_2[0].cookie.Domain());
Victor Costanf8cb27d2018-02-21 09:16:232756
Victor Costaned602f52018-03-01 22:48:532757 ASSERT_LE(2u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:552758 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 Costanf8cb27d2018-02-21 09:16:232761 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:552762 cookie_changes_2[1].cookie.Domain());
Victor Costaned602f52018-03-01 22:48:532763
2764 EXPECT_EQ(2u, cookie_changes_2.size());
Victor Costanf8cb27d2018-02-21 09:16:232765}
2766
Victor Costaned602f52018-03-01 22:48:532767TYPED_TEST_P(CookieStoreChangeNamedTest, DifferentSubscriptionsFiltering) {
Victor Costanf8cb27d2018-02-21 09:16:232768 if (!TypeParam::supports_named_cookie_tracking)
2769 return;
2770
2771 CookieStore* cs = this->GetCookieStore();
2772
Lily Chen19cced422019-10-17 21:45:552773 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
2774 std::vector<CookieChangeInfo> cookie_changes_3, cookie_changes_4;
Victor Costan14f47c12018-03-01 08:02:242775 std::unique_ptr<CookieChangeSubscription> subscription1 =
2776 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232777 this->http_www_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482778 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362779 base::BindRepeating(
2780 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2781 base::Unretained(&cookie_changes_1)));
Victor Costan14f47c12018-03-01 08:02:242782 std::unique_ptr<CookieChangeSubscription> subscription2 =
2783 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232784 this->http_www_foo_.url(), "hij",
Dylan Cutler7f121542021-09-28 20:41:482785 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362786 base::BindRepeating(
2787 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2788 base::Unretained(&cookie_changes_2)));
Victor Costan14f47c12018-03-01 08:02:242789 std::unique_ptr<CookieChangeSubscription> subscription3 =
2790 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232791 this->http_bar_com_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482792 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362793 base::BindRepeating(
2794 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2795 base::Unretained(&cookie_changes_3)));
Victor Costan14f47c12018-03-01 08:02:242796 std::unique_ptr<CookieChangeSubscription> subscription4 =
2797 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232798 this->www_foo_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482799 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362800 base::BindRepeating(
2801 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2802 base::Unretained(&cookie_changes_4)));
2803 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232804 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 Costan1dcd6752018-03-16 12:31:362810 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232811 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 Costan1dcd6752018-03-16 12:31:362818 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232819 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 Costan1dcd6752018-03-16 12:31:362827 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232828 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 Costan1dcd6752018-03-16 12:31:362835 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232836
Victor Costaned602f52018-03-01 22:48:532837 ASSERT_LE(1u, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:552838 EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name());
2839 EXPECT_EQ("def", cookie_changes_1[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:232840 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:552841 cookie_changes_1[0].cookie.Domain());
Victor Costaned602f52018-03-01 22:48:532842 EXPECT_EQ(1u, cookie_changes_1.size());
Victor Costanf8cb27d2018-02-21 09:16:232843
Victor Costaned602f52018-03-01 22:48:532844 ASSERT_LE(1u, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:552845 EXPECT_EQ("hij", cookie_changes_2[0].cookie.Name());
2846 EXPECT_EQ("mno", cookie_changes_2[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:232847 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:552848 cookie_changes_2[0].cookie.Domain());
Victor Costaned602f52018-03-01 22:48:532849 EXPECT_EQ(1u, cookie_changes_2.size());
Victor Costanf8cb27d2018-02-21 09:16:232850
Victor Costaned602f52018-03-01 22:48:532851 ASSERT_LE(1u, cookie_changes_3.size());
Lily Chen19cced422019-10-17 21:45:552852 EXPECT_EQ("abc", cookie_changes_3[0].cookie.Name());
2853 EXPECT_EQ("stu", cookie_changes_3[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:232854 EXPECT_EQ(this->http_bar_com_.url().host(),
Lily Chen19cced422019-10-17 21:45:552855 cookie_changes_3[0].cookie.Domain());
Victor Costaned602f52018-03-01 22:48:532856 EXPECT_EQ(1u, cookie_changes_3.size());
Victor Costanf8cb27d2018-02-21 09:16:232857
2858 ASSERT_LE(1u, cookie_changes_4.size());
Lily Chen19cced422019-10-17 21:45:552859 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 Costanf8cb27d2018-02-21 09:16:232862 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:552863 cookie_changes_4[0].cookie.Domain());
Victor Costanf8cb27d2018-02-21 09:16:232864
Victor Costaned602f52018-03-01 22:48:532865 ASSERT_LE(2u, cookie_changes_4.size());
Lily Chen19cced422019-10-17 21:45:552866 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 Costanf8cb27d2018-02-21 09:16:232869 EXPECT_EQ(this->http_www_foo_.url().host(),
Lily Chen19cced422019-10-17 21:45:552870 cookie_changes_4[1].cookie.Domain());
Victor Costaned602f52018-03-01 22:48:532871
2872 EXPECT_EQ(2u, cookie_changes_4.size());
Victor Costanf8cb27d2018-02-21 09:16:232873}
2874
Victor Costaned602f52018-03-01 22:48:532875TYPED_TEST_P(CookieStoreChangeNamedTest, MultipleSubscriptions) {
Victor Costanf8cb27d2018-02-21 09:16:232876 if (!TypeParam::supports_named_cookie_tracking ||
2877 !TypeParam::supports_multiple_tracking_callbacks)
2878 return;
2879
2880 CookieStore* cs = this->GetCookieStore();
2881
Lily Chen19cced422019-10-17 21:45:552882 std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
Victor Costan14f47c12018-03-01 08:02:242883 std::unique_ptr<CookieChangeSubscription> subscription1 =
2884 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232885 this->http_www_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482886 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362887 base::BindRepeating(
2888 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2889 base::Unretained(&cookie_changes_1)));
Victor Costan14f47c12018-03-01 08:02:242890 std::unique_ptr<CookieChangeSubscription> subscription2 =
2891 cs->GetChangeDispatcher().AddCallbackForCookie(
Victor Costanf8cb27d2018-02-21 09:16:232892 this->http_www_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482893 absl::nullopt /* cookie_partition_key */,
Victor Costan1dcd6752018-03-16 12:31:362894 base::BindRepeating(
2895 &CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
2896 base::Unretained(&cookie_changes_2)));
2897 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232898
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 Costan1dcd6752018-03-16 12:31:362901 this->DeliverChangeNotifications();
Victor Costanf8cb27d2018-02-21 09:16:232902
2903 ASSERT_EQ(1U, cookie_changes_1.size());
Lily Chen19cced422019-10-17 21:45:552904 EXPECT_EQ("abc", cookie_changes_1[0].cookie.Name());
2905 EXPECT_EQ("def", cookie_changes_1[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:232906 cookie_changes_1.clear();
2907
2908 ASSERT_EQ(1U, cookie_changes_2.size());
Lily Chen19cced422019-10-17 21:45:552909 EXPECT_EQ("abc", cookie_changes_2[0].cookie.Name());
2910 EXPECT_EQ("def", cookie_changes_2[0].cookie.Value());
Victor Costanf8cb27d2018-02-21 09:16:232911 cookie_changes_2.clear();
2912}
2913
Sergey Kuznetsov0edf1612018-10-12 14:29:052914TYPED_TEST_P(CookieStoreChangeNamedTest, SubscriptionOutlivesStore) {
2915 if (!TypeParam::supports_named_cookie_tracking)
2916 return;
2917
Lily Chen19cced422019-10-17 21:45:552918 std::vector<CookieChangeInfo> cookie_changes;
Sergey Kuznetsov0edf1612018-10-12 14:29:052919 std::unique_ptr<CookieChangeSubscription> subscription =
2920 this->GetCookieStore()->GetChangeDispatcher().AddCallbackForCookie(
2921 this->http_www_foo_.url(), "abc",
Dylan Cutler7f121542021-09-28 20:41:482922 absl::nullopt /* cookie_partition_key */,
Sergey Kuznetsov0edf1612018-10-12 14:29:052923 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 Chen19cced422019-10-17 21:45:552932TYPED_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 Cutler7f121542021-09-28 20:41:482948 absl::nullopt /* cookie_partition_key */,
Lily Chen19cced422019-10-17 21:45:552949 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 Ishii9f5e72dc2020-07-22 19:43:182961 CookieAccessSemantics::LEGACY,
2962 cookie_changes[0].access_result.access_semantics));
Lily Chen19cced422019-10-17 21:45:552963}
2964
Dylan Cutler7f121542021-09-28 20:41:482965TYPED_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 Cutler6ac1c67a82022-03-31 11:36:162975 CookiePartitionKey::FromURLForTesting(GURL("https://www.foo.com")),
Dylan Cutler7f121542021-09-28 20:41:482976 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 Costan2309ea02019-02-13 21:35:473034REGISTER_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 Chen19cced422019-10-17 21:45:553048 MultipleSubscriptions,
3049 ChangeIncludesCookieAccessSemantics);
Victor Costaned602f52018-03-01 22:48:533050
Victor Costan2309ea02019-02-13 21:35:473051REGISTER_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 Chen19cced422019-10-17 21:45:553072 MultipleSubscriptions,
Dylan Cutler7f121542021-09-28 20:41:483073 ChangeIncludesCookieAccessSemantics,
3074 PartitionedCookies);
Victor Costan2a1891672018-03-02 06:01:533075
Victor Costan2309ea02019-02-13 21:35:473076REGISTER_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 Chen19cced422019-10-17 21:45:553099 SubscriptionOutlivesStore,
Dylan Cutler7f121542021-09-28 20:41:483100 ChangeIncludesCookieAccessSemantics,
3101 PartitionedCookies);
Victor Costanf8cb27d2018-02-21 09:16:233102
3103} // namespace net
3104
Lei Zhang64361922021-04-21 19:43:393105#endif // NET_COOKIES_COOKIE_STORE_CHANGE_UNITTEST_H_