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 "base/strings/nullable_string16.h" | |
9 #include "base/strings/utf_string_conversions.h" | |
8 #include "content/browser/frame_host/frame_tree.h" | 10 #include "content/browser/frame_host/frame_tree.h" |
9 #include "content/browser/frame_host/navigation_handle_impl.h" | 11 #include "content/browser/frame_host/navigation_handle_impl.h" |
10 #include "content/browser/frame_host/navigation_request.h" | 12 #include "content/browser/frame_host/navigation_request.h" |
11 #include "content/browser/frame_host/navigator.h" | 13 #include "content/browser/frame_host/navigator.h" |
12 #include "content/browser/frame_host/navigator_impl.h" | 14 #include "content/browser/frame_host/navigator_impl.h" |
13 #include "content/browser/frame_host/render_frame_host_delegate.h" | 15 #include "content/browser/frame_host/render_frame_host_delegate.h" |
14 #include "content/browser/web_contents/web_contents_impl.h" | 16 #include "content/browser/web_contents/web_contents_impl.h" |
15 #include "content/common/frame_messages.h" | 17 #include "content/common/frame_messages.h" |
16 #include "content/common/frame_owner_properties.h" | 18 #include "content/common/frame_owner_properties.h" |
19 #include "content/common/page_state_serialization.h" | |
17 #include "content/public/browser/navigation_throttle.h" | 20 #include "content/public/browser/navigation_throttle.h" |
18 #include "content/public/browser/stream_handle.h" | 21 #include "content/public/browser/stream_handle.h" |
19 #include "content/public/common/browser_side_navigation_policy.h" | 22 #include "content/public/common/browser_side_navigation_policy.h" |
20 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
21 #include "content/public/test/browser_side_navigation_test_utils.h" | 24 #include "content/public/test/browser_side_navigation_test_utils.h" |
22 #include "content/test/test_navigation_url_loader.h" | 25 #include "content/test/test_navigation_url_loader.h" |
23 #include "content/test/test_render_view_host.h" | 26 #include "content/test/test_render_view_host.h" |
24 #include "mojo/public/cpp/bindings/interface_request.h" | 27 #include "mojo/public/cpp/bindings/interface_request.h" |
25 #include "net/base/load_flags.h" | 28 #include "net/base/load_flags.h" |
26 #include "third_party/WebKit/public/platform/WebPageVisibilityState.h" | 29 #include "third_party/WebKit/public/platform/WebPageVisibilityState.h" |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 params.origin = origin; | 346 params.origin = origin; |
344 | 347 |
345 url::Replacements<char> replacements; | 348 url::Replacements<char> replacements; |
346 replacements.ClearRef(); | 349 replacements.ClearRef(); |
347 params.was_within_same_page = | 350 params.was_within_same_page = |
348 !ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) && | 351 !ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) && |
349 !ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_TYPED) && | 352 !ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_TYPED) && |
350 url_copy.ReplaceComponents(replacements) == | 353 url_copy.ReplaceComponents(replacements) == |
351 GetLastCommittedURL().ReplaceComponents(replacements); | 354 GetLastCommittedURL().ReplaceComponents(replacements); |
352 | 355 |
353 params.page_state = | 356 params.page_state = TestRenderFrameHost::CreatePageStateForURL( |
354 PageState::CreateForTesting(url_copy, false, nullptr, nullptr); | 357 url_copy, params.item_sequence_number, params.document_sequence_number); |
355 | |
356 if (!callback.is_null()) | 358 if (!callback.is_null()) |
357 callback.Run(¶ms); | 359 callback.Run(¶ms); |
358 | 360 |
359 SendNavigateWithParams(¶ms); | 361 SendNavigateWithParams(¶ms); |
360 } | 362 } |
361 | 363 |
362 void TestRenderFrameHost::SendNavigateWithParams( | 364 void TestRenderFrameHost::SendNavigateWithParams( |
363 FrameHostMsg_DidCommitProvisionalLoad_Params* params) { | 365 FrameHostMsg_DidCommitProvisionalLoad_Params* params) { |
364 FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), *params); | 366 FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), *params); |
365 OnDidCommitProvisionalLoad(msg); | 367 OnDidCommitProvisionalLoad(msg); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 } | 460 } |
459 | 461 |
460 WebBluetoothServiceImpl* | 462 WebBluetoothServiceImpl* |
461 TestRenderFrameHost::CreateWebBluetoothServiceForTesting() { | 463 TestRenderFrameHost::CreateWebBluetoothServiceForTesting() { |
462 WebBluetoothServiceImpl* service = | 464 WebBluetoothServiceImpl* service = |
463 RenderFrameHostImpl::CreateWebBluetoothService( | 465 RenderFrameHostImpl::CreateWebBluetoothService( |
464 blink::mojom::WebBluetoothServiceRequest()); | 466 blink::mojom::WebBluetoothServiceRequest()); |
465 return service; | 467 return service; |
466 } | 468 } |
467 | 469 |
470 // static | |
471 PageState TestRenderFrameHost::CreatePageStateForURL( | |
472 const GURL& url, | |
473 int64_t item_sequence_number, | |
474 int64_t document_sequence_number) { | |
475 content::ExplodedPageState page_state; | |
476 page_state.top.url_string = | |
477 base::NullableString16(base::UTF8ToUTF16(url.spec()), false); | |
478 page_state.top.item_sequence_number = item_sequence_number; | |
479 page_state.top.document_sequence_number = document_sequence_number; | |
480 | |
481 std::string encoded_page_state; | |
482 EncodePageState(page_state, &encoded_page_state); | |
483 return PageState::CreateFromEncodedData(encoded_page_state); | |
nasko
2016/09/07 23:21:59
This code looks fine, but why can't this remain a
ananta
2016/09/07 23:58:44
Added a new method CreateForTestingWithSequenceNum
| |
484 } | |
485 | |
486 | |
468 int32_t TestRenderFrameHost::ComputeNextPageID() { | 487 int32_t TestRenderFrameHost::ComputeNextPageID() { |
469 const NavigationEntryImpl* entry = static_cast<NavigationEntryImpl*>( | 488 const NavigationEntryImpl* entry = static_cast<NavigationEntryImpl*>( |
470 frame_tree_node()->navigator()->GetController()->GetPendingEntry()); | 489 frame_tree_node()->navigator()->GetController()->GetPendingEntry()); |
471 DCHECK(!(entry && entry->site_instance()) || | 490 DCHECK(!(entry && entry->site_instance()) || |
472 entry->site_instance() == GetSiteInstance()); | 491 entry->site_instance() == GetSiteInstance()); |
473 // Entry can be null when committing an error page (the pending entry was | 492 // Entry can be null when committing an error page (the pending entry was |
474 // cleared during DidFailProvisionalLoad). | 493 // cleared during DidFailProvisionalLoad). |
475 int page_id = entry ? entry->GetPageID() : -1; | 494 int page_id = entry ? entry->GetPageID() : -1; |
476 if (page_id == -1) { | 495 if (page_id == -1) { |
477 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(delegate()); | 496 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(delegate()); |
478 page_id = web_contents->GetMaxPageIDForSiteInstance(GetSiteInstance()) + 1; | 497 page_id = web_contents->GetMaxPageIDForSiteInstance(GetSiteInstance()) + 1; |
479 } | 498 } |
480 return page_id; | 499 return page_id; |
481 } | 500 } |
482 | 501 |
483 void TestRenderFrameHost::SimulateWillStartRequest( | 502 void TestRenderFrameHost::SimulateWillStartRequest( |
484 ui::PageTransition transition) { | 503 ui::PageTransition transition) { |
485 // PlzNavigate: NavigationHandle::WillStartRequest has already been called at | 504 // PlzNavigate: NavigationHandle::WillStartRequest has already been called at |
486 // this point. | 505 // this point. |
487 if (!navigation_handle() || IsBrowserSideNavigationEnabled()) | 506 if (!navigation_handle() || IsBrowserSideNavigationEnabled()) |
488 return; | 507 return; |
489 navigation_handle()->CallWillStartRequestForTesting( | 508 navigation_handle()->CallWillStartRequestForTesting( |
490 false /* is_post */, Referrer(GURL(), blink::WebReferrerPolicyDefault), | 509 false /* is_post */, Referrer(GURL(), blink::WebReferrerPolicyDefault), |
491 true /* user_gesture */, transition, false /* is_external_protocol */); | 510 true /* user_gesture */, transition, false /* is_external_protocol */); |
492 } | 511 } |
493 | 512 |
494 } // namespace content | 513 } // namespace content |
OLD | NEW |