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

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

Issue 9706012: Add abstractions that let embedders drive tests of WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove CONTENT_EXPORT on statically linked functions. Merge to head for commit. Created 8 years, 9 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.h" 10 #include "chrome/browser/history/history.h"
11 #include "chrome/browser/history/history_backend.h" 11 #include "chrome/browser/history/history_backend.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/safe_browsing/malware_details.h" 13 #include "chrome/browser/safe_browsing/malware_details.h"
14 #include "chrome/browser/safe_browsing/malware_details_history.h" 14 #include "chrome/browser/safe_browsing/malware_details_history.h"
15 #include "chrome/browser/safe_browsing/report.pb.h" 15 #include "chrome/browser/safe_browsing/report.pb.h"
16 #include "chrome/common/render_messages.h" 16 #include "chrome/common/render_messages.h"
17 #include "chrome/common/safe_browsing/safebrowsing_messages.h" 17 #include "chrome/common/safe_browsing/safebrowsing_messages.h"
18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
19 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
20 #include "content/browser/tab_contents/test_tab_contents.h" 20 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/web_contents.h"
21 #include "content/test/test_browser_thread.h" 22 #include "content/test/test_browser_thread.h"
22 #include "net/base/io_buffer.h" 23 #include "net/base/io_buffer.h"
24 #include "net/base/net_errors.h"
23 #include "net/base/test_completion_callback.h" 25 #include "net/base/test_completion_callback.h"
24 #include "net/disk_cache/disk_cache.h" 26 #include "net/disk_cache/disk_cache.h"
25 #include "net/http/http_cache.h" 27 #include "net/http/http_cache.h"
26 #include "net/http/http_response_headers.h" 28 #include "net/http/http_response_headers.h"
27 #include "net/http/http_response_info.h" 29 #include "net/http/http_response_info.h"
28 #include "net/http/http_util.h" 30 #include "net/http/http_util.h"
29 #include "net/url_request/url_request_context.h" 31 #include "net/url_request/url_request_context.h"
30 #include "net/url_request/url_request_context_getter.h" 32 #include "net/url_request/url_request_context_getter.h"
31 33
32 static const char* kOriginalLandingURL = "http://www.originallandingpage.com/"; 34 static const char* kOriginalLandingURL = "http://www.originallandingpage.com/";
(...skipping 11 matching lines...) Expand all
44 46
45 static const char* kLandingURL = "http://www.landingpage.com/"; 47 static const char* kLandingURL = "http://www.landingpage.com/";
46 static const char* kLandingHeaders = 48 static const char* kLandingHeaders =
47 "HTTP/1.1 200 OK\n" 49 "HTTP/1.1 200 OK\n"
48 "Content-Type: text/html\n" 50 "Content-Type: text/html\n"
49 "Content-Length: 1024\n" 51 "Content-Length: 1024\n"
50 "Set-Cookie: tastycookie\n"; // This header is stripped. 52 "Set-Cookie: tastycookie\n"; // This header is stripped.
51 static const char* kLandingData = "<iframe src='http://www.malware.com'>"; 53 static const char* kLandingData = "<iframe src='http://www.malware.com'>";
52 54
53 using content::BrowserThread; 55 using content::BrowserThread;
56 using content::WebContents;
54 using safe_browsing::ClientMalwareReportRequest; 57 using safe_browsing::ClientMalwareReportRequest;
55 58
56 namespace { 59 namespace {
57 60
58 void WriteHeaders(disk_cache::Entry* entry, const std::string headers) { 61 void WriteHeaders(disk_cache::Entry* entry, const std::string headers) {
59 net::HttpResponseInfo responseinfo; 62 net::HttpResponseInfo responseinfo;
60 std::string raw_headers = net::HttpUtil::AssembleRawHeaders( 63 std::string raw_headers = net::HttpUtil::AssembleRawHeaders(
61 headers.c_str(), headers.size()); 64 headers.c_str(), headers.size());
62 responseinfo.socket_address = net::HostPortPair("1.2.3.4", 80); 65 responseinfo.socket_address = net::HostPortPair("1.2.3.4", 80);
63 responseinfo.headers = new net::HttpResponseHeaders(raw_headers); 66 responseinfo.headers = new net::HttpResponseHeaders(raw_headers);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 BrowserThread::PostTask(BrowserThread::UI, 124 BrowserThread::PostTask(BrowserThread::UI,
122 FROM_HERE, 125 FROM_HERE,
123 MessageLoop::QuitClosure()); 126 MessageLoop::QuitClosure());
124 } 127 }
125 128
126 // Lets us provide a MockURLRequestContext with an HTTP Cache we pre-populate. 129 // Lets us provide a MockURLRequestContext with an HTTP Cache we pre-populate.
127 // Also exposes the constructor. 130 // Also exposes the constructor.
128 class MalwareDetailsWrap : public MalwareDetails { 131 class MalwareDetailsWrap : public MalwareDetails {
129 public: 132 public:
130 MalwareDetailsWrap(SafeBrowsingService* sb_service, 133 MalwareDetailsWrap(SafeBrowsingService* sb_service,
131 TabContents* tab_contents, 134 WebContents* web_contents,
132 const SafeBrowsingService::UnsafeResource& unsafe_resource, 135 const SafeBrowsingService::UnsafeResource& unsafe_resource,
133 net::URLRequestContextGetter* request_context_getter) 136 net::URLRequestContextGetter* request_context_getter)
134 : MalwareDetails(sb_service, tab_contents, unsafe_resource) { 137 : MalwareDetails(sb_service, web_contents, unsafe_resource) {
135 request_context_getter_ = request_context_getter; 138 request_context_getter_ = request_context_getter;
136 } 139 }
137 140
138 virtual ~MalwareDetailsWrap() {} 141 virtual ~MalwareDetailsWrap() {}
139 }; 142 };
140 143
141 class MockSafeBrowsingService : public SafeBrowsingService { 144 class MockSafeBrowsingService : public SafeBrowsingService {
142 public: 145 public:
143 MockSafeBrowsingService() {} 146 MockSafeBrowsingService() {}
144 virtual ~MockSafeBrowsingService() {} 147 virtual ~MockSafeBrowsingService() {}
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 pb_resource = expected.add_resources(); 679 pb_resource = expected.add_resources();
677 pb_resource->set_id(2); 680 pb_resource->set_id(2);
678 pb_resource->set_parent_id(3); 681 pb_resource->set_parent_id(3);
679 pb_resource->set_url(kSecondRedirectURL); 682 pb_resource->set_url(kSecondRedirectURL);
680 pb_resource = expected.add_resources(); 683 pb_resource = expected.add_resources();
681 pb_resource->set_id(3); 684 pb_resource->set_id(3);
682 pb_resource->set_url(kFirstRedirectURL); 685 pb_resource->set_url(kFirstRedirectURL);
683 686
684 VerifyResults(actual, expected); 687 VerifyResults(actual, expected);
685 } 688 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698