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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/process.h" | 9 #include "base/process.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
13 #include "chrome/common/render_messages_params.h" | 13 #include "chrome/common/render_messages_params.h" |
14 #include "chrome/common/resource_dispatcher.h" | 14 #include "chrome/common/resource_dispatcher.h" |
15 #include "chrome/common/resource_response.h" | 15 #include "content/common/resource_response.h" |
| 16 #include "content/common/resource_messages.h" |
16 #include "net/base/upload_data.h" | 17 #include "net/base/upload_data.h" |
17 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "webkit/appcache/appcache_interfaces.h" | 20 #include "webkit/appcache/appcache_interfaces.h" |
20 | 21 |
21 using webkit_glue::ResourceLoaderBridge; | 22 using webkit_glue::ResourceLoaderBridge; |
22 using webkit_glue::ResourceResponseInfo; | 23 using webkit_glue::ResourceResponseInfo; |
23 | 24 |
24 static const char test_page_url[] = "http://www.google.com/"; | 25 static const char test_page_url[] = "http://www.google.com/"; |
25 static const char test_page_headers[] = | 26 static const char test_page_headers[] = |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 message_queue_.push_back(IPC::Message(*msg)); | 93 message_queue_.push_back(IPC::Message(*msg)); |
93 delete msg; | 94 delete msg; |
94 return true; | 95 return true; |
95 } | 96 } |
96 | 97 |
97 // Emulates the browser process and processes the pending IPC messages, | 98 // Emulates the browser process and processes the pending IPC messages, |
98 // returning the hardcoded file contents. | 99 // returning the hardcoded file contents. |
99 void ProcessMessages() { | 100 void ProcessMessages() { |
100 while (!message_queue_.empty()) { | 101 while (!message_queue_.empty()) { |
101 int request_id; | 102 int request_id; |
102 ViewHostMsg_Resource_Request request; | 103 ResourceHostMsg_Request request; |
103 ASSERT_TRUE(ViewHostMsg_RequestResource::Read( | 104 ASSERT_TRUE(ResourceHostMsg_RequestResource::Read( |
104 &message_queue_[0], &request_id, &request)); | 105 &message_queue_[0], &request_id, &request)); |
105 | 106 |
106 // check values | 107 // check values |
107 EXPECT_EQ(test_page_url, request.url.spec()); | 108 EXPECT_EQ(test_page_url, request.url.spec()); |
108 | 109 |
109 // received response message | 110 // received response message |
110 ResourceResponseHead response; | 111 ResourceResponseHead response; |
111 std::string raw_headers(test_page_headers); | 112 std::string raw_headers(test_page_headers); |
112 std::replace(raw_headers.begin(), raw_headers.end(), '\n', '\0'); | 113 std::replace(raw_headers.begin(), raw_headers.end(), '\n', '\0'); |
113 response.headers = new net::HttpResponseHeaders(raw_headers); | 114 response.headers = new net::HttpResponseHeaders(raw_headers); |
114 response.mime_type = test_page_mime_type; | 115 response.mime_type = test_page_mime_type; |
115 response.charset = test_page_charset; | 116 response.charset = test_page_charset; |
116 dispatcher_->OnReceivedResponse(request_id, response); | 117 dispatcher_->OnReceivedResponse(request_id, response); |
117 | 118 |
118 // received data message with the test contents | 119 // received data message with the test contents |
119 base::SharedMemory shared_mem; | 120 base::SharedMemory shared_mem; |
120 EXPECT_TRUE(shared_mem.CreateAndMapAnonymous(test_page_contents_len)); | 121 EXPECT_TRUE(shared_mem.CreateAndMapAnonymous(test_page_contents_len)); |
121 char* put_data_here = static_cast<char*>(shared_mem.memory()); | 122 char* put_data_here = static_cast<char*>(shared_mem.memory()); |
122 memcpy(put_data_here, test_page_contents, test_page_contents_len); | 123 memcpy(put_data_here, test_page_contents, test_page_contents_len); |
123 base::SharedMemoryHandle dup_handle; | 124 base::SharedMemoryHandle dup_handle; |
124 EXPECT_TRUE(shared_mem.GiveToProcess( | 125 EXPECT_TRUE(shared_mem.GiveToProcess( |
125 base::Process::Current().handle(), &dup_handle)); | 126 base::Process::Current().handle(), &dup_handle)); |
126 dispatcher_->OnReceivedData( | 127 dispatcher_->OnReceivedData( |
127 message_queue_[0], request_id, dup_handle, test_page_contents_len); | 128 message_queue_[0], request_id, dup_handle, test_page_contents_len); |
128 | 129 |
129 message_queue_.erase(message_queue_.begin()); | 130 message_queue_.erase(message_queue_.begin()); |
130 | 131 |
131 // read the ack message. | 132 // read the ack message. |
132 Tuple1<int> request_ack; | 133 Tuple1<int> request_ack; |
133 ASSERT_TRUE(ViewHostMsg_DataReceived_ACK::Read( | 134 ASSERT_TRUE(ResourceHostMsg_DataReceived_ACK::Read( |
134 &message_queue_[0], &request_ack)); | 135 &message_queue_[0], &request_ack)); |
135 | 136 |
136 ASSERT_EQ(request_ack.a, request_id); | 137 ASSERT_EQ(request_ack.a, request_id); |
137 | 138 |
138 message_queue_.erase(message_queue_.begin()); | 139 message_queue_.erase(message_queue_.begin()); |
139 } | 140 } |
140 } | 141 } |
141 | 142 |
142 protected: | 143 protected: |
143 // testing::Test | 144 // testing::Test |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 return true; | 224 return true; |
224 } | 225 } |
225 | 226 |
226 void InitMessages() { | 227 void InitMessages() { |
227 set_defer_loading(true); | 228 set_defer_loading(true); |
228 | 229 |
229 ResourceResponseHead response_head; | 230 ResourceResponseHead response_head; |
230 response_head.status.set_status(net::URLRequestStatus::SUCCESS); | 231 response_head.status.set_status(net::URLRequestStatus::SUCCESS); |
231 | 232 |
232 IPC::Message* response_message = | 233 IPC::Message* response_message = |
233 new ViewMsg_Resource_ReceivedResponse(0, 0, response_head); | 234 new ResourceMsg_ReceivedResponse(0, 0, response_head); |
234 | 235 |
235 dispatcher_->OnMessageReceived(*response_message); | 236 dispatcher_->OnMessageReceived(*response_message); |
236 | 237 |
237 delete response_message; | 238 delete response_message; |
238 | 239 |
239 // Duplicate the shared memory handle so both the test and the callee can | 240 // Duplicate the shared memory handle so both the test and the callee can |
240 // close their copy. | 241 // close their copy. |
241 base::SharedMemoryHandle duplicated_handle; | 242 base::SharedMemoryHandle duplicated_handle; |
242 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), | 243 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), |
243 &duplicated_handle)); | 244 &duplicated_handle)); |
244 | 245 |
245 response_message = | 246 response_message = |
246 new ViewMsg_Resource_DataReceived(0, 0, duplicated_handle, 100); | 247 new ResourceMsg_DataReceived(0, 0, duplicated_handle, 100); |
247 | 248 |
248 dispatcher_->OnMessageReceived(*response_message); | 249 dispatcher_->OnMessageReceived(*response_message); |
249 | 250 |
250 delete response_message; | 251 delete response_message; |
251 | 252 |
252 set_defer_loading(false); | 253 set_defer_loading(false); |
253 } | 254 } |
254 | 255 |
255 // ResourceLoaderBridge::Peer methods. | 256 // ResourceLoaderBridge::Peer methods. |
256 virtual void OnUploadProgress(uint64 position, uint64 size) { | 257 virtual void OnUploadProgress(uint64 position, uint64 size) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 316 |
316 ResourceLoaderBridge* bridge = CreateBridge(); | 317 ResourceLoaderBridge* bridge = CreateBridge(); |
317 | 318 |
318 bridge->Start(this); | 319 bridge->Start(this); |
319 InitMessages(); | 320 InitMessages(); |
320 | 321 |
321 // Dispatch deferred messages. | 322 // Dispatch deferred messages. |
322 message_loop.RunAllPending(); | 323 message_loop.RunAllPending(); |
323 delete bridge; | 324 delete bridge; |
324 } | 325 } |
OLD | NEW |