!10841 超大文件整改

Merge pull request !10841 from hwangsong/master
This commit is contained in:
openharmony_ci 2024-11-18 07:19:35 +00:00 committed by Gitee
commit b0ff461050
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 767 additions and 937 deletions

View File

@ -28,6 +28,7 @@ group("unittest") {
":ws_hidumper_controller_test",
":ws_intention_event_manager_test",
":ws_keyboard_session_test",
":ws_keyboard_session_test2",
":ws_main_session_lifecycle_test",
":ws_main_session_test",
":ws_move_drag_controller_test",
@ -172,7 +173,19 @@ ohos_unittest("ws_keyboard_session_test") {
external_deps = [
"c_utils:utils",
"hilog:libhilog",
"init:libbegetutil",
]
}
ohos_unittest("ws_keyboard_session_test2") {
module_out_path = module_out_path
sources = [ "keyboard_session_test2.cpp" ]
deps = [ ":ws_unittest_common" ]
external_deps = [
"c_utils:utils",
"hilog:libhilog",
]
}

View File

@ -15,14 +15,11 @@
#include "session/host/include/keyboard_session.h"
#include <gtest/gtest.h>
#include <parameters.h>
#include "common/include/session_permission.h"
#include "interfaces/include/ws_common.h"
#include "mock/mock_session_stage.h"
#include "mock/mock_keyboard_session.h"
#include "session/host/include/session.h"
#include "screen_session_manager_client/include/screen_session_manager_client.h"
#include "session/host/include/scene_session.h"
#include "window_helper.h"
#include "window_manager_hilog.h"
@ -36,17 +33,15 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "KeyboardSessionTest"};
}
constexpr int WAIT_ASYNC_US = 1000000;
class KeyboardSessionTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
private:
sptr<KeyboardSession> GetKeyboardSession(const std::string& abilityName, const std::string& bundleName);
sptr<SceneSession> GetSceneSession(const std::string& abilityName, const std::string& bundleName);
sptr<KSSceneSessionMocker> GetSceneSessionMocker(const std::string& abilityName, const std::string& bundleName);
};
void KeyboardSessionTest::SetUpTestCase()
@ -65,29 +60,6 @@ void KeyboardSessionTest::TearDown()
{
}
sptr<KeyboardSession> KeyboardSessionTest::GetKeyboardSession(const std::string& abilityName,
const std::string& bundleName)
{
SessionInfo info;
info.abilityName_ = abilityName;
info.bundleName_ = bundleName;
sptr<SceneSession::SpecificSessionCallback> specificCb =
new (std::nothrow) SceneSession::SpecificSessionCallback();
EXPECT_NE(specificCb, nullptr);
sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
EXPECT_NE(keyboardCb, nullptr);
sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
EXPECT_NE(keyboardSession, nullptr);
sptr<WindowSessionProperty> keyboardProperty = new (std::nothrow) WindowSessionProperty();
EXPECT_NE(keyboardProperty, nullptr);
keyboardProperty->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
keyboardSession->SetSessionProperty(keyboardProperty);
return keyboardSession;
}
sptr<SceneSession> KeyboardSessionTest::GetSceneSession(const std::string& abilityName,
const std::string& bundleName)
{
@ -102,20 +74,6 @@ sptr<SceneSession> KeyboardSessionTest::GetSceneSession(const std::string& abili
return sceneSession;
}
sptr<KSSceneSessionMocker> KeyboardSessionTest::GetSceneSessionMocker(const std::string& abilityName,
const std::string& bundleName)
{
SessionInfo info;
info.abilityName_ = abilityName;
info.bundleName_ = bundleName;
sptr<SceneSession::SpecificSessionCallback> specificCb =
new (std::nothrow) SceneSession::SpecificSessionCallback();
EXPECT_NE(specificCb, nullptr);
sptr<KSSceneSessionMocker> mockSession = sptr<KSSceneSessionMocker>::MakeSptr(info, nullptr);
return mockSession;
}
namespace {
/**
* @tc.name: Show
@ -640,217 +598,6 @@ HWTEST_F(KeyboardSessionTest, GetCallingSessionId, Function | SmallTest | Level1
ASSERT_EQ(ret, INVALID_WINDOW_ID);
}
/**
* @tc.name: AdjustKeyboardLayout01
* @tc.desc: AdjustKeyboardLayout
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, AdjustKeyboardLayout01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "AdjustKeyboardLayout01";
info.bundleName_ = "AdjustKeyboardLayout01";
sptr<SceneSession::SpecificSessionCallback> specificCb =
new (std::nothrow) SceneSession::SpecificSessionCallback();
EXPECT_NE(specificCb, nullptr);
sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
EXPECT_NE(keyboardCb, nullptr);
sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
EXPECT_NE(keyboardSession, nullptr);
sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
keyboardSession->SetSessionProperty(property);
keyboardSession->RegisterSessionChangeCallback(nullptr);
KeyboardLayoutParams params;
ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
sptr<SceneSession::SessionChangeCallback> sessionChangeCallback =
new (std::nothrow) SceneSession::SessionChangeCallback();
EXPECT_NE(sessionChangeCallback, nullptr);
keyboardSession->adjustKeyboardLayoutFunc_ = nullptr;
keyboardSession->RegisterSessionChangeCallback(sessionChangeCallback);
ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
keyboardSession->adjustKeyboardLayoutFunc_ = [](const KeyboardLayoutParams& params){};
ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
}
/**
* @tc.name: AdjustKeyboardLayout01
* @tc.desc: AdjustKeyboardLayout
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, AdjustKeyboardLayout02, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "AdjustKeyboardLayout02";
info.bundleName_ = "AdjustKeyboardLayout02";
sptr<SceneSession::SpecificSessionCallback> specificCb =
new (std::nothrow) SceneSession::SpecificSessionCallback();
EXPECT_NE(specificCb, nullptr);
sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
EXPECT_NE(keyboardCb, nullptr);
sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
EXPECT_NE(keyboardSession, nullptr);
keyboardSession->SetSessionProperty(nullptr);
KeyboardLayoutParams params;
ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
}
/**
* @tc.name: CheckIfNeedRaiseCallingSession
* @tc.desc: CheckIfNeedRaiseCallingSession
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, CheckIfNeedRaiseCallingSession, Function | SmallTest | Level1)
{
WLOGFI("CheckIfNeedRaiseCallingSession begin!");
SessionInfo info;
info.abilityName_ = "CheckIfNeedRaiseCallingSession";
info.bundleName_ = "CheckIfNeedRaiseCallingSession";
sptr<SceneSession::SpecificSessionCallback> specificCb =
new (std::nothrow) SceneSession::SpecificSessionCallback();
EXPECT_NE(specificCb, nullptr);
sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
EXPECT_NE(keyboardCb, nullptr);
sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
EXPECT_NE(keyboardSession, nullptr);
sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
EXPECT_NE(property, nullptr);
property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
keyboardSession->SetSessionProperty(property);
ASSERT_FALSE(keyboardSession->CheckIfNeedRaiseCallingSession(nullptr, true));
sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCb);
EXPECT_NE(sceneSession, nullptr);
keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_FLOAT;
ASSERT_FALSE(keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, true));
keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
ASSERT_TRUE(keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, false));
property->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
ASSERT_FALSE(keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, true));
property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, true);
WLOGFI("CheckIfNeedRaiseCallingSession end!");
}
/**
* @tc.name: OpenKeyboardSyncTransaction
* @tc.desc: OpenKeyboardSyncTransaction
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, OpenKeyboardSyncTransaction, Function | SmallTest | Level1)
{
std::string abilityName = "OpenKeyboardSyncTransaction";
std::string bundleName = "OpenKeyboardSyncTransaction";
sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
// isKeyBoardSyncTransactionOpen_ is false
keyboardSession->OpenKeyboardSyncTransaction();
// isKeyBoardSyncTransactionOpen_ is true
keyboardSession->OpenKeyboardSyncTransaction();
}
/**
* @tc.name: CloseKeyboardSyncTransaction1
* @tc.desc: CloseKeyboardSyncTransaction1
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, CloseKeyboardSyncTransaction1, Function | SmallTest | Level1)
{
std::string abilityName = "CloseKeyboardSyncTransaction1";
std::string bundleName = "CloseKeyboardSyncTransaction1";
sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
WSRect keyboardPanelRect = { 0, 0, 0, 0 };
bool isKeyboardShow = true;
bool isRotating = false;
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, isRotating);
}
/**
* @tc.name: CloseKeyboardSyncTransaction2
* @tc.desc: CloseKeyboardSyncTransaction2
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, CloseKeyboardSyncTransaction2, Function | SmallTest | Level1)
{
std::string abilityName = "CloseKeyboardSyncTransaction2";
std::string bundleName = "CloseKeyboardSyncTransaction2";
sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
WSRect keyboardPanelRect = { 0, 0, 0, 0 };
bool isKeyboardShow = true;
bool isRotating = false;
// isKeyBoardSyncTransactionOpen_ is true
keyboardSession->OpenKeyboardSyncTransaction();
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, isRotating);
}
/**
* @tc.name: BindKeyboardPanelSession
* @tc.desc: BindKeyboardPanelSession
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, BindKeyboardPanelSession, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "BindKeyboardPanelSession";
info.bundleName_ = "BindKeyboardPanelSession";
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
sptr<SceneSession> panelSession = nullptr;
keyboardSession->BindKeyboardPanelSession(panelSession);
sptr<SceneSession> getPanelSession = keyboardSession->GetKeyboardPanelSession();
ASSERT_EQ(getPanelSession, nullptr);
panelSession = sptr<SceneSession>::MakeSptr(info, nullptr);
ASSERT_NE(panelSession, nullptr);
keyboardSession->BindKeyboardPanelSession(panelSession);
getPanelSession = keyboardSession->GetKeyboardPanelSession();
EXPECT_EQ(getPanelSession, panelSession);
}
/**
* @tc.name: GetKeyboardGravity01
* @tc.desc: GetKeyboardGravity01
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, GetKeyboardGravity01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "GetKeyboardGravity";
info.bundleName_ = "GetKeyboardGravity";
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
keyboardSession->property_ = nullptr;
auto ret = keyboardSession->GetKeyboardGravity();
EXPECT_EQ(SessionGravity::SESSION_GRAVITY_DEFAULT, ret);
sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
ASSERT_NE(windowSessionProperty, nullptr);
keyboardSession->property_ = windowSessionProperty;
ASSERT_NE(keyboardSession->property_, nullptr);
keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
ASSERT_NE(keyboardSession, nullptr);
ret = keyboardSession->GetKeyboardGravity();
EXPECT_EQ(SessionGravity::SESSION_GRAVITY_BOTTOM, ret);
}
/**
* @tc.name: GetCallingSessionId01
* @tc.desc: GetCallingSessionId01
@ -875,688 +622,6 @@ HWTEST_F(KeyboardSessionTest, GetCallingSessionId01, Function | SmallTest | Leve
EXPECT_EQ(ret, 1);
}
/**
* @tc.name: NotifyKeyboardPanelInfoChange
* @tc.desc: NotifyKeyboardPanelInfoChange
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, NotifyKeyboardPanelInfoChange, Function | SmallTest | Level1)
{
WSRect rect = {800, 800, 1200, 1200};
SessionInfo info;
info.abilityName_ = "NotifyKeyboardPanelInfoChange";
info.bundleName_ = "NotifyKeyboardPanelInfoChange";
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
keyboardSession->isKeyboardPanelEnabled_ = false;
keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
keyboardSession->isKeyboardPanelEnabled_ = true;
keyboardSession->sessionStage_ = nullptr;
keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
ASSERT_NE(mockSessionStage, nullptr);
keyboardSession->sessionStage_ = mockSessionStage;
ASSERT_NE(keyboardSession->sessionStage_, nullptr);
keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
}
/**
* @tc.name: CheckIfNeedRaiseCallingSession01
* @tc.desc: CheckIfNeedRaiseCallingSession01
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, CheckIfNeedRaiseCallingSession01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "CheckIfNeedRaiseCallingSession";
info.bundleName_ = "CheckIfNeedRaiseCallingSession";
sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
ASSERT_NE(specificCb, nullptr);
sptr<SceneSession> callingSession = sptr<SceneSession>::MakeSptr(info, specificCb);
ASSERT_NE(callingSession, nullptr);
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
ASSERT_NE(windowSessionProperty, nullptr);
keyboardSession->property_ = windowSessionProperty;
ASSERT_NE(keyboardSession->property_, nullptr);
keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
keyboardSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
callingSession->systemConfig_.freeMultiWindowSupport_ = true;
callingSession->systemConfig_.freeMultiWindowEnable_ = true;
auto ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
EXPECT_EQ(ret, false);
callingSession->systemConfig_.freeMultiWindowEnable_ = false;
ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
EXPECT_EQ(ret, false);
callingSession->systemConfig_.freeMultiWindowEnable_ = true;
keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
EXPECT_EQ(ret, true);
keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
callingSession->systemConfig_.freeMultiWindowEnable_ = false;
ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
EXPECT_EQ(ret, true);
keyboardSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
EXPECT_EQ(ret, true);
ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, false);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: UpdateCallingSessionIdAndPosition01
* @tc.desc: UpdateCallingSessionIdAndPosition01
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, UpdateCallingSessionIdAndPosition01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "UpdateCallingSessionIdAndPosition";
info.bundleName_ = "UpdateCallingSessionIdAndPosition";
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
keyboardSession->property_ = nullptr;
keyboardSession->UpdateCallingSessionIdAndPosition(0);
sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
ASSERT_NE(windowSessionProperty, nullptr);
keyboardSession->property_ = windowSessionProperty;
ASSERT_NE(keyboardSession->property_, nullptr);
keyboardSession->property_->SetCallingSessionId(-1);
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
keyboardSession->UpdateCallingSessionIdAndPosition(0);
keyboardSession->state_ = SessionState::STATE_CONNECT;
keyboardSession->UpdateCallingSessionIdAndPosition(0);
keyboardSession->UpdateCallingSessionIdAndPosition(-1);
keyboardSession->property_->SetCallingSessionId(0);
keyboardSession->UpdateCallingSessionIdAndPosition(0);
}
/**
* @tc.name: OpenKeyboardSyncTransaction01
* @tc.desc: OpenKeyboardSyncTransaction
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, OpenKeyboardSyncTransaction01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "UpdateCallingSessionIdAndPosition";
info.bundleName_ = "UpdateCallingSessionIdAndPosition";
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
keyboardSession->isKeyboardSyncTransactionOpen_ = true;
keyboardSession->OpenKeyboardSyncTransaction();
keyboardSession->isKeyboardSyncTransactionOpen_ = false;
keyboardSession->OpenKeyboardSyncTransaction();
WSRect keyboardPanelRect = {0, 0, 0, 0};
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, true, true);
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, false);
}
/**
* @tc.name: RelayoutKeyBoard01
* @tc.desc: RelayoutKeyBoard01
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, RelayoutKeyBoard01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "RelayoutKeyBoard";
info.bundleName_ = "RelayoutKeyBoard";
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
keyboardSession->property_ = nullptr;
keyboardSession->RelayoutKeyBoard();
sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
ASSERT_NE(windowSessionProperty, nullptr);
keyboardSession->property_ = windowSessionProperty;
ASSERT_NE(keyboardSession->property_, nullptr);
keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
keyboardSession->RelayoutKeyBoard();
}
/**
* @tc.name: Hide01
* @tc.desc: test function : Hide
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, Hide01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "Hide";
info.bundleName_ = "Hide";
sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
ASSERT_NE(specificCb, nullptr);
sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
ASSERT_NE(keyboardCb, nullptr);
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
ASSERT_NE(keyboardSession, nullptr);
// setActive false return not ok
keyboardSession->state_ = SessionState::STATE_DISCONNECT;
EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
// setActive false return ok and deviceType is phone
keyboardSession->state_ = SessionState::STATE_CONNECT;
keyboardSession->isActive_ = true;
keyboardSession->sessionStage_ = new (std::nothrow) SessionStageMocker();
ASSERT_NE(keyboardSession->sessionStage_, nullptr);
keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
// deviceType is pc and property is not nullptr
ASSERT_NE(keyboardSession->property_, nullptr);
keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
// deviceType is pc and property is nullptr
keyboardSession->property_ = nullptr;
EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
}
/**
* @tc.name: RaiseCallingSession01
* @tc.desc: test function : RaiseCallingSession
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, RaiseCallingSession01, Function | SmallTest | Level1)
{
auto keyboardSession = GetKeyboardSession("RaiseCallingSession01",
"RaiseCallingSession01");
ASSERT_NE(keyboardSession, nullptr);
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
keyboardSession->isVisible_ = true;
Rosen::WSRect resultRect{ 0, 0, 0, 0 };
sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
ASSERT_NE(callingSession, nullptr);
callingSession->updateRectCallback_ = [&resultRect](const WSRect& rect, SizeChangeReason reason) {
resultRect.posX_ = rect.posX_;
resultRect.posY_ = rect.posY_;
resultRect.width_ = rect.width_;
resultRect.height_ = rect.height_;
};
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
Rosen::WSRect keyboardPanelRect{ 0, 0, 0, 0 };
Rosen::WSRect emptyRect{ 0, 0, 0, 0 };
std::shared_ptr<RSTransaction> rsTransaction = nullptr;
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, rsTransaction);
ASSERT_EQ(resultRect, emptyRect);
// for cover GetSceneSession
keyboardSession->keyboardCallback_->onGetSceneSession_ =
[callingSession](int32_t persistentId)->sptr<SceneSession> {
return callingSession;
};
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, rsTransaction);
// for cover CheckIfNeedRaiseCallingSession
keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
// for empty rect check;
keyboardSession->winRect_.posX_ = 1;
keyboardSession->winRect_.posY_ = 1;
keyboardSession->winRect_.posX_ = 1;
keyboardSession->winRect_.posX_ = 1;
// for cover oriPosYBeforeRaisedBykeyboard == 0
callingSession->SetOriPosYBeforeRaisedByKeyboard(0);
ASSERT_EQ(resultRect, emptyRect);
}
/**
* @tc.name: RaiseCallingSession02
* @tc.desc: test function : RaiseCallingSession
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, RaiseCallingSession02, Function | SmallTest | Level1)
{
Rosen::WSRect keyboardPanelRect{ 1, 1, 1, 1 };
auto keyboardSession = GetKeyboardSession("RaiseCallingSession02",
"RaiseCallingSession02");
ASSERT_NE(keyboardSession, nullptr);
sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
ASSERT_NE(callingSession, nullptr);
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
callingSession->winRect_ = { 1, 1, 1, 1 };
keyboardSession->keyboardCallback_->onGetSceneSession_ = [callingSession](int32_t persistentId) {
return callingSession;
};
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
keyboardSession->isVisible_ = true;
callingSession->oriPosYBeforeRaisedByKeyboard_ = 0;
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->winRect_.posY_, 1);
callingSession->oriPosYBeforeRaisedByKeyboard_ = 10;
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->winRect_.posY_, 1);
keyboardPanelRect = { 0, 0, 0, 0 };
callingSession->oriPosYBeforeRaisedByKeyboard_ = 10;
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->winRect_.posY_, 1);
}
/**
* @tc.name: RaiseCallingSession03
* @tc.desc: test function : RaiseCallingSession
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, RaiseCallingSession03, Function | SmallTest | Level1)
{
Rosen::WSRect keyboardPanelRect{ 1, 1, 1, 1 };
auto keyboardSession = GetKeyboardSession("RaiseCallingSession03",
"RaiseCallingSession03");
ASSERT_NE(keyboardSession, nullptr);
sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
ASSERT_NE(callingSession, nullptr);
callingSession->winRect_ = { 1, 1, 1, 1 };
callingSession->oriPosYBeforeRaisedByKeyboard_ = 0;
callingSession->updateRectCallback_ = [](const WSRect& rect, SizeChangeReason reason) {};
keyboardSession->keyboardCallback_->onGetSceneSession_ = [callingSession](int32_t persistentId) {
return callingSession;
};
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
keyboardSession->isVisible_ = true;
auto callingOriPosY = 0;
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
callingOriPosY = callingSession->oriPosYBeforeRaisedByKeyboard_;
ASSERT_EQ(callingOriPosY, 0);
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
callingSession->winRect_.posY_ = 200;
keyboardPanelRect.posY_ = 200;
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
callingOriPosY = callingSession->oriPosYBeforeRaisedByKeyboard_;
ASSERT_EQ(callingOriPosY, 200);
callingSession->oriPosYBeforeRaisedByKeyboard_ = 10;
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
callingOriPosY = callingSession->oriPosYBeforeRaisedByKeyboard_;
ASSERT_EQ(callingOriPosY, 10);
}
/**
* @tc.name: IsCallingSessionSplitMode01
* @tc.desc: test function : IsCallingSessionSplitMode
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, IsCallingSessionSplitMode01, Function | SmallTest | Level1)
{
Rosen::WSRect keyboardPanelRect{ 0, 0, 0, 0 };
auto keyboardSession = GetKeyboardSession("IsCallingSessionSplitMode01",
"IsCallingSessionSplitMode01");
ASSERT_NE(keyboardSession, nullptr);
sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
ASSERT_NE(callingSession, nullptr);
callingSession->oriPosYBeforeRaisedByKeyboard_ = 0;
callingSession->winRect_ = { 0, 0, 0, 0 };
callingSession->updateRectCallback_ = [](const WSRect& rect, SizeChangeReason reason) {};
keyboardSession->keyboardCallback_->onGetSceneSession_ = [callingSession](int32_t persistentId) {
return callingSession;
};
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
auto callingParentSession = GetSceneSession("callingParentSession", "callingParentSession");
ASSERT_NE(callingSession, nullptr);
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
callingSession->parentSession_ = callingParentSession;
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
callingParentSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
callingParentSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
}
/**
* @tc.name: CloseKeyBoardSyncTransaction3
* @tc.desc: test function : CloseKeyBoardSyncTransaction
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, CloseKeyBoardSyncTransaction3, Function | SmallTest | Level1)
{
std::string abilityName = "CloseKeyBoardSyncTransaction3";
std::string bundleName = "CloseKeyBoardSyncTransaction3";
sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
ASSERT_NE(keyboardSession, nullptr);
WSRect keyboardPanelRect = { 0, 0, 0, 0 };
bool isKeyboardShow = true;
bool isRotating = false;
keyboardSession->dirtyFlags_ = 0;
keyboardSession->specificCallback_->onUpdateAvoidArea_ = [](uint32_t callingSessionId) {};
keyboardSession->isKeyboardSyncTransactionOpen_ = true;
// isKeyBoardSyncTransactionOpen_ is true
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, isRotating);
usleep(WAIT_ASYNC_US);
ASSERT_EQ(keyboardSession->isKeyboardSyncTransactionOpen_, false);
}
/**
* @tc.name: CloseKeyboardSyncTransaction4
* @tc.desc: test function : CloseKeyboardSyncTransaction
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, CloseKeyboardSyncTransaction4, Function | SmallTest | Level1)
{
std::string abilityName = "CloseKeyboardSyncTransaction4";
std::string bundleName = "CloseKeyboardSyncTransaction4";
sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
ASSERT_NE(keyboardSession, nullptr);
WSRect keyboardPanelRect = { 0, 0, 0, 0 };
keyboardSession->dirtyFlags_ = 0;
keyboardSession->isKeyboardSyncTransactionOpen_ = false;
keyboardSession->property_ = nullptr;
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, false);
usleep(WAIT_ASYNC_US);
ASSERT_EQ(0, keyboardSession->dirtyFlags_);
sptr<WindowSessionProperty> keyboardProperty = sptr<WindowSessionProperty>::MakeSptr();
ASSERT_NE(keyboardProperty, nullptr);
keyboardSession->property_ = keyboardProperty;
keyboardSession->isKeyboardSyncTransactionOpen_ = true;
keyboardSession->property_->SetCallingSessionId(1);
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, false);
usleep(WAIT_ASYNC_US);
auto callingSessionId = keyboardSession->property_->GetCallingSessionId();
ASSERT_EQ(callingSessionId, INVALID_WINDOW_ID);
}
/**
* @tc.name: GetRSTransaction01
* @tc.desc: test function : GetRSTransaction
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, GetRSTransaction01, Function | SmallTest | Level1)
{
auto keyboardSession = GetKeyboardSession("GetRSTransaction01",
"GetRSTransaction01");
ASSERT_NE(keyboardSession, nullptr);
auto rsTransaction = keyboardSession->GetRSTransaction();
ASSERT_EQ(rsTransaction, nullptr);
}
/**
* @tc.name: GetSessionScreenName01
* @tc.desc: test function : GetSessionScreenName
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, GetSessionScreenName01, Function | SmallTest | Level1)
{
auto keyboardSession = GetKeyboardSession("GetSessionScreenName01",
"GetSessionScreenName01");
ASSERT_NE(keyboardSession, nullptr);
keyboardSession->property_ = nullptr;
auto resultStr = keyboardSession->GetSessionScreenName();
ASSERT_EQ(resultStr, "");
sptr<WindowSessionProperty> keyboardProperty = sptr<WindowSessionProperty>::MakeSptr();
ASSERT_NE(keyboardProperty, nullptr);
keyboardSession->property_ = keyboardProperty;
keyboardSession->property_->displayId_ = 100;
sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr();
ASSERT_NE(screenSession, nullptr);
screenSession->name_ = "testScreenSession";
screenSession->screenId_ = 100;
ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(100, screenSession);
resultStr = keyboardSession->GetSessionScreenName();
ASSERT_EQ(resultStr, screenSession->name_);
}
/**
* @tc.name: UseFocusIdIfCallingSessionIdInvalid01
* @tc.desc: test function : UseFocusIdIfCallingSessionIdInvalid
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, UseFocusIdIfCallingSessionIdInvalid01, Function | SmallTest | Level1)
{
auto keyboardSession = GetKeyboardSession("UseFocusIdIfCallingSessionIdInvalid01",
"UseFocusIdIfCallingSessionIdInvalid01");
ASSERT_NE(keyboardSession, nullptr);
sptr<KeyboardSession::KeyboardSessionCallback> keyboardCallback =
sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
ASSERT_NE(keyboardCallback, nullptr);
keyboardSession->keyboardCallback_ = keyboardCallback;
sptr<SceneSession> sceneSession = GetSceneSession("TestSceneSession", "TestSceneSession");
ASSERT_NE(sceneSession, nullptr);
sceneSession->persistentId_ = 100;
keyboardSession->keyboardCallback_->onGetSceneSession_ =
[sceneSession](uint32_t callingSessionId)->sptr<SceneSession> {
if (sceneSession->persistentId_ != callingSessionId) {
return nullptr;
}
return sceneSession;
};
keyboardSession->GetSessionProperty()->SetCallingSessionId(100);
keyboardSession->UseFocusIdIfCallingSessionIdInvalid();
auto resultId = keyboardSession->GetCallingSessionId();
ASSERT_EQ(resultId, 100);
keyboardSession->GetSessionProperty()->SetCallingSessionId(101);
keyboardSession->keyboardCallback_->onGetFocusedSessionId_ = []()->int32_t {
return 100;
};
keyboardSession->UseFocusIdIfCallingSessionIdInvalid();
resultId = keyboardSession->GetCallingSessionId();
ASSERT_EQ(resultId, 100);
}
/**
* @tc.name: UpdateKeyboardAvoidArea01
* @tc.desc: test function : UpdateKeyboardAvoidArea
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, UpdateKeyboardAvoidArea01, Function | SmallTest | Level1)
{
auto keyboardSession = GetKeyboardSession("UpdateKeyboardAvoidArea01",
"UpdateKeyboardAvoidArea01");
ASSERT_NE(keyboardSession, nullptr);
// not foreground
keyboardSession->dirtyFlags_ = 0;
keyboardSession->state_ = SessionState::STATE_CONNECT;
keyboardSession->UpdateKeyboardAvoidArea();
ASSERT_EQ(keyboardSession->dirtyFlags_, 0);
// has callback
auto expectDirtyFlag = 0;
keyboardSession->dirtyFlags_ = 0;
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
keyboardSession->isVisible_ = true;
keyboardSession->specificCallback_->onUpdateAvoidArea_ = [&expectDirtyFlag](const uint32_t& persistentId) {
expectDirtyFlag = 1;
};
keyboardSession->UpdateKeyboardAvoidArea();
if (Session::IsScbCoreEnabled()) {
expectDirtyFlag = 0 | static_cast<uint32_t>(SessionUIDirtyFlag::AVOID_AREA);
ASSERT_EQ(keyboardSession->dirtyFlags_, expectDirtyFlag);
} else {
ASSERT_EQ(expectDirtyFlag, 1);
}
// miss callback
expectDirtyFlag = 0;
keyboardSession->dirtyFlags_ = 1;
keyboardSession->specificCallback_->onUpdateAvoidArea_ = nullptr;
keyboardSession->UpdateKeyboardAvoidArea();
if (Session::IsScbCoreEnabled()) {
ASSERT_EQ(keyboardSession->dirtyFlags_, 1);
} else {
ASSERT_EQ(expectDirtyFlag, 0);
}
expectDirtyFlag = 0;
keyboardSession->dirtyFlags_ = 2;
keyboardSession->specificCallback_ = nullptr;
keyboardSession->UpdateKeyboardAvoidArea();
if (Session::IsScbCoreEnabled()) {
ASSERT_EQ(keyboardSession->dirtyFlags_, 2);
} else {
ASSERT_EQ(expectDirtyFlag, 0);
}
}
/**
* @tc.name: MoveAndResizeKeyboard01
* @tc.desc: test function : MoveAndResizeKeyboard
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, MoveAndResizeKeyboard01, Function | SmallTest | Level1)
{
auto keyboardSession = GetKeyboardSession("MoveAndResizeKeyboard01",
"MoveAndResizeKeyboard01");
ASSERT_NE(keyboardSession, nullptr);
KeyboardLayoutParams param;
param.LandscapeKeyboardRect_ = { 100, 100, 100, 200 };
param.PortraitKeyboardRect_ = { 200, 200, 200, 100 };
keyboardSession->isScreenAngleMismatch_ = true;
keyboardSession->targetScreenWidth_ = 300;
keyboardSession->targetScreenHeight_ = 400;
// branch SESSION_GRAVITY_BOTTOM
param.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
Rect expectRect = { 0, 300, 300, 100 };
keyboardSession->MoveAndResizeKeyboard(param, nullptr, false);
ASSERT_EQ(keyboardSession->property_->requestRect_, expectRect);
//branch SESSION_GRAVITY_DEFAULT
param.gravity_ = WindowGravity::WINDOW_GRAVITY_DEFAULT;
expectRect = { 200, 300, 200, 100 };
keyboardSession->MoveAndResizeKeyboard(param, nullptr, true);
ASSERT_EQ(keyboardSession->property_->requestRect_, expectRect);
}
/**
* @tc.name: MoveAndResizeKeyboard02
* @tc.desc: test function : MoveAndResizeKeyboard
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, MoveAndResizeKeyboard02, Function | SmallTest | Level1)
{
auto keyboardSession = GetKeyboardSession("MoveAndResizeKeyboard02",
"MoveAndResizeKeyboard02");
ASSERT_NE(keyboardSession, nullptr);
KeyboardLayoutParams param;
param.LandscapeKeyboardRect_ = { 100, 100, 100, 200 };
param.PortraitKeyboardRect_ = { 200, 200, 200, 100 };
keyboardSession->isScreenAngleMismatch_ = true;
keyboardSession->targetScreenWidth_ = 300;
keyboardSession->targetScreenHeight_ = 400;
param.gravity_ = WindowGravity::WINDOW_GRAVITY_FLOAT;
// branch else
Rect expectRect = param.PortraitKeyboardRect_;
keyboardSession->MoveAndResizeKeyboard(param, nullptr, true);
ASSERT_EQ(keyboardSession->property_->requestRect_, expectRect);
param.PortraitKeyboardRect_ = { 200, 200, 200, 0 };
auto requestRect = keyboardSession->GetSessionRequestRect();
expectRect = { requestRect.posX_, requestRect.posY_, requestRect.width_, requestRect.height_ };
keyboardSession->MoveAndResizeKeyboard(param, nullptr, true);
ASSERT_EQ(keyboardSession->property_->requestRect_, expectRect);
param.PortraitKeyboardRect_ = { 200, 200, 0, 0 };
requestRect = keyboardSession->GetSessionRequestRect();
expectRect = { requestRect.posX_, requestRect.posY_, requestRect.width_, requestRect.height_ };
keyboardSession->MoveAndResizeKeyboard(param, nullptr, true);
ASSERT_EQ(keyboardSession->property_->requestRect_, expectRect);
}
/**
* @tc.name: OnCallingSessionUpdated01
* @tc.desc: test function : OnCallingSessionUpdated
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest, OnCallingSessionUpdated01, Function | SmallTest | Level1)
{
auto keyboardSession = GetKeyboardSession("OnCallingSessionUpdated01",
"OnCallingSessionUpdated01");
ASSERT_NE(keyboardSession, nullptr);
// keyboardSession is not foreground
keyboardSession->OnCallingSessionUpdated();
ASSERT_EQ(keyboardSession->state_, SessionState::STATE_DISCONNECT);
// keyboardSession's isVisible_ is false
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
keyboardSession->OnCallingSessionUpdated();
ASSERT_EQ(keyboardSession->state_, SessionState::STATE_FOREGROUND);
// keyboardSession's isVisible_ is true
keyboardSession->isVisible_ = true;
keyboardSession->OnCallingSessionUpdated();
ASSERT_EQ(keyboardSession->state_, SessionState::STATE_FOREGROUND);
// callingsession is not nullptr
sptr<SceneSession::SpecificSessionCallback> specificCb =
new (std::nothrow) SceneSession::SpecificSessionCallback();
EXPECT_NE(specificCb, nullptr);
SessionInfo info;
info.abilityName_ = "OnCallingSessionUpdated01";
info.bundleName_ = "OnCallingSessionUpdated01";
info.windowType_ = 1; // 1 is main_window_type
sptr<SceneSession> callingSession = new (std::nothrow) SceneSession(info, specificCb);
EXPECT_NE(callingSession, nullptr);
ASSERT_NE(keyboardSession->keyboardCallback_, nullptr);
keyboardSession->keyboardCallback_->onGetSceneSession_ =
[callingSession](int32_t persistentId)->sptr<SceneSession> {
return callingSession;
};
// callingSession is fullScreen and isCallingSessionFloating is false
// keyboardSession's gravity is SessionGravity::SESSION_GRAVITY_DEFAULT
keyboardSession->OnCallingSessionUpdated();
ASSERT_EQ(keyboardSession->state_, SessionState::STATE_FOREGROUND);
// keyboardSession's gravity is WindowGravity::Window_GRAVITY_FLOAT
EXPECT_NE(keyboardSession->property_, nullptr);
keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_FLOAT;
ASSERT_EQ(keyboardSession->GetKeyboardGravity(), SessionGravity::SESSION_GRAVITY_FLOAT);
keyboardSession->OnCallingSessionUpdated();
ASSERT_EQ(keyboardSession->state_, SessionState::STATE_FOREGROUND);
}
} // namespace
} // namespace Rosen
} // namespace OHOS

View File

@ -0,0 +1,752 @@
/*
* 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 "session/host/include/keyboard_session.h"
#include <gtest/gtest.h>
#include "interfaces/include/ws_common.h"
#include "mock/mock_session_stage.h"
#include "mock/mock_keyboard_session.h"
#include "session/host/include/session.h"
#include "session/host/include/scene_session.h"
#include "window_helper.h"
#include "window_manager_hilog.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "KeyboardSessionTest2"};
}
constexpr int WAIT_ASYNC_US = 1000000;
class KeyboardSessionTest2 : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
private:
sptr<KeyboardSession> GetKeyboardSession(const std::string& abilityName, const std::string& bundleName);
sptr<SceneSession> GetSceneSession(const std::string& abilityName, const std::string& bundleName);
sptr<KSSceneSessionMocker> GetSceneSessionMocker(const std::string& abilityName, const std::string& bundleName);
};
void KeyboardSessionTest2::SetUpTestCase()
{
}
void KeyboardSessionTest2::TearDownTestCase()
{
}
void KeyboardSessionTest2::SetUp()
{
}
void KeyboardSessionTest2::TearDown()
{
}
sptr<KeyboardSession> KeyboardSessionTest2::GetKeyboardSession(const std::string& abilityName,
const std::string& bundleName)
{
SessionInfo info;
info.abilityName_ = abilityName;
info.bundleName_ = bundleName;
sptr<SceneSession::SpecificSessionCallback> specificCb =
new (std::nothrow) SceneSession::SpecificSessionCallback();
EXPECT_NE(specificCb, nullptr);
sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
EXPECT_NE(keyboardCb, nullptr);
sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
EXPECT_NE(keyboardSession, nullptr);
sptr<WindowSessionProperty> keyboardProperty = new (std::nothrow) WindowSessionProperty();
EXPECT_NE(keyboardProperty, nullptr);
keyboardProperty->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
keyboardSession->SetSessionProperty(keyboardProperty);
return keyboardSession;
}
sptr<SceneSession> KeyboardSessionTest2::GetSceneSession(const std::string& abilityName,
const std::string& bundleName)
{
SessionInfo info;
info.abilityName_ = abilityName;
info.bundleName_ = bundleName;
sptr<SceneSession::SpecificSessionCallback> specificCb =
new (std::nothrow) SceneSession::SpecificSessionCallback();
EXPECT_NE(specificCb, nullptr);
sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
return sceneSession;
}
sptr<KSSceneSessionMocker> KeyboardSessionTest2::GetSceneSessionMocker(const std::string& abilityName,
const std::string& bundleName)
{
SessionInfo info;
info.abilityName_ = abilityName;
info.bundleName_ = bundleName;
sptr<SceneSession::SpecificSessionCallback> specificCb =
new (std::nothrow) SceneSession::SpecificSessionCallback();
EXPECT_NE(specificCb, nullptr);
sptr<KSSceneSessionMocker> mockSession = sptr<KSSceneSessionMocker>::MakeSptr(info, nullptr);
return mockSession;
}
namespace {
/**
* @tc.name: AdjustKeyboardLayout01
* @tc.desc: AdjustKeyboardLayout
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, AdjustKeyboardLayout01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "AdjustKeyboardLayout01";
info.bundleName_ = "AdjustKeyboardLayout01";
sptr<SceneSession::SpecificSessionCallback> specificCb =
new (std::nothrow) SceneSession::SpecificSessionCallback();
EXPECT_NE(specificCb, nullptr);
sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
EXPECT_NE(keyboardCb, nullptr);
sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
EXPECT_NE(keyboardSession, nullptr);
sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
keyboardSession->SetSessionProperty(property);
keyboardSession->RegisterSessionChangeCallback(nullptr);
KeyboardLayoutParams params;
ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
sptr<SceneSession::SessionChangeCallback> sessionChangeCallback =
new (std::nothrow) SceneSession::SessionChangeCallback();
EXPECT_NE(sessionChangeCallback, nullptr);
keyboardSession->adjustKeyboardLayoutFunc_ = nullptr;
keyboardSession->RegisterSessionChangeCallback(sessionChangeCallback);
ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
keyboardSession->adjustKeyboardLayoutFunc_ = [](const KeyboardLayoutParams& params){};
ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
}
/**
* @tc.name: AdjustKeyboardLayout01
* @tc.desc: AdjustKeyboardLayout
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, AdjustKeyboardLayout02, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "AdjustKeyboardLayout02";
info.bundleName_ = "AdjustKeyboardLayout02";
sptr<SceneSession::SpecificSessionCallback> specificCb =
new (std::nothrow) SceneSession::SpecificSessionCallback();
EXPECT_NE(specificCb, nullptr);
sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
EXPECT_NE(keyboardCb, nullptr);
sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
EXPECT_NE(keyboardSession, nullptr);
keyboardSession->SetSessionProperty(nullptr);
KeyboardLayoutParams params;
ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
}
/**
* @tc.name: CheckIfNeedRaiseCallingSession
* @tc.desc: CheckIfNeedRaiseCallingSession
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, CheckIfNeedRaiseCallingSession, Function | SmallTest | Level1)
{
WLOGFI("CheckIfNeedRaiseCallingSession begin!");
SessionInfo info;
info.abilityName_ = "CheckIfNeedRaiseCallingSession";
info.bundleName_ = "CheckIfNeedRaiseCallingSession";
sptr<SceneSession::SpecificSessionCallback> specificCb =
new (std::nothrow) SceneSession::SpecificSessionCallback();
EXPECT_NE(specificCb, nullptr);
sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
EXPECT_NE(keyboardCb, nullptr);
sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
EXPECT_NE(keyboardSession, nullptr);
sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
EXPECT_NE(property, nullptr);
property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
keyboardSession->SetSessionProperty(property);
ASSERT_FALSE(keyboardSession->CheckIfNeedRaiseCallingSession(nullptr, true));
sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCb);
EXPECT_NE(sceneSession, nullptr);
keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_FLOAT;
ASSERT_FALSE(keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, true));
keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
ASSERT_TRUE(keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, false));
property->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
ASSERT_FALSE(keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, true));
property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, true);
WLOGFI("CheckIfNeedRaiseCallingSession end!");
}
/**
* @tc.name: OpenKeyboardSyncTransaction
* @tc.desc: OpenKeyboardSyncTransaction
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, OpenKeyboardSyncTransaction, Function | SmallTest | Level1)
{
std::string abilityName = "OpenKeyboardSyncTransaction";
std::string bundleName = "OpenKeyboardSyncTransaction";
sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
// isKeyBoardSyncTransactionOpen_ is false
keyboardSession->OpenKeyboardSyncTransaction();
// isKeyBoardSyncTransactionOpen_ is true
keyboardSession->OpenKeyboardSyncTransaction();
}
/**
* @tc.name: CloseKeyboardSyncTransaction1
* @tc.desc: CloseKeyboardSyncTransaction1
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, CloseKeyboardSyncTransaction1, Function | SmallTest | Level1)
{
std::string abilityName = "CloseKeyboardSyncTransaction1";
std::string bundleName = "CloseKeyboardSyncTransaction1";
sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
WSRect keyboardPanelRect = { 0, 0, 0, 0 };
bool isKeyboardShow = true;
bool isRotating = false;
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, isRotating);
}
/**
* @tc.name: CloseKeyboardSyncTransaction2
* @tc.desc: CloseKeyboardSyncTransaction2
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, CloseKeyboardSyncTransaction2, Function | SmallTest | Level1)
{
std::string abilityName = "CloseKeyboardSyncTransaction2";
std::string bundleName = "CloseKeyboardSyncTransaction2";
sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
WSRect keyboardPanelRect = { 0, 0, 0, 0 };
bool isKeyboardShow = true;
bool isRotating = false;
// isKeyBoardSyncTransactionOpen_ is true
keyboardSession->OpenKeyboardSyncTransaction();
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, isRotating);
}
/**
* @tc.name: BindKeyboardPanelSession
* @tc.desc: BindKeyboardPanelSession
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, BindKeyboardPanelSession, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "BindKeyboardPanelSession";
info.bundleName_ = "BindKeyboardPanelSession";
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
sptr<SceneSession> panelSession = nullptr;
keyboardSession->BindKeyboardPanelSession(panelSession);
sptr<SceneSession> getPanelSession = keyboardSession->GetKeyboardPanelSession();
ASSERT_EQ(getPanelSession, nullptr);
panelSession = sptr<SceneSession>::MakeSptr(info, nullptr);
ASSERT_NE(panelSession, nullptr);
keyboardSession->BindKeyboardPanelSession(panelSession);
getPanelSession = keyboardSession->GetKeyboardPanelSession();
EXPECT_EQ(getPanelSession, panelSession);
}
/**
* @tc.name: GetKeyboardGravity01
* @tc.desc: GetKeyboardGravity01
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, GetKeyboardGravity01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "GetKeyboardGravity";
info.bundleName_ = "GetKeyboardGravity";
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
keyboardSession->property_ = nullptr;
auto ret = keyboardSession->GetKeyboardGravity();
EXPECT_EQ(SessionGravity::SESSION_GRAVITY_DEFAULT, ret);
sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
ASSERT_NE(windowSessionProperty, nullptr);
keyboardSession->property_ = windowSessionProperty;
ASSERT_NE(keyboardSession->property_, nullptr);
keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
ASSERT_NE(keyboardSession, nullptr);
ret = keyboardSession->GetKeyboardGravity();
EXPECT_EQ(SessionGravity::SESSION_GRAVITY_BOTTOM, ret);
}
/**
* @tc.name: NotifyKeyboardPanelInfoChange
* @tc.desc: NotifyKeyboardPanelInfoChange
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, NotifyKeyboardPanelInfoChange, Function | SmallTest | Level1)
{
WSRect rect = {800, 800, 1200, 1200};
SessionInfo info;
info.abilityName_ = "NotifyKeyboardPanelInfoChange";
info.bundleName_ = "NotifyKeyboardPanelInfoChange";
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
keyboardSession->isKeyboardPanelEnabled_ = false;
keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
keyboardSession->isKeyboardPanelEnabled_ = true;
keyboardSession->sessionStage_ = nullptr;
keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
ASSERT_NE(mockSessionStage, nullptr);
keyboardSession->sessionStage_ = mockSessionStage;
ASSERT_NE(keyboardSession->sessionStage_, nullptr);
keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
}
/**
* @tc.name: CheckIfNeedRaiseCallingSession01
* @tc.desc: CheckIfNeedRaiseCallingSession01
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, CheckIfNeedRaiseCallingSession01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "CheckIfNeedRaiseCallingSession";
info.bundleName_ = "CheckIfNeedRaiseCallingSession";
sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
ASSERT_NE(specificCb, nullptr);
sptr<SceneSession> callingSession = sptr<SceneSession>::MakeSptr(info, specificCb);
ASSERT_NE(callingSession, nullptr);
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
ASSERT_NE(windowSessionProperty, nullptr);
keyboardSession->property_ = windowSessionProperty;
ASSERT_NE(keyboardSession->property_, nullptr);
keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
keyboardSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
callingSession->systemConfig_.freeMultiWindowSupport_ = true;
callingSession->systemConfig_.freeMultiWindowEnable_ = true;
auto ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
EXPECT_EQ(ret, false);
callingSession->systemConfig_.freeMultiWindowEnable_ = false;
ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
EXPECT_EQ(ret, false);
callingSession->systemConfig_.freeMultiWindowEnable_ = true;
keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
EXPECT_EQ(ret, true);
keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
callingSession->systemConfig_.freeMultiWindowEnable_ = false;
ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
EXPECT_EQ(ret, true);
keyboardSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
EXPECT_EQ(ret, true);
ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, false);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: UpdateCallingSessionIdAndPosition01
* @tc.desc: UpdateCallingSessionIdAndPosition01
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, UpdateCallingSessionIdAndPosition01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "UpdateCallingSessionIdAndPosition";
info.bundleName_ = "UpdateCallingSessionIdAndPosition";
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
keyboardSession->property_ = nullptr;
keyboardSession->UpdateCallingSessionIdAndPosition(0);
sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
ASSERT_NE(windowSessionProperty, nullptr);
keyboardSession->property_ = windowSessionProperty;
ASSERT_NE(keyboardSession->property_, nullptr);
keyboardSession->property_->SetCallingSessionId(-1);
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
keyboardSession->UpdateCallingSessionIdAndPosition(0);
keyboardSession->state_ = SessionState::STATE_CONNECT;
keyboardSession->UpdateCallingSessionIdAndPosition(0);
keyboardSession->UpdateCallingSessionIdAndPosition(-1);
keyboardSession->property_->SetCallingSessionId(0);
keyboardSession->UpdateCallingSessionIdAndPosition(0);
}
/**
* @tc.name: OpenKeyboardSyncTransaction01
* @tc.desc: OpenKeyboardSyncTransaction
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, OpenKeyboardSyncTransaction01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "UpdateCallingSessionIdAndPosition";
info.bundleName_ = "UpdateCallingSessionIdAndPosition";
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
keyboardSession->isKeyboardSyncTransactionOpen_ = true;
keyboardSession->OpenKeyboardSyncTransaction();
keyboardSession->isKeyboardSyncTransactionOpen_ = false;
keyboardSession->OpenKeyboardSyncTransaction();
WSRect keyboardPanelRect = {0, 0, 0, 0};
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, true, true);
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, false);
}
/**
* @tc.name: RelayoutKeyBoard01
* @tc.desc: RelayoutKeyBoard01
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, RelayoutKeyBoard01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "RelayoutKeyBoard";
info.bundleName_ = "RelayoutKeyBoard";
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
ASSERT_NE(keyboardSession, nullptr);
keyboardSession->property_ = nullptr;
keyboardSession->RelayoutKeyBoard();
sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
ASSERT_NE(windowSessionProperty, nullptr);
keyboardSession->property_ = windowSessionProperty;
ASSERT_NE(keyboardSession->property_, nullptr);
keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
keyboardSession->RelayoutKeyBoard();
}
/**
* @tc.name: Hide01
* @tc.desc: test function : Hide
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, Hide01, Function | SmallTest | Level1)
{
SessionInfo info;
info.abilityName_ = "Hide";
info.bundleName_ = "Hide";
sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
ASSERT_NE(specificCb, nullptr);
sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
ASSERT_NE(keyboardCb, nullptr);
sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
ASSERT_NE(keyboardSession, nullptr);
// setActive false return not ok
keyboardSession->state_ = SessionState::STATE_DISCONNECT;
EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
// setActive false return ok and deviceType is phone
keyboardSession->state_ = SessionState::STATE_CONNECT;
keyboardSession->isActive_ = true;
keyboardSession->sessionStage_ = new (std::nothrow) SessionStageMocker();
ASSERT_NE(keyboardSession->sessionStage_, nullptr);
keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
// deviceType is pc and property is not nullptr
ASSERT_NE(keyboardSession->property_, nullptr);
keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
// deviceType is pc and property is nullptr
keyboardSession->property_ = nullptr;
EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
}
/**
* @tc.name: RaiseCallingSession01
* @tc.desc: test function : RaiseCallingSession
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, RaiseCallingSession01, Function | SmallTest | Level1)
{
auto keyboardSession = GetKeyboardSession("RaiseCallingSession01",
"RaiseCallingSession01");
ASSERT_NE(keyboardSession, nullptr);
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
keyboardSession->isVisible_ = true;
Rosen::WSRect resultRect{ 0, 0, 0, 0 };
sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
ASSERT_NE(callingSession, nullptr);
callingSession->updateRectCallback_ = [&resultRect](const WSRect& rect, SizeChangeReason reason) {
resultRect.posX_ = rect.posX_;
resultRect.posY_ = rect.posY_;
resultRect.width_ = rect.width_;
resultRect.height_ = rect.height_;
};
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
Rosen::WSRect keyboardPanelRect{ 0, 0, 0, 0 };
Rosen::WSRect emptyRect{ 0, 0, 0, 0 };
std::shared_ptr<RSTransaction> rsTransaction = nullptr;
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, rsTransaction);
ASSERT_EQ(resultRect, emptyRect);
// for cover GetSceneSession
keyboardSession->keyboardCallback_->onGetSceneSession_ =
[callingSession](int32_t persistentId)->sptr<SceneSession> {
return callingSession;
};
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, rsTransaction);
// for cover CheckIfNeedRaiseCallingSession
keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
// for empty rect check;
keyboardSession->winRect_.posX_ = 1;
keyboardSession->winRect_.posY_ = 1;
keyboardSession->winRect_.posX_ = 1;
keyboardSession->winRect_.posX_ = 1;
// for cover oriPosYBeforeRaisedBykeyboard == 0
callingSession->SetOriPosYBeforeRaisedByKeyboard(0);
ASSERT_EQ(resultRect, emptyRect);
}
/**
* @tc.name: RaiseCallingSession02
* @tc.desc: test function : RaiseCallingSession
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, RaiseCallingSession02, Function | SmallTest | Level1)
{
Rosen::WSRect keyboardPanelRect{ 1, 1, 1, 1 };
auto keyboardSession = GetKeyboardSession("RaiseCallingSession02",
"RaiseCallingSession02");
ASSERT_NE(keyboardSession, nullptr);
sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
ASSERT_NE(callingSession, nullptr);
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
callingSession->winRect_ = { 1, 1, 1, 1 };
keyboardSession->keyboardCallback_->onGetSceneSession_ = [callingSession](int32_t persistentId) {
return callingSession;
};
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
keyboardSession->isVisible_ = true;
callingSession->oriPosYBeforeRaisedByKeyboard_ = 0;
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->winRect_.posY_, 1);
callingSession->oriPosYBeforeRaisedByKeyboard_ = 10;
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->winRect_.posY_, 1);
keyboardPanelRect = { 0, 0, 0, 0 };
callingSession->oriPosYBeforeRaisedByKeyboard_ = 10;
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->winRect_.posY_, 1);
}
/**
* @tc.name: RaiseCallingSession03
* @tc.desc: test function : RaiseCallingSession
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, RaiseCallingSession03, Function | SmallTest | Level1)
{
Rosen::WSRect keyboardPanelRect{ 1, 1, 1, 1 };
auto keyboardSession = GetKeyboardSession("RaiseCallingSession03",
"RaiseCallingSession03");
ASSERT_NE(keyboardSession, nullptr);
sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
ASSERT_NE(callingSession, nullptr);
callingSession->winRect_ = { 1, 1, 1, 1 };
callingSession->oriPosYBeforeRaisedByKeyboard_ = 0;
callingSession->updateRectCallback_ = [](const WSRect& rect, SizeChangeReason reason) {};
keyboardSession->keyboardCallback_->onGetSceneSession_ = [callingSession](int32_t persistentId) {
return callingSession;
};
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
keyboardSession->isVisible_ = true;
auto callingOriPosY = 0;
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
callingOriPosY = callingSession->oriPosYBeforeRaisedByKeyboard_;
ASSERT_EQ(callingOriPosY, 0);
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
callingSession->winRect_.posY_ = 200;
keyboardPanelRect.posY_ = 200;
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
callingOriPosY = callingSession->oriPosYBeforeRaisedByKeyboard_;
ASSERT_EQ(callingOriPosY, 200);
callingSession->oriPosYBeforeRaisedByKeyboard_ = 10;
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
callingOriPosY = callingSession->oriPosYBeforeRaisedByKeyboard_;
ASSERT_EQ(callingOriPosY, 10);
}
/**
* @tc.name: IsCallingSessionSplitMode01
* @tc.desc: test function : IsCallingSessionSplitMode
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, IsCallingSessionSplitMode01, Function | SmallTest | Level1)
{
Rosen::WSRect keyboardPanelRect{ 0, 0, 0, 0 };
auto keyboardSession = GetKeyboardSession("IsCallingSessionSplitMode01",
"IsCallingSessionSplitMode01");
ASSERT_NE(keyboardSession, nullptr);
sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
ASSERT_NE(callingSession, nullptr);
callingSession->oriPosYBeforeRaisedByKeyboard_ = 0;
callingSession->winRect_ = { 0, 0, 0, 0 };
callingSession->updateRectCallback_ = [](const WSRect& rect, SizeChangeReason reason) {};
keyboardSession->keyboardCallback_->onGetSceneSession_ = [callingSession](int32_t persistentId) {
return callingSession;
};
keyboardSession->state_ = SessionState::STATE_FOREGROUND;
auto callingParentSession = GetSceneSession("callingParentSession", "callingParentSession");
ASSERT_NE(callingSession, nullptr);
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
callingSession->parentSession_ = callingParentSession;
callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
callingParentSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
callingParentSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
}
/**
* @tc.name: CloseKeyBoardSyncTransaction3
* @tc.desc: test function : CloseKeyBoardSyncTransaction
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, CloseKeyBoardSyncTransaction3, Function | SmallTest | Level1)
{
std::string abilityName = "CloseKeyBoardSyncTransaction3";
std::string bundleName = "CloseKeyBoardSyncTransaction3";
sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
ASSERT_NE(keyboardSession, nullptr);
WSRect keyboardPanelRect = { 0, 0, 0, 0 };
bool isKeyboardShow = true;
bool isRotating = false;
keyboardSession->dirtyFlags_ = 0;
keyboardSession->specificCallback_->onUpdateAvoidArea_ = [](uint32_t callingSessionId) {};
keyboardSession->isKeyboardSyncTransactionOpen_ = true;
// isKeyBoardSyncTransactionOpen_ is true
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, isRotating);
usleep(WAIT_ASYNC_US);
ASSERT_EQ(keyboardSession->isKeyboardSyncTransactionOpen_, false);
}
/**
* @tc.name: CloseKeyboardSyncTransaction4
* @tc.desc: test function : CloseKeyboardSyncTransaction
* @tc.type: FUNC
*/
HWTEST_F(KeyboardSessionTest2, CloseKeyboardSyncTransaction4, Function | SmallTest | Level1)
{
std::string abilityName = "CloseKeyboardSyncTransaction4";
std::string bundleName = "CloseKeyboardSyncTransaction4";
sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
ASSERT_NE(keyboardSession, nullptr);
WSRect keyboardPanelRect = { 0, 0, 0, 0 };
keyboardSession->dirtyFlags_ = 0;
keyboardSession->isKeyboardSyncTransactionOpen_ = false;
keyboardSession->property_ = nullptr;
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, false);
usleep(WAIT_ASYNC_US);
ASSERT_EQ(0, keyboardSession->dirtyFlags_);
sptr<WindowSessionProperty> keyboardProperty = sptr<WindowSessionProperty>::MakeSptr();
ASSERT_NE(keyboardProperty, nullptr);
keyboardSession->property_ = keyboardProperty;
keyboardSession->isKeyboardSyncTransactionOpen_ = true;
keyboardSession->property_->SetCallingSessionId(1);
keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, false);
usleep(WAIT_ASYNC_US);
auto callingSessionId = keyboardSession->property_->GetCallingSessionId();
ASSERT_EQ(callingSessionId, INVALID_WINDOW_ID);
}
} // namespace
} // namespace Rosen
} // namespace OHOS