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 */
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>
__anona730d5710202(const SessionInfo& info, sptr<WindowSessionProperty> property) 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 */
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 */
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 */
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 */
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 */
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 */
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>
__anona730d5710302(const SessionInfo& info, sptr<WindowSessionProperty> property) 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 */
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: Background3
317 * @tc.desc: * @tc.name: Background
318 * @tc.type: FUNC
319 */
320 HWTEST_F(SceneSessionLifecycleTest, Background3, Function | SmallTest | Level2)
321 {
322 SessionInfo info;
323 info.abilityName_ = "Background3";
324 info.bundleName_ = "Background3";
325 sptr<SceneSession> sceneSession;
326 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
327 EXPECT_NE(nullptr, sceneSession);
328
329 sceneSession->specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback();
330 WindowType windowType = WindowType::APP_MAIN_WINDOW_BASE;
331 OHOS::Rosen::WindowHelper::IsMainWindow(windowType);
332 }
333
334 /**
335 * @tc.name: Background04
336 * @tc.desc: normal function
337 * @tc.type: FUNC
338 */
339 HWTEST_F(SceneSessionLifecycleTest, Background04, Function | SmallTest | Level2)
340 {
341 SessionInfo info;
342 info.abilityName_ = "Background04";
343 info.bundleName_ = "Background04";
344 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
345 EXPECT_NE(nullptr, sceneSession);
346
347 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
348 EXPECT_NE(property, nullptr);
349 property->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::CUSTOM));
350 sceneSession->SetSessionProperty(property);
351 EXPECT_EQ(WSError::WS_OK, sceneSession->Background(true));
352
353 sptr<WindowSessionProperty> property2 = new (std::nothrow) WindowSessionProperty();
354 EXPECT_NE(property2, nullptr);
355 property2->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
356 sceneSession->SetSessionProperty(property2);
357 EXPECT_EQ(WSError::WS_OK, sceneSession->Background(false));
358 EXPECT_EQ(WSError::WS_OK, sceneSession->Background(true));
359 }
360
361 /**
362 * @tc.name: BackgroundTask01
363 * @tc.desc: normal function
364 * @tc.type: FUNC
365 */
366 HWTEST_F(SceneSessionLifecycleTest, BackgroundTask01, Function | SmallTest | Level2)
367 {
368 SessionInfo info;
369 info.abilityName_ = "BackgroundTask01";
370 info.bundleName_ = "BackgroundTask01";
371 sptr<SceneSession::SpecificSessionCallback> specificCallback =
372 new (std::nothrow) SceneSession::SpecificSessionCallback();
373 EXPECT_NE(specificCallback, nullptr);
374 int resultValue = 0;
375 sptr<SceneSession> sceneSession;
376 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
377 EXPECT_NE(sceneSession, nullptr);
378 sceneSession->isActive_ = true;
379 auto result = sceneSession->BackgroundTask();
380 ASSERT_EQ(result, WSError::WS_OK);
381 sceneSession->isActive_ = true;
382 result = sceneSession->BackgroundTask(false);
383 ASSERT_EQ(result, WSError::WS_OK);
384 specificCallback->onCreate_ =
385 [&resultValue, specificCallback](const SessionInfo& info,
386 sptr<WindowSessionProperty> property) -> sptr<SceneSession>
__anona730d5710402(const SessionInfo& info, sptr<WindowSessionProperty> property) 387 {
388 sptr<SceneSession> sceneSessionReturn = new (std::nothrow) SceneSession(info, specificCallback);
389 EXPECT_NE(sceneSessionReturn, nullptr);
390 resultValue = 1;
391 return sceneSessionReturn;
392 };
393 sceneSession = new (std::nothrow) SceneSession(info, specificCallback);
394 EXPECT_NE(sceneSession, nullptr);
395 sceneSession->UpdateSessionState(SessionState::STATE_CONNECT);
396 sceneSession->isActive_ = true;
397 result = sceneSession->BackgroundTask();
398 ASSERT_EQ(result, WSError::WS_OK);
399 sceneSession->UpdateSessionState(SessionState::STATE_CONNECT);
400 sceneSession->isActive_ = true;
401 result = sceneSession->BackgroundTask(false);
402 ASSERT_EQ(result, WSError::WS_OK);
403 }
404
405 /**
406 * @tc.name: BackgroundTask02
407 * @tc.desc: normal function
408 * @tc.type: FUNC
409 */
410 HWTEST_F(SceneSessionLifecycleTest, BackgroundTask02, Function | SmallTest | Level2)
411 {
412 SessionInfo info;
413 info.abilityName_ = "BackgroundTask02";
414 info.bundleName_ = "BackgroundTask02";
415 sptr<SceneSession::SpecificSessionCallback> specificCallback =
416 new (std::nothrow) SceneSession::SpecificSessionCallback();
417 EXPECT_NE(specificCallback, nullptr);
418 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
419 EXPECT_NE(sceneSession, nullptr);
420 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
421 property->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::CUSTOM));
422 sceneSession->SetSessionProperty(property);
423 sceneSession->isActive_ = true;
424 auto result = sceneSession->BackgroundTask();
425 ASSERT_EQ(result, WSError::WS_OK);
426 sceneSession->isActive_ = true;
427 result = sceneSession->BackgroundTask(false);
428 ASSERT_EQ(result, WSError::WS_OK);
429 }
430
431 /**
432 * @tc.name: BackgroundTask03
433 * @tc.desc: BackgroundTask03 function
434 * @tc.type: FUNC
435 */
436 HWTEST_F(SceneSessionLifecycleTest, BackgroundTask03, Function | SmallTest | Level2)
437 {
438 SessionInfo info;
439 info.abilityName_ = "BackgroundTask03";
440 info.bundleName_ = "BackgroundTask03";
441
442 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
443 EXPECT_NE(session, nullptr);
444 sptr<WindowSessionProperty> property = nullptr;
445 session->SetSessionState(SessionState::STATE_BACKGROUND);
446 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false));
447
448 session->SetSessionState(SessionState::STATE_CONNECT);
449 session->Session::SetSessionState(SessionState::STATE_CONNECT);
450 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false));
451
452 session->Session::SetSessionState(SessionState::STATE_INACTIVE);
453 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
454 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false));
455
456 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
457 sptr<SceneSession::SpecificSessionCallback> specificCallback =
458 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
459 session->specificCallback_ = specificCallback;
460 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false));
461
462 session->scenePersistence_ = nullptr;
463 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(true));
464
465 session->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("Foreground02", 1);
466 struct RSSurfaceNodeConfig config;
467 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
468 session->surfaceNode_ = surfaceNode;
469 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(true));
470
471 sptr<WindowSessionProperty> property2 = new (std::nothrow) WindowSessionProperty();
472 EXPECT_NE(property2, nullptr);
473 property2->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
474 session->SetSessionProperty(property2);
475 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false));
476 EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(true));
477 }
478
479 /**
480 * @tc.name: DisconnectTask01
481 * @tc.desc: normal function
482 * @tc.type: FUNC
483 */
484 HWTEST_F(SceneSessionLifecycleTest, DisconnectTask01, Function | SmallTest | Level2)
485 {
486 SessionInfo info;
487 info.abilityName_ = "DisconnectTask01";
488 info.bundleName_ = "DisconnectTask01";
489 sptr<SceneSession::SpecificSessionCallback> specificCallback =
490 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
491 EXPECT_NE(specificCallback, nullptr);
492
493 int resultValue = 0;
494 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
495 EXPECT_NE(sceneSession, nullptr);
496 sceneSession->isActive_ = true;
497 auto result = sceneSession->DisconnectTask(true, true);
498 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
499 ASSERT_EQ(result, WSError::WS_OK);
500 sceneSession->isActive_ = true;
501 result = sceneSession->DisconnectTask(false, true);
502 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
503 ASSERT_EQ(result, WSError::WS_OK);
504 specificCallback->onCreate_ =
505 [&resultValue, specificCallback](const SessionInfo& info,
__anona730d5710502(const SessionInfo& info, sptr<WindowSessionProperty> property) 506 sptr<WindowSessionProperty> property) -> sptr<SceneSession> {
507 sptr<SceneSession> sceneSessionReturn = new (std::nothrow) SceneSession(info, specificCallback);
508 EXPECT_NE(sceneSessionReturn, nullptr);
509 resultValue = 1;
510 return sceneSessionReturn;
511 };
512 sceneSession = new (std::nothrow) SceneSession(info, specificCallback);
513 EXPECT_NE(sceneSession, nullptr);
514 sceneSession->UpdateSessionState(SessionState::STATE_CONNECT);
515 sceneSession->isActive_ = true;
516 result = sceneSession->DisconnectTask(true, true);
517 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
518 ASSERT_EQ(result, WSError::WS_OK);
519 sceneSession->UpdateSessionState(SessionState::STATE_CONNECT);
520 sceneSession->isActive_ = true;
521 result = sceneSession->DisconnectTask(false, true);
522 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
523 ASSERT_EQ(result, WSError::WS_OK);
524 }
525
526 /**
527 * @tc.name: DisconnectTask02
528 * @tc.desc: normal function
529 * @tc.type: FUNC
530 */
531 HWTEST_F(SceneSessionLifecycleTest, DisconnectTask02, Function | SmallTest | Level2)
532 {
533 SessionInfo info;
534 info.abilityName_ = "DisconnectTask02";
535 info.bundleName_ = "DisconnectTask02";
536 sptr<SceneSession::SpecificSessionCallback> specificCallback =
537 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
538 EXPECT_NE(specificCallback, nullptr);
539 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
540 EXPECT_NE(sceneSession, nullptr);
541 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
542 EXPECT_NE(property, nullptr);
543 property->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::CUSTOM));
544 sceneSession->SetSessionProperty(property);
545 sceneSession->isActive_ = true;
546 auto result = sceneSession->DisconnectTask(true, true);
547 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
548 ASSERT_EQ(result, WSError::WS_OK);
549 sceneSession->isActive_ = true;
550 result = sceneSession->DisconnectTask(false, true);
551 ASSERT_EQ(result, WSError::WS_OK);
552 }
553
554 /**
555 * @tc.name: Disconnect
556 * @tc.desc: normal function
557 * @tc.type: FUNC
558 */
559 HWTEST_F(SceneSessionLifecycleTest, Disconnect, Function | SmallTest | Level2)
560 {
561 SessionInfo info;
562 info.abilityName_ = "Disconnect";
563 info.bundleName_ = "Disconnect";
564 sptr<Rosen::ISession> session_;
565 sptr<SceneSession::SpecificSessionCallback> specificCallback =
566 new (std::nothrow) SceneSession::SpecificSessionCallback();
567 EXPECT_NE(specificCallback, nullptr);
568 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
569 EXPECT_NE(sceneSession, nullptr);
570
571 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
572 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
573 sceneSession->SetSessionProperty(property);
574 sceneSession->isActive_ = true;
575 auto result = sceneSession->Disconnect();
576 ASSERT_EQ(result, WSError::WS_OK);
577 }
578
579 /**
580 * @tc.name: Disconnect2
581 * @tc.desc: normal function
582 * @tc.type: FUNC
583 */
584 HWTEST_F(SceneSessionLifecycleTest, Disconnect2, Function | SmallTest | Level2)
585 {
586 SessionInfo info;
587 info.abilityName_ = "Disconnect2";
588 info.bundleName_ = "Disconnect2";
589 sptr<Rosen::ISession> session_;
590 sptr<SceneSession::SpecificSessionCallback> specificCallback =
591 new (std::nothrow) SceneSession::SpecificSessionCallback();
592 EXPECT_NE(specificCallback, nullptr);
593 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
594 EXPECT_NE(sceneSession, nullptr);
595
596 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
597 EXPECT_NE(property, nullptr);
598 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
599 sceneSession->SetSessionProperty(property);
600 sceneSession->isActive_ = true;
601
602 auto result = sceneSession->Disconnect(true);
603 ASSERT_EQ(result, WSError::WS_OK);
604 }
605
606 /**
607 * @tc.name: Disconnect3
608 * @tc.desc: normal function
609 * @tc.type: FUNC
610 */
611 HWTEST_F(SceneSessionLifecycleTest, Disconnect3, Function | SmallTest | Level2)
612 {
613 SessionInfo info;
614 info.abilityName_ = "Disconnect3";
615 info.bundleName_ = "Disconnect3";
616 sptr<Rosen::ISession> session_;
617 sptr<SceneSession::SpecificSessionCallback> specificCallback =
618 new (std::nothrow) SceneSession::SpecificSessionCallback();
619 EXPECT_NE(specificCallback, nullptr);
620 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
621 EXPECT_NE(sceneSession, nullptr);
622
623 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
624 EXPECT_NE(property, nullptr);
625 property->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
626 sceneSession->SetSessionProperty(property);
627 sceneSession->isActive_ = true;
628
629 auto result = sceneSession->Disconnect(true);
630 ASSERT_EQ(result, WSError::WS_OK);
631
632 sceneSession->specificCallback_ = nullptr;
633 result = sceneSession->Disconnect(false);
634 ASSERT_EQ(result, WSError::WS_OK);
635
636 sceneSession->needSnapshot_ = true;
637 sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
638 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
639 sceneSession->SetSessionProperty(property);
640
641 result = sceneSession->Disconnect(false);
642 ASSERT_EQ(result, WSError::WS_OK);
643 }
644
645 /**
646 * @tc.name: UpdateActiveStatus01
647 * @tc.desc: normal function
648 * @tc.type: FUNC
649 */
650 HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus01, Function | SmallTest | Level2)
651 {
652 SessionInfo info;
653 info.abilityName_ = "UpdateActiveStatus01";
654 info.bundleName_ = "UpdateActiveStatus01";
655 sptr<Rosen::ISession> session_;
656 sptr<SceneSession::SpecificSessionCallback> specificCallback =
657 new (std::nothrow) SceneSession::SpecificSessionCallback();
658 EXPECT_NE(specificCallback, nullptr);
659 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
660 EXPECT_NE(sceneSession, nullptr);
661
662 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
663 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
664 sceneSession->SetSessionProperty(property);
665 sceneSession->isActive_ = true;
666 auto result = sceneSession->UpdateActiveStatus(true);
667 ASSERT_EQ(result, WSError::WS_OK);
668
669 result = sceneSession->UpdateActiveStatus(false);
670 ASSERT_EQ(result, WSError::WS_OK);
671 }
672
673 /**
674 * @tc.name: UpdateActiveStatus02
675 * @tc.desc: normal function
676 * @tc.type: FUNC
677 */
678 HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus02, Function | SmallTest | Level2)
679 {
680 SessionInfo info;
681 info.abilityName_ = "UpdateActiveStatus02";
682 info.bundleName_ = "UpdateActiveStatus02";
683 sptr<Rosen::ISession> session_;
684 sptr<SceneSession::SpecificSessionCallback> specificCallback =
685 new (std::nothrow) SceneSession::SpecificSessionCallback();
686 EXPECT_NE(specificCallback, nullptr);
687 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
688 EXPECT_NE(sceneSession, nullptr);
689
690 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
691 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
692 sceneSession->SetSessionProperty(property);
693 sceneSession->isActive_ = false;
694 auto result = sceneSession->UpdateActiveStatus(true);
695 ASSERT_EQ(result, WSError::WS_OK);
696 }
697
698 /**
699 * @tc.name: UpdateActiveStatus03
700 * @tc.desc: normal function
701 * @tc.type: FUNC
702 */
703 HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus03, Function | SmallTest | Level2)
704 {
705 SessionInfo info;
706 info.abilityName_ = "UpdateActiveStatus03";
707 info.bundleName_ = "UpdateActiveStatus03";
708 sptr<Rosen::ISession> session_;
709 sptr<SceneSession::SpecificSessionCallback> specificCallback =
710 new (std::nothrow) SceneSession::SpecificSessionCallback();
711 EXPECT_NE(specificCallback, nullptr);
712 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
713 EXPECT_NE(sceneSession, nullptr);
714
715 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
716 EXPECT_NE(property, nullptr);
717 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
718 sceneSession->SetSessionProperty(property);
719 sceneSession->isActive_ = true;
720 sceneSession->state_ = SessionState::STATE_DISCONNECT;
721
722 auto result = sceneSession->UpdateActiveStatus(false);
723 ASSERT_EQ(result, WSError::WS_OK);
724
725 result = sceneSession->UpdateActiveStatus(true);
726 ASSERT_EQ(result, WSError::WS_OK);
727
728 sceneSession->isActive_ = false;
729 result = sceneSession->UpdateActiveStatus(false);
730 ASSERT_EQ(result, WSError::WS_OK);
731
732 sceneSession->isActive_ = true;
733 sceneSession->state_ = SessionState::STATE_FOREGROUND;
734 result = sceneSession->UpdateActiveStatus(true);
735 ASSERT_EQ(result, WSError::WS_OK);
736
737 sceneSession->isActive_ = true;
738 sceneSession->state_ = SessionState::STATE_ACTIVE;
739 result = sceneSession->UpdateActiveStatus(false);
740 ASSERT_EQ(result, WSError::WS_OK);
741
742 sceneSession->isActive_ = false;
743 result = sceneSession->UpdateActiveStatus(true);
744 ASSERT_EQ(result, WSError::WS_OK);
745 }
746
747 /**
748 * @tc.name: UpdateActiveStatus04
749 * @tc.desc: normal function
750 * @tc.type: FUNC
751 */
752 HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus04, Function | SmallTest | Level2)
753 {
754 SessionInfo info;
755 info.abilityName_ = "UpdateActiveStatus04";
756 info.bundleName_ = "UpdateActiveStatus04";
757 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
758 EXPECT_NE(sceneSession, nullptr);
759
760 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
761 EXPECT_NE(property, nullptr);
762 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
763 sceneSession->SetSessionProperty(property);
764 sceneSession->isActive_ = true;
765 sceneSession->state_ = SessionState::STATE_ACTIVE;
766
767 auto result = sceneSession->UpdateActiveStatus(true);
768 ASSERT_EQ(result, WSError::WS_OK);
769 }
770
771 /**
772 * @tc.name: Connect
773 * @tc.desc: Connect
774 * @tc.type: FUNC
775 */
776 HWTEST_F(SceneSessionLifecycleTest, Connect, Function | SmallTest | Level2)
777 {
778 SessionInfo info;
779 info.bundleName_ = "Connect";
780 info.abilityName_ = "Connect1";
781 info.windowType_ = 1;
782 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
783 EXPECT_NE(sceneSession, nullptr);
784
785 sptr<ISessionStage> sessionStage = nullptr;
786 sptr<IWindowEventChannel> eventChannel = nullptr;
787 std::shared_ptr<RSSurfaceNode> surfaceNode = nullptr;
788 SystemSessionConfig systemConfig;
789 sptr<WindowSessionProperty> property = new WindowSessionProperty();
790 sptr<IRemoteObject> token;
791 WSError res = sceneSession->Connect(sessionStage, eventChannel,
792 surfaceNode, systemConfig, property, token);
793 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
794 }
795
796 /**
797 * @tc.name: ConnectInner01
798 * @tc.desc: ConnectInner01
799 * @tc.type: FUNC
800 */
801 HWTEST_F(SceneSessionLifecycleTest, ConnectInner01, Function | SmallTest | Level2)
802 {
803 SessionInfo info;
804 info.bundleName_ = "ConnectInner01";
805 info.abilityName_ = "ConnectInner01";
806 info.windowType_ = 1;
807 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
808 EXPECT_NE(sceneSession, nullptr);
809 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
810 ASSERT_NE(mockSessionStage, nullptr);
811 SystemSessionConfig systemConfig;
812 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
813 ASSERT_NE(property, nullptr);
814 sceneSession->clientIdentityToken_ = "session1";
815
816 auto result = sceneSession->ConnectInner(mockSessionStage, nullptr, nullptr, systemConfig,
817 property, nullptr, -1, -1, "session2");
818 ASSERT_EQ(result, WSError::WS_OK);
819
820 result = sceneSession->ConnectInner(mockSessionStage, nullptr, nullptr, systemConfig,
821 property, nullptr, -1, -1, "session1");
822 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
823
824 result = sceneSession->ConnectInner(mockSessionStage, nullptr, nullptr, systemConfig,
825 property, nullptr, -1, -1);
826 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
827 }
828
829 /**
830 * @tc.name: ConnectInner02
831 * @tc.desc: ConnectInner02
832 * @tc.type: FUNC
833 */
834 HWTEST_F(SceneSessionLifecycleTest, ConnectInner02, Function | SmallTest | Level2)
835 {
836 SessionInfo info;
837 info.bundleName_ = "ConnectInner02";
838 info.abilityName_ = "ConnectInner02";
839
840 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
841 EXPECT_NE(sceneSession, nullptr);
842 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
843 ASSERT_NE(mockSessionStage, nullptr);
844 SystemSessionConfig systemConfig;
845 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
846 ASSERT_NE(property, nullptr);
847 sceneSession->SetSessionState(SessionState::STATE_CONNECT);
848 sceneSession->Session::isTerminating_ = false;
849 auto result = sceneSession->ConnectInner(mockSessionStage, nullptr, nullptr, systemConfig,
850 property, nullptr);
851 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
852
853 sptr<IWindowEventChannel> eventChannel = new WindowEventChannel(mockSessionStage);
854 ASSERT_NE(eventChannel, nullptr);
855 sceneSession->SetSessionState(SessionState::STATE_DISCONNECT);
856 result = sceneSession->ConnectInner(mockSessionStage, eventChannel, nullptr, systemConfig,
857 property, nullptr);
858 ASSERT_EQ(result, WSError::WS_OK);
859 }
860
861 /**
862 * @tc.name: Reconnect
863 * @tc.desc: Reconnect
864 * @tc.type: FUNC
865 */
866 HWTEST_F(SceneSessionLifecycleTest, Reconnect, Function | SmallTest | Level2)
867 {
868 SessionInfo info;
869 info.bundleName_ = "Reconnect";
870 info.abilityName_ = "Reconnect1";
871 info.windowType_ = 1;
872 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
873 EXPECT_NE(sceneSession, nullptr);
874
875 sptr<ISessionStage> sessionStage = nullptr;
876 sptr<IWindowEventChannel> eventChannel = nullptr;
877 std::shared_ptr<RSSurfaceNode> surfaceNode = nullptr;
878 sptr<WindowSessionProperty> property = new WindowSessionProperty();
879 sptr<IRemoteObject> token;
880 int32_t pid = -1;
881 int32_t uid = -1;
882 WSError res =
883 sceneSession->Reconnect(sessionStage, eventChannel, surfaceNode, property, token, pid, uid);
884 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
885
886 property->windowState_ = WindowState::STATE_SHOWN;
887 sessionStage = new SessionStageMocker();
888 eventChannel = new TestWindowEventChannel();
889 res = sceneSession->Reconnect(sessionStage, eventChannel, surfaceNode, property);
890 ASSERT_EQ(res, WSError::WS_OK);
891 }
892
893 /**
894 * @tc.name: ReconnectInner
895 * @tc.desc: ReconnectInner
896 * @tc.type: FUNC
897 */
898 HWTEST_F(SceneSessionLifecycleTest, ReconnectInner, Function | SmallTest | Level2)
899 {
900 SessionInfo info;
901 info.bundleName_ = "ReconnectInner";
902 info.abilityName_ = "ReconnectInner1";
903 info.windowType_ = 1;
904 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
905 EXPECT_NE(sceneSession, nullptr);
906
907 sptr<WindowSessionProperty> property = nullptr;
908 WSError res = sceneSession->ReconnectInner(property);
909 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
910
911 property = new WindowSessionProperty();
912 property->windowState_ = WindowState::STATE_INITIAL;
913 res = sceneSession->ReconnectInner(property);
914 ASSERT_EQ(res, WSError::WS_ERROR_INVALID_PARAM);
915
916 property->windowState_ = WindowState::STATE_CREATED;
917 res = sceneSession->ReconnectInner(property);
918 ASSERT_EQ(res, WSError::WS_OK);
919
920 property->windowState_ = WindowState::STATE_SHOWN;
921 res = sceneSession->ReconnectInner(property);
922 ASSERT_EQ(res, WSError::WS_OK);
923
924 property->windowState_ = WindowState::STATE_HIDDEN;
925 res = sceneSession->ReconnectInner(property);
926 ASSERT_EQ(res, WSError::WS_OK);
927
928 property->windowState_ = WindowState::STATE_DESTROYED;
929 res = sceneSession->ReconnectInner(property);
930 ASSERT_EQ(res, WSError::WS_ERROR_INVALID_PARAM);
931 }
932
933 /**
934 * @tc.name: PendingSessionActivation
935 * @tc.desc: normal function
936 * @tc.type: FUNC
937 */
938 HWTEST_F(SceneSessionLifecycleTest, PendingSessionActivation, Function | SmallTest | Level2)
939 {
940 SessionInfo info;
941 info.abilityName_ = "PendingSessionActivation";
942 info.bundleName_ = "PendingSessionActivation";
943 sptr<Rosen::ISession> session_;
944 sptr<SceneSession::SpecificSessionCallback> specificCallback =
945 new (std::nothrow) SceneSession::SpecificSessionCallback();
946 EXPECT_NE(specificCallback, nullptr);
947 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
948 EXPECT_NE(sceneSession, nullptr);
949 sceneSession->isActive_ = true;
950
951 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
952 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
953 property->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
954 sceneSession->SetSessionProperty(property);
955
956 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
957
958 sptr<AAFwk::SessionInfo> info1 = nullptr;
959 WSError result = sceneSession->PendingSessionActivation(info1);
960 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
961
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 */
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 property->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
987 sceneSession->SetSessionProperty(property);
988
989 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
990
991 sptr<AAFwk::SessionInfo> info1 = nullptr;
992 WSError result = sceneSession->TerminateSession(info1);
993 ASSERT_EQ(result, WSError::WS_OK);
994
995 result = sceneSession->TerminateSession(abilitySessionInfo);
996 ASSERT_EQ(result, WSError::WS_OK);
997 }
998
999 /**
1000 * @tc.name: TerminateSession01
1001 * @tc.desc: normal function
1002 * @tc.type: FUNC
1003 */
1004 HWTEST_F(SceneSessionLifecycleTest, TerminateSession01, Function | SmallTest | Level2)
1005 {
1006 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
1007 ASSERT_NE(nullptr, abilitySessionInfo);
1008 OHOS::Rosen::Session session(info);
1009 session.isTerminating_ = true;
1010 sceneSession->TerminateSession(abilitySessionInfo);
1011
1012 ASSERT_EQ(WSError::WS_OK, sceneSession->TerminateSession(abilitySessionInfo));
1013
1014 NotifyTerminateSessionFuncNew callback =
__anona730d5710602(const SessionInfo& info, bool needStartCaller, bool isFromBroker)1015 [](const SessionInfo& info, bool needStartCaller, bool isFromBroker){};
1016 session.isTerminating_ = false;
1017 ASSERT_EQ(WSError::WS_OK, sceneSession->TerminateSession(abilitySessionInfo));
1018 }
1019
1020 /**
1021 * @tc.name: NotifySessionException
1022 * @tc.desc: normal function
1023 * @tc.type: FUNC
1024 */
1025 HWTEST_F(SceneSessionLifecycleTest, NotifySessionException, Function | SmallTest | Level2)
1026 {
1027 SessionInfo info;
1028 info.abilityName_ = "NotifySessionException";
1029 info.bundleName_ = "NotifySessionException";
1030 sptr<Rosen::ISession> session_;
1031 sptr<SceneSession::SpecificSessionCallback> specificCallback =
1032 new (std::nothrow) SceneSession::SpecificSessionCallback();
1033 EXPECT_NE(specificCallback, nullptr);
1034 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1035 EXPECT_NE(sceneSession, nullptr);
1036 sceneSession->isActive_ = true;
1037
1038 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1039 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1040 property->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
1041 sceneSession->SetSessionProperty(property);
1042
1043 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
1044
1045 sptr<AAFwk::SessionInfo> info1 = nullptr;
1046 WSError result = sceneSession->NotifySessionException(info1);
1047 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
1048
1049 result = sceneSession->NotifySessionException(abilitySessionInfo);
1050 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
1051 }
1052
1053 /**
1054 * @tc.name: NotifySessionException01
1055 * @tc.desc: normal function
1056 * @tc.type: FUNC
1057 */
1058 HWTEST_F(SceneSessionLifecycleTest, NotifySessionException01, Function | SmallTest | Level2)
1059 {
1060 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
1061 ASSERT_NE(nullptr, abilitySessionInfo);
1062 bool needRemoveSession = true;
1063 OHOS::Rosen::Session session(info);
1064 session.isTerminating_ = true;
1065 sceneSession->NotifySessionException(abilitySessionInfo, needRemoveSession);
1066 sceneSession->GetLastSafeRect();
1067 WSRect rect;
1068 sceneSession->SetLastSafeRect(rect);
1069 }
1070
1071 /**
1072 * @tc.name: NotifySessionForeground01
1073 * @tc.desc: NotifySessionForeground
1074 * @tc.type: FUNC
1075 */
1076 HWTEST_F(SceneSessionLifecycleTest, NotifySessionForeground, Function | SmallTest | Level2)
1077 {
1078 SessionInfo info;
1079 info.abilityName_ = "Foreground01";
1080 info.bundleName_ = "IsFloatingWindowAppType";
1081 info.windowType_ = 1;
1082 sptr<Rosen::ISession> session_;
1083 sptr<SceneSession::SpecificSessionCallback> specificCallback =
1084 new (std::nothrow) SceneSession::SpecificSessionCallback();
1085 EXPECT_NE(specificCallback, nullptr);
1086 sptr<SceneSession> sceneSession;
1087 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1088 EXPECT_NE(sceneSession, nullptr);
1089 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
1090 ASSERT_NE(mockSessionStage, nullptr);
1091 uint32_t reason = 1;
1092 bool withAnimation = true;
1093 int ret = 1;
1094
1095 sceneSession->sessionStage_ = mockSessionStage;
1096 sceneSession->NotifySessionForeground(reason, withAnimation);
1097 ASSERT_EQ(ret, 1);
1098 }
1099
1100 /**
1101 * @tc.name: NotifySessionFullScreen01
1102 * @tc.desc: NotifySessionFullScreen
1103 * @tc.type: FUNC
1104 */
1105 HWTEST_F(SceneSessionLifecycleTest, NotifySessionFullScreen, Function | SmallTest | Level2)
1106 {
1107 SessionInfo info;
1108 info.abilityName_ = "FullScreen01";
1109 info.bundleName_ = "IsFloatingWindowAppType";
1110 info.windowType_ = 1;
1111 sptr<SceneSession::SpecificSessionCallback> specificCallback =
1112 new (std::nothrow) SceneSession::SpecificSessionCallback();
1113 EXPECT_NE(specificCallback, nullptr);
1114 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1115 EXPECT_NE(sceneSession, nullptr);
1116 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
1117 ASSERT_NE(mockSessionStage, nullptr);
1118 bool fullScreen = true;
1119 int ret = 1;
1120 sceneSession->sessionStage_ = mockSessionStage;
1121 sceneSession->NotifySessionFullScreen(fullScreen);
1122 ASSERT_EQ(ret, 1);
1123 sceneSession->sessionStage_ = nullptr;
1124 sceneSession->NotifySessionFullScreen(fullScreen);
1125 }
1126
1127 /**
1128 * @tc.name: NotifySessionBackground01
1129 * @tc.desc: NotifySessionBackground
1130 * @tc.type: FUNC
1131 */
1132 HWTEST_F(SceneSessionLifecycleTest, NotifySessionBackground, Function | SmallTest | Level2)
1133 {
1134 SessionInfo info;
1135 info.abilityName_ = "Background01";
1136 info.bundleName_ = "IsFloatingWindowAppType";
1137 info.windowType_ = 1;
1138 sptr<Rosen::ISession> session_;
1139 sptr<SceneSession::SpecificSessionCallback> specificCallback =
1140 new (std::nothrow) SceneSession::SpecificSessionCallback();
1141 EXPECT_NE(specificCallback, nullptr);
1142 sptr<SceneSession> sceneSession;
1143 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1144 EXPECT_NE(sceneSession, nullptr);
1145 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
1146 ASSERT_NE(mockSessionStage, nullptr);
1147 uint32_t reason = 1;
1148 bool withAnimation = true;
1149 bool isFromInnerkits = true;
1150 int ret = 1;
1151
1152 sceneSession->sessionStage_ = mockSessionStage;
1153 sceneSession->NotifySessionBackground(reason, withAnimation, isFromInnerkits);
1154 ASSERT_EQ(ret, 1);
1155 }
1156
1157 /**
1158 * @tc.name: NotifySessionExceptionInner
1159 * @tc.desc: NotifySessionExceptionInner
1160 * @tc.type: FUNC
1161 */
1162 HWTEST_F(SceneSessionLifecycleTest, NotifySessionExceptionInner, Function | SmallTest | Level2)
1163 {
1164 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
1165 ASSERT_NE(nullptr, abilitySessionInfo);
1166 bool needRemoveSession = true;
1167
1168 SessionInfo info;
1169 info.abilityName_ = "NotifySessionExceptionInner";
1170 info.bundleName_ = "NotifySessionExceptionInner";
1171 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1172 EXPECT_NE(sceneSession, nullptr);
1173 sceneSession->isTerminating_ = true;
1174 auto res = sceneSession->NotifySessionExceptionInner(nullptr, needRemoveSession);
1175 ASSERT_EQ(res, WSError::WS_OK);
1176
1177 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1178 ASSERT_NE(nullptr, property);
1179 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1180 sceneSession->SetSessionProperty(property);
1181 sceneSession->clientIdentityToken_ = "session1";
1182 abilitySessionInfo->identityToken = "session2";
1183 res = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, needRemoveSession, true);
1184 ASSERT_EQ(res, WSError::WS_OK);
1185
1186 sceneSession->isTerminating_ = true;
1187 res = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, needRemoveSession, false);
1188 ASSERT_EQ(res, WSError::WS_OK);
1189
1190 sceneSession->isTerminating_ = false;
1191 res = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, needRemoveSession, false);
1192 ASSERT_EQ(res, WSError::WS_OK);
1193
__anona730d5710702(const SessionInfo& info, bool removeSession, bool startFail) 1194 sceneSession->sessionExceptionFunc_ = [](const SessionInfo& info, bool removeSession, bool startFail) {};
1195 ASSERT_NE(nullptr, sceneSession->sessionExceptionFunc_);
__anona730d5710802(const SessionInfo& info, bool removeSession, bool startFail) 1196 sceneSession->jsSceneSessionExceptionFunc_ = [](const SessionInfo& info, bool removeSession, bool startFail) {};
1197 ASSERT_NE(nullptr, sceneSession->jsSceneSessionExceptionFunc_);
1198 res = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, needRemoveSession, false);
1199 ASSERT_EQ(res, WSError::WS_OK);
1200 }
1201 }
1202 }
1203 }