/* * 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 #include #include #include "mock/mock_session_stage.h" #include "mock/mock_window_event_channel.h" #include "session/host/include/extension_session.h" #include "session/host/include/move_drag_controller.h" #include "session/host/include/scene_session.h" #include "session/host/include/session.h" #include "session_info.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace Rosen { namespace { const std::string UNDEFINED = "undefined"; } class TestWindowEventChannel : public IWindowEventChannel { public: WSError TransferKeyEvent(const std::shared_ptr& keyEvent) override; WSError TransferPointerEvent(const std::shared_ptr& pointerEvent) override; WSError TransferFocusActiveEvent(bool isFocusActive) override; WSError TransferKeyEventForConsumed(const std::shared_ptr& keyEvent, bool& isConsumed) override; WSError TransferFocusState(bool focusState) override; sptr AsObject() override { return nullptr; }; }; WSError TestWindowEventChannel::TransferKeyEvent(const std::shared_ptr& keyEvent) { return WSError::WS_OK; } WSError TestWindowEventChannel::TransferPointerEvent(const std::shared_ptr& pointerEvent) { return WSError::WS_OK; } WSError TestWindowEventChannel::TransferFocusActiveEvent(bool isFocusActive) { return WSError::WS_OK; } WSError TestWindowEventChannel::TransferKeyEventForConsumed( const std::shared_ptr& keyEvent, bool& isConsumed) { return WSError::WS_OK; } WSError TestWindowEventChannel::TransferFocusState(bool foucsState) { return WSError::WS_OK; } class WindowSessionTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); void SetUp() override; void TearDown() override; private: RSSurfaceNode::SharedPtr CreateRSSurfaceNode(); sptr session_ = nullptr; }; void WindowSessionTest::SetUpTestCase() { } void WindowSessionTest::TearDownTestCase() { } void WindowSessionTest::SetUp() { SessionInfo info; info.abilityName_ = "testSession1"; info.moduleName_ = "testSession2"; info.bundleName_ = "testSession3"; session_ = new (std::nothrow) Session(info); session_->surfaceNode_ = CreateRSSurfaceNode(); EXPECT_NE(nullptr, session_); } void WindowSessionTest::TearDown() { session_ = nullptr; } RSSurfaceNode::SharedPtr WindowSessionTest::CreateRSSurfaceNode() { struct RSSurfaceNodeConfig rsSurfaceNodeConfig; rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTestSurfaceNode"; auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig); return surfaceNode; } namespace { /** * @tc.name: SetActive01 * @tc.desc: set session active * @tc.type: FUNC * @tc.require: #I6JLSI */ HWTEST_F(WindowSessionTest, SetActive01, Function | SmallTest | Level2) { sptr sessionToken = nullptr; sptr mockSessionStage = new(std::nothrow) SessionStageMocker(); EXPECT_NE(nullptr, mockSessionStage); EXPECT_CALL(*(mockSessionStage), SetActive(_)).WillOnce(Return(WSError::WS_OK)); EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _)).Times(1).WillOnce(Return(WSError::WS_OK)); session_->sessionStage_ = mockSessionStage; ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->SetActive(true)); sptr mockEventChannel = new(std::nothrow) WindowEventChannelMocker(mockSessionStage); EXPECT_NE(nullptr, mockEventChannel); auto surfaceNode = CreateRSSurfaceNode(); SystemSessionConfig sessionConfig; ASSERT_EQ(WSError::WS_OK, session_->Connect(mockSessionStage, mockEventChannel, surfaceNode, sessionConfig)); ASSERT_EQ(WSError::WS_OK, session_->SetActive(true)); ASSERT_EQ(false, session_->isActive_); session_->UpdateSessionState(SessionState::STATE_FOREGROUND); ASSERT_EQ(WSError::WS_OK, session_->SetActive(true)); ASSERT_EQ(true, session_->isActive_); } /** * @tc.name: UpdateRect01 * @tc.desc: update rect * @tc.type: FUNC * @tc.require: #I6JLSI */ HWTEST_F(WindowSessionTest, UpdateRect01, Function | SmallTest | Level2) { sptr sessionToken = nullptr; sptr mockSessionStage = new(std::nothrow) SessionStageMocker(); EXPECT_NE(nullptr, mockSessionStage); session_->sessionStage_ = mockSessionStage; EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _)).Times(1).WillOnce(Return(WSError::WS_OK)); WSRect rect = {0, 0, 0, 0}; ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED)); sptr mockEventChannel = new(std::nothrow) WindowEventChannelMocker(mockSessionStage); EXPECT_NE(nullptr, mockEventChannel); SystemSessionConfig sessionConfig; ASSERT_EQ(WSError::WS_OK, session_->Connect(mockSessionStage, mockEventChannel, nullptr, sessionConfig)); rect = {0, 0, 100, 100}; EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _)).Times(1).WillOnce(Return(WSError::WS_OK)); ASSERT_EQ(WSError::WS_OK, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED)); ASSERT_EQ(rect, session_->winRect_); } /** * @tc.name: IsSessionValid01 * @tc.desc: check func IsSessionValid * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, IsSessionValid01, Function | SmallTest | Level2) { session_->state_ = SessionState::STATE_DISCONNECT; ASSERT_FALSE(session_->IsSessionValid()); session_->state_ = SessionState::STATE_CONNECT; ASSERT_TRUE(session_->IsSessionValid()); } /** * @tc.name: UpdateWindowSessionProperty01 * @tc.desc: UpdateWindowSessionProperty * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, UpdateWindowSessionProperty01, Function | SmallTest | Level2) { session_->state_ = SessionState::STATE_DISCONNECT; ASSERT_EQ(session_->UpdateWindowSessionProperty(nullptr), WSError::WS_OK); } /** * @tc.name: Connect01 * @tc.desc: check func Connect * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, Connect01, Function | SmallTest | Level2) { auto surfaceNode = CreateRSSurfaceNode(); session_->state_ = SessionState::STATE_CONNECT; SystemSessionConfig systemConfig; auto result = session_->Connect(nullptr, nullptr, nullptr, systemConfig); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION); session_->state_ = SessionState::STATE_DISCONNECT; result = session_->Connect(nullptr, nullptr, nullptr, systemConfig); ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); sptr mockSessionStage = new(std::nothrow) SessionStageMocker(); EXPECT_NE(nullptr, mockSessionStage); result = session_->Connect(mockSessionStage, nullptr, surfaceNode, systemConfig); ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); sptr testWindowEventChannel = new(std::nothrow) TestWindowEventChannel(); EXPECT_NE(nullptr, testWindowEventChannel); result = session_->Connect(mockSessionStage, testWindowEventChannel, surfaceNode, systemConfig); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: Foreground01 * @tc.desc: check func Foreground * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, Foreground01, Function | SmallTest | Level2) { session_->state_ = SessionState::STATE_DISCONNECT; sptr property = new(std::nothrow) WindowSessionProperty(); ASSERT_NE(nullptr, property); auto result = session_->Foreground(property); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION); session_->state_ = SessionState::STATE_CONNECT; session_->isActive_ = true; result = session_->Foreground(property); ASSERT_EQ(result, WSError::WS_OK); session_->isActive_ = false; ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: Background01 * @tc.desc: check func Background * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, Background01, Function | SmallTest | Level2) { session_->state_ = SessionState::STATE_CONNECT; auto result = session_->Background(); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION); session_->state_ = SessionState::STATE_INACTIVE; result = session_->Background(); ASSERT_EQ(result, WSError::WS_OK); ASSERT_EQ(session_->state_, SessionState::STATE_BACKGROUND); } /** * @tc.name: Disconnect01 * @tc.desc: check func Disconnect * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, Disconnect01, Function | SmallTest | Level2) { session_->state_ = SessionState::STATE_CONNECT; auto result = session_->Disconnect(); ASSERT_EQ(result, WSError::WS_OK); ASSERT_EQ(session_->state_, SessionState::STATE_DISCONNECT); session_->state_ = SessionState::STATE_BACKGROUND; result = session_->Disconnect(); ASSERT_EQ(result, WSError::WS_OK); ASSERT_EQ(session_->state_, SessionState::STATE_DISCONNECT); } /** * @tc.name: PendingSessionActivation01 * @tc.desc: check func PendingSessionActivation * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, PendingSessionActivation01, Function | SmallTest | Level2) { int resultValue = 0; NotifyPendingSessionActivationFunc callback = [&resultValue](const SessionInfo& info) { resultValue = 1; }; sptr info = new (std::nothrow)AAFwk::SessionInfo(); session_->pendingSessionActivationFunc_ = nullptr; session_->PendingSessionActivation(info); ASSERT_EQ(resultValue, 0); session_->SetPendingSessionActivationEventListener(callback); session_->PendingSessionActivation(info); ASSERT_EQ(resultValue, 1); ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->PendingSessionActivation(nullptr)); } /** * @tc.name: TerminateSessionNew01 * @tc.desc: check func TerminateSessionNew * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, TerminateSessionNew01, Function | SmallTest | Level2) { int resultValue = 0; NotifyTerminateSessionFuncNew callback = [&resultValue](const SessionInfo& info, bool needStartCaller) { resultValue = 1; }; bool needStartCaller = false; sptr info = new (std::nothrow)AAFwk::SessionInfo(); session_->terminateSessionFuncNew_ = nullptr; session_->TerminateSessionNew(info, needStartCaller); ASSERT_EQ(resultValue, 0); needStartCaller = true; session_->SetTerminateSessionListenerNew(callback); session_->TerminateSessionNew(info, needStartCaller); ASSERT_EQ(resultValue, 1); ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->TerminateSessionNew(nullptr, needStartCaller)); } /** * @tc.name: NotifySessionException01 * @tc.desc: check func NotifySessionException * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, NotifySessionException01, Function | SmallTest | Level2) { int resultValue = 0; NotifySessionExceptionFunc callback = [&resultValue](const SessionInfo& info) { resultValue = 1; }; sptr info = new (std::nothrow)AAFwk::SessionInfo(); session_->sessionExceptionFuncs_.clear(); session_->NotifySessionException(info); ASSERT_EQ(resultValue, 0); session_->SetSessionExceptionListener(callback); session_->NotifySessionException(info); ASSERT_EQ(resultValue, 1); ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->NotifySessionException(nullptr)); } /** * @tc.name: UpdateActiveStatus01 * @tc.desc: check func UpdateActiveStatus01 * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, UpdateActiveStatus01, Function | SmallTest | Level2) { ASSERT_NE(session_, nullptr); session_->isActive_ = false; session_->UpdateSessionState(SessionState::STATE_FOREGROUND); auto result = session_->UpdateActiveStatus(false); ASSERT_EQ(result, WSError::WS_DO_NOTHING); result = session_->UpdateActiveStatus(true); ASSERT_EQ(result, WSError::WS_OK); ASSERT_EQ(SessionState::STATE_ACTIVE, session_->state_); } /** * @tc.name: UpdateActiveStatus02 * @tc.desc: check func UpdateActiveStatus02 * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, UpdateActiveStatus02, Function | SmallTest | Level2) { ASSERT_NE(session_, nullptr); session_->isActive_ = false; session_->UpdateSessionState(SessionState::STATE_INACTIVE); auto result = session_->UpdateActiveStatus(true); ASSERT_EQ(result, WSError::WS_DO_NOTHING); ASSERT_EQ(SessionState::STATE_INACTIVE, session_->state_); ASSERT_EQ(false, session_->isActive_); session_->UpdateSessionState(SessionState::STATE_FOREGROUND); result = session_->UpdateActiveStatus(true); ASSERT_EQ(result, WSError::WS_OK); ASSERT_EQ(SessionState::STATE_ACTIVE, session_->state_); result = session_->UpdateActiveStatus(false); ASSERT_EQ(result, WSError::WS_OK); ASSERT_EQ(SessionState::STATE_INACTIVE, session_->state_); } /** * @tc.name: SetSessionRect * @tc.desc: check func SetSessionRect * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, SetSessionRect, Function | SmallTest | Level2) { ASSERT_NE(session_, nullptr); WSRect rect = { 0, 0, 320, 240}; // width: 320, height: 240 session_->SetSessionRect(rect); ASSERT_EQ(rect, session_->winRect_); } /** * @tc.name: GetSessionRect * @tc.desc: check func GetSessionRect * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, GetSessionRect, Function | SmallTest | Level2) { ASSERT_NE(session_, nullptr); WSRect rect = { 0, 0, 320, 240}; // width: 320, height: 240 session_->SetSessionRect(rect); ASSERT_EQ(rect, session_->GetSessionRect()); } /** * @tc.name: CheckDialogOnForeground * @tc.desc: check func CheckDialogOnForeground * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, CheckDialogOnForeground, Function | SmallTest | Level2) { ASSERT_NE(session_, nullptr); session_->dialogVec_.clear(); ASSERT_EQ(false, session_->CheckDialogOnForeground()); SessionInfo info; info.abilityName_ = "dialogAbilityName"; info.moduleName_ = "dialogModuleName"; info.bundleName_ = "dialogBundleName"; sptr dialogSession = new (std::nothrow) Session(info); ASSERT_NE(dialogSession, nullptr); dialogSession->state_ = SessionState::STATE_INACTIVE; session_->dialogVec_.push_back(dialogSession); ASSERT_EQ(false, session_->CheckDialogOnForeground()); session_->dialogVec_.clear(); } /** * @tc.name: NotifyDestroy * @tc.desc: check func NotifyDestroy * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, NotifyDestroy, Function | SmallTest | Level2) { sptr mockSessionStage = new(std::nothrow) SessionStageMocker(); ASSERT_NE(mockSessionStage, nullptr); session_->sessionStage_ = mockSessionStage; EXPECT_CALL(*(mockSessionStage), NotifyDestroy()).Times(1).WillOnce(Return(WSError::WS_OK)); ASSERT_EQ(WSError::WS_OK, session_->NotifyDestroy()); session_->sessionStage_ = nullptr; ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->NotifyDestroy()); } /** * @tc.name: RequestSessionBack * @tc.desc: request session back * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, RequestSessionBack, Function | SmallTest | Level2) { ASSERT_NE(session_, nullptr); ASSERT_EQ(WSError::WS_DO_NOTHING, session_->RequestSessionBack()); NotifyBackPressedFunc callback = []() {}; session_->SetBackPressedListenser(callback); ASSERT_EQ(WSError::WS_OK, session_->RequestSessionBack()); } /** * @tc.name: RaiseToAppTop01 * @tc.desc: RaiseToAppTop * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, RaiseToAppTop01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "testSession1"; info.bundleName_ = "testSession3"; sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); auto result = scensession->RaiseToAppTop(); ASSERT_EQ(result, WSError::WS_OK); sptr scensessionchangeCallBack = new (std::nothrow) SceneSession::SessionChangeCallback(); EXPECT_NE(scensessionchangeCallBack, nullptr); scensession->RegisterSessionChangeCallback(scensessionchangeCallBack); result = scensession->RaiseToAppTop(); ASSERT_EQ(result, WSError::WS_OK); NotifyRaiseToTopFunc onRaiseToTop_ = []() {}; scensessionchangeCallBack->onRaiseToTop_ = onRaiseToTop_; result = scensession->RaiseToAppTop(); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: UpdateSessionRect01 * @tc.desc: UpdateSessionRect * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, UpdateSessionRect01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "testSession1"; info.bundleName_ = "testSession3"; sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); WSRect rect = {0, 0, 320, 240}; // width: 320, height: 240 auto result = scensession->UpdateSessionRect(rect, SizeChangeReason::RESIZE); ASSERT_EQ(result, WSError::WS_OK); sptr scensessionchangeCallBack = new (std::nothrow) SceneSession::SessionChangeCallback(); EXPECT_NE(scensessionchangeCallBack, nullptr); scensession->RegisterSessionChangeCallback(scensessionchangeCallBack); result = scensession->UpdateSessionRect(rect, SizeChangeReason::RESIZE); ASSERT_EQ(result, WSError::WS_OK); int resultValue = 0; NotifySessionRectChangeFunc onRectChange_ = [&resultValue](const WSRect &rect, const SizeChangeReason& reason) { resultValue = 1; }; scensessionchangeCallBack->onRectChange_ = onRectChange_; result = scensession->UpdateSessionRect(rect, SizeChangeReason::RESIZE); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: DestroyAndDisconnectSpecificSession01 * @tc.desc: DestroyAndDisconnectSpecificSession * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, DestroyAndDisconnectSpecificSession01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "testSession1"; info.bundleName_ = "testSession3"; int32_t persistentId = 0; sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); auto result = scensession->DestroyAndDisconnectSpecificSession(persistentId); ASSERT_EQ(result, WSError::WS_OK); sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback_, nullptr); int resultValue = 0; specificCallback_->onDestroy_ = [&resultValue](const int32_t &persistentId) -> WSError { resultValue = 1; return WSError::WS_OK; }; scensession = new (std::nothrow) SceneSession(info, specificCallback_); EXPECT_NE(scensession, nullptr); result = scensession->DestroyAndDisconnectSpecificSession(persistentId); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: CreateAndConnectSpecificSession02 * @tc.desc: CreateAndConnectSpecificSession * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, CreateAndConnectSpecificSession2, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "testSession1"; info.bundleName_ = "testSession3"; sptr session_; auto surfaceNode_ = CreateRSSurfaceNode(); sptr property_ = nullptr; int32_t persistentId = 0; sptr mockSessionStage = new (std::nothrow) SessionStageMocker(); EXPECT_NE(mockSessionStage, nullptr); sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback_, nullptr); int resultValue = 0; sptr scensession; sptr testWindowEventChannel = new (std::nothrow) TestWindowEventChannel(); EXPECT_NE(testWindowEventChannel, nullptr); scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); auto result = scensession->CreateAndConnectSpecificSession(mockSessionStage, testWindowEventChannel, surfaceNode_, property_, persistentId, session_); ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); 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; }; scensession = new (std::nothrow) SceneSession(info, specificCallback_); EXPECT_NE(scensession, nullptr); } /** * @tc.name: OnSessionEvent01 * @tc.desc: OnSessionEvent * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, OnSessionEvent01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "testSession1"; info.bundleName_ = "testSession3"; sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); auto result = scensession->OnSessionEvent(SessionEvent::EVENT_MINIMIZE); ASSERT_EQ(result, WSError::WS_OK); sptr scensessionchangeCallBack = new (std::nothrow) SceneSession::SessionChangeCallback(); EXPECT_NE(scensessionchangeCallBack, nullptr); scensession->RegisterSessionChangeCallback(scensessionchangeCallBack); result = scensession->OnSessionEvent(SessionEvent::EVENT_MINIMIZE); ASSERT_EQ(result, WSError::WS_OK); int resultValue = 0; NotifySessionEventFunc onSessionEvent_ = [&resultValue](int32_t eventId) { resultValue = 1; }; scensessionchangeCallBack->OnSessionEvent_ = onSessionEvent_; result = scensession->OnSessionEvent(SessionEvent::EVENT_MINIMIZE); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: ConsumeMoveEvent01 * @tc.desc: ConsumeMoveEvent, abnormal scene * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, ConsumeMoveEvent01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "testSession1"; info.bundleName_ = "testSession3"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); ASSERT_TRUE(sceneSession->moveDragController_); sceneSession->moveDragController_->InitMoveDragProperty(); WSRect originalRect = { 100, 100, 1000, 1000 }; std::shared_ptr pointerEvent = nullptr; auto result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect); ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); pointerEvent = MMI::PointerEvent::Create(); ASSERT_TRUE(pointerEvent); pointerEvent->SetPointerId(1); sceneSession->moveDragController_->moveDragProperty_.pointerId_ = 0; result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect); ASSERT_EQ(result, WSError::WS_DO_NOTHING); pointerEvent->SetPointerId(0); pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE); pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_RIGHT); result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect); ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); } /** * @tc.name: ConsumeMoveEvent02 * @tc.desc: ConsumeMoveEvent, normal secne * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, ConsumeMoveEvent02, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "testSession1"; info.bundleName_ = "testSession3"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); ASSERT_TRUE(sceneSession->moveDragController_); sceneSession->moveDragController_->InitMoveDragProperty(); WSRect originalRect = { 100, 100, 1000, 1000 }; std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); ASSERT_TRUE(pointerEvent); pointerEvent->SetAgentWindowId(1); pointerEvent->SetPointerId(0); pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN); MMI::PointerEvent::PointerItem pointerItem; pointerItem.SetPointerId(0); pointerEvent->AddPointerItem(pointerItem); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE); pointerItem.SetDisplayX(115); pointerItem.SetDisplayY(500); pointerItem.SetWindowX(15); pointerItem.SetWindowY(400); auto result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect); ASSERT_EQ(result, WSError::WS_OK); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE); pointerItem.SetDisplayX(145); pointerItem.SetDisplayY(550); result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect); ASSERT_EQ(result, WSError::WS_OK); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE); pointerItem.SetDisplayX(175); pointerItem.SetDisplayY(600); result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect); ASSERT_EQ(result, WSError::WS_OK); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP); pointerItem.SetDisplayX(205); pointerItem.SetDisplayY(650); result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: ConsumeDragEvent01 * @tc.desc: ConsumeDragEvent, abnormal scene * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, ConsumeDragEvent01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "testSession1"; info.bundleName_ = "testSession3"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); ASSERT_TRUE(sceneSession->moveDragController_); sceneSession->moveDragController_->InitMoveDragProperty(); WSRect originalRect = { 100, 100, 1000, 1000 }; SystemSessionConfig sessionConfig; std::shared_ptr pointerEvent = nullptr; sptr property = nullptr; auto result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, false); pointerEvent = MMI::PointerEvent::Create(); ASSERT_TRUE(pointerEvent); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP); property = new WindowSessionProperty(); sceneSession->moveDragController_->isStartDrag_ = false; result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, false); pointerEvent->SetPointerId(1); sceneSession->moveDragController_->moveDragProperty_.pointerId_ = 0; sceneSession->moveDragController_->isStartDrag_ = true; result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, false); pointerEvent->SetPointerId(0); result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, false); } /** * @tc.name: ConsumeDragEvent02 * @tc.desc: ConsumeDragEvent, normal scene * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, ConsumeDragEvent02, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "testSession1"; info.bundleName_ = "testSession3"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); ASSERT_TRUE(sceneSession->moveDragController_); sceneSession->moveDragController_->InitMoveDragProperty(); WSRect originalRect = { 100, 100, 1000, 1000 }; sptr property = new WindowSessionProperty(); property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); SystemSessionConfig sessionConfig; sessionConfig.isSystemDecorEnable_ = true; sessionConfig.decorModeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL; std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); ASSERT_TRUE(pointerEvent); pointerEvent->SetAgentWindowId(1); pointerEvent->SetPointerId(0); pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN); MMI::PointerEvent::PointerItem pointerItem; pointerItem.SetPointerId(0); pointerEvent->AddPointerItem(pointerItem); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN); pointerItem.SetDisplayX(100); pointerItem.SetDisplayY(100); pointerItem.SetWindowX(0); pointerItem.SetWindowY(0); auto result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, true); sceneSession->moveDragController_->aspectRatio_ = 0.0f; pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE); pointerItem.SetDisplayX(150); pointerItem.SetDisplayY(150); result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, true); sceneSession->moveDragController_->aspectRatio_ = 1.0f; pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE); pointerItem.SetDisplayX(200); pointerItem.SetDisplayY(200); result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, true); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP); pointerItem.SetDisplayX(250); pointerItem.SetDisplayY(250); result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, true); } /** * @tc.name: ConsumeDragEvent03 * @tc.desc: ConsumeDragEvent, normal scene * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, ConsumeDragEvent03, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "testSession1"; info.bundleName_ = "testSession3"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); ASSERT_TRUE(sceneSession->moveDragController_); sceneSession->moveDragController_->InitMoveDragProperty(); WSRect originalRect = { 100, 100, 1000, 1000 }; sptr property = new WindowSessionProperty(); property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); SystemSessionConfig sessionConfig; sessionConfig.isSystemDecorEnable_ = true; sessionConfig.decorModeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL; std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); ASSERT_TRUE(pointerEvent); pointerEvent->SetAgentWindowId(1); pointerEvent->SetPointerId(0); pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN); MMI::PointerEvent::PointerItem pointerItem; pointerItem.SetPointerId(0); pointerEvent->AddPointerItem(pointerItem); // LEFT_TOP pointerItem.SetWindowX(0); pointerItem.SetWindowY(0); auto result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, true); // RIGHT_TOP pointerItem.SetWindowX(1000); pointerItem.SetWindowY(0); result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, true); // RIGHT_BOTTOM pointerItem.SetWindowX(1000); pointerItem.SetWindowY(1000); result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, true); // LEFT_BOTTOM pointerItem.SetWindowX(0); pointerItem.SetWindowY(1000); result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, true); } /** * @tc.name: ConsumeDragEvent04 * @tc.desc: ConsumeDragEvent, normal scene * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, ConsumeDragEvent04, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "testSession1"; info.bundleName_ = "testSession3"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); ASSERT_TRUE(sceneSession->moveDragController_); sceneSession->moveDragController_->InitMoveDragProperty(); WSRect originalRect = { 100, 100, 1000, 1000 }; sptr property = new WindowSessionProperty(); property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); SystemSessionConfig sessionConfig; sessionConfig.isSystemDecorEnable_ = true; sessionConfig.decorModeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL; std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); ASSERT_TRUE(pointerEvent); pointerEvent->SetAgentWindowId(1); pointerEvent->SetPointerId(0); pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN); MMI::PointerEvent::PointerItem pointerItem; pointerItem.SetPointerId(0); pointerEvent->AddPointerItem(pointerItem); // LEFT pointerItem.SetWindowX(0); pointerItem.SetWindowY(500); auto result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, true); // TOP pointerItem.SetWindowX(500); pointerItem.SetWindowY(0); result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, true); // RIGHT pointerItem.SetWindowX(1000); pointerItem.SetWindowY(500); result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, true); // BOTTOM pointerItem.SetWindowX(500); pointerItem.SetWindowY(1000); result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig); ASSERT_EQ(result, true); } /** * @tc.name: SetAspectRatio01 * @tc.desc: SetAspectRatio * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, SetAspectRatio01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "testSession1"; info.bundleName_ = "testSession3"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); ASSERT_TRUE(sceneSession->moveDragController_); SystemSessionConfig sessionConfig; sessionConfig.isSystemDecorEnable_ = true; sessionConfig.decorModeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL; sceneSession->systemConfig_ = sessionConfig; sptr property = new WindowSessionProperty(); property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); WindowLimits windowLimits = WindowLimits(1500, 1500, 500, 500, 3.0f, 0.3333f); property->SetWindowLimits(windowLimits); sceneSession->property_ = property; float ratio = 4.0f; auto result = sceneSession->SetAspectRatio(ratio); if (result == WSError::WS_ERROR_INVALID_PARAM) { ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM); } ratio = 0.2f; result = sceneSession->SetAspectRatio(ratio); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM); ratio = 1.5f; result = sceneSession->SetAspectRatio(ratio); ASSERT_EQ(result, WSError::WS_OK); sessionConfig.isSystemDecorEnable_ = false; sceneSession->systemConfig_ = sessionConfig; ratio = 4.0f; result = sceneSession->SetAspectRatio(ratio); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM); ratio = 0.2f; result = sceneSession->SetAspectRatio(ratio); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM); ratio = 1.5f; result = sceneSession->SetAspectRatio(ratio); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: GetWindowId01 * @tc.desc: GetWindowId, normal scene * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, GetWindowId, Function | SmallTest | Level2) { ASSERT_NE(session_, nullptr); ASSERT_EQ(0, session_->GetWindowId()); } /** * @tc.name: GetVisible01 * @tc.desc: GetVisible, normal scene * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, GetVisible, Function | SmallTest | Level2) { ASSERT_NE(session_, nullptr); ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->SetVisible(false)); session_->state_ = SessionState::STATE_CONNECT; if (!session_->GetVisible()) { ASSERT_EQ(false, session_->GetVisible()); } } /** * @tc.name: IsActive01 * @tc.desc: IsActive, normal scene * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, IsActive, Function | SmallTest | Level2) { ASSERT_NE(session_, nullptr); session_->isActive_ = false; if (!session_->IsActive()) { ASSERT_EQ(false, session_->IsActive()); } } /** * @tc.name: SetFocusable01 * @tc.desc: SetFocusable, normal scene * @tc.type: FUNC */ HWTEST_F(WindowSessionTest, SetFocusable, Function | SmallTest | Level2) { ASSERT_NE(session_, nullptr); session_->state_ = SessionState::STATE_DISCONNECT; ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->SetFocusable(false)); } } } // namespace Rosen } // namespace OHOS