OLD | NEW |
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/test/history_client_fake_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" |
| 38 #include "testing/gmock/include/gmock/gmock.h" |
42 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
43 #include "url/gurl.h" | 40 #include "url/gurl.h" |
44 | 41 |
45 using base::Time; | 42 using base::Time; |
46 | 43 |
47 // This file only tests functionality where it is most convenient to call the | 44 // 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 | 45 // backend directly. Most of the history backend functions are tested by the |
49 // history unit test. Because of the elaborate callbacks involved, this is no | 46 // history unit test. Because of the elaborate callbacks involved, this is no |
50 // harder than calling it directly for many things. | 47 // harder than calling it directly for many things. |
51 | 48 |
52 namespace { | 49 namespace { |
53 | 50 |
54 static const gfx::Size kTinySize = gfx::Size(10, 10); | 51 static const gfx::Size kTinySize = gfx::Size(10, 10); |
55 static const gfx::Size kSmallSize = gfx::Size(16, 16); | 52 static const gfx::Size kSmallSize = gfx::Size(16, 16); |
56 static const gfx::Size kLargeSize = gfx::Size(32, 32); | 53 static const gfx::Size kLargeSize = gfx::Size(32, 32); |
57 | 54 |
58 // Comparison functions as to make it easier to check results of | 55 // Comparison functions as to make it easier to check results of |
59 // GetFaviconBitmaps() and GetIconMappingsForPageURL(). | 56 // GetFaviconBitmaps() and GetIconMappingsForPageURL(). |
60 bool IconMappingLessThan(const history::IconMapping& a, | 57 bool IconMappingLessThan(const history::IconMapping& a, |
61 const history::IconMapping& b) { | 58 const history::IconMapping& b) { |
62 return a.icon_url < b.icon_url; | 59 return a.icon_url < b.icon_url; |
63 } | 60 } |
64 | 61 |
65 bool FaviconBitmapLessThan(const history::FaviconBitmap& a, | 62 bool FaviconBitmapLessThan(const history::FaviconBitmap& a, |
66 const history::FaviconBitmap& b) { | 63 const history::FaviconBitmap& b) { |
67 return a.pixel_size.GetArea() < b.pixel_size.GetArea(); | 64 return a.pixel_size.GetArea() < b.pixel_size.GetArea(); |
68 } | 65 } |
69 | 66 |
| 67 class HistoryClientMock : public history::HistoryClientFakeBookmarks { |
| 68 public: |
| 69 MOCK_METHOD0(BlockUntilBookmarksLoaded, void()); |
| 70 }; |
| 71 |
70 } // namespace | 72 } // namespace |
71 | 73 |
72 namespace history { | 74 namespace history { |
73 | 75 |
74 class HistoryBackendTestBase; | 76 class HistoryBackendTestBase; |
75 | 77 |
76 // This must be a separate object since HistoryBackend manages its lifetime. | 78 // This must be a separate object since HistoryBackend manages its lifetime. |
77 // This just forwards the messages we're interested in to the test object. | 79 // This just forwards the messages we're interested in to the test object. |
78 class HistoryBackendTestDelegate : public HistoryBackend::Delegate { | 80 class HistoryBackendTestDelegate : public HistoryBackend::Delegate { |
79 public: | 81 public: |
(...skipping 29 matching lines...) Expand all Loading... |
109 AddRequest(request, this); | 111 AddRequest(request, this); |
110 return request->handle(); | 112 return request->handle(); |
111 } | 113 } |
112 }; | 114 }; |
113 | 115 |
114 class HistoryBackendTestBase : public testing::Test { | 116 class HistoryBackendTestBase : public testing::Test { |
115 public: | 117 public: |
116 typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList; | 118 typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList; |
117 | 119 |
118 HistoryBackendTestBase() | 120 HistoryBackendTestBase() |
119 : bookmark_model_(bookmark_client_.CreateModel(false)), | 121 : loaded_(false), |
120 loaded_(false), | |
121 ui_thread_(content::BrowserThread::UI, &message_loop_) {} | 122 ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
122 | 123 |
123 virtual ~HistoryBackendTestBase() { | 124 virtual ~HistoryBackendTestBase() { |
124 STLDeleteValues(&broadcasted_notifications_); | 125 STLDeleteValues(&broadcasted_notifications_); |
125 } | 126 } |
126 | 127 |
127 protected: | 128 protected: |
128 int num_broadcasted_notifications() const { | 129 int num_broadcasted_notifications() const { |
129 return broadcasted_notifications_.size(); | 130 return broadcasted_notifications_.size(); |
130 } | 131 } |
(...skipping 14 matching lines...) Expand all Loading... |
145 // Send the notifications directly to the in-memory database. | 146 // Send the notifications directly to the in-memory database. |
146 content::Details<HistoryDetails> det(details.get()); | 147 content::Details<HistoryDetails> det(details.get()); |
147 mem_backend_->Observe( | 148 mem_backend_->Observe( |
148 type, content::Source<HistoryBackendTestBase>(NULL), det); | 149 type, content::Source<HistoryBackendTestBase>(NULL), det); |
149 | 150 |
150 // The backend passes ownership of the details pointer to us. | 151 // The backend passes ownership of the details pointer to us. |
151 broadcasted_notifications_.push_back( | 152 broadcasted_notifications_.push_back( |
152 std::make_pair(type, details.release())); | 153 std::make_pair(type, details.release())); |
153 } | 154 } |
154 | 155 |
155 test::TestBookmarkClient bookmark_client_; | 156 history::HistoryClientFakeBookmarks history_client_; |
156 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. | 157 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. |
157 scoped_ptr<InMemoryHistoryBackend> mem_backend_; | 158 scoped_ptr<InMemoryHistoryBackend> mem_backend_; |
158 scoped_ptr<BookmarkModel> bookmark_model_; | |
159 bool loaded_; | 159 bool loaded_; |
160 | 160 |
161 private: | 161 private: |
162 friend class HistoryBackendTestDelegate; | 162 friend class HistoryBackendTestDelegate; |
163 | 163 |
164 // testing::Test | 164 // testing::Test |
165 virtual void SetUp() { | 165 virtual void SetUp() { |
166 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), | 166 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), |
167 &test_dir_)) | 167 &test_dir_)) |
168 return; | 168 return; |
169 backend_ = new HistoryBackend( | 169 backend_ = new HistoryBackend( |
170 test_dir_, new HistoryBackendTestDelegate(this), bookmark_model_.get()); | 170 test_dir_, new HistoryBackendTestDelegate(this), &history_client_); |
171 backend_->Init(std::string(), false); | 171 backend_->Init(std::string(), false); |
172 } | 172 } |
173 | 173 |
174 virtual void TearDown() { | 174 virtual void TearDown() { |
175 if (backend_.get()) | 175 if (backend_.get()) |
176 backend_->Closing(); | 176 backend_->Closing(); |
177 backend_ = NULL; | 177 backend_ = NULL; |
178 mem_backend_.reset(); | 178 mem_backend_.reset(); |
179 base::DeleteFile(test_dir_, true); | 179 base::DeleteFile(test_dir_, true); |
180 base::RunLoop().RunUntilIdle(); | 180 base::RunLoop().RunUntilIdle(); |
| 181 history_client_.ClearAllBookmarks(); |
181 } | 182 } |
182 | 183 |
183 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) { | 184 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) { |
184 mem_backend_.swap(backend); | 185 mem_backend_.swap(backend); |
185 } | 186 } |
186 | 187 |
187 // The types and details of notifications which were broadcasted. | 188 // The types and details of notifications which were broadcasted. |
188 NotificationList broadcasted_notifications_; | 189 NotificationList broadcasted_notifications_; |
189 | 190 |
190 base::MessageLoop message_loop_; | 191 base::MessageLoop message_loop_; |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 backend_->db_->GetVisitsForURL(row2_id, &visits); | 605 backend_->db_->GetVisitsForURL(row2_id, &visits); |
605 ASSERT_EQ(1U, visits.size()); | 606 ASSERT_EQ(1U, visits.size()); |
606 | 607 |
607 // The in-memory backend should have been set and it should have gotten the | 608 // The in-memory backend should have been set and it should have gotten the |
608 // typed URL. | 609 // typed URL. |
609 ASSERT_TRUE(mem_backend_.get()); | 610 ASSERT_TRUE(mem_backend_.get()); |
610 URLRow outrow1; | 611 URLRow outrow1; |
611 EXPECT_TRUE(mem_backend_->db_->GetRowForURL(row1.url(), NULL)); | 612 EXPECT_TRUE(mem_backend_->db_->GetRowForURL(row1.url(), NULL)); |
612 | 613 |
613 // Star row1. | 614 // Star row1. |
614 bookmark_model_->AddURL( | 615 history_client_.AddBookmark(row1.url()); |
615 bookmark_model_->bookmark_bar_node(), 0, base::string16(), row1.url()); | |
616 | 616 |
617 // Now finally clear all history. | 617 // Now finally clear all history. |
618 ClearBroadcastedNotifications(); | 618 ClearBroadcastedNotifications(); |
619 backend_->DeleteAllHistory(); | 619 backend_->DeleteAllHistory(); |
620 | 620 |
621 // The first URL should be preserved but the time should be cleared. | 621 // The first URL should be preserved but the time should be cleared. |
622 EXPECT_TRUE(backend_->db_->GetRowForURL(row1.url(), &outrow1)); | 622 EXPECT_TRUE(backend_->db_->GetRowForURL(row1.url(), &outrow1)); |
623 EXPECT_EQ(row1.url(), outrow1.url()); | 623 EXPECT_EQ(row1.url(), outrow1.url()); |
624 EXPECT_EQ(0, outrow1.visit_count()); | 624 EXPECT_EQ(0, outrow1.visit_count()); |
625 EXPECT_EQ(0, outrow1.typed_count()); | 625 EXPECT_EQ(0, outrow1.typed_count()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 | 669 |
670 // The remaining URL should still reference the same favicon, even if its | 670 // The remaining URL should still reference the same favicon, even if its |
671 // ID has changed. | 671 // ID has changed. |
672 std::vector<IconMapping> mappings; | 672 std::vector<IconMapping> mappings; |
673 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 673 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
674 outrow1.url(), favicon_base::FAVICON, &mappings)); | 674 outrow1.url(), favicon_base::FAVICON, &mappings)); |
675 EXPECT_EQ(1u, mappings.size()); | 675 EXPECT_EQ(1u, mappings.size()); |
676 EXPECT_EQ(out_favicon1, mappings[0].icon_id); | 676 EXPECT_EQ(out_favicon1, mappings[0].icon_id); |
677 | 677 |
678 // The first URL should still be bookmarked. | 678 // The first URL should still be bookmarked. |
679 EXPECT_TRUE(bookmark_model_->IsBookmarked(row1.url())); | 679 EXPECT_TRUE(history_client_.IsBookmarked(row1.url())); |
680 | 680 |
681 // Check that we fire the notification about all history having been deleted. | 681 // Check that we fire the notification about all history having been deleted. |
682 ASSERT_EQ(1u, broadcasted_notifications().size()); | 682 ASSERT_EQ(1u, broadcasted_notifications().size()); |
683 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 683 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
684 broadcasted_notifications()[0].first); | 684 broadcasted_notifications()[0].first); |
685 const URLsDeletedDetails* details = static_cast<const URLsDeletedDetails*>( | 685 const URLsDeletedDetails* details = static_cast<const URLsDeletedDetails*>( |
686 broadcasted_notifications()[0].second); | 686 broadcasted_notifications()[0].second); |
687 EXPECT_TRUE(details->all_history); | 687 EXPECT_TRUE(details->all_history); |
688 EXPECT_FALSE(details->archived); | 688 EXPECT_FALSE(details->archived); |
689 } | 689 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 | 767 |
768 URLRows rows; | 768 URLRows rows; |
769 rows.push_back(row2); // Reversed order for the same reason as favicons. | 769 rows.push_back(row2); // Reversed order for the same reason as favicons. |
770 rows.push_back(row1); | 770 rows.push_back(row1); |
771 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); | 771 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); |
772 | 772 |
773 URLID row1_id = backend_->db_->GetRowForURL(row1.url(), NULL); | 773 URLID row1_id = backend_->db_->GetRowForURL(row1.url(), NULL); |
774 URLID row2_id = backend_->db_->GetRowForURL(row2.url(), NULL); | 774 URLID row2_id = backend_->db_->GetRowForURL(row2.url(), NULL); |
775 | 775 |
776 // Star the two URLs. | 776 // Star the two URLs. |
777 bookmark_utils::AddIfNotBookmarked( | 777 history_client_.AddBookmark(row1.url()); |
778 bookmark_model_.get(), row1.url(), base::string16()); | 778 history_client_.AddBookmark(row2.url()); |
779 bookmark_utils::AddIfNotBookmarked( | |
780 bookmark_model_.get(), row2.url(), base::string16()); | |
781 | 779 |
782 // Delete url 2. Because url 2 is starred this won't delete the URL, only | 780 // Delete url 2. Because url 2 is starred this won't delete the URL, only |
783 // the visits. | 781 // the visits. |
784 backend_->expirer_.DeleteURL(row2.url()); | 782 backend_->expirer_.DeleteURL(row2.url()); |
785 | 783 |
786 // Make sure url 2 is still valid, but has no visits. | 784 // Make sure url 2 is still valid, but has no visits. |
787 URLRow tmp_url_row; | 785 URLRow tmp_url_row; |
788 EXPECT_EQ(row2_id, backend_->db_->GetRowForURL(row2.url(), NULL)); | 786 EXPECT_EQ(row2_id, backend_->db_->GetRowForURL(row2.url(), NULL)); |
789 VisitVector visits; | 787 VisitVector visits; |
790 backend_->db_->GetVisitsForURL(row2_id, &visits); | 788 backend_->db_->GetVisitsForURL(row2_id, &visits); |
791 EXPECT_EQ(0U, visits.size()); | 789 EXPECT_EQ(0U, visits.size()); |
792 // The favicon should still be valid. | 790 // The favicon should still be valid. |
793 EXPECT_EQ(favicon2, | 791 EXPECT_EQ(favicon2, |
794 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( | 792 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( |
795 favicon_url2, favicon_base::FAVICON, NULL)); | 793 favicon_url2, favicon_base::FAVICON, NULL)); |
796 | 794 |
797 // Unstar row2. | 795 // Unstar row2. |
798 bookmark_utils::RemoveAllBookmarks(bookmark_model_.get(), row2.url()); | 796 history_client_.DelBookmark(row2.url()); |
799 | 797 |
800 // Tell the backend it was unstarred. We have to explicitly do this as | 798 // Tell the backend it was unstarred. We have to explicitly do this as |
801 // BookmarkModel isn't wired up to the backend during testing. | 799 // BookmarkModel isn't wired up to the backend during testing. |
802 std::set<GURL> unstarred_urls; | 800 std::set<GURL> unstarred_urls; |
803 unstarred_urls.insert(row2.url()); | 801 unstarred_urls.insert(row2.url()); |
804 backend_->URLsNoLongerBookmarked(unstarred_urls); | 802 backend_->URLsNoLongerBookmarked(unstarred_urls); |
805 | 803 |
806 // The URL should no longer exist. | 804 // The URL should no longer exist. |
807 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &tmp_url_row)); | 805 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &tmp_url_row)); |
808 // And the favicon should be deleted. | 806 // And the favicon should be deleted. |
809 EXPECT_EQ(0, | 807 EXPECT_EQ(0, |
810 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( | 808 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( |
811 favicon_url2, favicon_base::FAVICON, NULL)); | 809 favicon_url2, favicon_base::FAVICON, NULL)); |
812 | 810 |
813 // Unstar row 1. | 811 // Unstar row 1. |
814 bookmark_utils::RemoveAllBookmarks(bookmark_model_.get(), row1.url()); | 812 history_client_.DelBookmark(row1.url()); |
| 813 |
815 // Tell the backend it was unstarred. We have to explicitly do this as | 814 // Tell the backend it was unstarred. We have to explicitly do this as |
816 // BookmarkModel isn't wired up to the backend during testing. | 815 // BookmarkModel isn't wired up to the backend during testing. |
817 unstarred_urls.clear(); | 816 unstarred_urls.clear(); |
818 unstarred_urls.insert(row1.url()); | 817 unstarred_urls.insert(row1.url()); |
819 backend_->URLsNoLongerBookmarked(unstarred_urls); | 818 backend_->URLsNoLongerBookmarked(unstarred_urls); |
820 | 819 |
821 // The URL should still exist (because there were visits). | 820 // The URL should still exist (because there were visits). |
822 EXPECT_EQ(row1_id, backend_->db_->GetRowForURL(row1.url(), NULL)); | 821 EXPECT_EQ(row1_id, backend_->db_->GetRowForURL(row1.url(), NULL)); |
823 | 822 |
824 // There should still be visits. | 823 // There should still be visits. |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 favicons.clear(); | 1075 favicons.clear(); |
1077 favicon.favicon_url = GURL("http://mail.google.com/favicon.ico"); | 1076 favicon.favicon_url = GURL("http://mail.google.com/favicon.ico"); |
1078 favicon.png_data.push_back('3'); | 1077 favicon.png_data.push_back('3'); |
1079 favicon.urls.insert(url3); | 1078 favicon.urls.insert(url3); |
1080 favicons.push_back(favicon); | 1079 favicons.push_back(favicon); |
1081 backend_->SetImportedFavicons(favicons); | 1080 backend_->SetImportedFavicons(favicons); |
1082 URLRow url_row3; | 1081 URLRow url_row3; |
1083 EXPECT_TRUE(backend_->db_->GetRowForURL(url3, &url_row3) == 0); | 1082 EXPECT_TRUE(backend_->db_->GetRowForURL(url3, &url_row3) == 0); |
1084 | 1083 |
1085 // If the URL is bookmarked, it should get added to history with 0 visits. | 1084 // If the URL is bookmarked, it should get added to history with 0 visits. |
1086 bookmark_model_->AddURL( | 1085 history_client_.AddBookmark(url3); |
1087 bookmark_model_->bookmark_bar_node(), 0, base::string16(), url3); | |
1088 backend_->SetImportedFavicons(favicons); | 1086 backend_->SetImportedFavicons(favicons); |
1089 EXPECT_FALSE(backend_->db_->GetRowForURL(url3, &url_row3) == 0); | 1087 EXPECT_FALSE(backend_->db_->GetRowForURL(url3, &url_row3) == 0); |
1090 EXPECT_TRUE(url_row3.visit_count() == 0); | 1088 EXPECT_TRUE(url_row3.visit_count() == 0); |
1091 } | 1089 } |
1092 | 1090 |
1093 TEST_F(HistoryBackendTest, StripUsernamePasswordTest) { | 1091 TEST_F(HistoryBackendTest, StripUsernamePasswordTest) { |
1094 ASSERT_TRUE(backend_.get()); | 1092 ASSERT_TRUE(backend_.get()); |
1095 | 1093 |
1096 GURL url("http://anyuser:anypass@www.google.com"); | 1094 GURL url("http://anyuser:anypass@www.google.com"); |
1097 GURL stripped_url("http://www.google.com"); | 1095 GURL stripped_url("http://www.google.com"); |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 | 1475 |
1478 // Copy history database file to current directory so that it will be deleted | 1476 // Copy history database file to current directory so that it will be deleted |
1479 // in Teardown. | 1477 // in Teardown. |
1480 base::FilePath new_history_path(test_dir()); | 1478 base::FilePath new_history_path(test_dir()); |
1481 base::DeleteFile(new_history_path, true); | 1479 base::DeleteFile(new_history_path, true); |
1482 base::CreateDirectory(new_history_path); | 1480 base::CreateDirectory(new_history_path); |
1483 base::FilePath new_history_file = | 1481 base::FilePath new_history_file = |
1484 new_history_path.Append(chrome::kHistoryFilename); | 1482 new_history_path.Append(chrome::kHistoryFilename); |
1485 ASSERT_TRUE(base::CopyFile(old_history_path, new_history_file)); | 1483 ASSERT_TRUE(base::CopyFile(old_history_path, new_history_file)); |
1486 | 1484 |
1487 backend_ = new HistoryBackend(new_history_path, | 1485 backend_ = new HistoryBackend( |
1488 new HistoryBackendTestDelegate(this), | 1486 new_history_path, new HistoryBackendTestDelegate(this), &history_client_); |
1489 bookmark_model_.get()); | |
1490 backend_->Init(std::string(), false); | 1487 backend_->Init(std::string(), false); |
1491 backend_->Closing(); | 1488 backend_->Closing(); |
1492 backend_ = NULL; | 1489 backend_ = NULL; |
1493 | 1490 |
1494 // Now the database should already be migrated. | 1491 // Now the database should already be migrated. |
1495 // Check version first. | 1492 // Check version first. |
1496 int cur_version = HistoryDatabase::GetCurrentVersion(); | 1493 int cur_version = HistoryDatabase::GetCurrentVersion(); |
1497 sql::Connection db; | 1494 sql::Connection db; |
1498 ASSERT_TRUE(db.Open(new_history_file)); | 1495 ASSERT_TRUE(db.Open(new_history_file)); |
1499 sql::Statement s(db.GetUniqueStatement( | 1496 sql::Statement s(db.GetUniqueStatement( |
(...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2880 base::FilePath new_history_path(test_dir()); | 2877 base::FilePath new_history_path(test_dir()); |
2881 base::DeleteFile(new_history_path, true); | 2878 base::DeleteFile(new_history_path, true); |
2882 base::CreateDirectory(new_history_path); | 2879 base::CreateDirectory(new_history_path); |
2883 base::FilePath new_history_file = | 2880 base::FilePath new_history_file = |
2884 new_history_path.Append(chrome::kHistoryFilename); | 2881 new_history_path.Append(chrome::kHistoryFilename); |
2885 base::FilePath new_archived_file = | 2882 base::FilePath new_archived_file = |
2886 new_history_path.Append(chrome::kArchivedHistoryFilename); | 2883 new_history_path.Append(chrome::kArchivedHistoryFilename); |
2887 ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); | 2884 ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); |
2888 ASSERT_TRUE(base::CopyFile(old_archived, new_archived_file)); | 2885 ASSERT_TRUE(base::CopyFile(old_archived, new_archived_file)); |
2889 | 2886 |
2890 backend_ = new HistoryBackend(new_history_path, | 2887 backend_ = new HistoryBackend( |
2891 new HistoryBackendTestDelegate(this), | 2888 new_history_path, new HistoryBackendTestDelegate(this), &history_client_); |
2892 bookmark_model_.get()); | |
2893 backend_->Init(std::string(), false); | 2889 backend_->Init(std::string(), false); |
2894 backend_->Closing(); | 2890 backend_->Closing(); |
2895 backend_ = NULL; | 2891 backend_ = NULL; |
2896 | 2892 |
2897 // Now both history and archived_history databases should already be migrated. | 2893 // Now both history and archived_history databases should already be migrated. |
2898 | 2894 |
2899 // Check version in history database first. | 2895 // Check version in history database first. |
2900 int cur_version = HistoryDatabase::GetCurrentVersion(); | 2896 int cur_version = HistoryDatabase::GetCurrentVersion(); |
2901 sql::Connection db; | 2897 sql::Connection db; |
2902 ASSERT_TRUE(db.Open(new_history_file)); | 2898 ASSERT_TRUE(db.Open(new_history_file)); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3118 EXPECT_TRUE(backend_->db()->GetKeywordSearchTermRow(url1_id, NULL)); | 3114 EXPECT_TRUE(backend_->db()->GetKeywordSearchTermRow(url1_id, NULL)); |
3119 EXPECT_FALSE(backend_->db()->GetKeywordSearchTermRow(url2_id, NULL)); | 3115 EXPECT_FALSE(backend_->db()->GetKeywordSearchTermRow(url2_id, NULL)); |
3120 EXPECT_FALSE(backend_->db()->GetKeywordSearchTermRow(url3_id, NULL)); | 3116 EXPECT_FALSE(backend_->db()->GetKeywordSearchTermRow(url3_id, NULL)); |
3121 } | 3117 } |
3122 | 3118 |
3123 // Simple test that removes a bookmark. This test exercises the code paths in | 3119 // Simple test that removes a bookmark. This test exercises the code paths in |
3124 // History that block till bookmark bar model is loaded. | 3120 // History that block till bookmark bar model is loaded. |
3125 TEST_F(HistoryBackendTest, RemoveNotification) { | 3121 TEST_F(HistoryBackendTest, RemoveNotification) { |
3126 scoped_ptr<TestingProfile> profile(new TestingProfile()); | 3122 scoped_ptr<TestingProfile> profile(new TestingProfile()); |
3127 | 3123 |
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. | 3124 // Add a URL. |
3134 GURL url("http://www.google.com"); | 3125 GURL url("http://www.google.com"); |
3135 bookmark_utils::AddIfNotBookmarked(model, url, base::string16()); | 3126 HistoryClientMock history_client; |
3136 | 3127 history_client.AddBookmark(url); |
3137 HistoryService* service = HistoryServiceFactory::GetForProfile( | 3128 scoped_ptr<HistoryService> service( |
3138 profile.get(), Profile::EXPLICIT_ACCESS); | 3129 new HistoryService(&history_client, profile.get())); |
| 3130 EXPECT_TRUE(service->Init(profile->GetPath())); |
3139 | 3131 |
3140 service->AddPage( | 3132 service->AddPage( |
3141 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(), | 3133 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(), |
3142 content::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false); | 3134 content::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false); |
3143 | 3135 |
3144 // This won't actually delete the URL, rather it'll empty out the visits. | 3136 // This won't actually delete the URL, rather it'll empty out the visits. |
3145 // This triggers blocking on the BookmarkModel. | 3137 // This triggers blocking on the BookmarkModel. |
| 3138 EXPECT_CALL(history_client, BlockUntilBookmarksLoaded()); |
3146 service->DeleteURL(url); | 3139 service->DeleteURL(url); |
3147 } | 3140 } |
3148 | 3141 |
3149 // Test DeleteFTSIndexDatabases deletes expected files. | 3142 // Test DeleteFTSIndexDatabases deletes expected files. |
3150 TEST_F(HistoryBackendTest, DeleteFTSIndexDatabases) { | 3143 TEST_F(HistoryBackendTest, DeleteFTSIndexDatabases) { |
3151 ASSERT_TRUE(backend_.get()); | 3144 ASSERT_TRUE(backend_.get()); |
3152 | 3145 |
3153 base::FilePath history_path(test_dir()); | 3146 base::FilePath history_path(test_dir()); |
3154 base::FilePath db1(history_path.AppendASCII("History Index 2013-05")); | 3147 base::FilePath db1(history_path.AppendASCII("History Index 2013-05")); |
3155 base::FilePath db1_journal(db1.InsertBeforeExtensionASCII("-journal")); | 3148 base::FilePath db1_journal(db1.InsertBeforeExtensionASCII("-journal")); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3384 // Verify that the second term is no longer returned as result, and also check | 3377 // 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 | 3378 // at the low level that it is gone for good. The term corresponding to the |
3386 // first URLRow should not be affected. | 3379 // first URLRow should not be affected. |
3387 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); | 3380 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); |
3388 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); | 3381 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); |
3389 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); | 3382 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); |
3390 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); | 3383 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); |
3391 } | 3384 } |
3392 | 3385 |
3393 } // namespace history | 3386 } // namespace history |
OLD | NEW |