| OLD | NEW |
| 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 19 matching lines...) Expand all Loading... |
| 30 #include "net/cookies/cookie_monster.h" | 30 #include "net/cookies/cookie_monster.h" |
| 31 #include "net/cookies/cookie_monster_store_test.h" // For CookieStore mock | 31 #include "net/cookies/cookie_monster_store_test.h" // For CookieStore mock |
| 32 #include "net/cookies/cookie_util.h" | 32 #include "net/cookies/cookie_util.h" |
| 33 #include "net/cookies/parsed_cookie.h" | 33 #include "net/cookies/parsed_cookie.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 37 | 37 |
| 38 namespace net { | 38 namespace net { |
| 39 | 39 |
| 40 using CookiePredicate = CookieStore::CookiePredicate; |
| 40 using base::Time; | 41 using base::Time; |
| 41 using base::TimeDelta; | 42 using base::TimeDelta; |
| 42 | 43 |
| 43 namespace { | 44 namespace { |
| 44 | 45 |
| 45 // TODO(erikwright): Replace the pre-existing MockPersistentCookieStore (and | 46 // TODO(erikwright): Replace the pre-existing MockPersistentCookieStore (and |
| 46 // brethren) with this one, and remove the 'New' prefix. | 47 // brethren) with this one, and remove the 'New' prefix. |
| 47 class NewMockPersistentCookieStore | 48 class NewMockPersistentCookieStore |
| 48 : public CookieMonster::PersistentCookieStore { | 49 : public CookieMonster::PersistentCookieStore { |
| 49 public: | 50 public: |
| 50 MOCK_METHOD1(Load, void(const LoadedCallback& loaded_callback)); | 51 MOCK_METHOD1(Load, void(const LoadedCallback& loaded_callback)); |
| 51 MOCK_METHOD2(LoadCookiesForKey, | 52 MOCK_METHOD2(LoadCookiesForKey, |
| 52 void(const std::string& key, | 53 void(const std::string& key, |
| 53 const LoadedCallback& loaded_callback)); | 54 const LoadedCallback& loaded_callback)); |
| 54 MOCK_METHOD1(AddCookie, void(const CanonicalCookie& cc)); | 55 MOCK_METHOD1(AddCookie, void(const CanonicalCookie& cc)); |
| 55 MOCK_METHOD1(UpdateCookieAccessTime, void(const CanonicalCookie& cc)); | 56 MOCK_METHOD1(UpdateCookieAccessTime, void(const CanonicalCookie& cc)); |
| 56 MOCK_METHOD1(DeleteCookie, void(const CanonicalCookie& cc)); | 57 MOCK_METHOD1(DeleteCookie, void(const CanonicalCookie& cc)); |
| 57 virtual void Flush(const base::Closure& callback) { | 58 virtual void Flush(const base::Closure& callback) { |
| 58 if (!callback.is_null()) | 59 if (!callback.is_null()) |
| 59 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 60 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| 60 } | 61 } |
| 61 MOCK_METHOD0(SetForceKeepSessionState, void()); | 62 MOCK_METHOD0(SetForceKeepSessionState, void()); |
| 62 | 63 |
| 63 private: | 64 private: |
| 64 virtual ~NewMockPersistentCookieStore() {} | 65 virtual ~NewMockPersistentCookieStore() {} |
| 65 }; | 66 }; |
| 66 | 67 |
| 68 // False means 'less than or equal', so we test both ways for full equal. |
| 69 MATCHER_P(CookieEquals, expected, "") { |
| 70 return !(arg.FullCompare(expected) || expected.FullCompare(arg)); |
| 71 } |
| 72 |
| 67 const char kTopLevelDomainPlus1[] = "http://www.harvard.edu"; | 73 const char kTopLevelDomainPlus1[] = "http://www.harvard.edu"; |
| 68 const char kTopLevelDomainPlus2[] = "http://www.math.harvard.edu"; | 74 const char kTopLevelDomainPlus2[] = "http://www.math.harvard.edu"; |
| 69 const char kTopLevelDomainPlus2Secure[] = "https://www.math.harvard.edu"; | 75 const char kTopLevelDomainPlus2Secure[] = "https://www.math.harvard.edu"; |
| 70 const char kTopLevelDomainPlus3[] = "http://www.bourbaki.math.harvard.edu"; | 76 const char kTopLevelDomainPlus3[] = "http://www.bourbaki.math.harvard.edu"; |
| 71 const char kOtherDomain[] = "http://www.mit.edu"; | 77 const char kOtherDomain[] = "http://www.mit.edu"; |
| 72 | 78 |
| 79 bool AlwaysTrueCookiePredicate(CanonicalCookie* to_save, |
| 80 const CanonicalCookie& cookie) { |
| 81 if (to_save) |
| 82 *to_save = cookie; |
| 83 return true; |
| 84 } |
| 85 |
| 86 bool AlwaysFalseCookiePredicate(CanonicalCookie* to_save, |
| 87 const CanonicalCookie& cookie) { |
| 88 if (to_save) |
| 89 *to_save = cookie; |
| 90 return false; |
| 91 } |
| 92 |
| 73 struct CookieMonsterTestTraits { | 93 struct CookieMonsterTestTraits { |
| 74 static scoped_ptr<CookieStore> Create() { | 94 static scoped_ptr<CookieStore> Create() { |
| 75 return make_scoped_ptr(new CookieMonster(nullptr, nullptr)); | 95 return make_scoped_ptr(new CookieMonster(nullptr, nullptr)); |
| 76 } | 96 } |
| 77 | 97 |
| 78 static const bool supports_http_only = true; | 98 static const bool supports_http_only = true; |
| 79 static const bool supports_non_dotted_domains = true; | 99 static const bool supports_non_dotted_domains = true; |
| 80 static const bool preserves_trailing_dots = true; | 100 static const bool preserves_trailing_dots = true; |
| 81 static const bool filters_schemes = true; | 101 static const bool filters_schemes = true; |
| 82 static const bool has_path_prefix_bug = false; | 102 static const bool has_path_prefix_bug = false; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 DCHECK(cm); | 163 DCHECK(cm); |
| 144 ResultSavingCookieCallback<int> callback; | 164 ResultSavingCookieCallback<int> callback; |
| 145 cm->DeleteAllCreatedBetweenAsync( | 165 cm->DeleteAllCreatedBetweenAsync( |
| 146 delete_begin, delete_end, | 166 delete_begin, delete_end, |
| 147 base::Bind(&ResultSavingCookieCallback<int>::Run, | 167 base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 148 base::Unretained(&callback))); | 168 base::Unretained(&callback))); |
| 149 callback.WaitUntilDone(); | 169 callback.WaitUntilDone(); |
| 150 return callback.result(); | 170 return callback.result(); |
| 151 } | 171 } |
| 152 | 172 |
| 153 int DeleteAllCreatedBetweenForHost(CookieMonster* cm, | 173 int DeleteAllCreatedBetweenWithPredicate(CookieMonster* cm, |
| 154 const base::Time delete_begin, | 174 const base::Time delete_begin, |
| 155 const base::Time delete_end, | 175 const base::Time delete_end, |
| 156 const GURL& url) { | 176 const CookiePredicate& 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 Loading... |
| 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 Loading... |
| 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 CookiePredicate predicate = base::Bind(&AlwaysTrueCookiePredicate, nullptr); |
| 1057 DeleteAllCreatedBetweenForHostAction( | 1078 |
| 1058 &cookie_monster(), base::Time(), base::Time::Now(), | 1079 BeginWith(DeleteAllCreatedBetweenWithPredicateAction( |
| 1059 http_www_google_.url(), &delete_callback)); | 1080 &cookie_monster(), base::Time(), base::Time::Now(), predicate, |
| 1081 &delete_callback)); |
| 1060 | 1082 |
| 1061 WaitForLoadCall(); | 1083 WaitForLoadCall(); |
| 1062 | 1084 |
| 1063 EXPECT_CALL(delete_callback, Invoke(false)) | 1085 EXPECT_CALL(delete_callback, Invoke(false)) |
| 1064 .WillOnce(DeleteAllCreatedBetweenForHostAction( | 1086 .WillOnce(DeleteAllCreatedBetweenWithPredicateAction( |
| 1065 &cookie_monster(), base::Time(), base::Time::Now(), | 1087 &cookie_monster(), base::Time(), base::Time::Now(), predicate, |
| 1066 http_www_google_.url(), &delete_callback)); | 1088 &delete_callback)); |
| 1067 base::RunLoop loop; | 1089 base::RunLoop loop; |
| 1068 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop)); | 1090 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop)); |
| 1069 | 1091 |
| 1070 CompleteLoading(); | 1092 CompleteLoading(); |
| 1071 loop.Run(); | 1093 loop.Run(); |
| 1072 } | 1094 } |
| 1073 | 1095 |
| 1074 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { | 1096 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { |
| 1075 std::vector<CanonicalCookie*> cookies; | 1097 std::vector<CanonicalCookie*> cookies; |
| 1076 CanonicalCookie cookie = BuildCanonicalCookie( | 1098 CanonicalCookie cookie = BuildCanonicalCookie( |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1180 } | 1202 } |
| 1181 | 1203 |
| 1182 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { | 1204 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { |
| 1183 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1205 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1184 Time now = Time::Now(); | 1206 Time now = Time::Now(); |
| 1185 | 1207 |
| 1186 // Nothing has been added so nothing should be deleted. | 1208 // Nothing has been added so nothing should be deleted. |
| 1187 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), | 1209 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), |
| 1188 Time())); | 1210 Time())); |
| 1189 | 1211 |
| 1190 // Create 3 cookies with creation date of today, yesterday and the day before. | 1212 // Create 5 cookies with different creation dates. |
| 1191 EXPECT_TRUE( | 1213 EXPECT_TRUE( |
| 1192 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now)); | 1214 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now)); |
| 1193 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1215 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1194 http_www_google_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); | 1216 http_www_google_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); |
| 1195 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1217 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1196 http_www_google_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); | 1218 http_www_google_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); |
| 1197 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1219 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1198 http_www_google_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); | 1220 http_www_google_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); |
| 1199 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1221 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1200 http_www_google_.url(), "T-7=LastWeek", now - TimeDelta::FromDays(7))); | 1222 http_www_google_.url(), "T-7=LastWeek", now - TimeDelta::FromDays(7))); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1212 EXPECT_EQ( | 1234 EXPECT_EQ( |
| 1213 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(7), now)); | 1235 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(7), now)); |
| 1214 | 1236 |
| 1215 // Delete the last (now) item. | 1237 // Delete the last (now) item. |
| 1216 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time())); | 1238 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time())); |
| 1217 | 1239 |
| 1218 // Really make sure everything is gone. | 1240 // Really make sure everything is gone. |
| 1219 EXPECT_EQ(0, DeleteAll(cm.get())); | 1241 EXPECT_EQ(0, DeleteAll(cm.get())); |
| 1220 } | 1242 } |
| 1221 | 1243 |
| 1244 TEST_F(CookieMonsterTest, |
| 1245 TestCookieDeleteAllCreatedBetweenTimestampsWithPredicate) { |
| 1246 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1247 Time now = Time::Now(); |
| 1248 |
| 1249 CanonicalCookie test_cookie; |
| 1250 CookiePredicate true_predicate = |
| 1251 base::Bind(&AlwaysTrueCookiePredicate, &test_cookie); |
| 1252 |
| 1253 CookiePredicate false_predicate = |
| 1254 base::Bind(&AlwaysFalseCookiePredicate, &test_cookie); |
| 1255 |
| 1256 // Nothing has been added so nothing should be deleted. |
| 1257 EXPECT_EQ( |
| 1258 0, DeleteAllCreatedBetweenWithPredicate( |
| 1259 cm.get(), now - TimeDelta::FromDays(99), Time(), true_predicate)); |
| 1260 |
| 1261 // Create 5 cookies with different creation dates. |
| 1262 EXPECT_TRUE( |
| 1263 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now)); |
| 1264 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1265 http_www_google_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); |
| 1266 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1267 http_www_google_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); |
| 1268 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1269 http_www_google_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); |
| 1270 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1271 http_www_google_.url(), "T-7=LastWeek", now - TimeDelta::FromDays(7))); |
| 1272 |
| 1273 // Try to delete threedays and the daybefore, but we should do nothing due |
| 1274 // to the predicate. |
| 1275 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate( |
| 1276 cm.get(), now - TimeDelta::FromDays(3), |
| 1277 now - TimeDelta::FromDays(1), false_predicate)); |
| 1278 // Same as above with a null predicate, so it shouldn't delete anything. |
| 1279 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate( |
| 1280 cm.get(), now - TimeDelta::FromDays(3), |
| 1281 now - TimeDelta::FromDays(1), CookiePredicate())); |
| 1282 // Same as above, but we use the true_predicate, so it works. |
| 1283 EXPECT_EQ(2, DeleteAllCreatedBetweenWithPredicate( |
| 1284 cm.get(), now - TimeDelta::FromDays(3), |
| 1285 now - TimeDelta::FromDays(1), true_predicate)); |
| 1286 |
| 1287 // Try to delete yesterday, also make sure that delete_end is not |
| 1288 // inclusive. |
| 1289 EXPECT_EQ(0, |
| 1290 DeleteAllCreatedBetweenWithPredicate( |
| 1291 cm.get(), now - TimeDelta::FromDays(2), now, false_predicate)); |
| 1292 EXPECT_EQ(1, |
| 1293 DeleteAllCreatedBetweenWithPredicate( |
| 1294 cm.get(), now - TimeDelta::FromDays(2), now, true_predicate)); |
| 1295 // Check our cookie values. |
| 1296 scoped_ptr<CanonicalCookie> expected_cookie = |
| 1297 CanonicalCookie::Create(http_www_google_.url(), "T-1=Yesterday", |
| 1298 now - TimeDelta::FromDays(1), CookieOptions()); |
| 1299 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie)) |
| 1300 << "Actual:\n" |
| 1301 << test_cookie.DebugString() << "\nExpected:\n" |
| 1302 << expected_cookie->DebugString(); |
| 1303 |
| 1304 // Make sure the delete_begin is inclusive. |
| 1305 EXPECT_EQ(0, |
| 1306 DeleteAllCreatedBetweenWithPredicate( |
| 1307 cm.get(), now - TimeDelta::FromDays(7), now, false_predicate)); |
| 1308 EXPECT_EQ(1, |
| 1309 DeleteAllCreatedBetweenWithPredicate( |
| 1310 cm.get(), now - TimeDelta::FromDays(7), now, true_predicate)); |
| 1311 |
| 1312 // Delete the last (now) item. |
| 1313 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate(cm.get(), Time(), Time(), |
| 1314 false_predicate)); |
| 1315 EXPECT_EQ(1, DeleteAllCreatedBetweenWithPredicate(cm.get(), Time(), Time(), |
| 1316 true_predicate)); |
| 1317 expected_cookie = CanonicalCookie::Create(http_www_google_.url(), "T-0=Now", |
| 1318 now, CookieOptions()); |
| 1319 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie)) |
| 1320 << "Actual:\n" |
| 1321 << test_cookie.DebugString() << "\nExpected:\n" |
| 1322 << expected_cookie->DebugString(); |
| 1323 |
| 1324 // Really make sure everything is gone. |
| 1325 EXPECT_EQ(0, DeleteAll(cm.get())); |
| 1326 } |
| 1327 |
| 1222 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20; | 1328 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20; |
| 1223 | 1329 |
| 1224 TEST_F(CookieMonsterTest, TestLastAccess) { | 1330 TEST_F(CookieMonsterTest, TestLastAccess) { |
| 1225 scoped_ptr<CookieMonster> cm( | 1331 scoped_ptr<CookieMonster> cm( |
| 1226 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds)); | 1332 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds)); |
| 1227 | 1333 |
| 1228 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 1334 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); |
| 1229 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); | 1335 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); |
| 1230 | 1336 |
| 1231 // Reading the cookie again immediately shouldn't update the access date, | 1337 // Reading the cookie again immediately shouldn't update the access date, |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1636 EXPECT_EQ("a", delegate->changes()[0].first.Name()); | 1742 EXPECT_EQ("a", delegate->changes()[0].first.Name()); |
| 1637 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); | 1743 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); |
| 1638 EXPECT_EQ(http_www_google_.url().host(), | 1744 EXPECT_EQ(http_www_google_.url().host(), |
| 1639 delegate->changes()[1].first.Domain()); | 1745 delegate->changes()[1].first.Domain()); |
| 1640 EXPECT_FALSE(delegate->changes()[1].second); | 1746 EXPECT_FALSE(delegate->changes()[1].second); |
| 1641 EXPECT_EQ("a", delegate->changes()[1].first.Name()); | 1747 EXPECT_EQ("a", delegate->changes()[1].first.Name()); |
| 1642 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); | 1748 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); |
| 1643 delegate->reset(); | 1749 delegate->reset(); |
| 1644 } | 1750 } |
| 1645 | 1751 |
| 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) { | 1752 TEST_F(CookieMonsterTest, UniqueCreationTime) { |
| 1720 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1753 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1721 CookieOptions options; | 1754 CookieOptions options; |
| 1722 | 1755 |
| 1723 // Add in three cookies through every public interface to the | 1756 // Add in three cookies through every public interface to the |
| 1724 // CookieMonster and confirm that none of them have duplicate | 1757 // CookieMonster and confirm that none of them have duplicate |
| 1725 // creation times. | 1758 // creation times. |
| 1726 | 1759 |
| 1727 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions | 1760 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions |
| 1728 // are not included as they aren't going to be public for very much | 1761 // 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 Loading... |
| 3187 monster()->AddCallbackForCookie( | 3220 monster()->AddCallbackForCookie( |
| 3188 test_url_, "abc", | 3221 test_url_, "abc", |
| 3189 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3222 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
| 3190 SetCookie(monster(), test_url_, "abc=def"); | 3223 SetCookie(monster(), test_url_, "abc=def"); |
| 3191 base::MessageLoop::current()->RunUntilIdle(); | 3224 base::MessageLoop::current()->RunUntilIdle(); |
| 3192 EXPECT_EQ(1U, cookies0.size()); | 3225 EXPECT_EQ(1U, cookies0.size()); |
| 3193 EXPECT_EQ(1U, cookies0.size()); | 3226 EXPECT_EQ(1U, cookies0.size()); |
| 3194 } | 3227 } |
| 3195 | 3228 |
| 3196 } // namespace net | 3229 } // namespace net |
| OLD | NEW |