| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 152 } |
| 153 | 153 |
| 154 // Lets us provide a MockURLRequestContext with an HTTP Cache we pre-populate. | 154 // Lets us provide a MockURLRequestContext with an HTTP Cache we pre-populate. |
| 155 // Also exposes the constructor. | 155 // Also exposes the constructor. |
| 156 class ThreatDetailsWrap : public ThreatDetails { | 156 class ThreatDetailsWrap : public ThreatDetails { |
| 157 public: | 157 public: |
| 158 ThreatDetailsWrap( | 158 ThreatDetailsWrap( |
| 159 SafeBrowsingUIManager* ui_manager, | 159 SafeBrowsingUIManager* ui_manager, |
| 160 WebContents* web_contents, | 160 WebContents* web_contents, |
| 161 const security_interstitials::UnsafeResource& unsafe_resource, | 161 const security_interstitials::UnsafeResource& unsafe_resource, |
| 162 net::URLRequestContextGetter* request_context_getter) | 162 net::URLRequestContextGetter* request_context_getter, |
| 163 : ThreatDetails(ui_manager, web_contents, unsafe_resource) { | 163 history::HistoryService* history_service) |
| 164 : ThreatDetails(ui_manager, |
| 165 web_contents, |
| 166 unsafe_resource, |
| 167 request_context_getter, |
| 168 history_service) { |
| 164 request_context_getter_ = request_context_getter; | 169 request_context_getter_ = request_context_getter; |
| 165 } | 170 } |
| 166 | 171 |
| 167 private: | 172 private: |
| 168 ~ThreatDetailsWrap() override {} | 173 ~ThreatDetailsWrap() override {} |
| 169 }; | 174 }; |
| 170 | 175 |
| 171 class MockSafeBrowsingUIManager : public SafeBrowsingUIManager { | 176 class MockSafeBrowsingUIManager : public SafeBrowsingUIManager { |
| 172 public: | 177 public: |
| 173 base::RunLoop* run_loop_; | 178 base::RunLoop* run_loop_; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 web_contents()->GetMainFrame(), 0 /* nav_entry_id */, | 382 web_contents()->GetMainFrame(), 0 /* nav_entry_id */, |
| 378 true /* did_create_new_entry */, GURL(kLandingURL), | 383 true /* did_create_new_entry */, GURL(kLandingURL), |
| 379 content::Referrer(GURL(kReferrerURL), | 384 content::Referrer(GURL(kReferrerURL), |
| 380 blink::WebReferrerPolicyDefault), | 385 blink::WebReferrerPolicyDefault), |
| 381 ui::PAGE_TRANSITION_TYPED); | 386 ui::PAGE_TRANSITION_TYPED); |
| 382 | 387 |
| 383 UnsafeResource resource; | 388 UnsafeResource resource; |
| 384 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, | 389 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, |
| 385 GURL(kThreatURL)); | 390 GURL(kThreatURL)); |
| 386 | 391 |
| 387 scoped_refptr<ThreatDetailsWrap> report = | 392 scoped_refptr<ThreatDetailsWrap> report = new ThreatDetailsWrap( |
| 388 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 393 ui_manager_.get(), web_contents(), resource, NULL, history_service()); |
| 389 | 394 |
| 390 std::string serialized = WaitForSerializedReport( | 395 std::string serialized = WaitForSerializedReport( |
| 391 report.get(), true /* did_proceed*/, 1 /* num_visit */); | 396 report.get(), true /* did_proceed*/, 1 /* num_visit */); |
| 392 | 397 |
| 393 ClientSafeBrowsingReportRequest actual; | 398 ClientSafeBrowsingReportRequest actual; |
| 394 actual.ParseFromString(serialized); | 399 actual.ParseFromString(serialized); |
| 395 | 400 |
| 396 ClientSafeBrowsingReportRequest expected; | 401 ClientSafeBrowsingReportRequest expected; |
| 397 expected.set_type(ClientSafeBrowsingReportRequest::URL_MALWARE); | 402 expected.set_type(ClientSafeBrowsingReportRequest::URL_MALWARE); |
| 398 expected.set_url(kThreatURL); | 403 expected.set_url(kThreatURL); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 421 // subresource has a different original_url. | 426 // subresource has a different original_url. |
| 422 TEST_F(ThreatDetailsTest, ThreatSubResourceWithOriginalUrl) { | 427 TEST_F(ThreatDetailsTest, ThreatSubResourceWithOriginalUrl) { |
| 423 content::WebContentsTester::For(web_contents()) | 428 content::WebContentsTester::For(web_contents()) |
| 424 ->NavigateAndCommit(GURL(kLandingURL)); | 429 ->NavigateAndCommit(GURL(kLandingURL)); |
| 425 | 430 |
| 426 UnsafeResource resource; | 431 UnsafeResource resource; |
| 427 InitResource(&resource, SB_THREAT_TYPE_URL_PHISHING, | 432 InitResource(&resource, SB_THREAT_TYPE_URL_PHISHING, |
| 428 true /* is_subresource */, GURL(kThreatURL)); | 433 true /* is_subresource */, GURL(kThreatURL)); |
| 429 resource.original_url = GURL(kOriginalLandingURL); | 434 resource.original_url = GURL(kOriginalLandingURL); |
| 430 | 435 |
| 431 scoped_refptr<ThreatDetailsWrap> report = | 436 scoped_refptr<ThreatDetailsWrap> report = new ThreatDetailsWrap( |
| 432 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 437 ui_manager_.get(), web_contents(), resource, NULL, history_service()); |
| 433 | 438 |
| 434 std::string serialized = WaitForSerializedReport( | 439 std::string serialized = WaitForSerializedReport( |
| 435 report.get(), false /* did_proceed*/, 1 /* num_visit */); | 440 report.get(), false /* did_proceed*/, 1 /* num_visit */); |
| 436 | 441 |
| 437 ClientSafeBrowsingReportRequest actual; | 442 ClientSafeBrowsingReportRequest actual; |
| 438 actual.ParseFromString(serialized); | 443 actual.ParseFromString(serialized); |
| 439 | 444 |
| 440 ClientSafeBrowsingReportRequest expected; | 445 ClientSafeBrowsingReportRequest expected; |
| 441 expected.set_type(ClientSafeBrowsingReportRequest::URL_PHISHING); | 446 expected.set_type(ClientSafeBrowsingReportRequest::URL_PHISHING); |
| 442 expected.set_url(kThreatURL); | 447 expected.set_url(kThreatURL); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 466 | 471 |
| 467 // Tests creating a threat report of a UwS page with data from the renderer. | 472 // Tests creating a threat report of a UwS page with data from the renderer. |
| 468 TEST_F(ThreatDetailsTest, ThreatDOMDetails) { | 473 TEST_F(ThreatDetailsTest, ThreatDOMDetails) { |
| 469 content::WebContentsTester::For(web_contents()) | 474 content::WebContentsTester::For(web_contents()) |
| 470 ->NavigateAndCommit(GURL(kLandingURL)); | 475 ->NavigateAndCommit(GURL(kLandingURL)); |
| 471 | 476 |
| 472 UnsafeResource resource; | 477 UnsafeResource resource; |
| 473 InitResource(&resource, SB_THREAT_TYPE_URL_UNWANTED, | 478 InitResource(&resource, SB_THREAT_TYPE_URL_UNWANTED, |
| 474 true /* is_subresource */, GURL(kThreatURL)); | 479 true /* is_subresource */, GURL(kThreatURL)); |
| 475 | 480 |
| 476 scoped_refptr<ThreatDetailsWrap> report = | 481 scoped_refptr<ThreatDetailsWrap> report = new ThreatDetailsWrap( |
| 477 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 482 ui_manager_.get(), web_contents(), resource, NULL, history_service()); |
| 478 | 483 |
| 479 // Send a message from the DOM, with 2 nodes, a parent and a child. | 484 // Send a message from the DOM, with 2 nodes, a parent and a child. |
| 480 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; | 485 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; |
| 481 SafeBrowsingHostMsg_ThreatDOMDetails_Node child_node; | 486 SafeBrowsingHostMsg_ThreatDOMDetails_Node child_node; |
| 482 child_node.url = GURL(kDOMChildURL); | 487 child_node.url = GURL(kDOMChildURL); |
| 483 child_node.tag_name = "iframe"; | 488 child_node.tag_name = "iframe"; |
| 484 child_node.parent = GURL(kDOMParentURL); | 489 child_node.parent = GURL(kDOMParentURL); |
| 485 child_node.attributes.push_back(std::make_pair("src", kDOMChildURL)); | 490 child_node.attributes.push_back(std::make_pair("src", kDOMChildURL)); |
| 486 params.push_back(child_node); | 491 params.push_back(child_node); |
| 487 SafeBrowsingHostMsg_ThreatDOMDetails_Node parent_node; | 492 SafeBrowsingHostMsg_ThreatDOMDetails_Node parent_node; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 content::WebContentsTester::For(web_contents()) | 669 content::WebContentsTester::For(web_contents()) |
| 665 ->NavigateAndCommit(GURL(kLandingURL)); | 670 ->NavigateAndCommit(GURL(kLandingURL)); |
| 666 | 671 |
| 667 UnsafeResource resource; | 672 UnsafeResource resource; |
| 668 InitResource(&resource, SB_THREAT_TYPE_URL_UNWANTED, | 673 InitResource(&resource, SB_THREAT_TYPE_URL_UNWANTED, |
| 669 true /* is_subresource */, GURL(kThreatURL)); | 674 true /* is_subresource */, GURL(kThreatURL)); |
| 670 | 675 |
| 671 // Send both sets of nodes, from different render frames. | 676 // Send both sets of nodes, from different render frames. |
| 672 { | 677 { |
| 673 scoped_refptr<ThreatDetailsWrap> report = new ThreatDetailsWrap( | 678 scoped_refptr<ThreatDetailsWrap> report = new ThreatDetailsWrap( |
| 674 ui_manager_.get(), web_contents(), resource, NULL); | 679 ui_manager_.get(), web_contents(), resource, NULL, history_service()); |
| 675 | 680 |
| 676 // We call AddDOMDetails directly so we can specify different render frame | 681 // We call AddDOMDetails directly so we can specify different render frame |
| 677 // IDs. | 682 // IDs. |
| 678 report->AddDOMDetails(100, GURL(kDOMParentURL), outer_params); | 683 report->AddDOMDetails(100, GURL(kDOMParentURL), outer_params); |
| 679 report->AddDOMDetails(200, GURL(kDOMChildURL), inner_params); | 684 report->AddDOMDetails(200, GURL(kDOMChildURL), inner_params); |
| 680 std::string serialized = WaitForSerializedReport( | 685 std::string serialized = WaitForSerializedReport( |
| 681 report.get(), false /* did_proceed*/, 0 /* num_visit */); | 686 report.get(), false /* did_proceed*/, 0 /* num_visit */); |
| 682 ClientSafeBrowsingReportRequest actual; | 687 ClientSafeBrowsingReportRequest actual; |
| 683 actual.ParseFromString(serialized); | 688 actual.ParseFromString(serialized); |
| 684 VerifyResults(actual, expected); | 689 VerifyResults(actual, expected); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 708 elem_dom_outer_div->set_id(2); | 713 elem_dom_outer_div->set_id(2); |
| 709 elem_dom_outer_div->clear_child_ids(); | 714 elem_dom_outer_div->clear_child_ids(); |
| 710 elem_dom_outer_div->add_child_ids(3); | 715 elem_dom_outer_div->add_child_ids(3); |
| 711 elem_dom_outer_iframe->set_id(3); | 716 elem_dom_outer_iframe->set_id(3); |
| 712 elem_dom_outer_iframe->set_resource_id(res_dom_child->id()); | 717 elem_dom_outer_iframe->set_resource_id(res_dom_child->id()); |
| 713 elem_dom_outer_iframe->clear_child_ids(); | 718 elem_dom_outer_iframe->clear_child_ids(); |
| 714 elem_dom_outer_iframe->add_child_ids(0); | 719 elem_dom_outer_iframe->add_child_ids(0); |
| 715 elem_dom_outer_iframe->add_child_ids(1); | 720 elem_dom_outer_iframe->add_child_ids(1); |
| 716 | 721 |
| 717 scoped_refptr<ThreatDetailsWrap> report = new ThreatDetailsWrap( | 722 scoped_refptr<ThreatDetailsWrap> report = new ThreatDetailsWrap( |
| 718 ui_manager_.get(), web_contents(), resource, NULL); | 723 ui_manager_.get(), web_contents(), resource, NULL, history_service()); |
| 719 | 724 |
| 720 // We call AddDOMDetails directly so we can specify different render frame | 725 // We call AddDOMDetails directly so we can specify different render frame |
| 721 // IDs. | 726 // IDs. |
| 722 report->AddDOMDetails(200, GURL(kDOMChildURL), inner_params); | 727 report->AddDOMDetails(200, GURL(kDOMChildURL), inner_params); |
| 723 report->AddDOMDetails(100, GURL(kDOMParentURL), outer_params); | 728 report->AddDOMDetails(100, GURL(kDOMParentURL), outer_params); |
| 724 std::string serialized = WaitForSerializedReport( | 729 std::string serialized = WaitForSerializedReport( |
| 725 report.get(), false /* did_proceed*/, 0 /* num_visit */); | 730 report.get(), false /* did_proceed*/, 0 /* num_visit */); |
| 726 ClientSafeBrowsingReportRequest actual; | 731 ClientSafeBrowsingReportRequest actual; |
| 727 actual.ParseFromString(serialized); | 732 actual.ParseFromString(serialized); |
| 728 VerifyResults(actual, expected); | 733 VerifyResults(actual, expected); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 pb_element->set_resource_id(4); | 822 pb_element->set_resource_id(4); |
| 818 pb_element->add_attribute()->set_name("src"); | 823 pb_element->add_attribute()->set_name("src"); |
| 819 pb_element->mutable_attribute(0)->set_value(kDOMChildUrl2); | 824 pb_element->mutable_attribute(0)->set_value(kDOMChildUrl2); |
| 820 | 825 |
| 821 content::WebContentsTester::For(web_contents()) | 826 content::WebContentsTester::For(web_contents()) |
| 822 ->NavigateAndCommit(GURL(kLandingURL)); | 827 ->NavigateAndCommit(GURL(kLandingURL)); |
| 823 | 828 |
| 824 UnsafeResource resource; | 829 UnsafeResource resource; |
| 825 InitResource(&resource, SB_THREAT_TYPE_URL_UNWANTED, | 830 InitResource(&resource, SB_THREAT_TYPE_URL_UNWANTED, |
| 826 true /* is_subresource */, GURL(kThreatURL)); | 831 true /* is_subresource */, GURL(kThreatURL)); |
| 827 scoped_refptr<ThreatDetailsWrap> report = | 832 scoped_refptr<ThreatDetailsWrap> report = new ThreatDetailsWrap( |
| 828 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 833 ui_manager_.get(), web_contents(), resource, NULL, history_service()); |
| 829 base::HistogramTester histograms; | 834 base::HistogramTester histograms; |
| 830 | 835 |
| 831 // Send both sets of nodes, from different render frames. We call | 836 // Send both sets of nodes, from different render frames. We call |
| 832 // AddDOMDetails directly so we can specify different render frame IDs. | 837 // AddDOMDetails directly so we can specify different render frame IDs. |
| 833 report->AddDOMDetails(100, GURL(kDOMParentURL), outer_params); | 838 report->AddDOMDetails(100, GURL(kDOMParentURL), outer_params); |
| 834 // The inner frame was using a data URL so its last committed URL is empty. | 839 // The inner frame was using a data URL so its last committed URL is empty. |
| 835 report->AddDOMDetails(200, GURL(), inner_params); | 840 report->AddDOMDetails(200, GURL(), inner_params); |
| 836 | 841 |
| 837 std::string serialized = WaitForSerializedReport( | 842 std::string serialized = WaitForSerializedReport( |
| 838 report.get(), false /* did_proceed*/, 0 /* num_visit */); | 843 report.get(), false /* did_proceed*/, 0 /* num_visit */); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 853 UnsafeResource resource; | 858 UnsafeResource resource; |
| 854 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, | 859 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, |
| 855 GURL(kThreatURL)); | 860 GURL(kThreatURL)); |
| 856 resource.original_url = GURL(kOriginalLandingURL); | 861 resource.original_url = GURL(kOriginalLandingURL); |
| 857 | 862 |
| 858 // add some redirect urls | 863 // add some redirect urls |
| 859 resource.redirect_urls.push_back(GURL(kFirstRedirectURL)); | 864 resource.redirect_urls.push_back(GURL(kFirstRedirectURL)); |
| 860 resource.redirect_urls.push_back(GURL(kSecondRedirectURL)); | 865 resource.redirect_urls.push_back(GURL(kSecondRedirectURL)); |
| 861 resource.redirect_urls.push_back(GURL(kThreatURL)); | 866 resource.redirect_urls.push_back(GURL(kThreatURL)); |
| 862 | 867 |
| 863 scoped_refptr<ThreatDetailsWrap> report = | 868 scoped_refptr<ThreatDetailsWrap> report = new ThreatDetailsWrap( |
| 864 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 869 ui_manager_.get(), web_contents(), resource, NULL, history_service()); |
| 865 | 870 |
| 866 std::string serialized = WaitForSerializedReport( | 871 std::string serialized = WaitForSerializedReport( |
| 867 report.get(), true /* did_proceed*/, 0 /* num_visit */); | 872 report.get(), true /* did_proceed*/, 0 /* num_visit */); |
| 868 ClientSafeBrowsingReportRequest actual; | 873 ClientSafeBrowsingReportRequest actual; |
| 869 actual.ParseFromString(serialized); | 874 actual.ParseFromString(serialized); |
| 870 | 875 |
| 871 ClientSafeBrowsingReportRequest expected; | 876 ClientSafeBrowsingReportRequest expected; |
| 872 expected.set_type(ClientSafeBrowsingReportRequest::URL_MALWARE); | 877 expected.set_type(ClientSafeBrowsingReportRequest::URL_MALWARE); |
| 873 expected.set_url(kThreatURL); | 878 expected.set_url(kThreatURL); |
| 874 expected.set_page_url(kLandingURL); | 879 expected.set_page_url(kLandingURL); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 content::Referrer(GURL(kReferrerURL), | 929 content::Referrer(GURL(kReferrerURL), |
| 925 blink::WebReferrerPolicyDefault), | 930 blink::WebReferrerPolicyDefault), |
| 926 ui::PAGE_TRANSITION_TYPED, std::string()); | 931 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 927 | 932 |
| 928 // Create UnsafeResource for the pending main page load. | 933 // Create UnsafeResource for the pending main page load. |
| 929 UnsafeResource resource; | 934 UnsafeResource resource; |
| 930 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, | 935 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, |
| 931 false /* is_subresource */, GURL(kLandingURL)); | 936 false /* is_subresource */, GURL(kLandingURL)); |
| 932 | 937 |
| 933 // Start ThreatDetails collection. | 938 // Start ThreatDetails collection. |
| 934 scoped_refptr<ThreatDetailsWrap> report = | 939 scoped_refptr<ThreatDetailsWrap> report = new ThreatDetailsWrap( |
| 935 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 940 ui_manager_.get(), web_contents(), resource, NULL, history_service()); |
| 936 | 941 |
| 937 // Simulate clicking don't proceed. | 942 // Simulate clicking don't proceed. |
| 938 controller().DiscardNonCommittedEntries(); | 943 controller().DiscardNonCommittedEntries(); |
| 939 | 944 |
| 940 // Finish ThreatDetails collection. | 945 // Finish ThreatDetails collection. |
| 941 std::string serialized = WaitForSerializedReport( | 946 std::string serialized = WaitForSerializedReport( |
| 942 report.get(), false /* did_proceed*/, 1 /* num_visit */); | 947 report.get(), false /* did_proceed*/, 1 /* num_visit */); |
| 943 | 948 |
| 944 ClientSafeBrowsingReportRequest actual; | 949 ClientSafeBrowsingReportRequest actual; |
| 945 actual.ParseFromString(serialized); | 950 actual.ParseFromString(serialized); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, | 990 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, |
| 986 GURL(kThreatURL)); | 991 GURL(kThreatURL)); |
| 987 | 992 |
| 988 // Start a pending load before creating ThreatDetails. | 993 // Start a pending load before creating ThreatDetails. |
| 989 controller().LoadURL(GURL(kPendingURL), | 994 controller().LoadURL(GURL(kPendingURL), |
| 990 content::Referrer(GURL(kPendingReferrerURL), | 995 content::Referrer(GURL(kPendingReferrerURL), |
| 991 blink::WebReferrerPolicyDefault), | 996 blink::WebReferrerPolicyDefault), |
| 992 ui::PAGE_TRANSITION_TYPED, std::string()); | 997 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 993 | 998 |
| 994 // Do ThreatDetails collection. | 999 // Do ThreatDetails collection. |
| 995 scoped_refptr<ThreatDetailsWrap> report = | 1000 scoped_refptr<ThreatDetailsWrap> report = new ThreatDetailsWrap( |
| 996 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 1001 ui_manager_.get(), web_contents(), resource, NULL, history_service()); |
| 997 std::string serialized = WaitForSerializedReport( | 1002 std::string serialized = WaitForSerializedReport( |
| 998 report.get(), true /* did_proceed*/, 1 /* num_visit */); | 1003 report.get(), true /* did_proceed*/, 1 /* num_visit */); |
| 999 | 1004 |
| 1000 ClientSafeBrowsingReportRequest actual; | 1005 ClientSafeBrowsingReportRequest actual; |
| 1001 actual.ParseFromString(serialized); | 1006 actual.ParseFromString(serialized); |
| 1002 | 1007 |
| 1003 ClientSafeBrowsingReportRequest expected; | 1008 ClientSafeBrowsingReportRequest expected; |
| 1004 expected.set_type(ClientSafeBrowsingReportRequest::URL_MALWARE); | 1009 expected.set_type(ClientSafeBrowsingReportRequest::URL_MALWARE); |
| 1005 expected.set_url(kThreatURL); | 1010 expected.set_url(kThreatURL); |
| 1006 expected.set_page_url(kLandingURL); | 1011 expected.set_page_url(kLandingURL); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1030 EXPECT_EQ(nullptr, controller().GetLastCommittedEntry()); | 1035 EXPECT_EQ(nullptr, controller().GetLastCommittedEntry()); |
| 1031 EXPECT_EQ(nullptr, controller().GetPendingEntry()); | 1036 EXPECT_EQ(nullptr, controller().GetPendingEntry()); |
| 1032 | 1037 |
| 1033 // Simulate a subresource malware hit (this could happen if the WebContents | 1038 // Simulate a subresource malware hit (this could happen if the WebContents |
| 1034 // was created with window.open, and had content injected into it). | 1039 // was created with window.open, and had content injected into it). |
| 1035 UnsafeResource resource; | 1040 UnsafeResource resource; |
| 1036 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, | 1041 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, |
| 1037 GURL(kThreatURL)); | 1042 GURL(kThreatURL)); |
| 1038 | 1043 |
| 1039 // Do ThreatDetails collection. | 1044 // Do ThreatDetails collection. |
| 1040 scoped_refptr<ThreatDetailsWrap> report = | 1045 scoped_refptr<ThreatDetailsWrap> report = new ThreatDetailsWrap( |
| 1041 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 1046 ui_manager_.get(), web_contents(), resource, NULL, history_service()); |
| 1042 std::string serialized = WaitForSerializedReport( | 1047 std::string serialized = WaitForSerializedReport( |
| 1043 report.get(), true /* did_proceed*/, 1 /* num_visit */); | 1048 report.get(), true /* did_proceed*/, 1 /* num_visit */); |
| 1044 | 1049 |
| 1045 ClientSafeBrowsingReportRequest actual; | 1050 ClientSafeBrowsingReportRequest actual; |
| 1046 actual.ParseFromString(serialized); | 1051 actual.ParseFromString(serialized); |
| 1047 | 1052 |
| 1048 ClientSafeBrowsingReportRequest expected; | 1053 ClientSafeBrowsingReportRequest expected; |
| 1049 expected.set_type(ClientSafeBrowsingReportRequest::URL_MALWARE); | 1054 expected.set_type(ClientSafeBrowsingReportRequest::URL_MALWARE); |
| 1050 expected.set_url(kThreatURL); | 1055 expected.set_url(kThreatURL); |
| 1051 expected.set_did_proceed(true); | 1056 expected.set_did_proceed(true); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1063 TEST_F(ThreatDetailsTest, HTTPCache) { | 1068 TEST_F(ThreatDetailsTest, HTTPCache) { |
| 1064 content::WebContentsTester::For(web_contents()) | 1069 content::WebContentsTester::For(web_contents()) |
| 1065 ->NavigateAndCommit(GURL(kLandingURL)); | 1070 ->NavigateAndCommit(GURL(kLandingURL)); |
| 1066 | 1071 |
| 1067 UnsafeResource resource; | 1072 UnsafeResource resource; |
| 1068 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, | 1073 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, |
| 1069 true /* is_subresource */, GURL(kThreatURL)); | 1074 true /* is_subresource */, GURL(kThreatURL)); |
| 1070 | 1075 |
| 1071 scoped_refptr<ThreatDetailsWrap> report = | 1076 scoped_refptr<ThreatDetailsWrap> report = |
| 1072 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, | 1077 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, |
| 1073 profile()->GetRequestContext()); | 1078 profile()->GetRequestContext(), history_service()); |
| 1074 | 1079 |
| 1075 BrowserThread::PostTask( | 1080 BrowserThread::PostTask( |
| 1076 BrowserThread::IO, FROM_HERE, | 1081 BrowserThread::IO, FROM_HERE, |
| 1077 base::Bind(&FillCache, | 1082 base::Bind(&FillCache, |
| 1078 base::RetainedRef(profile()->GetRequestContext()))); | 1083 base::RetainedRef(profile()->GetRequestContext()))); |
| 1079 | 1084 |
| 1080 // The cache collection starts after the IPC from the DOM is fired. | 1085 // The cache collection starts after the IPC from the DOM is fired. |
| 1081 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; | 1086 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; |
| 1082 report->OnReceivedThreatDOMDetails(main_rfh(), params); | 1087 report->OnReceivedThreatDOMDetails(main_rfh(), params); |
| 1083 | 1088 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 TEST_F(ThreatDetailsTest, HttpsResourceSanitization) { | 1151 TEST_F(ThreatDetailsTest, HttpsResourceSanitization) { |
| 1147 content::WebContentsTester::For(web_contents()) | 1152 content::WebContentsTester::For(web_contents()) |
| 1148 ->NavigateAndCommit(GURL(kLandingURL)); | 1153 ->NavigateAndCommit(GURL(kLandingURL)); |
| 1149 | 1154 |
| 1150 UnsafeResource resource; | 1155 UnsafeResource resource; |
| 1151 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, | 1156 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, |
| 1152 true /* is_subresource */, GURL(kThreatURLHttps)); | 1157 true /* is_subresource */, GURL(kThreatURLHttps)); |
| 1153 | 1158 |
| 1154 scoped_refptr<ThreatDetailsWrap> report = | 1159 scoped_refptr<ThreatDetailsWrap> report = |
| 1155 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, | 1160 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, |
| 1156 profile()->GetRequestContext()); | 1161 profile()->GetRequestContext(), history_service()); |
| 1157 | 1162 |
| 1158 BrowserThread::PostTask( | 1163 BrowserThread::PostTask( |
| 1159 BrowserThread::IO, FROM_HERE, | 1164 BrowserThread::IO, FROM_HERE, |
| 1160 base::Bind(&FillCacheHttps, | 1165 base::Bind(&FillCacheHttps, |
| 1161 base::RetainedRef(profile()->GetRequestContext()))); | 1166 base::RetainedRef(profile()->GetRequestContext()))); |
| 1162 | 1167 |
| 1163 // The cache collection starts after the IPC from the DOM is fired. | 1168 // The cache collection starts after the IPC from the DOM is fired. |
| 1164 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; | 1169 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; |
| 1165 report->OnReceivedThreatDOMDetails(main_rfh(), params); | 1170 report->OnReceivedThreatDOMDetails(main_rfh(), params); |
| 1166 | 1171 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 TEST_F(ThreatDetailsTest, HTTPCacheNoEntries) { | 1231 TEST_F(ThreatDetailsTest, HTTPCacheNoEntries) { |
| 1227 content::WebContentsTester::For(web_contents()) | 1232 content::WebContentsTester::For(web_contents()) |
| 1228 ->NavigateAndCommit(GURL(kLandingURL)); | 1233 ->NavigateAndCommit(GURL(kLandingURL)); |
| 1229 | 1234 |
| 1230 UnsafeResource resource; | 1235 UnsafeResource resource; |
| 1231 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL, | 1236 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL, |
| 1232 true /* is_subresource */, GURL(kThreatURL)); | 1237 true /* is_subresource */, GURL(kThreatURL)); |
| 1233 | 1238 |
| 1234 scoped_refptr<ThreatDetailsWrap> report = | 1239 scoped_refptr<ThreatDetailsWrap> report = |
| 1235 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, | 1240 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, |
| 1236 profile()->GetRequestContext()); | 1241 profile()->GetRequestContext(), history_service()); |
| 1237 | 1242 |
| 1238 // No call to FillCache | 1243 // No call to FillCache |
| 1239 | 1244 |
| 1240 // The cache collection starts after the IPC from the DOM is fired. | 1245 // The cache collection starts after the IPC from the DOM is fired. |
| 1241 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; | 1246 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; |
| 1242 report->OnReceivedThreatDOMDetails(main_rfh(), params); | 1247 report->OnReceivedThreatDOMDetails(main_rfh(), params); |
| 1243 | 1248 |
| 1244 // Let the cache callbacks complete. | 1249 // Let the cache callbacks complete. |
| 1245 base::RunLoop().RunUntilIdle(); | 1250 base::RunLoop().RunUntilIdle(); |
| 1246 | 1251 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 AddPageToHistory(baseurl, &redirects); | 1286 AddPageToHistory(baseurl, &redirects); |
| 1282 // Wait for history service operation finished. | 1287 // Wait for history service operation finished. |
| 1283 profile()->BlockUntilHistoryProcessesPendingRequests(); | 1288 profile()->BlockUntilHistoryProcessesPendingRequests(); |
| 1284 | 1289 |
| 1285 content::WebContentsTester::For(web_contents()) | 1290 content::WebContentsTester::For(web_contents()) |
| 1286 ->NavigateAndCommit(GURL(kLandingURL)); | 1291 ->NavigateAndCommit(GURL(kLandingURL)); |
| 1287 | 1292 |
| 1288 UnsafeResource resource; | 1293 UnsafeResource resource; |
| 1289 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, | 1294 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true /* is_subresource */, |
| 1290 GURL(kThreatURL)); | 1295 GURL(kThreatURL)); |
| 1291 scoped_refptr<ThreatDetailsWrap> report = | 1296 scoped_refptr<ThreatDetailsWrap> report = new ThreatDetailsWrap( |
| 1292 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); | 1297 ui_manager_.get(), web_contents(), resource, NULL, history_service()); |
| 1293 | 1298 |
| 1294 // The redirects collection starts after the IPC from the DOM is fired. | 1299 // The redirects collection starts after the IPC from the DOM is fired. |
| 1295 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; | 1300 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; |
| 1296 report->OnReceivedThreatDOMDetails(main_rfh(), params); | 1301 report->OnReceivedThreatDOMDetails(main_rfh(), params); |
| 1297 | 1302 |
| 1298 // Let the redirects callbacks complete. | 1303 // Let the redirects callbacks complete. |
| 1299 base::RunLoop().RunUntilIdle(); | 1304 base::RunLoop().RunUntilIdle(); |
| 1300 | 1305 |
| 1301 std::string serialized = WaitForSerializedReport( | 1306 std::string serialized = WaitForSerializedReport( |
| 1302 report.get(), true /* did_proceed*/, 1 /* num_visit */); | 1307 report.get(), true /* did_proceed*/, 1 /* num_visit */); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1324 pb_resource->set_parent_id(3); | 1329 pb_resource->set_parent_id(3); |
| 1325 pb_resource->set_url(kSecondRedirectURL); | 1330 pb_resource->set_url(kSecondRedirectURL); |
| 1326 pb_resource = expected.add_resources(); | 1331 pb_resource = expected.add_resources(); |
| 1327 pb_resource->set_id(3); | 1332 pb_resource->set_id(3); |
| 1328 pb_resource->set_url(kFirstRedirectURL); | 1333 pb_resource->set_url(kFirstRedirectURL); |
| 1329 | 1334 |
| 1330 VerifyResults(actual, expected); | 1335 VerifyResults(actual, expected); |
| 1331 } | 1336 } |
| 1332 | 1337 |
| 1333 } // namespace safe_browsing | 1338 } // namespace safe_browsing |
| OLD | NEW |