Commit 71a43871 authored by Steve Kobes's avatar Steve Kobes Committed by Commit Bot

Support delayed HTTP responses in MetricIntegrationTest.

Bug: 1045064
Change-Id: I49a454e4333c3f32a5516e632901ff368ddbe729
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2065322Reviewed-by: default avatarTimothy Dresser <tdresser@chromium.org>
Commit-Queue: Steve Kobes <skobes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743146}
parent 92a674af
...@@ -19,6 +19,7 @@ using base::CommandLine; ...@@ -19,6 +19,7 @@ using base::CommandLine;
using base::OnceClosure; using base::OnceClosure;
using base::RunLoop; using base::RunLoop;
using base::StringPiece; using base::StringPiece;
using base::TimeDelta;
using base::trace_event::TraceConfig; using base::trace_event::TraceConfig;
using content::TracingController; using content::TracingController;
using content::WebContents; using content::WebContents;
...@@ -43,10 +44,16 @@ void MetricIntegrationTest::SetUpOnMainThread() { ...@@ -43,10 +44,16 @@ void MetricIntegrationTest::SetUpOnMainThread() {
histogram_tester_.emplace(); histogram_tester_.emplace();
} }
void MetricIntegrationTest::ServeDelayed(const std::string& url,
const std::string& content,
TimeDelta delay) {
embedded_test_server()->RegisterRequestHandler(
base::BindRepeating(&HandleRequest, url, content, delay));
}
void MetricIntegrationTest::Serve(const std::string& url, void MetricIntegrationTest::Serve(const std::string& url,
const std::string& content) { const std::string& content) {
embedded_test_server()->RegisterRequestHandler( ServeDelayed(url, content, TimeDelta());
base::BindRepeating(&HandleRequest, url, content));
} }
void MetricIntegrationTest::Start() { void MetricIntegrationTest::Start() {
...@@ -106,9 +113,12 @@ void MetricIntegrationTest::SetUpCommandLine(CommandLine* command_line) { ...@@ -106,9 +113,12 @@ void MetricIntegrationTest::SetUpCommandLine(CommandLine* command_line) {
std::unique_ptr<HttpResponse> MetricIntegrationTest::HandleRequest( std::unique_ptr<HttpResponse> MetricIntegrationTest::HandleRequest(
const std::string& relative_url, const std::string& relative_url,
const std::string& content, const std::string& content,
TimeDelta delay,
const HttpRequest& request) { const HttpRequest& request) {
if (request.relative_url != relative_url) if (request.relative_url != relative_url)
return nullptr; return nullptr;
if (!delay.is_zero())
base::PlatformThread::Sleep(delay);
auto response = std::make_unique<BasicHttpResponse>(); auto response = std::make_unique<BasicHttpResponse>();
response->set_code(net::HTTP_OK); response->set_code(net::HTTP_OK);
response->set_content(content); response->set_content(content);
......
...@@ -49,6 +49,11 @@ class MetricIntegrationTest : public InProcessBrowserTest { ...@@ -49,6 +49,11 @@ class MetricIntegrationTest : public InProcessBrowserTest {
// type of "text/html; charset=utf-8". // type of "text/html; charset=utf-8".
void Serve(const std::string& url, const std::string& content); void Serve(const std::string& url, const std::string& content);
// Like Serve, but with an artificial time delay in the response.
void ServeDelayed(const std::string& url,
const std::string& content,
base::TimeDelta delay);
// Starts the test server. Call this after configuring request // Starts the test server. Call this after configuring request
// handlers, and before loading any pages. // handlers, and before loading any pages.
void Start(); void Start();
...@@ -90,6 +95,7 @@ class MetricIntegrationTest : public InProcessBrowserTest { ...@@ -90,6 +95,7 @@ class MetricIntegrationTest : public InProcessBrowserTest {
static std::unique_ptr<net::test_server::HttpResponse> HandleRequest( static std::unique_ptr<net::test_server::HttpResponse> HandleRequest(
const std::string& relative_url, const std::string& relative_url,
const std::string& content, const std::string& content,
base::TimeDelta delay,
const net::test_server::HttpRequest& request); const net::test_server::HttpRequest& request);
base::Optional<ukm::TestAutoSetUkmRecorder> ukm_recorder_; base::Optional<ukm::TestAutoSetUkmRecorder> ukm_recorder_;
......
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