Update V8 to version 4.7.1.
[chromium-blink-merge.git] / components / bookmarks / browser / bookmark_expanded_state_tracker_unittest.cc
blobde34da61aaa87fa6770e37237d3cbb3faeb917bc
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
3 // found in the LICENSE file.
5 #include "components/bookmarks/browser/bookmark_expanded_state_tracker.h"
7 #include "base/files/file_path.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/testing_pref_service.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "components/bookmarks/browser/bookmark_model.h"
14 #include "components/bookmarks/common/bookmark_pref_names.h"
15 #include "components/bookmarks/test/bookmark_test_helpers.h"
16 #include "components/bookmarks/test/test_bookmark_client.h"
17 #include "testing/gtest/include/gtest/gtest.h"
19 namespace bookmarks {
21 class BookmarkExpandedStateTrackerTest : public testing::Test {
22 public:
23 BookmarkExpandedStateTrackerTest();
24 ~BookmarkExpandedStateTrackerTest() override;
26 protected:
27 // testing::Test:
28 void SetUp() override;
29 void TearDown() override;
31 base::MessageLoop message_loop_;
32 TestingPrefServiceSimple prefs_;
33 TestBookmarkClient client_;
34 scoped_ptr<BookmarkModel> model_;
36 DISALLOW_COPY_AND_ASSIGN(BookmarkExpandedStateTrackerTest);
39 BookmarkExpandedStateTrackerTest::BookmarkExpandedStateTrackerTest() {}
41 BookmarkExpandedStateTrackerTest::~BookmarkExpandedStateTrackerTest() {}
43 void BookmarkExpandedStateTrackerTest::SetUp() {
44 prefs_.registry()->RegisterListPref(prefs::kBookmarkEditorExpandedNodes,
45 new base::ListValue);
46 prefs_.registry()->RegisterListPref(prefs::kManagedBookmarks);
47 model_.reset(new BookmarkModel(&client_));
48 model_->Load(&prefs_, std::string(), base::FilePath(),
49 base::ThreadTaskRunnerHandle::Get(),
50 base::ThreadTaskRunnerHandle::Get());
51 test::WaitForBookmarkModelToLoad(model_.get());
54 void BookmarkExpandedStateTrackerTest::TearDown() {
55 model_.reset();
56 message_loop_.RunUntilIdle();
59 // Various assertions for SetExpandedNodes.
60 TEST_F(BookmarkExpandedStateTrackerTest, SetExpandedNodes) {
61 BookmarkExpandedStateTracker* tracker = model_->expanded_state_tracker();
63 // Should start out initially empty.
64 EXPECT_TRUE(tracker->GetExpandedNodes().empty());
66 BookmarkExpandedStateTracker::Nodes nodes;
67 nodes.insert(model_->bookmark_bar_node());
68 tracker->SetExpandedNodes(nodes);
69 EXPECT_EQ(nodes, tracker->GetExpandedNodes());
71 // Add a folder and mark it expanded.
72 const BookmarkNode* n1 = model_->AddFolder(
73 model_->bookmark_bar_node(), 0, base::ASCIIToUTF16("x"));
74 nodes.insert(n1);
75 tracker->SetExpandedNodes(nodes);
76 EXPECT_EQ(nodes, tracker->GetExpandedNodes());
78 // Remove the folder, which should remove it from the list of expanded nodes.
79 model_->Remove(model_->bookmark_bar_node()->GetChild(0));
80 nodes.erase(n1);
81 n1 = NULL;
82 EXPECT_EQ(nodes, tracker->GetExpandedNodes());
85 TEST_F(BookmarkExpandedStateTrackerTest, RemoveAllUserBookmarks) {
86 BookmarkExpandedStateTracker* tracker = model_->expanded_state_tracker();
88 // Add a folder and mark it expanded.
89 const BookmarkNode* n1 = model_->AddFolder(
90 model_->bookmark_bar_node(), 0, base::ASCIIToUTF16("x"));
91 BookmarkExpandedStateTracker::Nodes nodes;
92 nodes.insert(n1);
93 tracker->SetExpandedNodes(nodes);
94 // Verify that the node is present.
95 EXPECT_EQ(nodes, tracker->GetExpandedNodes());
96 // Call remove all.
97 model_->RemoveAllUserBookmarks();
98 // Verify node is not present.
99 EXPECT_TRUE(tracker->GetExpandedNodes().empty());
102 } // namespace bookmarks