chromium/third_party/blink/renderer/modules/webtransport/web_transport_test.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/modules/webtransport/web_transport.h"

#include <array>
#include <memory>
#include <optional>
#include <utility>

#include "base/containers/span.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/test/mock_callback.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "services/network/public/mojom/web_transport.mojom-blink.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/webtransport/web_transport_connector.mojom-blink.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/bindings/core/v8/iterable.h"
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_tester.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/to_v8_traits.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_exception.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_gc_controller.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_readable_stream.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_arraybuffer_arraybufferview.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_writable_stream.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_web_transport_bidirectional_stream.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_web_transport_close_info.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_web_transport_error.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_web_transport_hash.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_web_transport_options.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/streams/readable_stream.h"
#include "third_party/blink/renderer/core/streams/readable_stream_byob_reader.h"
#include "third_party/blink/renderer/core/streams/readable_stream_default_reader.h"
#include "third_party/blink/renderer/core/streams/writable_stream.h"
#include "third_party/blink/renderer/core/streams/writable_stream_default_writer.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/modules/webtransport/bidirectional_stream.h"
#include "third_party/blink/renderer/modules/webtransport/datagram_duplex_stream.h"
#include "third_party/blink/renderer/modules/webtransport/receive_stream.h"
#include "third_party/blink/renderer/modules/webtransport/send_stream.h"
#include "third_party/blink/renderer/modules/webtransport/test_utils.h"
#include "third_party/blink/renderer/modules/webtransport/web_transport_error.h"
#include "third_party/blink/renderer/platform/bindings/exception_code.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/wtf/deque.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "v8/include/v8.h"

