| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // our destroy task. | 186 // our destroy task. |
| 187 MessageLoop::current()->Run(); | 187 MessageLoop::current()->Run(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 int64 AddDownload(int32 state, const Time& time) { | 190 int64 AddDownload(int32 state, const Time& time) { |
| 191 DownloadPersistentStoreInfo download( | 191 DownloadPersistentStoreInfo download( |
| 192 FilePath(FILE_PATH_LITERAL("foo-path")), | 192 FilePath(FILE_PATH_LITERAL("foo-path")), |
| 193 GURL("foo-url"), | 193 GURL("foo-url"), |
| 194 GURL(""), | 194 GURL(""), |
| 195 time, | 195 time, |
| 196 time, |
| 196 0, | 197 0, |
| 197 512, | 198 512, |
| 198 state, | 199 state, |
| 200 0, |
| 199 0); | 201 0); |
| 200 return db_->CreateDownload(download); | 202 return db_->CreateDownload(download); |
| 201 } | 203 } |
| 202 | 204 |
| 203 // Fills the query_url_row_ and query_url_visits_ structures with the | 205 // Fills the query_url_row_ and query_url_visits_ structures with the |
| 204 // information about the given URL and returns true. If the URL was not | 206 // information about the given URL and returns true. If the URL was not |
| 205 // found, this will return false and those structures will not be changed. | 207 // found, this will return false and those structures will not be changed. |
| 206 bool QueryURL(HistoryService* history, const GURL& url) { | 208 bool QueryURL(HistoryService* history, const GURL& url) { |
| 207 history->QueryURL(url, true, &consumer_, | 209 history->QueryURL(url, true, &consumer_, |
| 208 base::Bind(&HistoryTest::SaveURLAndQuit, | 210 base::Bind(&HistoryTest::SaveURLAndQuit, |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0].state); | 363 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0].state); |
| 362 EXPECT_EQ(0, downloads[0].start_time.ToInternalValue()); | 364 EXPECT_EQ(0, downloads[0].start_time.ToInternalValue()); |
| 363 EXPECT_EQ(DownloadItem::IN_PROGRESS, downloads[1].state); | 365 EXPECT_EQ(DownloadItem::IN_PROGRESS, downloads[1].state); |
| 364 EXPECT_EQ(month_ago_lossy.ToInternalValue(), | 366 EXPECT_EQ(month_ago_lossy.ToInternalValue(), |
| 365 downloads[1].start_time.ToInternalValue()); | 367 downloads[1].start_time.ToInternalValue()); |
| 366 EXPECT_EQ(DownloadItem::REMOVING, downloads[2].state); | 368 EXPECT_EQ(DownloadItem::REMOVING, downloads[2].state); |
| 367 EXPECT_EQ(month_ago_lossy.ToInternalValue(), | 369 EXPECT_EQ(month_ago_lossy.ToInternalValue(), |
| 368 downloads[2].start_time.ToInternalValue()); | 370 downloads[2].start_time.ToInternalValue()); |
| 369 | 371 |
| 370 // Change state so we can delete the downloads. | 372 // Change state so we can delete the downloads. |
| 371 EXPECT_TRUE(db_->UpdateDownload(512, DownloadItem::COMPLETE, in_progress)); | 373 DownloadPersistentStoreInfo data; |
| 372 EXPECT_TRUE(db_->UpdateDownload(512, DownloadItem::CANCELLED, removing)); | 374 data.received_bytes = 512; |
| 375 data.state = DownloadItem::COMPLETE; |
| 376 data.end_time = base::Time::Now(); |
| 377 data.opened = false; |
| 378 data.db_handle = in_progress; |
| 379 EXPECT_TRUE(db_->UpdateDownload(data)); |
| 380 data.state = DownloadItem::CANCELLED; |
| 381 data.db_handle = removing; |
| 382 EXPECT_TRUE(db_->UpdateDownload(data)); |
| 373 | 383 |
| 374 // Try removing from Time=0. This should delete all. | 384 // Try removing from Time=0. This should delete all. |
| 375 db_->RemoveDownloadsBetween(Time(), Time()); | 385 db_->RemoveDownloadsBetween(Time(), Time()); |
| 376 db_->QueryDownloads(&downloads); | 386 db_->QueryDownloads(&downloads); |
| 377 EXPECT_EQ(0U, downloads.size()); | 387 EXPECT_EQ(0U, downloads.size()); |
| 378 | 388 |
| 379 // Check removal of downloads stuck in IN_PROGRESS state. | 389 // Check removal of downloads stuck in IN_PROGRESS state. |
| 380 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, month_ago)); | 390 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, month_ago)); |
| 381 EXPECT_NE(0, AddDownload(DownloadItem::IN_PROGRESS, month_ago)); | 391 EXPECT_NE(0, AddDownload(DownloadItem::IN_PROGRESS, month_ago)); |
| 382 db_->QueryDownloads(&downloads); | 392 db_->QueryDownloads(&downloads); |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 history_service_ = history; | 872 history_service_ = history; |
| 863 history->ScheduleDBTask(task.get(), &request_consumer); | 873 history->ScheduleDBTask(task.get(), &request_consumer); |
| 864 request_consumer.CancelAllRequests(); | 874 request_consumer.CancelAllRequests(); |
| 865 CleanupHistoryService(); | 875 CleanupHistoryService(); |
| 866 // WARNING: history has now been deleted. | 876 // WARNING: history has now been deleted. |
| 867 history = NULL; | 877 history = NULL; |
| 868 ASSERT_FALSE(task->done_invoked); | 878 ASSERT_FALSE(task->done_invoked); |
| 869 } | 879 } |
| 870 | 880 |
| 871 } // namespace history | 881 } // namespace history |
| OLD | NEW |