BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / remoting / host / win / rdp_client_unittest.cc
blob9d187836dd7908c94d8cbb204a0877a36e1fe4bb
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // ATL headers have to go first.
6 #include <atlbase.h>
7 #include <atlhost.h>
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/bind.h"
12 #include "base/bind_helpers.h"
13 #include "base/guid.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h"
16 #include "base/win/scoped_com_initializer.h"
17 #include "remoting/base/auto_thread_task_runner.h"
18 #include "remoting/host/win/rdp_client.h"
19 #include "remoting/host/win/wts_terminal_monitor.h"
20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gmock_mutant.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
25 using testing::_;
26 using testing::AtMost;
27 using testing::InvokeWithoutArgs;
29 namespace remoting {
31 namespace {
33 // Default width and hight of the RDP client window.
34 const long kDefaultWidth = 1024;
35 const long kDefaultHeight = 768;
37 class MockRdpClientEventHandler : public RdpClient::EventHandler {
38 public:
39 MockRdpClientEventHandler() {}
40 virtual ~MockRdpClientEventHandler() {}
42 MOCK_METHOD0(OnRdpConnected, void());
43 MOCK_METHOD0(OnRdpClosed, void());
45 private:
46 DISALLOW_COPY_AND_ASSIGN(MockRdpClientEventHandler);
49 // a14498c6-7f3b-4e42-9605-6c4a20d53c87
50 static GUID RdpClientModuleLibid = {
51 0xa14498c6,
52 0x7f3b,
53 0x4e42,
54 { 0x96, 0x05, 0x6c, 0x4a, 0x20, 0xd5, 0x3c, 0x87 }
57 class RdpClientModule : public ATL::CAtlModuleT<RdpClientModule> {
58 public:
59 RdpClientModule();
60 ~RdpClientModule() override;
62 DECLARE_LIBID(RdpClientModuleLibid)
64 private:
65 base::win::ScopedCOMInitializer com_initializer_;
68 RdpClientModule::RdpClientModule() {
69 AtlAxWinInit();
72 RdpClientModule::~RdpClientModule() {
73 AtlAxWinTerm();
74 ATL::_pAtlModule = nullptr;
77 } // namespace
79 class RdpClientTest : public testing::Test {
80 public:
81 RdpClientTest();
82 ~RdpClientTest() override;
84 void SetUp() override;
85 void TearDown() override;
87 // Caaled when an RDP connection is established.
88 void OnRdpConnected();
90 // Tears down |rdp_client_|.
91 void CloseRdpClient();
93 protected:
94 // The ATL module instance required by the ATL code.
95 scoped_ptr<RdpClientModule> module_;
97 // The UI message loop used by RdpClient. The loop is stopped once there is no
98 // more references to |task_runner_|.
99 base::MessageLoopForUI message_loop_;
100 base::RunLoop run_loop_;
101 scoped_refptr<AutoThreadTaskRunner> task_runner_;
103 // Mocks RdpClient::EventHandler for testing.
104 MockRdpClientEventHandler event_handler_;
106 // Points to the object being tested.
107 scoped_ptr<RdpClient> rdp_client_;
109 // Unique terminal identifier passed to RdpClient.
110 std::string terminal_id_;
113 RdpClientTest::RdpClientTest() {
116 RdpClientTest::~RdpClientTest() {
119 void RdpClientTest::SetUp() {
120 // Arrange to run |message_loop_| until no components depend on it.
121 task_runner_ = new AutoThreadTaskRunner(
122 message_loop_.task_runner(), run_loop_.QuitClosure());
124 module_.reset(new RdpClientModule());
127 void RdpClientTest::TearDown() {
128 EXPECT_TRUE(!rdp_client_);
130 module_.reset();
133 void RdpClientTest::OnRdpConnected() {
134 uint32 session_id = WtsTerminalMonitor::LookupSessionId(terminal_id_);
136 std::string id;
137 EXPECT_TRUE(WtsTerminalMonitor::LookupTerminalId(session_id, &id));
138 EXPECT_EQ(id, terminal_id_);
140 message_loop_.PostTask(FROM_HERE, base::Bind(&RdpClientTest::CloseRdpClient,
141 base::Unretained(this)));
144 void RdpClientTest::CloseRdpClient() {
145 EXPECT_TRUE(rdp_client_);
147 rdp_client_.reset();
150 // Creates a loopback RDP connection.
151 TEST_F(RdpClientTest, Basic) {
152 terminal_id_ = base::GenerateGUID();
154 // An ability to establish a loopback RDP connection depends on many factors
155 // including OS SKU and having RDP enabled. Accept both successful connection
156 // and a connection error as a successful outcome.
157 EXPECT_CALL(event_handler_, OnRdpConnected())
158 .Times(AtMost(1))
159 .WillOnce(Invoke(this, &RdpClientTest::OnRdpConnected));
160 EXPECT_CALL(event_handler_, OnRdpClosed())
161 .Times(AtMost(1))
162 .WillOnce(InvokeWithoutArgs(this, &RdpClientTest::CloseRdpClient));
164 rdp_client_.reset(new RdpClient(
165 task_runner_, task_runner_,
166 webrtc::DesktopSize(kDefaultWidth, kDefaultHeight),
167 terminal_id_, &event_handler_));
168 task_runner_ = nullptr;
170 run_loop_.Run();
173 } // namespace remoting