OLD | NEW |
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> | 5 #include <set> |
6 | 6 |
7 #include "app/tree_node_iterator.h" | 7 #include "app/tree_node_iterator.h" |
8 #include "app/tree_node_model.h" | 8 #include "app/tree_node_model.h" |
9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 else | 612 else |
613 bb_model_->AddObserver(this); | 613 bb_model_->AddObserver(this); |
614 } | 614 } |
615 | 615 |
616 // Destroys the current profile, creates a new one and creates the history | 616 // Destroys the current profile, creates a new one and creates the history |
617 // service. | 617 // service. |
618 void RecreateProfile() { | 618 void RecreateProfile() { |
619 // Need to shutdown the old one before creating a new one. | 619 // Need to shutdown the old one before creating a new one. |
620 profile_.reset(NULL); | 620 profile_.reset(NULL); |
621 profile_.reset(new TestingProfile()); | 621 profile_.reset(new TestingProfile()); |
622 profile_->CreateHistoryService(true); | 622 profile_->CreateHistoryService(true, false); |
623 } | 623 } |
624 | 624 |
625 BookmarkModel* bb_model_; | 625 BookmarkModel* bb_model_; |
626 | 626 |
627 private: | 627 private: |
628 // Blocks until the BookmarkModel has finished loading. | 628 // Blocks until the BookmarkModel has finished loading. |
629 void BlockTillLoaded(BookmarkModel* model) { | 629 void BlockTillLoaded(BookmarkModel* model) { |
630 model->AddObserver(this); | 630 model->AddObserver(this); |
631 MessageLoop::current()->Run(); | 631 MessageLoop::current()->Run(); |
632 } | 632 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 { L"a [ b ]", L"" }, | 678 { L"a [ b ]", L"" }, |
679 { L"a b c [ d e [ f ] ]", L"g h i [ j k [ l ] ]"}, | 679 { L"a b c [ d e [ f ] ]", L"g h i [ j k [ l ] ]"}, |
680 }; | 680 }; |
681 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 681 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
682 // Recreate the profile. We need to reset with NULL first so that the last | 682 // Recreate the profile. We need to reset with NULL first so that the last |
683 // HistoryService releases the locks on the files it creates and we can | 683 // HistoryService releases the locks on the files it creates and we can |
684 // delete them. | 684 // delete them. |
685 profile_.reset(NULL); | 685 profile_.reset(NULL); |
686 profile_.reset(new TestingProfile()); | 686 profile_.reset(new TestingProfile()); |
687 profile_->CreateBookmarkModel(true); | 687 profile_->CreateBookmarkModel(true); |
688 profile_->CreateHistoryService(true); | 688 profile_->CreateHistoryService(true, false); |
689 BlockTillBookmarkModelLoaded(); | 689 BlockTillBookmarkModelLoaded(); |
690 | 690 |
691 TestNode bbn; | 691 TestNode bbn; |
692 PopulateNodeFromString(data[i].bbn_contents, &bbn); | 692 PopulateNodeFromString(data[i].bbn_contents, &bbn); |
693 PopulateBookmarkNode(&bbn, bb_model_, bb_model_->GetBookmarkBarNode()); | 693 PopulateBookmarkNode(&bbn, bb_model_, bb_model_->GetBookmarkBarNode()); |
694 | 694 |
695 TestNode other; | 695 TestNode other; |
696 PopulateNodeFromString(data[i].other_contents, &other); | 696 PopulateNodeFromString(data[i].other_contents, &other); |
697 PopulateBookmarkNode(&other, bb_model_, bb_model_->other_node()); | 697 PopulateBookmarkNode(&other, bb_model_, bb_model_->other_node()); |
698 | 698 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 old_history_path = old_history_path.AppendASCII("History_with_starred"); | 811 old_history_path = old_history_path.AppendASCII("History_with_starred"); |
812 FilePath new_history_path = profile_->GetPath(); | 812 FilePath new_history_path = profile_->GetPath(); |
813 file_util::Delete(new_history_path, true); | 813 file_util::Delete(new_history_path, true); |
814 file_util::CreateDirectory(new_history_path); | 814 file_util::CreateDirectory(new_history_path); |
815 FilePath new_history_file = new_history_path.Append( | 815 FilePath new_history_file = new_history_path.Append( |
816 chrome::kHistoryFilename); | 816 chrome::kHistoryFilename); |
817 ASSERT_TRUE(file_util::CopyFile(old_history_path, new_history_file)); | 817 ASSERT_TRUE(file_util::CopyFile(old_history_path, new_history_file)); |
818 | 818 |
819 // Create the history service making sure it doesn't blow away the file we | 819 // Create the history service making sure it doesn't blow away the file we |
820 // just copied. | 820 // just copied. |
821 profile_->CreateHistoryService(false); | 821 profile_->CreateHistoryService(false, false); |
822 profile_->CreateBookmarkModel(true); | 822 profile_->CreateBookmarkModel(true); |
823 BlockTillBookmarkModelLoaded(); | 823 BlockTillBookmarkModelLoaded(); |
824 | 824 |
825 // Make sure we loaded OK. | 825 // Make sure we loaded OK. |
826 VerifyExpectedState(); | 826 VerifyExpectedState(); |
827 if (HasFatalFailure()) | 827 if (HasFatalFailure()) |
828 return; | 828 return; |
829 | 829 |
830 // Make sure the ids are unique. | 830 // Make sure the ids are unique. |
831 VerifyUniqueIDs(); | 831 VerifyUniqueIDs(); |
832 if (HasFatalFailure()) | 832 if (HasFatalFailure()) |
833 return; | 833 return; |
834 | 834 |
835 // Create again. This time we shouldn't load from history at all. | 835 // Create again. This time we shouldn't load from history at all. |
836 profile_->CreateBookmarkModel(false); | 836 profile_->CreateBookmarkModel(false); |
837 BlockTillBookmarkModelLoaded(); | 837 BlockTillBookmarkModelLoaded(); |
838 | 838 |
839 // Make sure we loaded OK. | 839 // Make sure we loaded OK. |
840 VerifyExpectedState(); | 840 VerifyExpectedState(); |
841 if (HasFatalFailure()) | 841 if (HasFatalFailure()) |
842 return; | 842 return; |
843 | 843 |
844 VerifyUniqueIDs(); | 844 VerifyUniqueIDs(); |
845 if (HasFatalFailure()) | 845 if (HasFatalFailure()) |
846 return; | 846 return; |
847 | 847 |
848 // Recreate the history service (with a clean db). Do this just to make sure | 848 // Recreate the history service (with a clean db). Do this just to make sure |
849 // we're loading correctly from the bookmarks file. | 849 // we're loading correctly from the bookmarks file. |
850 profile_->CreateHistoryService(true); | 850 profile_->CreateHistoryService(true, false); |
851 profile_->CreateBookmarkModel(false); | 851 profile_->CreateBookmarkModel(false); |
852 BlockTillBookmarkModelLoaded(); | 852 BlockTillBookmarkModelLoaded(); |
853 VerifyExpectedState(); | 853 VerifyExpectedState(); |
854 VerifyUniqueIDs(); | 854 VerifyUniqueIDs(); |
855 } | 855 } |
856 | 856 |
857 // Simple test that removes a bookmark. This test exercises the code paths in | 857 // Simple test that removes a bookmark. This test exercises the code paths in |
858 // History that block till bookmark bar model is loaded. | 858 // History that block till bookmark bar model is loaded. |
859 TEST_F(BookmarkModelTestWithProfile2, RemoveNotification) { | 859 TEST_F(BookmarkModelTestWithProfile2, RemoveNotification) { |
860 profile_->CreateHistoryService(false); | 860 profile_->CreateHistoryService(false, false); |
861 profile_->CreateBookmarkModel(true); | 861 profile_->CreateBookmarkModel(true); |
862 BlockTillBookmarkModelLoaded(); | 862 BlockTillBookmarkModelLoaded(); |
863 | 863 |
864 // Add a URL. | 864 // Add a URL. |
865 GURL url("http://www.google.com"); | 865 GURL url("http://www.google.com"); |
866 bb_model_->SetURLStarred(url, std::wstring(), true); | 866 bb_model_->SetURLStarred(url, std::wstring(), true); |
867 | 867 |
868 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)->AddPage( | 868 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)->AddPage( |
869 url, NULL, 1, GURL(), PageTransition::TYPED, | 869 url, NULL, 1, GURL(), PageTransition::TYPED, |
870 history::RedirectList(), false); | 870 history::RedirectList(), false); |
(...skipping 26 matching lines...) Expand all Loading... |
897 // Make sure we were notified. | 897 // Make sure we were notified. |
898 AssertObserverCount(0, 0, 0, 0, 1); | 898 AssertObserverCount(0, 0, 0, 0, 1); |
899 | 899 |
900 // Make sure the order matches (remember, 'a' and 'C' are folders and | 900 // Make sure the order matches (remember, 'a' and 'C' are folders and |
901 // come first). | 901 // come first). |
902 EXPECT_TRUE(parent->GetChild(0)->GetTitle() == L"a"); | 902 EXPECT_TRUE(parent->GetChild(0)->GetTitle() == L"a"); |
903 EXPECT_TRUE(parent->GetChild(1)->GetTitle() == L"C"); | 903 EXPECT_TRUE(parent->GetChild(1)->GetTitle() == L"C"); |
904 EXPECT_TRUE(parent->GetChild(2)->GetTitle() == L"B"); | 904 EXPECT_TRUE(parent->GetChild(2)->GetTitle() == L"B"); |
905 EXPECT_TRUE(parent->GetChild(3)->GetTitle() == L"d"); | 905 EXPECT_TRUE(parent->GetChild(3)->GetTitle() == L"d"); |
906 } | 906 } |
OLD | NEW |