1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "session/container/include/zidl/window_event_channel_stub.h"
17 #include "session/container/include/zidl/session_stage_interface.h"
18 #include "session/container/include/zidl/window_event_ipc_interface_code.h"
19 #include "mock/mock_session_stage.h"
20 #include "mock/mock_window_event_channel.h"
21 #include "iremote_object_mocker.h"
22 #include <message_option.h>
23 #include <message_parcel.h>
24 #include <string>
25 #include <gtest/gtest.h>
26 #include <axis_event.h>
27 #include <ipc_types.h>
28 #include <key_event.h>
29 #include <pointer_event.h>
30 #include "session_manager/include/scene_session_manager.h"
31 #include "session_manager/include/zidl/scene_session_manager_interface.h"
32 #include "window_manager.h"
33 #include "window_manager_agent.h"
34
35 using namespace testing;
36 using namespace testing::ext;
37
38 namespace OHOS {
39 namespace Rosen {
40 namespace {
41 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelStubTest"};
42 }
43 class WindowEventChannelStubTest : public testing::Test {
44 public:
45 static void SetUpTestCase();
46 static void TearDownTestCase();
47 void SetUp() override;
48 void TearDown() override;
49
50 sptr<ISessionStage> sessionStage = new SessionStageMocker();
51 sptr<WindowEventChannelStub> windowEventChannelStub_ = new WindowEventChannelMocker(sessionStage);
52 };
53
SetUpTestCase()54 void WindowEventChannelStubTest::SetUpTestCase()
55 {
56 }
57
TearDownTestCase()58 void WindowEventChannelStubTest::TearDownTestCase()
59 {
60 }
61
SetUp()62 void WindowEventChannelStubTest::SetUp()
63 {
64 }
65
TearDown()66 void WindowEventChannelStubTest::TearDown()
67 {
68 }
69
70 namespace {
71 /**
72 * @tc.name: OnRemoteRequest
73 * @tc.desc: test function : OnRemoteRequest
74 * @tc.type: FUNC
75 */
76 HWTEST_F(WindowEventChannelStubTest, OnRemoteRequest, Function | SmallTest | Level1)
77 {
78 MessageParcel data;
79 MessageParcel reply;
80 MessageOption option;
81
82 data.WriteInterfaceToken(WindowEventChannelStub::GetDescriptor());
83 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
84 data.WriteUint32(static_cast<uint32_t>(type));
85 sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
86 data.WriteRemoteObject(windowManagerAgent->AsObject());
87
88 uint32_t code = static_cast<uint32_t>(
89 ISceneSessionManager::SceneSessionManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT);
90 ASSERT_TRUE((windowEventChannelStub_ != nullptr));
91 ASSERT_EQ(0, windowEventChannelStub_->OnRemoteRequest(code, data, reply, option));
92 }
93
94 /**
95 * @tc.name: HandleTransferKeyEvent01
96 * @tc.desc: test function : HandleTransferKeyEvent01
97 * @tc.type: FUNC
98 */
99 HWTEST_F(WindowEventChannelStubTest, HandleTransferKeyEvent01, Function | SmallTest | Level1)
100 {
101 MessageParcel data;
102 MessageParcel reply;
103
104 data.WriteUint32(1);
105 ASSERT_TRUE((windowEventChannelStub_ != nullptr));
106 ASSERT_EQ(5, windowEventChannelStub_->HandleTransferKeyEvent(data, reply));
107 }
108
109 /**
110 * @tc.name: HandleTransferKeyEvent02
111 * @tc.desc: test function : HandleTransferKeyEvent02
112 * @tc.type: FUNC
113 */
114 HWTEST_F(WindowEventChannelStubTest, HandleTransferKeyEvent02, Function | SmallTest | Level1)
115 {
116 MessageParcel data;
117 MessageParcel reply;
118
119 data.WriteUint32(0);
120 ASSERT_TRUE((windowEventChannelStub_ != nullptr));
121 ASSERT_EQ(5, windowEventChannelStub_->HandleTransferKeyEvent(data, reply));
122 }
123
124 /**
125 * @tc.name: HandleTransferKeyEventAsync
126 * @tc.desc: test function : HandleTransferKeyEventAsync
127 * @tc.type: FUNC
128 */
129 HWTEST_F(WindowEventChannelStubTest, HandleTransferKeyEventAsync, Function | SmallTest | Level1)
130 {
131 MessageParcel data;
132 MessageParcel reply;
133
134 data.WriteBool(true);
135 ASSERT_TRUE((windowEventChannelStub_ != nullptr));
136 ASSERT_EQ(5, windowEventChannelStub_->HandleTransferKeyEventAsync(data, reply));
137 }
138
139 /**
140 * @tc.name: HandleTransferPointerEvent01
141 * @tc.desc: test function : HandleTransferPointerEvent01
142 * @tc.type: FUNC
143 */
144 HWTEST_F(WindowEventChannelStubTest, HandleTransferPointerEvent01, Function | SmallTest | Level1)
145 {
146 MessageParcel data;
147 MessageParcel reply;
148 ASSERT_TRUE((windowEventChannelStub_ != nullptr));
149 ASSERT_EQ(5, windowEventChannelStub_->HandleTransferPointerEvent(data, reply));
150 }
151
152 /**
153 * @tc.name: HandleTransferPointerEvent02
154 * @tc.desc: test function : HandleTransferPointerEvent02
155 * @tc.type: FUNC
156 */
157 HWTEST_F(WindowEventChannelStubTest, HandleTransferPointerEvent02, Function | SmallTest | Level1)
158 {
159 MessageParcel data;
160 MessageParcel reply;
161
162 data.WriteUint32(0);
163 ASSERT_TRUE((windowEventChannelStub_ != nullptr));
164 ASSERT_EQ(5, windowEventChannelStub_->HandleTransferPointerEvent(data, reply));
165 }
166
167 /**
168 * @tc.name: HandleTransferFocusActiveEvent
169 * @tc.desc: test function : HandleTransferFocusActiveEvent
170 * @tc.type: FUNC
171 */
172 HWTEST_F(WindowEventChannelStubTest, HandleTransferFocusActiveEvent, Function | SmallTest | Level1)
173 {
174 MessageParcel data;
175 MessageParcel reply;
176
177 data.WriteBool(false);
178 ASSERT_TRUE((windowEventChannelStub_ != nullptr));
179 ASSERT_EQ(0, windowEventChannelStub_->HandleTransferFocusActiveEvent(data, reply));
180 }
181
182 /**
183 * @tc.name: HandleTransferFocusStateEvent
184 * @tc.desc: test function : HandleTransferFocusStateEvent
185 * @tc.type: FUNC
186 */
187 HWTEST_F(WindowEventChannelStubTest, HandleTransferFocusStateEvent, Function | SmallTest | Level1)
188 {
189 MessageParcel data;
190 MessageParcel reply;
191
192 data.WriteBool(false);
193 ASSERT_TRUE((windowEventChannelStub_ != nullptr));
194 ASSERT_EQ(0, windowEventChannelStub_->HandleTransferFocusStateEvent(data, reply));
195 }
196
197 /**
198 * @tc.name: HandleTransferAccessibilityHoverEvent01
199 * @tc.desc: test function : HandleTransferAccessibilityHoverEvent01
200 * @tc.type: FUNC
201 */
202 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityHoverEvent01, Function | SmallTest | Level1)
203 {
204 WLOGI("HandleTransferAccessibilityHoverEvent01 begin");
205 MessageParcel data;
206 MessageParcel reply;
207
208 data.WriteFloat(0.0f);
209 data.WriteFloat(0.0f);
210 data.WriteInt32(0);
211 data.WriteInt32(0);
212 data.WriteInt64(0);
213 ASSERT_TRUE(windowEventChannelStub_ != nullptr);
214 ASSERT_EQ(0, windowEventChannelStub_->HandleTransferAccessibilityHoverEvent(data, reply));
215 WLOGI("HandleTransferAccessibilityHoverEvent01 end");
216 }
217
218 /**
219 * @tc.name: HandleTransferAccessibilityHoverEvent02
220 * @tc.desc: test function : HandleTransferAccessibilityHoverEvent02
221 * @tc.type: FUNC
222 */
223 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityHoverEvent02, Function | SmallTest | Level1)
224 {
225 WLOGI("HandleTransferAccessibilityHoverEvent02 begin");
226 MessageParcel data;
227 MessageParcel reply;
228 ASSERT_TRUE(windowEventChannelStub_ != nullptr);
229 ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityHoverEvent(data, reply));
230 WLOGI("HandleTransferAccessibilityHoverEvent02 end");
231 }
232
233 /**
234 * @tc.name: HandleTransferAccessibilityHoverEvent03
235 * @tc.desc: test function : HandleTransferAccessibilityHoverEvent03
236 * @tc.type: FUNC
237 */
238 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityHoverEvent03, Function | SmallTest | Level1)
239 {
240 WLOGI("HandleTransferAccessibilityHoverEvent03 begin");
241 MessageParcel data;
242 MessageParcel reply;
243
244 data.WriteFloat(0.0f);
245 ASSERT_TRUE(windowEventChannelStub_ != nullptr);
246 ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityHoverEvent(data, reply));
247 WLOGI("HandleTransferAccessibilityHoverEvent03 end");
248 }
249
250 /**
251 * @tc.name: HandleTransferAccessibilityHoverEvent04
252 * @tc.desc: test function : HandleTransferAccessibilityHoverEvent04
253 * @tc.type: FUNC
254 */
255 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityHoverEvent04, Function | SmallTest | Level1)
256 {
257 WLOGI("HandleTransferAccessibilityHoverEvent04 begin");
258 MessageParcel data;
259 MessageParcel reply;
260
261 data.WriteFloat(0.0f);
262 data.WriteFloat(0.0f);
263 ASSERT_TRUE(windowEventChannelStub_ != nullptr);
264 ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityHoverEvent(data, reply));
265 WLOGI("HandleTransferAccessibilityHoverEvent04 end");
266 }
267
268 /**
269 * @tc.name: HandleTransferAccessibilityHoverEvent05
270 * @tc.desc: test function : HandleTransferAccessibilityHoverEvent05
271 * @tc.type: FUNC
272 */
273 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityHoverEvent05, Function | SmallTest | Level1)
274 {
275 WLOGI("HandleTransferAccessibilityHoverEvent05 begin");
276 MessageParcel data;
277 MessageParcel reply;
278
279 data.WriteFloat(0.0f);
280 data.WriteFloat(0.0f);
281 data.WriteInt32(0);
282 ASSERT_TRUE(windowEventChannelStub_ != nullptr);
283 ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityHoverEvent(data, reply));
284 WLOGI("HandleTransferAccessibilityHoverEvent05 end");
285 }
286
287 /**
288 * @tc.name: HandleTransferAccessibilityHoverEvent06
289 * @tc.desc: test function : HandleTransferAccessibilityHoverEvent06
290 * @tc.type: FUNC
291 */
292 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityHoverEvent06, Function | SmallTest | Level1)
293 {
294 WLOGI("HandleTransferAccessibilityHoverEvent06 begin");
295 MessageParcel data;
296 MessageParcel reply;
297
298 data.WriteFloat(0.0f);
299 data.WriteFloat(0.0f);
300 data.WriteInt32(0);
301 data.WriteInt32(0);
302 ASSERT_TRUE(windowEventChannelStub_ != nullptr);
303 ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityHoverEvent(data, reply));
304 WLOGI("HandleTransferAccessibilityHoverEvent06 end");
305 }
306
307 /**
308 * @tc.name: HandleTransferAccessibilityChildTreeRegister01
309 * @tc.desc: test function : HandleTransferAccessibilityChildTreeRegister01
310 * @tc.type: FUNC
311 */
312 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityChildTreeRegister01, Function | SmallTest | Level1)
313 {
314 WLOGI("HandleTransferAccessibilityChildTreeRegister01 begin");
315 MessageParcel data;
316 MessageParcel reply;
317
318 data.WriteUint32(0);
319 data.WriteInt32(0);
320 data.WriteInt64(0);
321 ASSERT_TRUE(windowEventChannelStub_ != nullptr);
322 ASSERT_EQ(0, windowEventChannelStub_->HandleTransferAccessibilityChildTreeRegister(data, reply));
323 WLOGI("HandleTransferAccessibilityChildTreeRegister01 end");
324 }
325
326 /**
327 * @tc.name: HandleTransferAccessibilityChildTreeRegister02
328 * @tc.desc: test function : HandleTransferAccessibilityChildTreeRegister02
329 * @tc.type: FUNC
330 */
331 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityChildTreeRegister02, Function | SmallTest | Level1)
332 {
333 WLOGI("HandleTransferAccessibilityChildTreeRegister02 begin");
334 MessageParcel data;
335 MessageParcel reply;
336
337 ASSERT_TRUE(windowEventChannelStub_ != nullptr);
338 ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityChildTreeRegister(data, reply));
339 WLOGI("HandleTransferAccessibilityChildTreeRegister02 end");
340 }
341
342 /**
343 * @tc.name: HandleTransferAccessibilityChildTreeRegister03
344 * @tc.desc: test function : HandleTransferAccessibilityChildTreeRegister03
345 * @tc.type: FUNC
346 */
347 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityChildTreeRegister03, Function | SmallTest | Level1)
348 {
349 WLOGI("HandleTransferAccessibilityChildTreeRegister03 begin");
350 MessageParcel data;
351 MessageParcel reply;
352
353 data.WriteUint32(0);
354 ASSERT_TRUE(windowEventChannelStub_ != nullptr);
355 ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityChildTreeRegister(data, reply));
356 WLOGI("HandleTransferAccessibilityChildTreeRegister03 end");
357 }
358
359 /**
360 * @tc.name: HandleTransferAccessibilityChildTreeRegister04
361 * @tc.desc: test function : HandleTransferAccessibilityChildTreeRegister04
362 * @tc.type: FUNC
363 */
364 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityChildTreeRegister04, Function | SmallTest | Level1)
365 {
366 WLOGI("HandleTransferAccessibilityChildTreeRegister04 begin");
367 MessageParcel data;
368 MessageParcel reply;
369
370 data.WriteUint32(0);
371 data.WriteInt32(0);
372 ASSERT_TRUE(windowEventChannelStub_ != nullptr);
373 ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityChildTreeRegister(data, reply));
374 WLOGI("HandleTransferAccessibilityChildTreeRegister04 end");
375 }
376
377 /**
378 * @tc.name: HandleTransferAccessibilityChildTreeUnregister01
379 * @tc.desc: test function : HandleTransferAccessibilityChildTreeUnregister01
380 * @tc.type: FUNC
381 */
382 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityChildTreeUnregister01, Function | SmallTest | Level1)
383 {
384 WLOGI("HandleTransferAccessibilityChildTreeUnregister01 begin");
385 MessageParcel data;
386 MessageParcel reply;
387 ASSERT_TRUE(windowEventChannelStub_ != nullptr);
388 ASSERT_EQ(0, windowEventChannelStub_->HandleTransferAccessibilityChildTreeUnregister(data, reply));
389 WLOGI("HandleTransferAccessibilityChildTreeUnregister01 end");
390 }
391
392 /**
393 * @tc.name: HandleTransferAccessibilityDumpChildInfo01
394 * @tc.desc: test function : HandleTransferAccessibilityDumpChildInfo01
395 * @tc.type: FUNC
396 */
397 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityDumpChildInfo01, Function | SmallTest | Level1)
398 {
399 WLOGI("HandleTransferAccessibilityDumpChildInfo01 begin");
400 MessageParcel data;
401 MessageParcel reply;
402
403 std::vector<std::string> params;
404 data.WriteStringVector(params);
405 ASSERT_TRUE(windowEventChannelStub_ != nullptr);
406 ASSERT_EQ(0, windowEventChannelStub_->HandleTransferAccessibilityDumpChildInfo(data, reply));
407 WLOGI("HandleTransferAccessibilityDumpChildInfo01 end");
408 }
409 }
410 }
411 }