| 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 58074479b785a8194a77a56a93da6ce0b00e0f98..42bbe51168638c147dc755699a8e2b49d1903767 100644
|
| --- a/components/history/core/browser/history_backend_db_unittest.cc
|
| +++ b/components/history/core/browser/history_backend_db_unittest.cc
|
| @@ -74,8 +74,12 @@ TEST_F(HistoryBackendDBTest, ClearBrowsingData_Downloads) {
|
| 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(std::string("http://referrer.example.com/"),
|
| + downloads[0].referrer_url.spec());
|
| + EXPECT_EQ(std::string("http://tab-url.example.com/"),
|
| + downloads[0].tab_url.spec());
|
| + EXPECT_EQ(std::string("http://tab-referrer-url.example.com/"),
|
| + downloads[0].tab_referrer_url.spec());
|
| EXPECT_EQ(now, downloads[0].start_time);
|
| EXPECT_EQ(now, downloads[0].end_time);
|
| EXPECT_EQ(0, downloads[0].received_bytes);
|
| @@ -611,6 +615,60 @@ TEST_F(HistoryBackendDBTest, MigrateHashHttpMethodAndGenerateGuids) {
|
| }
|
| }
|
|
|
| +TEST_F(HistoryBackendDBTest, MigrateTabUrls) {
|
| + ASSERT_NO_FATAL_FAILURE(CreateDBVersion(30));
|
| + {
|
| + sql::Connection db;
|
| + ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename)));
|
| + {
|
| + sql::Statement s(db.GetUniqueStatement(
|
| + "INSERT INTO downloads ("
|
| + " id, guid, current_path, target_path, start_time, received_bytes,"
|
| + " total_bytes, state, danger_type, interrupt_reason, hash,"
|
| + " end_time, opened, referrer, http_method, by_ext_id, by_ext_name,"
|
| + " etag, last_modified, mime_type, original_mime_type)"
|
| + "VALUES("
|
| + " 1, '435A5C7A-F6B7-4DF2-8696-22E4FCBA3EB2', 'foo.txt', 'foo.txt',"
|
| + " 13104873187307670, 11, 11, 1, 0, 0, X'', 13104873187521021, 0,"
|
| + " 'http://example.com/dl/', '', '', '', '', '', 'text/plain',"
|
| + " 'text/plain')"));
|
| + ASSERT_TRUE(s.Run());
|
| + }
|
| + {
|
| + sql::Statement s(db.GetUniqueStatement(
|
| + "INSERT INTO downloads_url_chains (id, chain_index, url) VALUES "
|
| + "(4, 0, 'url')"));
|
| + ASSERT_TRUE(s.Run());
|
| + }
|
| + }
|
| +
|
| + // Re-open the db using the HistoryDatabase, which should migrate to the
|
| + // current version, creating the tab_url and tab_referrer_url columns.
|
| + CreateBackendAndDatabase();
|
| + DeleteBackend();
|
| + {
|
| + // Re-open the db for manual manipulation.
|
| + sql::Connection db;
|
| + ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename)));
|
| + // The version should have been updated.
|
| + int cur_version = HistoryDatabase::GetCurrentVersion();
|
| + ASSERT_LE(31, 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 tab_url, tab_referrer_url from downloads"));
|
| + EXPECT_TRUE(s.Step());
|
| + EXPECT_EQ(std::string(), s.ColumnString(0));
|
| + EXPECT_EQ(std::string(), s.ColumnString(1));
|
| + }
|
| + }
|
| +}
|
| +
|
| TEST_F(HistoryBackendDBTest, DownloadCreateAndQuery) {
|
| CreateBackendAndDatabase();
|
|
|
| @@ -624,54 +682,33 @@ TEST_F(HistoryBackendDBTest, DownloadCreateAndQuery) {
|
| base::Time start_time(base::Time::Now());
|
| base::Time end_time(start_time + base::TimeDelta::FromHours(1));
|
|
|
| - DownloadRow download_A(base::FilePath(FILE_PATH_LITERAL("/path/1")),
|
| - base::FilePath(FILE_PATH_LITERAL("/path/2")),
|
| - url_chain,
|
| - GURL("http://example.com/referrer"),
|
| - "GET",
|
| - "mime/type",
|
| - "original/mime-type",
|
| - start_time,
|
| - end_time,
|
| - "etag1",
|
| - "last_modified_1",
|
| - 100,
|
| - 1000,
|
| - DownloadState::INTERRUPTED,
|
| - DownloadDangerType::NOT_DANGEROUS,
|
| - kTestDownloadInterruptReasonCrash,
|
| - "hash-value1",
|
| - 1,
|
| - "FE672168-26EF-4275-A149-FEC25F6A75F9",
|
| - false,
|
| - "extension-id",
|
| - "extension-name");
|
| + DownloadRow download_A(
|
| + 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/tab-url"),
|
| + GURL("http://example.com/tab-referrer"), "GET", "mime/type",
|
| + "original/mime-type", start_time, end_time, "etag1", "last_modified_1",
|
| + 100, 1000, DownloadState::INTERRUPTED, DownloadDangerType::NOT_DANGEROUS,
|
| + kTestDownloadInterruptReasonCrash, "hash-value1", 1,
|
| + "FE672168-26EF-4275-A149-FEC25F6A75F9", false, "extension-id",
|
| + "extension-name");
|
| ASSERT_TRUE(db_->CreateDownload(download_A));
|
|
|
| url_chain.push_back(GURL("http://example.com/d"));
|
|
|
| - DownloadRow download_B(base::FilePath(FILE_PATH_LITERAL("/path/3")),
|
| - base::FilePath(FILE_PATH_LITERAL("/path/4")),
|
| - url_chain,
|
| - GURL("http://example.com/referrer2"),
|
| - "POST",
|
| - "mime/type2",
|
| - "original/mime-type2",
|
| - start_time,
|
| - end_time,
|
| - "etag2",
|
| - "last_modified_2",
|
| - 1001,
|
| - 1001,
|
| - DownloadState::COMPLETE,
|
| - DownloadDangerType::DANGEROUS_FILE,
|
| - kTestDownloadInterruptReasonNone,
|
| - std::string(),
|
| - 2,
|
| - "b70f3869-7d75-4878-acb4-4caf7026d12b",
|
| - false,
|
| - "extension-id",
|
| - "extension-name");
|
| + base::Time start_time2(start_time + base::TimeDelta::FromHours(10));
|
| + base::Time end_time2(end_time + base::TimeDelta::FromHours(10));
|
| +
|
| + DownloadRow download_B(
|
| + base::FilePath(FILE_PATH_LITERAL("/path/3")),
|
| + base::FilePath(FILE_PATH_LITERAL("/path/4")), url_chain,
|
| + GURL("http://example.com/referrer2"), GURL("http://example.com/tab-url2"),
|
| + GURL("http://example.com/tab-referrer2"), "POST", "mime/type2",
|
| + "original/mime-type2", start_time2, end_time2, "etag2", "last_modified_2",
|
| + 1001, 1001, DownloadState::COMPLETE, DownloadDangerType::DANGEROUS_FILE,
|
| + kTestDownloadInterruptReasonNone, std::string(), 2,
|
| + "b70f3869-7d75-4878-acb4-4caf7026d12b", false, "extension-id",
|
| + "extension-name");
|
| ASSERT_TRUE(db_->CreateDownload(download_B));
|
|
|
| EXPECT_EQ(2u, db_->CountDownloads());
|
| @@ -701,28 +738,15 @@ TEST_F(HistoryBackendDBTest, DownloadCreateAndUpdate_VolatileFields) {
|
| 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"),
|
| - "GET",
|
| - "mime/type",
|
| - "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");
|
| + 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/tab-url"),
|
| + GURL("http://example.com/tab-referrer"), "GET", "mime/type",
|
| + "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");
|
| db_->CreateDownload(download);
|
|
|
| download.current_path =
|
| @@ -812,28 +836,15 @@ TEST_F(HistoryBackendDBTest, DownloadNukeRecordsMissingURLs) {
|
| CreateBackendAndDatabase();
|
| base::Time now(base::Time::Now());
|
| std::vector<GURL> url_chain;
|
| - DownloadRow download(base::FilePath(FILE_PATH_LITERAL("foo-path")),
|
| - base::FilePath(FILE_PATH_LITERAL("foo-path")),
|
| - url_chain,
|
| - GURL(std::string()),
|
| - std::string(),
|
| - "application/octet-stream",
|
| - "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");
|
| + DownloadRow download(
|
| + base::FilePath(FILE_PATH_LITERAL("foo-path")),
|
| + base::FilePath(FILE_PATH_LITERAL("foo-path")), url_chain,
|
| + GURL(std::string()), GURL(std::string()), GURL(std::string()),
|
| + std::string(), "application/octet-stream", "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");
|
|
|
| // Creating records without any urls should fail.
|
| EXPECT_FALSE(db_->CreateDownload(download));
|
|
|