forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookie_store_change_unittest.h
2930 lines (2505 loc) · 118 KB
/
cookie_store_change_unittest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_COOKIES_COOKIE_STORE_CHANGE_UNITTEST_H_
#define NET_COOKIES_COOKIE_STORE_CHANGE_UNITTEST_H_
#include "base/bind.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_change_dispatcher_test_helpers.h"
#include "net/cookies/cookie_constants.h"
#include "net/cookies/cookie_store.h"
#include "net/cookies/cookie_store_unittest.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace net {
namespace {
// Used to sort CookieChanges when testing stores without exact change ordering.
//
// The ordering relation must match the order in which the tests below issue
// cookie calls. Changes to this method should be tested by running the tests
// below with CookieMonsterTestTraits::has_exact_change_ordering set to both
// true and false.
bool CookieChangeLessThan(const CookieChangeInfo& lhs,
const CookieChangeInfo& rhs) {
if (lhs.cookie.Name() != rhs.cookie.Name())
return lhs.cookie.Name() < rhs.cookie.Name();
if (lhs.cookie.Value() != rhs.cookie.Value())
return lhs.cookie.Value() < rhs.cookie.Value();
if (lhs.cookie.Domain() != rhs.cookie.Domain())
return lhs.cookie.Domain() < rhs.cookie.Domain();
return lhs.cause < rhs.cause;
}
} // namespace
// Google Test supports at most 50 tests per typed case, so the tests here are
// broken up into multiple cases.
template <class CookieStoreTestTraits>
class CookieStoreChangeTestBase
: public CookieStoreTest<CookieStoreTestTraits> {
protected:
using CookieStoreTest<CookieStoreTestTraits>::FindAndDeleteCookie;
// Drains all pending tasks on the run loop(s) involved in the test.
void DeliverChangeNotifications() {
CookieStoreTestTraits::DeliverChangeNotifications();
}
bool FindAndDeleteCookie(CookieStore* cs,
const std::string& domain,
const std::string& name,
const std::string& path) {
for (auto& cookie : this->GetAllCookies(cs)) {
if (cookie.Domain() == domain && cookie.Name() == name &&
cookie.Path() == path) {
return this->DeleteCanonicalCookie(cs, cookie);
}
}
return false;
}
// Could be static, but it's actually easier to have it be a member function.
::testing::AssertionResult MatchesCause(CookieChangeCause expected_cause,
CookieChangeCause actual_cause) {
if (!CookieChangeCauseIsDeletion(expected_cause) ||
CookieStoreTestTraits::has_exact_change_cause) {
if (expected_cause == actual_cause)
return ::testing::AssertionSuccess();
return ::testing::AssertionFailure()
<< "expected " << expected_cause << " got " << actual_cause;
}
if (CookieChangeCauseIsDeletion(actual_cause))
return ::testing::AssertionSuccess();
return ::testing::AssertionFailure()
<< "expected a deletion cause, got " << actual_cause;
}
bool IsExpectedAccessSemantics(net::CookieAccessSemantics expected_semantics,
net::CookieAccessSemantics actual_semantics) {
if (CookieStoreTestTraits::supports_cookie_access_semantics)
return expected_semantics == actual_semantics;
return actual_semantics == net::CookieAccessSemantics::UNKNOWN;
}
static void OnCookieChange(std::vector<CookieChangeInfo>* changes,
const CookieChangeInfo& notification) {
if (CookieStoreTestTraits::has_exact_change_ordering) {
changes->push_back(notification);
} else {
// Assumes the vector is sorted before the insertion. If true, the vector
// will remain sorted.
changes->insert(std::upper_bound(changes->begin(), changes->end(),
notification, CookieChangeLessThan),
notification);
}
}
};
template <class CookieStoreTestTraits>
class CookieStoreChangeGlobalTest
: public CookieStoreChangeTestBase<CookieStoreTestTraits> {};
TYPED_TEST_SUITE_P(CookieStoreChangeGlobalTest);
template <class CookieStoreTestTraits>
class CookieStoreChangeUrlTest
: public CookieStoreChangeTestBase<CookieStoreTestTraits> {};
TYPED_TEST_SUITE_P(CookieStoreChangeUrlTest);
template <class CookieStoreTestTraits>
class CookieStoreChangeNamedTest
: public CookieStoreChangeTestBase<CookieStoreTestTraits> {};
TYPED_TEST_SUITE_P(CookieStoreChangeNamedTest);
TYPED_TEST_P(CookieStoreChangeGlobalTest, NoCookie) {
if (!TypeParam::supports_global_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
this->DeliverChangeNotifications();
EXPECT_EQ(0u, cookie_changes.size());
}
TYPED_TEST_P(CookieStoreChangeGlobalTest, InitialCookie) {
if (!TypeParam::supports_global_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
this->SetCookie(cs, this->http_www_foo_.url(), "A=B");
this->DeliverChangeNotifications();
std::unique_ptr<CookieChangeSubscription> subscription(
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes))));
this->DeliverChangeNotifications();
EXPECT_EQ(0u, cookie_changes.size());
}
TYPED_TEST_P(CookieStoreChangeGlobalTest, InsertOne) {
if (!TypeParam::supports_global_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
this->DeliverChangeNotifications();
ASSERT_EQ(0u, cookie_changes.size());
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
this->DeliverChangeNotifications();
ASSERT_EQ(1u, cookie_changes.size());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause));
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[0].cookie.Domain());
EXPECT_EQ("A", cookie_changes[0].cookie.Name());
EXPECT_EQ("B", cookie_changes[0].cookie.Value());
}
TYPED_TEST_P(CookieStoreChangeGlobalTest, InsertMany) {
if (!TypeParam::supports_global_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D"));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F"));
EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "G=H"));
this->DeliverChangeNotifications();
// Check that the cookie changes are dispatched before calling GetCookies.
// This is not an ASSERT because the following expectations produce useful
// debugging information if they fail.
EXPECT_EQ(4u, cookie_changes.size());
EXPECT_EQ("A=B; C=D; E=F", this->GetCookies(cs, this->http_www_foo_.url()));
EXPECT_EQ("G=H", this->GetCookies(cs, this->http_bar_com_.url()));
ASSERT_LE(1u, cookie_changes.size());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause));
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[0].cookie.Domain());
EXPECT_EQ("A", cookie_changes[0].cookie.Name());
EXPECT_EQ("B", cookie_changes[0].cookie.Value());
ASSERT_LE(2u, cookie_changes.size());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[1].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause));
EXPECT_EQ("C", cookie_changes[1].cookie.Name());
EXPECT_EQ("D", cookie_changes[1].cookie.Value());
ASSERT_LE(3u, cookie_changes.size());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[2].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[2].cause));
EXPECT_EQ("E", cookie_changes[2].cookie.Name());
EXPECT_EQ("F", cookie_changes[2].cookie.Value());
ASSERT_LE(4u, cookie_changes.size());
EXPECT_EQ(this->http_bar_com_.url().host(),
cookie_changes[3].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[3].cause));
EXPECT_EQ("G", cookie_changes[3].cookie.Name());
EXPECT_EQ("H", cookie_changes[3].cookie.Value());
EXPECT_EQ(4u, cookie_changes.size());
}
TYPED_TEST_P(CookieStoreChangeGlobalTest, DeleteOne) {
if (!TypeParam::supports_global_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
this->DeliverChangeNotifications();
EXPECT_EQ(1u, cookie_changes.size());
cookie_changes.clear();
EXPECT_TRUE(
this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "A"));
this->DeliverChangeNotifications();
ASSERT_EQ(1u, cookie_changes.size());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[0].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause));
EXPECT_EQ("A", cookie_changes[0].cookie.Name());
EXPECT_EQ("B", cookie_changes[0].cookie.Value());
}
TYPED_TEST_P(CookieStoreChangeGlobalTest, DeleteTwo) {
if (!TypeParam::supports_global_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D"));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F"));
EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "G=H"));
this->DeliverChangeNotifications();
EXPECT_EQ(4u, cookie_changes.size());
cookie_changes.clear();
EXPECT_TRUE(
this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "C"));
EXPECT_TRUE(
this->FindAndDeleteCookie(cs, this->http_bar_com_.url().host(), "G"));
this->DeliverChangeNotifications();
// Check that the cookie changes are dispatched before calling GetCookies.
// This is not an ASSERT because the following expectations produce useful
// debugging information if they fail.
EXPECT_EQ(2u, cookie_changes.size());
EXPECT_EQ("A=B; E=F", this->GetCookies(cs, this->http_www_foo_.url()));
EXPECT_EQ("", this->GetCookies(cs, this->http_bar_com_.url()));
ASSERT_LE(1u, cookie_changes.size());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[0].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause));
EXPECT_EQ("C", cookie_changes[0].cookie.Name());
EXPECT_EQ("D", cookie_changes[0].cookie.Value());
ASSERT_EQ(2u, cookie_changes.size());
EXPECT_EQ(this->http_bar_com_.url().host(),
cookie_changes[1].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[1].cause));
EXPECT_EQ("G", cookie_changes[1].cookie.Name());
EXPECT_EQ("H", cookie_changes[1].cookie.Value());
}
TYPED_TEST_P(CookieStoreChangeGlobalTest, Overwrite) {
if (!TypeParam::supports_global_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
this->DeliverChangeNotifications();
ASSERT_EQ(0u, cookie_changes.size());
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
this->DeliverChangeNotifications();
ASSERT_EQ(1u, cookie_changes.size());
cookie_changes.clear();
// Replacing an existing cookie is actually a two-phase delete + set
// operation, so we get an extra notification.
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=C"));
this->DeliverChangeNotifications();
ASSERT_LE(1u, cookie_changes.size());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[0].cookie.Domain());
EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
cookie_changes[0].cause));
EXPECT_EQ("A", cookie_changes[0].cookie.Name());
EXPECT_EQ("B", cookie_changes[0].cookie.Value());
ASSERT_LE(2u, cookie_changes.size());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[1].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause));
EXPECT_EQ("A", cookie_changes[1].cookie.Name());
EXPECT_EQ("C", cookie_changes[1].cookie.Value());
EXPECT_EQ(2u, cookie_changes.size());
}
TYPED_TEST_P(CookieStoreChangeGlobalTest, OverwriteWithHttpOnly) {
if (!TypeParam::supports_global_cookie_tracking)
return;
// Insert a cookie "A" for path "/path1"
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
this->DeliverChangeNotifications();
ASSERT_EQ(0u, cookie_changes.size());
EXPECT_TRUE(
this->SetCookie(cs, this->http_www_foo_.url(), "A=B; path=/path1"));
this->DeliverChangeNotifications();
ASSERT_EQ(1u, cookie_changes.size());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause));
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[0].cookie.Domain());
EXPECT_EQ("A", cookie_changes[0].cookie.Name());
EXPECT_EQ("B", cookie_changes[0].cookie.Value());
EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly());
cookie_changes.clear();
// Insert a cookie "A" for path "/path1", that is httponly. This should
// overwrite the non-http-only version.
CookieOptions allow_httponly;
allow_httponly.set_include_httponly();
allow_httponly.set_same_site_cookie_context(
net::CookieOptions::SameSiteCookieContext::MakeInclusive());
EXPECT_TRUE(this->CreateAndSetCookie(cs, this->http_www_foo_.url(),
"A=C; path=/path1; httponly",
allow_httponly));
this->DeliverChangeNotifications();
ASSERT_LE(1u, cookie_changes.size());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[0].cookie.Domain());
EXPECT_TRUE(this->MatchesCause(CookieChangeCause::OVERWRITE,
cookie_changes[0].cause));
EXPECT_EQ("A", cookie_changes[0].cookie.Name());
EXPECT_EQ("B", cookie_changes[0].cookie.Value());
EXPECT_FALSE(cookie_changes[0].cookie.IsHttpOnly());
ASSERT_LE(2u, cookie_changes.size());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[1].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause));
EXPECT_EQ("A", cookie_changes[1].cookie.Name());
EXPECT_EQ("C", cookie_changes[1].cookie.Value());
EXPECT_TRUE(cookie_changes[1].cookie.IsHttpOnly());
EXPECT_EQ(2u, cookie_changes.size());
}
TYPED_TEST_P(CookieStoreChangeGlobalTest, Deregister) {
if (!TypeParam::supports_global_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
this->DeliverChangeNotifications();
ASSERT_EQ(0u, cookie_changes.size());
// Insert a cookie and make sure it is seen.
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
this->DeliverChangeNotifications();
ASSERT_EQ(1u, cookie_changes.size());
EXPECT_EQ("A", cookie_changes[0].cookie.Name());
EXPECT_EQ("B", cookie_changes[0].cookie.Value());
cookie_changes.clear();
// De-register the subscription.
subscription.reset();
// Insert a second cookie and make sure that it's not visible.
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D"));
this->DeliverChangeNotifications();
EXPECT_EQ(0u, cookie_changes.size());
}
TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterMultiple) {
if (!TypeParam::supports_global_cookie_tracking ||
!TypeParam::supports_multiple_tracking_callbacks)
return;
CookieStore* cs = this->GetCookieStore();
// Register two subscriptions.
std::vector<CookieChangeInfo> cookie_changes_1;
std::unique_ptr<CookieChangeSubscription> subscription1 =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes_1)));
std::vector<CookieChangeInfo> cookie_changes_2;
std::unique_ptr<CookieChangeSubscription> subscription2 =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes_2)));
this->DeliverChangeNotifications();
ASSERT_EQ(0u, cookie_changes_1.size());
ASSERT_EQ(0u, cookie_changes_2.size());
// Insert a cookie and make sure it's seen.
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
this->DeliverChangeNotifications();
ASSERT_EQ(1u, cookie_changes_1.size());
EXPECT_EQ("A", cookie_changes_1[0].cookie.Name());
EXPECT_EQ("B", cookie_changes_1[0].cookie.Value());
cookie_changes_1.clear();
ASSERT_EQ(1u, cookie_changes_2.size());
EXPECT_EQ("A", cookie_changes_2[0].cookie.Name());
EXPECT_EQ("B", cookie_changes_2[0].cookie.Value());
cookie_changes_2.clear();
// De-register the second subscription.
subscription2.reset();
// Insert a second cookie and make sure that it's only visible in one
// change array.
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D"));
this->DeliverChangeNotifications();
ASSERT_EQ(1u, cookie_changes_1.size());
EXPECT_EQ("C", cookie_changes_1[0].cookie.Name());
EXPECT_EQ("D", cookie_changes_1[0].cookie.Value());
cookie_changes_1.clear();
ASSERT_EQ(0u, cookie_changes_2.size());
}
// Confirm that a listener does not receive notifications for changes that
// happened right before the subscription was established.
TYPED_TEST_P(CookieStoreChangeGlobalTest, DispatchRace) {
if (!TypeParam::supports_global_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
// This cookie insertion should not be seen.
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
// DeliverChangeNotifications() must NOT be called before the subscription is
// established.
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D"));
this->DeliverChangeNotifications();
EXPECT_LE(1u, cookie_changes.size());
EXPECT_EQ("C", cookie_changes[0].cookie.Name());
EXPECT_EQ("D", cookie_changes[0].cookie.Value());
ASSERT_EQ(1u, cookie_changes.size());
}
// Confirm that deregistering a subscription blocks the notification if the
// deregistration happened after the change but before the notification was
// received.
TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterRace) {
if (!TypeParam::supports_global_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
this->DeliverChangeNotifications();
ASSERT_EQ(0u, cookie_changes.size());
// Insert a cookie and make sure it's seen.
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
this->DeliverChangeNotifications();
ASSERT_EQ(1u, cookie_changes.size());
EXPECT_EQ("A", cookie_changes[0].cookie.Name());
EXPECT_EQ("B", cookie_changes[0].cookie.Value());
cookie_changes.clear();
// Insert a cookie, confirm it is not seen, deregister the subscription, run
// until idle, and confirm the cookie is still not seen.
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D"));
// Note that by the API contract it's perfectly valid to have received the
// notification immediately, i.e. synchronously with the cookie change. In
// that case, there's nothing to test.
if (1u == cookie_changes.size())
return;
// A task was posted by the SetCookie() above, but has not yet arrived. If it
// arrived before the subscription is destroyed, callback execution would be
// valid. Destroy the subscription so as to lose the race and make sure the
// task posted arrives after the subscription was destroyed.
subscription.reset();
this->DeliverChangeNotifications();
ASSERT_EQ(0u, cookie_changes.size());
}
TYPED_TEST_P(CookieStoreChangeGlobalTest, DeregisterRaceMultiple) {
if (!TypeParam::supports_global_cookie_tracking ||
!TypeParam::supports_multiple_tracking_callbacks)
return;
CookieStore* cs = this->GetCookieStore();
// Register two subscriptions.
std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
std::unique_ptr<CookieChangeSubscription> subscription1 =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes_1)));
std::unique_ptr<CookieChangeSubscription> subscription2 =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes_2)));
this->DeliverChangeNotifications();
ASSERT_EQ(0u, cookie_changes_1.size());
ASSERT_EQ(0u, cookie_changes_2.size());
// Insert a cookie and make sure it's seen.
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
this->DeliverChangeNotifications();
ASSERT_EQ(1u, cookie_changes_1.size());
EXPECT_EQ("A", cookie_changes_1[0].cookie.Name());
EXPECT_EQ("B", cookie_changes_1[0].cookie.Value());
cookie_changes_1.clear();
ASSERT_EQ(1u, cookie_changes_2.size());
EXPECT_EQ("A", cookie_changes_2[0].cookie.Name());
EXPECT_EQ("B", cookie_changes_2[0].cookie.Value());
cookie_changes_2.clear();
// Insert a cookie, confirm it is not seen, deregister a subscription, run
// until idle, and confirm the cookie is still not seen.
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D"));
// Note that by the API contract it's perfectly valid to have received the
// notification immediately, i.e. synchronously with the cookie change. In
// that case, there's nothing to test.
if (1u == cookie_changes_2.size())
return;
// A task was posted by the SetCookie() above, but has not yet arrived. If it
// arrived before the subscription is destroyed, callback execution would be
// valid. Destroy one of the subscriptions so as to lose the race and make
// sure the task posted arrives after the subscription was destroyed.
subscription2.reset();
this->DeliverChangeNotifications();
ASSERT_EQ(1u, cookie_changes_1.size());
EXPECT_EQ("C", cookie_changes_1[0].cookie.Name());
EXPECT_EQ("D", cookie_changes_1[0].cookie.Value());
// No late notification was received.
ASSERT_EQ(0u, cookie_changes_2.size());
}
TYPED_TEST_P(CookieStoreChangeGlobalTest, MultipleSubscriptions) {
if (!TypeParam::supports_global_cookie_tracking ||
!TypeParam::supports_multiple_tracking_callbacks)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes_1, cookie_changes_2;
std::unique_ptr<CookieChangeSubscription> subscription1 =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes_1)));
std::unique_ptr<CookieChangeSubscription> subscription2 =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes_2)));
this->DeliverChangeNotifications();
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
this->DeliverChangeNotifications();
ASSERT_EQ(1U, cookie_changes_1.size());
EXPECT_EQ("A", cookie_changes_1[0].cookie.Name());
EXPECT_EQ("B", cookie_changes_1[0].cookie.Value());
ASSERT_EQ(1U, cookie_changes_2.size());
EXPECT_EQ("A", cookie_changes_2[0].cookie.Name());
EXPECT_EQ("B", cookie_changes_2[0].cookie.Value());
}
TYPED_TEST_P(CookieStoreChangeGlobalTest, ChangeIncludesCookieAccessSemantics) {
if (!TypeParam::supports_global_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
// if !supports_cookie_access_semantics, the delegate will be stored but will
// not be used.
auto access_delegate = std::make_unique<TestCookieAccessDelegate>();
access_delegate->SetExpectationForCookieDomain("domain1.test",
CookieAccessSemantics::LEGACY);
access_delegate->SetExpectationForCookieDomain(
"domain2.test", CookieAccessSemantics::NONLEGACY);
access_delegate->SetExpectationForCookieDomain(
"domain3.test", CookieAccessSemantics::UNKNOWN);
cs->SetCookieAccessDelegate(std::move(access_delegate));
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForAllChanges(base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
this->CreateAndSetCookie(cs, GURL("http://domain1.test"), "cookie=1",
CookieOptions::MakeAllInclusive());
this->CreateAndSetCookie(cs, GURL("http://domain2.test"), "cookie=1",
CookieOptions::MakeAllInclusive());
this->CreateAndSetCookie(cs, GURL("http://domain3.test"), "cookie=1",
CookieOptions::MakeAllInclusive());
this->CreateAndSetCookie(cs, GURL("http://domain4.test"), "cookie=1",
CookieOptions::MakeAllInclusive());
this->DeliverChangeNotifications();
ASSERT_EQ(4u, cookie_changes.size());
EXPECT_EQ("domain1.test", cookie_changes[0].cookie.Domain());
EXPECT_TRUE(this->IsExpectedAccessSemantics(
CookieAccessSemantics::LEGACY,
cookie_changes[0].access_result.access_semantics));
EXPECT_EQ("domain2.test", cookie_changes[1].cookie.Domain());
EXPECT_TRUE(this->IsExpectedAccessSemantics(
CookieAccessSemantics::NONLEGACY,
cookie_changes[1].access_result.access_semantics));
EXPECT_EQ("domain3.test", cookie_changes[2].cookie.Domain());
EXPECT_TRUE(this->IsExpectedAccessSemantics(
CookieAccessSemantics::UNKNOWN,
cookie_changes[2].access_result.access_semantics));
EXPECT_EQ("domain4.test", cookie_changes[3].cookie.Domain());
EXPECT_TRUE(this->IsExpectedAccessSemantics(
CookieAccessSemantics::UNKNOWN,
cookie_changes[3].access_result.access_semantics));
}
TYPED_TEST_P(CookieStoreChangeUrlTest, NoCookie) {
if (!TypeParam::supports_url_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForUrl(
this->http_www_foo_.url(),
base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
this->DeliverChangeNotifications();
EXPECT_EQ(0u, cookie_changes.size());
}
TYPED_TEST_P(CookieStoreChangeUrlTest, InitialCookie) {
if (!TypeParam::supports_url_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
this->SetCookie(cs, this->http_www_foo_.url(), "A=B");
this->DeliverChangeNotifications();
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForUrl(
this->http_www_foo_.url(),
base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
this->DeliverChangeNotifications();
EXPECT_EQ(0u, cookie_changes.size());
}
TYPED_TEST_P(CookieStoreChangeUrlTest, InsertOne) {
if (!TypeParam::supports_url_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForUrl(
this->http_www_foo_.url(),
base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
this->DeliverChangeNotifications();
ASSERT_EQ(0u, cookie_changes.size());
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
this->DeliverChangeNotifications();
ASSERT_EQ(1u, cookie_changes.size());
EXPECT_EQ("A", cookie_changes[0].cookie.Name());
EXPECT_EQ("B", cookie_changes[0].cookie.Value());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[0].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause));
}
TYPED_TEST_P(CookieStoreChangeUrlTest, InsertMany) {
if (!TypeParam::supports_url_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForUrl(
this->http_www_foo_.url(),
base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D"));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F"));
this->DeliverChangeNotifications();
ASSERT_LE(1u, cookie_changes.size());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause));
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[0].cookie.Domain());
EXPECT_EQ("A", cookie_changes[0].cookie.Name());
EXPECT_EQ("B", cookie_changes[0].cookie.Value());
ASSERT_LE(2u, cookie_changes.size());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[1].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause));
EXPECT_EQ("C", cookie_changes[1].cookie.Name());
EXPECT_EQ("D", cookie_changes[1].cookie.Value());
ASSERT_LE(3u, cookie_changes.size());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[2].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[2].cause));
EXPECT_EQ("E", cookie_changes[2].cookie.Name());
EXPECT_EQ("F", cookie_changes[2].cookie.Value());
EXPECT_EQ(3u, cookie_changes.size());
}
TYPED_TEST_P(CookieStoreChangeUrlTest, InsertFiltering) {
if (!TypeParam::supports_url_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForUrl(
this->www_foo_foo_.url(),
base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
this->DeliverChangeNotifications();
ASSERT_EQ(0u, cookie_changes.size());
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B; path=/"));
EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "C=D; path=/"));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F; path=/bar"));
EXPECT_TRUE(
this->SetCookie(cs, this->http_www_foo_.url(), "G=H; path=/foo/bar"));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "I=J; path=/foo"));
EXPECT_TRUE(
this->SetCookie(cs, this->http_www_foo_.url(), "K=L; domain=foo.com"));
this->DeliverChangeNotifications();
ASSERT_LE(1u, cookie_changes.size());
EXPECT_EQ("A", cookie_changes[0].cookie.Name());
EXPECT_EQ("B", cookie_changes[0].cookie.Value());
EXPECT_EQ("/", cookie_changes[0].cookie.Path());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[0].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[0].cause));
ASSERT_LE(2u, cookie_changes.size());
EXPECT_EQ("I", cookie_changes[1].cookie.Name());
EXPECT_EQ("J", cookie_changes[1].cookie.Value());
EXPECT_EQ("/foo", cookie_changes[1].cookie.Path());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[1].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[1].cause));
ASSERT_LE(3u, cookie_changes.size());
EXPECT_EQ("K", cookie_changes[2].cookie.Name());
EXPECT_EQ("L", cookie_changes[2].cookie.Value());
EXPECT_EQ("/", cookie_changes[2].cookie.Path());
EXPECT_EQ(".foo.com", cookie_changes[2].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::INSERTED, cookie_changes[2].cause));
EXPECT_EQ(3u, cookie_changes.size());
}
TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteOne) {
if (!TypeParam::supports_url_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForUrl(
this->http_www_foo_.url(),
base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
this->DeliverChangeNotifications();
EXPECT_EQ(1u, cookie_changes.size());
cookie_changes.clear();
EXPECT_TRUE(
this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "A"));
this->DeliverChangeNotifications();
ASSERT_EQ(1u, cookie_changes.size());
EXPECT_EQ("A", cookie_changes[0].cookie.Name());
EXPECT_EQ("B", cookie_changes[0].cookie.Value());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[0].cookie.Domain());
ASSERT_TRUE(
this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause));
}
TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteTwo) {
if (!TypeParam::supports_url_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForUrl(
this->http_www_foo_.url(),
base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D"));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F"));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "G=H"));
this->DeliverChangeNotifications();
EXPECT_EQ(4u, cookie_changes.size());
cookie_changes.clear();
EXPECT_TRUE(
this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "C"));
EXPECT_TRUE(
this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "G"));
this->DeliverChangeNotifications();
// Check that the cookie changes are dispatched before calling GetCookies.
// This is not an ASSERT because the following expectations produce useful
// debugging information if they fail.
EXPECT_EQ(2u, cookie_changes.size());
EXPECT_EQ("A=B; E=F", this->GetCookies(cs, this->http_www_foo_.url()));
ASSERT_LE(1u, cookie_changes.size());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[0].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause));
EXPECT_EQ("C", cookie_changes[0].cookie.Name());
EXPECT_EQ("D", cookie_changes[0].cookie.Value());
ASSERT_EQ(2u, cookie_changes.size());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[1].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[1].cause));
EXPECT_EQ("G", cookie_changes[1].cookie.Name());
EXPECT_EQ("H", cookie_changes[1].cookie.Value());
}
TYPED_TEST_P(CookieStoreChangeUrlTest, DeleteFiltering) {
if (!TypeParam::supports_url_cookie_tracking)
return;
CookieStore* cs = this->GetCookieStore();
std::vector<CookieChangeInfo> cookie_changes;
std::unique_ptr<CookieChangeSubscription> subscription =
cs->GetChangeDispatcher().AddCallbackForUrl(
this->www_foo_foo_.url(),
base::BindRepeating(
&CookieStoreChangeTestBase<TypeParam>::OnCookieChange,
base::Unretained(&cookie_changes)));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B; path=/"));
EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "C=D; path=/"));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "E=F; path=/bar"));
EXPECT_TRUE(
this->SetCookie(cs, this->http_www_foo_.url(), "G=H; path=/foo/bar"));
EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "I=J; path=/foo"));
EXPECT_TRUE(
this->SetCookie(cs, this->http_www_foo_.url(), "K=L; domain=foo.com"));
this->DeliverChangeNotifications();
EXPECT_EQ(3u, cookie_changes.size());
cookie_changes.clear();
EXPECT_TRUE(
this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "A"));
EXPECT_TRUE(
this->FindAndDeleteCookie(cs, this->http_bar_com_.url().host(), "C"));
EXPECT_TRUE(
this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "E"));
EXPECT_TRUE(
this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "G"));
EXPECT_TRUE(
this->FindAndDeleteCookie(cs, this->http_www_foo_.url().host(), "I"));
EXPECT_TRUE(this->FindAndDeleteCookie(cs, ".foo.com", "K"));
this->DeliverChangeNotifications();
ASSERT_LE(1u, cookie_changes.size());
EXPECT_EQ("A", cookie_changes[0].cookie.Name());
EXPECT_EQ("B", cookie_changes[0].cookie.Value());
EXPECT_EQ("/", cookie_changes[0].cookie.Path());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[0].cookie.Domain());
EXPECT_TRUE(
this->MatchesCause(CookieChangeCause::EXPLICIT, cookie_changes[0].cause));
ASSERT_LE(2u, cookie_changes.size());
EXPECT_EQ("I", cookie_changes[1].cookie.Name());
EXPECT_EQ("J", cookie_changes[1].cookie.Value());
EXPECT_EQ("/foo", cookie_changes[1].cookie.Path());
EXPECT_EQ(this->http_www_foo_.url().host(),
cookie_changes[1].cookie.Domain());
EXPECT_TRUE(