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/test_renderer_host.h" | 5 #include "content/public/test/test_renderer_host.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 11 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
12 #include "content/browser/frame_host/navigation_entry_impl.h" | 12 #include "content/browser/frame_host/navigation_entry_impl.h" |
13 #include "content/browser/renderer_host/render_view_host_factory.h" | 13 #include "content/browser/renderer_host/render_view_host_factory.h" |
14 #include "content/browser/renderer_host/render_widget_host_impl.h" | 14 #include "content/browser/renderer_host/render_widget_host_impl.h" |
15 #include "content/browser/site_instance_impl.h" | 15 #include "content/browser/site_instance_impl.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/common/browser_side_navigation_policy.h" | 18 #include "content/public/common/browser_side_navigation_policy.h" |
| 19 #include "content/public/test/browser_side_navigation_test_utils.h" |
19 #include "content/public/test/mock_render_process_host.h" | 20 #include "content/public/test/mock_render_process_host.h" |
20 #include "content/public/test/test_browser_context.h" | 21 #include "content/public/test/test_browser_context.h" |
21 #include "content/test/browser_side_navigation_test_utils.h" | |
22 #include "content/test/content_browser_sanity_checker.h" | 22 #include "content/test/content_browser_sanity_checker.h" |
23 #include "content/test/test_render_frame_host.h" | 23 #include "content/test/test_render_frame_host.h" |
24 #include "content/test/test_render_frame_host_factory.h" | 24 #include "content/test/test_render_frame_host_factory.h" |
25 #include "content/test/test_render_view_host.h" | 25 #include "content/test/test_render_view_host.h" |
26 #include "content/test/test_render_view_host_factory.h" | 26 #include "content/test/test_render_view_host_factory.h" |
27 #include "content/test/test_web_contents.h" | 27 #include "content/test/test_web_contents.h" |
28 #include "ui/base/material_design/material_design_controller.h" | 28 #include "ui/base/material_design/material_design_controller.h" |
29 #include "ui/base/test/material_design_controller_test_api.h" | 29 #include "ui/base/test/material_design_controller_test_api.h" |
30 | 30 |
31 #if defined(OS_ANDROID) | 31 #if defined(OS_ANDROID) |
(...skipping 17 matching lines...) Expand all Loading... |
49 namespace content { | 49 namespace content { |
50 | 50 |
51 // RenderFrameHostTester ------------------------------------------------------ | 51 // RenderFrameHostTester ------------------------------------------------------ |
52 | 52 |
53 // static | 53 // static |
54 RenderFrameHostTester* RenderFrameHostTester::For(RenderFrameHost* host) { | 54 RenderFrameHostTester* RenderFrameHostTester::For(RenderFrameHost* host) { |
55 return static_cast<TestRenderFrameHost*>(host); | 55 return static_cast<TestRenderFrameHost*>(host); |
56 } | 56 } |
57 | 57 |
58 // static | 58 // static |
59 RenderFrameHost* RenderFrameHostTester::GetPendingForController( | 59 void RenderFrameHostTester::CommitPendingLoad( |
60 NavigationController* controller) { | 60 NavigationController* controller) { |
61 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 61 // This function is currently used by BrowserWithTestWindowTest. It would be |
62 controller->GetWebContents()); | 62 // ideal to instead make the users of that class create TestWebContents |
63 return web_contents->GetRenderManagerForTesting()->pending_frame_host(); | 63 // (rather than WebContentsImpl directly). This would allow the implementation |
| 64 // of PrepareForCommitIfNecessary() to live directly in |
| 65 // TestWebContents::CommitPendingNavigation() which could then be the only |
| 66 // place to handle this simulation. Unfortunately, it is not trivial to make |
| 67 // that change, so for now we have this extra simulation for |
| 68 // non-TestWebContents. |
| 69 RenderFrameHost* old_rfh = controller->GetWebContents()->GetMainFrame(); |
| 70 TestRenderFrameHost* old_rfh_tester = |
| 71 static_cast<TestRenderFrameHost*>(old_rfh); |
| 72 old_rfh_tester->PrepareForCommitIfNecessary(); |
| 73 |
| 74 WebContentsImpl* web_contents = |
| 75 static_cast<WebContentsImpl*>(controller->GetWebContents()); |
| 76 RenderFrameHost* pending_rfh = |
| 77 IsBrowserSideNavigationEnabled() |
| 78 ? web_contents->GetRenderManagerForTesting() |
| 79 ->speculative_render_frame_host_.get() |
| 80 : web_contents->GetRenderManagerForTesting()->pending_frame_host(); |
| 81 |
| 82 // Commit on the pending_rfh, if one exists. |
| 83 RenderFrameHost* test_rfh = pending_rfh ? pending_rfh : old_rfh; |
| 84 RenderFrameHostTester* test_rfh_tester = For(test_rfh); |
| 85 |
| 86 // For new navigations, we need to send a larger page ID. For renavigations, |
| 87 // we need to send the preexisting page ID. We can tell these apart because |
| 88 // renavigations will have a pending_entry_index while new ones won't (they'll |
| 89 // just have a standalong pending_entry that isn't in the list already). |
| 90 if (controller->GetPendingEntryIndex() >= 0) { |
| 91 test_rfh_tester->SendNavigateWithTransition( |
| 92 controller->GetPendingEntry()->GetPageID(), |
| 93 controller->GetPendingEntry()->GetUniqueID(), |
| 94 false, |
| 95 controller->GetPendingEntry()->GetURL(), |
| 96 controller->GetPendingEntry()->GetTransitionType()); |
| 97 } else { |
| 98 test_rfh_tester->SendNavigateWithTransition( |
| 99 controller->GetWebContents()->GetMaxPageIDForSiteInstance( |
| 100 test_rfh->GetSiteInstance()) + 1, |
| 101 controller->GetPendingEntry()->GetUniqueID(), |
| 102 true, |
| 103 controller->GetPendingEntry()->GetURL(), |
| 104 controller->GetPendingEntry()->GetTransitionType()); |
| 105 } |
64 } | 106 } |
65 | 107 |
66 // RenderViewHostTester ------------------------------------------------------- | 108 // RenderViewHostTester ------------------------------------------------------- |
67 | 109 |
68 // static | 110 // static |
69 RenderViewHostTester* RenderViewHostTester::For(RenderViewHost* host) { | 111 RenderViewHostTester* RenderViewHostTester::For(RenderViewHost* host) { |
70 return static_cast<TestRenderViewHost*>(host); | 112 return static_cast<TestRenderViewHost*>(host); |
71 } | 113 } |
72 | 114 |
73 // static | 115 // static |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 BrowserContext* RenderViewHostTestHarness::CreateBrowserContext() { | 320 BrowserContext* RenderViewHostTestHarness::CreateBrowserContext() { |
279 return new TestBrowserContext(); | 321 return new TestBrowserContext(); |
280 } | 322 } |
281 | 323 |
282 void RenderViewHostTestHarness::SetRenderProcessHostFactory( | 324 void RenderViewHostTestHarness::SetRenderProcessHostFactory( |
283 RenderProcessHostFactory* factory) { | 325 RenderProcessHostFactory* factory) { |
284 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory); | 326 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory); |
285 } | 327 } |
286 | 328 |
287 } // namespace content | 329 } // namespace content |
OLD | NEW |