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;
using base::OnceClosure;
using base::RunLoop;
using base::StringPiece;
using base::TimeDelta;
using base::trace_event::TraceConfig;
using content::TracingController;
using content::WebContents;
......@@ -43,10 +44,16 @@ void MetricIntegrationTest::SetUpOnMainThread() {
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,
const std::string& content) {
embedded_test_server()->RegisterRequestHandler(
base::BindRepeating(&HandleRequest, url, content));
ServeDelayed(url, content, TimeDelta());
}
void MetricIntegrationTest::Start() {
......@@ -106,9 +113,12 @@ void MetricIntegrationTest::SetUpCommandLine(CommandLine* command_line) {
std::unique_ptr<HttpResponse> MetricIntegrationTest::HandleRequest(
const std::string& relative_url,
const std::string& content,
TimeDelta delay,
const HttpRequest& request) {
if (request.relative_url != relative_url)
return nullptr;
if (!delay.is_zero())
base::PlatformThread::Sleep(delay);
auto response = std::make_unique<BasicHttpResponse>();
response->set_code(net::HTTP_OK);
response->set_content(content);
......
......@@ -49,6 +49,11 @@ class MetricIntegrationTest : public InProcessBrowserTest {
// type of "text/html; charset=utf-8".
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
// handlers, and before loading any pages.
void Start();
......@@ -90,6 +95,7 @@ class MetricIntegrationTest : public InProcessBrowserTest {
static std::unique_ptr<net::test_server::HttpResponse> HandleRequest(
const std::string& relative_url,
const std::string& content,
base::TimeDelta delay,
const net::test_server::HttpRequest& request);
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