Commit e7a44565 authored by arthursonzogni's avatar arthursonzogni Committed by Commit bot

PlzNavigate: Fix wrong "Cache-Control" header.

This CL modify the FrameLoadType of frames such that the
ReloadBypassingCache load type gets propagated to every subframe during
a reload.

It fixes ReloadCacheControlBrowserTest.BypassingReload test with
PlzNavigate. Every ReloadCacheControlbroserTest are passing now.

BUG=671545
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_chromium_browser_side_navigation_rel

Review-Url: https://codereview.chromium.org/2863683003
Cr-Commit-Position: refs/heads/master@{#471029}
parent 3d449e8c
...@@ -157,20 +157,14 @@ IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) { ...@@ -157,20 +157,14 @@ IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) {
// Test if bypassing reload issues requests with proper cache control flags. // Test if bypassing reload issues requests with proper cache control flags.
IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) { IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) {
// TODO(crbug.com/671545): This test gets to be unstable if browser-side
// navigation is enabled. This is because we can not ensure which of frame and
// image requests hits the network first.
if (IsBrowserSideNavigationEnabled())
return;
GURL url(embedded_test_server()->GetURL(kReloadTestPath)); GURL url(embedded_test_server()->GetURL(kReloadTestPath));
EXPECT_TRUE(NavigateToURL(shell(), url)); NavigateToURLBlockUntilNavigationsComplete(shell(), url, 1);
ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1);
{ {
base::AutoLock lock(request_log_lock_); base::AutoLock lock(request_log_lock_);
ASSERT_EQ(8UL, request_log_.size()); ASSERT_EQ(4UL, request_log_.size());
EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url); EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control); EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url); EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
...@@ -179,6 +173,12 @@ IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) { ...@@ -179,6 +173,12 @@ IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) {
EXPECT_EQ(kNoCacheControl, request_log_[2].cache_control); EXPECT_EQ(kNoCacheControl, request_log_[2].cache_control);
EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url); EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control); EXPECT_EQ(kNoCacheControl, request_log_[3].cache_control);
}
ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1);
{
base::AutoLock lock(request_log_lock_);
ASSERT_EQ(8UL, request_log_.size());
// Only the top main resource should be requested with kNoCacheCacheControl. // Only the top main resource should be requested with kNoCacheCacheControl.
EXPECT_EQ(kReloadTestPath, request_log_[4].relative_url); EXPECT_EQ(kReloadTestPath, request_log_[4].relative_url);
......
...@@ -228,6 +228,10 @@ void FrameFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request, ...@@ -228,6 +228,10 @@ void FrameFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request,
request.SetHTTPHeaderField("Save-Data", "on"); request.SetHTTPHeaderField("Save-Data", "on");
} }
// TODO(toyoshim, arthursonzogni): PlzNavigate doesn't use this function to set
// the ResourceRequest's cache policy. The cache policy determination needs to
// be factored out from FrameFetchContext and moved to the FrameLoader for
// instance.
WebCachePolicy FrameFetchContext::ResourceRequestCachePolicy( WebCachePolicy FrameFetchContext::ResourceRequestCachePolicy(
const ResourceRequest& request, const ResourceRequest& request,
Resource::Type type, Resource::Type type,
......
...@@ -1706,23 +1706,48 @@ LocalFrame* WebLocalFrameImpl::CreateChildFrame( ...@@ -1706,23 +1706,48 @@ LocalFrame* WebLocalFrameImpl::CreateChildFrame(
if (!webframe_child->Parent()) if (!webframe_child->Parent())
return nullptr; return nullptr;
// If we're moving in the back/forward list, we might want to replace the FrameLoadRequest new_request = request;
// content of this child frame with whatever was there at that point. FrameLoadType child_load_type = kFrameLoadTypeStandard;
HistoryItem* child_item = nullptr; HistoryItem* child_item = nullptr;
if (IsBackForwardLoadType(
GetFrame()->Loader().GetDocumentLoader()->LoadType()) &&
!GetFrame()->GetDocument()->LoadEventFinished())
child_item = webframe_child->Client()->HistoryItemForNewChildFrame();
FrameLoadRequest new_request = request; if (!GetFrame()->GetDocument()->LoadEventFinished()) {
FrameLoadType load_type = kFrameLoadTypeStandard; FrameLoadType load_type =
if (child_item) { GetFrame()->Loader().GetDocumentLoader()->LoadType();
new_request = FrameLoadRequest( switch (load_type) {
request.OriginDocument(), child_item->GenerateResourceRequest( case kFrameLoadTypeStandard:
WebCachePolicy::kUseProtocolCachePolicy)); case kFrameLoadTypeReplaceCurrentItem:
load_type = kFrameLoadTypeInitialHistoryLoad; case kFrameLoadTypeInitialInChildFrame:
break;
// If we're moving in the back/forward list, we might want to replace the
// content of this child frame with whatever was there at that point.
case kFrameLoadTypeBackForward:
case kFrameLoadTypeInitialHistoryLoad:
child_item = webframe_child->Client()->HistoryItemForNewChildFrame();
if (child_item) {
child_load_type = kFrameLoadTypeInitialHistoryLoad;
new_request =
FrameLoadRequest(request.OriginDocument(),
child_item->GenerateResourceRequest(
WebCachePolicy::kUseProtocolCachePolicy));
}
break;
// We're in a middle of a reload. The FrameLoadType is propagated to its
// children only if it is a ReloadBypassingCache, else it becomes a
// standard load.
case kFrameLoadTypeReload:
break;
case kFrameLoadTypeReloadBypassingCache:
child_load_type = kFrameLoadTypeReloadBypassingCache;
new_request.GetResourceRequest().SetCachePolicy(
WebCachePolicy::kBypassingCache);
break;
}
} }
webframe_child->GetFrame()->Loader().Load(new_request, load_type, child_item);
webframe_child->GetFrame()->Loader().Load(new_request, child_load_type,
child_item);
// Note a synchronous navigation (about:blank) would have already processed // Note a synchronous navigation (about:blank) would have already processed
// onload, so it is possible for the child frame to have already been // onload, so it is possible for the child frame to have already been
......
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