diff --git a/window_scene/test/unittest/scene_session_manager_test12.cpp b/window_scene/test/unittest/scene_session_manager_test12.cpp index e5ec3d08d7f4b1499c9b7d3236cd73cb5855cf78..4032f91b9fb4521711f9dfa1684591f2a9efc2e4 100644 --- a/window_scene/test/unittest/scene_session_manager_test12.cpp +++ b/window_scene/test/unittest/scene_session_manager_test12.cpp @@ -1793,6 +1793,80 @@ HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground06, TestSize.Leve EXPECT_EQ(hasFloatWindowForeground, false); } +/** + * @tc.name: GetRouterStackInfo01 + * @tc.desc: test function : GetRouterStackInfo01 + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, GetRouterStackInfo01, Function | SmallTest | Level2) +{ + class TestRouterListener : public SessionRouterStackListenerStub { + void SendRouterStackInfo(const sptr& routerStackInfo) override {} + }; + int32_t persistentId = -1; + auto listener = sptr::MakeSptr(); + MockAccesstokenKit::MockIsSystemApp(true); + MockAccesstokenKit::MockIsSACalling(true); + + auto result = ssm_->GetRouterStackInfo(persistentId, listener); + EXPECT_EQ(result, WMError::WM_ERROR_NULLPTR); + + result = ssm_->GetRouterStackInfo(persistentId, nullptr); + EXPECT_EQ(result, WMError::WM_ERROR_NULLPTR); +} + +/** + * @tc.name: GetRouterStackInfo02 + * @tc.desc: test function : GetRouterStackInfo02 + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, GetRouterStackInfo02, Function | SmallTest | Level2) +{ + class TestRouterListener : public SessionRouterStackListenerStub { + void SendRouterStackInfo(const sptr& routerStackInfo) override {} + }; + + SessionInfo info; + info.abilityName_ = "GetRouterStackInfo02"; + info.bundleName_ = "GetRouterStackInfo02"; + info.windowType_ = static_cast(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + sptr scenesession = sptr::MakeSptr(info, nullptr); + ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), scneSession}); + + auto listener = sptr::MakeSptr(); + MockAccesstokenKit::MockIsSystemApp(true); + MockAccesstokenKit::MockIsSACalling(true); + + auto result = ssm_->GetRouterStackInfo(sceneSession->GetPersistentId(), listener); + EXPECT_EQ(result, WMError::WM_OK); +} + +/** + * @tc.name: GetRouterStackInfo03 + * @tc.desc: test function : GetRouterStackInfo03 + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, GetRouterStackInfo03, Function | SmallTest | Level2) +{ + MockAccesstokenKit::MockIsSystemApp(false); + MockAccesstokenKit::MockIsSACalling(false); + auto result = ssm_->GetRouterStackInfo(1, nullptr); + EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION); + + MockAccesstokenKit::MockIsSystemApp(false); + MockAccesstokenKit::MockIsSACalling(true); + auto result = ssm_->GetRouterStackInfo(1, nullptr); + EXPECT_EQ(result, WMError::WM_ERROR_NULLPTR); + + MockAccesstokenKit::MockIsSystemApp(true); + MockAccesstokenKit::MockIsSACalling(false); + auto result = ssm_->GetRouterStackInfo(1, nullptr); + EXPECT_EQ(result, WMError::WM_ERROR_NULLPTR); + + MockAccesstokenKit::MockIsSystemApp(true); + MockAccesstokenKit::MockIsSACalling(true); +} + /** * @tc.name: UpdateSessionWithFoldStateChange * @tc.desc: test function : UpdateSessionWithFoldStateChange @@ -1870,6 +1944,132 @@ HWTEST_F(SceneSessionManagerTest12, GetActiveSceneSessionCopy, Function | SmallT EXPECT_EQ(activeSession.empty(), false); } +/** + * @tc.name: GetHookedSessionByModuleName + * @tc.desc: test function : GetHookedSessionByModuleName + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, GetHookedSessionByModuleName, Function | SmallTest | Level2) +{ + SessionInfo info; + info.bundleName_ = "testBundleName1"; + info.moduleName_ = "testModuleName1"; + info.appIndex_ = 1; + info.appInstanceKey_ = ""; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + ASSERT_NE(sceneSession, nullptr); + sceneSession->property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + auto res = ssm_->GetHookedSessionByModuleName(info); + ASSERT_EQ(res, nullptr); + + ssm_->sceneSessionMap_insert({101, sceneSession}); + res = ssm_->GetHookedSessionByModuleName(info); + ASSERT_EQ(res, sceneSession); + + info.appInstanceKey_ = "testAppInstanceKey1"; + res = ssm_->GetHookedSessionByModuleName(info); + ASSERT_EQ(res, nullptr); + + info.appIndex_ = 2; + res = ssm_->GetHookedSessionByModuleName(info); + ASSERT_EQ(res, nullptr); + + info.moduleName_ = "testModuleName2"; + res = ssm_->GetHookedSessionByModuleName(info); + ASSERT_EQ(res, nullptr); + + info.bundleName_ = "testBundleName2"; + res = ssm_->GetHookedSessionByModuleName(info); + ASSERT_EQ(res, nullptr); +} + +/** + * @tc.name: RequestSceneSession + * @tc.desc: test function : RequestSceneSession + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, RequestSceneSession, Function | SmallTest | Level2) +{ + SessionInfo info; + info.bundleName_ = "testBundleName1"; + info.moduleName_ = "testModuleName1"; + info.abilityName_ = "testAbilityName1"; + info.persistentId_ = 101; + info.appIndex_ = 0; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + ASSERT_NE(sceneSession, nullptr); + sceneSession->property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + sceneSession->sessionInfo_.isAbilityHook_ = true; + sptr windowSessionProperty = sptr::MakeSptr(); + ssm_->sceneSessionMap_[101] = sceneSession; + + auto result = ssm_->RequestSceneSession(info, windowSessionProperty); + ASSERT_NE(result, nullptr); + ASSERT_EQ(result->GetSessionInfo().moduleName_, info.moduleName_); +} + +/** + * @tc.name: RegisterSceneSessionDestructCallback + * @tc.desc: test function : RegisterSceneSessionDestructCallback + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, RegisterSceneSessionDestructCallback, Function | SmallTest | Level2) +{ + NotifySceneSessionDestructFunc func = [](int32_t persistentId) { return; }; + ssm_->RegisterSceneSessionDestructCallback(std::move(func)); + ASSERT_NE(nullptr, ssm_->onSeceneSessionDestruct_); +} + +/** + * @tc.name: RegisterSceneSessionDestructNotifyManagerFunc + * @tc.desc: test function : RegisterSceneSessionDestructNotifyManagerFunc + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, RegisterSceneSessionDestructNotifyManagerFunc, Function | SmallTest | Level2) +{ + SessionInfo info; + info.bundleName_ = "RegisterSceneSessionDestructNotifyManageFunc"; + info.moduleName_ = "RegisterSceneSessionDestructNotifyManageFunc"; + info.abilityName_ = "RegisterSceneSessionDestructNotifyManageFunc"; + info.persistentId_ = 999; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + ASSERT_NE(sceneSession, nullptr); + NotifySceneSessionDestructFunc func = [](int32_t persistentId) { return; }; + ssm_->RegisterSceneSessionDestructCallback(std::move(func)); + ssm_->RegisterSceneSessionDestructNotifyManagerFunc(sceneSession); + ASSERT_NE(sceneSession->notifySceneSessionDestructFunc_, nullptr); +} + +/** + * @tc.name: GetRecentMainSessionInfoList_Invalid_Permission + * @tc.desc: test function : GetRecentMainSessionInfoList_Invalid_Permission + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, GetRecentMainSessionInfoList_Invalid_Permission, Function | SmallTest | Level2) +{ + std::vector recentSessionInfoList = {}; + MockAccesstokenKit::MockIsSystemApp(false); + MockAccesstokenKit::MockIsSACalling(false); + auto result = ssm_->GetRecentMainSessionInfoList(recentSessionInfoList); + EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION); +} + +/** + * @tc.name: GetRecentMainSessionInfoList_Invalid_Param + * @tc.desc: test function : GetRecentMainSessionInfoList_Invalid_Param + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, GetRecentMainSessionInfoList_Invalid_Param, Function | SmallTest | Level2) +{ + std::vector recentSessionInfoList = {}; + RecentSessionInfo(101); + recentSessionInfoList.emplace_back(101); + MockAccesstokenKit::MockIsSystemApp(true); + MockAccesstokenKit::MockIsSACalling(false); + auto result = ssm_->GetRecentMainSessionInfoList(recentSessionInfoList); + EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PARAM); +} + /** * @tc.name: GetKeyboardOccupiedAreaWithRotation1 * @tc.desc: PC device is not compatible