| OLD | NEW |
| 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 Loading... |
| 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/octet-stream", |
| 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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 { | 612 { |
| 611 sql::Statement s(db.GetUniqueStatement( | 613 sql::Statement s(db.GetUniqueStatement( |
| 612 "SELECT etag, last_modified from downloads")); | 614 "SELECT etag, last_modified from downloads")); |
| 613 EXPECT_TRUE(s.Step()); | 615 EXPECT_TRUE(s.Step()); |
| 614 EXPECT_EQ(std::string(), s.ColumnString(0)); | 616 EXPECT_EQ(std::string(), s.ColumnString(0)); |
| 615 EXPECT_EQ(std::string(), s.ColumnString(1)); | 617 EXPECT_EQ(std::string(), s.ColumnString(1)); |
| 616 } | 618 } |
| 617 } | 619 } |
| 618 } | 620 } |
| 619 | 621 |
| 622 TEST_F(HistoryBackendDBTest, MigrateDownloadMimeType) { |
| 623 Time now(base::Time::Now()); |
| 624 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(28)); |
| 625 { |
| 626 sql::Connection db; |
| 627 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); |
| 628 { |
| 629 sql::Statement s(db.GetUniqueStatement( |
| 630 "INSERT INTO downloads (id, current_path, target_path, start_time, " |
| 631 "received_bytes, total_bytes, state, danger_type, interrupt_reason, " |
| 632 "end_time, opened, referrer, by_ext_id, by_ext_name, etag, " |
| 633 "last_modified) VALUES " |
| 634 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")); |
| 635 s.BindInt64(0, 1); |
| 636 s.BindString(1, "current_path"); |
| 637 s.BindString(2, "target_path"); |
| 638 s.BindInt64(3, now.ToTimeT()); |
| 639 s.BindInt64(4, 100); |
| 640 s.BindInt64(5, 100); |
| 641 s.BindInt(6, 1); |
| 642 s.BindInt(7, 0); |
| 643 s.BindInt(8, 0); |
| 644 s.BindInt64(9, now.ToTimeT()); |
| 645 s.BindInt(10, 1); |
| 646 s.BindString(11, "referrer"); |
| 647 s.BindString(12, "by extension ID"); |
| 648 s.BindString(13, "by extension name"); |
| 649 s.BindString(14, "etag"); |
| 650 s.BindInt64(15, now.ToTimeT()); |
| 651 ASSERT_TRUE(s.Run()); |
| 652 } |
| 653 { |
| 654 sql::Statement s(db.GetUniqueStatement( |
| 655 "INSERT INTO downloads_url_chains (id, chain_index, url) VALUES " |
| 656 "(?, ?, ?)")); |
| 657 s.BindInt64(0, 4); |
| 658 s.BindInt64(1, 0); |
| 659 s.BindString(2, "url"); |
| 660 ASSERT_TRUE(s.Run()); |
| 661 } |
| 662 } |
| 663 // Re-open the db using the HistoryDatabase, which should migrate to the |
| 664 // current version, creating the etag and last_modified columns. |
| 665 CreateBackendAndDatabase(); |
| 666 DeleteBackend(); |
| 667 { |
| 668 // Re-open the db for manual manipulation. |
| 669 sql::Connection db; |
| 670 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); |
| 671 // The version should have been updated. |
| 672 int cur_version = HistoryDatabase::GetCurrentVersion(); |
| 673 ASSERT_LE(29, cur_version); |
| 674 { |
| 675 sql::Statement s(db.GetUniqueStatement( |
| 676 "SELECT value FROM meta WHERE key = 'version'")); |
| 677 EXPECT_TRUE(s.Step()); |
| 678 EXPECT_EQ(cur_version, s.ColumnInt(0)); |
| 679 } |
| 680 { |
| 681 sql::Statement s(db.GetUniqueStatement( |
| 682 "SELECT mime_type, original_mime_type from downloads")); |
| 683 EXPECT_TRUE(s.Step()); |
| 684 EXPECT_EQ(std::string(), s.ColumnString(0)); |
| 685 EXPECT_EQ(std::string(), s.ColumnString(1)); |
| 686 } |
| 687 } |
| 688 } |
| 689 |
| 620 TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) { | 690 TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) { |
| 621 // Create the DB. | 691 // Create the DB. |
| 622 CreateBackendAndDatabase(); | 692 CreateBackendAndDatabase(); |
| 623 | 693 |
| 624 base::Time now(base::Time::Now()); | 694 base::Time now(base::Time::Now()); |
| 625 | 695 |
| 626 // Add some downloads. | 696 // Add some downloads. |
| 627 uint32 id1 = 1, id2 = 2, id3 = 3; | 697 uint32 id1 = 1, id2 = 2, id3 = 3; |
| 628 AddDownload(id1, DownloadItem::COMPLETE, now); | 698 AddDownload(id1, DownloadItem::COMPLETE, now); |
| 629 AddDownload(id2, DownloadItem::COMPLETE, now + base::TimeDelta::FromDays(2)); | 699 AddDownload(id2, DownloadItem::COMPLETE, now + base::TimeDelta::FromDays(2)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 } | 736 } |
| 667 | 737 |
| 668 TEST_F(HistoryBackendDBTest, DownloadNukeRecordsMissingURLs) { | 738 TEST_F(HistoryBackendDBTest, DownloadNukeRecordsMissingURLs) { |
| 669 CreateBackendAndDatabase(); | 739 CreateBackendAndDatabase(); |
| 670 base::Time now(base::Time::Now()); | 740 base::Time now(base::Time::Now()); |
| 671 std::vector<GURL> url_chain; | 741 std::vector<GURL> url_chain; |
| 672 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("foo-path")), | 742 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("foo-path")), |
| 673 base::FilePath(FILE_PATH_LITERAL("foo-path")), | 743 base::FilePath(FILE_PATH_LITERAL("foo-path")), |
| 674 url_chain, | 744 url_chain, |
| 675 GURL(std::string()), | 745 GURL(std::string()), |
| 746 "application/octet-stream", |
| 747 "application/octet-stream", |
| 676 now, | 748 now, |
| 677 now, | 749 now, |
| 678 std::string(), | 750 std::string(), |
| 679 std::string(), | 751 std::string(), |
| 680 0, | 752 0, |
| 681 512, | 753 512, |
| 682 DownloadItem::COMPLETE, | 754 DownloadItem::COMPLETE, |
| 683 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 755 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 684 content::DOWNLOAD_INTERRUPT_REASON_NONE, | 756 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
| 685 1, | 757 1, |
| (...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1880 std::vector<PageUsageData*> results; | 1952 std::vector<PageUsageData*> results; |
| 1881 db_->QuerySegmentUsage(segment_time, 10, &results); | 1953 db_->QuerySegmentUsage(segment_time, 10, &results); |
| 1882 ASSERT_EQ(1u, results.size()); | 1954 ASSERT_EQ(1u, results.size()); |
| 1883 EXPECT_EQ(url, results[0]->GetURL()); | 1955 EXPECT_EQ(url, results[0]->GetURL()); |
| 1884 EXPECT_EQ(segment_id, results[0]->GetID()); | 1956 EXPECT_EQ(segment_id, results[0]->GetID()); |
| 1885 EXPECT_EQ(title, results[0]->GetTitle()); | 1957 EXPECT_EQ(title, results[0]->GetTitle()); |
| 1886 STLDeleteElements(&results); | 1958 STLDeleteElements(&results); |
| 1887 } | 1959 } |
| 1888 | 1960 |
| 1889 } // namespace history | 1961 } // namespace history |
| OLD | NEW |