chromium/net/http/mock_http_cache.h

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

// This is a mock of the http cache and related testing classes. To be fair, it
// is not really a mock http cache given that it uses the real implementation of
// the http cache, but it has fake implementations of all required components,
// so it is useful for unit tests at the http layer.

#ifndef NET_HTTP_MOCK_HTTP_CACHE_H_
#define NET_HTTP_MOCK_HTTP_CACHE_H_

#include <stdint.h>

#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/strings/string_split.h"
#include "net/base/completion_once_callback.h"
#include "net/base/request_priority.h"
#include "net/disk_cache/disk_cache.h"
#include "net/http/http_cache.h"
#include "net/http/http_transaction_test_util.h"

namespace net {

//-----------------------------------------------------------------------------
// Mock disk cache (a very basic memory cache implementation).

class MockDiskEntry : public disk_cache::Entry,
                      public base::RefCounted<MockDiskEntry> {};

class MockDiskCache : public disk_cache::Backend {};

class MockBackendFactory : public HttpCache::BackendFactory {};

class MockHttpCache {};

// This version of the disk cache doesn't invoke CreateEntry callbacks.
class MockDiskCacheNoCB : public MockDiskCache {};

class MockBackendNoCbFactory : public HttpCache::BackendFactory {};

// This backend factory allows us to control the backend instantiation.
class MockBlockingBackendFactory : public HttpCache::BackendFactory {};

struct GetBackendResultIsPendingHelper {};
using TestGetBackendCompletionCallbackBase =
    net::internal::TestCompletionCallbackTemplate<
        HttpCache::GetBackendResult,
        GetBackendResultIsPendingHelper>;

class TestGetBackendCompletionCallback
    : public TestGetBackendCompletionCallbackBase {};

}  // namespace net

#endif  // NET_HTTP_MOCK_HTTP_CACHE_H_