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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // resetting the owner (whose destructor blocks on the pool completion). | 121 // resetting the owner (whose destructor blocks on the pool completion). |
122 pool_owner_->pool()->Shutdown(); | 122 pool_owner_->pool()->Shutdown(); |
123 // Create a new pool for the few tests that create multiple stores. In other | 123 // Create a new pool for the few tests that create multiple stores. In other |
124 // cases this is wasted but harmless. | 124 // cases this is wasted but harmless. |
125 pool_owner_.reset(new base::SequencedWorkerPoolOwner(3, "Background Pool")); | 125 pool_owner_.reset(new base::SequencedWorkerPoolOwner(3, "Background Pool")); |
126 } | 126 } |
127 | 127 |
128 void CreateAndLoad(bool crypt_cookies, | 128 void CreateAndLoad(bool crypt_cookies, |
129 bool restore_old_session_cookies, | 129 bool restore_old_session_cookies, |
130 CanonicalCookieVector* cookies) { | 130 CanonicalCookieVector* cookies) { |
| 131 if (crypt_cookies) |
| 132 cookie_crypto_delegate_.reset(new CookieCryptor()); |
| 133 |
131 store_ = new SQLitePersistentCookieStore( | 134 store_ = new SQLitePersistentCookieStore( |
132 temp_dir_.path().Append(kCookieFilename), | 135 temp_dir_.path().Append(kCookieFilename), |
133 client_task_runner(), | 136 client_task_runner(), |
134 background_task_runner(), | 137 background_task_runner(), |
135 restore_old_session_cookies, | 138 restore_old_session_cookies, |
136 NULL, | 139 NULL, |
137 crypt_cookies ? | 140 cookie_crypto_delegate_.get()); |
138 scoped_ptr<content::CookieCryptoDelegate>(new CookieCryptor) : | |
139 scoped_ptr<content::CookieCryptoDelegate>()); | |
140 Load(cookies); | 141 Load(cookies); |
141 } | 142 } |
142 | 143 |
143 void InitializeStore(bool crypt, bool restore_old_session_cookies) { | 144 void InitializeStore(bool crypt, bool restore_old_session_cookies) { |
144 CanonicalCookieVector cookies; | 145 CanonicalCookieVector cookies; |
145 CreateAndLoad(crypt, restore_old_session_cookies, &cookies); | 146 CreateAndLoad(crypt, restore_old_session_cookies, &cookies); |
146 EXPECT_EQ(0U, cookies.size()); | 147 EXPECT_EQ(0U, cookies.size()); |
147 } | 148 } |
148 | 149 |
149 // We have to create this method to wrap WaitableEvent::Wait, since we cannot | 150 // We have to create this method to wrap WaitableEvent::Wait, since we cannot |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 184 |
184 protected: | 185 protected: |
185 base::MessageLoop main_loop_; | 186 base::MessageLoop main_loop_; |
186 scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; | 187 scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; |
187 base::WaitableEvent loaded_event_; | 188 base::WaitableEvent loaded_event_; |
188 base::WaitableEvent key_loaded_event_; | 189 base::WaitableEvent key_loaded_event_; |
189 base::WaitableEvent db_thread_event_; | 190 base::WaitableEvent db_thread_event_; |
190 CanonicalCookieVector cookies_; | 191 CanonicalCookieVector cookies_; |
191 base::ScopedTempDir temp_dir_; | 192 base::ScopedTempDir temp_dir_; |
192 scoped_refptr<SQLitePersistentCookieStore> store_; | 193 scoped_refptr<SQLitePersistentCookieStore> store_; |
| 194 scoped_ptr<content::CookieCryptoDelegate> cookie_crypto_delegate_; |
193 }; | 195 }; |
194 | 196 |
195 TEST_F(SQLitePersistentCookieStoreTest, TestInvalidMetaTableRecovery) { | 197 TEST_F(SQLitePersistentCookieStoreTest, TestInvalidMetaTableRecovery) { |
196 InitializeStore(false, false); | 198 InitializeStore(false, false); |
197 AddCookie("A", "B", "foo.bar", "/", base::Time::Now()); | 199 AddCookie("A", "B", "foo.bar", "/", base::Time::Now()); |
198 DestroyStore(); | 200 DestroyStore(); |
199 | 201 |
200 // Load up the store and verify that it has good data in it. | 202 // Load up the store and verify that it has good data in it. |
201 CanonicalCookieVector cookies; | 203 CanonicalCookieVector cookies; |
202 CreateAndLoad(false, false, &cookies); | 204 CreateAndLoad(false, false, &cookies); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 t += base::TimeDelta::FromInternalValue(10); | 271 t += base::TimeDelta::FromInternalValue(10); |
270 AddCookie("A", "B", "travel.aaa.com", "/", t); | 272 AddCookie("A", "B", "travel.aaa.com", "/", t); |
271 t += base::TimeDelta::FromInternalValue(10); | 273 t += base::TimeDelta::FromInternalValue(10); |
272 AddCookie("A", "B", "www.bbb.com", "/", t); | 274 AddCookie("A", "B", "www.bbb.com", "/", t); |
273 DestroyStore(); | 275 DestroyStore(); |
274 | 276 |
275 store_ = new SQLitePersistentCookieStore( | 277 store_ = new SQLitePersistentCookieStore( |
276 temp_dir_.path().Append(kCookieFilename), | 278 temp_dir_.path().Append(kCookieFilename), |
277 client_task_runner(), | 279 client_task_runner(), |
278 background_task_runner(), | 280 background_task_runner(), |
279 false, NULL, | 281 false, NULL, NULL); |
280 scoped_ptr<content::CookieCryptoDelegate>()); | |
281 | 282 |
282 // Posting a blocking task to db_thread_ makes sure that the DB thread waits | 283 // Posting a blocking task to db_thread_ makes sure that the DB thread waits |
283 // until both Load and LoadCookiesForKey have been posted to its task queue. | 284 // until both Load and LoadCookiesForKey have been posted to its task queue. |
284 background_task_runner()->PostTask( | 285 background_task_runner()->PostTask( |
285 FROM_HERE, | 286 FROM_HERE, |
286 base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, | 287 base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, |
287 base::Unretained(this))); | 288 base::Unretained(this))); |
288 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, | 289 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, |
289 base::Unretained(this))); | 290 base::Unretained(this))); |
290 store_->LoadCookiesForKey("aaa.com", | 291 store_->LoadCookiesForKey("aaa.com", |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 EXPECT_EQ(2, resultcount); | 599 EXPECT_EQ(2, resultcount); |
599 | 600 |
600 // Verify that "encrypted_value" is NOT visible in the file. | 601 // Verify that "encrypted_value" is NOT visible in the file. |
601 contents = ReadRawDBContents(); | 602 contents = ReadRawDBContents(); |
602 EXPECT_NE(0U, contents.length()); | 603 EXPECT_NE(0U, contents.length()); |
603 EXPECT_EQ(contents.find("encrypted_value123XYZ"), std::string::npos); | 604 EXPECT_EQ(contents.find("encrypted_value123XYZ"), std::string::npos); |
604 EXPECT_EQ(contents.find("something456ABC"), std::string::npos); | 605 EXPECT_EQ(contents.find("something456ABC"), std::string::npos); |
605 } | 606 } |
606 | 607 |
607 } // namespace content | 608 } // namespace content |
OLD | NEW |