chromium/third_party/blink/renderer/modules/websockets/websocket_channel_impl_test.cc

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

#include "third_party/blink/renderer/modules/websockets/websocket_channel_impl.h"

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

#include <memory>

#include "base/containers/span.h"
#include "base/functional/callback.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote_set.h"
#include "net/storage_access_api/status.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/websockets/websocket_connector.mojom-blink.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/web_url.h"
#include "third_party/blink/public/platform/websocket_handshake_throttle.h"
#include "third_party/blink/renderer/bindings/core/v8/capture_source_location.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/loader/empty_clients.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/modules/websockets/websocket_channel.h"
#include "third_party/blink/renderer/modules/websockets/websocket_channel_client.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "third_party/blink/renderer/platform/wtf/wtf_size_t.h"

_;
AnyNumber;
InSequence;
PrintToString;
SaveArg;
StrictMock;
Unused;

namespace blink {

Checkpoint;

class MockWebSocketChannelClient
    : public GarbageCollected<MockWebSocketChannelClient>,
      public WebSocketChannelClient {};

class MockWebSocketHandshakeThrottle : public WebSocketHandshakeThrottle {};

// The base class sets up the page.
class WebSocketChannelImplTestBase : public PageTestBase {};

class WebSocketChannelImplTest : public WebSocketChannelImplTestBase {};

class CallTrackingClosure {};

std::ostream& operator<<(
    std::ostream& o,
    const WebSocketChannelImplTest::TestWebSocket::DataFrame& f) {}

TEST_F(WebSocketChannelImplTest, ConnectSuccess) {}

TEST_F(WebSocketChannelImplTest, MojoConnectionErrorDuringHandshake) {}

TEST_F(WebSocketChannelImplTest, SendText) {}

TEST_F(WebSocketChannelImplTest, SendBinaryInVector) {}

TEST_F(WebSocketChannelImplTest, SendBinaryInArrayBufferPartial) {}

TEST_F(WebSocketChannelImplTest, SendBinaryInArrayBufferWithNullBytes) {}

TEST_F(WebSocketChannelImplTest, SendBinaryInArrayBufferNonLatin1UTF8) {}

TEST_F(WebSocketChannelImplTest, SendBinaryInArrayBufferNonUTF8) {}

TEST_F(WebSocketChannelImplTest, SendTextSync) {}

TEST_F(WebSocketChannelImplTest, SendTextAsyncDueToQueueing) {}

TEST_F(WebSocketChannelImplTest, SendTextAsyncDueToMessageSize) {}

TEST_F(WebSocketChannelImplTest, SendBinaryInArrayBufferSync) {}

TEST_F(WebSocketChannelImplTest, SendBinaryInArrayBufferAsyncDueToQueueing) {}

TEST_F(WebSocketChannelImplTest, SendBinaryInArrayBufferAsyncDueToMessageSize) {}

// FIXME: Add tests for WebSocketChannel::send(scoped_refptr<BlobDataHandle>)

TEST_F(WebSocketChannelImplTest, ReceiveText) {}

TEST_F(WebSocketChannelImplTest, ReceiveTextContinuation) {}

TEST_F(WebSocketChannelImplTest, ReceiveTextNonLatin1) {}

TEST_F(WebSocketChannelImplTest, ReceiveTextNonLatin1Continuation) {}

TEST_F(WebSocketChannelImplTest, ReceiveBinary) {}

TEST_F(WebSocketChannelImplTest, ReceiveBinaryContinuation) {}

TEST_F(WebSocketChannelImplTest, ReceiveBinaryWithNullBytes) {}

TEST_F(WebSocketChannelImplTest, ReceiveBinaryNonLatin1UTF8) {}

TEST_F(WebSocketChannelImplTest, ReceiveBinaryNonLatin1UTF8Continuation) {}

TEST_F(WebSocketChannelImplTest, ReceiveBinaryNonUTF8) {}

TEST_F(WebSocketChannelImplTest, ReceiveWithExplicitBackpressure) {}

TEST_F(WebSocketChannelImplTest,
       ReceiveMultipleMessagesWithSmallDataPipeWrites) {}

TEST_F(WebSocketChannelImplTest, ConnectionCloseInitiatedByServer) {}

TEST_F(WebSocketChannelImplTest, ConnectionCloseInitiatedByClient) {}

TEST_F(WebSocketChannelImplTest, MojoConnectionError) {}

TEST_F(WebSocketChannelImplTest, FailFromClient) {}

class WebSocketChannelImplHandshakeThrottleTest
    : public WebSocketChannelImplTest {};

TEST_F(WebSocketChannelImplHandshakeThrottleTest, ThrottleSucceedsFirst) {}

TEST_F(WebSocketChannelImplHandshakeThrottleTest, HandshakeSucceedsFirst) {}

// This happens if JS code calls close() during the handshake.
TEST_F(WebSocketChannelImplHandshakeThrottleTest, FailDuringThrottle) {}

// It makes no difference to the behaviour if the WebSocketHandle has actually
// connected.
TEST_F(WebSocketChannelImplHandshakeThrottleTest,
       FailDuringThrottleAfterConnect) {}

TEST_F(WebSocketChannelImplHandshakeThrottleTest, DisconnectDuringThrottle) {}

TEST_F(WebSocketChannelImplHandshakeThrottleTest,
       DisconnectDuringThrottleAfterConnect) {}

TEST_F(WebSocketChannelImplHandshakeThrottleTest,
       ThrottleReportsErrorBeforeConnect) {}

TEST_F(WebSocketChannelImplHandshakeThrottleTest,
       ThrottleReportsErrorAfterConnect) {}

TEST_F(WebSocketChannelImplHandshakeThrottleTest, ConnectFailBeforeThrottle) {}

TEST_F(WebSocketChannelImplTest, RemoteConnectionCloseDuringSend) {}

class MockWebSocketConnector : public mojom::blink::WebSocketConnector {};

// This can't use WebSocketChannelImplTest because it requires multiple
// WebSocketChannels to be connected.
class WebSocketChannelImplMultipleTest : public WebSocketChannelImplTestBase {};

TEST_F(WebSocketChannelImplMultipleTest, ConnectionLimit) {}

}  // namespace blink