Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_render_frame_host.h" | 5 #include "content/test/test_render_frame_host.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "content/browser/frame_host/frame_tree.h" | 8 #include "content/browser/frame_host/frame_tree.h" |
| 9 #include "content/browser/frame_host/navigation_request.h" | 9 #include "content/browser/frame_host/navigation_request.h" |
| 10 #include "content/browser/frame_host/navigator.h" | 10 #include "content/browser/frame_host/navigator.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 BeginNavigationParams begin_params("GET", std::string(), net::LOAD_NORMAL, | 192 BeginNavigationParams begin_params("GET", std::string(), net::LOAD_NORMAL, |
| 193 has_user_gesture); | 193 has_user_gesture); |
| 194 CommonNavigationParams common_params; | 194 CommonNavigationParams common_params; |
| 195 common_params.url = url; | 195 common_params.url = url; |
| 196 common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault); | 196 common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault); |
| 197 common_params.transition = ui::PAGE_TRANSITION_LINK; | 197 common_params.transition = ui::PAGE_TRANSITION_LINK; |
| 198 OnBeginNavigation(common_params, begin_params, | 198 OnBeginNavigation(common_params, begin_params, |
| 199 scoped_refptr<ResourceRequestBody>()); | 199 scoped_refptr<ResourceRequestBody>()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void TestRenderFrameHost::SendRendererInitiatedNavigationRequest( | |
| 203 const GURL& url, | |
| 204 bool has_user_gesture) { | |
| 205 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 206 switches::kEnableBrowserSideNavigation)) { | |
| 207 SendBeginNavigationWithURL(url, has_user_gesture); | |
| 208 } | |
| 209 } | |
| 210 | |
| 202 void TestRenderFrameHost::DidDisownOpener() { | 211 void TestRenderFrameHost::DidDisownOpener() { |
| 203 OnDidDisownOpener(); | 212 OnDidDisownOpener(); |
| 204 } | 213 } |
| 205 | 214 |
| 206 void TestRenderFrameHost::PrepareForCommit(const GURL& url) { | 215 void TestRenderFrameHost::PrepareForCommit() { |
| 207 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 216 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 208 switches::kEnableBrowserSideNavigation)) { | 217 switches::kEnableBrowserSideNavigation)) { |
| 209 SendBeforeUnloadACK(true); | 218 SendBeforeUnloadACK(true); |
| 210 return; | 219 return; |
| 211 } | 220 } |
| 212 | 221 |
| 213 // PlzNavigate | 222 // PlzNavigate |
| 214 // Simulate the network stack commit without any redirects. | 223 // Simulate the network stack commit without any redirects. |
| 215 NavigationRequest* request = | 224 NavigationRequest* request = |
| 216 static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) | 225 static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) |
| 217 ->GetNavigationRequestForNodeForTesting(frame_tree_node_); | 226 ->GetNavigationRequestForNodeForTesting(frame_tree_node_); |
| 218 | 227 CHECK(request); |
| 219 // We are simulating a renderer-initiated user-initiated navigation. | |
| 220 if (!request) { | |
| 221 SendBeginNavigationWithURL(url, true); | |
| 222 request = static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) | |
| 223 ->GetNavigationRequestForNodeForTesting(frame_tree_node_); | |
| 224 } | |
| 225 ASSERT_TRUE(request); | |
| 226 | 228 |
| 227 // We may not have simulated the renderer response to the navigation request. | 229 // We may not have simulated the renderer response to the navigation request. |
|
clamy
2015/02/24 13:05:34
nit: I think this should be rephrased as something
carlosk
2015/02/24 16:38:56
Updated the comment.
| |
| 228 // Do that now. | 230 // Do that now. |
| 229 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) | 231 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) |
| 230 SendBeforeUnloadACK(true); | 232 SendBeforeUnloadACK(true); |
| 231 | 233 |
| 232 // We have already simulated the IO thread commit. Only the | 234 // We have already simulated the IO thread commit. Only the |
| 233 // DidCommitProvisionalLoad from the renderer is missing. | 235 // DidCommitProvisionalLoad from the renderer is missing. |
| 234 if (request->state() == NavigationRequest::RESPONSE_STARTED) | 236 if (request->state() == NavigationRequest::RESPONSE_STARTED) |
| 235 return; | 237 return; |
| 236 | 238 |
| 237 ASSERT_TRUE(request->state() == NavigationRequest::STARTED); | 239 CHECK(request->state() == NavigationRequest::STARTED); |
| 238 TestNavigationURLLoader* url_loader = | 240 TestNavigationURLLoader* url_loader = |
| 239 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | 241 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); |
| 240 ASSERT_TRUE(url_loader); | 242 CHECK(url_loader); |
|
carlosk
2015/02/23 16:42:03
Changed to CHECKs as ASSERTs will not trigger test
clamy
2015/02/24 13:05:34
Acknowledged.
| |
| 241 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 243 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| 242 url_loader->CallOnResponseStarted(response, MakeEmptyStream()); | 244 url_loader->CallOnResponseStarted(response, MakeEmptyStream()); |
| 243 } | 245 } |
| 244 | 246 |
| 245 void TestRenderFrameHost::SendBeforeUnloadHandlersPresent(bool present) { | 247 void TestRenderFrameHost::SendBeforeUnloadHandlersPresent(bool present) { |
| 246 OnBeforeUnloadHandlersPresent(present); | 248 OnBeforeUnloadHandlersPresent(present); |
| 247 } | 249 } |
| 248 | 250 |
| 249 void TestRenderFrameHost::SendUnloadHandlersPresent(bool present) { | 251 void TestRenderFrameHost::SendUnloadHandlersPresent(bool present) { |
| 250 OnUnloadHandlersPresent(present); | 252 OnUnloadHandlersPresent(present); |
| 251 } | 253 } |
| 252 | 254 |
| 253 } // namespace content | 255 } // namespace content |
| OLD | NEW |