/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include "interfaces/include/ws_common.h" #include "iremote_object_mocker.h" #include "session_manager/include/scene_session_manager.h" #include "session_info.h" #include "session/host/include/scene_session.h" #include "session_manager.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace Rosen { class SceneSessionManagerTest9 : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); void SetUp() override; void TearDown() override; static sptr ssm_; private: static constexpr uint32_t WAIT_SYNC_IN_NS = 200000; }; sptr SceneSessionManagerTest9::ssm_ = nullptr; void NotifyRecoverSceneSessionFuncTest(const sptr& session, const SessionInfo& sessionInfo) { } bool TraverseFuncTest(const sptr& session) { return true; } void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type) { } void ProcessStatusBarEnabledChangeFuncTest(bool enable) { } void DumpRootSceneElementInfoFuncTest(const std::vector& params, std::vector& infos) { } void SceneSessionManagerTest9::SetUpTestCase() { ssm_ = &SceneSessionManager::GetInstance(); } void SceneSessionManagerTest9::TearDownTestCase() { ssm_ = nullptr; } void SceneSessionManagerTest9::SetUp() { } void SceneSessionManagerTest9::TearDown() { usleep(WAIT_SYNC_IN_NS); } namespace { /** * @tc.name: TraverseSessionTreeFromTopToBottom * @tc.desc: TraverseSessionTreeFromTopToBottom * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, TraverseSessionTreeFromTopToBottom, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); ssm_->TraverseSessionTreeFromTopToBottom(TraverseFuncTest); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "TraverseSessionTreeFromTopToBottom"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); ssm_->sceneSessionMap_.insert(std::make_pair(1, nullptr)); ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession)); ssm_->TraverseSessionTreeFromTopToBottom(TraverseFuncTest); } /** * @tc.name: RequestFocusStatus02 * @tc.desc: RequestFocusStatus * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, RequestFocusStatus02, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); EXPECT_EQ(ssm_->RequestFocusStatus(1, false, false, FocusChangeReason::FLOATING_SCENE), WMError::WM_ERROR_NULLPTR); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "RequestFocusStatus02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ssm_->RequestFocusStatus(1, false, false, FocusChangeReason::FLOATING_SCENE); } /** * @tc.name: RequestSessionFocusImmediately02 * @tc.desc: RequestSessionFocusImmediately * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, RequestSessionFocusImmediately02, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); ssm_->sceneSessionMap_.clear(); WSError ret = ssm_->RequestSessionFocusImmediately(0); EXPECT_NE(ret, WSError::WS_OK); ret = ssm_->RequestSessionFocusImmediately(2); EXPECT_NE(ret, WSError::WS_OK); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "RequestSessionFocusImmediately02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); sceneSession->SetFocusable(false); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ret = ssm_->RequestSessionFocusImmediately(1); EXPECT_EQ(ret, WSError::WS_DO_NOTHING); sceneSession->SetFocusable(true); sceneSession->SetFocusedOnShow(false); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ret = ssm_->RequestSessionFocusImmediately(1); EXPECT_EQ(ret, WSError::WS_DO_NOTHING); sceneSession->SetFocusedOnShow(true); sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED); ret = ssm_->RequestSessionFocusImmediately(1); EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION); sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ret = ssm_->RequestSessionFocusImmediately(1); EXPECT_EQ(ret, WSError::WS_OK); } /** * @tc.name: RequestSessionFocus02 * @tc.desc: RequestSessionFocus * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, RequestSessionFocus02, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); ssm_->sceneSessionMap_.clear(); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "RequestSessionFocus02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); sceneSession->SetFocusable(true); sceneSession->UpdateVisibilityInner(true); sceneSession->SetSessionState(SessionState::STATE_ACTIVE); sceneSession->SetFocusedOnShow(false); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); WSError ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_DO_NOTHING); sceneSession->SetFocusedOnShow(true); sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_OK); sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION); sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN); sceneSession->SetTopmost(true); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_OK); ASSERT_EQ(sceneSession->isFocused_, true); } /** * @tc.name: RequestSessionUnfocus02 * @tc.desc: RequestSessionUnfocus * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, RequestSessionUnfocus02, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); ssm_->sceneSessionMap_.clear(); WSError ret = ssm_->RequestSessionUnfocus(0, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION); ret = ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_DO_NOTHING); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "RequestSessionUnfocus02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); ssm_->focusedSessionId_ = 2; sceneSession->persistentId_ = 1; sceneSession->SetZOrder(50); sceneSession->state_ = SessionState::STATE_FOREGROUND; sceneSession->isVisible_ = true; ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); SessionInfo sessionInfo1; sptr sceneSession1 = sptr::MakeSptr(sessionInfo1, nullptr); ASSERT_NE(nullptr, sceneSession1); sceneSession1->GetSessionProperty()->SetParentPersistentId(1); sceneSession1->persistentId_ = 2; sceneSession1->SetZOrder(100); ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1)); ret = ssm_->RequestSessionUnfocus(2, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_OK); ASSERT_EQ(ssm_->focusedSessionId_, 1); ssm_->lastFocusedSessionId_ = 4; sceneSession1->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_FLOAT); SessionInfo sessionInfo2; sptr sceneSession2 = sptr::MakeSptr(sessionInfo2, nullptr); ASSERT_NE(nullptr, sceneSession2); sceneSession2->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP); sceneSession2->SetZOrder(20); sceneSession2->state_ = SessionState::STATE_FOREGROUND; sceneSession2->isVisible_ = true; sceneSession2->persistentId_ = 4; ssm_->sceneSessionMap_.insert(std::make_pair(4, sceneSession2)); ret = ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_OK); ASSERT_EQ(ssm_->focusedSessionId_, 4); } /** * @tc.name: RequestAllAppSessionUnfocusInner * @tc.desc: RequestAllAppSessionUnfocusInner * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, RequestAllAppSessionUnfocusInner, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); ssm_->RequestAllAppSessionUnfocusInner(); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "RequestAllAppSessionUnfocusInner"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); ssm_->focusedSessionId_ = 1; ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ssm_->RequestAllAppSessionUnfocusInner(); sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_FLOAT); ssm_->RequestAllAppSessionUnfocusInner(); } /** * @tc.name: UpdateFocus04 * @tc.desc: UpdateFocus * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, UpdateFocus04, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "UpdateFocus04"; sessionInfo.isSystem_ = true; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ssm_->focusedSessionId_ = 0; sceneSession->UpdateFocus(false); ssm_->UpdateFocus(1, false); sessionInfo.isSystem_ = false; ssm_->focusedSessionId_ = 1; sceneSession->UpdateFocus(true); ssm_->UpdateFocus(1, false); sceneSession->UpdateFocus(false); ssm_->UpdateFocus(1, true); } /** * @tc.name: ProcessFocusWhenForeground * @tc.desc: ProcessFocusWhenForeground * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, ProcessFocusWhenForeground, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "ProcessFocusWhenForeground"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); sceneSession->persistentId_ = 1; ASSERT_NE(nullptr, sceneSession->property_); sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); ssm_->focusedSessionId_ = 1; ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; ssm_->ProcessFocusWhenForeground(sceneSession); sceneSession->isVisible_ = true; sceneSession->SetSessionState(SessionState::STATE_FOREGROUND); ssm_->ProcessFocusWhenForeground(sceneSession); } /** * @tc.name: ProcessSubSessionForeground03 * @tc.desc: ProcessSubSessionForeground * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, ProcessSubSessionForeground03, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "ProcessSubSessionForeground03"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); SessionInfo subSessionInfo; sptr subSceneSession = sptr::MakeSptr(subSessionInfo, nullptr); ASSERT_NE(nullptr, subSceneSession); subSceneSession->SetTopmost(true); subSceneSession->SetSessionState(SessionState::STATE_FOREGROUND); subSceneSession->persistentId_ = 1; sceneSession->GetSubSession().push_back(subSceneSession); ssm_->sceneSessionMap_.insert(std::make_pair(1, subSceneSession)); ssm_->focusedSessionId_ = 1; ssm_->needBlockNotifyFocusStatusUntilForeground_ = true; SessionInfo subSessionInfo1; sptr subSceneSession1 = sptr::MakeSptr(subSessionInfo1, nullptr); ASSERT_NE(nullptr, subSceneSession1); subSceneSession1->SetTopmost(true); subSceneSession1->SetSessionState(SessionState::STATE_ACTIVE); subSceneSession1->persistentId_ = 0; sceneSession->GetSubSession().push_back(subSceneSession1); SessionInfo subSessionInfo2; sptr subSceneSession2 = sptr::MakeSptr(subSessionInfo2, nullptr); ASSERT_NE(nullptr, subSceneSession2); subSceneSession2->SetTopmost(true); subSceneSession2->SetSessionState(SessionState::STATE_CONNECT); sceneSession->GetSubSession().push_back(subSceneSession2); SessionInfo subSessionInfo3; sptr subSceneSession3 = sptr::MakeSptr(subSessionInfo3, nullptr); ASSERT_NE(nullptr, subSceneSession3); subSceneSession3->SetTopmost(false); subSceneSession3->SetSessionState(SessionState::STATE_ACTIVE); sceneSession->GetSubSession().push_back(subSceneSession3); sceneSession->GetSubSession().push_back(nullptr); ssm_->ProcessSubSessionForeground(sceneSession); ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; ssm_->ProcessSubSessionForeground(sceneSession); ssm_->focusedSessionId_ = 2; ssm_->ProcessSubSessionForeground(sceneSession); } /** * @tc.name: ProcessModalTopmostRequestFocusImmdediately02 * @tc.desc: ProcessModalTopmostRequestFocusImmdediately * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, ProcessModalTopmostRequestFocusImmdediately02, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "ProcessModalTopmostRequestFocusImmdediately02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); SessionInfo subSessionInfo; sptr subSceneSession = sptr::MakeSptr(subSessionInfo, nullptr); ASSERT_NE(nullptr, subSceneSession); subSceneSession->SetTopmost(true); subSceneSession->SetSessionState(SessionState::STATE_FOREGROUND); subSceneSession->persistentId_ = 1; subSceneSession->SetFocusable(true); subSceneSession->SetFocusedOnShow(true); sceneSession->GetSubSession().push_back(subSceneSession); ssm_->sceneSessionMap_.insert(std::make_pair(1, subSceneSession)); ssm_->focusedSessionId_ = 1; ssm_->needBlockNotifyFocusStatusUntilForeground_ = true; SessionInfo subSessionInfo1; sptr subSceneSession1 = sptr::MakeSptr(subSessionInfo1, nullptr); ASSERT_NE(nullptr, subSceneSession1); subSceneSession1->SetTopmost(true); subSceneSession1->SetSessionState(SessionState::STATE_ACTIVE); subSceneSession1->persistentId_ = 0; sceneSession->GetSubSession().push_back(subSceneSession1); SessionInfo subSessionInfo2; sptr subSceneSession2 = sptr::MakeSptr(subSessionInfo2, nullptr); ASSERT_NE(nullptr, subSceneSession2); subSceneSession2->SetTopmost(true); subSceneSession2->SetSessionState(SessionState::STATE_CONNECT); sceneSession->GetSubSession().push_back(subSceneSession2); SessionInfo subSessionInfo3; sptr subSceneSession3 = sptr::MakeSptr(subSessionInfo3, nullptr); ASSERT_NE(nullptr, subSceneSession3); subSceneSession3->SetTopmost(false); subSceneSession3->SetSessionState(SessionState::STATE_ACTIVE); sceneSession->GetSubSession().push_back(subSceneSession3); sceneSession->GetSubSession().push_back(nullptr); WSError ret = ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession); ASSERT_NE(ret, WSError::WS_OK); ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; ssm_->ProcessSubSessionForeground(sceneSession); subSceneSession->persistentId_ = 0; ret = ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession); ASSERT_NE(ret, WSError::WS_OK); } /** * @tc.name: ProcessDialogRequestFocusImmdediately02 * @tc.desc: ProcessDialogRequestFocusImmdediately * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, ProcessDialogRequestFocusImmdediately02, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "ProcessDialogRequestFocusImmdediately02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); SessionInfo dialogSessionInfo; sptr dialogSceneSession = sptr::MakeSptr(dialogSessionInfo, nullptr); ASSERT_NE(nullptr, dialogSceneSession); dialogSceneSession->SetTopmost(true); dialogSceneSession->SetSessionState(SessionState::STATE_FOREGROUND); dialogSceneSession->persistentId_ = 1; dialogSceneSession->SetFocusable(true); dialogSceneSession->SetFocusedOnShow(true); sceneSession->GetDialogVector().push_back(dialogSceneSession); ssm_->sceneSessionMap_.insert(std::make_pair(1, dialogSceneSession)); ssm_->focusedSessionId_ = 1; ssm_->needBlockNotifyFocusStatusUntilForeground_ = true; SessionInfo dialogSessionInfo1; sptr dialogSceneSession1 = sptr::MakeSptr(dialogSessionInfo1, nullptr); ASSERT_NE(nullptr, dialogSceneSession1); dialogSceneSession1->SetTopmost(true); dialogSceneSession1->SetSessionState(SessionState::STATE_ACTIVE); dialogSceneSession1->persistentId_ = 0; sceneSession->GetDialogVector().push_back(dialogSceneSession1); SessionInfo dialogSessionInfo2; sptr dialogSceneSession2 = sptr::MakeSptr(dialogSessionInfo2, nullptr); ASSERT_NE(nullptr, dialogSceneSession2); dialogSceneSession2->SetTopmost(true); dialogSceneSession2->SetSessionState(SessionState::STATE_CONNECT); sceneSession->GetDialogVector().push_back(dialogSceneSession2); sceneSession->GetDialogVector().push_back(nullptr); WSError ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession); ASSERT_NE(ret, WSError::WS_OK); dialogSceneSession->persistentId_ = 0; ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession); ASSERT_NE(ret, WSError::WS_OK); } /** * @tc.name: NotifyCompleteFirstFrameDrawing03 * @tc.desc: NotifyCompleteFirstFrameDrawing * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, NotifyCompleteFirstFrameDrawing03, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "NotifyCompleteFirstFrameDrawing03"; std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->excludeFromMissions = true; sessionInfo.abilityInfo = abilityInfo; sessionInfo.isSystem_ = true; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ssm_->NotifyCompleteFirstFrameDrawing(1); sessionInfo.isSystem_ = false; ssm_->eventHandler_ = nullptr; ssm_->NotifyCompleteFirstFrameDrawing(1); std::shared_ptr eventHandler = std::make_shared(); ssm_->eventHandler_ = eventHandler; abilityInfo->excludeFromMissions = false; ssm_->NotifyCompleteFirstFrameDrawing(1); } /** * @tc.name: SetSessionLabel02 * @tc.desc: SetSessionLabel * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, SetSessionLabel02, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "SetSessionLabel02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); sptr token = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, token); sceneSession->SetAbilityToken(token); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); std::string label = "testLabel"; ssm_->SetSessionLabel(token, label); sessionInfo.isSystem_ = false; ssm_->SetSessionLabel(token, label); sessionInfo.isSystem_ = true; ssm_->SetSessionLabel(token, label); } /** * @tc.name: RecoverAndReconnectSceneSession02 * @tc.desc: RecoverAndReconnectSceneSession * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, RecoverAndReconnectSceneSession02, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "RecoverAndReconnectSceneSession02"; sessionInfo.moduleName_ = "moduleTest"; sessionInfo.appIndex_ = 10; sessionInfo.persistentId_ = 1; std::shared_ptr abilityInfo = std::make_shared(); abilityInfo->excludeFromMissions = true; sessionInfo.abilityInfo = abilityInfo; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); sptr property = sceneSession->GetSessionProperty(); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); property->SetPersistentId(1); property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); property->SetWindowState(WindowState::STATE_SHOWN); property->SetRequestedOrientation(Orientation::UNSPECIFIED); ssm_->alivePersistentIds_.push_back(1); ssm_->recoveringFinished_ = false; ssm_->recoverSceneSessionFunc_ = NotifyRecoverSceneSessionFuncTest; sptr session; ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); auto result = ssm_->RecoverAndReconnectSceneSession(nullptr, nullptr, nullptr, session, property, nullptr); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION); property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); property->SetPersistentId(0); result = ssm_->RecoverAndReconnectSceneSession(nullptr, nullptr, nullptr, session, property, nullptr); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM); } /** * @tc.name: RefreshPcZorder * @tc.desc: RefreshPcZorder * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, RefreshPcZorder, Function | SmallTest | Level3) { std::vector persistentIds; SessionInfo info1; info1.abilityName_ = "RefreshPcZorder1"; info1.bundleName_ = "RefreshPcZorder1"; sptr session1 = sptr::MakeSptr(info1, nullptr); ASSERT_NE(session1, nullptr); persistentIds.push_back(session1->GetPersistentId()); ssm_->sceneSessionMap_.insert({session1->GetPersistentId(), session1}); SessionInfo info2; info2.abilityName_ = "RefreshPcZorder2"; info2.bundleName_ = "RefreshPcZorder2"; sptr session2 = sptr::MakeSptr(info2, nullptr); ASSERT_NE(session2, nullptr); persistentIds.push_back(session2->GetPersistentId()); ssm_->sceneSessionMap_.insert({session2->GetPersistentId(), session2}); SessionInfo info3; info3.abilityName_ = "RefreshPcZorder3"; info3.bundleName_ = "RefreshPcZorder3"; sptr session3 = sptr::MakeSptr(info3, nullptr); ASSERT_NE(session3, nullptr); session3->SetZOrder(404); ssm_->sceneSessionMap_.insert({session3->GetPersistentId(), session3}); persistentIds.push_back(999); uint32_t startZOrder = 100; std::vector newPersistentIds = persistentIds; ssm_->RefreshPcZOrderList(startZOrder, std::move(persistentIds)); ssm_->RefreshPcZOrderList(UINT32_MAX, std::move(newPersistentIds)); auto start = std::chrono::system_clock::now(); // Due to RefreshPcZOrderList being asynchronous, spin lock is added. // The spin lock itself is set with a timeout escape time of 3 seconds while (true) { if ((session1->GetZOrder() != 0 && session2->GetZOrder() != 0 && session1->GetZOrder() != 100) || std::chrono::duration_cast(std::chrono::system_clock::now() - start).count() >= 3) { break; } std::this_thread::sleep_for(std::chrono::milliseconds(100)); } ASSERT_EQ(session2->GetZOrder(), 101); ASSERT_EQ(session3->GetZOrder(), 404); ASSERT_EQ(session1->GetZOrder(), UINT32_MAX); } /** * @tc.name: GetSessionRSVisible * @tc.desc: GetSessionRSVisible * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, GetSessionRSVisible, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "GetSessionRSVisible"; sessionInfo.moduleName_ = "moduleTest"; uint64_t windowId = 10; sptr sceneSession01 = sptr::MakeSptr(sessionInfo, nullptr); sceneSession01->persistentId_ = windowId; sptr sceneSession02 = sptr::MakeSptr(sessionInfo, nullptr); std::vector> currVisibleData; currVisibleData.push_back(std::make_pair(0, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION)); currVisibleData.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION)); struct RSSurfaceNodeConfig config; sceneSession02->surfaceNode_ = RSSurfaceNode::Create(config); ASSERT_NE(nullptr, sceneSession02->surfaceNode_); sceneSession02->surfaceNode_->id_ = 0; sceneSession02->persistentId_ = windowId; ssm_->sceneSessionMap_.insert(std::make_pair(0, sceneSession02)); bool actual = ssm_->GetSessionRSVisible(sceneSession01, currVisibleData); EXPECT_EQ(actual, true); } /** * @tc.name: CheckClickFocusIsDownThroughFullScreen * @tc.desc: CheckClickFocusIsDownThroughFullScreen * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, CheckClickFocusIsDownThroughFullScreen, Function | SmallTest | Level3) { ASSERT_NE(ssm_, nullptr); SessionInfo info; info.abilityName_ = "test1"; info.bundleName_ = "test2"; sptr focusedSession = new (std::nothrow) SceneSession(info, nullptr); ASSERT_NE(focusedSession, nullptr); sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); ASSERT_NE(sceneSession, nullptr); bool ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, false); sptr property = new (std::nothrow) WindowSessionProperty(); ASSERT_NE(property, nullptr); property->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH); focusedSession->SetSessionProperty(property); ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, false); sceneSession->SetZOrder(50); focusedSession->SetZOrder(100); focusedSession->blockingFocus_ = true; ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::CLICK); ASSERT_EQ(ret, true); } /** * @tc.name: ShiftFocus * @tc.desc: ShiftFocus * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest9, ShiftFocus, Function | SmallTest | Level3) { ASSERT_NE(ssm_, nullptr); ssm_->sceneSessionMap_.clear(); SessionInfo info; info.abilityName_ = "test1"; info.bundleName_ = "test2"; sptr focusedSession = new (std::nothrow) SceneSession(info, nullptr); ASSERT_NE(focusedSession, nullptr); sptr nextSession = new (std::nothrow) SceneSession(info, nullptr); ASSERT_NE(nextSession, nullptr); focusedSession->persistentId_ = 1; nextSession->persistentId_ = 4; ssm_->sceneSessionMap_.insert({1, focusedSession}); ssm_->sceneSessionMap_.insert({4, nextSession}); ssm_->focusedSessionId_ = 1; WSError ret = ssm_->ShiftFocus(nextSession, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_OK); ASSERT_EQ(focusedSession->isFocused_, false); ASSERT_EQ(nextSession->isFocused_, true); } } } // namespace Rosen } // namespace OHOS