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

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

Issue 2296483002: Fix some unit_tests under PlzNavigate (Closed)
Patch Set: teardown 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/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 "content/browser/browser_url_handler_impl.h" 9 #include "content/browser/browser_url_handler_impl.h"
10 #include "content/browser/frame_host/cross_process_frame_connector.h" 10 #include "content/browser/frame_host/cross_process_frame_connector.h"
11 #include "content/browser/frame_host/navigation_entry_impl.h" 11 #include "content/browser/frame_host/navigation_entry_impl.h"
12 #include "content/browser/frame_host/navigation_handle_impl.h" 12 #include "content/browser/frame_host/navigation_handle_impl.h"
13 #include "content/browser/frame_host/navigator.h" 13 #include "content/browser/frame_host/navigator.h"
14 #include "content/browser/frame_host/navigator_impl.h" 14 #include "content/browser/frame_host/navigator_impl.h"
15 #include "content/browser/renderer_host/render_view_host_impl.h" 15 #include "content/browser/renderer_host/render_view_host_impl.h"
16 #include "content/browser/site_instance_impl.h" 16 #include "content/browser/site_instance_impl.h"
17 #include "content/common/frame_messages.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/navigation_data.h" 19 #include "content/public/browser/navigation_data.h"
20 #include "content/public/browser/notification_registrar.h" 20 #include "content/public/browser/notification_registrar.h"
21 #include "content/public/browser/notification_source.h" 21 #include "content/public/browser/notification_source.h"
22 #include "content/public/browser/notification_types.h" 22 #include "content/public/browser/notification_types.h"
23 #include "content/public/common/browser_side_navigation_policy.h" 23 #include "content/public/common/browser_side_navigation_policy.h"
24 #include "content/public/common/page_state.h" 24 #include "content/public/common/page_state.h"
25 #include "content/public/test/browser_side_navigation_test_utils.h"
25 #include "content/public/test/mock_render_process_host.h" 26 #include "content/public/test/mock_render_process_host.h"
26 #include "content/test/test_render_view_host.h" 27 #include "content/test/test_render_view_host.h"
27 #include "ui/base/page_transition_types.h" 28 #include "ui/base/page_transition_types.h"
28 29
29 namespace content { 30 namespace content {
30 31
31 TestWebContents::TestWebContents(BrowserContext* browser_context) 32 TestWebContents::TestWebContents(BrowserContext* browser_context)
32 : WebContentsImpl(browser_context), 33 : WebContentsImpl(browser_context),
33 delegate_view_override_(NULL), 34 delegate_view_override_(NULL),
34 expect_set_history_offset_and_length_(false), 35 expect_set_history_offset_and_length_(false),
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 pending_frame_host->ResetLoadingState(); 212 pending_frame_host->ResetLoadingState();
212 } 213 }
213 } 214 }
214 } 215 }
215 } 216 }
216 217
217 void TestWebContents::CommitPendingNavigation() { 218 void TestWebContents::CommitPendingNavigation() {
218 const NavigationEntry* entry = GetController().GetPendingEntry(); 219 const NavigationEntry* entry = GetController().GetPendingEntry();
219 DCHECK(entry); 220 DCHECK(entry);
220 221
221 // If we are doing a cross-site navigation, this simulates the current RFH 222 TestRenderFrameHost* old_rfh = GetMainFrame();
222 // notifying that it has unloaded so the pending RFH is resumed and can 223 SimulateCurrentRenderFrameHostUnloading(old_rfh);
223 // navigate.
224 // PlzNavigate: the pending RFH is not created before the navigation commit,
225 // so it is necessary to simulate the IO thread response here to commit in the
226 // proper renderer. It is necessary to call PrepareForCommit before getting
227 // the main and the pending frame because when we are trying to navigate to a
228 // webui from a new tab, a RenderFrameHost is created to display it that is
229 // committed immediately (since it is a new tab). Therefore the main frame is
230 // replaced without a pending frame being created, and we don't get the right
231 // values for the RFH to navigate: we try to use the old one that has been
232 // deleted in the meantime.
233 // Note that for some synchronous navigations (about:blank, javascript
234 // urls, etc.) there will be no NavigationRequest, and no simulation of the
235 // network stack is required.
236 bool browser_side_navigation = IsBrowserSideNavigationEnabled();
237 if (!browser_side_navigation ||
238 GetMainFrame()->frame_tree_node()->navigation_request()) {
239 GetMainFrame()->PrepareForCommit();
240 }
241 224
242 TestRenderFrameHost* old_rfh = GetMainFrame();
243 TestRenderFrameHost* rfh = GetPendingMainFrame(); 225 TestRenderFrameHost* rfh = GetPendingMainFrame();
244 if (!rfh) 226 if (!rfh)
245 rfh = old_rfh; 227 rfh = old_rfh;
228 const bool browser_side_navigation = IsBrowserSideNavigationEnabled();
246 CHECK(!browser_side_navigation || rfh->is_loading()); 229 CHECK(!browser_side_navigation || rfh->is_loading());
247 CHECK(!browser_side_navigation || 230 CHECK(!browser_side_navigation ||
248 !rfh->frame_tree_node()->navigation_request()); 231 !rfh->frame_tree_node()->navigation_request());
249 232
250 int page_id = entry->GetPageID(); 233 int page_id = entry->GetPageID();
251 if (page_id == -1) { 234 if (page_id == -1) {
252 // It's a new navigation, assign a never-seen page id to it. 235 // It's a new navigation, assign a never-seen page id to it.
253 page_id = GetMaxPageIDForSiteInstance(rfh->GetSiteInstance()) + 1; 236 page_id = GetMaxPageIDForSiteInstance(rfh->GetSiteInstance()) + 1;
254 } 237 }
255 238
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 int route_id) { 339 int route_id) {
357 } 340 }
358 341
359 void TestWebContents::SaveFrameWithHeaders(const GURL& url, 342 void TestWebContents::SaveFrameWithHeaders(const GURL& url,
360 const Referrer& referrer, 343 const Referrer& referrer,
361 const std::string& headers) { 344 const std::string& headers) {
362 save_frame_headers_ = headers; 345 save_frame_headers_ = headers;
363 } 346 }
364 347
365 } // namespace content 348 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698