Commit 3d015abd authored by Ryan Sturm's avatar Ryan Sturm Committed by Chromium LUCI CQ

Set completion time for the search prefetch streaming requests

Completion time is the only timing field that is set even when load
timing is not enabled. For now, we will solve this with setting the
completion time (and thereafter response end) to when the memory cache
is actually hit.

Bug: 1167308
Change-Id: Idfa8d628d42f5acf66ba702319c1bce6aa618199
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2634022
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Reviewed-by: default avatarRobert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844319}
parent f6658bc4
......@@ -2304,6 +2304,66 @@ IN_PROC_BROWSER_TEST_P(SearchPrefetchServiceEnabledBrowserTest,
EXPECT_FALSE(prefetch_status.has_value());
}
IN_PROC_BROWSER_TEST_P(SearchPrefetchServiceEnabledBrowserTest,
RequestTimingIsNonNegative) {
base::HistogramTester histogram_tester;
auto* search_prefetch_service =
SearchPrefetchServiceFactory::GetForProfile(browser()->profile());
EXPECT_NE(nullptr, search_prefetch_service);
std::string search_terms = "prefetch_content";
GURL prefetch_url = GetSearchServerQueryURL(search_terms);
EXPECT_TRUE(search_prefetch_service->MaybePrefetchURL(prefetch_url));
auto prefetch_status =
search_prefetch_service->GetSearchPrefetchStatusForTesting(
base::ASCIIToUTF16(search_terms));
WaitUntilStatusChangesTo(base::ASCIIToUTF16(search_terms),
SearchPrefetchStatus::kComplete);
prefetch_status = search_prefetch_service->GetSearchPrefetchStatusForTesting(
base::ASCIIToUTF16(search_terms));
ASSERT_TRUE(prefetch_status.has_value());
EXPECT_EQ(SearchPrefetchStatus::kComplete, prefetch_status.value());
ui_test_utils::NavigateToURL(browser(), prefetch_url);
content::RenderFrameHost* frame = GetWebContents()->GetMainFrame();
// Check the request total time is non-negative.
int value = -1;
std::string script =
"window.domAutomationController.send(window.performance.timing."
"responseEnd - window.performance.timing.requestStart)";
EXPECT_TRUE(content::ExecuteScriptAndExtractInt(frame, script, &value));
EXPECT_LE(0, value);
// Check the response time is non-negative.
value = -1;
script =
"window.domAutomationController.send(window.performance.timing."
"responseEnd - window.performance.timing.responseStart)";
EXPECT_TRUE(content::ExecuteScriptAndExtractInt(frame, script, &value));
EXPECT_LE(0, value);
// Check request start is after (or the same as) navigation start.
value = -1;
script =
"window.domAutomationController.send(window.performance.timing."
"requestStart - window.performance.timing.navigationStart)";
EXPECT_TRUE(content::ExecuteScriptAndExtractInt(frame, script, &value));
EXPECT_LE(0, value);
// Check response end is after (or the same as) navigation start.
value = -1;
script =
"window.domAutomationController.send(window.performance.timing."
"responseEnd - window.performance.timing.navigationStart)";
EXPECT_TRUE(content::ExecuteScriptAndExtractInt(frame, script, &value));
EXPECT_LE(0, value);
}
// True means that responses are streamed, false means full responses must be
// received in order to server the response.
INSTANTIATE_TEST_SUITE_P(All,
......
......@@ -84,6 +84,12 @@ void StreamingSearchPrefetchURLLoader::SetUpForwardingClient(
resource_response_->raw_request_response_info = nullptr;
}
// We are serving, so if the request is complete before serving, mark the
// request completion time as now.
if (status_) {
status_->completion_time = base::TimeTicks::Now();
}
forwarding_client_->OnReceiveResponse(std::move(resource_response_));
RunEventQueue();
}
......
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