/* * 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 "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/keyboard_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 SceneSessionTest3 : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); void SetUp() override; void TearDown() override; }; void SceneSessionTest3::SetUpTestCase() { } void SceneSessionTest3::TearDownTestCase() { } void SceneSessionTest3::SetUp() { } void SceneSessionTest3::TearDown() { } namespace { /** * @tc.name: SetAspectRatio11 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, SetAspectRatio1, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "SetAspectRatio11"; info.bundleName_ = "SetAspectRatio11"; sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback_, nullptr); sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); scensession->isActive_ = true; scensession->property_ = nullptr; float ratio = 0.0001; auto result = scensession->SetAspectRatio(ratio); ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); } /** * @tc.name: SetAspectRatio12 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, SetAspectRatio12, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "SetAspectRatio12"; info.bundleName_ = "SetAspectRatio12"; sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback_, nullptr); sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); scensession->isActive_ = true; float ratio = 0.0001; scensession->moveDragController_ = nullptr; auto result = scensession->SetAspectRatio(ratio); ASSERT_EQ(result, WSError::WS_OK); scensession->moveDragController_ = new (std::nothrow) MoveDragController(0); result = scensession->SetAspectRatio(ratio); ASSERT_EQ(result, WSError::WS_OK); sptr property = new(std::nothrow) WindowSessionProperty(); EXPECT_NE(property, nullptr); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); scensession->SetSessionProperty(property); result = scensession->SetAspectRatio(ratio); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: SetAspectRatio15 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, SetAspectRatio15, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "SetAspectRatio15"; info.bundleName_ = "SetAspectRatio15"; sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback_, nullptr); sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); scensession->isActive_ = true; float ratio = 0.1; sptr property = new(std::nothrow) WindowSessionProperty(); EXPECT_NE(property, nullptr); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); scensession->SetSessionProperty(property); WindowLimits limits; limits.maxHeight_ = 10; limits.minWidth_ = 0; property->SetWindowLimits(limits); scensession->SetAspectRatio(ratio); limits.maxHeight_ = 0; limits.minWidth_ = 10; property->SetWindowLimits(limits); scensession->SetAspectRatio(ratio); EXPECT_NE(scensession, nullptr); } /** * @tc.name: SetAspectRatio8 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, SetAspectRatio8, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "SetAspectRatio8"; info.bundleName_ = "SetAspectRatio8"; sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback_, nullptr); sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); scensession->isActive_ = true; sptr property = new(std::nothrow) WindowSessionProperty(); EXPECT_NE(property, nullptr); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); scensession->SetSessionProperty(property); float ratio = 0.1; WindowLimits limits; limits.maxHeight_ = 10; limits.minWidth_ = 10; property->SetWindowLimits(limits); auto result = scensession->SetAspectRatio(ratio); ratio = 10; result = scensession->SetAspectRatio(ratio); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: UpdateRect1 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, UpdateRect1, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "UpdateRect1"; info.bundleName_ = "UpdateRect1"; sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback_, nullptr); sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); scensession->isActive_ = true; sptr property = new(std::nothrow) WindowSessionProperty(); EXPECT_NE(property, nullptr); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); scensession->SetSessionProperty(property); WSRect rect({1, 1, 1, 1}); SizeChangeReason reason = SizeChangeReason::UNDEFINED; WSError result = scensession->UpdateRect(rect, reason, "SceneSessionTest3"); ASSERT_EQ(result, WSError::WS_OK); scensession->winRect_ = rect; result = scensession->UpdateRect(rect, reason, "SceneSessionTest3"); ASSERT_EQ(result, WSError::WS_OK); scensession->reason_ = SizeChangeReason::DRAG_END; result = scensession->UpdateRect(rect, reason, "SceneSessionTest3"); ASSERT_EQ(result, WSError::WS_OK); WSRect rect2({0, 0, 0, 0}); result = scensession->UpdateRect(rect2, reason, "SceneSessionTest3"); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: FixKeyboardPositionByKeyboardPanel * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, FixKeyboardPositionByKeyboardPanel, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "FixKeyboardPositionByKeyboardPanel"; info.bundleName_ = "FixKeyboardPositionByKeyboardPanel"; sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback_, nullptr); sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); scensession->isActive_ = true; sptr property = new(std::nothrow) WindowSessionProperty(); EXPECT_NE(property, nullptr); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); scensession->SetSessionProperty(property); scensession->FixKeyboardPositionByKeyboardPanel(nullptr, nullptr); ASSERT_NE(scensession, nullptr); } /** * @tc.name: FixKeyboardPositionByKeyboardPanel1 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, FixKeyboardPositionByKeyboardPanel1, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "FixKeyboardPositionByKeyboardPanel1"; info.bundleName_ = "FixKeyboardPositionByKeyboardPanel1"; sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback_, nullptr); sptr scenceSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scenceSession, nullptr); scenceSession->isActive_ = true; sptr property = new(std::nothrow) WindowSessionProperty(); EXPECT_NE(property, nullptr); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); scenceSession->SetSessionProperty(property); scenceSession->FixKeyboardPositionByKeyboardPanel(scenceSession, scenceSession); ASSERT_NE(scenceSession, nullptr); sptr keyboardSession = new (std::nothrow) KeyboardSession(info, nullptr, nullptr); ASSERT_NE(keyboardSession, nullptr); property->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_FLOAT; scenceSession->FixKeyboardPositionByKeyboardPanel(scenceSession, keyboardSession); } /** * @tc.name: NotifyClientToUpdateRectTask * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, NotifyClientToUpdateRectTask, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "NotifyClientToUpdateRectTask"; info.bundleName_ = "NotifyClientToUpdateRectTask"; sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); sceneSession->isActive_ = true; sptr property = new (std::nothrow) WindowSessionProperty(); EXPECT_NE(property, nullptr); property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sceneSession->SetSessionProperty(property); auto result = sceneSession->NotifyClientToUpdateRectTask("SceneSessionTest3", nullptr); ASSERT_NE(result, WSError::WS_OK); property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL); sceneSession->SetSessionProperty(property); sceneSession->isKeyboardPanelEnabled_ = true; sceneSession->state_ = SessionState::STATE_FOREGROUND; sceneSession->isScbCoreEnabled_ = false; ASSERT_EQ(WSError::WS_OK, sceneSession->NotifyClientToUpdateRectTask("SceneSessionTest3", nullptr)); property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL); sceneSession->SetSessionProperty(property); sceneSession->isKeyboardPanelEnabled_ = true; ASSERT_EQ(WSError::WS_OK, sceneSession->NotifyClientToUpdateRectTask("SceneSessionTest3", nullptr)); std::shared_ptr rs; ASSERT_EQ(WSError::WS_OK, sceneSession->NotifyClientToUpdateRectTask("SceneSessionTest3", rs)); } /** * @tc.name: BindDialogSessionTarget1 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, BindDialogSessionTarget1, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "BindDialogSessionTarget1"; info.bundleName_ = "BindDialogSessionTarget1"; sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback_, nullptr); sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); scensession->isActive_ = true; sptr property = new(std::nothrow) WindowSessionProperty(); EXPECT_NE(property, nullptr); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); property->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM; scensession->SetSessionProperty(property); sptr sceneSession = nullptr; WSError result = scensession->BindDialogSessionTarget(sceneSession); ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); scensession->sessionChangeCallback_ = nullptr; sptr sceneSession1 = scensession; result = scensession->BindDialogSessionTarget(sceneSession1); ASSERT_EQ(result, WSError::WS_OK); sceneSession1->sessionChangeCallback_ = new (std::nothrow) MainSession::SessionChangeCallback(); EXPECT_NE(sceneSession1->sessionChangeCallback_, nullptr); sceneSession1->sessionChangeCallback_->onBindDialogTarget_ = [](const sptr&) {}; result = scensession->BindDialogSessionTarget(sceneSession1); ASSERT_EQ(result, WSError::WS_OK); } /** * @tc.name: ClearSpecificSessionCbMap1 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, ClearSpecificSessionCbMap1, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "ClearSpecificSessionCbMap1"; info.bundleName_ = "ClearSpecificSessionCbMap1"; sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(nullptr, scensession); scensession->ClearSpecificSessionCbMap(); sptr sessionChangeCallback = new (std::nothrow) MainSession::SessionChangeCallback(); scensession->clearCallbackMapFunc_ = [](bool, int32_t) {}; scensession->sessionChangeCallback_ = sessionChangeCallback; scensession->ClearSpecificSessionCbMap(); } /** * @tc.name: IsMovableWindowType * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, IsMovableWindowType, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "IsMovableWindowType"; info.bundleName_ = "IsMovableWindowType"; sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(nullptr, scensession); scensession->property_ = nullptr; EXPECT_EQ(scensession->IsMovableWindowType(), false); } /** * @tc.name: SetBlankFlag * @tc.desc: check func SetBlankFlag * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, SetBlankFlag, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "SetBlankFlag"; info.bundleName_ = "SetBlankFlag"; sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(nullptr, scensession); bool isAddBlank = true; scensession->SetBlankFlag(isAddBlank); ASSERT_EQ(isAddBlank, scensession->GetBlankFlag()); } /** * @tc.name: GetBlankFlag * @tc.desc: check func GetBlankFlag * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, GetBlankFlag, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "GetBlankFlag"; info.bundleName_ = "GetBlankFlag"; sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(nullptr, scensession); bool isAddBlank = true; scensession->SetBlankFlag(isAddBlank); ASSERT_EQ(isAddBlank, scensession->GetBlankFlag()); } /** * @tc.name: SetBufferAvailableCallbackEnable * @tc.desc: check func SetBufferAvailableCallbackEnable * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, SetBufferAvailableCallbackEnable, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "SetBufferAvailableCallbackEnable"; info.bundleName_ = "SetBufferAvailableCallbackEnable"; sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(nullptr, scensession); bool enable = true; scensession->SetBufferAvailableCallbackEnable(enable); ASSERT_EQ(enable, scensession->GetBufferAvailableCallbackEnable()); } /** * @tc.name: GetBufferAvailableCallbackEnable * @tc.desc: check func GetBufferAvailableCallbackEnable * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, GetBufferAvailableCallbackEnable, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "GetBufferAvailableCallbackEnable"; info.bundleName_ = "GetBufferAvailableCallbackEnable"; sptr scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(nullptr, scensession); bool enable = true; scensession->SetBufferAvailableCallbackEnable(enable); ASSERT_EQ(enable, scensession->GetBufferAvailableCallbackEnable()); } /** * @tc.name: UpdateScaleInner * @tc.desc: check func UpdateScaleInner * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, UpdateScaleInner, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "UpdateScaleInner"; info.bundleName_ = "UpdateScaleInner"; sptr sceneSession = sptr::MakeSptr(info, nullptr); EXPECT_NE(nullptr, sceneSession); sceneSession->sessionStage_ = nullptr; sceneSession->state_ = SessionState::STATE_FOREGROUND; bool res = sceneSession->UpdateScaleInner(10.0f, 10.0f, 10.0f, 10.0f); EXPECT_EQ(true, res); res = sceneSession->UpdateScaleInner(10.0f, 9.0f, 10.0f, 10.0f); res = sceneSession->UpdateScaleInner(10.0f, 9.0f, 9.0f, 10.0f); res = sceneSession->UpdateScaleInner(10.0f, 9.0f, 9.0f, 9.0f); EXPECT_EQ(true, res); sceneSession->state_ = SessionState::STATE_BACKGROUND; res = sceneSession->UpdateScaleInner(10.0f, 9.0f, 9.0f, 9.0f); EXPECT_EQ(false, res); sceneSession->state_ = SessionState::STATE_FOREGROUND; sptr mockSessionStage = sptr::MakeSptr(); ASSERT_NE(mockSessionStage, nullptr); sceneSession->sessionStage_ = mockSessionStage; res = sceneSession->UpdateScaleInner(1.0f, 2.0f, 3.0f, 4.0f); EXPECT_EQ(true, res); res = sceneSession->UpdateScaleInner(1.0f, 2.0f, 3.0f, 4.0f); EXPECT_EQ(false, res); } /** * @tc.name: SetWindowRectAutoSaveCallback * @tc.desc: SetWindowRectAutoSaveCallback * @tc.type: FUNC */ HWTEST_F(SceneSessionTest3, SetWindowRectAutoSaveCallback, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "SetWindowRectAutoSaveCallback"; info.bundleName_ = "SetWindowRectAutoSaveCallback"; sptr sceneSession = sptr::MakeSptr(info, nullptr); sptr windowSessionProperty = sptr::MakeSptr(); sceneSession->property_ = windowSessionProperty; NotifySetWindowRectAutoSaveFunc func1 = [](bool enabled) { return; }; sceneSession->SetWindowRectAutoSaveCallback(std::move(func1)); ASSERT_NE(nullptr, sceneSession->onSetWindowRectAutoSaveFunc_); } } } }