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

Unified Diff: components/history/core/browser/history_backend_db_unittest.cc

Issue 2665243003: add a download slices table into history download db (Closed)
Patch Set: use Select changes() instead of select count(*) Created 3 years, 10 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
Index: components/history/core/browser/history_backend_db_unittest.cc
diff --git a/components/history/core/browser/history_backend_db_unittest.cc b/components/history/core/browser/history_backend_db_unittest.cc
index fd033d7f8a2f867938a5b93dfc0bea2c8b864961..bcf849ae668afc4e2a2be994070ffebada195828 100644
--- a/components/history/core/browser/history_backend_db_unittest.cc
+++ b/components/history/core/browser/history_backend_db_unittest.cc
@@ -749,7 +749,7 @@ TEST_F(HistoryBackendDBTest, DownloadCreateAndQuery) {
100, 1000, DownloadState::INTERRUPTED, DownloadDangerType::NOT_DANGEROUS,
kTestDownloadInterruptReasonCrash, "hash-value1", 1,
"FE672168-26EF-4275-A149-FEC25F6A75F9", false, "extension-id",
- "extension-name");
+ "extension-name", std::vector<DownloadJobInfo>());
ASSERT_TRUE(db_->CreateDownload(download_A));
url_chain.push_back(GURL("http://example.com/d"));
@@ -767,7 +767,7 @@ TEST_F(HistoryBackendDBTest, DownloadCreateAndQuery) {
1001, 1001, DownloadState::COMPLETE, DownloadDangerType::DANGEROUS_FILE,
kTestDownloadInterruptReasonNone, std::string(), 2,
"b70f3869-7d75-4878-acb4-4caf7026d12b", false, "extension-id",
- "extension-name");
+ "extension-name", std::vector<DownloadJobInfo>());
ASSERT_TRUE(db_->CreateDownload(download_B));
EXPECT_EQ(2u, db_->CountDownloads());
@@ -806,7 +806,7 @@ TEST_F(HistoryBackendDBTest, DownloadCreateAndUpdate_VolatileFields) {
"original/mime-type", start_time, end_time, "etag1", "last_modified_1",
100, 1000, DownloadState::INTERRUPTED, DownloadDangerType::NOT_DANGEROUS,
3, "some-hash-value", 1, "FE672168-26EF-4275-A149-FEC25F6A75F9", false,
- "extension-id", "extension-name");
+ "extension-id", "extension-name", std::vector<DownloadJobInfo>());
db_->CreateDownload(download);
download.current_path =
@@ -847,6 +847,15 @@ TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) {
"05AF6C8E-E4E0-45D7-B5CE-BC99F7019918",
DownloadState::COMPLETE,
now);
+ std::vector<DownloadRow> results;
+ db_->QueryDownloads(&results);
+ ASSERT_EQ(1u, results.size());
+ // Add a download job and update the DB
+ results[0].download_job_info.push_back(DownloadJobInfo(
+ id1, 1, 500, 1000, 100, DownloadState::IN_PROGRESS,
+ kTestDownloadInterruptReasonNone));
+ ASSERT_TRUE(db_->UpdateDownload(results[0]));
+
AddDownload(id2,
"05AF6C8E-E4E0-45D7-B5CE-BC99F7019919",
DownloadState::COMPLETE,
@@ -870,12 +879,17 @@ TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) {
"Select Count(*) from downloads_url_chains"));
EXPECT_TRUE(statement1.Step());
EXPECT_EQ(3, statement1.ColumnInt(0));
+
+ sql::Statement statement2(db.GetUniqueStatement(
+ "Select Count(*) from downloads_jobs"));
+ EXPECT_TRUE(statement2.Step());
+ EXPECT_EQ(1, statement2.ColumnInt(0));
}
// Delete some rows and make sure the results are still correct.
CreateBackendAndDatabase();
+ db_->RemoveDownload(id1);
db_->RemoveDownload(id2);
- db_->RemoveDownload(id3);
DeleteBackend();
{
sql::Connection db;
@@ -889,6 +903,11 @@ TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) {
"Select Count(*) from downloads_url_chains"));
EXPECT_TRUE(statement1.Step());
EXPECT_EQ(1, statement1.ColumnInt(0));
+
+ sql::Statement statement2(db.GetUniqueStatement(
+ "Select Count(*) from downloads_jobs"));
+ EXPECT_TRUE(statement2.Step());
+ EXPECT_EQ(0, statement2.ColumnInt(0));
}
}
@@ -904,7 +923,8 @@ TEST_F(HistoryBackendDBTest, DownloadNukeRecordsMissingURLs) {
"application/octet-stream", now, now, std::string(), std::string(), 0,
512, DownloadState::COMPLETE, DownloadDangerType::NOT_DANGEROUS,
kTestDownloadInterruptReasonNone, std::string(), 1,
- "05AF6C8E-E4E0-45D7-B5CE-BC99F7019918", 0, "by_ext_id", "by_ext_name");
+ "05AF6C8E-E4E0-45D7-B5CE-BC99F7019918", 0, "by_ext_id", "by_ext_name",
+ std::vector<DownloadJobInfo>());
// Creating records without any urls should fail.
EXPECT_FALSE(db_->CreateDownload(download));
@@ -947,10 +967,19 @@ TEST_F(HistoryBackendDBTest, ConfirmDownloadInProgressCleanup) {
base::Time now(base::Time::Now());
// Put an IN_PROGRESS download in the DB.
- AddDownload(1,
+ DownloadId id = 1;
+ AddDownload(id,
"05AF6C8E-E4E0-45D7-B5CE-BC99F7019918",
DownloadState::IN_PROGRESS,
now);
+ std::vector<DownloadRow> results;
+ db_->QueryDownloads(&results);
+ ASSERT_EQ(1u, results.size());
+ // Add a download job and update the DB
+ results[0].download_job_info.push_back(DownloadJobInfo(
+ id, 1, 500, 1000, 100, DownloadState::IN_PROGRESS,
+ kTestDownloadInterruptReasonNone));
+ ASSERT_TRUE(db_->UpdateDownload(results[0]));
// Confirm that they made it into the DB unchanged.
DeleteBackend();
@@ -970,16 +999,28 @@ TEST_F(HistoryBackendDBTest, ConfirmDownloadInProgressCleanup) {
EXPECT_EQ(DownloadInterruptReasonToInt(kTestDownloadInterruptReasonNone),
statement1.ColumnInt(1));
EXPECT_FALSE(statement1.Step());
+
+ sql::Statement statement2(db.GetUniqueStatement(
+ "Select state, interrupt_reason from downloads_jobs"));
+ EXPECT_TRUE(statement2.Step());
+ EXPECT_EQ(DownloadStateToInt(DownloadState::IN_PROGRESS),
+ statement2.ColumnInt(0));
+ EXPECT_EQ(DownloadInterruptReasonToInt(kTestDownloadInterruptReasonNone),
+ statement2.ColumnInt(1));
+ EXPECT_FALSE(statement2.Step());
}
// Read in the DB through query downloads, then test that the
// right transformation was returned.
CreateBackendAndDatabase();
- std::vector<DownloadRow> results;
db_->QueryDownloads(&results);
ASSERT_EQ(1u, results.size());
EXPECT_EQ(DownloadState::INTERRUPTED, results[0].state);
EXPECT_EQ(kTestDownloadInterruptReasonCrash, results[0].interrupt_reason);
+ EXPECT_EQ(DownloadState::INTERRUPTED,
+ results[0].download_job_info[0].state);
+ EXPECT_EQ(kTestDownloadInterruptReasonCrash,
+ results[0].download_job_info[0].interrupt_reason);
// Allow the update to propagate, shut down the DB, and confirm that
// the query updated the on disk database as well.
@@ -1004,6 +1045,82 @@ TEST_F(HistoryBackendDBTest, ConfirmDownloadInProgressCleanup) {
}
}
+TEST_F(HistoryBackendDBTest, CreateAndUpdateParallelDownloadingJob) {
+ // Create the DB.
+ CreateBackendAndDatabase();
+
+ std::vector<GURL> url_chain;
+ url_chain.push_back(GURL("http://example.com/a"));
+
+ DownloadId id = 1;
+ std::vector<DownloadJobInfo> job_info;
+ int64_t received = 10;
+ job_info.push_back(DownloadJobInfo(
+ id, 1, 500, 1000, received, DownloadState::INTERRUPTED,
+ kTestDownloadInterruptReasonCrash));
+ base::Time start_time(base::Time::Now());
+ base::Time end_time(start_time + base::TimeDelta::FromHours(1));
+
+ DownloadRow download(
+ base::FilePath(FILE_PATH_LITERAL("/path/1")),
+ base::FilePath(FILE_PATH_LITERAL("/path/2")), url_chain,
+ GURL("http://example.com/referrer"), GURL("http://example.com"),
+ GURL("http://example.com/tab-url"),
+ GURL("http://example.com/tab-referrer"), "GET", "mime/type",
+ "original/mime-type", start_time, end_time, "etag1", "last_modified_1",
+ received, 1500, DownloadState::INTERRUPTED,
+ DownloadDangerType::NOT_DANGEROUS, kTestDownloadInterruptReasonCrash,
+ "hash-value1", id, "FE672168-26EF-4275-A149-FEC25F6A75F9",
+ false, "extension-id", "extension-name", job_info);
+ ASSERT_TRUE(db_->CreateDownload(download));
+ std::vector<DownloadRow> results;
+ db_->QueryDownloads(&results);
+ ASSERT_EQ(1u, results.size());
+ EXPECT_EQ(download, results[0]);
+
+ download.received_bytes += 10;
+ download.download_job_info[0].received_bytes = download.received_bytes;
+ ASSERT_TRUE(db_->UpdateDownload(download));
+ db_->QueryDownloads(&results);
+ ASSERT_EQ(1u, results.size());
+ EXPECT_EQ(download, results[0]);
+}
+
+// Test calling UpdateDownload with a new download job.
+TEST_F(HistoryBackendDBTest, UpdateDownloadWithNewJob) {
+ // Create the DB.
+ CreateBackendAndDatabase();
+
+ std::vector<GURL> url_chain;
+ url_chain.push_back(GURL("http://example.com/a"));
+
+ DownloadId id = 1;
+ base::Time start_time(base::Time::Now());
+ base::Time end_time(start_time + base::TimeDelta::FromHours(1));
+ DownloadRow download(
+ base::FilePath(FILE_PATH_LITERAL("/path/1")),
+ base::FilePath(FILE_PATH_LITERAL("/path/2")), url_chain,
+ GURL("http://example.com/referrer"), GURL("http://example.com"),
+ GURL("http://example.com/tab-url"),
+ GURL("http://example.com/tab-referrer"), "GET", "mime/type",
+ "original/mime-type", start_time, end_time, "etag1", "last_modified_1",
+ 0, 1500, DownloadState::INTERRUPTED,
+ DownloadDangerType::NOT_DANGEROUS, kTestDownloadInterruptReasonCrash,
+ "hash-value1", id, "FE672168-26EF-4275-A149-FEC25F6A75F9",
+ false, "extension-id", "extension-name", std::vector<DownloadJobInfo>());
+ ASSERT_TRUE(db_->CreateDownload(download));
+
+ // Add a new job and call UpdateDownload().
+ download.download_job_info.push_back(DownloadJobInfo(
+ id, 1, 500, 1000, 100, DownloadState::INTERRUPTED,
+ kTestDownloadInterruptReasonCrash));
+ ASSERT_TRUE(db_->UpdateDownload(download));
+ std::vector<DownloadRow> results;
+ db_->QueryDownloads(&results);
+ ASSERT_EQ(1u, results.size());
+ EXPECT_EQ(download.download_job_info[0], results[0].download_job_info[0]);
+}
+
TEST_F(HistoryBackendDBTest, MigratePresentations) {
// Create the db we want. Use 22 since segments didn't change in that time
// frame.

Powered by Google App Engine
This is Rietveld 408576698