| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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" | |
| 12 | |
| 13 namespace keys = extension_bookmarks_module_constants; | |
| 14 | |
| 15 class ExtensionBookmarksTest : public testing::Test { | |
| 16 public: | |
| 17 virtual void SetUp() { | |
| 18 model_.reset(new BookmarkModel(NULL)); | |
| 19 model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("Digg"), | |
| 20 GURL("http://www.reddit.com")); | |
| 21 model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("News"), | |
| 22 GURL("http://www.foxnews.com")); | |
| 23 folder = model_->AddFolder( | |
| 24 model_->other_node(), 0, ASCIIToUTF16("outer folder")); | |
| 25 model_->AddFolder(folder, 0, ASCIIToUTF16("inner folder 1")); | |
| 26 model_->AddFolder(folder, 0, ASCIIToUTF16("inner folder 2")); | |
| 27 model_->AddURL(folder, 0, ASCIIToUTF16("Digg"), GURL("http://reddit.com")); | |
| 28 model_->AddURL(folder, 0, ASCIIToUTF16("CNet"), GURL("http://cnet.com")); | |
| 29 } | |
| 30 | |
| 31 scoped_ptr<BookmarkModel> model_; | |
| 32 const BookmarkNode* folder; | |
| 33 }; | |
| 34 TEST_F(ExtensionBookmarksTest, GetFullTreeFromRoot) { | |
| 35 DictionaryValue* tree = extension_bookmark_helpers::GetNodeDictionary( | |
| 36 model_->other_node(), | |
| 37 true, // Recurse. | |
| 38 false); // Not only folders. | |
| 39 ListValue* children; | |
| 40 tree->GetList(keys::kChildrenKey, &children); | |
| 41 ASSERT_EQ(3U, children->GetSize()); | |
| 42 } | |
| 43 | |
| 44 TEST_F(ExtensionBookmarksTest, GetFoldersOnlyFromRoot) { | |
| 45 DictionaryValue* tree = extension_bookmark_helpers::GetNodeDictionary( | |
| 46 model_->other_node(), | |
| 47 true, // Recurse. | |
| 48 true); // Only folders. | |
| 49 ListValue* children; | |
| 50 tree->GetList(keys::kChildrenKey, &children); | |
| 51 ASSERT_EQ(1U, children->GetSize()); | |
| 52 } | |
| 53 | |
| 54 TEST_F(ExtensionBookmarksTest, GetSubtree) { | |
| 55 DictionaryValue* tree = extension_bookmark_helpers::GetNodeDictionary( | |
| 56 folder, | |
| 57 true, // Recurse. | |
| 58 false); // Not only folders. | |
| 59 ListValue* children; | |
| 60 tree->GetList(keys::kChildrenKey, &children); | |
| 61 ASSERT_EQ(4U, children->GetSize()); | |
| 62 DictionaryValue* digg; | |
| 63 ASSERT_TRUE(children->GetDictionary(1, &digg)); | |
| 64 std::string title; | |
| 65 digg->GetString(keys::kTitleKey, &title); | |
| 66 ASSERT_EQ("Digg", title); | |
| 67 } | |
| 68 | |
| 69 TEST_F(ExtensionBookmarksTest, GetSubtreeFoldersOnly) { | |
| 70 DictionaryValue* tree = extension_bookmark_helpers::GetNodeDictionary( | |
| 71 folder, | |
| 72 true, // Recurse. | |
| 73 true); // Only folders. | |
| 74 ListValue* children; | |
| 75 tree->GetList(keys::kChildrenKey, &children); | |
| 76 ASSERT_EQ(2U, children->GetSize()); | |
| 77 DictionaryValue* inner_folder; | |
| 78 ASSERT_TRUE(children->GetDictionary(1, &inner_folder)); | |
| 79 std::string title; | |
| 80 inner_folder->GetString(keys::kTitleKey, &title); | |
| 81 ASSERT_EQ("inner folder 1", title); | |
| 82 } | |
| OLD | NEW |