OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 19 matching lines...) Expand all Loading... |
30 #include "base/file_path.h" | 30 #include "base/file_path.h" |
31 #include "base/file_util.h" | 31 #include "base/file_util.h" |
32 #include "base/memory/scoped_temp_dir.h" | 32 #include "base/memory/scoped_temp_dir.h" |
33 #include "base/memory/scoped_vector.h" | 33 #include "base/memory/scoped_vector.h" |
34 #include "base/message_loop.h" | 34 #include "base/message_loop.h" |
35 #include "base/path_service.h" | 35 #include "base/path_service.h" |
36 #include "base/string_util.h" | 36 #include "base/string_util.h" |
37 #include "base/task.h" | 37 #include "base/task.h" |
38 #include "base/utf_string_conversions.h" | 38 #include "base/utf_string_conversions.h" |
39 #include "chrome/browser/download/download_item.h" | 39 #include "chrome/browser/download/download_item.h" |
40 #include "chrome/browser/history/download_create_info.h" | 40 #include "chrome/browser/history/download_history_info.h" |
41 #include "chrome/browser/history/history.h" | 41 #include "chrome/browser/history/history.h" |
42 #include "chrome/browser/history/history_backend.h" | 42 #include "chrome/browser/history/history_backend.h" |
43 #include "chrome/browser/history/history_database.h" | 43 #include "chrome/browser/history/history_database.h" |
44 #include "chrome/browser/history/history_notifications.h" | 44 #include "chrome/browser/history/history_notifications.h" |
45 #include "chrome/browser/history/in_memory_database.h" | 45 #include "chrome/browser/history/in_memory_database.h" |
46 #include "chrome/browser/history/in_memory_history_backend.h" | 46 #include "chrome/browser/history/in_memory_history_backend.h" |
47 #include "chrome/browser/history/page_usage_data.h" | 47 #include "chrome/browser/history/page_usage_data.h" |
48 #include "chrome/common/chrome_paths.h" | 48 #include "chrome/common/chrome_paths.h" |
49 #include "chrome/common/thumbnail_score.h" | 49 #include "chrome/common/thumbnail_score.h" |
50 #include "chrome/tools/profiles/thumbnail-inl.h" | 50 #include "chrome/tools/profiles/thumbnail-inl.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 history_service_ = NULL; | 177 history_service_ = NULL; |
178 | 178 |
179 // Wait for the backend class to terminate before deleting the files and | 179 // Wait for the backend class to terminate before deleting the files and |
180 // moving to the next test. Note: if this never terminates, somebody is | 180 // moving to the next test. Note: if this never terminates, somebody is |
181 // probably leaking a reference to the history backend, so it never calls | 181 // probably leaking a reference to the history backend, so it never calls |
182 // our destroy task. | 182 // our destroy task. |
183 MessageLoop::current()->Run(); | 183 MessageLoop::current()->Run(); |
184 } | 184 } |
185 | 185 |
186 int64 AddDownload(int32 state, const Time& time) { | 186 int64 AddDownload(int32 state, const Time& time) { |
187 DownloadCreateInfo download(FilePath(FILE_PATH_LITERAL("foo-path")), | 187 DownloadHistoryInfo download(FilePath(FILE_PATH_LITERAL("foo-path")), |
188 GURL("foo-url"), time, 0, 512, state, 0, false); | 188 GURL("foo-url"), |
| 189 GURL(""), |
| 190 time, |
| 191 0, |
| 192 512, |
| 193 state, |
| 194 0); |
189 return db_->CreateDownload(download); | 195 return db_->CreateDownload(download); |
190 } | 196 } |
191 | 197 |
192 // Fills the query_url_row_ and query_url_visits_ structures with the | 198 // Fills the query_url_row_ and query_url_visits_ structures with the |
193 // information about the given URL and returns true. If the URL was not | 199 // information about the given URL and returns true. If the URL was not |
194 // found, this will return false and those structures will not be changed. | 200 // found, this will return false and those structures will not be changed. |
195 bool QueryURL(HistoryService* history, const GURL& url) { | 201 bool QueryURL(HistoryService* history, const GURL& url) { |
196 history->QueryURL(url, true, &consumer_, | 202 history->QueryURL(url, true, &consumer_, |
197 NewCallback(this, &HistoryTest::SaveURLAndQuit)); | 203 NewCallback(this, &HistoryTest::SaveURLAndQuit)); |
198 MessageLoop::current()->Run(); // Will be exited in SaveURLAndQuit. | 204 MessageLoop::current()->Run(); // Will be exited in SaveURLAndQuit. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 303 } |
298 | 304 |
299 TEST_F(HistoryTest, ClearBrowsingData_Downloads) { | 305 TEST_F(HistoryTest, ClearBrowsingData_Downloads) { |
300 CreateBackendAndDatabase(); | 306 CreateBackendAndDatabase(); |
301 | 307 |
302 Time now = Time::Now(); | 308 Time now = Time::Now(); |
303 TimeDelta one_day = TimeDelta::FromDays(1); | 309 TimeDelta one_day = TimeDelta::FromDays(1); |
304 Time month_ago = now - TimeDelta::FromDays(30); | 310 Time month_ago = now - TimeDelta::FromDays(30); |
305 | 311 |
306 // Initially there should be nothing in the downloads database. | 312 // Initially there should be nothing in the downloads database. |
307 std::vector<DownloadCreateInfo> downloads; | 313 std::vector<DownloadHistoryInfo> downloads; |
308 db_->QueryDownloads(&downloads); | 314 db_->QueryDownloads(&downloads); |
309 EXPECT_EQ(0U, downloads.size()); | 315 EXPECT_EQ(0U, downloads.size()); |
310 | 316 |
311 // Keep track of these as we need to update them later during the test. | 317 // Keep track of these as we need to update them later during the test. |
312 DownloadID in_progress, removing; | 318 DownloadID in_progress, removing; |
313 | 319 |
314 // Create one with a 0 time. | 320 // Create one with a 0 time. |
315 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, Time())); | 321 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, Time())); |
316 // Create one for now and +/- 1 day. | 322 // Create one for now and +/- 1 day. |
317 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, now - one_day)); | 323 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, now - one_day)); |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 history_service_ = history; | 855 history_service_ = history; |
850 history->ScheduleDBTask(task.get(), &request_consumer); | 856 history->ScheduleDBTask(task.get(), &request_consumer); |
851 request_consumer.CancelAllRequests(); | 857 request_consumer.CancelAllRequests(); |
852 CleanupHistoryService(); | 858 CleanupHistoryService(); |
853 // WARNING: history has now been deleted. | 859 // WARNING: history has now been deleted. |
854 history = NULL; | 860 history = NULL; |
855 ASSERT_FALSE(task->done_invoked); | 861 ASSERT_FALSE(task->done_invoked); |
856 } | 862 } |
857 | 863 |
858 } // namespace history | 864 } // namespace history |
OLD | NEW |