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/extras/sqlite/sqlite_persistent_cookie_store.h" | 5 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 CanonicalCookieVector cookies; | 160 CanonicalCookieVector cookies; |
161 CreateAndLoad(crypt, restore_old_session_cookies, &cookies); | 161 CreateAndLoad(crypt, restore_old_session_cookies, &cookies); |
162 EXPECT_EQ(0U, cookies.size()); | 162 EXPECT_EQ(0U, cookies.size()); |
163 } | 163 } |
164 | 164 |
165 // We have to create this method to wrap WaitableEvent::Wait, since we cannot | 165 // We have to create this method to wrap WaitableEvent::Wait, since we cannot |
166 // bind a non-void returning method as a Closure. | 166 // bind a non-void returning method as a Closure. |
167 void WaitOnDBEvent() { db_thread_event_.Wait(); } | 167 void WaitOnDBEvent() { db_thread_event_.Wait(); } |
168 | 168 |
169 // Adds a persistent cookie to store_. | 169 // Adds a persistent cookie to store_. |
170 void AddCookie(const GURL& url, | 170 void AddCookie(const std::string& name, |
171 const std::string& name, | |
172 const std::string& value, | 171 const std::string& value, |
173 const std::string& domain, | 172 const std::string& domain, |
174 const std::string& path, | 173 const std::string& path, |
175 const base::Time& creation) { | 174 const base::Time& creation) { |
176 store_->AddCookie(*CanonicalCookie::Create( | 175 store_->AddCookie(*CanonicalCookie::Create( |
177 url, name, value, domain, path, creation, creation, false, false, | 176 name, value, domain, path, creation, creation, base::Time(), false, |
178 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 177 false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
179 } | 178 } |
180 | 179 |
181 void AddCookieWithExpiration(const GURL& url, | 180 void AddCookieWithExpiration(const std::string& name, |
182 const std::string& name, | |
183 const std::string& value, | 181 const std::string& value, |
184 const std::string& domain, | 182 const std::string& domain, |
185 const std::string& path, | 183 const std::string& path, |
186 const base::Time& creation, | 184 const base::Time& creation, |
187 const base::Time& expiration) { | 185 const base::Time& expiration) { |
188 store_->AddCookie(*CanonicalCookie::Create( | 186 store_->AddCookie(*CanonicalCookie::Create( |
189 url, name, value, domain, path, creation, expiration, false, false, | 187 name, value, domain, path, creation, expiration, base::Time(), false, |
190 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 188 false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
191 } | 189 } |
192 | 190 |
193 std::string ReadRawDBContents() { | 191 std::string ReadRawDBContents() { |
194 std::string contents; | 192 std::string contents; |
195 if (!base::ReadFileToString(temp_dir_.GetPath().Append(kCookieFilename), | 193 if (!base::ReadFileToString(temp_dir_.GetPath().Append(kCookieFilename), |
196 &contents)) | 194 &contents)) |
197 return std::string(); | 195 return std::string(); |
198 return contents; | 196 return contents; |
199 } | 197 } |
200 | 198 |
201 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); } | 199 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); } |
202 | 200 |
203 void TearDown() override { | 201 void TearDown() override { |
204 DestroyStore(); | 202 DestroyStore(); |
205 } | 203 } |
206 | 204 |
207 protected: | 205 protected: |
208 std::unique_ptr<base::SequencedWorkerPoolOwner> pool_owner_; | 206 std::unique_ptr<base::SequencedWorkerPoolOwner> pool_owner_; |
209 base::WaitableEvent loaded_event_; | 207 base::WaitableEvent loaded_event_; |
210 base::WaitableEvent key_loaded_event_; | 208 base::WaitableEvent key_loaded_event_; |
211 base::WaitableEvent db_thread_event_; | 209 base::WaitableEvent db_thread_event_; |
212 CanonicalCookieVector cookies_; | 210 CanonicalCookieVector cookies_; |
213 base::ScopedTempDir temp_dir_; | 211 base::ScopedTempDir temp_dir_; |
214 scoped_refptr<SQLitePersistentCookieStore> store_; | 212 scoped_refptr<SQLitePersistentCookieStore> store_; |
215 std::unique_ptr<CookieCryptor> cookie_crypto_delegate_; | 213 std::unique_ptr<CookieCryptor> cookie_crypto_delegate_; |
216 }; | 214 }; |
217 | 215 |
218 TEST_F(SQLitePersistentCookieStoreTest, TestInvalidMetaTableRecovery) { | 216 TEST_F(SQLitePersistentCookieStoreTest, TestInvalidMetaTableRecovery) { |
219 InitializeStore(false, false); | 217 InitializeStore(false, false); |
220 AddCookie(GURL("http://foo.bar"), "A", "B", std::string(), "/", | 218 AddCookie("A", "B", "foo.bar", "/", base::Time::Now()); |
221 base::Time::Now()); | |
222 DestroyStore(); | 219 DestroyStore(); |
223 | 220 |
224 // Load up the store and verify that it has good data in it. | 221 // Load up the store and verify that it has good data in it. |
225 CanonicalCookieVector cookies; | 222 CanonicalCookieVector cookies; |
226 CreateAndLoad(false, false, &cookies); | 223 CreateAndLoad(false, false, &cookies); |
227 ASSERT_EQ(1U, cookies.size()); | 224 ASSERT_EQ(1U, cookies.size()); |
228 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str()); | 225 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str()); |
229 ASSERT_STREQ("A", cookies[0]->Name().c_str()); | 226 ASSERT_STREQ("A", cookies[0]->Name().c_str()); |
230 ASSERT_STREQ("B", cookies[0]->Value().c_str()); | 227 ASSERT_STREQ("B", cookies[0]->Value().c_str()); |
231 DestroyStore(); | 228 DestroyStore(); |
232 cookies.clear(); | 229 cookies.clear(); |
233 | 230 |
234 // Now corrupt the meta table. | 231 // Now corrupt the meta table. |
235 { | 232 { |
236 sql::Connection db; | 233 sql::Connection db; |
237 ASSERT_TRUE(db.Open(temp_dir_.GetPath().Append(kCookieFilename))); | 234 ASSERT_TRUE(db.Open(temp_dir_.GetPath().Append(kCookieFilename))); |
238 sql::MetaTable meta_table_; | 235 sql::MetaTable meta_table_; |
239 meta_table_.Init(&db, 1, 1); | 236 meta_table_.Init(&db, 1, 1); |
240 ASSERT_TRUE(db.Execute("DELETE FROM meta")); | 237 ASSERT_TRUE(db.Execute("DELETE FROM meta")); |
241 db.Close(); | 238 db.Close(); |
242 } | 239 } |
243 | 240 |
244 // Upon loading, the database should be reset to a good, blank state. | 241 // Upon loading, the database should be reset to a good, blank state. |
245 CreateAndLoad(false, false, &cookies); | 242 CreateAndLoad(false, false, &cookies); |
246 ASSERT_EQ(0U, cookies.size()); | 243 ASSERT_EQ(0U, cookies.size()); |
247 | 244 |
248 // Verify that, after, recovery, the database persists properly. | 245 // Verify that, after, recovery, the database persists properly. |
249 AddCookie(GURL("http://foo.bar"), "X", "Y", std::string(), "/", | 246 AddCookie("X", "Y", "foo.bar", "/", base::Time::Now()); |
250 base::Time::Now()); | |
251 DestroyStore(); | 247 DestroyStore(); |
252 CreateAndLoad(false, false, &cookies); | 248 CreateAndLoad(false, false, &cookies); |
253 ASSERT_EQ(1U, cookies.size()); | 249 ASSERT_EQ(1U, cookies.size()); |
254 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str()); | 250 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str()); |
255 ASSERT_STREQ("X", cookies[0]->Name().c_str()); | 251 ASSERT_STREQ("X", cookies[0]->Name().c_str()); |
256 ASSERT_STREQ("Y", cookies[0]->Value().c_str()); | 252 ASSERT_STREQ("Y", cookies[0]->Value().c_str()); |
257 cookies.clear(); | 253 cookies.clear(); |
258 } | 254 } |
259 | 255 |
260 // Test if data is stored as expected in the SQLite database. | 256 // Test if data is stored as expected in the SQLite database. |
261 TEST_F(SQLitePersistentCookieStoreTest, TestPersistance) { | 257 TEST_F(SQLitePersistentCookieStoreTest, TestPersistance) { |
262 InitializeStore(false, false); | 258 InitializeStore(false, false); |
263 AddCookie(GURL("http://foo.bar"), "A", "B", std::string(), "/", | 259 AddCookie("A", "B", "foo.bar", "/", base::Time::Now()); |
264 base::Time::Now()); | |
265 // Replace the store effectively destroying the current one and forcing it | 260 // Replace the store effectively destroying the current one and forcing it |
266 // to write its data to disk. Then we can see if after loading it again it | 261 // to write its data to disk. Then we can see if after loading it again it |
267 // is still there. | 262 // is still there. |
268 DestroyStore(); | 263 DestroyStore(); |
269 // Reload and test for persistence | 264 // Reload and test for persistence |
270 CanonicalCookieVector cookies; | 265 CanonicalCookieVector cookies; |
271 CreateAndLoad(false, false, &cookies); | 266 CreateAndLoad(false, false, &cookies); |
272 ASSERT_EQ(1U, cookies.size()); | 267 ASSERT_EQ(1U, cookies.size()); |
273 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str()); | 268 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str()); |
274 ASSERT_STREQ("A", cookies[0]->Name().c_str()); | 269 ASSERT_STREQ("A", cookies[0]->Name().c_str()); |
275 ASSERT_STREQ("B", cookies[0]->Value().c_str()); | 270 ASSERT_STREQ("B", cookies[0]->Value().c_str()); |
276 | 271 |
277 // Now delete the cookie and check persistence again. | 272 // Now delete the cookie and check persistence again. |
278 store_->DeleteCookie(*cookies[0]); | 273 store_->DeleteCookie(*cookies[0]); |
279 DestroyStore(); | 274 DestroyStore(); |
280 cookies.clear(); | 275 cookies.clear(); |
281 | 276 |
282 // Reload and check if the cookie has been removed. | 277 // Reload and check if the cookie has been removed. |
283 CreateAndLoad(false, false, &cookies); | 278 CreateAndLoad(false, false, &cookies); |
284 ASSERT_EQ(0U, cookies.size()); | 279 ASSERT_EQ(0U, cookies.size()); |
285 } | 280 } |
286 | 281 |
287 TEST_F(SQLitePersistentCookieStoreTest, TestSessionCookiesDeletedOnStartup) { | 282 TEST_F(SQLitePersistentCookieStoreTest, TestSessionCookiesDeletedOnStartup) { |
288 // Initialize the cookie store with 3 persistent cookies, 5 transient | 283 // Initialize the cookie store with 3 persistent cookies, 5 transient |
289 // cookies. | 284 // cookies. |
290 InitializeStore(false, false); | 285 InitializeStore(false, false); |
291 | 286 |
292 // Add persistent cookies. | 287 // Add persistent cookies. |
293 base::Time t = base::Time::Now(); | 288 base::Time t = base::Time::Now(); |
294 AddCookie(GURL("http://a1.com"), "A", "B", std::string(), "/", t); | 289 AddCookie("A", "B", "a1.com", "/", t); |
295 t += base::TimeDelta::FromInternalValue(10); | 290 t += base::TimeDelta::FromInternalValue(10); |
296 AddCookie(GURL("http://a2.com"), "A", "B", std::string(), "/", t); | 291 AddCookie("A", "B", "a2.com", "/", t); |
297 t += base::TimeDelta::FromInternalValue(10); | 292 t += base::TimeDelta::FromInternalValue(10); |
298 AddCookie(GURL("http://a3.com"), "A", "B", std::string(), "/", t); | 293 AddCookie("A", "B", "a3.com", "/", t); |
299 | 294 |
300 // Add transient cookies. | 295 // Add transient cookies. |
301 t += base::TimeDelta::FromInternalValue(10); | 296 t += base::TimeDelta::FromInternalValue(10); |
302 AddCookieWithExpiration(GURL("http://b1.com"), "A", "B", std::string(), "/", | 297 AddCookieWithExpiration("A", "B", "b1.com", "/", t, base::Time()); |
303 t, base::Time()); | |
304 t += base::TimeDelta::FromInternalValue(10); | 298 t += base::TimeDelta::FromInternalValue(10); |
305 AddCookieWithExpiration(GURL("http://b2.com"), "A", "B", std::string(), "/", | 299 AddCookieWithExpiration("A", "B", "b2.com", "/", t, base::Time()); |
306 t, base::Time()); | |
307 t += base::TimeDelta::FromInternalValue(10); | 300 t += base::TimeDelta::FromInternalValue(10); |
308 AddCookieWithExpiration(GURL("http://b3.com"), "A", "B", std::string(), "/", | 301 AddCookieWithExpiration("A", "B", "b3.com", "/", t, base::Time()); |
309 t, base::Time()); | |
310 t += base::TimeDelta::FromInternalValue(10); | 302 t += base::TimeDelta::FromInternalValue(10); |
311 AddCookieWithExpiration(GURL("http://b4.com"), "A", "B", std::string(), "/", | 303 AddCookieWithExpiration("A", "B", "b4.com", "/", t, base::Time()); |
312 t, base::Time()); | |
313 t += base::TimeDelta::FromInternalValue(10); | 304 t += base::TimeDelta::FromInternalValue(10); |
314 AddCookieWithExpiration(GURL("http://b5.com"), "A", "B", std::string(), "/", | 305 AddCookieWithExpiration("A", "B", "b5.com", "/", t, base::Time()); |
315 t, base::Time()); | |
316 DestroyStore(); | 306 DestroyStore(); |
317 | 307 |
318 // Load the store a second time. Before the store finishes loading, add a | 308 // Load the store a second time. Before the store finishes loading, add a |
319 // transient cookie and flush it to disk. | 309 // transient cookie and flush it to disk. |
320 store_ = new SQLitePersistentCookieStore( | 310 store_ = new SQLitePersistentCookieStore( |
321 temp_dir_.GetPath().Append(kCookieFilename), client_task_runner(), | 311 temp_dir_.GetPath().Append(kCookieFilename), client_task_runner(), |
322 background_task_runner(), false, nullptr); | 312 background_task_runner(), false, nullptr); |
323 | 313 |
324 // Posting a blocking task to db_thread_ makes sure that the DB thread waits | 314 // Posting a blocking task to db_thread_ makes sure that the DB thread waits |
325 // until both Load and Flush have been posted to its task queue. | 315 // until both Load and Flush have been posted to its task queue. |
326 background_task_runner()->PostTask( | 316 background_task_runner()->PostTask( |
327 FROM_HERE, base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, | 317 FROM_HERE, base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, |
328 base::Unretained(this))); | 318 base::Unretained(this))); |
329 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, | 319 store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, |
330 base::Unretained(this))); | 320 base::Unretained(this))); |
331 t += base::TimeDelta::FromInternalValue(10); | 321 t += base::TimeDelta::FromInternalValue(10); |
332 AddCookieWithExpiration(GURL("http://c.com"), "A", "B", std::string(), "/", t, | 322 AddCookieWithExpiration("A", "B", "c.com", "/", t, base::Time()); |
333 base::Time()); | |
334 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 323 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
335 base::WaitableEvent::InitialState::NOT_SIGNALED); | 324 base::WaitableEvent::InitialState::NOT_SIGNALED); |
336 store_->Flush( | 325 store_->Flush( |
337 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | 326 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
338 | 327 |
339 // Now the DB-thread queue contains: | 328 // Now the DB-thread queue contains: |
340 // (active:) | 329 // (active:) |
341 // 1. Wait (on db_event) | 330 // 1. Wait (on db_event) |
342 // (pending:) | 331 // (pending:) |
343 // 2. "Init And Chain-Load First Domain" | 332 // 2. "Init And Chain-Load First Domain" |
(...skipping 16 matching lines...) Expand all Loading... |
360 loaded_event_.Wait(); | 349 loaded_event_.Wait(); |
361 ASSERT_EQ(4u, cookies_.size()); | 350 ASSERT_EQ(4u, cookies_.size()); |
362 cookies_.clear(); | 351 cookies_.clear(); |
363 } | 352 } |
364 | 353 |
365 // Test that priority load of cookies for a specfic domain key could be | 354 // Test that priority load of cookies for a specfic domain key could be |
366 // completed before the entire store is loaded | 355 // completed before the entire store is loaded |
367 TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) { | 356 TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) { |
368 InitializeStore(false, false); | 357 InitializeStore(false, false); |
369 base::Time t = base::Time::Now(); | 358 base::Time t = base::Time::Now(); |
370 AddCookie(GURL("http://foo.bar"), "A", "B", std::string(), "/", t); | 359 AddCookie("A", "B", "foo.bar", "/", t); |
371 t += base::TimeDelta::FromInternalValue(10); | 360 t += base::TimeDelta::FromInternalValue(10); |
372 AddCookie(GURL("http://www.aaa.com"), "A", "B", std::string(), "/", t); | 361 AddCookie("A", "B", "www.aaa.com", "/", t); |
373 t += base::TimeDelta::FromInternalValue(10); | 362 t += base::TimeDelta::FromInternalValue(10); |
374 AddCookie(GURL("http://travel.aaa.com"), "A", "B", std::string(), "/", t); | 363 AddCookie("A", "B", "travel.aaa.com", "/", t); |
375 t += base::TimeDelta::FromInternalValue(10); | 364 t += base::TimeDelta::FromInternalValue(10); |
376 AddCookie(GURL("http://www.bbb.com"), "A", "B", std::string(), "/", t); | 365 AddCookie("A", "B", "www.bbb.com", "/", t); |
377 DestroyStore(); | 366 DestroyStore(); |
378 | 367 |
379 store_ = new SQLitePersistentCookieStore( | 368 store_ = new SQLitePersistentCookieStore( |
380 temp_dir_.GetPath().Append(kCookieFilename), client_task_runner(), | 369 temp_dir_.GetPath().Append(kCookieFilename), client_task_runner(), |
381 background_task_runner(), false, nullptr); | 370 background_task_runner(), false, nullptr); |
382 | 371 |
383 // Posting a blocking task to db_thread_ makes sure that the DB thread waits | 372 // Posting a blocking task to db_thread_ makes sure that the DB thread waits |
384 // until both Load and LoadCookiesForKey have been posted to its task queue. | 373 // until both Load and LoadCookiesForKey have been posted to its task queue. |
385 background_task_runner()->PostTask( | 374 background_task_runner()->PostTask( |
386 FROM_HERE, base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, | 375 FROM_HERE, base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 base::File::Info info; | 425 base::File::Info info; |
437 ASSERT_TRUE(base::GetFileInfo(path, &info)); | 426 ASSERT_TRUE(base::GetFileInfo(path, &info)); |
438 int64_t base_size = info.size; | 427 int64_t base_size = info.size; |
439 | 428 |
440 // Write some large cookies, so the DB will have to expand by several KB. | 429 // Write some large cookies, so the DB will have to expand by several KB. |
441 for (char c = 'a'; c < 'z'; ++c) { | 430 for (char c = 'a'; c < 'z'; ++c) { |
442 // Each cookie needs a unique timestamp for creation_utc (see DB schema). | 431 // Each cookie needs a unique timestamp for creation_utc (see DB schema). |
443 base::Time t = base::Time::Now() + base::TimeDelta::FromMicroseconds(c); | 432 base::Time t = base::Time::Now() + base::TimeDelta::FromMicroseconds(c); |
444 std::string name(1, c); | 433 std::string name(1, c); |
445 std::string value(1000, c); | 434 std::string value(1000, c); |
446 AddCookie(GURL("http://foo.bar"), name, value, std::string(), "/", t); | 435 AddCookie(name, value, "foo.bar", "/", t); |
447 } | 436 } |
448 | 437 |
449 Flush(); | 438 Flush(); |
450 | 439 |
451 // We forced a write, so now the file will be bigger. | 440 // We forced a write, so now the file will be bigger. |
452 ASSERT_TRUE(base::GetFileInfo(path, &info)); | 441 ASSERT_TRUE(base::GetFileInfo(path, &info)); |
453 ASSERT_GT(info.size, base_size); | 442 ASSERT_GT(info.size, base_size); |
454 } | 443 } |
455 | 444 |
456 // Test loading old session cookies from the disk. | 445 // Test loading old session cookies from the disk. |
457 TEST_F(SQLitePersistentCookieStoreTest, TestLoadOldSessionCookies) { | 446 TEST_F(SQLitePersistentCookieStoreTest, TestLoadOldSessionCookies) { |
458 InitializeStore(false, true); | 447 InitializeStore(false, true); |
459 | 448 |
460 // Add a session cookie. | 449 // Add a session cookie. |
461 store_->AddCookie(*CanonicalCookie::Create( | 450 store_->AddCookie(*CanonicalCookie::Create( |
462 GURL("http://sessioncookie.com"), "C", "D", std::string(), "/", | 451 "C", "D", "sessioncookie.com", "/", base::Time::Now(), base::Time(), |
463 base::Time::Now(), base::Time(), false, false, | 452 base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
464 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 453 COOKIE_PRIORITY_DEFAULT)); |
465 | 454 |
466 // Force the store to write its data to the disk. | 455 // Force the store to write its data to the disk. |
467 DestroyStore(); | 456 DestroyStore(); |
468 | 457 |
469 // Create a store that loads session cookies and test that the session cookie | 458 // Create a store that loads session cookies and test that the session cookie |
470 // was loaded. | 459 // was loaded. |
471 CanonicalCookieVector cookies; | 460 CanonicalCookieVector cookies; |
472 CreateAndLoad(false, true, &cookies); | 461 CreateAndLoad(false, true, &cookies); |
473 | 462 |
474 ASSERT_EQ(1U, cookies.size()); | 463 ASSERT_EQ(1U, cookies.size()); |
475 ASSERT_STREQ("sessioncookie.com", cookies[0]->Domain().c_str()); | 464 ASSERT_STREQ("sessioncookie.com", cookies[0]->Domain().c_str()); |
476 ASSERT_STREQ("C", cookies[0]->Name().c_str()); | 465 ASSERT_STREQ("C", cookies[0]->Name().c_str()); |
477 ASSERT_STREQ("D", cookies[0]->Value().c_str()); | 466 ASSERT_STREQ("D", cookies[0]->Value().c_str()); |
478 ASSERT_EQ(COOKIE_PRIORITY_DEFAULT, cookies[0]->Priority()); | 467 ASSERT_EQ(COOKIE_PRIORITY_DEFAULT, cookies[0]->Priority()); |
479 | 468 |
480 cookies.clear(); | 469 cookies.clear(); |
481 } | 470 } |
482 | 471 |
483 // Test loading old session cookies from the disk. | 472 // Test loading old session cookies from the disk. |
484 TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) { | 473 TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) { |
485 InitializeStore(false, true); | 474 InitializeStore(false, true); |
486 | 475 |
487 // Add a session cookie. | 476 // Add a session cookie. |
488 store_->AddCookie(*CanonicalCookie::Create( | 477 store_->AddCookie(*CanonicalCookie::Create( |
489 GURL("http://sessioncookie.com"), "C", "D", std::string(), "/", | 478 "C", "D", "sessioncookie.com", "/", base::Time::Now(), base::Time(), |
490 base::Time::Now(), base::Time(), false, false, | 479 base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
491 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 480 COOKIE_PRIORITY_DEFAULT)); |
492 | 481 |
493 // Force the store to write its data to the disk. | 482 // Force the store to write its data to the disk. |
494 DestroyStore(); | 483 DestroyStore(); |
495 | 484 |
496 // Create a store that doesn't load old session cookies and test that the | 485 // Create a store that doesn't load old session cookies and test that the |
497 // session cookie was not loaded. | 486 // session cookie was not loaded. |
498 CanonicalCookieVector cookies; | 487 CanonicalCookieVector cookies; |
499 CreateAndLoad(false, false, &cookies); | 488 CreateAndLoad(false, false, &cookies); |
500 ASSERT_EQ(0U, cookies.size()); | 489 ASSERT_EQ(0U, cookies.size()); |
501 | 490 |
502 // The store should also delete the session cookie. Wait until that has been | 491 // The store should also delete the session cookie. Wait until that has been |
503 // done. | 492 // done. |
504 DestroyStore(); | 493 DestroyStore(); |
505 | 494 |
506 // Create a store that loads old session cookies and test that the session | 495 // Create a store that loads old session cookies and test that the session |
507 // cookie is gone. | 496 // cookie is gone. |
508 CreateAndLoad(false, true, &cookies); | 497 CreateAndLoad(false, true, &cookies); |
509 ASSERT_EQ(0U, cookies.size()); | 498 ASSERT_EQ(0U, cookies.size()); |
510 } | 499 } |
511 | 500 |
512 TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) { | 501 TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) { |
513 InitializeStore(false, true); | 502 InitializeStore(false, true); |
514 static const char kSessionName[] = "session"; | 503 static const char kSessionName[] = "session"; |
515 static const char kPersistentName[] = "persistent"; | 504 static const char kPersistentName[] = "persistent"; |
516 | 505 |
517 // Add a session cookie. | 506 // Add a session cookie. |
518 store_->AddCookie(*CanonicalCookie::Create( | 507 store_->AddCookie(*CanonicalCookie::Create( |
519 GURL("http://sessioncookie.com"), kSessionName, "val", std::string(), "/", | 508 kSessionName, "val", "sessioncookie.com", "/", base::Time::Now(), |
520 base::Time::Now(), base::Time(), false, false, | 509 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
521 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 510 COOKIE_PRIORITY_DEFAULT)); |
522 // Add a persistent cookie. | 511 // Add a persistent cookie. |
523 store_->AddCookie(*CanonicalCookie::Create( | 512 store_->AddCookie(*CanonicalCookie::Create( |
524 GURL("http://sessioncookie.com"), kPersistentName, "val", std::string(), | 513 kPersistentName, "val", "sessioncookie.com", "/", |
525 "/", base::Time::Now() - base::TimeDelta::FromDays(1), | 514 base::Time::Now() - base::TimeDelta::FromDays(1), |
526 base::Time::Now() + base::TimeDelta::FromDays(1), false, false, | 515 base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false, |
527 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 516 false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
528 | 517 |
529 // Force the store to write its data to the disk. | 518 // Force the store to write its data to the disk. |
530 DestroyStore(); | 519 DestroyStore(); |
531 | 520 |
532 // Create a store that loads session cookie and test that the IsPersistent | 521 // Create a store that loads session cookie and test that the IsPersistent |
533 // attribute is restored. | 522 // attribute is restored. |
534 CanonicalCookieVector cookies; | 523 CanonicalCookieVector cookies; |
535 CreateAndLoad(false, true, &cookies); | 524 CreateAndLoad(false, true, &cookies); |
536 ASSERT_EQ(2U, cookies.size()); | 525 ASSERT_EQ(2U, cookies.size()); |
537 | 526 |
538 std::map<std::string, CanonicalCookie*> cookie_map; | 527 std::map<std::string, CanonicalCookie*> cookie_map; |
539 for (const auto& cookie : cookies) | 528 for (const auto& cookie : cookies) |
540 cookie_map[cookie->Name()] = cookie.get(); | 529 cookie_map[cookie->Name()] = cookie.get(); |
541 | 530 |
542 auto it = cookie_map.find(kSessionName); | 531 auto it = cookie_map.find(kSessionName); |
543 ASSERT_TRUE(it != cookie_map.end()); | 532 ASSERT_TRUE(it != cookie_map.end()); |
544 EXPECT_FALSE(cookie_map[kSessionName]->IsPersistent()); | 533 EXPECT_FALSE(cookie_map[kSessionName]->IsPersistent()); |
545 | 534 |
546 it = cookie_map.find(kPersistentName); | 535 it = cookie_map.find(kPersistentName); |
547 ASSERT_TRUE(it != cookie_map.end()); | 536 ASSERT_TRUE(it != cookie_map.end()); |
548 EXPECT_TRUE(cookie_map[kPersistentName]->IsPersistent()); | 537 EXPECT_TRUE(cookie_map[kPersistentName]->IsPersistent()); |
549 | 538 |
550 cookies.clear(); | 539 cookies.clear(); |
551 } | 540 } |
552 | 541 |
553 TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) { | 542 TEST_F(SQLitePersistentCookieStoreTest, PriorityIsPersistent) { |
554 static const char kURL[] = "http://sessioncookie.com"; | 543 static const char kDomain[] = "sessioncookie.com"; |
555 static const char kLowName[] = "low"; | 544 static const char kLowName[] = "low"; |
556 static const char kMediumName[] = "medium"; | 545 static const char kMediumName[] = "medium"; |
557 static const char kHighName[] = "high"; | 546 static const char kHighName[] = "high"; |
558 static const char kCookieValue[] = "value"; | 547 static const char kCookieValue[] = "value"; |
559 static const char kCookiePath[] = "/"; | 548 static const char kCookiePath[] = "/"; |
560 | 549 |
561 InitializeStore(false, true); | 550 InitializeStore(false, true); |
562 | 551 |
563 // Add a low-priority persistent cookie. | 552 // Add a low-priority persistent cookie. |
564 store_->AddCookie(*CanonicalCookie::Create( | 553 store_->AddCookie(*CanonicalCookie::Create( |
565 GURL(kURL), kLowName, kCookieValue, std::string(), kCookiePath, | 554 kLowName, kCookieValue, kDomain, kCookiePath, |
566 base::Time::Now() - base::TimeDelta::FromMinutes(1), | 555 base::Time::Now() - base::TimeDelta::FromMinutes(1), |
567 base::Time::Now() + base::TimeDelta::FromDays(1), false, false, | 556 base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false, |
568 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_LOW)); | 557 false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_LOW)); |
569 | 558 |
570 // Add a medium-priority persistent cookie. | 559 // Add a medium-priority persistent cookie. |
571 store_->AddCookie(*CanonicalCookie::Create( | 560 store_->AddCookie(*CanonicalCookie::Create( |
572 GURL(kURL), kMediumName, kCookieValue, std::string(), kCookiePath, | 561 kMediumName, kCookieValue, kDomain, kCookiePath, |
573 base::Time::Now() - base::TimeDelta::FromMinutes(2), | 562 base::Time::Now() - base::TimeDelta::FromMinutes(2), |
574 base::Time::Now() + base::TimeDelta::FromDays(1), false, false, | 563 base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false, |
575 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_MEDIUM)); | 564 false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_MEDIUM)); |
576 | 565 |
577 // Add a high-priority peristent cookie. | 566 // Add a high-priority peristent cookie. |
578 store_->AddCookie(*CanonicalCookie::Create( | 567 store_->AddCookie(*CanonicalCookie::Create( |
579 GURL(kURL), kHighName, kCookieValue, std::string(), kCookiePath, | 568 kHighName, kCookieValue, kDomain, kCookiePath, |
580 base::Time::Now() - base::TimeDelta::FromMinutes(3), | 569 base::Time::Now() - base::TimeDelta::FromMinutes(3), |
581 base::Time::Now() + base::TimeDelta::FromDays(1), false, false, | 570 base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false, |
582 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_HIGH)); | 571 false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_HIGH)); |
583 | 572 |
584 // Force the store to write its data to the disk. | 573 // Force the store to write its data to the disk. |
585 DestroyStore(); | 574 DestroyStore(); |
586 | 575 |
587 // Create a store that loads session cookie and test that the priority | 576 // Create a store that loads session cookie and test that the priority |
588 // attribute values are restored. | 577 // attribute values are restored. |
589 CanonicalCookieVector cookies; | 578 CanonicalCookieVector cookies; |
590 CreateAndLoad(false, true, &cookies); | 579 CreateAndLoad(false, true, &cookies); |
591 ASSERT_EQ(3U, cookies.size()); | 580 ASSERT_EQ(3U, cookies.size()); |
592 | 581 |
(...skipping 12 matching lines...) Expand all Loading... |
605 EXPECT_EQ(COOKIE_PRIORITY_MEDIUM, cookie_map[kMediumName]->Priority()); | 594 EXPECT_EQ(COOKIE_PRIORITY_MEDIUM, cookie_map[kMediumName]->Priority()); |
606 | 595 |
607 it = cookie_map.find(kHighName); | 596 it = cookie_map.find(kHighName); |
608 ASSERT_TRUE(it != cookie_map.end()); | 597 ASSERT_TRUE(it != cookie_map.end()); |
609 EXPECT_EQ(COOKIE_PRIORITY_HIGH, cookie_map[kHighName]->Priority()); | 598 EXPECT_EQ(COOKIE_PRIORITY_HIGH, cookie_map[kHighName]->Priority()); |
610 | 599 |
611 cookies.clear(); | 600 cookies.clear(); |
612 } | 601 } |
613 | 602 |
614 TEST_F(SQLitePersistentCookieStoreTest, SameSiteIsPersistent) { | 603 TEST_F(SQLitePersistentCookieStoreTest, SameSiteIsPersistent) { |
615 const char kURL[] = "http://sessioncookie.com"; | 604 const char kDomain[] = "sessioncookie.com"; |
616 const char kNoneName[] = "none"; | 605 const char kNoneName[] = "none"; |
617 const char kLaxName[] = "lax"; | 606 const char kLaxName[] = "lax"; |
618 const char kStrictName[] = "strict"; | 607 const char kStrictName[] = "strict"; |
619 const char kCookieValue[] = "value"; | 608 const char kCookieValue[] = "value"; |
620 const char kCookiePath[] = "/"; | 609 const char kCookiePath[] = "/"; |
621 | 610 |
622 InitializeStore(false, true); | 611 InitializeStore(false, true); |
623 | 612 |
624 // Add a non-samesite cookie. | 613 // Add a non-samesite cookie. |
625 store_->AddCookie(*CanonicalCookie::Create( | 614 store_->AddCookie(*CanonicalCookie::Create( |
626 GURL(kURL), kNoneName, kCookieValue, std::string(), kCookiePath, | 615 kNoneName, kCookieValue, kDomain, kCookiePath, |
627 base::Time::Now() - base::TimeDelta::FromMinutes(1), | 616 base::Time::Now() - base::TimeDelta::FromMinutes(1), |
628 base::Time::Now() + base::TimeDelta::FromDays(1), false, false, | 617 base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false, |
629 CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT)); | 618 false, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT)); |
630 | 619 |
631 // Add a lax-samesite persistent cookie. | 620 // Add a lax-samesite persistent cookie. |
632 store_->AddCookie(*CanonicalCookie::Create( | 621 store_->AddCookie(*CanonicalCookie::Create( |
633 GURL(kURL), kLaxName, kCookieValue, std::string(), kCookiePath, | 622 kLaxName, kCookieValue, kDomain, kCookiePath, |
634 base::Time::Now() - base::TimeDelta::FromMinutes(2), | 623 base::Time::Now() - base::TimeDelta::FromMinutes(2), |
635 base::Time::Now() + base::TimeDelta::FromDays(1), false, false, | 624 base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false, |
636 CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT)); | 625 false, CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT)); |
637 | 626 |
638 // Add a strict-samesite persistent cookie. | 627 // Add a strict-samesite persistent cookie. |
639 store_->AddCookie(*CanonicalCookie::Create( | 628 store_->AddCookie(*CanonicalCookie::Create( |
640 GURL(kURL), kStrictName, kCookieValue, std::string(), kCookiePath, | 629 kStrictName, kCookieValue, kDomain, kCookiePath, |
641 base::Time::Now() - base::TimeDelta::FromMinutes(3), | 630 base::Time::Now() - base::TimeDelta::FromMinutes(3), |
642 base::Time::Now() + base::TimeDelta::FromDays(1), false, false, | 631 base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false, |
643 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT)); | 632 false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT)); |
644 | 633 |
645 // Force the store to write its data to the disk. | 634 // Force the store to write its data to the disk. |
646 DestroyStore(); | 635 DestroyStore(); |
647 | 636 |
648 // Create a store that loads session cookie and test that the priority | 637 // Create a store that loads session cookie and test that the priority |
649 // attribute values are restored. | 638 // attribute values are restored. |
650 CanonicalCookieVector cookies; | 639 CanonicalCookieVector cookies; |
651 CreateAndLoad(false, true, &cookies); | 640 CreateAndLoad(false, true, &cookies); |
652 ASSERT_EQ(3U, cookies.size()); | 641 ASSERT_EQ(3U, cookies.size()); |
653 | 642 |
(...skipping 13 matching lines...) Expand all Loading... |
667 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie_map[kStrictName]->SameSite()); | 656 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie_map[kStrictName]->SameSite()); |
668 | 657 |
669 cookies.clear(); | 658 cookies.clear(); |
670 } | 659 } |
671 | 660 |
672 TEST_F(SQLitePersistentCookieStoreTest, UpdateToEncryption) { | 661 TEST_F(SQLitePersistentCookieStoreTest, UpdateToEncryption) { |
673 CanonicalCookieVector cookies; | 662 CanonicalCookieVector cookies; |
674 | 663 |
675 // Create unencrypted cookie store and write something to it. | 664 // Create unencrypted cookie store and write something to it. |
676 InitializeStore(false, false); | 665 InitializeStore(false, false); |
677 AddCookie(GURL("http://foo.bar"), "name", "value123XYZ", std::string(), "/", | 666 AddCookie("name", "value123XYZ", "foo.bar", "/", base::Time::Now()); |
678 base::Time::Now()); | |
679 DestroyStore(); | 667 DestroyStore(); |
680 | 668 |
681 // Verify that "value" is visible in the file. This is necessary in order to | 669 // Verify that "value" is visible in the file. This is necessary in order to |
682 // have confidence in a later test that "encrypted_value" is not visible. | 670 // have confidence in a later test that "encrypted_value" is not visible. |
683 std::string contents = ReadRawDBContents(); | 671 std::string contents = ReadRawDBContents(); |
684 EXPECT_NE(0U, contents.length()); | 672 EXPECT_NE(0U, contents.length()); |
685 EXPECT_NE(contents.find("value123XYZ"), std::string::npos); | 673 EXPECT_NE(contents.find("value123XYZ"), std::string::npos); |
686 | 674 |
687 // Create encrypted cookie store and ensure old cookie still reads. | 675 // Create encrypted cookie store and ensure old cookie still reads. |
688 cookies.clear(); | 676 cookies.clear(); |
689 EXPECT_EQ(0U, cookies.size()); | 677 EXPECT_EQ(0U, cookies.size()); |
690 CreateAndLoad(true, false, &cookies); | 678 CreateAndLoad(true, false, &cookies); |
691 EXPECT_EQ(1U, cookies.size()); | 679 EXPECT_EQ(1U, cookies.size()); |
692 EXPECT_EQ("name", cookies[0]->Name()); | 680 EXPECT_EQ("name", cookies[0]->Name()); |
693 EXPECT_EQ("value123XYZ", cookies[0]->Value()); | 681 EXPECT_EQ("value123XYZ", cookies[0]->Value()); |
694 | 682 |
695 // Make sure we can update existing cookie and add new cookie as encrypted. | 683 // Make sure we can update existing cookie and add new cookie as encrypted. |
696 store_->DeleteCookie(*(cookies[0])); | 684 store_->DeleteCookie(*(cookies[0])); |
697 AddCookie(GURL("http://foo.bar"), "name", "encrypted_value123XYZ", | 685 AddCookie("name", "encrypted_value123XYZ", "foo.bar", "/", base::Time::Now()); |
698 std::string(), "/", base::Time::Now()); | 686 AddCookie("other", "something456ABC", "foo.bar", "/", |
699 AddCookie(GURL("http://foo.bar"), "other", "something456ABC", std::string(), | 687 base::Time::Now() + base::TimeDelta::FromInternalValue(10)); |
700 "/", base::Time::Now() + base::TimeDelta::FromInternalValue(10)); | |
701 DestroyStore(); | 688 DestroyStore(); |
702 cookies.clear(); | 689 cookies.clear(); |
703 CreateAndLoad(true, false, &cookies); | 690 CreateAndLoad(true, false, &cookies); |
704 EXPECT_EQ(2U, cookies.size()); | 691 EXPECT_EQ(2U, cookies.size()); |
705 CanonicalCookie* cookie_name = nullptr; | 692 CanonicalCookie* cookie_name = nullptr; |
706 CanonicalCookie* cookie_other = nullptr; | 693 CanonicalCookie* cookie_other = nullptr; |
707 if (cookies[0]->Name() == "name") { | 694 if (cookies[0]->Name() == "name") { |
708 cookie_name = cookies[0].get(); | 695 cookie_name = cookies[0].get(); |
709 cookie_other = cookies[1].get(); | 696 cookie_other = cookies[1].get(); |
710 } else { | 697 } else { |
(...skipping 28 matching lines...) Expand all Loading... |
739 EXPECT_NE(0U, contents.length()); | 726 EXPECT_NE(0U, contents.length()); |
740 EXPECT_EQ(contents.find("encrypted_value123XYZ"), std::string::npos); | 727 EXPECT_EQ(contents.find("encrypted_value123XYZ"), std::string::npos); |
741 EXPECT_EQ(contents.find("something456ABC"), std::string::npos); | 728 EXPECT_EQ(contents.find("something456ABC"), std::string::npos); |
742 } | 729 } |
743 | 730 |
744 TEST_F(SQLitePersistentCookieStoreTest, UpdateFromEncryption) { | 731 TEST_F(SQLitePersistentCookieStoreTest, UpdateFromEncryption) { |
745 CanonicalCookieVector cookies; | 732 CanonicalCookieVector cookies; |
746 | 733 |
747 // Create unencrypted cookie store and write something to it. | 734 // Create unencrypted cookie store and write something to it. |
748 InitializeStore(true, false); | 735 InitializeStore(true, false); |
749 AddCookie(GURL("http://foo.bar"), "name", "value123XYZ", std::string(), "/", | 736 AddCookie("name", "value123XYZ", "foo.bar", "/", base::Time::Now()); |
750 base::Time::Now()); | |
751 DestroyStore(); | 737 DestroyStore(); |
752 | 738 |
753 // Verify that "value" is not visible in the file. | 739 // Verify that "value" is not visible in the file. |
754 std::string contents = ReadRawDBContents(); | 740 std::string contents = ReadRawDBContents(); |
755 EXPECT_NE(0U, contents.length()); | 741 EXPECT_NE(0U, contents.length()); |
756 EXPECT_EQ(contents.find("value123XYZ"), std::string::npos); | 742 EXPECT_EQ(contents.find("value123XYZ"), std::string::npos); |
757 | 743 |
758 // Create encrypted cookie store and ensure old cookie still reads. | 744 // Create encrypted cookie store and ensure old cookie still reads. |
759 cookies.clear(); | 745 cookies.clear(); |
760 EXPECT_EQ(0U, cookies.size()); | 746 EXPECT_EQ(0U, cookies.size()); |
761 CreateAndLoad(true, false, &cookies); | 747 CreateAndLoad(true, false, &cookies); |
762 EXPECT_EQ(1U, cookies.size()); | 748 EXPECT_EQ(1U, cookies.size()); |
763 EXPECT_EQ("name", cookies[0]->Name()); | 749 EXPECT_EQ("name", cookies[0]->Name()); |
764 EXPECT_EQ("value123XYZ", cookies[0]->Value()); | 750 EXPECT_EQ("value123XYZ", cookies[0]->Value()); |
765 | 751 |
766 // Make sure we can update existing cookie and it writes unencrypted. | 752 // Make sure we can update existing cookie and it writes unencrypted. |
767 cookie_crypto_delegate_->should_encrypt_ = false; | 753 cookie_crypto_delegate_->should_encrypt_ = false; |
768 store_->DeleteCookie(*(cookies[0])); | 754 store_->DeleteCookie(*(cookies[0])); |
769 AddCookie(GURL("http://foo.bar"), "name", "plaintext_value123XYZ", | 755 AddCookie("name", "plaintext_value123XYZ", "foo.bar", "/", base::Time::Now()); |
770 std::string(), "/", base::Time::Now()); | 756 AddCookie("other", "something456ABC", "foo.bar", "/", |
771 AddCookie(GURL("http://foo.bar"), "other", "something456ABC", std::string(), | 757 base::Time::Now() + base::TimeDelta::FromInternalValue(10)); |
772 "/", base::Time::Now() + base::TimeDelta::FromInternalValue(10)); | |
773 DestroyStore(); | 758 DestroyStore(); |
774 cookies.clear(); | 759 cookies.clear(); |
775 CreateAndLoad(true, false, &cookies); | 760 CreateAndLoad(true, false, &cookies); |
776 EXPECT_EQ(2U, cookies.size()); | 761 EXPECT_EQ(2U, cookies.size()); |
777 CanonicalCookie* cookie_name = nullptr; | 762 CanonicalCookie* cookie_name = nullptr; |
778 CanonicalCookie* cookie_other = nullptr; | 763 CanonicalCookie* cookie_other = nullptr; |
779 if (cookies[0]->Name() == "name") { | 764 if (cookies[0]->Name() == "name") { |
780 cookie_name = cookies[0].get(); | 765 cookie_name = cookies[0].get(); |
781 cookie_other = cookies[1].get(); | 766 cookie_other = cookies[1].get(); |
782 } else { | 767 } else { |
(...skipping 15 matching lines...) Expand all Loading... |
798 void WasCalledWithNoCookies( | 783 void WasCalledWithNoCookies( |
799 bool* was_called_with_no_cookies, | 784 bool* was_called_with_no_cookies, |
800 std::vector<std::unique_ptr<CanonicalCookie>> cookies) { | 785 std::vector<std::unique_ptr<CanonicalCookie>> cookies) { |
801 *was_called_with_no_cookies = cookies.empty(); | 786 *was_called_with_no_cookies = cookies.empty(); |
802 } | 787 } |
803 } | 788 } |
804 | 789 |
805 TEST_F(SQLitePersistentCookieStoreTest, EmptyLoadAfterClose) { | 790 TEST_F(SQLitePersistentCookieStoreTest, EmptyLoadAfterClose) { |
806 // Create unencrypted cookie store and write something to it. | 791 // Create unencrypted cookie store and write something to it. |
807 InitializeStore(false, false); | 792 InitializeStore(false, false); |
808 AddCookie(GURL("http://foo.bar"), "name", "value123XYZ", std::string(), "/", | 793 AddCookie("name", "value123XYZ", "foo.bar", "/", base::Time::Now()); |
809 base::Time::Now()); | |
810 DestroyStore(); | 794 DestroyStore(); |
811 | 795 |
812 // Create the cookie store, but immediately close it. | 796 // Create the cookie store, but immediately close it. |
813 Create(false, false); | 797 Create(false, false); |
814 store_->Close(base::Closure()); | 798 store_->Close(base::Closure()); |
815 | 799 |
816 // Expect any attempt to call Load() to synchronously respond with an empty | 800 // Expect any attempt to call Load() to synchronously respond with an empty |
817 // vector of cookies after we've Close()d the database. | 801 // vector of cookies after we've Close()d the database. |
818 bool was_called_with_no_cookies = false; | 802 bool was_called_with_no_cookies = false; |
819 store_->Load(base::Bind(WasCalledWithNoCookies, &was_called_with_no_cookies)); | 803 store_->Load(base::Bind(WasCalledWithNoCookies, &was_called_with_no_cookies)); |
820 EXPECT_TRUE(was_called_with_no_cookies); | 804 EXPECT_TRUE(was_called_with_no_cookies); |
821 | 805 |
822 // Same with trying to load a specific cookie. | 806 // Same with trying to load a specific cookie. |
823 was_called_with_no_cookies = false; | 807 was_called_with_no_cookies = false; |
824 store_->LoadCookiesForKey("foo.bar", base::Bind(WasCalledWithNoCookies, | 808 store_->LoadCookiesForKey("foo.bar", base::Bind(WasCalledWithNoCookies, |
825 &was_called_with_no_cookies)); | 809 &was_called_with_no_cookies)); |
826 EXPECT_TRUE(was_called_with_no_cookies); | 810 EXPECT_TRUE(was_called_with_no_cookies); |
827 } | 811 } |
828 | 812 |
829 } // namespace net | 813 } // namespace net |
OLD | NEW |