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

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

Issue 8785004: Change NavigationController::LoadURL to take a Referrer class instead of a GURL as referrer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 9 years 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 306 }
307 307
308 content::TestBrowserThread ui_thread_; 308 content::TestBrowserThread ui_thread_;
309 content::TestBrowserThread io_thread_; 309 content::TestBrowserThread io_thread_;
310 scoped_refptr<MockSafeBrowsingService> sb_service_; 310 scoped_refptr<MockSafeBrowsingService> sb_service_;
311 }; 311 };
312 312
313 // Tests creating a simple malware report. 313 // Tests creating a simple malware report.
314 TEST_F(MalwareDetailsTest, MalwareSubResource) { 314 TEST_F(MalwareDetailsTest, MalwareSubResource) {
315 // Start a load. 315 // Start a load.
316 controller().LoadURL(GURL(kLandingURL), GURL(), 316 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
317 content::PAGE_TRANSITION_TYPED, std::string()); 317 content::PAGE_TRANSITION_TYPED, std::string());
318 318
319 SafeBrowsingService::UnsafeResource resource; 319 SafeBrowsingService::UnsafeResource resource;
320 InitResource(&resource, true, GURL(kMalwareURL)); 320 InitResource(&resource, true, GURL(kMalwareURL));
321 321
322 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 322 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
323 sb_service_, contents(), resource, NULL); 323 sb_service_, contents(), resource, NULL);
324 324
325 std::string serialized = WaitForSerializedReport(report); 325 std::string serialized = WaitForSerializedReport(report);
326 326
(...skipping 11 matching lines...) Expand all
338 pb_resource = expected.add_resources(); 338 pb_resource = expected.add_resources();
339 pb_resource->set_id(1); 339 pb_resource->set_id(1);
340 pb_resource->set_url(kMalwareURL); 340 pb_resource->set_url(kMalwareURL);
341 341
342 VerifyResults(actual, expected); 342 VerifyResults(actual, expected);
343 } 343 }
344 344
345 // Tests creating a simple malware report where the subresource has a 345 // Tests creating a simple malware report where the subresource has a
346 // different original_url. 346 // different original_url.
347 TEST_F(MalwareDetailsTest, MalwareSubResourceWithOriginalUrl) { 347 TEST_F(MalwareDetailsTest, MalwareSubResourceWithOriginalUrl) {
348 controller().LoadURL(GURL(kLandingURL), GURL(), 348 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
349 content::PAGE_TRANSITION_TYPED, std::string()); 349 content::PAGE_TRANSITION_TYPED, std::string());
350 350
351 SafeBrowsingService::UnsafeResource resource; 351 SafeBrowsingService::UnsafeResource resource;
352 InitResource(&resource, true, GURL(kMalwareURL)); 352 InitResource(&resource, true, GURL(kMalwareURL));
353 resource.original_url = GURL(kOriginalLandingURL); 353 resource.original_url = GURL(kOriginalLandingURL);
354 354
355 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 355 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
356 sb_service_.get(), contents(), resource, NULL); 356 sb_service_.get(), contents(), resource, NULL);
357 357
358 std::string serialized = WaitForSerializedReport(report); 358 std::string serialized = WaitForSerializedReport(report);
(...skipping 19 matching lines...) Expand all
378 pb_resource->set_url(kMalwareURL); 378 pb_resource->set_url(kMalwareURL);
379 // The Resource for kMmalwareUrl should have the Resource for 379 // The Resource for kMmalwareUrl should have the Resource for
380 // kOriginalLandingURL (with id 1) as parent. 380 // kOriginalLandingURL (with id 1) as parent.
381 pb_resource->set_parent_id(1); 381 pb_resource->set_parent_id(1);
382 382
383 VerifyResults(actual, expected); 383 VerifyResults(actual, expected);
384 } 384 }
385 385
386 // Tests creating a malware report with data from the renderer. 386 // Tests creating a malware report with data from the renderer.
387 TEST_F(MalwareDetailsTest, MalwareDOMDetails) { 387 TEST_F(MalwareDetailsTest, MalwareDOMDetails) {
388 controller().LoadURL(GURL(kLandingURL), GURL(), 388 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
389 content::PAGE_TRANSITION_TYPED, std::string()); 389 content::PAGE_TRANSITION_TYPED, std::string());
390 390
391 SafeBrowsingService::UnsafeResource resource; 391 SafeBrowsingService::UnsafeResource resource;
392 InitResource(&resource, true, GURL(kMalwareURL)); 392 InitResource(&resource, true, GURL(kMalwareURL));
393 393
394 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 394 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
395 sb_service_.get(), contents(), resource, NULL); 395 sb_service_.get(), contents(), resource, NULL);
396 396
397 // Send a message from the DOM, with 2 nodes, a parent and a child. 397 // Send a message from the DOM, with 2 nodes, a parent and a child.
398 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; 398 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 pb_resource->set_id(3); 435 pb_resource->set_id(3);
436 pb_resource->set_url(kDOMParentURL); 436 pb_resource->set_url(kDOMParentURL);
437 pb_resource->add_child_ids(2); 437 pb_resource->add_child_ids(2);
438 expected.set_complete(false); // Since the cache was missing. 438 expected.set_complete(false); // Since the cache was missing.
439 439
440 VerifyResults(actual, expected); 440 VerifyResults(actual, expected);
441 } 441 }
442 442
443 // Verify that https:// urls are dropped. 443 // Verify that https:// urls are dropped.
444 TEST_F(MalwareDetailsTest, NotPublicUrl) { 444 TEST_F(MalwareDetailsTest, NotPublicUrl) {
445 controller().LoadURL(GURL(kHttpsURL), GURL(), content::PAGE_TRANSITION_TYPED, 445 controller().LoadURL(GURL(kHttpsURL), content::Referrer(),
446 std::string()); 446 content::PAGE_TRANSITION_TYPED, std::string());
447 SafeBrowsingService::UnsafeResource resource; 447 SafeBrowsingService::UnsafeResource resource;
448 InitResource(&resource, true, GURL(kMalwareURL)); 448 InitResource(&resource, true, GURL(kMalwareURL));
449 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 449 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
450 sb_service_.get(), contents(), resource, NULL); 450 sb_service_.get(), contents(), resource, NULL);
451 451
452 std::string serialized = WaitForSerializedReport(report); 452 std::string serialized = WaitForSerializedReport(report);
453 ClientMalwareReportRequest actual; 453 ClientMalwareReportRequest actual;
454 actual.ParseFromString(serialized); 454 actual.ParseFromString(serialized);
455 455
456 ClientMalwareReportRequest expected; 456 ClientMalwareReportRequest expected;
457 expected.set_malware_url(kMalwareURL); // No page_url 457 expected.set_malware_url(kMalwareURL); // No page_url
458 expected.set_referrer_url(""); 458 expected.set_referrer_url("");
459 459
460 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); 460 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources();
461 pb_resource->set_url(kMalwareURL); // Only one resource 461 pb_resource->set_url(kMalwareURL); // Only one resource
462 462
463 VerifyResults(actual, expected); 463 VerifyResults(actual, expected);
464 } 464 }
465 465
466 // Tests creating a malware report where there are redirect urls to an unsafe 466 // Tests creating a malware report where there are redirect urls to an unsafe
467 // resource url 467 // resource url
468 TEST_F(MalwareDetailsTest, MalwareWithRedirectUrl) { 468 TEST_F(MalwareDetailsTest, MalwareWithRedirectUrl) {
469 controller().LoadURL(GURL(kLandingURL), GURL(), 469 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
470 content::PAGE_TRANSITION_TYPED, std::string()); 470 content::PAGE_TRANSITION_TYPED, std::string());
471 471
472 SafeBrowsingService::UnsafeResource resource; 472 SafeBrowsingService::UnsafeResource resource;
473 InitResource(&resource, true, GURL(kMalwareURL)); 473 InitResource(&resource, true, GURL(kMalwareURL));
474 resource.original_url = GURL(kOriginalLandingURL); 474 resource.original_url = GURL(kOriginalLandingURL);
475 475
476 // add some redirect urls 476 // add some redirect urls
477 resource.redirect_urls.push_back(GURL(kFirstRedirectURL)); 477 resource.redirect_urls.push_back(GURL(kFirstRedirectURL));
478 resource.redirect_urls.push_back(GURL(kSecondRedirectURL)); 478 resource.redirect_urls.push_back(GURL(kSecondRedirectURL));
479 resource.redirect_urls.push_back(GURL(kMalwareURL)); 479 resource.redirect_urls.push_back(GURL(kMalwareURL));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 pb_resource = expected.add_resources(); 511 pb_resource = expected.add_resources();
512 pb_resource->set_id(4); 512 pb_resource->set_id(4);
513 pb_resource->set_url(kSecondRedirectURL); 513 pb_resource->set_url(kSecondRedirectURL);
514 pb_resource->set_parent_id(3); 514 pb_resource->set_parent_id(3);
515 515
516 VerifyResults(actual, expected); 516 VerifyResults(actual, expected);
517 } 517 }
518 518
519 // Tests the interaction with the HTTP cache. 519 // Tests the interaction with the HTTP cache.
520 TEST_F(MalwareDetailsTest, HTTPCache) { 520 TEST_F(MalwareDetailsTest, HTTPCache) {
521 controller().LoadURL(GURL(kLandingURL), GURL(), 521 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
522 content::PAGE_TRANSITION_TYPED, std::string()); 522 content::PAGE_TRANSITION_TYPED, std::string());
523 523
524 SafeBrowsingService::UnsafeResource resource; 524 SafeBrowsingService::UnsafeResource resource;
525 InitResource(&resource, true, GURL(kMalwareURL)); 525 InitResource(&resource, true, GURL(kMalwareURL));
526 526
527 profile()->CreateRequestContext(); 527 profile()->CreateRequestContext();
528 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 528 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
529 sb_service_.get(), contents(), resource, profile()->GetRequestContext()); 529 sb_service_.get(), contents(), resource, profile()->GetRequestContext());
530 530
531 BrowserThread::PostTask( 531 BrowserThread::PostTask(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 pb_response->set_bodydigest("581373551c43d4cf33bfb3b26838ff95"); 584 pb_response->set_bodydigest("581373551c43d4cf33bfb3b26838ff95");
585 pb_response->set_remote_ip("1.2.3.4:80"); 585 pb_response->set_remote_ip("1.2.3.4:80");
586 expected.set_complete(true); 586 expected.set_complete(true);
587 587
588 VerifyResults(actual, expected); 588 VerifyResults(actual, expected);
589 profile()->ResetRequestContext(); 589 profile()->ResetRequestContext();
590 } 590 }
591 591
592 // Tests the interaction with the HTTP cache (where the cache is empty). 592 // Tests the interaction with the HTTP cache (where the cache is empty).
593 TEST_F(MalwareDetailsTest, HTTPCacheNoEntries) { 593 TEST_F(MalwareDetailsTest, HTTPCacheNoEntries) {
594 controller().LoadURL(GURL(kLandingURL), GURL(), 594 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
595 content::PAGE_TRANSITION_TYPED, std::string()); 595 content::PAGE_TRANSITION_TYPED, std::string());
596 596
597 SafeBrowsingService::UnsafeResource resource; 597 SafeBrowsingService::UnsafeResource resource;
598 InitResource(&resource, true, GURL(kMalwareURL)); 598 InitResource(&resource, true, GURL(kMalwareURL));
599 599
600 profile()->CreateRequestContext(); 600 profile()->CreateRequestContext();
601 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 601 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
602 sb_service_.get(), contents(), resource, 602 sb_service_.get(), contents(), resource,
603 profile()->GetRequestContext()); 603 profile()->GetRequestContext());
604 604
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 // There are two redirect urls before reacing malware url: 638 // There are two redirect urls before reacing malware url:
639 // kFirstRedirectURL -> kSecondRedirectURL -> kMalwareURL 639 // kFirstRedirectURL -> kSecondRedirectURL -> kMalwareURL
640 GURL baseurl(kMalwareURL); 640 GURL baseurl(kMalwareURL);
641 history::RedirectList redirects; 641 history::RedirectList redirects;
642 redirects.push_back(GURL(kFirstRedirectURL)); 642 redirects.push_back(GURL(kFirstRedirectURL));
643 redirects.push_back(GURL(kSecondRedirectURL)); 643 redirects.push_back(GURL(kSecondRedirectURL));
644 AddPageToHistory(baseurl, &redirects); 644 AddPageToHistory(baseurl, &redirects);
645 // Wait for history service operation finished. 645 // Wait for history service operation finished.
646 profile()->BlockUntilHistoryProcessesPendingRequests(); 646 profile()->BlockUntilHistoryProcessesPendingRequests();
647 647
648 controller().LoadURL(GURL(kLandingURL), GURL(), 648 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
649 content::PAGE_TRANSITION_TYPED, std::string()); 649 content::PAGE_TRANSITION_TYPED, std::string());
650 650
651 SafeBrowsingService::UnsafeResource resource; 651 SafeBrowsingService::UnsafeResource resource;
652 InitResource(&resource, true, GURL(kMalwareURL)); 652 InitResource(&resource, true, GURL(kMalwareURL));
653 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 653 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
654 sb_service_.get(), contents(), resource, NULL); 654 sb_service_.get(), contents(), resource, NULL);
655 655
656 // The redirects collection starts after the IPC from the DOM is fired. 656 // The redirects collection starts after the IPC from the DOM is fired.
657 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; 657 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params;
658 report->OnReceivedMalwareDOMDetails(params); 658 report->OnReceivedMalwareDOMDetails(params);
(...skipping 20 matching lines...) Expand all
679 pb_resource = expected.add_resources(); 679 pb_resource = expected.add_resources();
680 pb_resource->set_id(2); 680 pb_resource->set_id(2);
681 pb_resource->set_parent_id(3); 681 pb_resource->set_parent_id(3);
682 pb_resource->set_url(kSecondRedirectURL); 682 pb_resource->set_url(kSecondRedirectURL);
683 pb_resource = expected.add_resources(); 683 pb_resource = expected.add_resources();
684 pb_resource->set_id(3); 684 pb_resource->set_id(3);
685 pb_resource->set_url(kFirstRedirectURL); 685 pb_resource->set_url(kFirstRedirectURL);
686 686
687 VerifyResults(actual, expected); 687 VerifyResults(actual, expected);
688 } 688 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698