This source file includes following definitions.
- SetUp
- TearDown
- OnRdpConnected
- CloseRdpClient
- TEST_F
#include <atlbase.h>
#include <atlhost.h>
#include <string>
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/guid.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/win/scoped_com_initializer.h"
#include "remoting/base/auto_thread_task_runner.h"
#include "remoting/host/win/rdp_client.h"
#include "remoting/host/win/wts_terminal_monitor.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gmock_mutant.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
using testing::_;
using testing::AtMost;
using testing::InvokeWithoutArgs;
namespace remoting {
namespace {
const long kDefaultWidth = 1024;
const long kDefaultHeight = 768;
class MockRdpClientEventHandler : public RdpClient::EventHandler {
public:
MockRdpClientEventHandler() {}
virtual ~MockRdpClientEventHandler() {}
MOCK_METHOD0(OnRdpConnected, void());
MOCK_METHOD0(OnRdpClosed, void());
private:
DISALLOW_COPY_AND_ASSIGN(MockRdpClientEventHandler);
};
static GUID RdpClientModuleLibid = {
0xa14498c6,
0x7f3b,
0x4e42,
{ 0x96, 0x05, 0x6c, 0x4a, 0x20, 0xd5, 0x3c, 0x87 }
};
class RdpClientModule : public ATL::CAtlModuleT<RdpClientModule> {
public:
RdpClientModule();
virtual ~RdpClientModule();
DECLARE_LIBID(RdpClientModuleLibid)
private:
base::win::ScopedCOMInitializer com_initializer_;
};
RdpClientModule::RdpClientModule() {
AtlAxWinInit();
}
RdpClientModule::~RdpClientModule() {
AtlAxWinTerm();
ATL::_pAtlModule = NULL;
}
}
class RdpClientTest : public testing::Test {
public:
RdpClientTest();
virtual ~RdpClientTest();
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
void OnRdpConnected();
void CloseRdpClient();
protected:
scoped_ptr<RdpClientModule> module_;
base::MessageLoopForUI message_loop_;
base::RunLoop run_loop_;
scoped_refptr<AutoThreadTaskRunner> task_runner_;
MockRdpClientEventHandler event_handler_;
scoped_ptr<RdpClient> rdp_client_;
std::string terminal_id_;
};
RdpClientTest::RdpClientTest() {
}
RdpClientTest::~RdpClientTest() {
}
void RdpClientTest::SetUp() {
task_runner_ = new AutoThreadTaskRunner(
message_loop_.message_loop_proxy(), run_loop_.QuitClosure());
module_.reset(new RdpClientModule());
}
void RdpClientTest::TearDown() {
EXPECT_TRUE(!rdp_client_);
module_.reset();
}
void RdpClientTest::OnRdpConnected() {
uint32 session_id = WtsTerminalMonitor::LookupSessionId(terminal_id_);
std::string id;
EXPECT_TRUE(WtsTerminalMonitor::LookupTerminalId(session_id, &id));
EXPECT_EQ(id, terminal_id_);
message_loop_.PostTask(FROM_HERE, base::Bind(&RdpClientTest::CloseRdpClient,
base::Unretained(this)));
}
void RdpClientTest::CloseRdpClient() {
EXPECT_TRUE(rdp_client_);
rdp_client_.reset();
}
TEST_F(RdpClientTest, Basic) {
terminal_id_ = base::GenerateGUID();
EXPECT_CALL(event_handler_, OnRdpConnected())
.Times(AtMost(1))
.WillOnce(Invoke(this, &RdpClientTest::OnRdpConnected));
EXPECT_CALL(event_handler_, OnRdpClosed())
.Times(AtMost(1))
.WillOnce(InvokeWithoutArgs(this, &RdpClientTest::CloseRdpClient));
rdp_client_.reset(new RdpClient(
task_runner_, task_runner_,
webrtc::DesktopSize(kDefaultWidth, kDefaultHeight),
terminal_id_, &event_handler_));
task_runner_ = NULL;
run_loop_.Run();
}
}