| Index: chrome/browser/safe_browsing/malware_details_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/safe_browsing/malware_details_unittest.cc (revision 84048)
|
| +++ chrome/browser/safe_browsing/malware_details_unittest.cc (working copy)
|
| @@ -6,8 +6,11 @@
|
|
|
| #include "base/pickle.h"
|
| #include "base/time.h"
|
| +#include "chrome/browser/history/history.h"
|
| +#include "chrome/browser/history/history_backend.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/safe_browsing/malware_details.h"
|
| +#include "chrome/browser/safe_browsing/malware_details_history.h"
|
| #include "chrome/browser/safe_browsing/report.pb.h"
|
| #include "chrome/common/render_messages.h"
|
| #include "chrome/common/safe_browsing/safebrowsing_messages.h"
|
| @@ -175,10 +178,13 @@
|
| // The URLFetcher checks that the messageloop type is IO.
|
| ASSERT_TRUE(io_thread_.StartWithOptions(
|
| base::Thread::Options(MessageLoop::TYPE_IO, 0)));
|
| +
|
| + profile_->CreateHistoryService(true /* delete_file */, false /* no_db */);
|
| }
|
|
|
| virtual void TearDown() {
|
| io_thread_.Stop();
|
| + profile_->DestroyHistoryService();
|
| RenderViewHostTestHarness::TearDown();
|
| }
|
|
|
| @@ -200,6 +206,10 @@
|
| return sb_service_->GetSerialized();
|
| }
|
|
|
| + HistoryService* history_service() {
|
| + return profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
|
| + }
|
| +
|
| protected:
|
| void InitResource(SafeBrowsingService::UnsafeResource* resource,
|
| ResourceType::Type resource_type,
|
| @@ -278,6 +288,18 @@
|
| }
|
| }
|
|
|
| + // Adds a page to history.
|
| + // The redirects is the redirect url chain leading to the url.
|
| + void AddPageToHistory(const GURL& url,
|
| + history::RedirectList* redirects) {
|
| + // The last item of the redirect chain has to be the final url when adding
|
| + // to history backend.
|
| + redirects->push_back(url);
|
| + history_service()->AddPage(
|
| + url, static_cast<void*>(this), 0, GURL(), PageTransition::TYPED,
|
| + *redirects, history::SOURCE_BROWSED, false);
|
| + }
|
| +
|
| BrowserThread ui_thread_;
|
| BrowserThread io_thread_;
|
| scoped_refptr<MockSafeBrowsingService> sb_service_;
|
| @@ -592,3 +614,60 @@
|
|
|
| VerifyResults(actual, expected);
|
| }
|
| +
|
| +// Test getting redirects from history service.
|
| +TEST_F(MalwareDetailsTest, HistoryServiceUrls) {
|
| + // Add content to history service.
|
| + // There are two redirect urls before reacing malware url:
|
| + // kFirstRedirectURL -> kSecondRedirectURL -> kMalwareURL
|
| + GURL baseurl(kMalwareURL);
|
| + history::RedirectList redirects;
|
| + redirects.push_back(GURL(kFirstRedirectURL));
|
| + redirects.push_back(GURL(kSecondRedirectURL));
|
| + AddPageToHistory(baseurl, &redirects);
|
| + // Wait for history service operation finished.
|
| + profile_->BlockUntilHistoryProcessesPendingRequests();
|
| +
|
| + controller().LoadURL(GURL(kLandingURL), GURL(), PageTransition::TYPED);
|
| +
|
| + SafeBrowsingService::UnsafeResource resource;
|
| + InitResource(&resource, ResourceType::SUB_RESOURCE, GURL(kMalwareURL));
|
| + scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
|
| + sb_service_.get(), contents(), resource, NULL);
|
| +
|
| + // Reset the history service pointer.
|
| + report->redirects_collector_->SetHistory(history_service());
|
| +
|
| + // The redirects collection starts after the IPC from the DOM is fired.
|
| + std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params;
|
| + report->OnReceivedMalwareDOMDetails(params);
|
| +
|
| + // Let the redirects callbacks complete.
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + std::string serialized = WaitForSerializedReport(report);
|
| + ClientMalwareReportRequest actual;
|
| + actual.ParseFromString(serialized);
|
| +
|
| + ClientMalwareReportRequest expected;
|
| + expected.set_malware_url(kMalwareURL);
|
| + expected.set_page_url(kLandingURL);
|
| + expected.set_referrer_url("");
|
| +
|
| + ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources();
|
| + pb_resource->set_id(0);
|
| + pb_resource->set_url(kLandingURL);
|
| + pb_resource = expected.add_resources();
|
| + pb_resource->set_id(1);
|
| + pb_resource->set_parent_id(2);
|
| + pb_resource->set_url(kMalwareURL);
|
| + pb_resource = expected.add_resources();
|
| + pb_resource->set_id(2);
|
| + pb_resource->set_parent_id(3);
|
| + pb_resource->set_url(kSecondRedirectURL);
|
| + pb_resource = expected.add_resources();
|
| + pb_resource->set_id(3);
|
| + pb_resource->set_url(kFirstRedirectURL);
|
| +
|
| + VerifyResults(actual, expected);
|
| +}
|
|
|