/* * 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" #include "screen_session_manager/include/screen_session_manager_client.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace Rosen { class SceneSessionManagerTest10 : 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 SceneSessionManagerTest10::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 SceneSessionManagerTest10::SetUpTestCase() { ssm_ = &SceneSessionManager::GetInstance(); } void SceneSessionManagerTest10::TearDownTestCase() { ssm_ = nullptr; } void SceneSessionManagerTest10::SetUp() { } void SceneSessionManagerTest10::TearDown() { usleep(WAIT_SYNC_IN_NS); } namespace { /** * @tc.name: RequestSceneSessionDestructionInner * @tc.desc: RequestSceneSessionDestructionInner * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest10, RequestSceneSessionDestructionInner, Function | SmallTest | Level3) { ASSERT_NE(ssm_, nullptr); SessionInfo info; sptr specificCallback = nullptr; sptr scnSession = new (std::nothrow) SceneSession(info, specificCallback); sptr scnSessionInfo = new AAFwk::SessionInfo(); bool needRemoveSession = true; bool isForceClean = true; SessionInfo sessionInfo; sessionInfo.collaboratorType_ = CollaboratorType::RESERVE_TYPE; ssm_->RequestSceneSessionDestructionInner(scnSession, scnSessionInfo, needRemoveSession, isForceClean); needRemoveSession = false; isForceClean = false; sessionInfo.collaboratorType_ = CollaboratorType::DEFAULT_TYPE; sessionInfo.want = std::make_shared(); ssm_->listenerController_ = std::make_shared(); ssm_->RequestSceneSessionDestructionInner(scnSession, scnSessionInfo, needRemoveSession, isForceClean); } /** * @tc.name: RegisterWindowManagerAgent * @tc.desc: RegisterWindowManagerAgent * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest10, RegisterWindowManagerAgent01, Function | SmallTest | Level3) { WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR; sptr windowManagerAgent; ssm_->RegisterWindowManagerAgent(type, windowManagerAgent); type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED; ssm_->RegisterWindowManagerAgent(type, windowManagerAgent); type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG; ssm_->RegisterWindowManagerAgent(type, windowManagerAgent); type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE; ssm_->RegisterWindowManagerAgent(type, windowManagerAgent); type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY; ssm_->RegisterWindowManagerAgent(type, windowManagerAgent); type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE; ssm_->RegisterWindowManagerAgent(type, windowManagerAgent); type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM; ssm_->RegisterWindowManagerAgent(type, windowManagerAgent); type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS; ssm_->RegisterWindowManagerAgent(type, windowManagerAgent); type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE; ssm_->RegisterWindowManagerAgent(type, windowManagerAgent); type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT; ASSERT_EQ(windowManagerAgent, nullptr); ssm_->RegisterWindowManagerAgent(type, windowManagerAgent); } /** * @tc.name: UpdateRotateAnimationConfig * @tc.desc: UpdateRotateAnimationConfig * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest10, UpdateRotateAnimationConfig, Function | SmallTest | Level3) { ASSERT_NE(ssm_, nullptr); RotateAnimationConfig config = { 400 }; ssm_->UpdateRotateAnimationConfig(config); usleep(WAIT_SYNC_IN_NS); ASSERT_EQ(ssm_->rotateAnimationConfig_.duration_, 400); config.duration_ = 600; ssm_->UpdateRotateAnimationConfig(config); usleep(WAIT_SYNC_IN_NS); ASSERT_EQ(ssm_->rotateAnimationConfig_.duration_, 600); } /** * @tc.name: RegisterAcquireRotateAnimationConfigFunc * @tc.desc: RegisterAcquireRotateAnimationConfigFunc * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest10, RegisterAcquireRotateAnimationConfigFunc, Function | SmallTest | Level3) { ASSERT_NE(ssm_, nullptr); SessionInfo sessionInfo; sessionInfo.bundleName_ = "bundleName"; sessionInfo.persistentId_ = 1; sessionInfo.isSystem_ = false; sessionInfo.abilityInfo = std::make_shared(); ASSERT_NE(sessionInfo.abilityInfo, nullptr); sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(sceneSession, nullptr); sceneSession->scenePersistence_ = sptr::MakeSptr("bundleName", 1); ASSERT_NE(sceneSession->scenePersistence_, nullptr); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ssm_->RegisterAcquireRotateAnimationConfigFunc(sceneSession); WSRect rect({1, 1, 1, 1}); SizeChangeReason reason = SizeChangeReason::ROTATION; WSError result = sceneSession->UpdateRect(rect, reason, "SceneSessionManagerTest10"); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: CheckLastFocusedAppSessionFocus * @tc.desc: CheckLastFocusedAppSessionFocus * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest10, CheckLastFocusedAppSessionFocus, Function | SmallTest | Level3) { ASSERT_NE(ssm_, nullptr); SessionInfo info1; info1.abilityName_ = "focusedSession"; info1.bundleName_ = "focusedSession"; info1.windowType_ = 1; sptr focusedSession = new (std::nothrow) SceneSession(info1, nullptr); ASSERT_NE(focusedSession, nullptr); SessionInfo info2; info2.abilityName_ = "nextSession"; info2.bundleName_ = "nextSession"; info2.windowType_ = 1; sptr nextSession = new (std::nothrow) SceneSession(info2, nullptr); ASSERT_NE(nextSession, nullptr); ssm_->lastFocusedAppSessionId_ = nextSession->GetPersistentId(); ASSERT_EQ(false, ssm_->CheckLastFocusedAppSessionFocus(focusedSession, nextSession)); ssm_->lastFocusedAppSessionId_ = 124; focusedSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); ASSERT_EQ(false, ssm_->CheckLastFocusedAppSessionFocus(focusedSession, nextSession)); nextSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); ssm_->CheckLastFocusedAppSessionFocus(focusedSession, nextSession); ASSERT_EQ(0, ssm_->lastFocusedAppSessionId_); } /** * @tc.name: ProcessFocusZOrderChange * @tc.desc: ProcessFocusZOrderChange * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest10, ProcessFocusZOrderChange, Function | SmallTest | Level3) { ssm_->sceneSessionMap_.clear(); ssm_->ProcessFocusZOrderChange(10); ssm_->systemConfig_.uiType_ = "pc"; ssm_->ProcessFocusZOrderChange(97); ssm_->systemConfig_.uiType_ = "phone"; ssm_->ProcessFocusZOrderChange(97); SessionInfo sessionInfo; sessionInfo.bundleName_ = "focusedSession"; sessionInfo.abilityName_ = "focusedSession"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); ssm_->sceneSessionMap_.emplace(1, sceneSession); ssm_->focusedSessionId_ = 1; ssm_->ProcessFocusZOrderChange(97); sceneSession->lastZOrder_ = 2203; sceneSession->zOrder_ = 101; ssm_->ProcessFocusZOrderChange(97); SessionInfo sessionInfo1; sessionInfo1.bundleName_ = "voiceInteractionSession"; sessionInfo1.abilityName_ = "voiceInteractionSession"; sessionInfo1.windowType_ = static_cast(WindowType::WINDOW_TYPE_VOICE_INTERACTION); sptr sceneSession1 = sptr::MakeSptr(sessionInfo1, nullptr); ASSERT_NE(nullptr, sceneSession1); sceneSession1->zOrder_ = 2109; ssm_->sceneSessionMap_.emplace(2, sceneSession1); sceneSession->lastZOrder_ = 103; sceneSession->zOrder_ = 101; ssm_->ProcessFocusZOrderChange(97); sceneSession->lastZOrder_ = 2203; sceneSession->zOrder_ = 101; ssm_->ProcessFocusZOrderChange(97); } /** * @tc.name: NotifyVisibleChange * @tc.desc: test NotifyVisibleChange * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest10, NotifyVisibleChange, Function | SmallTest | Level3) { SessionInfo info; info.abilityName_ = "test"; info.bundleName_ = "test"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); ASSERT_NE(nullptr, sceneSession); ASSERT_FALSE(ssm_->NotifyVisibleChange(sceneSession->GetPersistentId())); ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession}); ASSERT_TRUE(ssm_->NotifyVisibleChange(sceneSession->GetPersistentId())); ssm_->sceneSessionMap_.erase(sceneSession->GetPersistentId()); } /** * @tc.name: IsInSecondaryScreen * @tc.desc: test IsInSecondaryScreen * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest10, IsInSecondaryScreen, Function | SmallTest | Level3) { SessionInfo info; info.abilityName_ = "test"; info.bundleName_ = "test"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); ASSERT_NE(nullptr, sceneSession); sptr property = new (std::nothrow) WindowSessionProperty(); ASSERT_NE(nullptr, property); DisplayId displayId = ScreenSessionManagerClient::GetInstance().GetDefaultScreenId(); property->SetDisplayId(displayId); sceneSession->SetSessionProperty(property); ASSERT_EQ(ssm_->IsInSecondaryScreen(sceneSession), false); displayId = 5; property->SetDisplayId(displayId); sceneSession->SetSessionProperty(property); ASSERT_EQ(ssm_->IsInSecondaryScreen(sceneSession), true); } /** * @tc.name: ProcessUpdateLastFocusedAppId * @tc.desc: test ProcessUpdateLastFocusedAppId * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest10, ProcessUpdateLastFocusedAppId, Function | SmallTest | Level1) { ssm_->sceneSessionMap_.clear(); std::vector zOrderList; ssm_->lastFocusedAppSessionId_ = INVALID_SESSION_ID; ssm_->ProcessUpdateLastFocusedAppId(zOrderList); SessionInfo sessionInfo; sessionInfo.bundleName_ = "lastFocusedAppSession"; sessionInfo.abilityName_ = "lastFocusedAppSession"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ssm_->sceneSessionMap_.emplace(1, sceneSession); ssm_->lastFocusedAppSessionId_ = 1; sceneSession->zOrder_ = 101; ssm_->ProcessUpdateLastFocusedAppId(zOrderList); ASSERT_EQ(1, ssm_->lastFocusedAppSessionId_); zOrderList.push_back(103); ssm_->ProcessUpdateLastFocusedAppId(zOrderList); ASSERT_EQ(INVALID_SESSION_ID, ssm_->lastFocusedAppSessionId_); } } // namespace } }