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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 false, | 182 false, |
183 file_path_for_history_item ? "data" : NULL, | 183 file_path_for_history_item ? "data" : NULL, |
184 file_path_for_history_item); | 184 file_path_for_history_item); |
185 | 185 |
186 FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), params); | 186 FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), params); |
187 OnDidCommitProvisionalLoad(msg); | 187 OnDidCommitProvisionalLoad(msg); |
188 } | 188 } |
189 | 189 |
190 void TestRenderFrameHost::SendBeginNavigationWithURL(const GURL& url, | 190 void TestRenderFrameHost::SendBeginNavigationWithURL(const GURL& url, |
191 bool has_user_gesture) { | 191 bool has_user_gesture) { |
192 BeginNavigationParams begin_params("GET", std::string(), net::LOAD_NORMAL, | 192 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
193 has_user_gesture); | 193 switches::kEnableBrowserSideNavigation)) { |
194 CommonNavigationParams common_params; | 194 BeginNavigationParams begin_params("GET", std::string(), net::LOAD_NORMAL, |
195 common_params.url = url; | 195 has_user_gesture); |
196 common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault); | 196 CommonNavigationParams common_params; |
197 common_params.transition = ui::PAGE_TRANSITION_LINK; | 197 common_params.url = url; |
198 OnBeginNavigation(common_params, begin_params, | 198 common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault); |
199 scoped_refptr<ResourceRequestBody>()); | 199 common_params.transition = ui::PAGE_TRANSITION_LINK; |
200 OnBeginNavigation(common_params, begin_params, | |
201 scoped_refptr<ResourceRequestBody>()); | |
202 } | |
200 } | 203 } |
201 | 204 |
202 void TestRenderFrameHost::DidDisownOpener() { | 205 void TestRenderFrameHost::DidDisownOpener() { |
203 OnDidDisownOpener(); | 206 OnDidDisownOpener(); |
204 } | 207 } |
205 | 208 |
206 void TestRenderFrameHost::PrepareForCommit(const GURL& url) { | 209 void TestRenderFrameHost::PrepareForCommit() { |
207 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 210 PrepareForCommitInternal(nullptr); |
208 switches::kEnableBrowserSideNavigation)) { | 211 } |
209 SendBeforeUnloadACK(true); | |
210 return; | |
211 } | |
212 | 212 |
213 // PlzNavigate | 213 void TestRenderFrameHost::PrepareForCommitWithServerRedirect( |
214 // Simulate the network stack commit without any redirects. | 214 const GURL& redirect_url) { |
215 NavigationRequest* request = | 215 PrepareForCommitInternal(&redirect_url); |
216 static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) | |
217 ->GetNavigationRequestForNodeForTesting(frame_tree_node_); | |
218 | |
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 | |
227 // We may not have simulated the renderer response to the navigation request. | |
228 // Do that now. | |
229 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) | |
230 SendBeforeUnloadACK(true); | |
231 | |
232 // We have already simulated the IO thread commit. Only the | |
233 // DidCommitProvisionalLoad from the renderer is missing. | |
234 if (request->state() == NavigationRequest::RESPONSE_STARTED) | |
235 return; | |
236 | |
237 ASSERT_TRUE(request->state() == NavigationRequest::STARTED); | |
238 TestNavigationURLLoader* url_loader = | |
239 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | |
240 ASSERT_TRUE(url_loader); | |
241 scoped_refptr<ResourceResponse> response(new ResourceResponse); | |
242 url_loader->CallOnResponseStarted(response, MakeEmptyStream()); | |
243 } | 216 } |
244 | 217 |
245 void TestRenderFrameHost::SendBeforeUnloadHandlersPresent(bool present) { | 218 void TestRenderFrameHost::SendBeforeUnloadHandlersPresent(bool present) { |
246 OnBeforeUnloadHandlersPresent(present); | 219 OnBeforeUnloadHandlersPresent(present); |
247 } | 220 } |
248 | 221 |
249 void TestRenderFrameHost::SendUnloadHandlersPresent(bool present) { | 222 void TestRenderFrameHost::SendUnloadHandlersPresent(bool present) { |
250 OnUnloadHandlersPresent(present); | 223 OnUnloadHandlersPresent(present); |
251 } | 224 } |
252 | 225 |
226 void TestRenderFrameHost::PrepareForCommitInternal( | |
227 const GURL* redirect_url) { | |
228 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
229 switches::kEnableBrowserSideNavigation)) { | |
230 // Non PlzNavigate | |
231 SendBeforeUnloadACK(true); | |
232 return; | |
233 } | |
234 | |
235 // PlzNavigate | |
236 NavigationRequest* request = | |
237 static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) | |
238 ->GetNavigationRequestForNodeForTesting(frame_tree_node_); | |
239 CHECK(request); | |
240 | |
241 // Simulate a beforeUnload ACK from the renderer if it's being expected. | |
clamy
2015/02/25 14:29:49
nit: s/it's being expected/the browser is waiting
carlosk
2015/02/25 16:08:00
Done.
| |
242 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) | |
243 SendBeforeUnloadACK(true); | |
244 | |
245 // We have already simulated the IO thread commit. Only the | |
246 // DidCommitProvisionalLoad from the renderer is missing. | |
247 if (request->state() == NavigationRequest::RESPONSE_STARTED) { | |
248 CHECK(!redirect_url) << "Unable to simulate server redirect to \"" << | |
clamy
2015/02/25 14:29:49
I noticed you like to add log to the CHECKs. This
carlosk
2015/02/25 16:08:00
I think this still makes it easier when running a
clamy
2015/02/25 17:10:33
I would be fine if this was a DCHECK, but it is a
carlosk
2015/02/25 19:30:21
Acknowledged.
| |
249 redirect_url << "\""; | |
250 return; | |
251 } | |
252 | |
253 CHECK(request->state() == NavigationRequest::STARTED); | |
254 | |
255 TestNavigationURLLoader* url_loader = | |
256 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | |
257 CHECK(url_loader); | |
258 | |
259 // If a |redirect_url| was provided, simulate a server redirect | |
260 if (redirect_url) | |
261 url_loader->SimulateServerRedirect(*redirect_url); | |
262 | |
263 // Simulate the network stack commit | |
264 scoped_refptr<ResourceResponse> response(new ResourceResponse); | |
265 url_loader->CallOnResponseStarted(response, MakeEmptyStream()); | |
266 } | |
267 | |
253 } // namespace content | 268 } // namespace content |
OLD | NEW |