| OLD | NEW |
| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 pending_frame_host->ResetLoadingState(); | 211 pending_frame_host->ResetLoadingState(); |
| 211 } | 212 } |
| 212 } | 213 } |
| 213 } | 214 } |
| 214 } | 215 } |
| 215 | 216 |
| 216 void TestWebContents::CommitPendingNavigation() { | 217 void TestWebContents::CommitPendingNavigation() { |
| 217 const NavigationEntry* entry = GetController().GetPendingEntry(); | 218 const NavigationEntry* entry = GetController().GetPendingEntry(); |
| 218 DCHECK(entry); | 219 DCHECK(entry); |
| 219 | 220 |
| 220 // If we are doing a cross-site navigation, this simulates the current RFH | 221 TestRenderFrameHost* old_rfh = GetMainFrame(); |
| 221 // notifying that it has unloaded so the pending RFH is resumed and can | |
| 222 // navigate. | |
| 223 // PlzNavigate: the pending RFH is not created before the navigation commit, | |
| 224 // so it is necessary to simulate the IO thread response here to commit in the | |
| 225 // proper renderer. It is necessary to call PrepareForCommit before getting | |
| 226 // the main and the pending frame because when we are trying to navigate to a | |
| 227 // webui from a new tab, a RenderFrameHost is created to display it that is | |
| 228 // committed immediately (since it is a new tab). Therefore the main frame is | |
| 229 // replaced without a pending frame being created, and we don't get the right | |
| 230 // values for the RFH to navigate: we try to use the old one that has been | |
| 231 // deleted in the meantime. | |
| 232 // Note that for some synchronous navigations (about:blank, javascript | |
| 233 // urls, etc.) there will be no NavigationRequest, and no simulation of the | |
| 234 // network stack is required. | |
| 235 bool browser_side_navigation = IsBrowserSideNavigationEnabled(); | |
| 236 if (!browser_side_navigation || | |
| 237 GetMainFrame()->frame_tree_node()->navigation_request()) { | |
| 238 GetMainFrame()->PrepareForCommit(); | |
| 239 } | |
| 240 | 222 |
| 241 TestRenderFrameHost* old_rfh = GetMainFrame(); | 223 // PlzNavigate: the pending RenderFrameHost is not created before the |
| 224 // navigation commit, so it is necessary to simulate the IO thread response |
| 225 // here to commit in the proper renderer. It is necessary to call |
| 226 // PrepareForCommit before getting the main and the pending frame because when |
| 227 // we are trying to navigate to a webui from a new tab, a RenderFrameHost is |
| 228 // created to display it that is committed immediately (since it is a new |
| 229 // tab). Therefore the main frame is replaced without a pending frame being |
| 230 // created, and we don't get the right values for the RenderFrameHost to |
| 231 // navigate: we try to use the old one that has been deleted in the meantime. |
| 232 // Note that for some synchronous navigations (about:blank, javascript urls, |
| 233 // etc.), no simulation of the network stack is required. |
| 234 old_rfh->PrepareForCommitIfNecessary(); |
| 235 |
| 242 TestRenderFrameHost* rfh = GetPendingMainFrame(); | 236 TestRenderFrameHost* rfh = GetPendingMainFrame(); |
| 243 if (!rfh) | 237 if (!rfh) |
| 244 rfh = old_rfh; | 238 rfh = old_rfh; |
| 239 const bool browser_side_navigation = IsBrowserSideNavigationEnabled(); |
| 245 CHECK(!browser_side_navigation || rfh->is_loading()); | 240 CHECK(!browser_side_navigation || rfh->is_loading()); |
| 246 CHECK(!browser_side_navigation || | 241 CHECK(!browser_side_navigation || |
| 247 !rfh->frame_tree_node()->navigation_request()); | 242 !rfh->frame_tree_node()->navigation_request()); |
| 248 | 243 |
| 249 int page_id = entry->GetPageID(); | 244 int page_id = entry->GetPageID(); |
| 250 if (page_id == -1) { | 245 if (page_id == -1) { |
| 251 // It's a new navigation, assign a never-seen page id to it. | 246 // It's a new navigation, assign a never-seen page id to it. |
| 252 page_id = GetMaxPageIDForSiteInstance(rfh->GetSiteInstance()) + 1; | 247 page_id = GetMaxPageIDForSiteInstance(rfh->GetSiteInstance()) + 1; |
| 253 } | 248 } |
| 254 | 249 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 int route_id) { | 350 int route_id) { |
| 356 } | 351 } |
| 357 | 352 |
| 358 void TestWebContents::SaveFrameWithHeaders(const GURL& url, | 353 void TestWebContents::SaveFrameWithHeaders(const GURL& url, |
| 359 const Referrer& referrer, | 354 const Referrer& referrer, |
| 360 const std::string& headers) { | 355 const std::string& headers) { |
| 361 save_frame_headers_ = headers; | 356 save_frame_headers_ = headers; |
| 362 } | 357 } |
| 363 | 358 |
| 364 } // namespace content | 359 } // namespace content |
| OLD | NEW |