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

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

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

Powered by Google App Engine
This is Rietveld 408576698