| 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 time, |
| 190 0, |
| 191 512, |
| 192 state); |
| 189 return db_->CreateDownload(download); | 193 return db_->CreateDownload(download); |
| 190 } | 194 } |
| 191 | 195 |
| 192 // Fills the query_url_row_ and query_url_visits_ structures with the | 196 // 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 | 197 // 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. | 198 // found, this will return false and those structures will not be changed. |
| 195 bool QueryURL(HistoryService* history, const GURL& url) { | 199 bool QueryURL(HistoryService* history, const GURL& url) { |
| 196 history->QueryURL(url, true, &consumer_, | 200 history->QueryURL(url, true, &consumer_, |
| 197 NewCallback(this, &HistoryTest::SaveURLAndQuit)); | 201 NewCallback(this, &HistoryTest::SaveURLAndQuit)); |
| 198 MessageLoop::current()->Run(); // Will be exited in SaveURLAndQuit. | 202 MessageLoop::current()->Run(); // Will be exited in SaveURLAndQuit. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 } | 301 } |
| 298 | 302 |
| 299 TEST_F(HistoryTest, ClearBrowsingData_Downloads) { | 303 TEST_F(HistoryTest, ClearBrowsingData_Downloads) { |
| 300 CreateBackendAndDatabase(); | 304 CreateBackendAndDatabase(); |
| 301 | 305 |
| 302 Time now = Time::Now(); | 306 Time now = Time::Now(); |
| 303 TimeDelta one_day = TimeDelta::FromDays(1); | 307 TimeDelta one_day = TimeDelta::FromDays(1); |
| 304 Time month_ago = now - TimeDelta::FromDays(30); | 308 Time month_ago = now - TimeDelta::FromDays(30); |
| 305 | 309 |
| 306 // Initially there should be nothing in the downloads database. | 310 // Initially there should be nothing in the downloads database. |
| 307 std::vector<DownloadCreateInfo> downloads; | 311 std::vector<DownloadHistoryInfo> downloads; |
| 308 db_->QueryDownloads(&downloads); | 312 db_->QueryDownloads(&downloads); |
| 309 EXPECT_EQ(0U, downloads.size()); | 313 EXPECT_EQ(0U, downloads.size()); |
| 310 | 314 |
| 311 // Keep track of these as we need to update them later during the test. | 315 // Keep track of these as we need to update them later during the test. |
| 312 DownloadID in_progress, removing; | 316 DownloadID in_progress, removing; |
| 313 | 317 |
| 314 // Create one with a 0 time. | 318 // Create one with a 0 time. |
| 315 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, Time())); | 319 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, Time())); |
| 316 // Create one for now and +/- 1 day. | 320 // Create one for now and +/- 1 day. |
| 317 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, now - one_day)); | 321 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; | 853 history_service_ = history; |
| 850 history->ScheduleDBTask(task.get(), &request_consumer); | 854 history->ScheduleDBTask(task.get(), &request_consumer); |
| 851 request_consumer.CancelAllRequests(); | 855 request_consumer.CancelAllRequests(); |
| 852 CleanupHistoryService(); | 856 CleanupHistoryService(); |
| 853 // WARNING: history has now been deleted. | 857 // WARNING: history has now been deleted. |
| 854 history = NULL; | 858 history = NULL; |
| 855 ASSERT_FALSE(task->done_invoked); | 859 ASSERT_FALSE(task->done_invoked); |
| 856 } | 860 } |
| 857 | 861 |
| 858 } // namespace history | 862 } // namespace history |
| OLD | NEW |