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 // Unit tests for the SafeBrowsing storage system. | 5 // Unit tests for the SafeBrowsing storage system. |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 { | 1119 { |
1120 // The following code will cause DCHECKs, so suppress the crashes. | 1120 // The following code will cause DCHECKs, so suppress the crashes. |
1121 ScopedLogMessageIgnorer ignorer; | 1121 ScopedLogMessageIgnorer ignorer; |
1122 | 1122 |
1123 // Start an update. The insert will fail due to corruption. | 1123 // Start an update. The insert will fail due to corruption. |
1124 EXPECT_TRUE(database_->UpdateStarted(&lists)); | 1124 EXPECT_TRUE(database_->UpdateStarted(&lists)); |
1125 database_->InsertChunks(safe_browsing_util::kMalwareList, chunks); | 1125 database_->InsertChunks(safe_browsing_util::kMalwareList, chunks); |
1126 database_->UpdateFinished(true); | 1126 database_->UpdateFinished(true); |
1127 | 1127 |
1128 // Database file still exists until the corruption handler has run. | 1128 // Database file still exists until the corruption handler has run. |
1129 EXPECT_TRUE(file_util::PathExists(database_filename_)); | 1129 EXPECT_TRUE(base::PathExists(database_filename_)); |
1130 | 1130 |
1131 // Flush through the corruption-handler task. | 1131 // Flush through the corruption-handler task. |
1132 VLOG(1) << "Expect failed check on: SafeBrowsing database reset"; | 1132 VLOG(1) << "Expect failed check on: SafeBrowsing database reset"; |
1133 base::MessageLoop::current()->RunUntilIdle(); | 1133 base::MessageLoop::current()->RunUntilIdle(); |
1134 } | 1134 } |
1135 | 1135 |
1136 // Database file should not exist. | 1136 // Database file should not exist. |
1137 EXPECT_FALSE(file_util::PathExists(database_filename_)); | 1137 EXPECT_FALSE(base::PathExists(database_filename_)); |
1138 | 1138 |
1139 // Run the update again successfully. | 1139 // Run the update again successfully. |
1140 EXPECT_TRUE(database_->UpdateStarted(&lists)); | 1140 EXPECT_TRUE(database_->UpdateStarted(&lists)); |
1141 database_->InsertChunks(safe_browsing_util::kMalwareList, chunks); | 1141 database_->InsertChunks(safe_browsing_util::kMalwareList, chunks); |
1142 database_->UpdateFinished(true); | 1142 database_->UpdateFinished(true); |
1143 EXPECT_TRUE(file_util::PathExists(database_filename_)); | 1143 EXPECT_TRUE(base::PathExists(database_filename_)); |
1144 | 1144 |
1145 database_.reset(); | 1145 database_.reset(); |
1146 } | 1146 } |
1147 | 1147 |
1148 // Checks database reading and writing. | 1148 // Checks database reading and writing. |
1149 TEST_F(SafeBrowsingDatabaseTest, ContainsDownloadUrl) { | 1149 TEST_F(SafeBrowsingDatabaseTest, ContainsDownloadUrl) { |
1150 database_.reset(); | 1150 database_.reset(); |
1151 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); | 1151 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); |
1152 SafeBrowsingStoreFile* browse_store = new SafeBrowsingStoreFile(); | 1152 SafeBrowsingStoreFile* browse_store = new SafeBrowsingStoreFile(); |
1153 SafeBrowsingStoreFile* download_store = new SafeBrowsingStoreFile(); | 1153 SafeBrowsingStoreFile* download_store = new SafeBrowsingStoreFile(); |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1640 &matching_list, &prefix_hits, &full_hashes, now)); | 1640 &matching_list, &prefix_hits, &full_hashes, now)); |
1641 EXPECT_FALSE(database_->ContainsBrowseUrl( | 1641 EXPECT_FALSE(database_->ContainsBrowseUrl( |
1642 GURL("http://www.good.com/goodware.html"), | 1642 GURL("http://www.good.com/goodware.html"), |
1643 &matching_list, &prefix_hits, &full_hashes, now)); | 1643 &matching_list, &prefix_hits, &full_hashes, now)); |
1644 | 1644 |
1645 base::FilePath filter_file = database_->PrefixSetForFilename( | 1645 base::FilePath filter_file = database_->PrefixSetForFilename( |
1646 database_->BrowseDBFilename(database_filename_)); | 1646 database_->BrowseDBFilename(database_filename_)); |
1647 | 1647 |
1648 // After re-creating the database, it should have a filter read from | 1648 // After re-creating the database, it should have a filter read from |
1649 // a file, so it should find the same results. | 1649 // a file, so it should find the same results. |
1650 ASSERT_TRUE(file_util::PathExists(filter_file)); | 1650 ASSERT_TRUE(base::PathExists(filter_file)); |
1651 database_.reset(new SafeBrowsingDatabaseNew); | 1651 database_.reset(new SafeBrowsingDatabaseNew); |
1652 database_->Init(database_filename_); | 1652 database_->Init(database_filename_); |
1653 EXPECT_TRUE(database_->ContainsBrowseUrl( | 1653 EXPECT_TRUE(database_->ContainsBrowseUrl( |
1654 GURL("http://www.evil.com/malware.html"), | 1654 GURL("http://www.evil.com/malware.html"), |
1655 &matching_list, &prefix_hits, &full_hashes, now)); | 1655 &matching_list, &prefix_hits, &full_hashes, now)); |
1656 EXPECT_FALSE(database_->ContainsBrowseUrl( | 1656 EXPECT_FALSE(database_->ContainsBrowseUrl( |
1657 GURL("http://www.good.com/goodware.html"), | 1657 GURL("http://www.good.com/goodware.html"), |
1658 &matching_list, &prefix_hits, &full_hashes, now)); | 1658 &matching_list, &prefix_hits, &full_hashes, now)); |
1659 | 1659 |
1660 // If there is no filter file, the database cannot find malware urls. | 1660 // If there is no filter file, the database cannot find malware urls. |
1661 base::Delete(filter_file, false); | 1661 base::Delete(filter_file, false); |
1662 ASSERT_FALSE(file_util::PathExists(filter_file)); | 1662 ASSERT_FALSE(base::PathExists(filter_file)); |
1663 database_.reset(new SafeBrowsingDatabaseNew); | 1663 database_.reset(new SafeBrowsingDatabaseNew); |
1664 database_->Init(database_filename_); | 1664 database_->Init(database_filename_); |
1665 EXPECT_FALSE(database_->ContainsBrowseUrl( | 1665 EXPECT_FALSE(database_->ContainsBrowseUrl( |
1666 GURL("http://www.evil.com/malware.html"), | 1666 GURL("http://www.evil.com/malware.html"), |
1667 &matching_list, &prefix_hits, &full_hashes, now)); | 1667 &matching_list, &prefix_hits, &full_hashes, now)); |
1668 EXPECT_FALSE(database_->ContainsBrowseUrl( | 1668 EXPECT_FALSE(database_->ContainsBrowseUrl( |
1669 GURL("http://www.good.com/goodware.html"), | 1669 GURL("http://www.good.com/goodware.html"), |
1670 &matching_list, &prefix_hits, &full_hashes, now)); | 1670 &matching_list, &prefix_hits, &full_hashes, now)); |
1671 } | 1671 } |
OLD | NEW |