OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/supervised_user/supervised_user_bookmarks_handler.h" | 5 #include "chrome/browser/supervised_user/supervised_user_bookmarks_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <iostream> | 9 #include <iostream> |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
| 13 #include <utility> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
16 #include "base/json/json_writer.h" | 17 #include "base/json/json_writer.h" |
17 #include "base/macros.h" | 18 #include "base/macros.h" |
18 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 using Folder = SupervisedUserBookmarksHandler::Folder; | 23 using Folder = SupervisedUserBookmarksHandler::Folder; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 return str; | 189 return str; |
189 } | 190 } |
190 | 191 |
191 std::ostream& operator<<(std::ostream& str, const Link& link) { | 192 std::ostream& operator<<(std::ostream& str, const Link& link) { |
192 str << link.url << " " << link.name << " " << link.parent_id; | 193 str << link.url << " " << link.name << " " << link.parent_id; |
193 return str; | 194 return str; |
194 } | 195 } |
195 | 196 |
196 class SupervisedUserBookmarksHandlerTest : public ::testing::Test { | 197 class SupervisedUserBookmarksHandlerTest : public ::testing::Test { |
197 protected: | 198 protected: |
198 static base::DictionaryValue* CreateSettings(base::DictionaryValue* links, | 199 static std::unique_ptr<base::DictionaryValue> CreateSettings( |
199 base::DictionaryValue* folders) { | 200 std::unique_ptr<base::DictionaryValue> links, |
200 base::DictionaryValue* settings = new base::DictionaryValue; | 201 std::unique_ptr<base::DictionaryValue> folders) { |
| 202 auto settings = base::MakeUnique<base::DictionaryValue>(); |
201 settings->SetStringWithoutPathExpansion("some_setting", "bleh"); | 203 settings->SetStringWithoutPathExpansion("some_setting", "bleh"); |
202 settings->SetWithoutPathExpansion("SupervisedBookmarkLink", links); | 204 settings->SetWithoutPathExpansion("SupervisedBookmarkLink", |
| 205 std::move(links)); |
203 settings->SetStringWithoutPathExpansion("some_other_setting", "foo"); | 206 settings->SetStringWithoutPathExpansion("some_other_setting", "foo"); |
204 settings->SetWithoutPathExpansion("SupervisedBookmarkFolder", folders); | 207 settings->SetWithoutPathExpansion("SupervisedBookmarkFolder", |
| 208 std::move(folders)); |
205 settings->SetStringWithoutPathExpansion("another_one", "blurb"); | 209 settings->SetStringWithoutPathExpansion("another_one", "blurb"); |
206 return settings; | 210 return settings; |
207 } | 211 } |
208 | 212 |
209 static base::DictionaryValue* CreateDictionary(const Setting* begin, | 213 static std::unique_ptr<base::DictionaryValue> CreateDictionary( |
210 const Setting* end) { | 214 const Setting* begin, |
211 base::DictionaryValue* dict = new base::DictionaryValue; | 215 const Setting* end) { |
| 216 auto dict = base::MakeUnique<base::DictionaryValue>(); |
212 for (const Setting* setting = begin; setting != end; ++setting) | 217 for (const Setting* setting = begin; setting != end; ++setting) |
213 dict->SetStringWithoutPathExpansion(setting->first, setting->second); | 218 dict->SetStringWithoutPathExpansion(setting->first, setting->second); |
214 return dict; | 219 return dict; |
215 } | 220 } |
216 | 221 |
217 static base::DictionaryValue* CreateLinkDictionary() { | 222 static std::unique_ptr<base::DictionaryValue> CreateLinkDictionary() { |
218 return CreateDictionary(LINK_SETTINGS, | 223 return CreateDictionary(LINK_SETTINGS, |
219 LINK_SETTINGS + arraysize(LINK_SETTINGS)); | 224 LINK_SETTINGS + arraysize(LINK_SETTINGS)); |
220 } | 225 } |
221 | 226 |
222 static base::DictionaryValue* CreateLinkDictionaryWithInvalidParents() { | 227 static std::unique_ptr<base::DictionaryValue> |
| 228 CreateLinkDictionaryWithInvalidParents() { |
223 return CreateDictionary( | 229 return CreateDictionary( |
224 LINK_SETTINGS_INVALID_PARENT, | 230 LINK_SETTINGS_INVALID_PARENT, |
225 LINK_SETTINGS_INVALID_PARENT + arraysize(LINK_SETTINGS_INVALID_PARENT)); | 231 LINK_SETTINGS_INVALID_PARENT + arraysize(LINK_SETTINGS_INVALID_PARENT)); |
226 } | 232 } |
227 | 233 |
228 static base::DictionaryValue* CreateFolderDictionary() { | 234 static std::unique_ptr<base::DictionaryValue> CreateFolderDictionary() { |
229 return CreateDictionary(FOLDER_SETTINGS, | 235 return CreateDictionary(FOLDER_SETTINGS, |
230 FOLDER_SETTINGS + arraysize(FOLDER_SETTINGS)); | 236 FOLDER_SETTINGS + arraysize(FOLDER_SETTINGS)); |
231 } | 237 } |
232 | 238 |
233 static base::DictionaryValue* CreateFolderDictionaryWithInvalidParents() { | 239 static std::unique_ptr<base::DictionaryValue> |
234 return CreateDictionary( | 240 CreateFolderDictionaryWithInvalidParents() { |
235 FOLDER_SETTINGS_INVALID_PARENT, | 241 return CreateDictionary(FOLDER_SETTINGS_INVALID_PARENT, |
236 FOLDER_SETTINGS_INVALID_PARENT + | 242 FOLDER_SETTINGS_INVALID_PARENT + |
237 arraysize(FOLDER_SETTINGS_INVALID_PARENT)); | 243 arraysize(FOLDER_SETTINGS_INVALID_PARENT)); |
238 } | 244 } |
239 | 245 |
240 static base::DictionaryValue* CreateFolderDictionaryWithCircle() { | 246 static std::unique_ptr<base::DictionaryValue> |
| 247 CreateFolderDictionaryWithCircle() { |
241 return CreateDictionary( | 248 return CreateDictionary( |
242 FOLDER_SETTINGS_CIRCLE, | 249 FOLDER_SETTINGS_CIRCLE, |
243 FOLDER_SETTINGS_CIRCLE + arraysize(FOLDER_SETTINGS_CIRCLE)); | 250 FOLDER_SETTINGS_CIRCLE + arraysize(FOLDER_SETTINGS_CIRCLE)); |
244 } | 251 } |
245 | 252 |
246 void ParseFolders(const base::DictionaryValue& folders) { | 253 void ParseFolders(const base::DictionaryValue& folders) { |
247 deserializer_.ParseFolders(folders); | 254 deserializer_.ParseFolders(folders); |
248 } | 255 } |
249 | 256 |
250 void ParseLinks(const base::DictionaryValue& links) { | 257 void ParseLinks(const base::DictionaryValue& links) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 | 325 |
319 TEST_F(SupervisedUserBookmarksHandlerTest, Circle) { | 326 TEST_F(SupervisedUserBookmarksHandlerTest, Circle) { |
320 // Make some fake settings which include a circular reference in the folders. | 327 // Make some fake settings which include a circular reference in the folders. |
321 std::unique_ptr<base::DictionaryValue> settings(CreateSettings( | 328 std::unique_ptr<base::DictionaryValue> settings(CreateSettings( |
322 CreateLinkDictionary(), CreateFolderDictionaryWithCircle())); | 329 CreateLinkDictionary(), CreateFolderDictionaryWithCircle())); |
323 std::unique_ptr<base::ListValue> bookmarks( | 330 std::unique_ptr<base::ListValue> bookmarks( |
324 SupervisedUserBookmarksHandler::BuildBookmarksTree(*settings.get())); | 331 SupervisedUserBookmarksHandler::BuildBookmarksTree(*settings.get())); |
325 // Don't care what exactly the result looks like, just that we don't run into | 332 // Don't care what exactly the result looks like, just that we don't run into |
326 // an endless loop. | 333 // an endless loop. |
327 } | 334 } |
OLD | NEW |