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 "window_helper.h"
17 #include "display_manager.h"
18 #include "pointer_event.h"
19
20 #include <gtest/gtest.h>
21 #include "key_event.h"
22 #include "session/host/include/scene_session.h"
23 #include "session/host/include/sub_session.h"
24 #include "session/host/include/system_session.h"
25 #include "session/host/include/main_session.h"
26 #include "wm_common.h"
27 #include "mock/mock_session_stage.h"
28 #include "input_event.h"
29 #include <pointer_event.h>
30 #include "ui/rs_surface_node.h"
31 #include "session/container/include/window_event_channel.h"
32 #include "window_event_channel_base.h"
33
34 using namespace testing;
35 using namespace testing::ext;
36 namespace OHOS {
37 namespace Rosen {
38 class SceneSessionLifecycleTest : public testing::Test {
39 public:
40 static void SetUpTestCase();
41 static void TearDownTestCase();
42 void SetUp() override;
43 void TearDown() override;
44 sptr <SceneSession> sceneSession;
45 SessionInfo info;
46 };
47
SetUpTestCase()48 void SceneSessionLifecycleTest::SetUpTestCase()
49 {
50 }
51
TearDownTestCase()52 void SceneSessionLifecycleTest::TearDownTestCase()
53 {
54 }
55
SetUp()56 void SceneSessionLifecycleTest::SetUp()
57 {
58 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
59 }
60
TearDown()61 void SceneSessionLifecycleTest::TearDown()
62 {
63 }
64
65 namespace {
66
67 /**
68 * @tc.name: Foreground01
69 * @tc.desc: normal function
70 * @tc.type: FUNC
71 */
HWTEST_F(SceneSessionLifecycleTest, Foreground01, Function | SmallTest | Level2)72 HWTEST_F(SceneSessionLifecycleTest, Foreground01, Function | SmallTest | Level2)
73 {
74 SessionInfo info;
75 info.abilityName_ = "Foreground01";
76 info.bundleName_ = "Foreground01";
77 sptr<Rosen::ISession> session_;
78 sptr<SceneSession::SpecificSessionCallback> specificCallback =
79 new (std::nothrow) SceneSession::SpecificSessionCallback();
80 EXPECT_NE(specificCallback, nullptr);
81 int resultValue = 0;
82 sptr<SceneSession> sceneSession;
83
84 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
85 EXPECT_NE(sceneSession, nullptr);
86 sceneSession->isActive_ = true;
87 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
88 ASSERT_NE(nullptr, property);
89
90 auto result = sceneSession->Foreground(property);
91 ASSERT_EQ(result, WSError::WS_OK);
92 specificCallback->onCreate_ = [&resultValue, specificCallback](const SessionInfo& info,
93 sptr<WindowSessionProperty> property) -> sptr<SceneSession>
94 {
95 sptr<SceneSession> scensessionreturn = new (std::nothrow) SceneSession(info, specificCallback);
96 EXPECT_NE(scensessionreturn, nullptr);
97 resultValue = 1;
98 return scensessionreturn;
99 };
100 sceneSession = new (std::nothrow) SceneSession(info, specificCallback);
101 EXPECT_NE(sceneSession, nullptr);
102 sceneSession->UpdateSessionState(SessionState::STATE_DISCONNECT);
103 sceneSession->isActive_ = true;
104 result = sceneSession->Foreground(property);
105 ASSERT_EQ(result, WSError::WS_OK);
106 }
107
108 /**
109 * @tc.name: Foreground02
110 * @tc.desc: normal function
111 * @tc.type: FUNC
112 */
HWTEST_F(SceneSessionLifecycleTest, Foreground02, Function | SmallTest | Level2)113 HWTEST_F(SceneSessionLifecycleTest, Foreground02, Function | SmallTest | Level2)
114 {
115 SessionInfo info;
116 info.abilityName_ = "Foreground02";
117 info.bundleName_ = "Foreground02";
118 sptr<Rosen::ISession> session_;
119 sptr<SceneSession::SpecificSessionCallback> specificCallback =
120 new (std::nothrow) SceneSession::SpecificSessionCallback();
121 EXPECT_NE(specificCallback, nullptr);
122 sptr<SceneSession> sceneSession;
123
124 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
125 EXPECT_NE(sceneSession, nullptr);
126 sceneSession->isActive_ = true;
127 sptr<WindowSessionProperty> property = nullptr;
128 auto result = sceneSession->Foreground(property);
129 ASSERT_EQ(result, WSError::WS_OK);
130 }
131
132 /**
133 * @tc.name: ForegroundAndBackground03
134 * @tc.desc: normal function
135 * @tc.type: FUNC
136 */
HWTEST_F(SceneSessionLifecycleTest, Foreground03, Function | SmallTest | Level2)137 HWTEST_F(SceneSessionLifecycleTest, Foreground03, Function | SmallTest | Level2)
138 {
139 SessionInfo info;
140 info.abilityName_ = "Foreground03";
141 info.bundleName_ = "Foreground03";
142 sptr<Rosen::ISession> session_;
143 sptr<SceneSession::SpecificSessionCallback> specificCallback =
144 new (std::nothrow) SceneSession::SpecificSessionCallback();
145 EXPECT_NE(specificCallback, nullptr);
146 sptr<SceneSession> sceneSession;
147
148 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
149 EXPECT_NE(sceneSession, nullptr);
150 sceneSession->isActive_ = true;
151 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
152 property->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::CUSTOM));
153 auto result = sceneSession->Foreground(property);
154 ASSERT_EQ(result, WSError::WS_OK);
155 }
156
157 /**
158 * @tc.name: Foreground04
159 * @tc.desc: Foreground04 function
160 * @tc.type: FUNC
161 */
HWTEST_F(SceneSessionLifecycleTest, Foreground04, Function | SmallTest | Level2)162 HWTEST_F(SceneSessionLifecycleTest, Foreground04, Function | SmallTest | Level2)
163 {
164 SessionInfo info;
165 info.abilityName_ = "Foreground04";
166 info.bundleName_ = "Foreground04";
167
168 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
169 EXPECT_NE(session, nullptr);
170 sptr<WindowSessionProperty> property = nullptr;
171 EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false));
172
173 session->property_ = nullptr;
174 EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false));
175
176 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
177 sptr<SceneSession> session1 = sptr<SceneSession>::MakeSptr(info, nullptr);
178 EXPECT_EQ(WSError::WS_OK, session1->Foreground(property, true));
179 EXPECT_EQ(WSError::WS_OK, session1->Foreground(property, false));
180 }
181
182 /**
183 * @tc.name: Foreground05
184 * @tc.desc: Foreground05 function
185 * @tc.type: FUNC
186 */
HWTEST_F(SceneSessionLifecycleTest, Foreground05, Function | SmallTest | Level2)187 HWTEST_F(SceneSessionLifecycleTest, Foreground05, Function | SmallTest | Level2)
188 {
189 SessionInfo info;
190 info.abilityName_ = "Foreground05";
191 info.bundleName_ = "Foreground05";
192
193 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
194 EXPECT_NE(session, nullptr);
195 sptr<WindowSessionProperty> property = nullptr;
196 session->Session::SetSessionState(SessionState::STATE_CONNECT);
197 session->Session::isActive_ = true;
198 session->SetLeashWinSurfaceNode(nullptr);
199 EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false));
200
201 sptr<SceneSession::SpecificSessionCallback> specificCallback =
202 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
203 session->specificCallback_ = specificCallback;
204 EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false));
205
206 struct RSSurfaceNodeConfig config;
207 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
208 session->SetLeashWinSurfaceNode(surfaceNode);
209 EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false));
210
211 session->SetSessionProperty(property);
212 EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false));
213 }
214
215 /**
216 * @tc.name: Foreground06
217 * @tc.desc: Foreground06 function
218 * @tc.type: FUNC
219 */
HWTEST_F(SceneSessionLifecycleTest, Foreground06, Function | SmallTest | Level2)220 HWTEST_F(SceneSessionLifecycleTest, Foreground06, Function | SmallTest | Level2)
221 {
222 SessionInfo info;
223 info.abilityName_ = "Foreground06";
224 info.bundleName_ = "Foreground06";
225
226 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
227 EXPECT_NE(session, nullptr);
228 sptr<WindowSessionProperty> property = nullptr;
229 session->property_ = property;
230 EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false));
231
232 session->SetLeashWinSurfaceNode(nullptr);
233 EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false));
234
235 sptr<WindowSessionProperty> property2 = new (std::nothrow) WindowSessionProperty();
236 EXPECT_NE(property2, nullptr);
237 property2->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::CUSTOM));
238 EXPECT_EQ(WSError::WS_OK, session->Foreground(property2, false));
239
240 struct RSSurfaceNodeConfig config;
241 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
242 session->SetLeashWinSurfaceNode(surfaceNode);
243 EXPECT_EQ(WSError::WS_OK, session->Foreground(property2, false));
244
245 sptr<WindowSessionProperty> property3 = new (std::nothrow) WindowSessionProperty();
246 EXPECT_NE(property3, nullptr);
247 property3->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
248 session->SetSessionProperty(property3);
249 EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false));
250 }
251
252 /**
253 * @tc.name: Background01
254 * @tc.desc: normal function
255 * @tc.type: FUNC
256 */
HWTEST_F(SceneSessionLifecycleTest, Background01, Function | SmallTest | Level2)257 HWTEST_F(SceneSessionLifecycleTest, Background01, Function | SmallTest | Level2)
258 {
259 SessionInfo info;
260 info.abilityName_ = "Background01";
261 info.bundleName_ = "Background01";
262 sptr<Rosen::ISession> session_;
263 sptr<SceneSession::SpecificSessionCallback> specificCallback =
264 new (std::nothrow) SceneSession::SpecificSessionCallback();
265 EXPECT_NE(specificCallback, nullptr);
266 int resultValue = 0;
267 sptr<SceneSession> sceneSession;
268
269 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
270 EXPECT_NE(sceneSession, nullptr);
271 sceneSession->isActive_ = true;
272 auto result = sceneSession->Background();
273 ASSERT_EQ(result, WSError::WS_OK);
274 specificCallback->onCreate_ = [&resultValue, specificCallback](const SessionInfo& info,
275 sptr<WindowSessionProperty> property) -> sptr<SceneSession>
276 {
277 sptr<SceneSession> scensessionreturn = new (std::nothrow) SceneSession(info, specificCallback);
278 EXPECT_NE(scensessionreturn, nullptr);
279 resultValue = 1;
280 return scensessionreturn;
281 };
282 sceneSession = new (std::nothrow) SceneSession(info, specificCallback);
283 EXPECT_NE(sceneSession, nullptr);
284 sceneSession->UpdateSessionState(SessionState::STATE_CONNECT);
285 sceneSession->isActive_ = true;
286 result = sceneSession->Background();
287 ASSERT_EQ(result, WSError::WS_OK);
288 }
289
290 /**
291 * @tc.name: Background02
292 * @tc.desc: normal function
293 * @tc.type: FUNC
294 */
HWTEST_F(SceneSessionLifecycleTest, Background02, Function | SmallTest | Level2)295 HWTEST_F(SceneSessionLifecycleTest, Background02, Function | SmallTest | Level2)
296 {
297 SessionInfo info;
298 info.abilityName_ = "Background02";
299 info.bundleName_ = "Background02";
300 sptr<Rosen::ISession> session_;
301 sptr<SceneSession::SpecificSessionCallback> specificCallback =
302 new (std::nothrow) SceneSession::SpecificSessionCallback();
303 EXPECT_NE(specificCallback, nullptr);
304 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
305 EXPECT_NE(sceneSession, nullptr);
306
307 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
308 property->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::CUSTOM));
309 sceneSession->SetSessionProperty(property);
310 sceneSession->isActive_ = true;
311 auto result = sceneSession->Background();
312 ASSERT_EQ(result, WSError::WS_OK);
313 }
314
315 /**
316 * @tc.name: Background04
317 * @tc.desc: normal function
318 * @tc.type: FUNC
319 */
HWTEST_F(SceneSessionLifecycleTest, Background04, Function | SmallTest | Level2)320 HWTEST_F(SceneSessionLifecycleTest, Background04, Function | SmallTest | Level2)
321 {
322 SessionInfo info;
323 info.abilityName_ = "Background04";
324 info.bundleName_ = "Background04";
325 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
326 EXPECT_NE(nullptr, sceneSession);
327
328 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
329 EXPECT_NE(property, nullptr);
330 property->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::CUSTOM));
331 sceneSession->SetSessionProperty(property);
332 EXPECT_EQ(WSError::WS_OK, sceneSession->Background(true));
333
334 sptr<WindowSessionProperty> property2 = new (std::nothrow) WindowSessionProperty();
335 EXPECT_NE(property2, nullptr);
336 property2->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
337 sceneSession->SetSessionProperty(property2);
338 EXPECT_EQ(WSError::WS_OK, sceneSession->Background(false));
339 EXPECT_EQ(WSError::WS_OK, sceneSession->Background(true));
340 }
341
342 /**
343 * @tc.name: BackgroundTask01
344 * @tc.desc: normal function
345 * @tc.type: FUNC
346 */
HWTEST_F(SceneSessionLifecycleTest, BackgroundTask01, Function | SmallTest | Level2)347 HWTEST_F(SceneSessionLifecycleTest, BackgroundTask01, Function | SmallTest | Level2)
348 {
349 SessionInfo info;
350 info.abilityName_ = "BackgroundTask01";
351 info.bundleName_ = "BackgroundTask01";
352 sptr<SceneSession::SpecificSessionCallback> specificCallback =
353 new (std::nothrow) SceneSession::SpecificSessionCallback();
354 EXPECT_NE(specificCallback, nullptr);
355 int resultValue = 0;
356 sptr<SceneSession> sceneSession;
357 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
358 EXPECT_NE(sceneSession, nullptr);
359 sceneSession->isActive_ = true;
360 auto result = sceneSession->BackgroundTask();
361 ASSERT_EQ(result, WSError::WS_OK);
362 sceneSession->isActive_ = true;
363 result = sceneSession->BackgroundTask(false);
364 ASSERT_EQ(result, WSError::WS_OK);
365 specificCallback->onCreate_ =
366 [&resultValue, specificCallback](const SessionInfo& info,
367 sptr<WindowSessionProperty> property) -> sptr<SceneSession>
368 {
369 sptr<SceneSession> sceneSessionReturn = new (std::nothrow) SceneSession(info, specificCallback);
370 EXPECT_NE(sceneSessionReturn, nullptr);
371 resultValue = 1;
372 return sceneSessionReturn;
373 };
374 sceneSession = new (std::nothrow) SceneSession(info, specificCallback);
375 EXPECT_NE(sceneSession, nullptr);
376 sceneSession->UpdateSessionState(SessionState::STATE_CONNECT);
377 sceneSession->isActive_ = true;
378 result = sceneSession->BackgroundTask();
379 ASSERT_EQ(result, WSError::WS_OK);
380 sceneSession->UpdateSessionState(SessionState::STATE_CONNECT);
381 sceneSession->isActive_ = true;
382 result = sceneSession->BackgroundTask(false);
383 ASSERT_EQ(result, WSError::WS_OK);
384 }
385
386 /**
387 * @tc.name: BackgroundTask02
388 * @tc.desc: normal function
389 * @tc.type: FUNC
390 */
HWTEST_F(SceneSessionLifecycleTest, BackgroundTask02, Function | SmallTest | Level2)391 HWTEST_F(SceneSessionLifecycleTest, BackgroundTask02, Function | SmallTest | Level2)
392 {
393 SessionInfo info;
394 info.abilityName_ = "BackgroundTask02";
395 info.bundleName_ = "BackgroundTask02";
396 sptr<SceneSession::SpecificSessionCallback> specificCallback =
397 new (std::nothrow) SceneSession::SpecificSessionCallback();
398 EXPECT_NE(specificCallback, nullptr);
399 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
400 EXPECT_NE(sceneSession, nullptr);
401 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
402 property->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::CUSTOM));
403 sceneSession->SetSessionProperty(property);
404 sceneSession->isActive_ = true;
405 auto result = sceneSession->BackgroundTask();
406 ASSERT_EQ(result, WSError::WS_OK);
407 sceneSession->isActive_ = true;
408 result = sceneSession->BackgroundTask(false);
409 ASSERT_EQ(result, WSError::WS_OK);
410 }
411
412 /**
413 * @tc.name: BackgroundTask03
414 * @tc.desc: BackgroundTask03 function
415 * @tc.type: FUNC
416 */
HWTEST_F(SceneSessionLifecycleTest, BackgroundTask03, Function | SmallTest | Level2)417 HWTEST_F(SceneSessionLifecycleTest, BackgroundTask03, Function | SmallTest | Level2)
418 {
419 SessionInfo info;
420 info.abilityName_ = "BackgroundTask03";
421 info.bundleName_ = "BackgroundTask03";
422
423 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
424 EXPECT_NE(session, nullptr);
425 sptr<WindowSessionProperty> property = nullptr;
426 session->SetSessionState(SessionState::STATE_BACKGROUND);
427 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false));
428
429 session->SetSessionState(SessionState::STATE_CONNECT);
430 session->Session::SetSessionState(SessionState::STATE_CONNECT);
431 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false));
432
433 session->Session::SetSessionState(SessionState::STATE_INACTIVE);
434 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
435 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false));
436
437 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
438 sptr<SceneSession::SpecificSessionCallback> specificCallback =
439 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
440 session->specificCallback_ = specificCallback;
441 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false));
442
443 session->scenePersistence_ = nullptr;
444 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(true));
445
446 session->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("Foreground02", 1);
447 struct RSSurfaceNodeConfig config;
448 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
449 session->surfaceNode_ = surfaceNode;
450 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(true));
451
452 sptr<WindowSessionProperty> property2 = new (std::nothrow) WindowSessionProperty();
453 EXPECT_NE(property2, nullptr);
454 property2->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
455 session->SetSessionProperty(property2);
456 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false));
457 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(true));
458 }
459
460 /**
461 * @tc.name: DisconnectTask01
462 * @tc.desc: normal function
463 * @tc.type: FUNC
464 */
HWTEST_F(SceneSessionLifecycleTest, DisconnectTask01, Function | SmallTest | Level2)465 HWTEST_F(SceneSessionLifecycleTest, DisconnectTask01, Function | SmallTest | Level2)
466 {
467 SessionInfo info;
468 info.abilityName_ = "DisconnectTask01";
469 info.bundleName_ = "DisconnectTask01";
470 sptr<SceneSession::SpecificSessionCallback> specificCallback =
471 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
472 EXPECT_NE(specificCallback, nullptr);
473
474 int resultValue = 0;
475 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
476 EXPECT_NE(sceneSession, nullptr);
477 sceneSession->isActive_ = true;
478 auto result = sceneSession->DisconnectTask(true, true);
479 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
480 ASSERT_EQ(result, WSError::WS_OK);
481 sceneSession->isActive_ = true;
482 result = sceneSession->DisconnectTask(false, true);
483 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
484 ASSERT_EQ(result, WSError::WS_OK);
485 specificCallback->onCreate_ =
486 [&resultValue, specificCallback](const SessionInfo& info,
487 sptr<WindowSessionProperty> property) -> sptr<SceneSession> {
488 sptr<SceneSession> sceneSessionReturn = new (std::nothrow) SceneSession(info, specificCallback);
489 EXPECT_NE(sceneSessionReturn, nullptr);
490 resultValue = 1;
491 return sceneSessionReturn;
492 };
493 sceneSession = new (std::nothrow) SceneSession(info, specificCallback);
494 EXPECT_NE(sceneSession, nullptr);
495 sceneSession->UpdateSessionState(SessionState::STATE_CONNECT);
496 sceneSession->isActive_ = true;
497 result = sceneSession->DisconnectTask(true, true);
498 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
499 ASSERT_EQ(result, WSError::WS_OK);
500 sceneSession->UpdateSessionState(SessionState::STATE_CONNECT);
501 sceneSession->isActive_ = true;
502 result = sceneSession->DisconnectTask(false, true);
503 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
504 ASSERT_EQ(result, WSError::WS_OK);
505 }
506
507 /**
508 * @tc.name: DisconnectTask02
509 * @tc.desc: normal function
510 * @tc.type: FUNC
511 */
HWTEST_F(SceneSessionLifecycleTest, DisconnectTask02, Function | SmallTest | Level2)512 HWTEST_F(SceneSessionLifecycleTest, DisconnectTask02, Function | SmallTest | Level2)
513 {
514 SessionInfo info;
515 info.abilityName_ = "DisconnectTask02";
516 info.bundleName_ = "DisconnectTask02";
517 sptr<SceneSession::SpecificSessionCallback> specificCallback =
518 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
519 EXPECT_NE(specificCallback, nullptr);
520 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
521 EXPECT_NE(sceneSession, nullptr);
522 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
523 EXPECT_NE(property, nullptr);
524 property->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::CUSTOM));
525 sceneSession->SetSessionProperty(property);
526 sceneSession->isActive_ = true;
527 auto result = sceneSession->DisconnectTask(true, true);
528 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
529 ASSERT_EQ(result, WSError::WS_OK);
530 sceneSession->isActive_ = true;
531 result = sceneSession->DisconnectTask(false, true);
532 ASSERT_EQ(result, WSError::WS_OK);
533 }
534
535 /**
536 * @tc.name: Disconnect
537 * @tc.desc: normal function
538 * @tc.type: FUNC
539 */
HWTEST_F(SceneSessionLifecycleTest, Disconnect, Function | SmallTest | Level2)540 HWTEST_F(SceneSessionLifecycleTest, Disconnect, Function | SmallTest | Level2)
541 {
542 SessionInfo info;
543 info.abilityName_ = "Disconnect";
544 info.bundleName_ = "Disconnect";
545 sptr<Rosen::ISession> session_;
546 sptr<SceneSession::SpecificSessionCallback> specificCallback =
547 new (std::nothrow) SceneSession::SpecificSessionCallback();
548 EXPECT_NE(specificCallback, nullptr);
549 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
550 EXPECT_NE(sceneSession, nullptr);
551
552 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
553 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
554 sceneSession->SetSessionProperty(property);
555 sceneSession->isActive_ = true;
556 auto result = sceneSession->Disconnect();
557 ASSERT_EQ(result, WSError::WS_OK);
558 }
559
560 /**
561 * @tc.name: Disconnect2
562 * @tc.desc: normal function
563 * @tc.type: FUNC
564 */
HWTEST_F(SceneSessionLifecycleTest, Disconnect2, Function | SmallTest | Level2)565 HWTEST_F(SceneSessionLifecycleTest, Disconnect2, Function | SmallTest | Level2)
566 {
567 SessionInfo info;
568 info.abilityName_ = "Disconnect2";
569 info.bundleName_ = "Disconnect2";
570 sptr<Rosen::ISession> session_;
571 sptr<SceneSession::SpecificSessionCallback> specificCallback =
572 new (std::nothrow) SceneSession::SpecificSessionCallback();
573 EXPECT_NE(specificCallback, nullptr);
574 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
575 EXPECT_NE(sceneSession, nullptr);
576
577 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
578 EXPECT_NE(property, nullptr);
579 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
580 sceneSession->SetSessionProperty(property);
581 sceneSession->isActive_ = true;
582
583 auto result = sceneSession->Disconnect(true);
584 ASSERT_EQ(result, WSError::WS_OK);
585 }
586
587 /**
588 * @tc.name: Disconnect3
589 * @tc.desc: normal function
590 * @tc.type: FUNC
591 */
HWTEST_F(SceneSessionLifecycleTest, Disconnect3, Function | SmallTest | Level2)592 HWTEST_F(SceneSessionLifecycleTest, Disconnect3, Function | SmallTest | Level2)
593 {
594 SessionInfo info;
595 info.abilityName_ = "Disconnect3";
596 info.bundleName_ = "Disconnect3";
597 sptr<Rosen::ISession> session_;
598 sptr<SceneSession::SpecificSessionCallback> specificCallback =
599 new (std::nothrow) SceneSession::SpecificSessionCallback();
600 EXPECT_NE(specificCallback, nullptr);
601 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
602 EXPECT_NE(sceneSession, nullptr);
603
604 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
605 EXPECT_NE(property, nullptr);
606 property->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
607 sceneSession->SetSessionProperty(property);
608 sceneSession->isActive_ = true;
609
610 auto result = sceneSession->Disconnect(true);
611 ASSERT_EQ(result, WSError::WS_OK);
612
613 sceneSession->specificCallback_ = nullptr;
614 result = sceneSession->Disconnect(false);
615 ASSERT_EQ(result, WSError::WS_OK);
616
617 sceneSession->needSnapshot_ = true;
618 sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
619 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
620 sceneSession->SetSessionProperty(property);
621
622 result = sceneSession->Disconnect(false);
623 ASSERT_EQ(result, WSError::WS_OK);
624
625 result = sceneSession->DisconnectTask(false, false);
626 ASSERT_EQ(result, WSError::WS_OK);
627
628 result = sceneSession->DisconnectTask(false, true);
629 ASSERT_EQ(result, WSError::WS_OK);
630 }
631
632 /**
633 * @tc.name: UpdateActiveStatus01
634 * @tc.desc: normal function
635 * @tc.type: FUNC
636 */
HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus01, Function | SmallTest | Level2)637 HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus01, Function | SmallTest | Level2)
638 {
639 SessionInfo info;
640 info.abilityName_ = "UpdateActiveStatus01";
641 info.bundleName_ = "UpdateActiveStatus01";
642 sptr<Rosen::ISession> session_;
643 sptr<SceneSession::SpecificSessionCallback> specificCallback =
644 new (std::nothrow) SceneSession::SpecificSessionCallback();
645 EXPECT_NE(specificCallback, nullptr);
646 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
647 EXPECT_NE(sceneSession, nullptr);
648
649 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
650 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
651 sceneSession->SetSessionProperty(property);
652 sceneSession->isActive_ = true;
653 auto result = sceneSession->UpdateActiveStatus(true);
654 ASSERT_EQ(result, WSError::WS_OK);
655
656 result = sceneSession->UpdateActiveStatus(false);
657 ASSERT_EQ(result, WSError::WS_OK);
658 }
659
660 /**
661 * @tc.name: UpdateActiveStatus02
662 * @tc.desc: normal function
663 * @tc.type: FUNC
664 */
HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus02, Function | SmallTest | Level2)665 HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus02, Function | SmallTest | Level2)
666 {
667 SessionInfo info;
668 info.abilityName_ = "UpdateActiveStatus02";
669 info.bundleName_ = "UpdateActiveStatus02";
670 sptr<Rosen::ISession> session_;
671 sptr<SceneSession::SpecificSessionCallback> specificCallback =
672 new (std::nothrow) SceneSession::SpecificSessionCallback();
673 EXPECT_NE(specificCallback, nullptr);
674 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
675 EXPECT_NE(sceneSession, nullptr);
676
677 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
678 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
679 sceneSession->SetSessionProperty(property);
680 sceneSession->isActive_ = false;
681 auto result = sceneSession->UpdateActiveStatus(true);
682 ASSERT_EQ(result, WSError::WS_OK);
683 }
684
685 /**
686 * @tc.name: UpdateActiveStatus03
687 * @tc.desc: normal function
688 * @tc.type: FUNC
689 */
HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus03, Function | SmallTest | Level2)690 HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus03, Function | SmallTest | Level2)
691 {
692 SessionInfo info;
693 info.abilityName_ = "UpdateActiveStatus03";
694 info.bundleName_ = "UpdateActiveStatus03";
695 sptr<Rosen::ISession> session_;
696 sptr<SceneSession::SpecificSessionCallback> specificCallback =
697 new (std::nothrow) SceneSession::SpecificSessionCallback();
698 EXPECT_NE(specificCallback, nullptr);
699 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
700 EXPECT_NE(sceneSession, nullptr);
701
702 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
703 EXPECT_NE(property, nullptr);
704 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
705 sceneSession->SetSessionProperty(property);
706 sceneSession->isActive_ = true;
707 sceneSession->state_ = SessionState::STATE_DISCONNECT;
708
709 auto result = sceneSession->UpdateActiveStatus(false);
710 ASSERT_EQ(result, WSError::WS_OK);
711
712 result = sceneSession->UpdateActiveStatus(true);
713 ASSERT_EQ(result, WSError::WS_OK);
714
715 sceneSession->isActive_ = false;
716 result = sceneSession->UpdateActiveStatus(false);
717 ASSERT_EQ(result, WSError::WS_OK);
718
719 sceneSession->isActive_ = true;
720 sceneSession->state_ = SessionState::STATE_FOREGROUND;
721 result = sceneSession->UpdateActiveStatus(true);
722 ASSERT_EQ(result, WSError::WS_OK);
723
724 sceneSession->isActive_ = true;
725 sceneSession->state_ = SessionState::STATE_ACTIVE;
726 result = sceneSession->UpdateActiveStatus(false);
727 ASSERT_EQ(result, WSError::WS_OK);
728
729 sceneSession->isActive_ = false;
730 result = sceneSession->UpdateActiveStatus(true);
731 ASSERT_EQ(result, WSError::WS_OK);
732 }
733
734 /**
735 * @tc.name: UpdateActiveStatus04
736 * @tc.desc: normal function
737 * @tc.type: FUNC
738 */
HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus04, Function | SmallTest | Level2)739 HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus04, Function | SmallTest | Level2)
740 {
741 SessionInfo info;
742 info.abilityName_ = "UpdateActiveStatus04";
743 info.bundleName_ = "UpdateActiveStatus04";
744 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
745 EXPECT_NE(sceneSession, nullptr);
746
747 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
748 EXPECT_NE(property, nullptr);
749 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
750 sceneSession->SetSessionProperty(property);
751 sceneSession->isActive_ = true;
752 sceneSession->state_ = SessionState::STATE_ACTIVE;
753
754 auto result = sceneSession->UpdateActiveStatus(true);
755 ASSERT_EQ(result, WSError::WS_OK);
756 }
757
758 /**
759 * @tc.name: Connect
760 * @tc.desc: Connect
761 * @tc.type: FUNC
762 */
HWTEST_F(SceneSessionLifecycleTest, Connect, Function | SmallTest | Level2)763 HWTEST_F(SceneSessionLifecycleTest, Connect, Function | SmallTest | Level2)
764 {
765 SessionInfo info;
766 info.bundleName_ = "Connect";
767 info.abilityName_ = "Connect1";
768 info.windowType_ = 1;
769 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
770 EXPECT_NE(sceneSession, nullptr);
771
772 sptr<ISessionStage> sessionStage = nullptr;
773 sptr<IWindowEventChannel> eventChannel = nullptr;
774 std::shared_ptr<RSSurfaceNode> surfaceNode = nullptr;
775 SystemSessionConfig systemConfig;
776 sptr<WindowSessionProperty> property = new WindowSessionProperty();
777 sptr<IRemoteObject> token;
778 WSError res = sceneSession->Connect(sessionStage, eventChannel,
779 surfaceNode, systemConfig, property, token);
780 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
781 }
782
783 /**
784 * @tc.name: ConnectInner01
785 * @tc.desc: ConnectInner01
786 * @tc.type: FUNC
787 */
HWTEST_F(SceneSessionLifecycleTest, ConnectInner01, Function | SmallTest | Level2)788 HWTEST_F(SceneSessionLifecycleTest, ConnectInner01, Function | SmallTest | Level2)
789 {
790 SessionInfo info;
791 info.bundleName_ = "ConnectInner01";
792 info.abilityName_ = "ConnectInner01";
793 info.windowType_ = 1;
794 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
795 EXPECT_NE(sceneSession, nullptr);
796 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
797 ASSERT_NE(mockSessionStage, nullptr);
798 SystemSessionConfig systemConfig;
799 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
800 ASSERT_NE(property, nullptr);
801 sceneSession->clientIdentityToken_ = "session1";
802
803 auto result = sceneSession->ConnectInner(mockSessionStage, nullptr, nullptr, systemConfig,
804 property, nullptr, -1, -1, "session2");
805 ASSERT_EQ(result, WSError::WS_OK);
806
807 result = sceneSession->ConnectInner(mockSessionStage, nullptr, nullptr, systemConfig,
808 property, nullptr, -1, -1, "session1");
809 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
810
811 result = sceneSession->ConnectInner(mockSessionStage, nullptr, nullptr, systemConfig,
812 property, nullptr, -1, -1);
813 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
814 }
815
816 /**
817 * @tc.name: ConnectInner02
818 * @tc.desc: ConnectInner02
819 * @tc.type: FUNC
820 */
HWTEST_F(SceneSessionLifecycleTest, ConnectInner02, Function | SmallTest | Level2)821 HWTEST_F(SceneSessionLifecycleTest, ConnectInner02, Function | SmallTest | Level2)
822 {
823 SessionInfo info;
824 info.bundleName_ = "ConnectInner02";
825 info.abilityName_ = "ConnectInner02";
826
827 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
828 EXPECT_NE(sceneSession, nullptr);
829 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
830 ASSERT_NE(mockSessionStage, nullptr);
831 SystemSessionConfig systemConfig;
832 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
833 ASSERT_NE(property, nullptr);
834 sceneSession->SetSessionState(SessionState::STATE_CONNECT);
835 sceneSession->Session::isTerminating_ = false;
836 auto result = sceneSession->ConnectInner(mockSessionStage, nullptr, nullptr, systemConfig,
837 property, nullptr);
838 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
839
840 sptr<IWindowEventChannel> eventChannel = new WindowEventChannel(mockSessionStage);
841 ASSERT_NE(eventChannel, nullptr);
842 sceneSession->SetSessionState(SessionState::STATE_DISCONNECT);
843 result = sceneSession->ConnectInner(mockSessionStage, eventChannel, nullptr, systemConfig,
844 property, nullptr);
845 ASSERT_EQ(result, WSError::WS_OK);
846 }
847
848 /**
849 * @tc.name: Reconnect
850 * @tc.desc: Reconnect
851 * @tc.type: FUNC
852 */
HWTEST_F(SceneSessionLifecycleTest, Reconnect, Function | SmallTest | Level2)853 HWTEST_F(SceneSessionLifecycleTest, Reconnect, Function | SmallTest | Level2)
854 {
855 SessionInfo info;
856 info.bundleName_ = "Reconnect";
857 info.abilityName_ = "Reconnect1";
858 info.windowType_ = 1;
859 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
860 EXPECT_NE(sceneSession, nullptr);
861
862 sptr<ISessionStage> sessionStage = nullptr;
863 sptr<IWindowEventChannel> eventChannel = nullptr;
864 std::shared_ptr<RSSurfaceNode> surfaceNode = nullptr;
865 sptr<WindowSessionProperty> property = new WindowSessionProperty();
866 sptr<IRemoteObject> token;
867 int32_t pid = -1;
868 int32_t uid = -1;
869 WSError res =
870 sceneSession->Reconnect(sessionStage, eventChannel, surfaceNode, property, token, pid, uid);
871 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
872
873 property->windowState_ = WindowState::STATE_SHOWN;
874 sessionStage = new SessionStageMocker();
875 eventChannel = new TestWindowEventChannel();
876 res = sceneSession->Reconnect(sessionStage, eventChannel, surfaceNode, property);
877 ASSERT_EQ(res, WSError::WS_OK);
878 }
879
880 /**
881 * @tc.name: ReconnectInner
882 * @tc.desc: ReconnectInner
883 * @tc.type: FUNC
884 */
HWTEST_F(SceneSessionLifecycleTest, ReconnectInner, Function | SmallTest | Level2)885 HWTEST_F(SceneSessionLifecycleTest, ReconnectInner, Function | SmallTest | Level2)
886 {
887 SessionInfo info;
888 info.bundleName_ = "ReconnectInner";
889 info.abilityName_ = "ReconnectInner1";
890 info.windowType_ = 1;
891 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
892 EXPECT_NE(sceneSession, nullptr);
893
894 sptr<WindowSessionProperty> property = nullptr;
895 WSError res = sceneSession->ReconnectInner(property);
896 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
897
898 property = new WindowSessionProperty();
899 property->windowState_ = WindowState::STATE_INITIAL;
900 res = sceneSession->ReconnectInner(property);
901 ASSERT_EQ(res, WSError::WS_ERROR_INVALID_PARAM);
902
903 property->windowState_ = WindowState::STATE_CREATED;
904 res = sceneSession->ReconnectInner(property);
905 ASSERT_EQ(res, WSError::WS_OK);
906
907 property->windowState_ = WindowState::STATE_SHOWN;
908 res = sceneSession->ReconnectInner(property);
909 ASSERT_EQ(res, WSError::WS_OK);
910
911 property->windowState_ = WindowState::STATE_HIDDEN;
912 res = sceneSession->ReconnectInner(property);
913 ASSERT_EQ(res, WSError::WS_OK);
914
915 property->windowState_ = WindowState::STATE_DESTROYED;
916 res = sceneSession->ReconnectInner(property);
917 ASSERT_EQ(res, WSError::WS_ERROR_INVALID_PARAM);
918 }
919
920 /**
921 * @tc.name: PendingSessionActivation
922 * @tc.desc: normal function
923 * @tc.type: FUNC
924 */
HWTEST_F(SceneSessionLifecycleTest, PendingSessionActivation, Function | SmallTest | Level2)925 HWTEST_F(SceneSessionLifecycleTest, PendingSessionActivation, Function | SmallTest | Level2)
926 {
927 SessionInfo info;
928 info.abilityName_ = "PendingSessionActivation";
929 info.bundleName_ = "PendingSessionActivation";
930 sptr<Rosen::ISession> session_;
931 sptr<SceneSession::SpecificSessionCallback> specificCallback =
932 new (std::nothrow) SceneSession::SpecificSessionCallback();
933 EXPECT_NE(specificCallback, nullptr);
934 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
935 EXPECT_NE(sceneSession, nullptr);
936 sceneSession->isActive_ = true;
937
938 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
939 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
940 uint32_t p = 10;
941 property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p);
942 sceneSession->SetSessionProperty(property);
943
944 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
945
946 sptr<AAFwk::SessionInfo> info1 = nullptr;
947 WSError result = sceneSession->PendingSessionActivation(info1);
948 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
949
950 result = sceneSession->PendingSessionActivation(abilitySessionInfo);
951 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
952
953 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
954 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
955 sceneSession->SetForegroundInteractiveStatus(false);
956 result = sceneSession->PendingSessionActivation(abilitySessionInfo);
957 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
958
959 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
960 sceneSession->SetSessionState(SessionState::STATE_BACKGROUND);
961 abilitySessionInfo->canStartAbilityFromBackground = false;
962 result = sceneSession->PendingSessionActivation(abilitySessionInfo);
963 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
964 }
965
966 /**
967 * @tc.name: TerminateSession
968 * @tc.desc: normal function
969 * @tc.type: FUNC
970 */
HWTEST_F(SceneSessionLifecycleTest, TerminateSession, Function | SmallTest | Level2)971 HWTEST_F(SceneSessionLifecycleTest, TerminateSession, Function | SmallTest | Level2)
972 {
973 SessionInfo info;
974 info.abilityName_ = "TerminateSession";
975 info.bundleName_ = "TerminateSession";
976 sptr<Rosen::ISession> session_;
977 sptr<SceneSession::SpecificSessionCallback> specificCallback =
978 new (std::nothrow) SceneSession::SpecificSessionCallback();
979 EXPECT_NE(specificCallback, nullptr);
980 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
981 EXPECT_NE(sceneSession, nullptr);
982 sceneSession->isActive_ = true;
983
984 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
985 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
986 uint32_t p = 10;
987 property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p);
988 sceneSession->SetSessionProperty(property);
989
990 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
991
992 sptr<AAFwk::SessionInfo> info1 = nullptr;
993 WSError result = sceneSession->TerminateSession(info1);
994 ASSERT_EQ(result, WSError::WS_OK);
995
996 sceneSession->isTerminating_ = true;
997 result = sceneSession->TerminateSession(abilitySessionInfo);
998 ASSERT_EQ(result, WSError::WS_OK);
999 sceneSession->isTerminating_ = false;
1000
1001 result = sceneSession->TerminateSession(abilitySessionInfo);
1002 ASSERT_EQ(result, WSError::WS_OK);
1003 }
1004
1005 /**
1006 * @tc.name: TerminateSession01
1007 * @tc.desc: normal function
1008 * @tc.type: FUNC
1009 */
HWTEST_F(SceneSessionLifecycleTest, TerminateSession01, Function | SmallTest | Level2)1010 HWTEST_F(SceneSessionLifecycleTest, TerminateSession01, Function | SmallTest | Level2)
1011 {
1012 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
1013 ASSERT_NE(nullptr, abilitySessionInfo);
1014 OHOS::Rosen::Session session(info);
1015 session.isTerminating_ = true;
1016 sceneSession->TerminateSession(abilitySessionInfo);
1017
1018 ASSERT_EQ(WSError::WS_OK, sceneSession->TerminateSession(abilitySessionInfo));
1019
1020 NotifyTerminateSessionFuncNew callback =
1021 [](const SessionInfo& info, bool needStartCaller, bool isFromBroker){};
1022 session.isTerminating_ = false;
1023 ASSERT_EQ(WSError::WS_OK, sceneSession->TerminateSession(abilitySessionInfo));
1024 }
1025
1026 /**
1027 * @tc.name: NotifySessionException
1028 * @tc.desc: normal function
1029 * @tc.type: FUNC
1030 */
HWTEST_F(SceneSessionLifecycleTest, NotifySessionException, Function | SmallTest | Level2)1031 HWTEST_F(SceneSessionLifecycleTest, NotifySessionException, Function | SmallTest | Level2)
1032 {
1033 SessionInfo info;
1034 info.abilityName_ = "NotifySessionException";
1035 info.bundleName_ = "NotifySessionException";
1036 sptr<Rosen::ISession> session_;
1037 sptr<SceneSession::SpecificSessionCallback> specificCallback =
1038 new (std::nothrow) SceneSession::SpecificSessionCallback();
1039 EXPECT_NE(specificCallback, nullptr);
1040 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1041 EXPECT_NE(sceneSession, nullptr);
1042 sceneSession->isActive_ = true;
1043
1044 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1045 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1046 uint32_t p = 10;
1047 property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p);
1048 sceneSession->SetSessionProperty(property);
1049
1050 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
1051
1052 sptr<AAFwk::SessionInfo> info1 = nullptr;
1053 WSError result = sceneSession->NotifySessionException(info1);
1054 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
1055
1056 result = sceneSession->NotifySessionException(abilitySessionInfo);
1057 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
1058 }
1059
1060 /**
1061 * @tc.name: NotifySessionException01
1062 * @tc.desc: normal function
1063 * @tc.type: FUNC
1064 */
HWTEST_F(SceneSessionLifecycleTest, NotifySessionException01, Function | SmallTest | Level2)1065 HWTEST_F(SceneSessionLifecycleTest, NotifySessionException01, Function | SmallTest | Level2)
1066 {
1067 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
1068 ASSERT_NE(nullptr, abilitySessionInfo);
1069 bool needRemoveSession = true;
1070 OHOS::Rosen::Session session(info);
1071 session.isTerminating_ = true;
1072 sceneSession->NotifySessionException(abilitySessionInfo, needRemoveSession);
1073 sceneSession->GetLastSafeRect();
1074 WSRect rect;
1075 sceneSession->SetLastSafeRect(rect);
1076 }
1077
1078 /**
1079 * @tc.name: NotifySessionForeground01
1080 * @tc.desc: NotifySessionForeground
1081 * @tc.type: FUNC
1082 */
HWTEST_F(SceneSessionLifecycleTest, NotifySessionForeground, Function | SmallTest | Level2)1083 HWTEST_F(SceneSessionLifecycleTest, NotifySessionForeground, Function | SmallTest | Level2)
1084 {
1085 SessionInfo info;
1086 info.abilityName_ = "Foreground01";
1087 info.bundleName_ = "IsFloatingWindowAppType";
1088 info.windowType_ = 1;
1089 sptr<Rosen::ISession> session_;
1090 sptr<SceneSession::SpecificSessionCallback> specificCallback =
1091 new (std::nothrow) SceneSession::SpecificSessionCallback();
1092 EXPECT_NE(specificCallback, nullptr);
1093 sptr<SceneSession> sceneSession;
1094 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1095 EXPECT_NE(sceneSession, nullptr);
1096 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
1097 ASSERT_NE(mockSessionStage, nullptr);
1098 uint32_t reason = 1;
1099 bool withAnimation = true;
1100 int ret = 1;
1101
1102 sceneSession->sessionStage_ = mockSessionStage;
1103 sceneSession->NotifySessionForeground(reason, withAnimation);
1104 ASSERT_EQ(ret, 1);
1105 }
1106
1107 /**
1108 * @tc.name: NotifySessionFullScreen01
1109 * @tc.desc: NotifySessionFullScreen
1110 * @tc.type: FUNC
1111 */
HWTEST_F(SceneSessionLifecycleTest, NotifySessionFullScreen, Function | SmallTest | Level2)1112 HWTEST_F(SceneSessionLifecycleTest, NotifySessionFullScreen, Function | SmallTest | Level2)
1113 {
1114 SessionInfo info;
1115 info.abilityName_ = "FullScreen01";
1116 info.bundleName_ = "IsFloatingWindowAppType";
1117 info.windowType_ = 1;
1118 sptr<SceneSession::SpecificSessionCallback> specificCallback =
1119 new (std::nothrow) SceneSession::SpecificSessionCallback();
1120 EXPECT_NE(specificCallback, nullptr);
1121 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1122 EXPECT_NE(sceneSession, nullptr);
1123 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
1124 ASSERT_NE(mockSessionStage, nullptr);
1125 bool fullScreen = true;
1126 int ret = 1;
1127 sceneSession->sessionStage_ = mockSessionStage;
1128 sceneSession->NotifySessionFullScreen(fullScreen);
1129 ASSERT_EQ(ret, 1);
1130 sceneSession->sessionStage_ = nullptr;
1131 sceneSession->NotifySessionFullScreen(fullScreen);
1132 }
1133
1134 /**
1135 * @tc.name: NotifySessionBackground01
1136 * @tc.desc: NotifySessionBackground
1137 * @tc.type: FUNC
1138 */
HWTEST_F(SceneSessionLifecycleTest, NotifySessionBackground, Function | SmallTest | Level2)1139 HWTEST_F(SceneSessionLifecycleTest, NotifySessionBackground, Function | SmallTest | Level2)
1140 {
1141 SessionInfo info;
1142 info.abilityName_ = "Background01";
1143 info.bundleName_ = "IsFloatingWindowAppType";
1144 info.windowType_ = 1;
1145 sptr<Rosen::ISession> session_;
1146 sptr<SceneSession::SpecificSessionCallback> specificCallback =
1147 new (std::nothrow) SceneSession::SpecificSessionCallback();
1148 EXPECT_NE(specificCallback, nullptr);
1149 sptr<SceneSession> sceneSession;
1150 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1151 EXPECT_NE(sceneSession, nullptr);
1152 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
1153 ASSERT_NE(mockSessionStage, nullptr);
1154 uint32_t reason = 1;
1155 bool withAnimation = true;
1156 bool isFromInnerkits = true;
1157 int ret = 1;
1158
1159 sceneSession->sessionStage_ = mockSessionStage;
1160 sceneSession->NotifySessionBackground(reason, withAnimation, isFromInnerkits);
1161 ASSERT_EQ(ret, 1);
1162 }
1163
1164 /**
1165 * @tc.name: NotifySessionExceptionInner
1166 * @tc.desc: NotifySessionExceptionInner
1167 * @tc.type: FUNC
1168 */
HWTEST_F(SceneSessionLifecycleTest, NotifySessionExceptionInner, Function | SmallTest | Level2)1169 HWTEST_F(SceneSessionLifecycleTest, NotifySessionExceptionInner, Function | SmallTest | Level2)
1170 {
1171 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
1172 ASSERT_NE(nullptr, abilitySessionInfo);
1173 bool needRemoveSession = true;
1174
1175 SessionInfo info;
1176 info.abilityName_ = "NotifySessionExceptionInner";
1177 info.bundleName_ = "NotifySessionExceptionInner";
1178 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1179 EXPECT_NE(sceneSession, nullptr);
1180 sceneSession->isTerminating_ = false;
1181 auto res = sceneSession->NotifySessionExceptionInner(nullptr, needRemoveSession, true);
1182 ASSERT_EQ(res, WSError::WS_OK);
1183
1184 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1185 ASSERT_NE(nullptr, property);
1186 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1187 sceneSession->SetSessionProperty(property);
1188 sceneSession->clientIdentityToken_ = "session1";
1189 abilitySessionInfo->identityToken = "session2";
1190 res = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, needRemoveSession, true);
1191 ASSERT_EQ(res, WSError::WS_OK);
1192
1193 sceneSession->isTerminating_ = true;
1194 res = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, needRemoveSession, false);
1195 ASSERT_EQ(res, WSError::WS_OK);
1196
1197 sceneSession->isTerminating_ = false;
1198 res = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, needRemoveSession, false);
1199 ASSERT_EQ(res, WSError::WS_OK);
1200
1201 sceneSession->sessionExceptionFunc_ = std::make_shared<NotifySessionExceptionFunc>();
1202 ASSERT_NE(nullptr, sceneSession->sessionExceptionFunc_);
1203 sceneSession->jsSceneSessionExceptionFunc_ = std::make_shared<NotifySessionExceptionFunc>();
1204 ASSERT_NE(nullptr, sceneSession->jsSceneSessionExceptionFunc_);
1205 res = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, needRemoveSession, false);
1206 ASSERT_EQ(res, WSError::WS_OK);
1207 }
1208 }
1209 }
1210 }