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/policy/core/browser/managed_bookmarks_tracker_unittest.cc

Issue 769153007: Managed bookmarks for supervised users (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 11 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/policy/core/browser/managed_bookmarks_tracker.h" 5 #include "components/policy/core/browser/managed_bookmarks_tracker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 18 matching lines...) Expand all
29 29
30 namespace policy { 30 namespace policy {
31 31
32 class ManagedBookmarksTrackerTest : public testing::Test { 32 class ManagedBookmarksTrackerTest : public testing::Test {
33 public: 33 public:
34 ManagedBookmarksTrackerTest() : managed_node_(NULL) {} 34 ManagedBookmarksTrackerTest() : managed_node_(NULL) {}
35 ~ManagedBookmarksTrackerTest() override {} 35 ~ManagedBookmarksTrackerTest() override {}
36 36
37 void SetUp() override { 37 void SetUp() override {
38 prefs_.registry()->RegisterListPref(bookmarks::prefs::kManagedBookmarks); 38 prefs_.registry()->RegisterListPref(bookmarks::prefs::kManagedBookmarks);
39 prefs_.registry()->RegisterListPref(bookmarks::prefs::kSupervisedBookmarks);
39 prefs_.registry()->RegisterListPref( 40 prefs_.registry()->RegisterListPref(
40 bookmarks::prefs::kBookmarkEditorExpandedNodes); 41 bookmarks::prefs::kBookmarkEditorExpandedNodes);
41 } 42 }
42 43
43 void TearDown() override { 44 void TearDown() override {
44 if (model_) 45 if (model_)
45 model_->RemoveObserver(&observer_); 46 model_->RemoveObserver(&observer_);
46 } 47 }
47 48
48 void CreateModel() { 49 void CreateModel() {
50 CreateModel(false);
51 }
52
53 void CreateModel(bool is_supervised) {
49 // Simulate the creation of the managed node by the BookmarkClient. 54 // Simulate the creation of the managed node by the BookmarkClient.
50 BookmarkPermanentNode* managed_node = new BookmarkPermanentNode(100); 55 BookmarkPermanentNode* managed_node = new BookmarkPermanentNode(100);
51 policy::ManagedBookmarksTracker::LoadInitial( 56 policy::ManagedBookmarksTracker::LoadInitial(
52 managed_node, prefs_.GetList(bookmarks::prefs::kManagedBookmarks), 101); 57 managed_node,
58 prefs_.GetList(ManagedBookmarksTracker::GetPrefName(is_supervised)),
59 101);
53 managed_node->set_visible(!managed_node->empty()); 60 managed_node->set_visible(!managed_node->empty());
54 managed_node->SetTitle(l10n_util::GetStringUTF16( 61 managed_node->SetTitle(l10n_util::GetStringUTF16(
55 IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME)); 62 is_supervised ? IDS_BOOKMARK_BAR_SUPERVISED_FOLDER_DEFAULT_NAME
63 : IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME));
56 64
57 bookmarks::BookmarkPermanentNodeList extra_nodes; 65 bookmarks::BookmarkPermanentNodeList extra_nodes;
58 extra_nodes.push_back(managed_node); 66 extra_nodes.push_back(managed_node);
59 client_.SetExtraNodesToLoad(extra_nodes.Pass()); 67 client_.SetExtraNodesToLoad(extra_nodes.Pass());
60 68
61 model_.reset(new BookmarkModel(&client_)); 69 model_.reset(new BookmarkModel(&client_));
62 model_->AddObserver(&observer_); 70 model_->AddObserver(&observer_);
63 EXPECT_CALL(observer_, BookmarkModelLoaded(model_.get(), _)); 71 EXPECT_CALL(observer_, BookmarkModelLoaded(model_.get(), _));
64 model_->Load(&prefs_, 72 model_->Load(&prefs_,
65 std::string(), 73 std::string(),
66 base::FilePath(), 74 base::FilePath(),
67 base::MessageLoopProxy::current(), 75 base::MessageLoopProxy::current(),
68 base::MessageLoopProxy::current()); 76 base::MessageLoopProxy::current());
69 bookmarks::test::WaitForBookmarkModelToLoad(model_.get()); 77 bookmarks::test::WaitForBookmarkModelToLoad(model_.get());
70 Mock::VerifyAndClearExpectations(&observer_); 78 Mock::VerifyAndClearExpectations(&observer_);
71 79
72 ASSERT_EQ(1u, client_.extra_nodes().size()); 80 ASSERT_EQ(1u, client_.extra_nodes().size());
73 managed_node_ = client_.extra_nodes()[0]; 81 managed_node_ = client_.extra_nodes()[0];
74 ASSERT_EQ(managed_node, managed_node_); 82 ASSERT_EQ(managed_node, managed_node_);
75 83
76 managed_bookmarks_tracker_.reset(new ManagedBookmarksTracker( 84 managed_bookmarks_tracker_.reset(new ManagedBookmarksTracker(
77 model_.get(), 85 model_.get(),
78 &prefs_, 86 &prefs_,
87 is_supervised,
79 base::Bind(&ManagedBookmarksTrackerTest::GetManagementDomain))); 88 base::Bind(&ManagedBookmarksTrackerTest::GetManagementDomain)));
80 managed_bookmarks_tracker_->Init(managed_node_); 89 managed_bookmarks_tracker_->Init(managed_node_);
81 } 90 }
82 91
83 const BookmarkNode* managed_node() { 92 const BookmarkNode* managed_node() {
84 return managed_node_; 93 return managed_node_;
85 } 94 }
86 95
87 bool IsManaged(const BookmarkNode* node) { 96 bool IsManaged(const BookmarkNode* node) {
88 return node && node->HasAncestor(managed_node_); 97 return node && node->HasAncestor(managed_node_);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 CreateModel(); 192 CreateModel();
184 EXPECT_TRUE(model_->bookmark_bar_node()->empty()); 193 EXPECT_TRUE(model_->bookmark_bar_node()->empty());
185 EXPECT_TRUE(model_->other_node()->empty()); 194 EXPECT_TRUE(model_->other_node()->empty());
186 EXPECT_FALSE(managed_node()->empty()); 195 EXPECT_FALSE(managed_node()->empty());
187 EXPECT_TRUE(managed_node()->IsVisible()); 196 EXPECT_TRUE(managed_node()->IsVisible());
188 197
189 scoped_ptr<base::DictionaryValue> expected(CreateExpectedTree()); 198 scoped_ptr<base::DictionaryValue> expected(CreateExpectedTree());
190 EXPECT_TRUE(NodeMatchesValue(managed_node(), expected.get())); 199 EXPECT_TRUE(NodeMatchesValue(managed_node(), expected.get()));
191 } 200 }
192 201
202 TEST_F(ManagedBookmarksTrackerTest, SupervisedTrackerIgnoresManagedPref) {
203 prefs_.SetManagedPref(bookmarks::prefs::kManagedBookmarks, CreateTestTree());
204 CreateModel(true);
205 EXPECT_TRUE(managed_node()->empty());
206 EXPECT_FALSE(managed_node()->IsVisible());
207 }
208
209 TEST_F(ManagedBookmarksTrackerTest, SupervisedTrackerHandlesSupervisedPref) {
210 prefs_.SetManagedPref(bookmarks::prefs::kSupervisedBookmarks,
211 CreateTestTree());
212 CreateModel(true);
213 EXPECT_FALSE(managed_node()->empty());
214 EXPECT_TRUE(managed_node()->IsVisible());
215 // Don't bother checking the actual contents, the non-supervised tests cover
216 // that already.
217 }
218
193 TEST_F(ManagedBookmarksTrackerTest, SwapNodes) { 219 TEST_F(ManagedBookmarksTrackerTest, SwapNodes) {
194 prefs_.SetManagedPref(bookmarks::prefs::kManagedBookmarks, CreateTestTree()); 220 prefs_.SetManagedPref(bookmarks::prefs::kManagedBookmarks, CreateTestTree());
195 CreateModel(); 221 CreateModel();
196 222
197 // Swap the Google bookmark with the Folder. 223 // Swap the Google bookmark with the Folder.
198 scoped_ptr<base::ListValue> updated(CreateTestTree()); 224 scoped_ptr<base::ListValue> updated(CreateTestTree());
199 scoped_ptr<base::Value> removed; 225 scoped_ptr<base::Value> removed;
200 ASSERT_TRUE(updated->Remove(0, &removed)); 226 ASSERT_TRUE(updated->Remove(0, &removed));
201 updated->Append(removed.release()); 227 updated->Append(removed.release());
202 228
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 Mock::VerifyAndClearExpectations(&observer_); 339 Mock::VerifyAndClearExpectations(&observer_);
314 340
315 EXPECT_CALL(observer_, BookmarkAllUserNodesRemoved(model_.get(), _)); 341 EXPECT_CALL(observer_, BookmarkAllUserNodesRemoved(model_.get(), _));
316 model_->RemoveAllUserBookmarks(); 342 model_->RemoveAllUserBookmarks();
317 EXPECT_EQ(2, managed_node()->child_count()); 343 EXPECT_EQ(2, managed_node()->child_count());
318 EXPECT_EQ(0, model_->bookmark_bar_node()->child_count()); 344 EXPECT_EQ(0, model_->bookmark_bar_node()->child_count());
319 Mock::VerifyAndClearExpectations(&observer_); 345 Mock::VerifyAndClearExpectations(&observer_);
320 } 346 }
321 347
322 } // namespace policy 348 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698