Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(820)

Unified Diff: chrome/browser/history/history_unittest.cc

Issue 10665049: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/history/history_marshaling.h ('k') | chrome/browser/ui/webui/downloads_dom_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/history_unittest.cc
diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc
index e339004a972d55bff2a18aa7e7214e40a9faf195..f0a78d5c172bb89f0b1356329814f3c7c13bbc1c 100644
--- a/chrome/browser/history/history_unittest.cc
+++ b/chrome/browser/history/history_unittest.cc
@@ -35,6 +35,7 @@
#include "base/scoped_temp_dir.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/history/download_persistent_store_info.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/history/history_backend.h"
#include "chrome/browser/history/history_database.h"
@@ -47,7 +48,6 @@
#include "chrome/common/thumbnail_score.h"
#include "chrome/tools/profiles/thumbnail-inl.h"
#include "content/public/browser/download_item.h"
-#include "content/public/browser/download_persistent_store_info.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "sql/connection.h"
@@ -59,7 +59,6 @@
using base::Time;
using base::TimeDelta;
using content::DownloadItem;
-using content::DownloadPersistentStoreInfo;
namespace history {
class HistoryTest;
@@ -311,89 +310,53 @@ void BackendDelegate::BroadcastNotifications(int type,
delete details;
}
-TEST_F(HistoryTest, ClearBrowsingData_Downloads) {
+TEST_F(HistoryTest, TimeRemoveDownloads) {
CreateBackendAndDatabase();
- Time now = Time::Now();
- TimeDelta one_day = TimeDelta::FromDays(1);
- Time month_ago = now - TimeDelta::FromDays(30);
-
// Initially there should be nothing in the downloads database.
std::vector<DownloadPersistentStoreInfo> downloads;
db_->QueryDownloads(&downloads);
EXPECT_EQ(0U, downloads.size());
- // Keep track of these as we need to update them later during the test.
- DownloadID in_progress;
-
- // Create one with a 0 time.
- EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, Time()));
- // Create one for now and +/- 1 day.
- EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, now - one_day));
- EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, now));
- EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, now + one_day));
- // Try the other four states.
- EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, month_ago));
- EXPECT_NE(0, in_progress = AddDownload(DownloadItem::IN_PROGRESS, month_ago));
- EXPECT_NE(0, AddDownload(DownloadItem::CANCELLED, month_ago));
- EXPECT_NE(0, AddDownload(DownloadItem::INTERRUPTED, month_ago));
-
- // Test to see if inserts worked.
- db_->QueryDownloads(&downloads);
- EXPECT_EQ(8U, downloads.size());
+ std::set<DownloadID> handles;
+ base::Time start_adding = base::Time::Now();
+ static const int kNumDownloads = 100000;
+ for (int i = 0; i < kNumDownloads; ++i) {
+ handles.insert(AddDownload(DownloadItem::COMPLETE,
+ start_adding - base::TimeDelta::FromSeconds(i)));
+ }
+ LOG(INFO) << "occam time to add " << kNumDownloads << " records: "
+ << (base::Time::Now() - start_adding).InMillisecondsF() << " ms";
- // Try removing from current timestamp. This should delete the one in the
- // future and one very recent one.
- db_->RemoveDownloadsBetween(now, Time());
db_->QueryDownloads(&downloads);
- EXPECT_EQ(6U, downloads.size());
+ EXPECT_EQ(static_cast<size_t>(kNumDownloads), downloads.size());
+
+ base::Time start_removing = base::Time::Now();
+ db_->RemoveDownloads(handles);
+ LOG(INFO) << "occam time to remove " << kNumDownloads << " records: "
+ << (base::Time::Now() - start_removing).InMillisecondsF() << " ms";
- // Try removing from two months ago. This should not delete items that are
- // 'in progress' or in 'removing' state.
- db_->RemoveDownloadsBetween(now - TimeDelta::FromDays(60), Time());
- db_->QueryDownloads(&downloads);
- EXPECT_EQ(2U, downloads.size());
-
- // Download manager converts to TimeT, which is lossy, so we do the same
- // for comparison.
- Time month_ago_lossy = Time::FromTimeT(month_ago.ToTimeT());
-
- // Make sure the right values remain.
- EXPECT_EQ(DownloadItem::COMPLETE, downloads[0].state);
- EXPECT_EQ(0, downloads[0].start_time.ToInternalValue());
- EXPECT_EQ(DownloadItem::IN_PROGRESS, downloads[1].state);
- EXPECT_EQ(month_ago_lossy.ToInternalValue(),
- downloads[1].start_time.ToInternalValue());
-
- // Change state so we can delete the downloads.
- DownloadPersistentStoreInfo data;
- data.received_bytes = 512;
- data.state = DownloadItem::COMPLETE;
- data.end_time = base::Time::Now();
- data.opened = false;
- data.db_handle = in_progress;
- EXPECT_TRUE(db_->UpdateDownload(data));
- data.state = DownloadItem::CANCELLED;
- EXPECT_TRUE(db_->UpdateDownload(data));
-
- // Try removing from Time=0. This should delete all.
- db_->RemoveDownloadsBetween(Time(), Time());
db_->QueryDownloads(&downloads);
EXPECT_EQ(0U, downloads.size());
+}
- // Check removal of downloads stuck in IN_PROGRESS state.
- EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, month_ago));
- EXPECT_NE(0, AddDownload(DownloadItem::IN_PROGRESS, month_ago));
- db_->QueryDownloads(&downloads);
- EXPECT_EQ(2U, downloads.size());
- db_->RemoveDownloadsBetween(Time(), Time());
+TEST_F(HistoryTest, ClearBrowsingData_Downloads) {
+ CreateBackendAndDatabase();
+
+ // Initially there should be nothing in the downloads database.
+ std::vector<DownloadPersistentStoreInfo> downloads;
db_->QueryDownloads(&downloads);
- // IN_PROGRESS download should remain. It it indicated as "Canceled"
- EXPECT_EQ(1U, downloads.size());
- db_->CleanUpInProgressEntries();
+ EXPECT_EQ(0U, downloads.size());
+
+ // Add a download, test that it was added, remove it, test that it was
+ // removed.
+ DownloadID handle;
+ EXPECT_NE(0, handle = AddDownload(DownloadItem::COMPLETE, Time()));
db_->QueryDownloads(&downloads);
EXPECT_EQ(1U, downloads.size());
- db_->RemoveDownloadsBetween(Time(), Time());
+ std::set<DownloadID> remove_set;
+ remove_set.insert(handle);
+ db_->RemoveDownloads(remove_set);
db_->QueryDownloads(&downloads);
EXPECT_EQ(0U, downloads.size());
}
« no previous file with comments | « chrome/browser/history/history_marshaling.h ('k') | chrome/browser/ui/webui/downloads_dom_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698