chromium/chrome/test/chromedriver/chrome/devtools_client_impl_unittest.cc

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

#include "chrome/test/chromedriver/chrome/devtools_client_impl.h"

#include <algorithm>
#include <list>
#include <memory>
#include <optional>
#include <queue>
#include <string>
#include <utility>

#include "base/compiler_specific.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/pattern.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/test/chromedriver/chrome/devtools_client.h"
#include "chrome/test/chromedriver/chrome/devtools_event_listener.h"
#include "chrome/test/chromedriver/chrome/status.h"
#include "chrome/test/chromedriver/net/stub_sync_websocket.h"
#include "chrome/test/chromedriver/net/sync_websocket.h"
#include "chrome/test/chromedriver/net/timeout.h"
#include "mojo/public/cpp/bindings/lib/string_serialization.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace {

Eq;
Optional;
Pointee;

const char kTestMapperScript[] =;

template <int Code>
testing::AssertionResult StatusCodeIs(const Status& status) {}

testing::AssertionResult StatusOk(const Status& status) {}

bool ParseCommand(const base::Value::Dict& command,
                  int* cmd_id,
                  std::string* method,
                  base::Value::Dict* params,
                  std::string* session_id) {}

bool ParseMessage(const std::string& message,
                  int* cmd_id,
                  std::string* method,
                  base::Value::Dict* params,
                  std::string* session_id) {}

template <class T>
Status SerializeAsJson(const T& value, std::string* json) {}

Status CreateCdpEvent(std::string method,
                      base::Value::Dict params,
                      std::string session_id,
                      base::Value::Dict* evt) {}

Status CreateCdpResponse(int cmd_id,
                         base::Value::Dict result,
                         std::string session_id,
                         base::Value::Dict* resp) {}

Status CreateBidiCommand(int cmd_id,
                         std::string method,
                         base::Value::Dict params,
                         const std::string* channel,
                         base::Value::Dict* cmd) {}

Status WrapBidiEventInCdpEvent(const base::Value::Dict& bidi_evt,
                               std::string mapper_session_id,
                               base::Value::Dict* evt) {}

Status WrapBidiResponseInCdpEvent(const base::Value::Dict& bidi_resp,
                                  std::string mapper_session_id,
                                  base::Value::Dict* evt) {}

class SyncWebSocketWrapper : public SyncWebSocket {};

template <typename TSocket>
class SocketHolder {};

struct SessionState {};

class MultiSessionMockSyncWebSocket : public SyncWebSocket {};

class DevToolsClientImplTest : public testing::Test {};

}  // namespace

TEST_F(DevToolsClientImplTest, Ctor) {}

TEST_F(DevToolsClientImplTest, SendCommand) {}

TEST_F(DevToolsClientImplTest, SendCommandAndGetResult) {}

TEST_F(DevToolsClientImplTest, SetMainPage) {}

TEST_F(DevToolsClientImplTest, SetTunnelSessionId) {}

TEST_F(DevToolsClientImplTest, ChangeTunnelSessionId) {}

TEST_F(DevToolsClientImplTest, SetNullSocket) {}

TEST_F(DevToolsClientImplTest, AttachToNull) {}

TEST_F(DevToolsClientImplTest, AttachToClientWithNoSocket) {}

TEST_F(DevToolsClientImplTest, AttachToAnotherRoot) {}

TEST_F(DevToolsClientImplTest, AttachRootToRoot) {}

TEST_F(DevToolsClientImplTest, AttachAsGrandChild) {}

namespace {

class MockSyncWebSocket3 : public StubSyncWebSocket {};

}  // namespace

TEST_F(DevToolsClientImplTest, SendCommandSendFails) {}

TEST_F(DevToolsClientImplTest, SendCommandReceiveNextMessageFails) {}

