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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 142 } |
143 | 143 |
144 TEST_F(SafeBrowsingDatabaseManagerTest, GetUrlSeverestThreatType) { | 144 TEST_F(SafeBrowsingDatabaseManagerTest, GetUrlSeverestThreatType) { |
145 std::vector<SBFullHashResult> full_hashes; | 145 std::vector<SBFullHashResult> full_hashes; |
146 | 146 |
147 const GURL kMalwareUrl("http://www.malware.com/page.html"); | 147 const GURL kMalwareUrl("http://www.malware.com/page.html"); |
148 const GURL kPhishingUrl("http://www.phishing.com/page.html"); | 148 const GURL kPhishingUrl("http://www.phishing.com/page.html"); |
149 const GURL kUnwantedUrl("http://www.unwanted.com/page.html"); | 149 const GURL kUnwantedUrl("http://www.unwanted.com/page.html"); |
150 const GURL kUnwantedAndMalwareUrl( | 150 const GURL kUnwantedAndMalwareUrl( |
151 "http://www.unwantedandmalware.com/page.html"); | 151 "http://www.unwantedandmalware.com/page.html"); |
| 152 const GURL kBlacklistedResourceUrl("http://www.blacklisted.com/script.js"); |
| 153 const GURL kUnwantedResourceUrl("http://www.unwantedresource.com/script.js"); |
| 154 const GURL kMalwareResourceUrl("http://www.malwareresource.com/script.js"); |
152 const GURL kSafeUrl("http://www.safe.com/page.html"); | 155 const GURL kSafeUrl("http://www.safe.com/page.html"); |
153 | 156 |
154 const SBFullHash kMalwareHostHash = SBFullHashForString("malware.com/"); | 157 const SBFullHash kMalwareHostHash = SBFullHashForString("malware.com/"); |
155 const SBFullHash kPhishingHostHash = SBFullHashForString("phishing.com/"); | 158 const SBFullHash kPhishingHostHash = SBFullHashForString("phishing.com/"); |
156 const SBFullHash kUnwantedHostHash = SBFullHashForString("unwanted.com/"); | 159 const SBFullHash kUnwantedHostHash = SBFullHashForString("unwanted.com/"); |
157 const SBFullHash kUnwantedAndMalwareHostHash = | 160 const SBFullHash kUnwantedAndMalwareHostHash = |
158 SBFullHashForString("unwantedandmalware.com/"); | 161 SBFullHashForString("unwantedandmalware.com/"); |
| 162 const SBFullHash kBlacklistedResourceHostHash = |
| 163 SBFullHashForString("blacklisted.com/"); |
| 164 const SBFullHash kUnwantedResourceHostHash = |
| 165 SBFullHashForString("unwantedresource.com/"); |
| 166 const SBFullHash kMalwareResourceHostHash = |
| 167 SBFullHashForString("malwareresource.com/"); |
159 const SBFullHash kSafeHostHash = SBFullHashForString("www.safe.com/"); | 168 const SBFullHash kSafeHostHash = SBFullHashForString("www.safe.com/"); |
160 | 169 |
161 { | 170 { |
162 SBFullHashResult full_hash; | 171 SBFullHashResult full_hash; |
163 full_hash.hash = kMalwareHostHash; | 172 full_hash.hash = kMalwareHostHash; |
164 full_hash.list_id = static_cast<int>(MALWARE); | 173 full_hash.list_id = static_cast<int>(MALWARE); |
165 full_hashes.push_back(full_hash); | 174 full_hashes.push_back(full_hash); |
166 } | 175 } |
167 | 176 |
168 { | 177 { |
169 SBFullHashResult full_hash; | 178 SBFullHashResult full_hash; |
170 full_hash.hash = kPhishingHostHash; | 179 full_hash.hash = kPhishingHostHash; |
171 full_hash.list_id = static_cast<int>(PHISH); | 180 full_hash.list_id = static_cast<int>(PHISH); |
172 full_hashes.push_back(full_hash); | 181 full_hashes.push_back(full_hash); |
173 } | 182 } |
174 | 183 |
175 { | 184 { |
176 SBFullHashResult full_hash; | 185 SBFullHashResult full_hash; |
177 full_hash.hash = kUnwantedHostHash; | 186 full_hash.hash = kUnwantedHostHash; |
178 full_hash.list_id = static_cast<int>(UNWANTEDURL); | 187 full_hash.list_id = static_cast<int>(UNWANTEDURL); |
179 full_hashes.push_back(full_hash); | 188 full_hashes.push_back(full_hash); |
180 } | 189 } |
181 | 190 |
182 { | 191 { |
| 192 SBFullHashResult full_hash; |
| 193 full_hash.hash = kBlacklistedResourceHostHash; |
| 194 full_hash.list_id = static_cast<int>(RESOURCEBLACKLIST); |
| 195 full_hashes.push_back(full_hash); |
| 196 } |
| 197 |
| 198 { |
183 // Add both MALWARE and UNWANTEDURL list IDs for | 199 // Add both MALWARE and UNWANTEDURL list IDs for |
184 // kUnwantedAndMalwareHostHash. | 200 // kUnwantedAndMalwareHostHash. |
185 SBFullHashResult full_hash_malware; | 201 SBFullHashResult full_hash_malware; |
186 full_hash_malware.hash = kUnwantedAndMalwareHostHash; | 202 full_hash_malware.hash = kUnwantedAndMalwareHostHash; |
187 full_hash_malware.list_id = static_cast<int>(MALWARE); | 203 full_hash_malware.list_id = static_cast<int>(MALWARE); |
188 full_hashes.push_back(full_hash_malware); | 204 full_hashes.push_back(full_hash_malware); |
189 | 205 |
190 SBFullHashResult full_hash_unwanted; | 206 SBFullHashResult full_hash_unwanted; |
191 full_hash_unwanted.hash = kUnwantedAndMalwareHostHash; | 207 full_hash_unwanted.hash = kUnwantedAndMalwareHostHash; |
192 full_hash_unwanted.list_id = static_cast<int>(UNWANTEDURL); | 208 full_hash_unwanted.list_id = static_cast<int>(UNWANTEDURL); |
193 full_hashes.push_back(full_hash_unwanted); | 209 full_hashes.push_back(full_hash_unwanted); |
194 } | 210 } |
195 | 211 |
| 212 { |
| 213 SBFullHashResult full_hash_unwanted = |
| 214 {kUnwantedResourceHostHash, static_cast<int>(UNWANTEDURL)}; |
| 215 full_hashes.push_back(full_hash_unwanted); |
| 216 |
| 217 SBFullHashResult full_hash_resource = |
| 218 {kUnwantedResourceHostHash, static_cast<int>(RESOURCEBLACKLIST)}; |
| 219 full_hashes.push_back(full_hash_resource); |
| 220 } |
| 221 |
| 222 { |
| 223 SBFullHashResult full_hash_malware = |
| 224 {kMalwareResourceHostHash, static_cast<int>(MALWARE)}; |
| 225 full_hashes.push_back(full_hash_malware); |
| 226 |
| 227 SBFullHashResult full_hash_resource = |
| 228 {kMalwareResourceHostHash, static_cast<int>(RESOURCEBLACKLIST)}; |
| 229 full_hashes.push_back(full_hash_resource); |
| 230 } |
| 231 |
196 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, | 232 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, |
197 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( | 233 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
198 kMalwareHostHash, full_hashes)); | 234 kMalwareHostHash, full_hashes)); |
199 | 235 |
200 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING, | 236 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING, |
201 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( | 237 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
202 kPhishingHostHash, full_hashes)); | 238 kPhishingHostHash, full_hashes)); |
203 | 239 |
204 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, | 240 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, |
205 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( | 241 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
206 kUnwantedHostHash, full_hashes)); | 242 kUnwantedHostHash, full_hashes)); |
207 | 243 |
208 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, | 244 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, |
209 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( | 245 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
210 kUnwantedAndMalwareHostHash, full_hashes)); | 246 kUnwantedAndMalwareHostHash, full_hashes)); |
211 | 247 |
| 248 EXPECT_EQ(SB_THREAT_TYPE_BLACKLISTED_RESOURCE, |
| 249 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
| 250 kBlacklistedResourceHostHash, full_hashes)); |
| 251 |
| 252 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, |
| 253 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
| 254 kUnwantedResourceHostHash, full_hashes)); |
| 255 |
| 256 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, |
| 257 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
| 258 kMalwareResourceHostHash, full_hashes)); |
| 259 |
212 EXPECT_EQ(SB_THREAT_TYPE_SAFE, | 260 EXPECT_EQ(SB_THREAT_TYPE_SAFE, |
213 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( | 261 LocalSafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
214 kSafeHostHash, full_hashes)); | 262 kSafeHostHash, full_hashes)); |
215 | 263 |
216 const size_t kArbitraryValue = 123456U; | 264 const size_t kArbitraryValue = 123456U; |
217 size_t index = kArbitraryValue; | 265 size_t index = kArbitraryValue; |
218 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, | 266 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, |
219 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( | 267 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
220 kMalwareUrl, full_hashes, &index)); | 268 kMalwareUrl, full_hashes, &index)); |
221 EXPECT_EQ(0U, index); | 269 EXPECT_EQ(0U, index); |
222 | 270 |
223 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING, | 271 EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING, |
224 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( | 272 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
225 kPhishingUrl, full_hashes, &index)); | 273 kPhishingUrl, full_hashes, &index)); |
226 EXPECT_EQ(1U, index); | 274 EXPECT_EQ(1U, index); |
227 | 275 |
228 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, | 276 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, |
229 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( | 277 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
230 kUnwantedUrl, full_hashes, &index)); | 278 kUnwantedUrl, full_hashes, &index)); |
231 EXPECT_EQ(2U, index); | 279 EXPECT_EQ(2U, index); |
232 | 280 |
| 281 EXPECT_EQ(SB_THREAT_TYPE_BLACKLISTED_RESOURCE, |
| 282 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
| 283 kBlacklistedResourceUrl, full_hashes, &index)); |
| 284 EXPECT_EQ(3U, index); |
| 285 |
233 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, | 286 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, |
234 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( | 287 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
235 kUnwantedAndMalwareUrl, full_hashes, &index)); | 288 kUnwantedAndMalwareUrl, full_hashes, &index)); |
236 EXPECT_EQ(3U, index); | 289 EXPECT_EQ(4U, index); |
| 290 |
| 291 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, |
| 292 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
| 293 kUnwantedResourceUrl, full_hashes, &index)); |
| 294 EXPECT_EQ(6U, index); |
| 295 |
| 296 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, |
| 297 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
| 298 kMalwareResourceUrl, full_hashes, &index)); |
| 299 EXPECT_EQ(8U, index); |
237 | 300 |
238 index = kArbitraryValue; | 301 index = kArbitraryValue; |
239 EXPECT_EQ(SB_THREAT_TYPE_SAFE, | 302 EXPECT_EQ(SB_THREAT_TYPE_SAFE, |
240 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( | 303 LocalSafeBrowsingDatabaseManager::GetUrlSeverestThreatType( |
241 kSafeUrl, full_hashes, &index)); | 304 kSafeUrl, full_hashes, &index)); |
242 EXPECT_EQ(kArbitraryValue, index); | 305 EXPECT_EQ(kArbitraryValue, index); |
243 } | 306 } |
244 | 307 |
245 TEST_F(SafeBrowsingDatabaseManagerTest, ServiceStopWithPendingChecks) { | 308 TEST_F(SafeBrowsingDatabaseManagerTest, ServiceStopWithPendingChecks) { |
246 scoped_refptr<SafeBrowsingService> sb_service( | 309 scoped_refptr<SafeBrowsingService> sb_service( |
(...skipping 16 matching lines...) Expand all Loading... |
263 // Stop the service without first flushing above tasks. | 326 // Stop the service without first flushing above tasks. |
264 db_manager->StopOnIOThread(false); | 327 db_manager->StopOnIOThread(false); |
265 | 328 |
266 // Now run posted tasks, whish should include the extension check which has | 329 // Now run posted tasks, whish should include the extension check which has |
267 // been posted to the safe browsing task runner. This should not crash. | 330 // been posted to the safe browsing task runner. This should not crash. |
268 content::RunAllBlockingPoolTasksUntilIdle(); | 331 content::RunAllBlockingPoolTasksUntilIdle(); |
269 base::RunLoop().RunUntilIdle(); | 332 base::RunLoop().RunUntilIdle(); |
270 } | 333 } |
271 | 334 |
272 } // namespace safe_browsing | 335 } // namespace safe_browsing |
OLD | NEW |