Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "remoting/base/auto_thread_task_runner.h" | 6 #include "remoting/base/auto_thread_task_runner.h" |
| 7 #include "remoting/base/constants.h" | 7 #include "remoting/base/constants.h" |
| 8 #include "remoting/host/audio_capturer.h" | 8 #include "remoting/host/audio_capturer.h" |
| 9 #include "remoting/host/client_session.h" | 9 #include "remoting/host/client_session.h" |
| 10 #include "remoting/host/desktop_environment.h" | 10 #include "remoting/host/desktop_environment.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 using testing::_; | 25 using testing::_; |
| 26 using testing::AnyNumber; | 26 using testing::AnyNumber; |
| 27 using testing::DeleteArg; | 27 using testing::DeleteArg; |
| 28 using testing::Expectation; | 28 using testing::Expectation; |
| 29 using testing::InSequence; | 29 using testing::InSequence; |
| 30 using testing::Return; | 30 using testing::Return; |
| 31 using testing::ReturnRef; | 31 using testing::ReturnRef; |
| 32 | 32 |
| 33 class ClientSessionTest : public testing::Test { | 33 class ClientSessionTest : public testing::Test { |
| 34 public: | 34 public: |
| 35 ClientSessionTest() {} | 35 ClientSessionTest() : event_executor_(NULL) {} |
| 36 | 36 |
| 37 virtual void SetUp() OVERRIDE { | 37 virtual void SetUp() OVERRIDE { |
| 38 ui_task_runner_ = new AutoThreadTaskRunner( | 38 ui_task_runner_ = new AutoThreadTaskRunner( |
| 39 message_loop_.message_loop_proxy(), | 39 message_loop_.message_loop_proxy(), |
| 40 base::Bind(&ClientSessionTest::QuitMainMessageLoop, | 40 base::Bind(&ClientSessionTest::QuitMainMessageLoop, |
| 41 base::Unretained(this))); | 41 base::Unretained(this))); |
| 42 | 42 |
| 43 EXPECT_CALL(context_, ui_task_runner()) | 43 EXPECT_CALL(context_, ui_task_runner()) |
| 44 .Times(AnyNumber()) | 44 .Times(AnyNumber()) |
| 45 .WillRepeatedly(Return(ui_task_runner_.get())); | 45 .WillRepeatedly(Return(ui_task_runner_.get())); |
| 46 EXPECT_CALL(context_, capture_task_runner()) | 46 EXPECT_CALL(context_, capture_task_runner()) |
| 47 .Times(AnyNumber()) | 47 .Times(AnyNumber()) |
| 48 .WillRepeatedly(Return(ui_task_runner_.get())); | 48 .WillRepeatedly(Return(ui_task_runner_.get())); |
| 49 EXPECT_CALL(context_, encode_task_runner()) | 49 EXPECT_CALL(context_, encode_task_runner()) |
| 50 .Times(AnyNumber()) | 50 .Times(AnyNumber()) |
| 51 .WillRepeatedly(Return(ui_task_runner_.get())); | 51 .WillRepeatedly(Return(ui_task_runner_.get())); |
| 52 EXPECT_CALL(context_, network_task_runner()) | 52 EXPECT_CALL(context_, network_task_runner()) |
| 53 .Times(AnyNumber()) | 53 .Times(AnyNumber()) |
| 54 .WillRepeatedly(Return(ui_task_runner_.get())); | 54 .WillRepeatedly(Return(ui_task_runner_.get())); |
| 55 | 55 |
| 56 client_jid_ = "user@domain/rest-of-jid"; | 56 client_jid_ = "user@domain/rest-of-jid"; |
| 57 | 57 |
| 58 event_executor_ = new MockEventExecutor(); | 58 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); |
|
Wez
2012/10/17 22:04:24
nit: Strictly we should use Fakes here, since we'r
alexeypa (please no reviews)
2012/10/17 22:46:56
Ack.
| |
| 59 capturer_ = new MockVideoFrameCapturer(); | 59 EXPECT_CALL(*desktop_environment_factory_, CreatePtr(_)) |
| 60 EXPECT_CALL(*capturer_, Start(_)); | 60 .Times(AnyNumber()) |
| 61 EXPECT_CALL(*capturer_, Stop()); | 61 .WillRepeatedly(Invoke(this, |
| 62 EXPECT_CALL(*capturer_, InvalidateRegion(_)).Times(AnyNumber()); | 62 &ClientSessionTest::CreateDesktopEnvironment)); |
| 63 EXPECT_CALL(*capturer_, CaptureInvalidRegion(_)).Times(AnyNumber()); | |
| 64 | |
| 65 scoped_ptr<DesktopEnvironment> desktop_environment(new DesktopEnvironment( | |
| 66 scoped_ptr<AudioCapturer>(NULL), | |
| 67 scoped_ptr<EventExecutor>(event_executor_), | |
| 68 scoped_ptr<VideoFrameCapturer>(capturer_))); | |
| 69 | 63 |
| 70 // Set up a large default screen size that won't affect most tests. | 64 // Set up a large default screen size that won't affect most tests. |
| 71 screen_size_.set(1000, 1000); | 65 screen_size_.set(1000, 1000); |
| 72 EXPECT_CALL(*capturer_, size_most_recent()) | |
| 73 .WillRepeatedly(ReturnRef(screen_size_)); | |
| 74 | 66 |
| 75 session_config_ = SessionConfig::GetDefault(); | 67 session_config_ = SessionConfig::GetDefault(); |
| 76 | 68 |
| 77 protocol::MockSession* session = new MockSession(); | 69 protocol::MockSession* session = new MockSession(); |
| 78 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(session_config_)); | 70 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(session_config_)); |
| 79 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); | 71 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); |
| 80 EXPECT_CALL(*session, SetEventHandler(_)); | 72 EXPECT_CALL(*session, SetEventHandler(_)); |
| 81 EXPECT_CALL(*session, Close()); | 73 EXPECT_CALL(*session, Close()); |
| 82 scoped_ptr<protocol::ConnectionToClient> connection( | 74 scoped_ptr<protocol::ConnectionToClient> connection( |
| 83 new protocol::ConnectionToClient(session)); | 75 new protocol::ConnectionToClient(session)); |
| 84 connection_ = connection.get(); | 76 connection_ = connection.get(); |
| 85 | 77 |
| 86 client_session_ = new ClientSession( | 78 client_session_ = new ClientSession( |
| 87 &session_event_handler_, | 79 &session_event_handler_, |
| 88 context_.capture_task_runner(), | 80 context_.capture_task_runner(), |
| 89 context_.encode_task_runner(), | 81 context_.encode_task_runner(), |
| 90 context_.network_task_runner(), | 82 context_.network_task_runner(), |
| 91 connection.Pass(), | 83 connection.Pass(), |
| 92 desktop_environment.Pass(), | 84 desktop_environment_factory_.get(), |
| 93 base::TimeDelta()); | 85 base::TimeDelta()); |
| 94 } | 86 } |
| 95 | 87 |
| 96 virtual void TearDown() OVERRIDE { | 88 virtual void TearDown() OVERRIDE { |
| 97 // MockClientSessionEventHandler won't trigger StopAndDelete, so fake it. | 89 // MockClientSessionEventHandler won't trigger StopAndDelete, so fake it. |
| 98 client_session_->Stop(base::Bind( | 90 client_session_->Stop(base::Bind( |
| 99 &ClientSessionTest::OnClientStopped, base::Unretained(this))); | 91 &ClientSessionTest::OnClientStopped, base::Unretained(this))); |
| 100 | 92 |
| 101 // Run message loop before destroying because the session is destroyed | 93 // Run message loop before destroying because the session is destroyed |
| 102 // asynchronously. | 94 // asynchronously. |
| 103 ui_task_runner_ = NULL; | 95 ui_task_runner_ = NULL; |
| 104 message_loop_.Run(); | 96 message_loop_.Run(); |
| 105 | 97 |
| 106 // Verify that the client session has been stopped. | 98 // Verify that the client session has been stopped. |
| 107 EXPECT_TRUE(client_session_.get() == NULL); | 99 EXPECT_TRUE(client_session_.get() == NULL); |
| 108 } | 100 } |
| 109 | 101 |
| 110 protected: | 102 protected: |
| 103 DesktopEnvironment* CreateDesktopEnvironment(ClientSession* client) { | |
| 104 MockVideoFrameCapturer* capturer = new MockVideoFrameCapturer(); | |
| 105 EXPECT_CALL(*capturer, Start(_)); | |
| 106 EXPECT_CALL(*capturer, Stop()); | |
| 107 EXPECT_CALL(*capturer, InvalidateRegion(_)).Times(AnyNumber()); | |
| 108 EXPECT_CALL(*capturer, CaptureInvalidRegion(_)).Times(AnyNumber()); | |
| 109 EXPECT_CALL(*capturer, size_most_recent()) | |
| 110 .WillRepeatedly(ReturnRef(screen_size_)); | |
| 111 | |
| 112 EXPECT_TRUE(!event_executor_); | |
| 113 event_executor_ = new MockEventExecutor(); | |
| 114 return new DesktopEnvironment(scoped_ptr<AudioCapturer>(NULL), | |
| 115 scoped_ptr<EventExecutor>(event_executor_), | |
| 116 scoped_ptr<VideoFrameCapturer>(capturer)); | |
| 117 } | |
| 118 | |
| 111 void DisconnectClientSession() { | 119 void DisconnectClientSession() { |
| 112 client_session_->Disconnect(); | 120 client_session_->Disconnect(); |
| 113 // MockSession won't trigger OnConnectionClosed, so fake it. | 121 // MockSession won't trigger OnConnectionClosed, so fake it. |
| 114 client_session_->OnConnectionClosed(client_session_->connection(), | 122 client_session_->OnConnectionClosed(client_session_->connection(), |
| 115 protocol::OK); | 123 protocol::OK); |
| 116 } | 124 } |
| 117 | 125 |
| 118 void QuitMainMessageLoop() { | 126 void QuitMainMessageLoop() { |
| 119 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 127 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 120 } | 128 } |
| 121 | 129 |
| 122 void OnClientStopped() { | 130 void OnClientStopped() { |
| 123 client_session_ = NULL; | 131 client_session_ = NULL; |
| 124 } | 132 } |
| 125 | 133 |
| 126 MessageLoop message_loop_; | 134 MessageLoop message_loop_; |
| 127 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; | 135 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
| 128 MockChromotingHostContext context_; | 136 MockChromotingHostContext context_; |
| 129 SkISize screen_size_; | 137 SkISize screen_size_; |
| 130 std::string client_jid_; | 138 std::string client_jid_; |
| 131 MockHostStub host_stub_; | 139 MockHostStub host_stub_; |
| 132 MockEventExecutor* event_executor_; | 140 MockEventExecutor* event_executor_; |
| 133 MockVideoFrameCapturer* capturer_; | |
| 134 MockClientSessionEventHandler session_event_handler_; | 141 MockClientSessionEventHandler session_event_handler_; |
| 135 scoped_refptr<ClientSession> client_session_; | 142 scoped_refptr<ClientSession> client_session_; |
| 136 SessionConfig session_config_; | 143 SessionConfig session_config_; |
| 137 | 144 |
| 138 // ClientSession owns |connection_| but tests need it to inject fake events. | 145 // ClientSession owns |connection_| but tests need it to inject fake events. |
| 139 protocol::ConnectionToClient* connection_; | 146 protocol::ConnectionToClient* connection_; |
| 147 scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory_; | |
| 140 }; | 148 }; |
| 141 | 149 |
| 142 MATCHER_P2(EqualsClipboardEvent, m, d, "") { | 150 MATCHER_P2(EqualsClipboardEvent, m, d, "") { |
| 143 return (strcmp(arg.mime_type().c_str(), m) == 0 && | 151 return (strcmp(arg.mime_type().c_str(), m) == 0 && |
| 144 memcmp(arg.data().data(), d, arg.data().size()) == 0); | 152 memcmp(arg.data().data(), d, arg.data().size()) == 0); |
| 145 } | 153 } |
| 146 | 154 |
| 147 TEST_F(ClientSessionTest, ClipboardStubFilter) { | 155 TEST_F(ClientSessionTest, ClipboardStubFilter) { |
| 148 protocol::ClipboardEvent clipboard_event1; | 156 protocol::ClipboardEvent clipboard_event1; |
| 149 clipboard_event1.set_mime_type(kMimeTypeTextUtf8); | 157 clipboard_event1.set_mime_type(kMimeTypeTextUtf8); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 expected_y[j]))) | 360 expected_y[j]))) |
| 353 .After(connected); | 361 .After(connected); |
| 354 connection_->input_stub()->InjectMouseEvent(event); | 362 connection_->input_stub()->InjectMouseEvent(event); |
| 355 } | 363 } |
| 356 } | 364 } |
| 357 | 365 |
| 358 DisconnectClientSession(); | 366 DisconnectClientSession(); |
| 359 } | 367 } |
| 360 | 368 |
| 361 } // namespace remoting | 369 } // namespace remoting |
| OLD | NEW |