| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "components/bookmarks/core/browser/bookmark_expanded_state_tracker.h" | |
| 6 | |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | |
| 9 #include "chrome/test/base/testing_profile.h" | |
| 10 #include "components/bookmarks/core/browser/bookmark_model.h" | |
| 11 #include "components/bookmarks/core/test/bookmark_test_helpers.h" | |
| 12 #include "content/public/test/test_browser_thread_bundle.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 class BookmarkExpandedStateTrackerTest : public testing::Test { | |
| 16 public: | |
| 17 BookmarkExpandedStateTrackerTest(); | |
| 18 | |
| 19 virtual void SetUp() OVERRIDE; | |
| 20 virtual void TearDown() OVERRIDE; | |
| 21 | |
| 22 protected: | |
| 23 BookmarkModel* GetModel(); | |
| 24 | |
| 25 private: | |
| 26 scoped_ptr<TestingProfile> profile_; | |
| 27 content::TestBrowserThreadBundle thread_bundle_; | |
| 28 | |
| 29 DISALLOW_COPY_AND_ASSIGN(BookmarkExpandedStateTrackerTest); | |
| 30 }; | |
| 31 | |
| 32 BookmarkExpandedStateTrackerTest::BookmarkExpandedStateTrackerTest() {} | |
| 33 | |
| 34 void BookmarkExpandedStateTrackerTest::SetUp() { | |
| 35 profile_.reset(new TestingProfile); | |
| 36 profile_->CreateBookmarkModel(true); | |
| 37 test::WaitForBookmarkModelToLoad(GetModel()); | |
| 38 } | |
| 39 | |
| 40 BookmarkModel* BookmarkExpandedStateTrackerTest::GetModel() { | |
| 41 return BookmarkModelFactory::GetForProfile(profile_.get()); | |
| 42 } | |
| 43 | |
| 44 void BookmarkExpandedStateTrackerTest::TearDown() { | |
| 45 profile_.reset(NULL); | |
| 46 } | |
| 47 | |
| 48 // Various assertions for SetExpandedNodes. | |
| 49 TEST_F(BookmarkExpandedStateTrackerTest, SetExpandedNodes) { | |
| 50 BookmarkModel* model = GetModel(); | |
| 51 BookmarkExpandedStateTracker* tracker = model->expanded_state_tracker(); | |
| 52 | |
| 53 // Should start out initially empty. | |
| 54 EXPECT_TRUE(tracker->GetExpandedNodes().empty()); | |
| 55 | |
| 56 BookmarkExpandedStateTracker::Nodes nodes; | |
| 57 nodes.insert(model->bookmark_bar_node()); | |
| 58 tracker->SetExpandedNodes(nodes); | |
| 59 EXPECT_EQ(nodes, tracker->GetExpandedNodes()); | |
| 60 | |
| 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()); | |
| 67 | |
| 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()); | |
| 73 } | |
| 74 | |
| 75 TEST_F(BookmarkExpandedStateTrackerTest, RemoveAll) { | |
| 76 BookmarkModel* model = GetModel(); | |
| 77 BookmarkExpandedStateTracker* tracker = model->expanded_state_tracker(); | |
| 78 | |
| 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()); | |
| 91 } | |
| OLD | NEW |