Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <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/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "chrome/browser/history/history_service_factory.h" | 11 #include "chrome/browser/history/history_service_factory.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 14 #include "chrome/browser/safe_browsing/threat_details.h" | 14 #include "chrome/browser/safe_browsing/threat_details.h" |
| 15 #include "chrome/browser/safe_browsing/threat_details_history.h" | 15 #include "chrome/browser/safe_browsing/threat_details_history.h" |
| 16 #include "chrome/browser/safe_browsing/ui_manager.h" | 16 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 17 #include "chrome/common/safe_browsing/csd.pb.h" | 17 #include "chrome/common/safe_browsing/csd.pb.h" |
| 18 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 18 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
| 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 21 #include "components/history/core/browser/history_backend.h" | 21 #include "components/history/core/browser/history_backend.h" |
| 22 #include "components/history/core/browser/history_service.h" | 22 #include "components/history/core/browser/history_service.h" |
| 23 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
| 24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/test/web_contents_tester.h" | |
| 25 #include "net/base/io_buffer.h" | 26 #include "net/base/io_buffer.h" |
| 26 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
| 27 #include "net/base/test_completion_callback.h" | 28 #include "net/base/test_completion_callback.h" |
| 28 #include "net/disk_cache/disk_cache.h" | 29 #include "net/disk_cache/disk_cache.h" |
| 29 #include "net/http/http_cache.h" | 30 #include "net/http/http_cache.h" |
| 30 #include "net/http/http_response_headers.h" | 31 #include "net/http/http_response_headers.h" |
| 31 #include "net/http/http_response_info.h" | 32 #include "net/http/http_response_info.h" |
| 32 #include "net/http/http_util.h" | 33 #include "net/http/http_util.h" |
| 33 #include "net/url_request/url_request_context.h" | 34 #include "net/url_request/url_request_context.h" |
| 34 #include "net/url_request/url_request_context_getter.h" | 35 #include "net/url_request/url_request_context_getter.h" |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 reinterpret_cast<history::ContextID>(1), 0, | 325 reinterpret_cast<history::ContextID>(1), 0, |
| 325 GURL(), *redirects, ui::PAGE_TRANSITION_TYPED, | 326 GURL(), *redirects, ui::PAGE_TRANSITION_TYPED, |
| 326 history::SOURCE_BROWSED, false); | 327 history::SOURCE_BROWSED, false); |
| 327 } | 328 } |
| 328 | 329 |
| 329 scoped_refptr<MockSafeBrowsingUIManager> ui_manager_; | 330 scoped_refptr<MockSafeBrowsingUIManager> ui_manager_; |
| 330 }; | 331 }; |
| 331 | 332 |
| 332 // Tests creating a simple threat report of a malware URL. | 333 // Tests creating a simple threat report of a malware URL. |
| 333 TEST_F(ThreatDetailsTest, ThreatSubResource) { | 334 TEST_F(ThreatDetailsTest, ThreatSubResource) { |
| 334 // Start a load. | 335 // Commit a load. |
| 335 controller().LoadURL( | 336 content::WebContentsTester::For(web_contents()) |
| 336 GURL(kLandingURL), | 337 ->TestDidNavigateWithReferrer( |
| 337 content::Referrer(GURL(kReferrerURL), blink::WebReferrerPolicyDefault), | 338 web_contents()->GetMainFrame(), 1 /* page_id */, 0 /* nav_entry_id */, |
| 338 ui::PAGE_TRANSITION_TYPED, std::string()); | 339 true /* did_create_new_entry */, GURL(kLandingURL), |
| 340 content::Referrer(GURL(kReferrerURL), | |
| 341 blink::WebReferrerPolicyDefault), | |
| 342 ui::PAGE_TRANSITION_TYPED); | |
| 339 | 343 |
| 340 UnsafeResource resource; | 344 UnsafeResource resource; |
| 341 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true, GURL(kThreatURL)); | 345 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, |
| 346 GURL(kThreatURL)); | |
| 342 | 347 |
| 343 scoped_refptr<ThreatDetailsWrap> report = | 348 scoped_refptr<ThreatDetailsWrap> report = |
| 344 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 349 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); |
| 345 | 350 |
| 346 std::string serialized = WaitForSerializedReport( | 351 std::string serialized = WaitForSerializedReport( |
| 347 report.get(), true /* did_proceed*/, 1 /* num_visit */); | 352 report.get(), true /* did_proceed*/, 1 /* num_visit */); |
| 348 | 353 |
| 349 ClientSafeBrowsingReportRequest actual; | 354 ClientSafeBrowsingReportRequest actual; |
| 350 actual.ParseFromString(serialized); | 355 actual.ParseFromString(serialized); |
| 351 | 356 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 369 pb_resource = expected.add_resources(); | 374 pb_resource = expected.add_resources(); |
| 370 pb_resource->set_id(2); | 375 pb_resource->set_id(2); |
| 371 pb_resource->set_url(kReferrerURL); | 376 pb_resource->set_url(kReferrerURL); |
| 372 | 377 |
| 373 VerifyResults(actual, expected); | 378 VerifyResults(actual, expected); |
| 374 } | 379 } |
| 375 | 380 |
| 376 // Tests creating a simple threat report of a phishing page where the | 381 // Tests creating a simple threat report of a phishing page where the |
| 377 // subresource has a different original_url. | 382 // subresource has a different original_url. |
| 378 TEST_F(ThreatDetailsTest, ThreatSubResourceWithOriginalUrl) { | 383 TEST_F(ThreatDetailsTest, ThreatSubResourceWithOriginalUrl) { |
| 379 controller().LoadURL(GURL(kLandingURL), content::Referrer(), | 384 content::WebContentsTester::For(web_contents()) |
| 380 ui::PAGE_TRANSITION_TYPED, std::string()); | 385 ->NavigateAndCommit(GURL(kLandingURL)); |
| 381 | 386 |
| 382 UnsafeResource resource; | 387 UnsafeResource resource; |
| 383 InitResource(&resource, SB_THREAT_TYPE_URL_PHISHING, true, GURL(kThreatURL)); | 388 InitResource(&resource, SB_THREAT_TYPE_URL_PHISHING, |
| 389 true /* is_subresource */, GURL(kThreatURL)); | |
| 384 resource.original_url = GURL(kOriginalLandingURL); | 390 resource.original_url = GURL(kOriginalLandingURL); |
| 385 | 391 |
| 386 scoped_refptr<ThreatDetailsWrap> report = | 392 scoped_refptr<ThreatDetailsWrap> report = |
| 387 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 393 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); |
| 388 | 394 |
| 389 std::string serialized = WaitForSerializedReport( | 395 std::string serialized = WaitForSerializedReport( |
| 390 report.get(), false /* did_proceed*/, 1 /* num_visit */); | 396 report.get(), false /* did_proceed*/, 1 /* num_visit */); |
| 391 | 397 |
| 392 ClientSafeBrowsingReportRequest actual; | 398 ClientSafeBrowsingReportRequest actual; |
| 393 actual.ParseFromString(serialized); | 399 actual.ParseFromString(serialized); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 414 pb_resource->set_url(kThreatURL); | 420 pb_resource->set_url(kThreatURL); |
| 415 // The Resource for kThreatURL should have the Resource for | 421 // The Resource for kThreatURL should have the Resource for |
| 416 // kOriginalLandingURL (with id 1) as parent. | 422 // kOriginalLandingURL (with id 1) as parent. |
| 417 pb_resource->set_parent_id(1); | 423 pb_resource->set_parent_id(1); |
| 418 | 424 |
| 419 VerifyResults(actual, expected); | 425 VerifyResults(actual, expected); |
| 420 } | 426 } |
| 421 | 427 |
| 422 // Tests creating a threat report of a UwS page with data from the renderer. | 428 // Tests creating a threat report of a UwS page with data from the renderer. |
| 423 TEST_F(ThreatDetailsTest, ThreatDOMDetails) { | 429 TEST_F(ThreatDetailsTest, ThreatDOMDetails) { |
| 424 controller().LoadURL(GURL(kLandingURL), content::Referrer(), | 430 content::WebContentsTester::For(web_contents()) |
| 425 ui::PAGE_TRANSITION_TYPED, std::string()); | 431 ->NavigateAndCommit(GURL(kLandingURL)); |
| 426 | 432 |
| 427 UnsafeResource resource; | 433 UnsafeResource resource; |
| 428 InitResource(&resource, SB_THREAT_TYPE_URL_UNWANTED, true, GURL(kThreatURL)); | 434 InitResource(&resource, SB_THREAT_TYPE_URL_UNWANTED, |
| 435 true /* is_subresource */, GURL(kThreatURL)); | |
| 429 | 436 |
| 430 scoped_refptr<ThreatDetailsWrap> report = | 437 scoped_refptr<ThreatDetailsWrap> report = |
| 431 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 438 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); |
| 432 | 439 |
| 433 // Send a message from the DOM, with 2 nodes, a parent and a child. | 440 // Send a message from the DOM, with 2 nodes, a parent and a child. |
| 434 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; | 441 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; |
| 435 SafeBrowsingHostMsg_ThreatDOMDetails_Node child_node; | 442 SafeBrowsingHostMsg_ThreatDOMDetails_Node child_node; |
| 436 child_node.url = GURL(kDOMChildURL); | 443 child_node.url = GURL(kDOMChildURL); |
| 437 child_node.tag_name = "iframe"; | 444 child_node.tag_name = "iframe"; |
| 438 child_node.parent = GURL(kDOMParentURL); | 445 child_node.parent = GURL(kDOMParentURL); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 pb_resource->set_url(kDOMParentURL); | 482 pb_resource->set_url(kDOMParentURL); |
| 476 pb_resource->add_child_ids(2); | 483 pb_resource->add_child_ids(2); |
| 477 expected.set_complete(false); // Since the cache was missing. | 484 expected.set_complete(false); // Since the cache was missing. |
| 478 | 485 |
| 479 VerifyResults(actual, expected); | 486 VerifyResults(actual, expected); |
| 480 } | 487 } |
| 481 | 488 |
| 482 // Tests creating a threat report of a malware page where there are redirect | 489 // Tests creating a threat report of a malware page where there are redirect |
| 483 // urls to an unsafe resource url. | 490 // urls to an unsafe resource url. |
| 484 TEST_F(ThreatDetailsTest, ThreatWithRedirectUrl) { | 491 TEST_F(ThreatDetailsTest, ThreatWithRedirectUrl) { |
| 485 controller().LoadURL(GURL(kLandingURL), content::Referrer(), | 492 content::WebContentsTester::For(web_contents()) |
| 486 ui::PAGE_TRANSITION_TYPED, std::string()); | 493 ->NavigateAndCommit(GURL(kLandingURL)); |
| 487 | 494 |
| 488 UnsafeResource resource; | 495 UnsafeResource resource; |
| 489 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true, GURL(kThreatURL)); | 496 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, |
| 497 GURL(kThreatURL)); | |
| 490 resource.original_url = GURL(kOriginalLandingURL); | 498 resource.original_url = GURL(kOriginalLandingURL); |
| 491 | 499 |
| 492 // add some redirect urls | 500 // add some redirect urls |
| 493 resource.redirect_urls.push_back(GURL(kFirstRedirectURL)); | 501 resource.redirect_urls.push_back(GURL(kFirstRedirectURL)); |
| 494 resource.redirect_urls.push_back(GURL(kSecondRedirectURL)); | 502 resource.redirect_urls.push_back(GURL(kSecondRedirectURL)); |
| 495 resource.redirect_urls.push_back(GURL(kThreatURL)); | 503 resource.redirect_urls.push_back(GURL(kThreatURL)); |
| 496 | 504 |
| 497 scoped_refptr<ThreatDetailsWrap> report = | 505 scoped_refptr<ThreatDetailsWrap> report = |
| 498 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 506 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); |
| 499 | 507 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 530 pb_resource->set_parent_id(1); | 538 pb_resource->set_parent_id(1); |
| 531 | 539 |
| 532 pb_resource = expected.add_resources(); | 540 pb_resource = expected.add_resources(); |
| 533 pb_resource->set_id(4); | 541 pb_resource->set_id(4); |
| 534 pb_resource->set_url(kSecondRedirectURL); | 542 pb_resource->set_url(kSecondRedirectURL); |
| 535 pb_resource->set_parent_id(3); | 543 pb_resource->set_parent_id(3); |
| 536 | 544 |
| 537 VerifyResults(actual, expected); | 545 VerifyResults(actual, expected); |
| 538 } | 546 } |
| 539 | 547 |
| 548 // Test collecting threat details for a blocked main frame load. | |
| 549 TEST_F(ThreatDetailsTest, ThreatOnMainPageLoadBlocked) { | |
| 550 const char* kUnrelatedReferrerURL = "http://www.unrelatedreferrer.com/some/pat h"; | |
|
Charlie Reis
2015/12/11 05:39:24
nit: 80 chars
mattm
2015/12/15 01:42:25
Done.
| |
| 551 const char* kUnrelatedURL = "http://www.unrelated.com/some/path"; | |
| 552 | |
| 553 // Load and commit an unrelated URL. The ThreatDetails should not use this | |
| 554 // navigation entry. | |
| 555 content::WebContentsTester::For(web_contents()) | |
| 556 ->TestDidNavigateWithReferrer( | |
| 557 web_contents()->GetMainFrame(), 1 /* page_id */, 0 /* nav_entry_id */, | |
| 558 true /* did_create_new_entry */, GURL(kUnrelatedURL), | |
| 559 content::Referrer(GURL(kUnrelatedReferrerURL), | |
| 560 blink::WebReferrerPolicyDefault), | |
| 561 ui::PAGE_TRANSITION_TYPED); | |
| 562 | |
| 563 // Start a pending load with a referrer. | |
| 564 controller().LoadURL(GURL(kLandingURL), | |
| 565 content::Referrer(GURL(kReferrerURL), | |
| 566 blink::WebReferrerPolicyDefault), | |
| 567 ui::PAGE_TRANSITION_TYPED, std::string()); | |
| 568 | |
| 569 // Create UnsafeResource for the pending main page load. | |
| 570 UnsafeResource resource; | |
| 571 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, | |
| 572 false /* is_subresource */, GURL(kLandingURL)); | |
| 573 | |
| 574 // Start ThreatDetails collection. | |
| 575 scoped_refptr<ThreatDetailsWrap> report = | |
| 576 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | |
| 577 | |
| 578 // Simulate clicking don't proceed. | |
| 579 controller().DiscardNonCommittedEntries(); | |
| 580 | |
| 581 // Finish ThreatDetails collection. | |
| 582 std::string serialized = WaitForSerializedReport( | |
| 583 report.get(), false /* did_proceed*/, 1 /* num_visit */); | |
| 584 | |
| 585 ClientSafeBrowsingReportRequest actual; | |
| 586 actual.ParseFromString(serialized); | |
| 587 | |
| 588 ClientSafeBrowsingReportRequest expected; | |
| 589 expected.set_type(ClientSafeBrowsingReportRequest::URL_MALWARE); | |
| 590 expected.set_url(kLandingURL); | |
| 591 expected.set_page_url(kLandingURL); | |
| 592 // Note that the referrer policy is not actually enacted here, since that's | |
| 593 // done in Blink. | |
| 594 expected.set_referrer_url(kReferrerURL); | |
| 595 expected.set_did_proceed(false); | |
| 596 expected.set_repeat_visit(true); | |
| 597 | |
| 598 ClientSafeBrowsingReportRequest::Resource* pb_resource = | |
| 599 expected.add_resources(); | |
| 600 pb_resource->set_id(0); | |
| 601 pb_resource->set_url(kLandingURL); | |
| 602 pb_resource = expected.add_resources(); | |
| 603 pb_resource->set_id(1); | |
| 604 pb_resource->set_url(kReferrerURL); | |
| 605 | |
| 606 VerifyResults(actual, expected); | |
| 607 } | |
| 608 | |
| 609 // Tests that a pending load does not interfere with collecting threat details | |
| 610 // for the committed page. | |
| 611 TEST_F(ThreatDetailsTest, ThreatWithPendingLoad) { | |
| 612 const char* kPendingReferrerURL = "http://www.pendingreferrer.com/some/path"; | |
| 613 const char* kPendingURL = "http://www.pending.com/some/path"; | |
| 614 | |
| 615 // Load and commit the landing URL with a referrer. | |
| 616 content::WebContentsTester::For(web_contents()) | |
| 617 ->TestDidNavigateWithReferrer( | |
| 618 web_contents()->GetMainFrame(), 1 /* page_id */, 0 /* nav_entry_id */, | |
| 619 true /* did_create_new_entry */, GURL(kLandingURL), | |
| 620 content::Referrer(GURL(kReferrerURL), | |
| 621 blink::WebReferrerPolicyDefault), | |
| 622 ui::PAGE_TRANSITION_TYPED); | |
| 623 | |
| 624 // Create UnsafeResource for fake sub-resource of landing page. | |
| 625 UnsafeResource resource; | |
| 626 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, | |
| 627 GURL(kThreatURL)); | |
| 628 | |
| 629 // Start a pending load before creating ThreatDetails. | |
| 630 controller().LoadURL(GURL(kPendingURL), | |
| 631 content::Referrer(GURL(kPendingReferrerURL), | |
| 632 blink::WebReferrerPolicyDefault), | |
| 633 ui::PAGE_TRANSITION_TYPED, std::string()); | |
| 634 | |
| 635 // Do ThreatDetails collection. | |
| 636 scoped_refptr<ThreatDetailsWrap> report = | |
| 637 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | |
| 638 std::string serialized = WaitForSerializedReport( | |
| 639 report.get(), true /* did_proceed*/, 1 /* num_visit */); | |
| 640 | |
| 641 ClientSafeBrowsingReportRequest actual; | |
| 642 actual.ParseFromString(serialized); | |
| 643 | |
| 644 ClientSafeBrowsingReportRequest expected; | |
| 645 expected.set_type(ClientSafeBrowsingReportRequest::URL_MALWARE); | |
| 646 expected.set_url(kThreatURL); | |
| 647 expected.set_page_url(kLandingURL); | |
| 648 // Note that the referrer policy is not actually enacted here, since that's | |
| 649 // done in Blink. | |
| 650 expected.set_referrer_url(kReferrerURL); | |
| 651 expected.set_did_proceed(true); | |
| 652 expected.set_repeat_visit(true); | |
| 653 | |
| 654 ClientSafeBrowsingReportRequest::Resource* pb_resource = | |
| 655 expected.add_resources(); | |
| 656 pb_resource->set_id(0); | |
| 657 pb_resource->set_url(kLandingURL); | |
| 658 pb_resource = expected.add_resources(); | |
| 659 pb_resource->set_id(1); | |
| 660 pb_resource->set_url(kThreatURL); | |
| 661 pb_resource = expected.add_resources(); | |
| 662 pb_resource->set_id(2); | |
| 663 pb_resource->set_url(kReferrerURL); | |
| 664 | |
| 665 VerifyResults(actual, expected); | |
| 666 } | |
| 667 | |
| 540 // Tests the interaction with the HTTP cache. | 668 // Tests the interaction with the HTTP cache. |
| 541 TEST_F(ThreatDetailsTest, HTTPCache) { | 669 TEST_F(ThreatDetailsTest, HTTPCache) { |
| 542 controller().LoadURL(GURL(kLandingURL), content::Referrer(), | 670 content::WebContentsTester::For(web_contents()) |
| 543 ui::PAGE_TRANSITION_TYPED, std::string()); | 671 ->NavigateAndCommit(GURL(kLandingURL)); |
| 544 | 672 |
| 545 UnsafeResource resource; | 673 UnsafeResource resource; |
| 546 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, true, | 674 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, |
| 547 GURL(kThreatURL)); | 675 true /* is_subresource */, GURL(kThreatURL)); |
| 548 | 676 |
| 549 scoped_refptr<ThreatDetailsWrap> report = | 677 scoped_refptr<ThreatDetailsWrap> report = |
| 550 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, | 678 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, |
| 551 profile()->GetRequestContext()); | 679 profile()->GetRequestContext()); |
| 552 | 680 |
| 553 BrowserThread::PostTask( | 681 BrowserThread::PostTask( |
| 554 BrowserThread::IO, FROM_HERE, | 682 BrowserThread::IO, FROM_HERE, |
| 555 base::Bind(&FillCache, | 683 base::Bind(&FillCache, |
| 556 make_scoped_refptr(profile()->GetRequestContext()))); | 684 make_scoped_refptr(profile()->GetRequestContext()))); |
| 557 | 685 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 pb_response->set_bodylength(threat_data.size()); | 739 pb_response->set_bodylength(threat_data.size()); |
| 612 pb_response->set_bodydigest(base::MD5String(threat_data)); | 740 pb_response->set_bodydigest(base::MD5String(threat_data)); |
| 613 pb_response->set_remote_ip("1.2.3.4:80"); | 741 pb_response->set_remote_ip("1.2.3.4:80"); |
| 614 expected.set_complete(true); | 742 expected.set_complete(true); |
| 615 | 743 |
| 616 VerifyResults(actual, expected); | 744 VerifyResults(actual, expected); |
| 617 } | 745 } |
| 618 | 746 |
| 619 // Tests the interaction with the HTTP cache (where the cache is empty). | 747 // Tests the interaction with the HTTP cache (where the cache is empty). |
| 620 TEST_F(ThreatDetailsTest, HTTPCacheNoEntries) { | 748 TEST_F(ThreatDetailsTest, HTTPCacheNoEntries) { |
| 621 controller().LoadURL(GURL(kLandingURL), content::Referrer(), | 749 content::WebContentsTester::For(web_contents()) |
| 622 ui::PAGE_TRANSITION_TYPED, std::string()); | 750 ->NavigateAndCommit(GURL(kLandingURL)); |
| 623 | 751 |
| 624 UnsafeResource resource; | 752 UnsafeResource resource; |
| 625 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL, true, | 753 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL, |
| 626 GURL(kThreatURL)); | 754 true /* is_subresource */, GURL(kThreatURL)); |
| 627 | 755 |
| 628 scoped_refptr<ThreatDetailsWrap> report = | 756 scoped_refptr<ThreatDetailsWrap> report = |
| 629 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, | 757 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, |
| 630 profile()->GetRequestContext()); | 758 profile()->GetRequestContext()); |
| 631 | 759 |
| 632 // No call to FillCache | 760 // No call to FillCache |
| 633 | 761 |
| 634 // The cache collection starts after the IPC from the DOM is fired. | 762 // The cache collection starts after the IPC from the DOM is fired. |
| 635 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; | 763 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; |
| 636 report->OnReceivedThreatDOMDetails(params); | 764 report->OnReceivedThreatDOMDetails(params); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 // There are two redirect urls before reacing malware url: | 797 // There are two redirect urls before reacing malware url: |
| 670 // kFirstRedirectURL -> kSecondRedirectURL -> kThreatURL | 798 // kFirstRedirectURL -> kSecondRedirectURL -> kThreatURL |
| 671 GURL baseurl(kThreatURL); | 799 GURL baseurl(kThreatURL); |
| 672 history::RedirectList redirects; | 800 history::RedirectList redirects; |
| 673 redirects.push_back(GURL(kFirstRedirectURL)); | 801 redirects.push_back(GURL(kFirstRedirectURL)); |
| 674 redirects.push_back(GURL(kSecondRedirectURL)); | 802 redirects.push_back(GURL(kSecondRedirectURL)); |
| 675 AddPageToHistory(baseurl, &redirects); | 803 AddPageToHistory(baseurl, &redirects); |
| 676 // Wait for history service operation finished. | 804 // Wait for history service operation finished. |
| 677 profile()->BlockUntilHistoryProcessesPendingRequests(); | 805 profile()->BlockUntilHistoryProcessesPendingRequests(); |
| 678 | 806 |
| 679 controller().LoadURL(GURL(kLandingURL), content::Referrer(), | 807 content::WebContentsTester::For(web_contents()) |
| 680 ui::PAGE_TRANSITION_TYPED, std::string()); | 808 ->NavigateAndCommit(GURL(kLandingURL)); |
| 681 | 809 |
| 682 UnsafeResource resource; | 810 UnsafeResource resource; |
| 683 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true, GURL(kThreatURL)); | 811 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, |
| 812 GURL(kThreatURL)); | |
| 684 scoped_refptr<ThreatDetailsWrap> report = | 813 scoped_refptr<ThreatDetailsWrap> report = |
| 685 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 814 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); |
| 686 | 815 |
| 687 // The redirects collection starts after the IPC from the DOM is fired. | 816 // The redirects collection starts after the IPC from the DOM is fired. |
| 688 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; | 817 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; |
| 689 report->OnReceivedThreatDOMDetails(params); | 818 report->OnReceivedThreatDOMDetails(params); |
| 690 | 819 |
| 691 // Let the redirects callbacks complete. | 820 // Let the redirects callbacks complete. |
| 692 base::RunLoop().RunUntilIdle(); | 821 base::RunLoop().RunUntilIdle(); |
| 693 | 822 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 717 pb_resource->set_parent_id(3); | 846 pb_resource->set_parent_id(3); |
| 718 pb_resource->set_url(kSecondRedirectURL); | 847 pb_resource->set_url(kSecondRedirectURL); |
| 719 pb_resource = expected.add_resources(); | 848 pb_resource = expected.add_resources(); |
| 720 pb_resource->set_id(3); | 849 pb_resource->set_id(3); |
| 721 pb_resource->set_url(kFirstRedirectURL); | 850 pb_resource->set_url(kFirstRedirectURL); |
| 722 | 851 |
| 723 VerifyResults(actual, expected); | 852 VerifyResults(actual, expected); |
| 724 } | 853 } |
| 725 | 854 |
| 726 } // namespace safe_browsing | 855 } // namespace safe_browsing |
| OLD | NEW |