extension_bookmarks_unittest.cc revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "testing/gtest/include/gtest/gtest.h" 6 7#include "base/utf_string_conversions.h" 8#include "base/values.h" 9#include "chrome/browser/bookmarks/bookmark_model.h" 10#include "chrome/browser/extensions/extension_bookmark_helpers.h" 11#include "chrome/browser/extensions/extension_bookmarks_module_constants.h" 12namespace keys = extension_bookmarks_module_constants; 13 14class ExtensionBookmarksTest : public testing::Test { 15 public: 16 virtual void SetUp() { 17 model_.reset(new BookmarkModel(NULL)); 18 model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("Digg"), 19 GURL("http://www.reddit.com")); 20 model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("News"), 21 GURL("http://www.foxnews.com")); 22 folder = 23 model_->AddGroup(model_->other_node(), 0, ASCIIToUTF16("outer folder")); 24 model_->AddGroup(folder, 0, ASCIIToUTF16("inner folder 1")); 25 model_->AddGroup(folder, 0, ASCIIToUTF16("inner folder 2")); 26 model_->AddURL(folder, 0, ASCIIToUTF16("Digg"), GURL("http://reddit.com")); 27 model_->AddURL(folder, 0, ASCIIToUTF16("CNet"), GURL("http://cnet.com")); 28 } 29 30 scoped_ptr<BookmarkModel> model_; 31 const BookmarkNode* folder; 32}; 33TEST_F(ExtensionBookmarksTest, GetFullTreeFromRoot) { 34 DictionaryValue* tree = extension_bookmark_helpers::GetNodeDictionary( 35 model_->other_node(), 36 true, // Recurse. 37 false); // Not only folders. 38 ListValue* children; 39 tree->GetList(keys::kChildrenKey, &children); 40 ASSERT_EQ(3U, children->GetSize()); 41} 42 43TEST_F(ExtensionBookmarksTest, GetFoldersOnlyFromRoot) { 44 DictionaryValue* tree = extension_bookmark_helpers::GetNodeDictionary( 45 model_->other_node(), 46 true, // Recurse. 47 true); // Only folders. 48 ListValue* children; 49 tree->GetList(keys::kChildrenKey, &children); 50 ASSERT_EQ(1U, children->GetSize()); 51} 52 53TEST_F(ExtensionBookmarksTest, GetSubtree) { 54 DictionaryValue* tree = extension_bookmark_helpers::GetNodeDictionary( 55 folder, 56 true, // Recurse. 57 false); // Not only folders. 58 ListValue* children; 59 tree->GetList(keys::kChildrenKey, &children); 60 ASSERT_EQ(4U, children->GetSize()); 61 DictionaryValue* digg; 62 ASSERT_TRUE(children->GetDictionary(1, &digg)); 63 std::string title; 64 digg->GetString(keys::kTitleKey, &title); 65 ASSERT_EQ("Digg", title); 66} 67 68TEST_F(ExtensionBookmarksTest, GetSubtreeFoldersOnly) { 69 DictionaryValue* tree = extension_bookmark_helpers::GetNodeDictionary( 70 folder, 71 true, // Recurse. 72 true); // Only folders. 73 ListValue* children; 74 tree->GetList(keys::kChildrenKey, &children); 75 ASSERT_EQ(2U, children->GetSize()); 76 DictionaryValue* inner_folder; 77 ASSERT_TRUE(children->GetDictionary(1, &inner_folder)); 78 std::string title; 79 inner_folder->GetString(keys::kTitleKey, &title); 80 ASSERT_EQ("inner folder 1", title); 81} 82