* Copyright (c) 2021 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.
*/
#define private public
#define protected public
#include "input_method_panel.h"
#include "ime_info_inquirer.h"
#include "input_method_ability.h"
#include "input_method_ability_utils.h"
#include "input_method_controller.h"
#include "input_method_system_ability.h"
#include "task_manager.h"
#undef private
#include <gtest/gtest.h>
#include <gtest/hwext/gtest-multithread.h>
#include <sys/time.h>
#include <unistd.h>
#include <condition_variable>
#include <cstdint>
#include <string>
#include "common_event_data.h"
#include "common_event_manager.h"
#include "common_event_subscribe_info.h"
#include "common_event_subscriber.h"
#include "common_event_support.h"
#include "display_manager.h"
#include "global.h"
#include "identity_checker_mock.h"
#include "ime_event_monitor_manager.h"
#include "input_method_ability.h"
#include "input_method_controller.h"
#include "input_method_engine_listener_impl.h"
#include "matching_skills.h"
#include "panel_status_listener.h"
#include "scene_board_judgement.h"
#include "scope_utils.h"
#include "tdd_util.h"
#include "text_listener.h"
#include "color_parser.h"
using namespace testing::ext;
using namespace testing::mt;
using namespace OHOS::Rosen;
namespace OHOS {
namespace MiscServices {
constexpr uint32_t IMC_WAIT_PANEL_STATUS_LISTEN_TIME = 500;
constexpr float FIXED_SOFT_KEYBOARD_PANEL_RATIO = 0.7;
constexpr float NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO = 1;
constexpr const char *COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED = "usual.event.imf.input_panel_status_changed";
constexpr const char *COMMON_EVENT_PARAM_PANEL_STATE = "panelState";
const constexpr char *IMMERSIVE_EFFECT = "immersive_effect";
constexpr uint32_t GRADIENT_HEIGHT = 10;
constexpr int32_t PORTRAIT_AVOID_HEIGHT = 20;
constexpr int32_t LANDSCAPE_AVOID_HEIGHT = 15;
constexpr uint32_t INITIAL_PORTRAIT_HEIGHT = 25;
constexpr uint32_t INITIAL_LANDSCAPE_HEIGHT = 20;
constexpr int32_t INITIAL_PORTRAIT_POS_Y = 100;
constexpr int32_t INITIAL_LANDSCAPE_POS_Y = 200;
constexpr int32_t DEFAULT_WIDTH = 100;
constexpr int32_t DEFAULT_HEIGHT = 200;
constexpr int32_t LANDSCAPE_WIDTH = 150;
constexpr int32_t LANDSCAPE_HEIGHT = 300;
constexpr int32_t INVALID_POS_Y = -1;
constexpr int32_t VALID_POS_Y = 0;
enum ListeningStatus : uint32_t {
ON,
OFF,
NONE
};
class InputMethodPanelTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
static std::shared_ptr<InputMethodPanel> CreatePanel();
static void DestroyPanel(const std::shared_ptr<InputMethodPanel> &panel);
static void Attach();
static bool TriggerShowCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel);
static bool TriggerHideCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel);
static void ImaCreatePanel(const PanelInfo &info, std::shared_ptr<InputMethodPanel> &panel);
static void ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> &panel);
static void ImcPanelListeningTestRestore();
static void ImcPanelShowNumCheck(uint32_t num);
static void ImcPanelHideNumCheck(uint32_t num);
static void ImcPanelShowInfoCheck(const InputWindowInfo &windowInfo);
static void ImcPanelHideInfoCheck(const InputWindowInfo &windowInfo);
static void TestShowPanel(const std::shared_ptr<InputMethodPanel> &panel);
static void TestHidePanel(const std::shared_ptr<InputMethodPanel> &panel);
static void TestIsPanelShown(const PanelInfo &info, bool expectedResult);
static void TriggerPanelStatusChangeToImc(const std::shared_ptr<InputMethodPanel> &panel, InputWindowStatus status);
static void TriggerKeyboardPanelInfoChange(
const std::shared_ptr<InputMethodPanel> &panel, const Rosen::KeyboardPanelInfo &info);
static void TriggerVisibilityChange(const std::shared_ptr<InputMethodPanel> &panel,
Rosen::WindowVisibilityState isVisible);
static void TestAdjust();
static int32_t GetDisplaySize(DisplaySize &size);
class PanelStatusListenerImpl : public PanelStatusListener {
public:
PanelStatusListenerImpl()
{
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("InputMethodPanelTest");
panelHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
}
~PanelStatusListenerImpl() = default;
void OnPanelStatus(uint32_t windowId, bool isShow)
{
{
std::unique_lock<std::mutex> lock(InputMethodPanelTest::panelListenerLock_);
if (isShow) {
InputMethodPanelTest::status_ = InputWindowStatus::SHOW;
} else {
InputMethodPanelTest::status_ = InputWindowStatus::HIDE;
}
}
InputMethodPanelTest::panelListenerCv_.notify_one();
IMSA_HILOGI("PanelStatusListenerImpl OnPanelStatus in, isShow is %{public}s", isShow ? "true" : "false");
}
void OnSizeChange(uint32_t windowId, const WindowSize &size) {}
void OnSizeChange(
uint32_t windowId, const WindowSize &size, const PanelAdjustInfo &keyboardArea, const std::string &event)
{
}
};
static std::mutex imcPanelStatusListenerLock_;
static std::condition_variable imcPanelStatusListenerCv_;
static InputWindowStatus status_;
static InputWindowInfo windowInfo_;
static uint32_t imeShowCallbackNum_;
static uint32_t imeHideCallbackNum_;
static sptr<InputMethodController> imc_;
static InputMethodAbility &ima_;
static sptr<InputMethodSystemAbility> imsa_;
static uint32_t windowWidth_;
static uint32_t windowHeight_;
static std::condition_variable panelListenerCv_;
static std::mutex panelListenerLock_;
static constexpr uint32_t DELAY_TIME = 100;
static constexpr int32_t INTERVAL = 10;
static std::shared_ptr<AppExecFwk::EventHandler> panelHandler_;
static int32_t currentImeUid_;
static uint64_t currentImeTokenId_;
static sptr<OnTextChangedListener> textListener_;
static std::shared_ptr<InputMethodEngineListener> imeListener_;
static bool isScbEnable_;
static std::shared_ptr<InputMethodPanel> panel_;
};
class InputMethodSettingListenerImpl : public ImeEventListener {
public:
InputMethodSettingListenerImpl() = default;
~InputMethodSettingListenerImpl() = default;
void OnImeShow(const ImeWindowInfo &info) override
{
IMSA_HILOGI("InputMethodPanelTest::OnImeShow.");
std::unique_lock<std::mutex> lock(InputMethodPanelTest::imcPanelStatusListenerLock_);
InputMethodPanelTest::status_ = InputWindowStatus::SHOW;
InputMethodPanelTest::windowInfo_ = info.windowInfo;
InputMethodPanelTest::imeShowCallbackNum_++;
InputMethodPanelTest::imcPanelStatusListenerCv_.notify_one();
}
void OnImeHide(const ImeWindowInfo &info) override
{
IMSA_HILOGI("InputMethodPanelTest::OnImeHide.");
std::unique_lock<std::mutex> lock(InputMethodPanelTest::imcPanelStatusListenerLock_);
InputMethodPanelTest::status_ = InputWindowStatus::HIDE;
InputMethodPanelTest::windowInfo_ = info.windowInfo;
InputMethodPanelTest::imeHideCallbackNum_++;
InputMethodPanelTest::imcPanelStatusListenerCv_.notify_one();
}
};
class TestEventSubscriber : public EventFwk::CommonEventSubscriber {
public:
explicit TestEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo)
: EventFwk::CommonEventSubscriber(subscribeInfo)
{
}
void OnReceiveEvent(const EventFwk::CommonEventData &data)
{
std::unique_lock<std::mutex> lock(InputMethodPanelTest::imcPanelStatusListenerLock_);
auto const &want = data.GetWant();
action_ = want.GetAction();
bool visible = want.GetBoolParam(COMMON_EVENT_PARAM_PANEL_STATE, false);
status_ = visible ? InputWindowStatus::SHOW : InputWindowStatus::HIDE;
InputMethodPanelTest::imcPanelStatusListenerCv_.notify_one();
}
void ResetParam()
{
action_ = "";
status_ = InputWindowStatus::NONE;
}
std::string action_;
InputWindowStatus status_ { InputWindowStatus::NONE };
};
std::condition_variable InputMethodPanelTest::panelListenerCv_;
std::mutex InputMethodPanelTest::panelListenerLock_;
std::shared_ptr<AppExecFwk::EventHandler> InputMethodPanelTest::panelHandler_ { nullptr };
std::condition_variable InputMethodPanelTest::imcPanelStatusListenerCv_;
std::mutex InputMethodPanelTest::imcPanelStatusListenerLock_;
InputWindowStatus InputMethodPanelTest::status_ { InputWindowStatus::NONE };
InputWindowInfo InputMethodPanelTest::windowInfo_;
uint32_t InputMethodPanelTest::imeShowCallbackNum_ { 0 };
uint32_t InputMethodPanelTest::imeHideCallbackNum_ { 0 };
sptr<InputMethodController> InputMethodPanelTest::imc_ { nullptr };
InputMethodAbility &InputMethodPanelTest::ima_ = InputMethodAbility::GetInstance();
sptr<InputMethodSystemAbility> InputMethodPanelTest::imsa_ { nullptr };
uint32_t InputMethodPanelTest::windowWidth_ = 0;
uint32_t InputMethodPanelTest::windowHeight_ = 0;
uint64_t InputMethodPanelTest::currentImeTokenId_ = 0;
int32_t InputMethodPanelTest::currentImeUid_ = 0;
sptr<OnTextChangedListener> InputMethodPanelTest::textListener_ { nullptr };
std::shared_ptr<InputMethodEngineListener> InputMethodPanelTest::imeListener_ { nullptr };
bool InputMethodPanelTest::isScbEnable_ { false };
std::shared_ptr<InputMethodPanel> InputMethodPanelTest::panel_ {nullptr};
void InputMethodPanelTest::SetUpTestCase(void)
{
IMSA_HILOGI("InputMethodPanelTest::SetUpTestCase");
IdentityCheckerMock::ResetParam();
isScbEnable_ = Rosen::SceneBoardJudgement::IsSceneBoardEnabled();
TddUtil::StorageSelfTokenID();
auto listener = std::make_shared<InputMethodSettingListenerImpl>();
imc_ = InputMethodController::GetInstance();
textListener_ = new (std::nothrow) TextListener();
imeListener_ = std::make_shared<InputMethodEngineListenerImpl>();
std::shared_ptr<Property> property = InputMethodController::GetInstance()->GetCurrentInputMethod();
std::string bundleName = property != nullptr ? property->name : "default.inputmethod.unittest";
currentImeTokenId_ = TddUtil::GetTestTokenID(bundleName);
currentImeUid_ = TddUtil::GetUid(bundleName);
imsa_ = new (std::nothrow) InputMethodSystemAbility();
if (imsa_ == nullptr) {
return;
}
imsa_->OnStart();
imsa_->identityChecker_ = std::make_shared<IdentityCheckerMock>();
imc_->abilityManager_ = imsa_;
{
TokenScope scope(currentImeTokenId_);
ima_.InitConnect();
}
ima_.abilityManager_ = imsa_;
TddUtil::InitCurrentImePermissionInfo();
IdentityCheckerMock::SetBundleName(TddUtil::currentBundleNameMock_);
ima_.SetCoreAndAgent();
InputMethodPanelTest::ima_.SetImeListener(imeListener_);
ImaUtils::abilityManager_ = imsa_;
}
void InputMethodPanelTest::TearDownTestCase(void)
{
IMSA_HILOGI("InputMethodPanelTest::TearDownTestCase");
TddUtil::RestoreSelfTokenID();
IdentityCheckerMock::ResetParam();
imsa_->OnStop();
ImaUtils::abilityManager_ = nullptr;
}
void InputMethodPanelTest::SetUp(void)
{
IMSA_HILOGI("InputMethodPanelTest::SetUp");
TaskManager::GetInstance().SetInited(true);
}
void InputMethodPanelTest::TearDown(void)
{
TddUtil::RestoreSelfTokenID();
IMSA_HILOGI("InputMethodPanelTest::TearDown");
std::this_thread::sleep_for(std::chrono::seconds(1));
TaskManager::GetInstance().Reset();
}
std::shared_ptr<InputMethodPanel> InputMethodPanelTest::CreatePanel()
{
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
return inputMethodPanel;
}
void InputMethodPanelTest::DestroyPanel(const std::shared_ptr<InputMethodPanel> &panel)
{
ASSERT_NE(panel, nullptr);
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto ret = panel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
void InputMethodPanelTest::ImaCreatePanel(const PanelInfo &info, std::shared_ptr<InputMethodPanel> &panel)
{
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto ret = ima_.CreatePanel(nullptr, info, panel);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
void InputMethodPanelTest::ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> &panel)
{
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto ret = ima_.DestroyPanel(panel);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
void InputMethodPanelTest::Attach()
{
IdentityCheckerMock::SetFocused(true);
auto ret = imc_->Attach(textListener_, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
std::this_thread::sleep_for(std::chrono::seconds(1));
IdentityCheckerMock::SetFocused(false);
}
bool InputMethodPanelTest::TriggerShowCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel)
{
IMSA_HILOGI("start");
status_ = InputWindowStatus::NONE;
panelHandler_->PostTask(
[&inputMethodPanel]() {
TestShowPanel(inputMethodPanel);
},
InputMethodPanelTest::INTERVAL);
std::this_thread::sleep_for(std::chrono::milliseconds(InputMethodPanelTest::INTERVAL));
{
std::unique_lock<std::mutex> lock(panelListenerLock_);
return panelListenerCv_.wait_for(lock, std::chrono::milliseconds(InputMethodPanelTest::DELAY_TIME), [] {
return status_ == InputWindowStatus::SHOW;
});
}
}
bool InputMethodPanelTest::TriggerHideCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel)
{
IMSA_HILOGI("start");
status_ = InputWindowStatus::NONE;
panelHandler_->PostTask(
[&inputMethodPanel]() {
TestHidePanel(inputMethodPanel);
},
InputMethodPanelTest::INTERVAL);
std::this_thread::sleep_for(std::chrono::milliseconds(InputMethodPanelTest::INTERVAL));
{
std::unique_lock<std::mutex> lock(panelListenerLock_);
return panelListenerCv_.wait_for(lock, std::chrono::milliseconds(InputMethodPanelTest::DELAY_TIME), [] {
return status_ == InputWindowStatus::HIDE;
});
}
}
void InputMethodPanelTest::ImcPanelShowNumCheck(uint32_t num)
{
std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
if (num == 0) {
auto ret =
imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME));
EXPECT_EQ(ret, std::cv_status::timeout);
return;
}
bool ret =
imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [&num] {
return imeShowCallbackNum_ >= num;
});
EXPECT_TRUE(ret);
}
void InputMethodPanelTest::ImcPanelHideNumCheck(uint32_t num)
{
std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
if (num == 0) {
auto ret =
imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME));
EXPECT_EQ(ret, std::cv_status::timeout);
return;
}
bool ret = imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME),
[&num] { return num <= imeHideCallbackNum_; });
EXPECT_TRUE(ret);
}
void InputMethodPanelTest::ImcPanelShowInfoCheck(const InputWindowInfo &windowInfo)
{
std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
bool ret =
imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [] {
return status_ == InputWindowStatus::SHOW;
});
EXPECT_TRUE(ret);
IMSA_HILOGI("InputMethodPanelTest::name: %{public}s, ret:[%{public}d, %{public}d,%{public}d, %{public}d]",
windowInfo_.name.c_str(), windowInfo_.top, windowInfo_.left, windowInfo_.width, windowInfo_.height);
EXPECT_FALSE(windowInfo_.name.empty());
}
void InputMethodPanelTest::ImcPanelHideInfoCheck(const InputWindowInfo &windowInfo)
{
std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
bool ret =
imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [] {
return status_ == InputWindowStatus::HIDE;
});
EXPECT_TRUE(ret);
IMSA_HILOGI("InputMethodPanelTest::name: %{public}s, ret:[%{public}d, %{public}d,%{public}d, %{public}d]",
windowInfo_.name.c_str(), windowInfo_.top, windowInfo_.left, windowInfo_.width, windowInfo_.height);
EXPECT_FALSE(windowInfo_.name.empty());
}
void InputMethodPanelTest::ImcPanelListeningTestRestore()
{
status_ = InputWindowStatus::NONE;
windowInfo_ = {};
imeShowCallbackNum_ = 0;
imeHideCallbackNum_ = 0;
}
void InputMethodPanelTest::TestShowPanel(const std::shared_ptr<InputMethodPanel> &panel)
{
ASSERT_NE(panel, nullptr);
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto ret = panel->ShowPanel(Trigger::IME_APP);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
void InputMethodPanelTest::TestHidePanel(const std::shared_ptr<InputMethodPanel> &panel)
{
ASSERT_NE(panel, nullptr);
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto ret = panel->HidePanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
void InputMethodPanelTest::TestIsPanelShown(const PanelInfo &info, bool expectedResult)
{
IdentityCheckerMock::SetSystemApp(true);
bool result = !expectedResult;
auto ret = imc_->IsPanelShown(info, result);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(result, expectedResult);
IdentityCheckerMock::SetSystemApp(false);
}
void InputMethodPanelTest::TriggerPanelStatusChangeToImc(
const std::shared_ptr<InputMethodPanel> &panel, InputWindowStatus status)
{
ASSERT_NE(panel, nullptr);
if (isScbEnable_) {
IdentityCheckerMock::SetBundleNameValid(true);
panel->PanelStatusChangeToImc(status, { 0, 0, 0, 0 });
IdentityCheckerMock::SetBundleNameValid(false);
}
}
void InputMethodPanelTest::TriggerKeyboardPanelInfoChange(
const std::shared_ptr<InputMethodPanel> &panel, const Rosen::KeyboardPanelInfo &info)
{
ASSERT_NE(panel, nullptr);
if (isScbEnable_) {
IdentityCheckerMock::SetBundleNameValid(true);
panel->OnKeyboardPanelInfoChange(info);
IdentityCheckerMock::SetBundleNameValid(false);
}
}
void InputMethodPanelTest::TriggerVisibilityChange(const std::shared_ptr<InputMethodPanel> &panel,
Rosen::WindowVisibilityState isVisible)
{
ASSERT_NE(panel, nullptr);
if (isScbEnable_) {
IdentityCheckerMock::SetBundleNameValid(true);
panel->OnVisibilityChange(isVisible);
IdentityCheckerMock::SetBundleNameValid(false);
}
}
int32_t InputMethodPanelTest::GetDisplaySize(DisplaySize &size)
{
auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
if (defaultDisplay == nullptr) {
IMSA_HILOGE("GetDefaultDisplay failed!");
return ErrorCode::ERROR_WINDOW_MANAGER;
}
auto width = defaultDisplay->GetWidth();
auto height = defaultDisplay->GetHeight();
if (width < height) {
size.portrait = { .width = width, .height = height };
size.landscape = { .width = height, .height = width };
} else {
size.portrait = { .width = height, .height = width };
size.landscape = { .width = width, .height = height };
}
return ErrorCode::NO_ERROR;
}
void InputMethodPanelTest::TestAdjust()
{
DisplaySize displaySize;
ASSERT_EQ(InputMethodPanelTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
LayoutParams layoutParams;
PanelFlag panelFlag = PanelFlag::FLG_FIXED;
for (int i = 0;i <= 1; i++) {
layoutParams.landscapeRect = { 0, 0, displaySize.landscape.width, i};
layoutParams.portraitRect = { 0, 0, displaySize.portrait.width, i};
auto ret = panel_->AdjustPanelRect(panelFlag, layoutParams, true, false, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
}
* @tc.name: testCreatePanel
* @tc.desc: Test CreatePanel.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testCreatePanel, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testCreatePanel start.");
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testDestroyPanel
* @tc.desc: Test DestroyPanel.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testDestroyPanel, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testDestroyPanel start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
auto ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
* @tc.name: testResizePanel001
* @tc.desc: Test Resize panel. Panels non fixed soft keyboard.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testResizePanel001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testResizePanel001 start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
auto ret = inputMethodPanel->Resize(1, 1);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
AccessScope scope(currentImeTokenId_, currentImeUid_);
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
ASSERT_TRUE(defaultDisplay != nullptr);
int32_t width = defaultDisplay->GetWidth();
int32_t height = defaultDisplay->GetHeight();
ret = inputMethodPanel->Resize(width - 1, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->Resize(width, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->Resize(width + 1, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
ret = inputMethodPanel->Resize(width, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
ret = inputMethodPanel->Resize(width + 1, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testResizePanel002
* @tc.desc: Test Resize panel. Fixed soft keyboard panel .
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testResizePanel002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testResizePanel002 start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
auto ret = inputMethodPanel->Resize(1, 1);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
AccessScope scope(currentImeTokenId_, currentImeUid_);
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
ASSERT_TRUE(defaultDisplay != nullptr);
int32_t width = defaultDisplay->GetWidth();
int32_t height = defaultDisplay->GetHeight();
ret = inputMethodPanel->Resize(width - 1, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->Resize(width, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->Resize(width + 1, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
ret = inputMethodPanel->Resize(width, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
ret = inputMethodPanel->Resize(width + 1, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testMovePanel
* @tc.desc: Test Move panel. SOFT_KEYBOARD panel with FLG_FIXED can not be moved.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testMovePanel, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testMovePanel start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
auto ret = inputMethodPanel->MoveTo(10, 100);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
AccessScope scope(currentImeTokenId_, currentImeUid_);
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->MoveTo(10, 100);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_FLOATING);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->MoveTo(10, 100);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
panelInfo.panelType = STATUS_BAR;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->MoveTo(10, 100);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testShowPanel
* @tc.desc: Test Show panel.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testShowPanel, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testShowPanel start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
auto ret = inputMethodPanel->ShowPanel(Trigger::IME_APP);
EXPECT_EQ(ret, ErrorCode::ERROR_IMA_NULLPTR);
AccessScope scope(currentImeTokenId_, currentImeUid_);
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->ShowPanel(Trigger::IME_APP);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
EXPECT_TRUE(statusListener != nullptr);
std::string type = "show";
inputMethodPanel->SetPanelStatusListener(statusListener, type);
ret = inputMethodPanel->ShowPanel(Trigger::IME_APP);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_FLOATING);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->ShowPanel(Trigger::IME_APP);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
panelInfo.panelType = STATUS_BAR;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->ShowPanel(Trigger::IME_APP);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->HidePanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testIsPanelShown_001
* @tc.desc: Test is panel shown.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testIsPanelShown_001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_001 start.");
InputMethodPanelTest::Attach();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
InputMethodPanelTest::TestShowPanel(inputMethodPanel);
InputMethodPanelTest::TestIsPanelShown(panelInfo, true);
InputMethodPanelTest::TestHidePanel(inputMethodPanel);
InputMethodPanelTest::TestIsPanelShown(panelInfo, false);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
}
* @tc.name: testIsPanelShown_002
* @tc.desc: Test is panel shown.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testIsPanelShown_002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_002 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
auto ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_FLOATING);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::TestShowPanel(inputMethodPanel);
InputMethodPanelTest::TestIsPanelShown(panelInfo, false);
panelInfo.panelFlag = PanelFlag::FLG_FLOATING;
InputMethodPanelTest::TestIsPanelShown(panelInfo, true);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
}
* @tc.name: testIsPanelShown_003
* @tc.desc: Test is panel shown.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testIsPanelShown_003, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_003 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = STATUS_BAR;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
InputMethodPanelTest::TestShowPanel(inputMethodPanel);
InputMethodPanelTest::TestIsPanelShown(panelInfo, true);
InputMethodPanelTest::TestHidePanel(inputMethodPanel);
InputMethodPanelTest::TestIsPanelShown(panelInfo, false);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
}
* @tc.name: testSetPanelStatusListener01
* @tc.desc: Test testSetPanelStatusListener01.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetPanelStatusListener01, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testSetPanelStatusListener01 start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
inputMethodPanel->SetPanelStatusListener(statusListener, "show");
inputMethodPanel->SetPanelStatusListener(statusListener, "hide");
AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_TRUE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
EXPECT_TRUE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
}
* @tc.name: testSetPanelStatusListener02
* @tc.desc: Test testSetPanelStatusListener02.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetPanelStatusListener02, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testSetPanelStatusListener02 start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
inputMethodPanel->panelStatusListener_ = statusListener;
InputMethodPanelTest::status_ = InputWindowStatus::NONE;
InputMethodPanelTest::TestShowPanel(inputMethodPanel);
inputMethodPanel->SetPanelStatusListener(statusListener, "show");
EXPECT_EQ(status_, InputWindowStatus::SHOW);
InputMethodPanelTest::status_ = InputWindowStatus::NONE;
InputMethodPanelTest::TestHidePanel(inputMethodPanel);
inputMethodPanel->SetPanelStatusListener(statusListener, "hide");
EXPECT_EQ(status_, InputWindowStatus::HIDE);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
}
* @tc.name: testGetPanelType
* @tc.desc: Test GetPanelType.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetPanelType, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetPanelType start.");
AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
auto type = inputMethodPanel->GetPanelType();
EXPECT_EQ(type, panelInfo.panelType);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testGetPanelFlag
* @tc.desc: Test GetPanelFlag.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetPanelFlag, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetPanelFlag start.");
AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
auto flag = inputMethodPanel->GetPanelFlag();
EXPECT_EQ(flag, panelInfo.panelFlag);
ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_CANDIDATE_COLUMN);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
flag = inputMethodPanel->GetPanelFlag();
EXPECT_EQ(flag, PanelFlag::FLG_CANDIDATE_COLUMN);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testChangePanelFlag
* @tc.desc: Test ChangePanelFlag.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testChangePanelFlag, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testChangePanelFlag start.");
AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelFlag flag = FLG_FLOATING;
auto ret = inputMethodPanel->ChangePanelFlag(flag);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
PanelInfo panelInfo1;
panelInfo1.panelType = SOFT_KEYBOARD;
panelInfo1.panelFlag = FLG_FLOATING;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo1);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->ChangePanelFlag(flag);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
flag = FLG_FIXED;
ret = inputMethodPanel->ChangePanelFlag(flag);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
inputMethodPanel->DestroyPanel();
PanelInfo panelInfo;
panelInfo.panelType = STATUS_BAR;
panelInfo.panelFlag = FLG_FLOATING;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->ChangePanelFlag(flag);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
inputMethodPanel->DestroyPanel();
}
* @tc.name: testClearPanelListener
* @tc.desc: Test ClearPanelListener.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testClearPanelListener, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testClearPanelListener start.");
auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
inputMethodPanel->SetPanelStatusListener(statusListener, "show");
inputMethodPanel->SetPanelStatusListener(statusListener, "hide");
inputMethodPanel->ClearPanelListener("show");
EXPECT_FALSE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
EXPECT_TRUE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
inputMethodPanel->ClearPanelListener("hide");
EXPECT_FALSE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
EXPECT_FALSE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testRegisterListener
* @tc.desc: Test ClearPanelListener.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testRegisterListener, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testRegisterListener start.");
auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
inputMethodPanel->SetPanelStatusListener(statusListener, "show");
inputMethodPanel->SetPanelStatusListener(statusListener, "hide");
EXPECT_TRUE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
EXPECT_TRUE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
inputMethodPanel->ClearPanelListener("show");
EXPECT_FALSE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
EXPECT_TRUE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
inputMethodPanel->SetPanelStatusListener(statusListener, "show");
EXPECT_TRUE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testImcPanelListening_001
* @tc.desc: SOFT_KEYBOARD/FLG_FIXED, listener(system app)
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testImcPanelListening_001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_001 start.");
IdentityCheckerMock::SetSystemApp(true);
IdentityCheckerMock::SetBundleNameValid(true);
auto listener = std::make_shared<InputMethodSettingListenerImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
std::shared_ptr<InputMethodPanel> panel = nullptr;
ImaCreatePanel(panelInfo, panel);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestShowPanel(panel);
InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::SHOW);
InputMethodPanelTest::ImcPanelShowNumCheck(1);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestHidePanel(panel);
InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::HIDE);
InputMethodPanelTest::ImcPanelHideNumCheck(1);
ImaDestroyPanel(panel);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
IdentityCheckerMock::SetSystemApp(false);
IdentityCheckerMock::SetBundleNameValid(false);
}
* @tc.name: testImcPanelListening_002
* @tc.desc: SOFT_KEYBOARD/FLG_FLOATING, listener(system app)
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testImcPanelListening_002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_002 start.");
IdentityCheckerMock::SetSystemApp(true);
IdentityCheckerMock::SetBundleNameValid(true);
auto listener = std::make_shared<InputMethodSettingListenerImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
AccessScope scope(currentImeTokenId_, currentImeUid_);
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
std::shared_ptr<InputMethodPanel> panel = nullptr;
ImaCreatePanel(panelInfo, panel);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestShowPanel(panel);
InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::SHOW);
InputMethodPanelTest::ImcPanelShowNumCheck(1);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestHidePanel(panel);
InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::HIDE);
InputMethodPanelTest::ImcPanelHideNumCheck(1);
ImaDestroyPanel(panel);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
IdentityCheckerMock::SetSystemApp(false);
IdentityCheckerMock::SetBundleNameValid(false);
}
* @tc.name: testImcPanelListening_003
* @tc.desc: SOFT_KEYBOARD/FLG_CANDIDATE_COLUMN, listener(system app)
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testImcPanelListening_003, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_003 start.");
IdentityCheckerMock::SetSystemApp(true);
IdentityCheckerMock::SetBundleNameValid(true);
auto listener = std::make_shared<InputMethodSettingListenerImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_CANDIDATE_COLUMN;
std::shared_ptr<InputMethodPanel> panel = nullptr;
ImaCreatePanel(panelInfo, panel);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestShowPanel(panel);
InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::SHOW);
InputMethodPanelTest::ImcPanelShowNumCheck(0);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestHidePanel(panel);
InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::HIDE);
InputMethodPanelTest::ImcPanelHideNumCheck(0);
ImaDestroyPanel(panel);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
IdentityCheckerMock::SetSystemApp(false);
IdentityCheckerMock::SetBundleNameValid(false);
}
* @tc.name: testImcPanelListening_004
* @tc.desc: STATUS_BAR, listener(system app)
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testImcPanelListening_004, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_004 start.");
IdentityCheckerMock::SetSystemApp(true);
IdentityCheckerMock::SetBundleNameValid(true);
auto listener = std::make_shared<InputMethodSettingListenerImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
PanelInfo panelInfo;
panelInfo.panelType = STATUS_BAR;
std::shared_ptr<InputMethodPanel> panel = nullptr;
ImaCreatePanel(panelInfo, panel);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestShowPanel(panel);
InputMethodPanelTest::ImcPanelShowNumCheck(0);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestHidePanel(panel);
InputMethodPanelTest::ImcPanelHideNumCheck(0);
ImaDestroyPanel(panel);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
IdentityCheckerMock::SetSystemApp(false);
IdentityCheckerMock::SetBundleNameValid(false);
}
* @tc.name: testPanelStatusChangeEventPublicTest
* @tc.desc: test subscriber can receive the panel status change event published by IMSA
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testPanelStatusChangeEventPublicTest, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testPanelStatusChangeEventPublicTest start.");
IdentityCheckerMock::SetBundleNameValid(true);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED);
EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
auto subscriber = std::make_shared<TestEventSubscriber>(subscriberInfo);
auto ret = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber);
EXPECT_TRUE(ret);
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
std::shared_ptr<InputMethodPanel> panel = nullptr;
ImaCreatePanel(panelInfo, panel);
subscriber->ResetParam();
InputMethodPanelTest::TestShowPanel(panel);
InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::SHOW);
{
std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
auto waitRet = imcPanelStatusListenerCv_.wait_for(
lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [subscriber]() {
return subscriber->action_ == COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED &&
subscriber->status_ == InputWindowStatus::SHOW;
});
EXPECT_TRUE(waitRet);
}
subscriber->ResetParam();
InputMethodPanelTest::TestHidePanel(panel);
InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::HIDE);
{
std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
auto waitRet = imcPanelStatusListenerCv_.wait_for(
lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [subscriber]() {
return subscriber->action_ == COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED &&
subscriber->status_ == InputWindowStatus::HIDE;
});
EXPECT_TRUE(waitRet);
}
ImaDestroyPanel(panel);
IdentityCheckerMock::SetBundleNameValid(false);
}
* @tc.name: testSetCallingWindow
* @tc.desc: test SetCallingWindow
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetCallingWindow, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testSetCallingWindow start.");
AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
uint32_t windowId = 8;
auto ret = inputMethodPanel->SetCallingWindow(windowId);
EXPECT_EQ(ret, ErrorCode::ERROR_PANEL_NOT_FOUND);
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->SetCallingWindow(windowId);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testKeyboardPanelInfoChangeListenerRegister_001
* @tc.desc: SOFT_KEYBOARD
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testKeyboardPanelInfoChangeListenerRegister_001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testKeyboardPanelInfoChangeListenerRegister_001 start.");
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
std::shared_ptr<InputMethodPanel> panel = nullptr;
ImaCreatePanel(panelInfo, panel);
ASSERT_NE(panel, nullptr);
if (isScbEnable_) {
EXPECT_NE(panel->kbPanelInfoListener_, nullptr);
} else {
EXPECT_EQ(panel->kbPanelInfoListener_, nullptr);
}
ImaDestroyPanel(panel);
EXPECT_EQ(panel->kbPanelInfoListener_, nullptr);
}
* @tc.name: testKeyboardPanelInfoChangeListenerRegister_002
* @tc.desc: STATUS_BAR
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testKeyboardPanelInfoChangeListenerRegister_002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testKeyboardPanelInfoChangeListenerRegister_002 start.");
PanelInfo panelInfo;
panelInfo.panelType = STATUS_BAR;
std::shared_ptr<InputMethodPanel> panel = nullptr;
ImaCreatePanel(panelInfo, panel);
ASSERT_NE(panel, nullptr);
EXPECT_EQ(panel->kbPanelInfoListener_, nullptr);
ImaDestroyPanel(panel);
}
* @tc.name: testAdjustPanelRect_001
* @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_001 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
PanelFlag panelFlag = PanelFlag::FLG_FIXED;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, 0, 0, 0 };
layoutParams.portraitRect = { 0, 0, 0, 0 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_002
* @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_002 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
PanelFlag panelFlag = PanelFlag::FLG_FIXED;
LayoutParams layoutParams;
layoutParams.landscapeRect = { -1, 0, 0, 0 };
layoutParams.portraitRect = { -1, 0, 0, 0 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_003
* @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_003, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_003 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
PanelFlag panelFlag = PanelFlag::FLG_FIXED;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, -1, 0, 0 };
layoutParams.portraitRect = { 0, -1, 0, 0 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_004
* @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_004, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_004 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
PanelFlag panelFlag = PanelFlag::FLG_FIXED;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, 0, -1, 0 };
layoutParams.portraitRect = { 0, 0, -1, 0 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_005
* @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_005, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_005 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
PanelFlag panelFlag = PanelFlag::FLG_FIXED;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, 0, 0, -1 };
layoutParams.portraitRect = { 0, 0, 0, -1 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_006
* @tc.desc: Test AdjustPanelRect with FLG_FIXED valid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_006, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_006 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
DisplaySize displaySize;
ASSERT_EQ(InputMethodPanelTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
PanelFlag panelFlag = PanelFlag::FLG_FIXED;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, 0, displaySize.landscape.width, 0 };
layoutParams.portraitRect = { 0, 0, displaySize.portrait.width, 0 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ima_.inputType_ = InputType::SECURITY_INPUT;
ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ima_.inputType_ = InputType::NONE;
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_007
* @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_007, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_007 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
DisplaySize displaySize;
ASSERT_EQ(InputMethodPanelTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
PanelFlag panelFlag = PanelFlag::FLG_FIXED;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, 0, displaySize.landscape.width + 1, 0 };
layoutParams.portraitRect = { 0, 0, displaySize.portrait.width + 1, 0 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_008
* @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_008, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_008 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
DisplaySize displaySize;
ASSERT_EQ(InputMethodPanelTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
PanelFlag panelFlag = PanelFlag::FLG_FIXED;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, 0, displaySize.landscape.width,
static_cast<uint32_t>(static_cast<float>(displaySize.landscape.height) * 0.7) + 1 };
layoutParams.portraitRect = { 0, 0, displaySize.portrait.width,
static_cast<uint32_t>(static_cast<float>(displaySize.portrait.height) * 0.7) + 1 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_009
* @tc.desc: Test AdjustPanelRect with FLG_FIXED valid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_009, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_009 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
DisplaySize displaySize;
ASSERT_EQ(InputMethodPanelTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
PanelFlag panelFlag = PanelFlag::FLG_FIXED;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, 0, displaySize.landscape.width,
static_cast<uint32_t>(static_cast<float>(displaySize.landscape.height) * 0.7) };
layoutParams.portraitRect = { 0, 0, displaySize.portrait.width,
static_cast<uint32_t>(static_cast<float>(displaySize.portrait.height) * 0.7) };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_010
* @tc.desc: Test AdjustPanelRect with FLG_FLOATING valid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_010, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_010 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, 0, 0, 0 };
layoutParams.portraitRect = { 0, 0, 0, 0 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_011
* @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_011, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_011 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
LayoutParams layoutParams;
layoutParams.landscapeRect = { -1, 0, 0, 0 };
layoutParams.portraitRect = { -1, 0, 0, 0 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_012
* @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_012, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_012 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, -1, 0, 0 };
layoutParams.portraitRect = { 0, -1, 0, 0 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_013
* @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_013, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_013 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, 0, -1, 0 };
layoutParams.portraitRect = { 0, 0, -1, 0 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_014
* @tc.desc: Test AdjustPanelRect with FLG_FLOATING valid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_014, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_014 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
DisplaySize displaySize;
ASSERT_EQ(InputMethodPanelTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, 0, displaySize.landscape.width, 0 };
layoutParams.portraitRect = { 0, 0, displaySize.portrait.width, 0 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_015
* @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_015, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_015 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
DisplaySize displaySize;
ASSERT_EQ(InputMethodPanelTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, 0, displaySize.landscape.width + 1, 0 };
layoutParams.portraitRect = { 0, 0, displaySize.portrait.width + 1, 0 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_016
* @tc.desc: Test AdjustPanelRect with FLG_FLOATING valid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_016, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_016 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
DisplaySize displaySize;
ASSERT_EQ(InputMethodPanelTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, 0, displaySize.landscape.width,
static_cast<uint32_t>(static_cast<float>(displaySize.landscape.height) * 0.7) + 1 };
layoutParams.portraitRect = { 0, 0, displaySize.portrait.width,
static_cast<uint32_t>(static_cast<float>(displaySize.portrait.height) * 0.7) + 1 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_017
* @tc.desc: Test AdjustPanelRect with FLG_FLOATING valid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_017, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_017 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
DisplaySize displaySize;
ASSERT_EQ(InputMethodPanelTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
LayoutParams layoutParams = { .landscapeRect = { 0, 0, displaySize.landscape.width, displaySize.landscape.height },
.portraitRect = { 0, 0, displaySize.portrait.width, displaySize.portrait.height } };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_018
* @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_018, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_018 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
DisplaySize displaySize;
ASSERT_EQ(InputMethodPanelTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
LayoutParams layoutParams;
layoutParams.landscapeRect = { 0, 0, displaySize.landscape.width, displaySize.landscape.height + 1 };
layoutParams.portraitRect = { 0, 0, displaySize.portrait.width, displaySize.portrait.height + 1 };
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true, true, false);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustPanelRect_muiltThread
* @tc.desc: Test AdjustPanelRect with FLG_FLOATING valid params.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_muiltThread, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustPanelRect_muiltThread start.");
InputMethodPanelTest::Attach();
panel_ = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
InputMethodPanelTest::ImaCreatePanel(panelInfo, panel_);
SET_THREAD_NUM(3);
GTEST_RUN_TASK(TestAdjust);
bool result = false;
if (panel_->keyboardLayoutParams_.LandscapeKeyboardRect_.height_ == 1 ||
panel_->keyboardLayoutParams_.PortraitKeyboardRect_.height_ == 1) {
result = true;
}
EXPECT_TRUE(result);
InputMethodPanelTest::ImaDestroyPanel(panel_);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustKeyboard_001
* @tc.desc: Test AdjustKeyboard
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustKeyboard_001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustKeyboard_001 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
auto ret = inputMethodPanel->AdjustKeyboard();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustKeyboard_002
* @tc.desc: Test AdjustKeyboard
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustKeyboard_002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustKeyboard_002 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
DisplaySize display;
ASSERT_EQ(InputMethodPanelTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
PanelFlag panelFlag = PanelFlag::FLG_FIXED;
Rosen::Rect portraitRect = { 0, 0, 0, static_cast<uint32_t>(display.portrait.height * 0.8) };
Rosen::Rect landscapeRect = { 0, 0, 0, static_cast<uint32_t>(display.landscape.height * 0.8) };
uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
uint32_t portraitAvoidY = display.portrait.height - portraitAvoidHeight;
uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight;
EnhancedLayoutParams params = {
.isFullScreen = false,
.portrait = { portraitRect, {}, static_cast<int32_t>(portraitAvoidY), 0 },
.landscape = { landscapeRect, {}, static_cast<int32_t>(landscapeAvoidY), 0 },
};
auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, {}, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
std::this_thread::sleep_for(std::chrono::seconds(1));
ret = inputMethodPanel->AdjustKeyboard();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
params = inputMethodPanel->GetEnhancedLayoutParams();
params.portrait.avoidHeight = 30000;
params.landscape.avoidHeight = 30000;
inputMethodPanel->SetEnhancedLayoutParams(params);
ret = inputMethodPanel->AdjustKeyboard();
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testAdjustKeyboard_003
* @tc.desc: Test AdjustKeyboard
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testAdjustKeyboard_003, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testAdjustKeyboard_003 start.");
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
auto ret = inputMethodPanel->AdjustKeyboard();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
panelInfo.panelFlag = FLG_CANDIDATE_COLUMN;
ret = inputMethodPanel->AdjustKeyboard();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testSetPrivacyMode
* @tc.desc: Test SetPrivacyMode.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetPrivacyMode, TestSize.Level0)
{
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
auto ret = inputMethodPanel->SetPrivacyMode(true);
EXPECT_NE(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testSetPanelProperties
* @tc.desc: Test SetPanelProperties.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetPanelProperties, TestSize.Level0)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
auto ret = inputMethodPanel->SetPanelProperties();
EXPECT_EQ(ret, ErrorCode::ERROR_OPERATE_PANEL);
inputMethodPanel->UnregisterKeyboardPanelInfoChangeListener();
ret = inputMethodPanel->SetPrivacyMode(false);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
* @tc.name: testGetKeyboardSize
* @tc.desc: Test GetKeyboardSize.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetKeyboardSize, TestSize.Level0)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
auto boardSize = inputMethodPanel->GetKeyboardSize();
EXPECT_EQ(boardSize.width, 0);
EXPECT_EQ(boardSize.height, 0);
}
* @tc.name: testMarkListener
* @tc.desc: Test MarkListener.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testMarkListener, TestSize.Level0)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
auto ret = inputMethodPanel->SetPanelStatusListener(statusListener, "text");
EXPECT_FALSE(ret);
inputMethodPanel->ClearPanelListener("text");
ret = inputMethodPanel->MarkListener("contenInfo", true);
EXPECT_FALSE(ret);
ret = inputMethodPanel->MarkListener("sizeChange", true);
EXPECT_TRUE(ret);
}
* @tc.name: testSizeChange
* @tc.desc: Test SizeChange.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSizeChange, TestSize.Level0)
{
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
inputMethodPanel->panelStatusListener_ = statusListener;
WindowSize windowSize;
ret = inputMethodPanel->SizeChange(windowSize);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testSetTextFieldAvoidInfo01
* @tc.desc: Test SetTextFieldAvoidInfo.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetTextFieldAvoidInfo01, TestSize.Level0)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
auto ret = inputMethodPanel->SetTextFieldAvoidInfo(0, 0);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
* @tc.name: testSetTextFieldAvoidInfo02
* @tc.desc: Test SetTextFieldAvoidInfo.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetTextFieldAvoidInfo02, TestSize.Level0)
{
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
auto ret = inputMethodPanel->SetTextFieldAvoidInfo(0, 0);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testGetCallingWindowInfo01
* @tc.desc: Test GetCallingWindowInfo.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetCallingWindowInfo01, TestSize.Level0)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
CallingWindowInfo windowInfo;
auto ret = inputMethodPanel->GetCallingWindowInfo(windowInfo);
EXPECT_EQ(ret, ErrorCode::ERROR_PANEL_NOT_FOUND);
}
* @tc.name: testGetCallingWindowInfo02
* @tc.desc: Test GetCallingWindowInfo.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetCallingWindowInfo02, TestSize.Level0)
{
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
CallingWindowInfo windowInfo;
auto ret = inputMethodPanel->GetCallingWindowInfo(windowInfo);
if (isScbEnable_) {
EXPECT_EQ(ret, ErrorCode::ERROR_WINDOW_MANAGER);
} else {
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testSetUiContent01
* @tc.desc: Test SetUiContent.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetUiContent01, TestSize.Level0)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
auto ret = inputMethodPanel->SetUiContent("text", nullptr, nullptr);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
* @tc.name: testSetUiContent02
* @tc.desc: Test SetUiContent.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetUiContent02, TestSize.Level0)
{
InputMethodPanelTest::Attach();
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
auto ret = inputMethodPanel->SetUiContent("text", nullptr, nullptr);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: testIsSizeValid
* @tc.desc: Test IsSizeValid
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testIsSizeValid, TestSize.Level0)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
EXPECT_FALSE(inputMethodPanel->IsSizeValid(INT32_MAX + 1, INT32_MAX));
EXPECT_FALSE(inputMethodPanel->IsSizeValid(INT32_MAX, INT32_MAX + 1));
}
* @tc.name: testGenerateSequenceId
* @tc.desc: Test GenerateSequenceId
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGenerateSequenceId, TestSize.Level0)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
inputMethodPanel->sequenceId_ = std::numeric_limits<uint32_t>::max() - 1;
uint32_t seqId = inputMethodPanel->GenerateSequenceId();
EXPECT_EQ(seqId, 0);
}
* @tc.name: testPanelStatusListener01
* @tc.desc: Test SetPanelStatusListener
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testPanelStatusListener01, TestSize.Level0)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
inputMethodPanel->panelStatusListener_ = nullptr;
inputMethodPanel->ClearPanelListener("show");
AccessScope scope(currentImeTokenId_, currentImeUid_);
PanelInfo panelInfo;
panelInfo.panelType = STATUS_BAR;
panelInfo.panelFlag = FLG_FIXED;
auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
inputMethodPanel->panelStatusListener_ = statusListener;
EXPECT_TRUE(inputMethodPanel->SetPanelStatusListener(statusListener, "sizeChange"));
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testPanelStatusListener02
* @tc.desc: Test SetPanelStatusListener
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testPanelStatusListener02, TestSize.Level0)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
AccessScope scope(currentImeTokenId_, currentImeUid_);
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
inputMethodPanel->panelStatusListener_ = statusListener;
EXPECT_TRUE(inputMethodPanel->SetPanelStatusListener(statusListener, "sizeChange"));
EXPECT_TRUE(inputMethodPanel->SetPanelStatusListener(nullptr, "sizeChange"));
inputMethodPanel->panelStatusListener_ = nullptr;
EXPECT_TRUE(inputMethodPanel->SetPanelStatusListener(nullptr, "sizeChange"));
EXPECT_TRUE(inputMethodPanel->SetPanelStatusListener(statusListener, "sizeChange"));
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testStartMoving01
* @tc.desc: Test StartMoving
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testStartMoving01, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testStartMoving start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
auto ret = inputMethodPanel->StartMoving();
EXPECT_EQ(ret, ErrorCode::ERROR_IME);
AccessScope scope(currentImeTokenId_, currentImeUid_);
PanelInfo panelInfo;
panelInfo.panelType = STATUS_BAR;
panelInfo.panelFlag = FLG_FLOATING;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->StartMoving();
EXPECT_TRUE(ret == ErrorCode::NO_ERROR || ret == ErrorCode::ERROR_DEVICE_UNSUPPORTED);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
panelInfo.panelType = SOFT_KEYBOARD;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->StartMoving();
EXPECT_TRUE(ret == ErrorCode::NO_ERROR || ret == ErrorCode::ERROR_DEVICE_UNSUPPORTED);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
panelInfo.panelType = STATUS_BAR;
panelInfo.panelFlag = FLG_FIXED;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->StartMoving();
EXPECT_TRUE(ret == ErrorCode::NO_ERROR || ret == ErrorCode::ERROR_DEVICE_UNSUPPORTED);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testStartMoving02
* @tc.desc: Test StartMoving
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testStartMoving02, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testStartMoving start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
auto ret = inputMethodPanel->StartMoving();
EXPECT_EQ(ret, ErrorCode::ERROR_IME);
AccessScope scope(currentImeTokenId_, currentImeUid_);
PanelInfo panelInfo;
panelInfo.panelType = STATUS_BAR;
panelInfo.panelFlag = FLG_CANDIDATE_COLUMN;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->StartMoving();
EXPECT_TRUE(ret == ErrorCode::NO_ERROR || ret == ErrorCode::ERROR_DEVICE_UNSUPPORTED);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
panelInfo.panelType = SOFT_KEYBOARD;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->StartMoving();
EXPECT_TRUE(ret == ErrorCode::NO_ERROR || ret == ErrorCode::ERROR_DEVICE_UNSUPPORTED);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
panelInfo.panelFlag = FLG_FIXED;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->StartMoving();
EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_PANEL_FLAG);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testGetDisplayId01
* @tc.desc: Test GetDisplayId
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetDisplayId01, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetDisplayId start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
uint64_t displayId;
auto ret = inputMethodPanel->GetDisplayId(displayId);
EXPECT_EQ(ret, ErrorCode::ERROR_IME);
AccessScope scope(currentImeTokenId_, currentImeUid_);
PanelInfo panelInfo;
panelInfo.panelType = STATUS_BAR;
panelInfo.panelFlag = FLG_FLOATING;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->GetDisplayId(displayId);
EXPECT_GE(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testSetImmersiveMode
* @tc.desc: Test set immersive mode.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetImmersiveMode, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testSetImmersiveMode start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
ret = inputMethodPanel->ShowPanel(Trigger::IME_APP);
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::NONE_IMMERSIVE);
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::LIGHT_IMMERSIVE);
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::DARK_IMMERSIVE);
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::IMMERSIVE);
EXPECT_EQ(ErrorCode::ERROR_PARAMETER_CHECK_FAILED, ret);
ret = inputMethodPanel->HidePanel();
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
}
* @tc.name: testGetImmersiveMode
* @tc.desc: Test get immersive mode.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetImmersiveMode, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetImmersiveMode start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
ret = inputMethodPanel->ShowPanel(Trigger::IME_APP);
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::NONE_IMMERSIVE);
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
auto mode = inputMethodPanel->GetImmersiveMode();
EXPECT_EQ(ImmersiveMode::NONE_IMMERSIVE, mode);
ret = inputMethodPanel->HidePanel();
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
}
* @tc.name: testParameterValidationInterface
* @tc.desc: Test Parameter validation interface
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testParameterValidationInterface, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testParameterValidationInterface start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EnhancedLayoutParams enhancedLayoutParams;
FullPanelAdjustInfo adjustInfo;
enhancedLayoutParams.portrait.avoidY = 10;
enhancedLayoutParams.landscape.avoidY = 20;
adjustInfo.portrait = {0, 0, 100, 100};
adjustInfo.landscape = {0, 0, 200, 200};
PanelAdjustInfo keyboardArea;
ret = inputMethodPanel->GetKeyboardArea(PanelFlag::FLG_FIXED, {100, 200}, keyboardArea);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(keyboardArea.top, inputMethodPanel->enhancedLayoutParams_.portrait.avoidY);
uint32_t validWidth = 100;
uint32_t validHeight = 200;
ret = inputMethodPanel->ResizeWithoutAdjust(validWidth, validHeight);
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
ret = inputMethodPanel->ResizeWithoutAdjust(INT32_MAX + 1, INT32_MAX + 1);
EXPECT_EQ(ErrorCode::ERROR_BAD_PARAMETERS, ret);
inputMethodPanel->panelType_ = PanelType::STATUS_BAR;
ret = inputMethodPanel->IsEnhancedParamValid(PanelFlag::FLG_FIXED, enhancedLayoutParams);
EXPECT_EQ(ErrorCode::ERROR_INVALID_PANEL_TYPE, ret);
Rosen::Rect rect1{10, 20, 100, 200};
WindowSize displaySize1 {800, 600};
EXPECT_TRUE(inputMethodPanel->IsRectValid(rect1, displaySize1));
Rosen::Rect rect2{-10, 20, 100, 200};
WindowSize displaySize2{800, 600};
EXPECT_FALSE(inputMethodPanel->IsRectValid(rect2, displaySize2));
Rosen::Rect rect3{10, 20, INT32_MAX, 200};
WindowSize displaySize3{800, 600};
EXPECT_FALSE(inputMethodPanel->IsRectValid(rect3, displaySize3));
Rosen::Rect rect4{10, 20, 9000, 20000};
WindowSize displaySize4{800, 600};
EXPECT_FALSE(inputMethodPanel->IsRectValid(rect4, displaySize4));
inputMethodPanel->window_ = nullptr;
ret= inputMethodPanel->IsEnhancedParamValid(PanelFlag::FLG_FIXED, enhancedLayoutParams);
EXPECT_EQ(ErrorCode::ERROR_WINDOW_MANAGER, ret);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ErrorCode::ERROR_NULL_POINTER, ret);
}
* @tc.name: testMoveEnhancedPanelRect
* @tc.desc: Test Move Enhanced Panel Rect
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testMoveEnhancedPanelRect, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testMoveEnhancedPanelRect start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
int32_t portraitX = 10;
int32_t portraitY = 20;
int32_t portraitRet = inputMethodPanel->MoveEnhancedPanelRect(portraitX, portraitY);
EXPECT_EQ(ErrorCode::NO_ERROR, portraitRet);
int32_t landscapeX = 30;
int32_t landscapeY = 40;
int32_t landscapeRet = inputMethodPanel->MoveEnhancedPanelRect(landscapeX, landscapeY);
EXPECT_EQ(ErrorCode::NO_ERROR, landscapeRet);
int32_t minX = -100;
int32_t minY = -200;
int32_t minRet = inputMethodPanel->MoveEnhancedPanelRect(minX, minY);
EXPECT_EQ(ErrorCode::ERROR_PARAMETER_CHECK_FAILED, minRet);
const std::string type = "sizeUpdate";
EXPECT_TRUE(inputMethodPanel->MarkListener(type, false));
uint32_t windowWidth = 100;
bool isPortrait = false;
ret = inputMethodPanel->GetWindowOrientation(PanelFlag::FLG_FIXED, windowWidth, isPortrait);
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::NONE_IMMERSIVE);
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
inputMethodPanel->window_ = nullptr;
ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::NONE_IMMERSIVE);
EXPECT_EQ(ErrorCode::NO_ERROR, ret);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ErrorCode::ERROR_NULL_POINTER, ret);
}
* @tc.name: testSetImmersiveEffect
* @tc.desc: Test SetImmersiveEffect device not supported.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetImmersiveEffect, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelAdjustTest testSetImmersiveEffect Test START");
auto supportedCapacityList = ImeInfoInquirer::GetInstance().GetSystemConfig().supportedCapacityList;
supportedCapacityList.erase(IMMERSIVE_EFFECT);
ImeInfoInquirer::GetInstance().systemConfig_.supportedCapacityList = supportedCapacityList;
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
ImmersiveEffect immersiveEffect = {
.gradientHeight = 20, .gradientMode = GradientMode::LINEAR_GRADIENT, .fluidLightMode = FluidLightMode::NONE
};
int32_t ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
EXPECT_EQ(ret, ErrorCode::ERROR_DEVICE_UNSUPPORTED);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
}
* @tc.name: testSetKeepScreenOn1
* @tc.desc: Test SetKeepScreenOn.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetKeepScreenOn1, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testSetKeepScreenOn1 start.");
auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(inputMethodPanel, nullptr);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
inputMethodPanel->window_ = nullptr;
bool isKeepScreenOn = false;
auto ret = inputMethodPanel->SetKeepScreenOn(isKeepScreenOn);
EXPECT_EQ(ret, ErrorCode::ERROR_WINDOW_MANAGER);
}
* @tc.name: testSetKeepScreenOn2
* @tc.desc: Test SetKeepScreenOn.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetKeepScreenOn2, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testSetKeepScreenOn2 start.");
auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(inputMethodPanel, nullptr);
bool isKeepScreenOn = true;
auto ret = inputMethodPanel->SetKeepScreenOn(isKeepScreenOn);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testInvalidParams
* @tc.desc: Test testInvalidParams
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testInvalidParams, TestSize.Level0)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
inputMethodPanel->immersiveEffect_.gradientHeight = GRADIENT_HEIGHT;
KeyboardLayoutParams param;
param.portraitAvoidHeight_ = -1;
auto ret = inputMethodPanel->FullScreenPrepare(param, inputMethodPanel->immersiveEffect_);
EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_RANGE);
param.portraitAvoidHeight_ = PORTRAIT_AVOID_HEIGHT;
param.landscapeAvoidHeight_ = -1;
ret = inputMethodPanel->FullScreenPrepare(param, inputMethodPanel->immersiveEffect_);
EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_RANGE);
param.landscapeAvoidHeight_ = LANDSCAPE_AVOID_HEIGHT;
param.PortraitPanelRect_.posY_ = -1;
ret = inputMethodPanel->FullScreenPrepare(param, inputMethodPanel->immersiveEffect_);
EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_RANGE);
param.PortraitPanelRect_.posY_ = VALID_POS_Y;
param.LandscapePanelRect_.posY_ = -1;
ret = inputMethodPanel->FullScreenPrepare(param, inputMethodPanel->immersiveEffect_);
EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_RANGE);
}
* @tc.name: testPortraitAdjustmentNeeded
* @tc.desc: Test testPortraitAdjustmentNeeded
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testPortraitAdjustmentNeeded, TestSize.Level0)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
inputMethodPanel->immersiveEffect_.gradientHeight = GRADIENT_HEIGHT;
KeyboardLayoutParams param;
param.portraitAvoidHeight_ = PORTRAIT_AVOID_HEIGHT;
param.landscapeAvoidHeight_ = LANDSCAPE_AVOID_HEIGHT;
param.PortraitPanelRect_.height_ = INITIAL_PORTRAIT_HEIGHT;
param.PortraitPanelRect_.posY_ = INITIAL_PORTRAIT_POS_Y;
auto ret = inputMethodPanel->FullScreenPrepare(param, inputMethodPanel->immersiveEffect_);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
const uint32_t expectedHeight = PORTRAIT_AVOID_HEIGHT + GRADIENT_HEIGHT;
const uint32_t expectedChangeY = expectedHeight - INITIAL_PORTRAIT_HEIGHT;
const int32_t expectedPosY = INITIAL_PORTRAIT_POS_Y - static_cast<int32_t>(expectedChangeY);
EXPECT_EQ(inputMethodPanel->changeY_.portrait, expectedChangeY);
EXPECT_EQ(param.PortraitPanelRect_.height_, expectedHeight);
EXPECT_EQ(param.PortraitPanelRect_.posY_, expectedPosY);
}
* @tc.name: testLargegradientHeight
* @tc.desc: Test testLargegradientHeight
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testLargegradientHeight, TestSize.Level1)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
KeyboardLayoutParams param;
param.portraitAvoidHeight_ = PORTRAIT_AVOID_HEIGHT;
param.landscapeAvoidHeight_ = LANDSCAPE_AVOID_HEIGHT;
param.PortraitPanelRect_.height_ = INITIAL_PORTRAIT_HEIGHT;
param.PortraitPanelRect_.posY_ = INITIAL_PORTRAIT_POS_Y;
inputMethodPanel->immersiveEffect_.gradientHeight = static_cast<uint32_t>(INT32_MAX);
auto ret = inputMethodPanel->FullScreenPrepare(param, inputMethodPanel->immersiveEffect_);
EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_RANGE);
inputMethodPanel->immersiveEffect_.gradientHeight = static_cast<uint32_t>(INT32_MAX - LANDSCAPE_AVOID_HEIGHT - 1);
ret = inputMethodPanel->FullScreenPrepare(param, inputMethodPanel->immersiveEffect_);
EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_RANGE);
}
* @tc.name: testLandscapeAdjustmentNeeded
* @tc.desc: Test testLandscapeAdjustmentNeeded
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testLandscapeAdjustmentNeeded, TestSize.Level0)
{
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
inputMethodPanel->immersiveEffect_.gradientHeight = GRADIENT_HEIGHT;
KeyboardLayoutParams param;
param.portraitAvoidHeight_ = PORTRAIT_AVOID_HEIGHT;
param.landscapeAvoidHeight_ = LANDSCAPE_AVOID_HEIGHT;
param.LandscapePanelRect_.height_ = INITIAL_LANDSCAPE_HEIGHT;
param.LandscapePanelRect_.posY_ = INITIAL_LANDSCAPE_POS_Y;
auto ret = inputMethodPanel->FullScreenPrepare(param, inputMethodPanel->immersiveEffect_);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
const uint32_t expectedHeight = LANDSCAPE_AVOID_HEIGHT + GRADIENT_HEIGHT;
const uint32_t expectedChangeY = expectedHeight - INITIAL_LANDSCAPE_HEIGHT;
const int32_t expectedPosY = INITIAL_LANDSCAPE_POS_Y - static_cast<int32_t>(expectedChangeY);
EXPECT_EQ(inputMethodPanel->changeY_.landscape, expectedChangeY);
EXPECT_EQ(param.LandscapePanelRect_.height_, expectedHeight);
EXPECT_EQ(param.LandscapePanelRect_.posY_, expectedPosY);
}
* @tc.name: ShouldRejectNegativePortraitPosition
* @tc.desc: Test ShouldRejectNegativePortraitPosition
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, ShouldRejectNegativePortraitPosition, TestSize.Level0)
{
auto panel = std::make_shared<InputMethodPanel>();
Rosen::KeyboardLayoutParams param;
panel->immersiveEffect_.gradientHeight = GRADIENT_HEIGHT;
param.PortraitPanelRect_ = { 0, INVALID_POS_Y, DEFAULT_WIDTH, DEFAULT_HEIGHT };
param.LandscapePanelRect_ = { 0, VALID_POS_Y, LANDSCAPE_WIDTH, LANDSCAPE_HEIGHT };
ASSERT_EQ(panel->NormalImePrepare(param, panel->immersiveEffect_), ErrorCode::ERROR_INVALID_RANGE);
}
* @tc.name: ShouldRejectNegativeLandscapePosition
* @tc.desc: Test ShouldRejectNegativeLandscapePosition
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, ShouldRejectNegativeLandscapePosition, TestSize.Level0)
{
auto panel = std::make_shared<InputMethodPanel>();
Rosen::KeyboardLayoutParams param;
panel->immersiveEffect_.gradientHeight = GRADIENT_HEIGHT;
param.PortraitPanelRect_ = { 0, VALID_POS_Y, DEFAULT_WIDTH, DEFAULT_HEIGHT };
param.LandscapePanelRect_ = { 0, INVALID_POS_Y, LANDSCAPE_WIDTH, LANDSCAPE_HEIGHT };
ASSERT_EQ(panel->NormalImePrepare(param, panel->immersiveEffect_), ErrorCode::ERROR_INVALID_RANGE);
}
* @tc.name: ShouldAdjustValidParametersCorrectly
* @tc.desc: Test ShouldAdjustValidParametersCorrectly
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, ShouldAdjustValidParametersCorrectly, TestSize.Level0)
{
auto panel = std::make_shared<InputMethodPanel>();
Rosen::KeyboardLayoutParams param;
const int originalPortraitHeight = DEFAULT_HEIGHT;
const int originalLandscapeHeight = LANDSCAPE_HEIGHT;
panel->immersiveEffect_.gradientHeight = GRADIENT_HEIGHT;
param.PortraitPanelRect_ = { 0, VALID_POS_Y, DEFAULT_WIDTH, originalPortraitHeight };
param.LandscapePanelRect_ = { 0, VALID_POS_Y, LANDSCAPE_WIDTH, originalLandscapeHeight };
ASSERT_EQ(panel->NormalImePrepare(param, panel->immersiveEffect_), ErrorCode::NO_ERROR);
EXPECT_EQ(param.PortraitPanelRect_.height_, originalPortraitHeight + GRADIENT_HEIGHT);
EXPECT_EQ(param.LandscapePanelRect_.height_, originalLandscapeHeight + GRADIENT_HEIGHT);
EXPECT_EQ(param.PortraitPanelRect_.posY_, 0);
EXPECT_EQ(param.LandscapePanelRect_.posY_, 0);
EXPECT_EQ(panel->changeY_.portrait, GRADIENT_HEIGHT);
EXPECT_EQ(panel->changeY_.landscape, GRADIENT_HEIGHT);
}
* @tc.name: SetNoneWhenHeightZero
* @tc.desc: Tests behavior when gradientHeight is already 0
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, SetNoneWhenHeightZero, TestSize.Level0)
{
auto panel = std::make_shared<InputMethodPanel>();
panel->immersiveEffect_.gradientHeight = 0;
panel->immersiveEffect_.gradientMode = GradientMode::LINEAR_GRADIENT;
panel->immersiveEffect_.fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT;
panel->SetImmersiveEffectToNone();
EXPECT_EQ(panel->immersiveEffect_.gradientMode, GradientMode::NONE);
EXPECT_EQ(panel->immersiveEffect_.fluidLightMode, FluidLightMode::NONE);
EXPECT_EQ(panel->immersiveEffect_.gradientHeight, 0);
}
* @tc.name: SetImmersiveEffectToNone
* @tc.desc: Tests return when Password Keyboard
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, PasswordKeyboardSetImmersive, TestSize.Level0)
{
auto panel = std::make_shared<InputMethodPanel>();
panel->immersiveEffect_.gradientHeight = 100;
panel->immersiveEffect_.gradientMode = GradientMode::LINEAR_GRADIENT;
panel->immersiveEffect_.fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT;
ima_.inputType_ = InputType::SECURITY_INPUT;
panel->SetImmersiveEffectToNone();
EXPECT_EQ(panel->immersiveEffect_.gradientMode, GradientMode::LINEAR_GRADIENT);
EXPECT_EQ(panel->immersiveEffect_.fluidLightMode, FluidLightMode::BACKGROUND_FLUID_LIGHT);
EXPECT_EQ(panel->immersiveEffect_.gradientHeight, 100);
ima_.inputType_ = InputType::NONE;
}
* @tc.name: ReturnWhenLayoutNotInitialized
* @tc.desc: Tests return when keyboard layout is uninitialized
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, ReturnWhenLayoutNotInitialized, TestSize.Level0)
{
auto panel = std::make_shared<InputMethodPanel>();
panel->immersiveEffect_.gradientHeight = GRADIENT_HEIGHT;
Rosen::KeyboardLayoutParams emptyParams;
panel->keyboardLayoutParams_ = emptyParams;
panel->SetImmersiveEffectToNone();
EXPECT_EQ(panel->immersiveEffect_.gradientHeight, GRADIENT_HEIGHT);
}
* @tc.name: RestoreConfigWhenAdjustFails
* @tc.desc: Tests configuration restoration when layout adjustment fails
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, RestoreConfigWhenAdjustFails, TestSize.Level1)
{
auto panel = std::make_shared<InputMethodPanel>();
panel->immersiveEffect_.gradientHeight = GRADIENT_HEIGHT;
panel->immersiveEffect_.gradientMode = GradientMode::LINEAR_GRADIENT;
Rosen::KeyboardLayoutParams validParams;
validParams.landscapeAvoidHeight_ = LANDSCAPE_AVOID_HEIGHT;
panel->keyboardLayoutParams_ = validParams;
panel->SetImmersiveEffectToNone();
EXPECT_EQ(panel->immersiveEffect_.gradientHeight, GRADIENT_HEIGHT);
EXPECT_EQ(panel->immersiveEffect_.gradientMode, GradientMode::LINEAR_GRADIENT);
}
* @tc.name: TestInitAdjustInfo
* @tc.desc: Test InitAdjustInfo
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, TestInitAdjustInfo, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::TestInitAdjustInfo.");
auto panel = std::make_shared<InputMethodPanel>();
InputMethodAbility::GetInstance().inputAttribute_.callingDisplayId = 0;
panel->isAdjustInfoInitialized_ = false;
panel->adjustInfoDisplayId_ = 0;
panel->panelAdjust_.clear();
auto ret = panel->InitAdjustInfo();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
panel->isAdjustInfoInitialized_ = true;
panel->adjustInfoDisplayId_ = 1000;
panel->panelAdjust_.clear();
ret = panel->InitAdjustInfo();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
panel->isAdjustInfoInitialized_ = true;
panel->adjustInfoDisplayId_ = 0;
panel->panelAdjust_.clear();
ret = panel->InitAdjustInfo();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: testGetSystemPanelInsets1
* @tc.desc: Test GetSystemPanelInsets.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets1, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets1 start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = PanelType::SOFT_KEYBOARD;
panelInfo.panelFlag = PanelFlag::FLG_FIXED;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
uint64_t displayId = 0;
ret = inputMethodPanel->GetDisplayId(displayId);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
SystemPanelInsets panelInsets = {0, 0, 0};
ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testGetSystemPanelInsets2
* @tc.desc: Test GetSystemPanelInsets.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets2, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets2 start.");
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = PanelType::SOFT_KEYBOARD;
panelInfo.panelFlag = PanelFlag::FLG_FLOATING;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
SystemPanelInsets panelInsets = {0, 0, 0};
uint64_t displayId = 0;
inputMethodPanel->GetDisplayId(displayId);
ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testGetSystemPanelInsets3
* @tc.desc: Test GetSystemPanelInsets.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets3, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets3 start.");
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = PanelType::STATUS_BAR;
panelInfo.panelFlag = PanelFlag::FLG_CANDIDATE_COLUMN;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
SystemPanelInsets panelInsets = {0, 0, 0};
uint64_t displayId = 0;
inputMethodPanel->GetDisplayId(displayId);
ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets);
EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_PANEL_TYPE);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testGetSystemPanelInsets4
* @tc.desc: Test GetSystemPanelInsets.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets4, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets4 start.");
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = PanelType::SOFT_KEYBOARD;
panelInfo.panelFlag = PanelFlag::FLG_CANDIDATE_COLUMN;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
SystemPanelInsets panelInsets = {0, 0, 0};
uint64_t displayId = 0;
inputMethodPanel->GetDisplayId(displayId);
ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets);
EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_PANEL_FLAG);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testGetSystemPanelInsets5
* @tc.desc: Test GetSystemPanelInsets.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets5, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets5 start.");
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = PanelType::SOFT_KEYBOARD;;
panelInfo.panelFlag = PanelFlag::FLG_FIXED;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
SystemPanelInsets panelInsets = {0, 0, 0};
uint64_t displayId = 10;
ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets);
EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_DISPLAYID);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testGetSystemPanelInsets6
* @tc.desc: Test GetSystemPanelInsets.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets6, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets6 start.");
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = PanelType::SOFT_KEYBOARD;;
panelInfo.panelFlag = PanelFlag::FLG_FIXED;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
SystemPanelInsets panelInsets = {0, 0, 0};
uint64_t displayId = 0;
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
inputMethodPanel->window_ = nullptr;
ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets);
EXPECT_EQ(ret, ErrorCode::ERROR_WINDOW_MANAGER);
}
* @tc.name: testGetSystemPanelInsets7
* @tc.desc: Test GetSystemPanelInsets.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets7, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets7 start.");
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = PanelType::SOFT_KEYBOARD;;
panelInfo.panelFlag = PanelFlag::FLG_FIXED;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
SystemPanelInsets panelInsets = {0, 0, 0};
uint64_t displayId = 0;
ima_.inputType_ = InputType::SECURITY_INPUT;
ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(0, panelInsets.left);
EXPECT_EQ(0, panelInsets.right);
EXPECT_EQ(0, panelInsets.bottom);
}
* @tc.name: testGetSystemPanelInsets8
* @tc.desc: Test GetSystemPanelInsets.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets8, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets8 start.");
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
std::vector<std::string> vec1 = { "123", "234"};
std::vector<std::string> vec2 = { "123" };
bool ret = inputMethodPanel->IsVectorsEqual(vec1, vec2);
EXPECT_EQ(ret, false);
vec2 = { "123", "345" };
ret = inputMethodPanel->IsVectorsEqual(vec1, vec2);
EXPECT_EQ(ret, false);
}
* @tc.name: testGetSystemPanelInsets9
* @tc.desc: Test GetSystemPanelInsets.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets9, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets9 start.");
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
std::vector<std::string> vec1 = {};
std::vector<std::string> vec2 = {};
bool ret = inputMethodPanel->IsVectorsEqual(vec1, vec2);
EXPECT_EQ(ret, true);
vec1 = { "123", "234"};
ret = inputMethodPanel->IsVectorsEqual(vec1, vec2);
EXPECT_EQ(ret, false);
vec2 = { "123", "234"};
ret = inputMethodPanel->IsVectorsEqual(vec1, vec2);
EXPECT_EQ(ret, true);
}
* @tc.name: testGetSystemPanelInsets10
* @tc.desc: Test GetSystemPanelInsets.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets10, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets10 start.");
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = PanelType::SOFT_KEYBOARD;;
panelInfo.panelFlag = PanelFlag::FLG_FIXED;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ima_.inputType_ = InputType::SECURITY_INPUT;
std::vector<int32_t> inputTypes{static_cast<int32_t>(InputType::SECURITY_INPUT)};
inputMethodPanel->SetIgnoreAdjustInputTypes(inputTypes);
bool isNeedConfig = inputMethodPanel->IsNeedConfig(true);
EXPECT_EQ(isNeedConfig, false);
isNeedConfig = inputMethodPanel->IsNeedConfig(false);
EXPECT_EQ(isNeedConfig, false);
ima_.inputType_ = InputType::NONE;
isNeedConfig = inputMethodPanel->IsNeedConfig(false);
EXPECT_EQ(isNeedConfig, true);
isNeedConfig = inputMethodPanel->IsNeedConfig(true);
EXPECT_EQ(isNeedConfig, true);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testGetSystemPanelInsets11
* @tc.desc: Test GetSystemPanelInsets.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets11, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets11 start.");
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = PanelType::SOFT_KEYBOARD;;
panelInfo.panelFlag = PanelFlag::FLG_FIXED;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
SystemPanelInsets panelInsets = {0, 0, 0};
inputMethodPanel->panelFlag_ = PanelFlag::FLG_FIXED;
auto display = Rosen::DisplayManager::GetInstance().GetPrimaryDisplaySync();
ret = inputMethodPanel->AreaInsets(panelInsets, display);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
inputMethodPanel->panelFlag_ = PanelFlag::FLG_FLOATING;
ret = inputMethodPanel->AreaInsets(panelInsets, display);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
display = Rosen::DisplayManager::GetInstance().GetDisplayById(1000);
ret = inputMethodPanel->AreaInsets(panelInsets, display);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
* @tc.name: testSetShadow_001
* @tc.desc: Test SetShadow.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetShadow_001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testSetShadow_001 start.");
IdentityCheckerMock::SetSystemApp(false);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
IdentityCheckerMock::SetSystemApp(false);
ima_.isSystemApp_ = false;
Shadow shadow = { 0.0, "#000000", 0.0, 0.0};
ret = inputMethodPanel->SetShadow(shadow);
EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testSetShadow_002
* @tc.desc: Test SetShadow.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetShadow_002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testSetShadow_002 start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ima_.isSystemApp_ = true;
Shadow shadow = { 0.0, "#000000", 0.0, 0.0};
ret = inputMethodPanel->SetShadow(shadow);
EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_PANEL_FLAG);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testSetShadow_003
* @tc.desc: Test SetShadow.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetShadow_003, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testSetShadow_003 start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
inputMethodPanel->panelType_ = SOFT_KEYBOARD;
inputMethodPanel->panelFlag_ = FLG_FLOATING;
Shadow shadow = { 0.0, "#000000", 0.0, 0.0};
auto ret = inputMethodPanel->SetShadow(shadow);
EXPECT_EQ(ret, ErrorCode::ERROR_WINDOW_MANAGER);
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FLOATING;
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ima_.isSystemApp_ = true;
shadow = { 0.0, "#000000", 0.0, 0.0};
ret = inputMethodPanel->SetShadow(shadow);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
shadow = { 20.0, "#000000", 0.0, 0.0};
ret = inputMethodPanel->SetShadow(shadow);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testSetShadow_004
* @tc.desc: Test SetShadow.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetShadow_004, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testSetShadow_004 start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = STATUS_BAR;
panelInfo.panelFlag = FLG_FLOATING;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ima_.isSystemApp_ = true;
Shadow shadow = { 0.0, "#000000", 0.0, 0.0};
ret = inputMethodPanel->SetShadow(shadow);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testSetShadow_005
* @tc.desc: Test SetShadow.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetShadow_005, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testSetShadow_005 start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = STATUS_BAR;
panelInfo.panelFlag = FLG_FLOATING;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ima_.isSystemApp_ = true;
Shadow shadow = { -10, "", 0.0, 0.0};
ret = inputMethodPanel->SetShadow(shadow);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
shadow = { 10.0, "", 0.0, 0.0};
ret = inputMethodPanel->SetShadow(shadow);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
shadow = { 10.0, "#000000000", 0.0, 0.0};
ret = inputMethodPanel->SetShadow(shadow);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
shadow = { 10.0, "#ssssss", 0.0, 0.0};
ret = inputMethodPanel->SetShadow(shadow);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
shadow = { 10.0, "#000000", 0.0, 0.0};
ret = inputMethodPanel->SetShadow(shadow);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
shadow = { 10.0, "#00000000", 10.0, 10.0};
ret = inputMethodPanel->SetShadow(shadow);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testNotifyPanelStatus
* @tc.desc: Test Show panel.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testNotifyPanelStatus, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testNotifyPanelStatus start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
inputMethodPanel->keyboardLayoutParams_.PortraitKeyboardRect_.height_ = 100;
inputMethodPanel->keyboardLayoutParams_.PortraitPanelRect_.height_ = 100;
InputMethodPanelTest::ima_.ClearInputAttribute();
InputMethodPanelTest::ima_.ClearAttachOptions();
InputMethodPanelTest::ima_.ClearSystemCmdChannel();
auto ret = InputMethodPanelTest::ima_.NotifyPanelStatus(false);
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
}
* @tc.name: testShowPanelWithAdjust01
* @tc.desc: Test Show panel.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testShowPanelWithAdjust01, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testShowPanelWithAdjust01 start.");
auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(inputMethodPanel, nullptr);
InputMethodAbility::GetInstance().inputAttribute_.callingDisplayId = 0;
InputMethodAbility::GetInstance().inputType_ = InputType::NONE;
inputMethodPanel->isInEnhancedAdjust_.store(false);
inputMethodPanel->isWaitSetUiContent_ = false;
inputMethodPanel->keyboardLayoutParams_.PortraitKeyboardRect_.height_ = 100;
inputMethodPanel->keyboardLayoutParams_.PortraitPanelRect_.height_ = 100;
InputMethodPanelTest::TestShowPanel(inputMethodPanel);
InputMethodAbility::GetInstance().ClearInputAttribute();
InputMethodAbility::GetInstance().ClearInputType();
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testShowPanelWithAdjust02
* @tc.desc: Test Show panel.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testShowPanelWithAdjust02, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testShowPanelWithAdjust02 start.");
auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(inputMethodPanel, nullptr);
InputMethodAbility::GetInstance().inputAttribute_.callingDisplayId = 0;
inputMethodPanel->isWaitSetUiContent_ = false;
InputMethodPanelTest::TestShowPanel(inputMethodPanel);
InputMethodAbility::GetInstance().ClearInputAttribute();
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testShowPanelWithAdjust03
* @tc.desc: Test Show panel.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testShowPanelWithAdjust03, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testShowPanelWithAdjust03 start.");
auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(inputMethodPanel, nullptr);
InputMethodAbility::GetInstance().inputAttribute_.callingDisplayId = 0;
inputMethodPanel->isInEnhancedAdjust_.store(true);
inputMethodPanel->isWaitSetUiContent_ = false;
InputMethodPanelTest::TestShowPanel(inputMethodPanel);
InputMethodAbility::GetInstance().ClearInputAttribute();
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testShowPanelWithAdjust04
* @tc.desc: Test Show panel.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testShowPanelWithAdjust04, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testShowPanelWithAdjust04 start.");
auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(inputMethodPanel, nullptr);
InputMethodAbility::GetInstance().inputAttribute_.callingDisplayId = 0;
inputMethodPanel->isInEnhancedAdjust_.store(false);
inputMethodPanel->isWaitSetUiContent_ = false;
inputMethodPanel->keyboardLayoutParams_.PortraitKeyboardRect_.height_ = 100;
inputMethodPanel->keyboardLayoutParams_.PortraitPanelRect_.height_ = 101;
InputMethodPanelTest::TestShowPanel(inputMethodPanel);
InputMethodAbility::GetInstance().ClearInputAttribute();
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testShowPanelWithAdjust05
* @tc.desc: Test Show panel.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testShowPanelWithAdjust05, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testShowPanelWithAdjust05 start.");
auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(inputMethodPanel, nullptr);
InputMethodAbility::GetInstance().inputAttribute_.callingDisplayId = 0;
InputMethodAbility::GetInstance().inputType_ = InputType::VOICE_INPUT;
inputMethodPanel->isInEnhancedAdjust_.store(false);
inputMethodPanel->isWaitSetUiContent_ = false;
inputMethodPanel->keyboardLayoutParams_.PortraitKeyboardRect_.height_ = 100;
inputMethodPanel->keyboardLayoutParams_.PortraitPanelRect_.height_ = 100;
inputMethodPanel->isIgnorePanelAdjustInitialized_.store(true);
inputMethodPanel->ignoreAdjustInputTypes_.push_back(static_cast<int32_t>(InputType::VOICE_INPUT));
InputMethodPanelTest::TestShowPanel(inputMethodPanel);
InputMethodAbility::GetInstance().ClearInputAttribute();
InputMethodAbility::GetInstance().ClearInputType();
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testGetInputWindowAvoidArea_01
* @tc.desc: Test GetInputWindowAvoidArea with different isInEnhancedAdjust_ and panelFlag.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetInputWindowAvoidArea_01, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest testGetInputWindowAvoidArea_01 Test START");
std::shared_ptr<InputMethodPanel> inputMethodPanel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(inputMethodPanel, nullptr);
inputMethodPanel->isInEnhancedAdjust_.store(false);
Rosen::Rect rect{};
auto ret = inputMethodPanel->GetInputWindowAvoidArea(PanelFlag::FLG_FIXED, rect);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
inputMethodPanel->isInEnhancedAdjust_.store(true);
ret = inputMethodPanel->GetInputWindowAvoidArea(PanelFlag::FLG_FLOATING, rect);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodAbility::GetInstance().ClearInputAttribute();
inputMethodPanel->isInEnhancedAdjust_.store(true);
ret = inputMethodPanel->GetInputWindowAvoidArea(PanelFlag::FLG_FIXED, rect);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputAttribute attribute = { .callingDisplayId = INVALID_DISPLAY_ID };
InputMethodAbility::GetInstance().SetInputAttribute(attribute);
inputMethodPanel->isInEnhancedAdjust_.store(true);
ret = inputMethodPanel->GetInputWindowAvoidArea(PanelFlag::FLG_FIXED, rect);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodAbility::GetInstance().ClearInputAttribute();
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: testGetInputWindowAvoidArea_02
* @tc.desc: Test GetInputWindowAvoidArea in different orientation.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testGetInputWindowAvoidArea_02, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest testGetInputWindowAvoidArea_02 Test START");
std::shared_ptr<InputMethodPanel> inputMethodPanel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(inputMethodPanel, nullptr);
inputMethodPanel->isInEnhancedAdjust_.store(true);
DisplaySize displaySize;
EXPECT_EQ(InputMethodPanelTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
Rosen::Rect rect = { .width_ = displaySize.portrait.width };
auto ret = inputMethodPanel->GetInputWindowAvoidArea(PanelFlag::FLG_FIXED, rect);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
rect = { .width_ = displaySize.landscape.width };
ret = inputMethodPanel->GetInputWindowAvoidArea(PanelFlag::FLG_FIXED, rect);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: SetSystemPanelButtonColor1
* @tc.desc: Test SetSystemPanelButtonColor.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetSystemPanelButtonColor1, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::SetSystemPanelButtonColor1 start.");
auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(inputMethodPanel, nullptr);
std::string fillColor = "#FFFFFF";
std::string backgroundColor = "";
ima_.isSysPanelSupport_ = 1;
auto ret = inputMethodPanel->SetSystemPanelButtonColor(fillColor, backgroundColor);
if (isScbEnable_) {
EXPECT_EQ(ret, ErrorCode::ERROR_SYSTEM_CMD_CHANNEL_ERROR);
} else {
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
fillColor = "";
backgroundColor = "#FFFFFF";
ret = inputMethodPanel->SetSystemPanelButtonColor(fillColor, backgroundColor);
if (isScbEnable_) {
EXPECT_EQ(ret, ErrorCode::ERROR_SYSTEM_CMD_CHANNEL_ERROR);
} else {
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: SetSystemPanelButtonColor2
* @tc.desc: Test SetSystemPanelButtonColor.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetSystemPanelButtonColor2, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::SetSystemPanelButtonColor2 start.");
auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(inputMethodPanel, nullptr);
std::string fillColor = "#FFFFFF";
std::string backgroundColor = "#FF0000";
ima_.isSysPanelSupport_ = 1;
auto ret = inputMethodPanel->SetSystemPanelButtonColor(fillColor, backgroundColor);
if (isScbEnable_) {
EXPECT_EQ(ret, ErrorCode::ERROR_SYSTEM_CMD_CHANNEL_ERROR);
} else {
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
inputMethodPanel->isScbEnable_ = false;
ret = inputMethodPanel->SetSystemPanelButtonColor(fillColor, backgroundColor);
inputMethodPanel->isScbEnable_ = Rosen::SceneBoardJudgement::IsSceneBoardEnabled();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: SetSystemPanelButtonColor3
* @tc.desc: Test SetSystemPanelButtonColor.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testSetSystemPanelButtonColor3, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::SetSystemPanelButtonColor2 start.");
auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(inputMethodPanel, nullptr);
std::string fillColor = "#00FFFFFF";
std::string backgroundColor = "#FF000000";
auto ret = inputMethodPanel->SetSystemPanelButtonColor(fillColor, backgroundColor);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
fillColor = "#FF000000";
backgroundColor = "#00FFFFFF";
ret = inputMethodPanel->SetSystemPanelButtonColor(fillColor, backgroundColor);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
fillColor = "#00FF0000";
ret = inputMethodPanel->SetSystemPanelButtonColor(fillColor, backgroundColor);
EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: IsColorFullyTransparent1
* @tc.desc: Test IsColorFullyTransparent.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testIsColorFullyTransparent1, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::IsColorFullyTransparent1 start.");
uint32_t colorValue = 0x00000000;
auto ret = ColorParser::IsColorFullyTransparent(colorValue);
EXPECT_EQ(ret, true);
}
* @tc.name: Parse1
* @tc.desc: Test Parse.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testParse1, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testParse1 start.");
std::string colorStr = "FFFFFF";
uint32_t colorValue = 0;
auto ret = ColorParser::Parse(colorStr, colorValue);
EXPECT_EQ(ret, false);
colorStr = "#@";
ret = ColorParser::Parse(colorStr, colorValue);
EXPECT_EQ(ret, false);
}
* @tc.name: Parse2
* @tc.desc: Test Parse.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testParse2, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testParse2 start.");
std::string colorStr = "#FFFFFF";
uint32_t colorValue = 0;
auto ret = ColorParser::Parse(colorStr, colorValue);
EXPECT_EQ(ret, true);
colorStr = "#FFFFFF00";
ret = ColorParser::Parse(colorStr, colorValue);
EXPECT_EQ(ret, true);
colorStr = "#FFFFFF0000";
ret = ColorParser::Parse(colorStr, colorValue);
EXPECT_EQ(ret, false);
}
* @tc.name: IsValidHexString1
* @tc.desc: Test IsValidHexString.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testIsValidHexString1, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testIsValidHexString1 start.");
std::string colorStr = "";
auto ret = ColorParser::IsValidHexString(colorStr);
EXPECT_EQ(ret, false);
}
* @tc.name: ConvertToWMSHotArea
* @tc.desc: Test ConvertToWMSHotArea.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testConvertToWMSHotArea, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testConvertToWMSHotArea start.");
auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(inputMethodPanel, nullptr);
HotAreas hotAreas;
hotAreas.screenId = 100;
hotAreas.landscape.keyboardHotArea.push_back({10, 10, 100, 50});
hotAreas.landscape.panelHotArea.push_back({40, 40, 400, 200});
hotAreas.portrait.keyboardHotArea.push_back({20, 20, 200, 100});
hotAreas.portrait.panelHotArea.push_back({30, 30, 300, 150});
auto result = inputMethodPanel->ConvertToWMSHotArea(hotAreas);
EXPECT_EQ(result.displayId_, hotAreas.screenId);
EXPECT_EQ(result.landscapeKeyboardHotAreas_.size(), hotAreas.landscape.keyboardHotArea.size());
EXPECT_EQ(result.landscapePanelHotAreas_.size(), hotAreas.landscape.panelHotArea.size());
EXPECT_EQ(result.portraitKeyboardHotAreas_.size(), hotAreas.portrait.keyboardHotArea.size());
EXPECT_EQ(result.portraitPanelHotAreas_.size(), hotAreas.portrait.panelHotArea.size());
ASSERT_EQ(result.landscapeKeyboardHotAreas_.size(), 1);
ASSERT_EQ(result.landscapePanelHotAreas_.size(), 1);
ASSERT_EQ(result.portraitKeyboardHotAreas_.size(), 1);
ASSERT_EQ(result.portraitPanelHotAreas_.size(), 1);
EXPECT_EQ(result.landscapeKeyboardHotAreas_[0], hotAreas.landscape.keyboardHotArea[0]);
EXPECT_EQ(result.landscapePanelHotAreas_[0], hotAreas.landscape.panelHotArea[0]);
EXPECT_EQ(result.portraitKeyboardHotAreas_[0], hotAreas.portrait.keyboardHotArea[0]);
EXPECT_EQ(result.portraitPanelHotAreas_[0], hotAreas.portrait.panelHotArea[0]);
InputMethodPanelTest::DestroyPanel(inputMethodPanel);
}
* @tc.name: TestKeyboardPanelInfoChangeListener001
* @tc.desc: Test keyboard panel status changes when panel invisible.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, TestKeyboardPanelInfoChangeListener001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::TestKeyboardPanelInfoChangeListener001 start.");
IdentityCheckerMock::SetSystemApp(true);
IdentityCheckerMock::SetBundleNameValid(true);
auto listener = std::make_shared<InputMethodSettingListenerImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
auto panel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(panel, nullptr);
panel->UnregisterVisibilityChangeListener();
Rosen::KeyboardPanelInfo info;
panel->isVisible_.store(false);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestShowPanel(panel);
info.isShowing_ = true;
InputMethodPanelTest::TriggerKeyboardPanelInfoChange(panel, info);
InputMethodPanelTest::ImcPanelShowNumCheck(0);
panel->isVisible_.store(false);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestHidePanel(panel);
info.isShowing_ = false;
InputMethodPanelTest::TriggerKeyboardPanelInfoChange(panel, info);
InputMethodPanelTest::ImcPanelHideNumCheck(1);
InputMethodPanelTest::DestroyPanel(panel);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
IdentityCheckerMock::SetSystemApp(false);
IdentityCheckerMock::SetBundleNameValid(false);
}
* @tc.name: TestKeyboardPanelInfoChangeListener002
* @tc.desc: Test keyboard panel status changes when panel visible.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, TestKeyboardPanelInfoChangeListener002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::TestKeyboardPanelInfoChangeListener002 start.");
IdentityCheckerMock::SetSystemApp(true);
IdentityCheckerMock::SetBundleNameValid(true);
auto listener = std::make_shared<InputMethodSettingListenerImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
auto panel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(panel, nullptr);
panel->UnregisterVisibilityChangeListener();
Rosen::KeyboardPanelInfo info;
panel->isVisible_.store(true);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestShowPanel(panel);
info.isShowing_ = true;
InputMethodPanelTest::TriggerKeyboardPanelInfoChange(panel, info);
InputMethodPanelTest::ImcPanelShowNumCheck(1);
panel->isVisible_.store(true);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestHidePanel(panel);
info.isShowing_ = false;
InputMethodPanelTest::TriggerKeyboardPanelInfoChange(panel, info);
InputMethodPanelTest::ImcPanelHideNumCheck(1);
InputMethodPanelTest::DestroyPanel(panel);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
IdentityCheckerMock::SetSystemApp(false);
IdentityCheckerMock::SetBundleNameValid(false);
}
* @tc.name: TestShowKeyboardToWms_ModeChanged
* @tc.desc: Test ShowKeyboardToWms when immersive mode changes between ShowPanel calls.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, testShowKeyboardToWms_ModeChanged, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testShowKeyboardToWms_ModeChanged start.");
AccessScope scope(currentImeTokenId_, currentImeUid_);
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::LIGHT_IMMERSIVE);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::DARK_IMMERSIVE);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->ShowPanel(Trigger::IME_APP);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->HidePanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodPanel->DestroyPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
* @tc.name: TestVisibilityChangeListener001
* @tc.desc: Test visibility change listener when window_ nullptr.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, TestVisibilityChangeListener001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::TestVisibilityChangeListener001 start.");
auto inputMethodPanel = std::make_shared<InputMethodPanel>();
int32_t ret = inputMethodPanel->RegisterVisibilityChangeListener();
EXPECT_EQ(ret, ErrorCode::ERROR_OPERATE_PANEL);
ret = inputMethodPanel->UnregisterVisibilityChangeListener();
EXPECT_EQ(ret, ErrorCode::ERROR_OPERATE_PANEL);
}
* @tc.name: TestVisibilityChangeListener002
* @tc.desc: Test visibility change listener when window_ nullptr.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, TestVisibilityChangeListener002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::TestVisibilityChangeListener002 start.");
IdentityCheckerMock::SetSystemApp(true);
IdentityCheckerMock::SetBundleNameValid(true);
auto listener = std::make_shared<InputMethodSettingListenerImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
auto panel = InputMethodPanelTest::CreatePanel();
ASSERT_NE(panel, nullptr);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestShowPanel(panel);
InputMethodPanelTest::TriggerVisibilityChange(panel,
WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
InputMethodPanelTest::ImcPanelShowNumCheck(1);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestHidePanel(panel);
InputMethodPanelTest::TriggerVisibilityChange(panel,
WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION);
InputMethodPanelTest::ImcPanelHideNumCheck(1);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestShowPanel(panel);
InputMethodPanelTest::TriggerVisibilityChange(panel,
WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
InputMethodPanelTest::ImcPanelShowNumCheck(1);
InputMethodPanelTest::ImcPanelListeningTestRestore();
InputMethodPanelTest::TestHidePanel(panel);
InputMethodPanelTest::TriggerVisibilityChange(panel,
WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION);
InputMethodPanelTest::ImcPanelHideNumCheck(1);
InputMethodPanelTest::DestroyPanel(panel);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
IdentityCheckerMock::SetSystemApp(false);
IdentityCheckerMock::SetBundleNameValid(false);
}
* @tc.name: TestOnVisibilityChange_TotallyOcclusion
* @tc.desc: Test visibility change with WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, TestOnVisibilityChange_TotallyOcclusion, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::TestOnVisibilityChange_TotallyOcclusion start.");
if (!isScbEnable_) {
return;
}
auto panel = std::make_shared<InputMethodPanel>();
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
InputMethodPanelTest::ImaCreatePanel(panelInfo, panel);
ASSERT_NE(panel, nullptr);
TriggerVisibilityChange(panel, WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION);
EXPECT_FALSE(panel->isVisible_.load());
InputMethodPanelTest::ImaDestroyPanel(panel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: TestOnVisibilityChange_NoOcclusion
* @tc.desc: Test visibility change with WINDOW_VISIBILITY_STATE_NO_OCCLUSION.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, TestOnVisibilityChange_NoOcclusion, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testOnVisibilityChange_NoOcclusion start.");
if (!isScbEnable_) {
return;
}
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
auto panel = std::make_shared<InputMethodPanel>();
InputMethodPanelTest::ImaCreatePanel(panelInfo, panel);
ASSERT_NE(panel, nullptr);
TriggerVisibilityChange(panel, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
EXPECT_TRUE(panel->isVisible_.load());
InputMethodPanelTest::ImaDestroyPanel(panel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: TestOnVisibilityChange_PartiallyOcclusion
* @tc.desc: Test visibility change with WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, TestOnVisibilityChange_PartiallyOcclusion, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::TestOnVisibilityChange_PartiallyOcclusion start.");
if (!isScbEnable_) {
return;
}
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
auto panel = std::make_shared<InputMethodPanel>();
InputMethodPanelTest::ImaCreatePanel(panelInfo, panel);
ASSERT_NE(panel, nullptr);
TriggerVisibilityChange(panel, WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION);
EXPECT_TRUE(panel->isVisible_.load());
InputMethodPanelTest::ImaDestroyPanel(panel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
* @tc.name: TestOnVisibilityChange_InvalidState
* @tc.desc: Test visibility change with invalid state (early return).
* @tc.type: FUNC
*/
HWTEST_F(InputMethodPanelTest, TestOnVisibilityChange_InvalidState, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::TestOnVisibilityChange_InvalidState start.");
if (!isScbEnable_) {
return;
}
PanelInfo panelInfo;
panelInfo.panelType = SOFT_KEYBOARD;
panelInfo.panelFlag = FLG_FIXED;
auto panel = std::make_shared<InputMethodPanel>();
InputMethodPanelTest::ImaCreatePanel(panelInfo, panel);
ASSERT_NE(panel, nullptr);
bool originalVisible = panel->isVisible_.load();
TriggerVisibilityChange(panel, static_cast<WindowVisibilityState>(999));
EXPECT_EQ(panel->isVisible_.load(), originalVisible);
InputMethodPanelTest::ImaDestroyPanel(panel);
InputMethodPanelTest::imc_->Close();
TddUtil::DestroyWindow();
}
}
}