/* * 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 #include "ability_context_impl.h" #include "display_info.h" #include "mock_ability_context_impl.h" #include "mock_session.h" #include "mock_uicontent.h" #include "mock_window_adapter.h" #include "parameters.h" #include "singleton_mocker.h" #include "window_scene_session_impl.h" #include "window_session_impl.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace Rosen { const std::string WATERFALL_WINDOW_EVENT = "scb_waterfall_window_event"; using Mocker = SingletonMocker; class WindowSceneSessionImplTest4 : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); void SetUp() override; void TearDown() override; std::shared_ptr abilityContext_; std::unique_ptr mocker_ = std::make_unique(); private: RSSurfaceNode::SharedPtr CreateRSSurfaceNode(); static constexpr uint32_t WAIT_SYNC_IN_NS = 200000; static constexpr uint32_t WAIT_SERVERAL_FRAMES = 36000; }; void WindowSceneSessionImplTest4::SetUpTestCase() {} void WindowSceneSessionImplTest4::TearDownTestCase() {} void WindowSceneSessionImplTest4::SetUp() { abilityContext_ = std::make_shared(); } void WindowSceneSessionImplTest4::TearDown() { usleep(WAIT_SYNC_IN_NS); abilityContext_ = nullptr; } RSSurfaceNode::SharedPtr WindowSceneSessionImplTest4::CreateRSSurfaceNode() { struct RSSurfaceNodeConfig rsSurfaceNodeConfig; rsSurfaceNodeConfig.SurfaceNodeName = "startingWindowTestSurfaceNode"; auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig, RSSurfaceNodeType::DEFAULT); return surfaceNode; } namespace { /** * @tc.name: UpdateSurfaceNodeAfterCustomAnimation * @tc.desc: UpdateSurfaceNodeAfterCustomAnimation * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, UpdateSurfaceNodeAfterCustomAnimation, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("UpdateSurfaceNodeAfterCustomAnimation"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); windowSceneSessionImpl->hostSession_ = nullptr; auto ret = windowSceneSessionImpl->UpdateSurfaceNodeAfterCustomAnimation(true); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN; windowSceneSessionImpl->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_END); ret = windowSceneSessionImpl->UpdateSurfaceNodeAfterCustomAnimation(true); EXPECT_EQ(WMError::WM_ERROR_INVALID_OPERATION, ret); windowSceneSessionImpl->property_->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE); ret = windowSceneSessionImpl->UpdateSurfaceNodeAfterCustomAnimation(true); EXPECT_EQ(WMError::WM_OK, ret); } /** * @tc.name: ConsumePointerEvent * @tc.desc: ConsumePointerEvent * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, ConsumePointerEvent, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("ConsumePointerEvent"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->hostSession_ = session; std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); windowSceneSessionImpl->ConsumePointerEvent(pointerEvent); windowSceneSessionImpl->hostSession_ = nullptr; windowSceneSessionImpl->ConsumePointerEvent(pointerEvent); pointerEvent = nullptr; windowSceneSessionImpl->ConsumePointerEvent(pointerEvent); windowSceneSessionImpl->property_->SetTurnScreenOn(true); auto ret = windowSceneSessionImpl->IsTurnScreenOn(); EXPECT_EQ(true, ret); windowSceneSessionImpl->property_->SetTurnScreenOn(false); ret = windowSceneSessionImpl->IsTurnScreenOn(); EXPECT_EQ(false, ret); } /** * @tc.name: ConsumePointerEvent02 * @tc.desc: ConsumePointerEvent02 * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, ConsumePointerEvent02, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("ConsumePointerEvent"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"}; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->hostSession_ = session; windowSceneSessionImpl->uiContent_ = std::make_unique(); int32_t pointerId = 0; std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); pointerEvent->SetPointerId(pointerId); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN); pointerEvent->SetSourceType(1); MMI::PointerEvent::PointerItem pointerItem; pointerItem.SetPointerId(pointerId); pointerItem.SetOriginPointerId(pointerId); pointerEvent->AddPointerItem(pointerItem); windowSceneSessionImpl->property_->SetWindowDelayRaiseEnabled(false); EXPECT_EQ(false, windowSceneSessionImpl->property_->IsWindowDelayRaiseEnabled()); windowSceneSessionImpl->ConsumePointerEvent(pointerEvent); windowSceneSessionImpl->SetUniqueVirtualPixelRatio(true, 1.0f); Rect rect = {1, 1, 1, 1}; windowSceneSessionImpl->property_->SetWindowRect(rect); pointerItem.SetWindowX(1); pointerItem.SetWindowY(1); windowSceneSessionImpl->property_->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING); windowSceneSessionImpl->property_->SetWindowDelayRaiseEnabled(true); EXPECT_EQ(true, windowSceneSessionImpl->property_->IsWindowDelayRaiseEnabled()); windowSceneSessionImpl->ConsumePointerEvent(pointerEvent); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN); windowSceneSessionImpl->ConsumePointerEvent(pointerEvent); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_UP); windowSceneSessionImpl->ConsumePointerEvent(pointerEvent); AAFwk::Want want; windowSceneSessionImpl->uiContent_ = nullptr; windowSceneSessionImpl->OnNewWant(want); EXPECT_EQ(windowSceneSessionImpl->GetUIContentSharedPtr(), nullptr); windowSceneSessionImpl->ConsumePointerEvent(pointerEvent); } /** * @tc.name: GetSystemSizeLimits01 * @tc.desc: GetSystemSizeLimits * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, GetSystemSizeLimits01, TestSize.Level1) { uint32_t minMainWidth = 10; uint32_t minMainHeight = 20; uint32_t minSubWidth = 30; uint32_t minSubHeight = 40; uint32_t displayWidth = 100; uint32_t displayHeight = 100; float displayVpr = 1.0f; sptr option = sptr::MakeSptr(); option->SetWindowName("GetSystemSizeLimits01"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); windowSceneSessionImpl->windowSystemConfig_.miniWidthOfMainWindow_ = minMainWidth; windowSceneSessionImpl->windowSystemConfig_.miniHeightOfMainWindow_ = minMainHeight; windowSceneSessionImpl->windowSystemConfig_.miniWidthOfSubWindow_ = minSubWidth; windowSceneSessionImpl->windowSystemConfig_.miniHeightOfSubWindow_ = minSubHeight; windowSceneSessionImpl->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); WindowLimits limits = windowSceneSessionImpl->GetSystemSizeLimits(displayWidth, displayHeight, displayVpr); EXPECT_EQ(limits.minWidth_, minMainWidth); EXPECT_EQ(limits.minHeight_, minMainHeight); windowSceneSessionImpl->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); limits = windowSceneSessionImpl->GetSystemSizeLimits(displayWidth, displayHeight, displayVpr); EXPECT_EQ(limits.minWidth_, minSubWidth); EXPECT_EQ(limits.minHeight_, minSubHeight); windowSceneSessionImpl->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); limits = windowSceneSessionImpl->GetSystemSizeLimits(displayWidth, displayHeight, displayVpr); EXPECT_EQ(limits.minWidth_, static_cast(MIN_FLOATING_WIDTH * displayVpr)); EXPECT_EQ(limits.minHeight_, static_cast(MIN_FLOATING_HEIGHT * displayVpr)); } /** * @tc.name: HandlePointDownEvent * @tc.desc: HandlePointDownEvent * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, HandlePointDownEvent, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("HandlePointDownEvent"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); ASSERT_NE(nullptr, pointerEvent); pointerEvent->SetSourceType(1); MMI::PointerEvent::PointerItem pointerItem; float vpr = 1.0f; SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->hostSession_ = session; windowSceneSessionImpl->SetUniqueVirtualPixelRatio(true, vpr); windowSceneSessionImpl->property_->SetWindowType(WindowType::BELOW_APP_SYSTEM_WINDOW_BASE); windowSceneSessionImpl->property_->SetDragEnabled(false); windowSceneSessionImpl->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); windowSceneSessionImpl->property_->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING); auto ret = windowSceneSessionImpl->HandlePointDownEvent(pointerEvent, pointerItem); EXPECT_EQ(true, ret); windowSceneSessionImpl->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); windowSceneSessionImpl->property_->SetDragEnabled(false); ret = windowSceneSessionImpl->HandlePointDownEvent(pointerEvent, pointerItem); EXPECT_EQ(true, ret); windowSceneSessionImpl->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); ret = windowSceneSessionImpl->HandlePointDownEvent(pointerEvent, pointerItem); EXPECT_EQ(true, ret); pointerItem.SetWindowX(100); pointerItem.SetWindowY(100); Rect rect = {1, 1, 1, 1}; windowSceneSessionImpl->property_->SetWindowRect(rect); ret = windowSceneSessionImpl->HandlePointDownEvent(pointerEvent, pointerItem); EXPECT_EQ(true, ret); pointerItem.SetWindowX(1); ret = windowSceneSessionImpl->HandlePointDownEvent(pointerEvent, pointerItem); EXPECT_EQ(true, ret); windowSceneSessionImpl->property_->SetDragEnabled(true); ret = windowSceneSessionImpl->HandlePointDownEvent(pointerEvent, pointerItem); EXPECT_EQ(false, ret); pointerItem.SetWindowX(100); ret = windowSceneSessionImpl->HandlePointDownEvent(pointerEvent, pointerItem); EXPECT_EQ(true, ret); windowSceneSessionImpl->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION); pointerItem.SetDisplayX(100); pointerItem.SetDisplayY(100); ret = windowSceneSessionImpl->HandlePointDownEvent(pointerEvent, pointerItem); EXPECT_EQ(true, ret); } /** * @tc.name: UpdateWindowModeImmediately * @tc.desc: UpdateWindowModeImmediately * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, UpdateWindowModeImmediately, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("UpdateWindowModeImmediately"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); windowSceneSessionImpl->state_ = WindowState::STATE_CREATED; auto ret = windowSceneSessionImpl->UpdateWindowModeImmediately(WindowMode::WINDOW_MODE_FLOATING); EXPECT_EQ(WMError::WM_OK, ret); ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, windowSceneSessionImpl->property_->GetWindowMode()); windowSceneSessionImpl->state_ = WindowState::STATE_HIDDEN; ret = windowSceneSessionImpl->UpdateWindowModeImmediately(WindowMode::WINDOW_MODE_FLOATING); EXPECT_EQ(WMError::WM_OK, ret); ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, windowSceneSessionImpl->property_->GetWindowMode()); windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN; SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; ret = windowSceneSessionImpl->UpdateWindowModeImmediately(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); EXPECT_EQ(WMError::WM_OK, ret); ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, windowSceneSessionImpl->property_->GetWindowMode()); ret = windowSceneSessionImpl->UpdateWindowModeImmediately(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); EXPECT_EQ(WMError::WM_OK, ret); ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, windowSceneSessionImpl->property_->GetWindowMode()); windowSceneSessionImpl->state_ = WindowState::STATE_UNFROZEN; ret = windowSceneSessionImpl->UpdateWindowModeImmediately(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); EXPECT_EQ(WMError::WM_OK, ret); ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, windowSceneSessionImpl->property_->GetWindowMode()); } /** * @tc.name: AdjustWindowAnimationFlag * @tc.desc: AdjustWindowAnimationFlag * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, AdjustWindowAnimationFlag, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("AdjustWindowAnimationFlag"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN; windowSceneSessionImpl->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); windowSceneSessionImpl->animationTransitionController_ = sptr::MakeSptr(); windowSceneSessionImpl->AdjustWindowAnimationFlag(true); auto ret = windowSceneSessionImpl->property_->GetAnimationFlag(); EXPECT_EQ(3, ret); windowSceneSessionImpl->animationTransitionController_ = nullptr; windowSceneSessionImpl->AdjustWindowAnimationFlag(true); ret = windowSceneSessionImpl->property_->GetAnimationFlag(); EXPECT_EQ(1, ret); windowSceneSessionImpl->AdjustWindowAnimationFlag(false); ret = windowSceneSessionImpl->property_->GetAnimationFlag(); EXPECT_EQ(0, ret); windowSceneSessionImpl->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); windowSceneSessionImpl->AdjustWindowAnimationFlag(false); ret = windowSceneSessionImpl->property_->GetAnimationFlag(); EXPECT_EQ(1, ret); windowSceneSessionImpl->enableDefaultAnimation_ = false; windowSceneSessionImpl->AdjustWindowAnimationFlag(false); ret = windowSceneSessionImpl->property_->GetAnimationFlag(); EXPECT_EQ(0, ret); } /** * @tc.name: UpdateConfigurationForAll * @tc.desc: UpdateConfigurationForAll * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, UpdateConfigurationForAll, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("UpdateConfigurationForAll"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); std::shared_ptr configuration = std::make_shared(); sptr windowSession = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle1", "CreateTestModule1", "CreateTestAbility1" }; sptr session = sptr::MakeSptr(sessionInfo); windowSession->hostSession_ = session; windowSession->property_->SetPersistentId(1); windowSession->state_ = WindowState::STATE_SHOWN; ASSERT_EQ(WMError::WM_OK, windowSession->Create(abilityContext_, session)); windowSceneSessionImpl->UpdateConfigurationForAll(configuration); ASSERT_EQ(WMError::WM_OK, windowSession->Destroy(true)); } /** * @tc.name: SetWindowFlags * @tc.desc: SetWindowFlags * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, SetWindowFlags, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("SetWindowFlags"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN; windowSceneSessionImpl->SetWindowFlags(1); auto ret = windowSceneSessionImpl->SetWindowFlags(1); EXPECT_EQ(WMError::WM_OK, ret); ret = windowSceneSessionImpl->SetWindowFlags(2); EXPECT_EQ(WMError::WM_OK, ret); windowSceneSessionImpl->property_->SetWindowType(WindowType::WINDOW_TYPE_PIP); ret = windowSceneSessionImpl->NotifyPrepareClosePiPWindow(); EXPECT_EQ(WMError::WM_OK, ret); } /** * @tc.name: ResetSuperFoldDisplayY * @tc.desc: ResetSuperFoldDisplayY * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, ResetSuperFoldDisplayY, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("ResetSuperFoldDisplayY"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); windowSceneSessionImpl->superFoldOffsetY_ = 150; MMI::PointerEvent::PointerItem pointerItem; pointerItem.SetDisplayY(100); pointerEvent->AddPointerItem(pointerItem); int32_t originalDisplayY = pointerItem.GetDisplayY(); windowSceneSessionImpl->ResetSuperFoldDisplayY(pointerEvent); pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem); int32_t updatedDisplayY = pointerItem.GetDisplayY(); pointerItem.SetDisplayY(150); pointerEvent->AddPointerItem(pointerItem); originalDisplayY = pointerItem.GetDisplayY(); windowSceneSessionImpl->ResetSuperFoldDisplayY(pointerEvent); pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem); updatedDisplayY = pointerItem.GetDisplayY(); ASSERT_EQ(updatedDisplayY, originalDisplayY - 150); } /** * @tc.name: ResetSuperFoldDisplayY01 * @tc.desc: ResetSuperFoldDisplayY01 * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, ResetSuperFoldDisplayY01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("ResetSuperFoldDisplayY01"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); windowSceneSessionImpl->superFoldOffsetY_ = 150; MMI::PointerEvent::PointerItem pointerItem; pointerItem.SetDisplayYPos(100); pointerEvent->AddPointerItem(pointerItem); auto originalDisplayY = pointerItem.GetDisplayYPos(); windowSceneSessionImpl->ResetSuperFoldDisplayY(pointerEvent); pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem); auto updatedDisplayY = pointerItem.GetDisplayYPos(); ASSERT_EQ(updatedDisplayY, originalDisplayY); pointerItem.SetDisplayYPos(150); pointerEvent->AddPointerItem(pointerItem); originalDisplayY = pointerItem.GetDisplayYPos(); windowSceneSessionImpl->ResetSuperFoldDisplayY(pointerEvent); pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem); updatedDisplayY = pointerItem.GetDisplayYPos(); ASSERT_EQ(updatedDisplayY, originalDisplayY - 150); pointerItem.SetDisplayYPos(150.001); pointerEvent->AddPointerItem(pointerItem); originalDisplayY = pointerItem.GetDisplayYPos(); windowSceneSessionImpl->ResetSuperFoldDisplayY(pointerEvent); pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem); updatedDisplayY = pointerItem.GetDisplayYPos(); ASSERT_EQ(updatedDisplayY, originalDisplayY - 150); pointerItem.SetDisplayYPos(151.001); pointerEvent->AddPointerItem(pointerItem); originalDisplayY = pointerItem.GetDisplayYPos(); windowSceneSessionImpl->ResetSuperFoldDisplayY(pointerEvent); pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem); updatedDisplayY = pointerItem.GetDisplayYPos(); ASSERT_EQ(updatedDisplayY, originalDisplayY - 150); } /** * @tc.name: ConsumePointerEventInner * @tc.desc: ConsumePointerEventInner * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, ConsumePointerEventInner, TestSize.Level0) { sptr option = sptr::MakeSptr(); option->SetWindowName("ConsumePointerEventInner"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); ASSERT_NE(nullptr, pointerEvent); MMI::PointerEvent::PointerItem pointerItem; pointerEvent->SetPointerAction(10); windowSceneSessionImpl->ConsumePointerEventInner(pointerEvent, pointerItem); pointerEvent->SetPointerAction(4); windowSceneSessionImpl->ConsumePointerEventInner(pointerEvent, pointerItem); pointerEvent->SetPointerAction(2); windowSceneSessionImpl->ConsumePointerEventInner(pointerEvent, pointerItem); } /** * @tc.name: ConsumePointerEventInner02 * @tc.desc: ConsumePointerEventInner02 * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, ConsumePointerEventInner02, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("ConsumePointerEventInner"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"}; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->hostSession_ = session; windowSceneSessionImpl->property_->SetWindowDelayRaiseEnabled(true); windowSceneSessionImpl->property_->SetPersistentId(1); std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); ASSERT_NE(nullptr, pointerEvent); MMI::PointerEvent::PointerItem pointerItem; pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN); windowSceneSessionImpl->ConsumePointerEventInner(pointerEvent, pointerItem, true); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_UP); windowSceneSessionImpl->ConsumePointerEventInner(pointerEvent, pointerItem, true); } /** * @tc.name: HandleEventForCompatibleMode * @tc.desc: HandleEventForCompatibleMode * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, HandleEventForCompatibleMode, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("HandleEventForCompatibleMode"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); ASSERT_NE(nullptr, pointerEvent); MMI::PointerEvent::PointerItem pointerItem; pointerEvent->SetPointerAction(2); windowSceneSessionImpl->HandleEventForCompatibleMode(pointerEvent, pointerItem); pointerEvent->SetPointerAction(3); windowSceneSessionImpl->HandleEventForCompatibleMode(pointerEvent, pointerItem); pointerEvent->SetPointerAction(4); windowSceneSessionImpl->HandleEventForCompatibleMode(pointerEvent, pointerItem); } /** * @tc.name: HandleDownForCompatibleMode * @tc.desc: HandleDownForCompatibleMode * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, HandleDownForCompatibleMode, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("HandleDownForCompatibleMode"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); ASSERT_NE(nullptr, pointerEvent); MMI::PointerEvent::PointerItem pointerItem; pointerEvent->SetPointerAction(2); windowSceneSessionImpl->HandleDownForCompatibleMode(pointerEvent, pointerItem); } /** * @tc.name: HandleMoveForCompatibleMode * @tc.desc: HandleMoveForCompatibleMode * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, HandleMoveForCompatibleMode, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("HandleMoveForCompatibleMode"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); ASSERT_NE(nullptr, pointerEvent); MMI::PointerEvent::PointerItem pointerItem; pointerEvent->SetPointerAction(3); windowSceneSessionImpl->HandleMoveForCompatibleMode(pointerEvent, pointerItem); } /** * @tc.name: HandleUpForCompatibleMode * @tc.desc: HandleUpForCompatibleMode * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, HandleUpForCompatibleMode, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("HandleUpForCompatibleMode"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); ASSERT_NE(nullptr, pointerEvent); MMI::PointerEvent::PointerItem pointerItem; pointerEvent->SetPointerAction(4); windowSceneSessionImpl->HandleUpForCompatibleMode(pointerEvent, pointerItem); } /** * @tc.name: ConvertPointForCompatibleMode * @tc.desc: ConvertPointForCompatibleMode * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, ConvertPointForCompatibleMode, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("ConvertPointForCompatibleMode"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; int32_t transferX = 800; std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); ASSERT_NE(nullptr, pointerEvent); MMI::PointerEvent::PointerItem pointerItem; pointerEvent->SetPointerAction(2); windowSceneSessionImpl->ConvertPointForCompatibleMode(pointerEvent, pointerItem, transferX); pointerEvent->SetPointerAction(3); windowSceneSessionImpl->ConvertPointForCompatibleMode(pointerEvent, pointerItem, transferX); pointerEvent->SetPointerAction(4); windowSceneSessionImpl->ConvertPointForCompatibleMode(pointerEvent, pointerItem, transferX); } /** * @tc.name: IsInMappingRegionForCompatibleMode * @tc.desc: IsInMappingRegionForCompatibleMode * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, IsInMappingRegionForCompatibleMode, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("IsInMappingRegionForCompatibleMode"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; windowSceneSessionImpl->property_->SetWindowRect({ 880, 0, 800, 1600 }); int32_t displayX = 400; int32_t displayY = 400; bool ret = windowSceneSessionImpl->IsInMappingRegionForCompatibleMode(displayX, displayY); EXPECT_EQ(true, ret); displayX = 1000; displayY = 1000; ret = windowSceneSessionImpl->IsInMappingRegionForCompatibleMode(displayX, displayY); EXPECT_EQ(false, ret); } /** * @tc.name: CheckTouchSlop * @tc.desc: CheckTouchSlop * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, CheckTouchSlop, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("CheckTouchSlop"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; int32_t pointerId = 0; int32_t displayX = 400; int32_t displayY = 400; int32_t threshold = 50; bool ret = windowSceneSessionImpl->CheckTouchSlop(pointerId, displayX, displayY, threshold); EXPECT_EQ(false, ret); } /** * @tc.name: IgnoreClickEvent * @tc.desc: IgnoreClickEvent * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, IgnoreClickEvent, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("IgnoreClickEvent"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); ASSERT_NE(nullptr, pointerEvent); pointerEvent->SetPointerAction(3); windowSceneSessionImpl->IgnoreClickEvent(pointerEvent); pointerEvent->SetPointerAction(4); windowSceneSessionImpl->IgnoreClickEvent(pointerEvent); } /** * @tc.name: RegisterKeyboardPanelInfoChangeListener * @tc.desc: RegisterKeyboardPanelInfoChangeListener * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, RegisterKeyboardPanelInfoChangeListener, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("RegisterKeyboardPanelInfoChangeListener"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); windowSceneSessionImpl->keyboardPanelInfoChangeListeners_ = sptr::MakeSptr(); sptr listener = nullptr; auto ret = windowSceneSessionImpl->RegisterKeyboardPanelInfoChangeListener(listener); EXPECT_EQ(WMError::WM_ERROR_INVALID_OPERATION, ret); } /** * @tc.name: RegisterWindowAttachStateChangeListener * @tc.desc: RegisterWindowAttachStateChangeListener * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, RegisterWindowAttachStateChangeListener, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("RegisterKeyboardPanelInfoChangeListener"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); windowSceneSessionImpl->windowAttachStateChangeListener_ = sptr::MakeSptr(); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN; windowSceneSessionImpl->hostSession_ = session; // case1: listener is nullptr sptr listener = nullptr; auto ret = windowSceneSessionImpl->RegisterWindowAttachStateChangeListener(listener); EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); // case2: listener is not nullptr listener = sptr::MakeSptr(); ret = windowSceneSessionImpl->RegisterWindowAttachStateChangeListener(listener); EXPECT_EQ(WMError::WM_OK, ret); // case3: host session is nullptr windowSceneSessionImpl->hostSession_ = nullptr; ret = windowSceneSessionImpl->RegisterWindowAttachStateChangeListener(listener); EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); } /** * @tc.name: UnregisterWindowAttachStateChangeListener * @tc.desc: UnregisterWindowAttachStateChangeListener * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, UnregisterWindowAttachStateChangeListener, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("UnregisterWindowAttachStateChangeListener"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); windowSceneSessionImpl->windowAttachStateChangeListener_ = sptr::MakeSptr(); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN; windowSceneSessionImpl->hostSession_ = session; // case1: register listener sptr listener = sptr::MakeSptr(); auto ret = windowSceneSessionImpl->RegisterWindowAttachStateChangeListener(listener); EXPECT_EQ(WMError::WM_OK, ret); // case2: unregister success ret = windowSceneSessionImpl->UnregisterWindowAttachStateChangeListener(); EXPECT_EQ(WMError::WM_OK, ret); EXPECT_EQ(windowSceneSessionImpl->windowAttachStateChangeListener_, nullptr); // case3: host session is nullptr windowSceneSessionImpl->hostSession_ = nullptr; ret = windowSceneSessionImpl->UnregisterWindowAttachStateChangeListener(); EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); } /** * @tc.name: NotifyWindowAttachStateChange * @tc.desc: NotifyWindowAttachStateChange * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, NotifyWindowAttachStateChange, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("NotifyWindowAttachStateChange"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); windowSceneSessionImpl->windowAttachStateChangeListener_ = nullptr; SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN; windowSceneSessionImpl->hostSession_ = session; // case1: listener is nullptr auto ret = windowSceneSessionImpl->NotifyWindowAttachStateChange(true); EXPECT_EQ(WSError::WS_ERROR_NULLPTR, ret); ret = windowSceneSessionImpl->NotifyWindowAttachStateChange(false); EXPECT_EQ(WSError::WS_ERROR_NULLPTR, ret); // case2: listener is not nullptr, then attach is true sptr listener = sptr::MakeSptr(); auto ret2 = windowSceneSessionImpl->RegisterWindowAttachStateChangeListener(listener); EXPECT_EQ(WMError::WM_OK, ret2); ret = windowSceneSessionImpl->NotifyWindowAttachStateChange(true); EXPECT_EQ(WSError::WS_OK, ret); ret = windowSceneSessionImpl->NotifyWindowAttachStateChange(true); EXPECT_EQ(WSError::WS_OK, ret); // case3: listener is not nullptr, then attach is false ret = windowSceneSessionImpl->NotifyWindowAttachStateChange(false); EXPECT_EQ(WSError::WS_OK, ret); ret = windowSceneSessionImpl->NotifyWindowAttachStateChange(false); EXPECT_EQ(WSError::WS_OK, ret); } /** * @tc.name: GetSystemBarPropertyByType * @tc.desc: GetSystemBarPropertyByType * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, GetSystemBarPropertyByType, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetSystemBarPropertyByType"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SystemBarProperty prop; prop.settingFlag_ = SystemBarSettingFlag::COLOR_SETTING; windowSceneSessionImpl->property_->SetPersistentId(1); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN; windowSceneSessionImpl->hostSession_ = session; ASSERT_EQ(WMError::WM_OK, windowSceneSessionImpl->SetSpecificBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, prop)); auto prop2 = windowSceneSessionImpl->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR); ASSERT_EQ(prop2, prop); } /** * @tc.name: SetSpecificBarProperty * @tc.desc: SetSpecificBarProperty * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, SetSpecificBarProperty, TestSize.Level0) { sptr option = sptr::MakeSptr(); option->SetWindowName("SetSpecificBarProperty"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->hostSession_ = session; SystemBarProperty property; windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->state_ = WindowState::STATE_INITIAL; auto type = WindowType::WINDOW_TYPE_STATUS_BAR; auto ret = windowSceneSessionImpl->SetSpecificBarProperty(type, property); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret); windowSceneSessionImpl->state_ = WindowState::STATE_BOTTOM; ret = windowSceneSessionImpl->SetSpecificBarProperty(type, property); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret); windowSceneSessionImpl->state_ = WindowState::STATE_CREATED; ret = windowSceneSessionImpl->SetSpecificBarProperty(type, property); EXPECT_EQ(WMError::WM_OK, ret); property = SystemBarProperty(); property.settingFlag_ = SystemBarSettingFlag::DEFAULT_SETTING; ret = windowSceneSessionImpl->SetSpecificBarProperty(type, property); EXPECT_EQ(WMError::WM_OK, ret); property.settingFlag_ = SystemBarSettingFlag::COLOR_SETTING; ret = windowSceneSessionImpl->SetSpecificBarProperty(type, property); EXPECT_EQ(WMError::WM_OK, ret); } /** * @tc.name: SetSystemBarPropertyForPage * @tc.desc: SetSystemBarPropertyForPage * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, SetSystemBarPropertyForPage, Function | SmallTest | Level2) { sptr option = sptr::MakeSptr(); option->SetWindowName("SetSystemBarPropertyForPage"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->hostSession_ = session; sptr property = sptr::MakeSptr(); property->SetPersistentId(1); windowSceneSessionImpl->property_ = property; std::optional prop; windowSceneSessionImpl->state_ = WindowState::STATE_DESTROYED; auto ret = windowSceneSessionImpl->SetSystemBarPropertyForPage(WindowType::WINDOW_TYPE_STATUS_BAR, prop); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret); windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN; windowSceneSessionImpl->SetWindowType(WindowType::SYSTEM_WINDOW_BASE); ret = windowSceneSessionImpl->SetSystemBarPropertyForPage(WindowType::WINDOW_TYPE_STATUS_BAR, prop); EXPECT_EQ(WMError::WM_DO_NOTHING, ret); windowSceneSessionImpl->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); ret = windowSceneSessionImpl->SetSystemBarPropertyForPage(WindowType::WINDOW_TYPE_STATUS_BAR, prop); EXPECT_EQ(WMError::WM_OK, ret); } /** * @tc.name: GetSystemBarPropertyForPage * @tc.desc: GetSystemBarPropertyForPage * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, GetSystemBarPropertyForPage, Function | SmallTest | Level2) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetSystemBarPropertyForPage"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->hostSession_ = session; sptr property = sptr::MakeSptr(); property->SetPersistentId(1); windowSceneSessionImpl->property_ = property; std::map properties; std::map pageProperties; windowSceneSessionImpl->GetSystemBarPropertyForPage(properties, pageProperties); EXPECT_EQ(pageProperties[WindowType::WINDOW_TYPE_STATUS_BAR], windowSceneSessionImpl->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR)); EXPECT_EQ(pageProperties[WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR], windowSceneSessionImpl->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR)); } /** * @tc.name: NotifyDialogStateChange * @tc.desc: NotifyDialogStateChange * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, NotifyDialogStateChange, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("NotifyDialogStateChange"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSceneSessionImpl->property_->SetPersistentId(1); windowSceneSessionImpl->hostSession_ = session; windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN; auto ret = windowSceneSessionImpl->NotifyDialogStateChange(true); EXPECT_EQ(WSError::WS_OK, ret); ret = windowSceneSessionImpl->NotifyDialogStateChange(false); EXPECT_EQ(WSError::WS_OK, ret); ret = windowSceneSessionImpl->NotifyDialogStateChange(false); EXPECT_EQ(WSError::WS_OK, ret); ret = windowSceneSessionImpl->NotifyDialogStateChange(true); EXPECT_EQ(WSError::WS_OK, ret); windowSceneSessionImpl->property_->SetPersistentId(0); windowSceneSessionImpl->hostSession_ = nullptr; windowSceneSessionImpl->state_ = WindowState::STATE_DESTROYED; ret = windowSceneSessionImpl->NotifyDialogStateChange(true); EXPECT_EQ(WSError::WS_ERROR_INVALID_WINDOW, ret); } /** * @tc.name: GetWindowStatus01 * @tc.desc: GetWindowStatus * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, GetWindowStatus01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetWindowStatus01"); sptr window = sptr::MakeSptr(option); WindowStatus windowStatus; ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->GetWindowStatus(windowStatus)); ASSERT_EQ(WindowStatus::WINDOW_STATUS_UNDEFINED, windowStatus); window->property_->SetPersistentId(1); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; ASSERT_EQ(WMError::WM_OK, window->GetWindowStatus(windowStatus)); ASSERT_EQ(WindowStatus::WINDOW_STATUS_UNDEFINED, windowStatus); } /** * @tc.name: GetWindowStatus02 * @tc.desc: GetWindowStatus * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, GetWindowStatus02, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetWindowStatus02"); option->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); sptr window = sptr::MakeSptr(option); window->property_->SetPersistentId(1); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; WindowStatus windowStatus; ASSERT_EQ(WMError::WM_OK, window->GetWindowStatus(windowStatus)); ASSERT_EQ(WindowStatus::WINDOW_STATUS_SPLITSCREEN, windowStatus); } /** * @tc.name: GetWindowStatus03 * @tc.desc: GetWindowStatus * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, GetWindowStatus03, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetWindowStatus03"); option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); option->SetDisplayId(0); option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sptr window = sptr::MakeSptr(option); window->property_->SetPersistentId(1); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; WindowStatus windowStatus; ASSERT_EQ(WMError::WM_OK, window->GetWindowStatus(windowStatus)); ASSERT_EQ(WindowStatus::WINDOW_STATUS_FLOATING, windowStatus); window->property_->SetMaximizeMode(MaximizeMode::MODE_AVOID_SYSTEM_BAR); ASSERT_EQ(WMError::WM_OK, window->GetWindowStatus(windowStatus)); ASSERT_EQ(WindowStatus::WINDOW_STATUS_MAXIMIZE, windowStatus); window->state_ = WindowState::STATE_HIDDEN; ASSERT_EQ(WMError::WM_OK, window->GetWindowStatus(windowStatus)); ASSERT_EQ(WindowStatus::WINDOW_STATUS_MINIMIZE, windowStatus); window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); window->state_ = WindowState::STATE_SHOWN; ASSERT_EQ(WMError::WM_OK, window->GetWindowStatus(windowStatus)); ASSERT_EQ(WindowStatus::WINDOW_STATUS_FULLSCREEN, windowStatus); } /** * @tc.name: SetWindowTitle * @tc.desc: SetWindowTitle Test * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, SetWindowTitle, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("SetWindowTitle"); option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); option->SetDisplayId(0); option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); sptr window = sptr::MakeSptr(option); std::string title = "SetWindowTitle"; EXPECT_EQ(window->SetWindowTitle(title), WMError::WM_ERROR_INVALID_WINDOW); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; window->property_->SetPersistentId(1); window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; EXPECT_EQ(window->SetWindowTitle(title), WMError::WM_ERROR_DEVICE_NOT_SUPPORT); window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; window->windowSystemConfig_.freeMultiWindowSupport_ = false; window->windowSystemConfig_.isSystemDecorEnable_ = false; EXPECT_EQ(window->SetWindowTitle(title), WMError::WM_ERROR_INVALID_WINDOW); window->windowSystemConfig_.freeMultiWindowSupport_ = true; window->windowSystemConfig_.isSystemDecorEnable_ = true; window->property_->SetDecorEnable(true); EXPECT_EQ(window->SetWindowTitle(title), WMError::WM_ERROR_NULLPTR); window->uiContent_ = std::make_unique(); EXPECT_EQ(window->SetWindowTitle(title), WMError::WM_OK); window->property_->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); EXPECT_EQ(window->SetWindowTitle(title), WMError::WM_ERROR_INVALID_WINDOW); window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); EXPECT_EQ(window->SetWindowTitle(title), WMError::WM_ERROR_NULLPTR); EXPECT_EQ(window->Create(abilityContext_, session), WMError::WM_OK); EXPECT_EQ(window->SetWindowTitle(title), WMError::WM_OK); window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW; window->property_->SetPcAppInpadCompatibleMode(true); window->windowSystemConfig_.freeMultiWindowEnable_ = false; window->windowSystemConfig_.isSystemDecorEnable_ = false; EXPECT_EQ(WMError::WM_OK, window->SetWindowTitle(title)); const std::string feature = "large_screen"; std::string deviceType = OHOS::system::GetParameter("const.product.devicetype", ""); auto context = std::make_shared(); window->context_ = context; context->hapModuleInfo_ = std::make_shared(); context->hapModuleInfo_->requiredDeviceFeatures = {{deviceType, {feature}}}; EXPECT_EQ(WMError::WM_OK, window->SetWindowTitle(title)); EXPECT_EQ(WMError::WM_OK, window->Destroy(true)); } /** * @tc.name: AddSubWindowMapForExtensionWindow * @tc.desc: AddSubWindowMapForExtensionWindow Test * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, AddSubWindowMapForExtensionWindow, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("AddSubWindowMapForExtensionWindow"); option->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; window->property_->SetPersistentId(1); window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; WindowSceneSessionImpl::subWindowSessionMap_.clear(); window->AddSubWindowMapForExtensionWindow(); EXPECT_EQ(WindowSceneSessionImpl::subWindowSessionMap_.size(), 0); window->context_ = abilityContext_; sptr windowSession = sptr::MakeSptr(option); windowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION); windowSession->context_ = abilityContext_; windowSession->property_->SetPersistentId(2); WindowSessionImpl::GetWindowExtensionSessionSet().insert(windowSession); window->AddSubWindowMapForExtensionWindow(); EXPECT_EQ(WindowSceneSessionImpl::subWindowSessionMap_.size(), 1); EXPECT_EQ(WMError::WM_OK, window->Destroy(true)); } /** * @tc.name: IsPcOrFreeMultiWindowCapabilityEnabled * @tc.desc: IsPcOrFreeMultiWindowCapabilityEnabled Test * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, IsPcOrFreeMultiWindowCapabilityEnabled, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("IsPcOrFreeMultiWindowCapabilityEnabled"); option->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; window->property_->SetPersistentId(1); window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; EXPECT_EQ(true, window->IsPcOrFreeMultiWindowCapabilityEnabled()); window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; EXPECT_EQ(false, window->IsPcOrFreeMultiWindowCapabilityEnabled()); window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW; EXPECT_EQ(false, window->IsPcOrFreeMultiWindowCapabilityEnabled()); window->property_->SetIsUIExtFirstSubWindow(true); window->windowSystemConfig_.freeMultiWindowEnable_ = true; window->windowSystemConfig_.freeMultiWindowSupport_ = true; EXPECT_EQ(true, window->IsPcOrFreeMultiWindowCapabilityEnabled()); EXPECT_EQ(WMError::WM_OK, window->Destroy(true)); } /** * @tc.name: GetParentSessionAndVerify * @tc.desc: GetParentSessionAndVerify Test * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, GetParentSessionAndVerify, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetParentSessionAndVerify"); option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; window->property_->SetPersistentId(1); window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; sptr parentSession = nullptr; auto res = window->GetParentSessionAndVerify(false, parentSession); EXPECT_EQ(WMError::WM_ERROR_NULLPTR, res); res = window->GetParentSessionAndVerify(true, parentSession); EXPECT_EQ(WMError::WM_ERROR_NULLPTR, res); sptr subOption = sptr::MakeSptr(); subOption->SetWindowName("GetParentSessionAndVerify2"); subOption->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); sptr subWindow = sptr::MakeSptr(subOption); SessionInfo subSessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr subSession = sptr::MakeSptr(subSessionInfo); subWindow->hostSession_ = subSession; subWindow->property_->SetPersistentId(2); subWindow->property_->SetParentId(1); subWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; std::vector> vec; WindowSceneSessionImpl::subWindowSessionMap_.insert( std::pair>>(1, vec)); WindowSceneSessionImpl::subWindowSessionMap_[1].push_back(subWindow); res = subWindow->GetParentSessionAndVerify(false, parentSession); EXPECT_EQ(WMError::WM_ERROR_NULLPTR, res); WindowSceneSessionImpl::windowSessionMap_.insert(std::make_pair( window->GetWindowName(), std::pair>(window->GetWindowId(), window))); res = subWindow->GetParentSessionAndVerify(false, parentSession); EXPECT_EQ(WMError::WM_OK, res); EXPECT_EQ(WMError::WM_OK, subWindow->Destroy(true)); EXPECT_EQ(WMError::WM_OK, window->Destroy(true)); } /** * @tc.name: GetParentSessionAndVerify01 * @tc.desc: GetParentSessionAndVerify Test * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, GetParentSessionAndVerify01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetParentSessionAndVerify01"); option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; window->property_->SetPersistentId(1); window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; WindowSceneSessionImpl::windowSessionMap_.clear(); WindowSceneSessionImpl::windowSessionMap_.insert(std::make_pair(window->GetWindowName(), std::pair>(window->GetWindowId(), window))); sptr subOption = sptr::MakeSptr(); subOption->SetWindowName("GetParentSessionAndVerify01_subWindow"); subOption->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); sptr subWindow = sptr::MakeSptr(subOption); SessionInfo subSessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr subSession = sptr::MakeSptr(subSessionInfo); subWindow->hostSession_ = subSession; subWindow->property_->SetPersistentId(2); subWindow->property_->SetParentId(1); subWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; subWindow->property_->SetIsUIExtFirstSubWindow(true); sptr parentSession = nullptr; auto res = subWindow->GetParentSessionAndVerify(false, parentSession); EXPECT_EQ(WMError::WM_OK, res); subWindow->property_->SetIsUIExtFirstSubWindow(false); res = subWindow->GetParentSessionAndVerify(false, parentSession); EXPECT_EQ(WMError::WM_OK, res); window->property_->SetSubWindowLevel(2); res = subWindow->GetParentSessionAndVerify(false, parentSession); EXPECT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, res); EXPECT_NE(nullptr, parentSession); EXPECT_EQ(WMError::WM_OK, subWindow->Destroy(true)); EXPECT_EQ(WMError::WM_OK, window->Destroy(true)); } /** * @tc.name: MainWindowCloseInner * @tc.desc: MainWindowCloseInner Test * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, MainWindowCloseInner, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("MainWindowCloseInner"); option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; window->property_->SetPersistentId(1); window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; EXPECT_EQ(WMError::WM_OK, window->MainWindowCloseInner()); } /** * @tc.name: SetWindowMode01 * @tc.desc: SetWindowMode * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, SetWindowMode01, TestSize.Level1) { sptr subOption = sptr::MakeSptr(); subOption->SetWindowName("SetWindowMode01"); subOption->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); sptr subWindow = sptr::MakeSptr(subOption); subWindow->property_->SetPersistentId(1007); SessionInfo subSessionInfo = { "CreateSubTestBundle", "CreateSubTestModule", "CreateSubTestAbility" }; sptr subSession = sptr::MakeSptr(subSessionInfo); subWindow->hostSession_ = subSession; subWindow->property_->SetWindowModeSupportType(0); auto ret = subWindow->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE, ret); } /** * @tc.name: SetWindowMode02 * @tc.desc: SetWindowMode * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, SetWindowMode02, TestSize.Level1) { sptr subOption = sptr::MakeSptr(); subOption->SetWindowName("SetWindowMode02"); subOption->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); sptr subWindow = sptr::MakeSptr(subOption); subWindow->property_->SetPersistentId(1007); SessionInfo subSessionInfo = { "CreateSubTestBundle", "CreateSubTestModule", "CreateSubTestAbility" }; sptr subSession = sptr::MakeSptr(subSessionInfo); subWindow->hostSession_ = subSession; subWindow->property_->SetWindowModeSupportType(1); auto ret = subWindow->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); EXPECT_EQ(WMError::WM_OK, ret); } /** * @tc.name: SetWindowMode03 * @tc.desc: SetWindowMode * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, SetWindowMode03, TestSize.Level1) { sptr subOption = sptr::MakeSptr(); subOption->SetWindowName("SetWindowMode03"); subOption->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); sptr subWindow = sptr::MakeSptr(subOption); subWindow->property_->SetPersistentId(0); SessionInfo subSessionInfo = {"CreateSubTestBundle", "CreateSubTestModule", "CreateSubTestAbility"}; sptr subSession = sptr::MakeSptr(subSessionInfo); subWindow->hostSession_ = subSession; subWindow->property_->SetWindowModeSupportType(1); auto ret = subWindow->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret); } /** * @tc.name: UpdateNewSize01 * @tc.desc: UpdateNewSize * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, UpdateNewSize01, TestSize.Level1) { sptr subOption = sptr::MakeSptr(); subOption->SetWindowName("UpdateNewSize01SubWindow"); sptr subWindow = sptr::MakeSptr(subOption); subWindow->property_->SetPersistentId(1003); SessionInfo subSessionInfo = { "CreateSubTestBundle", "CreateSubTestModule", "CreateSubTestAbility" }; sptr subSession = sptr::MakeSptr(subSessionInfo); subWindow->hostSession_ = subSession; subWindow->UpdateNewSize(); Rect windowRect = { 0, 0, 0, 0 }; WindowLimits windowLimits = { 0, 0, 0, 0, 0.0, 0, 0 }; subWindow->property_->SetRequestRect(windowRect); subWindow->property_->SetWindowRect(windowRect); subWindow->property_->SetWindowLimits(windowLimits); subWindow->UpdateNewSize(); windowRect.width_ = 10; windowRect.height_ = 10; subWindow->UpdateNewSize(); windowRect.width_ = 0; windowRect.height_ = 0; ASSERT_NE(nullptr, subWindow->property_); subWindow->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); subWindow->UpdateNewSize(); Rect windowRect1 = { 10, 10, 10, 10 }; WindowLimits windowLimits1 = { 100, 100, 100, 100, 0.0, 0, 0 }; subWindow->property_->SetRequestRect(windowRect1); subWindow->property_->SetWindowLimits(windowLimits1); subWindow->UpdateNewSize(); Rect windowRect2 = { 200, 200, 200, 200 }; subWindow->property_->SetRequestRect(windowRect2); subWindow->UpdateNewSize(); } /** * @tc.name: UpdateNewSize02 * @tc.desc: UpdateNewSize * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, UpdateNewSize02, TestSize.Level1) { sptr subOption = sptr::MakeSptr(); subOption->SetWindowName("UpdateNewSize01SubWindow"); sptr subWindow = sptr::MakeSptr(subOption); subWindow->property_->SetPersistentId(1003); SessionInfo subSessionInfo = { "CreateSubTestBundle", "CreateSubTestModule", "CreateSubTestAbility" }; sptr subSession = sptr::MakeSptr(subSessionInfo); subWindow->hostSession_ = subSession; subWindow->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); WindowLimits windowLimits = { 100, 100, 100, 100, 0.0, 0, 0 }; subWindow->property_->SetWindowLimits(windowLimits); Rect windowRect = { 200, 200, 200, 200 }; subWindow->property_->SetRequestRect(windowRect); subWindow->windowSystemConfig_.windowUIType_ = WindowUIType::INVALID_WINDOW; subWindow->windowSystemConfig_.freeMultiWindowEnable_ = false; subWindow->windowSystemConfig_.freeMultiWindowSupport_ = false; subWindow->UpdateNewSize(); subWindow->property_->SetRequestRect(windowRect); subWindow->windowSystemConfig_.freeMultiWindowSupport_ = true; subWindow->UpdateNewSize(); subWindow->property_->SetRequestRect(windowRect); subWindow->windowSystemConfig_.freeMultiWindowEnable_ = true; subWindow->windowSystemConfig_.freeMultiWindowSupport_ = false; subWindow->UpdateNewSize(); subWindow->property_->SetRequestRect(windowRect); subWindow->windowSystemConfig_.freeMultiWindowSupport_ = true; subWindow->UpdateNewSize(); subWindow->property_->SetRequestRect(windowRect); subWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; subWindow->windowSystemConfig_.freeMultiWindowEnable_ = false; subWindow->windowSystemConfig_.freeMultiWindowSupport_ = false; subWindow->UpdateNewSize(); subWindow->property_->SetRequestRect(windowRect); subWindow->windowSystemConfig_.freeMultiWindowSupport_ = true; subWindow->UpdateNewSize(); subWindow->property_->SetRequestRect(windowRect); subWindow->windowSystemConfig_.freeMultiWindowEnable_ = true; subWindow->windowSystemConfig_.freeMultiWindowSupport_ = false; subWindow->UpdateNewSize(); subWindow->property_->SetRequestRect(windowRect); subWindow->windowSystemConfig_.freeMultiWindowSupport_ = false; subWindow->UpdateNewSize(); ASSERT_NE(nullptr, subWindow->property_); } /** * @tc.name: UpdateSubWindowStateAndNotify01 * @tc.desc: UpdateSubWindowStateAndNotify * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, UpdateSubWindowStateAndNotify01, TestSize.Level1) { sptr subOption = sptr::MakeSptr(); subOption->SetWindowName("UpdateSubWindowStateAndNotify01"); subOption->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); sptr subWindow = sptr::MakeSptr(subOption); subWindow->property_->SetPersistentId(1005); SessionInfo subSessionInfo = { "CreateSubTestBundle", "CreateSubTestModule", "CreateSubTestAbility" }; sptr subSession = sptr::MakeSptr(subSessionInfo); subWindow->hostSession_ = subSession; sptr option = sptr::MakeSptr(); option->SetWindowName("UpdateSubWindowStateAndNotify02"); option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); sptr window = sptr::MakeSptr(option); window->property_->SetPersistentId(1006); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; std::vector> vec; WindowSceneSessionImpl::subWindowSessionMap_.insert( std::pair>>(1006, vec)); subWindow->UpdateSubWindowStateAndNotify(1006, WindowState::STATE_HIDDEN); WindowSceneSessionImpl::subWindowSessionMap_[1006].push_back(subWindow); subWindow->state_ = WindowState::STATE_SHOWN; subWindow->UpdateSubWindowStateAndNotify(1006, WindowState::STATE_HIDDEN); subWindow->state_ = WindowState::STATE_HIDDEN; subWindow->UpdateSubWindowStateAndNotify(1006, WindowState::STATE_HIDDEN); subWindow->state_ = WindowState::STATE_SHOWN; subWindow->UpdateSubWindowStateAndNotify(1006, WindowState::STATE_SHOWN); subWindow->state_ = WindowState::STATE_SHOWN; subWindow->UpdateSubWindowStateAndNotify(1006, WindowState::STATE_SHOWN); ASSERT_EQ(WMError::WM_OK, subWindow->Destroy(true)); ASSERT_EQ(WMError::WM_OK, window->Destroy(true)); } /** * @tc.name: PreLayoutOnShow01 * @tc.desc: PreLayoutOnShow * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, PreLayoutOnShow01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("PreLayoutOnShow01"); sptr window = sptr::MakeSptr(option); window->property_->SetPersistentId(2345); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = nullptr; sptr displayInfo = sptr::MakeSptr(); window->uiContent_ = std::make_unique(); ASSERT_NE(nullptr, window->uiContent_); window->PreLayoutOnShow(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, displayInfo); window->hostSession_ = session; window->PreLayoutOnShow(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, displayInfo); Rect originRect = window->GetRect(); Rect testRect = {10, 20, 100, 200}; window->GetProperty()->SetRequestRect(testRect); window->PreLayoutOnShow(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, displayInfo); ASSERT_EQ(window->GetRect(), originRect); window->PreLayoutOnShow(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, displayInfo); ASSERT_EQ(window->GetRect(), testRect); } /** * @tc.name: KeepKeyboardOnFocus01 * @tc.desc: KeepKeyboardOnFocus * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, KeepKeyboardOnFocus01, TestSize.Level1) { sptr keyboardOption = sptr::MakeSptr(); keyboardOption->SetWindowName("KeepKeyboardOnFocus01"); keyboardOption->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); sptr keyboardWindow = sptr::MakeSptr(keyboardOption); keyboardWindow->KeepKeyboardOnFocus(false); ASSERT_EQ(keyboardWindow->property_->keepKeyboardFlag_, false); keyboardWindow->KeepKeyboardOnFocus(true); ASSERT_EQ(keyboardWindow->property_->keepKeyboardFlag_, true); } /** * @tc.name: MoveAndResizeKeyboard01 * @tc.desc: MoveAndResizeKeyboard * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, MoveAndResizeKeyboard01, TestSize.Level1) { sptr keyboardOption = sptr::MakeSptr(); keyboardOption->SetWindowName("MoveAndResizeKeyboard01"); keyboardOption->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); sptr keyboardWindow = sptr::MakeSptr(keyboardOption); bool isLandscape = false; keyboardWindow->property_->displayId_ = 0; auto display = SingletonContainer::Get().GetDisplayById(0); if (display != nullptr) { isLandscape = display->GetWidth() > display->GetHeight(); } KeyboardLayoutParams param; param.LandscapeKeyboardRect_ = { 100, 100, 100, 200 }; param.PortraitKeyboardRect_ = { 200, 200, 200, 100 }; auto result = keyboardWindow->MoveAndResizeKeyboard(param); auto expectRect = isLandscape ? param.LandscapeKeyboardRect_ : param.PortraitKeyboardRect_; ASSERT_EQ(keyboardWindow->property_->requestRect_, expectRect); ASSERT_EQ(result, WMError::WM_OK); } /** * @tc.name: MoveAndResizeKeyboard02 * @tc.desc: MoveAndResizeKeyboard * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, MoveAndResizeKeyboard02, TestSize.Level1) { sptr keyboardOption = sptr::MakeSptr(); keyboardOption->SetWindowName("MoveAndResizeKeyboard02"); keyboardOption->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); sptr keyboardWindow = sptr::MakeSptr(keyboardOption); bool isLandscape = false; keyboardWindow->property_->displayId_ = DISPLAY_ID_INVALID; auto defaultDisplayInfo = DisplayManager::GetInstance().GetDefaultDisplay(); if (defaultDisplayInfo != nullptr) { isLandscape = defaultDisplayInfo->GetWidth() > defaultDisplayInfo->GetHeight(); } KeyboardLayoutParams param; param.LandscapeKeyboardRect_ = { 100, 100, 100, 200 }; param.PortraitKeyboardRect_ = { 200, 200, 200, 100 }; auto result = keyboardWindow->MoveAndResizeKeyboard(param); auto expectRect = isLandscape ? param.LandscapeKeyboardRect_ : param.PortraitKeyboardRect_; ASSERT_EQ(keyboardWindow->property_->requestRect_, expectRect); ASSERT_EQ(result, WMError::WM_OK); } static sptr CreateWindow(std::string windowName, WindowType type, int32_t id) { sptr option = sptr::MakeSptr(); option->SetWindowName(windowName); option->SetWindowType(type); auto window = sptr::MakeSptr(option); window->property_->SetPersistentId(id); return window; } /** * @tc.name: GetParentMainWindowId * @tc.desc: GetParentMainWindowId * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, GetParentMainWindowId001, TestSize.Level1) { using SessionPair = std::pair>; // toastSubWindow is function caller sptr toastWindow = CreateWindow("toastWindow", WindowType::WINDOW_TYPE_APP_SUB_WINDOW, 99); toastWindow->property_->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_TOAST); toastWindow->windowSessionMap_["toastWindow"] = SessionPair(toastWindow->GetPersistentId(), toastWindow); int32_t res = 0; res = toastWindow->GetParentMainWindowId(0); ASSERT_EQ(res, 0); sptr mainWindow = CreateWindow("mainWindow", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, 100); ASSERT_NE(mainWindow, nullptr); toastWindow->windowSessionMap_["mainWindow"] = SessionPair(mainWindow->GetPersistentId(), mainWindow); toastWindow->property_->SetParentPersistentId(mainWindow->GetPersistentId()); res = toastWindow->GetParentMainWindowId(toastWindow->GetPersistentId()); ASSERT_EQ(res, mainWindow->GetPersistentId()); res = 0; sptr subWindow = CreateWindow("subWindow", WindowType::WINDOW_TYPE_APP_SUB_WINDOW, 101); ASSERT_NE(subWindow, nullptr); subWindow->property_->SetParentPersistentId(mainWindow->GetPersistentId()); toastWindow->property_->SetParentPersistentId(subWindow->GetPersistentId()); toastWindow->windowSessionMap_["subWindow"] = SessionPair(subWindow->GetPersistentId(), subWindow); res = toastWindow->GetParentMainWindowId(toastWindow->GetPersistentId()); ASSERT_EQ(res, mainWindow->GetPersistentId()); res = 0; sptr dialogWindow = CreateWindow("dialogWindow", WindowType::WINDOW_TYPE_DIALOG, 102); ASSERT_NE(dialogWindow, nullptr); dialogWindow->property_->SetParentPersistentId(mainWindow->GetPersistentId()); toastWindow->property_->SetParentPersistentId(dialogWindow->GetPersistentId()); toastWindow->windowSessionMap_["dialogWindow"] = SessionPair(dialogWindow->GetPersistentId(), dialogWindow); res = toastWindow->GetParentMainWindowId(toastWindow->GetPersistentId()); ASSERT_EQ(res, mainWindow->GetPersistentId()); res = 0; sptr pipWindow = CreateWindow("dialogWindow", WindowType::WINDOW_TYPE_PIP, 103); ASSERT_NE(pipWindow, nullptr); pipWindow->property_->SetParentPersistentId(mainWindow->GetPersistentId()); toastWindow->property_->SetParentPersistentId(pipWindow->GetPersistentId()); toastWindow->windowSessionMap_.insert(std::make_pair( "dialogWindow", std::pair>(pipWindow->GetPersistentId(), pipWindow))); res = toastWindow->GetParentMainWindowId(toastWindow->GetPersistentId()); ASSERT_EQ(res, 0); } /** * @tc.name: FindParentMainSession001 * @tc.desc: FindParentMainSession001 * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, FindParentMainSession001, TestSize.Level1) { using SessionPair = std::pair>; // toastSubWindow is function caller sptr toastWindow = CreateWindow("toastWindow", WindowType::WINDOW_TYPE_APP_SUB_WINDOW, 99); toastWindow->property_->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_TOAST); ASSERT_NE(toastWindow, nullptr); toastWindow->windowSessionMap_["toastWindow"] = SessionPair(toastWindow->GetPersistentId(), toastWindow); sptr result = nullptr; result = toastWindow->FindParentMainSession(0, toastWindow->windowSessionMap_); ASSERT_EQ(result, nullptr); // mainWindow need to be found sptr mainWindow = CreateWindow("mainWindow", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, 100); ASSERT_NE(mainWindow, nullptr); toastWindow->windowSessionMap_["mainWindow"] = SessionPair(mainWindow->GetPersistentId(), mainWindow); toastWindow->property_->SetParentPersistentId(mainWindow->GetPersistentId()); result = toastWindow->FindParentMainSession(toastWindow->GetParentId(), toastWindow->windowSessionMap_); ASSERT_EQ(result, mainWindow); result = nullptr; sptr subWindow = CreateWindow("subWindow", WindowType::WINDOW_TYPE_APP_SUB_WINDOW, 101); ASSERT_NE(subWindow, nullptr); subWindow->property_->SetParentPersistentId(mainWindow->GetPersistentId()); toastWindow->property_->SetParentPersistentId(subWindow->GetPersistentId()); toastWindow->windowSessionMap_["subWindow"] = SessionPair(subWindow->GetPersistentId(), subWindow); result = toastWindow->FindParentMainSession(toastWindow->GetParentId(), toastWindow->windowSessionMap_); ASSERT_EQ(result, mainWindow); result = nullptr; sptr floatWindow = CreateWindow("floatWindow", WindowType::WINDOW_TYPE_FLOAT, 105); ASSERT_NE(subWindow, nullptr); toastWindow->property_->SetParentPersistentId(floatWindow->GetPersistentId()); floatWindow->property_->SetParentPersistentId(0); toastWindow->windowSessionMap_["floatWindow"] = SessionPair(floatWindow->GetPersistentId(), floatWindow); result = toastWindow->FindParentMainSession(toastWindow->GetParentId(), toastWindow->windowSessionMap_); ASSERT_EQ(result, floatWindow); result = nullptr; floatWindow->property_->SetParentPersistentId(mainWindow->GetPersistentId()); result = toastWindow->FindParentMainSession(toastWindow->GetParentId(), toastWindow->windowSessionMap_); ASSERT_EQ(result, mainWindow); } /** * @tc.name: IsPcOrPadFreeMultiWindowMode * @tc.desc: IsPcOrPadFreeMultiWindowMode * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, IsPcOrPadFreeMultiWindowMode, TestSize.Level1) { sptr mainWindow = CreateWindow("mainWindow", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, 100); ASSERT_NE(mainWindow, nullptr); mainWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; ASSERT_EQ(true, mainWindow->IsPcOrPadFreeMultiWindowMode()); mainWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; ASSERT_EQ(false, mainWindow->IsPcOrPadFreeMultiWindowMode()); } /** * @tc.name: IsPcOrPadFreeMultiWindowMode * @tc.desc: uitype = padwindow * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, IsPcOrPadFreeMultiWindowMode002, TestSize.Level1) { sptr mainWindow = CreateWindow("mainWindow", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, 100); ASSERT_NE(mainWindow, nullptr); mainWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW; mainWindow->SetFreeMultiWindowMode(true); ASSERT_EQ(true, mainWindow->IsPcOrPadFreeMultiWindowMode()); mainWindow->SetFreeMultiWindowMode(false); ASSERT_EQ(false, mainWindow->IsPcOrPadFreeMultiWindowMode()); } static sptr CreateWindowWithDisplayId(std::string windowName, WindowType type, int64_t displayId = DISPLAY_ID_INVALID, uint32_t parentId = INVALID_WINDOW_ID) { using SessionPair = std::pair>; static uint32_t windowPersistentId = 106; sptr option = sptr::MakeSptr(); option->SetWindowName(windowName); option->SetWindowType(type); option->SetParentId(parentId); option->SetDisplayId(displayId); auto window = sptr::MakeSptr(option); window->property_->SetPersistentId(windowPersistentId++); WindowSessionImpl::windowSessionMap_[std::move(windowName)] = SessionPair(window->GetPersistentId(), window); return window; } /** * @tc.name: SetSpecificDisplayId01 * @tc.desc: SetSpecificDisplayId01 * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, SetSpecificDisplayId01, TestSize.Level1) { // create main window int64_t displayId = 12; auto mainWindowContext = std::make_shared(); sptr mainWindow = CreateWindowWithDisplayId("mainWindow", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, displayId); mainWindow->context_ = mainWindowContext; // create sub window sptr subWindow = CreateWindowWithDisplayId( "subWindow", WindowType::WINDOW_TYPE_APP_SUB_WINDOW, DISPLAY_ID_INVALID, mainWindow->GetPersistentId()); // create float window sptr floatWindow = CreateWindowWithDisplayId("floatWindow", WindowType::WINDOW_TYPE_FLOAT); floatWindow->context_ = mainWindow->context_; // create other window uint64_t globalSearchDisplayId = 5678; sptr globalSearchWindow = CreateWindowWithDisplayId("globalWindow", WindowType::WINDOW_TYPE_GLOBAL_SEARCH, globalSearchDisplayId); // test display id subWindow->CreateAndConnectSpecificSession(); ASSERT_EQ(subWindow->property_->GetDisplayId(), displayId); floatWindow->CreateSystemWindow(WindowType::WINDOW_TYPE_FLOAT); ASSERT_EQ(floatWindow->property_->GetDisplayId(), displayId); globalSearchWindow->CreateSystemWindow(WindowType::WINDOW_TYPE_GLOBAL_SEARCH); ASSERT_EQ(globalSearchWindow->property_->GetDisplayId(), globalSearchDisplayId); floatWindow->CreateSystemWindow(WindowType::WINDOW_TYPE_FB); ASSERT_EQ(floatWindow->property_->GetDisplayId(), displayId); } /** * @tc.name: SetFullScreenWaterfallMode * @tc.desc: test SetFullScreenWaterfallMode * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, SetFullScreenWaterfallMode, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("SetFullScreenWaterfallMode"); sptr window = sptr::MakeSptr(option); window->property_->windowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN; EXPECT_EQ(WSError::WS_OK, window->SetFullScreenWaterfallMode(true)); EXPECT_EQ(WSError::WS_DO_NOTHING, window->SetFullScreenWaterfallMode(true)); EXPECT_TRUE(window->isFullScreenWaterfallMode_.load()); EXPECT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->lastWindowModeBeforeWaterfall_.load()); EXPECT_EQ(WSError::WS_OK, window->SetFullScreenWaterfallMode(false)); EXPECT_FALSE(window->isFullScreenWaterfallMode_.load()); EXPECT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, window->lastWindowModeBeforeWaterfall_.load()); } /** * @tc.name: SetSupportEnterWaterfallMode * @tc.desc: test SetSupportEnterWaterfallMode * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, SetSupportEnterWaterfallMode, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("SetSupportEnterWaterfallMode"); sptr window = sptr::MakeSptr(option); ASSERT_EQ(WSError::WS_OK, window->SetSupportEnterWaterfallMode(true)); } /** * @tc.name: OnContainerModalEvent * @tc.desc: test OnContainerModalEvent * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, OnContainerModalEvent, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("OnContainerModalEvent"); sptr window = sptr::MakeSptr(option); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->OnContainerModalEvent("not_waterfall_window_event", "")); } /** * @tc.name: UpdateConfigurationSyncForAll * @tc.desc: UpdateConfigurationSyncForAll * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, UpdateConfigurationSyncForAll, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("UpdateConfigurationSyncForAll"); sptr windowSceneSessionImpl = sptr::MakeSptr(option); std::shared_ptr configuration = std::make_shared(); sptr windowSession = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle1", "CreateTestModule1", "CreateTestAbility1" }; sptr session = sptr::MakeSptr(sessionInfo); windowSession->hostSession_ = session; windowSession->property_->SetPersistentId(1); windowSession->state_ = WindowState::STATE_SHOWN; ASSERT_EQ(WMError::WM_OK, windowSession->Create(abilityContext_, session)); windowSceneSessionImpl->UpdateConfigurationSyncForAll(configuration); ASSERT_EQ(WMError::WM_OK, windowSession->Destroy(true)); } /** * @tc.name: NotifyDrawingCompleted * @tc.desc: NotifyDrawingCompleted * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, NotifyDrawingCompleted, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("NotifyDrawingCompleted"); sptr window = sptr::MakeSptr(option); sptr windowSessionImpl = sptr::MakeSptr(option); windowSessionImpl->hostSession_ = nullptr; auto ret = window->NotifyDrawingCompleted(); ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_WINDOW); } /** * @tc.name: NotifyDrawingCompleted01 * @tc.desc: NotifyDrawingCompleted * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, NotifyDrawingCompleted01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("NotifyDrawingCompleted01"); sptr window = sptr::MakeSptr(option); sptr windowSessionImpl = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); windowSessionImpl->hostSession_ = session; WindowSessionProperty windowSessionProperty; windowSessionProperty.SetPersistentId(1); auto ret = window->NotifyDrawingCompleted(); ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_WINDOW); } /** * @tc.name: MoveTo * @tc.desc: MoveTo * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, MoveTo, TestSize.Level1) { sptr option = sptr::MakeSptr(); sptr windowSessionImpl = sptr::MakeSptr(option); option->SetWindowName("MoveTo"); sptr window = sptr::MakeSptr(option); MoveConfiguration moveConfiguration; windowSessionImpl->hostSession_ = nullptr; auto ret = window->MoveTo(0, 0, true, moveConfiguration); ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_WINDOW); windowSessionImpl->property_->SetWindowType(WindowType::WINDOW_TYPE_PIP); ret = window->MoveTo(0, 0, true, moveConfiguration); ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_WINDOW); windowSessionImpl->property_->type_ = WindowType::APP_SUB_WINDOW_BASE; window->MoveTo(0, 0, true, moveConfiguration); } /** * @tc.name: MoveTo * @tc.desc: MoveTo * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, MoveTo002, TestSize.Level1) { sptr option = sptr::MakeSptr(); sptr windowSessionImpl = sptr::MakeSptr(option); option->SetWindowName("MoveTo002"); sptr window = sptr::MakeSptr(option); MoveConfiguration moveConfiguration; auto ret = window->MoveTo(0, 0, true, moveConfiguration); windowSessionImpl->property_->SetWindowType(WindowType::WINDOW_TYPE_PIP); window->state_ = WindowState::STATE_INITIAL; window->property_->SetPersistentId(1); ret = window->MoveTo(0, 0, true, moveConfiguration); ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_WINDOW); } /** * @tc.name: MoveTo * @tc.desc: MoveTo * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, MoveTo003, TestSize.Level1) { sptr option = sptr::MakeSptr(); sptr windowSessionImpl = sptr::MakeSptr(option); option->SetWindowName("MoveTo002"); sptr window = sptr::MakeSptr(option); MoveConfiguration moveConfiguration; auto ret = window->MoveTo(0, 0, true, moveConfiguration); windowSessionImpl->property_->SetWindowType(WindowType::WINDOW_TYPE_PIP); window->state_ = WindowState::STATE_INITIAL; ret = window->MoveTo(0, 0, true, moveConfiguration); ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_WINDOW); windowSessionImpl->property_->type_ = WindowType::APP_SUB_WINDOW_BASE; int64_t displayId = 12; auto mainWindowContext = std::make_shared(); sptr mainWindow = CreateWindowWithDisplayId("mainWindow", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, displayId); mainWindow->context_ = mainWindowContext; window->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); ret = window->MoveTo(0, 0, true, moveConfiguration); ASSERT_EQ(ret, WMError::WM_OK); } /** * @tc.name: MoveWindowToGlobal * @tc.desc: MoveWindowToGlobal * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, MoveWindowToGlobal, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("MoveWindowToGlobal"); sptr window = sptr::MakeSptr(option); MoveConfiguration moveConfiguration; window->hostSession_ = nullptr; auto ret = window->MoveWindowToGlobal(0, 0, moveConfiguration); ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_WINDOW); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; window->property_->SetPersistentId(1); window->state_ = WindowState::STATE_INITIAL; window->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); ret = window->MoveWindowToGlobal(0, 0, moveConfiguration); ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS); window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); window->MoveWindowToGlobal(0, 0, moveConfiguration); } /** * @tc.name: MoveWindowToGlobal01 * @tc.desc: MoveWindowToGlobal * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, MoveWindowToGlobal01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("MoveWindowToGlobal01"); sptr window = sptr::MakeSptr(option); MoveConfiguration moveConfiguration; SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; window->property_->SetPersistentId(1); window->state_ = WindowState::STATE_INITIAL; window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); window->property_->SetWindowType(WindowType::WINDOW_TYPE_PIP); auto ret = window->MoveWindowToGlobal(0, 0, moveConfiguration); ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_OPERATION); } /** * @tc.name: OnContainerModalEvent01 * @tc.desc: OnContainerModalEvent * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, OnContainerModalEvent01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("VerifySubWindowLevel01"); sptr window = sptr::MakeSptr(option); std::string eventName = "window_scene_session_impl_test4"; std::string value = "window_scene_session_impl_test4"; auto ret = window->OnContainerModalEvent(eventName, value); ASSERT_EQ(WMError::WM_DO_NOTHING, ret); eventName = "scb_waterfall_window_event"; window->hostSession_ = nullptr; ret = window->OnContainerModalEvent(eventName, value); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret); } /** * @tc.name: IsSystemDensityChanged01 * @tc.desc: IsSystemDensityChanged * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, IsSystemDensityChanged01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("IsSystemDensityChanged01"); sptr window = sptr::MakeSptr(option); auto displayInfo = sptr::MakeSptr(); displayInfo->SetVirtualPixelRatio(1.5f); auto ret = window->IsSystemDensityChanged(displayInfo); ASSERT_EQ(true, ret); window->lastSystemDensity_ = 1.5f; ret = window->IsSystemDensityChanged(displayInfo); ASSERT_EQ(false, ret); } /** * @tc.name: GetWindowPropertyInfo * @tc.desc: GetWindowPropertyInfo01 * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, GetWindowPropertyInfo01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetFocusable(false); option->SetTouchable(true); option->SetDisplayId(999); option->SetWindowName("GetWindowPropertyInfo01"); sptr window = sptr::MakeSptr(option); window->hostSession_ = nullptr; WindowPropertyInfo windowPropertyInfo; auto ret = window->GetWindowPropertyInfo(windowPropertyInfo); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret); } /** * @tc.name: GetWindowPropertyInfo * @tc.desc: GetWindowPropertyInfo02 * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, GetWindowPropertyInfo02, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetFocusable(false); option->SetTouchable(true); option->SetDisplayId(999); option->SetWindowName("GetWindowPropertyInfo02"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->property_->SetPersistentId(1); window->hostSession_ = session; window->state_ = WindowState::STATE_SHOWN; WindowPropertyInfo windowPropertyInfo; auto ret = window->GetWindowPropertyInfo(windowPropertyInfo); EXPECT_EQ(WMError::WM_OK, ret); EXPECT_EQ(false, windowPropertyInfo.isFocusable); EXPECT_EQ(true, windowPropertyInfo.isTouchable); EXPECT_EQ(999, windowPropertyInfo.displayId); } /** * @tc.name: SetWindowContainerColor01 * @tc.desc: SetWindowContainerColor * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, SetWindowContainerColor01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetBundleName("SetWindowContainerColor"); option->SetWindowName("SetWindowContainerColor"); sptr window = sptr::MakeSptr(option); window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); std::string activeColor = "#00000000"; std::string inactiveColor = "#FF000000"; WMError res = window->SetWindowContainerColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_DEVICE_NOT_SUPPORT); window->containerColorList_.insert("SetWindowContainerColor"); window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; res = window->SetWindowContainerColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->property_->SetPersistentId(1); window->hostSession_ = session; window->state_ = WindowState::STATE_SHOWN; res = window->SetWindowContainerColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_CALLING); window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); res = window->SetWindowContainerColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); window->property_->SetDecorEnable(true); window->windowSystemConfig_.freeMultiWindowSupport_ = true; window->windowSystemConfig_.isSystemDecorEnable_ = true; res = window->SetWindowContainerColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR); window->uiContent_ = std::make_unique(); res = window->SetWindowContainerColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_OK); inactiveColor = "#F1000000"; res = window->SetWindowContainerColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_PARAM); inactiveColor = "rgb#FF000000"; res = window->SetWindowContainerColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_PARAM); activeColor = "rgb#00000000"; res = window->SetWindowContainerColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_PARAM); } /** * @tc.name: SetWindowContainerModalColor01 * @tc.desc: SetWindowContainerModalColor * @tc.type: FUNC */ HWTEST_F(WindowSceneSessionImplTest4, SetWindowContainerModalColor01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetBundleName("SetWindowContainerModalColor"); option->SetWindowName("SetWindowContainerModalColor"); sptr window = sptr::MakeSptr(option); window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); std::string activeColor = "#FF000000"; std::string inactiveColor = "#00000000"; WMError res = window->SetWindowContainerModalColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_DEVICE_NOT_SUPPORT); window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; res = window->SetWindowContainerModalColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->property_->SetPersistentId(1); window->hostSession_ = session; window->state_ = WindowState::STATE_SHOWN; res = window->SetWindowContainerModalColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_CALLING); window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); res = window->SetWindowContainerModalColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); window->property_->SetDecorEnable(true); window->windowSystemConfig_.freeMultiWindowSupport_ = true; window->windowSystemConfig_.isSystemDecorEnable_ = true; res = window->SetWindowContainerModalColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR); window->uiContent_ = std::make_unique(); res = window->SetWindowContainerModalColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_OK); inactiveColor = "rgb#FF000000"; res = window->SetWindowContainerModalColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_PARAM); activeColor = "rgb#00000000"; res = window->SetWindowContainerModalColor(activeColor, inactiveColor); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_PARAM); } } // namespace } // namespace Rosen } // namespace OHOS