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; ...@@ -21,6 +21,7 @@ class ListValue;
// Helper functions. // Helper functions.
namespace bookmark_extension_helpers { namespace bookmark_extension_helpers {
// The returned value is owned by the caller.
base::DictionaryValue* GetNodeDictionary(const BookmarkNode* node, base::DictionaryValue* GetNodeDictionary(const BookmarkNode* node,
bool recurse, bool recurse,
bool only_folders); bool only_folders);
......
...@@ -2,60 +2,64 @@ ...@@ -2,60 +2,64 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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/utf_string_conversions.h"
#include "base/values.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_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; namespace keys = bookmark_extension_api_constants;
class ExtensionBookmarksTest : public testing::Test { class ExtensionBookmarksTest : public testing::Test {
public: public:
virtual void SetUp() { virtual void SetUp() OVERRIDE {
model_.reset(new BookmarkModel(NULL)); model_.reset(new BookmarkModel(NULL));
model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("Digg"), model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("Digg"),
GURL("http://www.reddit.com")); GURL("http://www.reddit.com"));
model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("News"), model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("News"),
GURL("http://www.foxnews.com")); GURL("http://www.foxnews.com"));
folder = model_->AddFolder( folder_ = model_->AddFolder(
model_->other_node(), 0, ASCIIToUTF16("outer folder")); model_->other_node(), 0, ASCIIToUTF16("outer folder"));
model_->AddFolder(folder, 0, ASCIIToUTF16("inner folder 1")); model_->AddFolder(folder_, 0, ASCIIToUTF16("inner folder 1"));
model_->AddFolder(folder, 0, ASCIIToUTF16("inner folder 2")); model_->AddFolder(folder_, 0, ASCIIToUTF16("inner folder 2"));
model_->AddURL(folder, 0, ASCIIToUTF16("Digg"), GURL("http://reddit.com")); model_->AddURL(folder_, 0, ASCIIToUTF16("Digg"), GURL("http://reddit.com"));
model_->AddURL(folder, 0, ASCIIToUTF16("CNet"), GURL("http://cnet.com")); model_->AddURL(folder_, 0, ASCIIToUTF16("CNet"), GURL("http://cnet.com"));
} }
scoped_ptr<BookmarkModel> model_; scoped_ptr<BookmarkModel> model_;
const BookmarkNode* folder; const BookmarkNode* folder_;
}; };
TEST_F(ExtensionBookmarksTest, GetFullTreeFromRoot) { TEST_F(ExtensionBookmarksTest, GetFullTreeFromRoot) {
DictionaryValue* tree = bookmark_extension_helpers::GetNodeDictionary( scoped_ptr<DictionaryValue> tree(
model_->other_node(), bookmark_extension_helpers::GetNodeDictionary(
true, // Recurse. model_->other_node(),
false); // Not only folders. true, // Recurse.
false)); // Not only folders.
ListValue* children; ListValue* children;
tree->GetList(keys::kChildrenKey, &children); tree->GetList(keys::kChildrenKey, &children);
ASSERT_EQ(3U, children->GetSize()); ASSERT_EQ(3U, children->GetSize());
} }
TEST_F(ExtensionBookmarksTest, GetFoldersOnlyFromRoot) { TEST_F(ExtensionBookmarksTest, GetFoldersOnlyFromRoot) {
DictionaryValue* tree = bookmark_extension_helpers::GetNodeDictionary( scoped_ptr<DictionaryValue> tree(
model_->other_node(), bookmark_extension_helpers::GetNodeDictionary(
true, // Recurse. model_->other_node(),
true); // Only folders. true, // Recurse.
true)); // Only folders.
ListValue* children; ListValue* children;
tree->GetList(keys::kChildrenKey, &children); tree->GetList(keys::kChildrenKey, &children);
ASSERT_EQ(1U, children->GetSize()); ASSERT_EQ(1U, children->GetSize());
} }
TEST_F(ExtensionBookmarksTest, GetSubtree) { TEST_F(ExtensionBookmarksTest, GetSubtree) {
DictionaryValue* tree = bookmark_extension_helpers::GetNodeDictionary( scoped_ptr<DictionaryValue> tree(
folder, bookmark_extension_helpers::GetNodeDictionary(
true, // Recurse. folder_,
false); // Not only folders. true, // Recurse.
false)); // Not only folders.
ListValue* children; ListValue* children;
tree->GetList(keys::kChildrenKey, &children); tree->GetList(keys::kChildrenKey, &children);
ASSERT_EQ(4U, children->GetSize()); ASSERT_EQ(4U, children->GetSize());
...@@ -67,10 +71,11 @@ TEST_F(ExtensionBookmarksTest, GetSubtree) { ...@@ -67,10 +71,11 @@ TEST_F(ExtensionBookmarksTest, GetSubtree) {
} }
TEST_F(ExtensionBookmarksTest, GetSubtreeFoldersOnly) { TEST_F(ExtensionBookmarksTest, GetSubtreeFoldersOnly) {
DictionaryValue* tree = bookmark_extension_helpers::GetNodeDictionary( scoped_ptr<DictionaryValue> tree(
folder, bookmark_extension_helpers::GetNodeDictionary(
true, // Recurse. folder_,
true); // Only folders. true, // Recurse.
true)); // Only folders.
ListValue* children; ListValue* children;
tree->GetList(keys::kChildrenKey, &children); tree->GetList(keys::kChildrenKey, &children);
ASSERT_EQ(2U, children->GetSize()); ASSERT_EQ(2U, children->GetSize());
......
...@@ -4945,29 +4945,6 @@ ...@@ -4945,29 +4945,6 @@
fun:_ZN5ppapi5proxy38EnterHostFromHostResourceForceCallbackINS_5thunk18PPB_Graphics2D_APIEEC1IN2pp25CompletionCallbackFactoryINS0_20PPB_Graphics2D_ProxyENS0_26ProxyNonThreadSafeRefCountEEEMS8_FviRKNS_12HostResourceEESB_EESD_RT_T0_RKT1_ fun:_ZN5ppapi5proxy38EnterHostFromHostResourceForceCallbackINS_5thunk18PPB_Graphics2D_APIEEC1IN2pp25CompletionCallbackFactoryINS0_20PPB_Graphics2D_ProxyENS0_26ProxyNonThreadSafeRefCountEEEMS8_FviRKNS_12HostResourceEESB_EESD_RT_T0_RKT1_
fun:_ZN5ppapi5proxy20PPB_Graphics2D_Proxy10OnMsgFlushERKNS_12HostResourceE 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 bug_101470
Memcheck:Param 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