chromium/net/shared_dictionary/shared_dictionary_network_transaction_unittest.cc

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

#include "net/shared_dictionary/shared_dictionary_network_transaction.h"

#include <memory>
#include <optional>

#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/scoped_refptr.h"
#include "base/notreached.h"
#include "base/test/scoped_feature_list.h"
#include "crypto/secure_hash.h"
#include "net/base/features.h"
#include "net/base/hash_value.h"
#include "net/base/io_buffer.h"
#include "net/base/test_completion_callback.h"
#include "net/cert/x509_certificate.h"
#include "net/http/http_transaction.h"
#include "net/http/http_transaction_test_util.h"
#include "net/log/net_log_with_source.h"
#include "net/shared_dictionary/shared_dictionary.h"
#include "net/shared_dictionary/shared_dictionary_constants.h"
#include "net/ssl/ssl_private_key.h"
#include "net/test/gtest_util.h"
#include "net/test/test_with_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace net {

namespace {

const std::string kTestDictionaryData =;
// The hex of sha256 of `kTestDictionaryData`.
const std::string kTestDictionarySha256 =;
// The Structured Field sf-binary hash of sha256 of `kTestDictionaryData`.
const std::string kTestDictionarySha256Base64 =;
const std::string kTestData =;
// The brotli encoded data of `kTestData` using `kTestDictionaryData` as a
// dictionary.
// kBrotliEncodedData is generated using the following commands:
// $ echo -n "HelloHallo你好こんにちは" > /tmp/dict
// $ echo -n "HelloこんにちはHallo你好HelloこんにちはHallo你好" > /tmp/data
// $ echo -en '\xffDCB' > /tmp/out.dcb
// $ openssl dgst -sha256 -binary /tmp/dict >> /tmp/out.dcb
// $ brotli --stdout -D /tmp/dict /tmp/data >> /tmp/out.dcb
// $ xxd -i /tmp/out.dcb
const uint8_t kBrotliEncodedData[] =;
const std::string kBrotliEncodedDataString =;

// The zstd encoded data of `kTestData` using `kTestDictionaryData` as a
// dictionary.
// kZstdEncodedData is generated using the following commands:
// $ echo -n "HelloHallo你好こんにちは" > /tmp/dict
// $ echo -n "HelloこんにちはHallo你好HelloこんにちはHallo你好" > /tmp/data
// $ echo -en '\x5e\x2a\x4d\x18\x20\x00\x00\x00' > /tmp/out.dcz
// $ openssl dgst -sha256 -binary /tmp/dict >> /tmp/out.dcz
// $ zstd -D /tmp/dict -f -o /tmp/tmp.zstd /tmp/data
// $ cat /tmp/tmp.zstd >> /tmp/out.dcz
// $ xxd -i /tmp/out.dcz
const uint8_t kZstdEncodedData[] =;
const std::string kZstdEncodedDataString =;

const size_t kDefaultBufferSize =;

class DummySyncDictionary : public SharedDictionary {};

class DummyAsyncDictionary : public DummySyncDictionary {};

TransportInfo TestSpdyTransportInfo() {}

static void BrotliTestTransactionHandler(const HttpRequestInfo* request,
                                         std::string* response_status,
                                         std::string* response_headers,
                                         std::string* response_data) {}

static void ZstdTestTransactionHandler(const HttpRequestInfo* request,
                                       std::string* response_status,
                                       std::string* response_headers,
                                       std::string* response_data) {}

static const auto kTestTransactionHandlerWithoutAvailableDictionary =;

constexpr char kTestUrl[] =;

const MockTransaction kBrotliDictionaryTestTransaction =;

const MockTransaction kZstdDictionaryTestTransaction =;

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

TEST_F(SharedDictionaryNetworkTransactionTest, SyncDictionary) {}

TEST_F(SharedDictionaryNetworkTransactionTest, NotAllowedToUseDictionary) {}

TEST_F(SharedDictionaryNetworkTransactionTest, DictionaryId) {}

TEST_F(SharedDictionaryNetworkTransactionTest,
       DictionaryIdWithBackSlashAndDquote) {}

TEST_F(SharedDictionaryNetworkTransactionTest, EmptyDictionaryId) {}

TEST_F(SharedDictionaryNetworkTransactionTest,
       RequireKnownRootCertCheckFailure) {}

TEST_F(SharedDictionaryNetworkTransactionTest,
       RequireKnownRootCertCheckSuccess) {}

TEST_F(SharedDictionaryNetworkTransactionTest,
       RequireKnownRootCertCheckSuccessForLocalhost) {}

TEST_F(SharedDictionaryNetworkTransactionTest, NoMatchingDictionary) {}

TEST_F(SharedDictionaryNetworkTransactionTest, OpaqueFrameOrigin) {}

TEST_F(SharedDictionaryNetworkTransactionTest, WithoutValidLoadFlag) {}

TEST_F(SharedDictionaryNetworkTransactionTest, NoSbrContentEncoding) {}

TEST_F(SharedDictionaryNetworkTransactionTest, WrongContentDictionaryHeader) {}
TEST_F(SharedDictionaryNetworkTransactionTest, MultipleContentEncodingWithSbr) {}

TEST_F(SharedDictionaryNetworkTransactionTest,
       AsyncDictionarySuccessBeforeStartReading) {}

TEST_F(SharedDictionaryNetworkTransactionTest,
       AsyncDictionarySuccessAfterStartReading) {}

TEST_F(SharedDictionaryNetworkTransactionTest,
       AsyncDictionarySuccessAfterTransactionDestroy) {}

TEST_F(SharedDictionaryNetworkTransactionTest,
       AsyncDictionaryFailureBeforeStartReading) {}

TEST_F(SharedDictionaryNetworkTransactionTest,
       AsyncDictionaryFailureAfterStartReading) {}

TEST_F(SharedDictionaryNetworkTransactionTest, Restart) {}

TEST_F(SharedDictionaryNetworkTransactionTest, StopCaching) {}

TEST_F(SharedDictionaryNetworkTransactionTest, DoneReading) {}

TEST_F(SharedDictionaryNetworkTransactionTest, GetLoadState) {}

TEST_F(SharedDictionaryNetworkTransactionTest, SharedZstd) {}

TEST_F(SharedDictionaryNetworkTransactionTest, NoZstdDContentEncoding) {}

enum class ProtocolCheckProtocolTestCase {};
std::string ToString(ProtocolCheckProtocolTestCase protocol) {}

enum class ProtocolCheckHttp1TestCase {};
std::string ToString(ProtocolCheckHttp1TestCase feature) {}

enum class ProtocolCheckHttp2TestCase {};
std::string ToString(ProtocolCheckHttp2TestCase feature) {}

enum class ProtocolCheckHostTestCase {};
std::string ToString(ProtocolCheckHostTestCase host_type) {}

class SharedDictionaryNetworkTransactionProtocolCheckTest
    : public SharedDictionaryNetworkTransactionTest,
      public testing::WithParamInterface<
          std::tuple<ProtocolCheckHttp1TestCase,
                     ProtocolCheckHttp2TestCase,
                     ProtocolCheckProtocolTestCase,
                     ProtocolCheckHostTestCase>> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(SharedDictionaryNetworkTransactionProtocolCheckTest, Basic) {}

}  // namespace

}  // namespace net