Stack sampling profiler: add fire-and-forget interface
[chromium-blink-merge.git] / components / bookmarks / browser / bookmark_expanded_state_tracker_unittest.cc
blobde908b62d42f877b7da1d0ac16b556615bc000c6
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();
58 // Various assertions for SetExpandedNodes.
59 TEST_F(BookmarkExpandedStateTrackerTest, SetExpandedNodes) {
60 BookmarkExpandedStateTracker* tracker = model_->expanded_state_tracker();
62 // Should start out initially empty.
63 EXPECT_TRUE(tracker->GetExpandedNodes().empty());
65 BookmarkExpandedStateTracker::Nodes nodes;
66 nodes.insert(model_->bookmark_bar_node());
67 tracker->SetExpandedNodes(nodes);
68 EXPECT_EQ(nodes, tracker->GetExpandedNodes());
70 // Add a folder and mark it expanded.
71 const BookmarkNode* n1 = model_->AddFolder(
72 model_->bookmark_bar_node(), 0, base::ASCIIToUTF16("x"));
73 nodes.insert(n1);
74 tracker->SetExpandedNodes(nodes);
75 EXPECT_EQ(nodes, tracker->GetExpandedNodes());
77 // Remove the folder, which should remove it from the list of expanded nodes.
78 model_->Remove(model_->bookmark_bar_node()->GetChild(0));
79 nodes.erase(n1);
80 n1 = NULL;
81 EXPECT_EQ(nodes, tracker->GetExpandedNodes());
84 TEST_F(BookmarkExpandedStateTrackerTest, RemoveAllUserBookmarks) {
85 BookmarkExpandedStateTracker* tracker = model_->expanded_state_tracker();
87 // Add a folder and mark it expanded.
88 const BookmarkNode* n1 = model_->AddFolder(
89 model_->bookmark_bar_node(), 0, base::ASCIIToUTF16("x"));
90 BookmarkExpandedStateTracker::Nodes nodes;
91 nodes.insert(n1);
92 tracker->SetExpandedNodes(nodes);
93 // Verify that the node is present.
94 EXPECT_EQ(nodes, tracker->GetExpandedNodes());
95 // Call remove all.
96 model_->RemoveAllUserBookmarks();
97 // Verify node is not present.
98 EXPECT_TRUE(tracker->GetExpandedNodes().empty());
101 } // namespace bookmarks