Commit d3e5b177 authored by Fabrice de Gans-Riberi's avatar Fabrice de Gans-Riberi Committed by Commit Bot

Add tests for the fuchsia.oldhttp service.

This CL adds tests for the fuchsia.oldhttp service Chromium
implementation. These tests ensure the service is capable of sending
URL requests, receiving a response and/or an error code as expected.
The service implementation files have been moved around under a single
directory for consistency.

Bug: 874155
Change-Id: Iae843adc62db054a17125cea10b17771c127b801
Reviewed-on: https://chromium-review.googlesource.com/c/1239627Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Commit-Queue: Fabrice de Gans-Riberi <fdegans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600938}
parent d713bb2e
...@@ -749,6 +749,7 @@ group("gn_all") { ...@@ -749,6 +749,7 @@ group("gn_all") {
"//webrunner:archive_sources", "//webrunner:archive_sources",
"//webrunner:webrunner_unittests", "//webrunner:webrunner_unittests",
"//webrunner/net_http:http_pkg", "//webrunner/net_http:http_pkg",
"//webrunner/net_http:http_service_tests",
] ]
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
#include "build/build_config.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/base/proxy_delegate.h" #include "net/base/proxy_delegate.h"
#include "net/base/url_util.h" #include "net/base/url_util.h"
...@@ -1553,6 +1554,9 @@ ProxyResolutionService::CreateSystemProxyConfigService( ...@@ -1553,6 +1554,9 @@ ProxyResolutionService::CreateSystemProxyConfigService(
#elif defined(OS_ANDROID) #elif defined(OS_ANDROID)
return std::make_unique<ProxyConfigServiceAndroid>( return std::make_unique<ProxyConfigServiceAndroid>(
main_task_runner, base::ThreadTaskRunnerHandle::Get()); main_task_runner, base::ThreadTaskRunnerHandle::Get());
#elif defined(OS_FUCHSIA)
// TODO(crbug.com/889195): Implement a system proxy service for Fuchsia.
return std::make_unique<ProxyConfigServiceDirect>();
#else #else
LOG(WARNING) << "Failed to choose a system proxy settings fetcher " LOG(WARNING) << "Failed to choose a system proxy settings fetcher "
"for this platform."; "for this platform.";
......
...@@ -10,15 +10,14 @@ import("//build/util/process_version.gni") ...@@ -10,15 +10,14 @@ import("//build/util/process_version.gni")
import("//testing/test.gni") import("//testing/test.gni")
import("//tools/grit/repack.gni") import("//tools/grit/repack.gni")
executable("http_service") { component("http_lib") {
sources = [ sources = [
"service/http_service_impl.cc", "http_service_impl.cc",
"service/http_service_impl.h", "http_service_impl.h",
"service/http_service_main.cc", "url_loader_impl.cc",
"service/url_loader_impl.cc", "url_loader_impl.h",
"service/url_loader_impl.h",
] ]
deps = [ public_deps = [
"//base:base", "//base:base",
"//net:net", "//net:net",
"//third_party/fuchsia-sdk/sdk:oldhttp", "//third_party/fuchsia-sdk/sdk:oldhttp",
...@@ -26,6 +25,15 @@ executable("http_service") { ...@@ -26,6 +25,15 @@ executable("http_service") {
] ]
} }
executable("http_service") {
sources = [
"http_service_main.cc",
]
deps = [
":http_lib",
]
}
fuchsia_package("http_pkg") { fuchsia_package("http_pkg") {
binary = ":http_service" binary = ":http_service"
package_name_override = "http" package_name_override = "http"
...@@ -36,3 +44,18 @@ fuchsia_package_runner("http_pkg_runner") { ...@@ -36,3 +44,18 @@ fuchsia_package_runner("http_pkg_runner") {
package = ":http_pkg" package = ":http_pkg"
package_name_override = "http" package_name_override = "http"
} }
test("http_service_tests") {
sources = [
"http_service_test_main.cc",
"http_service_unittest.cc",
]
deps = [
":http_lib",
"//net:test_support",
"//testing/gtest",
]
data = [
"testdata/",
]
}
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "webrunner/net_http/service/http_service_impl.h" #include "webrunner/net_http/http_service_impl.h"
#include "net/url_request/url_request_context_builder.h" #include "net/url_request/url_request_context_builder.h"
#include "webrunner/net_http/service/url_loader_impl.h" #include "webrunner/net_http/url_loader_impl.h"
namespace net { namespace net_http {
HttpServiceImpl::HttpServiceImpl() { HttpServiceImpl::HttpServiceImpl() {
// TODO: Set the right options in the URLRequestContextBuilder. // TODO: Set the right options in the URLRequestContextBuilder.
...@@ -19,8 +19,8 @@ void HttpServiceImpl::CreateURLLoader( ...@@ -19,8 +19,8 @@ void HttpServiceImpl::CreateURLLoader(
fidl::InterfaceRequest<fuchsia::net::oldhttp::URLLoader> request) { fidl::InterfaceRequest<fuchsia::net::oldhttp::URLLoader> request) {
// The URLLoaderImpl objects lifespan is tied to their binding, which is set // The URLLoaderImpl objects lifespan is tied to their binding, which is set
// in their constructor. // in their constructor.
URLRequestContextBuilder builder; net::URLRequestContextBuilder builder;
new URLLoaderImpl(builder.Build(), std::move(request)); new URLLoaderImpl(builder.Build(), std::move(request));
} }
} // namespace net } // namespace net_http
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef WEBRUNNER_NET_HTTP_SERVICE_HTTP_SERVICE_IMPL_H_ #ifndef WEBRUNNER_NET_HTTP_HTTP_SERVICE_IMPL_H_
#define WEBRUNNER_NET_HTTP_SERVICE_HTTP_SERVICE_IMPL_H_ #define WEBRUNNER_NET_HTTP_HTTP_SERVICE_IMPL_H_
#include <fuchsia/net/oldhttp/cpp/fidl.h> #include <fuchsia/net/oldhttp/cpp/fidl.h>
#include <lib/fidl/cpp/interface_request.h> #include <lib/fidl/cpp/interface_request.h>
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
namespace net { namespace net_http {
// Implements the Fuchsia HttpService API, using the //net library. // Implements the Fuchsia HttpService API, using the //net library.
class HttpServiceImpl : public ::fuchsia::net::oldhttp::HttpService { class HttpServiceImpl : public ::fuchsia::net::oldhttp::HttpService {
...@@ -27,6 +27,6 @@ class HttpServiceImpl : public ::fuchsia::net::oldhttp::HttpService { ...@@ -27,6 +27,6 @@ class HttpServiceImpl : public ::fuchsia::net::oldhttp::HttpService {
DISALLOW_COPY_AND_ASSIGN(HttpServiceImpl); DISALLOW_COPY_AND_ASSIGN(HttpServiceImpl);
}; };
} // namespace net } // namespace net_http
#endif // WEBRUNNER_NET_HTTP_SERVICE_HTTP_SERVICE_IMPL_H_ #endif // WEBRUNNER_NET_HTTP_HTTP_SERVICE_IMPL_H_
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/task/task_scheduler/task_scheduler.h" #include "base/task/task_scheduler/task_scheduler.h"
#include "webrunner/net_http/service/http_service_impl.h" #include "webrunner/net_http/http_service_impl.h"
int main(int argc, char** argv) { int main(int argc, char** argv) {
// Instantiate various global structures. // Instantiate various global structures.
...@@ -23,7 +23,7 @@ int main(int argc, char** argv) { ...@@ -23,7 +23,7 @@ int main(int argc, char** argv) {
// publish the HTTP service into it. // publish the HTTP service into it.
base::fuchsia::ServiceDirectory* directory = base::fuchsia::ServiceDirectory* directory =
base::fuchsia::ServiceDirectory::GetDefault(); base::fuchsia::ServiceDirectory::GetDefault();
net::HttpServiceImpl http_service; net_http::HttpServiceImpl http_service;
base::fuchsia::ScopedServiceBinding<::fuchsia::net::oldhttp::HttpService> base::fuchsia::ScopedServiceBinding<::fuchsia::net::oldhttp::HttpService>
binding(directory, &http_service); binding(directory, &http_service);
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/at_exit.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
#include "base/task/task_scheduler/task_scheduler.h"
#include "testing/gtest/include/gtest/gtest.h"
int main(int argc, char** argv) {
// Instantiate various global structures.
base::TaskScheduler::CreateAndStartWithDefaultParams("HTTP Service Test");
base::CommandLine::Init(argc, argv);
base::MessageLoopForIO loop;
base::AtExitManager exit_manager;
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
This diff is collapsed.
HTTP/1.1 302 Redirect
Location: with-headers.html
Cache-Control: max-age=10000
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 5
This file is boring; all the action's in the .mock-http-headers.
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=ISO-8859-1
X-Multiple-Entries: a
X-Multiple-Entries: a
X-Multiple-Entries: b
This file is boring; all the action's in the .mock-http-headers.
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=ISO-8859-1
X-Multiple-Entries: a
X-Multiple-Entries: b
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef WEBRUNNER_NET_HTTP_SERVICE_URL_LOADER_IMPL_H_ #ifndef WEBRUNNER_NET_HTTP_URL_LOADER_IMPL_H_
#define WEBRUNNER_NET_HTTP_SERVICE_URL_LOADER_IMPL_H_ #define WEBRUNNER_NET_HTTP_URL_LOADER_IMPL_H_
#include <fuchsia/net/oldhttp/cpp/fidl.h> #include <fuchsia/net/oldhttp/cpp/fidl.h>
#include <fuchsia/sys/cpp/fidl.h> #include <fuchsia/sys/cpp/fidl.h>
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
namespace net { namespace net_http {
// URLLoader implementation. This class manages one network request per // URLLoader implementation. This class manages one network request per
// instance. Internally, this class uses a |net::URLRequest| object to handle // instance. Internally, this class uses a |net::URLRequest| object to handle
...@@ -23,16 +23,19 @@ namespace net { ...@@ -23,16 +23,19 @@ namespace net {
// |binding_|. // |binding_|.
// TODO(https://crbug.com/875532): Implement cache-mode. // TODO(https://crbug.com/875532): Implement cache-mode.
class URLLoaderImpl : public ::fuchsia::net::oldhttp::URLLoader, class URLLoaderImpl : public ::fuchsia::net::oldhttp::URLLoader,
public URLRequest::Delegate, public net::URLRequest::Delegate,
base::MessagePumpForIO::ZxHandleWatcher { base::MessagePumpForIO::ZxHandleWatcher {
public: public:
using Callback = ::fuchsia::net::oldhttp::URLLoader::StartCallback; using Callback = ::fuchsia::net::oldhttp::URLLoader::StartCallback;
URLLoaderImpl( URLLoaderImpl(
std::unique_ptr<URLRequestContext> context, std::unique_ptr<net::URLRequestContext> context,
::fidl::InterfaceRequest<::fuchsia::net::oldhttp::URLLoader> request); ::fidl::InterfaceRequest<::fuchsia::net::oldhttp::URLLoader> request);
~URLLoaderImpl() override; ~URLLoaderImpl() override;
// Returns the number of active requests. Used for testing.
static int GetNumActiveRequestsForTests();
private: private:
// URLLoader methods: // URLLoader methods:
void Start(::fuchsia::net::oldhttp::URLRequest request, void Start(::fuchsia::net::oldhttp::URLRequest request,
...@@ -42,18 +45,19 @@ class URLLoaderImpl : public ::fuchsia::net::oldhttp::URLLoader, ...@@ -42,18 +45,19 @@ class URLLoaderImpl : public ::fuchsia::net::oldhttp::URLLoader,
callback) override; callback) override;
// URLRequest::Delegate methods: // URLRequest::Delegate methods:
void OnReceivedRedirect(URLRequest* request, void OnReceivedRedirect(net::URLRequest* request,
const RedirectInfo& redirect_info, const net::RedirectInfo& redirect_info,
bool* defer_redirect) override; bool* defer_redirect) override;
void OnAuthRequired(URLRequest* request, void OnAuthRequired(net::URLRequest* request,
AuthChallengeInfo* auth_info) override; net::AuthChallengeInfo* auth_info) override;
void OnCertificateRequested(URLRequest* request, void OnCertificateRequested(
SSLCertRequestInfo* cert_request_info) override; net::URLRequest* request,
void OnSSLCertificateError(URLRequest* request, net::SSLCertRequestInfo* cert_request_info) override;
const SSLInfo& ssl_info, void OnSSLCertificateError(net::URLRequest* request,
const net::SSLInfo& ssl_info,
bool fatal) override; bool fatal) override;
void OnResponseStarted(URLRequest* request, int net_error) override; void OnResponseStarted(net::URLRequest* request, int net_error) override;
void OnReadCompleted(URLRequest* request, int bytes_read) override; void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
// MessagePumpForIO::ZxHandleWatcher method: // MessagePumpForIO::ZxHandleWatcher method:
void OnZxHandleSignalled(zx_handle_t handle, zx_signals_t signals) override; void OnZxHandleSignalled(zx_handle_t handle, zx_signals_t signals) override;
...@@ -77,10 +81,10 @@ class URLLoaderImpl : public ::fuchsia::net::oldhttp::URLLoader, ...@@ -77,10 +81,10 @@ class URLLoaderImpl : public ::fuchsia::net::oldhttp::URLLoader,
::fidl::Binding<::fuchsia::net::oldhttp::URLLoader> binding_; ::fidl::Binding<::fuchsia::net::oldhttp::URLLoader> binding_;
// Holds the net::URLRequestContext associated with the |net_request_| // Holds the net::URLRequestContext associated with the |net_request_|
std::unique_ptr<URLRequestContext> context_; std::unique_ptr<net::URLRequestContext> context_;
// Holds the net::URLRequest used to perform the network operation. // Holds the net::URLRequest used to perform the network operation.
std::unique_ptr<URLRequest> net_request_; std::unique_ptr<net::URLRequest> net_request_;
// Callback from a Start or FollowRedirect call. // Callback from a Start or FollowRedirect call.
Callback done_callback_; Callback done_callback_;
...@@ -116,6 +120,6 @@ class URLLoaderImpl : public ::fuchsia::net::oldhttp::URLLoader, ...@@ -116,6 +120,6 @@ class URLLoaderImpl : public ::fuchsia::net::oldhttp::URLLoader,
DISALLOW_COPY_AND_ASSIGN(URLLoaderImpl); DISALLOW_COPY_AND_ASSIGN(URLLoaderImpl);
}; };
} // namespace net } // namespace net_http
#endif // WEBRUNNER_NET_HTTP_SERVICE_URL_LOADER_IMPL_H_ #endif // WEBRUNNER_NET_HTTP_URL_LOADER_IMPL_H_
\ No newline at end of file \ No newline at end of file
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