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_proxy.h"
17 #include "iremote_object_mocker.h"
18 #include <gtest/gtest.h>
19 #include "proto.h"
20 #include "string_wrapper.h"
21 #include "util.h"
22 #include "window_manager.h"
23 #include "window_manager_hilog.h"
24 #include "wm_common.h"
25 #include "mock_message_parcel.h"
26 
27 
28 using namespace testing;
29 using namespace testing::ext;
30 
31 namespace OHOS {
32 namespace Rosen {
33 class SessionStageProxyTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp() override;
38     void TearDown() override;
39     sptr<IRemoteObject> iRemoteObjectMocker = new (std::nothrow) IRemoteObjectMocker();
40     sptr<SessionStageProxy> sessionStage_ = new SessionStageProxy(iRemoteObjectMocker);
41 };
42 
SetUpTestCase()43 void SessionStageProxyTest::SetUpTestCase()
44 {
45 }
46 
TearDownTestCase()47 void SessionStageProxyTest::TearDownTestCase()
48 {
49 }
50 
SetUp()51 void SessionStageProxyTest::SetUp()
52 {
53 }
54 
TearDown()55 void SessionStageProxyTest::TearDown()
56 {
57 }
58 
59 namespace {
60 /**
61  * @tc.name: SetActive
62  * @tc.desc: test function : SetActive
63  * @tc.type: FUNC
64  */
65 HWTEST_F(SessionStageProxyTest, SetActive, Function | SmallTest | Level1)
66 {
67     bool active = false;
68     ASSERT_TRUE((sessionStage_ != nullptr));
69     WSError res = sessionStage_->SetActive(active);
70     ASSERT_EQ(WSError::WS_OK, res);
71     active = true;
72     ASSERT_TRUE((sessionStage_ != nullptr));
73     res = sessionStage_->SetActive(active);
74     ASSERT_EQ(WSError::WS_OK, res);
75 }
76 
77 /**
78  * @tc.name: UpdateDisplayId
79  * @tc.desc: test function : UpdateDisplayId
80  * @tc.type: FUNC
81  */
82 HWTEST_F(SessionStageProxyTest, UpdateDisplayId, Function | SmallTest | Level1)
83 {
84     uint64_t displayID = 0;
85     ASSERT_TRUE((sessionStage_ != nullptr));
86     WSError res = sessionStage_->UpdateDisplayId(displayID);
87     ASSERT_EQ(WSError::WS_OK, res);
88     displayID = 1;
89     res = sessionStage_->UpdateDisplayId(displayID);
90     ASSERT_EQ(WSError::WS_OK, res);
91 }
92 
93 /**
94  * @tc.name: UpdateRect
95  * @tc.desc: test function : UpdateRect
96  * @tc.type: FUNC
97  */
98 HWTEST_F(SessionStageProxyTest, UpdateRect, Function | SmallTest | Level1)
99 {
100     WSRect rect;
101     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
102     ASSERT_TRUE((sessionStage_ != nullptr));
103     WSError res = sessionStage_->UpdateRect(rect, reason);
104     ASSERT_EQ(WSError::WS_OK, res);
105 }
106 
107 /**
108  * @tc.name: HandleBackEvent
109  * @tc.desc: test function : HandleBackEvent
110  * @tc.type: FUNC
111  */
112 HWTEST_F(SessionStageProxyTest, HandleBackEvent, Function | SmallTest | Level1)
113 {
114     ASSERT_TRUE((sessionStage_ != nullptr));
115     WSError res = sessionStage_->HandleBackEvent();
116     ASSERT_EQ(WSError::WS_OK, res);
117 }
118 
119 /**
120  * @tc.name: GetUIContentRemoteObj
121  * @tc.desc: test function : GetUIContentRemoteObj
122  * @tc.type: FUNC
123  */
124 HWTEST_F(SessionStageProxyTest, GetUIContentRemoteObj, Function | SmallTest | Level1)
125 {
126     ASSERT_NE(sessionStage_, nullptr);
127     sptr<IRemoteObject> remoteObj;
128     WSError res = sessionStage_->GetUIContentRemoteObj(remoteObj);
129     ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
130 }
131 
132 /**
133  * @tc.name: MarkProcessed
134  * @tc.desc: test function : MarkProcessed
135  * @tc.type: FUNC
136  */
137 HWTEST_F(SessionStageProxyTest, MarkProcessed, Function | SmallTest | Level1)
138 {
139     int32_t eventId = 1;
140     ASSERT_TRUE((sessionStage_ != nullptr));
141     WSError res = sessionStage_->MarkProcessed(eventId);
142     ASSERT_EQ(WSError::WS_DO_NOTHING, res);
143 }
144 
145 /**
146  * @tc.name: UpdateFocus
147  * @tc.desc: test function : UpdateFocus
148  * @tc.type: FUNC
149  */
150 HWTEST_F(SessionStageProxyTest, UpdateFocus, Function | SmallTest | Level1)
151 {
152     bool focus = false;
153     ASSERT_TRUE((sessionStage_ != nullptr));
154     WSError res = sessionStage_->UpdateFocus(focus);
155     ASSERT_EQ(WSError::WS_OK, res);
156     focus = true;
157     ASSERT_TRUE((sessionStage_ != nullptr));
158     res = sessionStage_->UpdateFocus(focus);
159     ASSERT_EQ(WSError::WS_OK, res);
160 }
161 
162 /**
163  * @tc.name: NotifyDestroy
164  * @tc.desc: test function : NotifyDestroy
165  * @tc.type: FUNC
166  */
167 HWTEST_F(SessionStageProxyTest, NotifyDestroy, Function | SmallTest | Level1)
168 {
169     ASSERT_TRUE((sessionStage_ != nullptr));
170     WSError res = sessionStage_->NotifyDestroy();
171     ASSERT_EQ(WSError::WS_OK, res);
172 }
173 
174 /**
175  * @tc.name: NotifyTransferComponentData
176  * @tc.desc: test function : NotifyTransferComponentData
177  * @tc.type: FUNC
178  */
179 HWTEST_F(SessionStageProxyTest, NotifyTransferComponentData, Function | SmallTest | Level1)
180 {
181     AAFwk::WantParams wantParams;
182     std::string testValue = "testValue";
183     wantParams.SetParam("keyStr", OHOS::AAFwk::String::Box(testValue));
184     ASSERT_TRUE((sessionStage_ != nullptr));
185     WSError res = sessionStage_->NotifyTransferComponentData(wantParams);
186     ASSERT_EQ(WSError::WS_OK, res);
187 }
188 
189 /**
190  * @tc.name: NotifyOccupiedAreaChangeInfo
191  * @tc.desc: test function : NotifyOccupiedAreaChangeInfo
192  * @tc.type: FUNC
193  */
194 HWTEST_F(SessionStageProxyTest, NotifyOccupiedAreaChangeInfo, Function | SmallTest | Level1)
195 {
196     sptr<OccupiedAreaChangeInfo> info = new OccupiedAreaChangeInfo();
197     ASSERT_TRUE((sessionStage_ != nullptr));
198     sessionStage_->NotifyOccupiedAreaChangeInfo(info);
199 }
200 
201 /**
202  * @tc.name: UpdateAvoidArea
203  * @tc.desc: test function : UpdateAvoidArea
204  * @tc.type: FUNC
205  */
206 HWTEST_F(SessionStageProxyTest, UpdateAvoidArea, Function | SmallTest | Level1)
207 {
208     sptr<AvoidArea> avoidArea = new AvoidArea();
209     AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM;
210     ASSERT_TRUE((sessionStage_ != nullptr));
211     WSError res = sessionStage_->UpdateAvoidArea(avoidArea, type);
212     ASSERT_EQ(WSError::WS_OK, res);
213 }
214 
215 /**
216  * @tc.name: DumpSessionElementInfo
217  * @tc.desc: test function : DumpSessionElementInfo
218  * @tc.type: FUNC
219  */
220 HWTEST_F(SessionStageProxyTest, DumpSessionElementInfo, Function | SmallTest | Level1)
221 {
222     std::vector<std::string> params;
223     params.push_back("test1");
224     params.push_back("test2");
225     ASSERT_TRUE((sessionStage_ != nullptr));
226     sessionStage_->DumpSessionElementInfo(params);
227 }
228 
229 /**
230  * @tc.name: NotifyScreenshot
231  * @tc.desc: test function : NotifyScreenshot
232  * @tc.type: FUNC
233  */
234 HWTEST_F(SessionStageProxyTest, NotifyScreenshot, Function | SmallTest | Level1)
235 {
236     ASSERT_TRUE((sessionStage_ != nullptr));
237     sessionStage_->NotifyScreenshot();
238 }
239 
240 /**
241  * @tc.name: NotifyTouchOutside
242  * @tc.desc: test function : NotifyTouchOutside
243  * @tc.type: FUNC
244  */
245 HWTEST_F(SessionStageProxyTest, NotifyTouchOutside, Function | SmallTest | Level1)
246 {
247     ASSERT_TRUE((sessionStage_ != nullptr));
248     sessionStage_->NotifyTouchOutside();
249 }
250 
251 /**
252  * @tc.name: UpdateWindowMode
253  * @tc.desc: test function : UpdateWindowMode
254  * @tc.type: FUNC
255  */
256 HWTEST_F(SessionStageProxyTest, UpdateWindowMode, Function | SmallTest | Level1)
257 {
258     WindowMode mode = WindowMode::WINDOW_MODE_UNDEFINED;
259     ASSERT_TRUE((sessionStage_ != nullptr));
260     sessionStage_->UpdateWindowMode(mode);
261 }
262 
263 /**
264  * @tc.name: NotifySessionFullScreen
265  * @tc.desc: test function : NotifySessionFullScreen
266  * @tc.type: FUNC
267  */
268 HWTEST_F(SessionStageProxyTest, NotifySessionFullScreen, Function | SmallTest | Level1)
269 {
270     bool fullScreen = true;
271     ASSERT_TRUE((sessionStage_ != nullptr));
272     sessionStage_->NotifySessionFullScreen(fullScreen);
273     fullScreen = false;
274     sessionStage_->NotifySessionFullScreen(fullScreen);
275 }
276 
277 /**
278  * @tc.name: NotifyForegroundInteractiveStatus
279  * @tc.desc: test function : NotifyForegroundInteractiveStatus
280  * @tc.type: FUNC
281  */
282 HWTEST_F(SessionStageProxyTest, NotifyForegroundInteractiveStatus, Function | SmallTest | Level1)
283 {
284     bool interactive = true;
285     ASSERT_TRUE((sessionStage_ != nullptr));
286     sessionStage_->NotifyForegroundInteractiveStatus(interactive);
287     interactive = false;
288     sessionStage_->NotifyForegroundInteractiveStatus(interactive);
289 }
290 
291 /**
292  * @tc.name: NotifySessionForeground
293  * @tc.desc: test function : NotifySessionForeground
294  * @tc.type: FUNC
295  */
296 HWTEST_F(SessionStageProxyTest, NotifySessionForeground, Function | SmallTest | Level1)
297 {
298     uint32_t reason = 1;
299     bool withAnimation = true;
300     ASSERT_TRUE((sessionStage_ != nullptr));
301     sessionStage_->NotifySessionForeground(reason, withAnimation);
302 }
303 
304 /**
305  * @tc.name: NotifySessionBackground
306  * @tc.desc: test function : NotifySessionBackground
307  * @tc.type: FUNC
308  */
309 HWTEST_F(SessionStageProxyTest, NotifySessionBackground, Function | SmallTest | Level1)
310 {
311     uint32_t reason = 1;
312     bool withAnimation = true;
313     bool isFromInnerkits = true;
314     ASSERT_TRUE((sessionStage_ != nullptr));
315     sessionStage_->NotifySessionBackground(reason, withAnimation, isFromInnerkits);
316 }
317 
318 /**
319  * @tc.name: NotifyWindowVisibility
320  * @tc.desc: test function : NotifyWindowVisibility
321  * @tc.type: FUNC
322  */
323 HWTEST_F(SessionStageProxyTest, NotifyWindowVisibility, Function | SmallTest | Level1)
324 {
325     ASSERT_TRUE((sessionStage_ != nullptr));
326     sessionStage_->NotifyWindowVisibility(true);
327 }
328 
329 /**
330  * @tc.name: NotifyCompatibleModeEnableInPad
331  * @tc.desc: test function : NotifyCompatibleModeEnableInPad
332  * @tc.type: FUNC
333  */
334 HWTEST_F(SessionStageProxyTest, NotifyCompatibleModeEnableInPad, Function | SmallTest | Level1)
335 {
336     ASSERT_TRUE((sessionStage_ != nullptr));
337     WSError res = sessionStage_->NotifyCompatibleModeEnableInPad(true);
338     ASSERT_EQ(WSError::WS_OK, res);
339 }
340 
341 /**
342  * @tc.name: NotifyDensityFollowHost
343  * @tc.desc: test function : NotifyDensityFollowHost
344  * @tc.type: FUNC
345  */
346 HWTEST_F(SessionStageProxyTest, NotifyDensityFollowHost, Function | SmallTest | Level1)
347 {
348     ASSERT_TRUE((sessionStage_ != nullptr));
349     ASSERT_EQ(WSError::WS_OK, sessionStage_->NotifyDensityFollowHost(true, 1.0f));
350 }
351 
352 /**
353  * @tc.name: SetPipActionEvent
354  * @tc.desc: test function : SetPipActionEvent
355  * @tc.type: FUNC
356  */
357 HWTEST_F(SessionStageProxyTest, SetPipActionEvent, Function | SmallTest | Level1)
358 {
359     ASSERT_TRUE((sessionStage_ != nullptr));
360     sessionStage_->SetPipActionEvent("close", 0);
361 }
362 
363 /**
364  * @tc.name: SetPiPControlEvent
365  * @tc.desc: test function : SetPiPControlEvent
366  * @tc.type: FUNC
367  */
368 HWTEST_F(SessionStageProxyTest, SetPiPControlEvent, Function | SmallTest | Level1)
369 {
370     ASSERT_TRUE(sessionStage_ != nullptr);
371     auto controlType = WsPiPControlType::VIDEO_PLAY_PAUSE;
372     auto status = WsPiPControlStatus::PLAY;
373     sessionStage_->SetPiPControlEvent(controlType, status);
374 }
375 
376 /**
377  * @tc.name: NotifyDumpInfo
378  * @tc.desc: test function : NotifyDumpInfo
379  * @tc.type: FUNC
380  */
381 HWTEST_F(SessionStageProxyTest, NotifyDumpInfo, Function | SmallTest | Level1)
382 {
383     ASSERT_TRUE(sessionStage_ != nullptr);
384     std::vector<std::string> params;
385     std::vector<std::string> info;
386     auto res = sessionStage_->NotifyDumpInfo(params, info);
387     ASSERT_NE(WSError::WS_OK, res);
388 
389     MockMessageParcel::SetReadStringVectorErrorFlag(true);
390     res = sessionStage_->NotifyDumpInfo(params, info);
391     ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
392 
393     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
394     res = sessionStage_->NotifyDumpInfo(params, info);
395     ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
396     sptr<SessionStageProxy> sessionStage = new SessionStageProxy(nullptr);
397     res = sessionStage->NotifyDumpInfo(params, info);
398     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, res);
399     MockMessageParcel::ClearAllErrorFlag();
400 }
401 
402 /**
403  * @tc.name: SetEnableDragBySystem
404  * @tc.desc: test function : SetEnableDragBySystem
405  * @tc.type: FUNC
406  */
407 HWTEST_F(SessionStageProxyTest, SetEnableDragBySystem, Function | SmallTest | Level1)
408 {
409     ASSERT_TRUE(sessionStage_ != nullptr);
410     WSError res = sessionStage_->SetEnableDragBySystem(false);
411     ASSERT_EQ(WSError::WS_OK, res);
412 }
413 }
414 }
415 }