namespace {

class FakeSyncWebSocket : public StubSyncWebSocket {};

bool ReturnCommand(const std::string& message,
                   int expected_id,
                   std::string& session_id,
                   internal::InspectorMessageType& type,
                   InspectorEvent& event,
                   InspectorCommandResponse& command_response) {}

bool ReturnBadResponse(const std::string& message,
                       int expected_id,
                       std::string& session_id,
                       internal::InspectorMessageType& type,
                       InspectorEvent& event,
                       InspectorCommandResponse& command_response) {}

bool ReturnCommandBadId(const std::string& message,
                        int expected_id,
                        std::string& session_id,
                        internal::InspectorMessageType& type,
                        InspectorEvent& event,
                        InspectorCommandResponse& command_response) {}

bool ReturnUnexpectedIdThenResponse(
    bool* first,
    const std::string& message,
    int expected_id,
    std::string& session_id,
    internal::InspectorMessageType& type,
    InspectorEvent& event,
    InspectorCommandResponse& command_response) {}

bool ReturnCommandError(const std::string& message,
                        int expected_id,
                        std::string& session_id,
                        internal::InspectorMessageType& type,
                        InspectorEvent& event,
                        InspectorCommandResponse& command_response) {}

class MockListener : public DevToolsEventListener {};

bool ReturnEventThenResponse(bool* first,
                             const std::string& message,
                             int expected_id,
                             std::string& session_id,
                             internal::InspectorMessageType& type,
                             InspectorEvent& event,
                             InspectorCommandResponse& command_response) {}

bool ReturnEvent(const std::string& message,
                 int expected_id,
                 std::string& session_id,
                 internal::InspectorMessageType& type,
                 InspectorEvent& event,
                 InspectorCommandResponse& command_response) {}

bool ReturnOutOfOrderResponses(int* recurse_count,
                               DevToolsClient* client,
                               const std::string& message,
                               int expected_id,
                               std::string& session_id,
                               internal::InspectorMessageType& type,
                               InspectorEvent& event,
                               InspectorCommandResponse& command_response) {}

bool ReturnError(const std::string& message,
                 int expected_id,
                 std::string& session_id,
                 internal::InspectorMessageType& type,
                 InspectorEvent& event,
                 InspectorCommandResponse& command_response) {}

Status AlwaysTrue(bool* is_met) {}

Status AlwaysFalse(bool* is_met) {}

Status AlwaysError(bool* is_met) {}

}  // namespace

TEST_F(DevToolsClientImplTest, FakeSyncWebSocketSelfTest) {}

TEST_F(DevToolsClientImplTest, SendCommandBadResponse) {}

TEST_F(DevToolsClientImplTest, SendCommandBadId) {}

TEST_F(DevToolsClientImplTest, SendCommandUnexpectedId) {}

TEST_F(DevToolsClientImplTest, SendCommandResponseError) {}

TEST_F(DevToolsClientImplTest, SendCommandEventBeforeResponse) {}

TEST(ParseInspectorMessage, NonJson) {}

TEST(ParseInspectorMessage, NeitherCommandNorEvent) {}

TEST(ParseInspectorMessage, EventNoParams) {}

TEST(ParseInspectorMessage, EventNoParamsWithSessionId) {}

TEST(ParseInspectorMessage, EventWithParams) {}

TEST(ParseInspectorMessage, CommandNoErrorOrResult) {}

TEST(ParseInspectorMessage, CommandError) {}

TEST(ParseInspectorMessage, Command) {}

TEST(ParseInspectorMessage, NoBindingName) {}

TEST(ParseInspectorMessage, UnknownBindingName) {}

TEST(ParseInspectorMessage, BidiMessageNoPayload) {}

TEST(ParseInspectorMessage, BidiMessagePayloadNotADict) {}

TEST(ParseInspectorMessage, TunneledCdpEvent) {}

TEST(ParseInspectorMessage, TunneledCdpEventNoCdpSession) {}

TEST(ParseInspectorMessage, TunneledCdpEventNoCdpParams) {}

TEST(ParseInspectorMessage, TunneledCdpEventNoCdpMethod) {}

TEST(ParseInspectorMessage, TunneledCdpEventNoPayloadParams) {}

TEST(ParseInspectorMessage, TunneledCdpResponse) {}

TEST(ParseInspectorMessage, TunneledCdpResponseNoSession) {}

TEST(ParseInspectorMessage, TunneledCdpResponseNoId) {}

TEST(ParseInspectorMessage, TunneledCdpResponseNoResult) {}

TEST(ParseInspectorMessage, TunneledCdpResponseError) {}

TEST(ParseInspectorError, EmptyError) {}

TEST(ParseInspectorError, InvalidUrlError) {}

TEST(ParseInspectorError, InvalidArgumentCode) {}

TEST(ParseInspectorError, NoTargetWithGivenIdFound) {}

TEST(ParseInspectorError, UnknownError) {}

TEST(ParseInspectorError, CdpNotImplementedError) {}

TEST(ParseInspectorError, NoSuchFrameError) {}

TEST(ParseInspectorError, SessionNotFoundError) {}

TEST(ParseInspectorError, ExecutionContextWasDestroyed) {}

TEST(ParseInspectorError, InspectedTargetNavigatedOrClosed) {}

TEST_F(DevToolsClientImplTest, HandleEventsUntil) {}

TEST_F(DevToolsClientImplTest, HandleEventsUntilTimeout) {}

TEST_F(DevToolsClientImplTest, WaitForNextEventCommand) {}

TEST_F(DevToolsClientImplTest, WaitForNextEventError) {}

TEST_F(DevToolsClientImplTest, WaitForNextEventConditionalFuncReturnsError) {}

TEST_F(DevToolsClientImplTest, NestedCommandsWithOutOfOrderResults) {}

namespace {

class OnConnectedListener : public DevToolsEventListener {};

class OnConnectedSyncWebSocket : public StubSyncWebSocket {};

}  // namespace

