Chromium Code Reviews| Index: components/cronet/android/test/native_test_server.cc |
| diff --git a/components/cronet/android/test/native_test_server.cc b/components/cronet/android/test/native_test_server.cc |
| index 60bd3a0070f05ece18867b1c09476d101c118382..687109b4c75024dbbefe05f614456f65c1b30e2c 100644 |
| --- a/components/cronet/android/test/native_test_server.cc |
| +++ b/components/cronet/android/test/native_test_server.cc |
| @@ -15,10 +15,12 @@ |
| #include "base/files/file_path.h" |
| #include "base/files/file_util.h" |
| #include "base/macros.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/path_service.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/test/test_support_android.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| #include "components/cronet/android/test/cronet_test_util.h" |
| #include "jni/NativeTestServer_jni.h" |
| #include "net/base/host_port_pair.h" |
| @@ -27,6 +29,7 @@ |
| #include "net/test/embedded_test_server/embedded_test_server.h" |
| #include "net/test/embedded_test_server/http_request.h" |
| #include "net/test/embedded_test_server/http_response.h" |
| +#include "net/test/embedded_test_server/request_handler_util.h" |
| #include "url/gurl.h" |
| namespace cronet { |
| @@ -38,6 +41,7 @@ const char kEchoHeaderPath[] = "/echo_header"; |
| const char kEchoAllHeadersPath[] = "/echo_all_headers"; |
| const char kEchoMethodPath[] = "/echo_method"; |
| const char kRedirectToEchoBodyPath[] = "/redirect_to_echo_body"; |
| +const char kExabyteResponsePath[] = "/exabyte_response"; |
| // Path that advertises the dictionary passed in query params if client |
| // supports Sdch encoding. E.g. /sdch/index?q=LeQxM80O will make the server |
| // responds with "Get-Dictionary: /sdch/dict/LeQxM80O". |
| @@ -49,6 +53,31 @@ const char kSdchDictPath[] = "/sdch/dict/"; |
| net::EmbeddedTestServer* g_test_server = nullptr; |
| +// A HttpResponse that is almost never ending (with an Extabyte content-length). |
| +class ExabyteResponse : public net::test_server::BasicHttpResponse { |
| + public: |
| + ExabyteResponse() {} |
| + |
| + void SendResponse( |
| + const net::test_server::SendBytesCallback& send, |
| + const net::test_server::SendCompleteCallback& done) override { |
| + // Use 10^18 bytes (exabyte) as the content length so that the client will |
| + // be expecting data. |
| + send.Run("HTTP/1.1 200 OK\r\nContent-Length:1000000000000000000\r\n\r\n", |
| + base::Bind(&ExabyteResponse::SendExabyte, send)); |
| + } |
| + |
| + private: |
| + // Keeps sending the word "echo" over and over again. |
| + static void SendExabyte(const net::test_server::SendBytesCallback& send) { |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
|
pauljensen
2016/07/21 11:30:54
I think we should make this stop after sending an
xunjieli
2016/07/21 13:05:05
Done.
|
| + FROM_HERE, base::Bind(send, "echo", |
| + base::Bind(&ExabyteResponse::SendExabyte, send))); |
| + } |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ExabyteResponse); |
| +}; |
| + |
| std::unique_ptr<net::test_server::RawHttpResponse> ConstructResponseBasedOnFile( |
| const base::FilePath& file_path) { |
| std::string file_contents; |
| @@ -161,6 +190,11 @@ std::unique_ptr<net::test_server::HttpResponse> SdchRequestHandler( |
| return std::unique_ptr<net::test_server::BasicHttpResponse>(); |
| } |
| +std::unique_ptr<net::test_server::HttpResponse> HandleExabyteRequest( |
| + const net::test_server::HttpRequest& request) { |
| + return base::WrapUnique(new ExabyteResponse); |
| +} |
| + |
| } // namespace |
| jboolean StartNativeTestServer(JNIEnv* env, |
| @@ -178,6 +212,9 @@ jboolean StartNativeTestServer(JNIEnv* env, |
| g_test_server = new net::EmbeddedTestServer(); |
| g_test_server->RegisterRequestHandler( |
| base::Bind(&NativeTestServerRequestHandler)); |
| + g_test_server->RegisterDefaultHandler( |
| + base::Bind(&net::test_server::HandlePrefixedRequest, kExabyteResponsePath, |
| + base::Bind(&HandleExabyteRequest))); |
| g_test_server->RegisterRequestHandler(base::Bind(&SdchRequestHandler)); |
| base::FilePath test_files_root( |
| base::android::ConvertJavaStringToUTF8(env, jtest_files_root)); |
| @@ -259,6 +296,14 @@ ScopedJavaLocalRef<jstring> GetSdchURL(JNIEnv* env, |
| return base::android::ConvertUTF8ToJavaString(env, url); |
| } |
| +ScopedJavaLocalRef<jstring> GetExabyteResponseURL( |
| + JNIEnv* env, |
| + const JavaParamRef<jclass>& jcaller) { |
| + DCHECK(g_test_server); |
| + GURL url = g_test_server->GetURL(kExabyteResponsePath); |
| + return base::android::ConvertUTF8ToJavaString(env, url.spec()); |
| +} |
| + |
| ScopedJavaLocalRef<jstring> GetHostPort(JNIEnv* env, |
| const JavaParamRef<jclass>& jcaller) { |
| DCHECK(g_test_server); |