Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "remoting/test/app_remoting_latency_test_fixture.h" | 5 #include "remoting/test/app_remoting_latency_test_fixture.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
| 11 #include "remoting/proto/event.pb.h" | 11 #include "remoting/proto/event.pb.h" |
| 12 #include "remoting/protocol/input_stub.h" | 12 #include "remoting/protocol/input_stub.h" |
| 13 #include "remoting/protocol/usb_key_codes.h" | 13 #include "remoting/protocol/usb_key_codes.h" |
| 14 #include "remoting/test/app_remoting_connection_helper.h" | 14 #include "remoting/test/app_remoting_connection_helper.h" |
| 15 #include "remoting/test/app_remoting_test_driver_environment.h" | 15 #include "remoting/test/app_remoting_test_driver_environment.h" |
| 16 #include "remoting/test/rgb_value.h" | |
| 16 #include "remoting/test/test_chromoting_client.h" | 17 #include "remoting/test/test_chromoting_client.h" |
| 17 #include "remoting/test/test_video_renderer.h" | 18 #include "remoting/test/test_video_renderer.h" |
| 18 | 19 |
| 19 namespace remoting { | 20 namespace remoting { |
| 20 namespace test { | 21 namespace test { |
| 21 | 22 |
| 22 AppRemotingLatencyTestFixture::AppRemotingLatencyTestFixture() | 23 AppRemotingLatencyTestFixture::AppRemotingLatencyTestFixture() |
| 23 : timer_(new base::Timer(true, false)) { | 24 : timer_(new base::Timer(true, false)) { |
| 24 // NOTE: Derived fixture must initialize application details in constructor. | 25 // NOTE: Derived fixture must initialize application details in constructor. |
| 25 } | 26 } |
| 26 | 27 |
| 27 AppRemotingLatencyTestFixture::~AppRemotingLatencyTestFixture() { | 28 AppRemotingLatencyTestFixture::~AppRemotingLatencyTestFixture() { |
| 28 } | 29 } |
| 29 | 30 |
| 30 void AppRemotingLatencyTestFixture::SetUp() { | 31 void AppRemotingLatencyTestFixture::SetUp() { |
| 31 DCHECK(thread_checker_.CalledOnValidThread()); | 32 DCHECK(thread_checker_.CalledOnValidThread()); |
| 32 | 33 |
| 33 scoped_ptr<TestVideoRenderer> test_video_renderer(new TestVideoRenderer()); | 34 scoped_ptr<TestVideoRenderer> test_video_renderer(new TestVideoRenderer()); |
| 34 test_video_renderer_ = test_video_renderer->GetWeakPtr(); | 35 test_video_renderer_ = test_video_renderer->GetWeakPtr(); |
| 35 | 36 |
| 36 scoped_ptr<TestChromotingClient> test_chromoting_client( | 37 scoped_ptr<TestChromotingClient> test_chromoting_client( |
| 37 new TestChromotingClient(test_video_renderer.Pass())); | 38 new TestChromotingClient(test_video_renderer.Pass())); |
| 38 | 39 |
| 40 test_chromoting_client->AddRemoteConnectionObserver(this); | |
| 41 | |
| 39 connection_helper_.reset( | 42 connection_helper_.reset( |
| 40 new AppRemotingConnectionHelper(GetApplicationDetails())); | 43 new AppRemotingConnectionHelper(GetApplicationDetails())); |
| 41 connection_helper_->Initialize(test_chromoting_client.Pass()); | 44 connection_helper_->Initialize(test_chromoting_client.Pass()); |
| 42 | 45 |
| 43 if (!connection_helper_->StartConnection()) { | 46 if (!connection_helper_->StartConnection()) { |
| 44 LOG(ERROR) << "Remote host connection could not be established."; | 47 LOG(ERROR) << "Remote host connection could not be established."; |
| 45 FAIL(); | 48 FAIL(); |
| 46 } | 49 } |
| 50 | |
| 51 if (!PrepareApplicationForTesting()) { | |
| 52 LOG(ERROR) << "New document could not be created."; | |
|
joedow
2015/07/24 13:50:58
Please fix error message, we don't know if creatin
liaoyuke
2015/07/25 01:43:49
I don't think so, the error message should come fr
| |
| 53 FAIL(); | |
| 54 } | |
| 47 } | 55 } |
| 48 | 56 |
| 49 void AppRemotingLatencyTestFixture::TearDown() { | 57 void AppRemotingLatencyTestFixture::TearDown() { |
| 50 // Only reset application state when remote host connection is established. | 58 // Only reset application state when remote host connection is established. |
| 51 if (connection_helper_->ConnectionIsReadyForTest()) { | 59 if (connection_helper_->ConnectionIsReadyForTest()) { |
| 52 ResetApplicationState(); | 60 ResetApplicationState(); |
| 53 } | 61 } |
| 54 | 62 |
| 63 connection_helper_->GetTestChromotingClient()->RemoveRemoteConnectionObserver( | |
| 64 this); | |
| 55 connection_helper_.reset(); | 65 connection_helper_.reset(); |
| 56 } | 66 } |
| 57 | 67 |
| 58 WaitForImagePatternMatchCallback | 68 WaitForImagePatternMatchCallback |
| 59 AppRemotingLatencyTestFixture::SetExpectedImagePattern( | 69 AppRemotingLatencyTestFixture::SetExpectedImagePattern( |
| 60 const webrtc::DesktopRect& expected_rect, | 70 const webrtc::DesktopRect& expected_rect, |
| 61 uint32_t expected_color) { | 71 const RGBValue& expected_color) { |
| 62 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 | 73 |
| 64 scoped_ptr<base::RunLoop> run_loop(new base::RunLoop()); | 74 scoped_ptr<base::RunLoop> run_loop(new base::RunLoop()); |
| 65 | 75 |
| 66 base::ThreadTaskRunnerHandle::Get()->PostTask( | 76 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 67 FROM_HERE, base::Bind(&TestVideoRenderer::ExpectAverageColorInRect, | 77 FROM_HERE, base::Bind(&TestVideoRenderer::ExpectAverageColorInRect, |
| 68 test_video_renderer_, expected_rect, expected_color, | 78 test_video_renderer_, expected_rect, expected_color, |
| 69 run_loop->QuitClosure())); | 79 run_loop->QuitClosure())); |
| 70 | 80 |
| 71 return base::Bind(&AppRemotingLatencyTestFixture::WaitForImagePatternMatch, | 81 return base::Bind(&AppRemotingLatencyTestFixture::WaitForImagePatternMatch, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 84 run_loop->Run(); | 94 run_loop->Run(); |
| 85 | 95 |
| 86 // Image pattern is matched if we stopped because of the reply not the timer. | 96 // Image pattern is matched if we stopped because of the reply not the timer. |
| 87 bool image_pattern_is_matched = (timer_->IsRunning()); | 97 bool image_pattern_is_matched = (timer_->IsRunning()); |
| 88 timer_->Stop(); | 98 timer_->Stop(); |
| 89 run_loop.reset(); | 99 run_loop.reset(); |
| 90 | 100 |
| 91 return image_pattern_is_matched; | 101 return image_pattern_is_matched; |
| 92 } | 102 } |
| 93 | 103 |
| 104 void AppRemotingLatencyTestFixture::HostMessageReceived( | |
| 105 const protocol::ExtensionMessage& message) { | |
| 106 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 107 | |
| 108 if (!host_message_received_callback_.is_null()) { | |
| 109 host_message_received_callback_.Run(message); | |
| 110 } | |
| 111 } | |
| 112 | |
| 94 void AppRemotingLatencyTestFixture::PressKey(uint32_t usb_keycode, | 113 void AppRemotingLatencyTestFixture::PressKey(uint32_t usb_keycode, |
| 95 bool pressed) { | 114 bool pressed) { |
| 96 remoting::protocol::KeyEvent event; | 115 remoting::protocol::KeyEvent event; |
| 97 event.set_usb_keycode(usb_keycode); | 116 event.set_usb_keycode(usb_keycode); |
| 98 event.set_pressed(pressed); | 117 event.set_pressed(pressed); |
| 99 connection_helper_->input_stub()->InjectKeyEvent(event); | 118 connection_helper_->input_stub()->InjectKeyEvent(event); |
| 100 } | 119 } |
| 101 | 120 |
| 102 void AppRemotingLatencyTestFixture::PressAndReleaseKey(uint32_t usb_keycode) { | 121 void AppRemotingLatencyTestFixture::PressAndReleaseKey(uint32_t usb_keycode) { |
| 103 PressKey(usb_keycode, true); | 122 PressKey(usb_keycode, true); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 164 |
| 146 run_loop_.reset(new base::RunLoop()); | 165 run_loop_.reset(new base::RunLoop()); |
| 147 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 166 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 148 FROM_HERE, run_loop_->QuitClosure(), base::TimeDelta::FromSeconds(2)); | 167 FROM_HERE, run_loop_->QuitClosure(), base::TimeDelta::FromSeconds(2)); |
| 149 run_loop_->Run(); | 168 run_loop_->Run(); |
| 150 run_loop_.reset(); | 169 run_loop_.reset(); |
| 151 } | 170 } |
| 152 | 171 |
| 153 } // namespace test | 172 } // namespace test |
| 154 } // namespace remoting | 173 } // namespace remoting |
| OLD | NEW |