#include "net/http/http_response_headers.h"
#include <stdint.h>
#include <iostream>
#include <memory>
#include <optional>
#include <string_view>
#include <unordered_set>
#include "base/pickle.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/values.h"
#include "net/base/cronet_buildflags.h"
#include "net/base/tracing.h"
#include "net/http/http_byte_range.h"
#include "net/http/http_response_headers_test_util.h"
#include "net/http/http_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#if !BUILDFLAG(CRONET_BUILD)
#include "third_party/perfetto/include/perfetto/test/traced_value_test_support.h"
#endif
namespace net {
namespace {
struct TestData { … };
class HttpResponseHeadersTest : public testing::Test { … };
void HeadersToRaw(std::string* headers) { … }
class HttpResponseHeadersCacheControlTest : public HttpResponseHeadersTest { … };
class CommonHttpResponseHeadersTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<TestData> { … };
constexpr auto ToSimpleString = …;
void EscapeForPrinting(std::string* s) { … }
TEST_P(CommonHttpResponseHeadersTest, TestCommon) { … }
TestData response_headers_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct PersistData { … };
class PersistenceTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<PersistData> { … };
TEST_P(PersistenceTest, Persist) { … }
const struct PersistData persistence_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
TEST(HttpResponseHeadersTest, EnumerateHeader_Coalesced) { … }
TEST(HttpResponseHeadersTest, EnumerateHeader_Challenge) { … }
TEST(HttpResponseHeadersTest, EnumerateHeader_DateValued) { … }
TEST(HttpResponseHeadersTest, DefaultDateToGMT) { … }
TEST(HttpResponseHeadersTest, GetAgeValue10) { … }
TEST(HttpResponseHeadersTest, GetAgeValue0) { … }
TEST(HttpResponseHeadersTest, GetAgeValueBogus) { … }
TEST(HttpResponseHeadersTest, GetAgeValueNegative) { … }
TEST(HttpResponseHeadersTest, GetAgeValueLeadingPlus) { … }
TEST(HttpResponseHeadersTest, GetAgeValueOverflow) { … }
struct ContentTypeTestData { … };
class ContentTypeTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<ContentTypeTestData> { … };
TEST_P(ContentTypeTest, GetMimeType) { … }
const ContentTypeTestData mimetype_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct RequiresValidationTestData { … };
class RequiresValidationTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<RequiresValidationTestData> { … };
TEST_P(RequiresValidationTest, RequiresValidation) { … }
const struct RequiresValidationTestData requires_validation_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct UpdateTestData { … };
class UpdateTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<UpdateTestData> { … };
TEST_P(UpdateTest, Update) { … }
const UpdateTestData update_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct EnumerateHeaderTestData { … };
class EnumerateHeaderLinesTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<EnumerateHeaderTestData> { … };
TEST_P(EnumerateHeaderLinesTest, EnumerateHeaderLines) { … }
const EnumerateHeaderTestData enumerate_header_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct IsRedirectTestData { … };
class IsRedirectTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<IsRedirectTestData> { … };
TEST_P(IsRedirectTest, IsRedirect) { … }
const IsRedirectTestData is_redirect_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct ContentLengthTestData { … };
class GetContentLengthTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<ContentLengthTestData> { … };
TEST_P(GetContentLengthTest, GetContentLength) { … }
const ContentLengthTestData content_length_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct ContentRangeTestData { … };
class ContentRangeTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<ContentRangeTestData> { … };
TEST_P(ContentRangeTest, GetContentRangeFor206) { … }
const ContentRangeTestData content_range_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct KeepAliveTestData { … };
void PrintTo(const KeepAliveTestData& keep_alive_test_data,
std::ostream* os) { … }
class IsKeepAliveTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<KeepAliveTestData> { … };
TEST_P(IsKeepAliveTest, IsKeepAlive) { … }
const KeepAliveTestData keepalive_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct HasStrongValidatorsTestData { … };
class HasStrongValidatorsTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<HasStrongValidatorsTestData> { … };
TEST_P(HasStrongValidatorsTest, HasStrongValidators) { … }
const HasStrongValidatorsTestData strong_validators_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
TEST(HttpResponseHeadersTest, HasValidatorsNone) { … }
TEST(HttpResponseHeadersTest, HasValidatorsEtag) { … }
TEST(HttpResponseHeadersTest, HasValidatorsLastModified) { … }
TEST(HttpResponseHeadersTest, HasValidatorsWeakEtag) { … }
TEST(HttpResponseHeadersTest, GetNormalizedHeaderWithEmptyValues) { … }
TEST(HttpResponseHeadersTest, GetNormalizedHeaderWithCommas) { … }
TEST(HttpResponseHeadersTest, AddHeader) { … }
TEST(HttpResponseHeadersTest, SetHeader) { … }
TEST(HttpResponseHeadersTest, TryToCreateWithNul) { … }
#if !BUILDFLAG(CRONET_BUILD)
TEST(HttpResponseHeadersTest, TracingSupport) { … }
#endif
struct RemoveHeaderTestData { … };
class RemoveHeaderTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<RemoveHeaderTestData> { … };
TEST_P(RemoveHeaderTest, RemoveHeader) { … }
const RemoveHeaderTestData remove_header_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct RemoveHeadersTestData { … };
class RemoveHeadersTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<RemoveHeadersTestData> { … };
TEST_P(RemoveHeadersTest, RemoveHeaders) { … }
const RemoveHeadersTestData remove_headers_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct RemoveIndividualHeaderTestData { … };
class RemoveIndividualHeaderTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<RemoveIndividualHeaderTestData> { … };
TEST_P(RemoveIndividualHeaderTest, RemoveIndividualHeader) { … }
const RemoveIndividualHeaderTestData remove_individual_header_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct ReplaceStatusTestData { … };
class ReplaceStatusTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<ReplaceStatusTestData> { … };
TEST_P(ReplaceStatusTest, ReplaceStatus) { … }
const ReplaceStatusTestData replace_status_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct UpdateWithNewRangeTestData { … };
class UpdateWithNewRangeTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<UpdateWithNewRangeTestData> { … };
TEST_P(UpdateWithNewRangeTest, UpdateWithNewRange) { … }
const UpdateWithNewRangeTestData update_range_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(HttpResponseHeadersCacheControlTest, AbsentMaxAgeReturnsFalse) { … }
TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeWithNoParameterRejected) { … }
TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeWithSpaceParameterRejected) { … }
TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeWithInterimSpaceIsRejected) { … }
TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeWithMinusSignIsRejected) { … }
TEST_F(HttpResponseHeadersCacheControlTest,
MaxAgeWithSpaceBeforeEqualsIsRejected) { … }
TEST_F(HttpResponseHeadersCacheControlTest,
MaxAgeWithLeadingandTrailingSpaces) { … }
TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeFirstMatchUsed) { … }
TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeBogusFirstMatchUsed) { … }
TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeCaseInsensitive) { … }
TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeOverflow) { … }
struct MaxAgeTestData { … };
class MaxAgeEdgeCasesTest
: public HttpResponseHeadersCacheControlTest,
public ::testing::WithParamInterface<MaxAgeTestData> { … };
TEST_P(MaxAgeEdgeCasesTest, MaxAgeEdgeCases) { … }
const MaxAgeTestData max_age_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(HttpResponseHeadersCacheControlTest,
AbsentStaleWhileRevalidateReturnsFalse) { … }
TEST_F(HttpResponseHeadersCacheControlTest,
StaleWhileRevalidateWithoutValueRejected) { … }
TEST_F(HttpResponseHeadersCacheControlTest,
StaleWhileRevalidateWithInvalidValueIgnored) { … }
TEST_F(HttpResponseHeadersCacheControlTest, StaleWhileRevalidateValueReturned) { … }
TEST_F(HttpResponseHeadersCacheControlTest,
FirstStaleWhileRevalidateValueUsed) { … }
struct GetCurrentAgeTestData { … };
class GetCurrentAgeTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<GetCurrentAgeTestData> { … };
TEST_P(GetCurrentAgeTest, GetCurrentAge) { … }
const struct GetCurrentAgeTestData get_current_age_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
TEST(HttpResponseHeadersBuilderTest, Version) { … }
struct BuilderStatusLineTestData { … };
void PrintTo(const BuilderStatusLineTestData& data, std::ostream* os) { … }
class BuilderStatusLineTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<BuilderStatusLineTestData> { … };
TEST_P(BuilderStatusLineTest, Common) { … }
constexpr BuilderStatusLineTestData kBuilderStatusLineTests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
struct BuilderHeadersTestData { … };
void PrintTo(const BuilderHeadersTestData& data, std::ostream* os) { … }
class BuilderHeadersTest
: public HttpResponseHeadersTest,
public ::testing::WithParamInterface<BuilderHeadersTestData> { … };
TEST_P(BuilderHeadersTest, Common) { … }
const BuilderHeadersTestData builder_headers_tests[] = …;
INSTANTIATE_TEST_SUITE_P(…);
TEST(HttpResponseHeadersTest, StrictlyEqualsSuccess) { … }
TEST(HttpResponseHeadersTest, StrictlyEqualsVersionMismatch) { … }
TEST(HttpResponseHeadersTest, StrictlyEqualsResponseCodeMismatch) { … }
TEST(HttpResponseHeadersTest, StrictlyEqualsStatusTextMismatch) { … }
TEST(HttpResponseHeadersTest, StrictlyEqualsRawMismatch) { … }
}
}