| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/safe_browsing/download_protection_service.h" | 5 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 207 |
| 208 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { | 208 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { |
| 209 DownloadProtectionService::DownloadInfo info; | 209 DownloadProtectionService::DownloadInfo info; |
| 210 download_service_->CheckClientDownload( | 210 download_service_->CheckClientDownload( |
| 211 info, | 211 info, |
| 212 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 212 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 213 base::Unretained(this))); | 213 base::Unretained(this))); |
| 214 msg_loop_.Run(); | 214 msg_loop_.Run(); |
| 215 EXPECT_EQ(DownloadProtectionService::SAFE, result_); | 215 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
| 216 | 216 |
| 217 // Only http is supported for now. | 217 // Only https is not supported for now for privacy reasons. |
| 218 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 218 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); |
| 219 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 219 info.download_url_chain.push_back(GURL("https://www.google.com/")); | 220 info.download_url_chain.push_back(GURL("https://www.google.com/")); |
| 220 download_service_->CheckClientDownload( | 221 download_service_->CheckClientDownload( |
| 221 info, | 222 info, |
| 222 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 223 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 223 base::Unretained(this))); | 224 base::Unretained(this))); |
| 224 msg_loop_.Run(); | 225 msg_loop_.Run(); |
| 225 EXPECT_EQ(DownloadProtectionService::SAFE, result_); | 226 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
| 226 | |
| 227 info.download_url_chain[0] = GURL("ftp://www.google.com/"); | |
| 228 download_service_->CheckClientDownload( | |
| 229 info, | |
| 230 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | |
| 231 base::Unretained(this))); | |
| 232 msg_loop_.Run(); | |
| 233 EXPECT_EQ(DownloadProtectionService::SAFE, result_); | |
| 234 } | 227 } |
| 235 | 228 |
| 236 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadWhitelistedUrl) { | 229 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadWhitelistedUrl) { |
| 237 DownloadProtectionService::DownloadInfo info; | 230 DownloadProtectionService::DownloadInfo info; |
| 238 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 231 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); |
| 232 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 239 info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe")); | 233 info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe")); |
| 240 info.download_url_chain.push_back(GURL("http://www.google.com/a.exe")); | 234 info.download_url_chain.push_back(GURL("http://www.google.com/a.exe")); |
| 241 info.referrer_url = GURL("http://www.google.com/"); | 235 info.referrer_url = GURL("http://www.google.com/"); |
| 242 | 236 |
| 243 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) | 237 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) |
| 244 .WillRepeatedly(Return(false)); | 238 .WillRepeatedly(Return(false)); |
| 245 EXPECT_CALL(*sb_service_, | 239 EXPECT_CALL(*sb_service_, |
| 246 MatchDownloadWhitelistUrl(GURL("http://www.google.com/a.exe"))) | 240 MatchDownloadWhitelistUrl(GURL("http://www.google.com/a.exe"))) |
| 247 .WillRepeatedly(Return(true)); | 241 .WillRepeatedly(Return(true)); |
| 248 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(2); | 242 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(2); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 265 EXPECT_EQ(DownloadProtectionService::SAFE, result_); | 259 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
| 266 } | 260 } |
| 267 | 261 |
| 268 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { | 262 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { |
| 269 FakeURLFetcherFactory factory; | 263 FakeURLFetcherFactory factory; |
| 270 // HTTP request will fail. | 264 // HTTP request will fail. |
| 271 factory.SetFakeResponse( | 265 factory.SetFakeResponse( |
| 272 DownloadProtectionService::kDownloadRequestUrl, "", false); | 266 DownloadProtectionService::kDownloadRequestUrl, "", false); |
| 273 | 267 |
| 274 DownloadProtectionService::DownloadInfo info; | 268 DownloadProtectionService::DownloadInfo info; |
| 275 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 269 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); |
| 270 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 276 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); | 271 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); |
| 277 info.referrer_url = GURL("http://www.google.com/"); | 272 info.referrer_url = GURL("http://www.google.com/"); |
| 278 | 273 |
| 279 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) | 274 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) |
| 280 .WillRepeatedly(Return(false)); | 275 .WillRepeatedly(Return(false)); |
| 281 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); | 276 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); |
| 282 | 277 |
| 283 download_service_->CheckClientDownload( | 278 download_service_->CheckClientDownload( |
| 284 info, | 279 info, |
| 285 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 280 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 286 base::Unretained(this))); | 281 base::Unretained(this))); |
| 287 msg_loop_.Run(); | 282 msg_loop_.Run(); |
| 288 EXPECT_EQ(DownloadProtectionService::SAFE, result_); | 283 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
| 289 } | 284 } |
| 290 | 285 |
| 291 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { | 286 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { |
| 292 ClientDownloadResponse response; | 287 ClientDownloadResponse response; |
| 293 response.set_verdict(ClientDownloadResponse::SAFE); | 288 response.set_verdict(ClientDownloadResponse::SAFE); |
| 294 FakeURLFetcherFactory factory; | 289 FakeURLFetcherFactory factory; |
| 295 // Empty response means SAFE. | 290 // Empty response means SAFE. |
| 296 factory.SetFakeResponse( | 291 factory.SetFakeResponse( |
| 297 DownloadProtectionService::kDownloadRequestUrl, | 292 DownloadProtectionService::kDownloadRequestUrl, |
| 298 response.SerializeAsString(), | 293 response.SerializeAsString(), |
| 299 true); | 294 true); |
| 300 | 295 |
| 301 DownloadProtectionService::DownloadInfo info; | 296 DownloadProtectionService::DownloadInfo info; |
| 302 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 297 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); |
| 298 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 303 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); | 299 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); |
| 304 info.referrer_url = GURL("http://www.google.com/"); | 300 info.referrer_url = GURL("http://www.google.com/"); |
| 305 | 301 |
| 306 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) | 302 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) |
| 307 .WillRepeatedly(Return(false)); | 303 .WillRepeatedly(Return(false)); |
| 308 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(3); | 304 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(3); |
| 309 | 305 |
| 310 download_service_->CheckClientDownload( | 306 download_service_->CheckClientDownload( |
| 311 info, | 307 info, |
| 312 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 308 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 340 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 336 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 341 base::Unretained(this))); | 337 base::Unretained(this))); |
| 342 msg_loop_.Run(); | 338 msg_loop_.Run(); |
| 343 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); | 339 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); |
| 344 } | 340 } |
| 345 | 341 |
| 346 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { | 342 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { |
| 347 TestURLFetcherFactory factory; | 343 TestURLFetcherFactory factory; |
| 348 | 344 |
| 349 DownloadProtectionService::DownloadInfo info; | 345 DownloadProtectionService::DownloadInfo info; |
| 350 info.local_file = FilePath(FILE_PATH_LITERAL("bla.exe")); | 346 info.local_file = FilePath(FILE_PATH_LITERAL("bla.tmp")); |
| 347 info.target_file = FilePath(FILE_PATH_LITERAL("bla.exe")); |
| 351 info.download_url_chain.push_back(GURL("http://www.google.com/")); | 348 info.download_url_chain.push_back(GURL("http://www.google.com/")); |
| 352 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); | 349 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); |
| 353 info.referrer_url = GURL("http://www.google.com/"); | 350 info.referrer_url = GURL("http://www.google.com/"); |
| 354 info.sha256_hash = "hash"; | 351 info.sha256_hash = "hash"; |
| 355 info.total_bytes = 100; | 352 info.total_bytes = 100; |
| 356 info.user_initiated = false; | 353 info.user_initiated = false; |
| 357 | 354 |
| 358 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) | 355 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) |
| 359 .WillRepeatedly(Return(false)); | 356 .WillRepeatedly(Return(false)); |
| 360 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)) | 357 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 base::Unretained(this), fetcher)); | 391 base::Unretained(this), fetcher)); |
| 395 msg_loop_.Run(); | 392 msg_loop_.Run(); |
| 396 } | 393 } |
| 397 | 394 |
| 398 // Similar to above, but with an unsigned binary. | 395 // Similar to above, but with an unsigned binary. |
| 399 TEST_F(DownloadProtectionServiceTest, | 396 TEST_F(DownloadProtectionServiceTest, |
| 400 CheckClientDownloadValidateRequestNoSignature) { | 397 CheckClientDownloadValidateRequestNoSignature) { |
| 401 TestURLFetcherFactory factory; | 398 TestURLFetcherFactory factory; |
| 402 | 399 |
| 403 DownloadProtectionService::DownloadInfo info; | 400 DownloadProtectionService::DownloadInfo info; |
| 404 info.local_file = FilePath(FILE_PATH_LITERAL("bla.exe")); | 401 info.local_file = FilePath(FILE_PATH_LITERAL("bla.tmp")); |
| 402 info.target_file = FilePath(FILE_PATH_LITERAL("bla.exe")); |
| 405 info.download_url_chain.push_back(GURL("http://www.google.com/")); | 403 info.download_url_chain.push_back(GURL("http://www.google.com/")); |
| 406 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); | 404 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); |
| 407 info.referrer_url = GURL("http://www.google.com/"); | 405 info.referrer_url = GURL("http://www.google.com/"); |
| 408 info.sha256_hash = "hash"; | 406 info.sha256_hash = "hash"; |
| 409 info.total_bytes = 100; | 407 info.total_bytes = 100; |
| 410 info.user_initiated = false; | 408 info.user_initiated = false; |
| 411 | 409 |
| 412 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) | 410 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) |
| 413 .WillRepeatedly(Return(false)); | 411 .WillRepeatedly(Return(false)); |
| 414 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); | 412 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 442 // Simulate the request finishing. | 440 // Simulate the request finishing. |
| 443 MessageLoop::current()->PostTask( | 441 MessageLoop::current()->PostTask( |
| 444 FROM_HERE, | 442 FROM_HERE, |
| 445 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, | 443 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, |
| 446 base::Unretained(this), fetcher)); | 444 base::Unretained(this), fetcher)); |
| 447 msg_loop_.Run(); | 445 msg_loop_.Run(); |
| 448 } | 446 } |
| 449 | 447 |
| 450 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadDigestList) { | 448 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadDigestList) { |
| 451 DownloadProtectionService::DownloadInfo info; | 449 DownloadProtectionService::DownloadInfo info; |
| 452 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 450 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); |
| 451 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 452 |
| 453 // HTTPs URLs never result in a server ping for privacy reasons. However, | 453 // HTTPs URLs never result in a server ping for privacy reasons. However, |
| 454 // we do lookup the bad binary digest list. | 454 // we do lookup the bad binary digest list. |
| 455 info.download_url_chain.push_back(GURL("https://www.evil.com/a.exe")); | 455 info.download_url_chain.push_back(GURL("https://www.evil.com/a.exe")); |
| 456 info.referrer_url = GURL("http://www.google.com/"); | 456 info.referrer_url = GURL("http://www.google.com/"); |
| 457 info.sha256_hash = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; | 457 info.sha256_hash = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; |
| 458 | 458 |
| 459 // CheckDownloadHash returns immediately which means the hash is not | 459 // CheckDownloadHash returns immediately which means the hash is not |
| 460 // malicious. | 460 // malicious. |
| 461 EXPECT_CALL(*sb_service_, | 461 EXPECT_CALL(*sb_service_, |
| 462 CheckDownloadHash(info.sha256_hash, NotNull())) | 462 CheckDownloadHash(info.sha256_hash, NotNull())) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 491 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_URL), | 491 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_URL), |
| 492 Return(false))); | 492 Return(false))); |
| 493 download_service_->CheckClientDownload( | 493 download_service_->CheckClientDownload( |
| 494 info, | 494 info, |
| 495 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 495 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 496 base::Unretained(this))); | 496 base::Unretained(this))); |
| 497 msg_loop_.Run(); | 497 msg_loop_.Run(); |
| 498 EXPECT_EQ(DownloadProtectionService::SAFE, result_); | 498 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
| 499 Mock::VerifyAndClearExpectations(sb_service_); | 499 Mock::VerifyAndClearExpectations(sb_service_); |
| 500 | 500 |
| 501 // A match is found with the bad binary digest list. | 501 // A match is found with the bad binary digest list. We currently do not |
| 502 // warn based on the digest list. Hence we should always return SAFE. |
| 502 EXPECT_CALL(*sb_service_, | 503 EXPECT_CALL(*sb_service_, |
| 503 CheckDownloadHash(info.sha256_hash, NotNull())) | 504 CheckDownloadHash(info.sha256_hash, NotNull())) |
| 504 .WillOnce(DoAll( | 505 .WillOnce(DoAll( |
| 505 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH), | 506 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH), |
| 506 Return(false))); | 507 Return(false))); |
| 507 download_service_->CheckClientDownload( | 508 download_service_->CheckClientDownload( |
| 508 info, | 509 info, |
| 509 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 510 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 510 base::Unretained(this))); | 511 base::Unretained(this))); |
| 511 msg_loop_.Run(); | 512 msg_loop_.Run(); |
| 512 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); | 513 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
| 513 Mock::VerifyAndClearExpectations(sb_service_); | 514 Mock::VerifyAndClearExpectations(sb_service_); |
| 514 | 515 |
| 515 // If the download is not an executable we do not send a server ping but we | 516 // If the download is not an executable we do not send a server ping but we |
| 516 // still want to lookup the binary digest list. | 517 // still want to lookup the binary digest list. |
| 517 info.local_file = FilePath(FILE_PATH_LITERAL("a.pdf")); | 518 info.target_file = FilePath(FILE_PATH_LITERAL("a.pdf")); |
| 518 info.download_url_chain[0] = GURL("http://www.evil.com/a.pdf"); | 519 info.download_url_chain[0] = GURL("http://www.evil.com/a.pdf"); |
| 519 EXPECT_CALL(*sb_service_, | 520 EXPECT_CALL(*sb_service_, |
| 520 CheckDownloadHash(info.sha256_hash, NotNull())) | 521 CheckDownloadHash(info.sha256_hash, NotNull())) |
| 521 .WillOnce(DoAll( | 522 .WillOnce(DoAll( |
| 522 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH), | 523 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH), |
| 523 Return(false))); | 524 Return(false))); |
| 524 download_service_->CheckClientDownload( | 525 download_service_->CheckClientDownload( |
| 525 info, | 526 info, |
| 526 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 527 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 527 base::Unretained(this))); | 528 base::Unretained(this))); |
| 528 msg_loop_.Run(); | 529 msg_loop_.Run(); |
| 529 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); | 530 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
| 530 Mock::VerifyAndClearExpectations(sb_service_); | 531 Mock::VerifyAndClearExpectations(sb_service_); |
| 531 | 532 |
| 532 // If the URL or the referrer matches the download whitelist we cannot send | 533 // If the URL or the referrer matches the download whitelist we cannot send |
| 533 // a server ping for privacy reasons but we still match the digest against | 534 // a server ping for privacy reasons but we still match the digest against |
| 534 // the bad binary digest list. | 535 // the bad binary digest list. |
| 535 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 536 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 536 info.download_url_chain[0] = GURL("http://www.evil.com/a.exe"); | 537 info.download_url_chain[0] = GURL("http://www.evil.com/a.exe"); |
| 537 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) | 538 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) |
| 538 .WillRepeatedly(Return(true)); | 539 .WillRepeatedly(Return(true)); |
| 539 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); | 540 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); |
| 540 EXPECT_CALL(*sb_service_, | 541 EXPECT_CALL(*sb_service_, |
| 541 CheckDownloadHash(info.sha256_hash, NotNull())) | 542 CheckDownloadHash(info.sha256_hash, NotNull())) |
| 542 .WillOnce(DoAll( | 543 .WillOnce(DoAll( |
| 543 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH), | 544 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH), |
| 544 Return(false))); | 545 Return(false))); |
| 545 download_service_->CheckClientDownload( | 546 download_service_->CheckClientDownload( |
| 546 info, | 547 info, |
| 547 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 548 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 548 base::Unretained(this))); | 549 base::Unretained(this))); |
| 549 msg_loop_.Run(); | 550 msg_loop_.Run(); |
| 550 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); | 551 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
| 551 } | 552 } |
| 552 | 553 |
| 553 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { | 554 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { |
| 554 DownloadProtectionService::DownloadInfo info; | 555 DownloadProtectionService::DownloadInfo info; |
| 555 info.download_url_chain.push_back(GURL("http://www.google.com/")); | 556 info.download_url_chain.push_back(GURL("http://www.google.com/")); |
| 556 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); | 557 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); |
| 557 info.referrer_url = GURL("http://www.google.com/"); | 558 info.referrer_url = GURL("http://www.google.com/"); |
| 558 | 559 |
| 559 // CheckDownloadURL returns immediately which means the client object callback | 560 // CheckDownloadURL returns immediately which means the client object callback |
| 560 // will never be called. Nevertheless the callback provided to | 561 // will never be called. Nevertheless the callback provided to |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 CheckDownloadUrlDone(SafeBrowsingService::BINARY_MALWARE_URL), | 606 CheckDownloadUrlDone(SafeBrowsingService::BINARY_MALWARE_URL), |
| 606 Return(false))); | 607 Return(false))); |
| 607 download_service_->CheckDownloadUrl( | 608 download_service_->CheckDownloadUrl( |
| 608 info, | 609 info, |
| 609 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 610 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 610 base::Unretained(this))); | 611 base::Unretained(this))); |
| 611 msg_loop_.Run(); | 612 msg_loop_.Run(); |
| 612 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); | 613 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); |
| 613 } | 614 } |
| 614 } // namespace safe_browsing | 615 } // namespace safe_browsing |
| OLD | NEW |