| 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" | |
| 14 #include "remoting/test/app_remoting_connection_helper.h" | 13 #include "remoting/test/app_remoting_connection_helper.h" |
| 15 #include "remoting/test/app_remoting_test_driver_environment.h" | 14 #include "remoting/test/app_remoting_test_driver_environment.h" |
| 16 #include "remoting/test/rgb_value.h" | 15 #include "remoting/test/rgb_value.h" |
| 17 #include "remoting/test/test_chromoting_client.h" | 16 #include "remoting/test/test_chromoting_client.h" |
| 18 #include "remoting/test/test_video_renderer.h" | 17 #include "remoting/test/test_video_renderer.h" |
| 19 | 18 |
| 20 namespace remoting { | 19 namespace remoting { |
| 21 namespace test { | 20 namespace test { |
| 22 | 21 |
| 23 AppRemotingLatencyTestFixture::AppRemotingLatencyTestFixture() | 22 AppRemotingLatencyTestFixture::AppRemotingLatencyTestFixture() |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 return image_pattern_is_matched; | 98 return image_pattern_is_matched; |
| 100 } | 99 } |
| 101 | 100 |
| 102 void AppRemotingLatencyTestFixture::HostMessageReceived( | 101 void AppRemotingLatencyTestFixture::HostMessageReceived( |
| 103 const protocol::ExtensionMessage& message) { | 102 const protocol::ExtensionMessage& message) { |
| 104 if (!host_message_received_callback_.is_null()) { | 103 if (!host_message_received_callback_.is_null()) { |
| 105 host_message_received_callback_.Run(message); | 104 host_message_received_callback_.Run(message); |
| 106 } | 105 } |
| 107 } | 106 } |
| 108 | 107 |
| 109 void AppRemotingLatencyTestFixture::PressKey(uint32_t usb_keycode, | 108 void AppRemotingLatencyTestFixture::PressKey(ui::DomCode dom_code, |
| 110 bool pressed) { | 109 bool pressed) { |
| 111 remoting::protocol::KeyEvent event; | 110 remoting::protocol::KeyEvent event; |
| 112 event.set_usb_keycode(usb_keycode); | 111 event.set_usb_keycode(static_cast<unsigned int>(dom_code)); |
| 113 event.set_pressed(pressed); | 112 event.set_pressed(pressed); |
| 114 connection_helper_->input_stub()->InjectKeyEvent(event); | 113 connection_helper_->input_stub()->InjectKeyEvent(event); |
| 115 } | 114 } |
| 116 | 115 |
| 117 void AppRemotingLatencyTestFixture::PressAndReleaseKey(uint32_t usb_keycode) { | 116 void AppRemotingLatencyTestFixture::PressAndReleaseKey(ui::DomCode dom_code) { |
| 118 PressKey(usb_keycode, true); | 117 PressKey(dom_code, true); |
| 119 PressKey(usb_keycode, false); | 118 PressKey(dom_code, false); |
| 120 } | 119 } |
| 121 | 120 |
| 122 void AppRemotingLatencyTestFixture::PressAndReleaseKeyCombination( | 121 void AppRemotingLatencyTestFixture::PressAndReleaseKeyCombination( |
| 123 const std::vector<uint32_t>& usb_keycodes) { | 122 const std::vector<ui::DomCode>& dom_codes) { |
| 124 for (std::vector<uint32_t>::const_iterator iter = usb_keycodes.begin(); | 123 for (auto iter = dom_codes.begin(); iter != dom_codes.end(); ++iter) { |
| 125 iter != usb_keycodes.end(); ++iter) { | |
| 126 PressKey(*iter, true); | 124 PressKey(*iter, true); |
| 127 } | 125 } |
| 128 for (std::vector<uint32_t>::const_reverse_iterator iter = | 126 for (auto iter = dom_codes.rbegin(); iter != dom_codes.rend(); ++iter) { |
| 129 usb_keycodes.rbegin(); | |
| 130 iter != usb_keycodes.rend(); ++iter) { | |
| 131 PressKey(*iter, false); | 127 PressKey(*iter, false); |
| 132 } | 128 } |
| 133 } | 129 } |
| 134 | 130 |
| 135 void AppRemotingLatencyTestFixture::SetHostMessageReceivedCallback( | 131 void AppRemotingLatencyTestFixture::SetHostMessageReceivedCallback( |
| 136 const HostMessageReceivedCallback& host_message_received_callback) { | 132 const HostMessageReceivedCallback& host_message_received_callback) { |
| 137 host_message_received_callback_ = host_message_received_callback; | 133 host_message_received_callback_ = host_message_received_callback; |
| 138 } | 134 } |
| 139 | 135 |
| 140 void AppRemotingLatencyTestFixture::ResetHostMessageReceivedCallback() { | 136 void AppRemotingLatencyTestFixture::ResetHostMessageReceivedCallback() { |
| 141 host_message_received_callback_.Reset(); | 137 host_message_received_callback_.Reset(); |
| 142 } | 138 } |
| 143 | 139 |
| 144 void AppRemotingLatencyTestFixture::ResetApplicationState() { | 140 void AppRemotingLatencyTestFixture::ResetApplicationState() { |
| 145 DCHECK(!timer_->IsRunning()); | 141 DCHECK(!timer_->IsRunning()); |
| 146 DCHECK(!run_loop_ || !run_loop_->running()); | 142 DCHECK(!run_loop_ || !run_loop_->running()); |
| 147 | 143 |
| 148 // Give the app some time to settle before reseting to initial state. | 144 // Give the app some time to settle before reseting to initial state. |
| 149 run_loop_.reset(new base::RunLoop()); | 145 run_loop_.reset(new base::RunLoop()); |
| 150 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 146 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 151 FROM_HERE, run_loop_->QuitClosure(), base::TimeDelta::FromSeconds(1)); | 147 FROM_HERE, run_loop_->QuitClosure(), base::TimeDelta::FromSeconds(1)); |
| 152 run_loop_->Run(); | 148 run_loop_->Run(); |
| 153 | 149 |
| 154 // Press Alt + F4 and wait for amount of time for the input to be delivered | 150 // Press Alt + F4 and wait for amount of time for the input to be delivered |
| 155 // and processed. | 151 // and processed. |
| 156 std::vector<uint32_t> usb_keycodes; | 152 std::vector<ui::DomCode> dom_codes; |
| 157 usb_keycodes.push_back(kUsbLeftAlt); | 153 dom_codes.push_back(ui::DomCode::ALT_LEFT); |
| 158 usb_keycodes.push_back(kUsbF4); | 154 dom_codes.push_back(ui::DomCode::F4); |
| 159 PressAndReleaseKeyCombination(usb_keycodes); | 155 PressAndReleaseKeyCombination(dom_codes); |
| 160 | 156 |
| 161 run_loop_.reset(new base::RunLoop()); | 157 run_loop_.reset(new base::RunLoop()); |
| 162 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 158 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 163 FROM_HERE, run_loop_->QuitClosure(), base::TimeDelta::FromSeconds(2)); | 159 FROM_HERE, run_loop_->QuitClosure(), base::TimeDelta::FromSeconds(2)); |
| 164 run_loop_->Run(); | 160 run_loop_->Run(); |
| 165 | 161 |
| 166 // Press 'N' to choose not save and wait for 1 second for the input to be | 162 // Press 'N' to choose not save and wait for 1 second for the input to be |
| 167 // delivered and processed. | 163 // delivered and processed. |
| 168 PressAndReleaseKey(kUsbN); | 164 PressAndReleaseKey(ui::DomCode::KEY_N); |
| 169 | 165 |
| 170 run_loop_.reset(new base::RunLoop()); | 166 run_loop_.reset(new base::RunLoop()); |
| 171 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 167 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 172 FROM_HERE, run_loop_->QuitClosure(), base::TimeDelta::FromSeconds(2)); | 168 FROM_HERE, run_loop_->QuitClosure(), base::TimeDelta::FromSeconds(2)); |
| 173 run_loop_->Run(); | 169 run_loop_->Run(); |
| 174 run_loop_.reset(); | 170 run_loop_.reset(); |
| 175 } | 171 } |
| 176 | 172 |
| 177 } // namespace test | 173 } // namespace test |
| 178 } // namespace remoting | 174 } // namespace remoting |
| OLD | NEW |