OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/public/test/render_view_test.h" | 5 #include "content/public/test/render_view_test.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "content/common/dom_storage/dom_storage_types.h" | 8 #include "content/common/dom_storage/dom_storage_types.h" |
9 #include "content/common/frame_messages.h" | 9 #include "content/common/frame_messages.h" |
10 #include "content/common/input_messages.h" | 10 #include "content/common/input_messages.h" |
11 #include "content/common/view_messages.h" | 11 #include "content/common/view_messages.h" |
| 12 #include "content/public/browser/content_browser_client.h" |
12 #include "content/public/browser/native_web_keyboard_event.h" | 13 #include "content/public/browser/native_web_keyboard_event.h" |
| 14 #include "content/public/common/content_client.h" |
13 #include "content/public/common/renderer_preferences.h" | 15 #include "content/public/common/renderer_preferences.h" |
| 16 #include "content/public/renderer/content_renderer_client.h" |
14 #include "content/public/renderer/history_item_serialization.h" | 17 #include "content/public/renderer/history_item_serialization.h" |
15 #include "content/renderer/render_thread_impl.h" | 18 #include "content/renderer/render_thread_impl.h" |
16 #include "content/renderer/render_view_impl.h" | 19 #include "content/renderer/render_view_impl.h" |
17 #include "content/renderer/renderer_main_platform_delegate.h" | 20 #include "content/renderer/renderer_main_platform_delegate.h" |
18 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 21 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
19 #include "content/test/mock_render_process.h" | 22 #include "content/test/mock_render_process.h" |
20 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 23 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
21 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 24 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
22 #include "third_party/WebKit/public/web/WebFrame.h" | 25 #include "third_party/WebKit/public/web/WebFrame.h" |
23 #include "third_party/WebKit/public/web/WebHistoryItem.h" | 26 #include "third_party/WebKit/public/web/WebHistoryItem.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 126 |
124 void RenderViewTest::GoBack(const blink::WebHistoryItem& item) { | 127 void RenderViewTest::GoBack(const blink::WebHistoryItem& item) { |
125 GoToOffset(-1, item); | 128 GoToOffset(-1, item); |
126 } | 129 } |
127 | 130 |
128 void RenderViewTest::GoForward(const blink::WebHistoryItem& item) { | 131 void RenderViewTest::GoForward(const blink::WebHistoryItem& item) { |
129 GoToOffset(1, item); | 132 GoToOffset(1, item); |
130 } | 133 } |
131 | 134 |
132 void RenderViewTest::SetUp() { | 135 void RenderViewTest::SetUp() { |
133 // Subclasses can set the ContentClient's renderer before calling | 136 content_client_.reset(CreateContentClient()); |
134 // RenderViewTest::SetUp(). | 137 content_browser_client_.reset(CreateContentBrowserClient()); |
135 ContentRendererClient* old_client = | 138 content_renderer_client_.reset(CreateContentRendererClient()); |
136 SetRendererClientForTesting(&content_renderer_client_); | 139 SetContentClient(content_client_.get()); |
137 if (old_client) | 140 SetBrowserClientForTesting(content_browser_client_.get()); |
138 SetRendererClientForTesting(old_client); | 141 SetRendererClientForTesting(content_renderer_client_.get()); |
139 | 142 |
140 // Subclasses can set render_thread_ with their own implementation before | 143 // Subclasses can set render_thread_ with their own implementation before |
141 // calling RenderViewTest::SetUp(). | 144 // calling RenderViewTest::SetUp(). |
142 if (!render_thread_) | 145 if (!render_thread_) |
143 render_thread_.reset(new MockRenderThread()); | 146 render_thread_.reset(new MockRenderThread()); |
144 render_thread_->set_routing_id(kRouteId); | 147 render_thread_->set_routing_id(kRouteId); |
145 render_thread_->set_surface_id(kSurfaceId); | 148 render_thread_->set_surface_id(kSurfaceId); |
146 render_thread_->set_new_window_routing_id(kNewWindowRouteId); | 149 render_thread_->set_new_window_routing_id(kNewWindowRouteId); |
147 render_thread_->set_new_frame_routing_id(kNewFrameRouteId); | 150 render_thread_->set_new_frame_routing_id(kNewFrameRouteId); |
148 | 151 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 void RenderViewTest::SendContentStateImmediately() { | 366 void RenderViewTest::SendContentStateImmediately() { |
364 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 367 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
365 impl->set_send_content_state_immediately(true); | 368 impl->set_send_content_state_immediately(true); |
366 } | 369 } |
367 | 370 |
368 blink::WebWidget* RenderViewTest::GetWebWidget() { | 371 blink::WebWidget* RenderViewTest::GetWebWidget() { |
369 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 372 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
370 return impl->webwidget(); | 373 return impl->webwidget(); |
371 } | 374 } |
372 | 375 |
| 376 |
| 377 ContentClient* RenderViewTest::CreateContentClient() { |
| 378 return new ContentClient; |
| 379 } |
| 380 |
| 381 ContentBrowserClient* RenderViewTest::CreateContentBrowserClient() { |
| 382 return new ContentBrowserClient; |
| 383 } |
| 384 |
| 385 ContentRendererClient* RenderViewTest::CreateContentRendererClient() { |
| 386 return new ContentRendererClient; |
| 387 } |
| 388 |
373 void RenderViewTest::GoToOffset(int offset, | 389 void RenderViewTest::GoToOffset(int offset, |
374 const blink::WebHistoryItem& history_item) { | 390 const blink::WebHistoryItem& history_item) { |
375 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); | 391 RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
376 | 392 |
377 int history_list_length = impl->historyBackListCount() + | 393 int history_list_length = impl->historyBackListCount() + |
378 impl->historyForwardListCount() + 1; | 394 impl->historyForwardListCount() + 1; |
379 int pending_offset = offset + impl->history_list_offset(); | 395 int pending_offset = offset + impl->history_list_offset(); |
380 | 396 |
381 FrameMsg_Navigate_Params navigate_params; | 397 FrameMsg_Navigate_Params navigate_params; |
382 navigate_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 398 navigate_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
383 navigate_params.transition = PAGE_TRANSITION_FORWARD_BACK; | 399 navigate_params.transition = PAGE_TRANSITION_FORWARD_BACK; |
384 navigate_params.current_history_list_length = history_list_length; | 400 navigate_params.current_history_list_length = history_list_length; |
385 navigate_params.current_history_list_offset = impl->history_list_offset(); | 401 navigate_params.current_history_list_offset = impl->history_list_offset(); |
386 navigate_params.pending_history_list_offset = pending_offset; | 402 navigate_params.pending_history_list_offset = pending_offset; |
387 navigate_params.page_id = impl->GetPageId() + offset; | 403 navigate_params.page_id = impl->GetPageId() + offset; |
388 navigate_params.page_state = HistoryItemToPageState(history_item); | 404 navigate_params.page_state = HistoryItemToPageState(history_item); |
389 navigate_params.request_time = base::Time::Now(); | 405 navigate_params.request_time = base::Time::Now(); |
390 | 406 |
391 FrameMsg_Navigate navigate_message(impl->main_render_frame()->GetRoutingID(), | 407 FrameMsg_Navigate navigate_message(impl->main_render_frame()->GetRoutingID(), |
392 navigate_params); | 408 navigate_params); |
393 impl->main_render_frame()->OnMessageReceived(navigate_message); | 409 impl->main_render_frame()->OnMessageReceived(navigate_message); |
394 | 410 |
395 // The load actually happens asynchronously, so we pump messages to process | 411 // The load actually happens asynchronously, so we pump messages to process |
396 // the pending continuation. | 412 // the pending continuation. |
397 ProcessPendingMessages(); | 413 ProcessPendingMessages(); |
398 } | 414 } |
399 | 415 |
400 } // namespace content | 416 } // namespace content |
OLD | NEW |