1 // Copyright 2015 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 #include "remoting/test/app_remoting_latency_test_fixture.h"
7 #include "base/logging.h"
8 #include "base/run_loop.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "base/timer/timer.h"
11 #include "remoting/test/app_remoting_connection_helper.h"
12 #include "remoting/test/app_remoting_test_driver_environment.h"
13 #include "remoting/test/test_chromoting_client.h"
14 #include "remoting/test/test_video_renderer.h"
19 AppRemotingLatencyTestFixture::AppRemotingLatencyTestFixture()
20 : application_details_(
21 AppRemotingSharedData
->GetDetailsFromAppName(application_name_
)),
22 timer_(new base::Timer(true, false)) {
23 // NOTE: Derived fixture must initialize application name in constructor.
26 AppRemotingLatencyTestFixture::~AppRemotingLatencyTestFixture() {
29 void AppRemotingLatencyTestFixture::SetUp() {
30 DCHECK(thread_checker_
.CalledOnValidThread());
32 scoped_ptr
<TestVideoRenderer
> test_video_renderer(new TestVideoRenderer());
33 test_video_renderer_
= test_video_renderer
->GetWeakPtr();
35 scoped_ptr
<TestChromotingClient
> test_chromoting_client(
36 new TestChromotingClient(test_video_renderer
.Pass()));
38 connection_helper_
.reset(
39 new AppRemotingConnectionHelper(application_details_
));
40 connection_helper_
->Initialize(test_chromoting_client
.Pass());
42 if (!connection_helper_
->StartConnection()) {
43 LOG(ERROR
) << "Remote host connection could not be established.";
48 void AppRemotingLatencyTestFixture::TearDown() {
49 connection_helper_
.reset();
52 void AppRemotingLatencyTestFixture::SetExpectedImagePattern(
53 const webrtc::DesktopRect
& expected_rect
,
54 uint32_t expected_color
) {
55 DCHECK(thread_checker_
.CalledOnValidThread());
56 DCHECK(!run_loop_
|| !run_loop_
->running());
58 run_loop_
.reset(new base::RunLoop());
59 base::ThreadTaskRunnerHandle::Get()->PostTask(
60 FROM_HERE
, base::Bind(&TestVideoRenderer::ExpectAverageColorInRect
,
61 test_video_renderer_
, expected_rect
, expected_color
,
62 run_loop_
->QuitClosure()));
65 bool AppRemotingLatencyTestFixture::WaitForImagePatternMatched(
66 const base::TimeDelta
& max_wait_time
) {
67 DCHECK(thread_checker_
.CalledOnValidThread());
70 DCHECK(!timer_
->IsRunning());
71 timer_
->Start(FROM_HERE
, max_wait_time
, run_loop_
->QuitClosure());
75 // Image pattern is matched if we stopped because of the reply not the timer.
76 bool image_pattern_is_matched
= (timer_
->IsRunning());
80 return image_pattern_is_matched
;
84 } // namespace remoting