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

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

Issue 10870029: Remove legacy migration code that coupled history and bookmarks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove obsoleted unit test. Created 8 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 7
8 #include "base/base_paths.h" 8 #include "base/base_paths.h"
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 profile_->CreateBookmarkModel(false); 902 profile_->CreateBookmarkModel(false);
903 BlockTillBookmarkModelLoaded(); 903 BlockTillBookmarkModelLoaded();
904 904
905 VerifyModelMatchesNode(&bbn, bb_model_->bookmark_bar_node()); 905 VerifyModelMatchesNode(&bbn, bb_model_->bookmark_bar_node());
906 VerifyModelMatchesNode(&other, bb_model_->other_node()); 906 VerifyModelMatchesNode(&other, bb_model_->other_node());
907 VerifyModelMatchesNode(&mobile, bb_model_->mobile_node()); 907 VerifyModelMatchesNode(&mobile, bb_model_->mobile_node());
908 VerifyNoDuplicateIDs(bb_model_); 908 VerifyNoDuplicateIDs(bb_model_);
909 } 909 }
910 } 910 }
911 911
912 // Test class that creates a BookmarkModel with a real history backend.
913 class BookmarkModelTestWithProfile2 : public BookmarkModelTestWithProfile {
914 public:
915 virtual void SetUp() {
916 profile_.reset(new TestingProfile());
917 }
918
919 protected:
920 // Verifies the state of the model matches that of the state in the saved
921 // history file.
922 void VerifyExpectedState() {
923 // Here's the structure we expect:
924 // bbn
925 // www.google.com - Google
926 // F1
927 // http://www.google.com/intl/en/ads/ - Google Advertising
928 // F11
929 // http://www.google.com/services/ - Google Business Solutions
930 // other
931 // OF1
932 // http://www.google.com/intl/en/about.html - About Google
933 const BookmarkNode* bbn = bb_model_->bookmark_bar_node();
934 ASSERT_EQ(2, bbn->child_count());
935
936 const BookmarkNode* child = bbn->GetChild(0);
937 ASSERT_EQ(BookmarkNode::URL, child->type());
938 ASSERT_EQ(ASCIIToUTF16("Google"), child->GetTitle());
939 ASSERT_TRUE(child->url() == GURL("http://www.google.com"));
940
941 child = bbn->GetChild(1);
942 ASSERT_TRUE(child->is_folder());
943 ASSERT_EQ(ASCIIToUTF16("F1"), child->GetTitle());
944 ASSERT_EQ(2, child->child_count());
945
946 const BookmarkNode* parent = child;
947 child = parent->GetChild(0);
948 ASSERT_EQ(BookmarkNode::URL, child->type());
949 ASSERT_EQ(ASCIIToUTF16("Google Advertising"), child->GetTitle());
950 ASSERT_TRUE(child->url() == GURL("http://www.google.com/intl/en/ads/"));
951
952 child = parent->GetChild(1);
953 ASSERT_TRUE(child->is_folder());
954 ASSERT_EQ(ASCIIToUTF16("F11"), child->GetTitle());
955 ASSERT_EQ(1, child->child_count());
956
957 parent = child;
958 child = parent->GetChild(0);
959 ASSERT_EQ(BookmarkNode::URL, child->type());
960 ASSERT_EQ(ASCIIToUTF16("Google Business Solutions"), child->GetTitle());
961 ASSERT_TRUE(child->url() == GURL("http://www.google.com/services/"));
962
963 parent = bb_model_->other_node();
964 ASSERT_EQ(2, parent->child_count());
965
966 child = parent->GetChild(0);
967 ASSERT_TRUE(child->is_folder());
968 ASSERT_EQ(ASCIIToUTF16("OF1"), child->GetTitle());
969 ASSERT_EQ(0, child->child_count());
970
971 child = parent->GetChild(1);
972 ASSERT_EQ(BookmarkNode::URL, child->type());
973 ASSERT_EQ(ASCIIToUTF16("About Google"), child->GetTitle());
974 ASSERT_TRUE(child->url() ==
975 GURL("http://www.google.com/intl/en/about.html"));
976
977 parent = bb_model_->mobile_node();
978 ASSERT_EQ(0, parent->child_count());
979
980 ASSERT_TRUE(bb_model_->IsBookmarked(GURL("http://www.google.com")));
981 }
982
983 void VerifyUniqueIDs() {
984 std::set<int64> ids;
985 bool has_unique = true;
986 VerifyUniqueIDImpl(bb_model_->bookmark_bar_node(), &ids, &has_unique);
987 VerifyUniqueIDImpl(bb_model_->other_node(), &ids, &has_unique);
988 ASSERT_TRUE(has_unique);
989 }
990
991 private:
992 void VerifyUniqueIDImpl(const BookmarkNode* node,
993 std::set<int64>* ids,
994 bool* has_unique) {
995 if (!*has_unique)
996 return;
997 if (ids->count(node->id()) != 0) {
998 *has_unique = false;
999 return;
1000 }
1001 ids->insert(node->id());
1002 for (int i = 0; i < node->child_count(); ++i) {
1003 VerifyUniqueIDImpl(node->GetChild(i), ids, has_unique);
1004 if (!*has_unique)
1005 return;
1006 }
1007 }
1008 };
1009
1010 // Tests migrating bookmarks from db into file. This copies an old history db
1011 // file containing bookmarks and make sure they are loaded correctly and
1012 // persisted correctly.
1013 TEST_F(BookmarkModelTestWithProfile2, MigrateFromDBToFileTest) {
1014 // Copy db file over that contains starred table.
1015 FilePath old_history_path;
1016 PathService::Get(chrome::DIR_TEST_DATA, &old_history_path);
1017 old_history_path = old_history_path.AppendASCII("bookmarks");
1018 old_history_path = old_history_path.AppendASCII("History_with_starred");
1019 FilePath new_history_path = profile_->GetPath();
1020 file_util::Delete(new_history_path, true);
1021 file_util::CreateDirectory(new_history_path);
1022 FilePath new_history_file = new_history_path.Append(
1023 chrome::kHistoryFilename);
1024 ASSERT_TRUE(file_util::CopyFile(old_history_path, new_history_file));
1025
1026 // Create the history service making sure it doesn't blow away the file we
1027 // just copied.
1028 profile_->CreateHistoryService(false, false);
1029 profile_->CreateBookmarkModel(true);
1030 BlockTillBookmarkModelLoaded();
1031
1032 // Make sure we loaded OK.
1033 VerifyExpectedState();
1034 if (HasFatalFailure())
1035 return;
1036
1037 // Make sure the ids are unique.
1038 VerifyUniqueIDs();
1039 if (HasFatalFailure())
1040 return;
1041
1042 // Create again. This time we shouldn't load from history at all.
1043 profile_->CreateBookmarkModel(false);
1044 BlockTillBookmarkModelLoaded();
1045
1046 // Make sure we loaded OK.
1047 VerifyExpectedState();
1048 if (HasFatalFailure())
1049 return;
1050
1051 VerifyUniqueIDs();
1052 if (HasFatalFailure())
1053 return;
1054
1055 // Recreate the history service (with a clean db). Do this just to make sure
1056 // we're loading correctly from the bookmarks file.
1057 profile_->CreateHistoryService(true, false);
1058 profile_->CreateBookmarkModel(false);
1059 BlockTillBookmarkModelLoaded();
1060 VerifyExpectedState();
1061 VerifyUniqueIDs();
1062 }
1063
1064 // Simple test that removes a bookmark. This test exercises the code paths in 912 // Simple test that removes a bookmark. This test exercises the code paths in
1065 // History that block till bookmark bar model is loaded. 913 // History that block till bookmark bar model is loaded.
1066 TEST_F(BookmarkModelTestWithProfile2, RemoveNotification) { 914 TEST_F(BookmarkModelTestWithProfile, RemoveNotification) {
915 profile_.reset(new TestingProfile());
916
1067 profile_->CreateHistoryService(false, false); 917 profile_->CreateHistoryService(false, false);
1068 profile_->CreateBookmarkModel(true); 918 profile_->CreateBookmarkModel(true);
1069 BlockTillBookmarkModelLoaded(); 919 BlockTillBookmarkModelLoaded();
1070 920
1071 // Add a URL. 921 // Add a URL.
1072 GURL url("http://www.google.com"); 922 GURL url("http://www.google.com");
1073 bookmark_utils::AddIfNotBookmarked(bb_model_, url, string16()); 923 bookmark_utils::AddIfNotBookmarked(bb_model_, url, string16());
1074 924
1075 HistoryServiceFactory::GetForProfile( 925 HistoryServiceFactory::GetForProfile(
1076 profile_.get(), Profile::EXPLICIT_ACCESS)->AddPage( 926 profile_.get(), Profile::EXPLICIT_ACCESS)->AddPage(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 AssertExtensiveChangesObserverCount(1, 0); 1020 AssertExtensiveChangesObserverCount(1, 0);
1171 model_.EndExtensiveChanges(); 1021 model_.EndExtensiveChanges();
1172 EXPECT_TRUE(model_.IsDoingExtensiveChanges()); 1022 EXPECT_TRUE(model_.IsDoingExtensiveChanges());
1173 AssertExtensiveChangesObserverCount(1, 0); 1023 AssertExtensiveChangesObserverCount(1, 0);
1174 model_.EndExtensiveChanges(); 1024 model_.EndExtensiveChanges();
1175 EXPECT_FALSE(model_.IsDoingExtensiveChanges()); 1025 EXPECT_FALSE(model_.IsDoingExtensiveChanges());
1176 AssertExtensiveChangesObserverCount(1, 1); 1026 AssertExtensiveChangesObserverCount(1, 1);
1177 } 1027 }
1178 1028
1179 } // namespace 1029 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/history/DEPS » ('j') | chrome/browser/history/history_database_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698