Commit dd06babf authored by csharrison's avatar csharrison Committed by Commit bot

Call WillStartRequestForTesting in TestRenderFrameHost

This CL calls WillStartRequest on the current NavigationHandle when a
navigation is starting. This mimics the SimulateRedirect call, and enables
NavigationThrottles which override WillStartRequest to be unit testable
using the content unit test framework.

Note: like SimulateRedirect, there is no current support for the throttles
actually cancelling / deferring the navigation.

BUG=627501

Review-Url: https://codereview.chromium.org/2157153003
Cr-Commit-Position: refs/heads/master@{#407150}
parent 77ad42cf
...@@ -2964,7 +2964,8 @@ ChromeContentBrowserClient::CreateThrottlesForNavigation( ...@@ -2964,7 +2964,8 @@ ChromeContentBrowserClient::CreateThrottlesForNavigation(
// Add interstitial page while merge session process (cookie reconstruction // Add interstitial page while merge session process (cookie reconstruction
// from OAuth2 refresh token in ChromeOS login) is still in progress while // from OAuth2 refresh token in ChromeOS login) is still in progress while
// we are attempting to load a google property. // we are attempting to load a google property.
if (!merge_session_throttling_utils::AreAllSessionMergedAlready() && if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() &&
!merge_session_throttling_utils::AreAllSessionMergedAlready() &&
handle->GetURL().SchemeIsHTTPOrHTTPS()) { handle->GetURL().SchemeIsHTTPOrHTTPS()) {
throttles.push_back(MergeSessionNavigationThrottle::Create(handle)); throttles.push_back(MergeSessionNavigationThrottle::Create(handle));
} }
......
...@@ -63,6 +63,10 @@ base::AtomicRefCount g_all_profiles_restored_ = 0; ...@@ -63,6 +63,10 @@ base::AtomicRefCount g_all_profiles_restored_ = 0;
} // namespace } // namespace
bool ShouldAttachNavigationThrottle() {
return user_manager::UserManager::IsInitialized();
}
bool AreAllSessionMergedAlready() { bool AreAllSessionMergedAlready() {
return !base::AtomicRefCountIsZero(&g_all_profiles_restored_); return !base::AtomicRefCountIsZero(&g_all_profiles_restored_);
} }
......
...@@ -25,6 +25,11 @@ namespace merge_session_throttling_utils { ...@@ -25,6 +25,11 @@ namespace merge_session_throttling_utils {
// page load. // page load.
using CompletionCallback = base::Closure; using CompletionCallback = base::Closure;
// Policy for when it is valid to attach a MergeSessionNavigationThrottle.
// Namely, this will be false for unit tests, where the UserManager is not
// initialized.
bool ShouldAttachNavigationThrottle();
// Checks if session is already merged. This is safe to call on all threads. // Checks if session is already merged. This is safe to call on all threads.
bool AreAllSessionMergedAlready(); bool AreAllSessionMergedAlready();
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/frame_messages.h" #include "content/common/frame_messages.h"
#include "content/common/frame_owner_properties.h" #include "content/common/frame_owner_properties.h"
#include "content/public/browser/navigation_throttle.h"
#include "content/public/browser/stream_handle.h" #include "content/public/browser/stream_handle.h"
#include "content/public/common/browser_side_navigation_policy.h" #include "content/public/common/browser_side_navigation_policy.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
...@@ -106,6 +107,7 @@ void TestRenderFrameHost::SimulateNavigationStart(const GURL& url) { ...@@ -106,6 +107,7 @@ void TestRenderFrameHost::SimulateNavigationStart(const GURL& url) {
OnDidStartLoading(true); OnDidStartLoading(true);
OnDidStartProvisionalLoad(url, base::TimeTicks::Now()); OnDidStartProvisionalLoad(url, base::TimeTicks::Now());
SimulateWillStartRequest(ui::PAGE_TRANSITION_LINK);
} }
void TestRenderFrameHost::SimulateRedirect(const GURL& new_url) { void TestRenderFrameHost::SimulateRedirect(const GURL& new_url) {
...@@ -290,6 +292,7 @@ void TestRenderFrameHost::SendNavigateWithParameters( ...@@ -290,6 +292,7 @@ void TestRenderFrameHost::SendNavigateWithParameters(
// so we keep a copy of it to use below. // so we keep a copy of it to use below.
GURL url_copy(url); GURL url_copy(url);
OnDidStartProvisionalLoad(url_copy, base::TimeTicks::Now()); OnDidStartProvisionalLoad(url_copy, base::TimeTicks::Now());
SimulateWillStartRequest(transition);
FrameHostMsg_DidCommitProvisionalLoad_Params params; FrameHostMsg_DidCommitProvisionalLoad_Params params;
params.page_id = page_id; params.page_id = page_id;
...@@ -440,4 +443,13 @@ int32_t TestRenderFrameHost::ComputeNextPageID() { ...@@ -440,4 +443,13 @@ int32_t TestRenderFrameHost::ComputeNextPageID() {
return page_id; return page_id;
} }
void TestRenderFrameHost::SimulateWillStartRequest(
ui::PageTransition transition) {
if (!navigation_handle())
return;
navigation_handle()->CallWillStartRequestForTesting(
false /* is_post */, Referrer(GURL(), blink::WebReferrerPolicyDefault),
true /* user_gesture */, transition, false /* is_external_protocol */);
}
} // namespace content } // namespace content
...@@ -149,6 +149,8 @@ class TestRenderFrameHost : public RenderFrameHostImpl, ...@@ -149,6 +149,8 @@ class TestRenderFrameHost : public RenderFrameHostImpl,
// Computes the page ID for a pending navigation in this RenderFrameHost; // Computes the page ID for a pending navigation in this RenderFrameHost;
int32_t ComputeNextPageID(); int32_t ComputeNextPageID();
void SimulateWillStartRequest(ui::PageTransition transition);
TestRenderFrameHostCreationObserver child_creation_observer_; TestRenderFrameHostCreationObserver child_creation_observer_;
std::string contents_mime_type_; std::string contents_mime_type_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment