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

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 use TestWebContents (rather
63 return web_contents->GetRenderManagerForTesting()->pending_frame_host(); 63 // than WebContentsImpl directly) so that PrepareForCommitIfNecessary() could
64 // live in TestWebContents::CommitPendingNavigation() and could be used, so
65 // that only one place would handle this simulation. Unfortunately, it is not
66 // trivial to do so, so for now we have this extra simulation for
nasko 2016/08/31 19:45:24 nit: maybe drop one of the "so" in the "so, so" :
scottmg 2016/08/31 20:10:36 Replaced with "this, this". ;) (Rewrote it a bit
67 // non-TestWebContents.
68 RenderFrameHost* old_rfh = controller->GetWebContents()->GetMainFrame();
69 RenderFrameHostTester* old_rfh_tester = For(old_rfh);
70 old_rfh_tester->PrepareForCommitIfNecessary();
71
72 WebContentsImpl* web_contents =
73 static_cast<WebContentsImpl*>(controller->GetWebContents());
74 RenderFrameHost* pending_rfh =
75 IsBrowserSideNavigationEnabled()
76 ? web_contents->GetRenderManagerForTesting()
77 ->speculative_render_frame_host_.get()
78 : web_contents->GetRenderManagerForTesting()->pending_frame_host();
79
80 // Commit on the pending_rfh, if one exists.
81 RenderFrameHost* test_rfh = pending_rfh ? pending_rfh : old_rfh;
82 RenderFrameHostTester* test_rfh_tester = For(test_rfh);
83
84 // For new navigations, we need to send a larger page ID. For renavigations,
85 // we need to send the preexisting page ID. We can tell these apart because
86 // renavigations will have a pending_entry_index while new ones won't (they'll
87 // just have a standalong pending_entry that isn't in the list already).
88 if (controller->GetPendingEntryIndex() >= 0) {
89 test_rfh_tester->SendNavigateWithTransition(
90 controller->GetPendingEntry()->GetPageID(),
91 controller->GetPendingEntry()->GetUniqueID(),
92 false,
93 controller->GetPendingEntry()->GetURL(),
94 controller->GetPendingEntry()->GetTransitionType());
95 } else {
96 test_rfh_tester->SendNavigateWithTransition(
97 controller->GetWebContents()->GetMaxPageIDForSiteInstance(
98 test_rfh->GetSiteInstance()) + 1,
99 controller->GetPendingEntry()->GetUniqueID(),
100 true,
101 controller->GetPendingEntry()->GetURL(),
102 controller->GetPendingEntry()->GetTransitionType());
103 }
64 } 104 }
65 105
66 // RenderViewHostTester ------------------------------------------------------- 106 // RenderViewHostTester -------------------------------------------------------
67 107
68 // static 108 // static
69 RenderViewHostTester* RenderViewHostTester::For(RenderViewHost* host) { 109 RenderViewHostTester* RenderViewHostTester::For(RenderViewHost* host) {
70 return static_cast<TestRenderViewHost*>(host); 110 return static_cast<TestRenderViewHost*>(host);
71 } 111 }
72 112
73 // static 113 // static
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 BrowserContext* RenderViewHostTestHarness::CreateBrowserContext() { 318 BrowserContext* RenderViewHostTestHarness::CreateBrowserContext() {
279 return new TestBrowserContext(); 319 return new TestBrowserContext();
280 } 320 }
281 321
282 void RenderViewHostTestHarness::SetRenderProcessHostFactory( 322 void RenderViewHostTestHarness::SetRenderProcessHostFactory(
283 RenderProcessHostFactory* factory) { 323 RenderProcessHostFactory* factory) {
284 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory); 324 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory);
285 } 325 }
286 326
287 } // namespace content 327 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698