Commit 983f2c4e authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Remove use of URLFetcher in HttpServer tests.

We have two implementations of HttpServer - one wraps a net::Socket and
one wraps a network::mojom::*Socket. They have near identical tests.
They have each have one corresponding test that, for some reason, was
using a URLFetcher. This CL makes both tests use the infrastructure all
other HttpServer tests use instead, for both tests.

Also worth noting that the net::Socket version is used only by
chromedriver and DevTools.  The latter seems like it might be a bug,
and the latter could perhaps be switched to the EmbeddedTestServer,
which would allow us to remove the net version.

Bug: 1010491
Change-Id: Ibb17e3795237cfc9005b409ca3fcec32fedb5448
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1842015Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Commit-Queue: Matt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703042}
parent 19c405e9
......@@ -44,11 +44,6 @@
#include "net/test/gtest_util.h"
#include "net/test/test_with_task_environment.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -451,37 +446,19 @@ TEST_F(WebSocketTest, RequestWebSocketTrailingJunk) {
}
TEST_F(HttpServerTest, RequestWithTooLargeBody) {
class TestURLFetcherDelegate : public URLFetcherDelegate {
public:
TestURLFetcherDelegate(const base::Closure& quit_loop_func)
: quit_loop_func_(quit_loop_func) {}
~TestURLFetcherDelegate() override = default;
void OnURLFetchComplete(const URLFetcher* source) override {
EXPECT_EQ(HTTP_INTERNAL_SERVER_ERROR, source->GetResponseCode());
quit_loop_func_.Run();
}
private:
base::Closure quit_loop_func_;
};
base::RunLoop run_loop;
TestURLFetcherDelegate delegate(run_loop.QuitClosure());
scoped_refptr<URLRequestContextGetter> request_context_getter(
new TestURLRequestContextGetter(base::ThreadTaskRunnerHandle::Get()));
std::unique_ptr<URLFetcher> fetcher = URLFetcher::Create(
GURL(base::StringPrintf("http://127.0.0.1:%d/test",
server_address_.port())),
URLFetcher::GET, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS);
fetcher->SetRequestContext(request_context_getter.get());
fetcher->AddExtraRequestHeader(
base::StringPrintf("content-length:%d", 1 << 30));
fetcher->Start();
run_loop.Run();
ASSERT_EQ(0u, requests_.size());
TestHttpClient client;
ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk());
client.Send(
"GET /test HTTP/1.1\r\n"
"Content-Length: 1073741824\r\n\r\n");
std::string response;
ASSERT_TRUE(client.ReadResponse(&response));
EXPECT_EQ(
"HTTP/1.1 500 Internal Server Error\r\n"
"Content-Length:42\r\n"
"Content-Type:text/html\r\n\r\n"
"request content-length too big or unknown.",
response);
}
TEST_F(HttpServerTest, Send200) {
......
......@@ -26,10 +26,6 @@
#include "net/log/net_log_source.h"
#include "net/test/gtest_util.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_test_util.h"
#include "services/network/public/cpp/server/http_connection.h"
#include "services/network/public/cpp/server/http_server_request_info.h"
......@@ -486,37 +482,19 @@ TEST_F(WebSocketTest, RequestWebSocketTrailingJunk) {
}
TEST_F(HttpServerTest, RequestWithTooLargeBody) {
class TestURLFetcherDelegate : public net::URLFetcherDelegate {
public:
TestURLFetcherDelegate(const base::RepeatingClosure& quit_loop_func)
: quit_loop_func_(quit_loop_func) {}
~TestURLFetcherDelegate() override = default;
void OnURLFetchComplete(const net::URLFetcher* source) override {
EXPECT_EQ(net::HTTP_INTERNAL_SERVER_ERROR, source->GetResponseCode());
quit_loop_func_.Run();
}
private:
base::RepeatingClosure quit_loop_func_;
};
base::RunLoop run_loop;
TestURLFetcherDelegate delegate(run_loop.QuitClosure());
scoped_refptr<net::URLRequestContextGetter> request_context_getter(
new net::TestURLRequestContextGetter(
base::ThreadTaskRunnerHandle::Get()));
std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create(
GURL(base::StringPrintf("http://[::1]:%d/test", server_address_.port())),
net::URLFetcher::GET, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS);
fetcher->SetRequestContext(request_context_getter.get());
fetcher->AddExtraRequestHeader(
base::StringPrintf("content-length:%d", 1 << 30));
fetcher->Start();
run_loop.Run();
ASSERT_EQ(0u, requests_.size());
TestHttpClient client;
ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk());
client.Send(
"GET /test HTTP/1.1\r\n"
"Content-Length: 1073741824\r\n\r\n");
std::string response;
ASSERT_TRUE(client.ReadResponse(&response));
EXPECT_EQ(
"HTTP/1.1 500 Internal Server Error\r\n"
"Content-Length:53\r\n"
"Content-Type:text/html\r\n\r\n"
"request content-length too big or unknown: 1073741824",
response);
}
TEST_F(HttpServerTest, Send200) {
......
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