[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / chrome / browser / bookmarks / bookmark_expanded_state_tracker_unittest.cc
blob19798c956e6e0b41b80574df9b2b397403f69a94
1 // Copyright (c) 2012 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/core/browser/bookmark_expanded_state_tracker.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
9 #include "chrome/browser/bookmarks/bookmark_test_helpers.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "components/bookmarks/core/browser/bookmark_model.h"
12 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 class BookmarkExpandedStateTrackerTest : public testing::Test {
16 public:
17 BookmarkExpandedStateTrackerTest();
19 virtual void SetUp() OVERRIDE;
20 virtual void TearDown() OVERRIDE;
22 protected:
23 BookmarkModel* GetModel();
25 private:
26 scoped_ptr<TestingProfile> profile_;
27 content::TestBrowserThreadBundle thread_bundle_;
29 DISALLOW_COPY_AND_ASSIGN(BookmarkExpandedStateTrackerTest);
32 BookmarkExpandedStateTrackerTest::BookmarkExpandedStateTrackerTest() {}
34 void BookmarkExpandedStateTrackerTest::SetUp() {
35 profile_.reset(new TestingProfile);
36 profile_->CreateBookmarkModel(true);
37 test::WaitForBookmarkModelToLoad(GetModel());
40 BookmarkModel* BookmarkExpandedStateTrackerTest::GetModel() {
41 return BookmarkModelFactory::GetForProfile(profile_.get());
44 void BookmarkExpandedStateTrackerTest::TearDown() {
45 profile_.reset(NULL);
48 // Various assertions for SetExpandedNodes.
49 TEST_F(BookmarkExpandedStateTrackerTest, SetExpandedNodes) {
50 BookmarkModel* model = GetModel();
51 BookmarkExpandedStateTracker* tracker = model->expanded_state_tracker();
53 // Should start out initially empty.
54 EXPECT_TRUE(tracker->GetExpandedNodes().empty());
56 BookmarkExpandedStateTracker::Nodes nodes;
57 nodes.insert(model->bookmark_bar_node());
58 tracker->SetExpandedNodes(nodes);
59 EXPECT_EQ(nodes, tracker->GetExpandedNodes());
61 // Add a folder and mark it expanded.
62 const BookmarkNode* n1 = model->AddFolder(model->bookmark_bar_node(), 0,
63 base::ASCIIToUTF16("x"));
64 nodes.insert(n1);
65 tracker->SetExpandedNodes(nodes);
66 EXPECT_EQ(nodes, tracker->GetExpandedNodes());
68 // Remove the folder, which should remove it from the list of expanded nodes.
69 model->Remove(model->bookmark_bar_node(), 0);
70 nodes.erase(n1);
71 n1 = NULL;
72 EXPECT_EQ(nodes, tracker->GetExpandedNodes());
75 TEST_F(BookmarkExpandedStateTrackerTest, RemoveAll) {
76 BookmarkModel* model = GetModel();
77 BookmarkExpandedStateTracker* tracker = model->expanded_state_tracker();
79 // Add a folder and mark it expanded.
80 const BookmarkNode* n1 =
81 model->AddFolder(model->bookmark_bar_node(), 0, base::ASCIIToUTF16("x"));
82 BookmarkExpandedStateTracker::Nodes nodes;
83 nodes.insert(n1);
84 tracker->SetExpandedNodes(nodes);
85 // Verify that the node is present.
86 EXPECT_EQ(nodes, tracker->GetExpandedNodes());
87 // Call remove all.
88 model->RemoveAll();
89 // Verify node is not present.
90 EXPECT_TRUE(tracker->GetExpandedNodes().empty());