TEST_F(DevToolsClientImplTest, ProcessOnConnectedFirstOnCommand) {}

TEST_F(DevToolsClientImplTest, ProcessOnConnectedFirstOnHandleEventsUntil) {}

namespace {

class MockSyncWebSocket5 : public SyncWebSocket {};

class OtherEventListener : public DevToolsEventListener {};

class OnEventListener : public DevToolsEventListener {};

}  // namespace

TEST_F(DevToolsClientImplTest, ProcessOnEventFirst) {}

namespace {

class MockSyncWebSocket6 : public StubSyncWebSocket {};

class MockDevToolsEventListener : public DevToolsEventListener {};

std::string JavaScriptDialogOpeningEvent(const std::string& message,
                                         const std::string& type,
                                         const std::string& default_prompt) {}

std::string JavaScriptDialogClosedEvent(bool result,
                                        const std::string& user_input) {}

}  // namespace

TEST_F(DevToolsClientImplTest, BlockedByAlert) {}

TEST_F(DevToolsClientImplTest, CorrectlyDeterminesWhichIsBlockedByAlert) {}

TEST_F(DevToolsClientImplTest, AutoAcceptsBeforeunloadInheritance) {}

TEST_F(DevToolsClientImplTest, NoDialog) {}

TEST_F(DevToolsClientImplTest, HandleDialogPassesParams) {}

TEST_F(DevToolsClientImplTest, HandleDialogNullPrompt) {}

TEST_F(DevToolsClientImplTest, OneDialog) {}

TEST_F(DevToolsClientImplTest, TwoDialogs) {}

TEST_F(DevToolsClientImplTest, OneDialogManualClose) {}

TEST_F(DevToolsClientImplTest, BeforeunloadIsNotAutoAccepted) {}

TEST_F(DevToolsClientImplTest, BeforeunloadIsAutoAccepted) {}

TEST_F(DevToolsClientImplTest, AlertAndBeforeunloadAreAutoAccepted) {}

namespace {

class MockCommandListener : public DevToolsEventListener {};

void HandleReceivedEvents(DevToolsClient* client) {}

}  // namespace

TEST_F(DevToolsClientImplTest, ReceivesCommandResponse) {}

TEST_F(DevToolsClientImplTest, SendCommandAndIgnoreResponse) {}

namespace {

class PingingListener : public DevToolsEventListener {};

class MultiSessionMockSyncWebSocket2 : public MultiSessionMockSyncWebSocket {};

}  // namespace

TEST_F(DevToolsClientImplTest, AttachToConnected) {}

TEST_F(DevToolsClientImplTest, RoutingChildParent) {}

TEST_F(DevToolsClientImplTest, RoutingTwoChildren) {}

TEST_F(DevToolsClientImplTest, RoutingWithEvent) {}

namespace {

class BidiMockSyncWebSocket : public MultiSessionMockSyncWebSocket {};

class MultiSessionMockSyncWebSocket3 : public BidiMockSyncWebSocket {};

class BidiEventListener : public DevToolsEventListener {};

}  // namespace

TEST_F(DevToolsClientImplTest, BidiCommand) {}

TEST_F(DevToolsClientImplTest, BidiCommandIds) {}

TEST_F(DevToolsClientImplTest, CdpCommandTunneling) {}

namespace {
class MultiSessionMockSyncWebSocket4 : public BidiMockSyncWebSocket {};

class CdpEventListener : public DevToolsEventListener {};

}  // namespace

TEST_F(DevToolsClientImplTest, BidiEvent) {}

TEST_F(DevToolsClientImplTest, BidiEventCrossRouting) {}

TEST_F(DevToolsClientImplTest, CdpEventTunneling) {}

TEST_F(DevToolsClientImplTest, BidiChannels) {}

namespace {

struct BidiMapperState {};

class BidiServerMockSyncWebSocket : public BidiMockSyncWebSocket {};

}  // namespace

TEST_F(DevToolsClientImplTest, StartBidiServer) {}

TEST_F(DevToolsClientImplTest, StartBidiServerNotConnected) {}

TEST_F(DevToolsClientImplTest, StartBidiServerNotAPageClient) {}

TEST_F(DevToolsClientImplTest, StartBidiServerTunnelIsAlreadySet) {}

TEST_F(DevToolsClientImplTest, StartBidiServerFailOnAddBidiResponseBinding) {}

TEST_F(DevToolsClientImplTest, StartBidiServerFailOnRunMapperInstnace) {}

TEST_F(DevToolsClientImplTest, StartBidiServerFailOnExposeDevTools) {}

TEST_F(DevToolsClientImplTest, StartBidiServerFailOnMapperInit) {}

TEST_F(DevToolsClientImplTest, StartBidiServerFailOnSubscribeToCdp) {}