/* * Copyright (c) 2023 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 "window_helper.h" #include "display_manager.h" #include "pointer_event.h" #include #include "key_event.h" #include "session/host/include/scene_session.h" #include "session/host/include/sub_session.h" #include "session/host/include/system_session.h" #include "session/host/include/main_session.h" #include "wm_common.h" #include "mock/mock_session_stage.h" #include "input_event.h" #include #include "ui/rs_surface_node.h" #include "session/container/include/window_event_channel.h" #include "window_event_channel_base.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace Rosen { class SceneSessionLifecycleTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); void SetUp() override; void TearDown() override; sptr sceneSession; SessionInfo info; }; void SceneSessionLifecycleTest::SetUpTestCase() { } void SceneSessionLifecycleTest::TearDownTestCase() { } void SceneSessionLifecycleTest::SetUp() { sceneSession = new (std::nothrow) SceneSession(info, nullptr); } void SceneSessionLifecycleTest::TearDown() { } namespace { /** * @tc.name: Foreground01 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Foreground01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Foreground01"; info.bundleName_ = "Foreground01"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); int resultValue = 0; sptr sceneSession; sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sceneSession->isActive_ = true; sptr property = new (std::nothrow) WindowSessionProperty(); ASSERT_NE(nullptr, property); auto result = sceneSession->Foreground(property); ASSERT_EQ(result, WSError::WS_OK); specificCallback->onCreate_ = [&resultValue, specificCallback](const SessionInfo& info, sptr property) -> sptr { sptr scensessionreturn = new (std::nothrow) SceneSession(info, specificCallback); EXPECT_NE(scensessionreturn, nullptr); resultValue = 1; return scensessionreturn; }; sceneSession = new (std::nothrow) SceneSession(info, specificCallback); EXPECT_NE(sceneSession, nullptr); sceneSession->UpdateSessionState(SessionState::STATE_DISCONNECT); sceneSession->isActive_ = true; result = sceneSession->Foreground(property); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: Foreground02 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Foreground02, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Foreground02"; info.bundleName_ = "Foreground02"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession; sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sceneSession->isActive_ = true; sptr property = nullptr; auto result = sceneSession->Foreground(property); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: ForegroundAndBackground03 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Foreground03, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Foreground03"; info.bundleName_ = "Foreground03"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession; sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sceneSession->isActive_ = true; sptr property = new (std::nothrow) WindowSessionProperty(); property->SetAnimationFlag(static_cast(WindowAnimation::CUSTOM)); auto result = sceneSession->Foreground(property); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: Foreground04 * @tc.desc: Foreground04 function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Foreground04, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Foreground04"; info.bundleName_ = "Foreground04"; sptr session = sptr::MakeSptr(info, nullptr); EXPECT_NE(session, nullptr); sptr property = nullptr; EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false)); session->property_ = nullptr; EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false)); info.windowType_ = static_cast(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE); sptr session1 = sptr::MakeSptr(info, nullptr); EXPECT_EQ(WSError::WS_OK, session1->Foreground(property, true)); EXPECT_EQ(WSError::WS_OK, session1->Foreground(property, false)); } /** * @tc.name: Foreground05 * @tc.desc: Foreground05 function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Foreground05, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Foreground05"; info.bundleName_ = "Foreground05"; sptr session = sptr::MakeSptr(info, nullptr); EXPECT_NE(session, nullptr); sptr property = nullptr; session->Session::SetSessionState(SessionState::STATE_CONNECT); session->Session::isActive_ = true; session->SetLeashWinSurfaceNode(nullptr); EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false)); sptr specificCallback = sptr::MakeSptr(); session->specificCallback_ = specificCallback; EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false)); struct RSSurfaceNodeConfig config; std::shared_ptr surfaceNode = RSSurfaceNode::Create(config); session->SetLeashWinSurfaceNode(surfaceNode); EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false)); session->SetSessionProperty(property); EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false)); } /** * @tc.name: Foreground06 * @tc.desc: Foreground06 function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Foreground06, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Foreground06"; info.bundleName_ = "Foreground06"; sptr session = sptr::MakeSptr(info, nullptr); EXPECT_NE(session, nullptr); sptr property = nullptr; session->property_ = property; EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false)); session->SetLeashWinSurfaceNode(nullptr); EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false)); sptr property2 = new (std::nothrow) WindowSessionProperty(); EXPECT_NE(property2, nullptr); property2->SetAnimationFlag(static_cast(WindowAnimation::CUSTOM)); EXPECT_EQ(WSError::WS_OK, session->Foreground(property2, false)); struct RSSurfaceNodeConfig config; std::shared_ptr surfaceNode = RSSurfaceNode::Create(config); session->SetLeashWinSurfaceNode(surfaceNode); EXPECT_EQ(WSError::WS_OK, session->Foreground(property2, false)); sptr property3 = new (std::nothrow) WindowSessionProperty(); EXPECT_NE(property3, nullptr); property3->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE); session->SetSessionProperty(property3); EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false)); } /** * @tc.name: Background01 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Background01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Background01"; info.bundleName_ = "Background01"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); int resultValue = 0; sptr sceneSession; sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sceneSession->isActive_ = true; auto result = sceneSession->Background(); ASSERT_EQ(result, WSError::WS_OK); specificCallback->onCreate_ = [&resultValue, specificCallback](const SessionInfo& info, sptr property) -> sptr { sptr scensessionreturn = new (std::nothrow) SceneSession(info, specificCallback); EXPECT_NE(scensessionreturn, nullptr); resultValue = 1; return scensessionreturn; }; sceneSession = new (std::nothrow) SceneSession(info, specificCallback); EXPECT_NE(sceneSession, nullptr); sceneSession->UpdateSessionState(SessionState::STATE_CONNECT); sceneSession->isActive_ = true; result = sceneSession->Background(); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: Background02 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Background02, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Background02"; info.bundleName_ = "Background02"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr property = new (std::nothrow) WindowSessionProperty(); property->SetAnimationFlag(static_cast(WindowAnimation::CUSTOM)); sceneSession->SetSessionProperty(property); sceneSession->isActive_ = true; auto result = sceneSession->Background(); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: Background3 * @tc.desc: * @tc.name: Background * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Background3, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Background3"; info.bundleName_ = "Background3"; sptr sceneSession; sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(nullptr, sceneSession); sceneSession->specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); WindowType windowType = WindowType::APP_MAIN_WINDOW_BASE; OHOS::Rosen::WindowHelper::IsMainWindow(windowType); } /** * @tc.name: Background04 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Background04, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Background04"; info.bundleName_ = "Background04"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(nullptr, sceneSession); sptr property = new (std::nothrow) WindowSessionProperty(); EXPECT_NE(property, nullptr); property->SetAnimationFlag(static_cast(WindowAnimation::CUSTOM)); sceneSession->SetSessionProperty(property); EXPECT_EQ(WSError::WS_OK, sceneSession->Background(true)); sptr property2 = new (std::nothrow) WindowSessionProperty(); EXPECT_NE(property2, nullptr); property2->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE); sceneSession->SetSessionProperty(property2); EXPECT_EQ(WSError::WS_OK, sceneSession->Background(false)); EXPECT_EQ(WSError::WS_OK, sceneSession->Background(true)); } /** * @tc.name: BackgroundTask01 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, BackgroundTask01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "BackgroundTask01"; info.bundleName_ = "BackgroundTask01"; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); int resultValue = 0; sptr sceneSession; sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sceneSession->isActive_ = true; auto result = sceneSession->BackgroundTask(); ASSERT_EQ(result, WSError::WS_OK); sceneSession->isActive_ = true; result = sceneSession->BackgroundTask(false); ASSERT_EQ(result, WSError::WS_OK); specificCallback->onCreate_ = [&resultValue, specificCallback](const SessionInfo& info, sptr property) -> sptr { sptr sceneSessionReturn = new (std::nothrow) SceneSession(info, specificCallback); EXPECT_NE(sceneSessionReturn, nullptr); resultValue = 1; return sceneSessionReturn; }; sceneSession = new (std::nothrow) SceneSession(info, specificCallback); EXPECT_NE(sceneSession, nullptr); sceneSession->UpdateSessionState(SessionState::STATE_CONNECT); sceneSession->isActive_ = true; result = sceneSession->BackgroundTask(); ASSERT_EQ(result, WSError::WS_OK); sceneSession->UpdateSessionState(SessionState::STATE_CONNECT); sceneSession->isActive_ = true; result = sceneSession->BackgroundTask(false); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: BackgroundTask02 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, BackgroundTask02, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "BackgroundTask02"; info.bundleName_ = "BackgroundTask02"; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr property = new (std::nothrow) WindowSessionProperty(); property->SetAnimationFlag(static_cast(WindowAnimation::CUSTOM)); sceneSession->SetSessionProperty(property); sceneSession->isActive_ = true; auto result = sceneSession->BackgroundTask(); ASSERT_EQ(result, WSError::WS_OK); sceneSession->isActive_ = true; result = sceneSession->BackgroundTask(false); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: BackgroundTask03 * @tc.desc: BackgroundTask03 function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, BackgroundTask03, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "BackgroundTask03"; info.bundleName_ = "BackgroundTask03"; sptr session = sptr::MakeSptr(info, nullptr); EXPECT_NE(session, nullptr); sptr property = nullptr; session->SetSessionState(SessionState::STATE_BACKGROUND); EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false)); session->SetSessionState(SessionState::STATE_CONNECT); session->Session::SetSessionState(SessionState::STATE_CONNECT); EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false)); session->Session::SetSessionState(SessionState::STATE_INACTIVE); info.windowType_ = static_cast(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE); EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false)); info.windowType_ = static_cast(WindowType::APP_MAIN_WINDOW_BASE); sptr specificCallback = sptr::MakeSptr(); session->specificCallback_ = specificCallback; EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false)); session->scenePersistence_ = nullptr; EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(true)); session->scenePersistence_ = sptr::MakeSptr("Foreground02", 1); struct RSSurfaceNodeConfig config; std::shared_ptr surfaceNode = RSSurfaceNode::Create(config); session->surfaceNode_ = surfaceNode; EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(true)); sptr property2 = new (std::nothrow) WindowSessionProperty(); EXPECT_NE(property2, nullptr); property2->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE); session->SetSessionProperty(property2); EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(false)); EXPECT_EQ(WSError::WS_OK, session->BackgroundTask(true)); } /** * @tc.name: DisconnectTask01 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, DisconnectTask01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "DisconnectTask01"; info.bundleName_ = "DisconnectTask01"; sptr specificCallback = sptr::MakeSptr(); EXPECT_NE(specificCallback, nullptr); int resultValue = 0; sptr sceneSession = sptr::MakeSptr(info, nullptr); EXPECT_NE(sceneSession, nullptr); sceneSession->isActive_ = true; auto result = sceneSession->DisconnectTask(true, true); sceneSession = sptr::MakeSptr(info, nullptr); ASSERT_EQ(result, WSError::WS_OK); sceneSession->isActive_ = true; result = sceneSession->DisconnectTask(false, true); sceneSession = sptr::MakeSptr(info, nullptr); ASSERT_EQ(result, WSError::WS_OK); specificCallback->onCreate_ = [&resultValue, specificCallback](const SessionInfo& info, sptr property) -> sptr { sptr sceneSessionReturn = new (std::nothrow) SceneSession(info, specificCallback); EXPECT_NE(sceneSessionReturn, nullptr); resultValue = 1; return sceneSessionReturn; }; sceneSession = new (std::nothrow) SceneSession(info, specificCallback); EXPECT_NE(sceneSession, nullptr); sceneSession->UpdateSessionState(SessionState::STATE_CONNECT); sceneSession->isActive_ = true; result = sceneSession->DisconnectTask(true, true); sceneSession = sptr::MakeSptr(info, nullptr); ASSERT_EQ(result, WSError::WS_OK); sceneSession->UpdateSessionState(SessionState::STATE_CONNECT); sceneSession->isActive_ = true; result = sceneSession->DisconnectTask(false, true); sceneSession = sptr::MakeSptr(info, nullptr); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: DisconnectTask02 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, DisconnectTask02, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "DisconnectTask02"; info.bundleName_ = "DisconnectTask02"; sptr specificCallback = sptr::MakeSptr(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession = sptr::MakeSptr(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr property = sptr::MakeSptr(); EXPECT_NE(property, nullptr); property->SetAnimationFlag(static_cast(WindowAnimation::CUSTOM)); sceneSession->SetSessionProperty(property); sceneSession->isActive_ = true; auto result = sceneSession->DisconnectTask(true, true); sceneSession = sptr::MakeSptr(info, nullptr); ASSERT_EQ(result, WSError::WS_OK); sceneSession->isActive_ = true; result = sceneSession->DisconnectTask(false, true); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: Disconnect * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Disconnect, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Disconnect"; info.bundleName_ = "Disconnect"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr property = new (std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sceneSession->SetSessionProperty(property); sceneSession->isActive_ = true; auto result = sceneSession->Disconnect(); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: Disconnect2 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Disconnect2, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Disconnect2"; info.bundleName_ = "Disconnect2"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr property = new (std::nothrow) WindowSessionProperty(); EXPECT_NE(property, nullptr); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sceneSession->SetSessionProperty(property); sceneSession->isActive_ = true; auto result = sceneSession->Disconnect(true); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: Disconnect3 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Disconnect3, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Disconnect3"; info.bundleName_ = "Disconnect3"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr property = new (std::nothrow) WindowSessionProperty(); EXPECT_NE(property, nullptr); property->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE); sceneSession->SetSessionProperty(property); sceneSession->isActive_ = true; auto result = sceneSession->Disconnect(true); ASSERT_EQ(result, WSError::WS_OK); sceneSession->specificCallback_ = nullptr; result = sceneSession->Disconnect(false); ASSERT_EQ(result, WSError::WS_OK); sceneSession->needSnapshot_ = true; sceneSession->SetSessionState(SessionState::STATE_ACTIVE); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sceneSession->SetSessionProperty(property); result = sceneSession->Disconnect(false); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: UpdateActiveStatus01 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "UpdateActiveStatus01"; info.bundleName_ = "UpdateActiveStatus01"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr property = new (std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sceneSession->SetSessionProperty(property); sceneSession->isActive_ = true; auto result = sceneSession->UpdateActiveStatus(true); ASSERT_EQ(result, WSError::WS_OK); result = sceneSession->UpdateActiveStatus(false); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: UpdateActiveStatus02 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus02, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "UpdateActiveStatus02"; info.bundleName_ = "UpdateActiveStatus02"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr property = new (std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sceneSession->SetSessionProperty(property); sceneSession->isActive_ = false; auto result = sceneSession->UpdateActiveStatus(true); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: UpdateActiveStatus03 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus03, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "UpdateActiveStatus03"; info.bundleName_ = "UpdateActiveStatus03"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr property = new (std::nothrow) WindowSessionProperty(); EXPECT_NE(property, nullptr); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sceneSession->SetSessionProperty(property); sceneSession->isActive_ = true; sceneSession->state_ = SessionState::STATE_DISCONNECT; auto result = sceneSession->UpdateActiveStatus(false); ASSERT_EQ(result, WSError::WS_OK); result = sceneSession->UpdateActiveStatus(true); ASSERT_EQ(result, WSError::WS_OK); sceneSession->isActive_ = false; result = sceneSession->UpdateActiveStatus(false); ASSERT_EQ(result, WSError::WS_OK); sceneSession->isActive_ = true; sceneSession->state_ = SessionState::STATE_FOREGROUND; result = sceneSession->UpdateActiveStatus(true); ASSERT_EQ(result, WSError::WS_OK); sceneSession->isActive_ = true; sceneSession->state_ = SessionState::STATE_ACTIVE; result = sceneSession->UpdateActiveStatus(false); ASSERT_EQ(result, WSError::WS_OK); sceneSession->isActive_ = false; result = sceneSession->UpdateActiveStatus(true); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: UpdateActiveStatus04 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, UpdateActiveStatus04, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "UpdateActiveStatus04"; info.bundleName_ = "UpdateActiveStatus04"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr property = new (std::nothrow) WindowSessionProperty(); EXPECT_NE(property, nullptr); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sceneSession->SetSessionProperty(property); sceneSession->isActive_ = true; sceneSession->state_ = SessionState::STATE_ACTIVE; auto result = sceneSession->UpdateActiveStatus(true); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: Connect * @tc.desc: Connect * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Connect, Function | SmallTest | Level2) { SessionInfo info; info.bundleName_ = "Connect"; info.abilityName_ = "Connect1"; info.windowType_ = 1; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr sessionStage = nullptr; sptr eventChannel = nullptr; std::shared_ptr surfaceNode = nullptr; SystemSessionConfig systemConfig; sptr property = new WindowSessionProperty(); sptr token; WSError res = sceneSession->Connect(sessionStage, eventChannel, surfaceNode, systemConfig, property, token); ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR); } /** * @tc.name: ConnectInner01 * @tc.desc: ConnectInner01 * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, ConnectInner01, Function | SmallTest | Level2) { SessionInfo info; info.bundleName_ = "ConnectInner01"; info.abilityName_ = "ConnectInner01"; info.windowType_ = 1; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr mockSessionStage = new (std::nothrow) SessionStageMocker(); ASSERT_NE(mockSessionStage, nullptr); SystemSessionConfig systemConfig; sptr property = new (std::nothrow) WindowSessionProperty(); ASSERT_NE(property, nullptr); sceneSession->clientIdentityToken_ = "session1"; auto result = sceneSession->ConnectInner(mockSessionStage, nullptr, nullptr, systemConfig, property, nullptr, -1, -1, "session2"); ASSERT_EQ(result, WSError::WS_OK); result = sceneSession->ConnectInner(mockSessionStage, nullptr, nullptr, systemConfig, property, nullptr, -1, -1, "session1"); ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); result = sceneSession->ConnectInner(mockSessionStage, nullptr, nullptr, systemConfig, property, nullptr, -1, -1); ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); } /** * @tc.name: ConnectInner02 * @tc.desc: ConnectInner02 * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, ConnectInner02, Function | SmallTest | Level2) { SessionInfo info; info.bundleName_ = "ConnectInner02"; info.abilityName_ = "ConnectInner02"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr mockSessionStage = new (std::nothrow) SessionStageMocker(); ASSERT_NE(mockSessionStage, nullptr); SystemSessionConfig systemConfig; sptr property = new (std::nothrow) WindowSessionProperty(); ASSERT_NE(property, nullptr); sceneSession->SetSessionState(SessionState::STATE_CONNECT); sceneSession->Session::isTerminating_ = false; auto result = sceneSession->ConnectInner(mockSessionStage, nullptr, nullptr, systemConfig, property, nullptr); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION); sptr eventChannel = new WindowEventChannel(mockSessionStage); ASSERT_NE(eventChannel, nullptr); sceneSession->SetSessionState(SessionState::STATE_DISCONNECT); result = sceneSession->ConnectInner(mockSessionStage, eventChannel, nullptr, systemConfig, property, nullptr); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: Reconnect * @tc.desc: Reconnect * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, Reconnect, Function | SmallTest | Level2) { SessionInfo info; info.bundleName_ = "Reconnect"; info.abilityName_ = "Reconnect1"; info.windowType_ = 1; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr sessionStage = nullptr; sptr eventChannel = nullptr; std::shared_ptr surfaceNode = nullptr; sptr property = new WindowSessionProperty(); sptr token; int32_t pid = -1; int32_t uid = -1; WSError res = sceneSession->Reconnect(sessionStage, eventChannel, surfaceNode, property, token, pid, uid); ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR); property->windowState_ = WindowState::STATE_SHOWN; sessionStage = new SessionStageMocker(); eventChannel = new TestWindowEventChannel(); res = sceneSession->Reconnect(sessionStage, eventChannel, surfaceNode, property); ASSERT_EQ(res, WSError::WS_OK); } /** * @tc.name: ReconnectInner * @tc.desc: ReconnectInner * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, ReconnectInner, Function | SmallTest | Level2) { SessionInfo info; info.bundleName_ = "ReconnectInner"; info.abilityName_ = "ReconnectInner1"; info.windowType_ = 1; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr property = nullptr; WSError res = sceneSession->ReconnectInner(property); ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR); property = new WindowSessionProperty(); property->windowState_ = WindowState::STATE_INITIAL; res = sceneSession->ReconnectInner(property); ASSERT_EQ(res, WSError::WS_ERROR_INVALID_PARAM); property->windowState_ = WindowState::STATE_CREATED; res = sceneSession->ReconnectInner(property); ASSERT_EQ(res, WSError::WS_OK); property->windowState_ = WindowState::STATE_SHOWN; res = sceneSession->ReconnectInner(property); ASSERT_EQ(res, WSError::WS_OK); property->windowState_ = WindowState::STATE_HIDDEN; res = sceneSession->ReconnectInner(property); ASSERT_EQ(res, WSError::WS_OK); property->windowState_ = WindowState::STATE_DESTROYED; res = sceneSession->ReconnectInner(property); ASSERT_EQ(res, WSError::WS_ERROR_INVALID_PARAM); } /** * @tc.name: PendingSessionActivation * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, PendingSessionActivation, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "PendingSessionActivation"; info.bundleName_ = "PendingSessionActivation"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sceneSession->isActive_ = true; sptr property = new (std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); property->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM; sceneSession->SetSessionProperty(property); sptr abilitySessionInfo = new AAFwk::SessionInfo(); sptr info1 = nullptr; WSError result = sceneSession->PendingSessionActivation(info1); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION); result = sceneSession->PendingSessionActivation(abilitySessionInfo); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION); } /** * @tc.name: TerminateSession * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, TerminateSession, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "TerminateSession"; info.bundleName_ = "TerminateSession"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sceneSession->isActive_ = true; sptr property = new (std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); property->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM; sceneSession->SetSessionProperty(property); sptr abilitySessionInfo = new AAFwk::SessionInfo(); sptr info1 = nullptr; WSError result = sceneSession->TerminateSession(info1); ASSERT_EQ(result, WSError::WS_OK); result = sceneSession->TerminateSession(abilitySessionInfo); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: TerminateSession01 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, TerminateSession01, Function | SmallTest | Level2) { sptr abilitySessionInfo = new AAFwk::SessionInfo(); ASSERT_NE(nullptr, abilitySessionInfo); OHOS::Rosen::Session session(info); session.isTerminating_ = true; sceneSession->TerminateSession(abilitySessionInfo); ASSERT_EQ(WSError::WS_OK, sceneSession->TerminateSession(abilitySessionInfo)); NotifyTerminateSessionFuncNew callback = [](const SessionInfo& info, bool needStartCaller, bool isFromBroker){}; session.isTerminating_ = false; ASSERT_EQ(WSError::WS_OK, sceneSession->TerminateSession(abilitySessionInfo)); } /** * @tc.name: NotifySessionException * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, NotifySessionException, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "NotifySessionException"; info.bundleName_ = "NotifySessionException"; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sceneSession->isActive_ = true; sptr property = new (std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); property->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM; sceneSession->SetSessionProperty(property); sptr abilitySessionInfo = new AAFwk::SessionInfo(); sptr info1 = nullptr; WSError result = sceneSession->NotifySessionException(info1); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION); result = sceneSession->NotifySessionException(abilitySessionInfo); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION); } /** * @tc.name: NotifySessionException01 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, NotifySessionException01, Function | SmallTest | Level2) { sptr abilitySessionInfo = new AAFwk::SessionInfo(); ASSERT_NE(nullptr, abilitySessionInfo); bool needRemoveSession = true; OHOS::Rosen::Session session(info); session.isTerminating_ = true; sceneSession->NotifySessionException(abilitySessionInfo, needRemoveSession); sceneSession->GetLastSafeRect(); WSRect rect; sceneSession->SetLastSafeRect(rect); } /** * @tc.name: NotifySessionForeground01 * @tc.desc: NotifySessionForeground * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, NotifySessionForeground, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Foreground01"; info.bundleName_ = "IsFloatingWindowAppType"; info.windowType_ = 1; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession; sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr mockSessionStage = new (std::nothrow) SessionStageMocker(); ASSERT_NE(mockSessionStage, nullptr); uint32_t reason = 1; bool withAnimation = true; int ret = 1; sceneSession->sessionStage_ = mockSessionStage; sceneSession->NotifySessionForeground(reason, withAnimation); ASSERT_EQ(ret, 1); } /** * @tc.name: NotifySessionFullScreen01 * @tc.desc: NotifySessionFullScreen * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, NotifySessionFullScreen, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "FullScreen01"; info.bundleName_ = "IsFloatingWindowAppType"; info.windowType_ = 1; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr mockSessionStage = new (std::nothrow) SessionStageMocker(); ASSERT_NE(mockSessionStage, nullptr); bool fullScreen = true; int ret = 1; sceneSession->sessionStage_ = mockSessionStage; sceneSession->NotifySessionFullScreen(fullScreen); ASSERT_EQ(ret, 1); sceneSession->sessionStage_ = nullptr; sceneSession->NotifySessionFullScreen(fullScreen); } /** * @tc.name: NotifySessionBackground01 * @tc.desc: NotifySessionBackground * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, NotifySessionBackground, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Background01"; info.bundleName_ = "IsFloatingWindowAppType"; info.windowType_ = 1; sptr session_; sptr specificCallback = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback, nullptr); sptr sceneSession; sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sptr mockSessionStage = new (std::nothrow) SessionStageMocker(); ASSERT_NE(mockSessionStage, nullptr); uint32_t reason = 1; bool withAnimation = true; bool isFromInnerkits = true; int ret = 1; sceneSession->sessionStage_ = mockSessionStage; sceneSession->NotifySessionBackground(reason, withAnimation, isFromInnerkits); ASSERT_EQ(ret, 1); } /** * @tc.name: NotifySessionExceptionInner * @tc.desc: NotifySessionExceptionInner * @tc.type: FUNC */ HWTEST_F(SceneSessionLifecycleTest, NotifySessionExceptionInner, Function | SmallTest | Level2) { sptr abilitySessionInfo = new AAFwk::SessionInfo(); ASSERT_NE(nullptr, abilitySessionInfo); bool needRemoveSession = true; SessionInfo info; info.abilityName_ = "NotifySessionExceptionInner"; info.bundleName_ = "NotifySessionExceptionInner"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sceneSession->isTerminating_ = true; auto res = sceneSession->NotifySessionExceptionInner(nullptr, needRemoveSession); ASSERT_EQ(res, WSError::WS_OK); sptr property = new (std::nothrow) WindowSessionProperty(); ASSERT_NE(nullptr, property); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sceneSession->SetSessionProperty(property); sceneSession->clientIdentityToken_ = "session1"; abilitySessionInfo->identityToken = "session2"; res = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, needRemoveSession, true); ASSERT_EQ(res, WSError::WS_OK); sceneSession->isTerminating_ = true; res = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, needRemoveSession, false); ASSERT_EQ(res, WSError::WS_OK); sceneSession->isTerminating_ = false; res = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, needRemoveSession, false); ASSERT_EQ(res, WSError::WS_OK); sceneSession->sessionExceptionFunc_ = [](const SessionInfo& info, bool removeSession, bool startFail) {}; ASSERT_NE(nullptr, sceneSession->sessionExceptionFunc_); sceneSession->jsSceneSessionExceptionFunc_ = [](const SessionInfo& info, bool removeSession, bool startFail) {}; ASSERT_NE(nullptr, sceneSession->jsSceneSessionExceptionFunc_); res = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, needRemoveSession, false); ASSERT_EQ(res, WSError::WS_OK); } } } }