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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_database_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 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 | Annotate | Revision Log
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 // 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 EXPECT_TRUE(lists[0].name == safe_browsing_util::kMalwareList); 356 EXPECT_TRUE(lists[0].name == safe_browsing_util::kMalwareList);
357 EXPECT_EQ(lists[0].adds, "1-3"); 357 EXPECT_EQ(lists[0].adds, "1-3");
358 EXPECT_EQ(lists[0].subs, "7"); 358 EXPECT_EQ(lists[0].subs, "7");
359 EXPECT_TRUE(lists[1].name == safe_browsing_util::kPhishingList); 359 EXPECT_TRUE(lists[1].name == safe_browsing_util::kPhishingList);
360 EXPECT_EQ(lists[1].adds, "47"); 360 EXPECT_EQ(lists[1].adds, "47");
361 EXPECT_EQ(lists[1].subs, "200-201"); 361 EXPECT_EQ(lists[1].subs, "200-201");
362 } 362 }
363 363
364 TEST_F(SafeBrowsingDatabaseTest, ListNameForBrowseAndDownload) { 364 TEST_F(SafeBrowsingDatabaseTest, ListNameForBrowseAndDownload) {
365 database_.reset(); 365 database_.reset();
366 MessageLoop loop(MessageLoop::TYPE_DEFAULT); 366 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT);
367 SafeBrowsingStoreFile* browse_store = new SafeBrowsingStoreFile(); 367 SafeBrowsingStoreFile* browse_store = new SafeBrowsingStoreFile();
368 SafeBrowsingStoreFile* download_store = new SafeBrowsingStoreFile(); 368 SafeBrowsingStoreFile* download_store = new SafeBrowsingStoreFile();
369 SafeBrowsingStoreFile* csd_whitelist_store = new SafeBrowsingStoreFile(); 369 SafeBrowsingStoreFile* csd_whitelist_store = new SafeBrowsingStoreFile();
370 SafeBrowsingStoreFile* download_whitelist_store = new SafeBrowsingStoreFile(); 370 SafeBrowsingStoreFile* download_whitelist_store = new SafeBrowsingStoreFile();
371 SafeBrowsingStoreFile* extension_blacklist_store = 371 SafeBrowsingStoreFile* extension_blacklist_store =
372 new SafeBrowsingStoreFile(); 372 new SafeBrowsingStoreFile();
373 database_.reset(new SafeBrowsingDatabaseNew(browse_store, 373 database_.reset(new SafeBrowsingDatabaseNew(browse_store,
374 download_store, 374 download_store,
375 csd_whitelist_store, 375 csd_whitelist_store,
376 download_whitelist_store, 376 download_whitelist_store,
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 1072
1073 // Test that corrupt databases are appropriately handled, even if the 1073 // Test that corrupt databases are appropriately handled, even if the
1074 // corruption is detected in the midst of the update. 1074 // corruption is detected in the midst of the update.
1075 // TODO(shess): Disabled until ScopedLogMessageIgnorer resolved. 1075 // TODO(shess): Disabled until ScopedLogMessageIgnorer resolved.
1076 // http://crbug.com/56448 1076 // http://crbug.com/56448
1077 TEST_F(SafeBrowsingDatabaseTest, DISABLED_FileCorruptionHandling) { 1077 TEST_F(SafeBrowsingDatabaseTest, DISABLED_FileCorruptionHandling) {
1078 // Re-create the database in a captive message loop so that we can 1078 // Re-create the database in a captive message loop so that we can
1079 // influence task-posting. Database specifically needs to the 1079 // influence task-posting. Database specifically needs to the
1080 // file-backed. 1080 // file-backed.
1081 database_.reset(); 1081 database_.reset();
1082 MessageLoop loop(MessageLoop::TYPE_DEFAULT); 1082 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT);
1083 SafeBrowsingStoreFile* store = new SafeBrowsingStoreFile(); 1083 SafeBrowsingStoreFile* store = new SafeBrowsingStoreFile();
1084 database_.reset(new SafeBrowsingDatabaseNew(store, NULL, NULL, NULL, NULL, 1084 database_.reset(new SafeBrowsingDatabaseNew(store, NULL, NULL, NULL, NULL,
1085 NULL)); 1085 NULL));
1086 database_->Init(database_filename_); 1086 database_->Init(database_filename_);
1087 1087
1088 // This will cause an empty database to be created. 1088 // This will cause an empty database to be created.
1089 std::vector<SBListChunkRanges> lists; 1089 std::vector<SBListChunkRanges> lists;
1090 EXPECT_TRUE(database_->UpdateStarted(&lists)); 1090 EXPECT_TRUE(database_->UpdateStarted(&lists));
1091 database_->UpdateFinished(true); 1091 database_->UpdateFinished(true);
1092 1092
(...skipping 30 matching lines...) Expand all
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(file_util::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 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(file_util::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(file_util::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 MessageLoop loop(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();
1154 SafeBrowsingStoreFile* csd_whitelist_store = new SafeBrowsingStoreFile(); 1154 SafeBrowsingStoreFile* csd_whitelist_store = new SafeBrowsingStoreFile();
1155 database_.reset(new SafeBrowsingDatabaseNew(browse_store, 1155 database_.reset(new SafeBrowsingDatabaseNew(browse_store,
1156 download_store, 1156 download_store,
1157 csd_whitelist_store, 1157 csd_whitelist_store,
1158 NULL, 1158 NULL,
1159 NULL, 1159 NULL,
1160 NULL)); 1160 NULL));
1161 database_->Init(database_filename_); 1161 database_->Init(database_filename_);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 EXPECT_TRUE(database_->ContainsDownloadUrl(urls, &prefix_hits)); 1245 EXPECT_TRUE(database_->ContainsDownloadUrl(urls, &prefix_hits));
1246 ASSERT_EQ(prefix_hits.size(), 2U); 1246 ASSERT_EQ(prefix_hits.size(), 2U);
1247 EXPECT_EQ(prefix_hits[0], Sha256Prefix(kEvil1Url1)); 1247 EXPECT_EQ(prefix_hits[0], Sha256Prefix(kEvil1Url1));
1248 EXPECT_EQ(prefix_hits[1], Sha256Prefix(kEvil1Url2)); 1248 EXPECT_EQ(prefix_hits[1], Sha256Prefix(kEvil1Url2));
1249 database_.reset(); 1249 database_.reset();
1250 } 1250 }
1251 1251
1252 // Checks that the whitelists are handled properly. 1252 // Checks that the whitelists are handled properly.
1253 TEST_F(SafeBrowsingDatabaseTest, Whitelists) { 1253 TEST_F(SafeBrowsingDatabaseTest, Whitelists) {
1254 database_.reset(); 1254 database_.reset();
1255 MessageLoop loop(MessageLoop::TYPE_DEFAULT); 1255 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT);
1256 // We expect all calls to ContainsCsdWhitelistedUrl in particular to be made 1256 // We expect all calls to ContainsCsdWhitelistedUrl in particular to be made
1257 // from the IO thread. In general the whitelist lookups are thread-safe. 1257 // from the IO thread. In general the whitelist lookups are thread-safe.
1258 content::TestBrowserThread io_thread(BrowserThread::IO, &loop); 1258 content::TestBrowserThread io_thread(BrowserThread::IO, &loop);
1259 1259
1260 // If the whitelist is disabled everything should match the whitelist. 1260 // If the whitelist is disabled everything should match the whitelist.
1261 database_.reset(new SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile(), 1261 database_.reset(new SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile(),
1262 NULL, NULL, NULL, NULL, NULL)); 1262 NULL, NULL, NULL, NULL, NULL));
1263 database_->Init(database_filename_); 1263 database_->Init(database_filename_);
1264 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1264 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1265 GURL(std::string("http://www.phishing.com/")))); 1265 GURL(std::string("http://www.phishing.com/"))));
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 ASSERT_FALSE(file_util::PathExists(filter_file)); 1662 ASSERT_FALSE(file_util::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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698