Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: content/public/test/test_renderer_host.cc

Issue 2296483002: Fix some unit_tests under PlzNavigate (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 RenderFrameHostTester* old_rfh_tester = For(old_rfh);
71 old_rfh_tester->PrepareForCommitIfNecessary();
72
73 WebContentsImpl* web_contents =
74 static_cast<WebContentsImpl*>(controller->GetWebContents());
75 RenderFrameHost* pending_rfh =
76 IsBrowserSideNavigationEnabled()
77 ? web_contents->GetRenderManagerForTesting()
78 ->speculative_render_frame_host_.get()
79 : web_contents->GetRenderManagerForTesting()->pending_frame_host();
80
81 // Commit on the pending_rfh, if one exists.
82 RenderFrameHost* test_rfh = pending_rfh ? pending_rfh : old_rfh;
83 RenderFrameHostTester* test_rfh_tester = For(test_rfh);
84
85 // For new navigations, we need to send a larger page ID. For renavigations,
86 // we need to send the preexisting page ID. We can tell these apart because
87 // renavigations will have a pending_entry_index while new ones won't (they'll
88 // just have a standalong pending_entry that isn't in the list already).
89 if (controller->GetPendingEntryIndex() >= 0) {
90 test_rfh_tester->SendNavigateWithTransition(
91 controller->GetPendingEntry()->GetPageID(),
92 controller->GetPendingEntry()->GetUniqueID(),
93 false,
94 controller->GetPendingEntry()->GetURL(),
95 controller->GetPendingEntry()->GetTransitionType());
96 } else {
97 test_rfh_tester->SendNavigateWithTransition(
98 controller->GetWebContents()->GetMaxPageIDForSiteInstance(
99 test_rfh->GetSiteInstance()) + 1,
100 controller->GetPendingEntry()->GetUniqueID(),
101 true,
102 controller->GetPendingEntry()->GetURL(),
103 controller->GetPendingEntry()->GetTransitionType());
104 }
64 } 105 }
65 106
66 // RenderViewHostTester ------------------------------------------------------- 107 // RenderViewHostTester -------------------------------------------------------
67 108
68 // static 109 // static
69 RenderViewHostTester* RenderViewHostTester::For(RenderViewHost* host) { 110 RenderViewHostTester* RenderViewHostTester::For(RenderViewHost* host) {
70 return static_cast<TestRenderViewHost*>(host); 111 return static_cast<TestRenderViewHost*>(host);
71 } 112 }
72 113
73 // static 114 // static
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 BrowserContext* RenderViewHostTestHarness::CreateBrowserContext() { 319 BrowserContext* RenderViewHostTestHarness::CreateBrowserContext() {
279 return new TestBrowserContext(); 320 return new TestBrowserContext();
280 } 321 }
281 322
282 void RenderViewHostTestHarness::SetRenderProcessHostFactory( 323 void RenderViewHostTestHarness::SetRenderProcessHostFactory(
283 RenderProcessHostFactory* factory) { 324 RenderProcessHostFactory* factory) {
284 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory); 325 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory);
285 } 326 }
286 327
287 } // namespace content 328 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698