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 "content/browser/net/sqlite_persistent_cookie_store.h" | 5 #include "content/browser/net/sqlite_persistent_cookie_store.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 STLDeleteElements(&cookies_); | 282 STLDeleteElements(&cookies_); |
283 } | 283 } |
284 | 284 |
285 // Test that we can force the database to be written by calling Flush(). | 285 // Test that we can force the database to be written by calling Flush(). |
286 TEST_F(SQLitePersistentCookieStoreTest, TestFlush) { | 286 TEST_F(SQLitePersistentCookieStoreTest, TestFlush) { |
287 InitializeStore(false); | 287 InitializeStore(false); |
288 // File timestamps don't work well on all platforms, so we'll determine | 288 // File timestamps don't work well on all platforms, so we'll determine |
289 // whether the DB file has been modified by checking its size. | 289 // whether the DB file has been modified by checking its size. |
290 base::FilePath path = temp_dir_.path().Append(kCookieFilename); | 290 base::FilePath path = temp_dir_.path().Append(kCookieFilename); |
291 base::PlatformFileInfo info; | 291 base::PlatformFileInfo info; |
292 ASSERT_TRUE(file_util::GetFileInfo(path, &info)); | 292 ASSERT_TRUE(base::GetFileInfo(path, &info)); |
293 int64 base_size = info.size; | 293 int64 base_size = info.size; |
294 | 294 |
295 // Write some large cookies, so the DB will have to expand by several KB. | 295 // Write some large cookies, so the DB will have to expand by several KB. |
296 for (char c = 'a'; c < 'z'; ++c) { | 296 for (char c = 'a'; c < 'z'; ++c) { |
297 // Each cookie needs a unique timestamp for creation_utc (see DB schema). | 297 // Each cookie needs a unique timestamp for creation_utc (see DB schema). |
298 base::Time t = base::Time::Now() + base::TimeDelta::FromMicroseconds(c); | 298 base::Time t = base::Time::Now() + base::TimeDelta::FromMicroseconds(c); |
299 std::string name(1, c); | 299 std::string name(1, c); |
300 std::string value(1000, c); | 300 std::string value(1000, c); |
301 AddCookie(name, value, "foo.bar", "/", t); | 301 AddCookie(name, value, "foo.bar", "/", t); |
302 } | 302 } |
303 | 303 |
304 Flush(); | 304 Flush(); |
305 | 305 |
306 // We forced a write, so now the file will be bigger. | 306 // We forced a write, so now the file will be bigger. |
307 ASSERT_TRUE(file_util::GetFileInfo(path, &info)); | 307 ASSERT_TRUE(base::GetFileInfo(path, &info)); |
308 ASSERT_GT(info.size, base_size); | 308 ASSERT_GT(info.size, base_size); |
309 } | 309 } |
310 | 310 |
311 // Test loading old session cookies from the disk. | 311 // Test loading old session cookies from the disk. |
312 TEST_F(SQLitePersistentCookieStoreTest, TestLoadOldSessionCookies) { | 312 TEST_F(SQLitePersistentCookieStoreTest, TestLoadOldSessionCookies) { |
313 InitializeStore(true); | 313 InitializeStore(true); |
314 | 314 |
315 // Add a session cookie. | 315 // Add a session cookie. |
316 store_->AddCookie( | 316 store_->AddCookie( |
317 net::CanonicalCookie( | 317 net::CanonicalCookie( |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 EXPECT_EQ(net::COOKIE_PRIORITY_MEDIUM, cookie_map[kMediumName]->Priority()); | 479 EXPECT_EQ(net::COOKIE_PRIORITY_MEDIUM, cookie_map[kMediumName]->Priority()); |
480 | 480 |
481 it = cookie_map.find(kHighName); | 481 it = cookie_map.find(kHighName); |
482 ASSERT_TRUE(it != cookie_map.end()); | 482 ASSERT_TRUE(it != cookie_map.end()); |
483 EXPECT_EQ(net::COOKIE_PRIORITY_HIGH, cookie_map[kHighName]->Priority()); | 483 EXPECT_EQ(net::COOKIE_PRIORITY_HIGH, cookie_map[kHighName]->Priority()); |
484 | 484 |
485 STLDeleteElements(&cookies); | 485 STLDeleteElements(&cookies); |
486 } | 486 } |
487 | 487 |
488 } // namespace content | 488 } // namespace content |
OLD | NEW |