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

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

Issue 17397003: Add the referrer url to the downloads table in the History database. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r207869 Created 7 years, 6 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_database.cc ('k') | no next file » | 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 d9e8949dcee3557a7014462113a777faa16b7ee9..822ebddb5628a32ef4a2bc4ca31a4323fe4c9c79 100644
--- a/chrome/browser/history/history_unittest.cc
+++ b/chrome/browser/history/history_unittest.cc
@@ -165,10 +165,10 @@ class HistoryBackendDBTest : public HistoryUnitTestBase {
std::vector<GURL> url_chain;
url_chain.push_back(GURL("foo-url"));
- DownloadRow download(base::FilePath(FILE_PATH_LITERAL("foo-path")),
- base::FilePath(FILE_PATH_LITERAL("foo-path")),
+ DownloadRow download(base::FilePath(FILE_PATH_LITERAL("current-path")),
+ base::FilePath(FILE_PATH_LITERAL("target-path")),
url_chain,
- GURL(std::string()),
+ GURL("http://referrer.com/"),
time,
time,
0,
@@ -177,7 +177,7 @@ class HistoryBackendDBTest : public HistoryUnitTestBase {
content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
content::DOWNLOAD_INTERRUPT_REASON_NONE,
0,
- 0);
+ false);
return db_->CreateDownload(download);
}
@@ -221,12 +221,33 @@ TEST_F(HistoryBackendDBTest, ClearBrowsingData_Downloads) {
db_->QueryDownloads(&downloads);
EXPECT_EQ(0U, downloads.size());
- // Add a download, test that it was added, remove it, test that it was
- // removed.
+ // Add a download, test that it was added correctly, remove it, test that it
+ // was removed.
DownloadID handle;
- EXPECT_NE(0, handle = AddDownload(DownloadItem::COMPLETE, Time()));
+ Time now = Time();
+ EXPECT_NE(0, handle = AddDownload(DownloadItem::COMPLETE, now));
db_->QueryDownloads(&downloads);
EXPECT_EQ(1U, downloads.size());
+
+ EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("current-path")),
+ downloads[0].current_path);
+ EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("target-path")),
+ downloads[0].target_path);
+ EXPECT_EQ(1UL, downloads[0].url_chain.size());
+ EXPECT_EQ(GURL("foo-url"), downloads[0].url_chain[0]);
+ EXPECT_EQ(std::string("http://referrer.com/"),
+ std::string(downloads[0].referrer_url.spec()));
+ EXPECT_EQ(now, downloads[0].start_time);
+ EXPECT_EQ(now, downloads[0].end_time);
+ EXPECT_EQ(0, downloads[0].received_bytes);
+ EXPECT_EQ(512, downloads[0].total_bytes);
+ EXPECT_EQ(DownloadItem::COMPLETE, downloads[0].state);
+ EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
+ downloads[0].danger_type);
+ EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE,
+ downloads[0].interrupt_reason);
+ EXPECT_FALSE(downloads[0].opened);
+
db_->RemoveDownload(handle);
db_->QueryDownloads(&downloads);
EXPECT_EQ(0U, downloads.size());
@@ -411,6 +432,54 @@ TEST_F(HistoryBackendDBTest, MigrateDownloadsReasonPathsAndDangerType) {
}
}
+TEST_F(HistoryBackendDBTest, MigrateReferrer) {
+ Time now(base::Time::Now());
+ ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22));
+ {
+ sql::Connection db;
+ ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
+ sql::Statement s(db.GetUniqueStatement(
+ "INSERT INTO downloads (id, full_path, url, start_time, "
+ "received_bytes, total_bytes, state, end_time, opened) VALUES "
+ "(?, ?, ?, ?, ?, ?, ?, ?, ?)"));
+ int64 db_handle = 0;
+ s.BindInt64(0, ++db_handle);
+ s.BindString(1, "full_path");
+ s.BindString(2, "http://whatever.com/index.html");
+ s.BindInt64(3, now.ToTimeT());
+ s.BindInt64(4, 100);
+ s.BindInt64(5, 100);
+ s.BindInt(6, 1);
+ s.BindInt64(7, now.ToTimeT());
+ s.BindInt(8, 1);
+ ASSERT_TRUE(s.Run());
+ }
+ // Re-open the db using the HistoryDatabase, which should migrate to version
+ // 26, creating the referrer column.
+ CreateBackendAndDatabase();
+ DeleteBackend();
+ {
+ // Re-open the db for manual manipulation.
+ sql::Connection db;
+ ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
+ // The version should have been updated.
+ int cur_version = HistoryDatabase::GetCurrentVersion();
+ ASSERT_LE(26, cur_version);
+ {
+ sql::Statement s(db.GetUniqueStatement(
+ "SELECT value FROM meta WHERE key = 'version'"));
+ EXPECT_TRUE(s.Step());
+ EXPECT_EQ(cur_version, s.ColumnInt(0));
+ }
+ {
+ sql::Statement s(db.GetUniqueStatement(
+ "SELECT referrer from downloads"));
+ EXPECT_TRUE(s.Step());
+ EXPECT_EQ(std::string(), s.ColumnString(0));
+ }
+ }
+}
+
TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) {
// Create the DB.
CreateBackendAndDatabase();
« no previous file with comments | « chrome/browser/history/history_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698