| 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 "base/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 9 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
| 10 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 10 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 274 |
| 275 void SetUnsafeResourceToCurrent() { | 275 void SetUnsafeResourceToCurrent() { |
| 276 SafeBrowsingService::UnsafeResource resource; | 276 SafeBrowsingService::UnsafeResource resource; |
| 277 resource.url = GURL("http://www.malware.com/"); | 277 resource.url = GURL("http://www.malware.com/"); |
| 278 resource.original_url = contents()->GetURL(); | 278 resource.original_url = contents()->GetURL(); |
| 279 resource.is_subresource = true; | 279 resource.is_subresource = true; |
| 280 resource.threat_type = SafeBrowsingService::URL_MALWARE; | 280 resource.threat_type = SafeBrowsingService::URL_MALWARE; |
| 281 resource.callback = base::Bind(&EmptyUrlCheckCallback); | 281 resource.callback = base::Bind(&EmptyUrlCheckCallback); |
| 282 resource.render_process_host_id = contents()->GetRenderProcessHost()-> | 282 resource.render_process_host_id = contents()->GetRenderProcessHost()-> |
| 283 GetID(); | 283 GetID(); |
| 284 resource.render_view_id = contents()->GetRenderViewHost()->routing_id(); | 284 resource.render_view_id = contents()->GetRenderViewHost()->GetRoutingID(); |
| 285 csd_host_->OnSafeBrowsingHit(resource); | 285 csd_host_->OnSafeBrowsingHit(resource); |
| 286 resource.callback.Reset(); | 286 resource.callback.Reset(); |
| 287 ASSERT_TRUE(csd_host_->DidShowSBInterstitial()); | 287 ASSERT_TRUE(csd_host_->DidShowSBInterstitial()); |
| 288 ASSERT_TRUE(csd_host_->unsafe_resource_.get()); | 288 ASSERT_TRUE(csd_host_->unsafe_resource_.get()); |
| 289 // Test that the resource above was copied. | 289 // Test that the resource above was copied. |
| 290 EXPECT_EQ(resource.url, csd_host_->unsafe_resource_->url); | 290 EXPECT_EQ(resource.url, csd_host_->unsafe_resource_->url); |
| 291 EXPECT_EQ(resource.original_url, csd_host_->unsafe_resource_->original_url); | 291 EXPECT_EQ(resource.original_url, csd_host_->unsafe_resource_->original_url); |
| 292 EXPECT_EQ(resource.is_subresource, | 292 EXPECT_EQ(resource.is_subresource, |
| 293 csd_host_->unsafe_resource_->is_subresource); | 293 csd_host_->unsafe_resource_->is_subresource); |
| 294 EXPECT_EQ(resource.threat_type, csd_host_->unsafe_resource_->threat_type); | 294 EXPECT_EQ(resource.threat_type, csd_host_->unsafe_resource_->threat_type); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 | 420 |
| 421 MessageLoop::current()->RunAllPending(); | 421 MessageLoop::current()->RunAllPending(); |
| 422 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 422 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
| 423 EXPECT_EQ(phishing_url, resource.url); | 423 EXPECT_EQ(phishing_url, resource.url); |
| 424 EXPECT_EQ(phishing_url, resource.original_url); | 424 EXPECT_EQ(phishing_url, resource.original_url); |
| 425 EXPECT_FALSE(resource.is_subresource); | 425 EXPECT_FALSE(resource.is_subresource); |
| 426 EXPECT_EQ(SafeBrowsingService::CLIENT_SIDE_PHISHING_URL, | 426 EXPECT_EQ(SafeBrowsingService::CLIENT_SIDE_PHISHING_URL, |
| 427 resource.threat_type); | 427 resource.threat_type); |
| 428 EXPECT_EQ(contents()->GetRenderProcessHost()->GetID(), | 428 EXPECT_EQ(contents()->GetRenderProcessHost()->GetID(), |
| 429 resource.render_process_host_id); | 429 resource.render_process_host_id); |
| 430 EXPECT_EQ(contents()->GetRenderViewHost()->routing_id(), | 430 EXPECT_EQ(contents()->GetRenderViewHost()->GetRoutingID(), |
| 431 resource.render_view_id); | 431 resource.render_view_id); |
| 432 | 432 |
| 433 // Make sure the client object will be deleted. | 433 // Make sure the client object will be deleted. |
| 434 BrowserThread::PostTask( | 434 BrowserThread::PostTask( |
| 435 BrowserThread::IO, | 435 BrowserThread::IO, |
| 436 FROM_HERE, | 436 FROM_HERE, |
| 437 base::Bind(&MockSafeBrowsingService::InvokeOnBlockingPageComplete, | 437 base::Bind(&MockSafeBrowsingService::InvokeOnBlockingPageComplete, |
| 438 sb_service_.get(), resource.callback)); | 438 sb_service_.get(), resource.callback)); |
| 439 // Since the CsdClient object will be deleted on the UI thread I need | 439 // Since the CsdClient object will be deleted on the UI thread I need |
| 440 // to run the UI message loop. Post a task to stop the UI message loop | 440 // to run the UI message loop. Post a task to stop the UI message loop |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 512 |
| 513 MessageLoop::current()->RunAllPending(); | 513 MessageLoop::current()->RunAllPending(); |
| 514 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 514 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
| 515 EXPECT_EQ(other_phishing_url, resource.url); | 515 EXPECT_EQ(other_phishing_url, resource.url); |
| 516 EXPECT_EQ(other_phishing_url, resource.original_url); | 516 EXPECT_EQ(other_phishing_url, resource.original_url); |
| 517 EXPECT_FALSE(resource.is_subresource); | 517 EXPECT_FALSE(resource.is_subresource); |
| 518 EXPECT_EQ(SafeBrowsingService::CLIENT_SIDE_PHISHING_URL, | 518 EXPECT_EQ(SafeBrowsingService::CLIENT_SIDE_PHISHING_URL, |
| 519 resource.threat_type); | 519 resource.threat_type); |
| 520 EXPECT_EQ(contents()->GetRenderProcessHost()->GetID(), | 520 EXPECT_EQ(contents()->GetRenderProcessHost()->GetID(), |
| 521 resource.render_process_host_id); | 521 resource.render_process_host_id); |
| 522 EXPECT_EQ(contents()->GetRenderViewHost()->routing_id(), | 522 EXPECT_EQ(contents()->GetRenderViewHost()->GetRoutingID(), |
| 523 resource.render_view_id); | 523 resource.render_view_id); |
| 524 | 524 |
| 525 // Make sure the client object will be deleted. | 525 // Make sure the client object will be deleted. |
| 526 BrowserThread::PostTask( | 526 BrowserThread::PostTask( |
| 527 BrowserThread::IO, | 527 BrowserThread::IO, |
| 528 FROM_HERE, | 528 FROM_HERE, |
| 529 base::Bind(&MockSafeBrowsingService::InvokeOnBlockingPageComplete, | 529 base::Bind(&MockSafeBrowsingService::InvokeOnBlockingPageComplete, |
| 530 sb_service_.get(), resource.callback)); | 530 sb_service_.get(), resource.callback)); |
| 531 // Since the CsdClient object will be deleted on the UI thread I need | 531 // Since the CsdClient object will be deleted on the UI thread I need |
| 532 // to run the UI message loop. Post a task to stop the UI message loop | 532 // to run the UI message loop. Post a task to stop the UI message loop |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 &kFalse, &kFalse); | 606 &kFalse, &kFalse); |
| 607 NavigateAndCommit(url); | 607 NavigateAndCommit(url); |
| 608 WaitAndCheckPreClassificationChecks(); | 608 WaitAndCheckPreClassificationChecks(); |
| 609 | 609 |
| 610 const IPC::Message* msg = process()->sink().GetFirstMessageMatching( | 610 const IPC::Message* msg = process()->sink().GetFirstMessageMatching( |
| 611 SafeBrowsingMsg_StartPhishingDetection::ID); | 611 SafeBrowsingMsg_StartPhishingDetection::ID); |
| 612 ASSERT_TRUE(msg); | 612 ASSERT_TRUE(msg); |
| 613 Tuple1<GURL> actual_url; | 613 Tuple1<GURL> actual_url; |
| 614 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); | 614 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); |
| 615 EXPECT_EQ(url, actual_url.a); | 615 EXPECT_EQ(url, actual_url.a); |
| 616 EXPECT_EQ(rvh()->routing_id(), msg->routing_id()); | 616 EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); |
| 617 process()->sink().ClearMessages(); | 617 process()->sink().ClearMessages(); |
| 618 | 618 |
| 619 // Now try an in-page navigation. This should not trigger an IPC. | 619 // Now try an in-page navigation. This should not trigger an IPC. |
| 620 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)).Times(0); | 620 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)).Times(0); |
| 621 url = GURL("http://host.com/#foo"); | 621 url = GURL("http://host.com/#foo"); |
| 622 ExpectPreClassificationChecks(url, NULL, NULL, NULL, NULL, NULL, NULL); | 622 ExpectPreClassificationChecks(url, NULL, NULL, NULL, NULL, NULL, NULL); |
| 623 NavigateAndCommit(url); | 623 NavigateAndCommit(url); |
| 624 WaitAndCheckPreClassificationChecks(); | 624 WaitAndCheckPreClassificationChecks(); |
| 625 | 625 |
| 626 msg = process()->sink().GetFirstMessageMatching( | 626 msg = process()->sink().GetFirstMessageMatching( |
| 627 SafeBrowsingMsg_StartPhishingDetection::ID); | 627 SafeBrowsingMsg_StartPhishingDetection::ID); |
| 628 ASSERT_FALSE(msg); | 628 ASSERT_FALSE(msg); |
| 629 | 629 |
| 630 // Check that XHTML is supported, in addition to the default HTML type. | 630 // Check that XHTML is supported, in addition to the default HTML type. |
| 631 // Note: for this test to work correctly, the new URL must be on the | 631 // Note: for this test to work correctly, the new URL must be on the |
| 632 // same domain as the previous URL, otherwise it will create a new | 632 // same domain as the previous URL, otherwise it will create a new |
| 633 // RenderViewHost that won't have the mime type set. | 633 // RenderViewHost that won't have the mime type set. |
| 634 url = GURL("http://host.com/xhtml"); | 634 url = GURL("http://host.com/xhtml"); |
| 635 rvh()->set_contents_mime_type("application/xhtml+xml"); | 635 rvh()->set_contents_mime_type("application/xhtml+xml"); |
| 636 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | 636 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
| 637 &kFalse, &kFalse); | 637 &kFalse, &kFalse); |
| 638 NavigateAndCommit(url); | 638 NavigateAndCommit(url); |
| 639 WaitAndCheckPreClassificationChecks(); | 639 WaitAndCheckPreClassificationChecks(); |
| 640 msg = process()->sink().GetFirstMessageMatching( | 640 msg = process()->sink().GetFirstMessageMatching( |
| 641 SafeBrowsingMsg_StartPhishingDetection::ID); | 641 SafeBrowsingMsg_StartPhishingDetection::ID); |
| 642 ASSERT_TRUE(msg); | 642 ASSERT_TRUE(msg); |
| 643 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); | 643 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); |
| 644 EXPECT_EQ(url, actual_url.a); | 644 EXPECT_EQ(url, actual_url.a); |
| 645 EXPECT_EQ(rvh()->routing_id(), msg->routing_id()); | 645 EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); |
| 646 process()->sink().ClearMessages(); | 646 process()->sink().ClearMessages(); |
| 647 | 647 |
| 648 // Navigate to a new host, which should cause another IPC. | 648 // Navigate to a new host, which should cause another IPC. |
| 649 url = GURL("http://host2.com/"); | 649 url = GURL("http://host2.com/"); |
| 650 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | 650 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
| 651 &kFalse, &kFalse); | 651 &kFalse, &kFalse); |
| 652 NavigateAndCommit(url); | 652 NavigateAndCommit(url); |
| 653 WaitAndCheckPreClassificationChecks(); | 653 WaitAndCheckPreClassificationChecks(); |
| 654 msg = process()->sink().GetFirstMessageMatching( | 654 msg = process()->sink().GetFirstMessageMatching( |
| 655 SafeBrowsingMsg_StartPhishingDetection::ID); | 655 SafeBrowsingMsg_StartPhishingDetection::ID); |
| 656 ASSERT_TRUE(msg); | 656 ASSERT_TRUE(msg); |
| 657 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); | 657 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); |
| 658 EXPECT_EQ(url, actual_url.a); | 658 EXPECT_EQ(url, actual_url.a); |
| 659 EXPECT_EQ(rvh()->routing_id(), msg->routing_id()); | 659 EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); |
| 660 process()->sink().ClearMessages(); | 660 process()->sink().ClearMessages(); |
| 661 | 661 |
| 662 // If the mime type is not one that we support, no IPC should be triggered. | 662 // If the mime type is not one that we support, no IPC should be triggered. |
| 663 // Note: for this test to work correctly, the new URL must be on the | 663 // Note: for this test to work correctly, the new URL must be on the |
| 664 // same domain as the previous URL, otherwise it will create a new | 664 // same domain as the previous URL, otherwise it will create a new |
| 665 // RenderViewHost that won't have the mime type set. | 665 // RenderViewHost that won't have the mime type set. |
| 666 url = GURL("http://host2.com/image.jpg"); | 666 url = GURL("http://host2.com/image.jpg"); |
| 667 rvh()->set_contents_mime_type("image/jpeg"); | 667 rvh()->set_contents_mime_type("image/jpeg"); |
| 668 ExpectPreClassificationChecks(url, NULL, NULL, NULL, NULL, NULL, NULL); | 668 ExpectPreClassificationChecks(url, NULL, NULL, NULL, NULL, NULL, NULL); |
| 669 NavigateAndCommit(url); | 669 NavigateAndCommit(url); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 url = GURL("http://host6.com/"); | 706 url = GURL("http://host6.com/"); |
| 707 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, &kTrue, | 707 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, &kTrue, |
| 708 NULL); | 708 NULL); |
| 709 NavigateAndCommit(url); | 709 NavigateAndCommit(url); |
| 710 WaitAndCheckPreClassificationChecks(); | 710 WaitAndCheckPreClassificationChecks(); |
| 711 msg = process()->sink().GetFirstMessageMatching( | 711 msg = process()->sink().GetFirstMessageMatching( |
| 712 SafeBrowsingMsg_StartPhishingDetection::ID); | 712 SafeBrowsingMsg_StartPhishingDetection::ID); |
| 713 ASSERT_TRUE(msg); | 713 ASSERT_TRUE(msg); |
| 714 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); | 714 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); |
| 715 EXPECT_EQ(url, actual_url.a); | 715 EXPECT_EQ(url, actual_url.a); |
| 716 EXPECT_EQ(rvh()->routing_id(), msg->routing_id()); | 716 EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); |
| 717 process()->sink().ClearMessages(); | 717 process()->sink().ClearMessages(); |
| 718 | 718 |
| 719 // If the url isn't in the cache and we are over the reporting limit, we | 719 // If the url isn't in the cache and we are over the reporting limit, we |
| 720 // don't do classification. | 720 // don't do classification. |
| 721 url = GURL("http://host7.com/"); | 721 url = GURL("http://host7.com/"); |
| 722 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | 722 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
| 723 &kFalse, &kTrue); | 723 &kFalse, &kTrue); |
| 724 NavigateAndCommit(url); | 724 NavigateAndCommit(url); |
| 725 WaitAndCheckPreClassificationChecks(); | 725 WaitAndCheckPreClassificationChecks(); |
| 726 msg = process()->sink().GetFirstMessageMatching( | 726 msg = process()->sink().GetFirstMessageMatching( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 748 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 748 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
| 749 EXPECT_EQ(url, resource.url); | 749 EXPECT_EQ(url, resource.url); |
| 750 EXPECT_EQ(url, resource.original_url); | 750 EXPECT_EQ(url, resource.original_url); |
| 751 resource.callback.Reset(); | 751 resource.callback.Reset(); |
| 752 msg = process()->sink().GetFirstMessageMatching( | 752 msg = process()->sink().GetFirstMessageMatching( |
| 753 SafeBrowsingMsg_StartPhishingDetection::ID); | 753 SafeBrowsingMsg_StartPhishingDetection::ID); |
| 754 ASSERT_FALSE(msg); | 754 ASSERT_FALSE(msg); |
| 755 } | 755 } |
| 756 | 756 |
| 757 } // namespace safe_browsing | 757 } // namespace safe_browsing |
| OLD | NEW |