#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "content/public/test/test_download_http_response.h"
#include <inttypes.h>
#include <algorithm>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/functional/callback_helpers.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/lock.h"
#include "base/task/single_thread_task_runner.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/test_completion_callback.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_util.h"
#include "net/test/embedded_test_server/http_response.h"
namespace content {
namespace {
base::LazyInstance<base::Lock>::Leaky g_lock = …;
ParametersMap;
base::LazyInstance<ParametersMap>::Leaky g_parameters_map = …;
const char* kTestDownloadPath = …;
const int64_t kBufferSize = …;
uint64_t XorShift64StarWithIndex(uint64_t seed, uint64_t index) { … }
void OnResume(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
base::OnceClosure resume_callback) { … }
void OnResponseSentOnServerIOThread(
TestDownloadHttpResponse::OnResponseSentCallback callback,
std::unique_ptr<TestDownloadHttpResponse::CompletedRequest> request) { … }
GURL GetURLFromRequest(const net::test_server::HttpRequest& request) { … }
class HttpResponse : public net::test_server::HttpResponse { … };
}
const char TestDownloadHttpResponse::kTestDownloadHostName[] = …;
GURL TestDownloadHttpResponse::GetNextURLForDownload() { … }
TestDownloadHttpResponse::HttpResponseData::HttpResponseData(
int64_t min_offset,
int64_t max_offset,
const std::string& response,
bool is_transient,
bool delay_response)
: … { … }
TestDownloadHttpResponse::Parameters
TestDownloadHttpResponse::Parameters::WithSingleInterruption(
const TestDownloadHttpResponse::InjectErrorCallback& inject_error_cb) { … }
TestDownloadHttpResponse::Parameters::Parameters()
: … { … }
TestDownloadHttpResponse::Parameters::Parameters(const Parameters& that) =
default;
TestDownloadHttpResponse::Parameters& TestDownloadHttpResponse::Parameters::
operator=(const Parameters& that) = default;
TestDownloadHttpResponse::Parameters::~Parameters() = default;
void TestDownloadHttpResponse::Parameters::ClearInjectedErrors() { … }
void TestDownloadHttpResponse::Parameters::SetResponseForRangeRequest(
int64_t min_offset,
int64_t max_offset,
const std::string& response,
bool is_transient,
bool delay_response) { … }
TestDownloadHttpResponse::CompletedRequest::CompletedRequest(
const net::test_server::HttpRequest& request)
: … { … }
TestDownloadHttpResponse::CompletedRequest::~CompletedRequest() = default;
void TestDownloadHttpResponse::StartServing(
const TestDownloadHttpResponse::Parameters& parameters,
const GURL& url) { … }
void TestDownloadHttpResponse::StartServingStaticResponse(
const std::string& response,
const GURL& url) { … }
std::unique_ptr<net::test_server::HttpResponse>
TestDownloadHttpResponse::CreateResponseForTestServer() { … }
std::string TestDownloadHttpResponse::GetPatternBytes(int seed,
int64_t starting_offset,
int length) { … }
TestDownloadHttpResponse::TestDownloadHttpResponse(
const net::test_server::HttpRequest& request,
const Parameters& parameters,
OnResponseSentCallback on_response_sent_callback)
: … { … }
TestDownloadHttpResponse::~TestDownloadHttpResponse() = default;
void TestDownloadHttpResponse::SendResponse(
base::WeakPtr<net::test_server::HttpResponseDelegate> delegate) { … }
void TestDownloadHttpResponse::ParseRequestHeader() { … }
void TestDownloadHttpResponse::SendResponseHeaders() { … }
std::string TestDownloadHttpResponse::GetDefaultResponseHeaders() { … }
bool TestDownloadHttpResponse::GetResponseForRangeRequest(
std::string* output,
bool* delay_response) { … }
bool TestDownloadHttpResponse::HandleRangeAssumingValidatorMatch(
std::string& response) { … }
std::string TestDownloadHttpResponse::GetCommonEntityHeaders() { … }
std::string TestDownloadHttpResponse::GetResponseChunk(
const net::HttpByteRange& buffer_range) { … }
bool TestDownloadHttpResponse::ShouldAbortImmediately() const { … }
bool TestDownloadHttpResponse::ShouldPauseImmediately() const { … }
bool TestDownloadHttpResponse::HandlePause(
const net::HttpByteRange& buffer_range) { … }
bool TestDownloadHttpResponse::HandleInjectedError(
const net::HttpByteRange& buffer_range) { … }
bool TestDownloadHttpResponse::ShouldPause(
const net::HttpByteRange& buffer_range) const { … }
void TestDownloadHttpResponse::PauseResponsesAndWaitForResumption() { … }
void TestDownloadHttpResponse::SendResponseBodyChunk() { … }
void TestDownloadHttpResponse::SendBodyChunkInternal(
const net::HttpByteRange& buffer_range,
base::OnceClosure next) { … }
base::OnceClosure TestDownloadHttpResponse::SendNextBodyChunkClosure() { … }
void TestDownloadHttpResponse::SendDelayedResponse() { … }
void TestDownloadHttpResponse::GenerateResult() { … }
base::OnceClosure TestDownloadHttpResponse::GenerateResultClosure() { … }
std::unique_ptr<net::test_server::HttpResponse>
TestDownloadResponseHandler::HandleTestDownloadRequest(
TestDownloadHttpResponse::OnResponseSentCallback callback,
const net::test_server::HttpRequest& request) { … }
TestDownloadResponseHandler::TestDownloadResponseHandler() = default;
TestDownloadResponseHandler::~TestDownloadResponseHandler() { … }
void TestDownloadResponseHandler::RegisterToTestServer(
net::test_server::EmbeddedTestServer* server) { … }
void TestDownloadResponseHandler::OnRequestCompleted(
std::unique_ptr<TestDownloadHttpResponse::CompletedRequest> request) { … }
void TestDownloadResponseHandler::WaitUntilCompletion(size_t request_count) { … }
void TestDownloadResponseHandler::DispatchDelayedResponses() { … }
}