diff options
author | kewang@google.com <kewang@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-24 06:46:43 +0000 |
---|---|---|
committer | kewang@google.com <kewang@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-24 06:46:43 +0000 |
commit | db9b9ef42d41951c20e135b7076fb72c9869e35f (patch) | |
tree | 29072ab2e2f4fd7b60060ec625b8ce88cc61a41d /chrome/browser/safe_browsing/malware_details_unittest.cc | |
parent | 03616ddad3438ddde91cbc2c405444346fb341f3 (diff) | |
download | chromium_src-db9b9ef42d41951c20e135b7076fb72c9869e35f.zip chromium_src-db9b9ef42d41951c20e135b7076fb72c9869e35f.tar.gz chromium_src-db9b9ef42d41951c20e135b7076fb72c9869e35f.tar.bz2 |
Querying the history service to get the redirect information for urls.
Bug=60831
TEST=unit_tests
Review URL: http://codereview.chromium.org/6710004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86401 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/safe_browsing/malware_details_unittest.cc')
-rw-r--r-- | chrome/browser/safe_browsing/malware_details_unittest.cc | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/chrome/browser/safe_browsing/malware_details_unittest.cc b/chrome/browser/safe_browsing/malware_details_unittest.cc index 73ccfdd..60a65f8 100644 --- a/chrome/browser/safe_browsing/malware_details_unittest.cc +++ b/chrome/browser/safe_browsing/malware_details_unittest.cc @@ -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" @@ -176,10 +179,13 @@ class MalwareDetailsTest : public RenderViewHostTestHarness { // 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(); } @@ -201,6 +207,10 @@ class MalwareDetailsTest : public RenderViewHostTestHarness { return sb_service_->GetSerialized(); } + HistoryService* history_service() { + return profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); + } + protected: void InitResource(SafeBrowsingService::UnsafeResource* resource, ResourceType::Type resource_type, @@ -283,6 +293,18 @@ class MalwareDetailsTest : public RenderViewHostTestHarness { resource->response().remote_ip()); } + // 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_; @@ -603,3 +625,60 @@ TEST_F(MalwareDetailsTest, HTTPCacheNoEntries) { 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); +} |