| OLD | NEW |
| 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/bookmarks/browser/bookmark_model.h" | 5 #include "components/bookmarks/browser/bookmark_model.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 int extensive_changes_ended_count) { | 258 int extensive_changes_ended_count) { |
| 259 EXPECT_EQ(extensive_changes_beginning_count, | 259 EXPECT_EQ(extensive_changes_beginning_count, |
| 260 extensive_changes_beginning_count_); | 260 extensive_changes_beginning_count_); |
| 261 EXPECT_EQ(extensive_changes_ended_count, extensive_changes_ended_count_); | 261 EXPECT_EQ(extensive_changes_ended_count, extensive_changes_ended_count_); |
| 262 } | 262 } |
| 263 | 263 |
| 264 int AllNodesRemovedObserverCount() const { return all_bookmarks_removed_; } | 264 int AllNodesRemovedObserverCount() const { return all_bookmarks_removed_; } |
| 265 | 265 |
| 266 BookmarkPermanentNode* ReloadModelWithExtraNode() { | 266 BookmarkPermanentNode* ReloadModelWithExtraNode() { |
| 267 BookmarkPermanentNode* extra_node = new BookmarkPermanentNode(100); | 267 BookmarkPermanentNode* extra_node = new BookmarkPermanentNode(100); |
| 268 bookmarks::BookmarkPermanentNodeList extra_nodes; | 268 BookmarkPermanentNodeList extra_nodes; |
| 269 extra_nodes.push_back(extra_node); | 269 extra_nodes.push_back(extra_node); |
| 270 client_.SetExtraNodesToLoad(extra_nodes.Pass()); | 270 client_.SetExtraNodesToLoad(extra_nodes.Pass()); |
| 271 | 271 |
| 272 model_->RemoveObserver(this); | 272 model_->RemoveObserver(this); |
| 273 model_ = client_.CreateModel(); | 273 model_ = client_.CreateModel(); |
| 274 model_->AddObserver(this); | 274 model_->AddObserver(this); |
| 275 ClearCounts(); | 275 ClearCounts(); |
| 276 | 276 |
| 277 if (model_->root_node()->GetIndexOf(extra_node) == -1) | 277 if (model_->root_node()->GetIndexOf(extra_node) == -1) |
| 278 ADD_FAILURE(); | 278 ADD_FAILURE(); |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 // Make sure recently modified stays in sync when adding a URL. | 715 // Make sure recently modified stays in sync when adding a URL. |
| 716 TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) { | 716 TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) { |
| 717 // Add a folder. | 717 // Add a folder. |
| 718 const BookmarkNode* folder = | 718 const BookmarkNode* folder = |
| 719 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foo")); | 719 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foo")); |
| 720 // Add a URL to it. | 720 // Add a URL to it. |
| 721 model_->AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com")); | 721 model_->AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com")); |
| 722 | 722 |
| 723 // Make sure folder is in the most recently modified. | 723 // Make sure folder is in the most recently modified. |
| 724 std::vector<const BookmarkNode*> most_recent_folders = | 724 std::vector<const BookmarkNode*> most_recent_folders = |
| 725 bookmarks::GetMostRecentlyModifiedUserFolders(model_.get(), 1); | 725 GetMostRecentlyModifiedUserFolders(model_.get(), 1); |
| 726 ASSERT_EQ(1U, most_recent_folders.size()); | 726 ASSERT_EQ(1U, most_recent_folders.size()); |
| 727 ASSERT_EQ(folder, most_recent_folders[0]); | 727 ASSERT_EQ(folder, most_recent_folders[0]); |
| 728 | 728 |
| 729 // Nuke the folder and do another fetch, making sure folder isn't in the | 729 // Nuke the folder and do another fetch, making sure folder isn't in the |
| 730 // returned list. | 730 // returned list. |
| 731 model_->Remove(folder->parent(), 0); | 731 model_->Remove(folder->parent(), 0); |
| 732 most_recent_folders = | 732 most_recent_folders = GetMostRecentlyModifiedUserFolders(model_.get(), 1); |
| 733 bookmarks::GetMostRecentlyModifiedUserFolders(model_.get(), 1); | |
| 734 ASSERT_EQ(1U, most_recent_folders.size()); | 733 ASSERT_EQ(1U, most_recent_folders.size()); |
| 735 ASSERT_TRUE(most_recent_folders[0] != folder); | 734 ASSERT_TRUE(most_recent_folders[0] != folder); |
| 736 } | 735 } |
| 737 | 736 |
| 738 // Make sure MostRecentlyAddedEntries stays in sync. | 737 // Make sure MostRecentlyAddedEntries stays in sync. |
| 739 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { | 738 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { |
| 740 // Add a couple of nodes such that the following holds for the time of the | 739 // Add a couple of nodes such that the following holds for the time of the |
| 741 // nodes: n1 > n2 > n3 > n4. | 740 // nodes: n1 > n2 > n3 > n4. |
| 742 Time base_time = Time::Now(); | 741 Time base_time = Time::Now(); |
| 743 BookmarkNode* n1 = AsMutable(model_->AddURL(model_->bookmark_bar_node(), | 742 BookmarkNode* n1 = AsMutable(model_->AddURL(model_->bookmark_bar_node(), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 756 3, | 755 3, |
| 757 ASCIIToUTF16("blah"), | 756 ASCIIToUTF16("blah"), |
| 758 GURL("http://foo.com/3"))); | 757 GURL("http://foo.com/3"))); |
| 759 n1->set_date_added(base_time + TimeDelta::FromDays(4)); | 758 n1->set_date_added(base_time + TimeDelta::FromDays(4)); |
| 760 n2->set_date_added(base_time + TimeDelta::FromDays(3)); | 759 n2->set_date_added(base_time + TimeDelta::FromDays(3)); |
| 761 n3->set_date_added(base_time + TimeDelta::FromDays(2)); | 760 n3->set_date_added(base_time + TimeDelta::FromDays(2)); |
| 762 n4->set_date_added(base_time + TimeDelta::FromDays(1)); | 761 n4->set_date_added(base_time + TimeDelta::FromDays(1)); |
| 763 | 762 |
| 764 // Make sure order is honored. | 763 // Make sure order is honored. |
| 765 std::vector<const BookmarkNode*> recently_added; | 764 std::vector<const BookmarkNode*> recently_added; |
| 766 bookmarks::GetMostRecentlyAddedEntries(model_.get(), 2, &recently_added); | 765 GetMostRecentlyAddedEntries(model_.get(), 2, &recently_added); |
| 767 ASSERT_EQ(2U, recently_added.size()); | 766 ASSERT_EQ(2U, recently_added.size()); |
| 768 ASSERT_TRUE(n1 == recently_added[0]); | 767 ASSERT_TRUE(n1 == recently_added[0]); |
| 769 ASSERT_TRUE(n2 == recently_added[1]); | 768 ASSERT_TRUE(n2 == recently_added[1]); |
| 770 | 769 |
| 771 // swap 1 and 2, then check again. | 770 // swap 1 and 2, then check again. |
| 772 recently_added.clear(); | 771 recently_added.clear(); |
| 773 SwapDateAdded(n1, n2); | 772 SwapDateAdded(n1, n2); |
| 774 bookmarks::GetMostRecentlyAddedEntries(model_.get(), 4, &recently_added); | 773 GetMostRecentlyAddedEntries(model_.get(), 4, &recently_added); |
| 775 ASSERT_EQ(4U, recently_added.size()); | 774 ASSERT_EQ(4U, recently_added.size()); |
| 776 ASSERT_TRUE(n2 == recently_added[0]); | 775 ASSERT_TRUE(n2 == recently_added[0]); |
| 777 ASSERT_TRUE(n1 == recently_added[1]); | 776 ASSERT_TRUE(n1 == recently_added[1]); |
| 778 ASSERT_TRUE(n3 == recently_added[2]); | 777 ASSERT_TRUE(n3 == recently_added[2]); |
| 779 ASSERT_TRUE(n4 == recently_added[3]); | 778 ASSERT_TRUE(n4 == recently_added[3]); |
| 780 } | 779 } |
| 781 | 780 |
| 782 // Makes sure GetMostRecentlyAddedUserNodeForURL stays in sync. | 781 // Makes sure GetMostRecentlyAddedUserNodeForURL stays in sync. |
| 783 TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURL) { | 782 TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURL) { |
| 784 // Add a couple of nodes such that the following holds for the time of the | 783 // Add a couple of nodes such that the following holds for the time of the |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 model_->AddURL(model_->other_node(), 0, base::ASCIIToUTF16("User"), | 1121 model_->AddURL(model_->other_node(), 0, base::ASCIIToUTF16("User"), |
| 1123 GURL("http://google.com")); | 1122 GURL("http://google.com")); |
| 1124 // "youtube.com" is not. | 1123 // "youtube.com" is not. |
| 1125 model_->AddURL(extra_node, 0, base::ASCIIToUTF16("Extra"), | 1124 model_->AddURL(extra_node, 0, base::ASCIIToUTF16("Extra"), |
| 1126 GURL("http://youtube.com")); | 1125 GURL("http://youtube.com")); |
| 1127 | 1126 |
| 1128 EXPECT_TRUE(model_->IsBookmarked(GURL("http://google.com"))); | 1127 EXPECT_TRUE(model_->IsBookmarked(GURL("http://google.com"))); |
| 1129 EXPECT_TRUE(model_->IsBookmarked(GURL("http://youtube.com"))); | 1128 EXPECT_TRUE(model_->IsBookmarked(GURL("http://youtube.com"))); |
| 1130 EXPECT_FALSE(model_->IsBookmarked(GURL("http://reddit.com"))); | 1129 EXPECT_FALSE(model_->IsBookmarked(GURL("http://reddit.com"))); |
| 1131 | 1130 |
| 1132 EXPECT_TRUE( | 1131 EXPECT_TRUE(IsBookmarkedByUser(model_.get(), GURL("http://google.com"))); |
| 1133 bookmarks::IsBookmarkedByUser(model_.get(), GURL("http://google.com"))); | 1132 EXPECT_FALSE(IsBookmarkedByUser(model_.get(), GURL("http://youtube.com"))); |
| 1134 EXPECT_FALSE( | 1133 EXPECT_FALSE(IsBookmarkedByUser(model_.get(), GURL("http://reddit.com"))); |
| 1135 bookmarks::IsBookmarkedByUser(model_.get(), GURL("http://youtube.com"))); | |
| 1136 EXPECT_FALSE( | |
| 1137 bookmarks::IsBookmarkedByUser(model_.get(), GURL("http://reddit.com"))); | |
| 1138 } | 1134 } |
| 1139 | 1135 |
| 1140 // Verifies that GetMostRecentlyAddedUserNodeForURL skips bookmarks that | 1136 // Verifies that GetMostRecentlyAddedUserNodeForURL skips bookmarks that |
| 1141 // are not owned by the user. | 1137 // are not owned by the user. |
| 1142 TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURLSkipsManagedNodes) { | 1138 TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURLSkipsManagedNodes) { |
| 1143 // Reload the model with an extra node that is not editable by the user. | 1139 // Reload the model with an extra node that is not editable by the user. |
| 1144 BookmarkPermanentNode* extra_node = ReloadModelWithExtraNode(); | 1140 BookmarkPermanentNode* extra_node = ReloadModelWithExtraNode(); |
| 1145 | 1141 |
| 1146 const base::string16 title = base::ASCIIToUTF16("Title"); | 1142 const base::string16 title = base::ASCIIToUTF16("Title"); |
| 1147 const BookmarkNode* user_parent = model_->other_node(); | 1143 const BookmarkNode* user_parent = model_->other_node(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 EXPECT_FALSE(node.DeleteMetaInfo("key3")); | 1188 EXPECT_FALSE(node.DeleteMetaInfo("key3")); |
| 1193 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); | 1189 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); |
| 1194 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); | 1190 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); |
| 1195 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); | 1191 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); |
| 1196 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); | 1192 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); |
| 1197 EXPECT_FALSE(node.GetMetaInfoMap()); | 1193 EXPECT_FALSE(node.GetMetaInfoMap()); |
| 1198 } | 1194 } |
| 1199 | 1195 |
| 1200 } // namespace | 1196 } // namespace |
| 1201 } // namespace bookmarks | 1197 } // namespace bookmarks |
| OLD | NEW |