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