| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/pickle.h" | 7 #include "base/pickle.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "chrome/browser/history/history.h" | 9 #include "chrome/browser/history/history.h" |
| 10 #include "chrome/browser/history/history_backend.h" | 10 #include "chrome/browser/history/history_backend.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/safe_browsing/malware_details.h" | 12 #include "chrome/browser/safe_browsing/malware_details.h" |
| 13 #include "chrome/browser/safe_browsing/malware_details_history.h" | 13 #include "chrome/browser/safe_browsing/malware_details_history.h" |
| 14 #include "chrome/browser/safe_browsing/report.pb.h" | 14 #include "chrome/browser/safe_browsing/report.pb.h" |
| 15 #include "chrome/common/render_messages.h" | 15 #include "chrome/common/render_messages.h" |
| 16 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 16 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
| 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 17 #include "chrome/test/base/test_url_request_context_getter.h" | 18 #include "chrome/test/base/test_url_request_context_getter.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
| 19 #include "content/browser/browser_thread.h" | 20 #include "content/browser/browser_thread.h" |
| 20 #include "content/browser/renderer_host/test_render_view_host.h" | |
| 21 #include "content/browser/tab_contents/navigation_entry.h" | 21 #include "content/browser/tab_contents/navigation_entry.h" |
| 22 #include "content/browser/tab_contents/test_tab_contents.h" | 22 #include "content/browser/tab_contents/test_tab_contents.h" |
| 23 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
| 24 #include "net/base/test_completion_callback.h" | 24 #include "net/base/test_completion_callback.h" |
| 25 #include "net/disk_cache/disk_cache.h" | 25 #include "net/disk_cache/disk_cache.h" |
| 26 #include "net/http/http_cache.h" | 26 #include "net/http/http_cache.h" |
| 27 #include "net/http/http_response_headers.h" | 27 #include "net/http/http_response_headers.h" |
| 28 #include "net/http/http_response_info.h" | 28 #include "net/http/http_response_info.h" |
| 29 #include "net/http/http_util.h" | 29 #include "net/http/http_util.h" |
| 30 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 return serialized_; | 157 return serialized_; |
| 158 } | 158 } |
| 159 | 159 |
| 160 private: | 160 private: |
| 161 std::string serialized_; | 161 std::string serialized_; |
| 162 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingService); | 162 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingService); |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 } // namespace. | 165 } // namespace. |
| 166 | 166 |
| 167 class MalwareDetailsTest : public RenderViewHostTestHarness { | 167 class MalwareDetailsTest : public ChromeRenderViewHostTestHarness { |
| 168 public: | 168 public: |
| 169 MalwareDetailsTest() | 169 MalwareDetailsTest() |
| 170 : ui_thread_(BrowserThread::UI, &message_loop_), | 170 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 171 io_thread_(BrowserThread::IO), | 171 io_thread_(BrowserThread::IO), |
| 172 sb_service_(new MockSafeBrowsingService()) { | 172 sb_service_(new MockSafeBrowsingService()) { |
| 173 } | 173 } |
| 174 | 174 |
| 175 virtual void SetUp() { | 175 virtual void SetUp() { |
| 176 RenderViewHostTestHarness::SetUp(); | 176 ChromeRenderViewHostTestHarness::SetUp(); |
| 177 // The URLFetcher checks that the messageloop type is IO. | 177 // The URLFetcher checks that the messageloop type is IO. |
| 178 ASSERT_TRUE(io_thread_.StartWithOptions( | 178 ASSERT_TRUE(io_thread_.StartWithOptions( |
| 179 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 179 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| 180 | 180 |
| 181 profile_->CreateHistoryService(true /* delete_file */, false /* no_db */); | 181 profile()->CreateHistoryService(true /* delete_file */, false /* no_db */); |
| 182 } | 182 } |
| 183 | 183 |
| 184 virtual void TearDown() { | 184 virtual void TearDown() { |
| 185 io_thread_.Stop(); | 185 io_thread_.Stop(); |
| 186 profile_->DestroyHistoryService(); | 186 profile()->DestroyHistoryService(); |
| 187 RenderViewHostTestHarness::TearDown(); | 187 ChromeRenderViewHostTestHarness::TearDown(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 static bool ResourceLessThan( | 190 static bool ResourceLessThan( |
| 191 const ClientMalwareReportRequest::Resource* lhs, | 191 const ClientMalwareReportRequest::Resource* lhs, |
| 192 const ClientMalwareReportRequest::Resource* rhs) { | 192 const ClientMalwareReportRequest::Resource* rhs) { |
| 193 return lhs->id() < rhs->id(); | 193 return lhs->id() < rhs->id(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 std::string WaitForSerializedReport(MalwareDetails* report) { | 196 std::string WaitForSerializedReport(MalwareDetails* report) { |
| 197 BrowserThread::PostTask( | 197 BrowserThread::PostTask( |
| 198 BrowserThread::IO, | 198 BrowserThread::IO, |
| 199 FROM_HERE, | 199 FROM_HERE, |
| 200 NewRunnableMethod( | 200 NewRunnableMethod( |
| 201 report, &MalwareDetails::FinishCollection)); | 201 report, &MalwareDetails::FinishCollection)); |
| 202 // Wait for the callback (SendSerializedMalwareDetails). | 202 // Wait for the callback (SendSerializedMalwareDetails). |
| 203 DVLOG(1) << "Waiting for SendSerializedMalwareDetails"; | 203 DVLOG(1) << "Waiting for SendSerializedMalwareDetails"; |
| 204 MessageLoop::current()->Run(); | 204 MessageLoop::current()->Run(); |
| 205 return sb_service_->GetSerialized(); | 205 return sb_service_->GetSerialized(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 HistoryService* history_service() { | 208 HistoryService* history_service() { |
| 209 return profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 209 return profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 210 } | 210 } |
| 211 | 211 |
| 212 protected: | 212 protected: |
| 213 void InitResource(SafeBrowsingService::UnsafeResource* resource, | 213 void InitResource(SafeBrowsingService::UnsafeResource* resource, |
| 214 bool is_subresource, | 214 bool is_subresource, |
| 215 const GURL& url) { | 215 const GURL& url) { |
| 216 resource->client = NULL; | 216 resource->client = NULL; |
| 217 resource->url = url; | 217 resource->url = url; |
| 218 resource->is_subresource = is_subresource; | 218 resource->is_subresource = is_subresource; |
| 219 resource->threat_type = SafeBrowsingService::URL_MALWARE; | 219 resource->threat_type = SafeBrowsingService::URL_MALWARE; |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 TEST_F(MalwareDetailsTest, HistoryServiceUrls) { | 635 TEST_F(MalwareDetailsTest, HistoryServiceUrls) { |
| 636 // Add content to history service. | 636 // Add content to history service. |
| 637 // There are two redirect urls before reacing malware url: | 637 // There are two redirect urls before reacing malware url: |
| 638 // kFirstRedirectURL -> kSecondRedirectURL -> kMalwareURL | 638 // kFirstRedirectURL -> kSecondRedirectURL -> kMalwareURL |
| 639 GURL baseurl(kMalwareURL); | 639 GURL baseurl(kMalwareURL); |
| 640 history::RedirectList redirects; | 640 history::RedirectList redirects; |
| 641 redirects.push_back(GURL(kFirstRedirectURL)); | 641 redirects.push_back(GURL(kFirstRedirectURL)); |
| 642 redirects.push_back(GURL(kSecondRedirectURL)); | 642 redirects.push_back(GURL(kSecondRedirectURL)); |
| 643 AddPageToHistory(baseurl, &redirects); | 643 AddPageToHistory(baseurl, &redirects); |
| 644 // Wait for history service operation finished. | 644 // Wait for history service operation finished. |
| 645 profile_->BlockUntilHistoryProcessesPendingRequests(); | 645 profile()->BlockUntilHistoryProcessesPendingRequests(); |
| 646 | 646 |
| 647 controller().LoadURL(GURL(kLandingURL), GURL(), PageTransition::TYPED, | 647 controller().LoadURL(GURL(kLandingURL), GURL(), PageTransition::TYPED, |
| 648 std::string()); | 648 std::string()); |
| 649 | 649 |
| 650 SafeBrowsingService::UnsafeResource resource; | 650 SafeBrowsingService::UnsafeResource resource; |
| 651 InitResource(&resource, true, GURL(kMalwareURL)); | 651 InitResource(&resource, true, GURL(kMalwareURL)); |
| 652 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( | 652 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( |
| 653 sb_service_.get(), contents(), resource, NULL); | 653 sb_service_.get(), contents(), resource, NULL); |
| 654 | 654 |
| 655 // The redirects collection starts after the IPC from the DOM is fired. | 655 // The redirects collection starts after the IPC from the DOM is fired. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 678 pb_resource = expected.add_resources(); | 678 pb_resource = expected.add_resources(); |
| 679 pb_resource->set_id(2); | 679 pb_resource->set_id(2); |
| 680 pb_resource->set_parent_id(3); | 680 pb_resource->set_parent_id(3); |
| 681 pb_resource->set_url(kSecondRedirectURL); | 681 pb_resource->set_url(kSecondRedirectURL); |
| 682 pb_resource = expected.add_resources(); | 682 pb_resource = expected.add_resources(); |
| 683 pb_resource->set_id(3); | 683 pb_resource->set_id(3); |
| 684 pb_resource->set_url(kFirstRedirectURL); | 684 pb_resource->set_url(kFirstRedirectURL); |
| 685 | 685 |
| 686 VerifyResults(actual, expected); | 686 VerifyResults(actual, expected); |
| 687 } | 687 } |
| OLD | NEW |