| 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 "base/command_line.h" |
| 9 #include "content/browser/browser_url_handler_impl.h" | 10 #include "content/browser/browser_url_handler_impl.h" |
| 10 #include "content/browser/frame_host/cross_process_frame_connector.h" | 11 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 11 #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" |
| 12 #include "content/browser/frame_host/navigator.h" | 14 #include "content/browser/frame_host/navigator.h" |
| 15 #include "content/browser/frame_host/navigator_impl.h" |
| 13 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 14 #include "content/browser/site_instance_impl.h" | 17 #include "content/browser/site_instance_impl.h" |
| 15 #include "content/common/frame_messages.h" | |
| 16 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
| 19 #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" |
| 20 #include "content/public/common/page_state.h" | 24 #include "content/public/common/page_state.h" |
| 21 #include "content/public/test/mock_render_process_host.h" | 25 #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" |
| 22 #include "content/test/test_render_view_host.h" | 28 #include "content/test/test_render_view_host.h" |
| 23 #include "ui/base/page_transition_types.h" | 29 #include "ui/base/page_transition_types.h" |
| 24 | 30 |
| 25 namespace content { | 31 namespace content { |
| 26 | 32 |
| 27 TestWebContents::TestWebContents(BrowserContext* browser_context) | 33 TestWebContents::TestWebContents(BrowserContext* browser_context) |
| 28 : WebContentsImpl(browser_context, NULL), | 34 : WebContentsImpl(browser_context, NULL), |
| 29 delegate_view_override_(NULL), | 35 delegate_view_override_(NULL), |
| 30 expect_set_history_length_and_prune_(false), | 36 expect_set_history_length_and_prune_(false), |
| 31 expect_set_history_length_and_prune_site_instance_(NULL), | 37 expect_set_history_length_and_prune_site_instance_(NULL), |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 122 } |
| 117 | 123 |
| 118 WebContents* TestWebContents::Clone() { | 124 WebContents* TestWebContents::Clone() { |
| 119 WebContentsImpl* contents = | 125 WebContentsImpl* contents = |
| 120 Create(GetBrowserContext(), SiteInstance::Create(GetBrowserContext())); | 126 Create(GetBrowserContext(), SiteInstance::Create(GetBrowserContext())); |
| 121 contents->GetController().CopyStateFrom(controller_); | 127 contents->GetController().CopyStateFrom(controller_); |
| 122 return contents; | 128 return contents; |
| 123 } | 129 } |
| 124 | 130 |
| 125 void TestWebContents::NavigateAndCommit(const GURL& url) { | 131 void TestWebContents::NavigateAndCommit(const GURL& url) { |
| 132 bool has_live_renderer = GetMainFrame()->IsRenderFrameLive(); |
| 126 GetController().LoadURL( | 133 GetController().LoadURL( |
| 127 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 134 url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 128 GURL loaded_url(url); | 135 GURL loaded_url(url); |
| 129 bool reverse_on_redirect = false; | 136 bool reverse_on_redirect = false; |
| 130 BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary( | 137 BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary( |
| 131 &loaded_url, GetBrowserContext(), &reverse_on_redirect); | 138 &loaded_url, GetBrowserContext(), &reverse_on_redirect); |
| 132 | 139 |
| 140 // PlzNavigate |
| 141 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 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 |
| 133 // LoadURL created a navigation entry, now simulate the RenderView sending | 161 // LoadURL created a navigation entry, now simulate the RenderView sending |
| 134 // a notification that it actually navigated. | 162 // a notification that it actually navigated. |
| 135 CommitPendingNavigation(); | 163 CommitPendingNavigation(); |
| 136 } | 164 } |
| 137 | 165 |
| 138 void TestWebContents::TestSetIsLoading(bool value) { | 166 void TestWebContents::TestSetIsLoading(bool value) { |
| 139 SetIsLoading(GetRenderViewHost(), value, true, NULL); | 167 SetIsLoading(GetRenderViewHost(), value, true, NULL); |
| 140 } | 168 } |
| 141 | 169 |
| 142 void TestWebContents::CommitPendingNavigation() { | 170 void TestWebContents::CommitPendingNavigation() { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 278 } |
| 251 | 279 |
| 252 void TestWebContents::ShowCreatedWidget(int route_id, | 280 void TestWebContents::ShowCreatedWidget(int route_id, |
| 253 const gfx::Rect& initial_pos) { | 281 const gfx::Rect& initial_pos) { |
| 254 } | 282 } |
| 255 | 283 |
| 256 void TestWebContents::ShowCreatedFullscreenWidget(int route_id) { | 284 void TestWebContents::ShowCreatedFullscreenWidget(int route_id) { |
| 257 } | 285 } |
| 258 | 286 |
| 259 } // namespace content | 287 } // namespace content |
| OLD | NEW |