| 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 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 EXPECT_EQ( | 1212 EXPECT_EQ( |
| 1213 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(7), now)); | 1213 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(7), now)); |
| 1214 | 1214 |
| 1215 // Delete the last (now) item. | 1215 // Delete the last (now) item. |
| 1216 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time())); | 1216 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time())); |
| 1217 | 1217 |
| 1218 // Really make sure everything is gone. | 1218 // Really make sure everything is gone. |
| 1219 EXPECT_EQ(0, DeleteAll(cm.get())); | 1219 EXPECT_EQ(0, DeleteAll(cm.get())); |
| 1220 } | 1220 } |
| 1221 | 1221 |
| 1222 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20; | 1222 static const base::TimeDelta kLastAccessThreshold = |
| 1223 base::TimeDelta::FromMilliseconds(200); |
| 1224 static const base::TimeDelta kAccessDelay = |
| 1225 kLastAccessThreshold + base::TimeDelta::FromMilliseconds(20); |
| 1223 | 1226 |
| 1224 TEST_F(CookieMonsterTest, TestLastAccess) { | 1227 TEST_F(CookieMonsterTest, TestLastAccess) { |
| 1225 scoped_ptr<CookieMonster> cm( | 1228 scoped_ptr<CookieMonster> cm( |
| 1226 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds)); | 1229 new CookieMonster(nullptr, nullptr, kLastAccessThreshold)); |
| 1227 | 1230 |
| 1228 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 1231 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); |
| 1229 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); | 1232 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); |
| 1230 | 1233 |
| 1231 // Reading the cookie again immediately shouldn't update the access date, | 1234 // Reading the cookie again immediately shouldn't update the access date, |
| 1232 // since we're inside the threshold. | 1235 // since we're inside the threshold. |
| 1233 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); | 1236 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); |
| 1234 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); | 1237 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); |
| 1235 | 1238 |
| 1236 // Reading after a short wait will update the access date, if the cookie | 1239 // Reading after a short wait will update the access date, if the cookie |
| 1237 // is requested with options that would update the access date. First, test | 1240 // is requested with options that would update the access date. First, test |
| 1238 // that the flag's behavior is respected. | 1241 // that the flag's behavior is respected. |
| 1239 base::PlatformThread::Sleep( | 1242 base::PlatformThread::Sleep(kAccessDelay); |
| 1240 base::TimeDelta::FromMilliseconds(kAccessDelayMs)); | |
| 1241 CookieOptions options; | 1243 CookieOptions options; |
| 1242 options.set_do_not_update_access_time(); | 1244 options.set_do_not_update_access_time(); |
| 1243 EXPECT_EQ("A=B", | 1245 EXPECT_EQ("A=B", |
| 1244 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); | 1246 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); |
| 1245 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); | 1247 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); |
| 1246 | 1248 |
| 1247 // Getting all cookies for a URL doesn't update the accessed time either. | 1249 // Getting all cookies for a URL doesn't update the accessed time either. |
| 1248 CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_google_.url()); | 1250 CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_google_.url()); |
| 1249 CookieList::iterator it = cookies.begin(); | 1251 CookieList::iterator it = cookies.begin(); |
| 1250 ASSERT_TRUE(it != cookies.end()); | 1252 ASSERT_TRUE(it != cookies.end()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 GURL http_url("http://host/path"); | 1284 GURL http_url("http://host/path"); |
| 1283 | 1285 |
| 1284 EXPECT_TRUE(SetCookie(cm.get(), http_url, "x=1")); | 1286 EXPECT_TRUE(SetCookie(cm.get(), http_url, "x=1")); |
| 1285 EXPECT_FALSE(SetCookie(cm.get(), foo_url, "x=1")); | 1287 EXPECT_FALSE(SetCookie(cm.get(), foo_url, "x=1")); |
| 1286 EXPECT_TRUE(SetCookie(cm_foo.get(), foo_url, "x=1")); | 1288 EXPECT_TRUE(SetCookie(cm_foo.get(), foo_url, "x=1")); |
| 1287 EXPECT_FALSE(SetCookie(cm_foo.get(), http_url, "x=1")); | 1289 EXPECT_FALSE(SetCookie(cm_foo.get(), http_url, "x=1")); |
| 1288 } | 1290 } |
| 1289 | 1291 |
| 1290 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { | 1292 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { |
| 1291 scoped_ptr<CookieMonster> cm( | 1293 scoped_ptr<CookieMonster> cm( |
| 1292 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds)); | 1294 new CookieMonster(nullptr, nullptr, kLastAccessThreshold)); |
| 1293 | 1295 |
| 1294 // Create an httponly cookie. | 1296 // Create an httponly cookie. |
| 1295 CookieOptions options; | 1297 CookieOptions options; |
| 1296 options.set_include_httponly(); | 1298 options.set_include_httponly(); |
| 1297 | 1299 |
| 1298 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1300 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
| 1299 "A=B; httponly", options)); | 1301 "A=B; httponly", options)); |
| 1300 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1302 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
| 1301 http_www_google_.Format("C=D; domain=.%D"), | 1303 http_www_google_.Format("C=D; domain=.%D"), |
| 1302 options)); | 1304 options)); |
| 1303 EXPECT_TRUE(SetCookieWithOptions( | 1305 EXPECT_TRUE(SetCookieWithOptions( |
| 1304 cm.get(), https_www_google_.url(), | 1306 cm.get(), https_www_google_.url(), |
| 1305 http_www_google_.Format("E=F; domain=.%D; secure"), options)); | 1307 http_www_google_.Format("E=F; domain=.%D; secure"), options)); |
| 1306 | 1308 |
| 1307 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); | 1309 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); |
| 1308 | 1310 |
| 1309 base::PlatformThread::Sleep( | 1311 base::PlatformThread::Sleep(kAccessDelay); |
| 1310 base::TimeDelta::FromMilliseconds(kAccessDelayMs)); | |
| 1311 | 1312 |
| 1312 // Check cookies for url. | 1313 // Check cookies for url. |
| 1313 CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_google_.url()); | 1314 CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_google_.url()); |
| 1314 CookieList::iterator it = cookies.begin(); | 1315 CookieList::iterator it = cookies.begin(); |
| 1315 | 1316 |
| 1316 ASSERT_TRUE(it != cookies.end()); | 1317 ASSERT_TRUE(it != cookies.end()); |
| 1317 EXPECT_EQ(http_www_google_.host(), it->Domain()); | 1318 EXPECT_EQ(http_www_google_.host(), it->Domain()); |
| 1318 EXPECT_EQ("A", it->Name()); | 1319 EXPECT_EQ("A", it->Name()); |
| 1319 | 1320 |
| 1320 ASSERT_TRUE(++it != cookies.end()); | 1321 ASSERT_TRUE(++it != cookies.end()); |
| (...skipping 1875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3196 monster()->AddCallbackForCookie( | 3197 monster()->AddCallbackForCookie( |
| 3197 test_url_, "abc", | 3198 test_url_, "abc", |
| 3198 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3199 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
| 3199 SetCookie(monster(), test_url_, "abc=def"); | 3200 SetCookie(monster(), test_url_, "abc=def"); |
| 3200 base::MessageLoop::current()->RunUntilIdle(); | 3201 base::MessageLoop::current()->RunUntilIdle(); |
| 3201 EXPECT_EQ(1U, cookies0.size()); | 3202 EXPECT_EQ(1U, cookies0.size()); |
| 3202 EXPECT_EQ(1U, cookies0.size()); | 3203 EXPECT_EQ(1U, cookies0.size()); |
| 3203 } | 3204 } |
| 3204 | 3205 |
| 3205 } // namespace net | 3206 } // namespace net |
| OLD | NEW |