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

Side by Side Diff: chrome/browser/bookmarks/managed_bookmark_service_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_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 27 matching lines...) Expand all
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 // TODO(crbug.com/697817): Convert SetManagedPrefs to take a unique_ptr.
47 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks, 47 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks,
48 CreateTestTree().release()); 48 CreateTestTree());
49 ResetModel(); 49 ResetModel();
50 50
51 // The managed node always exists. 51 // The managed node always exists.
52 ASSERT_TRUE(managed_->managed_node()); 52 ASSERT_TRUE(managed_->managed_node());
53 ASSERT_TRUE(managed_->managed_node()->parent() == model_->root_node()); 53 ASSERT_TRUE(managed_->managed_node()->parent() == model_->root_node());
54 EXPECT_NE(-1, model_->root_node()->GetIndexOf(managed_->managed_node())); 54 EXPECT_NE(-1, model_->root_node()->GetIndexOf(managed_->managed_node()));
55 } 55 }
56 56
57 void TearDown() override { model_->RemoveObserver(&observer_); } 57 void TearDown() override { model_->RemoveObserver(&observer_); }
58 58
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // Swap the Google bookmark with the Folder. 171 // Swap the Google bookmark with the Folder.
172 std::unique_ptr<base::ListValue> updated(CreateTestTree()); 172 std::unique_ptr<base::ListValue> updated(CreateTestTree());
173 std::unique_ptr<base::Value> removed; 173 std::unique_ptr<base::Value> removed;
174 ASSERT_TRUE(updated->Remove(0, &removed)); 174 ASSERT_TRUE(updated->Remove(0, &removed));
175 updated->Append(std::move(removed)); 175 updated->Append(std::move(removed));
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->CreateDeepCopy());
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(), std::move(updated))); 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->CreateDeepCopy());
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(), std::move(updated))); 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->CreateDeepCopy());
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(), std::move(updated))); 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.
(...skipping 61 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

Powered by Google App Engine
This is Rietveld 408576698