| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 | 862 |
| 863 // Case (1): is_extended_reporting && is_incognito. | 863 // Case (1): is_extended_reporting && is_incognito. |
| 864 // ClientDownloadRequest should NOT be sent. | 864 // ClientDownloadRequest should NOT be sent. |
| 865 SetExtendedReportingPreference(true); | 865 SetExtendedReportingPreference(true); |
| 866 EXPECT_CALL(item, GetBrowserContext()) | 866 EXPECT_CALL(item, GetBrowserContext()) |
| 867 .WillRepeatedly(Return(profile_->GetOffTheRecordProfile())); | 867 .WillRepeatedly(Return(profile_->GetOffTheRecordProfile())); |
| 868 download_service_->CheckClientDownload( | 868 download_service_->CheckClientDownload( |
| 869 &item, | 869 &item, |
| 870 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 870 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 871 base::Unretained(this))); | 871 base::Unretained(this))); |
| 872 MessageLoop::current()->Run(); | 872 base::RunLoop().Run(); |
| 873 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 873 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 874 EXPECT_FALSE(HasClientDownloadRequest()); | 874 EXPECT_FALSE(HasClientDownloadRequest()); |
| 875 | 875 |
| 876 // Case (2): is_extended_reporting && !is_incognito. | 876 // Case (2): is_extended_reporting && !is_incognito. |
| 877 // A "light" ClientDownloadRequest should be sent. | 877 // A "light" ClientDownloadRequest should be sent. |
| 878 EXPECT_CALL(item, GetBrowserContext()) | 878 EXPECT_CALL(item, GetBrowserContext()) |
| 879 .WillRepeatedly(Return(profile_.get())); | 879 .WillRepeatedly(Return(profile_.get())); |
| 880 download_service_->CheckClientDownload( | 880 download_service_->CheckClientDownload( |
| 881 &item, | 881 &item, |
| 882 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 882 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 883 base::Unretained(this))); | 883 base::Unretained(this))); |
| 884 MessageLoop::current()->Run(); | 884 base::RunLoop().Run(); |
| 885 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 885 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 886 EXPECT_TRUE(HasClientDownloadRequest()); | 886 EXPECT_TRUE(HasClientDownloadRequest()); |
| 887 // Verify it's a "light" ping, check that URLs don't have paths, and | 887 // Verify it's a "light" ping, check that URLs don't have paths, and |
| 888 // and verify filename is just an extension. | 888 // and verify filename is just an extension. |
| 889 auto* req = GetClientDownloadRequest(); | 889 auto* req = GetClientDownloadRequest(); |
| 890 EXPECT_EQ(ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE, | 890 EXPECT_EQ(ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE, |
| 891 req->download_type()); | 891 req->download_type()); |
| 892 EXPECT_EQ(GURL(req->url()).GetOrigin().spec(), req->url()); | 892 EXPECT_EQ(GURL(req->url()).GetOrigin().spec(), req->url()); |
| 893 for (auto resource : req->resources()) { | 893 for (auto resource : req->resources()) { |
| 894 EXPECT_EQ(GURL(resource.url()).GetOrigin().spec(), resource.url()); | 894 EXPECT_EQ(GURL(resource.url()).GetOrigin().spec(), resource.url()); |
| 895 EXPECT_EQ(GURL(resource.referrer()).GetOrigin().spec(), | 895 EXPECT_EQ(GURL(resource.referrer()).GetOrigin().spec(), |
| 896 resource.referrer()); | 896 resource.referrer()); |
| 897 } | 897 } |
| 898 EXPECT_EQ('.', req->file_basename()[0]); | 898 EXPECT_EQ('.', req->file_basename()[0]); |
| 899 | 899 |
| 900 ClearClientDownloadRequest(); | 900 ClearClientDownloadRequest(); |
| 901 | 901 |
| 902 // Case (3): !is_extended_reporting && is_incognito. | 902 // Case (3): !is_extended_reporting && is_incognito. |
| 903 // ClientDownloadRequest should NOT be sent. | 903 // ClientDownloadRequest should NOT be sent. |
| 904 SetExtendedReportingPreference(false); | 904 SetExtendedReportingPreference(false); |
| 905 EXPECT_CALL(item, GetBrowserContext()) | 905 EXPECT_CALL(item, GetBrowserContext()) |
| 906 .WillRepeatedly(Return(profile_->GetOffTheRecordProfile())); | 906 .WillRepeatedly(Return(profile_->GetOffTheRecordProfile())); |
| 907 download_service_->CheckClientDownload( | 907 download_service_->CheckClientDownload( |
| 908 &item, | 908 &item, |
| 909 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 909 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 910 base::Unretained(this))); | 910 base::Unretained(this))); |
| 911 MessageLoop::current()->Run(); | 911 base::RunLoop().Run(); |
| 912 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 912 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 913 EXPECT_FALSE(HasClientDownloadRequest()); | 913 EXPECT_FALSE(HasClientDownloadRequest()); |
| 914 | 914 |
| 915 // Case (4): !is_extended_reporting && !is_incognito. | 915 // Case (4): !is_extended_reporting && !is_incognito. |
| 916 // ClientDownloadRequest should NOT be sent. | 916 // ClientDownloadRequest should NOT be sent. |
| 917 EXPECT_CALL(item, GetBrowserContext()) | 917 EXPECT_CALL(item, GetBrowserContext()) |
| 918 .WillRepeatedly(Return(profile_.get())); | 918 .WillRepeatedly(Return(profile_.get())); |
| 919 download_service_->CheckClientDownload( | 919 download_service_->CheckClientDownload( |
| 920 &item, | 920 &item, |
| 921 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 921 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 922 base::Unretained(this))); | 922 base::Unretained(this))); |
| 923 MessageLoop::current()->Run(); | 923 base::RunLoop().Run(); |
| 924 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 924 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 925 EXPECT_FALSE(HasClientDownloadRequest()); | 925 EXPECT_FALSE(HasClientDownloadRequest()); |
| 926 } | 926 } |
| 927 | 927 |
| 928 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { | 928 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { |
| 929 // HTTP request will fail. | 929 // HTTP request will fail. |
| 930 net::FakeURLFetcherFactory factory(NULL); | 930 net::FakeURLFetcherFactory factory(NULL); |
| 931 PrepareResponse( | 931 PrepareResponse( |
| 932 &factory, ClientDownloadResponse::SAFE, net::HTTP_INTERNAL_SERVER_ERROR, | 932 &factory, ClientDownloadResponse::SAFE, net::HTTP_INTERNAL_SERVER_ERROR, |
| 933 net::URLRequestStatus::FAILED); | 933 net::URLRequestStatus::FAILED); |
| (...skipping 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2284 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2284 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2285 base::Unretained(this))); | 2285 base::Unretained(this))); |
| 2286 base::RunLoop().Run(); | 2286 base::RunLoop().Run(); |
| 2287 | 2287 |
| 2288 EXPECT_FALSE(HasClientDownloadRequest()); | 2288 EXPECT_FALSE(HasClientDownloadRequest()); |
| 2289 // Overriden by flag: | 2289 // Overriden by flag: |
| 2290 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2290 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 2291 } | 2291 } |
| 2292 | 2292 |
| 2293 } // namespace safe_browsing | 2293 } // namespace safe_browsing |
| OLD | NEW |