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

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

Issue 8372073: Merge 8401001 r107836 into branch 912: Fix history importing by delaying DownloadManager creation. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/912/src/
Patch Set: 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/browser_thread.h" 13 #include "content/browser/browser_thread.h"
14 #include "content/browser/child_process_security_policy.h" 14 #include "content/browser/child_process_security_policy.h"
15 #include "content/browser/download/download_id.h" 15 #include "content/browser/download/download_id.h"
16 #include "content/browser/download/download_id_factory.h"
16 #include "content/browser/mock_resource_context.h" 17 #include "content/browser/mock_resource_context.h"
17 #include "content/browser/renderer_host/dummy_resource_handler.h" 18 #include "content/browser/renderer_host/dummy_resource_handler.h"
18 #include "content/browser/renderer_host/global_request_id.h" 19 #include "content/browser/renderer_host/global_request_id.h"
19 #include "content/browser/renderer_host/resource_dispatcher_host.h" 20 #include "content/browser/renderer_host/resource_dispatcher_host.h"
20 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" 21 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
21 #include "content/browser/renderer_host/resource_handler.h" 22 #include "content/browser/renderer_host/resource_handler.h"
22 #include "content/browser/renderer_host/resource_message_filter.h" 23 #include "content/browser/renderer_host/resource_message_filter.h"
23 #include "content/common/resource_messages.h" 24 #include "content/common/resource_messages.h"
24 #include "content/common/resource_response.h" 25 #include "content/common/resource_response.h"
25 #include "content/common/view_messages.h" 26 #include "content/common/view_messages.h"
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 1129
1129 void* iter = NULL; 1130 void* iter = NULL;
1130 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); 1131 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id));
1131 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); 1132 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status));
1132 1133
1133 EXPECT_EQ(1, request_id); 1134 EXPECT_EQ(1, request_id);
1134 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); 1135 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status());
1135 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, status.error()); 1136 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, status.error());
1136 } 1137 }
1137 1138
1138 namespace {
1139 DownloadId MockNextDownloadId() {
1140 return DownloadId(reinterpret_cast<DownloadManager*>(0xFFFFFFFF), 0);
1141 }
1142 }
1143
1144 // Test for http://crbug.com/76202 . We don't want to destroy a 1139 // Test for http://crbug.com/76202 . We don't want to destroy a
1145 // download request prematurely when processing a cancellation from 1140 // download request prematurely when processing a cancellation from
1146 // the renderer. 1141 // the renderer.
1147 TEST_F(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { 1142 TEST_F(ResourceDispatcherHostTest, IgnoreCancelForDownloads) {
1148 EXPECT_EQ(0, host_.pending_requests()); 1143 EXPECT_EQ(0, host_.pending_requests());
1149 1144
1150 int render_view_id = 0; 1145 int render_view_id = 0;
1151 int request_id = 1; 1146 int request_id = 1;
1152 1147
1153 std::string response("HTTP\n" 1148 std::string response("HTTP\n"
1154 "Content-disposition: attachment; filename=foo\n\n"); 1149 "Content-disposition: attachment; filename=foo\n\n");
1155 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), 1150 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(),
1156 response.size())); 1151 response.size()));
1157 std::string response_data("01234567890123456789\x01foobar"); 1152 std::string response_data("01234567890123456789\x01foobar");
1158 1153
1159 SetResponse(raw_headers, response_data); 1154 SetResponse(raw_headers, response_data);
1160 SetResourceType(ResourceType::MAIN_FRAME); 1155 SetResourceType(ResourceType::MAIN_FRAME);
1161 HandleScheme("http"); 1156 HandleScheme("http");
1162 1157
1163 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); 1158 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah"));
1164 content::MockResourceContext::GetInstance()->set_next_download_id_thunk( 1159 scoped_refptr<DownloadIdFactory> id_factory(
1165 base::Bind(&MockNextDownloadId)); 1160 new DownloadIdFactory("valid DownloadId::Domain"));
1161 content::MockResourceContext::GetInstance()->set_download_id_factory(
1162 id_factory);
1166 // Return some data so that the request is identified as a download 1163 // Return some data so that the request is identified as a download
1167 // and the proper resource handlers are created. 1164 // and the proper resource handlers are created.
1168 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 1165 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
1169 1166
1170 // And now simulate a cancellation coming from the renderer. 1167 // And now simulate a cancellation coming from the renderer.
1171 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); 1168 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id);
1172 bool msg_was_ok; 1169 bool msg_was_ok;
1173 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); 1170 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok);
1174 1171
1175 // Since the request had already started processing as a download, 1172 // Since the request had already started processing as a download,
(...skipping 15 matching lines...) Expand all
1191 "Content-disposition: attachment; filename=foo\n\n"); 1188 "Content-disposition: attachment; filename=foo\n\n");
1192 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), 1189 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(),
1193 response.size())); 1190 response.size()));
1194 std::string response_data("01234567890123456789\x01foobar"); 1191 std::string response_data("01234567890123456789\x01foobar");
1195 1192
1196 SetResponse(raw_headers, response_data); 1193 SetResponse(raw_headers, response_data);
1197 SetResourceType(ResourceType::MAIN_FRAME); 1194 SetResourceType(ResourceType::MAIN_FRAME);
1198 HandleScheme("http"); 1195 HandleScheme("http");
1199 1196
1200 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); 1197 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah"));
1201 content::MockResourceContext::GetInstance()->set_next_download_id_thunk( 1198 scoped_refptr<DownloadIdFactory> id_factory(
1202 base::Bind(&MockNextDownloadId)); 1199 new DownloadIdFactory("valid DownloadId::Domain"));
1200 content::MockResourceContext::GetInstance()->set_download_id_factory(
1201 id_factory);
1203 // Return some data so that the request is identified as a download 1202 // Return some data so that the request is identified as a download
1204 // and the proper resource handlers are created. 1203 // and the proper resource handlers are created.
1205 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 1204 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
1206 1205
1207 // And now simulate a cancellation coming from the renderer. 1206 // And now simulate a cancellation coming from the renderer.
1208 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); 1207 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id);
1209 bool msg_was_ok; 1208 bool msg_was_ok;
1210 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); 1209 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok);
1211 1210
1212 // Since the request had already started processing as a download, 1211 // Since the request had already started processing as a download,
1213 // the cancellation above should have been ignored and the request 1212 // the cancellation above should have been ignored and the request
1214 // should still be alive. 1213 // should still be alive.
1215 EXPECT_EQ(1, host_.pending_requests()); 1214 EXPECT_EQ(1, host_.pending_requests());
1216 1215
1217 // Cancelling by other methods shouldn't work either. 1216 // Cancelling by other methods shouldn't work either.
1218 host_.CancelRequestsForProcess(render_view_id); 1217 host_.CancelRequestsForProcess(render_view_id);
1219 EXPECT_EQ(1, host_.pending_requests()); 1218 EXPECT_EQ(1, host_.pending_requests());
1220 1219
1221 // Cancelling by context should work. 1220 // Cancelling by context should work.
1222 host_.CancelRequestsForContext(&filter_->resource_context()); 1221 host_.CancelRequestsForContext(&filter_->resource_context());
1223 EXPECT_EQ(0, host_.pending_requests()); 1222 EXPECT_EQ(0, host_.pending_requests());
1224 } 1223 }
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