chromium/net/websockets/websocket_deflate_stream_test.cc

// Copyright 2013 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/websockets/websocket_deflate_stream.h"

#include <stddef.h>
#include <stdint.h>
#include <string.h>

#include <iterator>
#include <string>
#include <utility>
#include <vector>

#include "base/check.h"
#include "base/containers/circular_deque.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/test/mock_callback.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/log/net_log_with_source.h"
#include "net/test/gtest_util.h"
#include "net/websockets/websocket_deflate_parameters.h"
#include "net/websockets/websocket_deflate_predictor.h"
#include "net/websockets/websocket_deflater.h"
#include "net/websockets/websocket_frame.h"
#include "net/websockets/websocket_stream.h"
#include "net/websockets/websocket_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

IsError;
IsOk;

namespace net {
namespace {

_;
InSequence;
Invoke;
Return;

FrameFlag;
constexpr FrameFlag kNoFlag =;
constexpr FrameFlag kFinal =;
constexpr FrameFlag kReserved1 =;
// We don't define values for other flags because we don't need them.

// The value must equal to the value of the corresponding
// constant in websocket_deflate_stream.cc
constexpr size_t kChunkSize =;
constexpr int kWindowBits =;

std::string ToString(IOBufferWithSize* buffer) {}

std::string ToString(const scoped_refptr<IOBufferWithSize>& buffer) {}

std::string ToString(const WebSocketFrame* frame) {}

std::string ToString(const std::unique_ptr<WebSocketFrame>& frame) {}

class MockWebSocketStream : public WebSocketStream {};

// This mock class relies on some assumptions.
//  - RecordInputDataFrame is called after the corresponding WriteFrames
//    call.
//  - RecordWrittenDataFrame is called before writing the frame.
class WebSocketDeflatePredictorMock : public WebSocketDeflatePredictor {};

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

// Since WebSocketDeflater with DoNotTakeOverContext is well tested at
// websocket_deflater_test.cc, we have only a few tests for this configuration
// here.
class WebSocketDeflateStreamWithDoNotTakeOverContextTest
    : public WebSocketDeflateStreamTest {};

class WebSocketDeflateStreamWithClientWindowBitsTest
    : public WebSocketDeflateStreamTest {};

// ReadFrameStub is a stub for WebSocketStream::ReadFrames.
// It returns |result_| and |frames_to_output_| to the caller and
// saves parameters to |frames_passed_| and |callback_|.
class ReadFramesStub {};

// WriteFramesStub is a stub for WebSocketStream::WriteFrames.
// It returns |result_| and |frames_| to the caller and
// saves |callback| parameter to |callback_|.
class WriteFramesStub {};

TEST_F(WebSocketDeflateStreamTest, ReadFailedImmediately) {}

TEST_F(WebSocketDeflateStreamTest, ReadUncompressedFrameImmediately) {}

TEST_F(WebSocketDeflateStreamTest, ReadUncompressedFrameAsync) {}

TEST_F(WebSocketDeflateStreamTest, ReadFailedAsync) {}

TEST_F(WebSocketDeflateStreamTest, ReadCompressedFrameImmediately) {}

TEST_F(WebSocketDeflateStreamTest, ReadCompressedFrameAsync) {}

TEST_F(WebSocketDeflateStreamTest,
       ReadCompressedFrameFragmentImmediatelyButInflaterReturnsPending) {}

TEST_F(WebSocketDeflateStreamTest, ReadInvalidCompressedPayload) {}

TEST_F(WebSocketDeflateStreamTest, MergeMultipleFramesInReadFrames) {}

TEST_F(WebSocketDeflateStreamTest, ReadUncompressedEmptyFrames) {}

TEST_F(WebSocketDeflateStreamTest, ReadCompressedEmptyFrames) {}

TEST_F(WebSocketDeflateStreamTest,
       ReadCompressedFrameFollowedByEmptyFrame) {}

TEST_F(WebSocketDeflateStreamTest, ReadControlFrameBetweenDataFrames) {}

TEST_F(WebSocketDeflateStreamTest, SplitToMultipleFramesInReadFrames) {}

TEST_F(WebSocketDeflateStreamTest, InflaterInternalDataCanBeEmpty) {}

TEST_F(WebSocketDeflateStreamTest,
       Reserved1TurnsOnDuringReadingCompressedContinuationFrame) {}

TEST_F(WebSocketDeflateStreamTest,
       Reserved1TurnsOnDuringReadingUncompressedContinuationFrame) {}

TEST_F(WebSocketDeflateStreamTest, ReadCompressedMessages) {}

TEST_F(WebSocketDeflateStreamTest, ReadUncompressedMessages) {}

TEST_F(WebSocketDeflateStreamTest,
       ReadCompressedMessageThenUncompressedMessage) {}

TEST_F(WebSocketDeflateStreamTest,
       ReadUncompressedMessageThenCompressedMessage) {}

// This is a regression test for crbug.com/343506.
TEST_F(WebSocketDeflateStreamTest, ReadEmptyAsyncFrame) {}

TEST_F(WebSocketDeflateStreamTest, WriteEmpty) {}

TEST_F(WebSocketDeflateStreamTest, WriteFailedImmediately) {}

TEST_F(WebSocketDeflateStreamTest, WriteFrameImmediately) {}

TEST_F(WebSocketDeflateStreamTest, WriteFrameAsync) {}

TEST_F(WebSocketDeflateStreamTest, WriteControlFrameBetweenDataFrames) {}

TEST_F(WebSocketDeflateStreamTest, WriteEmptyMessage) {}

TEST_F(WebSocketDeflateStreamTest, WriteUncompressedMessage) {}

TEST_F(WebSocketDeflateStreamTest, LargeDeflatedFramesShouldBeSplit) {}

TEST_F(WebSocketDeflateStreamTest, WriteMultipleMessages) {}

TEST_F(WebSocketDeflateStreamWithDoNotTakeOverContextTest,
       WriteMultipleMessages) {}

// In order to check the stream works correctly for multiple
// "PossiblyCompressedMessage"s, we test various messages at one test case.
TEST_F(WebSocketDeflateStreamWithDoNotTakeOverContextTest,
       WritePossiblyCompressMessages) {}

// This is based on the similar test from websocket_deflater_test.cc
TEST_F(WebSocketDeflateStreamWithClientWindowBitsTest, WindowBits8) {}

// The same input with window_bits=10 returns smaller output.
TEST_F(WebSocketDeflateStreamWithClientWindowBitsTest, WindowBits10) {}

}  // namespace

}  // namespace net