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

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

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

Powered by Google App Engine
This is Rietveld 408576698