Fixed leak in ExtensionBookmarksTest.

BUG=101468
TEST=ExtensionBookmarksTest.* passes and doesn't leak a DictionaryValue


Review URL: http://codereview.chromium.org/8394001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107132 0039d316-1c4b-4281-b951-d872f2087c98
parent 88c6271c
......@@ -21,6 +21,7 @@ class ListValue;
// Helper functions.
namespace bookmark_extension_helpers {
// The returned value is owned by the caller.
base::DictionaryValue* GetNodeDictionary(const BookmarkNode* node,
bool recurse,
bool only_folders);
......
......@@ -2,60 +2,64 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "testing/gtest/include/gtest/gtest.h"
#include "chrome/browser/bookmarks/bookmark_extension_helpers.h"
#include "base/memory/scoped_ptr.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_extension_api_constants.h"
#include "chrome/browser/bookmarks/bookmark_extension_helpers.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace keys = bookmark_extension_api_constants;
class ExtensionBookmarksTest : public testing::Test {
public:
virtual void SetUp() {
virtual void SetUp() OVERRIDE {
model_.reset(new BookmarkModel(NULL));
model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("Digg"),
GURL("http://www.reddit.com"));
model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("News"),
GURL("http://www.foxnews.com"));
folder = model_->AddFolder(
folder_ = model_->AddFolder(
model_->other_node(), 0, ASCIIToUTF16("outer folder"));
model_->AddFolder(folder, 0, ASCIIToUTF16("inner folder 1"));
model_->AddFolder(folder, 0, ASCIIToUTF16("inner folder 2"));
model_->AddURL(folder, 0, ASCIIToUTF16("Digg"), GURL("http://reddit.com"));
model_->AddURL(folder, 0, ASCIIToUTF16("CNet"), GURL("http://cnet.com"));
model_->AddFolder(folder_, 0, ASCIIToUTF16("inner folder 1"));
model_->AddFolder(folder_, 0, ASCIIToUTF16("inner folder 2"));
model_->AddURL(folder_, 0, ASCIIToUTF16("Digg"), GURL("http://reddit.com"));
model_->AddURL(folder_, 0, ASCIIToUTF16("CNet"), GURL("http://cnet.com"));
}
scoped_ptr<BookmarkModel> model_;
const BookmarkNode* folder;
const BookmarkNode* folder_;
};
TEST_F(ExtensionBookmarksTest, GetFullTreeFromRoot) {
DictionaryValue* tree = bookmark_extension_helpers::GetNodeDictionary(
model_->other_node(),
true, // Recurse.
false); // Not only folders.
scoped_ptr<DictionaryValue> tree(
bookmark_extension_helpers::GetNodeDictionary(
model_->other_node(),
true, // Recurse.
false)); // Not only folders.
ListValue* children;
tree->GetList(keys::kChildrenKey, &children);
ASSERT_EQ(3U, children->GetSize());
}
TEST_F(ExtensionBookmarksTest, GetFoldersOnlyFromRoot) {
DictionaryValue* tree = bookmark_extension_helpers::GetNodeDictionary(
model_->other_node(),
true, // Recurse.
true); // Only folders.
scoped_ptr<DictionaryValue> tree(
bookmark_extension_helpers::GetNodeDictionary(
model_->other_node(),
true, // Recurse.
true)); // Only folders.
ListValue* children;
tree->GetList(keys::kChildrenKey, &children);
ASSERT_EQ(1U, children->GetSize());
}
TEST_F(ExtensionBookmarksTest, GetSubtree) {
DictionaryValue* tree = bookmark_extension_helpers::GetNodeDictionary(
folder,
true, // Recurse.
false); // Not only folders.
scoped_ptr<DictionaryValue> tree(
bookmark_extension_helpers::GetNodeDictionary(
folder_,
true, // Recurse.
false)); // Not only folders.
ListValue* children;
tree->GetList(keys::kChildrenKey, &children);
ASSERT_EQ(4U, children->GetSize());
......@@ -67,10 +71,11 @@ TEST_F(ExtensionBookmarksTest, GetSubtree) {
}
TEST_F(ExtensionBookmarksTest, GetSubtreeFoldersOnly) {
DictionaryValue* tree = bookmark_extension_helpers::GetNodeDictionary(
folder,
true, // Recurse.
true); // Only folders.
scoped_ptr<DictionaryValue> tree(
bookmark_extension_helpers::GetNodeDictionary(
folder_,
true, // Recurse.
true)); // Only folders.
ListValue* children;
tree->GetList(keys::kChildrenKey, &children);
ASSERT_EQ(2U, children->GetSize());
......
......@@ -4945,29 +4945,6 @@
fun:_ZN5ppapi5proxy38EnterHostFromHostResourceForceCallbackINS_5thunk18PPB_Graphics2D_APIEEC1IN2pp25CompletionCallbackFactoryINS0_20PPB_Graphics2D_ProxyENS0_26ProxyNonThreadSafeRefCountEEEMS8_FviRKNS_12HostResourceEESB_EESD_RT_T0_RKT1_
fun:_ZN5ppapi5proxy20PPB_Graphics2D_Proxy10OnMsgFlushERKNS_12HostResourceE
}
{
bug_101468a
Memcheck:Leak
fun:_Znw*
fun:_ZN9__gnu_cxx13new_allocatorISt13_Rb_tree_nodeISt4pairIKSsPN4base5ValueEEEE8allocateEmPKv
fun:_ZNSt8_Rb_treeISsSt4pairIKSsPN4base5ValueEESt10_Select1stIS5_ESt4lessISsESaIS5_EE11_M_get_nodeEv
fun:_ZNSt8_Rb_treeISsSt4pairIKSsPN4base5ValueEESt10_Select1stIS5_ESt4lessISsESaIS5_EE14_M_create_nodeERKS5_
fun:_ZNSt8_Rb_treeISsSt4pairIKSsPN4base5ValueEESt10_Select1stIS5_ESt4lessISsESaIS5_EE10_M_insert_EPKSt18_Rb_tree_node_baseSE_RKS5_
fun:_ZNSt8_Rb_treeISsSt4pairIKSsPN4base5ValueEESt10_Select1stIS5_ESt4lessISsESaIS5_EE16_M_insert_uniqueERKS5_
fun:_ZNSt3mapISsPN4base5ValueESt4lessISsESaISt4pairIKSsS2_EEE6insertERKS7_
fun:_ZN4base15DictionaryValue23SetWithoutPathExpansionERKSsPNS_5ValueE
fun:_ZN4base15DictionaryValue3SetERKSsPNS_5ValueE
...
fun:_ZN26bookmark_extension_helpers17GetNodeDictionaryEPK12BookmarkNodebb
fun:_ZN*ExtensionBookmarksTest_*_Test8TestBodyEv
}
{
bug_101468b
Memcheck:Leak
fun:_Znw*
fun:_ZN26bookmark_extension_helpers17GetNodeDictionaryEPK12BookmarkNodebb
fun:_ZN*ExtensionBookmarksTest_*_Test8TestBodyEv
}
{
bug_101470
Memcheck:Param
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment