• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 #include <message_option.h>
18 #include <message_parcel.h>
19 
20 #include "iremote_object_mocker.h"
21 #include "session_manager/include/scene_session_manager.h"
22 #include "session_manager/include/zidl/scene_session_manager_interface.h"
23 #include "session/container/include/window_event_channel.h"
24 #include "window_manager_agent.h"
25 #include "zidl/scene_session_manager_stub.h"
26 #include "zidl/window_manager_agent_interface.h"
27 #include "pattern_detach_callback.h"
28 #include "test/mock/mock_session_stage.h"
29 
30 using namespace testing;
31 using namespace testing::ext;
32 namespace OHOS {
33 namespace Rosen {
34 class SceneSessionManagerStubLifecycleTest : public testing::Test {
35 public:
36     static void SetUpTestCase();
37     static void TearDownTestCase();
38     void SetUp() override;
39     void TearDown() override;
40     sptr<SceneSessionManagerStub> stub_;
41 private:
42     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
43 };
44 
SetUpTestCase()45 void SceneSessionManagerStubLifecycleTest::SetUpTestCase()
46 {
47 }
48 
TearDownTestCase()49 void SceneSessionManagerStubLifecycleTest::TearDownTestCase()
50 {
51 }
52 
SetUp()53 void SceneSessionManagerStubLifecycleTest::SetUp()
54 {
55     stub_ = sptr<SceneSessionManager>::MakeSptr();
56 }
57 
TearDown()58 void SceneSessionManagerStubLifecycleTest::TearDown()
59 {
60     usleep(WAIT_SYNC_IN_NS);
61 }
62 
63 namespace {
64 /**
65  * @tc.name: HandleRecoverAndReconnectSceneSession
66  * @tc.desc: test HandleRecoverAndReconnectSceneSession
67  * @tc.type: FUNC
68  */
69 HWTEST_F(SceneSessionManagerStubLifecycleTest, HandleRecoverAndReconnectSceneSession, Function | SmallTest | Level2)
70 {
71     if (stub_ == nullptr) {
72         return;
73     }
74 
75     MessageParcel data;
76     MessageParcel reply;
77 
78     sptr<ISessionStage> sessionStage = sptr<SessionStageMocker>::MakeSptr();
79     ASSERT_NE(nullptr, sessionStage);
80     int res = stub_->HandleRecoverAndReconnectSceneSession(data, reply);
81     ASSERT_EQ(res, ERR_INVALID_DATA);
82 
83     data.WriteRemoteObject(sessionStage->AsObject());
84     sptr<IWindowEventChannel> eventChannel = sptr<WindowEventChannel>::MakeSptr(sessionStage);
85     ASSERT_NE(nullptr, eventChannel);
86     data.WriteRemoteObject(eventChannel->AsObject());
87     struct RSSurfaceNodeConfig surfaceNodeConfig;
88     surfaceNodeConfig.SurfaceNodeName = "SurfaceNode";
89     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(surfaceNodeConfig, RSSurfaceNodeType::DEFAULT);
90     surfaceNode->Marshalling(data);
91     data.WriteBool(false);
92     res = stub_->HandleRecoverAndReconnectSceneSession(data, reply);
93     ASSERT_EQ(res, ERR_INVALID_STATE);
94 
95     data.WriteRemoteObject(sessionStage->AsObject());
96     data.WriteRemoteObject(eventChannel->AsObject());
97     surfaceNode->Marshalling(data);
98     data.WriteBool(true);
99     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
100     ASSERT_NE(nullptr, property);
101     property->SetTokenState(true);
102     data.WriteStrongParcelable(property);
103     sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
104     ASSERT_NE(nullptr, windowManagerAgent);
105     data.WriteRemoteObject(windowManagerAgent->AsObject());
106     res = stub_->HandleRecoverAndReconnectSceneSession(data, reply);
107     EXPECT_EQ(res, ERR_INVALID_STATE);
108 }
109 
110 /**
111  * @tc.name: HandlePendingSessionToForeground
112  * @tc.desc: test HandlePendingSessionToForeground
113  * @tc.type: FUNC
114  */
115 HWTEST_F(SceneSessionManagerStubLifecycleTest, HandlePendingSessionToForeground, Function | SmallTest | Level2)
116 {
117     MessageParcel data;
118     MessageParcel reply;
119 
120     sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
121     data.WriteRemoteObject(windowManagerAgent->AsObject());
122 
123     int res = stub_->HandlePendingSessionToForeground(data, reply);
124     EXPECT_EQ(res, ERR_NONE);
125 }
126 
127 /**
128  * @tc.name: HandlePendingSessionToBackgroundForDelegator
129  * @tc.desc: test HandlePendingSessionToBackgroundForDelegator
130  * @tc.type: FUNC
131  */
132 HWTEST_F(
133     SceneSessionManagerStubLifecycleTest,
134     HandlePendingSessionToBackgroundForDelegator,
135     Function | SmallTest | Level2
136 )
137 {
138     MessageParcel data;
139     MessageParcel reply;
140 
141     sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
142     data.WriteRemoteObject(windowManagerAgent->AsObject());
143 
144     int res = stub_->HandlePendingSessionToBackgroundForDelegator(data, reply);
145     EXPECT_EQ(res, ERR_INVALID_DATA);
146 }
147 
148 /**
149  * @tc.name: HandleTerminateSessionNew
150  * @tc.desc: test HandleTerminateSessionNew
151  * @tc.type: FUNC
152  */
153 HWTEST_F(SceneSessionManagerStubLifecycleTest, HandleTerminateSessionNew, Function | SmallTest | Level2)
154 {
155     MessageParcel data;
156     MessageParcel reply;
157 
158     data.WriteBool(false);
159 
160     int res = stub_->HandleTerminateSessionNew(data, reply);
161     EXPECT_EQ(res, ERR_INVALID_DATA);
162 }
163 
164 /**
165  * @tc.name: HandleSetSessionContinueState
166  * @tc.desc: test HandleSetSessionContinueState
167  * @tc.type: FUNC
168  */
169 HWTEST_F(SceneSessionManagerStubLifecycleTest, HandleSetSessionContinueState, Function | SmallTest | Level2)
170 {
171     MessageParcel data;
172     MessageParcel reply;
173 
174     int32_t x = 1;
175     sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
176     data.WriteRemoteObject(windowManagerAgent->AsObject());
177     data.WriteInt32(x);
178 
179     int res = stub_->HandleSetSessionContinueState(data, reply);
180     EXPECT_EQ(res, ERR_NONE);
181 }
182 
183 /**
184  * @tc.name: HandleClearSession
185  * @tc.desc: test HandleClearSession
186  * @tc.type: FUNC
187  */
188 HWTEST_F(SceneSessionManagerStubLifecycleTest, HandleClearSession, Function | SmallTest | Level2)
189 {
190     if (stub_ == nullptr) {
191         return;
192     }
193 
194     MessageParcel data;
195     MessageParcel reply;
196 
197     auto res = stub_->HandleClearSession(data, reply);
198     EXPECT_EQ(res, ERR_INVALID_DATA);
199 
200     int32_t persistentId = 65535;
201     data.WriteInt32(persistentId);
202 
203     res = stub_->HandleClearSession(data, reply);
204     EXPECT_EQ(res, ERR_NONE);
205 }
206 
207 /**
208  * @tc.name: HandleClearAllSessions
209  * @tc.desc: test HandleClearAllSessions
210  * @tc.type: FUNC
211  */
212 HWTEST_F(SceneSessionManagerStubLifecycleTest, HandleClearAllSessions, Function | SmallTest | Level2)
213 {
214     if (stub_ == nullptr) {
215         return;
216     }
217 
218     MessageParcel data;
219     MessageParcel reply;
220 
221     int res = stub_->HandleClearAllSessions(data, reply);
222     EXPECT_EQ(res, ERR_NONE);
223 }
224 
225 /**
226  * @tc.name: HandleLockSession
227  * @tc.desc: test HandleLockSession
228  * @tc.type: FUNC
229  */
230 HWTEST_F(SceneSessionManagerStubLifecycleTest, HandleLockSession, Function | SmallTest | Level2)
231 {
232     if (stub_ == nullptr) {
233         return;
234     }
235 
236     MessageParcel data;
237     MessageParcel reply;
238 
239     auto res = stub_->HandleLockSession(data, reply);
240     EXPECT_EQ(res, ERR_INVALID_DATA);
241     int32_t sessionId = 65535;
242     data.WriteInt32(sessionId);
243     res = stub_->HandleLockSession(data, reply);
244     EXPECT_EQ(res, ERR_NONE);
245 }
246 
247 /**
248  * @tc.name: HandleUnlockSession
249  * @tc.desc: test HandleUnlockSession
250  * @tc.type: FUNC
251  */
252 HWTEST_F(SceneSessionManagerStubLifecycleTest, HandleUnlockSession, Function | SmallTest | Level2)
253 {
254     if (stub_ == nullptr) {
255         return;
256     }
257 
258     MessageParcel data;
259     MessageParcel reply;
260 
261     auto res = stub_->HandleUnlockSession(data, reply);
262     EXPECT_EQ(res, ERR_INVALID_DATA);
263     int32_t sessionId = 65535;
264     data.WriteInt32(sessionId);
265     res = stub_->HandleUnlockSession(data, reply);
266     EXPECT_EQ(res, ERR_NONE);
267 }
268 
269 /**
270  * @tc.name: HandleMoveSessionsToForeground
271  * @tc.desc: test HandleMoveSessionsToForeground
272  * @tc.type: FUNC
273  */
274 HWTEST_F(SceneSessionManagerStubLifecycleTest, HandleMoveSessionsToForeground, Function | SmallTest | Level2)
275 {
276     if (stub_ == nullptr) {
277         return;
278     }
279 
280     MessageParcel data;
281     MessageParcel reply;
282 
283     auto res = stub_->HandleMoveSessionsToForeground(data, reply);
284     EXPECT_EQ(res, ERR_INVALID_DATA);
285 
286     std::vector<int32_t> sessionIds = {1, 2, 3, 15, 1423};
287     data.WriteInt32Vector(sessionIds);
288     int32_t topSessionId = 1;
289     data.WriteInt32(topSessionId);
290     res = stub_->HandleMoveSessionsToForeground(data, reply);
291     EXPECT_EQ(res, ERR_NONE);
292 }
293 
294 /**
295  * @tc.name: HandleMoveSessionsToBackground
296  * @tc.desc: test HandleMoveSessionsToBackground
297  * @tc.type: FUNC
298  */
299 HWTEST_F(SceneSessionManagerStubLifecycleTest, HandleMoveSessionsToBackground, Function | SmallTest | Level2)
300 {
301     if (stub_ == nullptr) {
302         return;
303     }
304 
305     MessageParcel data;
306     MessageParcel reply;
307 
308     std::vector<int32_t> sessionIds = {1, 2, 3, 15, 1423};
309     data.WriteInt32Vector(sessionIds);
310     std::vector<int32_t> result = {1, 2, 3, 15, 1423};
311     data.WriteInt32Vector(result);
312 
313     int res = stub_->HandleMoveSessionsToBackground(data, reply);
314     EXPECT_EQ(res, ERR_NONE);
315 }
316 
317 /**
318  * @tc.name: HandleUpdateSessionWindowVisibilityListener
319  * @tc.desc: test HandleUpdateSessionWindowVisibilityListener
320  * @tc.type: FUNC
321  */
322 HWTEST_F(
323     SceneSessionManagerStubLifecycleTest,
324     HandleUpdateSessionWindowVisibilityListener,
325     Function | SmallTest | Level2
326 )
327 {
328     MessageParcel data;
329     MessageParcel reply;
330 
331     data.WriteInt32(0);
332     data.WriteBool(true);
333 
334     int res = stub_->HandleUpdateSessionWindowVisibilityListener(data, reply);
335     EXPECT_EQ(res, ERR_NONE);
336 }
337 
338 /**
339  * @tc.name: HandleGetVisibilityWindowInfo
340  * @tc.desc: test HandleGetVisibilityWindowInfo
341  * @tc.type: FUNC
342  */
343 HWTEST_F(SceneSessionManagerStubLifecycleTest, HandleGetVisibilityWindowInfo, Function | SmallTest | Level2)
344 {
345     if (stub_ == nullptr) {
346         return;
347     }
348 
349     MessageParcel data;
350     MessageParcel reply;
351 
352     int res = stub_->HandleGetVisibilityWindowInfo(data, reply);
353     EXPECT_EQ(res, ERR_NONE);
354 }
355 }
356 }
357 }