namespace blink {

namespace {

_;
ElementsAre;
Invoke;
Mock;
StrictMock;
Truly;
Unused;

class WebTransportConnector final : public mojom::blink::WebTransportConnector {};

class MockWebTransport : public network::mojom::blink::WebTransport {};

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

TEST_F(WebTransportTest, FailWithNullURL) {}

TEST_F(WebTransportTest, FailWithEmptyURL) {}

TEST_F(WebTransportTest, FailWithNoScheme) {}

TEST_F(WebTransportTest, FailWithHttpsURL) {}

TEST_F(WebTransportTest, FailWithNoHost) {}

TEST_F(WebTransportTest, FailWithURLFragment) {}

TEST_F(WebTransportTest, FailByCSP) {}

TEST_F(WebTransportTest, PassCSP) {}

TEST_F(WebTransportTest, SendConnect) {}

TEST_F(WebTransportTest, SuccessfulConnect) {}

TEST_F(WebTransportTest, FailedConnect) {}

TEST_F(WebTransportTest, SendConnectWithFingerprint) {}

TEST_F(WebTransportTest, SendConnectWithArrayBufferHash) {}

TEST_F(WebTransportTest, SendConnectWithOffsetArrayBufferViewHash) {}

// Regression test for https://crbug.com/1242185.
TEST_F(WebTransportTest, SendConnectWithInvalidFingerprint) {}

TEST_F(WebTransportTest, CloseDuringConnect) {}

TEST_F(WebTransportTest, CloseAfterConnection) {}

TEST_F(WebTransportTest, CloseWithNull) {}

TEST_F(WebTransportTest, CloseWithReasonOnly) {}

// A live connection will be kept alive even if there is no explicit reference.
// When the underlying connection is shut down, the connection will be swept.
TEST_F(WebTransportTest, GarbageCollection) {}

TEST_F(WebTransportTest, GarbageCollectMojoConnectionError) {}

TEST_F(WebTransportTest, SendDatagram) {}

// TODO(yhirano): Move this to datagram_duplex_stream_test.cc.
TEST_F(WebTransportTest, BackpressureForOutgoingDatagrams) {}

TEST_F(WebTransportTest, SendDatagramBeforeConnect) {}

TEST_F(WebTransportTest, SendDatagramAfterClose) {}

Vector<uint8_t> GetValueAsVector(ScriptState* script_state,
                                 ScriptValue iterator_result) {}

TEST_F(WebTransportTest, ReceiveDatagramBeforeRead) {}

TEST_F(WebTransportTest, ReceiveDatagramDuringRead) {}

TEST_F(WebTransportTest, ReceiveDatagramWithBYOBReader) {}

bool IsRangeError(ScriptState* script_state,
                  ScriptValue value,
                  const String& message) {}

TEST_F(WebTransportTest, ReceiveDatagramWithoutEnoughBuffer) {}

TEST_F(WebTransportTest, CancelDatagramReadableWorks) {}

TEST_F(WebTransportTest, DatagramsShouldBeErroredAfterClose) {}

TEST_F(WebTransportTest, ResettingIncomingHighWaterMarkWorksAfterClose) {}

TEST_F(WebTransportTest, TransportErrorErrorsReadableStream) {}

TEST_F(WebTransportTest, DatagramsAreDropped) {}

TEST_F(WebTransportTest, IncomingHighWaterMarkIsObeyed) {}

TEST_F(WebTransportTest, ResettingHighWaterMarkClearsQueue) {}

TEST_F(WebTransportTest, ReadIncomingDatagramWorksWithHighWaterMarkZero) {}

// We only do an extremely basic test for incomingMaxAge as overriding
// base::TimeTicks::Now() doesn't work well in Blink and passing in a mock clock
// would add a lot of complexity for little benefit.
TEST_F(WebTransportTest, IncomingMaxAgeIsObeyed) {}

// This is a regression test for https://crbug.com/1246335
TEST_F(WebTransportTest, TwoSimultaneousReadsWork) {}

bool ValidProducerHandle(const mojo::ScopedDataPipeProducerHandle& handle) {}

bool ValidConsumerHandle(const mojo::ScopedDataPipeConsumerHandle& handle) {}

TEST_F(WebTransportTest, CreateSendStream) {}

TEST_F(WebTransportTest, CreateSendStreamBeforeConnect) {}

TEST_F(WebTransportTest, CreateSendStreamFailure) {}

// Every active stream is kept alive by the WebTransport object.
TEST_F(WebTransportTest, SendStreamGarbageCollection) {}

// A live stream will be kept alive even if there is no explicit reference.
// When the underlying connection is shut down, the connection will be swept.
TEST_F(WebTransportTest, SendStreamGarbageCollectionLocalClose) {}

TEST_F(WebTransportTest, SendStreamGarbageCollectionRemoteClose) {}

// A live stream will be kept alive even if there is no explicit reference.
// When the underlying connection is shut down, the connection will be swept.
TEST_F(WebTransportTest, ReceiveStreamGarbageCollectionCancel) {}

TEST_F(WebTransportTest, ReceiveStreamGarbageCollectionRemoteClose) {}

// This is the same test as ReceiveStreamGarbageCollectionRemoteClose, except
// that the order of the data pipe being reset and the OnIncomingStreamClosed
// message is reversed. It is important that the object is not collected until
// both events have happened.
TEST_F(WebTransportTest, ReceiveStreamGarbageCollectionRemoteCloseReverse) {}

TEST_F(WebTransportTest, CreateSendStreamAbortedByClose) {}

// ReceiveStream functionality is thoroughly tested in incoming_stream_test.cc.
// This test just verifies that the creation is done correctly.
TEST_F(WebTransportTest, CreateReceiveStream) {}

TEST_F(WebTransportTest, CreateReceiveStreamThenClose) {}

TEST_F(WebTransportTest, CreateReceiveStreamThenRemoteClose) {}

// BidirectionalStreams are thoroughly tested in bidirectional_stream_test.cc.
// Here we just test the WebTransport APIs.
TEST_F(WebTransportTest, CreateBidirectionalStream) {}

TEST_F(WebTransportTest, ReceiveBidirectionalStream) {}

TEST_F(WebTransportTest, SetDatagramWritableQueueExpirationDuration) {}

// Regression test for https://crbug.com/1241489.
TEST_F(WebTransportTest, SetOutgoingMaxAgeBeforeConnectComplete) {}

TEST_F(WebTransportTest, OnClosed) {}

// Regression test for https://crbug.com/347710668.
TEST_F(WebTransportTest, ClosedAccessorCalledAfterOnClosed) {}

TEST_F(WebTransportTest, OnClosedWithNull) {}

TEST_F(WebTransportTest, ReceivedResetStream) {}

TEST_F(WebTransportTest, ReceivedStopSending) {}

}  // namespace

}  // namespace blink