Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: net/cookies/cookie_monster_unittest.cc

Issue 1844243002: [CookieStore] Upgrading host-based deleting to predicate-based deleting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments, and ios Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/cookies/cookie_store_unittest.h" 5 #include "net/cookies/cookie_store_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 virtual void Flush(const base::Closure& callback) { 57 virtual void Flush(const base::Closure& callback) {
58 if (!callback.is_null()) 58 if (!callback.is_null())
59 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 59 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
60 } 60 }
61 MOCK_METHOD0(SetForceKeepSessionState, void()); 61 MOCK_METHOD0(SetForceKeepSessionState, void());
62 62
63 private: 63 private:
64 virtual ~NewMockPersistentCookieStore() {} 64 virtual ~NewMockPersistentCookieStore() {}
65 }; 65 };
66 66
67 // False means 'less than or equal', so we test both ways for full equal.
68 MATCHER_P(CookieEquals, expected, "") {
69 return !(arg.FullCompare(expected) || expected.FullCompare(arg));
70 }
71
67 const char kTopLevelDomainPlus1[] = "http://www.harvard.edu"; 72 const char kTopLevelDomainPlus1[] = "http://www.harvard.edu";
68 const char kTopLevelDomainPlus2[] = "http://www.math.harvard.edu"; 73 const char kTopLevelDomainPlus2[] = "http://www.math.harvard.edu";
69 const char kTopLevelDomainPlus2Secure[] = "https://www.math.harvard.edu"; 74 const char kTopLevelDomainPlus2Secure[] = "https://www.math.harvard.edu";
70 const char kTopLevelDomainPlus3[] = "http://www.bourbaki.math.harvard.edu"; 75 const char kTopLevelDomainPlus3[] = "http://www.bourbaki.math.harvard.edu";
71 const char kOtherDomain[] = "http://www.mit.edu"; 76 const char kOtherDomain[] = "http://www.mit.edu";
72 77
78 bool AlwaysTrueCookiePredicate(CanonicalCookie* to_save,
79 const CanonicalCookie& cookie) {
80 if (to_save)
81 *to_save = cookie;
82 return true;
83 }
84
85 bool AlwaysFalseCookiePredicate(CanonicalCookie* to_save,
86 const CanonicalCookie& cookie) {
87 if (to_save)
88 *to_save = cookie;
89 return false;
90 }
91
73 struct CookieMonsterTestTraits { 92 struct CookieMonsterTestTraits {
74 static scoped_ptr<CookieStore> Create() { 93 static scoped_ptr<CookieStore> Create() {
75 return make_scoped_ptr(new CookieMonster(nullptr, nullptr)); 94 return make_scoped_ptr(new CookieMonster(nullptr, nullptr));
76 } 95 }
77 96
78 static const bool supports_http_only = true; 97 static const bool supports_http_only = true;
79 static const bool supports_non_dotted_domains = true; 98 static const bool supports_non_dotted_domains = true;
80 static const bool preserves_trailing_dots = true; 99 static const bool preserves_trailing_dots = true;
81 static const bool filters_schemes = true; 100 static const bool filters_schemes = true;
82 static const bool has_path_prefix_bug = false; 101 static const bool has_path_prefix_bug = false;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 DCHECK(cm); 162 DCHECK(cm);
144 ResultSavingCookieCallback<int> callback; 163 ResultSavingCookieCallback<int> callback;
145 cm->DeleteAllCreatedBetweenAsync( 164 cm->DeleteAllCreatedBetweenAsync(
146 delete_begin, delete_end, 165 delete_begin, delete_end,
147 base::Bind(&ResultSavingCookieCallback<int>::Run, 166 base::Bind(&ResultSavingCookieCallback<int>::Run,
148 base::Unretained(&callback))); 167 base::Unretained(&callback)));
149 callback.WaitUntilDone(); 168 callback.WaitUntilDone();
150 return callback.result(); 169 return callback.result();
151 } 170 }
152 171
153 int DeleteAllCreatedBetweenForHost(CookieMonster* cm, 172 int DeleteAllCreatedBetweenWithPredicate(
154 const base::Time delete_begin, 173 CookieMonster* cm,
155 const base::Time delete_end, 174 const base::Time delete_begin,
156 const GURL& url) { 175 const base::Time delete_end,
176 const base::Callback<bool(const CanonicalCookie&)>& predicate) {
157 DCHECK(cm); 177 DCHECK(cm);
158 ResultSavingCookieCallback<int> callback; 178 ResultSavingCookieCallback<int> callback;
159 cm->DeleteAllCreatedBetweenForHostAsync( 179 cm->DeleteAllCreatedBetweenWithPredicateAsync(
160 delete_begin, delete_end, url, 180 delete_begin, delete_end, predicate,
161 base::Bind(&ResultSavingCookieCallback<int>::Run, 181 base::Bind(&ResultSavingCookieCallback<int>::Run,
162 base::Unretained(&callback))); 182 base::Unretained(&callback)));
163 callback.WaitUntilDone(); 183 callback.WaitUntilDone();
164 return callback.result(); 184 return callback.result();
165 } 185 }
166 186
167 // Helper for DeleteAllForHost test; repopulates CM with same layout 187 // Helper for DeleteAllForHost test; repopulates CM with same layout
168 // each time. 188 // each time.
169 void PopulateCmForDeleteAllForHost(CookieMonster* cm) { 189 void PopulateCmForDeleteAllForHost(CookieMonster* cm) {
170 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); 190 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1);
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 cc.url, cc.name, cc.value, cc.domain, cc.path, base::Time(), 680 cc.url, cc.name, cc.value, cc.domain, cc.path, base::Time(),
661 cc.expiration_time, base::Time(), cc.secure, cc.http_only, cc.same_site, 681 cc.expiration_time, base::Time(), cc.secure, cc.http_only, cc.same_site,
662 false /* enforces strict secure cookies */, cc.priority, 682 false /* enforces strict secure cookies */, cc.priority,
663 callback->AsCallback()); 683 callback->AsCallback());
664 } 684 }
665 685
666 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { 686 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) {
667 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); 687 cookie_monster->GetAllCookiesAsync(callback->AsCallback());
668 } 688 }
669 689
670 ACTION_P5(DeleteAllCreatedBetweenForHostAction, 690 ACTION_P5(DeleteAllCreatedBetweenWithPredicateAction,
671 cookie_monster, 691 cookie_monster,
672 delete_begin, 692 delete_begin,
673 delete_end, 693 delete_end,
674 url, 694 predicate,
675 callback) { 695 callback) {
676 cookie_monster->DeleteAllCreatedBetweenForHostAsync( 696 cookie_monster->DeleteAllCreatedBetweenWithPredicateAsync(
677 delete_begin, delete_end, url, callback->AsCallback()); 697 delete_begin, delete_end, predicate, callback->AsCallback());
678 } 698 }
679 699
680 ACTION_P3(DeleteCanonicalCookieAction, cookie_monster, cookie, callback) { 700 ACTION_P3(DeleteCanonicalCookieAction, cookie_monster, cookie, callback) {
681 cookie_monster->DeleteCanonicalCookieAsync(cookie, callback->AsCallback()); 701 cookie_monster->DeleteCanonicalCookieAsync(cookie, callback->AsCallback());
682 } 702 }
683 703
684 ACTION_P2(DeleteAllAction, cookie_monster, callback) { 704 ACTION_P2(DeleteAllAction, cookie_monster, callback) {
685 cookie_monster->DeleteAllAsync(callback->AsCallback()); 705 cookie_monster->DeleteAllAsync(callback->AsCallback());
686 } 706 }
687 707
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 .WillOnce(DeleteAllCreatedBetweenAction(&cookie_monster(), base::Time(), 1063 .WillOnce(DeleteAllCreatedBetweenAction(&cookie_monster(), base::Time(),
1044 base::Time::Now(), 1064 base::Time::Now(),
1045 &delete_callback)); 1065 &delete_callback));
1046 base::RunLoop loop; 1066 base::RunLoop loop;
1047 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop)); 1067 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop));
1048 1068
1049 CompleteLoading(); 1069 CompleteLoading();
1050 loop.Run(); 1070 loop.Run();
1051 } 1071 }
1052 1072
1053 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCreatedBetweenCookies) { 1073 TEST_F(DeferredCookieTaskTest,
1074 DeferredDeleteAllWithPredicateCreatedBetweenCookies) {
1054 MockDeleteCallback delete_callback; 1075 MockDeleteCallback delete_callback;
1055 1076
1056 BeginWithForDomainKey(http_www_google_.domain(), 1077 base::Callback<bool(const CanonicalCookie&)> predicate =
1057 DeleteAllCreatedBetweenForHostAction( 1078 base::Bind(&AlwaysTrueCookiePredicate, nullptr);
1058 &cookie_monster(), base::Time(), base::Time::Now(), 1079
1059 http_www_google_.url(), &delete_callback)); 1080 BeginWith(DeleteAllCreatedBetweenWithPredicateAction(
1081 &cookie_monster(), base::Time(), base::Time::Now(), predicate,
1082 &delete_callback));
1060 1083
1061 WaitForLoadCall(); 1084 WaitForLoadCall();
1062 1085
1063 EXPECT_CALL(delete_callback, Invoke(false)) 1086 EXPECT_CALL(delete_callback, Invoke(false))
1064 .WillOnce(DeleteAllCreatedBetweenForHostAction( 1087 .WillOnce(DeleteAllCreatedBetweenWithPredicateAction(
1065 &cookie_monster(), base::Time(), base::Time::Now(), 1088 &cookie_monster(), base::Time(), base::Time::Now(), predicate,
1066 http_www_google_.url(), &delete_callback)); 1089 &delete_callback));
1067 base::RunLoop loop; 1090 base::RunLoop loop;
1068 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop)); 1091 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop));
1069 1092
1070 CompleteLoading(); 1093 CompleteLoading();
1071 loop.Run(); 1094 loop.Run();
1072 } 1095 }
1073 1096
1074 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { 1097 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) {
1075 std::vector<CanonicalCookie*> cookies; 1098 std::vector<CanonicalCookie*> cookies;
1076 CanonicalCookie cookie = BuildCanonicalCookie( 1099 CanonicalCookie cookie = BuildCanonicalCookie(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 } 1203 }
1181 1204
1182 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { 1205 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) {
1183 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); 1206 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr));
1184 Time now = Time::Now(); 1207 Time now = Time::Now();
1185 1208
1186 // Nothing has been added so nothing should be deleted. 1209 // Nothing has been added so nothing should be deleted.
1187 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), 1210 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99),
1188 Time())); 1211 Time()));
1189 1212
1190 // Create 3 cookies with creation date of today, yesterday and the day before. 1213 // Create 5 cookies with different creation dates.
1191 EXPECT_TRUE( 1214 EXPECT_TRUE(
1192 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now)); 1215 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now));
1193 EXPECT_TRUE(cm->SetCookieWithCreationTime( 1216 EXPECT_TRUE(cm->SetCookieWithCreationTime(
1194 http_www_google_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); 1217 http_www_google_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1)));
1195 EXPECT_TRUE(cm->SetCookieWithCreationTime( 1218 EXPECT_TRUE(cm->SetCookieWithCreationTime(
1196 http_www_google_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); 1219 http_www_google_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2)));
1197 EXPECT_TRUE(cm->SetCookieWithCreationTime( 1220 EXPECT_TRUE(cm->SetCookieWithCreationTime(
1198 http_www_google_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); 1221 http_www_google_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3)));
1199 EXPECT_TRUE(cm->SetCookieWithCreationTime( 1222 EXPECT_TRUE(cm->SetCookieWithCreationTime(
1200 http_www_google_.url(), "T-7=LastWeek", now - TimeDelta::FromDays(7))); 1223 http_www_google_.url(), "T-7=LastWeek", now - TimeDelta::FromDays(7)));
(...skipping 11 matching lines...) Expand all
1212 EXPECT_EQ( 1235 EXPECT_EQ(
1213 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(7), now)); 1236 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(7), now));
1214 1237
1215 // Delete the last (now) item. 1238 // Delete the last (now) item.
1216 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time())); 1239 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time()));
1217 1240
1218 // Really make sure everything is gone. 1241 // Really make sure everything is gone.
1219 EXPECT_EQ(0, DeleteAll(cm.get())); 1242 EXPECT_EQ(0, DeleteAll(cm.get()));
1220 } 1243 }
1221 1244
1245 TEST_F(CookieMonsterTest,
1246 TestCookieDeleteAllCreatedBetweenTimestampsWithPredicate) {
1247 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr));
1248 Time now = Time::Now();
1249
1250 CanonicalCookie test_cookie;
1251 base::Callback<bool(const CanonicalCookie&)> true_predicate =
1252 base::Bind(&AlwaysTrueCookiePredicate, &test_cookie);
1253
1254 base::Callback<bool(const CanonicalCookie&)> false_predicate =
1255 base::Bind(&AlwaysFalseCookiePredicate, &test_cookie);
1256
1257 // Nothing has been added so nothing should be deleted.
1258 EXPECT_EQ(
1259 0, DeleteAllCreatedBetweenWithPredicate(
1260 cm.get(), now - TimeDelta::FromDays(99), Time(), true_predicate));
1261
1262 // Create 5 cookies with different creation dates.
1263 EXPECT_TRUE(
1264 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now));
1265 EXPECT_TRUE(cm->SetCookieWithCreationTime(
1266 http_www_google_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1)));
1267 EXPECT_TRUE(cm->SetCookieWithCreationTime(
1268 http_www_google_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2)));
1269 EXPECT_TRUE(cm->SetCookieWithCreationTime(
1270 http_www_google_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3)));
1271 EXPECT_TRUE(cm->SetCookieWithCreationTime(
1272 http_www_google_.url(), "T-7=LastWeek", now - TimeDelta::FromDays(7)));
1273
Mike West 2016/04/02 05:12:40 Nit: Could you add a test for a null predicate her
dmurph 2016/04/04 18:28:32 Sure. This also is tested by the cookie_store_unit
1274 // Try to delete threedays and the daybefore, but we should do nothing due
1275 // to the predicate.
1276 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate(
1277 cm.get(), now - TimeDelta::FromDays(3),
1278 now - TimeDelta::FromDays(1), false_predicate));
1279 // Same as above, but we use the true_predicate, so it works.
1280 EXPECT_EQ(2, DeleteAllCreatedBetweenWithPredicate(
1281 cm.get(), now - TimeDelta::FromDays(3),
1282 now - TimeDelta::FromDays(1), true_predicate));
1283
1284 // Try to delete yesterday, also make sure that delete_end is not
1285 // inclusive.
1286 EXPECT_EQ(0,
1287 DeleteAllCreatedBetweenWithPredicate(
1288 cm.get(), now - TimeDelta::FromDays(2), now, false_predicate));
1289 EXPECT_EQ(1,
1290 DeleteAllCreatedBetweenWithPredicate(
1291 cm.get(), now - TimeDelta::FromDays(2), now, true_predicate));
1292 // Check our cookie values.
1293 scoped_ptr<CanonicalCookie> expected_cookie =
1294 CanonicalCookie::Create(http_www_google_.url(), "T-1=Yesterday",
1295 now - TimeDelta::FromDays(1), CookieOptions());
1296 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie))
1297 << "Actual:\n"
1298 << test_cookie.DebugString() << "\nExpected:\n"
1299 << expected_cookie->DebugString();
1300
1301 // Make sure the delete_begin is inclusive.
1302 EXPECT_EQ(0,
1303 DeleteAllCreatedBetweenWithPredicate(
1304 cm.get(), now - TimeDelta::FromDays(7), now, false_predicate));
1305 EXPECT_EQ(1,
1306 DeleteAllCreatedBetweenWithPredicate(
1307 cm.get(), now - TimeDelta::FromDays(7), now, true_predicate));
1308
1309 // Delete the last (now) item.
1310 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate(cm.get(), Time(), Time(),
1311 false_predicate));
1312 EXPECT_EQ(1, DeleteAllCreatedBetweenWithPredicate(cm.get(), Time(), Time(),
1313 true_predicate));
1314 expected_cookie = CanonicalCookie::Create(http_www_google_.url(), "T-0=Now",
1315 now, CookieOptions());
1316 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie))
1317 << "Actual:\n"
1318 << test_cookie.DebugString() << "\nExpected:\n"
1319 << expected_cookie->DebugString();
1320
1321 // Really make sure everything is gone.
1322 EXPECT_EQ(0, DeleteAll(cm.get()));
1323 }
1324
1222 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20; 1325 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20;
1223 1326
1224 TEST_F(CookieMonsterTest, TestLastAccess) { 1327 TEST_F(CookieMonsterTest, TestLastAccess) {
1225 scoped_ptr<CookieMonster> cm( 1328 scoped_ptr<CookieMonster> cm(
1226 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds)); 1329 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds));
1227 1330
1228 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); 1331 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
1229 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); 1332 const Time last_access_date(GetFirstCookieAccessDate(cm.get()));
1230 1333
1231 // Reading the cookie again immediately shouldn't update the access date, 1334 // Reading the cookie again immediately shouldn't update the access date,
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 EXPECT_EQ("a", delegate->changes()[0].first.Name()); 1739 EXPECT_EQ("a", delegate->changes()[0].first.Name());
1637 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); 1740 EXPECT_EQ("val1", delegate->changes()[0].first.Value());
1638 EXPECT_EQ(http_www_google_.url().host(), 1741 EXPECT_EQ(http_www_google_.url().host(),
1639 delegate->changes()[1].first.Domain()); 1742 delegate->changes()[1].first.Domain());
1640 EXPECT_FALSE(delegate->changes()[1].second); 1743 EXPECT_FALSE(delegate->changes()[1].second);
1641 EXPECT_EQ("a", delegate->changes()[1].first.Name()); 1744 EXPECT_EQ("a", delegate->changes()[1].first.Name());
1642 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); 1745 EXPECT_EQ("val2", delegate->changes()[1].first.Value());
1643 delegate->reset(); 1746 delegate->reset();
1644 } 1747 }
1645 1748
1646 TEST_F(CookieMonsterTest, DeleteAllForHost) {
1647 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr));
1648
1649 // Test probes:
1650 // * Non-secure URL, mid-level (http://w.c.b.a)
1651 // * Secure URL, mid-level (https://w.c.b.a)
1652 // * URL with path, mid-level (https:/w.c.b.a/dir1/xx)
1653 // All three tests should nuke only the midlevel host cookie,
1654 // the http_only cookie, the host secure cookie, and the two host
1655 // path cookies. http_only, secure, and paths are ignored by
1656 // this call, and domain cookies arent touched.
1657 PopulateCmForDeleteAllForHost(cm.get());
1658 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
1659 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3)));
1660 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X",
1661 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure)));
1662 EXPECT_EQ("dom_1=X; host_1=X",
1663 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1)));
1664 EXPECT_EQ(
1665 "dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; "
1666 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X",
1667 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure +
1668 std::string("/dir1/dir2/xxx"))));
1669
1670 EXPECT_EQ(6, DeleteAllCreatedBetweenForHost(cm.get(), base::Time(),
1671 base::Time::Now(),
1672 GURL(kTopLevelDomainPlus2)));
1673 EXPECT_EQ(8U, GetAllCookies(cm.get()).size());
1674
1675 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
1676 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3)));
1677 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X",
1678 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure)));
1679 EXPECT_EQ("dom_1=X; host_1=X",
1680 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1)));
1681 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X",
1682 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure +
1683 std::string("/dir1/dir2/xxx"))));
1684
1685 PopulateCmForDeleteAllForHost(cm.get());
1686 EXPECT_EQ(6, DeleteAllCreatedBetweenForHost(
1687 cm.get(), base::Time(), base::Time::Now(),
1688 GURL(kTopLevelDomainPlus2Secure)));
1689 EXPECT_EQ(8U, GetAllCookies(cm.get()).size());
1690
1691 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
1692 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3)));
1693 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X",
1694 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure)));
1695 EXPECT_EQ("dom_1=X; host_1=X",
1696 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1)));
1697 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X",
1698 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure +
1699 std::string("/dir1/dir2/xxx"))));
1700
1701 PopulateCmForDeleteAllForHost(cm.get());
1702 EXPECT_EQ(6,
1703 DeleteAllCreatedBetweenForHost(
1704 cm.get(), base::Time(), base::Time::Now(),
1705 GURL(kTopLevelDomainPlus2Secure + std::string("/dir1/xxx"))));
1706 EXPECT_EQ(8U, GetAllCookies(cm.get()).size());
1707
1708 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
1709 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3)));
1710 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X",
1711 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure)));
1712 EXPECT_EQ("dom_1=X; host_1=X",
1713 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1)));
1714 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X",
1715 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure +
1716 std::string("/dir1/dir2/xxx"))));
1717 }
1718
1719 TEST_F(CookieMonsterTest, UniqueCreationTime) { 1749 TEST_F(CookieMonsterTest, UniqueCreationTime) {
1720 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); 1750 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr));
1721 CookieOptions options; 1751 CookieOptions options;
1722 1752
1723 // Add in three cookies through every public interface to the 1753 // Add in three cookies through every public interface to the
1724 // CookieMonster and confirm that none of them have duplicate 1754 // CookieMonster and confirm that none of them have duplicate
1725 // creation times. 1755 // creation times.
1726 1756
1727 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions 1757 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions
1728 // are not included as they aren't going to be public for very much 1758 // are not included as they aren't going to be public for very much
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after
3187 monster()->AddCallbackForCookie( 3217 monster()->AddCallbackForCookie(
3188 test_url_, "abc", 3218 test_url_, "abc",
3189 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); 3219 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
3190 SetCookie(monster(), test_url_, "abc=def"); 3220 SetCookie(monster(), test_url_, "abc=def");
3191 base::MessageLoop::current()->RunUntilIdle(); 3221 base::MessageLoop::current()->RunUntilIdle();
3192 EXPECT_EQ(1U, cookies0.size()); 3222 EXPECT_EQ(1U, cookies0.size());
3193 EXPECT_EQ(1U, cookies0.size()); 3223 EXPECT_EQ(1U, cookies0.size());
3194 } 3224 }
3195 3225
3196 } // namespace net 3226 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698