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

Side by Side Diff: content/browser/renderer_host/resource_dispatcher_host_unittest.cc

Issue 8401001: Fix history importing by delaying DownloadManager creation. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: fix ifndefs Created 9 years, 1 month 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) 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 "content/browser/renderer_host/resource_dispatcher_host.h" 5 #include "content/browser/renderer_host/resource_dispatcher_host.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/process_util.h" 12 #include "base/process_util.h"
13 #include "content/browser/child_process_security_policy.h" 13 #include "content/browser/child_process_security_policy.h"
14 #include "content/browser/download/download_id.h" 14 #include "content/browser/download/download_id.h"
15 #include "content/browser/download/download_id_factory.h"
15 #include "content/browser/mock_resource_context.h" 16 #include "content/browser/mock_resource_context.h"
16 #include "content/browser/renderer_host/dummy_resource_handler.h" 17 #include "content/browser/renderer_host/dummy_resource_handler.h"
17 #include "content/browser/renderer_host/global_request_id.h" 18 #include "content/browser/renderer_host/global_request_id.h"
18 #include "content/browser/renderer_host/resource_dispatcher_host.h" 19 #include "content/browser/renderer_host/resource_dispatcher_host.h"
19 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" 20 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
20 #include "content/browser/renderer_host/resource_handler.h" 21 #include "content/browser/renderer_host/resource_handler.h"
21 #include "content/browser/renderer_host/resource_message_filter.h" 22 #include "content/browser/renderer_host/resource_message_filter.h"
22 #include "content/common/resource_messages.h" 23 #include "content/common/resource_messages.h"
23 #include "content/common/resource_response.h" 24 #include "content/common/resource_response.h"
24 #include "content/common/view_messages.h" 25 #include "content/common/view_messages.h"
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 "Content-disposition: attachment; filename=foo\n\n"); 1155 "Content-disposition: attachment; filename=foo\n\n");
1155 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), 1156 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(),
1156 response.size())); 1157 response.size()));
1157 std::string response_data("01234567890123456789\x01foobar"); 1158 std::string response_data("01234567890123456789\x01foobar");
1158 1159
1159 SetResponse(raw_headers, response_data); 1160 SetResponse(raw_headers, response_data);
1160 SetResourceType(ResourceType::MAIN_FRAME); 1161 SetResourceType(ResourceType::MAIN_FRAME);
1161 HandleScheme("http"); 1162 HandleScheme("http");
1162 1163
1163 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); 1164 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah"));
1164 content::MockResourceContext::GetInstance()->set_next_download_id_thunk( 1165 scoped_refptr<DownloadIdFactory> id_factory(
1165 base::Bind(&MockNextDownloadId)); 1166 new DownloadIdFactory("valid DownloadId::Domain"));
1167 content::MockResourceContext::GetInstance()->set_download_id_factory(
1168 id_factory);
1166 // Return some data so that the request is identified as a download 1169 // Return some data so that the request is identified as a download
1167 // and the proper resource handlers are created. 1170 // and the proper resource handlers are created.
1168 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 1171 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
1169 1172
1170 // And now simulate a cancellation coming from the renderer. 1173 // And now simulate a cancellation coming from the renderer.
1171 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); 1174 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id);
1172 bool msg_was_ok; 1175 bool msg_was_ok;
1173 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); 1176 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok);
1174 1177
1175 // Since the request had already started processing as a download, 1178 // Since the request had already started processing as a download,
(...skipping 15 matching lines...) Expand all
1191 "Content-disposition: attachment; filename=foo\n\n"); 1194 "Content-disposition: attachment; filename=foo\n\n");
1192 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), 1195 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(),
1193 response.size())); 1196 response.size()));
1194 std::string response_data("01234567890123456789\x01foobar"); 1197 std::string response_data("01234567890123456789\x01foobar");
1195 1198
1196 SetResponse(raw_headers, response_data); 1199 SetResponse(raw_headers, response_data);
1197 SetResourceType(ResourceType::MAIN_FRAME); 1200 SetResourceType(ResourceType::MAIN_FRAME);
1198 HandleScheme("http"); 1201 HandleScheme("http");
1199 1202
1200 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); 1203 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah"));
1201 content::MockResourceContext::GetInstance()->set_next_download_id_thunk( 1204 scoped_refptr<DownloadIdFactory> id_factory(
1202 base::Bind(&MockNextDownloadId)); 1205 new DownloadIdFactory("valid DownloadId::Domain"));
1206 content::MockResourceContext::GetInstance()->set_download_id_factory(
1207 id_factory);
1203 // Return some data so that the request is identified as a download 1208 // Return some data so that the request is identified as a download
1204 // and the proper resource handlers are created. 1209 // and the proper resource handlers are created.
1205 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 1210 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
1206 1211
1207 // And now simulate a cancellation coming from the renderer. 1212 // And now simulate a cancellation coming from the renderer.
1208 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); 1213 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id);
1209 bool msg_was_ok; 1214 bool msg_was_ok;
1210 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); 1215 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok);
1211 1216
1212 // Since the request had already started processing as a download, 1217 // Since the request had already started processing as a download,
1213 // the cancellation above should have been ignored and the request 1218 // the cancellation above should have been ignored and the request
1214 // should still be alive. 1219 // should still be alive.
1215 EXPECT_EQ(1, host_.pending_requests()); 1220 EXPECT_EQ(1, host_.pending_requests());
1216 1221
1217 // Cancelling by other methods shouldn't work either. 1222 // Cancelling by other methods shouldn't work either.
1218 host_.CancelRequestsForProcess(render_view_id); 1223 host_.CancelRequestsForProcess(render_view_id);
1219 EXPECT_EQ(1, host_.pending_requests()); 1224 EXPECT_EQ(1, host_.pending_requests());
1220 1225
1221 // Cancelling by context should work. 1226 // Cancelling by context should work.
1222 host_.CancelRequestsForContext(&filter_->resource_context()); 1227 host_.CancelRequestsForContext(&filter_->resource_context());
1223 EXPECT_EQ(0, host_.pending_requests()); 1228 EXPECT_EQ(0, host_.pending_requests());
1224 } 1229 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/resource_dispatcher_host.cc ('k') | content/browser/resource_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698