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

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

Issue 8438012: Parse the download server response. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 info.referrer_url = GURL("http://www.google.com/"); 216 info.referrer_url = GURL("http://www.google.com/");
217 download_service_->CheckClientDownload( 217 download_service_->CheckClientDownload(
218 info, 218 info,
219 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 219 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
220 base::Unretained(this))); 220 base::Unretained(this)));
221 msg_loop_.Run(); 221 msg_loop_.Run();
222 EXPECT_EQ(DownloadProtectionService::SAFE, result_); 222 EXPECT_EQ(DownloadProtectionService::SAFE, result_);
223 } 223 }
224 224
225 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { 225 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) {
226 ClientDownloadResponse response;
227 response.set_verdict(ClientDownloadResponse::SAFE);
226 FakeURLFetcherFactory factory; 228 FakeURLFetcherFactory factory;
227 // Empty response means SAFE. 229 // Empty response means SAFE.
228 factory.SetFakeResponse( 230 factory.SetFakeResponse(
229 DownloadProtectionService::kDownloadRequestUrl, "", true); 231 DownloadProtectionService::kDownloadRequestUrl,
232 response.SerializeAsString(),
233 true);
230 234
231 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) 235 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_))
232 .WillRepeatedly(Return(false)); 236 .WillRepeatedly(Return(false));
233 237
234 DownloadProtectionService::DownloadInfo info; 238 DownloadProtectionService::DownloadInfo info;
235 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); 239 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe"));
236 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); 240 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe"));
237 info.referrer_url = GURL("http://www.google.com/"); 241 info.referrer_url = GURL("http://www.google.com/");
238 download_service_->CheckClientDownload( 242 download_service_->CheckClientDownload(
239 info, 243 info,
240 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 244 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
241 base::Unretained(this))); 245 base::Unretained(this)));
242 msg_loop_.Run(); 246 msg_loop_.Run();
243 EXPECT_EQ(DownloadProtectionService::SAFE, result_); 247 EXPECT_EQ(DownloadProtectionService::SAFE, result_);
244 248
245 // Invalid response should be safe too. 249 // Invalid response should be safe too.
250 response.Clear();
246 factory.SetFakeResponse( 251 factory.SetFakeResponse(
247 DownloadProtectionService::kDownloadRequestUrl, "bla", true); 252 DownloadProtectionService::kDownloadRequestUrl,
253 response.SerializePartialAsString(),
254 true);
248 255
249 download_service_->CheckClientDownload( 256 download_service_->CheckClientDownload(
250 info, 257 info,
251 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 258 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
252 base::Unretained(this))); 259 base::Unretained(this)));
253 msg_loop_.Run(); 260 msg_loop_.Run();
254 EXPECT_EQ(DownloadProtectionService::SAFE, result_); 261 EXPECT_EQ(DownloadProtectionService::SAFE, result_);
262
263 // If the response is malicious the result should also be makred as malicious.
mattm 2011/11/01 23:57:53 marked
noelutz 2011/11/02 00:55:31 Done.
264 response.set_verdict(ClientDownloadResponse::MALICIOUS);
265 factory.SetFakeResponse(
266 DownloadProtectionService::kDownloadRequestUrl,
267 response.SerializeAsString(),
268 true);
269
270 download_service_->CheckClientDownload(
271 info,
272 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
273 base::Unretained(this)));
274 msg_loop_.Run();
275 EXPECT_EQ(DownloadProtectionService::MALICIOUS, result_);
255 } 276 }
256 277
257 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { 278 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) {
258 TestURLFetcherFactory factory; 279 TestURLFetcherFactory factory;
259 280
260 DownloadProtectionService::DownloadInfo info; 281 DownloadProtectionService::DownloadInfo info;
261 info.local_file = FilePath(FILE_PATH_LITERAL("bla.exe")); 282 info.local_file = FilePath(FILE_PATH_LITERAL("bla.exe"));
262 info.download_url_chain.push_back(GURL("http://www.google.com/")); 283 info.download_url_chain.push_back(GURL("http://www.google.com/"));
263 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); 284 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe"));
264 info.referrer_url = GURL("http://www.google.com/"); 285 info.referrer_url = GURL("http://www.google.com/");
(...skipping 28 matching lines...) Expand all
293 info.referrer_url.spec())); 314 info.referrer_url.spec()));
294 315
295 // Simulate the request finishing. 316 // Simulate the request finishing.
296 MessageLoop::current()->PostTask( 317 MessageLoop::current()->PostTask(
297 FROM_HERE, 318 FROM_HERE,
298 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, 319 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete,
299 base::Unretained(this), fetcher)); 320 base::Unretained(this), fetcher));
300 msg_loop_.Run(); 321 msg_loop_.Run();
301 } 322 }
302 } // namespace safe_browsing 323 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/download_protection_service.cc ('k') | chrome/common/safe_browsing/csd.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698