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

Unified Diff: remoting/host/client_session_unittest.cc

Issue 11778049: Making DesktopEnvironment a factory class used by ClientSession to create audio/video capturers and… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/client_session.cc ('k') | remoting/host/desktop_environment.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/client_session_unittest.cc
diff --git a/remoting/host/client_session_unittest.cc b/remoting/host/client_session_unittest.cc
index 285bf4ad9f39b6f235589c559a4124b28383c0d9..1720382d4a4d07590053835c37514b6bb3a9ffae 100644
--- a/remoting/host/client_session_unittest.cc
+++ b/remoting/host/client_session_unittest.cc
@@ -55,9 +55,7 @@ ACTION_P2(LocalMouseMoved, client_session, event) {
class ClientSessionTest : public testing::Test {
public:
- ClientSessionTest()
- : client_jid_("user@domain/rest-of-jid"),
- event_executor_(NULL) {}
+ ClientSessionTest() : client_jid_("user@domain/rest-of-jid") {}
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
@@ -65,8 +63,7 @@ class ClientSessionTest : public testing::Test {
// Disconnects the client session.
void DisconnectClientSession();
- // Asynchronously stops the client session. OnClientStopped() will be called
- // once the client session is fully stopped.
+ // Stops and releases the ClientSession, allowing the MessageLoop to quit.
void StopClientSession();
protected:
@@ -74,6 +71,18 @@ class ClientSessionTest : public testing::Test {
// DesktopEnvironmentFactory::Create().
DesktopEnvironment* CreateDesktopEnvironment();
+ // Returns |event_executor_| created and initialized by SetUp(), to mock
+ // DesktopEnvironment::CreateEventExecutor().
+ EventExecutor* CreateEventExecutor(
+ scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
+
+ // Creates a fake VideoFrameCapturer, to mock
+ // DesktopEnvironment::CreateVideoCapturer().
+ VideoFrameCapturer* CreateVideoCapturer(
+ scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner);
+
// Notifies the client session that the client connection has been
// authenticated and channels have been connected. This effectively enables
// the input pipe line and starts video capturing.
@@ -83,10 +92,6 @@ class ClientSessionTest : public testing::Test {
// released and quits the message loop to finish the test.
void QuitMainMessageLoop();
- // Releases the ClientSession when it has been fully stopped, allowing
- // the MessageLoop to quit.
- void OnClientStopped();
-
// Message loop passed to |client_session_| to perform all functions on.
MessageLoop message_loop_;
@@ -106,7 +111,7 @@ class ClientSessionTest : public testing::Test {
// DesktopEnvironment owns |event_executor_|, but input injection tests need
// to express expectations on it.
- MockEventExecutor* event_executor_;
+ scoped_ptr<MockEventExecutor> event_executor_;
// ClientSession owns |connection_| but tests need it to inject fake events.
MockConnectionToClient* connection_;
@@ -126,6 +131,11 @@ void ClientSessionTest::SetUp() {
.Times(AnyNumber())
.WillRepeatedly(Invoke(this,
&ClientSessionTest::CreateDesktopEnvironment));
+ EXPECT_CALL(*desktop_environment_factory_, SupportsAudioCapture())
+ .Times(AnyNumber())
+ .WillRepeatedly(Return(false));
+
+ event_executor_.reset(new MockEventExecutor());
session_config_ = SessionConfig::ForTest();
@@ -149,9 +159,11 @@ void ClientSessionTest::SetUp() {
client_session_ = new ClientSession(
&session_event_handler_,
ui_task_runner, // Audio thread.
+ ui_task_runner, // Input thread.
ui_task_runner, // Capture thread.
ui_task_runner, // Encode thread.
ui_task_runner, // Network thread.
+ ui_task_runner, // UI thread.
connection.PassAs<protocol::ConnectionToClient>(),
desktop_environment_factory_.get(),
base::TimeDelta());
@@ -171,18 +183,35 @@ void ClientSessionTest::DisconnectClientSession() {
void ClientSessionTest::StopClientSession() {
// MockClientSessionEventHandler won't trigger Stop, so fake it.
- client_session_->Stop(base::Bind(
- &ClientSessionTest::OnClientStopped, base::Unretained(this)));
+ client_session_->Stop();
+ client_session_ = NULL;
+
+ desktop_environment_factory_.reset();
}
DesktopEnvironment* ClientSessionTest::CreateDesktopEnvironment() {
- scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake());
+ MockDesktopEnvironment* desktop_environment = new MockDesktopEnvironment();
+ EXPECT_CALL(*desktop_environment, CreateAudioCapturerPtr(_))
+ .Times(0);
+ EXPECT_CALL(*desktop_environment, CreateEventExecutorPtr(_, _))
+ .WillOnce(Invoke(this, &ClientSessionTest::CreateEventExecutor));
+ EXPECT_CALL(*desktop_environment, CreateVideoCapturerPtr(_, _))
+ .WillOnce(Invoke(this, &ClientSessionTest::CreateVideoCapturer));
+
+ return desktop_environment;
+}
+
+EventExecutor* ClientSessionTest::CreateEventExecutor(
+ scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
+ EXPECT_TRUE(event_executor_);
+ return event_executor_.release();
+}
- EXPECT_TRUE(!event_executor_);
- event_executor_ = new MockEventExecutor();
- return new DesktopEnvironment(scoped_ptr<AudioCapturer>(NULL),
- scoped_ptr<EventExecutor>(event_executor_),
- video_capturer.Pass());
+VideoFrameCapturer* ClientSessionTest::CreateVideoCapturer(
+ scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) {
+ return new VideoFrameCapturerFake();
}
void ClientSessionTest::ConnectClientSession() {
@@ -194,10 +223,6 @@ void ClientSessionTest::QuitMainMessageLoop() {
message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure());
}
-void ClientSessionTest::OnClientStopped() {
- client_session_ = NULL;
-}
-
MATCHER_P2(EqualsClipboardEvent, m, d, "") {
return (strcmp(arg.mime_type().c_str(), m) == 0 &&
memcmp(arg.data().data(), d, arg.data().size()) == 0);
@@ -416,22 +441,22 @@ TEST_F(ClientSessionTest, ClampMouseEvents) {
int input_y[3] = { -999, 50, 999 };
int expected_y[3] = { 0, 50, VideoFrameCapturerFake::kHeight - 1 };
- // Inject the 1st event once a video packet has been received.
- protocol::MouseEvent injected_event;
- injected_event.set_x(input_x[0]);
- injected_event.set_y(input_y[0]);
- connected =
- EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
- .After(connected)
- .WillOnce(InjectMouseEvent(connection_, injected_event));
-
protocol::MouseEvent expected_event;
for (int j = 0; j < 3; j++) {
for (int i = 0; i < 3; i++) {
- // Skip the first iteration since the 1st event has been injected already.
- if (i > 0 || j > 0) {
- injected_event.set_x(input_x[i]);
- injected_event.set_y(input_y[j]);
+ protocol::MouseEvent injected_event;
+ injected_event.set_x(input_x[i]);
+ injected_event.set_y(input_y[j]);
+
+ if (i == 0 && j == 0) {
+ // Inject the 1st event once a video packet has been received.
+ connected =
+ EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
+ .After(connected)
+ .WillOnce(InjectMouseEvent(connection_, injected_event));
+ } else {
+ // Every next event is injected once the previous event has been
+ // received.
connected =
EXPECT_CALL(*event_executor_,
InjectMouseEvent(EqualsMouseEvent(expected_event.x(),
« no previous file with comments | « remoting/host/client_session.cc ('k') | remoting/host/desktop_environment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698