Avi Drissman | d6cdf9b | 2022-09-15 19:52:53 | [diff] [blame^] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 5 | #include "remoting/host/ipc_desktop_environment.h" |
| 6 | |
avi | c5960f3 | 2015-12-22 22:49:48 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 9 | #include <memory> |
sergeyu | 1417e013 | 2015-12-23 19:01:22 | [diff] [blame] | 10 | #include <utility> |
| 11 | |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 12 | #include "base/bind.h" |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 13 | #include "base/callback.h" |
danakj | db9ae794 | 2020-11-11 16:01:35 | [diff] [blame] | 14 | #include "base/callback_helpers.h" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 15 | #include "base/memory/raw_ptr.h" |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 16 | #include "base/memory/ref_counted.h" |
Yuwei Huang | 3628aa5 | 2021-12-08 23:00:55 | [diff] [blame] | 17 | #include "base/memory/weak_ptr.h" |
Carlos Caballero | dd8bf7b04 | 2019-07-30 14:14:15 | [diff] [blame] | 18 | #include "base/message_loop/message_pump_type.h" |
[email protected] | f090f581 | 2013-07-23 14:49:46 | [diff] [blame] | 19 | #include "base/process/process.h" |
| 20 | #include "base/process/process_handle.h" |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 21 | #include "base/run_loop.h" |
Patrick Monette | 643cdf6 | 2021-10-15 19:13:42 | [diff] [blame] | 22 | #include "base/task/single_thread_task_runner.h" |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 23 | #include "base/test/gmock_callback_support.h" |
| 24 | #include "base/test/mock_callback.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 25 | #include "base/test/task_environment.h" |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 26 | #include "base/threading/sequenced_task_runner_handle.h" |
avi | c5960f3 | 2015-12-22 22:49:48 | [diff] [blame] | 27 | #include "build/build_config.h" |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 28 | #include "ipc/ipc_channel.h" |
| 29 | #include "ipc/ipc_channel_proxy.h" |
| 30 | #include "ipc/ipc_listener.h" |
| 31 | #include "ipc/ipc_message.h" |
| 32 | #include "ipc/ipc_platform_file.h" |
Joe Downing | 185945a | 2022-02-15 18:57:19 | [diff] [blame] | 33 | #include "mojo/public/cpp/system/message_pipe.h" |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 34 | #include "remoting/base/auto_thread.h" |
| 35 | #include "remoting/base/auto_thread_task_runner.h" |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 36 | #include "remoting/base/constants.h" |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 37 | #include "remoting/host/desktop_process.h" |
[email protected] | e36460f | 2013-03-08 09:29:32 | [diff] [blame] | 38 | #include "remoting/host/desktop_session.h" |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 39 | #include "remoting/host/desktop_session_connector.h" |
| 40 | #include "remoting/host/desktop_session_proxy.h" |
Erik Jensen | c08ecf11 | 2019-12-19 00:29:49 | [diff] [blame] | 41 | #include "remoting/host/fake_keyboard_layout_monitor.h" |
[email protected] | 2001320 | 2014-08-08 06:33:50 | [diff] [blame] | 42 | #include "remoting/host/fake_mouse_cursor_monitor.h" |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 43 | #include "remoting/host/host_mock_objects.h" |
Joe Downing | d4d6f34 | 2021-09-23 22:12:09 | [diff] [blame] | 44 | #include "remoting/host/mojom/desktop_session.mojom.h" |
sergeyu | 4d20800 | 2015-11-23 22:27:43 | [diff] [blame] | 45 | #include "remoting/protocol/fake_desktop_capturer.h" |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 46 | #include "remoting/protocol/protocol_mock_objects.h" |
rkuroiwa | d11ebf0 | 2015-03-06 01:31:45 | [diff] [blame] | 47 | #include "remoting/protocol/test_event_matchers.h" |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 48 | #include "testing/gmock/include/gmock/gmock.h" |
| 49 | #include "testing/gtest/include/gtest/gtest.h" |
zijiehe | a69c784 | 2016-11-11 01:28:20 | [diff] [blame] | 50 | #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 51 | #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
| 52 | #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 53 | |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 54 | using base::test::RunCallback; |
| 55 | using base::test::RunOnceCallback; |
| 56 | using base::test::RunOnceClosure; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 57 | using testing::_; |
| 58 | using testing::AnyNumber; |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 59 | using testing::AtLeast; |
[email protected] | a5d181f | 2013-04-19 14:55:37 | [diff] [blame] | 60 | using testing::AtMost; |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 61 | using testing::ByMove; |
[email protected] | c4d9d29 | 2013-05-16 18:31:10 | [diff] [blame] | 62 | using testing::DeleteArg; |
| 63 | using testing::DoAll; |
rkuroiwa | d11ebf0 | 2015-03-06 01:31:45 | [diff] [blame] | 64 | using testing::InSequence; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 65 | using testing::Return; |
[email protected] | 231316a | 2013-03-25 06:01:12 | [diff] [blame] | 66 | using testing::ReturnRef; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 67 | |
| 68 | namespace remoting { |
| 69 | |
rkuroiwa | 2933366 | 2015-03-13 17:21:11 | [diff] [blame] | 70 | using protocol::test::EqualsTouchEvent; |
| 71 | using protocol::test::EqualsTouchEventTypeAndId; |
| 72 | |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 73 | using SetUpUrlForwarderResponse = |
| 74 | protocol::UrlForwarderControl::SetUpUrlForwarderResponse; |
| 75 | |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 76 | namespace { |
| 77 | |
zijiehe | a69c784 | 2016-11-11 01:28:20 | [diff] [blame] | 78 | class MockScreenCapturerCallback : public webrtc::DesktopCapturer::Callback { |
sergeyu | 1e5d35af | 2016-06-07 21:43:01 | [diff] [blame] | 79 | public: |
Chris Watkins | 6fe52aa | 2017-11-28 03:24:05 | [diff] [blame] | 80 | MockScreenCapturerCallback() = default; |
Peter Boström | e9178e4 | 2021-09-22 18:11:49 | [diff] [blame] | 81 | |
| 82 | MockScreenCapturerCallback(const MockScreenCapturerCallback&) = delete; |
| 83 | MockScreenCapturerCallback& operator=(const MockScreenCapturerCallback&) = |
| 84 | delete; |
| 85 | |
Daniel Cheng | 8b41cd28 | 2018-04-26 20:41:15 | [diff] [blame] | 86 | ~MockScreenCapturerCallback() override = default; |
sergeyu | 1e5d35af | 2016-06-07 21:43:01 | [diff] [blame] | 87 | |
Joe Downing | d198b51 | 2022-02-25 14:46:48 | [diff] [blame] | 88 | MOCK_METHOD(void, |
| 89 | OnCaptureResultPtr, |
| 90 | (webrtc::DesktopCapturer::Result, |
| 91 | std::unique_ptr<webrtc::DesktopFrame>*)); |
sergeyu | 546cbaa | 2016-06-17 20:39:32 | [diff] [blame] | 92 | void OnCaptureResult(webrtc::DesktopCapturer::Result result, |
| 93 | std::unique_ptr<webrtc::DesktopFrame> frame) override { |
| 94 | OnCaptureResultPtr(result, &frame); |
| 95 | } |
sergeyu | 1e5d35af | 2016-06-07 21:43:01 | [diff] [blame] | 96 | }; |
| 97 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 98 | // Receives messages sent from the desktop process to the daemon. |
Joe Downing | d4d6f34 | 2021-09-23 22:12:09 | [diff] [blame] | 99 | class MockDaemonListener : public IPC::Listener, |
| 100 | public mojom::DesktopSessionRequestHandler { |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 101 | public: |
Chris Watkins | 6fe52aa | 2017-11-28 03:24:05 | [diff] [blame] | 102 | MockDaemonListener() = default; |
Peter Boström | e9178e4 | 2021-09-22 18:11:49 | [diff] [blame] | 103 | |
| 104 | MockDaemonListener(const MockDaemonListener&) = delete; |
| 105 | MockDaemonListener& operator=(const MockDaemonListener&) = delete; |
| 106 | |
Chris Watkins | 6fe52aa | 2017-11-28 03:24:05 | [diff] [blame] | 107 | ~MockDaemonListener() override = default; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 108 | |
nick | 697f429 | 2015-04-23 18:22:31 | [diff] [blame] | 109 | bool OnMessageReceived(const IPC::Message& message) override; |
Joe Downing | d4d6f34 | 2021-09-23 22:12:09 | [diff] [blame] | 110 | void OnAssociatedInterfaceRequest( |
| 111 | const std::string& interface_name, |
| 112 | mojo::ScopedInterfaceEndpointHandle handle) override; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 113 | |
Joe Downing | d4d6f34 | 2021-09-23 22:12:09 | [diff] [blame] | 114 | MOCK_METHOD(void, |
| 115 | ConnectDesktopChannel, |
| 116 | (mojo::ScopedMessagePipeHandle handle), |
| 117 | (override)); |
| 118 | MOCK_METHOD(void, InjectSecureAttentionSequence, (), (override)); |
| 119 | MOCK_METHOD(void, CrashNetworkProcess, (), (override)); |
| 120 | MOCK_METHOD(void, OnChannelConnected, (int32_t), (override)); |
| 121 | MOCK_METHOD(void, OnChannelError, (), (override)); |
| 122 | |
| 123 | void Disconnect(); |
| 124 | |
| 125 | private: |
| 126 | mojo::AssociatedReceiver<mojom::DesktopSessionRequestHandler> |
| 127 | desktop_session_request_handler_{this}; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 128 | }; |
| 129 | |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 130 | bool MockDaemonListener::OnMessageReceived(const IPC::Message& message) { |
Joe Downing | d4d6f34 | 2021-09-23 22:12:09 | [diff] [blame] | 131 | ADD_FAILURE() << "Unexpected call to OnMessageReceived()"; |
| 132 | return false; |
| 133 | } |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 134 | |
Joe Downing | d4d6f34 | 2021-09-23 22:12:09 | [diff] [blame] | 135 | void MockDaemonListener::OnAssociatedInterfaceRequest( |
| 136 | const std::string& interface_name, |
| 137 | mojo::ScopedInterfaceEndpointHandle handle) { |
| 138 | EXPECT_EQ(mojom::DesktopSessionRequestHandler::Name_, interface_name); |
| 139 | mojo::PendingAssociatedReceiver<mojom::DesktopSessionRequestHandler> |
| 140 | pending_receiver(std::move(handle)); |
| 141 | desktop_session_request_handler_.Bind(std::move(pending_receiver)); |
| 142 | } |
| 143 | |
| 144 | void MockDaemonListener::Disconnect() { |
| 145 | desktop_session_request_handler_.reset(); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 146 | } |
| 147 | |
Joe Downing | 1437fb7 | 2022-02-16 15:25:26 | [diff] [blame] | 148 | class MockDesktopSessionManager : public mojom::DesktopSessionManager { |
| 149 | public: |
| 150 | MockDesktopSessionManager() = default; |
| 151 | ~MockDesktopSessionManager() override = default; |
| 152 | |
| 153 | void BindNewReceiver( |
| 154 | mojo::PendingAssociatedReceiver<mojom::DesktopSessionManager> receiver); |
| 155 | |
| 156 | // mojom::DesktopSessionManager implementation. |
| 157 | MOCK_METHOD(void, |
| 158 | CreateDesktopSession, |
| 159 | (int, const ScreenResolution&, bool), |
| 160 | (override)); |
| 161 | MOCK_METHOD(void, CloseDesktopSession, (int), (override)); |
| 162 | MOCK_METHOD(void, |
| 163 | SetScreenResolution, |
| 164 | (int, const ScreenResolution&), |
| 165 | (override)); |
| 166 | |
| 167 | private: |
| 168 | mojo::AssociatedReceiver<mojom::DesktopSessionManager> |
| 169 | desktop_session_manager_{this}; |
| 170 | }; |
| 171 | |
| 172 | void MockDesktopSessionManager::BindNewReceiver( |
| 173 | mojo::PendingAssociatedReceiver<mojom::DesktopSessionManager> receiver) { |
| 174 | desktop_session_manager_.reset(); |
| 175 | |
| 176 | // EnableUnassociatedUsage() sets up a private message pipe for the remote / |
| 177 | // receiver pair used in this test which simplifies our test setup and |
| 178 | // doesn't change any behaviors being tested. |
| 179 | receiver.EnableUnassociatedUsage(); |
| 180 | desktop_session_manager_.Bind(std::move(receiver)); |
| 181 | } |
| 182 | |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 183 | } // namespace |
| 184 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 185 | class IpcDesktopEnvironmentTest : public testing::Test { |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 186 | public: |
| 187 | IpcDesktopEnvironmentTest(); |
dcheng | 440d8e1c | 2014-10-28 01:23:15 | [diff] [blame] | 188 | ~IpcDesktopEnvironmentTest() override; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 189 | |
dcheng | 440d8e1c | 2014-10-28 01:23:15 | [diff] [blame] | 190 | void SetUp() override; |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 191 | void TearDown() override; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 192 | |
Joe Downing | 1437fb7 | 2022-02-16 15:25:26 | [diff] [blame] | 193 | void CreateDesktopSession(int terminal_id, |
| 194 | const ScreenResolution& resolution, |
| 195 | bool virtual_terminal); |
| 196 | void CloseDesktopSession(int terminal_id); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 197 | |
[email protected] | 4e719f4 | 2014-08-12 18:04:37 | [diff] [blame] | 198 | // Creates a DesktopEnvironment with a fake webrtc::DesktopCapturer, to mock |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 199 | // DesktopEnvironmentFactory::Create(). |
Lambros Lambrou | a4a259e | 2022-02-11 05:07:58 | [diff] [blame] | 200 | std::unique_ptr<DesktopEnvironment> CreateDesktopEnvironment(); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 201 | |
Lambros Lambrou | a4a259e | 2022-02-11 05:07:58 | [diff] [blame] | 202 | // Creates a fake InputInjector, to mock |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 203 | // DesktopEnvironment::CreateInputInjector(). |
Lambros Lambrou | a4a259e | 2022-02-11 05:07:58 | [diff] [blame] | 204 | std::unique_ptr<InputInjector> CreateInputInjector(); |
Erik Jensen | c08ecf11 | 2019-12-19 00:29:49 | [diff] [blame] | 205 | |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 206 | void DeleteDesktopEnvironment(); |
| 207 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 208 | // Forwards |event| to |clipboard_stub_|. |
| 209 | void ReflectClipboardEvent(const protocol::ClipboardEvent& event); |
| 210 | |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 211 | protected: |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 212 | // Creates and starts an instance of desktop process object. |
| 213 | void CreateDesktopProcess(); |
| 214 | |
| 215 | // Destroys the desktop process object created by CreateDesktopProcess(). |
Joe Downing | 28a8fd0 | 2022-01-26 21:08:19 | [diff] [blame] | 216 | void DestroyDesktopProcess(); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 217 | |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 218 | // Creates a new remote URL forwarder configurator for the desktop process. |
| 219 | void ResetRemoteUrlForwarderConfigurator(); |
| 220 | |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 221 | void OnDisconnectCallback(); |
| 222 | |
Joe Downing | d4d6f34 | 2021-09-23 22:12:09 | [diff] [blame] | 223 | // Invoked when ConnectDesktopChannel() is called over IPC. |
| 224 | void ConnectDesktopChannel(mojo::ScopedMessagePipeHandle desktop_pipe); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 225 | |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 226 | // Runs until there are no references to |task_runner_|. Calls after the main |
| 227 | // loop has been run are no-op. |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 228 | void RunMainLoopUntilDone(); |
| 229 | |
Joe Downing | 28a8fd0 | 2022-01-26 21:08:19 | [diff] [blame] | 230 | // Some tests require |setup_run_loop_| to be reset so we need a method which |
| 231 | // can be bound that will quit the current run loop. |
| 232 | void QuitSetupRunLoop(); |
| 233 | |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 234 | base::test::TaskEnvironment task_environment_{ |
| 235 | base::test::TaskEnvironment::MainThreadType::UI}; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 236 | |
| 237 | // Runs until |desktop_session_proxy_| is connected to the desktop. |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 238 | std::unique_ptr<base::RunLoop> setup_run_loop_; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 239 | |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 240 | scoped_refptr<AutoThreadTaskRunner> task_runner_; |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 241 | scoped_refptr<AutoThreadTaskRunner> io_task_runner_; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 242 | |
[email protected] | 231316a | 2013-03-25 06:01:12 | [diff] [blame] | 243 | std::string client_jid_; |
| 244 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 245 | // Clipboard stub that receives clipboard events from the desktop process. |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 246 | raw_ptr<protocol::ClipboardStub> clipboard_stub_; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 247 | |
| 248 | // The daemons's end of the daemon-to-desktop channel. |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 249 | std::unique_ptr<IPC::ChannelProxy> desktop_channel_; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 250 | |
Joe Downing | 1437fb7 | 2022-02-16 15:25:26 | [diff] [blame] | 251 | MockDesktopSessionManager mock_desktop_session_manager_; |
| 252 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 253 | // Delegate that is passed to |desktop_channel_|. |
| 254 | MockDaemonListener desktop_listener_; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 255 | |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 256 | std::unique_ptr<IpcDesktopEnvironmentFactory> desktop_environment_factory_; |
| 257 | std::unique_ptr<DesktopEnvironment> desktop_environment_; |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 258 | |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 259 | // The IPC input injector. |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 260 | std::unique_ptr<InputInjector> input_injector_; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 261 | |
[email protected] | e3cab67 | 2013-05-31 02:20:29 | [diff] [blame] | 262 | // The IPC screen controls. |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 263 | std::unique_ptr<ScreenControls> screen_controls_; |
[email protected] | e3cab67 | 2013-05-31 02:20:29 | [diff] [blame] | 264 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 265 | // The IPC screen capturer. |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 266 | std::unique_ptr<webrtc::DesktopCapturer> video_capturer_; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 267 | |
| 268 | // Represents the desktop process running in a user session. |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 269 | std::unique_ptr<DesktopProcess> desktop_process_; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 270 | |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 271 | // Input injector owned by |desktop_process_|. |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 272 | raw_ptr<MockInputInjector> remote_input_injector_; |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 273 | |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 274 | // Will be transferred to the caller of |
| 275 | // MockDesktopEnvironment::CreateUrlForwarderConfigurator(). |
| 276 | // We create the configurator in advance to allow setting expectations before |
| 277 | // the desktop process is being created, during which the configurator will be |
| 278 | // used. |
| 279 | std::unique_ptr<MockUrlForwarderConfigurator> |
| 280 | owned_remote_url_forwarder_configurator_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 281 | raw_ptr<MockUrlForwarderConfigurator> remote_url_forwarder_configurator_; |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 282 | std::unique_ptr<UrlForwarderConfigurator> url_forwarder_configurator_; |
| 283 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 284 | // The last |terminal_id| passed to ConnectTermina(); |
| 285 | int terminal_id_; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 286 | |
sergeyu | 1e5d35af | 2016-06-07 21:43:01 | [diff] [blame] | 287 | MockScreenCapturerCallback desktop_capturer_callback_; |
[email protected] | 231316a | 2013-03-25 06:01:12 | [diff] [blame] | 288 | |
| 289 | MockClientSessionControl client_session_control_; |
| 290 | base::WeakPtrFactory<ClientSessionControl> client_session_control_factory_; |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 291 | |
Yuwei Huang | 3628aa5 | 2021-12-08 23:00:55 | [diff] [blame] | 292 | MockClientSessionEvents client_session_events_; |
| 293 | base::WeakPtrFactory<MockClientSessionEvents> client_session_events_factory_{ |
| 294 | &client_session_events_}; |
| 295 | |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 296 | private: |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 297 | // Runs until there are no references to |task_runner_|. |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 298 | base::RunLoop main_run_loop_; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 299 | }; |
| 300 | |
| 301 | IpcDesktopEnvironmentTest::IpcDesktopEnvironmentTest() |
[email protected] | 166f2ed | 2013-12-19 19:34:00 | [diff] [blame] | 302 | : client_jid_("user@domain/rest-of-jid"), |
sergeyu | c5f104b | 2015-01-09 19:33:24 | [diff] [blame] | 303 | clipboard_stub_(nullptr), |
| 304 | remote_input_injector_(nullptr), |
[email protected] | 231316a | 2013-03-25 06:01:12 | [diff] [blame] | 305 | terminal_id_(-1), |
| 306 | client_session_control_factory_(&client_session_control_) { |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 307 | } |
| 308 | |
Chris Watkins | 6fe52aa | 2017-11-28 03:24:05 | [diff] [blame] | 309 | IpcDesktopEnvironmentTest::~IpcDesktopEnvironmentTest() = default; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 310 | |
| 311 | void IpcDesktopEnvironmentTest::SetUp() { |
| 312 | // Arrange to run |message_loop_| until no components depend on it. |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 313 | task_runner_ = |
| 314 | new AutoThreadTaskRunner(task_environment_.GetMainThreadTaskRunner(), |
| 315 | main_run_loop_.QuitClosure()); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 316 | |
Carlos Caballero | dd8bf7b04 | 2019-07-30 14:14:15 | [diff] [blame] | 317 | io_task_runner_ = AutoThread::CreateWithType("IPC thread", task_runner_, |
| 318 | base::MessagePumpType::IO); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 319 | |
Peter Boström | 42afa23f | 2021-04-02 22:10:46 | [diff] [blame] | 320 | setup_run_loop_ = std::make_unique<base::RunLoop>(); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 321 | |
| 322 | // Set expectation that the DaemonProcess will send DesktopAttached message |
| 323 | // once it is ready. |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 324 | EXPECT_CALL(desktop_listener_, OnChannelConnected(_)) |
| 325 | .Times(AnyNumber()); |
Joe Downing | d4d6f34 | 2021-09-23 22:12:09 | [diff] [blame] | 326 | EXPECT_CALL(desktop_listener_, ConnectDesktopChannel(_)) |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 327 | .Times(AnyNumber()) |
Joe Downing | d4d6f34 | 2021-09-23 22:12:09 | [diff] [blame] | 328 | .WillRepeatedly([&](mojo::ScopedMessagePipeHandle desktop_pipe) { |
| 329 | ConnectDesktopChannel(std::move(desktop_pipe)); |
| 330 | }); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 331 | EXPECT_CALL(desktop_listener_, OnChannelError()) |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 332 | .Times(AnyNumber()) |
Joe Downing | 28a8fd0 | 2022-01-26 21:08:19 | [diff] [blame] | 333 | .WillOnce( |
| 334 | Invoke(this, &IpcDesktopEnvironmentTest::DestroyDesktopProcess)); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 335 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 336 | // Intercept requests to connect and disconnect a terminal. |
Joe Downing | 1437fb7 | 2022-02-16 15:25:26 | [diff] [blame] | 337 | EXPECT_CALL(mock_desktop_session_manager_, CreateDesktopSession(_, _, _)) |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 338 | .Times(AnyNumber()) |
Joe Downing | 1437fb7 | 2022-02-16 15:25:26 | [diff] [blame] | 339 | .WillRepeatedly( |
| 340 | Invoke(this, &IpcDesktopEnvironmentTest::CreateDesktopSession)); |
| 341 | EXPECT_CALL(mock_desktop_session_manager_, CloseDesktopSession(_)) |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 342 | .Times(AnyNumber()) |
Joe Downing | 1437fb7 | 2022-02-16 15:25:26 | [diff] [blame] | 343 | .WillRepeatedly( |
| 344 | Invoke(this, &IpcDesktopEnvironmentTest::CloseDesktopSession)); |
[email protected] | 691e4b6 | 2013-02-16 20:31:08 | [diff] [blame] | 345 | |
[email protected] | 231316a | 2013-03-25 06:01:12 | [diff] [blame] | 346 | EXPECT_CALL(client_session_control_, client_jid()) |
| 347 | .Times(AnyNumber()) |
| 348 | .WillRepeatedly(ReturnRef(client_jid_)); |
sergeyu | ec77d854 | 2015-11-03 22:31:00 | [diff] [blame] | 349 | EXPECT_CALL(client_session_control_, DisconnectSession(_)) |
[email protected] | 231316a | 2013-03-25 06:01:12 | [diff] [blame] | 350 | .Times(AnyNumber()) |
sergeyu | ec77d854 | 2015-11-03 22:31:00 | [diff] [blame] | 351 | .WillRepeatedly(InvokeWithoutArgs( |
[email protected] | 231316a | 2013-03-25 06:01:12 | [diff] [blame] | 352 | this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
Jamie Walch | 6e3a4229 | 2019-05-03 02:19:21 | [diff] [blame] | 353 | EXPECT_CALL(client_session_control_, OnLocalPointerMoved(_, _)).Times(0); |
[email protected] | 231316a | 2013-03-25 06:01:12 | [diff] [blame] | 354 | EXPECT_CALL(client_session_control_, SetDisableInputs(_)) |
| 355 | .Times(0); |
| 356 | |
Joe Downing | 28a8fd0 | 2022-01-26 21:08:19 | [diff] [blame] | 357 | // Most tests will only call this once but reattach will call multiple times. |
| 358 | EXPECT_CALL(client_session_events_, OnDesktopAttached(_)) |
| 359 | .Times(AnyNumber()) |
| 360 | .WillRepeatedly(InvokeWithoutArgs( |
| 361 | this, &IpcDesktopEnvironmentTest::QuitSetupRunLoop)); |
Joe Downing | 975f211 | 2022-01-28 20:07:42 | [diff] [blame] | 362 | EXPECT_CALL(client_session_events_, OnDesktopDetached()).Times(AnyNumber()); |
Joe Downing | 28a8fd0 | 2022-01-26 21:08:19 | [diff] [blame] | 363 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 364 | // Create a desktop environment instance. |
Joe Downing | 1437fb7 | 2022-02-16 15:25:26 | [diff] [blame] | 365 | mojo::AssociatedRemote<mojom::DesktopSessionManager> remote; |
| 366 | mock_desktop_session_manager_.BindNewReceiver( |
| 367 | remote.BindNewEndpointAndPassReceiver()); |
Peter Boström | 42afa23f | 2021-04-02 22:10:46 | [diff] [blame] | 368 | desktop_environment_factory_ = std::make_unique<IpcDesktopEnvironmentFactory>( |
Joe Downing | 1437fb7 | 2022-02-16 15:25:26 | [diff] [blame] | 369 | task_runner_, task_runner_, io_task_runner_, std::move(remote)); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 370 | desktop_environment_ = desktop_environment_factory_->Create( |
zijiehe | 4aa6ea4 | 2016-11-12 01:28:16 | [diff] [blame] | 371 | client_session_control_factory_.GetWeakPtr(), |
Yuwei Huang | 3628aa5 | 2021-12-08 23:00:55 | [diff] [blame] | 372 | client_session_events_factory_.GetWeakPtr(), DesktopEnvironmentOptions()); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 373 | |
[email protected] | e3cab67 | 2013-05-31 02:20:29 | [diff] [blame] | 374 | screen_controls_ = desktop_environment_->CreateScreenControls(); |
| 375 | |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 376 | // Create the input injector. |
[email protected] | 231316a | 2013-03-25 06:01:12 | [diff] [blame] | 377 | input_injector_ = desktop_environment_->CreateInputInjector(); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 378 | |
| 379 | // Create the screen capturer. |
Joe Downing | e910cf9 | 2022-09-14 22:20:44 | [diff] [blame] | 380 | video_capturer_ = desktop_environment_->CreateVideoCapturer(); |
[email protected] | a5d181f | 2013-04-19 14:55:37 | [diff] [blame] | 381 | |
| 382 | desktop_environment_->SetCapabilities(std::string()); |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 383 | |
| 384 | url_forwarder_configurator_ = |
| 385 | desktop_environment_->CreateUrlForwarderConfigurator(); |
| 386 | ResetRemoteUrlForwarderConfigurator(); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 387 | } |
| 388 | |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 389 | void IpcDesktopEnvironmentTest::TearDown() { |
| 390 | RunMainLoopUntilDone(); |
| 391 | } |
| 392 | |
Joe Downing | 1437fb7 | 2022-02-16 15:25:26 | [diff] [blame] | 393 | void IpcDesktopEnvironmentTest::CreateDesktopSession( |
[email protected] | e36460f | 2013-03-08 09:29:32 | [diff] [blame] | 394 | int terminal_id, |
[email protected] | 739e280 | 2013-03-18 01:03:48 | [diff] [blame] | 395 | const ScreenResolution& resolution, |
[email protected] | e36460f | 2013-03-08 09:29:32 | [diff] [blame] | 396 | bool virtual_terminal) { |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 397 | EXPECT_NE(terminal_id_, terminal_id); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 398 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 399 | terminal_id_ = terminal_id; |
| 400 | CreateDesktopProcess(); |
| 401 | } |
| 402 | |
Joe Downing | 1437fb7 | 2022-02-16 15:25:26 | [diff] [blame] | 403 | void IpcDesktopEnvironmentTest::CloseDesktopSession(int terminal_id) { |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 404 | EXPECT_EQ(terminal_id_, terminal_id); |
| 405 | |
| 406 | // The IPC desktop environment is fully destroyed now. Release the remaining |
| 407 | // task runners. |
| 408 | desktop_environment_factory_.reset(); |
| 409 | } |
| 410 | |
Lambros Lambrou | a4a259e | 2022-02-11 05:07:58 | [diff] [blame] | 411 | std::unique_ptr<DesktopEnvironment> |
| 412 | IpcDesktopEnvironmentTest::CreateDesktopEnvironment() { |
| 413 | auto desktop_environment = std::make_unique<MockDesktopEnvironment>(); |
| 414 | EXPECT_CALL(*desktop_environment, CreateAudioCapturer()).Times(0); |
| 415 | EXPECT_CALL(*desktop_environment, CreateInputInjector()) |
[email protected] | a5d181f | 2013-04-19 14:55:37 | [diff] [blame] | 416 | .Times(AtMost(1)) |
Lambros Lambrou | a4a259e | 2022-02-11 05:07:58 | [diff] [blame] | 417 | .WillOnce(Invoke(this, &IpcDesktopEnvironmentTest::CreateInputInjector)); |
| 418 | EXPECT_CALL(*desktop_environment, CreateScreenControls()).Times(AtMost(1)); |
Joe Downing | e910cf9 | 2022-09-14 22:20:44 | [diff] [blame] | 419 | EXPECT_CALL(*desktop_environment, CreateVideoCapturer()) |
[email protected] | a5d181f | 2013-04-19 14:55:37 | [diff] [blame] | 420 | .Times(AtMost(1)) |
Lambros Lambrou | a4a259e | 2022-02-11 05:07:58 | [diff] [blame] | 421 | .WillOnce( |
| 422 | Return(ByMove(std::make_unique<protocol::FakeDesktopCapturer>()))); |
| 423 | EXPECT_CALL(*desktop_environment, CreateActionExecutor()).Times(AtMost(1)); |
| 424 | EXPECT_CALL(*desktop_environment, CreateFileOperations()).Times(AtMost(1)); |
Joe Downing | e910cf9 | 2022-09-14 22:20:44 | [diff] [blame] | 425 | EXPECT_CALL(*desktop_environment, CreateMouseCursorMonitor()) |
[email protected] | 2001320 | 2014-08-08 06:33:50 | [diff] [blame] | 426 | .Times(AtMost(1)) |
Lambros Lambrou | a4a259e | 2022-02-11 05:07:58 | [diff] [blame] | 427 | .WillOnce(Return(ByMove(std::make_unique<FakeMouseCursorMonitor>()))); |
| 428 | EXPECT_CALL(*desktop_environment, CreateKeyboardLayoutMonitor(_)) |
Erik Jensen | c08ecf11 | 2019-12-19 00:29:49 | [diff] [blame] | 429 | .Times(AtMost(1)) |
Lambros Lambrou | a4a259e | 2022-02-11 05:07:58 | [diff] [blame] | 430 | .WillOnce(Return(ByMove(std::make_unique<FakeKeyboardLayoutMonitor>()))); |
[email protected] | a5d181f | 2013-04-19 14:55:37 | [diff] [blame] | 431 | EXPECT_CALL(*desktop_environment, GetCapabilities()) |
| 432 | .Times(AtMost(1)); |
| 433 | EXPECT_CALL(*desktop_environment, SetCapabilities(_)) |
| 434 | .Times(AtMost(1)); |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 435 | DCHECK(owned_remote_url_forwarder_configurator_); |
| 436 | EXPECT_CALL(*desktop_environment, CreateUrlForwarderConfigurator()) |
| 437 | .Times(AtMost(1)) |
| 438 | .WillOnce( |
| 439 | Return(ByMove(std::move(owned_remote_url_forwarder_configurator_)))); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 440 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 441 | return desktop_environment; |
| 442 | } |
| 443 | |
Lambros Lambrou | a4a259e | 2022-02-11 05:07:58 | [diff] [blame] | 444 | std::unique_ptr<InputInjector> |
| 445 | IpcDesktopEnvironmentTest::CreateInputInjector() { |
| 446 | auto remote_input_injector = |
| 447 | std::make_unique<testing::StrictMock<MockInputInjector>>(); |
sergeyu | c5f104b | 2015-01-09 19:33:24 | [diff] [blame] | 448 | EXPECT_TRUE(remote_input_injector_ == nullptr); |
Lambros Lambrou | a4a259e | 2022-02-11 05:07:58 | [diff] [blame] | 449 | remote_input_injector_ = remote_input_injector.get(); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 450 | |
Lambros Lambrou | a4a259e | 2022-02-11 05:07:58 | [diff] [blame] | 451 | EXPECT_CALL(*remote_input_injector_, Start(_)); |
| 452 | return remote_input_injector; |
Erik Jensen | c08ecf11 | 2019-12-19 00:29:49 | [diff] [blame] | 453 | } |
| 454 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 455 | void IpcDesktopEnvironmentTest::DeleteDesktopEnvironment() { |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 456 | input_injector_.reset(); |
[email protected] | e3cab67 | 2013-05-31 02:20:29 | [diff] [blame] | 457 | screen_controls_.reset(); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 458 | video_capturer_.reset(); |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 459 | url_forwarder_configurator_.reset(); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 460 | |
Joe Downing | 1437fb7 | 2022-02-16 15:25:26 | [diff] [blame] | 461 | // Trigger CloseDesktopSession(). |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 462 | desktop_environment_.reset(); |
| 463 | } |
| 464 | |
| 465 | void IpcDesktopEnvironmentTest::ReflectClipboardEvent( |
| 466 | const protocol::ClipboardEvent& event) { |
| 467 | clipboard_stub_->InjectClipboardEvent(event); |
| 468 | } |
| 469 | |
| 470 | void IpcDesktopEnvironmentTest::CreateDesktopProcess() { |
[email protected] | f9d8a77 | 2013-06-01 04:33:17 | [diff] [blame] | 471 | EXPECT_TRUE(task_runner_.get()); |
| 472 | EXPECT_TRUE(io_task_runner_.get()); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 473 | |
| 474 | // Create the daemon end of the daemon-to-desktop channel. |
sammc | 34c69a1 | 2016-10-27 22:43:37 | [diff] [blame] | 475 | mojo::MessagePipe pipe; |
erikchen | 30dc281 | 2015-09-24 03:26:38 | [diff] [blame] | 476 | desktop_channel_ = IPC::ChannelProxy::Create( |
sammc | 34c69a1 | 2016-10-27 22:43:37 | [diff] [blame] | 477 | pipe.handle0.release(), IPC::Channel::MODE_SERVER, &desktop_listener_, |
Hajime Hoshi | ff15e97 | 2017-11-09 06:37:09 | [diff] [blame] | 478 | io_task_runner_.get(), base::ThreadTaskRunnerHandle::Get()); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 479 | |
[email protected] | 691e4b6 | 2013-02-16 20:31:08 | [diff] [blame] | 480 | // Create and start the desktop process. |
Peter Boström | 42afa23f | 2021-04-02 22:10:46 | [diff] [blame] | 481 | desktop_process_ = std::make_unique<DesktopProcess>( |
| 482 | task_runner_, io_task_runner_, io_task_runner_, std::move(pipe.handle1)); |
[email protected] | 691e4b6 | 2013-02-16 20:31:08 | [diff] [blame] | 483 | |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 484 | std::unique_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory( |
[email protected] | 691e4b6 | 2013-02-16 20:31:08 | [diff] [blame] | 485 | new MockDesktopEnvironmentFactory()); |
Lambros Lambrou | a4a259e | 2022-02-11 05:07:58 | [diff] [blame] | 486 | EXPECT_CALL(*desktop_environment_factory, Create(_, _, _)) |
[email protected] | 691e4b6 | 2013-02-16 20:31:08 | [diff] [blame] | 487 | .Times(AnyNumber()) |
Lambros Lambrou | a4a259e | 2022-02-11 05:07:58 | [diff] [blame] | 488 | .WillRepeatedly( |
| 489 | Invoke(this, &IpcDesktopEnvironmentTest::CreateDesktopEnvironment)); |
[email protected] | 691e4b6 | 2013-02-16 20:31:08 | [diff] [blame] | 490 | EXPECT_CALL(*desktop_environment_factory, SupportsAudioCapture()) |
| 491 | .Times(AnyNumber()) |
| 492 | .WillRepeatedly(Return(false)); |
| 493 | |
sergeyu | 1417e013 | 2015-12-23 19:01:22 | [diff] [blame] | 494 | EXPECT_TRUE(desktop_process_->Start(std::move(desktop_environment_factory))); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 495 | } |
| 496 | |
Joe Downing | 28a8fd0 | 2022-01-26 21:08:19 | [diff] [blame] | 497 | void IpcDesktopEnvironmentTest::DestroyDesktopProcess() { |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 498 | desktop_channel_.reset(); |
| 499 | if (desktop_process_) { |
| 500 | desktop_process_->OnChannelError(); |
| 501 | desktop_process_.reset(); |
| 502 | } |
Joe Downing | d4d6f34 | 2021-09-23 22:12:09 | [diff] [blame] | 503 | desktop_listener_.Disconnect(); |
sergeyu | c5f104b | 2015-01-09 19:33:24 | [diff] [blame] | 504 | remote_input_injector_ = nullptr; |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 505 | } |
| 506 | |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 507 | void IpcDesktopEnvironmentTest::ResetRemoteUrlForwarderConfigurator() { |
| 508 | owned_remote_url_forwarder_configurator_ = |
| 509 | std::make_unique<MockUrlForwarderConfigurator>(); |
| 510 | remote_url_forwarder_configurator_ = |
| 511 | owned_remote_url_forwarder_configurator_.get(); |
| 512 | ON_CALL(*remote_url_forwarder_configurator_, IsUrlForwarderSetUp(_)) |
| 513 | .WillByDefault(RunOnceCallback<0>(false)); |
| 514 | } |
| 515 | |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 516 | void IpcDesktopEnvironmentTest::OnDisconnectCallback() { |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 517 | DeleteDesktopEnvironment(); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 518 | } |
| 519 | |
Joe Downing | d4d6f34 | 2021-09-23 22:12:09 | [diff] [blame] | 520 | void IpcDesktopEnvironmentTest::ConnectDesktopChannel( |
| 521 | mojo::ScopedMessagePipeHandle desktop_pipe) { |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 522 | // Instruct DesktopSessionProxy to connect to the network-to-desktop pipe. |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 523 | desktop_environment_factory_->OnDesktopSessionAgentAttached( |
Joe Downing | 185945a | 2022-02-15 18:57:19 | [diff] [blame] | 524 | terminal_id_, /*session_id=*/0, std::move(desktop_pipe)); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 525 | } |
| 526 | |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 527 | void IpcDesktopEnvironmentTest::RunMainLoopUntilDone() { |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 528 | bool should_run_loop = task_runner_ != nullptr; |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 529 | task_runner_ = nullptr; |
| 530 | io_task_runner_ = nullptr; |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 531 | if (should_run_loop) { |
| 532 | main_run_loop_.Run(); |
| 533 | } |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 534 | } |
| 535 | |
Joe Downing | 28a8fd0 | 2022-01-26 21:08:19 | [diff] [blame] | 536 | void IpcDesktopEnvironmentTest::QuitSetupRunLoop() { |
| 537 | setup_run_loop_->Quit(); |
| 538 | } |
| 539 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 540 | // Runs until the desktop is attached and exits immediately after that. |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 541 | TEST_F(IpcDesktopEnvironmentTest, Basic) { |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 542 | std::unique_ptr<protocol::MockClipboardStub> clipboard_stub( |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 543 | new protocol::MockClipboardStub()); |
| 544 | EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 545 | .Times(0); |
| 546 | |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 547 | // Start the input injector and screen capturer. |
sergeyu | 1417e013 | 2015-12-23 19:01:22 | [diff] [blame] | 548 | input_injector_->Start(std::move(clipboard_stub)); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 549 | |
| 550 | // Run the message loop until the desktop is attached. |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 551 | setup_run_loop_->Run(); |
| 552 | |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 553 | // Stop the test. |
| 554 | DeleteDesktopEnvironment(); |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 555 | } |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 556 | |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 557 | // Check touchEvents capability is set when the desktop environment can |
| 558 | // inject touch events. |
| 559 | TEST_F(IpcDesktopEnvironmentTest, TouchEventsCapabilities) { |
| 560 | // Create an environment with multi touch enabled. |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 561 | desktop_environment_ = desktop_environment_factory_->Create( |
zijiehe | 4aa6ea4 | 2016-11-12 01:28:16 | [diff] [blame] | 562 | client_session_control_factory_.GetWeakPtr(), |
Yuwei Huang | 3628aa5 | 2021-12-08 23:00:55 | [diff] [blame] | 563 | client_session_events_factory_.GetWeakPtr(), DesktopEnvironmentOptions()); |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 564 | |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 565 | std::unique_ptr<protocol::MockClipboardStub> clipboard_stub( |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 566 | new protocol::MockClipboardStub()); |
| 567 | EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 568 | .Times(0); |
| 569 | |
sergeyu | b3e637e | 2016-10-27 23:31:21 | [diff] [blame] | 570 | std::string expected_capabilities = "rateLimitResizeRequests"; |
| 571 | if (InputInjector::SupportsTouchEvents()) |
| 572 | expected_capabilities += " touchEvents"; |
| 573 | |
| 574 | EXPECT_EQ(expected_capabilities, desktop_environment_->GetCapabilities()); |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 575 | |
| 576 | // Start the input injector and screen capturer. |
sergeyu | 1417e013 | 2015-12-23 19:01:22 | [diff] [blame] | 577 | input_injector_->Start(std::move(clipboard_stub)); |
rkuroiwa | a7815e7 | 2015-06-05 21:39:04 | [diff] [blame] | 578 | |
| 579 | // Run the message loop until the desktop is attached. |
| 580 | setup_run_loop_->Run(); |
| 581 | |
| 582 | // Stop the test. |
| 583 | DeleteDesktopEnvironment(); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 584 | } |
| 585 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 586 | // Tests that the video capturer receives a frame over IPC. |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 587 | TEST_F(IpcDesktopEnvironmentTest, CaptureFrame) { |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 588 | std::unique_ptr<protocol::MockClipboardStub> clipboard_stub( |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 589 | new protocol::MockClipboardStub()); |
| 590 | EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 591 | .Times(0); |
| 592 | |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 593 | // Start the input injector and screen capturer. |
sergeyu | 1417e013 | 2015-12-23 19:01:22 | [diff] [blame] | 594 | input_injector_->Start(std::move(clipboard_stub)); |
[email protected] | 4e719f4 | 2014-08-12 18:04:37 | [diff] [blame] | 595 | video_capturer_->Start(&desktop_capturer_callback_); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 596 | |
| 597 | // Run the message loop until the desktop is attached. |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 598 | setup_run_loop_->Run(); |
| 599 | |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 600 | // Stop the test when the first frame is captured. |
sergeyu | 546cbaa | 2016-06-17 20:39:32 | [diff] [blame] | 601 | EXPECT_CALL(desktop_capturer_callback_, OnCaptureResultPtr(_, _)) |
| 602 | .WillOnce(InvokeWithoutArgs( |
| 603 | this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 604 | |
| 605 | // Capture a single frame. |
zijiehe | 27bcc91 | 2016-10-18 05:57:56 | [diff] [blame] | 606 | video_capturer_->CaptureFrame(); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | // Tests that attaching to a new desktop works. |
| 610 | TEST_F(IpcDesktopEnvironmentTest, Reattach) { |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 611 | std::unique_ptr<protocol::MockClipboardStub> clipboard_stub( |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 612 | new protocol::MockClipboardStub()); |
| 613 | EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 614 | .Times(0); |
| 615 | |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 616 | // Start the input injector and screen capturer. |
sergeyu | 1417e013 | 2015-12-23 19:01:22 | [diff] [blame] | 617 | input_injector_->Start(std::move(clipboard_stub)); |
[email protected] | 4e719f4 | 2014-08-12 18:04:37 | [diff] [blame] | 618 | video_capturer_->Start(&desktop_capturer_callback_); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 619 | |
| 620 | // Run the message loop until the desktop is attached. |
| 621 | setup_run_loop_->Run(); |
| 622 | |
| 623 | // Create and start a new desktop process object. |
Peter Boström | 42afa23f | 2021-04-02 22:10:46 | [diff] [blame] | 624 | setup_run_loop_ = std::make_unique<base::RunLoop>(); |
Joe Downing | 28a8fd0 | 2022-01-26 21:08:19 | [diff] [blame] | 625 | DestroyDesktopProcess(); |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 626 | ResetRemoteUrlForwarderConfigurator(); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 627 | CreateDesktopProcess(); |
| 628 | setup_run_loop_->Run(); |
| 629 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 630 | // Stop the test. |
| 631 | DeleteDesktopEnvironment(); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 632 | } |
| 633 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 634 | // Tests injection of clipboard events. |
| 635 | TEST_F(IpcDesktopEnvironmentTest, InjectClipboardEvent) { |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 636 | std::unique_ptr<protocol::MockClipboardStub> clipboard_stub( |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 637 | new protocol::MockClipboardStub()); |
| 638 | clipboard_stub_ = clipboard_stub.get(); |
| 639 | |
| 640 | // Stop the test when a clipboard event is received from the desktop process. |
| 641 | EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 642 | .Times(1) |
| 643 | .WillOnce(InvokeWithoutArgs( |
| 644 | this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| 645 | |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 646 | // Start the input injector and screen capturer. |
sergeyu | 1417e013 | 2015-12-23 19:01:22 | [diff] [blame] | 647 | input_injector_->Start(std::move(clipboard_stub)); |
[email protected] | 4e719f4 | 2014-08-12 18:04:37 | [diff] [blame] | 648 | video_capturer_->Start(&desktop_capturer_callback_); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 649 | |
| 650 | // Run the message loop until the desktop is attached. |
| 651 | setup_run_loop_->Run(); |
| 652 | |
| 653 | // Expect a single clipboard event. |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 654 | EXPECT_CALL(*remote_input_injector_, InjectClipboardEvent(_)) |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 655 | .Times(1) |
| 656 | .WillOnce(Invoke(this, |
| 657 | &IpcDesktopEnvironmentTest::ReflectClipboardEvent)); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 658 | |
| 659 | // Send a clipboard event. |
| 660 | protocol::ClipboardEvent event; |
| 661 | event.set_mime_type(kMimeTypeTextUtf8); |
| 662 | event.set_data("a"); |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 663 | input_injector_->InjectClipboardEvent(event); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | // Tests injection of key events. |
| 667 | TEST_F(IpcDesktopEnvironmentTest, InjectKeyEvent) { |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 668 | std::unique_ptr<protocol::MockClipboardStub> clipboard_stub( |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 669 | new protocol::MockClipboardStub()); |
| 670 | EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 671 | .Times(0); |
| 672 | |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 673 | // Start the input injector and screen capturer. |
sergeyu | 1417e013 | 2015-12-23 19:01:22 | [diff] [blame] | 674 | input_injector_->Start(std::move(clipboard_stub)); |
[email protected] | 4e719f4 | 2014-08-12 18:04:37 | [diff] [blame] | 675 | video_capturer_->Start(&desktop_capturer_callback_); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 676 | |
| 677 | // Run the message loop until the desktop is attached. |
| 678 | setup_run_loop_->Run(); |
| 679 | |
| 680 | // Expect a single key event. |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 681 | EXPECT_CALL(*remote_input_injector_, InjectKeyEvent(_)) |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 682 | .Times(AtLeast(1)) |
| 683 | .WillRepeatedly(InvokeWithoutArgs( |
| 684 | this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 685 | |
| 686 | // Send a key event. |
| 687 | protocol::KeyEvent event; |
| 688 | event.set_usb_keycode(0x070004); |
| 689 | event.set_pressed(true); |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 690 | input_injector_->InjectKeyEvent(event); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 691 | } |
| 692 | |
[email protected] | 529bbd1 | 2014-03-27 20:25:39 | [diff] [blame] | 693 | // Tests injection of text events. |
| 694 | TEST_F(IpcDesktopEnvironmentTest, InjectTextEvent) { |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 695 | std::unique_ptr<protocol::MockClipboardStub> clipboard_stub( |
[email protected] | 529bbd1 | 2014-03-27 20:25:39 | [diff] [blame] | 696 | new protocol::MockClipboardStub()); |
| 697 | EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 698 | .Times(0); |
| 699 | |
| 700 | // Start the input injector and screen capturer. |
sergeyu | 1417e013 | 2015-12-23 19:01:22 | [diff] [blame] | 701 | input_injector_->Start(std::move(clipboard_stub)); |
[email protected] | 4e719f4 | 2014-08-12 18:04:37 | [diff] [blame] | 702 | video_capturer_->Start(&desktop_capturer_callback_); |
[email protected] | 529bbd1 | 2014-03-27 20:25:39 | [diff] [blame] | 703 | |
| 704 | // Run the message loop until the desktop is attached. |
| 705 | setup_run_loop_->Run(); |
| 706 | |
| 707 | // Expect a single text event. |
| 708 | EXPECT_CALL(*remote_input_injector_, InjectTextEvent(_)) |
| 709 | .Times(AtLeast(1)) |
| 710 | .WillRepeatedly(InvokeWithoutArgs( |
| 711 | this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| 712 | |
| 713 | // Send a text event. |
| 714 | protocol::TextEvent event; |
| 715 | event.set_text("hello"); |
| 716 | input_injector_->InjectTextEvent(event); |
[email protected] | 529bbd1 | 2014-03-27 20:25:39 | [diff] [blame] | 717 | } |
| 718 | |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 719 | // Tests injection of mouse events. |
| 720 | TEST_F(IpcDesktopEnvironmentTest, InjectMouseEvent) { |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 721 | std::unique_ptr<protocol::MockClipboardStub> clipboard_stub( |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 722 | new protocol::MockClipboardStub()); |
| 723 | EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 724 | .Times(0); |
| 725 | |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 726 | // Start the input injector and screen capturer. |
sergeyu | 1417e013 | 2015-12-23 19:01:22 | [diff] [blame] | 727 | input_injector_->Start(std::move(clipboard_stub)); |
[email protected] | 4e719f4 | 2014-08-12 18:04:37 | [diff] [blame] | 728 | video_capturer_->Start(&desktop_capturer_callback_); |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 729 | |
| 730 | // Run the message loop until the desktop is attached. |
| 731 | setup_run_loop_->Run(); |
| 732 | |
| 733 | // Expect a single mouse event. |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 734 | EXPECT_CALL(*remote_input_injector_, InjectMouseEvent(_)) |
[email protected] | 73fc557 | 2013-02-20 11:59:37 | [diff] [blame] | 735 | .Times(1) |
| 736 | .WillOnce(InvokeWithoutArgs( |
| 737 | this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| 738 | |
| 739 | // Send a mouse event. |
| 740 | protocol::MouseEvent event; |
| 741 | event.set_x(0); |
| 742 | event.set_y(0); |
[email protected] | b0b72f11 | 2013-03-24 03:42:42 | [diff] [blame] | 743 | input_injector_->InjectMouseEvent(event); |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 744 | } |
| 745 | |
rkuroiwa | d11ebf0 | 2015-03-06 01:31:45 | [diff] [blame] | 746 | // Tests injection of touch events. |
| 747 | TEST_F(IpcDesktopEnvironmentTest, InjectTouchEvent) { |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 748 | std::unique_ptr<protocol::MockClipboardStub> clipboard_stub( |
rkuroiwa | d11ebf0 | 2015-03-06 01:31:45 | [diff] [blame] | 749 | new protocol::MockClipboardStub()); |
| 750 | EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 751 | .Times(0); |
| 752 | |
| 753 | // Start the input injector and screen capturer. |
sergeyu | 1417e013 | 2015-12-23 19:01:22 | [diff] [blame] | 754 | input_injector_->Start(std::move(clipboard_stub)); |
rkuroiwa | d11ebf0 | 2015-03-06 01:31:45 | [diff] [blame] | 755 | video_capturer_->Start(&desktop_capturer_callback_); |
| 756 | |
| 757 | // Run the message loop until the desktop is attached. |
| 758 | setup_run_loop_->Run(); |
| 759 | |
| 760 | protocol::TouchEvent event; |
| 761 | event.set_event_type(protocol::TouchEvent::TOUCH_POINT_START); |
| 762 | protocol::TouchEventPoint* point = event.add_touch_points(); |
| 763 | point->set_id(0u); |
| 764 | point->set_x(0.0f); |
| 765 | point->set_y(0.0f); |
| 766 | point->set_radius_x(0.0f); |
| 767 | point->set_radius_y(0.0f); |
| 768 | point->set_angle(0.0f); |
| 769 | point->set_pressure(0.0f); |
| 770 | |
| 771 | ON_CALL(*remote_input_injector_, InjectTouchEvent(_)) |
| 772 | .WillByDefault(InvokeWithoutArgs( |
| 773 | this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| 774 | |
| 775 | InSequence s; |
| 776 | // Expect that the event gets propagated to remote_input_injector_. |
| 777 | // And one more call for ReleaseAll(). |
| 778 | EXPECT_CALL(*remote_input_injector_, |
rkuroiwa | 2933366 | 2015-03-13 17:21:11 | [diff] [blame] | 779 | InjectTouchEvent(EqualsTouchEvent(event))); |
rkuroiwa | d11ebf0 | 2015-03-06 01:31:45 | [diff] [blame] | 780 | EXPECT_CALL(*remote_input_injector_, |
rkuroiwa | 2933366 | 2015-03-13 17:21:11 | [diff] [blame] | 781 | InjectTouchEvent(EqualsTouchEventTypeAndId( |
| 782 | protocol::TouchEvent::TOUCH_POINT_CANCEL, 0u))); |
rkuroiwa | d11ebf0 | 2015-03-06 01:31:45 | [diff] [blame] | 783 | |
| 784 | // Send the touch event. |
| 785 | input_injector_->InjectTouchEvent(event); |
rkuroiwa | d11ebf0 | 2015-03-06 01:31:45 | [diff] [blame] | 786 | } |
| 787 | |
[email protected] | e3cab67 | 2013-05-31 02:20:29 | [diff] [blame] | 788 | // Tests that setting the desktop resolution works. |
| 789 | TEST_F(IpcDesktopEnvironmentTest, SetScreenResolution) { |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 790 | std::unique_ptr<protocol::MockClipboardStub> clipboard_stub( |
[email protected] | e3cab67 | 2013-05-31 02:20:29 | [diff] [blame] | 791 | new protocol::MockClipboardStub()); |
| 792 | EXPECT_CALL(*clipboard_stub, InjectClipboardEvent(_)) |
| 793 | .Times(0); |
| 794 | |
| 795 | // Start the input injector and screen capturer. |
sergeyu | 1417e013 | 2015-12-23 19:01:22 | [diff] [blame] | 796 | input_injector_->Start(std::move(clipboard_stub)); |
[email protected] | 4e719f4 | 2014-08-12 18:04:37 | [diff] [blame] | 797 | video_capturer_->Start(&desktop_capturer_callback_); |
[email protected] | e3cab67 | 2013-05-31 02:20:29 | [diff] [blame] | 798 | |
| 799 | // Run the message loop until the desktop is attached. |
| 800 | setup_run_loop_->Run(); |
| 801 | |
Joe Downing | 1437fb7 | 2022-02-16 15:25:26 | [diff] [blame] | 802 | EXPECT_CALL(mock_desktop_session_manager_, SetScreenResolution(_, _)) |
[email protected] | e3cab67 | 2013-05-31 02:20:29 | [diff] [blame] | 803 | .Times(1) |
| 804 | .WillOnce(InvokeWithoutArgs( |
| 805 | this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| 806 | |
| 807 | // Change the desktop resolution. |
Lambros Lambrou | ec5f1b0 | 2022-05-20 00:45:53 | [diff] [blame] | 808 | screen_controls_->SetScreenResolution( |
| 809 | ScreenResolution(webrtc::DesktopSize(100, 100), |
| 810 | webrtc::DesktopVector(96, 96)), |
| 811 | absl::nullopt); |
[email protected] | e3cab67 | 2013-05-31 02:20:29 | [diff] [blame] | 812 | } |
| 813 | |
Joe Downing | 975f211 | 2022-01-28 20:07:42 | [diff] [blame] | 814 | TEST_F(IpcDesktopEnvironmentTest, CheckUrlForwarderState) { |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 815 | EXPECT_CALL(*remote_url_forwarder_configurator_, IsUrlForwarderSetUp(_)) |
| 816 | .WillOnce(RunOnceCallback<0>(true)); |
| 817 | base::MockCallback<UrlForwarderConfigurator::IsUrlForwarderSetUpCallback> |
| 818 | callback; |
| 819 | EXPECT_CALL(callback, Run(true)) |
| 820 | .WillOnce([&]() { |
| 821 | // Do it again when the state is already known. |
| 822 | url_forwarder_configurator_->IsUrlForwarderSetUp(callback.Get()); |
| 823 | }) |
| 824 | .WillOnce(InvokeWithoutArgs( |
| 825 | this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| 826 | |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 827 | // Run the message loop until the desktop is attached. |
| 828 | setup_run_loop_->Run(); |
| 829 | |
Joe Downing | 975f211 | 2022-01-28 20:07:42 | [diff] [blame] | 830 | url_forwarder_configurator_->IsUrlForwarderSetUp(callback.Get()); |
| 831 | |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 832 | // Run now rather than in TearDown() so that we can verify |callback|. |
| 833 | RunMainLoopUntilDone(); |
| 834 | } |
| 835 | |
Joe Downing | 975f211 | 2022-01-28 20:07:42 | [diff] [blame] | 836 | TEST_F(IpcDesktopEnvironmentTest, SetUpUrlForwarderHappyPath) { |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 837 | EXPECT_CALL(*remote_url_forwarder_configurator_, IsUrlForwarderSetUp(_)) |
| 838 | .WillOnce(RunOnceCallback<0>(false)); |
| 839 | EXPECT_CALL(*remote_url_forwarder_configurator_, SetUpUrlForwarder(_)) |
| 840 | .WillOnce([](auto& callback) { |
| 841 | callback.Run(SetUpUrlForwarderResponse::USER_INTERVENTION_REQUIRED); |
| 842 | callback.Run(SetUpUrlForwarderResponse::COMPLETE); |
| 843 | }); |
| 844 | base::MockCallback<UrlForwarderConfigurator::SetUpUrlForwarderCallback> |
| 845 | setup_state_callback; |
| 846 | base::MockCallback<UrlForwarderConfigurator::IsUrlForwarderSetUpCallback> |
| 847 | is_set_up_callback; |
| 848 | |
| 849 | { |
| 850 | InSequence s; |
| 851 | |
| 852 | EXPECT_CALL(is_set_up_callback, Run(false)).WillOnce([&]() { |
| 853 | // Post task to prevent reentrant issue. |
| 854 | base::SequencedTaskRunnerHandle::Get()->PostTask( |
| 855 | FROM_HERE, |
| 856 | base::BindOnce(&UrlForwarderConfigurator::SetUpUrlForwarder, |
| 857 | base::Unretained(url_forwarder_configurator_.get()), |
| 858 | setup_state_callback.Get())); |
| 859 | }); |
| 860 | EXPECT_CALL(setup_state_callback, |
| 861 | Run(SetUpUrlForwarderResponse::USER_INTERVENTION_REQUIRED)) |
| 862 | .Times(1); |
| 863 | EXPECT_CALL(setup_state_callback, Run(SetUpUrlForwarderResponse::COMPLETE)) |
| 864 | .WillOnce([&]() { |
| 865 | url_forwarder_configurator_->IsUrlForwarderSetUp( |
| 866 | is_set_up_callback.Get()); |
| 867 | }); |
| 868 | EXPECT_CALL(is_set_up_callback, Run(true)) |
| 869 | .WillOnce(InvokeWithoutArgs( |
| 870 | this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| 871 | } |
| 872 | |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 873 | // Run the message loop until the desktop is attached. |
| 874 | setup_run_loop_->Run(); |
| 875 | |
Joe Downing | 975f211 | 2022-01-28 20:07:42 | [diff] [blame] | 876 | url_forwarder_configurator_->IsUrlForwarderSetUp(is_set_up_callback.Get()); |
| 877 | |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 878 | // Run now rather than in TearDown() so that we can verify |callback|. |
| 879 | RunMainLoopUntilDone(); |
| 880 | } |
| 881 | |
Joe Downing | 975f211 | 2022-01-28 20:07:42 | [diff] [blame] | 882 | TEST_F(IpcDesktopEnvironmentTest, SetUpUrlForwarderFailed) { |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 883 | EXPECT_CALL(*remote_url_forwarder_configurator_, IsUrlForwarderSetUp(_)) |
| 884 | .WillOnce(RunOnceCallback<0>(false)); |
| 885 | EXPECT_CALL(*remote_url_forwarder_configurator_, SetUpUrlForwarder(_)) |
| 886 | .WillOnce(RunOnceCallback<0>(SetUpUrlForwarderResponse::FAILED)); |
| 887 | base::MockCallback<UrlForwarderConfigurator::SetUpUrlForwarderCallback> |
| 888 | setup_state_callback; |
| 889 | base::MockCallback<UrlForwarderConfigurator::IsUrlForwarderSetUpCallback> |
| 890 | is_set_up_callback; |
| 891 | |
| 892 | { |
| 893 | InSequence s; |
| 894 | |
| 895 | EXPECT_CALL(is_set_up_callback, Run(false)).WillOnce([&]() { |
| 896 | // Post task to prevent reentrant issue. |
| 897 | base::SequencedTaskRunnerHandle::Get()->PostTask( |
| 898 | FROM_HERE, |
| 899 | base::BindOnce(&UrlForwarderConfigurator::SetUpUrlForwarder, |
| 900 | base::Unretained(url_forwarder_configurator_.get()), |
| 901 | setup_state_callback.Get())); |
| 902 | }); |
| 903 | EXPECT_CALL(setup_state_callback, Run(SetUpUrlForwarderResponse::FAILED)) |
| 904 | .WillOnce([&]() { |
| 905 | url_forwarder_configurator_->IsUrlForwarderSetUp( |
| 906 | is_set_up_callback.Get()); |
| 907 | }); |
| 908 | EXPECT_CALL(is_set_up_callback, Run(false)) |
| 909 | .WillOnce(InvokeWithoutArgs( |
| 910 | this, &IpcDesktopEnvironmentTest::DeleteDesktopEnvironment)); |
| 911 | } |
| 912 | |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 913 | // Run the message loop until the desktop is attached. |
| 914 | setup_run_loop_->Run(); |
| 915 | |
Joe Downing | 975f211 | 2022-01-28 20:07:42 | [diff] [blame] | 916 | url_forwarder_configurator_->IsUrlForwarderSetUp(is_set_up_callback.Get()); |
| 917 | |
Yuwei Huang | 219fc03 | 2021-09-08 23:15:39 | [diff] [blame] | 918 | // Run now rather than in TearDown() so that we can verify |callback|. |
| 919 | RunMainLoopUntilDone(); |
| 920 | } |
| 921 | |
[email protected] | 5de788d8 | 2013-02-07 05:54:23 | [diff] [blame] | 922 | } // namespace remoting |