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

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

Issue 744183002: More explicit thread checking in SafeBrowsingDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@a3_deadcode
Patch Set: Created 6 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 // Unit tests for the SafeBrowsing storage system. 5 // Unit tests for the SafeBrowsing storage system.
6 6
7 #include "chrome/browser/safe_browsing/safe_browsing_database.h" 7 #include "chrome/browser/safe_browsing/safe_browsing_database.h"
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 void SubDelChunk(const std::string& list, int chunk_id) { 324 void SubDelChunk(const std::string& list, int chunk_id) {
325 DelChunk(list, chunk_id, true); 325 DelChunk(list, chunk_id, true);
326 } 326 }
327 327
328 // Utility function for setting up the database for the caching test. 328 // Utility function for setting up the database for the caching test.
329 void PopulateDatabaseForCacheTest(); 329 void PopulateDatabaseForCacheTest();
330 330
331 scoped_ptr<SafeBrowsingDatabaseNew> database_; 331 scoped_ptr<SafeBrowsingDatabaseNew> database_;
332 base::FilePath database_filename_; 332 base::FilePath database_filename_;
333 base::ScopedTempDir temp_dir_; 333 base::ScopedTempDir temp_dir_;
334
335 // We expect most checks made on |database_| to be made from the IO thread.
336 // Use this ThreadBundle to fake the IO thread in the main message loop in
337 // these tests.
338 content::TestBrowserThreadBundle thread_bundle_;
334 }; 339 };
335 340
336 // Tests retrieving list name information. 341 // Tests retrieving list name information.
337 TEST_F(SafeBrowsingDatabaseTest, ListNameForBrowse) { 342 TEST_F(SafeBrowsingDatabaseTest, ListNameForBrowse) {
338 std::vector<SBListChunkRanges> lists; 343 std::vector<SBListChunkRanges> lists;
339 ScopedVector<SBChunkData> chunks; 344 ScopedVector<SBChunkData> chunks;
340 345
341 chunks.push_back(AddChunkPrefixValue(1, "www.evil.com/malware.html")); 346 chunks.push_back(AddChunkPrefixValue(1, "www.evil.com/malware.html"));
342 chunks.push_back(AddChunkPrefixValue(2, "www.foo.com/malware.html")); 347 chunks.push_back(AddChunkPrefixValue(2, "www.foo.com/malware.html"));
343 chunks.push_back(AddChunkPrefixValue(3, "www.whatever.com/malware.html")); 348 chunks.push_back(AddChunkPrefixValue(3, "www.whatever.com/malware.html"));
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 urls.push_back(GURL(std::string("https://") + kEvil1Url2)); 1237 urls.push_back(GURL(std::string("https://") + kEvil1Url2));
1233 EXPECT_TRUE(database_->ContainsDownloadUrl(urls, &prefix_hits)); 1238 EXPECT_TRUE(database_->ContainsDownloadUrl(urls, &prefix_hits));
1234 ASSERT_EQ(2U, prefix_hits.size()); 1239 ASSERT_EQ(2U, prefix_hits.size());
1235 EXPECT_EQ(SBPrefixForString(kEvil1Url1), prefix_hits[0]); 1240 EXPECT_EQ(SBPrefixForString(kEvil1Url1), prefix_hits[0]);
1236 EXPECT_EQ(SBPrefixForString(kEvil1Url2), prefix_hits[1]); 1241 EXPECT_EQ(SBPrefixForString(kEvil1Url2), prefix_hits[1]);
1237 database_.reset(); 1242 database_.reset();
1238 } 1243 }
1239 1244
1240 // Checks that the whitelists are handled properly. 1245 // Checks that the whitelists are handled properly.
1241 TEST_F(SafeBrowsingDatabaseTest, Whitelists) { 1246 TEST_F(SafeBrowsingDatabaseTest, Whitelists) {
1242 database_.reset();
1243
1244 // We expect all calls to ContainsCsdWhitelistedUrl in particular to be made
1245 // from the IO thread. In general the whitelist lookups are thread-safe.
1246 content::TestBrowserThreadBundle thread_bundle_;
1247
1248 // If the whitelist is disabled everything should match the whitelist. 1247 // If the whitelist is disabled everything should match the whitelist.
1249 database_.reset(new SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile(), 1248 database_.reset(new SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile(),
1250 NULL, NULL, NULL, NULL, NULL, 1249 NULL, NULL, NULL, NULL, NULL,
1251 NULL, NULL)); 1250 NULL, NULL));
1252 database_->Init(database_filename_); 1251 database_->Init(database_filename_);
1253 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1252 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1254 GURL(std::string("http://www.phishing.com/")))); 1253 GURL(std::string("http://www.phishing.com/"))));
1255 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1254 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1256 GURL(std::string("http://www.phishing.com/")))); 1255 GURL(std::string("http://www.phishing.com/"))));
1257 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString("asdf")); 1256 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString("asdf"));
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
2137 GURL(std::string("http://") + kExampleCollision), 2136 GURL(std::string("http://") + kExampleCollision),
2138 &prefix_hits, &cache_hits)); 2137 &prefix_hits, &cache_hits));
2139 ASSERT_EQ(1U, prefix_hits.size()); 2138 ASSERT_EQ(1U, prefix_hits.size());
2140 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]); 2139 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]);
2141 EXPECT_TRUE(cache_hits.empty()); 2140 EXPECT_TRUE(cache_hits.empty());
2142 2141
2143 // This prefix collides, but no full hash match. 2142 // This prefix collides, but no full hash match.
2144 EXPECT_FALSE(database_->ContainsBrowseUrl( 2143 EXPECT_FALSE(database_->ContainsBrowseUrl(
2145 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits)); 2144 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits));
2146 } 2145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698