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

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

Issue 268001: Makes sure bookmark ids are unique on reading from file. If not unique... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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
« no previous file with comments | « chrome/browser/bookmarks/bookmark_codec.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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>
6
5 #include "app/tree_node_iterator.h" 7 #include "app/tree_node_iterator.h"
6 #include "app/tree_node_model.h" 8 #include "app/tree_node_model.h"
7 #include "base/hash_tables.h" 9 #include "base/hash_tables.h"
8 #include "base/string_util.h" 10 #include "base/string_util.h"
9 #include "chrome/browser/bookmarks/bookmark_codec.h" 11 #include "chrome/browser/bookmarks/bookmark_codec.h"
10 #include "chrome/browser/bookmarks/bookmark_model.h" 12 #include "chrome/browser/bookmarks/bookmark_model.h"
11 #include "chrome/browser/bookmarks/bookmark_utils.h" 13 #include "chrome/browser/bookmarks/bookmark_utils.h"
12 #include "chrome/common/chrome_constants.h" 14 #include "chrome/common/chrome_constants.h"
13 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/notification_registrar.h" 16 #include "chrome/common/notification_registrar.h"
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 ASSERT_EQ(0, child->GetChildCount()); 759 ASSERT_EQ(0, child->GetChildCount());
758 760
759 child = parent->GetChild(1); 761 child = parent->GetChild(1);
760 ASSERT_EQ(BookmarkNode::URL, child->GetType()); 762 ASSERT_EQ(BookmarkNode::URL, child->GetType());
761 ASSERT_EQ(L"About Google", child->GetTitle()); 763 ASSERT_EQ(L"About Google", child->GetTitle());
762 ASSERT_TRUE(child->GetURL() == 764 ASSERT_TRUE(child->GetURL() ==
763 GURL("http://www.google.com/intl/en/about.html")); 765 GURL("http://www.google.com/intl/en/about.html"));
764 766
765 ASSERT_TRUE(bb_model_->IsBookmarked(GURL("http://www.google.com"))); 767 ASSERT_TRUE(bb_model_->IsBookmarked(GURL("http://www.google.com")));
766 } 768 }
769
770 void VerifyUniqueIDs() {
771 std::set<int64> ids;
772 bool has_unique = true;
773 VerifyUniqueIDImpl(bb_model_->GetBookmarkBarNode(), &ids, &has_unique);
774 VerifyUniqueIDImpl(bb_model_->other_node(), &ids, &has_unique);
775 ASSERT_TRUE(has_unique);
776 }
777
778 private:
779 void VerifyUniqueIDImpl(const BookmarkNode* node,
780 std::set<int64>* ids,
781 bool* has_unique) {
782 if (!*has_unique)
783 return;
784 if (ids->count(node->id()) != 0) {
785 *has_unique = false;
786 return;
787 }
788 ids->insert(node->id());
789 for (int i = 0; i < node->GetChildCount(); ++i) {
790 VerifyUniqueIDImpl(node->GetChild(i), ids, has_unique);
791 if (!*has_unique)
792 return;
793 }
794 }
767 }; 795 };
768 796
769 // Tests migrating bookmarks from db into file. This copies an old history db 797 // Tests migrating bookmarks from db into file. This copies an old history db
770 // file containing bookmarks and make sure they are loaded correctly and 798 // file containing bookmarks and make sure they are loaded correctly and
771 // persisted correctly. 799 // persisted correctly.
772 TEST_F(BookmarkModelTestWithProfile2, MigrateFromDBToFileTest) { 800 TEST_F(BookmarkModelTestWithProfile2, MigrateFromDBToFileTest) {
773 // Copy db file over that contains starred table. 801 // Copy db file over that contains starred table.
774 FilePath old_history_path; 802 FilePath old_history_path;
775 PathService::Get(chrome::DIR_TEST_DATA, &old_history_path); 803 PathService::Get(chrome::DIR_TEST_DATA, &old_history_path);
776 old_history_path = old_history_path.AppendASCII("bookmarks"); 804 old_history_path = old_history_path.AppendASCII("bookmarks");
777 old_history_path = old_history_path.AppendASCII("History_with_starred"); 805 old_history_path = old_history_path.AppendASCII("History_with_starred");
778 FilePath new_history_path = profile_->GetPath(); 806 FilePath new_history_path = profile_->GetPath();
779 file_util::Delete(new_history_path, true); 807 file_util::Delete(new_history_path, true);
780 file_util::CreateDirectory(new_history_path); 808 file_util::CreateDirectory(new_history_path);
781 FilePath new_history_file = new_history_path.Append( 809 FilePath new_history_file = new_history_path.Append(
782 chrome::kHistoryFilename); 810 chrome::kHistoryFilename);
783 ASSERT_TRUE(file_util::CopyFile(old_history_path, new_history_file)); 811 ASSERT_TRUE(file_util::CopyFile(old_history_path, new_history_file));
784 812
785 // Create the history service making sure it doesn't blow away the file we 813 // Create the history service making sure it doesn't blow away the file we
786 // just copied. 814 // just copied.
787 profile_->CreateHistoryService(false); 815 profile_->CreateHistoryService(false);
788 profile_->CreateBookmarkModel(true); 816 profile_->CreateBookmarkModel(true);
789 BlockTillBookmarkModelLoaded(); 817 BlockTillBookmarkModelLoaded();
790 818
791 // Make sure we loaded OK. 819 // Make sure we loaded OK.
792 VerifyExpectedState(); 820 VerifyExpectedState();
793 if (HasFatalFailure()) 821 if (HasFatalFailure())
794 return; 822 return;
795 823
824 // Make sure the ids are unique.
825 VerifyUniqueIDs();
826 if (HasFatalFailure())
827 return;
828
796 // Create again. This time we shouldn't load from history at all. 829 // Create again. This time we shouldn't load from history at all.
797 profile_->CreateBookmarkModel(false); 830 profile_->CreateBookmarkModel(false);
798 BlockTillBookmarkModelLoaded(); 831 BlockTillBookmarkModelLoaded();
799 832
800 // Make sure we loaded OK. 833 // Make sure we loaded OK.
801 VerifyExpectedState(); 834 VerifyExpectedState();
802 if (HasFatalFailure()) 835 if (HasFatalFailure())
803 return; 836 return;
804 837
838 VerifyUniqueIDs();
839 if (HasFatalFailure())
840 return;
841
805 // Recreate the history service (with a clean db). Do this just to make sure 842 // Recreate the history service (with a clean db). Do this just to make sure
806 // we're loading correctly from the bookmarks file. 843 // we're loading correctly from the bookmarks file.
807 profile_->CreateHistoryService(true); 844 profile_->CreateHistoryService(true);
808 profile_->CreateBookmarkModel(false); 845 profile_->CreateBookmarkModel(false);
809 BlockTillBookmarkModelLoaded(); 846 BlockTillBookmarkModelLoaded();
810 VerifyExpectedState(); 847 VerifyExpectedState();
848 VerifyUniqueIDs();
811 } 849 }
812 850
813 // Simple test that removes a bookmark. This test exercises the code paths in 851 // Simple test that removes a bookmark. This test exercises the code paths in
814 // History that block till bookmark bar model is loaded. 852 // History that block till bookmark bar model is loaded.
815 TEST_F(BookmarkModelTestWithProfile2, RemoveNotification) { 853 TEST_F(BookmarkModelTestWithProfile2, RemoveNotification) {
816 profile_->CreateHistoryService(false); 854 profile_->CreateHistoryService(false);
817 profile_->CreateBookmarkModel(true); 855 profile_->CreateBookmarkModel(true);
818 BlockTillBookmarkModelLoaded(); 856 BlockTillBookmarkModelLoaded();
819 857
820 // Add a URL. 858 // Add a URL.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 // Make sure we were notified. 891 // Make sure we were notified.
854 AssertObserverCount(0, 0, 0, 0, 1); 892 AssertObserverCount(0, 0, 0, 0, 1);
855 893
856 // Make sure the order matches (remember, 'a' and 'C' are folders and 894 // Make sure the order matches (remember, 'a' and 'C' are folders and
857 // come first). 895 // come first).
858 EXPECT_TRUE(parent->GetChild(0)->GetTitle() == L"a"); 896 EXPECT_TRUE(parent->GetChild(0)->GetTitle() == L"a");
859 EXPECT_TRUE(parent->GetChild(1)->GetTitle() == L"C"); 897 EXPECT_TRUE(parent->GetChild(1)->GetTitle() == L"C");
860 EXPECT_TRUE(parent->GetChild(2)->GetTitle() == L"B"); 898 EXPECT_TRUE(parent->GetChild(2)->GetTitle() == L"B");
861 EXPECT_TRUE(parent->GetChild(3)->GetTitle() == L"d"); 899 EXPECT_TRUE(parent->GetChild(3)->GetTitle() == L"d");
862 } 900 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_codec.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698