OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/bookmarks/managed/managed_bookmarks_tracker.h" | 5 #include "components/bookmarks/managed/managed_bookmarks_tracker.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 91 } |
92 | 92 |
93 const BookmarkNode* managed_node() { | 93 const BookmarkNode* managed_node() { |
94 return managed_node_; | 94 return managed_node_; |
95 } | 95 } |
96 | 96 |
97 bool IsManaged(const BookmarkNode* node) { | 97 bool IsManaged(const BookmarkNode* node) { |
98 return node && node->HasAncestor(managed_node_); | 98 return node && node->HasAncestor(managed_node_); |
99 } | 99 } |
100 | 100 |
101 static base::DictionaryValue* CreateBookmark(const std::string& title, | 101 static std::unique_ptr<base::DictionaryValue> CreateBookmark( |
102 const std::string& url) { | 102 const std::string& title, |
| 103 const std::string& url) { |
103 EXPECT_TRUE(GURL(url).is_valid()); | 104 EXPECT_TRUE(GURL(url).is_valid()); |
104 base::DictionaryValue* dict = new base::DictionaryValue(); | 105 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
105 dict->SetString("name", title); | 106 dict->SetString("name", title); |
106 dict->SetString("url", GURL(url).spec()); | 107 dict->SetString("url", GURL(url).spec()); |
107 return dict; | 108 return dict; |
108 } | 109 } |
109 | 110 |
110 static base::DictionaryValue* CreateFolder(const std::string& title, | 111 static std::unique_ptr<base::DictionaryValue> CreateFolder( |
111 base::ListValue* children) { | 112 const std::string& title, |
112 base::DictionaryValue* dict = new base::DictionaryValue(); | 113 base::ListValue* children) { |
| 114 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
113 dict->SetString("name", title); | 115 dict->SetString("name", title); |
114 dict->Set("children", children); | 116 dict->Set("children", children); |
115 return dict; | 117 return dict; |
116 } | 118 } |
117 | 119 |
118 static base::ListValue* CreateTestTree() { | 120 static base::ListValue* CreateTestTree() { |
119 base::ListValue* folder = new base::ListValue(); | 121 base::ListValue* folder = new base::ListValue(); |
120 base::ListValue* empty = new base::ListValue(); | 122 base::ListValue* empty = new base::ListValue(); |
121 folder->Append(CreateFolder("Empty", empty)); | 123 folder->Append(CreateFolder("Empty", empty)); |
122 folder->Append(CreateBookmark("Youtube", "http://youtube.com/")); | 124 folder->Append(CreateBookmark("Youtube", "http://youtube.com/")); |
123 | 125 |
124 base::ListValue* list = new base::ListValue(); | 126 base::ListValue* list = new base::ListValue(); |
125 list->Append(CreateBookmark("Google", "http://google.com/")); | 127 list->Append(CreateBookmark("Google", "http://google.com/")); |
126 list->Append(CreateFolder("Folder", folder)); | 128 list->Append(CreateFolder("Folder", folder)); |
127 | 129 |
128 return list; | 130 return list; |
129 } | 131 } |
130 | 132 |
131 static std::string GetManagementDomain() { | 133 static std::string GetManagementDomain() { |
132 return std::string(); | 134 return std::string(); |
133 } | 135 } |
134 | 136 |
135 static std::string GetManagedFolderTitle() { | 137 static std::string GetManagedFolderTitle() { |
136 return l10n_util::GetStringUTF8( | 138 return l10n_util::GetStringUTF8( |
137 IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME); | 139 IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME); |
138 } | 140 } |
139 | 141 |
140 static base::DictionaryValue* CreateExpectedTree() { | 142 static std::unique_ptr<base::DictionaryValue> CreateExpectedTree() { |
141 return CreateFolder(GetManagedFolderTitle(), CreateTestTree()); | 143 return CreateFolder(GetManagedFolderTitle(), CreateTestTree()); |
142 } | 144 } |
143 | 145 |
144 static bool NodeMatchesValue(const BookmarkNode* node, | 146 static bool NodeMatchesValue(const BookmarkNode* node, |
145 const base::DictionaryValue* dict) { | 147 const base::DictionaryValue* dict) { |
146 base::string16 title; | 148 base::string16 title; |
147 if (!dict->GetString("name", &title) || node->GetTitle() != title) | 149 if (!dict->GetString("name", &title) || node->GetTitle() != title) |
148 return false; | 150 return false; |
149 | 151 |
150 if (node->is_folder()) { | 152 if (node->is_folder()) { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 Mock::VerifyAndClearExpectations(&observer_); | 354 Mock::VerifyAndClearExpectations(&observer_); |
353 | 355 |
354 EXPECT_CALL(observer_, BookmarkAllUserNodesRemoved(model_.get(), _)); | 356 EXPECT_CALL(observer_, BookmarkAllUserNodesRemoved(model_.get(), _)); |
355 model_->RemoveAllUserBookmarks(); | 357 model_->RemoveAllUserBookmarks(); |
356 EXPECT_EQ(2, managed_node()->child_count()); | 358 EXPECT_EQ(2, managed_node()->child_count()); |
357 EXPECT_EQ(0, model_->bookmark_bar_node()->child_count()); | 359 EXPECT_EQ(0, model_->bookmark_bar_node()->child_count()); |
358 Mock::VerifyAndClearExpectations(&observer_); | 360 Mock::VerifyAndClearExpectations(&observer_); |
359 } | 361 } |
360 | 362 |
361 } // namespace bookmarks | 363 } // namespace bookmarks |
OLD | NEW |