| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 new base::ThreadTestHelper( | 60 new base::ThreadTestHelper( |
| 61 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); | 61 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); |
| 62 ASSERT_TRUE(helper->Run()); | 62 ASSERT_TRUE(helper->Run()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void CreateAndLoad( | 65 void CreateAndLoad( |
| 66 bool restore_old_session_cookies, | 66 bool restore_old_session_cookies, |
| 67 std::vector<net::CookieMonster::CanonicalCookie*>* cookies) { | 67 std::vector<net::CookieMonster::CanonicalCookie*>* cookies) { |
| 68 store_ = new SQLitePersistentCookieStore( | 68 store_ = new SQLitePersistentCookieStore( |
| 69 temp_dir_.path().Append(chrome::kCookieFilename), | 69 temp_dir_.path().Append(chrome::kCookieFilename), |
| 70 restore_old_session_cookies); | 70 restore_old_session_cookies, |
| 71 NULL); |
| 71 Load(cookies); | 72 Load(cookies); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void InitializeStore(bool restore_old_session_cookies) { | 75 void InitializeStore(bool restore_old_session_cookies) { |
| 75 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | 76 std::vector<net::CookieMonster::CanonicalCookie*> cookies; |
| 76 CreateAndLoad(restore_old_session_cookies, &cookies); | 77 CreateAndLoad(restore_old_session_cookies, &cookies); |
| 77 ASSERT_EQ(0u, cookies.size()); | 78 ASSERT_EQ(0u, cookies.size()); |
| 78 } | 79 } |
| 79 | 80 |
| 80 // We have to create this method to wrap WaitableEvent::Wait, since we cannot | 81 // We have to create this method to wrap WaitableEvent::Wait, since we cannot |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 AddCookie("A", "B", "http://foo.bar", "/", t); | 217 AddCookie("A", "B", "http://foo.bar", "/", t); |
| 217 t += base::TimeDelta::FromInternalValue(10); | 218 t += base::TimeDelta::FromInternalValue(10); |
| 218 AddCookie("A", "B", "www.aaa.com", "/", t); | 219 AddCookie("A", "B", "www.aaa.com", "/", t); |
| 219 t += base::TimeDelta::FromInternalValue(10); | 220 t += base::TimeDelta::FromInternalValue(10); |
| 220 AddCookie("A", "B", "travel.aaa.com", "/", t); | 221 AddCookie("A", "B", "travel.aaa.com", "/", t); |
| 221 t += base::TimeDelta::FromInternalValue(10); | 222 t += base::TimeDelta::FromInternalValue(10); |
| 222 AddCookie("A", "B", "www.bbb.com", "/", t); | 223 AddCookie("A", "B", "www.bbb.com", "/", t); |
| 223 DestroyStore(); | 224 DestroyStore(); |
| 224 | 225 |
| 225 store_ = new SQLitePersistentCookieStore( | 226 store_ = new SQLitePersistentCookieStore( |
| 226 temp_dir_.path().Append(chrome::kCookieFilename), false); | 227 temp_dir_.path().Append(chrome::kCookieFilename), false, NULL); |
| 227 // Posting a blocking task to db_thread_ makes sure that the DB thread waits | 228 // Posting a blocking task to db_thread_ makes sure that the DB thread waits |
| 228 // until both Load and LoadCookiesForKey have been posted to its task queue. | 229 // until both Load and LoadCookiesForKey have been posted to its task queue. |
| 229 BrowserThread::PostTask( | 230 BrowserThread::PostTask( |
| 230 BrowserThread::DB, FROM_HERE, | 231 BrowserThread::DB, FROM_HERE, |
| 231 base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, | 232 base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, |
| 232 base::Unretained(this))); | 233 base::Unretained(this))); |
| 233 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, | 234 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, |
| 234 base::Unretained(this))); | 235 base::Unretained(this))); |
| 235 store_->LoadCookiesForKey("aaa.com", | 236 store_->LoadCookiesForKey("aaa.com", |
| 236 base::Bind(&SQLitePersistentCookieStoreTest::OnKeyLoaded, | 237 base::Bind(&SQLitePersistentCookieStoreTest::OnKeyLoaded, |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 | 448 |
| 448 EXPECT_FALSE(cookie_map["session-noexpires"]->DoesExpire()); | 449 EXPECT_FALSE(cookie_map["session-noexpires"]->DoesExpire()); |
| 449 EXPECT_FALSE(cookie_map["session-noexpires"]->IsPersistent()); | 450 EXPECT_FALSE(cookie_map["session-noexpires"]->IsPersistent()); |
| 450 | 451 |
| 451 EXPECT_TRUE(cookie_map["persistent"]->DoesExpire()); | 452 EXPECT_TRUE(cookie_map["persistent"]->DoesExpire()); |
| 452 EXPECT_TRUE(cookie_map["persistent"]->IsPersistent()); | 453 EXPECT_TRUE(cookie_map["persistent"]->IsPersistent()); |
| 453 | 454 |
| 454 STLDeleteContainerPointers(cookies.begin(), cookies.end()); | 455 STLDeleteContainerPointers(cookies.begin(), cookies.end()); |
| 455 cookies.clear(); | 456 cookies.clear(); |
| 456 } | 457 } |
| OLD | NEW |