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

Side by Side Diff: content/test/test_web_contents.cc

Issue 761013003: PlzNavigate: add support in several navigation controller unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Nasko's comments Created 6 years 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
« no previous file with comments | « content/test/test_render_frame_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/test/test_web_contents.h" 5 #include "content/test/test_web_contents.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "content/browser/browser_url_handler_impl.h" 10 #include "content/browser/browser_url_handler_impl.h"
11 #include "content/browser/frame_host/cross_process_frame_connector.h" 11 #include "content/browser/frame_host/cross_process_frame_connector.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/frame_host/navigation_request.h"
14 #include "content/browser/frame_host/navigator.h" 13 #include "content/browser/frame_host/navigator.h"
15 #include "content/browser/frame_host/navigator_impl.h" 14 #include "content/browser/frame_host/navigator_impl.h"
16 #include "content/browser/renderer_host/render_view_host_impl.h" 15 #include "content/browser/renderer_host/render_view_host_impl.h"
17 #include "content/browser/site_instance_impl.h" 16 #include "content/browser/site_instance_impl.h"
17 #include "content/common/frame_messages.h"
18 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
19 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
21 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
22 #include "content/public/browser/stream_handle.h"
23 #include "content/public/common/content_switches.h" 22 #include "content/public/common/content_switches.h"
24 #include "content/public/common/page_state.h" 23 #include "content/public/common/page_state.h"
25 #include "content/public/test/mock_render_process_host.h" 24 #include "content/public/test/mock_render_process_host.h"
26 #include "content/test/browser_side_navigation_test_utils.h"
27 #include "content/test/test_navigation_url_loader.h"
28 #include "content/test/test_render_view_host.h" 25 #include "content/test/test_render_view_host.h"
29 #include "ui/base/page_transition_types.h" 26 #include "ui/base/page_transition_types.h"
30 27
31 namespace content { 28 namespace content {
32 29
33 TestWebContents::TestWebContents(BrowserContext* browser_context) 30 TestWebContents::TestWebContents(BrowserContext* browser_context)
34 : WebContentsImpl(browser_context, NULL), 31 : WebContentsImpl(browser_context, NULL),
35 delegate_view_override_(NULL), 32 delegate_view_override_(NULL),
36 expect_set_history_offset_and_length_(false), 33 expect_set_history_offset_and_length_(false),
37 expect_set_history_offset_and_length_history_length_(0) { 34 expect_set_history_offset_and_length_history_length_(0) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 117 }
121 118
122 WebContents* TestWebContents::Clone() { 119 WebContents* TestWebContents::Clone() {
123 WebContentsImpl* contents = 120 WebContentsImpl* contents =
124 Create(GetBrowserContext(), SiteInstance::Create(GetBrowserContext())); 121 Create(GetBrowserContext(), SiteInstance::Create(GetBrowserContext()));
125 contents->GetController().CopyStateFrom(controller_); 122 contents->GetController().CopyStateFrom(controller_);
126 return contents; 123 return contents;
127 } 124 }
128 125
129 void TestWebContents::NavigateAndCommit(const GURL& url) { 126 void TestWebContents::NavigateAndCommit(const GURL& url) {
130 bool has_live_renderer = GetMainFrame()->IsRenderFrameLive();
131 GetController().LoadURL( 127 GetController().LoadURL(
132 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 128 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
133 GURL loaded_url(url); 129 GURL loaded_url(url);
134 bool reverse_on_redirect = false; 130 bool reverse_on_redirect = false;
135 BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary( 131 BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary(
136 &loaded_url, GetBrowserContext(), &reverse_on_redirect); 132 &loaded_url, GetBrowserContext(), &reverse_on_redirect);
137 133
138 // PlzNavigate
139 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
140 switches::kEnableBrowserSideNavigation)) {
141 // Simulate the renderer response if there was a live renderer when the
142 // navigation started. Otherwise, it will have been sent directly to the
143 // network stack.
144 if (has_live_renderer)
145 GetMainFrame()->SendBeginNavigationWithURL(url);
146
147 // Now simulate the network stack commit without any redirects. This will
148 // cause the navigation to commit at the same url.
149 FrameTreeNode* frame_tree_node = GetMainFrame()->frame_tree_node();
150 NavigationRequest* request =
151 static_cast<NavigatorImpl*>(frame_tree_node->navigator())
152 ->GetNavigationRequestForNodeForTesting(frame_tree_node);
153 TestNavigationURLLoader* url_loader =
154 static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
155 scoped_refptr<ResourceResponse> response(new ResourceResponse);
156 url_loader->CallOnResponseStarted(response, MakeEmptyStream());
157 }
158
159 // LoadURL created a navigation entry, now simulate the RenderView sending 134 // LoadURL created a navigation entry, now simulate the RenderView sending
160 // a notification that it actually navigated. 135 // a notification that it actually navigated.
161 CommitPendingNavigation(); 136 CommitPendingNavigation();
162 } 137 }
163 138
164 void TestWebContents::TestSetIsLoading(bool value) { 139 void TestWebContents::TestSetIsLoading(bool value) {
165 SetIsLoading(GetRenderViewHost(), value, true, NULL); 140 SetIsLoading(GetRenderViewHost(), value, true, NULL);
166 } 141 }
167 142
168 void TestWebContents::CommitPendingNavigation() { 143 void TestWebContents::CommitPendingNavigation() {
169 // If we are doing a cross-site navigation, this simulates the current RVH 144 // If we are doing a cross-site navigation, this simulates the current RFH
170 // notifying that it has unloaded so the pending RVH is resumed and can 145 // notifying that it has unloaded so the pending RFH is resumed and can
171 // navigate. 146 // navigate.
172 ProceedWithCrossSiteNavigation();
173 TestRenderFrameHost* old_rfh = GetMainFrame(); 147 TestRenderFrameHost* old_rfh = GetMainFrame();
148 const NavigationEntry* entry = GetController().GetPendingEntry();
149 DCHECK(entry);
150
151 // Simulate the BeforeUnload ACK if necessary.
152 // PlzNavigate: the pending RFH is not created before the navigation commit,
153 // so it is necessary to simulate the IO thread response here to commit in the
154 // proper renderer.
155 old_rfh->PrepareForCommit(entry->GetURL());
156
174 TestRenderFrameHost* rfh = GetPendingMainFrame(); 157 TestRenderFrameHost* rfh = GetPendingMainFrame();
175 if (!rfh) 158 if (!rfh)
176 rfh = old_rfh; 159 rfh = old_rfh;
177 160
178 const NavigationEntry* entry = GetController().GetPendingEntry();
179 DCHECK(entry);
180 int page_id = entry->GetPageID(); 161 int page_id = entry->GetPageID();
181 if (page_id == -1) { 162 if (page_id == -1) {
182 // It's a new navigation, assign a never-seen page id to it. 163 // It's a new navigation, assign a never-seen page id to it.
183 page_id = GetMaxPageIDForSiteInstance(rfh->GetSiteInstance()) + 1; 164 page_id = GetMaxPageIDForSiteInstance(rfh->GetSiteInstance()) + 1;
184 } 165 }
185 166
186 rfh->SendNavigate(page_id, entry->GetURL()); 167 rfh->SendNavigate(page_id, entry->GetURL());
187 // Simulate the SwapOut_ACK. This is needed when cross-site navigation happens 168 // Simulate the SwapOut_ACK. This is needed when cross-site navigation
188 // (old_rfh != rfh). 169 // happens.
189 if (old_rfh != rfh) 170 if (old_rfh != rfh)
190 old_rfh->OnSwappedOut(); 171 old_rfh->OnSwappedOut();
191 } 172 }
192 173
193 void TestWebContents::ProceedWithCrossSiteNavigation() { 174 void TestWebContents::ProceedWithCrossSiteNavigation() {
194 if (!GetPendingMainFrame()) 175 if (!GetPendingMainFrame())
195 return; 176 return;
196 GetMainFrame()->SendBeforeUnloadACK(true); 177 GetMainFrame()->SendBeforeUnloadACK(true);
197 } 178 }
198 179
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 251 }
271 252
272 void TestWebContents::ShowCreatedWidget(int route_id, 253 void TestWebContents::ShowCreatedWidget(int route_id,
273 const gfx::Rect& initial_pos) { 254 const gfx::Rect& initial_pos) {
274 } 255 }
275 256
276 void TestWebContents::ShowCreatedFullscreenWidget(int route_id) { 257 void TestWebContents::ShowCreatedFullscreenWidget(int route_id) {
277 } 258 }
278 259
279 } // namespace content 260 } // namespace content
OLDNEW
« no previous file with comments | « content/test/test_render_frame_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698