chromium/components/cronet/native/test/url_request_test.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <atomic>
#include <memory>
#include <tuple>

#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/task_environment.h"
#include "components/cronet/native/test/test_request_finished_info_listener.h"
#include "components/cronet/native/test/test_upload_data_provider.h"
#include "components/cronet/native/test/test_url_request_callback.h"
#include "components/cronet/native/test/test_util.h"
#include "components/cronet/testing/test_server/test_server.h"
#include "cronet_c.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

TestRequestFinishedInfoListener;
TestUploadDataProvider;
TestUrlRequestCallback;
HasSubstr;

namespace {

// A Cronet_UrlRequestStatusListener impl that waits for OnStatus callback.
class StatusListener {};

// Query and return status of |request|. |callback| is verified to not yet have
// reached a final state by the time OnStatus is called.
Cronet_UrlRequestStatusListener_Status GetRequestStatus(
    Cronet_UrlRequestPtr request,
    TestUrlRequestCallback* callback) {}

enum class RequestFinishedListenerType {};

// Converts a Cronet_DateTimePtr into the int64 number of milliseconds since
// the UNIX epoch.
//
// Returns -1 if |date_time| is nullptr.
int64_t DateToMillis(Cronet_DateTimePtr date_time) {}

// Verification check that the date isn't wildly off, somehow (perhaps due to
// read of used memory, wild pointer, etc.).
//
// Interpreted as milliseconds after the UNIX timestamp, this timestamp occurs
// at 37,648 C.E.
constexpr int64_t kDateOverrunThreshold =;

// Basic verification checking of all Cronet_Metrics fields. For optional
// fields, we allow the field to be non-present. Start/end pairs should be
// monotonic (end not less than start).
//
// Ordering of events is also checked.
void VerifyRequestMetrics(Cronet_MetricsPtr metrics) {}

// Convert a TestUrlRequestCallback::ResponseStep into the equivalent
// RequestFinishedInfo.FINISHED_REASON.
Cronet_RequestFinishedInfo_FINISHED_REASON MapFinishedReason(
    TestUrlRequestCallback::ResponseStep response_step) {}

// Basic verification checking of all Cronet_RequestFinishedInfo,
// Cronet_UrlResponseInfoPtr, and Cronet_ErrorPtr fields passed to
// RequestFinishedInfoListener.OnRequestFinished().
//
// All fields are checked except for |annotations|.
//
// |test_request_finished_info_listener| Test listener -- will verify all fields
//     of this listener.
// |callback| Callback associated with the UrlRequest associated with
//     |request_info|.
void VerifyRequestFinishedInfoListener(
    TestRequestFinishedInfoListener* test_request_finished_info_listener,
    const TestUrlRequestCallback& callback) {}

// Parameterized off whether to use a direct executor, and whether (if so, how)
// to add a RequestFinishedInfoListener.
class UrlRequestTest : public ::testing::TestWithParam<
                           std::tuple<bool, RequestFinishedListenerType>> {};

const bool kDirectExecutorEnabled[]{};
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

TEST_P(UrlRequestTest, InitChecks) {}

TEST_P(UrlRequestTest, SimpleGet) {}

TEST_P(UrlRequestTest, UploadEmptyBodySync) {}

TEST_P(UrlRequestTest, UploadSync) {}

TEST_P(UrlRequestTest, SSLCertificateError) {}

TEST_P(UrlRequestTest, SSLUpload) {}

TEST_P(UrlRequestTest, UploadMultiplePiecesSync) {}

TEST_P(UrlRequestTest, UploadMultiplePiecesAsync) {}

TEST_P(UrlRequestTest, UploadChangesDefaultMethod) {}

TEST_P(UrlRequestTest, UploadWithSetMethod) {}

TEST_P(UrlRequestTest, UploadWithBigRead) {}

TEST_P(UrlRequestTest, UploadWithDirectExecutor) {}

TEST_P(UrlRequestTest, UploadRedirectSync) {}

TEST_P(UrlRequestTest, UploadRedirectAsync) {}

TEST_P(UrlRequestTest, UploadWithBadLength) {}

TEST_P(UrlRequestTest, UploadWithBadLengthBufferAligned) {}

TEST_P(UrlRequestTest, UploadReadFailSync) {}

TEST_P(UrlRequestTest, UploadReadFailAsync) {}

TEST_P(UrlRequestTest, UploadRewindFailSync) {}

TEST_P(UrlRequestTest, UploadRewindFailAsync) {}

TEST_P(UrlRequestTest, UploadChunked) {}

TEST_P(UrlRequestTest, UploadChunkedLastReadZeroLengthBody) {}

// Test where an upload fails without ever initializing the
// UploadDataStream, because it can't connect to the server.
TEST_P(UrlRequestTest, UploadFailsWithoutInitializingStream) {}

// TODO(crbug.com/41453771): Flakes in AssertClosed().
TEST_P(UrlRequestTest, DISABLED_UploadCancelReadSync) {}

TEST_P(UrlRequestTest, UploadCancelReadAsync) {}

// TODO(crbug.com/41453771): Flakes in AssertClosed().
TEST_P(UrlRequestTest, DISABLED_UploadCancelRewindSync) {}

TEST_P(UrlRequestTest, UploadCancelRewindAsync) {}

TEST_P(UrlRequestTest, SimpleRequest) {}

TEST_P(UrlRequestTest, ReceiveBackAnnotations) {}

TEST_P(UrlRequestTest, UrlParamsAnnotationsUnchanged) {}

TEST_P(UrlRequestTest, MultiRedirect) {}

TEST_P(UrlRequestTest, CancelRequest) {}

TEST_P(UrlRequestTest, FailedRequestHostNotFound) {}

void UrlRequestTest::TestCancel(
    TestUrlRequestCallback::FailureType failure_type,
    TestUrlRequestCallback::ResponseStep failure_step,
    bool expect_response_info,
    bool expect_error) {}

TEST_P(UrlRequestTest, TestCancel) {}

TEST_P(UrlRequestTest, PerfTest) {}

TEST_P(UrlRequestTest, GetStatus) {}

class UrlRequestTestNoParam : public ::testing::Test {};

TEST_F(UrlRequestTestNoParam,
       RequestFinishedListenerWithoutExecutorReturnsError) {}

TEST_F(UrlRequestTestNoParam,
       UseRequestFinishedInfoAfterUrlRequestDestructionSuccess) {}

TEST_F(UrlRequestTestNoParam,
       UseRequestFinishedInfoAfterUrlRequestDestructionFailure) {}

TEST_F(UrlRequestTestNoParam,
       CorrelateCallbackAndRequestInfoWithoutSynchronization) {}

}  // namespace