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

Unified Diff: chrome/browser/safe_browsing/safe_browsing_database_unittest.cc

Issue 220493003: Safebrowsing: change gethash caching to match api 2.3 rules, fix some corner cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changes for review #2 Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
index 70d2b019dceb9a39589e4ed38430fcb456eada17..0c1e302bec68741f77f9186ec2accaa4814f1d39 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
@@ -4,13 +4,14 @@
//
// Unit tests for the SafeBrowsing storage system.
+#include "chrome/browser/safe_browsing/safe_browsing_database.h"
+
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/sha1.h"
#include "base/time/time.h"
-#include "chrome/browser/safe_browsing/safe_browsing_database.h"
#include "chrome/browser/safe_browsing/safe_browsing_store_file.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "crypto/sha2.h"
@@ -29,6 +30,15 @@ SBPrefix SBPrefixForString(const std::string& str) {
return SBFullHashForString(str).prefix;
}
+SBFullHash SBFullHashForPrefixAndSuffix(SBPrefix prefix, std::string suffix) {
+ SBFullHash full_hash;
+ memset(&full_hash, 0, sizeof(SBFullHash));
+ full_hash.prefix = prefix;
+ CHECK_LE(suffix.size() + sizeof(SBPrefix), sizeof(SBFullHash));
+ memcpy(full_hash.full_hash + sizeof(SBPrefix), suffix.data(), suffix.size());
+ return full_hash;
+}
+
std::string HashedIpPrefix(const std::string& ip_prefix, size_t prefix_size) {
net::IPAddressNumber ip_number;
EXPECT_TRUE(net::ParseIPLiteralToNumber(ip_prefix, &ip_number));
@@ -68,21 +78,33 @@ void InsertAddChunkHostPrefixUrl(SBChunk* chunk,
SBPrefixForString(url));
}
-// Same as InsertAddChunkHostPrefixUrl, but with full hashes.
-void InsertAddChunkHostFullHashes(SBChunk* chunk,
- int chunk_number,
- const std::string& host_name,
- const std::string& url) {
+// Same as InsertAddChunkHostFullHashes, but with pre-computed
+// prefix and fullhash values.
+void InsertAddChunkHostFullHashValue(SBChunk* chunk,
+ int chunk_number,
+ const SBPrefix& host_prefix,
+ const SBFullHash& url_fullhash) {
chunk->chunk_number = chunk_number;
chunk->is_add = true;
SBChunkHost host;
- host.host = SBPrefixForString(host_name);
+ host.host = host_prefix;
host.entry = SBEntry::Create(SBEntry::ADD_FULL_HASH, 1);
host.entry->set_chunk_id(chunk->chunk_number);
- host.entry->SetFullHashAt(0, SBFullHashForString(url));
+ host.entry->SetFullHashAt(0, url_fullhash);
chunk->hosts.push_back(host);
}
+// Same as InsertAddChunkHostPrefixUrl, but with full hashes.
+void InsertAddChunkHostFullHashes(SBChunk* chunk,
+ int chunk_number,
+ const std::string& host_name,
+ const std::string& url) {
+ InsertAddChunkHostFullHashValue(chunk,
+ chunk_number,
+ SBPrefixForString(host_name),
+ SBFullHashForString(url));
+}
+
void InsertAddChunkFullHash(SBChunk* chunk,
int chunk_number,
const std::string& ip_str,
@@ -285,6 +307,14 @@ class SafeBrowsingDatabaseTest : public PlatformTest {
DelChunk(list, chunk_id, true);
}
+ bool ContainsBrowseUrlHashes(std::vector<SBFullHash>* full_hashes,
+ std::vector<SBPrefix>* prefix_hits,
+ std::vector<SBFullHashResult>* cache_hits) {
+ std::sort(full_hashes->begin(), full_hashes->end(), SBFullHashLess);
+ return database_->ContainsBrowseUrlHashes(
+ *full_hashes, prefix_hits, cache_hits);
+ }
+
// Utility function for setting up the database for the caching test.
void PopulateDatabaseForCacheTest();
@@ -528,57 +558,39 @@ TEST_F(SafeBrowsingDatabaseTest, BrowseDatabase) {
EXPECT_EQ(lists[0].adds, "1-3");
EXPECT_TRUE(lists[0].subs.empty());
- const Time now = Time::Now();
- std::vector<SBFullHashResult> full_hashes;
+ std::vector<SBFullHashResult> cache_hits;
std::vector<SBPrefix> prefix_hits;
- std::string matching_list;
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/phishing.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.evil.com/phishing.html"), &prefix_hits, &cache_hits));
EXPECT_EQ(prefix_hits[0], SBPrefixForString("www.evil.com/phishing.html"));
EXPECT_EQ(prefix_hits.size(), 1U);
+ EXPECT_TRUE(cache_hits.empty());
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/malware.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.evil.com/malware.html"), &prefix_hits, &cache_hits));
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/notevil1.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.evil.com/notevil1.html"), &prefix_hits, &cache_hits));
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/notevil2.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.evil.com/notevil2.html"), &prefix_hits, &cache_hits));
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.good.com/good1.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.good.com/good1.html"), &prefix_hits, &cache_hits));
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.good.com/good2.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.good.com/good2.html"), &prefix_hits, &cache_hits));
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://192.168.0.1/malware.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://192.168.0.1/malware.html"), &prefix_hits, &cache_hits));
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.evil.com/"), &prefix_hits, &cache_hits));
EXPECT_TRUE(prefix_hits.empty());
+ EXPECT_TRUE(cache_hits.empty());
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/robots.txt"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.evil.com/robots.txt"), &prefix_hits, &cache_hits));
// Attempt to re-add the first chunk (should be a no-op).
// see bug: http://code.google.com/p/chromium/issues/detail?id=4522
@@ -609,32 +621,24 @@ TEST_F(SafeBrowsingDatabaseTest, BrowseDatabase) {
database_->UpdateFinished(true);
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/phishing.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.evil.com/phishing.html"), &prefix_hits, &cache_hits));
EXPECT_EQ(prefix_hits[0], SBPrefixForString("www.evil.com/phishing.html"));
EXPECT_EQ(prefix_hits.size(), 1U);
+ EXPECT_TRUE(cache_hits.empty());
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/notevil1.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.evil.com/notevil1.html"), &prefix_hits, &cache_hits));
EXPECT_TRUE(prefix_hits.empty());
+ EXPECT_TRUE(cache_hits.empty());
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/notevil2.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.evil.com/notevil2.html"), &prefix_hits, &cache_hits));
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.good.com/good1.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.good.com/good1.html"), &prefix_hits, &cache_hits));
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.good.com/good2.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.good.com/good2.html"), &prefix_hits, &cache_hits));
GetListsInfo(&lists);
EXPECT_TRUE(lists[0].name == safe_browsing_util::kMalwareList);
@@ -662,19 +666,13 @@ TEST_F(SafeBrowsingDatabaseTest, BrowseDatabase) {
database_->UpdateFinished(true);
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/notevil2.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.evil.com/notevil2.html"), &prefix_hits, &cache_hits));
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.good.com/good1.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.good.com/good1.html"), &prefix_hits, &cache_hits));
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.good.com/good2.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.good.com/good2.html"), &prefix_hits, &cache_hits));
GetListsInfo(&lists);
EXPECT_TRUE(lists[0].name == safe_browsing_util::kMalwareList);
@@ -719,7 +717,8 @@ TEST_F(SafeBrowsingDatabaseTest, BrowseDatabase) {
EXPECT_FALSE(database_->ContainsBrowseUrl(
GURL("http://www.notevilanymore.com/index.html"),
- &matching_list, &prefix_hits, &full_hashes, now));
+ &prefix_hits,
+ &cache_hits));
// Now insert the tardy add chunk and we don't expect them to appear
// in database because of the previous sub chunk.
@@ -735,11 +734,13 @@ TEST_F(SafeBrowsingDatabaseTest, BrowseDatabase) {
EXPECT_FALSE(database_->ContainsBrowseUrl(
GURL("http://www.notevilanymore.com/index.html"),
- &matching_list, &prefix_hits, &full_hashes, now));
+ &prefix_hits,
+ &cache_hits));
EXPECT_FALSE(database_->ContainsBrowseUrl(
GURL("http://www.notevilanymore.com/good.html"),
- &matching_list, &prefix_hits, &full_hashes, now));
+ &prefix_hits,
+ &cache_hits));
}
@@ -810,18 +811,12 @@ TEST_F(SafeBrowsingDatabaseTest, ZeroSizeChunk) {
database_->InsertChunks(safe_browsing_util::kMalwareList, chunks);
database_->UpdateFinished(true);
- const Time now = Time::Now();
- std::vector<SBFullHashResult> full_hashes;
+ std::vector<SBFullHashResult> cache_hits;
std::vector<SBPrefix> prefix_hits;
- std::string matching_list;
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.notempty.com/full1.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.notempty.com/full1.html"), &prefix_hits, &cache_hits));
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.notempty.com/full2.html"),
- &matching_list, &prefix_hits,
- &full_hashes, now));
+ GURL("http://www.notempty.com/full2.html"), &prefix_hits, &cache_hits));
GetListsInfo(&lists);
EXPECT_EQ(lists[0].adds, "1,10,19-22");
@@ -864,50 +859,53 @@ void SafeBrowsingDatabaseTest::PopulateDatabaseForCacheTest() {
SBFullHashResult full_hash;
full_hash.hash = SBFullHashForString("www.evil.com/phishing.html");
full_hash.list_name = safe_browsing_util::kMalwareList;
- full_hash.add_chunk_id = 1;
std::vector<SBFullHashResult> results;
+ std::vector<SBPrefix> prefixes;
results.push_back(full_hash);
+ prefixes.push_back(full_hash.hash.prefix);
+ database_->CacheHashResults(
+ prefixes, results, base::TimeDelta::FromMinutes(45));
full_hash.hash = SBFullHashForString("www.evil.com/malware.html");
+ results.clear();
+ prefixes.clear();
results.push_back(full_hash);
-
- std::vector<SBPrefix> prefixes;
- database_->CacheHashResults(prefixes, results);
+ prefixes.push_back(full_hash.hash.prefix);
+ database_->CacheHashResults(
+ prefixes, results, base::TimeDelta::FromMinutes(45));
}
TEST_F(SafeBrowsingDatabaseTest, HashCaching) {
PopulateDatabaseForCacheTest();
// We should have both full hashes in the cache.
- EXPECT_EQ(database_->pending_browse_hashes_.size(), 2U);
+ EXPECT_EQ(database_->browse_gethash_cache_.size(), 2U);
// Test the cache lookup for the first prefix.
std::string listname;
std::vector<SBPrefix> prefixes;
- std::vector<SBFullHashResult> full_hashes;
+ std::vector<SBFullHashResult> cache_hits;
database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/phishing.html"),
- &listname, &prefixes, &full_hashes, Time::Now());
- EXPECT_EQ(full_hashes.size(), 1U);
- EXPECT_TRUE(
- SBFullHashEqual(full_hashes[0].hash,
- SBFullHashForString("www.evil.com/phishing.html")));
+ GURL("http://www.evil.com/phishing.html"), &prefixes, &cache_hits);
+ EXPECT_TRUE(prefixes.empty());
+ EXPECT_EQ(cache_hits.size(), 1U);
+ EXPECT_TRUE(SBFullHashEqual(
+ cache_hits[0].hash, SBFullHashForString("www.evil.com/phishing.html")));
prefixes.clear();
- full_hashes.clear();
+ cache_hits.clear();
// Test the cache lookup for the second prefix.
database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/malware.html"),
- &listname, &prefixes, &full_hashes, Time::Now());
- EXPECT_EQ(full_hashes.size(), 1U);
- EXPECT_TRUE(
- SBFullHashEqual(full_hashes[0].hash,
- SBFullHashForString("www.evil.com/malware.html")));
+ GURL("http://www.evil.com/malware.html"), &prefixes, &cache_hits);
+ EXPECT_TRUE(prefixes.empty());
+ EXPECT_EQ(cache_hits.size(), 1U);
+ EXPECT_TRUE(SBFullHashEqual(
+ cache_hits[0].hash, SBFullHashForString("www.evil.com/malware.html")));
prefixes.clear();
- full_hashes.clear();
+ cache_hits.clear();
// Test removing a prefix via a sub chunk.
SBChunk chunk;
@@ -921,71 +919,66 @@ TEST_F(SafeBrowsingDatabaseTest, HashCaching) {
database_->InsertChunks(safe_browsing_util::kMalwareList, chunks);
database_->UpdateFinished(true);
- // This prefix should still be there.
+ // This prefix should still be there, but cached fullhash should be gone.
database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/malware.html"),
- &listname, &prefixes, &full_hashes, Time::Now());
- EXPECT_EQ(full_hashes.size(), 1U);
- EXPECT_TRUE(
- SBFullHashEqual(full_hashes[0].hash,
- SBFullHashForString("www.evil.com/malware.html")));
+ GURL("http://www.evil.com/malware.html"), &prefixes, &cache_hits);
+ EXPECT_TRUE(cache_hits.empty());
+ EXPECT_EQ(prefixes.size(), 1U);
+ EXPECT_EQ(prefixes[0], SBPrefixForString("www.evil.com/malware.html"));
prefixes.clear();
- full_hashes.clear();
+ cache_hits.clear();
// This prefix should be gone.
database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/phishing.html"),
- &listname, &prefixes, &full_hashes, Time::Now());
- EXPECT_TRUE(full_hashes.empty());
+ GURL("http://www.evil.com/phishing.html"), &prefixes, &cache_hits);
+ EXPECT_TRUE(prefixes.empty());
+ EXPECT_TRUE(cache_hits.empty());
prefixes.clear();
- full_hashes.clear();
+ cache_hits.clear();
- // Test that an AddDel for the original chunk removes the last cached entry.
+ // Test that an AddDel for the original chunk removes the last entry.
EXPECT_TRUE(database_->UpdateStarted(&lists));
AddDelChunk(safe_browsing_util::kMalwareList, 1);
database_->UpdateFinished(true);
database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/malware.html"),
- &listname, &prefixes, &full_hashes, Time::Now());
- EXPECT_TRUE(full_hashes.empty());
+ GURL("http://www.evil.com/malware.html"), &prefixes, &cache_hits);
+ EXPECT_TRUE(cache_hits.empty());
EXPECT_TRUE(database_->full_browse_hashes_.empty());
- EXPECT_TRUE(database_->pending_browse_hashes_.empty());
+ EXPECT_TRUE(database_->browse_gethash_cache_.empty());
prefixes.clear();
- full_hashes.clear();
+ cache_hits.clear();
// Test that the cache won't return expired values. First we have to adjust
// the cached entries' received time to make them older, since the database
// cache insert uses Time::Now(). First, store some entries.
PopulateDatabaseForCacheTest();
- std::vector<SBAddFullHash>* hash_cache = &database_->pending_browse_hashes_;
+ std::map<SBPrefix, SBCachedFullHashResult>* hash_cache =
+ &database_->browse_gethash_cache_;
EXPECT_EQ(hash_cache->size(), 2U);
// Now adjust one of the entries times to be in the past.
- base::Time expired = base::Time::Now() - base::TimeDelta::FromMinutes(60);
const SBPrefix key = SBPrefixForString("www.evil.com/malware.html");
- std::vector<SBAddFullHash>::iterator iter;
- for (iter = hash_cache->begin(); iter != hash_cache->end(); ++iter) {
- if (iter->full_hash.prefix == key) {
- iter->received = static_cast<int32>(expired.ToTimeT());
- break;
- }
- }
- EXPECT_TRUE(iter != hash_cache->end());
+ std::map<SBPrefix, SBCachedFullHashResult>::iterator iter =
+ hash_cache->find(key);
+ ASSERT_TRUE(iter != hash_cache->end());
+ iter->second.expire_after =
+ base::Time::Now() - base::TimeDelta::FromMinutes(1);
database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/malware.html"),
- &listname, &prefixes, &full_hashes, expired);
- EXPECT_TRUE(full_hashes.empty());
+ GURL("http://www.evil.com/malware.html"), &prefixes, &cache_hits);
+ EXPECT_EQ(prefixes.size(), 1U);
+ EXPECT_TRUE(cache_hits.empty());
+ // Expired entry should have been removed from cache.
+ EXPECT_EQ(hash_cache->size(), 1U);
// This entry should still exist.
database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/phishing.html"),
- &listname, &prefixes, &full_hashes, expired);
- EXPECT_EQ(full_hashes.size(), 1U);
-
+ GURL("http://www.evil.com/phishing.html"), &prefixes, &cache_hits);
+ EXPECT_TRUE(prefixes.empty());
+ EXPECT_EQ(cache_hits.size(), 1U);
// Testing prefix miss caching. First, we clear out the existing database,
// Since PopulateDatabaseForCacheTest() doesn't handle adding duplicate
@@ -999,33 +992,44 @@ TEST_F(SafeBrowsingDatabaseTest, HashCaching) {
prefix_misses.push_back(SBPrefixForString("http://www.bad.com/malware.html"));
prefix_misses.push_back(
SBPrefixForString("http://www.bad.com/phishing.html"));
- database_->CacheHashResults(prefix_misses, empty_full_hash);
+ database_->CacheHashResults(
+ prefix_misses, empty_full_hash, base::TimeDelta::FromMinutes(45));
// Prefixes with no full results are misses.
- EXPECT_EQ(database_->prefix_miss_cache_.size(), 2U);
+ EXPECT_EQ(hash_cache->size(), 2U);
+ EXPECT_NE(
+ hash_cache->find(SBPrefixForString("http://www.bad.com/malware.html")),
+ hash_cache->end());
Scott Hess - ex-Googler 2014/04/03 21:44:03 I think EXPECT_TRUE(hash_cache->count(key)) would
mattm 2014/04/04 23:58:49 Done.
+ EXPECT_TRUE(
+ hash_cache->find(SBPrefixForString("http://www.bad.com/malware.html"))
+ ->second.full_hashes.empty());
+ EXPECT_NE(
+ hash_cache->find(SBPrefixForString("http://www.bad.com/phishing.html")),
+ hash_cache->end());
+ EXPECT_TRUE(
+ hash_cache->find(SBPrefixForString("http://www.bad.com/phishing.html"))
+ ->second.full_hashes.empty());
// Update the database.
PopulateDatabaseForCacheTest();
- // Prefix miss cache should be cleared.
- EXPECT_TRUE(database_->prefix_miss_cache_.empty());
Scott Hess - ex-Googler 2014/04/03 21:44:03 EXPECT_TRUE(database_->hash_cache_.empty()); might
mattm 2014/04/04 23:58:49 PopulateDatabaseForCacheTest inserts some more thi
-
// Cache a GetHash miss for a particular prefix, and even though the prefix is
// in the database, it is flagged as a miss so looking up the associated URL
// will not succeed.
prefixes.clear();
- full_hashes.clear();
+ cache_hits.clear();
prefix_misses.clear();
empty_full_hash.clear();
prefix_misses.push_back(SBPrefixForString("www.evil.com/phishing.html"));
- database_->CacheHashResults(prefix_misses, empty_full_hash);
+ database_->CacheHashResults(
+ prefix_misses, empty_full_hash, base::TimeDelta::FromMinutes(45));
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/phishing.html"),
- &listname, &prefixes,
- &full_hashes, Time::Now()));
+ GURL("http://www.evil.com/phishing.html"), &prefixes, &cache_hits));
+ EXPECT_TRUE(prefixes.empty());
+ EXPECT_TRUE(cache_hits.empty());
prefixes.clear();
- full_hashes.clear();
+ cache_hits.clear();
// Test receiving a full add chunk.
chunk.hosts.clear();
@@ -1039,26 +1043,20 @@ TEST_F(SafeBrowsingDatabaseTest, HashCaching) {
database_->UpdateFinished(true);
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.fullevil.com/bad1.html"),
- &listname, &prefixes, &full_hashes,
- Time::Now()));
- EXPECT_EQ(full_hashes.size(), 1U);
- EXPECT_TRUE(
- SBFullHashEqual(full_hashes[0].hash,
- SBFullHashForString("www.fullevil.com/bad1.html")));
+ GURL("http://www.fullevil.com/bad1.html"), &prefixes, &cache_hits));
+ EXPECT_EQ(prefixes.size(), 1U);
+ EXPECT_EQ(prefixes[0], SBPrefixForString("www.fullevil.com/bad1.html"));
+ EXPECT_TRUE(cache_hits.empty());
prefixes.clear();
- full_hashes.clear();
+ cache_hits.clear();
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.fullevil.com/bad2.html"),
- &listname, &prefixes, &full_hashes,
- Time::Now()));
- EXPECT_EQ(full_hashes.size(), 1U);
- EXPECT_TRUE(
- SBFullHashEqual(full_hashes[0].hash,
- SBFullHashForString("www.fullevil.com/bad2.html")));
+ GURL("http://www.fullevil.com/bad2.html"), &prefixes, &cache_hits));
+ EXPECT_EQ(prefixes.size(), 1U);
+ EXPECT_EQ(prefixes[0], SBPrefixForString("www.fullevil.com/bad2.html"));
+ EXPECT_TRUE(cache_hits.empty());
prefixes.clear();
- full_hashes.clear();
+ cache_hits.clear();
// Test receiving a full sub chunk, which will remove one of the full adds.
chunk.hosts.clear();
@@ -1072,22 +1070,18 @@ TEST_F(SafeBrowsingDatabaseTest, HashCaching) {
database_->UpdateFinished(true);
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.fullevil.com/bad1.html"),
- &listname, &prefixes, &full_hashes,
- Time::Now()));
- EXPECT_TRUE(full_hashes.empty());
+ GURL("http://www.fullevil.com/bad1.html"), &prefixes, &cache_hits));
+ EXPECT_TRUE(prefixes.empty());
+ EXPECT_TRUE(cache_hits.empty());
// There should be one remaining full add.
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.fullevil.com/bad2.html"),
- &listname, &prefixes, &full_hashes,
- Time::Now()));
- EXPECT_EQ(full_hashes.size(), 1U);
- EXPECT_TRUE(
- SBFullHashEqual(full_hashes[0].hash,
- SBFullHashForString("www.fullevil.com/bad2.html")));
+ GURL("http://www.fullevil.com/bad2.html"), &prefixes, &cache_hits));
+ EXPECT_EQ(prefixes.size(), 1U);
+ EXPECT_EQ(prefixes[0], SBPrefixForString("www.fullevil.com/bad2.html"));
+ EXPECT_TRUE(cache_hits.empty());
prefixes.clear();
- full_hashes.clear();
+ cache_hits.clear();
// Now test an AddDel for the remaining full add.
EXPECT_TRUE(database_->UpdateStarted(&lists));
@@ -1095,13 +1089,9 @@ TEST_F(SafeBrowsingDatabaseTest, HashCaching) {
database_->UpdateFinished(true);
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.fullevil.com/bad1.html"),
- &listname, &prefixes, &full_hashes,
- Time::Now()));
+ GURL("http://www.fullevil.com/bad1.html"), &prefixes, &cache_hits));
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.fullevil.com/bad2.html"),
- &listname, &prefixes, &full_hashes,
- Time::Now()));
+ GURL("http://www.fullevil.com/bad2.html"), &prefixes, &cache_hits));
}
// Test that corrupt databases are appropriately handled, even if the
@@ -1547,25 +1537,18 @@ TEST_F(SafeBrowsingDatabaseTest, SameHostEntriesOkay) {
EXPECT_EQ(std::string(safe_browsing_util::kPhishingList), lists[1].name);
EXPECT_EQ("47", lists[1].adds);
- const Time now = Time::Now();
std::vector<SBPrefix> prefixes;
- std::vector<SBFullHashResult> full_hashes;
- std::vector<SBPrefix> prefix_hits;
- std::string matching_list;
+ std::vector<SBFullHashResult> cache_hits;
std::string listname;
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/malware1.html"),
- &listname, &prefixes, &full_hashes, now));
+ GURL("http://www.evil.com/malware1.html"), &prefixes, &cache_hits));
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/malware2.html"),
- &listname, &prefixes, &full_hashes, now));
+ GURL("http://www.evil.com/malware2.html"), &prefixes, &cache_hits));
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/phishing1.html"),
- &listname, &prefixes, &full_hashes, now));
+ GURL("http://www.evil.com/phishing1.html"), &prefixes, &cache_hits));
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/phishing2.html"),
- &listname, &prefixes, &full_hashes, now));
+ GURL("http://www.evil.com/phishing2.html"), &prefixes, &cache_hits));
// Test removing a single prefix from the add chunk.
// Remove the prefix that added first.
@@ -1590,17 +1573,13 @@ TEST_F(SafeBrowsingDatabaseTest, SameHostEntriesOkay) {
// Verify that the database contains urls expected.
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/malware1.html"),
- &listname, &prefixes, &full_hashes, now));
+ GURL("http://www.evil.com/malware1.html"), &prefixes, &cache_hits));
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/malware2.html"),
- &listname, &prefixes, &full_hashes, now));
+ GURL("http://www.evil.com/malware2.html"), &prefixes, &cache_hits));
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/phishing1.html"),
- &listname, &prefixes, &full_hashes, now));
+ GURL("http://www.evil.com/phishing1.html"), &prefixes, &cache_hits));
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/phishing2.html"),
- &listname, &prefixes, &full_hashes, now));
+ GURL("http://www.evil.com/phishing2.html"), &prefixes, &cache_hits));
}
// Test that an empty update doesn't actually update the database.
@@ -1686,16 +1665,12 @@ TEST_F(SafeBrowsingDatabaseTest, FilterFile) {
}
// Find the malware url in the database, don't find a good url.
- const Time now = Time::Now();
- std::vector<SBFullHashResult> full_hashes;
+ std::vector<SBFullHashResult> cache_hits;
std::vector<SBPrefix> prefix_hits;
- std::string matching_list;
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/malware.html"),
- &matching_list, &prefix_hits, &full_hashes, now));
+ GURL("http://www.evil.com/malware.html"), &prefix_hits, &cache_hits));
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.good.com/goodware.html"),
- &matching_list, &prefix_hits, &full_hashes, now));
+ GURL("http://www.good.com/goodware.html"), &prefix_hits, &cache_hits));
base::FilePath filter_file = database_->PrefixSetForFilename(
database_->BrowseDBFilename(database_filename_));
@@ -1706,11 +1681,9 @@ TEST_F(SafeBrowsingDatabaseTest, FilterFile) {
database_.reset(new SafeBrowsingDatabaseNew);
database_->Init(database_filename_);
EXPECT_TRUE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/malware.html"),
- &matching_list, &prefix_hits, &full_hashes, now));
+ GURL("http://www.evil.com/malware.html"), &prefix_hits, &cache_hits));
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.good.com/goodware.html"),
- &matching_list, &prefix_hits, &full_hashes, now));
+ GURL("http://www.good.com/goodware.html"), &prefix_hits, &cache_hits));
// If there is no filter file, the database cannot find malware urls.
base::DeleteFile(filter_file, false);
@@ -1718,11 +1691,344 @@ TEST_F(SafeBrowsingDatabaseTest, FilterFile) {
database_.reset(new SafeBrowsingDatabaseNew);
database_->Init(database_filename_);
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.evil.com/malware.html"),
- &matching_list, &prefix_hits, &full_hashes, now));
+ GURL("http://www.evil.com/malware.html"), &prefix_hits, &cache_hits));
EXPECT_FALSE(database_->ContainsBrowseUrl(
- GURL("http://www.good.com/goodware.html"),
- &matching_list, &prefix_hits, &full_hashes, now));
+ GURL("http://www.good.com/goodware.html"), &prefix_hits, &cache_hits));
+}
+
+TEST_F(SafeBrowsingDatabaseTest, TestCachedFullMiss) {
+ std::vector<SBListChunkRanges> lists;
+ EXPECT_TRUE(database_->UpdateStarted(&lists));
Scott Hess - ex-Googler 2014/04/03 21:44:03 Suggest ASSERT_TRUE(), as probably if this line fa
mattm 2014/04/04 23:58:49 Done.
+
+ SBChunkList chunks;
+ {
+ // Insert prefix 1001 into database.
+ SBChunk chunk;
+ InsertAddChunkHostPrefixValue(&chunk, 1, SBPrefix(100), SBPrefix(1001));
+ chunks.push_back(chunk);
+ }
+ {
+ // Insert prefix 1002 into database.
+ SBChunk chunk;
+ InsertAddChunkHostPrefixValue(&chunk, 2, SBPrefix(101), SBPrefix(1002));
+ chunks.push_back(chunk);
+ }
+
+ database_->InsertChunks(safe_browsing_util::kMalwareList, chunks);
+ database_->UpdateFinished(true);
+
+ {
+ // Cache a full miss result for 1001.
+ std::vector<SBPrefix> prefixes;
+ prefixes.push_back(SBPrefix(1001));
+ std::vector<SBFullHashResult> cache_results;
+ database_->CacheHashResults(
+ prefixes, cache_results, base::TimeDelta::FromMinutes(60));
+ }
+
+ {
+ // Check if DB contains (prefix 1001, suffix 01). Should return false, since
+ // we have a cached miss for that prefix.
+ std::vector<SBFullHash> full_hashes;
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1001, "\x01"));
+ std::vector<SBPrefix> prefix_hits;
+ std::vector<SBFullHashResult> cache_hits;
+ EXPECT_FALSE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ EXPECT_TRUE(prefix_hits.empty());
+ EXPECT_TRUE(cache_hits.empty());
+
+ // Add (1002,01) to search. Should return a prefix hit for 1002 only.
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1002, "\x01"));
+ prefix_hits.clear();
+ cache_hits.clear();
+ EXPECT_TRUE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ ASSERT_EQ(1U, prefix_hits.size());
+ EXPECT_EQ(1002U, prefix_hits[0]);
+ EXPECT_TRUE(cache_hits.empty());
+ }
+}
+
+TEST_F(SafeBrowsingDatabaseTest, TestCachedPrefixHitFullMiss) {
+ std::vector<SBListChunkRanges> lists;
+ EXPECT_TRUE(database_->UpdateStarted(&lists));
+
+ SBChunkList chunks;
+ {
+ // Insert prefix 1001 into database.
+ SBChunk chunk;
+ InsertAddChunkHostPrefixValue(&chunk, 1, SBPrefix(100), SBPrefix(1001));
+ chunks.push_back(chunk);
+ }
+ {
+ // Insert prefix 1002 into database.
+ SBChunk chunk;
+ InsertAddChunkHostPrefixValue(&chunk, 2, SBPrefix(101), SBPrefix(1002));
+ chunks.push_back(chunk);
+ }
+
+ database_->InsertChunks(safe_browsing_util::kMalwareList, chunks);
+ database_->UpdateFinished(true);
+
+ {
+ // Check if DB contains (prefix 1001, suffix 01). Should return a prefix
+ // hit.
+ std::vector<SBFullHash> full_hashes;
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1001, "\x01"));
+ std::vector<SBPrefix> prefix_hits;
+ std::vector<SBFullHashResult> cache_hits;
+ EXPECT_TRUE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ ASSERT_EQ(1U, prefix_hits.size());
+ EXPECT_EQ(1001U, prefix_hits[0]);
+ EXPECT_TRUE(cache_hits.empty());
+
+ // Add (1002,01) to search. Should return a prefix hit for both 1001 and
+ // 1002.
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1002, "\x01"));
+ prefix_hits.clear();
+ cache_hits.clear();
+ EXPECT_TRUE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ ASSERT_EQ(2U, prefix_hits.size());
+ EXPECT_EQ(1001U, prefix_hits[0]);
+ EXPECT_EQ(1002U, prefix_hits[1]);
+ EXPECT_TRUE(cache_hits.empty());
+
+ // Add (1003,01) to search. Should still return a prefix hit for both 1001
+ // and 1002.
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1003, "\x01"));
+ prefix_hits.clear();
+ cache_hits.clear();
+ EXPECT_TRUE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ ASSERT_EQ(2U, prefix_hits.size());
+ EXPECT_EQ(1001U, prefix_hits[0]);
+ EXPECT_EQ(1002U, prefix_hits[1]);
+ EXPECT_TRUE(cache_hits.empty());
+ }
+
+ {
+ // Cache a fullhash result for (1001,01) and (1001,03).
+ std::vector<SBPrefix> prefixes;
+ prefixes.push_back(SBPrefix(1001));
+ std::vector<SBFullHashResult> cache_results;
+
+ SBFullHashResult full_hash_result;
+ full_hash_result.hash = SBFullHashForPrefixAndSuffix(1001, "\x01");
+ full_hash_result.list_name = safe_browsing_util::kMalwareList;
+ cache_results.push_back(full_hash_result);
+
+ full_hash_result.hash = SBFullHashForPrefixAndSuffix(1001, "\x03");
+ cache_results.push_back(full_hash_result);
+
+ database_->CacheHashResults(
+ prefixes, cache_results, base::TimeDelta::FromMinutes(60));
+ }
+
+ {
+ // Check again if DB contains (prefix 1001, suffix 01). Should return a
+ // cache hit now.
+ std::vector<SBFullHash> full_hashes;
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1001, "\x01"));
+ std::vector<SBPrefix> prefix_hits;
+ std::vector<SBFullHashResult> cache_hits;
+ EXPECT_TRUE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ EXPECT_TRUE(prefix_hits.empty());
+ ASSERT_EQ(1U, cache_hits.size());
+ EXPECT_TRUE(SBFullHashEqual(SBFullHashForPrefixAndSuffix(1001, "\x01"),
+ cache_hits[0].hash));
+
+ // Add (1002,01) to search. Should return a cache hit for 1001 and prefix
+ // hit for 1002.
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1002, "\x01"));
+ prefix_hits.clear();
+ cache_hits.clear();
+ EXPECT_TRUE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ ASSERT_EQ(1U, prefix_hits.size());
+ EXPECT_EQ(1002U, prefix_hits[0]);
+ ASSERT_EQ(1U, cache_hits.size());
+ EXPECT_TRUE(SBFullHashEqual(SBFullHashForPrefixAndSuffix(1001, "\x01"),
+ cache_hits[0].hash));
+
+ // Add (1001,03) to search. Should return 2 cache hits for 1001 and a prefix
+ // hit for 1002.
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1001, "\x03"));
+ prefix_hits.clear();
+ cache_hits.clear();
+ EXPECT_TRUE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ ASSERT_EQ(1U, prefix_hits.size());
+ EXPECT_EQ(1002U, prefix_hits[0]);
+ ASSERT_EQ(2U, cache_hits.size());
+ EXPECT_TRUE(SBFullHashEqual(SBFullHashForPrefixAndSuffix(1001, "\x01"),
+ cache_hits[0].hash));
+ EXPECT_TRUE(SBFullHashEqual(SBFullHashForPrefixAndSuffix(1001, "\x03"),
+ cache_hits[1].hash));
+ }
+
+ {
+ // Check if DB contains only (prefix 1001, suffix 03). Should return a cache
+ // hit.
+ std::vector<SBFullHash> full_hashes;
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1001, "\x03"));
+ std::vector<SBPrefix> prefix_hits;
+ std::vector<SBFullHashResult> cache_hits;
+ EXPECT_TRUE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ EXPECT_TRUE(prefix_hits.empty());
+ ASSERT_EQ(1U, cache_hits.size());
+ EXPECT_TRUE(SBFullHashEqual(SBFullHashForPrefixAndSuffix(1001, "\x03"),
+ cache_hits[0].hash));
+ }
+
+ {
+ // Check if DB contains (prefix 1001, suffix 02). Should return false, since
+ // we have a cached fullhash for that prefix but which does not match the
+ // fullhash.
+ std::vector<SBFullHash> full_hashes;
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1001, "\x02"));
+ std::vector<SBPrefix> prefix_hits;
+ std::vector<SBFullHashResult> cache_hits;
+ EXPECT_FALSE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ EXPECT_TRUE(prefix_hits.empty());
+ EXPECT_TRUE(cache_hits.empty());
+
+ // Add (1002,01) to search. Should return a prefix hit for 1002.
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1002, "\x01"));
+ prefix_hits.clear();
+ cache_hits.clear();
+ EXPECT_TRUE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ ASSERT_EQ(1U, prefix_hits.size());
+ EXPECT_EQ(1002U, prefix_hits[0]);
+ EXPECT_TRUE(cache_hits.empty());
+ }
+}
+
+TEST_F(SafeBrowsingDatabaseTest, TestBrowseFullHashMatching) {
+ std::vector<SBListChunkRanges> lists;
+ EXPECT_TRUE(database_->UpdateStarted(&lists));
+
+ SBChunkList chunks;
+ {
+ // Insert fullhash (1001,1) into database.
+ SBChunk chunk;
+ InsertAddChunkHostFullHashValue(
+ &chunk, 1, SBPrefix(100), SBFullHashForPrefixAndSuffix(1001, "\x01"));
+ chunks.push_back(chunk);
+ }
+ {
+ // Insert fullhash (1001,2) into database.
+ SBChunk chunk;
+ InsertAddChunkHostFullHashValue(
+ &chunk, 2, SBPrefix(100), SBFullHashForPrefixAndSuffix(1001, "\x02"));
+ chunks.push_back(chunk);
+ }
+
+ database_->InsertChunks(safe_browsing_util::kMalwareList, chunks);
+ database_->UpdateFinished(true);
+
+ {
+ // Check if DB contains (prefix 1001, suffix 03). Should return false,
+ // since the DB contains a matching prefix but the full hashes do not match.
+ std::vector<SBFullHash> full_hashes;
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1001, "\x03"));
+ std::vector<SBPrefix> prefix_hits;
+ std::vector<SBFullHashResult> cache_hits;
+ EXPECT_FALSE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ EXPECT_TRUE(prefix_hits.empty());
+ EXPECT_TRUE(cache_hits.empty());
+
+ // Add (1001,1). Should now return a prefix hit.
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1001, "\x01"));
+ prefix_hits.clear();
+ cache_hits.clear();
+ EXPECT_TRUE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ ASSERT_EQ(1U, prefix_hits.size());
+ EXPECT_EQ(1001U, prefix_hits[0]);
+ EXPECT_TRUE(cache_hits.empty());
+
+ // Add (1001,2). Should still return a single prefix hit.
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1001, "\x02"));
+ prefix_hits.clear();
+ cache_hits.clear();
+ EXPECT_TRUE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ ASSERT_EQ(1U, prefix_hits.size());
+ EXPECT_EQ(1001U, prefix_hits[0]);
+ EXPECT_TRUE(cache_hits.empty());
+ }
+
+ {
+ // Check if DB contains (prefix 1001, suffix 02) alone. Should return a
+ // prefix hit.
+ std::vector<SBFullHash> full_hashes;
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1001, "\x02"));
+ std::vector<SBPrefix> prefix_hits;
+ std::vector<SBFullHashResult> cache_hits;
+ EXPECT_TRUE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ ASSERT_EQ(1U, prefix_hits.size());
+ EXPECT_EQ(1001U, prefix_hits[0]);
+ EXPECT_TRUE(cache_hits.empty());
+ }
+
+ {
+ // Cache a fullhash result for (prefix 1001, suffix 02).
+ std::vector<SBPrefix> prefixes;
+ prefixes.push_back(SBPrefix(1001));
+ std::vector<SBFullHashResult> cache_results;
+
+ SBFullHashResult full_hash_result;
+ full_hash_result.hash = SBFullHashForPrefixAndSuffix(1001, "\x02");
+ full_hash_result.list_name = safe_browsing_util::kMalwareList;
+
+ cache_results.push_back(full_hash_result);
+
+ database_->CacheHashResults(
+ prefixes, cache_results, base::TimeDelta::FromMinutes(60));
+ }
+
+ {
+ // Check if DB contains (prefix 1001, suffix 03). Should return false,
+ // since the DB containts a cached hit with matching prefix but not
Scott Hess - ex-Googler 2014/04/03 21:44:03 "contains"
mattm 2014/04/04 23:58:49 Done.
+ // matching the fullhash.
+ std::vector<SBFullHash> full_hashes;
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1001, "\x03"));
+ std::vector<SBPrefix> prefix_hits;
+ std::vector<SBFullHashResult> cache_hits;
+ EXPECT_FALSE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ EXPECT_TRUE(prefix_hits.empty());
+ EXPECT_TRUE(cache_hits.empty());
+
+ // Add (1001,1). Should still return false.
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1001, "\x01"));
+ prefix_hits.clear();
+ cache_hits.clear();
+ EXPECT_FALSE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ EXPECT_TRUE(prefix_hits.empty());
+ EXPECT_TRUE(cache_hits.empty());
+
+ // Add (1001,2). Should now return a cache hit.
+ full_hashes.push_back(SBFullHashForPrefixAndSuffix(1001, "\x02"));
+ prefix_hits.clear();
+ cache_hits.clear();
+ EXPECT_TRUE(
+ ContainsBrowseUrlHashes(&full_hashes, &prefix_hits, &cache_hits));
+ EXPECT_TRUE(prefix_hits.empty());
+ ASSERT_EQ(1U, cache_hits.size());
+ EXPECT_TRUE(SBFullHashEqual(SBFullHashForPrefixAndSuffix(1001, "\x02"),
+ cache_hits[0].hash));
+ }
}
TEST_F(SafeBrowsingDatabaseTest, MalwareIpBlacklist) {

Powered by Google App Engine
This is Rietveld 408576698