From 218aa6a199672545356f7fd49c7937b3272fdac6 Mon Sep 17 00:00:00 2001 From: "erikwright@chromium.org" Date: Tue, 13 Sep 2011 17:38:38 +0000 Subject: Third try at committing this. Patchset 1 is the original patch ( http://codereview.chromium.org/7833042/ ). Patchset 2 is the original patch plus a fix to a memory leak from the initial commit ( http://codereview.chromium.org/7831056/ ) On the first try there was a memory leak in a test. I fixed that, but made a mistake in the commit (the committed code did not correspond to the reviewed code). Both commits were reverted. I then landed a new CL ( http://codereview.chromium.org/7860039/ ) that contained the correct changes combining the first two CLs. This caused an error in heapchecker for which a suppression has subsequently been defined ( http://codereview.chromium.org/7780010 ). In summary, all of this is reviewed, minus some lint fixes. BUG=68657 TEST=net_unittests / DeferredCookieTaskTest.* and CookieMonsterTest.* TBR=estade Review URL: http://codereview.chromium.org/7891008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100932 0039d316-1c4b-4281-b951-d872f2087c98 --- .../net/sqlite_persistent_cookie_store_unittest.cc | 33 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc') diff --git a/chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc b/chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc index f3e52cc..942ca83 100644 --- a/chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc +++ b/chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc @@ -2,11 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/bind.h" #include "base/file_util.h" #include "base/memory/ref_counted.h" #include "base/message_loop.h" #include "base/scoped_temp_dir.h" #include "base/stl_util.h" +#include "base/synchronization/waitable_event.h" #include "base/test/thread_test_helper.h" #include "base/time.h" #include "chrome/browser/net/sqlite_persistent_cookie_store.h" @@ -19,19 +21,37 @@ class SQLitePersistentCookieStoreTest : public testing::Test { public: SQLitePersistentCookieStoreTest() : ui_thread_(BrowserThread::UI), - db_thread_(BrowserThread::DB) { + db_thread_(BrowserThread::DB), + io_thread_(BrowserThread::IO), + event_(false, false) { } protected: + void OnLoaded( + const std::vector& cookies) { + cookies_ = cookies; + event_.Signal(); + } + + bool Load(std::vector* cookies) { + bool result = + store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, + base::Unretained(this))); + event_.Wait(); + *cookies = cookies_; + return result; + } + virtual void SetUp() { ui_thread_.Start(); db_thread_.Start(); + io_thread_.Start(); ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); store_ = new SQLitePersistentCookieStore( temp_dir_.path().Append(chrome::kCookieFilename)); std::vector cookies; - ASSERT_TRUE(store_->Load(&cookies)); - ASSERT_TRUE(0 == cookies.size()); + ASSERT_TRUE(Load(&cookies)); + ASSERT_EQ(0u, cookies.size()); // Make sure the store gets written at least once. store_->AddCookie( net::CookieMonster::CanonicalCookie(GURL(), "A", "B", "http://foo.bar", @@ -44,6 +64,9 @@ class SQLitePersistentCookieStoreTest : public testing::Test { BrowserThread ui_thread_; BrowserThread db_thread_; + BrowserThread io_thread_; + base::WaitableEvent event_; + std::vector cookies_; ScopedTempDir temp_dir_; scoped_refptr store_; }; @@ -95,7 +118,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestPersistance) { temp_dir_.path().Append(chrome::kCookieFilename)); // Reload and test for persistence - ASSERT_TRUE(store_->Load(&cookies)); + ASSERT_TRUE(Load(&cookies)); ASSERT_EQ(1U, cookies.size()); ASSERT_STREQ("http://foo.bar", cookies[0]->Domain().c_str()); ASSERT_STREQ("A", cookies[0]->Name().c_str()); @@ -112,7 +135,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestPersistance) { temp_dir_.path().Append(chrome::kCookieFilename)); // Reload and check if the cookie has been removed. - ASSERT_TRUE(store_->Load(&cookies)); + ASSERT_TRUE(Load(&cookies)); ASSERT_EQ(0U, cookies.size()); } -- cgit v1.1