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

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: Fix DownloadUIController_HistoryDownload test failure 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 bool AddDownload(uint32 id, 177 bool AddDownload(uint32 id,
178 DownloadItem::DownloadState state, 178 DownloadItem::DownloadState state,
179 const Time& time) { 179 const Time& time) {
180 std::vector<GURL> url_chain; 180 std::vector<GURL> url_chain;
181 url_chain.push_back(GURL("foo-url")); 181 url_chain.push_back(GURL("foo-url"));
182 182
183 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("current-path")), 183 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("current-path")),
184 base::FilePath(FILE_PATH_LITERAL("target-path")), 184 base::FilePath(FILE_PATH_LITERAL("target-path")),
185 url_chain, 185 url_chain,
186 GURL("http://referrer.com/"), 186 GURL("http://referrer.com/"),
187 "application/vnd.oasis.opendocument.text",
188 "application/octet-stream",
187 time, 189 time,
188 time, 190 time,
189 std::string(), 191 std::string(),
190 std::string(), 192 std::string(),
191 0, 193 0,
192 512, 194 512,
193 state, 195 state,
194 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 196 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
195 content::DOWNLOAD_INTERRUPT_REASON_NONE, 197 content::DOWNLOAD_INTERRUPT_REASON_NONE,
196 id, 198 id,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 EXPECT_EQ(0, downloads[0].received_bytes); 261 EXPECT_EQ(0, downloads[0].received_bytes);
260 EXPECT_EQ(512, downloads[0].total_bytes); 262 EXPECT_EQ(512, downloads[0].total_bytes);
261 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0].state); 263 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0].state);
262 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 264 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
263 downloads[0].danger_type); 265 downloads[0].danger_type);
264 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, 266 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE,
265 downloads[0].interrupt_reason); 267 downloads[0].interrupt_reason);
266 EXPECT_FALSE(downloads[0].opened); 268 EXPECT_FALSE(downloads[0].opened);
267 EXPECT_EQ("by_ext_id", downloads[0].by_ext_id); 269 EXPECT_EQ("by_ext_id", downloads[0].by_ext_id);
268 EXPECT_EQ("by_ext_name", downloads[0].by_ext_name); 270 EXPECT_EQ("by_ext_name", downloads[0].by_ext_name);
271 EXPECT_EQ("application/vnd.oasis.opendocument.text", downloads[0].mime_type);
272 EXPECT_EQ("application/octet-stream", downloads[0].original_mime_type);
269 273
270 db_->QueryDownloads(&downloads); 274 db_->QueryDownloads(&downloads);
271 EXPECT_EQ(1U, downloads.size()); 275 EXPECT_EQ(1U, downloads.size());
272 db_->RemoveDownload(id); 276 db_->RemoveDownload(id);
273 db_->QueryDownloads(&downloads); 277 db_->QueryDownloads(&downloads);
274 EXPECT_EQ(0U, downloads.size()); 278 EXPECT_EQ(0U, downloads.size());
275 } 279 }
276 280
277 TEST_F(HistoryBackendDBTest, MigrateDownloadsState) { 281 TEST_F(HistoryBackendDBTest, MigrateDownloadsState) {
278 // Create the db we want. 282 // Create the db we want.
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 642
639 CreateBackendAndDatabase(); 643 CreateBackendAndDatabase();
640 DeleteBackend(); 644 DeleteBackend();
641 645
642 // We do not retain expired history entries in an archived database as of M37. 646 // We do not retain expired history entries in an archived database as of M37.
643 // Verify that any legacy archived database is deleted on start-up. 647 // Verify that any legacy archived database is deleted on start-up.
644 ASSERT_FALSE(base::PathExists( 648 ASSERT_FALSE(base::PathExists(
645 history_dir_.Append(chrome::kArchivedHistoryFilename))); 649 history_dir_.Append(chrome::kArchivedHistoryFilename)));
646 } 650 }
647 651
652 TEST_F(HistoryBackendDBTest, MigrateDownloadMimeType) {
653 Time now(base::Time::Now());
654 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(28));
655 {
656 sql::Connection db;
657 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
658 {
659 sql::Statement s(db.GetUniqueStatement(
660 "INSERT INTO downloads (id, current_path, target_path, start_time, "
661 "received_bytes, total_bytes, state, danger_type, interrupt_reason, "
662 "end_time, opened, referrer, by_ext_id, by_ext_name, etag, "
663 "last_modified) VALUES "
664 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"));
665 s.BindInt64(0, 1);
666 s.BindString(1, "current_path");
667 s.BindString(2, "target_path");
668 s.BindInt64(3, now.ToTimeT());
669 s.BindInt64(4, 100);
670 s.BindInt64(5, 100);
671 s.BindInt(6, 1);
672 s.BindInt(7, 0);
673 s.BindInt(8, 0);
674 s.BindInt64(9, now.ToTimeT());
675 s.BindInt(10, 1);
676 s.BindString(11, "referrer");
677 s.BindString(12, "by extension ID");
678 s.BindString(13, "by extension name");
679 s.BindString(14, "etag");
680 s.BindInt64(15, now.ToTimeT());
681 ASSERT_TRUE(s.Run());
682 }
683 {
684 sql::Statement s(db.GetUniqueStatement(
685 "INSERT INTO downloads_url_chains (id, chain_index, url) VALUES "
686 "(?, ?, ?)"));
687 s.BindInt64(0, 4);
688 s.BindInt64(1, 0);
689 s.BindString(2, "url");
690 ASSERT_TRUE(s.Run());
691 }
692 }
693 // Re-open the db using the HistoryDatabase, which should migrate to the
694 // current version, creating themime_type abd original_mime_type columns.
695 CreateBackendAndDatabase();
696 DeleteBackend();
697 {
698 // Re-open the db for manual manipulation.
699 sql::Connection db;
700 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
701 // The version should have been updated.
702 int cur_version = HistoryDatabase::GetCurrentVersion();
703 ASSERT_LE(29, cur_version);
704 {
705 sql::Statement s(db.GetUniqueStatement(
706 "SELECT value FROM meta WHERE key = 'version'"));
707 EXPECT_TRUE(s.Step());
708 EXPECT_EQ(cur_version, s.ColumnInt(0));
709 }
710 {
711 sql::Statement s(db.GetUniqueStatement(
712 "SELECT mime_type, original_mime_type from downloads"));
713 EXPECT_TRUE(s.Step());
714 EXPECT_EQ(std::string(), s.ColumnString(0));
715 EXPECT_EQ(std::string(), s.ColumnString(1));
716 }
717 }
718 }
719
648 TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) { 720 TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) {
649 // Create the DB. 721 // Create the DB.
650 CreateBackendAndDatabase(); 722 CreateBackendAndDatabase();
651 723
652 base::Time now(base::Time::Now()); 724 base::Time now(base::Time::Now());
653 725
654 // Add some downloads. 726 // Add some downloads.
655 uint32 id1 = 1, id2 = 2, id3 = 3; 727 uint32 id1 = 1, id2 = 2, id3 = 3;
656 AddDownload(id1, DownloadItem::COMPLETE, now); 728 AddDownload(id1, DownloadItem::COMPLETE, now);
657 AddDownload(id2, DownloadItem::COMPLETE, now + base::TimeDelta::FromDays(2)); 729 AddDownload(id2, DownloadItem::COMPLETE, now + base::TimeDelta::FromDays(2));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 } 766 }
695 767
696 TEST_F(HistoryBackendDBTest, DownloadNukeRecordsMissingURLs) { 768 TEST_F(HistoryBackendDBTest, DownloadNukeRecordsMissingURLs) {
697 CreateBackendAndDatabase(); 769 CreateBackendAndDatabase();
698 base::Time now(base::Time::Now()); 770 base::Time now(base::Time::Now());
699 std::vector<GURL> url_chain; 771 std::vector<GURL> url_chain;
700 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("foo-path")), 772 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("foo-path")),
701 base::FilePath(FILE_PATH_LITERAL("foo-path")), 773 base::FilePath(FILE_PATH_LITERAL("foo-path")),
702 url_chain, 774 url_chain,
703 GURL(std::string()), 775 GURL(std::string()),
776 "application/octet-stream",
777 "application/octet-stream",
704 now, 778 now,
705 now, 779 now,
706 std::string(), 780 std::string(),
707 std::string(), 781 std::string(),
708 0, 782 0,
709 512, 783 512,
710 DownloadItem::COMPLETE, 784 DownloadItem::COMPLETE,
711 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 785 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
712 content::DOWNLOAD_INTERRUPT_REASON_NONE, 786 content::DOWNLOAD_INTERRUPT_REASON_NONE,
713 1, 787 1,
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 std::vector<PageUsageData*> results; 1934 std::vector<PageUsageData*> results;
1861 db_->QuerySegmentUsage(segment_time, 10, &results); 1935 db_->QuerySegmentUsage(segment_time, 10, &results);
1862 ASSERT_EQ(1u, results.size()); 1936 ASSERT_EQ(1u, results.size());
1863 EXPECT_EQ(url, results[0]->GetURL()); 1937 EXPECT_EQ(url, results[0]->GetURL());
1864 EXPECT_EQ(segment_id, results[0]->GetID()); 1938 EXPECT_EQ(segment_id, results[0]->GetID());
1865 EXPECT_EQ(title, results[0]->GetTitle()); 1939 EXPECT_EQ(title, results[0]->GetTitle());
1866 STLDeleteElements(&results); 1940 STLDeleteElements(&results);
1867 } 1941 }
1868 1942
1869 } // namespace history 1943 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_database.cc ('k') | chrome/browser/ui/webui/downloads_dom_handler_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698