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