| 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/time.h" | 9 #include "base/time.h" |
| 10 #include "chrome/browser/history/history_backend.h" | 10 #include "chrome/browser/history/history_backend.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 GetCache()->GetBackend(&cache, cb.callback()); | 117 GetCache()->GetBackend(&cache, cb.callback()); |
| 118 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 118 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 119 | 119 |
| 120 std::string empty; | 120 std::string empty; |
| 121 WriteToEntry(cache, kMalwareURL, kMalwareHeaders, kMalwareData); | 121 WriteToEntry(cache, kMalwareURL, kMalwareHeaders, kMalwareData); |
| 122 WriteToEntry(cache, kLandingURL, kLandingHeaders, kLandingData); | 122 WriteToEntry(cache, kLandingURL, kLandingHeaders, kLandingData); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void QuitUIMessageLoop() { | 125 void QuitUIMessageLoop() { |
| 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 127 BrowserThread::PostTask(BrowserThread::UI, | 127 BrowserThread::PostTask( |
| 128 FROM_HERE, | 128 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); |
| 129 MessageLoop::QuitClosure()); | |
| 130 } | 129 } |
| 131 | 130 |
| 132 // Lets us provide a MockURLRequestContext with an HTTP Cache we pre-populate. | 131 // Lets us provide a MockURLRequestContext with an HTTP Cache we pre-populate. |
| 133 // Also exposes the constructor. | 132 // Also exposes the constructor. |
| 134 class MalwareDetailsWrap : public MalwareDetails { | 133 class MalwareDetailsWrap : public MalwareDetails { |
| 135 public: | 134 public: |
| 136 MalwareDetailsWrap( | 135 MalwareDetailsWrap( |
| 137 SafeBrowsingUIManager* ui_manager, | 136 SafeBrowsingUIManager* ui_manager, |
| 138 WebContents* web_contents, | 137 WebContents* web_contents, |
| 139 const SafeBrowsingUIManager::UnsafeResource& unsafe_resource, | 138 const SafeBrowsingUIManager::UnsafeResource& unsafe_resource, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 return lhs->id() < rhs->id(); | 206 return lhs->id() < rhs->id(); |
| 208 } | 207 } |
| 209 | 208 |
| 210 std::string WaitForSerializedReport(MalwareDetails* report) { | 209 std::string WaitForSerializedReport(MalwareDetails* report) { |
| 211 BrowserThread::PostTask( | 210 BrowserThread::PostTask( |
| 212 BrowserThread::IO, | 211 BrowserThread::IO, |
| 213 FROM_HERE, | 212 FROM_HERE, |
| 214 base::Bind(&MalwareDetails::FinishCollection, report)); | 213 base::Bind(&MalwareDetails::FinishCollection, report)); |
| 215 // Wait for the callback (SendSerializedMalwareDetails). | 214 // Wait for the callback (SendSerializedMalwareDetails). |
| 216 DVLOG(1) << "Waiting for SendSerializedMalwareDetails"; | 215 DVLOG(1) << "Waiting for SendSerializedMalwareDetails"; |
| 217 MessageLoop::current()->Run(); | 216 base::MessageLoop::current()->Run(); |
| 218 return ui_manager_->GetSerialized(); | 217 return ui_manager_->GetSerialized(); |
| 219 } | 218 } |
| 220 | 219 |
| 221 HistoryService* history_service() { | 220 HistoryService* history_service() { |
| 222 return HistoryServiceFactory::GetForProfile(profile(), | 221 return HistoryServiceFactory::GetForProfile(profile(), |
| 223 Profile::EXPLICIT_ACCESS); | 222 Profile::EXPLICIT_ACCESS); |
| 224 } | 223 } |
| 225 | 224 |
| 226 protected: | 225 protected: |
| 227 void InitResource(UnsafeResource* resource, | 226 void InitResource(UnsafeResource* resource, |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 child_node.url = GURL(kDOMChildURL); | 413 child_node.url = GURL(kDOMChildURL); |
| 415 child_node.tag_name = "iframe"; | 414 child_node.tag_name = "iframe"; |
| 416 child_node.parent = GURL(kDOMParentURL); | 415 child_node.parent = GURL(kDOMParentURL); |
| 417 params.push_back(child_node); | 416 params.push_back(child_node); |
| 418 SafeBrowsingHostMsg_MalwareDOMDetails_Node parent_node; | 417 SafeBrowsingHostMsg_MalwareDOMDetails_Node parent_node; |
| 419 parent_node.url = GURL(kDOMParentURL); | 418 parent_node.url = GURL(kDOMParentURL); |
| 420 parent_node.children.push_back(GURL(kDOMChildURL)); | 419 parent_node.children.push_back(GURL(kDOMChildURL)); |
| 421 params.push_back(parent_node); | 420 params.push_back(parent_node); |
| 422 report->OnReceivedMalwareDOMDetails(params); | 421 report->OnReceivedMalwareDOMDetails(params); |
| 423 | 422 |
| 424 MessageLoop::current()->RunUntilIdle(); | 423 base::MessageLoop::current()->RunUntilIdle(); |
| 425 | 424 |
| 426 std::string serialized = WaitForSerializedReport(report); | 425 std::string serialized = WaitForSerializedReport(report); |
| 427 ClientMalwareReportRequest actual; | 426 ClientMalwareReportRequest actual; |
| 428 actual.ParseFromString(serialized); | 427 actual.ParseFromString(serialized); |
| 429 | 428 |
| 430 ClientMalwareReportRequest expected; | 429 ClientMalwareReportRequest expected; |
| 431 expected.set_malware_url(kMalwareURL); | 430 expected.set_malware_url(kMalwareURL); |
| 432 expected.set_page_url(kLandingURL); | 431 expected.set_page_url(kLandingURL); |
| 433 expected.set_referrer_url(""); | 432 expected.set_referrer_url(""); |
| 434 | 433 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 BrowserThread::PostTask( | 545 BrowserThread::PostTask( |
| 547 BrowserThread::IO, FROM_HERE, | 546 BrowserThread::IO, FROM_HERE, |
| 548 base::Bind(&FillCache, | 547 base::Bind(&FillCache, |
| 549 make_scoped_refptr(profile()->GetRequestContext()))); | 548 make_scoped_refptr(profile()->GetRequestContext()))); |
| 550 | 549 |
| 551 // The cache collection starts after the IPC from the DOM is fired. | 550 // The cache collection starts after the IPC from the DOM is fired. |
| 552 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; | 551 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; |
| 553 report->OnReceivedMalwareDOMDetails(params); | 552 report->OnReceivedMalwareDOMDetails(params); |
| 554 | 553 |
| 555 // Let the cache callbacks complete | 554 // Let the cache callbacks complete |
| 556 MessageLoop::current()->RunUntilIdle(); | 555 base::MessageLoop::current()->RunUntilIdle(); |
| 557 | 556 |
| 558 DVLOG(1) << "Getting serialized report"; | 557 DVLOG(1) << "Getting serialized report"; |
| 559 std::string serialized = WaitForSerializedReport(report); | 558 std::string serialized = WaitForSerializedReport(report); |
| 560 ClientMalwareReportRequest actual; | 559 ClientMalwareReportRequest actual; |
| 561 actual.ParseFromString(serialized); | 560 actual.ParseFromString(serialized); |
| 562 | 561 |
| 563 ClientMalwareReportRequest expected; | 562 ClientMalwareReportRequest expected; |
| 564 expected.set_malware_url(kMalwareURL); | 563 expected.set_malware_url(kMalwareURL); |
| 565 expected.set_page_url(kLandingURL); | 564 expected.set_page_url(kLandingURL); |
| 566 expected.set_referrer_url(""); | 565 expected.set_referrer_url(""); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 ui_manager_.get(), web_contents(), resource, | 616 ui_manager_.get(), web_contents(), resource, |
| 618 profile()->GetRequestContext()); | 617 profile()->GetRequestContext()); |
| 619 | 618 |
| 620 // No call to FillCache | 619 // No call to FillCache |
| 621 | 620 |
| 622 // The cache collection starts after the IPC from the DOM is fired. | 621 // The cache collection starts after the IPC from the DOM is fired. |
| 623 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; | 622 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; |
| 624 report->OnReceivedMalwareDOMDetails(params); | 623 report->OnReceivedMalwareDOMDetails(params); |
| 625 | 624 |
| 626 // Let the cache callbacks complete | 625 // Let the cache callbacks complete |
| 627 MessageLoop::current()->RunUntilIdle(); | 626 base::MessageLoop::current()->RunUntilIdle(); |
| 628 | 627 |
| 629 DVLOG(1) << "Getting serialized report"; | 628 DVLOG(1) << "Getting serialized report"; |
| 630 std::string serialized = WaitForSerializedReport(report); | 629 std::string serialized = WaitForSerializedReport(report); |
| 631 ClientMalwareReportRequest actual; | 630 ClientMalwareReportRequest actual; |
| 632 actual.ParseFromString(serialized); | 631 actual.ParseFromString(serialized); |
| 633 | 632 |
| 634 ClientMalwareReportRequest expected; | 633 ClientMalwareReportRequest expected; |
| 635 expected.set_malware_url(kMalwareURL); | 634 expected.set_malware_url(kMalwareURL); |
| 636 expected.set_page_url(kLandingURL); | 635 expected.set_page_url(kLandingURL); |
| 637 expected.set_referrer_url(""); | 636 expected.set_referrer_url(""); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 666 UnsafeResource resource; | 665 UnsafeResource resource; |
| 667 InitResource(&resource, true, GURL(kMalwareURL)); | 666 InitResource(&resource, true, GURL(kMalwareURL)); |
| 668 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( | 667 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( |
| 669 ui_manager_.get(), web_contents(), resource, NULL); | 668 ui_manager_.get(), web_contents(), resource, NULL); |
| 670 | 669 |
| 671 // The redirects collection starts after the IPC from the DOM is fired. | 670 // The redirects collection starts after the IPC from the DOM is fired. |
| 672 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; | 671 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; |
| 673 report->OnReceivedMalwareDOMDetails(params); | 672 report->OnReceivedMalwareDOMDetails(params); |
| 674 | 673 |
| 675 // Let the redirects callbacks complete. | 674 // Let the redirects callbacks complete. |
| 676 MessageLoop::current()->RunUntilIdle(); | 675 base::MessageLoop::current()->RunUntilIdle(); |
| 677 | 676 |
| 678 std::string serialized = WaitForSerializedReport(report); | 677 std::string serialized = WaitForSerializedReport(report); |
| 679 ClientMalwareReportRequest actual; | 678 ClientMalwareReportRequest actual; |
| 680 actual.ParseFromString(serialized); | 679 actual.ParseFromString(serialized); |
| 681 | 680 |
| 682 ClientMalwareReportRequest expected; | 681 ClientMalwareReportRequest expected; |
| 683 expected.set_malware_url(kMalwareURL); | 682 expected.set_malware_url(kMalwareURL); |
| 684 expected.set_page_url(kLandingURL); | 683 expected.set_page_url(kLandingURL); |
| 685 expected.set_referrer_url(""); | 684 expected.set_referrer_url(""); |
| 686 | 685 |
| 687 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); | 686 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); |
| 688 pb_resource->set_id(0); | 687 pb_resource->set_id(0); |
| 689 pb_resource->set_url(kLandingURL); | 688 pb_resource->set_url(kLandingURL); |
| 690 pb_resource = expected.add_resources(); | 689 pb_resource = expected.add_resources(); |
| 691 pb_resource->set_id(1); | 690 pb_resource->set_id(1); |
| 692 pb_resource->set_parent_id(2); | 691 pb_resource->set_parent_id(2); |
| 693 pb_resource->set_url(kMalwareURL); | 692 pb_resource->set_url(kMalwareURL); |
| 694 pb_resource = expected.add_resources(); | 693 pb_resource = expected.add_resources(); |
| 695 pb_resource->set_id(2); | 694 pb_resource->set_id(2); |
| 696 pb_resource->set_parent_id(3); | 695 pb_resource->set_parent_id(3); |
| 697 pb_resource->set_url(kSecondRedirectURL); | 696 pb_resource->set_url(kSecondRedirectURL); |
| 698 pb_resource = expected.add_resources(); | 697 pb_resource = expected.add_resources(); |
| 699 pb_resource->set_id(3); | 698 pb_resource->set_id(3); |
| 700 pb_resource->set_url(kFirstRedirectURL); | 699 pb_resource->set_url(kFirstRedirectURL); |
| 701 | 700 |
| 702 VerifyResults(actual, expected); | 701 VerifyResults(actual, expected); |
| 703 } | 702 } |
| OLD | NEW |