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

Side by Side Diff: chrome/browser/history/history_unittest.cc

Issue 319703002: Add mime type information to the download database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 bool AddDownload(uint32 id, 167 bool AddDownload(uint32 id,
168 DownloadItem::DownloadState state, 168 DownloadItem::DownloadState state,
169 const Time& time) { 169 const Time& time) {
170 std::vector<GURL> url_chain; 170 std::vector<GURL> url_chain;
171 url_chain.push_back(GURL("foo-url")); 171 url_chain.push_back(GURL("foo-url"));
172 172
173 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("current-path")), 173 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("current-path")),
174 base::FilePath(FILE_PATH_LITERAL("target-path")), 174 base::FilePath(FILE_PATH_LITERAL("target-path")),
175 url_chain, 175 url_chain,
176 GURL("http://referrer.com/"), 176 GURL("http://referrer.com/"),
177 "application/vnd.oasis.opendocument.text",
178 "application/octet-stream",
177 time, 179 time,
178 time, 180 time,
179 std::string(), 181 std::string(),
180 std::string(), 182 std::string(),
181 0, 183 0,
182 512, 184 512,
183 state, 185 state,
184 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 186 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
185 content::DOWNLOAD_INTERRUPT_REASON_NONE, 187 content::DOWNLOAD_INTERRUPT_REASON_NONE,
186 id, 188 id,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 EXPECT_EQ(0, downloads[0].received_bytes); 251 EXPECT_EQ(0, downloads[0].received_bytes);
250 EXPECT_EQ(512, downloads[0].total_bytes); 252 EXPECT_EQ(512, downloads[0].total_bytes);
251 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0].state); 253 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0].state);
252 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 254 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
253 downloads[0].danger_type); 255 downloads[0].danger_type);
254 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, 256 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE,
255 downloads[0].interrupt_reason); 257 downloads[0].interrupt_reason);
256 EXPECT_FALSE(downloads[0].opened); 258 EXPECT_FALSE(downloads[0].opened);
257 EXPECT_EQ("by_ext_id", downloads[0].by_ext_id); 259 EXPECT_EQ("by_ext_id", downloads[0].by_ext_id);
258 EXPECT_EQ("by_ext_name", downloads[0].by_ext_name); 260 EXPECT_EQ("by_ext_name", downloads[0].by_ext_name);
261 EXPECT_EQ("application/vnd.oasis.opendocument.text", downloads[0].mime_type);
262 EXPECT_EQ("application/octet-stream", downloads[0].original_mime_type);
259 263
260 db_->QueryDownloads(&downloads); 264 db_->QueryDownloads(&downloads);
261 EXPECT_EQ(1U, downloads.size()); 265 EXPECT_EQ(1U, downloads.size());
262 db_->RemoveDownload(id); 266 db_->RemoveDownload(id);
263 db_->QueryDownloads(&downloads); 267 db_->QueryDownloads(&downloads);
264 EXPECT_EQ(0U, downloads.size()); 268 EXPECT_EQ(0U, downloads.size());
265 } 269 }
266 270
267 TEST_F(HistoryBackendDBTest, MigrateDownloadsState) { 271 TEST_F(HistoryBackendDBTest, MigrateDownloadsState) {
268 // Create the db we want. 272 // Create the db we want.
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 { 616 {
613 sql::Statement s(db.GetUniqueStatement( 617 sql::Statement s(db.GetUniqueStatement(
614 "SELECT etag, last_modified from downloads")); 618 "SELECT etag, last_modified from downloads"));
615 EXPECT_TRUE(s.Step()); 619 EXPECT_TRUE(s.Step());
616 EXPECT_EQ(std::string(), s.ColumnString(0)); 620 EXPECT_EQ(std::string(), s.ColumnString(0));
617 EXPECT_EQ(std::string(), s.ColumnString(1)); 621 EXPECT_EQ(std::string(), s.ColumnString(1));
618 } 622 }
619 } 623 }
620 } 624 }
621 625
626 TEST_F(HistoryBackendDBTest, MigrateDownloadMimeType) {
627 Time now(base::Time::Now());
628 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(28));
629 {
630 sql::Connection db;
631 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
632 {
633 sql::Statement s(db.GetUniqueStatement(
634 "INSERT INTO downloads (id, current_path, target_path, start_time, "
635 "received_bytes, total_bytes, state, danger_type, interrupt_reason, "
636 "end_time, opened, referrer, by_ext_id, by_ext_name, etag, "
637 "last_modified) VALUES "
638 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"));
639 s.BindInt64(0, 1);
640 s.BindString(1, "current_path");
641 s.BindString(2, "target_path");
642 s.BindInt64(3, now.ToTimeT());
643 s.BindInt64(4, 100);
644 s.BindInt64(5, 100);
645 s.BindInt(6, 1);
646 s.BindInt(7, 0);
647 s.BindInt(8, 0);
648 s.BindInt64(9, now.ToTimeT());
649 s.BindInt(10, 1);
650 s.BindString(11, "referrer");
651 s.BindString(12, "by extension ID");
652 s.BindString(13, "by extension name");
653 s.BindString(14, "etag");
654 s.BindInt64(15, now.ToTimeT());
655 ASSERT_TRUE(s.Run());
656 }
657 {
658 sql::Statement s(db.GetUniqueStatement(
659 "INSERT INTO downloads_url_chains (id, chain_index, url) VALUES "
660 "(?, ?, ?)"));
661 s.BindInt64(0, 4);
662 s.BindInt64(1, 0);
663 s.BindString(2, "url");
664 ASSERT_TRUE(s.Run());
665 }
666 }
667 // Re-open the db using the HistoryDatabase, which should migrate to the
668 // current version, creating themime_type abd original_mime_type columns.
669 CreateBackendAndDatabase();
670 DeleteBackend();
671 {
672 // Re-open the db for manual manipulation.
673 sql::Connection db;
674 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
675 // The version should have been updated.
676 int cur_version = HistoryDatabase::GetCurrentVersion();
677 ASSERT_LE(29, cur_version);
678 {
679 sql::Statement s(db.GetUniqueStatement(
680 "SELECT value FROM meta WHERE key = 'version'"));
681 EXPECT_TRUE(s.Step());
682 EXPECT_EQ(cur_version, s.ColumnInt(0));
683 }
684 {
685 sql::Statement s(db.GetUniqueStatement(
686 "SELECT mime_type, original_mime_type from downloads"));
687 EXPECT_TRUE(s.Step());
688 EXPECT_EQ(std::string(), s.ColumnString(0));
689 EXPECT_EQ(std::string(), s.ColumnString(1));
690 }
691 }
692 }
693
622 TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) { 694 TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) {
623 // Create the DB. 695 // Create the DB.
624 CreateBackendAndDatabase(); 696 CreateBackendAndDatabase();
625 697
626 base::Time now(base::Time::Now()); 698 base::Time now(base::Time::Now());
627 699
628 // Add some downloads. 700 // Add some downloads.
629 uint32 id1 = 1, id2 = 2, id3 = 3; 701 uint32 id1 = 1, id2 = 2, id3 = 3;
630 AddDownload(id1, DownloadItem::COMPLETE, now); 702 AddDownload(id1, DownloadItem::COMPLETE, now);
631 AddDownload(id2, DownloadItem::COMPLETE, now + base::TimeDelta::FromDays(2)); 703 AddDownload(id2, DownloadItem::COMPLETE, now + base::TimeDelta::FromDays(2));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 } 740 }
669 741
670 TEST_F(HistoryBackendDBTest, DownloadNukeRecordsMissingURLs) { 742 TEST_F(HistoryBackendDBTest, DownloadNukeRecordsMissingURLs) {
671 CreateBackendAndDatabase(); 743 CreateBackendAndDatabase();
672 base::Time now(base::Time::Now()); 744 base::Time now(base::Time::Now());
673 std::vector<GURL> url_chain; 745 std::vector<GURL> url_chain;
674 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("foo-path")), 746 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("foo-path")),
675 base::FilePath(FILE_PATH_LITERAL("foo-path")), 747 base::FilePath(FILE_PATH_LITERAL("foo-path")),
676 url_chain, 748 url_chain,
677 GURL(std::string()), 749 GURL(std::string()),
750 "application/octet-stream",
751 "application/octet-stream",
678 now, 752 now,
679 now, 753 now,
680 std::string(), 754 std::string(),
681 std::string(), 755 std::string(),
682 0, 756 0,
683 512, 757 512,
684 DownloadItem::COMPLETE, 758 DownloadItem::COMPLETE,
685 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 759 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
686 content::DOWNLOAD_INTERRUPT_REASON_NONE, 760 content::DOWNLOAD_INTERRUPT_REASON_NONE,
687 1, 761 1,
(...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 std::vector<PageUsageData*> results; 1916 std::vector<PageUsageData*> results;
1843 db_->QuerySegmentUsage(segment_time, 10, &results); 1917 db_->QuerySegmentUsage(segment_time, 10, &results);
1844 ASSERT_EQ(1u, results.size()); 1918 ASSERT_EQ(1u, results.size());
1845 EXPECT_EQ(url, results[0]->GetURL()); 1919 EXPECT_EQ(url, results[0]->GetURL());
1846 EXPECT_EQ(segment_id, results[0]->GetID()); 1920 EXPECT_EQ(segment_id, results[0]->GetID());
1847 EXPECT_EQ(title, results[0]->GetTitle()); 1921 EXPECT_EQ(title, results[0]->GetTitle());
1848 STLDeleteElements(&results); 1922 STLDeleteElements(&results);
1849 } 1923 }
1850 1924
1851 } // namespace history 1925 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698