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/guid.h" | 7 #include "base/guid.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_handle_impl.h" | 9 #include "content/browser/frame_host/navigation_handle_impl.h" |
10 #include "content/browser/frame_host/navigation_request.h" | 10 #include "content/browser/frame_host/navigation_request.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 render_view_host, | 57 render_view_host, |
58 delegate, | 58 delegate, |
59 rwh_delegate, | 59 rwh_delegate, |
60 frame_tree, | 60 frame_tree, |
61 frame_tree_node, | 61 frame_tree_node, |
62 routing_id, | 62 routing_id, |
63 widget_routing_id, | 63 widget_routing_id, |
64 flags), | 64 flags), |
65 child_creation_observer_(delegate ? delegate->GetAsWebContents() : NULL), | 65 child_creation_observer_(delegate ? delegate->GetAsWebContents() : NULL), |
66 contents_mime_type_("text/html"), | 66 contents_mime_type_("text/html"), |
67 simulate_history_list_was_cleared_(false) {} | 67 simulate_history_list_was_cleared_(false), |
| 68 last_commit_was_error_page_(false) {} |
68 | 69 |
69 TestRenderFrameHost::~TestRenderFrameHost() { | 70 TestRenderFrameHost::~TestRenderFrameHost() { |
70 } | 71 } |
71 | 72 |
72 TestRenderViewHost* TestRenderFrameHost::GetRenderViewHost() { | 73 TestRenderViewHost* TestRenderFrameHost::GetRenderViewHost() { |
73 return static_cast<TestRenderViewHost*>( | 74 return static_cast<TestRenderViewHost*>( |
74 RenderFrameHostImpl::GetRenderViewHost()); | 75 RenderFrameHostImpl::GetRenderViewHost()); |
75 } | 76 } |
76 | 77 |
77 MockRenderProcessHost* TestRenderFrameHost::GetProcess() { | 78 MockRenderProcessHost* TestRenderFrameHost::GetProcess() { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 params.contents_mime_type = contents_mime_type_; | 150 params.contents_mime_type = contents_mime_type_; |
150 params.method = "GET"; | 151 params.method = "GET"; |
151 params.http_status_code = 200; | 152 params.http_status_code = 200; |
152 params.socket_address.set_host("2001:db8::1"); | 153 params.socket_address.set_host("2001:db8::1"); |
153 params.socket_address.set_port(80); | 154 params.socket_address.set_port(80); |
154 params.history_list_was_cleared = simulate_history_list_was_cleared_; | 155 params.history_list_was_cleared = simulate_history_list_was_cleared_; |
155 params.original_request_url = url; | 156 params.original_request_url = url; |
156 | 157 |
157 url::Replacements<char> replacements; | 158 url::Replacements<char> replacements; |
158 replacements.ClearRef(); | 159 replacements.ClearRef(); |
| 160 |
| 161 // This approach to determining whether a navigation is to be treated as |
| 162 // same page is not robust, as it will not handle pushState type navigation. |
| 163 // Do not use elsewhere! |
159 params.was_within_same_page = | 164 params.was_within_same_page = |
160 url.ReplaceComponents(replacements) == | 165 (GetLastCommittedURL().is_valid() && !last_commit_was_error_page_ && |
161 GetLastCommittedURL().ReplaceComponents(replacements); | 166 url.ReplaceComponents(replacements) == |
| 167 GetLastCommittedURL().ReplaceComponents(replacements)); |
162 | 168 |
163 params.page_state = PageState::CreateForTesting(url, false, nullptr, nullptr); | 169 params.page_state = PageState::CreateForTesting(url, false, nullptr, nullptr); |
164 | 170 |
165 SendNavigateWithParams(¶ms); | 171 SendNavigateWithParams(¶ms); |
166 } | 172 } |
167 | 173 |
168 void TestRenderFrameHost::SimulateNavigationError(const GURL& url, | 174 void TestRenderFrameHost::SimulateNavigationError(const GURL& url, |
169 int error_code) { | 175 int error_code) { |
170 if (IsBrowserSideNavigationEnabled()) { | 176 if (IsBrowserSideNavigationEnabled()) { |
171 NavigationRequest* request = frame_tree_node_->navigation_request(); | 177 NavigationRequest* request = frame_tree_node_->navigation_request(); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 } | 349 } |
344 | 350 |
345 // In most cases, the origin will match the URL's origin. Tests that need to | 351 // In most cases, the origin will match the URL's origin. Tests that need to |
346 // check corner cases (like about:blank) should specify the origin param | 352 // check corner cases (like about:blank) should specify the origin param |
347 // manually. | 353 // manually. |
348 url::Origin origin(url_copy); | 354 url::Origin origin(url_copy); |
349 params.origin = origin; | 355 params.origin = origin; |
350 | 356 |
351 url::Replacements<char> replacements; | 357 url::Replacements<char> replacements; |
352 replacements.ClearRef(); | 358 replacements.ClearRef(); |
| 359 |
| 360 // This approach to determining whether a navigation is to be treated as |
| 361 // same page is not robust, as it will not handle pushState type navigation. |
| 362 // Do not use elsewhere! |
353 params.was_within_same_page = | 363 params.was_within_same_page = |
354 !ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) && | 364 !ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) && |
355 !ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_TYPED) && | 365 !ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_TYPED) && |
356 url_copy.ReplaceComponents(replacements) == | 366 (GetLastCommittedURL().is_valid() && !last_commit_was_error_page_ && |
357 GetLastCommittedURL().ReplaceComponents(replacements); | 367 url_copy.ReplaceComponents(replacements) == |
| 368 GetLastCommittedURL().ReplaceComponents(replacements)); |
358 | 369 |
359 params.page_state = | 370 params.page_state = |
360 PageState::CreateForTesting(url_copy, false, nullptr, nullptr); | 371 PageState::CreateForTesting(url_copy, false, nullptr, nullptr); |
361 | 372 |
362 if (!callback.is_null()) | 373 if (!callback.is_null()) |
363 callback.Run(¶ms); | 374 callback.Run(¶ms); |
364 | 375 |
365 SendNavigateWithParams(¶ms); | 376 SendNavigateWithParams(¶ms); |
366 } | 377 } |
367 | 378 |
368 void TestRenderFrameHost::SendNavigateWithParams( | 379 void TestRenderFrameHost::SendNavigateWithParams( |
369 FrameHostMsg_DidCommitProvisionalLoad_Params* params) { | 380 FrameHostMsg_DidCommitProvisionalLoad_Params* params) { |
370 FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), *params); | 381 FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), *params); |
371 OnDidCommitProvisionalLoad(msg); | 382 OnDidCommitProvisionalLoad(msg); |
| 383 last_commit_was_error_page_ = params->url_is_unreachable; |
372 } | 384 } |
373 | 385 |
374 void TestRenderFrameHost::SendRendererInitiatedNavigationRequest( | 386 void TestRenderFrameHost::SendRendererInitiatedNavigationRequest( |
375 const GURL& url, | 387 const GURL& url, |
376 bool has_user_gesture) { | 388 bool has_user_gesture) { |
377 // Since this is renderer-initiated navigation, the RenderFrame must be | 389 // Since this is renderer-initiated navigation, the RenderFrame must be |
378 // initialized. Do it if it hasn't happened yet. | 390 // initialized. Do it if it hasn't happened yet. |
379 InitializeRenderFrameIfNeeded(); | 391 InitializeRenderFrameIfNeeded(); |
380 | 392 |
381 if (IsBrowserSideNavigationEnabled()) { | 393 if (IsBrowserSideNavigationEnabled()) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 // PlzNavigate: NavigationHandle::WillStartRequest has already been called at | 477 // PlzNavigate: NavigationHandle::WillStartRequest has already been called at |
466 // this point. | 478 // this point. |
467 if (!navigation_handle() || IsBrowserSideNavigationEnabled()) | 479 if (!navigation_handle() || IsBrowserSideNavigationEnabled()) |
468 return; | 480 return; |
469 navigation_handle()->CallWillStartRequestForTesting( | 481 navigation_handle()->CallWillStartRequestForTesting( |
470 false /* is_post */, Referrer(GURL(), blink::WebReferrerPolicyDefault), | 482 false /* is_post */, Referrer(GURL(), blink::WebReferrerPolicyDefault), |
471 true /* user_gesture */, transition, false /* is_external_protocol */); | 483 true /* user_gesture */, transition, false /* is_external_protocol */); |
472 } | 484 } |
473 | 485 |
474 } // namespace content | 486 } // namespace content |
OLD | NEW |