Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1605)

Side by Side Diff: chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc

Issue 10447117: Unwire the clear on exit preference from the storage systems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 content::TestBrowserThread db_thread_; 111 content::TestBrowserThread db_thread_;
112 content::TestBrowserThread io_thread_; 112 content::TestBrowserThread io_thread_;
113 base::WaitableEvent loaded_event_; 113 base::WaitableEvent loaded_event_;
114 base::WaitableEvent key_loaded_event_; 114 base::WaitableEvent key_loaded_event_;
115 base::WaitableEvent db_thread_event_; 115 base::WaitableEvent db_thread_event_;
116 std::vector<net::CookieMonster::CanonicalCookie*> cookies_; 116 std::vector<net::CookieMonster::CanonicalCookie*> cookies_;
117 ScopedTempDir temp_dir_; 117 ScopedTempDir temp_dir_;
118 scoped_refptr<SQLitePersistentCookieStore> store_; 118 scoped_refptr<SQLitePersistentCookieStore> store_;
119 }; 119 };
120 120
121 TEST_F(SQLitePersistentCookieStoreTest, KeepOnDestruction) {
122 InitializeStore(false);
123 // Put some data - any data - on disk, to have something to keep.
124 AddCookie("A", "B", "foo.bar", "/", base::Time::Now());
125 store_->SetClearLocalStateOnExit(false);
126 DestroyStore();
127
128 ASSERT_TRUE(file_util::PathExists(
129 temp_dir_.path().Append(chrome::kCookieFilename)));
130 ASSERT_TRUE(file_util::Delete(
131 temp_dir_.path().Append(chrome::kCookieFilename), false));
132 }
133
134 TEST_F(SQLitePersistentCookieStoreTest, RemoveOnDestruction) {
135 InitializeStore(false);
136 // Put some data - any data - on disk, to have something to remove.
137 AddCookie("A", "B", "foo.bar", "/", base::Time::Now());
138 store_->SetClearLocalStateOnExit(true);
139 DestroyStore();
140
141 ASSERT_FALSE(file_util::PathExists(
142 temp_dir_.path().Append(chrome::kCookieFilename)));
143 }
144
145 TEST_F(SQLitePersistentCookieStoreTest, TestInvalidMetaTableRecovery) { 121 TEST_F(SQLitePersistentCookieStoreTest, TestInvalidMetaTableRecovery) {
146 InitializeStore(false); 122 InitializeStore(false);
147 AddCookie("A", "B", "foo.bar", "/", base::Time::Now()); 123 AddCookie("A", "B", "foo.bar", "/", base::Time::Now());
148 DestroyStore(); 124 DestroyStore();
149 125
150 // Load up the store and verify that it has good data in it. 126 // Load up the store and verify that it has good data in it.
151 std::vector<net::CookieMonster::CanonicalCookie*> cookies; 127 std::vector<net::CookieMonster::CanonicalCookie*> cookies;
152 CreateAndLoad(false, &cookies); 128 CreateAndLoad(false, &cookies);
153 ASSERT_EQ(1U, cookies.size()); 129 ASSERT_EQ(1U, cookies.size());
154 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str()); 130 ASSERT_STREQ("foo.bar", cookies[0]->Domain().c_str());
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 t += base::TimeDelta::FromInternalValue(10); 486 t += base::TimeDelta::FromInternalValue(10);
511 AddCookie("C", "3", other_origin, "/", t); 487 AddCookie("C", "3", other_origin, "/", t);
512 // A secure cookie on session_origin. 488 // A secure cookie on session_origin.
513 t += base::TimeDelta::FromInternalValue(10); 489 t += base::TimeDelta::FromInternalValue(10);
514 store_->AddCookie( 490 store_->AddCookie(
515 net::CookieMonster::CanonicalCookie(GURL(), "D", "4", session_origin, "/", 491 net::CookieMonster::CanonicalCookie(GURL(), "D", "4", session_origin, "/",
516 std::string(), std::string(), 492 std::string(), std::string(),
517 t, t, t, 493 t, t, t,
518 true, false, true, true)); 494 true, false, true, true));
519 495
496 // First, check that we can override the policy.
497 store_->SetForceKeepSessionState();
498
520 // Force the store to write its data to the disk. 499 // Force the store to write its data to the disk.
521 DestroyStore(); 500 DestroyStore();
522 501
523 // Create a store test that the cookie on session_origin does not exist. 502 // Create a store test that the cookie on session_origin does not exist.
524 store_ = new SQLitePersistentCookieStore( 503 store_ = new SQLitePersistentCookieStore(
525 temp_dir_.path().Append(chrome::kCookieFilename), 504 temp_dir_.path().Append(chrome::kCookieFilename),
526 false, 505 false,
527 clear_policy.get()); 506 clear_policy.get());
528 Load(&cookies); 507 Load(&cookies);
529 508
509 EXPECT_EQ(4U, cookies.size());
510 EXPECT_TRUE(IsCookiePresent(&cookies, protected_origin, "A", "1", false));
511 EXPECT_TRUE(IsCookiePresent(&cookies, session_origin, "B", "2", false));
512 EXPECT_TRUE(IsCookiePresent(&cookies, other_origin, "C", "3", false));
513 EXPECT_TRUE(IsCookiePresent(&cookies, session_origin, "D", "4", true));
514
515 // This time, the clear on exit policy should be in effect.
516 DestroyStore();
517
518 // Create a store test that the cookie on session_origin does not exist.
519 store_ = new SQLitePersistentCookieStore(
520 temp_dir_.path().Append(chrome::kCookieFilename),
521 false,
522 clear_policy.get());
523 Load(&cookies);
524
530 EXPECT_EQ(3U, cookies.size()); 525 EXPECT_EQ(3U, cookies.size());
531 EXPECT_TRUE(IsCookiePresent(&cookies, protected_origin, "A", "1", false)); 526 EXPECT_TRUE(IsCookiePresent(&cookies, protected_origin, "A", "1", false));
532 EXPECT_TRUE(IsCookiePresent(&cookies, other_origin, "C", "3", false)); 527 EXPECT_TRUE(IsCookiePresent(&cookies, other_origin, "C", "3", false));
533 EXPECT_TRUE(IsCookiePresent(&cookies, session_origin, "D", "4", true)); 528 EXPECT_TRUE(IsCookiePresent(&cookies, session_origin, "D", "4", true));
534 529
535 DestroyStore(); 530 DestroyStore();
536 } 531 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698