OLD | NEW |
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 81 |
82 TEST_F(SafeBrowsingDatabaseManagerTest, GetUrlThreatType) { | 82 TEST_F(SafeBrowsingDatabaseManagerTest, GetUrlSeverestThreatType) { |
83 std::vector<SBFullHashResult> full_hashes; | 83 std::vector<SBFullHashResult> full_hashes; |
84 | 84 |
85 const GURL kMalwareUrl("http://www.malware.com/page.html"); | 85 const GURL kMalwareUrl("http://www.malware.com/page.html"); |
86 const GURL kPhishingUrl("http://www.phishing.com/page.html"); | 86 const GURL kPhishingUrl("http://www.phishing.com/page.html"); |
| 87 const GURL kUnwantedUrl("http://www.unwanted.com/page.html"); |
| 88 const GURL kUnwantedAndMalwareUrl( |
| 89 "http://www.unwantedandmalware.com/page.html"); |
87 const GURL kSafeUrl("http://www.safe.com/page.html"); | 90 const GURL kSafeUrl("http://www.safe.com/page.html"); |
88 | 91 |
89 const SBFullHash kMalwareHostHash = SBFullHashForString("malware.com/"); | 92 const SBFullHash kMalwareHostHash = SBFullHashForString("malware.com/"); |
90 const SBFullHash kPhishingHostHash = SBFullHashForString("phishing.com/"); | 93 const SBFullHash kPhishingHostHash = SBFullHashForString("phishing.com/"); |
| 94 const SBFullHash kUnwantedHostHash = SBFullHashForString("unwanted.com/"); |
| 95 const SBFullHash kUnwantedAndMalwareHostHash = |
| 96 SBFullHashForString("unwantedandmalware.com/"); |
91 const SBFullHash kSafeHostHash = SBFullHashForString("www.safe.com/"); | 97 const SBFullHash kSafeHostHash = SBFullHashForString("www.safe.com/"); |
92 | 98 |
93 { | 99 { |
94 SBFullHashResult full_hash; | 100 SBFullHashResult full_hash; |
95 full_hash.hash = kMalwareHostHash; | 101 full_hash.hash = kMalwareHostHash; |
96 full_hash.list_id = static_cast<int>(safe_browsing_util::MALWARE); | 102 full_hash.list_id = static_cast<int>(safe_browsing_util::MALWARE); |
97 full_hashes.push_back(full_hash); | 103 full_hashes.push_back(full_hash); |
98 } | 104 } |
99 | 105 |
100 { | 106 { |
101 SBFullHashResult full_hash; | 107 SBFullHashResult full_hash; |
102 full_hash.hash = kPhishingHostHash; | 108 full_hash.hash = kPhishingHostHash; |
103 full_hash.list_id = static_cast<int>(safe_browsing_util::PHISH); | 109 full_hash.list_id = static_cast<int>(safe_browsing_util::PHISH); |
104 full_hashes.push_back(full_hash); | 110 full_hashes.push_back(full_hash); |
105 } | 111 } |
106 | 112 |
| 113 { |
| 114 SBFullHashResult full_hash; |
| 115 full_hash.hash = kUnwantedHostHash; |
| 116 full_hash.list_id = static_cast<int>(safe_browsing_util::UNWANTEDURL); |
| 117 full_hashes.push_back(full_hash); |
| 118 } |
| 119 |
| 120 { |
| 121 // Add both MALWARE and UNWANTEDURL list IDs for |
| 122 // kUnwantedAndMalwareHostHash. |
| 123 SBFullHashResult full_hash_malware; |
| 124 full_hash_malware.hash = kUnwantedAndMalwareHostHash; |
| 125 full_hash_malware.list_id = static_cast<int>(safe_browsing_util::MALWARE); |
| 126 full_hashes.push_back(full_hash_malware); |
| 127 |
| 128 SBFullHashResult full_hash_unwanted; |
| 129 full_hash_unwanted.hash = kUnwantedAndMalwareHostHash; |
| 130 full_hash_unwanted.list_id = |
| 131 static_cast<int>(safe_browsing_util::UNWANTEDURL); |
| 132 full_hashes.push_back(full_hash_unwanted); |
| 133 } |
| 134 |
107 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, | 135 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, |
108 SafeBrowsingDatabaseManager::GetHashThreatType( | 136 SafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
109 kMalwareHostHash, full_hashes)); | 137 kMalwareHostHash, full_hashes)); |
110 | 138 |
111 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING, | 139 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING, |
112 SafeBrowsingDatabaseManager::GetHashThreatType( | 140 SafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
113 kPhishingHostHash, full_hashes)); | 141 kPhishingHostHash, full_hashes)); |
114 | 142 |
| 143 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, |
| 144 SafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
| 145 kUnwantedHostHash, full_hashes)); |
| 146 |
| 147 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, |
| 148 SafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
| 149 kUnwantedAndMalwareHostHash, full_hashes)); |
| 150 |
115 EXPECT_EQ(SB_THREAT_TYPE_SAFE, | 151 EXPECT_EQ(SB_THREAT_TYPE_SAFE, |
116 SafeBrowsingDatabaseManager::GetHashThreatType( | 152 SafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
117 kSafeHostHash, full_hashes)); | 153 kSafeHostHash, full_hashes)); |
118 | 154 |
119 size_t index = 100; | 155 const size_t kArbitraryValue = 123456U; |
| 156 size_t index = kArbitraryValue; |
120 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, | 157 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, |
121 SafeBrowsingDatabaseManager::GetUrlThreatType( | 158 SafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
122 kMalwareUrl, full_hashes, &index)); | 159 kMalwareUrl, full_hashes, &index)); |
123 EXPECT_EQ(0U, index); | 160 EXPECT_EQ(0U, index); |
124 | 161 |
125 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING, | 162 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING, |
126 SafeBrowsingDatabaseManager::GetUrlThreatType( | 163 SafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
127 kPhishingUrl, full_hashes, &index)); | 164 kPhishingUrl, full_hashes, &index)); |
128 EXPECT_EQ(1U, index); | 165 EXPECT_EQ(1U, index); |
129 | 166 |
130 index = 100; | 167 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, |
| 168 SafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
| 169 kUnwantedUrl, full_hashes, &index)); |
| 170 EXPECT_EQ(2U, index); |
| 171 |
| 172 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, |
| 173 SafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
| 174 kUnwantedAndMalwareUrl, full_hashes, &index)); |
| 175 EXPECT_EQ(3U, index); |
| 176 |
| 177 index = kArbitraryValue; |
131 EXPECT_EQ(SB_THREAT_TYPE_SAFE, | 178 EXPECT_EQ(SB_THREAT_TYPE_SAFE, |
132 SafeBrowsingDatabaseManager::GetUrlThreatType( | 179 SafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
133 kSafeUrl, full_hashes, &index)); | 180 kSafeUrl, full_hashes, &index)); |
134 EXPECT_EQ(100U, index); | 181 EXPECT_EQ(kArbitraryValue, index); |
135 } | 182 } |
OLD | NEW |