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/session_stage_stub.h"
17 #include "session/container/include/zidl/session_stage_ipc_interface_code.h"
18 #include <ipc_types.h>
19 #include <iremote_stub.h>
20
21 #include "iremote_object_mocker.h"
22 #include "mock/mock_session_stage.h"
23 #include <message_option.h>
24 #include <message_parcel.h>
25 #include <gtest/gtest.h>
26 #include <gmock/gmock.h>
27 #include "session_manager/include/scene_session_manager.h"
28 #include "session_manager/include/zidl/scene_session_manager_interface.h"
29 #include "window_manager.h"
30 #include "window_manager_agent.h"
31 #include "ws_common.h"
32 #include "zidl/window_manager_agent_interface.h"
33 #include "window_manager_hilog.h"
34
35
36 using namespace testing;
37 using namespace testing::ext;
38
39 namespace OHOS {
40 namespace Rosen {
41 class SessionStageStubTest : public testing::Test {
42 public:
43 static void SetUpTestCase();
44 static void TearDownTestCase();
45 void SetUp() override;
46 void TearDown() override;
47 sptr<SessionStageStub> sessionStageStub_ = new SessionStageMocker();
48 };
49
SetUpTestCase()50 void SessionStageStubTest::SetUpTestCase()
51 {
52 }
53
TearDownTestCase()54 void SessionStageStubTest::TearDownTestCase()
55 {
56 }
57
SetUp()58 void SessionStageStubTest::SetUp()
59 {
60 }
61
TearDown()62 void SessionStageStubTest::TearDown()
63 {
64 }
65
66 namespace {
67 /**
68 * @tc.name: OnRemoteRequest
69 * @tc.desc: test function : OnRemoteRequest
70 * @tc.type: FUNC
71 */
72 HWTEST_F(SessionStageStubTest, OnRemoteRequest, Function | SmallTest | Level1)
73 {
74 MessageParcel data;
75 MessageParcel reply;
76 MessageOption option;
77
78 data.WriteInterfaceToken(SessionStageStub::GetDescriptor());
79 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
80 data.WriteUint32(static_cast<uint32_t>(type));
81 sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
82 data.WriteRemoteObject(windowManagerAgent->AsObject());
83
84 uint32_t code = static_cast<uint32_t>(
85 ISceneSessionManager::SceneSessionManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT);
86 ASSERT_TRUE((sessionStageStub_ != nullptr));
87 ASSERT_EQ(22, sessionStageStub_->OnRemoteRequest(code, data, reply, option));
88 }
89
90 /**
91 * @tc.name: HandleSetActive
92 * @tc.desc: test function : HandleSetActive
93 * @tc.type: FUNC
94 */
95 HWTEST_F(SessionStageStubTest, HandleSetActive, Function | SmallTest | Level1)
96 {
97 MessageParcel data;
98 MessageParcel reply;
99
100 data.WriteBool(false);
101 ASSERT_TRUE((sessionStageStub_ != nullptr));
102 ASSERT_EQ(0, sessionStageStub_->HandleSetActive(data, reply));
103 }
104
105 /**
106 * @tc.name: HandleUpdateRect
107 * @tc.desc: test function : HandleUpdateRect
108 * @tc.type: FUNC
109 */
110 HWTEST_F(SessionStageStubTest, HandleUpdateRect, Function | SmallTest | Level1)
111 {
112 MessageParcel data;
113 MessageParcel reply;
114
115 data.WriteUint32(1);
116 ASSERT_TRUE((sessionStageStub_ != nullptr));
117 ASSERT_EQ(0, sessionStageStub_->HandleUpdateRect(data, reply));
118 }
119
120 /**
121 * @tc.name: HandleBackEventInner
122 * @tc.desc: test function : HandleBackEventInner
123 * @tc.type: FUNC
124 */
125 HWTEST_F(SessionStageStubTest, HandleBackEventInner, Function | SmallTest | Level1)
126 {
127 MessageParcel data;
128 MessageParcel reply;
129
130 data.WriteBool(false);
131 ASSERT_TRUE((sessionStageStub_ != nullptr));
132 ASSERT_EQ(0, sessionStageStub_->HandleBackEventInner(data, reply));
133 }
134
135 /**
136 * @tc.name: HandleUpdateFocus
137 * @tc.desc: test function : HandleUpdateFocus
138 * @tc.type: FUNC
139 */
140 HWTEST_F(SessionStageStubTest, HandleUpdateFocus, Function | SmallTest | Level1)
141 {
142 MessageParcel data;
143 MessageParcel reply;
144
145 data.WriteBool(false);
146 ASSERT_TRUE((sessionStageStub_ != nullptr));
147 ASSERT_EQ(0, sessionStageStub_->HandleUpdateFocus(data, reply));
148 }
149
150 /**
151 * @tc.name: HandleNotifyDestroy
152 * @tc.desc: test function : HandleNotifyDestroy
153 * @tc.type: FUNC
154 */
155 HWTEST_F(SessionStageStubTest, HandleNotifyDestroy, Function | SmallTest | Level1)
156 {
157 MessageParcel data;
158 MessageParcel reply;
159
160 ASSERT_TRUE((sessionStageStub_ != nullptr));
161 ASSERT_EQ(0, sessionStageStub_->HandleNotifyDestroy(data, reply));
162 }
163
164 /**
165 * @tc.name: HandleNotifyTransferComponentData
166 * @tc.desc: test function : HandleNotifyTransferComponentData
167 * @tc.type: FUNC
168 */
169 HWTEST_F(SessionStageStubTest, HandleNotifyTransferComponentData, Function | SmallTest | Level1)
170 {
171 MessageParcel data;
172 MessageParcel reply;
173
174 data.WriteUint32(1);
175 ASSERT_TRUE((sessionStageStub_ != nullptr));
176 ASSERT_EQ(22, sessionStageStub_->HandleNotifyTransferComponentData(data, reply));
177 }
178
179 /**
180 * @tc.name: HandleNotifyOccupiedAreaChange
181 * @tc.desc: test function : HandleNotifyOccupiedAreaChange
182 * @tc.type: FUNC
183 */
184 HWTEST_F(SessionStageStubTest, HandleNotifyOccupiedAreaChange, Function | SmallTest | Level1)
185 {
186 MessageParcel data;
187 MessageParcel reply;
188
189 data.WriteUint32(1);
190 ASSERT_TRUE((sessionStageStub_ != nullptr));
191 ASSERT_EQ(22, sessionStageStub_->HandleNotifyOccupiedAreaChange(data, reply));
192 }
193
194 /**
195 * @tc.name: HandleUpdateAvoidArea
196 * @tc.desc: test function : HandleUpdateAvoidArea
197 * @tc.type: FUNC
198 */
199 HWTEST_F(SessionStageStubTest, HandleUpdateAvoidArea, Function | SmallTest | Level1)
200 {
201 MessageParcel data;
202 MessageParcel reply;
203
204 data.WriteUint32(1);
205 ASSERT_TRUE((sessionStageStub_ != nullptr));
206 ASSERT_EQ(22, sessionStageStub_->HandleUpdateAvoidArea(data, reply));
207 }
208
209 /**
210 * @tc.name: HandleNotifyScreenshot
211 * @tc.desc: test function : HandleNotifyScreenshot
212 * @tc.type: FUNC
213 */
214 HWTEST_F(SessionStageStubTest, HandleNotifyScreenshot, Function | SmallTest | Level1)
215 {
216 MessageParcel data;
217 MessageParcel reply;
218
219 ASSERT_TRUE((sessionStageStub_ != nullptr));
220 ASSERT_EQ(0, sessionStageStub_->HandleNotifyScreenshot(data, reply));
221 }
222
223 /**
224 * @tc.name: HandleDumpSessionElementInfo
225 * @tc.desc: test function : HandleDumpSessionElementInfo
226 * @tc.type: FUNC
227 */
228 HWTEST_F(SessionStageStubTest, HandleDumpSessionElementInfo, Function | SmallTest | Level1)
229 {
230 MessageParcel data;
231 MessageParcel reply;
232
233 std::vector<std::string> params;
234 params.push_back("test1");
235 params.push_back("test2");
236 data.WriteStringVector(params);
237 ASSERT_TRUE((sessionStageStub_ != nullptr));
238 ASSERT_EQ(0, sessionStageStub_->HandleDumpSessionElementInfo(data, reply));
239 }
240
241 /**
242 * @tc.name: HandleNotifyTouchOutside
243 * @tc.desc: test function : HandleNotifyTouchOutside
244 * @tc.type: FUNC
245 */
246 HWTEST_F(SessionStageStubTest, HandleNotifyTouchOutside, Function | SmallTest | Level1)
247 {
248 MessageParcel data;
249 MessageParcel reply;
250
251 ASSERT_TRUE((sessionStageStub_ != nullptr));
252 ASSERT_EQ(0, sessionStageStub_->HandleNotifyTouchOutside(data, reply));
253 }
254
255 /**
256 * @tc.name: HandleUpdateWindowMode
257 * @tc.desc: test function : HandleUpdateWindowMode
258 * @tc.type: FUNC
259 */
260 HWTEST_F(SessionStageStubTest, HandleUpdateWindowMode, Function | SmallTest | Level1)
261 {
262 MessageParcel data;
263 MessageParcel reply;
264
265 data.WriteUint32(1);
266 ASSERT_TRUE((sessionStageStub_ != nullptr));
267 ASSERT_EQ(0, sessionStageStub_->HandleUpdateWindowMode(data, reply));
268 }
269
270 /**
271 * @tc.name: NotifySessionFullScreen
272 * @tc.desc: test function : NotifySessionFullScreen
273 * @tc.type: FUNC
274 */
275 HWTEST_F(SessionStageStubTest, HandleNotifySessionFullScreen, Function | SmallTest | Level1)
276 {
277 MessageParcel data;
278 MessageParcel reply;
279
280 data.WriteBool(true);
281 ASSERT_TRUE(sessionStageStub_ != nullptr);
282 ASSERT_EQ(0, sessionStageStub_->HandleNotifySessionFullScreen(data, reply));
283 }
284
285 /**
286 * @tc.name: HandleNotifyWindowVisibilityChange
287 * @tc.desc: test function : HandleNotifyWindowVisibilityChange
288 * @tc.type: FUNC
289 */
290 HWTEST_F(SessionStageStubTest, HandleNotifyWindowVisibilityChange, Function | SmallTest | Level1)
291 {
292 MessageParcel data;
293 MessageParcel reply;
294 data.WriteBool(true);
295 ASSERT_TRUE((sessionStageStub_ != nullptr));
296 ASSERT_EQ(0, sessionStageStub_->HandleNotifyWindowVisibilityChange(data, reply));
297 }
298
299 /**
300 * @tc.name: HandleUpdateDensity
301 * @tc.desc: test function : HandleUpdateDensity
302 * @tc.type: FUNC
303 */
304 HWTEST_F(SessionStageStubTest, HandleUpdateDensity, Function | SmallTest | Level1)
305 {
306 MessageParcel data;
307 MessageParcel reply;
308 ASSERT_TRUE((sessionStageStub_ != nullptr));
309 ASSERT_EQ(0, sessionStageStub_->HandleNotifyWindowVisibilityChange(data, reply));
310 }
311
312 /**
313 * @tc.name: HandleUpdateOrientation
314 * @tc.desc: test function : HandleUpdateOrientation
315 * @tc.type: FUNC
316 */
317 HWTEST_F(SessionStageStubTest, HandleUpdateOrientation, Function | SmallTest | Level1)
318 {
319 MessageParcel data;
320 MessageParcel reply;
321 ASSERT_TRUE((sessionStageStub_ != nullptr));
322 ASSERT_EQ(0, sessionStageStub_->HandleUpdateOrientation(data, reply));
323 }
324
325 /**
326 * @tc.name: HandleNotifyCloseExistPipWindow
327 * @tc.desc: test function : HandleNotifyCloseExistPipWindow
328 * @tc.type: FUNC
329 */
330 HWTEST_F(SessionStageStubTest, HandleNotifyCloseExistPipWindow, Function | SmallTest | Level1)
331 {
332 MessageParcel data;
333 MessageParcel reply;
334 ASSERT_TRUE((sessionStageStub_ != nullptr));
335 ASSERT_EQ(0, sessionStageStub_->HandleNotifyCloseExistPipWindow(data, reply));
336 }
337
338 /**
339 * @tc.name: HandleUpdateMaximizeMode
340 * @tc.desc: test function : HandleUpdateMaximizeMode
341 * @tc.type: FUNC
342 */
343 HWTEST_F(SessionStageStubTest, HandleUpdateMaximizeMode, Function | SmallTest | Level1)
344 {
345 MessageParcel data;
346 MessageParcel reply;
347 ASSERT_TRUE((sessionStageStub_ != nullptr));
348 ASSERT_EQ(0, sessionStageStub_->HandleUpdateMaximizeMode(data, reply));
349 }
350
351 /**
352 * @tc.name: HandleUpdateTitleInTargetPos
353 * @tc.desc: test function : HandleUpdateTitleInTargetPos
354 * @tc.type: FUNC
355 */
356 HWTEST_F(SessionStageStubTest, HandleUpdateTitleInTargetPos, Function | SmallTest | Level1)
357 {
358 MessageParcel data;
359 MessageParcel reply;
360 ASSERT_TRUE((sessionStageStub_ != nullptr));
361 ASSERT_EQ(0, sessionStageStub_->HandleUpdateTitleInTargetPos(data, reply));
362 }
363
364 /**
365 * @tc.name: HandleNotifyDensityFollowHost
366 * @tc.desc: test function : HandleNotifyDensityFollowHost
367 * @tc.type: FUNC
368 */
369 HWTEST_F(SessionStageStubTest, HandleNotifyDensityFollowHost, Function | SmallTest | Level1)
370 {
371 MessageParcel data;
372 MessageParcel reply;
373 ASSERT_TRUE((sessionStageStub_ != nullptr));
374 ASSERT_EQ(0, sessionStageStub_->HandleNotifyDensityFollowHost(data, reply));
375 }
376
377 /**
378 * @tc.name: HandleGetUIContentRemoteObj
379 * @tc.desc: test function : HandleGetUIContentRemoteObj
380 * @tc.type: FUNC
381 */
382 HWTEST_F(SessionStageStubTest, HandleGetUIContentRemoteObj, Function | SmallTest | Level1)
383 {
384 MessageParcel data;
385 MessageParcel reply;
386 ASSERT_NE(sessionStageStub_, nullptr);
387 ASSERT_EQ(0, sessionStageStub_->HandleGetUIContentRemoteObj(data, reply));
388 }
389
390 /**
391 * @tc.name: HandleSetPipActionEvent
392 * @tc.desc: test function : HandleSetPipActionEvent
393 * @tc.type: FUNC
394 */
395 HWTEST_F(SessionStageStubTest, HandleSetPipActionEvent, Function | SmallTest | Level1)
396 {
397 MessageParcel data;
398 MessageParcel reply;
399 data.WriteString("str");
400 data.WriteInt32(1);
401 ASSERT_TRUE((sessionStageStub_ != nullptr));
402 ASSERT_EQ(0, sessionStageStub_->HandleSetPipActionEvent(data, reply));
403 }
404
405 /**
406 * @tc.name: HandleSetPiPControlEvent
407 * @tc.desc: test function : HandleSetPiPControlEvent
408 * @tc.type: FUNC
409 */
410 HWTEST_F(SessionStageStubTest, HandleSetPiPControlEvent, Function | SmallTest | Level1)
411 {
412 MessageParcel data;
413 MessageParcel reply;
414 auto controlType = WsPiPControlType::VIDEO_PLAY_PAUSE;
415 auto status = WsPiPControlStatus::PLAY;
416 data.WriteUint32(static_cast<uint32_t>(controlType));
417 data.WriteInt32(static_cast<int32_t>(status));
418 ASSERT_TRUE(sessionStageStub_ != nullptr);
419 ASSERT_EQ(0, sessionStageStub_->HandleSetPiPControlEvent(data, reply));
420 }
421
422 /**
423 * @tc.name: HandleSetUniqueVirtualPixelRatio
424 * @tc.desc: test function : HandleSetUniqueVirtualPixelRatio
425 * @tc.type: FUNC
426 */
427 HWTEST_F(SessionStageStubTest, HandleSetUniqueVirtualPixelRatio, Function | SmallTest | Level1)
428 {
429 MessageParcel data;
430 MessageParcel reply;
431 data.WriteBool(true);
432 data.WriteFloat(3.25f);
433 ASSERT_TRUE(sessionStageStub_ != nullptr);
434 ASSERT_EQ(0, sessionStageStub_->HandleSetUniqueVirtualPixelRatio(data, reply));
435 }
436
437 /**
438 * @tc.name: HandleNotifyCompatibleModeEnableInPad
439 * @tc.desc: test function : HandleNotifyCompatibleModeEnableInPad
440 * @tc.type: FUNC
441 */
442 HWTEST_F(SessionStageStubTest, HandleNotifyCompatibleModeEnableInPad, Function | SmallTest | Level1)
443 {
444 MessageParcel data;
445 MessageParcel reply;
446 MessageOption option;
447 uint32_t code = static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_COMPATIBLE_MODE_ENABLE);
448 data.WriteInterfaceToken(SessionStageStub::GetDescriptor());
449 data.WriteBool(true);
450 ASSERT_NE(sessionStageStub_, nullptr);
451 ASSERT_EQ(0, sessionStageStub_->OnRemoteRequest(code, data, reply, option));
452 }
453
454 /**
455 * @tc.name: HandleNotifyDumpInfo
456 * @tc.desc: test function : HandleNotifyDumpInfo
457 * @tc.type: FUNC
458 */
459 HWTEST_F(SessionStageStubTest, HandleNotifyDumpInfo, Function | SmallTest | Level1)
460 {
461 MessageParcel data;
462 MessageParcel reply;
463 MessageOption option;
464 uint32_t code = static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DUMP_INFO);
465 std::vector<std::string> params;
466 std::vector<std::string> info;
467 data.WriteInterfaceToken(SessionStageStub::GetDescriptor());
468 data.WriteStringVector(params);
469 ASSERT_TRUE(sessionStageStub_ != nullptr);
470 ASSERT_EQ(0, sessionStageStub_->OnRemoteRequest(code, data, reply, option));
471 }
472
473 /**
474 * @tc.name: HandleSetEnableDragBySystem
475 * @tc.desc: test function : HandleSetEnableDragBySystem
476 * @tc.type: FUNC
477 */
478 HWTEST_F(SessionStageStubTest, HandleSetEnableDragBySystem, Function | SmallTest | Level1)
479 {
480 MessageParcel data;
481 MessageParcel reply;
482 MessageOption option;
483 uint32_t code = static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_SET_ENABLE_DRAG_BY_SYSTEM);
484 data.WriteInterfaceToken(SessionStageStub::GetDescriptor());
485 data.WriteBool(true);
486 ASSERT_TRUE(sessionStageStub_ != nullptr);
487 ASSERT_EQ(0, sessionStageStub_->OnRemoteRequest(code, data, reply, option));
488 data.WriteBool(false);
489 ASSERT_EQ(0, sessionStageStub_->HandleSetEnableDragBySystem(data, reply));
490 }
491 }
492 }
493 }