Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: components/bookmarks/managed/managed_bookmarks_tracker_unittest.cc

Issue 2782553004: Move TestingPrefService to use unique_ptr<Value> (Closed)
Patch Set: comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 const std::string& url) { 104 const std::string& url) {
105 EXPECT_TRUE(GURL(url).is_valid()); 105 EXPECT_TRUE(GURL(url).is_valid());
106 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 106 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
107 dict->SetString("name", title); 107 dict->SetString("name", title);
108 dict->SetString("url", GURL(url).spec()); 108 dict->SetString("url", GURL(url).spec());
109 return dict; 109 return dict;
110 } 110 }
111 111
112 static std::unique_ptr<base::DictionaryValue> CreateFolder( 112 static std::unique_ptr<base::DictionaryValue> CreateFolder(
113 const std::string& title, 113 const std::string& title,
114 base::ListValue* children) { 114 std::unique_ptr<base::ListValue> children) {
115 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 115 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
116 dict->SetString("name", title); 116 dict->SetString("name", title);
117 dict->Set("children", children); 117 dict->Set("children", std::move(children));
118 return dict; 118 return dict;
119 } 119 }
120 120
121 static base::ListValue* CreateTestTree() { 121 static std::unique_ptr<base::ListValue> CreateTestTree() {
122 base::ListValue* folder = new base::ListValue(); 122 auto folder = base::MakeUnique<base::ListValue>();
123 base::ListValue* empty = new base::ListValue(); 123 folder->Append(CreateFolder("Empty", base::MakeUnique<base::ListValue>()));
124 folder->Append(CreateFolder("Empty", empty));
125 folder->Append(CreateBookmark("Youtube", "http://youtube.com/")); 124 folder->Append(CreateBookmark("Youtube", "http://youtube.com/"));
126 125
127 base::ListValue* list = new base::ListValue(); 126 auto list = base::MakeUnique<base::ListValue>();
128 list->Append(CreateBookmark("Google", "http://google.com/")); 127 list->Append(CreateBookmark("Google", "http://google.com/"));
129 list->Append(CreateFolder("Folder", folder)); 128 list->Append(CreateFolder("Folder", std::move(folder)));
130 129
131 return list; 130 return list;
132 } 131 }
133 132
134 static std::string GetManagementDomain() { 133 static std::string GetManagementDomain() {
135 return std::string(); 134 return std::string();
136 } 135 }
137 136
138 static std::string GetManagedFolderTitle() { 137 static std::string GetManagedFolderTitle() {
139 return l10n_util::GetStringUTF8( 138 return l10n_util::GetStringUTF8(
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 240
242 // Swap the Google bookmark with the Folder. 241 // Swap the Google bookmark with the Folder.
243 std::unique_ptr<base::ListValue> updated(CreateTestTree()); 242 std::unique_ptr<base::ListValue> updated(CreateTestTree());
244 std::unique_ptr<base::Value> removed; 243 std::unique_ptr<base::Value> removed;
245 ASSERT_TRUE(updated->Remove(0, &removed)); 244 ASSERT_TRUE(updated->Remove(0, &removed));
246 updated->Append(std::move(removed)); 245 updated->Append(std::move(removed));
247 246
248 // These two nodes should just be swapped. 247 // These two nodes should just be swapped.
249 const BookmarkNode* parent = managed_node(); 248 const BookmarkNode* parent = managed_node();
250 EXPECT_CALL(observer_, BookmarkNodeMoved(model_.get(), parent, 1, parent, 0)); 249 EXPECT_CALL(observer_, BookmarkNodeMoved(model_.get(), parent, 1, parent, 0));
251 prefs_.SetManagedPref(prefs::kManagedBookmarks, updated->DeepCopy()); 250 prefs_.SetManagedPref(prefs::kManagedBookmarks, updated->CreateDeepCopy());
252 Mock::VerifyAndClearExpectations(&observer_); 251 Mock::VerifyAndClearExpectations(&observer_);
253 252
254 // Verify the final tree. 253 // Verify the final tree.
255 std::unique_ptr<base::DictionaryValue> expected( 254 std::unique_ptr<base::DictionaryValue> expected(
256 CreateFolder(GetManagedFolderTitle(), updated.release())); 255 CreateFolder(GetManagedFolderTitle(), std::move(updated)));
257 EXPECT_TRUE(NodeMatchesValue(managed_node(), expected.get())); 256 EXPECT_TRUE(NodeMatchesValue(managed_node(), expected.get()));
258 } 257 }
259 258
260 TEST_F(ManagedBookmarksTrackerTest, RemoveNode) { 259 TEST_F(ManagedBookmarksTrackerTest, RemoveNode) {
261 prefs_.SetManagedPref(prefs::kManagedBookmarks, CreateTestTree()); 260 prefs_.SetManagedPref(prefs::kManagedBookmarks, CreateTestTree());
262 CreateModel(false /* is_supervised */); 261 CreateModel(false /* is_supervised */);
263 262
264 // Remove the Folder. 263 // Remove the Folder.
265 std::unique_ptr<base::ListValue> updated(CreateTestTree()); 264 std::unique_ptr<base::ListValue> updated(CreateTestTree());
266 ASSERT_TRUE(updated->Remove(1, NULL)); 265 ASSERT_TRUE(updated->Remove(1, NULL));
267 266
268 const BookmarkNode* parent = managed_node(); 267 const BookmarkNode* parent = managed_node();
269 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_.get(), parent, 1, _, _)); 268 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_.get(), parent, 1, _, _));
270 prefs_.SetManagedPref(prefs::kManagedBookmarks, updated->DeepCopy()); 269 prefs_.SetManagedPref(prefs::kManagedBookmarks, updated->CreateDeepCopy());
271 Mock::VerifyAndClearExpectations(&observer_); 270 Mock::VerifyAndClearExpectations(&observer_);
272 271
273 // Verify the final tree. 272 // Verify the final tree.
274 std::unique_ptr<base::DictionaryValue> expected( 273 std::unique_ptr<base::DictionaryValue> expected(
275 CreateFolder(GetManagedFolderTitle(), updated.release())); 274 CreateFolder(GetManagedFolderTitle(), std::move(updated)));
276 EXPECT_TRUE(NodeMatchesValue(managed_node(), expected.get())); 275 EXPECT_TRUE(NodeMatchesValue(managed_node(), expected.get()));
277 } 276 }
278 277
279 TEST_F(ManagedBookmarksTrackerTest, CreateNewNodes) { 278 TEST_F(ManagedBookmarksTrackerTest, CreateNewNodes) {
280 prefs_.SetManagedPref(prefs::kManagedBookmarks, CreateTestTree()); 279 prefs_.SetManagedPref(prefs::kManagedBookmarks, CreateTestTree());
281 CreateModel(false /* is_supervised */); 280 CreateModel(false /* is_supervised */);
282 281
283 // Put all the nodes inside another folder. 282 // Put all the nodes inside another folder.
284 std::unique_ptr<base::ListValue> updated(new base::ListValue); 283 std::unique_ptr<base::ListValue> updated(new base::ListValue);
285 updated->Append(CreateFolder("Container", CreateTestTree())); 284 updated->Append(CreateFolder("Container", CreateTestTree()));
286 285
287 EXPECT_CALL(observer_, BookmarkNodeAdded(model_.get(), _, _)).Times(5); 286 EXPECT_CALL(observer_, BookmarkNodeAdded(model_.get(), _, _)).Times(5);
288 // The remaining nodes have been pushed to positions 1 and 2; they'll both be 287 // The remaining nodes have been pushed to positions 1 and 2; they'll both be
289 // removed when at position 1. 288 // removed when at position 1.
290 const BookmarkNode* parent = managed_node(); 289 const BookmarkNode* parent = managed_node();
291 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_.get(), parent, 1, _, _)) 290 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_.get(), parent, 1, _, _))
292 .Times(2); 291 .Times(2);
293 prefs_.SetManagedPref(prefs::kManagedBookmarks, updated->DeepCopy()); 292 prefs_.SetManagedPref(prefs::kManagedBookmarks, updated->CreateDeepCopy());
294 Mock::VerifyAndClearExpectations(&observer_); 293 Mock::VerifyAndClearExpectations(&observer_);
295 294
296 // Verify the final tree. 295 // Verify the final tree.
297 std::unique_ptr<base::DictionaryValue> expected( 296 std::unique_ptr<base::DictionaryValue> expected(
298 CreateFolder(GetManagedFolderTitle(), updated.release())); 297 CreateFolder(GetManagedFolderTitle(), std::move(updated)));
299 EXPECT_TRUE(NodeMatchesValue(managed_node(), expected.get())); 298 EXPECT_TRUE(NodeMatchesValue(managed_node(), expected.get()));
300 } 299 }
301 300
302 TEST_F(ManagedBookmarksTrackerTest, RemoveAll) { 301 TEST_F(ManagedBookmarksTrackerTest, RemoveAll) {
303 prefs_.SetManagedPref(prefs::kManagedBookmarks, CreateTestTree()); 302 prefs_.SetManagedPref(prefs::kManagedBookmarks, CreateTestTree());
304 CreateModel(false /* is_supervised */); 303 CreateModel(false /* is_supervised */);
305 EXPECT_TRUE(managed_node()->IsVisible()); 304 EXPECT_TRUE(managed_node()->IsVisible());
306 305
307 // Remove the policy. 306 // Remove the policy.
308 const BookmarkNode* parent = managed_node(); 307 const BookmarkNode* parent = managed_node();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 Mock::VerifyAndClearExpectations(&observer_); 354 Mock::VerifyAndClearExpectations(&observer_);
356 355
357 EXPECT_CALL(observer_, BookmarkAllUserNodesRemoved(model_.get(), _)); 356 EXPECT_CALL(observer_, BookmarkAllUserNodesRemoved(model_.get(), _));
358 model_->RemoveAllUserBookmarks(); 357 model_->RemoveAllUserBookmarks();
359 EXPECT_EQ(2, managed_node()->child_count()); 358 EXPECT_EQ(2, managed_node()->child_count());
360 EXPECT_EQ(0, model_->bookmark_bar_node()->child_count()); 359 EXPECT_EQ(0, model_->bookmark_bar_node()->child_count());
361 Mock::VerifyAndClearExpectations(&observer_); 360 Mock::VerifyAndClearExpectations(&observer_);
362 } 361 }
363 362
364 } // namespace bookmarks 363 } // namespace bookmarks
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698