Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: remoting/host/chromoting_host_unittest.cc

Issue 6266023: Revert "Fix crashes in ChromotingHost" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/chromoting_host.cc ('k') | remoting/host/screen_recorder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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.
4
5 #include "base/task.h"
6 #include "remoting/host/capturer_fake.h"
7 #include "remoting/host/chromoting_host.h"
8 #include "remoting/host/chromoting_host_context.h"
9 #include "remoting/host/in_memory_host_config.h"
10 #include "remoting/proto/video.pb.h"
11 #include "remoting/protocol/mock_objects.h"
12 #include "remoting/protocol/session_config.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 using testing::_;
17 using testing::AnyNumber;
18 using testing::DeleteArg;
19 using testing::DoAll;
20 using testing::InSequence;
21 using testing::InvokeWithoutArgs;
22 using testing::Return;
23
24 namespace remoting {
25
26 namespace {
27
28 void PostQuitTask(MessageLoop* message_loop) {
29 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
30 }
31
32 // Run the task and delete it afterwards. This action is used to deal with
33 // done callbacks.
34 ACTION(RunDoneTask) {
35 arg1->Run();
36 delete arg1;
37 }
38
39 ACTION_P(QuitMainMessageLoop, message_loop) {
40 PostQuitTask(message_loop);
41 }
42
43 } // namepace
44
45 class ChromotingHostTest : public testing::Test {
46 public:
47 ChromotingHostTest() {
48 }
49
50 virtual void SetUp() {
51 config_ = new InMemoryHostConfig();
52 context_.Start();
53 Capturer* capturer = new CapturerFake(context_.main_message_loop());
54 input_stub_ = new protocol::MockInputStub();
55 host_ = ChromotingHost::Create(&context_, config_, capturer, input_stub_);
56 connection_ = new protocol::MockConnectionToClient();
57 session_ = new protocol::MockSession();
58 session_config_.reset(protocol::SessionConfig::CreateDefault());
59
60 ON_CALL(*connection_.get(), video_stub())
61 .WillByDefault(Return(&video_stub_));
62 ON_CALL(*connection_.get(), session())
63 .WillByDefault(Return(session_));
64 ON_CALL(*session_.get(), config())
65 .WillByDefault(Return(session_config_.get()));
66 }
67
68 virtual void TearDown() {
69 context_.Stop();
70 }
71
72 // Helper metjod to pretend a client is connected to ChromotingHost.
73 void InjectClientConnection() {
74 context_.network_message_loop()->PostTask(
75 FROM_HERE,
76 NewRunnableMethod(host_.get(),
77 &ChromotingHost::OnConnectionOpened,
78 connection_));
79 }
80
81 // Helper method to remove a client connection from ChromotongHost.
82 void RemoveClientConnection() {
83 context_.network_message_loop()->PostTask(
84 FROM_HERE,
85 NewRunnableMethod(host_.get(),
86 &ChromotingHost::OnConnectionClosed,
87 connection_));
88 }
89
90 protected:
91 MessageLoop message_loop_;
92 scoped_refptr<ChromotingHost> host_;
93 scoped_refptr<InMemoryHostConfig> config_;
94 ChromotingHostContext context_;
95 scoped_refptr<protocol::MockConnectionToClient> connection_;
96 scoped_refptr<protocol::MockSession> session_;
97 scoped_ptr<protocol::SessionConfig> session_config_;
98 protocol::MockVideoStub video_stub_;
99 protocol::MockInputStub* input_stub_;
100 };
101
102 TEST_F(ChromotingHostTest, StartAndShutdown) {
103 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
104
105 message_loop_.PostTask(FROM_HERE,
106 NewRunnableMethod(host_.get(),
107 &ChromotingHost::Shutdown));
108 message_loop_.Run();
109 }
110
111 TEST_F(ChromotingHostTest, Connect) {
112 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
113
114 ON_CALL(video_stub_, ProcessVideoPacket(_, _))
115 .WillByDefault(
116 DoAll(DeleteArg<0>(), DeleteArg<1>()));
117
118 // When the video packet is received we first shutdown ChromotingHost
119 // then execute the done task.
120 InSequence s;
121 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
122 .WillOnce(DoAll(
123 InvokeWithoutArgs(host_.get(), &ChromotingHost::Shutdown),
124 RunDoneTask()))
125 .RetiresOnSaturation();
126 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
127 .Times(AnyNumber());
128
129 InjectClientConnection();
130 message_loop_.Run();
131 }
132
133 TEST_F(ChromotingHostTest, Reconnect) {
134 host_->Start(NewRunnableFunction(&PostQuitTask, &message_loop_));
135
136 ON_CALL(video_stub_, ProcessVideoPacket(_, _))
137 .WillByDefault(
138 DoAll(DeleteArg<0>(), DeleteArg<1>()));
139
140 // When the video packet is received we first disconnect the mock
141 // connection.
142 InSequence s;
143 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
144 .WillOnce(DoAll(
145 InvokeWithoutArgs(this, &ChromotingHostTest::RemoveClientConnection),
146 RunDoneTask()))
147 .RetiresOnSaturation();
148 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
149 .Times(AnyNumber());
150
151 // If Disconnect() is called we can break the main message loop.
152 EXPECT_CALL(*connection_.get(), Disconnect())
153 .WillOnce(QuitMainMessageLoop(&message_loop_))
154 .RetiresOnSaturation();
155
156 InjectClientConnection();
157 message_loop_.Run();
158
159 // Connect the client again.
160 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
161 .WillOnce(DoAll(
162 InvokeWithoutArgs(host_.get(), &ChromotingHost::Shutdown),
163 RunDoneTask()))
164 .RetiresOnSaturation();
165 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _))
166 .Times(AnyNumber());
167
168 InjectClientConnection();
169 message_loop_.Run();
170 }
171
172 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/chromoting_host.cc ('k') | remoting/host/screen_recorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698