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

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: 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
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"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 void TestWebContents::NavigateAndCommit(const GURL& url) { 131 void TestWebContents::NavigateAndCommit(const GURL& url) {
132 bool has_live_renderer = GetMainFrame()->IsRenderFrameLive(); 132 bool has_live_renderer = GetMainFrame()->IsRenderFrameLive();
133 GetController().LoadURL( 133 GetController().LoadURL(
134 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 134 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
135 GURL loaded_url(url); 135 GURL loaded_url(url);
136 bool reverse_on_redirect = false; 136 bool reverse_on_redirect = false;
137 BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary( 137 BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary(
138 &loaded_url, GetBrowserContext(), &reverse_on_redirect); 138 &loaded_url, GetBrowserContext(), &reverse_on_redirect);
139 139
140 // PlzNavigate 140 TestRenderFrameHost* old_rfh = GetMainFrame();
141 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 141 TestRenderFrameHost* rfh = GetPendingMainFrame();
142 switches::kEnableBrowserSideNavigation)) {
143 // Simulate the renderer response if there was a live renderer when the
144 // navigation started. Otherwise, it will have been sent directly to the
145 // network stack.
146 if (has_live_renderer)
147 GetMainFrame()->SendBeginNavigationWithURL(url);
148
149 // Now simulate the network stack commit without any redirects. This will
150 // cause the navigation to commit at the same url.
151 FrameTreeNode* frame_tree_node = GetMainFrame()->frame_tree_node();
152 NavigationRequest* request =
153 static_cast<NavigatorImpl*>(frame_tree_node->navigator())
154 ->GetNavigationRequestForNodeForTesting(frame_tree_node);
155 TestNavigationURLLoader* url_loader =
156 static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
157 scoped_refptr<ResourceResponse> response(new ResourceResponse);
158 url_loader->CallOnResponseStarted(response, MakeEmptyStream());
159 }
160 142
161 // LoadURL created a navigation entry, now simulate the RenderView sending 143 // LoadURL created a navigation entry, now simulate the RenderView sending
162 // a notification that it actually navigated. 144 // a notification that it actually navigated.
163 CommitPendingNavigation(); 145 CommitNavigationWithParams(-1, loaded_url, has_live_renderer, false,
146 NavigationEntryImpl::kInvalidBindings);
147
148 // Simulate the SwapOut_ACK. This is needed when cross-site navigation happens
149 // (old_rfh != rfh).
nasko 2014/12/11 00:51:45 Why have in comment the same condition you are tes
clamy 2014/12/15 17:01:39 Done.
150 if (old_rfh != rfh)
151 old_rfh->OnSwappedOut();
164 } 152 }
165 153
166 void TestWebContents::TestSetIsLoading(bool value) { 154 void TestWebContents::TestSetIsLoading(bool value) {
167 SetIsLoading(GetRenderViewHost(), value, true, NULL); 155 SetIsLoading(GetRenderViewHost(), value, true, NULL);
168 } 156 }
169 157
170 void TestWebContents::CommitPendingNavigation() { 158 void TestWebContents::CommitPendingNavigation() {
171 // If we are doing a cross-site navigation, this simulates the current RVH
172 // notifying that it has unloaded so the pending RVH is resumed and can
173 // navigate.
174 ProceedWithCrossSiteNavigation();
175 TestRenderFrameHost* old_rfh = GetMainFrame(); 159 TestRenderFrameHost* old_rfh = GetMainFrame();
176 TestRenderFrameHost* rfh = GetPendingMainFrame(); 160 TestRenderFrameHost* rfh = GetPendingMainFrame();
177 if (!rfh)
178 rfh = old_rfh;
179 161
180 const NavigationEntry* entry = GetController().GetPendingEntry(); 162 const NavigationEntry* entry = GetController().GetPendingEntry();
181 DCHECK(entry); 163 DCHECK(entry);
182 int page_id = entry->GetPageID(); 164 CommitNavigationWithParams(-1, entry->GetURL(), true, false,
183 if (page_id == -1) { 165 NavigationEntryImpl::kInvalidBindings);
184 // It's a new navigation, assign a never-seen page id to it.
185 page_id = GetMaxPageIDForSiteInstance(rfh->GetSiteInstance()) + 1;
186 }
187 166
188 rfh->SendNavigate(page_id, entry->GetURL());
189 // Simulate the SwapOut_ACK. This is needed when cross-site navigation happens 167 // Simulate the SwapOut_ACK. This is needed when cross-site navigation happens
190 // (old_rfh != rfh). 168 // (old_rfh != rfh).
191 if (old_rfh != rfh) 169 if (old_rfh != rfh)
192 old_rfh->OnSwappedOut(); 170 old_rfh->OnSwappedOut();
193 } 171 }
194 172
195 void TestWebContents::ProceedWithCrossSiteNavigation() { 173 void TestWebContents::ProceedWithCrossSiteNavigation() {
196 if (!GetPendingMainFrame()) 174 if (!GetPendingMainFrame())
197 return; 175 return;
198 GetMainFrame()->SendBeforeUnloadACK(true); 176 GetMainFrame()->SendBeforeUnloadACK(true);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 225
248 void TestWebContents::TestDidFailLoadWithError( 226 void TestWebContents::TestDidFailLoadWithError(
249 const GURL& url, 227 const GURL& url,
250 int error_code, 228 int error_code,
251 const base::string16& error_description) { 229 const base::string16& error_description) {
252 FrameHostMsg_DidFailLoadWithError msg( 230 FrameHostMsg_DidFailLoadWithError msg(
253 0, url, error_code, error_description); 231 0, url, error_code, error_description);
254 frame_tree_.root()->current_frame_host()->OnMessageReceived(msg); 232 frame_tree_.root()->current_frame_host()->OnMessageReceived(msg);
255 } 233 }
256 234
235 void TestWebContents::ProceedNavigationWithRendererResponse(const GURL& url) {
nasko 2014/12/11 00:51:45 Does it matter that it is "WithRendererResponse"?
236 // PlzNavigate
237 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
238 switches::kEnableBrowserSideNavigation)) {
239 GetMainFrame()->SendBeginNavigationWithURL(url);
240 } else {
241 ProceedWithCrossSiteNavigation();
242 }
243 }
244
245 void TestWebContents::CommitPendingNavigationWithHistoryCleared(
246 bool had_live_renderer,
247 bool simulate_history_list_was_cleared) {
248 const NavigationEntry* entry = GetController().GetPendingEntry();
249 DCHECK(entry);
250 CommitNavigationWithParams(-1, entry->GetURL(), had_live_renderer,
251 simulate_history_list_was_cleared,
252 NavigationEntryImpl::kInvalidBindings);
253 }
254
255 void TestWebContents::CommitNavigationWithPageID(int32 page_id,
256 const GURL& url,
257 bool had_live_renderer) {
258 CommitNavigationWithParams(page_id, url, had_live_renderer, false,
259 NavigationEntryImpl::kInvalidBindings);
260 }
261
262 void TestWebContents::CommitPendingNavigationWithBindings(
263 int binding_flags,
264 bool had_live_renderer) {
265 const NavigationEntry* entry = GetController().GetPendingEntry();
266 DCHECK(entry);
267 CommitNavigationWithParams(-1, entry->GetURL(), had_live_renderer, false,
268 binding_flags);
269 }
270
271 void TestWebContents::CommitPendingNavigationNoLiveRenderer() {
nasko 2014/12/11 00:51:45 This method is almost identical to the latter port
272 TestRenderFrameHost* old_rfh = GetMainFrame();
273 TestRenderFrameHost* rfh = GetPendingMainFrame();
274
275 const NavigationEntry* entry = GetController().GetPendingEntry();
276 DCHECK(entry);
277 CommitNavigationWithParams(-1, entry->GetURL(), false, false,
278 NavigationEntryImpl::kInvalidBindings);
279
280 // Simulate the SwapOut_ACK. This is needed when cross-site navigation happens
281 // (old_rfh != rfh).
nasko 2014/12/11 00:51:45 nit: Another instance of comment and code being th
282 if (old_rfh != rfh)
283 old_rfh->OnSwappedOut();
284 }
285
286 void TestWebContents::SimulateRendererInitiatedNavigation(int page_id,
287 const GURL& url) {
288 // PlzNavigate
289 // Simulate the beginning of a renderer initiated navigation.
290 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
291 switches::kEnableBrowserSideNavigation)) {
292 GetMainFrame()->SendBeginNavigationWithURL(url);
293 SimulateIOThreadResponse();
294 }
295 TestRenderFrameHost* current_rfh = GetMainFrame();
296
297 current_rfh->SendNavigate(page_id, url);
298 }
299
257 void TestWebContents::CreateNewWindow( 300 void TestWebContents::CreateNewWindow(
258 int render_process_id, 301 int render_process_id,
259 int route_id, 302 int route_id,
260 int main_frame_route_id, 303 int main_frame_route_id,
261 const ViewHostMsg_CreateWindow_Params& params, 304 const ViewHostMsg_CreateWindow_Params& params,
262 SessionStorageNamespace* session_storage_namespace) { 305 SessionStorageNamespace* session_storage_namespace) {
263 } 306 }
264 307
265 void TestWebContents::CreateNewWidget(int render_process_id, 308 void TestWebContents::CreateNewWidget(int render_process_id,
266 int route_id, 309 int route_id,
(...skipping 10 matching lines...) Expand all
277 bool user_gesture) { 320 bool user_gesture) {
278 } 321 }
279 322
280 void TestWebContents::ShowCreatedWidget(int route_id, 323 void TestWebContents::ShowCreatedWidget(int route_id,
281 const gfx::Rect& initial_pos) { 324 const gfx::Rect& initial_pos) {
282 } 325 }
283 326
284 void TestWebContents::ShowCreatedFullscreenWidget(int route_id) { 327 void TestWebContents::ShowCreatedFullscreenWidget(int route_id) {
285 } 328 }
286 329
330 void TestWebContents::CommitNavigationWithParams(
nasko 2014/12/11 00:51:45 Shouldn't this method name start with CommitPendin
331 int page_id,
332 const GURL& url,
333 bool had_live_renderer,
334 bool simulate_history_list_was_cleared,
335 int binding_flags) {
336 // If we are doing a cross-site navigation, this simulates the current RVH
nasko 2014/12/11 00:51:45 nit: Did you mean RFH?
clamy 2014/12/15 17:01:39 Done.
337 // notifying that it has unloaded so the pending RVH is resumed and can
338 // navigate.
339 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
340 switches::kEnableBrowserSideNavigation)) {
341 ProceedWithCrossSiteNavigation();
342 } else {
343 // Simulate the renderer response if there was a live renderer when the
344 // navigation started. Otherwise, it will have been sent directly to the
345 // network stack.
346 if (had_live_renderer)
347 ProceedNavigationWithRendererResponse(url);
348
349 SimulateIOThreadResponse();
350 }
351
352 TestRenderFrameHost* old_rfh = GetMainFrame();
353 TestRenderFrameHost* rfh = GetPendingMainFrame();
354 if (!rfh)
355 rfh = old_rfh;
356
357 if (simulate_history_list_was_cleared)
358 rfh->set_simulate_history_list_was_cleared(true);
359
360 if (binding_flags != NavigationEntryImpl::kInvalidBindings)
361 rfh->GetRenderViewHost()->AllowBindings(binding_flags);
362
363 int page_id_final = page_id;
364
365 if (page_id_final == -1) {
366 const NavigationEntry* entry = GetController().GetPendingEntry();
367 DCHECK(entry);
368 // If it's a new navigation, assign a never-seen page id to it.
369 page_id_final = entry->GetPageID() == -1 ?
370 GetMaxPageIDForSiteInstance(rfh->GetSiteInstance()) + 1 :
371 entry->GetPageID();
372 }
373
374 rfh->SendNavigate(page_id_final, url);
375 }
376
377 // PlzNavigate
378 void TestWebContents::SimulateIOThreadResponse() {
379 // Simulate the network stack commit without any redirects. This will cause
380 // the navigation to commit at the same url.
381 FrameTreeNode* frame_tree_node = GetMainFrame()->frame_tree_node();
382 NavigationRequest* request =
383 static_cast<NavigatorImpl*>(frame_tree_node->navigator())
384 ->GetNavigationRequestForNodeForTesting(frame_tree_node);
385 TestNavigationURLLoader* url_loader =
386 static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
387 scoped_refptr<ResourceResponse> response(new ResourceResponse);
388 url_loader->CallOnResponseStarted(response, MakeEmptyStream());
389 }
390
287 } // namespace content 391 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698