chromium/remoting/host/chromoting_host_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.

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

#include "remoting/host/chromoting_host.h"

#include <memory>
#include <utility>

#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/network_change_notifier.h"
#include "remoting/base/auto_thread_task_runner.h"
#include "remoting/base/local_session_policies_provider.h"
#include "remoting/host/audio_capturer.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/fake_desktop_environment.h"
#include "remoting/host/fake_mouse_cursor_monitor.h"
#include "remoting/host/host_mock_objects.h"
#include "remoting/host/mojom/chromoting_host_services.mojom.h"
#include "remoting/proto/video.pb.h"
#include "remoting/protocol/errors.h"
#include "remoting/protocol/fake_connection_to_client.h"
#include "remoting/protocol/fake_desktop_capturer.h"
#include "remoting/protocol/protocol_mock_objects.h"
#include "remoting/protocol/session_config.h"
#include "remoting/protocol/transport_context.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(IS_WIN)
#include <windows.h>
#endif

MockClientStub;
MockConnectionToClientEventHandler;
MockHostStub;
MockSession;
MockVideoStub;
Session;
SessionConfig;

_;
AnyNumber;
AtLeast;
AtMost;
DeleteArg;
DoAll;
Expectation;
InSequence;
Invoke;
InvokeArgument;
InvokeWithoutArgs;
Return;
ReturnRef;
SaveArg;
Sequence;

namespace remoting {

const size_t kNumFailuresIgnored =;

class ChromotingHostTest : public testing::Test {};

TEST_F(ChromotingHostTest, StartAndShutdown) {}

TEST_F(ChromotingHostTest, Connect) {}

TEST_F(ChromotingHostTest, AuthenticationFailed) {}

TEST_F(ChromotingHostTest, Reconnect) {}

TEST_F(ChromotingHostTest, ConnectWhenAnotherClientIsConnected) {}

TEST_F(ChromotingHostTest, IncomingSessionAccepted) {}

TEST_F(ChromotingHostTest, LoginBackOffTriggersIfClientsDoNotAuthenticate) {}

TEST_F(ChromotingHostTest, LoginBackOffResetsIfClientsAuthenticate) {}

// Flaky on all platforms.  http://crbug.com/1265894
TEST_F(ChromotingHostTest, DISABLED_OnSessionRouteChange) {}

TEST_F(ChromotingHostTest, BindSessionServicesWithNoConnectedSession_Rejected) {}

TEST_F(ChromotingHostTest, BindSessionServicesWithConnectedSession_Accepted) {}

#if BUILDFLAG(IS_WIN)
TEST_F(ChromotingHostTest, BindSessionServicesWithWrongSession_Rejected) {
  StartHost();
  auto host_services_remote = BindChromotingHostServices();
  SimulateIpcClientSessionId(/* is_remote_desktop_session_id= */ false);
  ExpectClientConnected(0);
  SimulateClientConnection(0, true, false);

  mojo::Remote<mojom::ChromotingSessionServices> remote;
  auto receiver = remote.BindNewPipeAndPassReceiver();
  base::RunLoop wait_for_disconnect_run_loop;
  remote.set_disconnect_handler(wait_for_disconnect_run_loop.QuitClosure());
  // Note that we can't just call host_->BindSessionServices(), since that
  // doesn't have the peer PID context.
  host_services_remote->BindSessionServices(std::move(receiver));
  wait_for_disconnect_run_loop.Run();
}
#endif

}  // namespace remoting