Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: chrome/browser/safe_browsing/download_protection_service_unittest.cc

Issue 2601303002: Wireup SafeBrowsingNavigationObserverManager to help PPAPI download attribution (Closed)
Patch Set: nit Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after
2014 2014
2015 DownloadProtectionService::SetDownloadPingToken(&item, std::string()); 2015 DownloadProtectionService::SetDownloadPingToken(&item, std::string());
2016 EXPECT_TRUE(DownloadProtectionService::GetDownloadPingToken(&item).empty()); 2016 EXPECT_TRUE(DownloadProtectionService::GetDownloadPingToken(&item).empty());
2017 } 2017 }
2018 2018
2019 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Unsupported) { 2019 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Unsupported) {
2020 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.txt")); 2020 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.txt"));
2021 std::vector<base::FilePath::StringType> alternate_extensions{ 2021 std::vector<base::FilePath::StringType> alternate_extensions{
2022 FILE_PATH_LITERAL(".tmp"), FILE_PATH_LITERAL(".asdfasdf")}; 2022 FILE_PATH_LITERAL(".tmp"), FILE_PATH_LITERAL(".asdfasdf")};
2023 download_service_->CheckPPAPIDownloadRequest( 2023 download_service_->CheckPPAPIDownloadRequest(
2024 GURL("http://example.com/foo"), default_file_path, alternate_extensions, 2024 GURL("http://example.com/foo"), GURL(), nullptr, default_file_path,
2025 profile_.get(), 2025 alternate_extensions, profile_.get(),
2026 base::Bind(&DownloadProtectionServiceTest::SyncCheckDoneCallback, 2026 base::Bind(&DownloadProtectionServiceTest::SyncCheckDoneCallback,
2027 base::Unretained(this))); 2027 base::Unretained(this)));
2028 ASSERT_TRUE(IsResult(DownloadProtectionService::SAFE)); 2028 ASSERT_TRUE(IsResult(DownloadProtectionService::SAFE));
2029 } 2029 }
2030 2030
2031 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_SupportedDefault) { 2031 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_SupportedDefault) {
2032 net::FakeURLFetcherFactory factory(nullptr); 2032 net::FakeURLFetcherFactory factory(nullptr);
2033 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx")); 2033 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx"));
2034 std::vector<base::FilePath::StringType> alternate_extensions; 2034 std::vector<base::FilePath::StringType> alternate_extensions;
2035 EXPECT_CALL(*sb_service_->mock_database_manager(), 2035 EXPECT_CALL(*sb_service_->mock_database_manager(),
(...skipping 13 matching lines...) Expand all
2049 {ClientDownloadResponse::UNKNOWN, DownloadProtectionService::UNKNOWN}, 2049 {ClientDownloadResponse::UNKNOWN, DownloadProtectionService::UNKNOWN},
2050 }; 2050 };
2051 2051
2052 for (const auto& test_case : kExpectedResults) { 2052 for (const auto& test_case : kExpectedResults) {
2053 factory.ClearFakeResponses(); 2053 factory.ClearFakeResponses();
2054 PrepareResponse(&factory, test_case.verdict, net::HTTP_OK, 2054 PrepareResponse(&factory, test_case.verdict, net::HTTP_OK,
2055 net::URLRequestStatus::SUCCESS); 2055 net::URLRequestStatus::SUCCESS);
2056 SetExtendedReportingPreference(true); 2056 SetExtendedReportingPreference(true);
2057 RunLoop run_loop; 2057 RunLoop run_loop;
2058 download_service_->CheckPPAPIDownloadRequest( 2058 download_service_->CheckPPAPIDownloadRequest(
2059 GURL("http://example.com/foo"), default_file_path, alternate_extensions, 2059 GURL("http://example.com/foo"), GURL(), nullptr, default_file_path,
2060 profile_.get(), 2060 alternate_extensions, profile_.get(),
2061 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 2061 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
2062 base::Unretained(this), run_loop.QuitClosure())); 2062 base::Unretained(this), run_loop.QuitClosure()));
2063 run_loop.Run(); 2063 run_loop.Run();
2064 ASSERT_TRUE(IsResult(test_case.expected_result)); 2064 ASSERT_TRUE(IsResult(test_case.expected_result));
2065 ASSERT_EQ(ChromeUserPopulation::EXTENDED_REPORTING, 2065 ASSERT_EQ(ChromeUserPopulation::EXTENDED_REPORTING,
2066 GetClientDownloadRequest()->population().user_population()); 2066 GetClientDownloadRequest()->population().user_population());
2067 } 2067 }
2068 } 2068 }
2069 2069
2070 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_SupportedAlternate) { 2070 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_SupportedAlternate) {
2071 net::FakeURLFetcherFactory factory(nullptr); 2071 net::FakeURLFetcherFactory factory(nullptr);
2072 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.txt")); 2072 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.txt"));
2073 std::vector<base::FilePath::StringType> alternate_extensions{ 2073 std::vector<base::FilePath::StringType> alternate_extensions{
2074 FILE_PATH_LITERAL(".tmp"), FILE_PATH_LITERAL(".crx")}; 2074 FILE_PATH_LITERAL(".tmp"), FILE_PATH_LITERAL(".crx")};
2075 PrepareResponse(&factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, 2075 PrepareResponse(&factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK,
2076 net::URLRequestStatus::SUCCESS); 2076 net::URLRequestStatus::SUCCESS);
2077 EXPECT_CALL(*sb_service_->mock_database_manager(), 2077 EXPECT_CALL(*sb_service_->mock_database_manager(),
2078 MatchDownloadWhitelistUrl(_)) 2078 MatchDownloadWhitelistUrl(_))
2079 .WillRepeatedly(Return(false)); 2079 .WillRepeatedly(Return(false));
2080 SetExtendedReportingPreference(false); 2080 SetExtendedReportingPreference(false);
2081 RunLoop run_loop; 2081 RunLoop run_loop;
2082 download_service_->CheckPPAPIDownloadRequest( 2082 download_service_->CheckPPAPIDownloadRequest(
2083 GURL("http://example.com/foo"), default_file_path, alternate_extensions, 2083 GURL("http://example.com/foo"), GURL(), nullptr, default_file_path,
2084 profile_.get(), 2084 alternate_extensions, profile_.get(),
2085 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 2085 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
2086 base::Unretained(this), run_loop.QuitClosure())); 2086 base::Unretained(this), run_loop.QuitClosure()));
2087 run_loop.Run(); 2087 run_loop.Run();
2088 2088
2089 ASSERT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); 2089 ASSERT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
2090 ASSERT_EQ(ChromeUserPopulation::SAFE_BROWSING, 2090 ASSERT_EQ(ChromeUserPopulation::SAFE_BROWSING,
2091 GetClientDownloadRequest()->population().user_population()); 2091 GetClientDownloadRequest()->population().user_population());
2092 } 2092 }
2093 2093
2094 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_WhitelistedURL) { 2094 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_WhitelistedURL) {
2095 net::FakeURLFetcherFactory factory(nullptr); 2095 net::FakeURLFetcherFactory factory(nullptr);
2096 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx")); 2096 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx"));
2097 std::vector<base::FilePath::StringType> alternate_extensions; 2097 std::vector<base::FilePath::StringType> alternate_extensions;
2098 EXPECT_CALL(*sb_service_->mock_database_manager(), 2098 EXPECT_CALL(*sb_service_->mock_database_manager(),
2099 MatchDownloadWhitelistUrl(_)) 2099 MatchDownloadWhitelistUrl(_))
2100 .WillRepeatedly(Return(true)); 2100 .WillRepeatedly(Return(true));
2101 2101
2102 RunLoop run_loop; 2102 RunLoop run_loop;
2103 download_service_->CheckPPAPIDownloadRequest( 2103 download_service_->CheckPPAPIDownloadRequest(
2104 GURL("http://example.com/foo"), default_file_path, alternate_extensions, 2104 GURL("http://example.com/foo"), GURL(), nullptr, default_file_path,
2105 profile_.get(), 2105 alternate_extensions, profile_.get(),
2106 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 2106 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
2107 base::Unretained(this), run_loop.QuitClosure())); 2107 base::Unretained(this), run_loop.QuitClosure()));
2108 run_loop.Run(); 2108 run_loop.Run();
2109 2109
2110 ASSERT_TRUE(IsResult(DownloadProtectionService::SAFE)); 2110 ASSERT_TRUE(IsResult(DownloadProtectionService::SAFE));
2111 } 2111 }
2112 2112
2113 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_FetchFailed) { 2113 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_FetchFailed) {
2114 net::FakeURLFetcherFactory factory(nullptr); 2114 net::FakeURLFetcherFactory factory(nullptr);
2115 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx")); 2115 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx"));
2116 std::vector<base::FilePath::StringType> alternate_extensions; 2116 std::vector<base::FilePath::StringType> alternate_extensions;
2117 PrepareResponse(&factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, 2117 PrepareResponse(&factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK,
2118 net::URLRequestStatus::FAILED); 2118 net::URLRequestStatus::FAILED);
2119 EXPECT_CALL(*sb_service_->mock_database_manager(), 2119 EXPECT_CALL(*sb_service_->mock_database_manager(),
2120 MatchDownloadWhitelistUrl(_)) 2120 MatchDownloadWhitelistUrl(_))
2121 .WillRepeatedly(Return(false)); 2121 .WillRepeatedly(Return(false));
2122 RunLoop run_loop; 2122 RunLoop run_loop;
2123 download_service_->CheckPPAPIDownloadRequest( 2123 download_service_->CheckPPAPIDownloadRequest(
2124 GURL("http://example.com/foo"), default_file_path, alternate_extensions, 2124 GURL("http://example.com/foo"), GURL(), nullptr, default_file_path,
2125 profile_.get(), 2125 alternate_extensions, profile_.get(),
2126 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 2126 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
2127 base::Unretained(this), run_loop.QuitClosure())); 2127 base::Unretained(this), run_loop.QuitClosure()));
2128 run_loop.Run(); 2128 run_loop.Run();
2129 2129
2130 ASSERT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); 2130 ASSERT_TRUE(IsResult(DownloadProtectionService::UNKNOWN));
2131 } 2131 }
2132 2132
2133 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_InvalidResponse) { 2133 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_InvalidResponse) {
2134 net::FakeURLFetcherFactory factory(nullptr); 2134 net::FakeURLFetcherFactory factory(nullptr);
2135 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx")); 2135 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx"));
2136 std::vector<base::FilePath::StringType> alternate_extensions; 2136 std::vector<base::FilePath::StringType> alternate_extensions;
2137 factory.SetFakeResponse(DownloadProtectionService::GetDownloadRequestUrl(), 2137 factory.SetFakeResponse(DownloadProtectionService::GetDownloadRequestUrl(),
2138 "Hello world!", net::HTTP_OK, 2138 "Hello world!", net::HTTP_OK,
2139 net::URLRequestStatus::SUCCESS); 2139 net::URLRequestStatus::SUCCESS);
2140 EXPECT_CALL(*sb_service_->mock_database_manager(), 2140 EXPECT_CALL(*sb_service_->mock_database_manager(),
2141 MatchDownloadWhitelistUrl(_)) 2141 MatchDownloadWhitelistUrl(_))
2142 .WillRepeatedly(Return(false)); 2142 .WillRepeatedly(Return(false));
2143 RunLoop run_loop; 2143 RunLoop run_loop;
2144 download_service_->CheckPPAPIDownloadRequest( 2144 download_service_->CheckPPAPIDownloadRequest(
2145 GURL("http://example.com/foo"), default_file_path, alternate_extensions, 2145 GURL("http://example.com/foo"), GURL(), nullptr, default_file_path,
2146 profile_.get(), 2146 alternate_extensions, profile_.get(),
2147 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 2147 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
2148 base::Unretained(this), run_loop.QuitClosure())); 2148 base::Unretained(this), run_loop.QuitClosure()));
2149 run_loop.Run(); 2149 run_loop.Run();
2150 2150
2151 ASSERT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); 2151 ASSERT_TRUE(IsResult(DownloadProtectionService::UNKNOWN));
2152 } 2152 }
2153 2153
2154 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Timeout) { 2154 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Timeout) {
2155 net::FakeURLFetcherFactory factory(nullptr); 2155 net::FakeURLFetcherFactory factory(nullptr);
2156 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx")); 2156 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx"));
2157 std::vector<base::FilePath::StringType> alternate_extensions; 2157 std::vector<base::FilePath::StringType> alternate_extensions;
2158 EXPECT_CALL(*sb_service_->mock_database_manager(), 2158 EXPECT_CALL(*sb_service_->mock_database_manager(),
2159 MatchDownloadWhitelistUrl(_)) 2159 MatchDownloadWhitelistUrl(_))
2160 .WillRepeatedly(Return(false)); 2160 .WillRepeatedly(Return(false));
2161 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, 2161 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK,
2162 net::URLRequestStatus::SUCCESS); 2162 net::URLRequestStatus::SUCCESS);
2163 download_service_->download_request_timeout_ms_ = 0; 2163 download_service_->download_request_timeout_ms_ = 0;
2164 RunLoop run_loop; 2164 RunLoop run_loop;
2165 download_service_->CheckPPAPIDownloadRequest( 2165 download_service_->CheckPPAPIDownloadRequest(
2166 GURL("http://example.com/foo"), default_file_path, alternate_extensions, 2166 GURL("http://example.com/foo"), GURL(), nullptr, default_file_path,
2167 profile_.get(), 2167 alternate_extensions, profile_.get(),
2168 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 2168 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
2169 base::Unretained(this), run_loop.QuitClosure())); 2169 base::Unretained(this), run_loop.QuitClosure()));
2170 run_loop.Run(); 2170 run_loop.Run();
2171 2171
2172 ASSERT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); 2172 ASSERT_TRUE(IsResult(DownloadProtectionService::UNKNOWN));
2173 } 2173 }
2174 2174
2175 namespace { 2175 namespace {
2176 2176
2177 std::unique_ptr<net::FakeURLFetcher> FakeURLFetcherCreatorFunc( 2177 std::unique_ptr<net::FakeURLFetcher> FakeURLFetcherCreatorFunc(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2218 FILE_PATH_LITERAL(".txt"), FILE_PATH_LITERAL(".abc"), 2218 FILE_PATH_LITERAL(".txt"), FILE_PATH_LITERAL(".abc"),
2219 FILE_PATH_LITERAL(""), FILE_PATH_LITERAL(".sdF")}; 2219 FILE_PATH_LITERAL(""), FILE_PATH_LITERAL(".sdF")};
2220 EXPECT_CALL(*sb_service_->mock_database_manager(), 2220 EXPECT_CALL(*sb_service_->mock_database_manager(),
2221 MatchDownloadWhitelistUrl(_)) 2221 MatchDownloadWhitelistUrl(_))
2222 .WillRepeatedly(Return(false)); 2222 .WillRepeatedly(Return(false));
2223 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, 2223 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK,
2224 net::URLRequestStatus::SUCCESS); 2224 net::URLRequestStatus::SUCCESS);
2225 const GURL kRequestorUrl("http://example.com/foo"); 2225 const GURL kRequestorUrl("http://example.com/foo");
2226 RunLoop run_loop; 2226 RunLoop run_loop;
2227 download_service_->CheckPPAPIDownloadRequest( 2227 download_service_->CheckPPAPIDownloadRequest(
2228 kRequestorUrl, default_file_path, alternate_extensions, profile_.get(), 2228 kRequestorUrl, GURL(), nullptr, default_file_path, alternate_extensions,
2229 profile_.get(),
2229 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 2230 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
2230 base::Unretained(this), run_loop.QuitClosure())); 2231 base::Unretained(this), run_loop.QuitClosure()));
2231 run_loop.Run(); 2232 run_loop.Run();
2232 2233
2233 ASSERT_FALSE(upload_data.empty()); 2234 ASSERT_FALSE(upload_data.empty());
2234 2235
2235 ClientDownloadRequest request; 2236 ClientDownloadRequest request;
2236 ASSERT_TRUE(request.ParseFromString(upload_data)); 2237 ASSERT_TRUE(request.ParseFromString(upload_data));
2237 2238
2238 EXPECT_EQ(ClientDownloadRequest::PPAPI_SAVE_REQUEST, request.download_type()); 2239 EXPECT_EQ(ClientDownloadRequest::PPAPI_SAVE_REQUEST, request.download_type());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2320 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 2321 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
2321 base::Unretained(this), run_loop.QuitClosure())); 2322 base::Unretained(this), run_loop.QuitClosure()));
2322 run_loop.Run(); 2323 run_loop.Run();
2323 2324
2324 EXPECT_FALSE(HasClientDownloadRequest()); 2325 EXPECT_FALSE(HasClientDownloadRequest());
2325 // Overriden by flag: 2326 // Overriden by flag:
2326 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); 2327 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
2327 } 2328 }
2328 2329
2329 } // namespace safe_browsing 2330 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698