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

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: Remove DCHECK bug 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 info.referrer_url = GURL("http://www.google.com/"); 217 info.referrer_url = GURL("http://www.google.com/");
218 download_service_->CheckClientDownload( 218 download_service_->CheckClientDownload(
219 info, 219 info,
220 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 220 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
221 base::Unretained(this))); 221 base::Unretained(this)));
222 msg_loop_.Run(); 222 msg_loop_.Run();
223 EXPECT_EQ(DownloadProtectionService::SAFE, result_); 223 EXPECT_EQ(DownloadProtectionService::SAFE, result_);
224 } 224 }
225 225
226 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { 226 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) {
227 ClientDownloadResponse response;
228 response.set_verdict(ClientDownloadResponse::SAFE);
227 FakeURLFetcherFactory factory; 229 FakeURLFetcherFactory factory;
228 // Empty response means SAFE. 230 // Empty response means SAFE.
229 factory.SetFakeResponse( 231 factory.SetFakeResponse(
230 DownloadProtectionService::kDownloadRequestUrl, "", true); 232 DownloadProtectionService::kDownloadRequestUrl,
233 response.SerializeAsString(),
234 true);
231 235
232 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) 236 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_))
233 .WillRepeatedly(Return(false)); 237 .WillRepeatedly(Return(false));
234 238
235 DownloadProtectionService::DownloadInfo info; 239 DownloadProtectionService::DownloadInfo info;
236 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); 240 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe"));
237 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); 241 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe"));
238 info.referrer_url = GURL("http://www.google.com/"); 242 info.referrer_url = GURL("http://www.google.com/");
239 download_service_->CheckClientDownload( 243 download_service_->CheckClientDownload(
240 info, 244 info,
241 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 245 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
242 base::Unretained(this))); 246 base::Unretained(this)));
243 msg_loop_.Run(); 247 msg_loop_.Run();
244 EXPECT_EQ(DownloadProtectionService::SAFE, result_); 248 EXPECT_EQ(DownloadProtectionService::SAFE, result_);
245 249
246 // Invalid response should be safe too. 250 // Invalid response should be safe too.
251 response.Clear();
247 factory.SetFakeResponse( 252 factory.SetFakeResponse(
248 DownloadProtectionService::kDownloadRequestUrl, "bla", true); 253 DownloadProtectionService::kDownloadRequestUrl,
254 response.SerializePartialAsString(),
255 true);
249 256
250 download_service_->CheckClientDownload( 257 download_service_->CheckClientDownload(
251 info, 258 info,
252 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 259 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
253 base::Unretained(this))); 260 base::Unretained(this)));
254 msg_loop_.Run(); 261 msg_loop_.Run();
255 EXPECT_EQ(DownloadProtectionService::SAFE, result_); 262 EXPECT_EQ(DownloadProtectionService::SAFE, result_);
263
264 // If the response is dangerous the result should also be marked as dangerous.
265 response.set_verdict(ClientDownloadResponse::DANGEROUS);
266 factory.SetFakeResponse(
267 DownloadProtectionService::kDownloadRequestUrl,
268 response.SerializeAsString(),
269 true);
270
271 download_service_->CheckClientDownload(
272 info,
273 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
274 base::Unretained(this)));
275 msg_loop_.Run();
276 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_);
256 } 277 }
257 278
258 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { 279 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) {
259 TestURLFetcherFactory factory; 280 TestURLFetcherFactory factory;
260 281
261 DownloadProtectionService::DownloadInfo info; 282 DownloadProtectionService::DownloadInfo info;
262 info.local_file = FilePath(FILE_PATH_LITERAL("bla.exe")); 283 info.local_file = FilePath(FILE_PATH_LITERAL("bla.exe"));
263 info.download_url_chain.push_back(GURL("http://www.google.com/")); 284 info.download_url_chain.push_back(GURL("http://www.google.com/"));
264 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); 285 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe"));
265 info.referrer_url = GURL("http://www.google.com/"); 286 info.referrer_url = GURL("http://www.google.com/");
(...skipping 28 matching lines...) Expand all
294 info.referrer_url.spec())); 315 info.referrer_url.spec()));
295 316
296 // Simulate the request finishing. 317 // Simulate the request finishing.
297 MessageLoop::current()->PostTask( 318 MessageLoop::current()->PostTask(
298 FROM_HERE, 319 FROM_HERE,
299 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, 320 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete,
300 base::Unretained(this), fetcher)); 321 base::Unretained(this), fetcher));
301 msg_loop_.Run(); 322 msg_loop_.Run();
302 } 323 }
303 } // namespace safe_browsing 324 } // 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