summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-09 02:24:18 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-09 02:24:18 +0000
commitd36cba48e5d038505c0ad48ef54d734792312a91 (patch)
treecf455e4e336403703e48d67dd4ec4ad0aefbd093 /net/base
parent575fdd3b09c42c0a25fe2a7c3e7b6b94dd78e95a (diff)
downloadchromium_src-d36cba48e5d038505c0ad48ef54d734792312a91.zip
chromium_src-d36cba48e5d038505c0ad48ef54d734792312a91.tar.gz
chromium_src-d36cba48e5d038505c0ad48ef54d734792312a91.tar.bz2
Revert 100316 - Fix a memory leak in a unit test.
In the DeferredDeleteCanonicalCookie test, we were using an existing helper method that initialized a CanonicalCookie on the heap and put a pointer to it in a list. This makes sense for other tests because they provide that list to the CookieMonster, which takes ownership of the list. In this case, we only needed one cookie, which we pass by reference to the CookieMonster via a method that does not take ownership. Yet, it's enough of a hassle to create the cookie that I used this method. The result is that no-one deletes the cookie from the heap. I extracted the existing code that prepared the cookie, so that one can create either a single cookie or a list of them. BUG=68657 TEST=net_unittests / DeferredDeleteCanonicalCookie Review URL: http://codereview.chromium.org/7831056 TBR=erikwright@chromium.org Review URL: http://codereview.chromium.org/7857023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100332 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/cookie_monster_store_test.cc21
-rw-r--r--net/base/cookie_monster_store_test.h6
-rw-r--r--net/base/cookie_monster_unittest.cc7
3 files changed, 12 insertions, 22 deletions
diff --git a/net/base/cookie_monster_store_test.cc b/net/base/cookie_monster_store_test.cc
index 1f129bd..717a70c 100644
--- a/net/base/cookie_monster_store_test.cc
+++ b/net/base/cookie_monster_store_test.cc
@@ -80,13 +80,6 @@ void AddCookieToList(
const std::string& cookie_line,
const base::Time& creation_time,
std::vector<CookieMonster::CanonicalCookie*>* out_list) {
- out_list->push_back(BuildCanonicalCookie(key, cookie_line, creation_time));
-}
-
-CookieMonster::CanonicalCookie* BuildCanonicalCookie(
- const std::string& key,
- const std::string& cookie_line,
- const base::Time& creation_time) {
// Parse the cookie line.
CookieMonster::ParsedCookie pc(cookie_line);
@@ -101,11 +94,15 @@ CookieMonster::CanonicalCookie* BuildCanonicalCookie(
CookieMonster::ParseCookieTime(pc.Expires()) : base::Time();
std::string cookie_path = pc.Path();
- return CookieMonster::CanonicalCookie::Create(
- GURL(), pc.Name(), pc.Value(), key, cookie_path,
- pc.MACKey(), pc.MACAlgorithm(),
- creation_time, cookie_expires,
- pc.IsSecure(), pc.IsHttpOnly());
+ scoped_ptr<CookieMonster::CanonicalCookie> cookie(
+ new CookieMonster::CanonicalCookie(
+ GURL(), pc.Name(), pc.Value(), key, cookie_path,
+ pc.MACKey(), pc.MACAlgorithm(),
+ creation_time, creation_time, cookie_expires,
+ pc.IsSecure(), pc.IsHttpOnly(),
+ !cookie_expires.is_null()));
+
+ out_list->push_back(cookie.release());
}
MockSimplePersistentCookieStore::MockSimplePersistentCookieStore() {}
diff --git a/net/base/cookie_monster_store_test.h b/net/base/cookie_monster_store_test.h
index 9d51906..bff777c 100644
--- a/net/base/cookie_monster_store_test.h
+++ b/net/base/cookie_monster_store_test.h
@@ -109,12 +109,6 @@ class MockCookieMonsterDelegate : public CookieMonster::Delegate {
DISALLOW_COPY_AND_ASSIGN(MockCookieMonsterDelegate);
};
-// Helper to build a single CanonicalCookie.
-CookieMonster::CanonicalCookie* BuildCanonicalCookie(
- const std::string& key,
- const std::string& cookie_line,
- const base::Time& creation_time);
-
// Helper to build a list of CanonicalCookie*s.
void AddCookieToList(
const std::string& key,
diff --git a/net/base/cookie_monster_unittest.cc b/net/base/cookie_monster_unittest.cc
index a08280a..67f3396 100644
--- a/net/base/cookie_monster_unittest.cc
+++ b/net/base/cookie_monster_unittest.cc
@@ -1294,19 +1294,18 @@ TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) {
TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) {
std::vector<CookieMonster::CanonicalCookie*> cookies;
- scoped_ptr<CookieMonster::CanonicalCookie> cookie(BuildCanonicalCookie(
- "www.google.com", "X=1; path=/", base::Time::Now()));
+ AddCookieToList("www.google.com", "X=1; path=/", base::Time::Now(), &cookies);
MockDeleteCookieCallback delete_cookie_callback;
BeginWith(DeleteCanonicalCookieAction(
- &cookie_monster(), *cookie, &delete_cookie_callback));
+ &cookie_monster(), *cookies[0], &delete_cookie_callback));
WaitForLoadCall();
EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce(
DeleteCanonicalCookieAction(
- &cookie_monster(), *cookie, &delete_cookie_callback));
+ &cookie_monster(), *cookies[0], &delete_cookie_callback));
EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce(
QuitCurrentMessageLoop());