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

Side by Side Diff: chrome/browser/history/history_backend_unittest.cc

Issue 285233012: Abstract history dependencies on bookmarks through HistoryClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests Created 6 years, 7 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
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 "chrome/browser/history/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/run_loop.h" 19 #include "base/run_loop.h"
20 #include "base/strings/string16.h" 20 #include "base/strings/string16.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
24 #include "chrome/browser/chrome_notification_types.h" 23 #include "chrome/browser/chrome_notification_types.h"
25 #include "chrome/browser/history/history_notifications.h" 24 #include "chrome/browser/history/history_notifications.h"
26 #include "chrome/browser/history/history_service.h" 25 #include "chrome/browser/history/history_service.h"
27 #include "chrome/browser/history/history_service_factory.h" 26 #include "chrome/browser/history/history_service_factory.h"
28 #include "chrome/browser/history/in_memory_database.h" 27 #include "chrome/browser/history/in_memory_database.h"
29 #include "chrome/browser/history/in_memory_history_backend.h" 28 #include "chrome/browser/history/in_memory_history_backend.h"
30 #include "chrome/browser/history/visit_filter.h" 29 #include "chrome/browser/history/visit_filter.h"
31 #include "chrome/common/chrome_constants.h" 30 #include "chrome/common/chrome_constants.h"
32 #include "chrome/common/chrome_paths.h" 31 #include "chrome/common/chrome_paths.h"
33 #include "chrome/common/importer/imported_favicon_usage.h" 32 #include "chrome/common/importer/imported_favicon_usage.h"
34 #include "chrome/test/base/testing_profile.h" 33 #include "chrome/test/base/testing_profile.h"
35 #include "components/bookmarks/browser/bookmark_model.h" 34 #include "components/history/core/browser/history_client_mock_bookmarks.h"
36 #include "components/bookmarks/browser/bookmark_utils.h"
37 #include "components/bookmarks/test/bookmark_test_helpers.h"
38 #include "components/bookmarks/test/test_bookmark_client.h"
39 #include "content/public/browser/notification_details.h" 35 #include "content/public/browser/notification_details.h"
40 #include "content/public/browser/notification_source.h" 36 #include "content/public/browser/notification_source.h"
41 #include "content/public/test/test_browser_thread.h" 37 #include "content/public/test/test_browser_thread.h"
42 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
43 #include "url/gurl.h" 39 #include "url/gurl.h"
44 40
45 using base::Time; 41 using base::Time;
46 42
47 // This file only tests functionality where it is most convenient to call the 43 // This file only tests functionality where it is most convenient to call the
48 // backend directly. Most of the history backend functions are tested by the 44 // backend directly. Most of the history backend functions are tested by the
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 AddRequest(request, this); 105 AddRequest(request, this);
110 return request->handle(); 106 return request->handle();
111 } 107 }
112 }; 108 };
113 109
114 class HistoryBackendTestBase : public testing::Test { 110 class HistoryBackendTestBase : public testing::Test {
115 public: 111 public:
116 typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList; 112 typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList;
117 113
118 HistoryBackendTestBase() 114 HistoryBackendTestBase()
119 : bookmark_model_(bookmark_client_.CreateModel(false)), 115 : loaded_(false),
120 loaded_(false),
121 ui_thread_(content::BrowserThread::UI, &message_loop_) {} 116 ui_thread_(content::BrowserThread::UI, &message_loop_) {}
122 117
123 virtual ~HistoryBackendTestBase() { 118 virtual ~HistoryBackendTestBase() {
124 STLDeleteValues(&broadcasted_notifications_); 119 STLDeleteValues(&broadcasted_notifications_);
125 } 120 }
126 121
127 protected: 122 protected:
128 int num_broadcasted_notifications() const { 123 int num_broadcasted_notifications() const {
129 return broadcasted_notifications_.size(); 124 return broadcasted_notifications_.size();
130 } 125 }
(...skipping 14 matching lines...) Expand all
145 // Send the notifications directly to the in-memory database. 140 // Send the notifications directly to the in-memory database.
146 content::Details<HistoryDetails> det(details.get()); 141 content::Details<HistoryDetails> det(details.get());
147 mem_backend_->Observe( 142 mem_backend_->Observe(
148 type, content::Source<HistoryBackendTestBase>(NULL), det); 143 type, content::Source<HistoryBackendTestBase>(NULL), det);
149 144
150 // The backend passes ownership of the details pointer to us. 145 // The backend passes ownership of the details pointer to us.
151 broadcasted_notifications_.push_back( 146 broadcasted_notifications_.push_back(
152 std::make_pair(type, details.release())); 147 std::make_pair(type, details.release()));
153 } 148 }
154 149
155 test::TestBookmarkClient bookmark_client_; 150 history::HistoryClientMockBookmarks history_client_;
156 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. 151 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure.
157 scoped_ptr<InMemoryHistoryBackend> mem_backend_; 152 scoped_ptr<InMemoryHistoryBackend> mem_backend_;
158 scoped_ptr<BookmarkModel> bookmark_model_;
159 bool loaded_; 153 bool loaded_;
160 154
161 private: 155 private:
162 friend class HistoryBackendTestDelegate; 156 friend class HistoryBackendTestDelegate;
163 157
164 // testing::Test 158 // testing::Test
165 virtual void SetUp() { 159 virtual void SetUp() {
166 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), 160 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"),
167 &test_dir_)) 161 &test_dir_))
168 return; 162 return;
169 backend_ = new HistoryBackend( 163 backend_ = new HistoryBackend(
170 test_dir_, new HistoryBackendTestDelegate(this), bookmark_model_.get()); 164 test_dir_, new HistoryBackendTestDelegate(this), &history_client_);
171 backend_->Init(std::string(), false); 165 backend_->Init(std::string(), false);
172 } 166 }
173 167
174 virtual void TearDown() { 168 virtual void TearDown() {
175 if (backend_.get()) 169 if (backend_.get())
176 backend_->Closing(); 170 backend_->Closing();
177 backend_ = NULL; 171 backend_ = NULL;
178 mem_backend_.reset(); 172 mem_backend_.reset();
179 base::DeleteFile(test_dir_, true); 173 base::DeleteFile(test_dir_, true);
180 base::RunLoop().RunUntilIdle(); 174 base::RunLoop().RunUntilIdle();
175 history_client_.ClearAllBookmarks();
181 } 176 }
182 177
183 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) { 178 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) {
184 mem_backend_.swap(backend); 179 mem_backend_.swap(backend);
185 } 180 }
186 181
187 // The types and details of notifications which were broadcasted. 182 // The types and details of notifications which were broadcasted.
188 NotificationList broadcasted_notifications_; 183 NotificationList broadcasted_notifications_;
189 184
190 base::MessageLoop message_loop_; 185 base::MessageLoop message_loop_;
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 backend_->db_->GetVisitsForURL(row2_id, &visits); 599 backend_->db_->GetVisitsForURL(row2_id, &visits);
605 ASSERT_EQ(1U, visits.size()); 600 ASSERT_EQ(1U, visits.size());
606 601
607 // The in-memory backend should have been set and it should have gotten the 602 // The in-memory backend should have been set and it should have gotten the
608 // typed URL. 603 // typed URL.
609 ASSERT_TRUE(mem_backend_.get()); 604 ASSERT_TRUE(mem_backend_.get());
610 URLRow outrow1; 605 URLRow outrow1;
611 EXPECT_TRUE(mem_backend_->db_->GetRowForURL(row1.url(), NULL)); 606 EXPECT_TRUE(mem_backend_->db_->GetRowForURL(row1.url(), NULL));
612 607
613 // Star row1. 608 // Star row1.
614 bookmark_model_->AddURL( 609 history_client_.AddBookmark(row1.url());
615 bookmark_model_->bookmark_bar_node(), 0, base::string16(), row1.url());
616 610
617 // Now finally clear all history. 611 // Now finally clear all history.
618 ClearBroadcastedNotifications(); 612 ClearBroadcastedNotifications();
619 backend_->DeleteAllHistory(); 613 backend_->DeleteAllHistory();
620 614
621 // The first URL should be preserved but the time should be cleared. 615 // The first URL should be preserved but the time should be cleared.
622 EXPECT_TRUE(backend_->db_->GetRowForURL(row1.url(), &outrow1)); 616 EXPECT_TRUE(backend_->db_->GetRowForURL(row1.url(), &outrow1));
623 EXPECT_EQ(row1.url(), outrow1.url()); 617 EXPECT_EQ(row1.url(), outrow1.url());
624 EXPECT_EQ(0, outrow1.visit_count()); 618 EXPECT_EQ(0, outrow1.visit_count());
625 EXPECT_EQ(0, outrow1.typed_count()); 619 EXPECT_EQ(0, outrow1.typed_count());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 663
670 // The remaining URL should still reference the same favicon, even if its 664 // The remaining URL should still reference the same favicon, even if its
671 // ID has changed. 665 // ID has changed.
672 std::vector<IconMapping> mappings; 666 std::vector<IconMapping> mappings;
673 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 667 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
674 outrow1.url(), favicon_base::FAVICON, &mappings)); 668 outrow1.url(), favicon_base::FAVICON, &mappings));
675 EXPECT_EQ(1u, mappings.size()); 669 EXPECT_EQ(1u, mappings.size());
676 EXPECT_EQ(out_favicon1, mappings[0].icon_id); 670 EXPECT_EQ(out_favicon1, mappings[0].icon_id);
677 671
678 // The first URL should still be bookmarked. 672 // The first URL should still be bookmarked.
679 EXPECT_TRUE(bookmark_model_->IsBookmarked(row1.url())); 673 EXPECT_TRUE(history_client_.IsBookmarked(row1.url()));
680 674
681 // Check that we fire the notification about all history having been deleted. 675 // Check that we fire the notification about all history having been deleted.
682 ASSERT_EQ(1u, broadcasted_notifications().size()); 676 ASSERT_EQ(1u, broadcasted_notifications().size());
683 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, 677 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
684 broadcasted_notifications()[0].first); 678 broadcasted_notifications()[0].first);
685 const URLsDeletedDetails* details = static_cast<const URLsDeletedDetails*>( 679 const URLsDeletedDetails* details = static_cast<const URLsDeletedDetails*>(
686 broadcasted_notifications()[0].second); 680 broadcasted_notifications()[0].second);
687 EXPECT_TRUE(details->all_history); 681 EXPECT_TRUE(details->all_history);
688 EXPECT_FALSE(details->archived); 682 EXPECT_FALSE(details->archived);
689 } 683 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 761
768 URLRows rows; 762 URLRows rows;
769 rows.push_back(row2); // Reversed order for the same reason as favicons. 763 rows.push_back(row2); // Reversed order for the same reason as favicons.
770 rows.push_back(row1); 764 rows.push_back(row1);
771 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); 765 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED);
772 766
773 URLID row1_id = backend_->db_->GetRowForURL(row1.url(), NULL); 767 URLID row1_id = backend_->db_->GetRowForURL(row1.url(), NULL);
774 URLID row2_id = backend_->db_->GetRowForURL(row2.url(), NULL); 768 URLID row2_id = backend_->db_->GetRowForURL(row2.url(), NULL);
775 769
776 // Star the two URLs. 770 // Star the two URLs.
777 bookmark_utils::AddIfNotBookmarked( 771 history_client_.AddBookmark(row1.url());
778 bookmark_model_.get(), row1.url(), base::string16()); 772 history_client_.AddBookmark(row2.url());
779 bookmark_utils::AddIfNotBookmarked(
780 bookmark_model_.get(), row2.url(), base::string16());
781 773
782 // Delete url 2. Because url 2 is starred this won't delete the URL, only 774 // Delete url 2. Because url 2 is starred this won't delete the URL, only
783 // the visits. 775 // the visits.
784 backend_->expirer_.DeleteURL(row2.url()); 776 backend_->expirer_.DeleteURL(row2.url());
785 777
786 // Make sure url 2 is still valid, but has no visits. 778 // Make sure url 2 is still valid, but has no visits.
787 URLRow tmp_url_row; 779 URLRow tmp_url_row;
788 EXPECT_EQ(row2_id, backend_->db_->GetRowForURL(row2.url(), NULL)); 780 EXPECT_EQ(row2_id, backend_->db_->GetRowForURL(row2.url(), NULL));
789 VisitVector visits; 781 VisitVector visits;
790 backend_->db_->GetVisitsForURL(row2_id, &visits); 782 backend_->db_->GetVisitsForURL(row2_id, &visits);
791 EXPECT_EQ(0U, visits.size()); 783 EXPECT_EQ(0U, visits.size());
792 // The favicon should still be valid. 784 // The favicon should still be valid.
793 EXPECT_EQ(favicon2, 785 EXPECT_EQ(favicon2,
794 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 786 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
795 favicon_url2, favicon_base::FAVICON, NULL)); 787 favicon_url2, favicon_base::FAVICON, NULL));
796 788
797 // Unstar row2. 789 // Unstar row2.
798 bookmark_utils::RemoveAllBookmarks(bookmark_model_.get(), row2.url()); 790 history_client_.DelBookmark(row2.url());
799 791
800 // Tell the backend it was unstarred. We have to explicitly do this as 792 // Tell the backend it was unstarred. We have to explicitly do this as
801 // BookmarkModel isn't wired up to the backend during testing. 793 // BookmarkModel isn't wired up to the backend during testing.
802 std::set<GURL> unstarred_urls; 794 std::set<GURL> unstarred_urls;
803 unstarred_urls.insert(row2.url()); 795 unstarred_urls.insert(row2.url());
804 backend_->URLsNoLongerBookmarked(unstarred_urls); 796 backend_->URLsNoLongerBookmarked(unstarred_urls);
805 797
806 // The URL should no longer exist. 798 // The URL should no longer exist.
807 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &tmp_url_row)); 799 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &tmp_url_row));
808 // And the favicon should be deleted. 800 // And the favicon should be deleted.
809 EXPECT_EQ(0, 801 EXPECT_EQ(0,
810 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 802 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
811 favicon_url2, favicon_base::FAVICON, NULL)); 803 favicon_url2, favicon_base::FAVICON, NULL));
812 804
813 // Unstar row 1. 805 // Unstar row 1.
814 bookmark_utils::RemoveAllBookmarks(bookmark_model_.get(), row1.url()); 806 history_client_.DelBookmark(row1.url());
807
815 // Tell the backend it was unstarred. We have to explicitly do this as 808 // Tell the backend it was unstarred. We have to explicitly do this as
816 // BookmarkModel isn't wired up to the backend during testing. 809 // BookmarkModel isn't wired up to the backend during testing.
817 unstarred_urls.clear(); 810 unstarred_urls.clear();
818 unstarred_urls.insert(row1.url()); 811 unstarred_urls.insert(row1.url());
819 backend_->URLsNoLongerBookmarked(unstarred_urls); 812 backend_->URLsNoLongerBookmarked(unstarred_urls);
820 813
821 // The URL should still exist (because there were visits). 814 // The URL should still exist (because there were visits).
822 EXPECT_EQ(row1_id, backend_->db_->GetRowForURL(row1.url(), NULL)); 815 EXPECT_EQ(row1_id, backend_->db_->GetRowForURL(row1.url(), NULL));
823 816
824 // There should still be visits. 817 // There should still be visits.
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 favicons.clear(); 1069 favicons.clear();
1077 favicon.favicon_url = GURL("http://mail.google.com/favicon.ico"); 1070 favicon.favicon_url = GURL("http://mail.google.com/favicon.ico");
1078 favicon.png_data.push_back('3'); 1071 favicon.png_data.push_back('3');
1079 favicon.urls.insert(url3); 1072 favicon.urls.insert(url3);
1080 favicons.push_back(favicon); 1073 favicons.push_back(favicon);
1081 backend_->SetImportedFavicons(favicons); 1074 backend_->SetImportedFavicons(favicons);
1082 URLRow url_row3; 1075 URLRow url_row3;
1083 EXPECT_TRUE(backend_->db_->GetRowForURL(url3, &url_row3) == 0); 1076 EXPECT_TRUE(backend_->db_->GetRowForURL(url3, &url_row3) == 0);
1084 1077
1085 // If the URL is bookmarked, it should get added to history with 0 visits. 1078 // If the URL is bookmarked, it should get added to history with 0 visits.
1086 bookmark_model_->AddURL( 1079 history_client_.AddBookmark(url3);
1087 bookmark_model_->bookmark_bar_node(), 0, base::string16(), url3);
1088 backend_->SetImportedFavicons(favicons); 1080 backend_->SetImportedFavicons(favicons);
1089 EXPECT_FALSE(backend_->db_->GetRowForURL(url3, &url_row3) == 0); 1081 EXPECT_FALSE(backend_->db_->GetRowForURL(url3, &url_row3) == 0);
1090 EXPECT_TRUE(url_row3.visit_count() == 0); 1082 EXPECT_TRUE(url_row3.visit_count() == 0);
1091 } 1083 }
1092 1084
1093 TEST_F(HistoryBackendTest, StripUsernamePasswordTest) { 1085 TEST_F(HistoryBackendTest, StripUsernamePasswordTest) {
1094 ASSERT_TRUE(backend_.get()); 1086 ASSERT_TRUE(backend_.get());
1095 1087
1096 GURL url("http://anyuser:anypass@www.google.com"); 1088 GURL url("http://anyuser:anypass@www.google.com");
1097 GURL stripped_url("http://www.google.com"); 1089 GURL stripped_url("http://www.google.com");
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 // in Teardown. 1471 // in Teardown.
1480 base::FilePath new_history_path(test_dir()); 1472 base::FilePath new_history_path(test_dir());
1481 base::DeleteFile(new_history_path, true); 1473 base::DeleteFile(new_history_path, true);
1482 base::CreateDirectory(new_history_path); 1474 base::CreateDirectory(new_history_path);
1483 base::FilePath new_history_file = 1475 base::FilePath new_history_file =
1484 new_history_path.Append(chrome::kHistoryFilename); 1476 new_history_path.Append(chrome::kHistoryFilename);
1485 ASSERT_TRUE(base::CopyFile(old_history_path, new_history_file)); 1477 ASSERT_TRUE(base::CopyFile(old_history_path, new_history_file));
1486 1478
1487 backend_ = new HistoryBackend(new_history_path, 1479 backend_ = new HistoryBackend(new_history_path,
1488 new HistoryBackendTestDelegate(this), 1480 new HistoryBackendTestDelegate(this),
1489 bookmark_model_.get()); 1481 &history_client_);
1490 backend_->Init(std::string(), false); 1482 backend_->Init(std::string(), false);
1491 backend_->Closing(); 1483 backend_->Closing();
1492 backend_ = NULL; 1484 backend_ = NULL;
1493 1485
1494 // Now the database should already be migrated. 1486 // Now the database should already be migrated.
1495 // Check version first. 1487 // Check version first.
1496 int cur_version = HistoryDatabase::GetCurrentVersion(); 1488 int cur_version = HistoryDatabase::GetCurrentVersion();
1497 sql::Connection db; 1489 sql::Connection db;
1498 ASSERT_TRUE(db.Open(new_history_file)); 1490 ASSERT_TRUE(db.Open(new_history_file));
1499 sql::Statement s(db.GetUniqueStatement( 1491 sql::Statement s(db.GetUniqueStatement(
(...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after
2882 base::CreateDirectory(new_history_path); 2874 base::CreateDirectory(new_history_path);
2883 base::FilePath new_history_file = 2875 base::FilePath new_history_file =
2884 new_history_path.Append(chrome::kHistoryFilename); 2876 new_history_path.Append(chrome::kHistoryFilename);
2885 base::FilePath new_archived_file = 2877 base::FilePath new_archived_file =
2886 new_history_path.Append(chrome::kArchivedHistoryFilename); 2878 new_history_path.Append(chrome::kArchivedHistoryFilename);
2887 ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); 2879 ASSERT_TRUE(base::CopyFile(old_history, new_history_file));
2888 ASSERT_TRUE(base::CopyFile(old_archived, new_archived_file)); 2880 ASSERT_TRUE(base::CopyFile(old_archived, new_archived_file));
2889 2881
2890 backend_ = new HistoryBackend(new_history_path, 2882 backend_ = new HistoryBackend(new_history_path,
2891 new HistoryBackendTestDelegate(this), 2883 new HistoryBackendTestDelegate(this),
2892 bookmark_model_.get()); 2884 &history_client_);
2893 backend_->Init(std::string(), false); 2885 backend_->Init(std::string(), false);
2894 backend_->Closing(); 2886 backend_->Closing();
2895 backend_ = NULL; 2887 backend_ = NULL;
2896 2888
2897 // Now both history and archived_history databases should already be migrated. 2889 // Now both history and archived_history databases should already be migrated.
2898 2890
2899 // Check version in history database first. 2891 // Check version in history database first.
2900 int cur_version = HistoryDatabase::GetCurrentVersion(); 2892 int cur_version = HistoryDatabase::GetCurrentVersion();
2901 sql::Connection db; 2893 sql::Connection db;
2902 ASSERT_TRUE(db.Open(new_history_file)); 2894 ASSERT_TRUE(db.Open(new_history_file));
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
3118 EXPECT_TRUE(backend_->db()->GetKeywordSearchTermRow(url1_id, NULL)); 3110 EXPECT_TRUE(backend_->db()->GetKeywordSearchTermRow(url1_id, NULL));
3119 EXPECT_FALSE(backend_->db()->GetKeywordSearchTermRow(url2_id, NULL)); 3111 EXPECT_FALSE(backend_->db()->GetKeywordSearchTermRow(url2_id, NULL));
3120 EXPECT_FALSE(backend_->db()->GetKeywordSearchTermRow(url3_id, NULL)); 3112 EXPECT_FALSE(backend_->db()->GetKeywordSearchTermRow(url3_id, NULL));
3121 } 3113 }
3122 3114
3123 // Simple test that removes a bookmark. This test exercises the code paths in 3115 // Simple test that removes a bookmark. This test exercises the code paths in
3124 // History that block till bookmark bar model is loaded. 3116 // History that block till bookmark bar model is loaded.
3125 TEST_F(HistoryBackendTest, RemoveNotification) { 3117 TEST_F(HistoryBackendTest, RemoveNotification) {
3126 scoped_ptr<TestingProfile> profile(new TestingProfile()); 3118 scoped_ptr<TestingProfile> profile(new TestingProfile());
3127 3119
3128 ASSERT_TRUE(profile->CreateHistoryService(false, false));
3129 profile->CreateBookmarkModel(true);
3130 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile.get());
3131 test::WaitForBookmarkModelToLoad(model);
3132
3133 // Add a URL. 3120 // Add a URL.
3134 GURL url("http://www.google.com"); 3121 GURL url("http://www.google.com");
3135 bookmark_utils::AddIfNotBookmarked(model, url, base::string16()); 3122 history_client_.AddBookmark(url);
3136 3123 scoped_ptr<HistoryService> service(
3137 HistoryService* service = HistoryServiceFactory::GetForProfile( 3124 new HistoryService(&history_client_, profile.get()));
3138 profile.get(), Profile::EXPLICIT_ACCESS); 3125 EXPECT_TRUE(service->Init(profile->GetPath()));
3139 3126
3140 service->AddPage( 3127 service->AddPage(
3141 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(), 3128 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(),
3142 content::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false); 3129 content::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false);
3143 3130
3144 // This won't actually delete the URL, rather it'll empty out the visits. 3131 // This won't actually delete the URL, rather it'll empty out the visits.
3145 // This triggers blocking on the BookmarkModel. 3132 // This triggers blocking on the BookmarkModel.
3133 // TODO(sdefresne): mock the BlockTillBookmarksLoaded and check it has been
3134 // called at least once!
3146 service->DeleteURL(url); 3135 service->DeleteURL(url);
3147 } 3136 }
3148 3137
3149 // Test DeleteFTSIndexDatabases deletes expected files. 3138 // Test DeleteFTSIndexDatabases deletes expected files.
3150 TEST_F(HistoryBackendTest, DeleteFTSIndexDatabases) { 3139 TEST_F(HistoryBackendTest, DeleteFTSIndexDatabases) {
3151 ASSERT_TRUE(backend_.get()); 3140 ASSERT_TRUE(backend_.get());
3152 3141
3153 base::FilePath history_path(test_dir()); 3142 base::FilePath history_path(test_dir());
3154 base::FilePath db1(history_path.AppendASCII("History Index 2013-05")); 3143 base::FilePath db1(history_path.AppendASCII("History Index 2013-05"));
3155 base::FilePath db1_journal(db1.InsertBeforeExtensionASCII("-journal")); 3144 base::FilePath db1_journal(db1.InsertBeforeExtensionASCII("-journal"));
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
3384 // Verify that the second term is no longer returned as result, and also check 3373 // Verify that the second term is no longer returned as result, and also check
3385 // at the low level that it is gone for good. The term corresponding to the 3374 // at the low level that it is gone for good. The term corresponding to the
3386 // first URLRow should not be affected. 3375 // first URLRow should not be affected.
3387 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); 3376 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
3388 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); 3377 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
3389 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); 3378 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
3390 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); 3379 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
3391 } 3380 }
3392 3381
3393 } // namespace history 3382 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698