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 // History unit tests come in two flavors: | 5 // History unit tests come in two flavors: |
6 // | 6 // |
7 // 1. The more complicated style is that the unit test creates a full history | 7 // 1. The more complicated style is that the unit test creates a full history |
8 // service. This spawns a background thread for the history backend, and | 8 // service. This spawns a background thread for the history backend, and |
9 // all communication is asynchronous. This is useful for testing more | 9 // all communication is asynchronous. This is useful for testing more |
10 // complicated things or end-to-end behavior. | 10 // complicated things or end-to-end behavior. |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "base/memory/scoped_vector.h" | 36 #include "base/memory/scoped_vector.h" |
37 #include "base/message_loop/message_loop.h" | 37 #include "base/message_loop/message_loop.h" |
38 #include "base/path_service.h" | 38 #include "base/path_service.h" |
39 #include "base/strings/string_util.h" | 39 #include "base/strings/string_util.h" |
40 #include "base/strings/stringprintf.h" | 40 #include "base/strings/stringprintf.h" |
41 #include "base/strings/utf_string_conversions.h" | 41 #include "base/strings/utf_string_conversions.h" |
42 #include "base/task/cancelable_task_tracker.h" | 42 #include "base/task/cancelable_task_tracker.h" |
43 #include "base/threading/platform_thread.h" | 43 #include "base/threading/platform_thread.h" |
44 #include "base/time/time.h" | 44 #include "base/time/time.h" |
45 #include "chrome/browser/history/history_backend.h" | 45 #include "chrome/browser/history/history_backend.h" |
46 #include "chrome/browser/history/history_notifications.h" | |
47 #include "chrome/browser/history/history_service.h" | 46 #include "chrome/browser/history/history_service.h" |
48 #include "chrome/browser/history/in_memory_history_backend.h" | 47 #include "chrome/browser/history/in_memory_history_backend.h" |
49 #include "chrome/common/chrome_constants.h" | 48 #include "chrome/common/chrome_constants.h" |
50 #include "chrome/common/chrome_paths.h" | 49 #include "chrome/common/chrome_paths.h" |
51 #include "chrome/tools/profiles/thumbnail-inl.h" | 50 #include "chrome/tools/profiles/thumbnail-inl.h" |
52 #include "components/history/content/browser/download_constants_utils.h" | 51 #include "components/history/content/browser/download_constants_utils.h" |
53 #include "components/history/content/browser/history_database_helper.h" | 52 #include "components/history/content/browser/history_database_helper.h" |
54 #include "components/history/core/browser/download_constants.h" | 53 #include "components/history/core/browser/download_constants.h" |
55 #include "components/history/core/browser/download_row.h" | 54 #include "components/history/core/browser/download_row.h" |
56 #include "components/history/core/browser/history_constants.h" | 55 #include "components/history/core/browser/history_constants.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 100 |
102 void NotifyProfileError(sql::InitStatus init_status) override {} | 101 void NotifyProfileError(sql::InitStatus init_status) override {} |
103 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) override; | 102 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) override; |
104 void NotifyAddVisit(const BriefVisitInfo& info) override {} | 103 void NotifyAddVisit(const BriefVisitInfo& info) override {} |
105 void NotifyFaviconChanged(const std::set<GURL>& url) override {} | 104 void NotifyFaviconChanged(const std::set<GURL>& url) override {} |
106 void NotifyURLVisited(ui::PageTransition transition, | 105 void NotifyURLVisited(ui::PageTransition transition, |
107 const URLRow& row, | 106 const URLRow& row, |
108 const RedirectList& redirects, | 107 const RedirectList& redirects, |
109 base::Time visit_time) override {} | 108 base::Time visit_time) override {} |
110 void NotifyURLsModified(const URLRows& changed_urls) override {} | 109 void NotifyURLsModified(const URLRows& changed_urls) override {} |
| 110 void NotifyURLsDeleted(bool all_history, |
| 111 bool expired, |
| 112 const URLRows& deleted_rows, |
| 113 const std::set<GURL>& favicon_urls) override {} |
111 void NotifyKeywordSearchTermUpdated(const URLRow& row, | 114 void NotifyKeywordSearchTermUpdated(const URLRow& row, |
112 KeywordID keyword_id, | 115 KeywordID keyword_id, |
113 const base::string16& term) override {} | 116 const base::string16& term) override {} |
114 void NotifyKeywordSearchTermDeleted(URLID url_id) override {} | 117 void NotifyKeywordSearchTermDeleted(URLID url_id) override {} |
115 void BroadcastNotifications(int type, | |
116 scoped_ptr<HistoryDetails> details) override; | |
117 void DBLoaded() override {} | 118 void DBLoaded() override {} |
118 | 119 |
119 private: | 120 private: |
120 HistoryBackendDBTest* history_test_; | 121 HistoryBackendDBTest* history_test_; |
121 }; | 122 }; |
122 | 123 |
123 // This must be outside the anonymous namespace for the friend statement in | 124 // This must be outside the anonymous namespace for the friend statement in |
124 // HistoryBackend to work. | 125 // HistoryBackend to work. |
125 class HistoryBackendDBTest : public HistoryUnitTestBase { | 126 class HistoryBackendDBTest : public HistoryUnitTestBase { |
126 public: | 127 public: |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 HistoryDatabase* db_; // Cached reference to the backend's database. | 228 HistoryDatabase* db_; // Cached reference to the backend's database. |
228 }; | 229 }; |
229 | 230 |
230 void BackendDelegate::SetInMemoryBackend( | 231 void BackendDelegate::SetInMemoryBackend( |
231 scoped_ptr<InMemoryHistoryBackend> backend) { | 232 scoped_ptr<InMemoryHistoryBackend> backend) { |
232 // Save the in-memory backend to the history test object, this happens | 233 // Save the in-memory backend to the history test object, this happens |
233 // synchronously, so we don't have to do anything fancy. | 234 // synchronously, so we don't have to do anything fancy. |
234 history_test_->in_mem_backend_.swap(backend); | 235 history_test_->in_mem_backend_.swap(backend); |
235 } | 236 } |
236 | 237 |
237 void BackendDelegate::BroadcastNotifications( | |
238 int type, | |
239 scoped_ptr<HistoryDetails> details) { | |
240 // Currently, just send the notifications directly to the in-memory database. | |
241 // We may want do do something more fancy in the future. | |
242 content::Details<HistoryDetails> det(details.get()); | |
243 history_test_->in_mem_backend_->Observe(type, | |
244 content::Source<HistoryBackendDBTest>(NULL), det); | |
245 } | |
246 | |
247 TEST_F(HistoryBackendDBTest, ClearBrowsingData_Downloads) { | 238 TEST_F(HistoryBackendDBTest, ClearBrowsingData_Downloads) { |
248 CreateBackendAndDatabase(); | 239 CreateBackendAndDatabase(); |
249 | 240 |
250 // Initially there should be nothing in the downloads database. | 241 // Initially there should be nothing in the downloads database. |
251 std::vector<DownloadRow> downloads; | 242 std::vector<DownloadRow> downloads; |
252 db_->QueryDownloads(&downloads); | 243 db_->QueryDownloads(&downloads); |
253 EXPECT_EQ(0U, downloads.size()); | 244 EXPECT_EQ(0U, downloads.size()); |
254 | 245 |
255 // Add a download, test that it was added correctly, remove it, test that it | 246 // Add a download, test that it was added correctly, remove it, test that it |
256 // was removed. | 247 // was removed. |
(...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1874 std::vector<PageUsageData*> results; | 1865 std::vector<PageUsageData*> results; |
1875 db_->QuerySegmentUsage(segment_time, 10, &results); | 1866 db_->QuerySegmentUsage(segment_time, 10, &results); |
1876 ASSERT_EQ(1u, results.size()); | 1867 ASSERT_EQ(1u, results.size()); |
1877 EXPECT_EQ(url, results[0]->GetURL()); | 1868 EXPECT_EQ(url, results[0]->GetURL()); |
1878 EXPECT_EQ(segment_id, results[0]->GetID()); | 1869 EXPECT_EQ(segment_id, results[0]->GetID()); |
1879 EXPECT_EQ(title, results[0]->GetTitle()); | 1870 EXPECT_EQ(title, results[0]->GetTitle()); |
1880 STLDeleteElements(&results); | 1871 STLDeleteElements(&results); |
1881 } | 1872 } |
1882 | 1873 |
1883 } // namespace history | 1874 } // namespace history |
OLD | NEW |