OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdint.h> | 7 #include <stdint.h> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
17 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
21 #include "base/path_service.h" | 21 #include "base/path_service.h" |
| 22 #include "base/prefs/pref_service.h" |
22 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
23 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
24 #include "base/threading/sequenced_worker_pool.h" | 25 #include "base/threading/sequenced_worker_pool.h" |
25 #include "chrome/browser/history/history_service_factory.h" | 26 #include "chrome/browser/history/history_service_factory.h" |
26 #include "chrome/browser/safe_browsing/database_manager.h" | 27 #include "chrome/browser/safe_browsing/database_manager.h" |
27 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 28 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
28 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" | 29 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" |
29 #include "chrome/browser/safe_browsing/local_database_manager.h" | 30 #include "chrome/browser/safe_browsing/local_database_manager.h" |
30 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 31 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
31 #include "chrome/browser/safe_browsing/test_database_manager.h" | 32 #include "chrome/browser/safe_browsing/test_database_manager.h" |
32 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/common/pref_names.h" |
33 #include "chrome/common/safe_browsing/binary_feature_extractor.h" | 35 #include "chrome/common/safe_browsing/binary_feature_extractor.h" |
34 #include "chrome/common/safe_browsing/csd.pb.h" | 36 #include "chrome/common/safe_browsing/csd.pb.h" |
35 #include "chrome/test/base/testing_profile.h" | 37 #include "chrome/test/base/testing_profile.h" |
36 #include "components/history/core/browser/history_service.h" | 38 #include "components/history/core/browser/history_service.h" |
37 #include "content/public/browser/download_danger_type.h" | 39 #include "content/public/browser/download_danger_type.h" |
38 #include "content/public/browser/page_navigator.h" | 40 #include "content/public/browser/page_navigator.h" |
39 #include "content/public/test/mock_download_item.h" | 41 #include "content/public/test/mock_download_item.h" |
40 #include "content/public/test/test_browser_thread_bundle.h" | 42 #include "content/public/test/test_browser_thread_bundle.h" |
41 #include "content/public/test/test_utils.h" | 43 #include "content/public/test/test_utils.h" |
42 #include "net/base/url_util.h" | 44 #include "net/base/url_util.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 has_result_ = false; | 238 has_result_ = false; |
237 | 239 |
238 base::FilePath source_path; | 240 base::FilePath source_path; |
239 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_path)); | 241 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_path)); |
240 testdata_path_ = source_path | 242 testdata_path_ = source_path |
241 .AppendASCII("chrome") | 243 .AppendASCII("chrome") |
242 .AppendASCII("test") | 244 .AppendASCII("test") |
243 .AppendASCII("data") | 245 .AppendASCII("data") |
244 .AppendASCII("safe_browsing") | 246 .AppendASCII("safe_browsing") |
245 .AppendASCII("download_protection"); | 247 .AppendASCII("download_protection"); |
| 248 |
| 249 // Setup a profile |
| 250 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
| 251 profile_.reset(new TestingProfile(profile_dir_.path())); |
| 252 ASSERT_TRUE(profile_->CreateHistoryService(true /* delete_file */, |
| 253 false /* no_db */)); |
246 } | 254 } |
247 | 255 |
248 void TearDown() override { | 256 void TearDown() override { |
249 client_download_request_subscription_.reset(); | 257 client_download_request_subscription_.reset(); |
250 sb_service_->ShutDown(); | 258 sb_service_->ShutDown(); |
251 // Flush all of the thread message loops to ensure that there are no | 259 // Flush all of the thread message loops to ensure that there are no |
252 // tasks currently running. | 260 // tasks currently running. |
253 FlushThreadMessageLoops(); | 261 FlushThreadMessageLoops(); |
254 sb_service_ = NULL; | 262 sb_service_ = NULL; |
255 } | 263 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 testing::AssertionResult IsResult( | 403 testing::AssertionResult IsResult( |
396 DownloadProtectionService::DownloadCheckResult expected) { | 404 DownloadProtectionService::DownloadCheckResult expected) { |
397 if (!has_result_) | 405 if (!has_result_) |
398 return testing::AssertionFailure() << "No result"; | 406 return testing::AssertionFailure() << "No result"; |
399 has_result_ = false; | 407 has_result_ = false; |
400 return result_ == expected ? | 408 return result_ == expected ? |
401 testing::AssertionSuccess() : | 409 testing::AssertionSuccess() : |
402 testing::AssertionFailure() << "Expected " << expected << | 410 testing::AssertionFailure() << "Expected " << expected << |
403 ", got " << result_; | 411 ", got " << result_; |
404 } | 412 } |
| 413 // Check scenarios where we should/shouldn't send a report for |
| 414 // a corrupted zip. |
| 415 void CheckClientDownloadReportCorruptZip(bool is_extended_reporting, |
| 416 bool is_incognito); |
| 417 |
405 | 418 |
406 protected: | 419 protected: |
407 scoped_refptr<FakeSafeBrowsingService> sb_service_; | 420 scoped_refptr<FakeSafeBrowsingService> sb_service_; |
408 scoped_refptr<MockBinaryFeatureExtractor> binary_feature_extractor_; | 421 scoped_refptr<MockBinaryFeatureExtractor> binary_feature_extractor_; |
409 DownloadProtectionService* download_service_; | 422 DownloadProtectionService* download_service_; |
410 DownloadProtectionService::DownloadCheckResult result_; | 423 DownloadProtectionService::DownloadCheckResult result_; |
411 bool has_result_; | 424 bool has_result_; |
412 content::TestBrowserThreadBundle test_browser_thread_bundle_; | 425 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
413 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; | 426 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; |
414 base::FilePath testdata_path_; | 427 base::FilePath testdata_path_; |
415 DownloadProtectionService::ClientDownloadRequestSubscription | 428 DownloadProtectionService::ClientDownloadRequestSubscription |
416 client_download_request_subscription_; | 429 client_download_request_subscription_; |
417 scoped_ptr<ClientDownloadRequest> last_client_download_request_; | 430 scoped_ptr<ClientDownloadRequest> last_client_download_request_; |
| 431 base::ScopedTempDir profile_dir_; |
| 432 scoped_ptr<TestingProfile> profile_; |
418 }; | 433 }; |
419 | 434 |
| 435 |
| 436 void DownloadProtectionServiceTest::CheckClientDownloadReportCorruptZip( |
| 437 bool is_extended_reporting, |
| 438 bool is_incognito) { |
| 439 ClientDownloadResponse response; |
| 440 response.set_verdict(ClientDownloadResponse::SAFE); |
| 441 net::FakeURLFetcherFactory factory(NULL); |
| 442 // Empty response means SAFE. |
| 443 factory.SetFakeResponse( |
| 444 DownloadProtectionService::GetDownloadRequestUrl(), |
| 445 response.SerializeAsString(), |
| 446 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 447 |
| 448 base::ScopedTempDir download_dir; |
| 449 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); |
| 450 |
| 451 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"))); |
| 452 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip")); |
| 453 std::vector<GURL> url_chain; |
| 454 url_chain.push_back(GURL("http://www.evil.com/a.zip")); |
| 455 GURL referrer("http://www.google.com/"); |
| 456 std::string hash = "hash"; |
| 457 profile_->GetPrefs()->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, |
| 458 is_extended_reporting); |
| 459 |
| 460 content::MockDownloadItem item; |
| 461 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); |
| 462 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_zip)); |
| 463 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); |
| 464 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); |
| 465 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(GURL::EmptyGURL())); |
| 466 EXPECT_CALL(item, GetTabReferrerUrl()) |
| 467 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); |
| 468 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); |
| 469 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); |
| 470 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); |
| 471 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); |
| 472 |
| 473 if (is_incognito) { |
| 474 EXPECT_CALL(item, GetBrowserContext()) |
| 475 .WillRepeatedly(Return(profile_->GetOffTheRecordProfile())); |
| 476 } else { |
| 477 EXPECT_CALL(item, GetBrowserContext()) |
| 478 .WillRepeatedly(Return(profile_.get())); |
| 479 } |
| 480 |
| 481 std::string file_contents = "corrupt zip file"; |
| 482 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile( |
| 483 a_tmp, file_contents.data(), file_contents.size())); |
| 484 |
| 485 download_service_->CheckClientDownload( |
| 486 &item, |
| 487 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 488 base::Unretained(this))); |
| 489 MessageLoop::current()->Run(); |
| 490 |
| 491 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 492 const bool expect_request = is_extended_reporting && !is_incognito; |
| 493 #else |
| 494 // For !(OS_WIN || OS_MACOSX || OS_CHROMEOS), |
| 495 // no file types are currently supported. |
| 496 const bool expect_request = false; |
| 497 #endif |
| 498 |
| 499 if (expect_request) { |
| 500 ASSERT_TRUE(HasClientDownloadRequest()); |
| 501 EXPECT_EQ(0, GetClientDownloadRequest()->archived_binary_size()); |
| 502 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type()); |
| 503 EXPECT_EQ(ClientDownloadRequest_DownloadType_INVALID_ZIP, |
| 504 GetClientDownloadRequest()->download_type()); |
| 505 ClearClientDownloadRequest(); |
| 506 } else { |
| 507 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 508 EXPECT_FALSE(HasClientDownloadRequest()); |
| 509 } |
| 510 |
| 511 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 512 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 513 } |
| 514 |
| 515 |
420 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { | 516 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { |
421 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); | 517 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); |
422 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); | 518 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); |
423 std::vector<GURL> url_chain; | 519 std::vector<GURL> url_chain; |
424 GURL referrer("http://www.google.com/"); | 520 GURL referrer("http://www.google.com/"); |
425 std::string hash = "hash"; | 521 std::string hash = "hash"; |
426 | 522 |
427 content::MockDownloadItem item; | 523 content::MockDownloadItem item; |
428 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); | 524 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); |
429 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe)); | 525 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe)); |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 #else | 1272 #else |
1177 // For !(OS_WIN || OS_MACOSX || OS_CHROMEOS), | 1273 // For !(OS_WIN || OS_MACOSX || OS_CHROMEOS), |
1178 // no file types are currently supported. Hence | 1274 // no file types are currently supported. Hence |
1179 // the resulting verdict is UNKNOWN. | 1275 // the resulting verdict is UNKNOWN. |
1180 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1276 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
1181 EXPECT_FALSE(HasClientDownloadRequest()); | 1277 EXPECT_FALSE(HasClientDownloadRequest()); |
1182 #endif | 1278 #endif |
1183 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 1279 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
1184 } | 1280 } |
1185 | 1281 |
1186 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { | 1282 TEST_F(DownloadProtectionServiceTest, |
1187 base::ScopedTempDir download_dir; | 1283 CheckClientDownloadReportCorruptZipNormal) { |
1188 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); | 1284 // !is_extended_reporting && !is_incognito |
| 1285 CheckClientDownloadReportCorruptZip(false, false); |
| 1286 } |
1189 | 1287 |
1190 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"))); | 1288 TEST_F(DownloadProtectionServiceTest, |
1191 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip")); | 1289 CheckClientDownloadReportCorruptZipExtended) { |
1192 std::vector<GURL> url_chain; | 1290 // !is_extended_reporting && !is_incognito |
1193 url_chain.push_back(GURL("http://www.evil.com/a.zip")); | 1291 CheckClientDownloadReportCorruptZip(true, false); |
1194 GURL referrer("http://www.google.com/"); | 1292 } |
1195 std::string hash = "hash"; | |
1196 | 1293 |
1197 content::MockDownloadItem item; | 1294 TEST_F(DownloadProtectionServiceTest, |
1198 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); | 1295 CheckClientDownloadReportCorruptZipIncognito) { |
1199 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_zip)); | 1296 // is_extended_reporting && is_incognito |
1200 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); | 1297 CheckClientDownloadReportCorruptZip(true, true); |
1201 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); | |
1202 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(GURL::EmptyGURL())); | |
1203 EXPECT_CALL(item, GetTabReferrerUrl()) | |
1204 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); | |
1205 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); | |
1206 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); | |
1207 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); | |
1208 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); | |
1209 | |
1210 std::string file_contents = "corrupt zip file"; | |
1211 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile( | |
1212 a_tmp, file_contents.data(), file_contents.size())); | |
1213 | |
1214 download_service_->CheckClientDownload( | |
1215 &item, | |
1216 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | |
1217 base::Unretained(this))); | |
1218 MessageLoop::current()->Run(); | |
1219 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | |
1220 EXPECT_FALSE(HasClientDownloadRequest()); | |
1221 Mock::VerifyAndClearExpectations(sb_service_.get()); | |
1222 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | |
1223 } | 1298 } |
1224 | 1299 |
1225 TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) { | 1300 TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) { |
1226 ClientDownloadResponse response; | 1301 ClientDownloadResponse response; |
1227 // Even if the server verdict is dangerous we should return SAFE because | 1302 // Even if the server verdict is dangerous we should return SAFE because |
1228 // DownloadProtectionService::IsSupportedDownload() will return false | 1303 // DownloadProtectionService::IsSupportedDownload() will return false |
1229 // for crx downloads. | 1304 // for crx downloads. |
1230 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 1305 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
1231 net::FakeURLFetcherFactory factory(NULL); | 1306 net::FakeURLFetcherFactory factory(NULL); |
1232 // Empty response means SAFE. | 1307 // Empty response means SAFE. |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 base::Unretained(this), fetcher)); | 1516 base::Unretained(this), fetcher)); |
1442 MessageLoop::current()->Run(); | 1517 MessageLoop::current()->Run(); |
1443 #endif | 1518 #endif |
1444 } | 1519 } |
1445 | 1520 |
1446 // Similar to above, but with tab history. | 1521 // Similar to above, but with tab history. |
1447 TEST_F(DownloadProtectionServiceTest, | 1522 TEST_F(DownloadProtectionServiceTest, |
1448 CheckClientDownloadValidateRequestTabHistory) { | 1523 CheckClientDownloadValidateRequestTabHistory) { |
1449 net::TestURLFetcherFactory factory; | 1524 net::TestURLFetcherFactory factory; |
1450 | 1525 |
1451 base::ScopedTempDir profile_dir; | |
1452 ASSERT_TRUE(profile_dir.CreateUniqueTempDir()); | |
1453 TestingProfile profile(profile_dir.path()); | |
1454 ASSERT_TRUE( | |
1455 profile.CreateHistoryService(true /* delete_file */, false /* no_db */)); | |
1456 | |
1457 base::FilePath tmp_path(FILE_PATH_LITERAL("bla.tmp")); | 1526 base::FilePath tmp_path(FILE_PATH_LITERAL("bla.tmp")); |
1458 base::FilePath final_path(FILE_PATH_LITERAL("bla.exe")); | 1527 base::FilePath final_path(FILE_PATH_LITERAL("bla.exe")); |
1459 std::vector<GURL> url_chain; | 1528 std::vector<GURL> url_chain; |
1460 url_chain.push_back(GURL("http://www.google.com/")); | 1529 url_chain.push_back(GURL("http://www.google.com/")); |
1461 url_chain.push_back(GURL("http://www.google.com/bla.exe")); | 1530 url_chain.push_back(GURL("http://www.google.com/bla.exe")); |
1462 GURL referrer("http://www.google.com/"); | 1531 GURL referrer("http://www.google.com/"); |
1463 GURL tab_url("http://tab.com/final"); | 1532 GURL tab_url("http://tab.com/final"); |
1464 GURL tab_referrer("http://tab.com/referrer"); | 1533 GURL tab_referrer("http://tab.com/referrer"); |
1465 std::string hash = "hash"; | 1534 std::string hash = "hash"; |
1466 std::string remote_address = "10.11.12.13"; | 1535 std::string remote_address = "10.11.12.13"; |
1467 | 1536 |
1468 content::MockDownloadItem item; | 1537 content::MockDownloadItem item; |
1469 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(tmp_path)); | 1538 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(tmp_path)); |
1470 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(final_path)); | 1539 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(final_path)); |
1471 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); | 1540 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); |
1472 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); | 1541 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); |
1473 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(tab_url)); | 1542 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(tab_url)); |
1474 EXPECT_CALL(item, GetTabReferrerUrl()) | 1543 EXPECT_CALL(item, GetTabReferrerUrl()) |
1475 .WillRepeatedly(ReturnRef(tab_referrer)); | 1544 .WillRepeatedly(ReturnRef(tab_referrer)); |
1476 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); | 1545 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); |
1477 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); | 1546 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); |
1478 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); | 1547 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); |
1479 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address)); | 1548 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address)); |
1480 EXPECT_CALL(item, GetBrowserContext()).WillRepeatedly(Return(&profile)); | 1549 EXPECT_CALL(item, GetBrowserContext()).WillRepeatedly(Return(profile_.get())); |
1481 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1550 EXPECT_CALL(*sb_service_->mock_database_manager(), |
1482 MatchDownloadWhitelistUrl(_)) | 1551 MatchDownloadWhitelistUrl(_)) |
1483 .WillRepeatedly(Return(false)); | 1552 .WillRepeatedly(Return(false)); |
1484 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path, _)) | 1553 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path, _)) |
1485 .WillRepeatedly(SetCertificateContents("dummy cert data")); | 1554 .WillRepeatedly(SetCertificateContents("dummy cert data")); |
1486 EXPECT_CALL( | 1555 EXPECT_CALL( |
1487 *binary_feature_extractor_.get(), | 1556 *binary_feature_extractor_.get(), |
1488 ExtractImageFeatures(tmp_path, BinaryFeatureExtractor::kDefaultOptions, | 1557 ExtractImageFeatures(tmp_path, BinaryFeatureExtractor::kDefaultOptions, |
1489 _, _)) | 1558 _, _)) |
1490 .WillRepeatedly(SetDosHeaderContents("dummy dos header")); | 1559 .WillRepeatedly(SetDosHeaderContents("dummy dos header")); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1552 MessageLoop::current()->Run(); | 1621 MessageLoop::current()->Run(); |
1553 #endif | 1622 #endif |
1554 } | 1623 } |
1555 | 1624 |
1556 // Now try with a history match. | 1625 // Now try with a history match. |
1557 { | 1626 { |
1558 history::RedirectList redirects; | 1627 history::RedirectList redirects; |
1559 redirects.push_back(GURL("http://tab.com/ref1")); | 1628 redirects.push_back(GURL("http://tab.com/ref1")); |
1560 redirects.push_back(GURL("http://tab.com/ref2")); | 1629 redirects.push_back(GURL("http://tab.com/ref2")); |
1561 redirects.push_back(tab_url); | 1630 redirects.push_back(tab_url); |
1562 HistoryServiceFactory::GetForProfile(&profile, | 1631 HistoryServiceFactory::GetForProfile(profile_.get(), |
1563 ServiceAccessType::EXPLICIT_ACCESS) | 1632 ServiceAccessType::EXPLICIT_ACCESS) |
1564 ->AddPage(tab_url, | 1633 ->AddPage(tab_url, |
1565 base::Time::Now(), | 1634 base::Time::Now(), |
1566 reinterpret_cast<history::ContextID>(1), | 1635 reinterpret_cast<history::ContextID>(1), |
1567 0, | 1636 0, |
1568 GURL(), | 1637 GURL(), |
1569 redirects, | 1638 redirects, |
1570 ui::PAGE_TRANSITION_TYPED, | 1639 ui::PAGE_TRANSITION_TYPED, |
1571 history::SOURCE_BROWSED, | 1640 history::SOURCE_BROWSED, |
1572 false); | 1641 false); |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2028 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2097 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
2029 #else | 2098 #else |
2030 // On !(OS_WIN || OS_MACOSX || OS_CHROMEOS), | 2099 // On !(OS_WIN || OS_MACOSX || OS_CHROMEOS), |
2031 // no file types are currently supported. Hence all | 2100 // no file types are currently supported. Hence all |
2032 // requests to CheckClientDownload() result in a verdict of UNKNOWN. | 2101 // requests to CheckClientDownload() result in a verdict of UNKNOWN. |
2033 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 2102 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
2034 #endif | 2103 #endif |
2035 } | 2104 } |
2036 | 2105 |
2037 } // namespace safe_browsing | 2106 } // namespace safe_browsing |
OLD | NEW |