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/database_manager_unittest.cc

Issue 337723004: [Safe browsing] Clean up code to scan hash results for threats. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/safe_browsing/database_manager.h" 10 #include "chrome/browser/safe_browsing/database_manager.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 std::vector<SBThreatType> multiple_threats; 71 std::vector<SBThreatType> multiple_threats;
72 multiple_threats.push_back(SB_THREAT_TYPE_URL_MALWARE); 72 multiple_threats.push_back(SB_THREAT_TYPE_URL_MALWARE);
73 multiple_threats.push_back(SB_THREAT_TYPE_URL_PHISHING); 73 multiple_threats.push_back(SB_THREAT_TYPE_URL_PHISHING);
74 EXPECT_FALSE(RunSBHashTest(safe_browsing_util::MALWARE, 74 EXPECT_FALSE(RunSBHashTest(safe_browsing_util::MALWARE,
75 multiple_threats, 75 multiple_threats,
76 safe_browsing_util::kBinUrlList)); 76 safe_browsing_util::kBinUrlList));
77 EXPECT_TRUE(RunSBHashTest(safe_browsing_util::MALWARE, 77 EXPECT_TRUE(RunSBHashTest(safe_browsing_util::MALWARE,
78 multiple_threats, 78 multiple_threats,
79 safe_browsing_util::kMalwareList)); 79 safe_browsing_util::kMalwareList));
80 } 80 }
81
82 TEST_F(SafeBrowsingDatabaseManagerTest, GetUrlThreatType) {
83 std::vector<SBFullHashResult> full_hashes;
84
85 const GURL kMalwareUrl("http://www.malware.com/page.html");
86 const GURL kPhishingUrl("http://www.phishing.com/page.html");
87 const GURL kSafeUrl("http://www.safe.com/page.html");
88
89 const SBFullHash kMalwareHostHash = SBFullHashForString("malware.com/");
90 const SBFullHash kPhishingHostHash = SBFullHashForString("phishing.com/");
91 const SBFullHash kSafeHostHash = SBFullHashForString("www.safe.com/");
92
93 {
94 SBFullHashResult full_hash;
95 full_hash.hash = kMalwareHostHash;
96 full_hash.list_id = static_cast<int>(safe_browsing_util::MALWARE);
97 full_hashes.push_back(full_hash);
98 }
99
100 {
101 SBFullHashResult full_hash;
102 full_hash.hash = kPhishingHostHash;
103 full_hash.list_id = static_cast<int>(safe_browsing_util::PHISH);
104 full_hashes.push_back(full_hash);
105 }
106
107 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
108 SafeBrowsingDatabaseManager::GetHashThreatType(
109 kMalwareHostHash, full_hashes));
110
111 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING,
112 SafeBrowsingDatabaseManager::GetHashThreatType(
113 kPhishingHostHash, full_hashes));
114
115 EXPECT_EQ(SB_THREAT_TYPE_SAFE,
116 SafeBrowsingDatabaseManager::GetHashThreatType(
117 kSafeHostHash, full_hashes));
118
119 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
120 SafeBrowsingDatabaseManager::GetUrlThreatType(
121 kMalwareUrl, full_hashes));
122
123 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING,
124 SafeBrowsingDatabaseManager::GetUrlThreatType(
125 kPhishingUrl, full_hashes));
126
127 EXPECT_EQ(SB_THREAT_TYPE_SAFE,
128 SafeBrowsingDatabaseManager::GetUrlThreatType(
129 kSafeUrl, full_hashes));
130 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/database_manager.cc ('k') | chrome/browser/safe_browsing/safe_browsing_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698