Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Side by Side Diff: components/bookmarks/browser/bookmark_model_unittest.cc

Issue 386283002: Move bookmark_utils into bookmarks namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 // Make sure recently modified stays in sync when adding a URL. 728 // Make sure recently modified stays in sync when adding a URL.
729 TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) { 729 TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) {
730 // Add a folder. 730 // Add a folder.
731 const BookmarkNode* folder = 731 const BookmarkNode* folder =
732 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foo")); 732 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foo"));
733 // Add a URL to it. 733 // Add a URL to it.
734 model_->AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com")); 734 model_->AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com"));
735 735
736 // Make sure folder is in the most recently modified. 736 // Make sure folder is in the most recently modified.
737 std::vector<const BookmarkNode*> most_recent_folders = 737 std::vector<const BookmarkNode*> most_recent_folders =
738 bookmark_utils::GetMostRecentlyModifiedUserFolders(model_.get(), 1); 738 bookmarks::GetMostRecentlyModifiedUserFolders(model_.get(), 1);
739 ASSERT_EQ(1U, most_recent_folders.size()); 739 ASSERT_EQ(1U, most_recent_folders.size());
740 ASSERT_EQ(folder, most_recent_folders[0]); 740 ASSERT_EQ(folder, most_recent_folders[0]);
741 741
742 // Nuke the folder and do another fetch, making sure folder isn't in the 742 // Nuke the folder and do another fetch, making sure folder isn't in the
743 // returned list. 743 // returned list.
744 model_->Remove(folder->parent(), 0); 744 model_->Remove(folder->parent(), 0);
745 most_recent_folders = 745 most_recent_folders =
746 bookmark_utils::GetMostRecentlyModifiedUserFolders(model_.get(), 1); 746 bookmarks::GetMostRecentlyModifiedUserFolders(model_.get(), 1);
747 ASSERT_EQ(1U, most_recent_folders.size()); 747 ASSERT_EQ(1U, most_recent_folders.size());
748 ASSERT_TRUE(most_recent_folders[0] != folder); 748 ASSERT_TRUE(most_recent_folders[0] != folder);
749 } 749 }
750 750
751 // Make sure MostRecentlyAddedEntries stays in sync. 751 // Make sure MostRecentlyAddedEntries stays in sync.
752 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { 752 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) {
753 // Add a couple of nodes such that the following holds for the time of the 753 // Add a couple of nodes such that the following holds for the time of the
754 // nodes: n1 > n2 > n3 > n4. 754 // nodes: n1 > n2 > n3 > n4.
755 Time base_time = Time::Now(); 755 Time base_time = Time::Now();
756 BookmarkNode* n1 = AsMutable(model_->AddURL(model_->bookmark_bar_node(), 756 BookmarkNode* n1 = AsMutable(model_->AddURL(model_->bookmark_bar_node(),
(...skipping 12 matching lines...) Expand all
769 3, 769 3,
770 ASCIIToUTF16("blah"), 770 ASCIIToUTF16("blah"),
771 GURL("http://foo.com/3"))); 771 GURL("http://foo.com/3")));
772 n1->set_date_added(base_time + TimeDelta::FromDays(4)); 772 n1->set_date_added(base_time + TimeDelta::FromDays(4));
773 n2->set_date_added(base_time + TimeDelta::FromDays(3)); 773 n2->set_date_added(base_time + TimeDelta::FromDays(3));
774 n3->set_date_added(base_time + TimeDelta::FromDays(2)); 774 n3->set_date_added(base_time + TimeDelta::FromDays(2));
775 n4->set_date_added(base_time + TimeDelta::FromDays(1)); 775 n4->set_date_added(base_time + TimeDelta::FromDays(1));
776 776
777 // Make sure order is honored. 777 // Make sure order is honored.
778 std::vector<const BookmarkNode*> recently_added; 778 std::vector<const BookmarkNode*> recently_added;
779 bookmark_utils::GetMostRecentlyAddedEntries(model_.get(), 2, &recently_added); 779 bookmarks::GetMostRecentlyAddedEntries(model_.get(), 2, &recently_added);
780 ASSERT_EQ(2U, recently_added.size()); 780 ASSERT_EQ(2U, recently_added.size());
781 ASSERT_TRUE(n1 == recently_added[0]); 781 ASSERT_TRUE(n1 == recently_added[0]);
782 ASSERT_TRUE(n2 == recently_added[1]); 782 ASSERT_TRUE(n2 == recently_added[1]);
783 783
784 // swap 1 and 2, then check again. 784 // swap 1 and 2, then check again.
785 recently_added.clear(); 785 recently_added.clear();
786 SwapDateAdded(n1, n2); 786 SwapDateAdded(n1, n2);
787 bookmark_utils::GetMostRecentlyAddedEntries(model_.get(), 4, &recently_added); 787 bookmarks::GetMostRecentlyAddedEntries(model_.get(), 4, &recently_added);
788 ASSERT_EQ(4U, recently_added.size()); 788 ASSERT_EQ(4U, recently_added.size());
789 ASSERT_TRUE(n2 == recently_added[0]); 789 ASSERT_TRUE(n2 == recently_added[0]);
790 ASSERT_TRUE(n1 == recently_added[1]); 790 ASSERT_TRUE(n1 == recently_added[1]);
791 ASSERT_TRUE(n3 == recently_added[2]); 791 ASSERT_TRUE(n3 == recently_added[2]);
792 ASSERT_TRUE(n4 == recently_added[3]); 792 ASSERT_TRUE(n4 == recently_added[3]);
793 } 793 }
794 794
795 // Makes sure GetMostRecentlyAddedUserNodeForURL stays in sync. 795 // Makes sure GetMostRecentlyAddedUserNodeForURL stays in sync.
796 TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURL) { 796 TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURL) {
797 // Add a couple of nodes such that the following holds for the time of the 797 // Add a couple of nodes such that the following holds for the time of the
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 model_->AddURL(model_->other_node(), 0, base::ASCIIToUTF16("User"), 1134 model_->AddURL(model_->other_node(), 0, base::ASCIIToUTF16("User"),
1135 GURL("http://google.com")); 1135 GURL("http://google.com"));
1136 // "youtube.com" is not. 1136 // "youtube.com" is not.
1137 model_->AddURL(extra_node, 0, base::ASCIIToUTF16("Extra"), 1137 model_->AddURL(extra_node, 0, base::ASCIIToUTF16("Extra"),
1138 GURL("http://youtube.com")); 1138 GURL("http://youtube.com"));
1139 1139
1140 EXPECT_TRUE(model_->IsBookmarked(GURL("http://google.com"))); 1140 EXPECT_TRUE(model_->IsBookmarked(GURL("http://google.com")));
1141 EXPECT_TRUE(model_->IsBookmarked(GURL("http://youtube.com"))); 1141 EXPECT_TRUE(model_->IsBookmarked(GURL("http://youtube.com")));
1142 EXPECT_FALSE(model_->IsBookmarked(GURL("http://reddit.com"))); 1142 EXPECT_FALSE(model_->IsBookmarked(GURL("http://reddit.com")));
1143 1143
1144 EXPECT_TRUE(bookmark_utils::IsBookmarkedByUser(model_.get(), 1144 EXPECT_TRUE(
1145 GURL("http://google.com"))); 1145 bookmarks::IsBookmarkedByUser(model_.get(), GURL("http://google.com")));
1146 EXPECT_FALSE(bookmark_utils::IsBookmarkedByUser(model_.get(), 1146 EXPECT_FALSE(
1147 GURL("http://youtube.com"))); 1147 bookmarks::IsBookmarkedByUser(model_.get(), GURL("http://youtube.com")));
1148 EXPECT_FALSE(bookmark_utils::IsBookmarkedByUser(model_.get(), 1148 EXPECT_FALSE(
1149 GURL("http://reddit.com"))); 1149 bookmarks::IsBookmarkedByUser(model_.get(), GURL("http://reddit.com")));
1150 } 1150 }
1151 1151
1152 // Verifies that GetMostRecentlyAddedUserNodeForURL skips bookmarks that 1152 // Verifies that GetMostRecentlyAddedUserNodeForURL skips bookmarks that
1153 // are not owned by the user. 1153 // are not owned by the user.
1154 TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURLSkipsManagedNodes) { 1154 TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURLSkipsManagedNodes) {
1155 // Reload the model with an extra node that is not editable by the user. 1155 // Reload the model with an extra node that is not editable by the user.
1156 BookmarkPermanentNode* extra_node = ReloadModelWithExtraNode(); 1156 BookmarkPermanentNode* extra_node = ReloadModelWithExtraNode();
1157 1157
1158 const base::string16 title = base::ASCIIToUTF16("Title"); 1158 const base::string16 title = base::ASCIIToUTF16("Title");
1159 const BookmarkNode* user_parent = model_->other_node(); 1159 const BookmarkNode* user_parent = model_->other_node();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 EXPECT_TRUE(node.DeleteMetaInfo("key2.subkey2.leaf")); 1203 EXPECT_TRUE(node.DeleteMetaInfo("key2.subkey2.leaf"));
1204 EXPECT_FALSE(node.DeleteMetaInfo("key3")); 1204 EXPECT_FALSE(node.DeleteMetaInfo("key3"));
1205 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); 1205 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value));
1206 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); 1206 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value));
1207 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); 1207 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value));
1208 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); 1208 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value));
1209 EXPECT_FALSE(node.GetMetaInfoMap()); 1209 EXPECT_FALSE(node.GetMetaInfoMap());
1210 } 1210 }
1211 1211
1212 } // namespace 1212 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698