| 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 "content/test/render_view_fake_resources_test.h" |    5 #include "content/test/render_view_fake_resources_test.h" | 
|    6  |    6  | 
|    7 #include <string.h> |    7 #include <string.h> | 
|    8  |    8  | 
|    9 #include "base/process.h" |    9 #include "base/process.h" | 
|   10 #include "base/shared_memory.h" |   10 #include "base/shared_memory.h" | 
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  147     body = "content not found"; |  147     body = "content not found"; | 
|  148   } else { |  148   } else { | 
|  149     headers = "HTTP/1.1 200 OK\0Content-Type:text/html\0\0"; |  149     headers = "HTTP/1.1 200 OK\0Content-Type:text/html\0\0"; | 
|  150     body = it->second; |  150     body = it->second; | 
|  151   } |  151   } | 
|  152  |  152  | 
|  153   ResourceResponseHead response_head; |  153   ResourceResponseHead response_head; | 
|  154   response_head.headers = new net::HttpResponseHeaders(headers); |  154   response_head.headers = new net::HttpResponseHeaders(headers); | 
|  155   response_head.mime_type = "text/html"; |  155   response_head.mime_type = "text/html"; | 
|  156   ASSERT_TRUE(channel_->Send(new ResourceMsg_ReceivedResponse( |  156   ASSERT_TRUE(channel_->Send(new ResourceMsg_ReceivedResponse( | 
|  157       message.routing_id(), request_id, response_head))); |  157       message.routing_id(), request_id, response_head, base::TimeTicks(), | 
 |  158       base::TimeTicks()))); | 
|  158  |  159  | 
|  159   base::SharedMemory shared_memory; |  160   base::SharedMemory shared_memory; | 
|  160   ASSERT_TRUE(shared_memory.CreateAndMapAnonymous(body.size())); |  161   ASSERT_TRUE(shared_memory.CreateAndMapAnonymous(body.size())); | 
|  161   memcpy(shared_memory.memory(), body.data(), body.size()); |  162   memcpy(shared_memory.memory(), body.data(), body.size()); | 
|  162  |  163  | 
|  163   base::SharedMemoryHandle handle; |  164   base::SharedMemoryHandle handle; | 
|  164   ASSERT_TRUE(shared_memory.GiveToProcess(base::Process::Current().handle(), |  165   ASSERT_TRUE(shared_memory.GiveToProcess(base::Process::Current().handle(), | 
|  165                                           &handle)); |  166                                           &handle)); | 
|  166   ASSERT_TRUE(channel_->Send(new ResourceMsg_DataReceived( |  167   ASSERT_TRUE(channel_->Send(new ResourceMsg_DataReceived( | 
|  167       message.routing_id(), |  168       message.routing_id(), | 
|  168       request_id, |  169       request_id, | 
|  169       handle, |  170       handle, | 
|  170       body.size(), |  171       body.size(), | 
|  171       body.size()))); |  172       body.size()))); | 
|  172  |  173  | 
|  173   ASSERT_TRUE(channel_->Send(new ResourceMsg_RequestComplete( |  174   ASSERT_TRUE(channel_->Send(new ResourceMsg_RequestComplete( | 
|  174       message.routing_id(), |  175       message.routing_id(), | 
|  175       request_id, |  176       request_id, | 
|  176       net::URLRequestStatus(), |  177       net::URLRequestStatus(), | 
|  177       std::string(), |  178       std::string(), | 
|  178       base::Time()))); |  179       base::TimeTicks()))); | 
|  179 } |  180 } | 
|  180  |  181  | 
|  181 void RenderViewFakeResourcesTest::OnRenderViewReady() { |  182 void RenderViewFakeResourcesTest::OnRenderViewReady() { | 
|  182   // Grab a pointer to the new view using RenderViewVisitor. |  183   // Grab a pointer to the new view using RenderViewVisitor. | 
|  183   ASSERT_TRUE(!view_); |  184   ASSERT_TRUE(!view_); | 
|  184   content::RenderView::ForEach(this); |  185   content::RenderView::ForEach(this); | 
|  185   ASSERT_TRUE(view_); |  186   ASSERT_TRUE(view_); | 
|  186   message_loop_.Quit(); |  187   message_loop_.Quit(); | 
|  187 } |  188 } | 
|  188  |  189  | 
|  189 void RenderViewFakeResourcesTest::GoToOffset( |  190 void RenderViewFakeResourcesTest::GoToOffset( | 
|  190     int offset, |  191     int offset, | 
|  191     const WebKit::WebHistoryItem& history_item) { |  192     const WebKit::WebHistoryItem& history_item) { | 
|  192   RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |  193   RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 
|  193   ViewMsg_Navigate_Params params; |  194   ViewMsg_Navigate_Params params; | 
|  194   params.page_id = impl->GetPageId() + offset; |  195   params.page_id = impl->GetPageId() + offset; | 
|  195   params.pending_history_list_offset = |  196   params.pending_history_list_offset = | 
|  196       impl->history_list_offset() + offset; |  197       impl->history_list_offset() + offset; | 
|  197   params.current_history_list_offset = impl->history_list_offset(); |  198   params.current_history_list_offset = impl->history_list_offset(); | 
|  198   params.current_history_list_length = (impl->historyBackListCount() + |  199   params.current_history_list_length = (impl->historyBackListCount() + | 
|  199                                         impl->historyForwardListCount() + 1); |  200                                         impl->historyForwardListCount() + 1); | 
|  200   params.url = GURL(history_item.urlString()); |  201   params.url = GURL(history_item.urlString()); | 
|  201   params.transition = content::PAGE_TRANSITION_FORWARD_BACK; |  202   params.transition = content::PAGE_TRANSITION_FORWARD_BACK; | 
|  202   params.state = webkit_glue::HistoryItemToString(history_item); |  203   params.state = webkit_glue::HistoryItemToString(history_item); | 
|  203   params.navigation_type = ViewMsg_Navigate_Type::NORMAL; |  204   params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 
|  204   params.request_time = base::Time::Now(); |  205   params.request_time = base::Time::Now(); | 
|  205   channel_->Send(new ViewMsg_Navigate(impl->routing_id(), params)); |  206   channel_->Send(new ViewMsg_Navigate(impl->routing_id(), params)); | 
|  206   message_loop_.Run(); |  207   message_loop_.Run(); | 
|  207 } |  208 } | 
| OLD | NEW |