#include "services/network/public/cpp/simple_url_loader.h"
#include <stdint.h>
#include <list>
#include <optional>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>
#include <vector>
#include "base/base_paths.h"
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/notreached.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/sequence_checker.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/bind.h"
#include "base/test/power_monitor_test.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_timeouts.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/data_pipe.h"
#include "net/base/mock_network_change_notifier.h"
#include "net/base/network_change_notifier.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_status_code.h"
#include "net/http/http_util.h"
#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/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/redirect_info.h"
#include "net/url_request/url_request.h"
#include "services/network/network_service.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
#include "services/network/public/mojom/data_pipe_getter.mojom.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/fake_test_cert_verifier_params_factory.h"
#include "services/network/test/test_network_context_client.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/radio_utils.h"
#endif
namespace network {
namespace {
ElementsAre;
const char kResponseSizePath[] = …;
const char kInvalidGzipPath[] = …;
const char kTruncatedBodyPath[] = …;
const char kTruncatedBody[] = …;
const char kFailOnceThenEchoBody[] = …;
const char kShortUploadBody[] = …;
const char kExpectedResponse[] = …;
const int64_t kExpectedResponseSize = …;
std::string GetLongUploadBody(
size_t size = SimpleURLLoader::kMaxUploadStringSizeToCopy) { … }
class SimpleLoaderTestHelper : public SimpleURLLoaderStreamConsumer { … };
std::unique_ptr<net::test_server::HttpResponse> HandleResponseSize(
const net::test_server::HttpRequest& request) { … }
std::unique_ptr<net::test_server::HttpResponse> HandleInvalidGzip(
const net::test_server::HttpRequest& request) { … }
std::unique_ptr<net::test_server::HttpResponse> HandleTruncatedBody(
const net::test_server::HttpRequest& request) { … }
std::unique_ptr<net::test_server::HttpResponse> FailOnceThenEchoBody(
bool* has_failed_request,
const net::test_server::HttpRequest& request) { … }
class SimpleURLLoaderTestBase { … };
enum class ReadAndDiscardBodyType { … };
DownloadTypeAndOptions;
void PrintTo(const DownloadTypeAndOptions& value, std::ostream* os) { … }
struct URLLoaderFactoryTestConfig { … };
class SimpleURLLoaderTest
: public SimpleURLLoaderTestBase,
public testing::TestWithParam<DownloadTypeAndOptions> { … };
TEST_P(SimpleURLLoaderTest, BasicRequest) { … }
TEST_P(SimpleURLLoaderTest, GzipBody) { … }
TEST_P(SimpleURLLoaderTest, Redirect) { … }
TEST_P(SimpleURLLoaderTest, RedirectFile) { … }
TEST_P(SimpleURLLoaderTest, RedirectData) { … }
TEST_P(SimpleURLLoaderTest, OnRedirectCallback) { … }
TEST_P(SimpleURLLoaderTest, OnRedirectCallbackTwoRedirects) { … }
TEST_P(SimpleURLLoaderTest, DeleteInOnRedirectCallback) { … }
TEST_P(SimpleURLLoaderTest, UploadShortStringWithRedirect) { … }
TEST_P(SimpleURLLoaderTest, UploadLongStringWithRedirect) { … }
TEST_P(SimpleURLLoaderTest,
OnRedirectCallbackReturnsExistingToBeRemovedHeaders) { … }
TEST_P(SimpleURLLoaderTest,
OnRedirectCallbackReturnsNonExistingToBeRemovedHeaders) { … }
TEST_P(SimpleURLLoaderTest, OnResponseStartedCallback) { … }
TEST_P(SimpleURLLoaderTest, DeleteInOnResponseStartedCallback) { … }
TEST_P(SimpleURLLoaderTest, DestroyLoaderInOnComplete) { … }
TEST_P(SimpleURLLoaderTest, DisconnectedURLLoader) { … }
TEST_P(SimpleURLLoaderTest, HttpErrorStatusCodeResponse) { … }
TEST_P(SimpleURLLoaderTest, HttpErrorStatusCodeResponseAllowed) { … }
TEST_P(SimpleURLLoaderTest, EmptyResponseBody) { … }
TEST_P(SimpleURLLoaderTest, BigResponseBody) { … }
#define GTEST_SKIP_IF_STREAM() …
TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeMatchingLimit) { … }
TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeBelowLimit) { … }
TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeAboveLimit) { … }
TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeAboveLimitPartialResponse) { … }
TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeMatchingLimit) { … }
TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeBelowLimit) { … }
TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeAboveLimit) { … }
TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeAboveLimitPartialResponse) { … }
TEST_P(SimpleURLLoaderTest, NetErrorBeforeHeaders) { … }
TEST_P(SimpleURLLoaderTest, NetErrorBeforeHeadersWithPartialResults) { … }
TEST_P(SimpleURLLoaderTest, NetErrorAfterHeaders) { … }
TEST_P(SimpleURLLoaderTest, NetErrorAfterHeadersWithPartialResults) { … }
TEST_P(SimpleURLLoaderTest, TruncatedBody) { … }
TEST_P(SimpleURLLoaderTest, TruncatedBodyWithPartialResults) { … }
TEST_P(SimpleURLLoaderTest, DestroyServiceBeforeResponseStarts) { … }
TEST_P(SimpleURLLoaderTest, UploadShortString) { … }
TEST_P(SimpleURLLoaderTest, UploadLongString) { … }
TEST_P(SimpleURLLoaderTest, UploadEmptyString) { … }
TEST_P(SimpleURLLoaderTest, UploadShortStringWithRetry) { … }
TEST_P(SimpleURLLoaderTest, UploadLongStringWithRetry) { … }
TEST_P(SimpleURLLoaderTest, UploadFile) { … }
TEST_P(SimpleURLLoaderTest, UploadFileRange) { … }
TEST_P(SimpleURLLoaderTest, UploadFileWithPut) { … }
TEST_P(SimpleURLLoaderTest, UploadFileWithRetry) { … }
TEST_P(SimpleURLLoaderTest, UploadNonexistentFile) { … }
TEST_P(SimpleURLLoaderTest, UploadFileCanceledBeforeLoaderStarted) { … }
TEST_P(SimpleURLLoaderTest, UploadFileCanceledWithRetry) { … }
enum class TestLoaderEvent { … };
class MockURLLoader : public network::mojom::URLLoader { … };
class MockURLLoaderFactory : public network::mojom::URLLoaderFactory { … };
TEST_P(SimpleURLLoaderTest, ResponseCompleteBeforeReceivedResponse) { … }
TEST_P(SimpleURLLoaderTest, ResponseCompleteAfterReceivedResponse) { … }
TEST_P(SimpleURLLoaderTest, CloseClientPipeBeforeBodyStarts) { … }
#if BUILDFLAG(IS_IOS)
#define MAYBE_CloseClientPipeOrder …
#else
#define MAYBE_CloseClientPipeOrder …
#endif
TEST_P(SimpleURLLoaderTest, MAYBE_CloseClientPipeOrder) { … }
TEST_P(SimpleURLLoaderTest, ErrorAndCloseClientPipeBeforeBodyStarts) { … }
TEST_P(SimpleURLLoaderTest, SuccessAndCloseClientPipeBeforeBodyComplete) { … }
TEST_P(SimpleURLLoaderTest, SuccessAndCloseClientPipeAfterBodyComplete) { … }
TEST_P(SimpleURLLoaderTest, DoubleReceivedResponse) { … }
TEST_P(SimpleURLLoaderTest, RedirectAfterReceivedResponse) { … }
TEST_P(SimpleURLLoaderTest, DoubleBodyBufferReceived) { … }
TEST_P(SimpleURLLoaderTest, UnexpectedMessageAfterBodyStarts) { … }
TEST_P(SimpleURLLoaderTest, UnexpectedMessageAfterBodyStarts2) { … }
TEST_P(SimpleURLLoaderTest, UnexpectedMessageAfterBodyComplete) { … }
TEST_P(SimpleURLLoaderTest, MoreDataThanExpected) { … }
TEST_P(SimpleURLLoaderTest, DownloadProgressCallbackIncremental) { … }
TEST_P(SimpleURLLoaderTest, RetryOn5xx) { … }
TEST_P(SimpleURLLoaderTest, RetryOnNameNotResolved) { … }
TEST_P(SimpleURLLoaderTest, NoRetryOn4xx) { … }
TEST_P(SimpleURLLoaderTest, RetryAfterRedirect) { … }
TEST_P(SimpleURLLoaderTest, RetryOnNetworkChange) { … }
TEST_P(SimpleURLLoaderTest, RetryWithUnboundFactory) { … }
TEST_P(SimpleURLLoaderTest, UploadLongStringStartReadTwice) { … }
TEST_P(SimpleURLLoaderTest,
UploadLongStringReadPartOfUploadBodyBeforeRestartBodyRead) { … }
TEST_P(SimpleURLLoaderTest, GetFinalURL) { … }
TEST_P(SimpleURLLoaderTest, GetFinalURLAfterRedirect) { … }
INSTANTIATE_TEST_SUITE_P(…);
class SimpleURLLoaderFileTest : public SimpleURLLoaderTestBase,
public testing::Test { … };
TEST_F(SimpleURLLoaderFileTest, OverwriteFile) { … }
TEST_F(SimpleURLLoaderFileTest, FileCreateError) { … }
TEST_F(SimpleURLLoaderFileTest, DeleteLoaderDuringRequestDestroysFile) { … }
class SimpleURLLoaderStreamTest : public SimpleURLLoaderTestBase,
public testing::Test { … };
TEST_F(SimpleURLLoaderStreamTest, OnDataReceivedCompletesAsync) { … }
TEST_F(SimpleURLLoaderStreamTest, OnDataReceivedDestruction) { … }
TEST_F(SimpleURLLoaderStreamTest, OnRetryCompletesAsync) { … }
TEST_F(SimpleURLLoaderStreamTest, OnRetryDestruction) { … }
class SimpleURLLoaderMockTimeTest : public testing::Test { … };
TEST_F(SimpleURLLoaderMockTimeTest, TimeoutTriggered) { … }
TEST_F(SimpleURLLoaderMockTimeTest, StreamResumeAfterTimeout) { … }
TEST_F(SimpleURLLoaderMockTimeTest, TimeoutNotTriggered) { … }
TEST_F(SimpleURLLoaderMockTimeTest, TimeNotSetAndTimeAdvanced) { … }
TEST_F(SimpleURLLoaderMockTimeTest, TimeoutAfterRedirectTriggered) { … }
TEST_F(SimpleURLLoaderMockTimeTest, TimeoutAfterRetryNotTriggered) { … }
TEST_F(SimpleURLLoaderMockTimeTest, TimeoutAfterRetryTriggered) { … }
TEST_P(SimpleURLLoaderTest, OnUploadProgressCallback) { … }
TEST_P(SimpleURLLoaderTest, OnDownloadProgressCallback) { … }
TEST_P(SimpleURLLoaderTest, DeleteInOnUploadProgressCallback) { … }
TEST_P(SimpleURLLoaderTest, DeleteInDownloadProgressCallback) { … }
TEST_P(SimpleURLLoaderTest, DeleteInDownloadProgressCallback2) { … }
}
}