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

Side by Side Diff: chrome/browser/bookmarks/managed_bookmark_service_unittest.cc

Issue 2765363004: Stop passing raw pointers to DictionaryValue::Set, part 2 (Closed)
Patch Set: Fix comments Created 3 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/app_mode/kiosk_app_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_bookmark_service.h" 5 #include "components/bookmarks/managed/managed_bookmark_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 25 matching lines...) Expand all
36 36
37 class ManagedBookmarkServiceTest : public testing::Test { 37 class ManagedBookmarkServiceTest : public testing::Test {
38 public: 38 public:
39 ManagedBookmarkServiceTest() : managed_(NULL), model_(NULL) {} 39 ManagedBookmarkServiceTest() : managed_(NULL), model_(NULL) {}
40 ~ManagedBookmarkServiceTest() override {} 40 ~ManagedBookmarkServiceTest() override {}
41 41
42 void SetUp() override { 42 void SetUp() override {
43 prefs_ = profile_.GetTestingPrefService(); 43 prefs_ = profile_.GetTestingPrefService();
44 ASSERT_FALSE(prefs_->HasPrefPath(bookmarks::prefs::kManagedBookmarks)); 44 ASSERT_FALSE(prefs_->HasPrefPath(bookmarks::prefs::kManagedBookmarks));
45 45
46 // TODO(crbug.com/697817): Convert SetManagedPrefs to take a unique_ptr.
46 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks, 47 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks,
47 CreateTestTree()); 48 CreateTestTree().release());
48 ResetModel(); 49 ResetModel();
49 50
50 // The managed node always exists. 51 // The managed node always exists.
51 ASSERT_TRUE(managed_->managed_node()); 52 ASSERT_TRUE(managed_->managed_node());
52 ASSERT_TRUE(managed_->managed_node()->parent() == model_->root_node()); 53 ASSERT_TRUE(managed_->managed_node()->parent() == model_->root_node());
53 EXPECT_NE(-1, model_->root_node()->GetIndexOf(managed_->managed_node())); 54 EXPECT_NE(-1, model_->root_node()->GetIndexOf(managed_->managed_node()));
54 } 55 }
55 56
56 void TearDown() override { model_->RemoveObserver(&observer_); } 57 void TearDown() override { model_->RemoveObserver(&observer_); }
57 58
(...skipping 11 matching lines...) Expand all
69 const std::string& url) { 70 const std::string& url) {
70 EXPECT_TRUE(GURL(url).is_valid()); 71 EXPECT_TRUE(GURL(url).is_valid());
71 auto dict = base::MakeUnique<base::DictionaryValue>(); 72 auto dict = base::MakeUnique<base::DictionaryValue>();
72 dict->SetString("name", title); 73 dict->SetString("name", title);
73 dict->SetString("url", GURL(url).spec()); 74 dict->SetString("url", GURL(url).spec());
74 return dict; 75 return dict;
75 } 76 }
76 77
77 static std::unique_ptr<base::DictionaryValue> CreateFolder( 78 static std::unique_ptr<base::DictionaryValue> CreateFolder(
78 const std::string& title, 79 const std::string& title,
79 base::ListValue* children) { 80 std::unique_ptr<base::ListValue> children) {
80 auto dict = base::MakeUnique<base::DictionaryValue>(); 81 auto dict = base::MakeUnique<base::DictionaryValue>();
81 dict->SetString("name", title); 82 dict->SetString("name", title);
82 dict->Set("children", children); 83 dict->Set("children", std::move(children));
83 return dict; 84 return dict;
84 } 85 }
85 86
86 static base::ListValue* CreateTestTree() { 87 static std::unique_ptr<base::ListValue> CreateTestTree() {
87 base::ListValue* folder = new base::ListValue(); 88 auto folder = base::MakeUnique<base::ListValue>();
88 base::ListValue* empty = new base::ListValue(); 89 folder->Append(CreateFolder("Empty", base::MakeUnique<base::ListValue>()));
89 folder->Append(CreateFolder("Empty", empty));
90 folder->Append(CreateBookmark("Youtube", "http://youtube.com/")); 90 folder->Append(CreateBookmark("Youtube", "http://youtube.com/"));
91 91
92 base::ListValue* list = new base::ListValue(); 92 auto list = base::MakeUnique<base::ListValue>();
93 list->Append(CreateBookmark("Google", "http://google.com/")); 93 list->Append(CreateBookmark("Google", "http://google.com/"));
94 list->Append(CreateFolder("Folder", folder)); 94 list->Append(CreateFolder("Folder", std::move(folder)));
95 95
96 return list; 96 return list;
97 } 97 }
98 98
99 static std::unique_ptr<base::DictionaryValue> CreateExpectedTree() { 99 static std::unique_ptr<base::DictionaryValue> CreateExpectedTree() {
100 return CreateFolder(GetManagedFolderTitle(), CreateTestTree()); 100 return CreateFolder(GetManagedFolderTitle(), CreateTestTree());
101 } 101 }
102 102
103 static std::string GetManagedFolderTitle() { 103 static std::string GetManagedFolderTitle() {
104 return l10n_util::GetStringUTF8( 104 return l10n_util::GetStringUTF8(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 176
177 // These two nodes should just be swapped. 177 // These two nodes should just be swapped.
178 const BookmarkNode* parent = managed_->managed_node(); 178 const BookmarkNode* parent = managed_->managed_node();
179 EXPECT_CALL(observer_, BookmarkNodeMoved(model_, parent, 1, parent, 0)); 179 EXPECT_CALL(observer_, BookmarkNodeMoved(model_, parent, 1, parent, 0));
180 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks, 180 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks,
181 updated->DeepCopy()); 181 updated->DeepCopy());
182 Mock::VerifyAndClearExpectations(&observer_); 182 Mock::VerifyAndClearExpectations(&observer_);
183 183
184 // Verify the final tree. 184 // Verify the final tree.
185 std::unique_ptr<base::DictionaryValue> expected( 185 std::unique_ptr<base::DictionaryValue> expected(
186 CreateFolder(GetManagedFolderTitle(), updated.release())); 186 CreateFolder(GetManagedFolderTitle(), std::move(updated)));
187 EXPECT_TRUE(NodeMatchesValue(managed_->managed_node(), expected.get())); 187 EXPECT_TRUE(NodeMatchesValue(managed_->managed_node(), expected.get()));
188 } 188 }
189 189
190 TEST_F(ManagedBookmarkServiceTest, RemoveNode) { 190 TEST_F(ManagedBookmarkServiceTest, RemoveNode) {
191 // Remove the Folder. 191 // Remove the Folder.
192 std::unique_ptr<base::ListValue> updated(CreateTestTree()); 192 std::unique_ptr<base::ListValue> updated(CreateTestTree());
193 ASSERT_TRUE(updated->Remove(1, NULL)); 193 ASSERT_TRUE(updated->Remove(1, NULL));
194 194
195 const BookmarkNode* parent = managed_->managed_node(); 195 const BookmarkNode* parent = managed_->managed_node();
196 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 1, _, _)); 196 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 1, _, _));
197 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks, 197 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks,
198 updated->DeepCopy()); 198 updated->DeepCopy());
199 Mock::VerifyAndClearExpectations(&observer_); 199 Mock::VerifyAndClearExpectations(&observer_);
200 200
201 // Verify the final tree. 201 // Verify the final tree.
202 std::unique_ptr<base::DictionaryValue> expected( 202 std::unique_ptr<base::DictionaryValue> expected(
203 CreateFolder(GetManagedFolderTitle(), updated.release())); 203 CreateFolder(GetManagedFolderTitle(), std::move(updated)));
204 EXPECT_TRUE(NodeMatchesValue(managed_->managed_node(), expected.get())); 204 EXPECT_TRUE(NodeMatchesValue(managed_->managed_node(), expected.get()));
205 } 205 }
206 206
207 TEST_F(ManagedBookmarkServiceTest, CreateNewNodes) { 207 TEST_F(ManagedBookmarkServiceTest, CreateNewNodes) {
208 // Put all the nodes inside another folder. 208 // Put all the nodes inside another folder.
209 std::unique_ptr<base::ListValue> updated(new base::ListValue); 209 std::unique_ptr<base::ListValue> updated(new base::ListValue);
210 updated->Append(CreateFolder("Container", CreateTestTree())); 210 updated->Append(CreateFolder("Container", CreateTestTree()));
211 211
212 EXPECT_CALL(observer_, BookmarkNodeAdded(model_, _, _)).Times(5); 212 EXPECT_CALL(observer_, BookmarkNodeAdded(model_, _, _)).Times(5);
213 // The remaining nodes have been pushed to positions 1 and 2; they'll both be 213 // The remaining nodes have been pushed to positions 1 and 2; they'll both be
214 // removed when at position 1. 214 // removed when at position 1.
215 const BookmarkNode* parent = managed_->managed_node(); 215 const BookmarkNode* parent = managed_->managed_node();
216 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 1, _, _)).Times(2); 216 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 1, _, _)).Times(2);
217 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks, 217 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks,
218 updated->DeepCopy()); 218 updated->DeepCopy());
219 Mock::VerifyAndClearExpectations(&observer_); 219 Mock::VerifyAndClearExpectations(&observer_);
220 220
221 // Verify the final tree. 221 // Verify the final tree.
222 std::unique_ptr<base::DictionaryValue> expected( 222 std::unique_ptr<base::DictionaryValue> expected(
223 CreateFolder(GetManagedFolderTitle(), updated.release())); 223 CreateFolder(GetManagedFolderTitle(), std::move(updated)));
224 EXPECT_TRUE(NodeMatchesValue(managed_->managed_node(), expected.get())); 224 EXPECT_TRUE(NodeMatchesValue(managed_->managed_node(), expected.get()));
225 } 225 }
226 226
227 TEST_F(ManagedBookmarkServiceTest, RemoveAllUserBookmarks) { 227 TEST_F(ManagedBookmarkServiceTest, RemoveAllUserBookmarks) {
228 // Remove the policy. 228 // Remove the policy.
229 const BookmarkNode* parent = managed_->managed_node(); 229 const BookmarkNode* parent = managed_->managed_node();
230 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 0, _, _)).Times(2); 230 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 0, _, _)).Times(2);
231 prefs_->RemoveManagedPref(bookmarks::prefs::kManagedBookmarks); 231 prefs_->RemoveManagedPref(bookmarks::prefs::kManagedBookmarks);
232 Mock::VerifyAndClearExpectations(&observer_); 232 Mock::VerifyAndClearExpectations(&observer_);
233 233
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 const BookmarkNode* managed_node = managed_->managed_node()->GetChild(0); 290 const BookmarkNode* managed_node = managed_->managed_node()->GetChild(0);
291 ASSERT_TRUE(managed_node); 291 ASSERT_TRUE(managed_node);
292 292
293 std::vector<const BookmarkNode*> nodes; 293 std::vector<const BookmarkNode*> nodes;
294 EXPECT_FALSE(bookmarks::HasDescendantsOf(nodes, managed_->managed_node())); 294 EXPECT_FALSE(bookmarks::HasDescendantsOf(nodes, managed_->managed_node()));
295 nodes.push_back(user_node); 295 nodes.push_back(user_node);
296 EXPECT_FALSE(bookmarks::HasDescendantsOf(nodes, managed_->managed_node())); 296 EXPECT_FALSE(bookmarks::HasDescendantsOf(nodes, managed_->managed_node()));
297 nodes.push_back(managed_node); 297 nodes.push_back(managed_node);
298 EXPECT_TRUE(bookmarks::HasDescendantsOf(nodes, managed_->managed_node())); 298 EXPECT_TRUE(bookmarks::HasDescendantsOf(nodes, managed_->managed_node()));
299 } 299 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/app_mode/kiosk_app_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698