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

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

Issue 8253002: Move PageTransition into content namespace. While I'm touching all these files, I've also updated... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 | 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "chrome/browser/history/history.h" 10 #include "chrome/browser/history/history.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 292 }
293 293
294 // Adds a page to history. 294 // Adds a page to history.
295 // The redirects is the redirect url chain leading to the url. 295 // The redirects is the redirect url chain leading to the url.
296 void AddPageToHistory(const GURL& url, 296 void AddPageToHistory(const GURL& url,
297 history::RedirectList* redirects) { 297 history::RedirectList* redirects) {
298 // The last item of the redirect chain has to be the final url when adding 298 // The last item of the redirect chain has to be the final url when adding
299 // to history backend. 299 // to history backend.
300 redirects->push_back(url); 300 redirects->push_back(url);
301 history_service()->AddPage( 301 history_service()->AddPage(
302 url, static_cast<void*>(this), 0, GURL(), PageTransition::TYPED, 302 url, static_cast<void*>(this), 0, GURL(),
303 content::PAGE_TRANSITION_TYPED,
303 *redirects, history::SOURCE_BROWSED, false); 304 *redirects, history::SOURCE_BROWSED, false);
304 } 305 }
305 306
306 BrowserThread ui_thread_; 307 BrowserThread ui_thread_;
307 BrowserThread io_thread_; 308 BrowserThread io_thread_;
308 scoped_refptr<MockSafeBrowsingService> sb_service_; 309 scoped_refptr<MockSafeBrowsingService> sb_service_;
309 }; 310 };
310 311
311 // Tests creating a simple malware report. 312 // Tests creating a simple malware report.
312 TEST_F(MalwareDetailsTest, MalwareSubResource) { 313 TEST_F(MalwareDetailsTest, MalwareSubResource) {
313 // Start a load. 314 // Start a load.
314 controller().LoadURL(GURL(kLandingURL), GURL(), PageTransition::TYPED, 315 controller().LoadURL(GURL(kLandingURL), GURL(),
315 std::string()); 316 content::PAGE_TRANSITION_TYPED, std::string());
316 317
317 SafeBrowsingService::UnsafeResource resource; 318 SafeBrowsingService::UnsafeResource resource;
318 InitResource(&resource, true, GURL(kMalwareURL)); 319 InitResource(&resource, true, GURL(kMalwareURL));
319 320
320 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 321 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
321 sb_service_, contents(), resource, NULL); 322 sb_service_, contents(), resource, NULL);
322 323
323 std::string serialized = WaitForSerializedReport(report); 324 std::string serialized = WaitForSerializedReport(report);
324 325
325 ClientMalwareReportRequest actual; 326 ClientMalwareReportRequest actual;
(...skipping 10 matching lines...) Expand all
336 pb_resource = expected.add_resources(); 337 pb_resource = expected.add_resources();
337 pb_resource->set_id(1); 338 pb_resource->set_id(1);
338 pb_resource->set_url(kMalwareURL); 339 pb_resource->set_url(kMalwareURL);
339 340
340 VerifyResults(actual, expected); 341 VerifyResults(actual, expected);
341 } 342 }
342 343
343 // Tests creating a simple malware report where the subresource has a 344 // Tests creating a simple malware report where the subresource has a
344 // different original_url. 345 // different original_url.
345 TEST_F(MalwareDetailsTest, MalwareSubResourceWithOriginalUrl) { 346 TEST_F(MalwareDetailsTest, MalwareSubResourceWithOriginalUrl) {
346 controller().LoadURL(GURL(kLandingURL), GURL(), PageTransition::TYPED, 347 controller().LoadURL(GURL(kLandingURL), GURL(),
347 std::string()); 348 content::PAGE_TRANSITION_TYPED, std::string());
348 349
349 SafeBrowsingService::UnsafeResource resource; 350 SafeBrowsingService::UnsafeResource resource;
350 InitResource(&resource, true, GURL(kMalwareURL)); 351 InitResource(&resource, true, GURL(kMalwareURL));
351 resource.original_url = GURL(kOriginalLandingURL); 352 resource.original_url = GURL(kOriginalLandingURL);
352 353
353 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 354 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
354 sb_service_.get(), contents(), resource, NULL); 355 sb_service_.get(), contents(), resource, NULL);
355 356
356 std::string serialized = WaitForSerializedReport(report); 357 std::string serialized = WaitForSerializedReport(report);
357 358
(...skipping 18 matching lines...) Expand all
376 pb_resource->set_url(kMalwareURL); 377 pb_resource->set_url(kMalwareURL);
377 // The Resource for kMmalwareUrl should have the Resource for 378 // The Resource for kMmalwareUrl should have the Resource for
378 // kOriginalLandingURL (with id 1) as parent. 379 // kOriginalLandingURL (with id 1) as parent.
379 pb_resource->set_parent_id(1); 380 pb_resource->set_parent_id(1);
380 381
381 VerifyResults(actual, expected); 382 VerifyResults(actual, expected);
382 } 383 }
383 384
384 // Tests creating a malware report with data from the renderer. 385 // Tests creating a malware report with data from the renderer.
385 TEST_F(MalwareDetailsTest, MalwareDOMDetails) { 386 TEST_F(MalwareDetailsTest, MalwareDOMDetails) {
386 controller().LoadURL(GURL(kLandingURL), GURL(), PageTransition::TYPED, 387 controller().LoadURL(GURL(kLandingURL), GURL(),
387 std::string()); 388 content::PAGE_TRANSITION_TYPED, std::string());
388 389
389 SafeBrowsingService::UnsafeResource resource; 390 SafeBrowsingService::UnsafeResource resource;
390 InitResource(&resource, true, GURL(kMalwareURL)); 391 InitResource(&resource, true, GURL(kMalwareURL));
391 392
392 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 393 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
393 sb_service_.get(), contents(), resource, NULL); 394 sb_service_.get(), contents(), resource, NULL);
394 395
395 // Send a message from the DOM, with 2 nodes, a parent and a child. 396 // Send a message from the DOM, with 2 nodes, a parent and a child.
396 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; 397 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params;
397 SafeBrowsingHostMsg_MalwareDOMDetails_Node child_node; 398 SafeBrowsingHostMsg_MalwareDOMDetails_Node child_node;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 pb_resource->set_id(3); 434 pb_resource->set_id(3);
434 pb_resource->set_url(kDOMParentURL); 435 pb_resource->set_url(kDOMParentURL);
435 pb_resource->add_child_ids(2); 436 pb_resource->add_child_ids(2);
436 expected.set_complete(false); // Since the cache was missing. 437 expected.set_complete(false); // Since the cache was missing.
437 438
438 VerifyResults(actual, expected); 439 VerifyResults(actual, expected);
439 } 440 }
440 441
441 // Verify that https:// urls are dropped. 442 // Verify that https:// urls are dropped.
442 TEST_F(MalwareDetailsTest, NotPublicUrl) { 443 TEST_F(MalwareDetailsTest, NotPublicUrl) {
443 controller().LoadURL(GURL(kHttpsURL), GURL(), PageTransition::TYPED, 444 controller().LoadURL(GURL(kHttpsURL), GURL(), content::PAGE_TRANSITION_TYPED,
444 std::string()); 445 std::string());
445 SafeBrowsingService::UnsafeResource resource; 446 SafeBrowsingService::UnsafeResource resource;
446 InitResource(&resource, true, GURL(kMalwareURL)); 447 InitResource(&resource, true, GURL(kMalwareURL));
447 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 448 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
448 sb_service_.get(), contents(), resource, NULL); 449 sb_service_.get(), contents(), resource, NULL);
449 450
450 std::string serialized = WaitForSerializedReport(report); 451 std::string serialized = WaitForSerializedReport(report);
451 ClientMalwareReportRequest actual; 452 ClientMalwareReportRequest actual;
452 actual.ParseFromString(serialized); 453 actual.ParseFromString(serialized);
453 454
454 ClientMalwareReportRequest expected; 455 ClientMalwareReportRequest expected;
455 expected.set_malware_url(kMalwareURL); // No page_url 456 expected.set_malware_url(kMalwareURL); // No page_url
456 expected.set_referrer_url(""); 457 expected.set_referrer_url("");
457 458
458 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); 459 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources();
459 pb_resource->set_url(kMalwareURL); // Only one resource 460 pb_resource->set_url(kMalwareURL); // Only one resource
460 461
461 VerifyResults(actual, expected); 462 VerifyResults(actual, expected);
462 } 463 }
463 464
464 // Tests creating a malware report where there are redirect urls to an unsafe 465 // Tests creating a malware report where there are redirect urls to an unsafe
465 // resource url 466 // resource url
466 TEST_F(MalwareDetailsTest, MalwareWithRedirectUrl) { 467 TEST_F(MalwareDetailsTest, MalwareWithRedirectUrl) {
467 controller().LoadURL(GURL(kLandingURL), GURL(), PageTransition::TYPED, 468 controller().LoadURL(GURL(kLandingURL), GURL(),
468 std::string()); 469 content::PAGE_TRANSITION_TYPED, std::string());
469 470
470 SafeBrowsingService::UnsafeResource resource; 471 SafeBrowsingService::UnsafeResource resource;
471 InitResource(&resource, true, GURL(kMalwareURL)); 472 InitResource(&resource, true, GURL(kMalwareURL));
472 resource.original_url = GURL(kOriginalLandingURL); 473 resource.original_url = GURL(kOriginalLandingURL);
473 474
474 // add some redirect urls 475 // add some redirect urls
475 resource.redirect_urls.push_back(GURL(kFirstRedirectURL)); 476 resource.redirect_urls.push_back(GURL(kFirstRedirectURL));
476 resource.redirect_urls.push_back(GURL(kSecondRedirectURL)); 477 resource.redirect_urls.push_back(GURL(kSecondRedirectURL));
477 resource.redirect_urls.push_back(GURL(kMalwareURL)); 478 resource.redirect_urls.push_back(GURL(kMalwareURL));
478 479
(...skipping 30 matching lines...) Expand all
509 pb_resource = expected.add_resources(); 510 pb_resource = expected.add_resources();
510 pb_resource->set_id(4); 511 pb_resource->set_id(4);
511 pb_resource->set_url(kSecondRedirectURL); 512 pb_resource->set_url(kSecondRedirectURL);
512 pb_resource->set_parent_id(3); 513 pb_resource->set_parent_id(3);
513 514
514 VerifyResults(actual, expected); 515 VerifyResults(actual, expected);
515 } 516 }
516 517
517 // Tests the interaction with the HTTP cache. 518 // Tests the interaction with the HTTP cache.
518 TEST_F(MalwareDetailsTest, HTTPCache) { 519 TEST_F(MalwareDetailsTest, HTTPCache) {
519 controller().LoadURL(GURL(kLandingURL), GURL(), PageTransition::TYPED, 520 controller().LoadURL(GURL(kLandingURL), GURL(),
520 std::string()); 521 content::PAGE_TRANSITION_TYPED, std::string());
521 522
522 SafeBrowsingService::UnsafeResource resource; 523 SafeBrowsingService::UnsafeResource resource;
523 InitResource(&resource, true, GURL(kMalwareURL)); 524 InitResource(&resource, true, GURL(kMalwareURL));
524 525
525 profile()->CreateRequestContext(); 526 profile()->CreateRequestContext();
526 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 527 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
527 sb_service_.get(), contents(), resource, profile()->GetRequestContext()); 528 sb_service_.get(), contents(), resource, profile()->GetRequestContext());
528 529
529 BrowserThread::PostTask( 530 BrowserThread::PostTask(
530 BrowserThread::IO, FROM_HERE, 531 BrowserThread::IO, FROM_HERE,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 pb_response->set_bodydigest("581373551c43d4cf33bfb3b26838ff95"); 583 pb_response->set_bodydigest("581373551c43d4cf33bfb3b26838ff95");
583 pb_response->set_remote_ip("1.2.3.4:80"); 584 pb_response->set_remote_ip("1.2.3.4:80");
584 expected.set_complete(true); 585 expected.set_complete(true);
585 586
586 VerifyResults(actual, expected); 587 VerifyResults(actual, expected);
587 profile()->ResetRequestContext(); 588 profile()->ResetRequestContext();
588 } 589 }
589 590
590 // Tests the interaction with the HTTP cache (where the cache is empty). 591 // Tests the interaction with the HTTP cache (where the cache is empty).
591 TEST_F(MalwareDetailsTest, HTTPCacheNoEntries) { 592 TEST_F(MalwareDetailsTest, HTTPCacheNoEntries) {
592 controller().LoadURL(GURL(kLandingURL), GURL(), PageTransition::TYPED, 593 controller().LoadURL(GURL(kLandingURL), GURL(),
593 std::string()); 594 content::PAGE_TRANSITION_TYPED, std::string());
594 595
595 SafeBrowsingService::UnsafeResource resource; 596 SafeBrowsingService::UnsafeResource resource;
596 InitResource(&resource, true, GURL(kMalwareURL)); 597 InitResource(&resource, true, GURL(kMalwareURL));
597 598
598 profile()->CreateRequestContext(); 599 profile()->CreateRequestContext();
599 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 600 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
600 sb_service_.get(), contents(), resource, 601 sb_service_.get(), contents(), resource,
601 profile()->GetRequestContext()); 602 profile()->GetRequestContext());
602 603
603 // No call to FillCache 604 // No call to FillCache
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 // There are two redirect urls before reacing malware url: 637 // There are two redirect urls before reacing malware url:
637 // kFirstRedirectURL -> kSecondRedirectURL -> kMalwareURL 638 // kFirstRedirectURL -> kSecondRedirectURL -> kMalwareURL
638 GURL baseurl(kMalwareURL); 639 GURL baseurl(kMalwareURL);
639 history::RedirectList redirects; 640 history::RedirectList redirects;
640 redirects.push_back(GURL(kFirstRedirectURL)); 641 redirects.push_back(GURL(kFirstRedirectURL));
641 redirects.push_back(GURL(kSecondRedirectURL)); 642 redirects.push_back(GURL(kSecondRedirectURL));
642 AddPageToHistory(baseurl, &redirects); 643 AddPageToHistory(baseurl, &redirects);
643 // Wait for history service operation finished. 644 // Wait for history service operation finished.
644 profile()->BlockUntilHistoryProcessesPendingRequests(); 645 profile()->BlockUntilHistoryProcessesPendingRequests();
645 646
646 controller().LoadURL(GURL(kLandingURL), GURL(), PageTransition::TYPED, 647 controller().LoadURL(GURL(kLandingURL), GURL(),
647 std::string()); 648 content::PAGE_TRANSITION_TYPED, std::string());
648 649
649 SafeBrowsingService::UnsafeResource resource; 650 SafeBrowsingService::UnsafeResource resource;
650 InitResource(&resource, true, GURL(kMalwareURL)); 651 InitResource(&resource, true, GURL(kMalwareURL));
651 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 652 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
652 sb_service_.get(), contents(), resource, NULL); 653 sb_service_.get(), contents(), resource, NULL);
653 654
654 // The redirects collection starts after the IPC from the DOM is fired. 655 // The redirects collection starts after the IPC from the DOM is fired.
655 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; 656 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params;
656 report->OnReceivedMalwareDOMDetails(params); 657 report->OnReceivedMalwareDOMDetails(params);
657 658
(...skipping 19 matching lines...) Expand all
677 pb_resource = expected.add_resources(); 678 pb_resource = expected.add_resources();
678 pb_resource->set_id(2); 679 pb_resource->set_id(2);
679 pb_resource->set_parent_id(3); 680 pb_resource->set_parent_id(3);
680 pb_resource->set_url(kSecondRedirectURL); 681 pb_resource->set_url(kSecondRedirectURL);
681 pb_resource = expected.add_resources(); 682 pb_resource = expected.add_resources();
682 pb_resource->set_id(3); 683 pb_resource->set_id(3);
683 pb_resource->set_url(kFirstRedirectURL); 684 pb_resource->set_url(kFirstRedirectURL);
684 685
685 VerifyResults(actual, expected); 686 VerifyResults(actual, expected);
686 } 687 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698