Commit 638b48e2 authored by fdoray's avatar fdoray Committed by Commit bot

Use ScopedTaskEnvironment instead of MessageLoopForUI in remoting tests.

ScopedTaskEnvironment allows usage of ThreadTaskRunnerHandle and
base/task_scheduler/post_task.h within its scope. It should be
instantiated in everytest that uses either of these APIs
(i.e. no test should instantiate a MessageLoop directly).

Motivation for ScopedTaskEnvironment can be found in:
https://docs.google.com/document/d/1QabRo8c7D9LsYY3cEcaPQbOCLo8Tu-6VLykYXyl3Pkk/edit

BUG=708584
R=gab@chromium.org
TBR=garykac@chromium.org

Review-Url: https://codereview.chromium.org/2846943002
Cr-Commit-Position: refs/heads/master@{#468018}
parent e17ef94d
......@@ -173,6 +173,7 @@ if (enable_remoting_host && !is_android && !is_chromeos) {
deps = [
":fake_connection_event_logger",
"//base/test:test_support",
"//third_party/webrtc/modules/desktop_capture",
]
......
......@@ -12,6 +12,7 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "remoting/base/auto_thread_task_runner.h"
#include "remoting/host/chromoting_host_context.h"
......@@ -36,24 +37,26 @@ constexpr char kSessionJid[] = "user@domain/rest-of-jid";
using ::remoting::protocol::MockSession;
It2MeStandaloneHost::It2MeStandaloneHost()
: context_(ChromotingHostContext::Create(
new AutoThreadTaskRunner(
message_loop_.task_runner(), run_loop_.QuitClosure()))),
main_task_runner_(context_->file_task_runner()),
factory_(main_task_runner_,
context_->video_capture_task_runner(),
context_->input_task_runner(),
context_->ui_task_runner()),
connection_(base::WrapUnique(new testing::NiceMock<MockSession>())),
session_jid_(kSessionJid),
: scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::UI),
context_(ChromotingHostContext::Create(
new AutoThreadTaskRunner(base::ThreadTaskRunnerHandle::Get(),
run_loop_.QuitClosure()))),
main_task_runner_(context_->file_task_runner()),
factory_(main_task_runner_,
context_->video_capture_task_runner(),
context_->input_task_runner(),
context_->ui_task_runner()),
connection_(base::WrapUnique(new testing::NiceMock<MockSession>())),
session_jid_(kSessionJid),
#if defined(OS_LINUX)
// We cannot support audio capturing for linux, since a pipe name is
// needed to initialize AudioCapturerLinux.
config_(protocol::SessionConfig::ForTest()),
// We cannot support audio capturing for linux, since a pipe name is
// needed to initialize AudioCapturerLinux.
config_(protocol::SessionConfig::ForTest()),
#else
config_(protocol::SessionConfig::ForTestWithAudio()),
config_(protocol::SessionConfig::ForTestWithAudio()),
#endif
event_logger_(&connection_) {
event_logger_(&connection_) {
EXPECT_CALL(*static_cast<MockSession*>(connection_.session()), jid())
.WillRepeatedly(testing::ReturnRef(session_jid_));
EXPECT_CALL(*static_cast<MockSession*>(connection_.session()), config())
......
......@@ -9,8 +9,8 @@
#include <string>
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "base/timer/timer.h"
#include "remoting/host/host_mock_objects.h"
#include "remoting/host/it2me_desktop_environment.h"
......@@ -43,7 +43,7 @@ class It2MeStandaloneHost {
private:
void Connect();
base::MessageLoopForUI message_loop_;
base::test::ScopedTaskEnvironment scoped_task_environment_;
base::RunLoop run_loop_;
std::unique_ptr<ChromotingHostContext> context_;
scoped_refptr<AutoThreadTaskRunner> main_task_runner_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment