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 "chrome/renderer/safe_browsing/render_view_fake_resources_test.h" | 5 #include "chrome/renderer/safe_browsing/render_view_fake_resources_test.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/process.h" | 10 #include "base/process.h" |
11 #include "base/shared_memory.h" | 11 #include "base/shared_memory.h" |
12 #include "chrome/common/dom_storage_common.h" | 12 #include "chrome/common/dom_storage_common.h" |
13 #include "chrome/common/main_function_params.h" | 13 #include "chrome/common/main_function_params.h" |
14 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
15 #include "chrome/common/render_messages_params.h" | 15 #include "chrome/common/render_messages_params.h" |
16 #include "chrome/common/resource_response.h" | |
17 #include "chrome/common/sandbox_init_wrapper.h" | 16 #include "chrome/common/sandbox_init_wrapper.h" |
18 #include "chrome/renderer/mock_render_process.h" | 17 #include "chrome/renderer/mock_render_process.h" |
19 #include "chrome/renderer/render_thread.h" | 18 #include "chrome/renderer/render_thread.h" |
20 #include "chrome/renderer/render_view.h" | 19 #include "chrome/renderer/render_view.h" |
21 #include "chrome/renderer/renderer_main_platform_delegate.h" | 20 #include "chrome/renderer/renderer_main_platform_delegate.h" |
| 21 #include "content/common/resource_messages.h" |
| 22 #include "content/common/resource_response.h" |
22 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
23 #include "net/base/upload_data.h" | 24 #include "net/base/upload_data.h" |
24 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
25 #include "net/url_request/url_request_status.h" | 26 #include "net/url_request/url_request_status.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
31 #include "webkit/glue/webkit_glue.h" | 32 #include "webkit/glue/webkit_glue.h" |
32 | 33 |
33 namespace safe_browsing { | 34 namespace safe_browsing { |
34 | 35 |
35 const int32 RenderViewFakeResourcesTest::kViewId = 5; | 36 const int32 RenderViewFakeResourcesTest::kViewId = 5; |
36 | 37 |
37 RenderViewFakeResourcesTest::RenderViewFakeResourcesTest() {} | 38 RenderViewFakeResourcesTest::RenderViewFakeResourcesTest() {} |
38 RenderViewFakeResourcesTest::~RenderViewFakeResourcesTest() {} | 39 RenderViewFakeResourcesTest::~RenderViewFakeResourcesTest() {} |
39 | 40 |
40 bool RenderViewFakeResourcesTest::OnMessageReceived( | 41 bool RenderViewFakeResourcesTest::OnMessageReceived( |
41 const IPC::Message& message) { | 42 const IPC::Message& message) { |
42 IPC_BEGIN_MESSAGE_MAP(RenderViewFakeResourcesTest, message) | 43 IPC_BEGIN_MESSAGE_MAP(RenderViewFakeResourcesTest, message) |
43 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnRenderViewReady) | 44 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnRenderViewReady) |
44 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStopLoading, OnDidStopLoading) | 45 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStopLoading, OnDidStopLoading) |
45 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestResource, OnRequestResource) | 46 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) |
46 IPC_END_MESSAGE_MAP() | 47 IPC_END_MESSAGE_MAP() |
47 return true; | 48 return true; |
48 } | 49 } |
49 | 50 |
50 bool RenderViewFakeResourcesTest::Visit(RenderView* render_view) { | 51 bool RenderViewFakeResourcesTest::Visit(RenderView* render_view) { |
51 view_ = render_view; | 52 view_ = render_view; |
52 return false; | 53 return false; |
53 } | 54 } |
54 | 55 |
55 void RenderViewFakeResourcesTest::SetUp() { | 56 void RenderViewFakeResourcesTest::SetUp() { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 message_loop_.Run(); | 133 message_loop_.Run(); |
133 } | 134 } |
134 | 135 |
135 void RenderViewFakeResourcesTest::OnDidStopLoading() { | 136 void RenderViewFakeResourcesTest::OnDidStopLoading() { |
136 message_loop_.Quit(); | 137 message_loop_.Quit(); |
137 } | 138 } |
138 | 139 |
139 void RenderViewFakeResourcesTest::OnRequestResource( | 140 void RenderViewFakeResourcesTest::OnRequestResource( |
140 const IPC::Message& message, | 141 const IPC::Message& message, |
141 int request_id, | 142 int request_id, |
142 const ViewHostMsg_Resource_Request& request_data) { | 143 const ResourceHostMsg_Request& request_data) { |
143 std::string headers, body; | 144 std::string headers, body; |
144 std::map<std::string, std::string>::const_iterator it = | 145 std::map<std::string, std::string>::const_iterator it = |
145 responses_.find(request_data.url.spec()); | 146 responses_.find(request_data.url.spec()); |
146 if (it == responses_.end()) { | 147 if (it == responses_.end()) { |
147 headers = "HTTP/1.1 404 Not Found\0Content-Type:text/html\0\0"; | 148 headers = "HTTP/1.1 404 Not Found\0Content-Type:text/html\0\0"; |
148 body = "content not found"; | 149 body = "content not found"; |
149 } else { | 150 } else { |
150 headers = "HTTP/1.1 200 OK\0Content-Type:text/html\0\0"; | 151 headers = "HTTP/1.1 200 OK\0Content-Type:text/html\0\0"; |
151 body = it->second; | 152 body = it->second; |
152 } | 153 } |
153 | 154 |
154 ResourceResponseHead response_head; | 155 ResourceResponseHead response_head; |
155 response_head.headers = new net::HttpResponseHeaders(headers); | 156 response_head.headers = new net::HttpResponseHeaders(headers); |
156 response_head.mime_type = "text/html"; | 157 response_head.mime_type = "text/html"; |
157 ASSERT_TRUE(channel_->Send(new ViewMsg_Resource_ReceivedResponse( | 158 ASSERT_TRUE(channel_->Send(new ResourceMsg_ReceivedResponse( |
158 message.routing_id(), request_id, response_head))); | 159 message.routing_id(), request_id, response_head))); |
159 | 160 |
160 base::SharedMemory shared_memory; | 161 base::SharedMemory shared_memory; |
161 ASSERT_TRUE(shared_memory.CreateAndMapAnonymous(body.size())); | 162 ASSERT_TRUE(shared_memory.CreateAndMapAnonymous(body.size())); |
162 memcpy(shared_memory.memory(), body.data(), body.size()); | 163 memcpy(shared_memory.memory(), body.data(), body.size()); |
163 | 164 |
164 base::SharedMemoryHandle handle; | 165 base::SharedMemoryHandle handle; |
165 ASSERT_TRUE(shared_memory.GiveToProcess(base::Process::Current().handle(), | 166 ASSERT_TRUE(shared_memory.GiveToProcess(base::Process::Current().handle(), |
166 &handle)); | 167 &handle)); |
167 ASSERT_TRUE(channel_->Send(new ViewMsg_Resource_DataReceived( | 168 ASSERT_TRUE(channel_->Send(new ResourceMsg_DataReceived( |
168 message.routing_id(), request_id, handle, body.size()))); | 169 message.routing_id(), request_id, handle, body.size()))); |
169 | 170 |
170 ASSERT_TRUE(channel_->Send(new ViewMsg_Resource_RequestComplete( | 171 ASSERT_TRUE(channel_->Send(new ResourceMsg_RequestComplete( |
171 message.routing_id(), | 172 message.routing_id(), |
172 request_id, | 173 request_id, |
173 net::URLRequestStatus(), | 174 net::URLRequestStatus(), |
174 std::string(), | 175 std::string(), |
175 base::Time()))); | 176 base::Time()))); |
176 } | 177 } |
177 | 178 |
178 void RenderViewFakeResourcesTest::OnRenderViewReady() { | 179 void RenderViewFakeResourcesTest::OnRenderViewReady() { |
179 // Grab a pointer to the new view using RenderViewVisitor. | 180 // Grab a pointer to the new view using RenderViewVisitor. |
180 ASSERT_TRUE(!view_); | 181 ASSERT_TRUE(!view_); |
181 RenderView::ForEach(this); | 182 RenderView::ForEach(this); |
182 ASSERT_TRUE(view_); | 183 ASSERT_TRUE(view_); |
183 message_loop_.Quit(); | 184 message_loop_.Quit(); |
184 } | 185 } |
185 | 186 |
186 } // namespace safe_browsing | 187 } // namespace safe_browsing |
OLD | NEW |