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

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

Issue 7237034: sql::MetaTable.next_download_id, DownloadManager::GetNextId() (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: merge AGAIN Created 9 years, 4 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) 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/file_path.h" 10 #include "base/file_path.h"
10 #include "base/message_loop.h" 11 #include "base/message_loop.h"
11 #include "base/process_util.h" 12 #include "base/process_util.h"
12 #include "content/browser/browser_thread.h" 13 #include "content/browser/browser_thread.h"
13 #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"
14 #include "content/browser/mock_resource_context.h" 16 #include "content/browser/mock_resource_context.h"
15 #include "content/browser/renderer_host/global_request_id.h" 17 #include "content/browser/renderer_host/global_request_id.h"
16 #include "content/browser/renderer_host/resource_dispatcher_host.h" 18 #include "content/browser/renderer_host/resource_dispatcher_host.h"
17 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" 19 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
18 #include "content/browser/renderer_host/resource_handler.h" 20 #include "content/browser/renderer_host/resource_handler.h"
19 #include "content/browser/renderer_host/resource_message_filter.h" 21 #include "content/browser/renderer_host/resource_message_filter.h"
20 #include "content/common/resource_messages.h" 22 #include "content/common/resource_messages.h"
21 #include "content/common/resource_response.h" 23 #include "content/common/resource_response.h"
22 #include "content/common/view_messages.h" 24 #include "content/common/view_messages.h"
23 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 1126
1125 void* iter = NULL; 1127 void* iter = NULL;
1126 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); 1128 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id));
1127 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); 1129 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status));
1128 1130
1129 EXPECT_EQ(1, request_id); 1131 EXPECT_EQ(1, request_id);
1130 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); 1132 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status());
1131 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, status.os_error()); 1133 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, status.os_error());
1132 } 1134 }
1133 1135
1136 namespace {
1137 DownloadId MockNextDownloadId() {
1138 return DownloadId(reinterpret_cast<DownloadManager*>(0xFFFFFFFF), 0);
1139 }
1140 }
1141
1134 // Test for http://crbug.com/76202 . We don't want to destroy a 1142 // Test for http://crbug.com/76202 . We don't want to destroy a
1135 // download request prematurely when processing a cancellation from 1143 // download request prematurely when processing a cancellation from
1136 // the renderer. 1144 // the renderer.
1137 TEST_F(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { 1145 TEST_F(ResourceDispatcherHostTest, IgnoreCancelForDownloads) {
1138 EXPECT_EQ(0, host_.pending_requests()); 1146 EXPECT_EQ(0, host_.pending_requests());
1139 1147
1140 int render_view_id = 0; 1148 int render_view_id = 0;
1141 int request_id = 1; 1149 int request_id = 1;
1142 1150
1143 std::string response("HTTP\n" 1151 std::string response("HTTP\n"
1144 "Content-disposition: attachment; filename=foo\n\n"); 1152 "Content-disposition: attachment; filename=foo\n\n");
1145 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), 1153 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(),
1146 response.size())); 1154 response.size()));
1147 std::string response_data("01234567890123456789\x01foobar"); 1155 std::string response_data("01234567890123456789\x01foobar");
1148 1156
1149 SetResponse(raw_headers, response_data); 1157 SetResponse(raw_headers, response_data);
1150 SetResourceType(ResourceType::MAIN_FRAME); 1158 SetResourceType(ResourceType::MAIN_FRAME);
1151 HandleScheme("http"); 1159 HandleScheme("http");
1152 1160
1153 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); 1161 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah"));
1162 content::MockResourceContext::GetInstance()->set_next_download_id_thunk(
1163 base::Bind(&MockNextDownloadId));
1154 // Return some data so that the request is identified as a download 1164 // Return some data so that the request is identified as a download
1155 // and the proper resource handlers are created. 1165 // and the proper resource handlers are created.
1156 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 1166 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
1157 1167
1158 // And now simulate a cancellation coming from the renderer. 1168 // And now simulate a cancellation coming from the renderer.
1159 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); 1169 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id);
1160 bool msg_was_ok; 1170 bool msg_was_ok;
1161 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); 1171 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok);
1162 1172
1163 // Since the request had already started processing as a download, 1173 // Since the request had already started processing as a download,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 const net::URLRequestStatus& status, 1253 const net::URLRequestStatus& status,
1244 const std::string& info) { 1254 const std::string& info) {
1245 return true; 1255 return true;
1246 } 1256 }
1247 1257
1248 void OnRequestClosed() {} 1258 void OnRequestClosed() {}
1249 1259
1250 private: 1260 private:
1251 DISALLOW_COPY_AND_ASSIGN(DummyResourceHandler); 1261 DISALLOW_COPY_AND_ASSIGN(DummyResourceHandler);
1252 }; 1262 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698