diff --git a/window_scene/test/unittest/keyboard_session_layout_test.cpp b/window_scene/test/unittest/keyboard_session_layout_test.cpp deleted file mode 100644 index 58c97533ed28d8cda662f2d3bb862deb49de92b3..0000000000000000000000000000000000000000 --- a/window_scene/test/unittest/keyboard_session_layout_test.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "interfaces/include/ws_common.h" -#include "mock/mock_keyboard_session.h" -#include "mock/mock_session_stage.h" -#include "session/host/include/keyboard_session.h" -#include "session/host/include/scene_session.h" -#include "session/host/include/session.h" -#include "window_helper.h" -#include "window_manager_hilog.h" - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace Rosen { - -class KeyboardSessionLayoutTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - -private: - sptr GetSceneSession(const std::string& abilityName, const std::string& bundleName); -}; - -void KeyboardSessionLayoutTest::SetUpTestCase() {} - -void KeyboardSessionLayoutTest::TearDownTestCase() {} - -void KeyboardSessionLayoutTest::SetUp() {} - -void KeyboardSessionLayoutTest::TearDown() {} - -sptr KeyboardSessionLayoutTest::GetSceneSession(const std::string& abilityName, - const std::string& bundleName) -{ - SessionInfo info; - info.abilityName_ = abilityName; - info.bundleName_ = bundleName; - auto specificCb = sptr::MakeSptr(); - return sptr::MakeSptr(info, specificCb); -} - -namespace { -/** - * @tc.name: NotifyClientToUpdateRect01 - * @tc.desc: NotifyClientToUpdateRect - * @tc.type: FUNC - */ -HWTEST_F(KeyboardSessionLayoutTest, NotifyClientToUpdateRect01, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "NotifyClientToUpdateRect01"; - info.bundleName_ = "NotifyClientToUpdateRect01"; - auto specificCb = sptr::MakeSptr(); - auto keyboardCb = sptr::MakeSptr(); - sptr keyboardSession = sptr::MakeSptr(info, specificCb, keyboardCb); - sptr mockSessionStage = sptr::MakeSptr(); - keyboardSession->dirtyFlags_ |= static_cast(SessionUIDirtyFlag::RECT); - keyboardSession->sessionStage_ = mockSessionStage; - auto ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr); - ASSERT_EQ(ret, WSError::WS_OK); -} - -/** - * @tc.name: NotifyClientToUpdateRect02 - * @tc.desc: NotifyClientToUpdateRect - * @tc.type: FUNC - */ -HWTEST_F(KeyboardSessionLayoutTest, NotifyClientToUpdateRect02, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "NotifyClientToUpdateRect02"; - info.bundleName_ = "NotifyClientToUpdateRect02"; - auto specificCb = sptr::MakeSptr(); - auto keyboardCb = sptr::MakeSptr(); - sptr keyboardSession = sptr::MakeSptr(info, specificCb, keyboardCb); - keyboardSession->dirtyFlags_ |= static_cast(SessionUIDirtyFlag::RECT); - keyboardSession->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE); - keyboardSession->isKeyboardPanelEnabled_ = true; - sptr windowSessionProperty = sptr::MakeSptr(); - windowSessionProperty->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL); - keyboardSession->SetSessionProperty(windowSessionProperty); - auto ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr); - ASSERT_EQ(ret, WSError::WS_OK); -} - -/** - * @tc.name: NotifyClientToUpdateRect03 - * @tc.desc: NotifyClientToUpdateRect - * @tc.type: FUNC - */ -HWTEST_F(KeyboardSessionLayoutTest, NotifyClientToUpdateRect03, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "NotifyClientToUpdateRect03"; - info.bundleName_ = "NotifyClientToUpdateRect03"; - auto specificCb = sptr::MakeSptr(); - auto keyboardCb = sptr::MakeSptr(); - sptr keyboardSession = sptr::MakeSptr(info, specificCb, keyboardCb); - - // NotifyClientToUpdateRectTask return not ok - WSError ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr); - ASSERT_EQ(ret, WSError::WS_OK); - - // NotifyClientToUpdateRectTask return ok and GetSizeChangeReason() is UNDEFINED - keyboardSession->sessionStage_ = sptr::MakeSptr(); - keyboardSession->state_ = SessionState::STATE_CONNECT; - ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr); - ASSERT_EQ(ret, WSError::WS_OK); - - // NotifyClientToUpdateRectTask return ok and GetSizeChangeReason() is DRAG - keyboardSession->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG); - keyboardSession->dirtyFlags_ |= static_cast(SessionUIDirtyFlag::RECT); - ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr); - ASSERT_EQ(ret, WSError::WS_OK); -} -} // namespace -} // namespace Rosen -} // namespace OHOS diff --git a/window_scene/test/unittest/layout/BUILD.gn b/window_scene/test/unittest/layout/BUILD.gn index c291f10eec48671a69614f3ffaea4127bb181f2b..d27593f23b4e7142e647db5770f39fe2da10f168 100644 --- a/window_scene/test/unittest/layout/BUILD.gn +++ b/window_scene/test/unittest/layout/BUILD.gn @@ -32,7 +32,6 @@ ohos_unittest("ws_layout_test") { "scene_session_layout_test.cpp", "scene_session_manager_layout_test.cpp", "session_layout_test.cpp", - "session_stage_proxy_layout_test.cpp", "session_stub_layout_test.cpp", "sub_session_layout_test.cpp", ] @@ -71,6 +70,7 @@ ohos_unittest("ws_layout_test") { "ipc:ipc_single", "libxml2:libxml2", "napi:ace_napi", + "safwk:system_ability_fwk", ] public_external_deps = [ "accessibility:accessibility_interface" ] diff --git a/window_scene/test/unittest/layout/scene_session_layout_test.cpp b/window_scene/test/unittest/layout/scene_session_layout_test.cpp index fcce252a7f39122fa9abbaf51278075dfc7125ec..48487927118a82f1b2db8b7e89a806292c933f08 100644 --- a/window_scene/test/unittest/layout/scene_session_layout_test.cpp +++ b/window_scene/test/unittest/layout/scene_session_layout_test.cpp @@ -26,6 +26,9 @@ #include "session/host/include/scene_session.h" #include "session/host/include/sub_session.h" #include "session/host/include/system_session.h" +#include "session/screen/include/screen_session.h" +#include "screen_session_manager/include/screen_session_manager.h" +#include "screen_session_manager_client/include/screen_session_manager_client.h" #include "window_helper.h" #include "wm_common.h" @@ -983,6 +986,96 @@ HWTEST_F(SceneSessionLayoutTest, UpdateWindowModeForUITest01, TestSize.Level1) errCode = sceneSession->UpdateWindowModeForUITest(updateMode); EXPECT_EQ(errCode, WMError::WM_OK); } + +/** + * @tc.name: SetMoveAvailableArea01 + * @tc.desc: SetMoveAvailableArea01 + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionLayoutTest, SetMoveAvailableArea01, TestSize.Level1) +{ + SessionInfo info; + info.abilityName_ = "SetMoveAvailableArea01"; + info.bundleName_ = "SetMoveAvailableArea01"; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + + WSError res = sceneSession->SetMoveAvailableArea(-1); + EXPECT_EQ(res, WSError::WS_ERROR_INVALID_DISPLAY); + + sceneSession->moveDragController_ = sptr::MakeSptr(2024, sceneSession->GetWindowType()); + int32_t screenId = 0; + sceneSession->SetScreenId(screenId); + res = sceneSession->SetMoveAvailableArea(0); + EXPECT_EQ(res, WSError::WS_OK); + + sptr currentScreenSession = + ScreenSessionManager::GetInstance().GetOrCreateScreenSession(0); + ASSERT_NE(currentScreenSession, nullptr); + uint32_t currentScreenHeight = currentScreenSession->GetScreenProperty().GetBounds().rect_.height_; + DMRect statusBarRect = sceneSession->CalcRectForStatusBar(); + int32_t dockHeight = sceneSession->GetDockHeight(); + if (PcFoldScreenManager::GetInstance().IsHalfFolded(screenId)) { + sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); + DMRect availableArea; + DMError ret = DisplayManager::GetInstance().GetExpandAvailableArea( + sceneSession->GetSessionProperty()->GetDisplayId(), availableArea); + if (ret != DMError::DM_OK) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Failed to get available area, ret: %{public}d", ret); + } + EXPECT_EQ(sceneSession->moveDragController_->moveAvailableArea_, availableArea); + EXPECT_EQ(sceneSession->moveDragController_->moveAvailableArea_.height_, + currentScreenHeight - statusBarRect.height_ - dockHeight); + } +} + +/** + * @tc.name: SetMoveAvailableArea02 + * @tc.desc: SetMoveAvailableArea02 + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionLayoutTest, SetMoveAvailableArea02, TestSize.Level1) +{ + SessionInfo info; + info.abilityName_ = "SetMoveAvailableArea02"; + info.bundleName_ = "SetMoveAvailableArea02"; + sptr specificCallback_ = + sptr::MakeSptr(); + EXPECT_NE(specificCallback_, nullptr); + sptr sceneSession = sptr::MakeSptr(info, specificCallback_); + + WSRect rect({0, 0, 50, 50}); + sceneSession->GetLayoutController()->SetSessionRect(rect); + sceneSession->specificCallback_->onGetSceneSessionVectorByTypeAndDisplayId_ = + [&](WindowType type, uint64_t displayId) -> std::vector> { + std::vector> vec; + vec.push_back(sceneSession); + return vec; + }; + + SystemSessionConfig systemConfig; + int32_t screenId = 0; + sceneSession->SetScreenId(screenId); + + sptr property = sptr::MakeSptr(); + property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); + sceneSession->SetSessionProperty(property); + ScreenSessionConfig config; + sptr screenSession = + sptr::MakeSptr(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(screenId, screenSession)); + + systemConfig.windowUIType_ = WindowUIType::PHONE_WINDOW; + sceneSession->SetSystemConfig(systemConfig); + sceneSession->moveDragController_ = sptr::MakeSptr(2024, sceneSession->GetWindowType()); + WSError res = sceneSession->SetMoveAvailableArea(0); + EXPECT_EQ(res, WSError::WS_OK); + + systemConfig.windowUIType_ = WindowUIType::PC_WINDOW; + sceneSession->SetSystemConfig(systemConfig); + sceneSession->moveDragController_ = sptr::MakeSptr(2024, sceneSession->GetWindowType()); + res = sceneSession->SetMoveAvailableArea(0); + EXPECT_EQ(res, WSError::WS_OK); +} } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/layout/scene_session_manager_layout_test.cpp b/window_scene/test/unittest/layout/scene_session_manager_layout_test.cpp index c3d76e7d96c122b419e02315b2a3cee2df38e2bd..7d16f35617aea5331fc4d25b05f4556dd864d04b 100644 --- a/window_scene/test/unittest/layout/scene_session_manager_layout_test.cpp +++ b/window_scene/test/unittest/layout/scene_session_manager_layout_test.cpp @@ -227,6 +227,73 @@ HWTEST_F(SceneSessionManagerLayoutTest, NotifySingleHandInfoChange_TestMode, Tes ssm_->singleHandTransform_ = singleHandTransform; } +/** + * @tc.name: SetHasRootSceneRequestedVsyncFunc + * @tc.desc: SetHasRootSceneRequestedVsyncFunc + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerLayoutTest, SetHasRootSceneRequestedVsyncFunc, TestSize.Level1) +{ + ssm_->SetHasRootSceneRequestedVsyncFunc(nullptr); + ASSERT_EQ(nullptr, ssm_->hasRootSceneRequestedVsyncFunc_); + ssm_->SetHasRootSceneRequestedVsyncFunc([] { + bool tempBool = false; + return tempBool; + }); + ASSERT_NE(nullptr, ssm_->hasRootSceneRequestedVsyncFunc_); +} + +/** + * @tc.name: HasRootSceneRequestedVsync + * @tc.desc: HasRootSceneRequestedVsync + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerLayoutTest, HasRootSceneRequestedVsync, TestSize.Level1) +{ + bool tempBool = false; + ssm_->hasRootSceneRequestedVsyncFunc_ = nullptr; + EXPECT_EQ(WSError::WS_ERROR_NULLPTR, ssm_->HasRootSceneRequestedVsync(tempBool)); + EXPECT_EQ(false, tempBool); + + ssm_->SetHasRootSceneRequestedVsyncFunc([] { + bool tempInnerBool = true; + return tempInnerBool; + }); + EXPECT_EQ(WSError::WS_OK, ssm_->HasRootSceneRequestedVsync(tempBool)); + EXPECT_EQ(true, tempBool); +} + +/** + * @tc.name: SetRequestVsyncByRootSceneWhenModeChangeFunc + * @tc.desc: SetRequestVsyncByRootSceneWhenModeChangeFunc + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerLayoutTest, SetRequestVsyncByRootSceneWhenModeChangeFunc, TestSize.Level1) +{ + ssm_->SetRequestVsyncByRootSceneWhenModeChangeFunc(nullptr); + ASSERT_EQ(nullptr, ssm_->requestVsyncByRootSceneWhenModeChangeFunc_); + ssm_->SetRequestVsyncByRootSceneWhenModeChangeFunc([](const std::shared_ptr& vsyncCallback) { + auto tempCallback = vsyncCallback; + }); + ASSERT_NE(nullptr, ssm_->requestVsyncByRootSceneWhenModeChangeFunc_); +} + +/** + * @tc.name: RequestVsyncByRootSceneWhenModeChange + * @tc.desc: RequestVsyncByRootSceneWhenModeChange + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerLayoutTest, RequestVsyncByRootSceneWhenModeChange, TestSize.Level1) +{ + std::shared_ptr nextVsyncCallback = std::make_shared(); + ssm_->requestVsyncByRootSceneWhenModeChangeFunc_ = nullptr; + EXPECT_EQ(WSError::WS_ERROR_NULLPTR, ssm_->RequestVsyncByRootSceneWhenModeChange(nextVsyncCallback)); + ssm_->SetRequestVsyncByRootSceneWhenModeChangeFunc([](const std::shared_ptr& vsyncCallback) { + auto tempCallback = vsyncCallback; + }); + EXPECT_EQ(WSError::WS_OK, ssm_->RequestVsyncByRootSceneWhenModeChange(nextVsyncCallback)); +} + /** * @tc.name: GetDisplaySizeById_TestDisplayId * @tc.desc: test function : GetDisplaySizeById diff --git a/window_scene/test/unittest/layout/session_layout_test.cpp b/window_scene/test/unittest/layout/session_layout_test.cpp index 74c887b2ffba22fba2a44a4803bdbc52815ca6c3..735363fe2e74470ad1594828248ae36635cbf594 100644 --- a/window_scene/test/unittest/layout/session_layout_test.cpp +++ b/window_scene/test/unittest/layout/session_layout_test.cpp @@ -18,7 +18,6 @@ #include #include -#include "ability_info.h" #include "mock/mock_session_stage.h" #include "mock/mock_window_event_channel.h" #include "mock/mock_pattern_detach_callback.h" @@ -275,6 +274,140 @@ HWTEST_F(SessionLayoutTest, UpdateWindowModeSupportType01, TestSize.Level1) std::shared_ptr abilityInfo = std::make_shared(); EXPECT_EQ(session->UpdateWindowModeSupportType(abilityInfo), false); } + +/** + * @tc.name: SetHasRequestedVsyncFunc + * @tc.desc: SetHasRequestedVsyncFunc + * @tc.type: FUNC + */ +HWTEST_F(SessionLayoutTest, SetHasRequestedVsyncFunc, TestSize.Level1) +{ + SessionInfo info; + info.abilityName_ = "SetHasRequestedVsyncFunc"; + info.bundleName_ = "SetHasRequestedVsyncFunc"; + sptr session = sptr::MakeSptr(info); + session->SetHasRequestedVsyncFunc(nullptr); + ASSERT_EQ(nullptr, session->hasRequestedVsyncFunc_); + session->SetHasRequestedVsyncFunc([](bool& hasRequestedVsync) { + hasRequestedVsync = true; + return WSError::WS_OK; + }); + ASSERT_NE(nullptr, session->hasRequestedVsyncFunc_); +} + +/** + * @tc.name: SetRequestNextVsyncWhenModeChangeFunc + * @tc.desc: SetRequestNextVsyncWhenModeChangeFunc + * @tc.type: FUNC + */ +HWTEST_F(SessionLayoutTest, SetRequestNextVsyncWhenModeChangeFunc, TestSize.Level1) +{ + SessionInfo info; + info.abilityName_ = "SetRequestNextVsyncWhenModeChangeFunc"; + info.bundleName_ = "SetRequestNextVsyncWhenModeChangeFunc"; + sptr session = sptr::MakeSptr(info); + session->SetRequestNextVsyncWhenModeChangeFunc(nullptr); + ASSERT_EQ(nullptr, session->requestNextVsyncWhenModeChangeFunc_); + session->SetRequestNextVsyncWhenModeChangeFunc([](const std::shared_ptr& vsyncCallback) { + return WSError::WS_OK; + }); + ASSERT_NE(nullptr, session->requestNextVsyncWhenModeChangeFunc_); +} + +/** + * @tc.name: RequestNextVsyncWhenModeChange + * @tc.desc: RequestNextVsyncWhenModeChange + * @tc.type: FUNC + */ +HWTEST_F(SessionLayoutTest, RequestNextVsyncWhenModeChange, TestSize.Level1) +{ + SessionInfo info; + info.abilityName_ = "RequestNextVsyncWhenModeChange"; + info.bundleName_ = "RequestNextVsyncWhenModeChange"; + sptr session = sptr::MakeSptr(info); + auto ret = session->RequestNextVsyncWhenModeChange(); + EXPECT_EQ(WSError::WS_ERROR_NULLPTR, ret); + session->SetHasRequestedVsyncFunc([](bool& hasRequestedVsync) { + hasRequestedVsync = true; + return WSError::WS_OK; + }); + ret = session->RequestNextVsyncWhenModeChange(); + EXPECT_EQ(WSError::WS_OK, ret); +} + +/** + * @tc.name: InitVsyncCallbackForModeChangeAndRequestNextVsync + * @tc.desc: InitVsyncCallbackForModeChangeAndRequestNextVsync + * @tc.type: FUNC + */ +HWTEST_F(SessionLayoutTest, InitVsyncCallbackForModeChangeAndRequestNextVsync, TestSize.Level1) +{ + SessionInfo info; + info.abilityName_ = "InitVsyncCallbackForModeChangeAndRequestNextVsync"; + info.bundleName_ = "InitVsyncCallbackForModeChangeAndRequestNextVsync"; + sptr session = sptr::MakeSptr(info); + session->isWindowModeDirty_.store(true); + session->timesToWaitForVsync_.store(2); + session->requestNextVsyncWhenModeChangeFunc_ = nullptr; + session->InitVsyncCallbackForModeChangeAndRequestNextVsync(); + usleep(WAIT_SYNC_IN_NS); + EXPECT_EQ(session->timesToWaitForVsync_.load(), 2); + + session->SetRequestNextVsyncWhenModeChangeFunc([](const std::shared_ptr& vsyncCallback) { + vsyncCallback->onCallback(1, 1); + return WSError::WS_OK; + }); + session->InitVsyncCallbackForModeChangeAndRequestNextVsync(); + usleep(WAIT_SYNC_IN_NS); + EXPECT_NE(session->timesToWaitForVsync_.load(), 2); +} + +/** + * @tc.name: OnVsyncReceivedAfterModeChanged + * @tc.desc: OnVsyncReceivedAfterModeChanged + * @tc.type: FUNC + */ +HWTEST_F(SessionLayoutTest, OnVsyncReceivedAfterModeChanged, TestSize.Level1) +{ + SessionInfo info; + info.abilityName_ = "OnVsyncReceivedAfterModeChanged"; + info.bundleName_ = "OnVsyncReceivedAfterModeChanged"; + sptr session = sptr::MakeSptr(info); + session->isWindowModeDirty_.store(false); + session->timesToWaitForVsync_.store(2); + session->OnVsyncReceivedAfterModeChanged(); + usleep(WAIT_SYNC_IN_NS); + EXPECT_EQ(session->timesToWaitForVsync_.load(), 2); + + session->SetRequestNextVsyncWhenModeChangeFunc([](const std::shared_ptr& vsyncCallback) { + vsyncCallback->onCallback(1, 1); + return WSError::WS_OK; + }); + session->isWindowModeDirty_.store(true); + session->OnVsyncReceivedAfterModeChanged(); + usleep(WAIT_SYNC_IN_NS); + EXPECT_NE(session->timesToWaitForVsync_.load(), 2); + + session->isWindowModeDirty_.store(true); + session->timesToWaitForVsync_.store(-1); + session->OnVsyncReceivedAfterModeChanged(); + usleep(WAIT_SYNC_IN_NS); + EXPECT_EQ(session->timesToWaitForVsync_.load(), 0); + + session->isWindowModeDirty_.store(true); + session->timesToWaitForVsync_.store(1); + session->sessionStage_ = nullptr; + session->OnVsyncReceivedAfterModeChanged(); + usleep(WAIT_SYNC_IN_NS); + EXPECT_EQ(session->isWindowModeDirty_.load(), false); + + session->isWindowModeDirty_.store(true); + session->timesToWaitForVsync_.store(1); + session->sessionStage_ = sptr::MakeSptr(); + session->OnVsyncReceivedAfterModeChanged(); + usleep(WAIT_SYNC_IN_NS); + EXPECT_EQ(session->isWindowModeDirty_.load(), false); +} } // namespace } // namespace Rosen } // namespace OHOS diff --git a/window_scene/test/unittest/layout/session_stage_proxy_layout_test.cpp b/window_scene/test/unittest/layout/session_stage_proxy_layout_test.cpp deleted file mode 100644 index f5bbdac153417b38809ddc98c62a1f5bbf01cb3f..0000000000000000000000000000000000000000 --- a/window_scene/test/unittest/layout/session_stage_proxy_layout_test.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2025 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 "iremote_object_mocker.h" -#include "mock_message_parcel.h" -#include "session/container/include/zidl/session_stage_proxy.h" -#include "window_manager_hilog.h" -#include "wm_common.h" - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace Rosen { -class SessionStageProxyLayoutTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - sptr iRemoteObjectMocker = sptr::MakeSptr(); - sptr sessionStage_ = sptr::MakeSptr(iRemoteObjectMocker); -}; - -void SessionStageProxyLayoutTest::SetUpTestCase() {} - -void SessionStageProxyLayoutTest::TearDownTestCase() {} - -void SessionStageProxyLayoutTest::SetUp() {} - -void SessionStageProxyLayoutTest::TearDown() {} - -namespace { -/** - * @tc.name: NotifySingleHandTransformChange - * @tc.desc: test function : NotifySingleHandTransformChange - * @tc.type: FUNC - */ -HWTEST_F(SessionStageProxyLayoutTest, NotifySingleHandTransformChange, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SessionStageProxyLayoutTest: NotifySingleHandTransformChange start"; - SingleHandTransform singleHandTransform; - sessionStage_->NotifySingleHandTransformChange(singleHandTransform); - ASSERT_TRUE((sessionStage_ != nullptr)); - GTEST_LOG_(INFO) << "SessionStageProxyLayoutTest: NotifySingleHandTransformChange end"; -} -} // namespace -} // namespace Rosen -} // namespace OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/scb_system_session_layout_test.cpp b/window_scene/test/unittest/scb_system_session_layout_test.cpp deleted file mode 100644 index fcb0f73feefc278eac0e6666e67fa0333d03c6d5..0000000000000000000000000000000000000000 --- a/window_scene/test/unittest/scb_system_session_layout_test.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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 "common/include/session_permission.h" -#include "key_event.h" -#include "mock/mock_session_stage.h" -#include "session/host/include/scb_system_session.h" -#include "session/host/include/session.h" -#include "window_helper.h" -#include "window_manager_hilog.h" - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace Rosen { -class SCBSystemSessionLayoutTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - sptr specificCallback_ = nullptr; - sptr scbSystemSession_; -}; - -void SCBSystemSessionLayoutTest::SetUpTestCase() {} - -void SCBSystemSessionLayoutTest::TearDownTestCase() {} - -void SCBSystemSessionLayoutTest::SetUp() -{ - SessionInfo info; - info.abilityName_ = "testSCBSystemSession1"; - info.moduleName_ = "testSCBSystemSession2"; - info.bundleName_ = "testSCBSystemSession3"; - scbSystemSession_ = sptr::MakeSptr(info, specificCallback_); -} - -void SCBSystemSessionLayoutTest::TearDown() -{ - scbSystemSession_ = nullptr; -} - -namespace { -/** - * @tc.name: UpdateWindowMode - * @tc.desc: check func UpdateWindowMode - * @tc.type: FUNC - */ -HWTEST_F(SCBSystemSessionLayoutTest, UpdateWindowMode, TestSize.Level1) -{ - scbSystemSession_->PresentFocusIfPointDown(); - scbSystemSession_->PresentFocusIfNeed(2, 0); - ASSERT_EQ(WSError::WS_OK, scbSystemSession_->SetSystemSceneBlockingFocus(true)); - WSRect rect = { 0, 0, 0, 0 }; - scbSystemSession_->UpdatePointerArea(rect); - auto ret = scbSystemSession_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED); - ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, ret); -} - -/** - * @tc.name: NotifyClientToUpdateRect02 - * @tc.desc: check func NotifyClientToUpdateRect - * @tc.type: FUNC - */ -HWTEST_F(SCBSystemSessionLayoutTest, NotifyClientToUpdateRect02, TestSize.Level1) -{ - auto specificCallback1 = sptr::MakeSptr(); - SessionInfo info; - sptr scbSystemSession = sptr::MakeSptr(info, specificCallback1); - UpdateAvoidAreaCallback onUpdateAvoidArea; - ClearDisplayStatusBarTemporarilyFlags onClearDisplayStatusBarTemporarilyFlags; - scbSystemSession->specificCallback_ = specificCallback1; - scbSystemSession->specificCallback_->onUpdateAvoidArea_ = onUpdateAvoidArea; - scbSystemSession->specificCallback_->onClearDisplayStatusBarTemporarilyFlags_ = - onClearDisplayStatusBarTemporarilyFlags; - auto ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); - - scbSystemSession->specificCallback_->onClearDisplayStatusBarTemporarilyFlags_ = nullptr; - ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); - - scbSystemSession->specificCallback_->onUpdateAvoidArea_ = nullptr; - ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); - - scbSystemSession->specificCallback_->onClearDisplayStatusBarTemporarilyFlags_ = - onClearDisplayStatusBarTemporarilyFlags; - ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); - - scbSystemSession->specificCallback_ = nullptr; - ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); -} - -/** - * @tc.name: NotifyClientToUpdateRect03 - * @tc.desc: check func NotifyClientToUpdateRect - * @tc.type: FUNC - */ -HWTEST_F(SCBSystemSessionLayoutTest, NotifyClientToUpdateRect03, TestSize.Level1) -{ - sptr property = sptr::MakeSptr(); - property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL); - - auto ret = scbSystemSession_->SetSessionProperty(property); - ASSERT_EQ(WSError::WS_OK, ret); - scbSystemSession_->isKeyboardPanelEnabled_ = true; - ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); - - scbSystemSession_->isKeyboardPanelEnabled_ = false; - ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); - - scbSystemSession_->isKeyboardPanelEnabled_ = true; - ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); - - scbSystemSession_->isKeyboardPanelEnabled_ = false; - ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); - - property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - ret = scbSystemSession_->SetSessionProperty(property); - ASSERT_EQ(WSError::WS_OK, ret); - scbSystemSession_->isKeyboardPanelEnabled_ = true; - ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); - - scbSystemSession_->isKeyboardPanelEnabled_ = false; - ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); - - scbSystemSession_->isKeyboardPanelEnabled_ = true; - ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); - - scbSystemSession_->isKeyboardPanelEnabled_ = false; - ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); - - scbSystemSession_->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG); - ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); -} - -/** - * @tc.name: NotifyClientToUpdateRect04 - * @tc.desc: check func NotifyClientToUpdateRect - * @tc.type: FUNC - */ -HWTEST_F(SCBSystemSessionLayoutTest, NotifyClientToUpdateRect04, TestSize.Level1) -{ - scbSystemSession_->sessionStage_ = sptr::MakeSptr(); - auto ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr); - ASSERT_EQ(WSError::WS_OK, ret); -} -} // namespace -} // namespace Rosen -} // namespace OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/scene_session_layout_test.cpp b/window_scene/test/unittest/scene_session_layout_test.cpp deleted file mode 100644 index 4c5f28cb9d2072437ee283741eea83d635897e6e..0000000000000000000000000000000000000000 --- a/window_scene/test/unittest/scene_session_layout_test.cpp +++ /dev/null @@ -1,989 +0,0 @@ -/* - * 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 - -#include "display_manager.h" -#include "input_event.h" -#include "key_event.h" -#include "mock/mock_session_stage.h" -#include "pointer_event.h" -#include "session/host/include/main_session.h" -#include "session/host/include/scene_session.h" -#include "session/host/include/sub_session.h" -#include "session/host/include/system_session.h" -#include "window_helper.h" -#include "wm_common.h" - -using namespace testing; -using namespace testing::ext; -namespace OHOS { -namespace Rosen { -class SceneSessionLayoutTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - -private: - sptr mockSessionStage_ = nullptr; -}; - -void SceneSessionLayoutTest::SetUpTestCase() {} - -void SceneSessionLayoutTest::TearDownTestCase() {} - -void SceneSessionLayoutTest::SetUp() -{ - mockSessionStage_ = sptr::MakeSptr(); -} - -void SceneSessionLayoutTest::TearDown() {} - -namespace { -/** - * @tc.name: UpdateRect01 - * @tc.desc: normal function - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, UpdateRect01, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "UpdateRect01"; - info.bundleName_ = "UpdateRect01"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->isActive_ = true; - - sptr property = sptr::MakeSptr(); - property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - - sceneSession->SetSessionProperty(property); - WSRect rect({ 1, 1, 1, 1 }); - SizeChangeReason reason = SizeChangeReason::UNDEFINED; - WSError result = sceneSession->UpdateRect(rect, reason, "SceneSessionLayoutTest"); - ASSERT_EQ(result, WSError::WS_OK); -} - -/** - * @tc.name: UpdateRect02 - * @tc.desc: normal function - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, UpdateRect02, TestSize.Level0) -{ - SessionInfo info; - info.abilityName_ = "UpdateRect02"; - info.bundleName_ = "UpdateRect02"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->isActive_ = true; - - sptr property = sptr::MakeSptr(); - property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - - sceneSession->SetSessionProperty(property); - WSRect rect({ 1, 1, 1, 1 }); - SizeChangeReason reason = SizeChangeReason::UNDEFINED; - WSError result = sceneSession->UpdateRect(rect, reason, "SceneSessionLayoutTest"); - ASSERT_EQ(result, WSError::WS_OK); - - sceneSession->GetLayoutController()->SetSessionRect(rect); - result = sceneSession->UpdateRect(rect, reason, "SceneSessionLayoutTest"); - ASSERT_EQ(result, WSError::WS_OK); - - sceneSession->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG_END); - result = sceneSession->UpdateRect(rect, reason, "SceneSessionLayoutTest"); - ASSERT_EQ(result, WSError::WS_OK); - - WSRect rect2({ 0, 0, 0, 0 }); - result = sceneSession->UpdateRect(rect2, reason, "SceneSessionLayoutTest"); - ASSERT_EQ(result, WSError::WS_OK); -} - -/** - * @tc.name: UpdateRect03 - * @tc.desc: UpdateRect - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, UpdateRect03, TestSize.Level0) -{ - SessionInfo info; - info.abilityName_ = "UpdateRect03"; - info.bundleName_ = "UpdateRect03"; - info.windowType_ = static_cast(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); - sptr session = sptr::MakeSptr(info, nullptr); - SizeChangeReason reason = SizeChangeReason::UNDEFINED; - - WSRect rect = { 200, 200, 200, 200 }; - session->GetLayoutController()->SetSessionRect(rect); - session->SetClientRect(rect); - EXPECT_EQ(session->UpdateRect(rect, reason, "SceneSessionLayoutTest"), WSError::WS_OK); - - rect.posX_ = 100; - rect.posY_ = 100; - rect.width_ = 800; - rect.height_ = 800; - session->GetLayoutController()->SetSessionRect(rect); - EXPECT_EQ(session->UpdateRect(rect, reason, "SceneSessionLayoutTest"), WSError::WS_OK); -} - -/** - * @tc.name: NotifyClientToUpdateRect01 - * @tc.desc: NotifyClientToUpdateRect - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, NotifyClientToUpdateRect01, TestSize.Level0) -{ - SessionInfo info; - info.abilityName_ = "NotifyClientToUpdateRect01"; - info.bundleName_ = "NotifyClientToUpdateRect01"; - info.windowType_ = 1; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sptr mockSessionStage = sptr::MakeSptr(); - sceneSession->dirtyFlags_ |= static_cast(SessionUIDirtyFlag::RECT); - sceneSession->sessionStage_ = mockSessionStage; - auto ret = sceneSession->NotifyClientToUpdateRect("SceneSessionLayoutTest", nullptr); - ASSERT_EQ(ret, WSError::WS_OK); -} - -/** - * @tc.name: UpdateRectInner - * @tc.desc: UpdateRectInner - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, UpdateRectInner01, TestSize.Level0) -{ - SessionInfo info; - info.abilityName_ = "UpdateRectInner01"; - info.bundleName_ = "UpdateRectInner01"; - info.screenId_ = 20; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - SessionUIParam uiParam; - SizeChangeReason reason = SizeChangeReason::UNDEFINED; - sceneSession->SetForegroundInteractiveStatus(true); - - uiParam.needSync_ = true; - uiParam.rect_ = { 0, 0, 1, 1 }; - - sceneSession->GetLayoutController()->SetSessionRect({ 1, 1, 1, 1 }); - sceneSession->isVisible_ = true; - ASSERT_EQ(false, sceneSession->UpdateRectInner(uiParam, reason)); -} - -/** - * @tc.name: NotifyClientToUpdateRect - * @tc.desc: NotifyClientToUpdateRect function01 - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, NotifyClientToUpdateRect, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "NotifyClientToUpdateRect"; - info.bundleName_ = "NotifyClientToUpdateRect"; - info.isSystem_ = false; - sptr session = sptr::MakeSptr(info, nullptr); - session->moveDragController_ = nullptr; - session->isKeyboardPanelEnabled_ = false; - session->Session::UpdateSizeChangeReason(SizeChangeReason::UNDEFINED); - session->Session::SetSessionState(SessionState::STATE_CONNECT); - session->specificCallback_ = nullptr; - session->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG); - EXPECT_EQ(WSError::WS_OK, session->NotifyClientToUpdateRect("SceneSessionLayoutTest", nullptr)); - - UpdateAvoidAreaCallback func = [](const int32_t& persistentId) { return; }; - auto specificCallback = sptr::MakeSptr(); - specificCallback->onUpdateAvoidArea_ = func; - session->specificCallback_ = specificCallback; - session->Session::UpdateSizeChangeReason(SizeChangeReason::RECOVER); - EXPECT_EQ(WSError::WS_OK, session->NotifyClientToUpdateRect("SceneSessionLayoutTest", nullptr)); -} - -/** - * @tc.name: CheckAspectRatioValid - * @tc.desc: CheckAspectRatioValid function01 - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, CheckAspectRatioValid, TestSize.Level0) -{ - SessionInfo info; - info.abilityName_ = "CheckAspectRatioValid"; - info.bundleName_ = "CheckAspectRatioValid"; - info.isSystem_ = false; - sptr session = sptr::MakeSptr(info, nullptr); - WindowLimits windowLimits; - ASSERT_NE(session->GetSessionProperty(), nullptr); - session->GetSessionProperty()->SetWindowLimits(windowLimits); - - SystemSessionConfig systemConfig; - systemConfig.isSystemDecorEnable_ = false; - session->SetSystemConfig(systemConfig); - EXPECT_EQ(false, session->IsDecorEnable()); - - windowLimits.minWidth_ = 0; - windowLimits.minHeight_ = 0; - EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f)); - - windowLimits.minWidth_ = 1; - windowLimits.maxHeight_ = 0; - windowLimits.minHeight_ = 1; - windowLimits.maxWidth_ = 0; - EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f)); - - windowLimits.maxHeight_ = 1; - windowLimits.maxWidth_ = 1; - EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(1.0f)); - - windowLimits.maxHeight_ = 10000; - windowLimits.minHeight_ = -10000; - EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f)); - - windowLimits.maxHeight_ = 10000; - windowLimits.minHeight_ = -10000; - EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f)); - - sptr property = sptr::MakeSptr(); - WindowLimits limits = { 8, 1, 6, 1, 1, 1.0f, 1.0f }; - property->SetWindowLimits(limits); - session->SetSessionProperty(property); - EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, session->SetAspectRatio(0.1f)); - EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, session->SetAspectRatio(10.0f)); -} - -/** - * @tc.name: CheckAspectRatioValid02 - * @tc.desc: CheckAspectRatioValid - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, CheckAspectRatioValid02, TestSize.Level0) -{ - SessionInfo info; - info.abilityName_ = "CheckAspectRatioValid02"; - info.bundleName_ = "CheckAspectRatioValid02"; - info.isSystem_ = false; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sptr property = sptr::MakeSptr(); - sceneSession->SetSessionProperty(property); - - WindowLimits windowLimits; - sceneSession->GetSessionProperty()->SetWindowLimits(windowLimits); - - SystemSessionConfig systemConfig; - systemConfig.isSystemDecorEnable_ = false; - sceneSession->SetSystemConfig(systemConfig); - EXPECT_EQ(false, sceneSession->IsDecorEnable()); - - windowLimits.minWidth_ = 0; - windowLimits.minHeight_ = 0; - EXPECT_EQ(WSError::WS_OK, sceneSession->SetAspectRatio(0.0f)); - - windowLimits.minWidth_ = 1; - windowLimits.minHeight_ = 2; - EXPECT_EQ(WSError::WS_OK, sceneSession->SetAspectRatio(0.0f)); - - windowLimits.minWidth_ = 2; - windowLimits.minHeight_ = 1; - EXPECT_EQ(WSError::WS_OK, sceneSession->SetAspectRatio(0.0f)); - - windowLimits.minWidth_ = 1; - windowLimits.minHeight_ = 2; - EXPECT_EQ(WSError::WS_OK, sceneSession->SetAspectRatio(1.0f)); -} - -/** - * @tc.name: NotifyClientToUpdateRectTask - * @tc.desc: NotifyClientToUpdateRectTask function - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, NotifyClientToUpdateRectTask, TestSize.Level0) -{ - SessionInfo info; - info.abilityName_ = "NotifyClientToUpdateRectTask"; - info.bundleName_ = "NotifyClientToUpdateRectTask"; - info.isSystem_ = true; - - sptr session = sptr::MakeSptr(info, nullptr); - session->moveDragController_ = nullptr; - session->isKeyboardPanelEnabled_ = false; - session->SetSessionRect({ 0, 0, 800, 800 }); - - session->Session::UpdateSizeChangeReason(SizeChangeReason::UNDEFINED); - EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, - session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr)); - session->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE); - EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, - session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr)); - session->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG_MOVE); - EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, - session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr)); - session->Session::UpdateSizeChangeReason(SizeChangeReason::RESIZE); - EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, - session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr)); - session->Session::UpdateSizeChangeReason(SizeChangeReason::RECOVER); - EXPECT_EQ(session->GetSizeChangeReason(), SizeChangeReason::RECOVER); - EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, - session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr)); - - session->moveDragController_ = sptr::MakeSptr(2024, session->GetWindowType()); - session->moveDragController_->isStartDrag_ = true; - session->moveDragController_->isStartMove_ = true; - session->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE); - session->isKeyboardPanelEnabled_ = true; - info.windowType_ = static_cast(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE); - EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, - session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr)); - info.windowType_ = static_cast(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); - EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, - session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr)); - - session->Session::UpdateSizeChangeReason(SizeChangeReason::UNDEFINED); - EXPECT_EQ(WSError::WS_ERROR_REPEAT_OPERATION, - session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr)); - - session->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE); - info.windowType_ = static_cast(WindowType::WINDOW_TYPE_KEYBOARD_PANEL); - EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, - session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr)); - session->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG_MOVE); - info.windowType_ = static_cast(WindowType::WINDOW_TYPE_KEYBOARD_PANEL); - EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, - session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr)); -} - -/** - * @tc.name: HandleActionUpdateWindowLimits - * @tc.desc: normal function - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, HandleActionUpdateWindowLimits, TestSize.Level1) -{ - SessionInfo info; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sptr property = sptr::MakeSptr(); - - WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_WINDOW_LIMITS; - WMError res = sceneSession->HandleActionUpdateWindowLimits(property, action); - EXPECT_EQ(WMError::WM_OK, res); -} - -/** - * @tc.name: SetAspectRatio2 - * @tc.desc: normal function - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, SetAspectRatio2, TestSize.Level0) -{ - SessionInfo info; - info.abilityName_ = "SetAspectRatio2"; - info.bundleName_ = "SetAspectRatio2"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->isActive_ = true; - - float ratio = 0.0001; - sceneSession->moveDragController_ = nullptr; - auto result = sceneSession->SetAspectRatio(ratio); - ASSERT_EQ(result, WSError::WS_OK); - ASSERT_EQ(sceneSession->GetAspectRatio(), ratio); - - sceneSession->moveDragController_ = sptr::MakeSptr(0, sceneSession->GetWindowType()); - result = sceneSession->SetAspectRatio(ratio); - ASSERT_EQ(result, WSError::WS_OK); - ASSERT_EQ(sceneSession->GetAspectRatio(), ratio); - - sptr property = sptr::MakeSptr(); - property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - sceneSession->SetSessionProperty(property); - result = sceneSession->SetAspectRatio(ratio); - ASSERT_EQ(result, WSError::WS_OK); - ASSERT_EQ(sceneSession->GetAspectRatio(), ratio); -} - -/** - * @tc.name: SetAspectRatio3 - * @tc.desc: normal function - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, SetAspectRatio3, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetAspectRatio3"; - info.bundleName_ = "SetAspectRatio3"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->isActive_ = true; - - float ratio = 0.1; - sptr property = sptr::MakeSptr(); - property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - sceneSession->SetSessionProperty(property); - WindowLimits limits; - limits.maxHeight_ = 10; - limits.minWidth_ = 1; - limits.minHeight_ = 1; - property->SetWindowLimits(limits); - auto result = sceneSession->SetAspectRatio(ratio); - ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM); -} - -/** - * @tc.name: SetAspectRatio4 - * @tc.desc: normal function - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, SetAspectRatio4, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetAspectRatio4"; - info.bundleName_ = "SetAspectRatio4"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->isActive_ = true; - sptr property = sptr::MakeSptr(); - property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - sceneSession->SetSessionProperty(property); - - float ratio = 0.1; - WindowLimits limits; - limits.maxHeight_ = 10; - limits.minWidth_ = 10; - property->SetWindowLimits(limits); - auto result = sceneSession->SetAspectRatio(ratio); - ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM); -} - -/** - * @tc.name: SetAspectRatio5 - * @tc.desc: test for aspectRatio NearZero - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, SetAspectRatio5, TestSize.Level0) -{ - SessionInfo info; - info.abilityName_ = "SetAspectRatio5"; - info.bundleName_ = "SetAspectRatio5"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->isActive_ = true; - - float ratio = 0.0001; - auto result = sceneSession->SetAspectRatio(ratio); - ASSERT_EQ(result, WSError::WS_OK); - - sptr property = sptr::MakeSptr(); - property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - sceneSession->SetSessionProperty(property); - result = sceneSession->SetAspectRatio(ratio); - ASSERT_EQ(result, WSError::WS_OK); - ASSERT_EQ(sceneSession->GetAspectRatio(), ratio); -} - -/** - * @tc.name: SetAspectRatio6 - * @tc.desc: test for aspectRatio is smaller than minWidth/maxHeight - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, SetAspectRatio6, TestSize.Level0) -{ - SessionInfo info; - info.abilityName_ = "SetAspectRatio6"; - info.bundleName_ = "SetAspectRatio6"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->isActive_ = true; - - float ratio = 2.5; - sptr property = sptr::MakeSptr(); - property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - WindowLimits limits; - limits.maxWidth_ = 3000; - limits.maxHeight_ = 3000; - limits.minWidth_ = 2000; - limits.minHeight_ = 2000; - property->SetWindowLimits(limits); - sceneSession->SetSessionProperty(property); - auto result = sceneSession->SetAspectRatio(ratio); - ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM); -} - -/** - * @tc.name: SetAspectRatio7 - * @tc.desc: test for aspectRatio is smaller than minWidth/maxHeight - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, SetAspectRatio7, TestSize.Level0) -{ - SessionInfo info; - info.abilityName_ = "SetAspectRatio7"; - info.bundleName_ = "SetAspectRatio7"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->isActive_ = true; - - float ratio = 0.1; - sptr property = sptr::MakeSptr(); - property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - WindowLimits limits; - limits.maxWidth_ = 3000; - limits.maxHeight_ = 3000; - limits.minWidth_ = 2000; - limits.minHeight_ = 2000; - property->SetWindowLimits(limits); - sceneSession->SetSessionProperty(property); - auto result = sceneSession->SetAspectRatio(ratio); - ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM); -} - -/** - * @tc.name: SetAspectRatio8 - * @tc.desc: normal function - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, SetAspectRatio8, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetAspectRatio8"; - info.bundleName_ = "SetAspectRatio8"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->isActive_ = true; - - float ratio = 0.1; - sptr property = sptr::MakeSptr(); - property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - WindowLimits limits; - limits.maxHeight_ = 10; - limits.minWidth_ = 0; - property->SetWindowLimits(limits); - sceneSession->SetSessionProperty(property); - auto result = sceneSession->SetAspectRatio(ratio); - ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM); -} - -/** - * @tc.name: SetAspectRatio9 - * @tc.desc: normal function - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, SetAspectRatio9, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetAspectRatio9"; - info.bundleName_ = "SetAspectRatio9"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->isActive_ = true; - - float ratio = 0.1; - sptr property = sptr::MakeSptr(); - property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - WindowLimits limits; - limits.maxHeight_ = 10; - limits.minWidth_ = 10; - property->SetWindowLimits(limits); - sceneSession->SetSessionProperty(property); - auto result = sceneSession->SetAspectRatio(ratio); - ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM); -} - -/** - * @tc.name: SaveAspectRatio - * @tc.desc: SaveAspectRatio - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, SaveAspectRatio, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "Background01"; - info.bundleName_ = "IsFloatingWindowAppType"; - info.windowType_ = 1; - sptr sceneSession; - sceneSession = sptr::MakeSptr(info, nullptr); - ASSERT_EQ(true, sceneSession->SaveAspectRatio(0.1)); - - sceneSession->sessionInfo_.bundleName_ = ""; - sceneSession->sessionInfo_.moduleName_ = ""; - sceneSession->sessionInfo_.abilityName_ = ""; - ASSERT_EQ(false, sceneSession->SaveAspectRatio(0.1)); -} - -/** - * @tc.name: AdjustRectByAspectRatio - * @tc.desc: AdjustRectByAspectRatio - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, AdjustRectByAspectRatio, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "Background01"; - info.bundleName_ = "IsFloatingWindowAppType"; - info.windowType_ = 1; - sptr sceneSession; - sceneSession = sptr::MakeSptr(info, nullptr); - WSRect originalRect = { 0, 0, 0, 0 }; - ASSERT_EQ(false, sceneSession->AdjustRectByAspectRatio(originalRect)); -} - -/** - * To test the function call - * - * @tc.name: ActivateDragBySystem - * @tc.desc: ActivateDragBySystem function - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, ActivateDragBySystem, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "ActivateDragBySystem"; - info.bundleName_ = "ActivateDragBySystem"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - auto ret = sceneSession->ActivateDragBySystem(true); - EXPECT_EQ(WMError::WM_OK, ret); -} - -/** - * To test the drag activated settings, and validate the draggable results. - * Expect the results: - * enableDrag: true, dragActivated: true => true - * enableDrag: false, dragActivated: true => false - * enableDrag: true, dragActivated: false => false - * enableDrag: false, dragActivated: false => false - * - * @tc.name: CheckDragActivatedSettings - * @tc.desc: CheckDragActivatedSettings - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, CheckDragActivatedSettings, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "CheckDragActivatedSettings"; - info.bundleName_ = "CheckDragActivatedSettings"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - - sceneSession->ActivateDragBySystem(true); - sceneSession->GetSessionProperty()->SetDragEnabled(true); - ASSERT_EQ(true, sceneSession->IsDragAccessible()); - - sceneSession->GetSessionProperty()->SetDragEnabled(false); - ASSERT_EQ(false, sceneSession->IsDragAccessible()); - - sceneSession->ActivateDragBySystem(false); - sceneSession->GetSessionProperty()->SetDragEnabled(true); - ASSERT_EQ(false, sceneSession->IsDragAccessible()); - - sceneSession->GetSessionProperty()->SetDragEnabled(false); - ASSERT_EQ(false, sceneSession->IsDragAccessible()); -} - -/** - * @tc.name: NotifySingleHandTransformChange - * @tc.desc: NotifySingleHandTransformChange - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, NotifySingleHandTransformChange, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "NotifySingleHandTransformChange"; - info.bundleName_ = "NotifySingleHandTransformChange"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - - SingleHandTransform testTransform; - sceneSession->state_ = SessionState::STATE_BACKGROUND; - sceneSession->NotifySingleHandTransformChange(testTransform); - - sceneSession->state_ = SessionState::STATE_FOREGROUND; - mockSessionStage_ = nullptr; - sceneSession->sessionStage_ = mockSessionStage_; - sceneSession->NotifySingleHandTransformChange(testTransform); - - mockSessionStage_ = sptr::MakeSptr(); - sceneSession->sessionStage_ = mockSessionStage_; - sceneSession->NotifySingleHandTransformChange(testTransform); - ASSERT_NE(100, testTransform.posX); -} - -/** - * @tc.name: GetSessionGlobalRectWithSingleHandScale - * @tc.desc: GetSessionGlobalRectWithSingleHandScale - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, GetSessionGlobalRectWithSingleHandScale, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "GetSessionGlobalRectWithSingleHandScale"; - info.bundleName_ = "GetSessionGlobalRectWithSingleHandScale"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - - SingleHandTransform testTransform; - WSRect globalRect = { 100, 100, 800, 800 }; - sceneSession->SetSessionGlobalRect(globalRect); - sceneSession->SetSingleHandTransform(testTransform); - ASSERT_EQ(sceneSession->GetSessionGlobalRect().posX_, - sceneSession->GetSessionGlobalRectWithSingleHandScale().posX_); - - testTransform.posX = 10; - testTransform.posY = 10; - testTransform.scaleX = 0.75f; - testTransform.scaleY = 0.75f; - sceneSession->SetSingleHandTransform(testTransform); - ASSERT_NE(sceneSession->GetSessionGlobalRect().posX_, - sceneSession->GetSessionGlobalRectWithSingleHandScale().posX_); -} - -/** - * @tc.name: IsNeedConvertToRelativeRect - * @tc.desc: IsNeedConvertToRelativeRect - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, IsNeedConvertToRelativeRect, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "IsNeedConvertToRelativeRect"; - info.bundleName_ = "IsNeedConvertToRelativeRect"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - sceneSession->moveDragController_ = - sptr::MakeSptr(sceneSession->GetPersistentId(), sceneSession->GetWindowType()); - info.abilityName_ = "IsNeedConvertToRelativeRect_subSession"; - info.bundleName_ = "IsNeedConvertToRelativeRect_subSession"; - sptr subSceneSession = sptr::MakeSptr(info, nullptr); - subSceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); - sceneSession->subSession_.emplace_back(subSceneSession); - subSceneSession->parentSession_ = sceneSession; - - ASSERT_EQ(sceneSession->IsNeedConvertToRelativeRect(SizeChangeReason::MAXIMIZE), false); - ASSERT_EQ(sceneSession->IsNeedConvertToRelativeRect(SizeChangeReason::DRAG_MOVE), true); - - sceneSession->moveDragController_->isStartMove_ = true; - sceneSession->moveDragController_->isStartDrag_ = false; - ASSERT_EQ(subSceneSession->IsNeedConvertToRelativeRect(SizeChangeReason::MAXIMIZE), false); - - sceneSession->moveDragController_->isStartMove_ = false; - sceneSession->moveDragController_->isStartDrag_ = true; - ASSERT_EQ(subSceneSession->IsNeedConvertToRelativeRect(SizeChangeReason::MAXIMIZE), false); -} - -/** - * @tc.name: IsAnyParentSessionDragMoving - * @tc.desc: IsAnyParentSessionDragMoving - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, IsAnyParentSessionDragMoving, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "IsAnyParentSessionDragMoving"; - info.bundleName_ = "IsAnyParentSessionDragMoving"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - sceneSession->moveDragController_ = - sptr::MakeSptr(sceneSession->GetPersistentId(), sceneSession->GetWindowType()); - info.abilityName_ = "IsAnyParentSessionDragMoving_subSession"; - info.bundleName_ = "IsAnyParentSessionDragMoving_subSession"; - sptr subSceneSession = sptr::MakeSptr(info, nullptr); - subSceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); - - subSceneSession->parentSession_ = nullptr; - ASSERT_EQ(subSceneSession->IsAnyParentSessionDragMoving(), false); - sceneSession->moveDragController_->isStartMove_ = true; - ASSERT_EQ(sceneSession->IsAnyParentSessionDragMoving(), true); - - sceneSession->subSession_.emplace_back(subSceneSession); - subSceneSession->parentSession_ = sceneSession; - ASSERT_EQ(subSceneSession->IsAnyParentSessionDragMoving(), true); -} - -/** - * @tc.name: IsAnyParentSessionDragZooming - * @tc.desc: IsAnyParentSessionDragZooming - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, IsAnyParentSessionDragZooming, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "IsAnyParentSessionDragZooming"; - info.bundleName_ = "IsAnyParentSessionDragZooming"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - sceneSession->moveDragController_ = - sptr::MakeSptr(sceneSession->GetPersistentId(), sceneSession->GetWindowType()); - info.abilityName_ = "IsAnyParentSessionDragZooming_subSession"; - info.bundleName_ = "IsAnyParentSessionDragZooming_subSession"; - sptr subSceneSession = sptr::MakeSptr(info, nullptr); - subSceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); - - subSceneSession->parentSession_ = nullptr; - ASSERT_EQ(subSceneSession->IsAnyParentSessionDragZooming(), false); - sceneSession->moveDragController_->isStartDrag_ = true; - ASSERT_EQ(sceneSession->IsAnyParentSessionDragZooming(), true); - - sceneSession->subSession_.emplace_back(subSceneSession); - subSceneSession->parentSession_ = sceneSession; - ASSERT_EQ(subSceneSession->IsAnyParentSessionDragZooming(), true); -} - -/** - * @tc.name: HandleSubSessionSurfaceNode - * @tc.desc: HandleSubSessionSurfaceNode - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, HandleSubSessionSurfaceNode, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "HandleSubSessionSurfaceNode"; - info.bundleName_ = "HandleSubSessionSurfaceNode"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - sceneSession->moveDragController_ = - sptr::MakeSptr(sceneSession->GetPersistentId(), sceneSession->GetWindowType()); - info.abilityName_ = "HandleSubSessionSurfaceNode_subSession"; - info.bundleName_ = "HandleSubSessionSurfaceNode_subSession"; - sptr subSceneSession = sptr::MakeSptr(info, nullptr); - subSceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); - sceneSession->subSession_.emplace_back(subSceneSession); - subSceneSession->parentSession_ = sceneSession; - sceneSession->displayIdSetDuringMoveTo_.insert(888); - subSceneSession->displayIdSetDuringMoveTo_.insert(888); - - subSceneSession->NotifyFollowParentMultiScreenPolicy(false); - sceneSession->HandleSubSessionSurfaceNode(false, 0); - ASSERT_NE(0, subSceneSession->displayIdSetDuringMoveTo_.size()); - subSceneSession->NotifyFollowParentMultiScreenPolicy(true); - sceneSession->HandleSubSessionSurfaceNode(true, 0); - ASSERT_NE(0, subSceneSession->displayIdSetDuringMoveTo_.size()); - sceneSession->HandleSubSessionSurfaceNode(false, 0); - ASSERT_EQ(0, subSceneSession->displayIdSetDuringMoveTo_.size()); -} - -/** - * @tc.name: HandleSubSessionCrossNode - * @tc.desc: HandleSubSessionCrossNode - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, HandleSubSessionCrossNode, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "HandleSubSessionCrossNode"; - info.bundleName_ = "HandleSubSessionCrossNode"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - info.abilityName_ = "HandleSubSessionCrossNode_subSession"; - info.bundleName_ = "HandleSubSessionCrossNode_subSession"; - sptr subSceneSession = sptr::MakeSptr(info, nullptr); - subSceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); - - sceneSession->SetDragStart(true); - sceneSession->HandleSubSessionCrossNode(SizeChangeReason::UNDEFINED); - ASSERT_EQ(sceneSession->IsDragStart(), true); - sceneSession->HandleSubSessionCrossNode(SizeChangeReason::DRAG); - ASSERT_EQ(sceneSession->IsDragStart(), true); - sceneSession->HandleSubSessionCrossNode(SizeChangeReason::DRAG_END); - ASSERT_EQ(sceneSession->IsDragStart(), false); - - sceneSession->HandleSubSessionCrossNode(SizeChangeReason::DRAG); - ASSERT_EQ(sceneSession->IsDragStart(), true); - sceneSession->subSession_.emplace_back(subSceneSession); - subSceneSession->parentSession_ = sceneSession; - sceneSession->HandleSubSessionCrossNode(SizeChangeReason::DRAG_END); - ASSERT_EQ(sceneSession->IsDragStart(), false); - sceneSession->HandleSubSessionCrossNode(SizeChangeReason::DRAG_MOVE); - ASSERT_EQ(sceneSession->IsDragStart(), true); -} - - -/** - * @tc.name: SetMoveAvailableArea01 - * @tc.desc: SetMoveAvailableArea01 - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, SetMoveAvailableArea01, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetMoveAvailableArea01"; - info.bundleName_ = "SetMoveAvailableArea01"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - - WSError res = sceneSession->SetMoveAvailableArea(-1); - EXPECT_EQ(res, WSError::WS_ERROR_INVALID_DISPLAY); - - sceneSession->moveDragController_ = sptr::MakeSptr(2024, sceneSession->GetWindowType()); - int32_t screenId = 0; - sceneSession->SetScreenId(screenId); - res = sceneSession->SetMoveAvailableArea(0); - EXPECT_EQ(res, WSError::WS_OK); - - sptr currentScreenSession = - ScreenSessionManager::GetInstance().GetOrCreateScreenSession(0); - ASSERT_NE(currentScreenSession, nullptr); - uint32_t currentScreenHeight = currentScreenSession->GetScreenProperty().GetBounds().rect_.height_; - DMRect statusBarRect = sceneSession->CalcRectForStatusBar(); - int32_t dockHeight = sceneSession->GetDockHeight(); - if (PcFoldScreenManager::GetInstance().IsHalfFolded(screenId)) { - sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); - DMRect availableArea; - DMError ret = DisplayManager::GetInstance().GetExpandAvailableArea( - sceneSession->GetSessionProperty()->GetDisplayId(), availableArea); - if (ret != DMError::DM_OK) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "Failed to get available area, ret: %{public}d", ret); - } - EXPECT_EQ(sceneSession->moveDragController_->moveAvailableArea_, availableArea); - EXPECT_EQ(sceneSession->moveDragController_->moveAvailableArea_.height_, - currentScreenHeight - statusBarRect.height_ - dockHeight); - } -} - -/** - * @tc.name: SetMoveAvailableArea02 - * @tc.desc: SetMoveAvailableArea02 - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionLayoutTest, SetMoveAvailableArea02, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetMoveAvailableArea02"; - info.bundleName_ = "SetMoveAvailableArea02"; - sptr specificCallback_ = - sptr::MakeSptr(); - EXPECT_NE(specificCallback_, nullptr); - sptr sceneSession = sptr::MakeSptr(info, specificCallback_); - - WSRect rect({0, 0, 50, 50}); - sceneSession->GetLayoutController()->SetSessionRect(rect); - sceneSession->specificCallback_->onGetSceneSessionVectorByTypeAndDisplayId_ = - [](WindowType type, uint64_t displayId) -> std::vector> { - std::vector> vec; - vec.push_back(sceneSession); - return vec; - }; - - SystemSessionConfig systemConfig; - int32_t screenId = 0; - sceneSession->SetScreenId(screenId); - - sptr property = sptr::MakeSptr(); - property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - sceneSession->SetSessionProperty(property); - ScreenSessionConfig config; - sptr screenSession = - sptr::MakeSptr(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT); - ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(screenId, screenSession)); - - systemConfig.windowUIType_ = WindowUIType::PHONE_WINDOW; - sceneSession->SetSystemConfig(systemConfig); - sceneSession->moveDragController_ = sptr::MakeSptr(2024, sceneSession->GetWindowType()); - WSError res = sceneSession->SetMoveAvailableArea(0); - EXPECT_EQ(res, WSError::WS_OK); - - systemConfig.windowUIType_ = WindowUIType::PC_WINDOW; - sceneSession->SetSystemConfig(systemConfig); - sceneSession->moveDragController_ = sptr::MakeSptr(2024, sceneSession->GetWindowType()); - res = sceneSession->SetMoveAvailableArea(0); - EXPECT_EQ(res, WSError::WS_OK); -} -} // namespace -} // namespace Rosen -} // namespace OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/scene_session_manager_layout_test.cpp b/window_scene/test/unittest/scene_session_manager_layout_test.cpp deleted file mode 100644 index 3eeaa4520102a22f801931f03dfa4711ea4ac703..0000000000000000000000000000000000000000 --- a/window_scene/test/unittest/scene_session_manager_layout_test.cpp +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Copyright (c) 2025 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 "interfaces/include/ws_common.h" -#include "iremote_object_mocker.h" -#include "screen_session_manager_client/include/screen_session_manager_client.h" -#include "session_manager/include/scene_session_manager.h" -#include "session_info.h" -#include "session/host/include/scene_session.h" - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace Rosen { -namespace { -const std::string EMPTY_DEVICE_ID = ""; -constexpr float SINGLE_HAND_SCALE = 0.75f; -constexpr float SINGLE_HAND_DEFAULT_SCALE = 1.0f; -} // namespace -class SceneSessionManagerLayoutTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - static sptr ssm_; - -private: - static constexpr uint32_t WAIT_SYNC_IN_NS = 200000; -}; - -sptr SceneSessionManagerLayoutTest::ssm_ = nullptr; - -void SceneSessionManagerLayoutTest::SetUpTestCase() -{ - ssm_ = &SceneSessionManager::GetInstance(); -} - -void SceneSessionManagerLayoutTest::TearDownTestCase() -{ - ssm_ = nullptr; -} - -void SceneSessionManagerLayoutTest::SetUp() -{ - ssm_->sceneSessionMap_.clear(); -} - -void SceneSessionManagerLayoutTest::TearDown() -{ - usleep(WAIT_SYNC_IN_NS); - ssm_->sceneSessionMap_.clear(); -} - -namespace { -/** - * @tc.name: GetNormalSingleHandTransform - * @tc.desc: test function : GetNormalSingleHandTransform - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionManagerLayoutTest, GetNormalSingleHandTransform, TestSize.Level1) -{ - SingleHandTransform preTransform = ssm_->singleHandTransform_; - ssm_->singleHandTransform_.posX = 100; - EXPECT_EQ(100, ssm_->GetNormalSingleHandTransform().posX); - ssm_->singleHandTransform_ = preTransform; -} - -/** - * @tc.name: NotifySingleHandInfoChange_TestUIType - * @tc.desc: test function : NotifySingleHandInfoChange - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionManagerLayoutTest, NotifySingleHandInfoChange_TestUIType, TestSize.Level1) -{ - SingleHandTransform singleHandTransform; - ssm_->singleHandTransform_ = singleHandTransform; - SingleHandScreenInfo singleHandScreenInfo; - WSRect originRect, singleHandRect; - singleHandScreenInfo.scaleRatio = SINGLE_HAND_SCALE; - singleHandScreenInfo.mode = SingleHandMode::LEFT; - originRect = { 0, 0, 400, 600 }; - singleHandRect = { 0, 100, 200, 300 }; - ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear(); - sptr screenSession = sptr::MakeSptr(); - ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(0, screenSession)); - - ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; - ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect); - usleep(WAIT_SYNC_IN_NS); - EXPECT_NE(singleHandScreenInfo.scaleRatio, ssm_->singleHandTransform_.scaleX); - - ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; - ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(singleHandScreenInfo.scaleRatio, ssm_->singleHandTransform_.scaleX); - ssm_->singleHandTransform_ = singleHandTransform; -} - -/** - * @tc.name: NotifySingleHandInfoChange_TestWindowName - * @tc.desc: test function : NotifySingleHandInfoChange - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionManagerLayoutTest, NotifySingleHandInfoChange_TestWindowName, TestSize.Level1) -{ - SingleHandTransform singleHandTransform; - ssm_->singleHandTransform_ = singleHandTransform; - SessionInfo sessionInfo; - sessionInfo.bundleName_ = "OneHandModeBackground_testWindow"; - sessionInfo.abilityName_ = "OneHandModeBackground_testWindow"; - sptr sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr); - EXPECT_NE(sceneSession, nullptr); - sceneSession->property_->SetWindowName("OneHandModeBackground_testWindow"); - ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession }); - ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear(); - sptr screenSession = sptr::MakeSptr(); - ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(0, screenSession)); - SingleHandScreenInfo singleHandScreenInfo; - WSRect originRect, singleHandRect; - originRect = { 0, 0, 400, 600 }; - singleHandRect = { 0, 100, 200, 300 }; - singleHandScreenInfo.scaleRatio = SINGLE_HAND_SCALE; - singleHandScreenInfo.mode = SingleHandMode::LEFT; - ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; - ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect); - usleep(WAIT_SYNC_IN_NS); - EXPECT_NE(singleHandScreenInfo.scaleRatio, sceneSession->singleHandTransform_.scaleX); -} - -/** - * @tc.name: NotifySingleHandInfoChange_TestDisplayId - * @tc.desc: test function : NotifySingleHandInfoChange - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionManagerLayoutTest, NotifySingleHandInfoChange_TestDisplayId, TestSize.Level1) -{ - SingleHandTransform singleHandTransform; - ssm_->singleHandTransform_ = singleHandTransform; - SingleHandScreenInfo singleHandScreenInfo; - WSRect originRect, singleHandRect; - originRect = { 0, 0, 400, 600 }; - singleHandRect = { 0, 100, 200, 300 }; - singleHandScreenInfo.scaleRatio = SINGLE_HAND_SCALE; - singleHandScreenInfo.mode = SingleHandMode::LEFT; - ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; - ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear(); - sptr screenSession = sptr::MakeSptr(); - ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(0, screenSession)); - SessionInfo sessionInfo; - sessionInfo.bundleName_ = "NotifySingleHandInfoChange_TestDisplayId"; - sessionInfo.abilityName_ = "NotifySingleHandInfoChange_TestDisplayId"; - sptr sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr); - EXPECT_NE(sceneSession, nullptr); - - sceneSession->GetSessionProperty()->SetDisplayId(2025); - ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession }); - ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect); - usleep(WAIT_SYNC_IN_NS); - EXPECT_NE(singleHandScreenInfo.scaleRatio, sceneSession->singleHandTransform_.scaleX); - - sceneSession->GetSessionProperty()->SetDisplayId(0); - ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(singleHandScreenInfo.scaleRatio, sceneSession->singleHandTransform_.scaleY); - ssm_->singleHandTransform_ = singleHandTransform; -} - -/** - * @tc.name: NotifySingleHandInfoChange_TestMode - * @tc.desc: test function : NotifySingleHandInfoChange - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionManagerLayoutTest, NotifySingleHandInfoChange_TestMode, TestSize.Level1) -{ - SingleHandTransform singleHandTransform; - ssm_->singleHandTransform_ = singleHandTransform; - ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; - ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear(); - sptr screenSession = sptr::MakeSptr(); - ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(0, screenSession)); - - SingleHandScreenInfo singleHandScreenInfo; - WSRect originRect, singleHandRect; - originRect = { 0, 0, 400, 600 }; - singleHandRect = { 0, 100, 200, 300 }; - singleHandScreenInfo.scaleRatio = SINGLE_HAND_SCALE; - singleHandScreenInfo.mode = SingleHandMode::LEFT; - ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(100, ssm_->singleHandTransform_.posY); - EXPECT_EQ(0, ssm_->singleHandTransform_.posX); - ssm_->singleHandTransform_ = singleHandTransform; - - singleHandScreenInfo.mode = SingleHandMode::RIGHT; - singleHandRect = { 50, 100, 200, 300 }; - ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(100, ssm_->singleHandTransform_.posY); - EXPECT_EQ(50, ssm_->singleHandTransform_.posX); - ssm_->singleHandTransform_ = singleHandTransform; - - singleHandScreenInfo.scaleRatio = SINGLE_HAND_DEFAULT_SCALE; - singleHandScreenInfo.mode = SingleHandMode::MIDDLE; - singleHandRect = { 0, 0, 200, 300 }; - ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(0, ssm_->singleHandTransform_.posY); - EXPECT_EQ(0, ssm_->singleHandTransform_.posX); - ssm_->singleHandTransform_ = singleHandTransform; -} - -/** - * @tc.name: SetHasRootSceneRequestedVsyncFunc - * @tc.desc: SetHasRootSceneRequestedVsyncFunc - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionManagerLayoutTest, SetHasRootSceneRequestedVsyncFunc, TestSize.Level1) -{ - ssm_->SetHasRootSceneRequestedVsyncFunc(nullptr); - ASSERT_EQ(nullptr, ssm_->hasRootSceneRequestedVsyncFunc_); - ssm_->SetHasRootSceneRequestedVsyncFunc([] { - bool tempBool = false; - return tempBool; - }); - ASSERT_NE(nullptr, ssm_->hasRootSceneRequestedVsyncFunc_); -} - -/** - * @tc.name: HasRootSceneRequestedVsync - * @tc.desc: HasRootSceneRequestedVsync - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionManagerLayoutTest, HasRootSceneRequestedVsync, TestSize.Level1) -{ - bool tempBool = false; - ssm_->hasRootSceneRequestedVsyncFunc_ = nullptr; - EXPECT_EQ(WSError::WS_ERROR_NULLPTR, ssm_->HasRootSceneRequestedVsync(tempBool)); - EXPECT_EQ(false, tempBool); - - ssm_->SetHasRootSceneRequestedVsyncFunc([] { - bool tempInnerBool = true; - return tempInnerBool; - }); - EXPECT_EQ(WSError::WS_OK, ssm_->HasRootSceneRequestedVsync(tempBool)); - EXPECT_EQ(true, tempBool); -} - -/** - * @tc.name: SetRequestVsyncByRootSceneWhenModeChangeFunc - * @tc.desc: SetRequestVsyncByRootSceneWhenModeChangeFunc - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionManagerLayoutTest, SetRequestVsyncByRootSceneWhenModeChangeFunc, TestSize.Level1) -{ - ssm_->SetRequestVsyncByRootSceneWhenModeChangeFunc(nullptr); - ASSERT_EQ(nullptr, ssm_->requestVsyncByRootSceneWhenModeChangeFunc_); - ssm_->SetRequestVsyncByRootSceneWhenModeChangeFunc([](const std::shared_ptr& vsyncCallback) { - auto tempCallback = vsyncCallback; - }); - ASSERT_NE(nullptr, ssm_->requestVsyncByRootSceneWhenModeChangeFunc_); -} - -/** - * @tc.name: RequestVsyncByRootSceneWhenModeChange - * @tc.desc: RequestVsyncByRootSceneWhenModeChange - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionManagerLayoutTest, RequestVsyncByRootSceneWhenModeChange, TestSize.Level1) -{ - std::shared_ptr nextVsyncCallback = std::make_shared(); - ssm_->requestVsyncByRootSceneWhenModeChangeFunc_ = nullptr; - EXPECT_EQ(WSError::WS_ERROR_NULLPTR, ssm_->RequestVsyncByRootSceneWhenModeChange(nextVsyncCallback)); - ssm_->SetRequestVsyncByRootSceneWhenModeChangeFunc([](const std::shared_ptr& vsyncCallback) { - auto tempCallback = vsyncCallback; - }); - EXPECT_EQ(WSError::WS_OK, ssm_->RequestVsyncByRootSceneWhenModeChange(nextVsyncCallback)); -} - -/** - * @tc.name: GetDisplaySizeById_TestDisplayId - * @tc.desc: test function : GetDisplaySizeById - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionManagerLayoutTest, GetDisplaySizeById_TestDisplayId, TestSize.Level1) -{ - DisplayId displayId = 2025; - int32_t displayWidth = 0; - int32_t displayHeight = 0; - EXPECT_EQ(false, ssm_->GetDisplaySizeById(displayId, displayWidth, displayHeight)); - - displayId = 0; - EXPECT_EQ(true, ssm_->GetDisplaySizeById(displayId, displayWidth, displayHeight)); -} -} // namespace -} // namespace Rosen -} // namespace OHOS diff --git a/window_scene/test/unittest/session_layout_test.cpp b/window_scene/test/unittest/session_layout_test.cpp deleted file mode 100644 index 115b67a3d17d9cdf7447e268232e94d261d772fe..0000000000000000000000000000000000000000 --- a/window_scene/test/unittest/session_layout_test.cpp +++ /dev/null @@ -1,395 +0,0 @@ -/* - * 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 -#include - -#include "mock/mock_session_stage.h" -#include "mock/mock_window_event_channel.h" -#include "mock/mock_pattern_detach_callback.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_manager/include/scene_session_manager.h" -#include "session/host/include/session.h" -#include "session_info.h" -#include "key_event.h" -#include "wm_common.h" -#include "window_manager_hilog.h" - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace Rosen { -namespace { -const std::string UNDEFINED = "undefined"; -} - -class SessionLayoutTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - int32_t GetTaskCount(); - sptr ssm_; - -private: - RSSurfaceNode::SharedPtr CreateRSSurfaceNode(); - sptr session_ = nullptr; - static constexpr uint32_t WAIT_SYNC_IN_NS = 500000; - - class TLifecycleListener : public ILifecycleListener { - public: - virtual ~TLifecycleListener() {} - void OnActivation() override {} - void OnConnect() override {} - void OnForeground() override {} - void OnBackground() override {} - void OnDisconnect() override {} - void OnExtensionDied() override {} - void OnExtensionTimeout(int32_t errorCode) override {} - void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, - int64_t uiExtensionIdLevel) override - { - } - void OnDrawingCompleted() override {} - void OnAppRemoveStartingWindow() override {} - }; - std::shared_ptr lifecycleListener_ = std::make_shared(); - - sptr mockSessionStage_ = nullptr; - sptr mockEventChannel_ = nullptr; -}; - -void SessionLayoutTest::SetUpTestCase() {} - -void SessionLayoutTest::TearDownTestCase() {} - -void SessionLayoutTest::SetUp() -{ - SessionInfo info; - info.abilityName_ = "testSession1"; - info.moduleName_ = "testSession2"; - info.bundleName_ = "testSession3"; - session_ = sptr::MakeSptr(info); - session_->surfaceNode_ = CreateRSSurfaceNode(); - ssm_ = sptr::MakeSptr(); - session_->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_); - auto isScreenLockedCallback = [this]() { return ssm_->IsScreenLocked(); }; - session_->RegisterIsScreenLockedCallback(isScreenLockedCallback); - mockSessionStage_ = sptr::MakeSptr(); - mockEventChannel_ = sptr::MakeSptr(mockSessionStage_); -} - -void SessionLayoutTest::TearDown() -{ - session_ = nullptr; - usleep(WAIT_SYNC_IN_NS); -} - -RSSurfaceNode::SharedPtr SessionLayoutTest::CreateRSSurfaceNode() -{ - struct RSSurfaceNodeConfig rsSurfaceNodeConfig; - rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTestSurfaceNode"; - auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig); - if (surfaceNode == nullptr) { - GTEST_LOG_(INFO) << "SessionLayoutTest::CreateRSSurfaceNode surfaceNode is nullptr"; - } - return surfaceNode; -} - -int32_t SessionLayoutTest::GetTaskCount() -{ - std::string dumpInfo = session_->handler_->GetEventRunner()->GetEventQueue()->DumpCurrentQueueSize(); - std::regex pattern("\\d+"); - std::smatch matches; - int32_t taskNum = 0; - while (std::regex_search(dumpInfo, matches, pattern)) { - taskNum += std::stoi(matches.str()); - dumpInfo = matches.suffix(); - } - return taskNum; -} - -namespace { -/** - * @tc.name: UpdateRect01 - * @tc.desc: update rect - * @tc.type: FUNC - * @tc.require: #I6JLSI - */ -HWTEST_F(SessionLayoutTest, UpdateRect01, TestSize.Level1) -{ - bool preBackgroundUpdateRectNotifyEnabled = Session::IsBackgroundUpdateRectNotifyEnabled(); - Session::SetBackgroundUpdateRectNotifyEnabled(true); - sptr mockSessionStage = sptr::MakeSptr(); - session_->sessionStage_ = mockSessionStage; - EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _, _, _)).Times(AtLeast(1)).WillOnce(Return(WSError::WS_OK)); - - WSRect rect = { 0, 0, 0, 0 }; - ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, - session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "SessionLayoutTest")); - sptr mockEventChannel = sptr::MakeSptr(mockSessionStage); - SystemSessionConfig sessionConfig; - sptr property = sptr::MakeSptr(); - ASSERT_EQ(WSError::WS_OK, session_->Connect(mockSessionStage, mockEventChannel, nullptr, sessionConfig, property)); - - rect = { 0, 0, 100, 100 }; - ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, - session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "SessionLayoutTest")); - ASSERT_EQ(rect, session_->GetSessionRect()); - - rect = { 0, 0, 200, 200 }; - session_->UpdateSessionState(SessionState::STATE_ACTIVE); - ASSERT_EQ(WSError::WS_OK, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "SessionLayoutTest")); - ASSERT_EQ(rect, session_->GetSessionRect()); - - rect = { 0, 0, 300, 300 }; - session_->sessionStage_ = nullptr; - ASSERT_EQ(WSError::WS_OK, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "SessionLayoutTest")); - ASSERT_EQ(rect, session_->GetSessionRect()); - Session::SetBackgroundUpdateRectNotifyEnabled(preBackgroundUpdateRectNotifyEnabled); -} - -/** - * @tc.name: UpdateRect_TestForeground - * @tc.desc: update rect - * @tc.type: FUNC - * @tc.require: #I6JLSI - */ -HWTEST_F(SessionLayoutTest, UpdateRect_TestForeground, TestSize.Level1) -{ - bool preBackgroundUpdateRectNotifyEnabled = Session::IsBackgroundUpdateRectNotifyEnabled(); - Session::SetBackgroundUpdateRectNotifyEnabled(false); - sptr mockSessionStage = sptr::MakeSptr(); - session_->sessionStage_ = mockSessionStage; - - WSRect rect = { 0, 0, 100, 100 }; - session_->UpdateSessionState(SessionState::STATE_ACTIVE); - ASSERT_EQ(WSError::WS_OK, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "SessionLayoutTest")); - session_->UpdateSessionState(SessionState::STATE_BACKGROUND); - ASSERT_EQ(WSError::WS_DO_NOTHING, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "SessionLayoutTest")); - Session::SetBackgroundUpdateRectNotifyEnabled(preBackgroundUpdateRectNotifyEnabled); -} - -/** - * @tc.name: UpdateSessionRect01 - * @tc.desc: UpdateSessionRect - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, UpdateSessionRect01, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "testSession1"; - info.bundleName_ = "testSession3"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - WSRect rect = { 0, 0, 320, 240 }; // width: 320, height: 240 - auto result = sceneSession->UpdateSessionRect(rect, SizeChangeReason::RESIZE); - ASSERT_EQ(result, WSError::WS_OK); - - result = sceneSession->UpdateSessionRect(rect, SizeChangeReason::RESIZE); - ASSERT_EQ(result, WSError::WS_OK); -} - -/** - * @tc.name: SetSingleHandTransform - * @tc.desc: SetSingleHandTransform - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, SetSingleHandTransform, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetSingleHandTransform"; - info.bundleName_ = "SetSingleHandTransform"; - sptr session = sptr::MakeSptr(info); - SingleHandTransform transform; - session->SetSingleHandTransform(transform); - ASSERT_EQ(transform, session->GetSingleHandTransform()); -} - -/** - * @tc.name: IsDraggingReason - * @tc.desc: IsDraggingReason - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, IsDraggingReason, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "IsDraggingReason"; - info.bundleName_ = "IsDraggingReason"; - sptr session = sptr::MakeSptr(info); - ASSERT_EQ(false, session->IsDraggingReason(SizeChangeReason::UNDEFINED)); - ASSERT_EQ(true, session->IsDraggingReason(SizeChangeReason::DRAG)); - ASSERT_EQ(true, session->IsDraggingReason(SizeChangeReason::DRAG_START)); - ASSERT_EQ(true, session->IsDraggingReason(SizeChangeReason::DRAG_MOVE)); -} - -/** - * @tc.name: SetDragStart - * @tc.desc: SetDragStart - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, SetDragStart, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetDragStart"; - info.bundleName_ = "SetDragStart"; - sptr session = sptr::MakeSptr(info); - session->SetDragStart(true); - ASSERT_EQ(true, session->IsDragStart()); - session->SetDragStart(false); - ASSERT_EQ(false, session->IsDragStart()); -} - -/** - * @tc.name: SetHasRequestedVsyncFunc - * @tc.desc: SetHasRequestedVsyncFunc - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, SetHasRequestedVsyncFunc, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetHasRequestedVsyncFunc"; - info.bundleName_ = "SetHasRequestedVsyncFunc"; - sptr session = sptr::MakeSptr(info); - session->SetHasRequestedVsyncFunc(nullptr); - ASSERT_EQ(nullptr, session->hasRequestedVsyncFunc_); - session->SetHasRequestedVsyncFunc([](bool& hasRequestedVsync) { - hasRequestedVsync = true; - return WSError::WS_OK; - }); - ASSERT_NE(nullptr, session->hasRequestedVsyncFunc_); -} - -/** - * @tc.name: SetRequestNextVsyncWhenModeChangeFunc - * @tc.desc: SetRequestNextVsyncWhenModeChangeFunc - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, SetRequestNextVsyncWhenModeChangeFunc, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetRequestNextVsyncWhenModeChangeFunc"; - info.bundleName_ = "SetRequestNextVsyncWhenModeChangeFunc"; - sptr session = sptr::MakeSptr(info); - session->SetRequestNextVsyncWhenModeChangeFunc(nullptr); - ASSERT_EQ(nullptr, session->requestNextVsyncWhenModeChangeFunc_); - session->SetRequestNextVsyncWhenModeChangeFunc([](const std::shared_ptr& vsyncCallback) { - return WSError::WS_OK; - }); - ASSERT_NE(nullptr, session->requestNextVsyncWhenModeChangeFunc_); -} - -/** - * @tc.name: RequestNextVsyncWhenModeChange - * @tc.desc: RequestNextVsyncWhenModeChange - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, RequestNextVsyncWhenModeChange, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "RequestNextVsyncWhenModeChange"; - info.bundleName_ = "RequestNextVsyncWhenModeChange"; - sptr session = sptr::MakeSptr(info); - auto ret = session->RequestNextVsyncWhenModeChange(); - EXPECT_EQ(WSError::WS_ERROR_NULLPTR, ret); - session->SetHasRequestedVsyncFunc([](bool& hasRequestedVsync) { - hasRequestedVsync = true; - return WSError::WS_OK; - }); - ret = session->RequestNextVsyncWhenModeChange(); - EXPECT_EQ(WSError::WS_OK, ret); -} - -/** - * @tc.name: InitVsyncCallbackForModeChangeAndRequestNextVsync - * @tc.desc: InitVsyncCallbackForModeChangeAndRequestNextVsync - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, InitVsyncCallbackForModeChangeAndRequestNextVsync, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "InitVsyncCallbackForModeChangeAndRequestNextVsync"; - info.bundleName_ = "InitVsyncCallbackForModeChangeAndRequestNextVsync"; - sptr session = sptr::MakeSptr(info); - session->isWindowModeDirty_.store(true); - session->timesToWaitForVsync_.store(2); - session->requestNextVsyncWhenModeChangeFunc_ = nullptr; - session->InitVsyncCallbackForModeChangeAndRequestNextVsync(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(session->timesToWaitForVsync_.load(), 2); - - session->SetRequestNextVsyncWhenModeChangeFunc([](const std::shared_ptr& vsyncCallback) { - vsyncCallback->onCallback(1, 1); - return WSError::WS_OK; - }); - session->InitVsyncCallbackForModeChangeAndRequestNextVsync(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_NE(session->timesToWaitForVsync_.load(), 2); -} - -/** - * @tc.name: OnVsyncReceivedAfterModeChanged - * @tc.desc: OnVsyncReceivedAfterModeChanged - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, OnVsyncReceivedAfterModeChanged, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "OnVsyncReceivedAfterModeChanged"; - info.bundleName_ = "OnVsyncReceivedAfterModeChanged"; - sptr session = sptr::MakeSptr(info); - session->isWindowModeDirty_.store(false); - session->timesToWaitForVsync_.store(2); - session->OnVsyncReceivedAfterModeChanged(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(session->timesToWaitForVsync_.load(), 2); - - session->SetRequestNextVsyncWhenModeChangeFunc([](const std::shared_ptr& vsyncCallback) { - vsyncCallback->onCallback(1, 1); - return WSError::WS_OK; - }); - session->isWindowModeDirty_.store(true); - session->OnVsyncReceivedAfterModeChanged(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_NE(session->timesToWaitForVsync_.load(), 2); - - session->isWindowModeDirty_.store(true); - session->timesToWaitForVsync_.store(-1); - session->OnVsyncReceivedAfterModeChanged(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(session->timesToWaitForVsync_.load(), 0); - - session->isWindowModeDirty_.store(true); - session->timesToWaitForVsync_.store(1); - session->sessionStage_ = nullptr; - session->OnVsyncReceivedAfterModeChanged(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(session->isWindowModeDirty_.load(), false); - - session->isWindowModeDirty_.store(true); - session->timesToWaitForVsync_.store(1); - session->sessionStage_ = sptr::MakeSptr(); - session->OnVsyncReceivedAfterModeChanged(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(session->isWindowModeDirty_.load(), false); -} -} // namespace -} // namespace Rosen -} // namespace OHOS diff --git a/window_scene/test/unittest/session_stub_layout_test.cpp b/window_scene/test/unittest/session_stub_layout_test.cpp deleted file mode 100644 index 675acf37eb452a050b2321ebd2ce05429b99502d..0000000000000000000000000000000000000000 --- a/window_scene/test/unittest/session_stub_layout_test.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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 - -#include "ability_start_setting.h" -#include "iremote_object_mocker.h" -#include "mock/mock_session_stub.h" -#include "parcel/accessibility_event_info_parcel.h" -#include "session/host/include/zidl/session_ipc_interface_code.h" -#include "session/host/include/zidl/session_stub.h" -#include "want.h" -#include "ws_common.h" - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace Rosen { -namespace { -const std::string UNDEFINED = "undefined"; -} - -namespace OHOS::Accessibility { -class AccessibilityEventInfo; -} -class SessionStubLayoutTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - -private: - sptr session_ = nullptr; -}; - -void SessionStubLayoutTest::SetUpTestCase() {} - -void SessionStubLayoutTest::TearDownTestCase() {} - -void SessionStubLayoutTest::SetUp() -{ - session_ = sptr::MakeSptr(); -} - -void SessionStubLayoutTest::TearDown() -{ - session_ = nullptr; -} - -namespace { -/** - * @tc.name: HandleUpdateRectChangeListenerRegistered008 - * @tc.desc: sessionStub sessionStubTest - * @tc.type: FUNC - * @tc.require: #I6JLSI - */ -HWTEST_F(SessionStubLayoutTest, HandleUpdateRectChangeListenerRegistered008, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - data.WriteBool(true); - sptr iRemoteObjectMocker = sptr::MakeSptr(); - auto res = session_->HandleUpdateRectChangeListenerRegistered(data, reply); - ASSERT_EQ(ERR_NONE, res); -} - -/** - * @tc.name: HandleUpdateSessionRect - * @tc.desc: test for HandleUpdateSessionRect - * @tc.type: FUNC - * @tc.require: #I6JLSI - */ -HWTEST_F(SessionStubLayoutTest, HandleUpdateSessionRect, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - data.WriteUint32(10); - data.WriteUint32(20); - data.WriteUint32(30); - data.WriteUint32(40); - data.WriteUint32(0); - data.WriteBool(true); - data.WriteBool(true); - auto res = session_->HandleUpdateSessionRect(data, reply); - ASSERT_EQ(ERR_NONE, res); -} - -/** - * @tc.name: HandleUpdateClientRect01 - * @tc.desc: sessionStub sessionStubTest - * @tc.type: FUNC - */ -HWTEST_F(SessionStubLayoutTest, HandleUpdateClientRect01, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - auto res = session_->HandleUpdateClientRect(data, reply); - ASSERT_EQ(ERR_INVALID_DATA, res); - data.WriteInt32(100); - data.WriteInt32(100); - data.WriteInt32(800); - data.WriteInt32(800); - res = session_->HandleUpdateClientRect(data, reply); - ASSERT_EQ(ERR_NONE, res); -} - -/** - * @tc.name: HandleSetSystemEnableDrag_TestReadBool - * @tc.desc: Check whether the enableDrag is read successfully. - * @tc.type: FUNC - */ -HWTEST_F(SessionStubLayoutTest, HandleSetSystemEnableDrag_TestReadBool, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - auto res = session_->HandleSetSystemEnableDrag(data, reply); - ASSERT_EQ(ERR_INVALID_DATA, res); - - data.WriteBool(true); - res = session_->HandleSetSystemEnableDrag(data, reply); - ASSERT_EQ(ERR_NONE, res); -} -} // namespace -} // namespace Rosen -} // namespace OHOS \ No newline at end of file diff --git a/wm/test/unittest/layout/window_session_impl_layout_test.cpp b/wm/test/unittest/layout/window_session_impl_layout_test.cpp index fd8fabe7740e31ed7712f1b90721a3999c106fb9..7e22d4cc2c103c137d0a22513eac20f07bc1e589 100644 --- a/wm/test/unittest/layout/window_session_impl_layout_test.cpp +++ b/wm/test/unittest/layout/window_session_impl_layout_test.cpp @@ -62,6 +62,27 @@ void WindowSessionImplLayoutTest::TearDown() } namespace { +sptr GetTestWindowImpl(const std::string& name) +{ + sptr option = sptr::MakeSptr(); + option->SetWindowName(name); + sptr window = sptr::MakeSptr(option); + + SessionInfo sessionInfo = { name, name, name }; + sptr session = sptr::MakeSptr(sessionInfo); + + window->hostSession_ = session; + return window; +} + +template std::vector> GetListenerList() +{ + std::vector> listeners; + sptr listener = sptr::MakeSptr(); + listeners.insert(listeners.begin(), listener); + return listeners; +} + /** * @tc.name: UpdateRect01 * @tc.desc: UpdateRect @@ -334,6 +355,24 @@ HWTEST_F(WindowSessionImplLayoutTest, NotifyTransformChange_TestUIContent, TestS GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyTransformChange_TestUIContent end"; } +/** + * @tc.name: NotifyWindowStatusDidChange + * @tc.desc: NotifyWindowStatusDidChange + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplLayoutTest, NotifyWindowStatusDidChange, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyWindowStatusDidChange start"; + auto window = GetTestWindowImpl("NotifyWindowStatusDidChange"); + auto listeners = GetListenerList(); + EXPECT_NE(listeners.size(), 0); + listeners.insert(listeners.begin(), nullptr); + window->windowStatusDidChangeListeners_.insert({ window->GetPersistentId(), listeners }); + window->NotifyWindowStatusDidChange(WindowMode::WINDOW_MODE_FLOATING); + EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); + GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyWindowStatusDidChange end"; +} + /** * @tc.name: NotifyAfterUIContentReady * @tc.desc: NotifyAfterUIContentReady @@ -356,6 +395,39 @@ HWTEST_F(WindowSessionImplLayoutTest, NotifyAfterUIContentReady, TestSize.Level1 ASSERT_EQ(false, window->IsNeedRenotifyTransform()); GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyAfterUIContentReady end"; } + +/** + * @tc.name: NotifyFirstValidLayoutUpdate + * @tc.desc: NotifyFirstValidLayoutUpdate + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplLayoutTest, NotifyFirstValidLayoutUpdate, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyFirstValidLayoutUpdate start"; + sptr option = sptr::MakeSptr(); + option->SetWindowName("NotifyFirstValidLayoutUpdate"); + sptr window = sptr::MakeSptr(option); + window->property_->SetPersistentId(2025); + + Rect preRect = { 0, 0, 1000, 1000 }; + Rect newRect = { 0, 0, 0, 0 }; + window->isFirstValidLayoutUpdate_ = true; + window->NotifyFirstValidLayoutUpdate(preRect, newRect); + EXPECT_EQ(window->isFirstValidLayoutUpdate_, true); + + preRect = { 0, 0, 0, 0 }; + window->NotifyFirstValidLayoutUpdate(preRect, newRect); + EXPECT_EQ(window->isFirstValidLayoutUpdate_, true); + + + newRect = { 0, 0, 1000, 1000 }; + window->NotifyFirstValidLayoutUpdate(preRect, newRect); + EXPECT_EQ(window->isFirstValidLayoutUpdate_, false); + + window->NotifyFirstValidLayoutUpdate(preRect, newRect); + EXPECT_EQ(window->isFirstValidLayoutUpdate_, false); + GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyFirstValidLayoutUpdate end"; +} } } // namespace Rosen } // namespace OHOS diff --git a/wm/test/unittest/window_scene_session_impl_layout_test.cpp b/wm/test/unittest/window_scene_session_impl_layout_test.cpp deleted file mode 100644 index 3549886bfc292815145571ade8ff82f99abaf346..0000000000000000000000000000000000000000 --- a/wm/test/unittest/window_scene_session_impl_layout_test.cpp +++ /dev/null @@ -1,671 +0,0 @@ -/* - * 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_session.h" -#include "mock_uicontent.h" -#include "mock_window_adapter.h" -#include "scene_board_judgement.h" -#include "session/host/include/scene_session.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 { -using Mocker = SingletonMocker; - -class MockWindowChangeListener : public IWindowChangeListener { -public: - MOCK_METHOD3(OnSizeChange, - void(Rect rect, WindowSizeChangeReason reason, const std::shared_ptr& rsTransaction)); -}; - -class MockWindowLifeCycleListener : public IWindowLifeCycle { -public: - MOCK_METHOD0(AfterForeground, void(void)); - MOCK_METHOD0(AfterBackground, void(void)); - MOCK_METHOD0(AfterFocused, void(void)); - MOCK_METHOD0(AfterUnfocused, void(void)); - MOCK_METHOD1(ForegroundFailed, void(int32_t)); - MOCK_METHOD0(AfterActive, void(void)); - MOCK_METHOD0(AfterInactive, void(void)); - MOCK_METHOD0(AfterResumed, void(void)); - MOCK_METHOD0(AfterPaused, void(void)); -}; - -class WindowSceneSessionImplLayoutTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - - std::shared_ptr abilityContext_; - std::unique_ptr m = 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 WindowSceneSessionImplLayoutTest::SetUpTestCase() {} - -void WindowSceneSessionImplLayoutTest::TearDownTestCase() {} - -void WindowSceneSessionImplLayoutTest::SetUp() -{ - abilityContext_ = std::make_shared(); -} - -void WindowSceneSessionImplLayoutTest::TearDown() -{ - usleep(WAIT_SYNC_IN_NS); - abilityContext_ = nullptr; -} - -RSSurfaceNode::SharedPtr WindowSceneSessionImplLayoutTest::CreateRSSurfaceNode() -{ - struct RSSurfaceNodeConfig rsSurfaceNodeConfig; - rsSurfaceNodeConfig.SurfaceNodeName = "startingWindowTestSurfaceNode"; - auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig, RSSurfaceNodeType::DEFAULT); - return surfaceNode; -} - -namespace { - -/** - * @tc.name: SetAspectRatio01 - * @tc.desc: SetAspectRatio test - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, SetAspectRatio01, TestSize.Level1) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("SetAspectRatio01"); - sptr window = sptr::MakeSptr(option); - window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); - ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetAspectRatio(0.1)); -} - -/** - * @tc.name: SetAspectRatio02 - * @tc.desc: SetAspectRatio test - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, SetAspectRatio02, TestSize.Level0) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("SetAspectRatio02"); - sptr window = sptr::MakeSptr(option); - window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); - ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetAspectRatio(0.1)); - - window->property_->SetPersistentId(1); - window->property_->SetDisplayId(0); - WindowLimits windowLimits = { 3000, 3000, 2000, 2000, 2.0, 2.0 }; - window->property_->SetWindowLimits(windowLimits); - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo, nullptr); - window->hostSession_ = session; - session->GetSessionProperty()->SetWindowLimits(windowLimits); - const float ratio = 1.2; - ASSERT_EQ(WMError::WM_OK, window->SetAspectRatio(ratio)); - ASSERT_EQ(ratio, session->GetAspectRatio()); -} - -/** - * @tc.name: SetAspectRatio03 - * @tc.desc: SetAspectRatio - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, SetAspectRatio03, TestSize.Level1) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("SetAspectRatio03"); - sptr windowSceneSessionImpl = sptr::MakeSptr(option); - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo); - windowSceneSessionImpl->hostSession_ = session; - auto ret = windowSceneSessionImpl->SetAspectRatio(MathHelper::INF); - EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret); - windowSceneSessionImpl->property_->SetPersistentId(1); - ret = windowSceneSessionImpl->SetAspectRatio(MathHelper::INF); - EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, ret); - ret = windowSceneSessionImpl->SetAspectRatio(MathHelper::NAG_INF); - EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, ret); - ret = windowSceneSessionImpl->SetAspectRatio(std::sqrt(-1.0)); - EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, ret); - ret = windowSceneSessionImpl->SetAspectRatio(0.0f); - EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, ret); - ret = windowSceneSessionImpl->SetAspectRatio(1.0f); - EXPECT_EQ(WMError::WM_OK, ret); -} - -/** - * @tc.name: ResetAspectRatio01 - * @tc.desc: ResetAspectRatio test GetAvoidAreaByType - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, ResetAspectRatio01, TestSize.Level1) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("ResetAspectRatio01"); - sptr window = sptr::MakeSptr(option); - window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - ASSERT_EQ(WMError::WM_OK, window->ResetAspectRatio()); - ASSERT_EQ(0, session->GetAspectRatio()); -} - -/** - * @tc.name: ResetAspectRatio02 - * @tc.desc: ResetAspectRatio - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, ResetAspectRatio02, TestSize.Level1) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("ResetAspectRatio02"); - sptr windowSceneSessionImpl = sptr::MakeSptr(option); - windowSceneSessionImpl->hostSession_ = nullptr; - auto ret = windowSceneSessionImpl->ResetAspectRatio(); - EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); - windowSceneSessionImpl->property_->SetPersistentId(1); - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo); - windowSceneSessionImpl->hostSession_ = session; - windowSceneSessionImpl->state_ = WindowState::STATE_CREATED; - ret = windowSceneSessionImpl->ResetAspectRatio(); - EXPECT_EQ(WMError::WM_OK, ret); -} - -/** - * @tc.name: SetWindowLimits01 - * @tc.desc: SetWindowLimits - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, SetWindowLimits01, TestSize.Level0) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("SetWindowLimits01"); - option->SetDisplayId(0); - - sptr window = sptr::MakeSptr(option); - - window->property_->SetPersistentId(1); - window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - window->state_ = WindowState::STATE_FROZEN; - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - - window->useUniqueDensity_ = true; - window->virtualPixelRatio_ = 1.9; - - WindowLimits windowLimits = { 2000, 2000, 2000, 2000, 0.0f, 0.0f }; - EXPECT_EQ(WMError::WM_OK, window->SetWindowLimits(windowLimits, false)); - WindowLimits windowSizeLimits = window->property_->GetWindowLimits(); - EXPECT_EQ(windowSizeLimits.maxWidth_, 2000); - EXPECT_EQ(windowSizeLimits.maxHeight_, 2000); - EXPECT_EQ(windowSizeLimits.minWidth_, 2000); - EXPECT_EQ(windowSizeLimits.minHeight_, 2000); - - windowLimits = { 2000, 2000, 100, 100, 0.0f, 0.0f }; - EXPECT_EQ(WMError::WM_OK, window->SetWindowLimits(windowLimits, false)); - windowSizeLimits = window->property_->GetWindowLimits(); - EXPECT_EQ(windowSizeLimits.maxWidth_, 2000); - EXPECT_EQ(windowSizeLimits.maxHeight_, 2000); - EXPECT_NE(windowSizeLimits.minWidth_, 100); - EXPECT_NE(windowSizeLimits.minHeight_, 100); - - windowLimits = { 10000, 10000, 30, 30, 0.0f, 0.0f }; - EXPECT_EQ(WMError::WM_OK, window->SetWindowLimits(windowLimits, false)); - windowSizeLimits = window->property_->GetWindowLimits(); - EXPECT_NE(windowSizeLimits.maxWidth_, 10000); - EXPECT_NE(windowSizeLimits.maxHeight_, 10000); - EXPECT_NE(windowSizeLimits.minWidth_, 30); - EXPECT_NE(windowSizeLimits.minHeight_, 30); -} - -/** - * @tc.name: SetWindowLimits06 - * @tc.desc: SetWindowLimits - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, SetWindowLimits06, TestSize.Level0) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("SetWindowLimits06"); - option->SetDisplayId(0); - - sptr window = sptr::MakeSptr(option); - - window->property_->SetPersistentId(1); - window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - window->state_ = WindowState::STATE_FROZEN; - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - - window->useUniqueDensity_ = true; - window->virtualPixelRatio_ = 1.9; - - WindowLimits windowLimits = { 2000, 2000, 2000, 2000, 0.0f, 0.0f }; - EXPECT_EQ(WMError::WM_OK, window->SetWindowLimits(windowLimits, true)); - WindowLimits windowSizeLimits = window->property_->GetWindowLimits(); - EXPECT_EQ(windowSizeLimits.maxWidth_, 2000); - EXPECT_EQ(windowSizeLimits.maxHeight_, 2000); - EXPECT_EQ(windowSizeLimits.minWidth_, 2000); - EXPECT_EQ(windowSizeLimits.minHeight_, 2000); - - windowLimits = { 2000, 2000, 100, 100, 0.0f, 0.0f }; - EXPECT_EQ(WMError::WM_OK, window->SetWindowLimits(windowLimits, true)); - windowSizeLimits = window->property_->GetWindowLimits(); - EXPECT_EQ(windowSizeLimits.maxWidth_, 2000); - EXPECT_EQ(windowSizeLimits.maxHeight_, 2000); - EXPECT_NE(windowSizeLimits.minWidth_, 100); - EXPECT_NE(windowSizeLimits.minHeight_, 100); - - windowLimits = { 2000, 2000, 100, 100, 0.0f, 0.0f }; - window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; - EXPECT_EQ(WMError::WM_OK, window->SetWindowLimits(windowLimits, true)); - windowSizeLimits = window->property_->GetWindowLimits(); - EXPECT_EQ(windowSizeLimits.maxWidth_, 2000); - EXPECT_EQ(windowSizeLimits.maxHeight_, 2000); - EXPECT_EQ(windowSizeLimits.minWidth_, 100); - EXPECT_EQ(windowSizeLimits.minHeight_, 100); - - windowLimits = { 10000, 10000, 30, 30, 0.0f, 0.0f }; - EXPECT_EQ(WMError::WM_OK, window->SetWindowLimits(windowLimits, true)); - windowSizeLimits = window->property_->GetWindowLimits(); - EXPECT_NE(windowSizeLimits.maxWidth_, 10000); - EXPECT_NE(windowSizeLimits.maxHeight_, 10000); - EXPECT_NE(windowSizeLimits.minWidth_, 30); - EXPECT_NE(windowSizeLimits.minHeight_, 30); -} - -/** - * @tc.name: SetWindowLimits02 - * @tc.desc: SetWindowLimits - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, SetWindowLimits02, TestSize.Level1) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("SetWindowLimits02"); - sptr windowSceneSessionImpl = sptr::MakeSptr(option); - WindowLimits windowLimits = { 1000, 1000, 1000, 1000, 0.0f, 0.0f }; - - windowSceneSessionImpl->property_->SetWindowType(WindowType::APP_SUB_WINDOW_END); - auto ret = windowSceneSessionImpl->SetWindowLimits(windowLimits, false); - EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret); - ret = windowSceneSessionImpl->SetWindowLimits(windowLimits, true); - EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret); -} - -/** - * @tc.name: SetWindowLimits03 - * @tc.desc: SetWindowLimits - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, SetWindowLimits03, TestSize.Level1) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("SetWindowLimits03"); - sptr windowSceneSessionImpl = sptr::MakeSptr(option); - WindowLimits windowLimits = { 1000, 1000, 1000, 1000, 0.0f, 0.0f }; - windowSceneSessionImpl->property_->SetPersistentId(1); - windowSceneSessionImpl->property_->SetDisplayId(0); - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo); - windowSceneSessionImpl->hostSession_ = session; - windowSceneSessionImpl->state_ = WindowState::STATE_CREATED; - windowSceneSessionImpl->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); - auto ret = windowSceneSessionImpl->SetWindowLimits(windowLimits, false); - EXPECT_EQ(WMError::WM_OK, ret); - ret = windowSceneSessionImpl->SetWindowLimits(windowLimits, true); - EXPECT_EQ(WMError::WM_OK, ret); -} - -/** - * @tc.name: SetWindowLimits04 - * @tc.desc: SetWindowLimits - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, SetWindowLimits04, TestSize.Level1) -{ - sptr subWindow = sptr::MakeSptr(); - subWindow->SetWindowName("SetWindowLimits04"); - sptr windowSceneSessionImpl = sptr::MakeSptr(subWindow); - WindowLimits windowLimits = { 1000, 1000, 1000, 1000, 0.0f, 0.0f }; - windowSceneSessionImpl->SetWindowLimits(windowLimits, false); - windowSceneSessionImpl->property_->SetPersistentId(1004); - windowSceneSessionImpl->property_->SetDisplayId(0); - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo); - windowSceneSessionImpl->hostSession_ = session; - windowSceneSessionImpl->state_ = WindowState::STATE_CREATED; - windowSceneSessionImpl->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_LAUNCHING); - auto ret = windowSceneSessionImpl->SetWindowLimits(windowLimits, false); - EXPECT_EQ(WMError::WM_OK, ret); - ret = windowSceneSessionImpl->SetWindowLimits(windowLimits, true); - EXPECT_EQ(WMError::WM_OK, ret); -} - -/** - * @tc.name: SetWindowLimits05 - * @tc.desc: SetWindowLimits - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, SetWindowLimits05, TestSize.Level1) -{ - sptr subWindow = sptr::MakeSptr(); - subWindow->SetWindowName("SetWindowLimits05"); - sptr windowSceneSessionImpl = sptr::MakeSptr(subWindow); - WindowLimits windowLimits = { 1000, 1000, 1000, 1000, 0.0f, 0.0f }; - windowSceneSessionImpl->property_->SetPersistentId(1005); - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr subSession = sptr::MakeSptr(sessionInfo); - windowSceneSessionImpl->hostSession_ = subSession; - windowSceneSessionImpl->property_->SetWindowType(WindowType::APP_SUB_WINDOW_END); - EXPECT_EQ(WMError::WM_ERROR_INVALID_CALLING, windowSceneSessionImpl->SetWindowLimits(windowLimits, false)); - EXPECT_EQ(WMError::WM_ERROR_INVALID_CALLING, windowSceneSessionImpl->SetWindowLimits(windowLimits, true)); - - windowSceneSessionImpl->property_->SetWindowType(WindowType::BELOW_APP_SYSTEM_WINDOW_BASE); - EXPECT_EQ(WMError::WM_OK, windowSceneSessionImpl->SetWindowLimits(windowLimits, false)); - EXPECT_EQ(WMError::WM_OK, windowSceneSessionImpl->SetWindowLimits(windowLimits, true)); - - windowSceneSessionImpl->property_->SetDragEnabled(false); - EXPECT_EQ(WMError::WM_ERROR_INVALID_CALLING, windowSceneSessionImpl->SetWindowLimits(windowLimits, false)); - EXPECT_EQ(WMError::WM_ERROR_INVALID_CALLING, windowSceneSessionImpl->SetWindowLimits(windowLimits, true)); -} - -/** - * @tc.name: CalculateNewLimitsByRatio01 - * @tc.desc: CalculateNewLimitsByRatio - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, CalculateNewLimitsByRatio01, TestSize.Level1) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("CalculateNewLimitsByRatio01"); - sptr windowSceneSessionImpl = sptr::MakeSptr(option); - - WindowLimits newLimits = { 0, 0, 0, 0, 0.0, 0.0 }; - WindowLimits customizedLimits = { 3, 3, 3, 3, 0.0, 0.0 }; - windowSceneSessionImpl->CalculateNewLimitsByRatio(newLimits, customizedLimits); - newLimits = { 500, 500, 500, 500, 0.0, 0.0 }; - customizedLimits = { 3, 3, 3, 3, 2.0, 2.0 }; - windowSceneSessionImpl->CalculateNewLimitsByRatio(newLimits, customizedLimits); - customizedLimits = { 3, 3, 3, 3, 1.0, 1.0 }; - windowSceneSessionImpl->CalculateNewLimitsByRatio(newLimits, customizedLimits); - windowSceneSessionImpl->property_->SetWindowType(WindowType::BELOW_APP_SYSTEM_WINDOW_END); - auto ret = windowSceneSessionImpl->UpdateAnimationFlagProperty(true); - EXPECT_EQ(WMError::WM_OK, ret); -} - -/** - * @tc.name: CalculateNewLimitsByRatio02 - * @tc.desc: CalculateNewLimitsByRatio - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, CalculateNewLimitsByRatio02, TestSize.Level1) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("CalculateNewLimitsByRatio02"); - sptr windowSceneSessionImpl = sptr::MakeSptr(option); - - WindowLimits newLimits = { 0, 0, 0, 0, 0.0, 0.0 }; - WindowLimits customizedLimits = { 3, 3, 3, 3, 0.0, 0.0 }; - windowSceneSessionImpl->CalculateNewLimitsByRatio(newLimits, customizedLimits); - newLimits = { 500, 500, 500, 500, 0.0, 0.0 }; - customizedLimits = { 3, 3, 3, 3, 2.0, 2.0 }; - windowSceneSessionImpl->CalculateNewLimitsByRatio(newLimits, customizedLimits); - customizedLimits = { 3, 3, 3, 3, 1.0, 1.0 }; - windowSceneSessionImpl->CalculateNewLimitsByRatio(newLimits, customizedLimits); - windowSceneSessionImpl->property_->SetWindowType(WindowType::BELOW_APP_SYSTEM_WINDOW_BASE); - auto ret = windowSceneSessionImpl->UpdateAnimationFlagProperty(true); - EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret); -} - -/** - * @tc.name: MoveToAsync01 - * @tc.desc: MoveToAsync - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, MoveToAsync01, TestSize.Level0) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("MoveToAsync01"); - option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); - option->SetWindowType(WindowType::WINDOW_TYPE_PIP); - sptr window = sptr::MakeSptr(option); - ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->MoveToAsync(10, 10)); - - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - window->property_->SetPersistentId(1); - ASSERT_EQ(WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS, window->MoveToAsync(10, 10)); -} - -/** - * @tc.name: MoveToAsync02 - * @tc.desc: MoveToAsync - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, MoveToAsync02, TestSize.Level1) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("MoveToAsync02"); - option->SetWindowType(WindowType::WINDOW_TYPE_TOAST); - option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(10001); - Rect rect; - WMError ret; - ret = window->Create(abilityContext_, nullptr); - if (SceneBoardJudgement::IsSceneBoardEnabled()) { - EXPECT_EQ(WMError::WM_OK, ret); - ret = window->Show(); - EXPECT_EQ(WMError::WM_OK, ret); - window->state_ = WindowState::STATE_SHOWN; - ret = window->MoveToAsync(500, 500); - EXPECT_EQ(WMError::WM_OK, ret); - rect = window->property_->GetWindowRect(); - EXPECT_EQ(500, rect.posX_); - EXPECT_EQ(500, rect.posY_); - window->state_ = WindowState::STATE_HIDDEN; - ret = window->MoveToAsync(20000, 20000); - usleep(WAIT_SERVERAL_FRAMES); - EXPECT_EQ(WMError::WM_OK, ret); - rect = window->property_->GetWindowRect(); - EXPECT_EQ(20000, rect.posX_); - EXPECT_EQ(20000, rect.posY_); - ASSERT_EQ(WMError::WM_OK, window->Destroy(true)); - } else { - EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); - } -} - -/** - * @tc.name: ResizeAsync01 - * @tc.desc: ResizeAsync - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, ResizeAsync01, TestSize.Level0) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("ResizeAsync01"); - option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); - option->SetWindowType(WindowType::WINDOW_TYPE_PIP); - sptr window = sptr::MakeSptr(option); - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - window->property_->SetPersistentId(1); - ASSERT_EQ(WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS, window->ResizeAsync(500, 500)); -} - -/** - * @tc.name: ResizeAsync02 - * @tc.desc: ResizeAsync - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, ResizeAsync02, TestSize.Level1) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("ResizeAsync02"); - option->SetWindowType(WindowType::WINDOW_TYPE_TOAST); - option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(10012); - Rect rect; - WMError ret; - ret = window->Create(abilityContext_, nullptr); - if (SceneBoardJudgement::IsSceneBoardEnabled()) { - EXPECT_EQ(WMError::WM_OK, ret); - ret = window->Show(); - EXPECT_EQ(WMError::WM_OK, ret); - WindowLimits windowLimits; - ret = window->GetWindowLimits(windowLimits); - EXPECT_EQ(WMError::WM_OK, ret); - window->state_ = WindowState::STATE_SHOWN; - ret = window->ResizeAsync(windowLimits.maxWidth_ - 100, windowLimits.maxHeight_ - 100); - EXPECT_EQ(WMError::WM_OK, ret); - rect = window->property_->GetWindowRect(); - EXPECT_EQ(windowLimits.maxWidth_ - 100, rect.width_); - EXPECT_EQ(windowLimits.maxHeight_ - 100, rect.height_); - window->state_ = WindowState::STATE_HIDDEN; - ret = window->ResizeAsync(windowLimits.maxWidth_ + 100, windowLimits.maxHeight_ + 100); - EXPECT_EQ(WMError::WM_OK, ret); - usleep(WAIT_SERVERAL_FRAMES); - rect = window->property_->GetWindowRect(); - EXPECT_EQ(windowLimits.maxWidth_, rect.width_); - EXPECT_EQ(windowLimits.maxHeight_, rect.height_); - ASSERT_EQ(WMError::WM_OK, window->Destroy(true)); - } else { - EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); - } -} - -/** - * @tc.name: MoveTo01 - * @tc.desc: MoveTo - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, MoveTo01, TestSize.Level1) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("MoveTo01"); - sptr windowSceneSession = sptr::MakeSptr(option); - - windowSceneSession->property_->SetPersistentId(1); - windowSceneSession->state_ = WindowState::STATE_HIDDEN; - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo); - windowSceneSession->hostSession_ = session; - ASSERT_EQ(WMError::WM_OK, windowSceneSession->MoveTo(2, 2)); -} - -/** - * @tc.name: MoveTo02 - * @tc.desc: MoveTo - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, MoveTo02, TestSize.Level1) -{ - sptr subOption = sptr::MakeSptr(); - subOption->SetWindowName("MoveTo02SubWindow"); - subOption->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); - sptr subWindow = sptr::MakeSptr(subOption); - subWindow->property_->SetPersistentId(1001); - SessionInfo subSessionInfo = { "CreateSubTestBundle", "CreateSubTestModule", "CreateSubTestAbility" }; - sptr subSession = sptr::MakeSptr(subSessionInfo); - subWindow->hostSession_ = subSession; - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(2, 2)); - - sptr option = sptr::MakeSptr(); - option->SetWindowName("MoveTo02"); - option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(1); - SessionInfo sessionInfo = { "CreateTestBundle2", "CreateTestModule2", "CreateTestAbility2" }; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - window->state_ = WindowState::STATE_SHOWN; - ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session)); - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(3, 3)); - window->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(3, 3)); - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(3, 4)); - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(4, 4)); - window->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(4, 4)); - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(4, 5)); - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(5, 5)); - ASSERT_EQ(WMError::WM_OK, window->Destroy(true)); -} - -/** - * @tc.name: MoveTo03 - * @tc.desc: MoveTo - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplLayoutTest, MoveTo03, TestSize.Level1) -{ - sptr subOption = sptr::MakeSptr(); - subOption->SetWindowName("MoveTo01SubWindow"); - subOption->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); - sptr subWindow = sptr::MakeSptr(subOption); - subWindow->property_->SetPersistentId(1001); - SessionInfo subSessionInfo = { "CreateSubTestBundle", "CreateSubTestModule", "CreateSubTestAbility" }; - sptr subSession = sptr::MakeSptr(subSessionInfo); - subWindow->hostSession_ = subSession; - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(2, 2)); - - sptr option = sptr::MakeSptr(); - option->SetWindowName("MoveTo02"); - option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(1); - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - WindowSceneSessionImpl::windowSessionMap_.insert(std::make_pair( - window->GetWindowName(), std::pair>(window->GetWindowId(), window))); - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(3, 3)); - window->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(4, 3)); - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(4, 4)); - window->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(5, 4)); - ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(5, 4)); - WindowSceneSessionImpl::windowSessionMap_.erase(window->GetWindowName()); -} -} // namespace -} // namespace Rosen -} // namespace OHOS diff --git a/wm/test/unittest/window_session_impl_layout_test.cpp b/wm/test/unittest/window_session_impl_layout_test.cpp deleted file mode 100644 index 7e22d4cc2c103c137d0a22513eac20f07bc1e589..0000000000000000000000000000000000000000 --- a/wm/test/unittest/window_session_impl_layout_test.cpp +++ /dev/null @@ -1,433 +0,0 @@ -/* - * 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 - -#include "ability_context_impl.h" -#include "accessibility_event_info.h" -#include "color_parser.h" -#include "mock_session.h" -#include "mock_uicontent.h" -#include "mock_window.h" -#include "parameters.h" -#include "window_helper.h" -#include "window_session_impl.h" -#include "wm_common.h" - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace Rosen { -class WindowSessionImplLayoutTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - - std::shared_ptr abilityContext_; - -private: - static constexpr uint32_t WAIT_SYNC_IN_NS = 50000; -}; - -void WindowSessionImplLayoutTest::SetUpTestCase() {} - -void WindowSessionImplLayoutTest::TearDownTestCase() {} - -void WindowSessionImplLayoutTest::SetUp() -{ - abilityContext_ = std::make_shared(); -} - -void WindowSessionImplLayoutTest::TearDown() -{ - usleep(WAIT_SYNC_IN_NS); - abilityContext_ = nullptr; -} - -namespace { -sptr GetTestWindowImpl(const std::string& name) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName(name); - sptr window = sptr::MakeSptr(option); - - SessionInfo sessionInfo = { name, name, name }; - sptr session = sptr::MakeSptr(sessionInfo); - - window->hostSession_ = session; - return window; -} - -template std::vector> GetListenerList() -{ - std::vector> listeners; - sptr listener = sptr::MakeSptr(); - listeners.insert(listeners.begin(), listener); - return listeners; -} - -/** - * @tc.name: UpdateRect01 - * @tc.desc: UpdateRect - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplLayoutTest, UpdateRect01, TestSize.Level0) -{ - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: UpdateRect01 start"; - sptr option = sptr::MakeSptr(); - option->SetWindowName("UpdateRect01"); - sptr window = sptr::MakeSptr(option); - - WSRect rect; - rect.posX_ = 0; - rect.posY_ = 0; - rect.height_ = 50; - rect.width_ = 50; - - Rect rectW; // GetRect().IsUninitializedRect is false - rectW.posX_ = 0; - rectW.posY_ = 0; - rectW.height_ = 200; // rectW - rect > 50 - rectW.width_ = 200; // rectW - rect > 50 - - window->property_->SetWindowRect(rectW); - SizeChangeReason reason = SizeChangeReason::UNDEFINED; - WSError res = window->UpdateRect(rect, reason); - ASSERT_EQ(res, WSError::WS_OK); - - rectW.height_ = 50; - window->property_->SetWindowRect(rectW); - res = window->UpdateRect(rect, reason); - ASSERT_EQ(res, WSError::WS_OK); - - rectW.height_ = 200; - rectW.width_ = 50; - window->property_->SetWindowRect(rectW); - res = window->UpdateRect(rect, reason); - ASSERT_EQ(res, WSError::WS_OK); - Rect nowRect = window->property_->GetWindowRect(); - EXPECT_EQ(nowRect.posX_, rect.posX_); - EXPECT_EQ(nowRect.posY_, rect.posY_); - EXPECT_EQ(nowRect.width_, rect.width_); - EXPECT_EQ(nowRect.height_, rect.height_); - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: UpdateRect01 end"; -} - -/** - * @tc.name: UpdateRect02 - * @tc.desc: UpdateRect - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplLayoutTest, UpdateRect02, TestSize.Level0) -{ - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: UpdateRect02 start"; - sptr option = sptr::MakeSptr(); - option->SetWindowName("UpdateRect02"); - sptr window = sptr::MakeSptr(option); - - WSRect rect; - rect.posX_ = 0; - rect.posY_ = 0; - rect.height_ = 0; - rect.width_ = 0; - - Rect rectW; // GetRect().IsUninitializedRect is true - rectW.posX_ = 0; - rectW.posY_ = 0; - rectW.height_ = 0; // rectW - rect > 50 - rectW.width_ = 0; // rectW - rect > 50 - - window->property_->SetWindowRect(rectW); - SizeChangeReason reason = SizeChangeReason::ROTATION; - WSError res = window->UpdateRect(rect, reason); - ASSERT_EQ(res, WSError::WS_OK); - - rect.height_ = 50; - rect.width_ = 50; - rectW.height_ = 50; - rectW.width_ = 50; - window->property_->SetWindowRect(rectW); - res = window->UpdateRect(rect, reason); - ASSERT_EQ(res, WSError::WS_OK); - Rect nowRect = window->property_->GetWindowRect(); - EXPECT_EQ(nowRect.posX_, rect.posX_); - EXPECT_EQ(nowRect.posY_, rect.posY_); - EXPECT_EQ(nowRect.width_, rect.width_); - EXPECT_EQ(nowRect.height_, rect.height_); - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: UpdateRect02 end"; -} - -/** - * @tc.name: SetResizeByDragEnabled01 - * @tc.desc: SetResizeByDragEnabled and check the retCode - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplLayoutTest, SetResizeByDragEnabled01, TestSize.Level0) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("SetResizeByDragEnabled01"); - sptr window = sptr::MakeSptr(option); - WMError retCode = window->SetResizeByDragEnabled(true); - ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW); -} - -/** - * @tc.name: SetResizeByDragEnabled02 - * @tc.desc: SetResizeByDragEnabled and check the retCode - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplLayoutTest, SetResizeByDragEnabled02, TestSize.Level0) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("SetResizeByDragEnabled02"); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(1); - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - window->state_ = WindowState::STATE_CREATED; - ASSERT_FALSE(window->IsWindowSessionInvalid()); - WMError retCode = window->SetResizeByDragEnabled(true); - ASSERT_EQ(retCode, WMError::WM_OK); - ASSERT_EQ(true, window->property_->GetDragEnabled()); -} - -/** - * @tc.name: SetResizeByDragEnabled03 - * @tc.desc: SetResizeByDragEnabled and check the retCode - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplLayoutTest, SetResizeByDragEnabled03, TestSize.Level0) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("SetResizeByDragEnabled03"); - option->SetSubWindowDecorEnable(true); - sptr window = sptr::MakeSptr(option); - - window->property_->SetPersistentId(1); - SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - - window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); - WMError retCode = window->SetResizeByDragEnabled(true); - ASSERT_EQ(retCode, WMError::WM_OK); - - window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - retCode = window->SetResizeByDragEnabled(true); - ASSERT_EQ(retCode, WMError::WM_OK); - - window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE); - retCode = window->SetResizeByDragEnabled(true); - ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_TYPE); -} - -/** - * @tc.name: UpdateViewportConfig - * @tc.desc: UpdateViewportConfig - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplLayoutTest, UpdateViewportConfig, TestSize.Level0) -{ - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: UpdateViewportConfig start"; - sptr option = sptr::MakeSptr(); - option->SetWindowName("WindowSessionCreateCheck"); - sptr window = sptr::MakeSptr(option); - - Rect rectW; // GetRect().IsUninitializedRect is true - rectW.posX_ = 0; - rectW.posY_ = 0; - rectW.height_ = 0; // rectW - rect > 50 - rectW.width_ = 0; // rectW - rect > 50 - - window->virtualPixelRatio_ = -1.0; - window->useUniqueDensity_ = true; - WindowSizeChangeReason reason = WindowSizeChangeReason::UNDEFINED; - window->UpdateViewportConfig(rectW, reason); - ASSERT_EQ(window->virtualPixelRatio_, -1.0); - - window->virtualPixelRatio_ = -2.0; - DisplayId displayId = 1; - window->property_->SetDisplayId(displayId); - window->UpdateViewportConfig(rectW, reason); - ASSERT_EQ(window->virtualPixelRatio_, -2.0); - - displayId = 0; - rectW.height_ = 500; - rectW.width_ = 500; - window->useUniqueDensity_ = false; - window->property_->SetDisplayId(displayId); - window->UpdateViewportConfig(rectW, reason); - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: UpdateViewportConfig end"; -} - -/** - * @tc.name: UpdateViewportConfig01 - * @tc.desc: UpdateViewportConfig - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplLayoutTest, UpdateViewportConfig01, TestSize.Level1) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("UpdateViewportConfig01"); - sptr window = sptr::MakeSptr(option); - Rect rectW; - rectW.posX_ = 0; - rectW.posY_ = 0; - rectW.height_ = 0; - rectW.width_ = 0; - WindowSizeChangeReason reason = WindowSizeChangeReason::UNDEFINED; - sptr displayInfo = sptr::MakeSptr(); - window->UpdateViewportConfig(rectW, reason, nullptr, displayInfo); - rectW.width_ = 10; - rectW.height_ = 0; - window->UpdateViewportConfig(rectW, reason, nullptr, displayInfo); - rectW.width_ = 10; - rectW.height_ = 10; - window->UpdateViewportConfig(rectW, reason, nullptr, displayInfo); - ASSERT_NE(window, nullptr); -} - -/** - * @tc.name: NotifySingleHandTransformChange_TestUIContent - * @tc.desc: NotifySingleHandTransformChange - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplLayoutTest, NotifySingleHandTransformChange_TestUIContent, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifySingleHandTransformChange_TestUIContent start"; - sptr option = sptr::MakeSptr(); - option->SetWindowName("NotifySingleHandTransformChange_TestUIContent"); - option->SetIsUIExtFirstSubWindow(true); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(2025); - std::string url = ""; - window->SetUIContentInner( - url, nullptr, nullptr, WindowSetUIContentType::DEFAULT, BackupAndRestoreType::NONE, nullptr); - SingleHandTransform testTransform; - testTransform.posX = 100; - window->NotifySingleHandTransformChange(testTransform); - ASSERT_EQ(testTransform.posX, window->singleHandTransform_.posX); - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifySingleHandTransformChange_TestUIContent end"; -} - -/** - * @tc.name: NotifyTransformChange_TestUIContent - * @tc.desc: NotifyTransformChange - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplLayoutTest, NotifyTransformChange_TestUIContent, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyTransformChange_TestUIContent start"; - sptr option = sptr::MakeSptr(); - option->SetWindowName("NotifyTransformChange_TestUIContent"); - option->SetIsUIExtFirstSubWindow(true); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(2025); - - Transform testTransform; - window->uiContent_ = nullptr; - window->SetNeedRenotifyTransform(true); - window->NotifyTransformChange(testTransform); - ASSERT_EQ(true, window->IsNeedRenotifyTransform()); - - window->uiContent_ = std::make_unique(); - window->SetNeedRenotifyTransform(true); - window->NotifyTransformChange(testTransform); - ASSERT_EQ(false, window->IsNeedRenotifyTransform()); - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyTransformChange_TestUIContent end"; -} - -/** - * @tc.name: NotifyWindowStatusDidChange - * @tc.desc: NotifyWindowStatusDidChange - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplLayoutTest, NotifyWindowStatusDidChange, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyWindowStatusDidChange start"; - auto window = GetTestWindowImpl("NotifyWindowStatusDidChange"); - auto listeners = GetListenerList(); - EXPECT_NE(listeners.size(), 0); - listeners.insert(listeners.begin(), nullptr); - window->windowStatusDidChangeListeners_.insert({ window->GetPersistentId(), listeners }); - window->NotifyWindowStatusDidChange(WindowMode::WINDOW_MODE_FLOATING); - EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyWindowStatusDidChange end"; -} - -/** - * @tc.name: NotifyAfterUIContentReady - * @tc.desc: NotifyAfterUIContentReady - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplLayoutTest, NotifyAfterUIContentReady, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyAfterUIContentReady start"; - sptr option = sptr::MakeSptr(); - option->SetWindowName("NotifyAfterUIContentReady"); - option->SetIsUIExtFirstSubWindow(true); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(2025); - window->uiContent_ = std::make_unique(); - window->SetNeedRenotifyTransform(false); - window->NotifyAfterUIContentReady(); - ASSERT_EQ(false, window->IsNeedRenotifyTransform()); - window->SetNeedRenotifyTransform(false); - window->NotifyAfterUIContentReady(); - ASSERT_EQ(false, window->IsNeedRenotifyTransform()); - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyAfterUIContentReady end"; -} - -/** - * @tc.name: NotifyFirstValidLayoutUpdate - * @tc.desc: NotifyFirstValidLayoutUpdate - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplLayoutTest, NotifyFirstValidLayoutUpdate, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyFirstValidLayoutUpdate start"; - sptr option = sptr::MakeSptr(); - option->SetWindowName("NotifyFirstValidLayoutUpdate"); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(2025); - - Rect preRect = { 0, 0, 1000, 1000 }; - Rect newRect = { 0, 0, 0, 0 }; - window->isFirstValidLayoutUpdate_ = true; - window->NotifyFirstValidLayoutUpdate(preRect, newRect); - EXPECT_EQ(window->isFirstValidLayoutUpdate_, true); - - preRect = { 0, 0, 0, 0 }; - window->NotifyFirstValidLayoutUpdate(preRect, newRect); - EXPECT_EQ(window->isFirstValidLayoutUpdate_, true); - - - newRect = { 0, 0, 1000, 1000 }; - window->NotifyFirstValidLayoutUpdate(preRect, newRect); - EXPECT_EQ(window->isFirstValidLayoutUpdate_, false); - - window->NotifyFirstValidLayoutUpdate(preRect, newRect); - EXPECT_EQ(window->isFirstValidLayoutUpdate_, false); - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyFirstValidLayoutUpdate end"; -} -} -} // namespace Rosen -} // namespace OHOS