mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-23 22:59:45 +00:00
优化tdd用例修改
Signed-off-by: cy7717 <chenyu301@huawei.com>
This commit is contained in:
parent
7ab4919810
commit
e0fab340ed
@ -28,13 +28,14 @@ using namespace Rosen;
|
||||
using namespace Security::AccessToken;
|
||||
bool BundleChecker::IsFocused(int64_t callingPid, uint32_t callingTokenId, int64_t focusedPid)
|
||||
{
|
||||
if (focusedPid == INVALID_PID) {
|
||||
int64_t realFocusedPid = focusedPid;
|
||||
if (realFocusedPid == INVALID_PID) {
|
||||
FocusChangeInfo info;
|
||||
WindowManager::GetInstance().GetFocusWindowInfo(info);
|
||||
focusedPid = info.pid_;
|
||||
realFocusedPid = info.pid_;
|
||||
}
|
||||
IMSA_HILOGD("focusedPid:%{public}" PRId64 ", pid:%{public}" PRId64 "", focusedPid, callingPid);
|
||||
if (callingPid == focusedPid) {
|
||||
IMSA_HILOGD("focusedPid:%{public}" PRId64 ", pid:%{public}" PRId64 "", realFocusedPid, callingPid);
|
||||
if (callingPid == realFocusedPid) {
|
||||
IMSA_HILOGI("pid is same, focused app");
|
||||
return true;
|
||||
}
|
||||
|
@ -36,8 +36,16 @@ public:
|
||||
static bool ExecuteCmd(const std::string &cmd, std::string &result);
|
||||
static pid_t GetImsaPid();
|
||||
static void KillImsaProcess();
|
||||
static void SetFocusWindow();
|
||||
static void RestoreFocusWindow();
|
||||
class WindowManager {
|
||||
public:
|
||||
static void CreateWindow();
|
||||
static void ShowWindow();
|
||||
static void HideWindow();
|
||||
static void DestroyWindow();
|
||||
|
||||
private:
|
||||
static sptr<Rosen::Window> window_;
|
||||
};
|
||||
|
||||
private:
|
||||
static int32_t GetCurrentUserId();
|
||||
@ -46,8 +54,6 @@ private:
|
||||
static uint64_t selfTokenID_;
|
||||
static uint64_t testTokenID_;
|
||||
static int32_t userID_;
|
||||
static sptr<Rosen::Window> window_;
|
||||
static sptr<Rosen::WindowOption> winOption_;
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -45,8 +45,7 @@ constexpr int32_t BUFF_LENGTH = 10;
|
||||
constexpr const char *CMD_PIDOF_IMS = "pidof inputmethod_ser";
|
||||
uint64_t TddUtil::selfTokenID_ = 0;
|
||||
int32_t TddUtil::userID_ = INVALID_USER_ID;
|
||||
sptr<Window> TddUtil::window_ = nullptr;
|
||||
sptr<WindowOption> TddUtil::winOption_ = nullptr;
|
||||
sptr<Window> TddUtil::WindowManager::window_ = nullptr;
|
||||
int32_t TddUtil::GetCurrentUserId()
|
||||
{
|
||||
if (userID_ != INVALID_USER_ID) {
|
||||
@ -115,29 +114,6 @@ void TddUtil::RestoreSelfTokenID()
|
||||
IMSA_HILOGI("SetSelfTokenID ret = %{public}d", ret);
|
||||
}
|
||||
|
||||
void TddUtil::SetFocusWindow()
|
||||
{
|
||||
std::string windowName = "inputmethod_test_window";
|
||||
winOption_ = new OHOS::Rosen::WindowOption();
|
||||
winOption_->SetFocusable(true);
|
||||
std::shared_ptr<AbilityRuntime::Context> context = nullptr;
|
||||
WMError wmError = WMError::WM_OK;
|
||||
|
||||
window_ = Window::Create(windowName, winOption_, context, wmError);
|
||||
if (window_ != nullptr) {
|
||||
window_->Show();
|
||||
IMSA_HILOGI("Create window success");
|
||||
}
|
||||
}
|
||||
|
||||
void TddUtil::RestoreFocusWindow()
|
||||
{
|
||||
if (window_ != nullptr) {
|
||||
window_->Hide();
|
||||
window_->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
bool TddUtil::ExecuteCmd(const std::string &cmd, std::string &result)
|
||||
{
|
||||
char buff[EACH_LINE_LENGTH] = { 0x00 };
|
||||
@ -212,5 +188,37 @@ int TddUtil::GetUserIdByBundleName(const std::string &bundleName, const int curr
|
||||
// 200000 means userId = uid / 200000.
|
||||
return uid/200000;
|
||||
}
|
||||
|
||||
void TddUtil::WindowManager::CreateWindow()
|
||||
{
|
||||
std::string windowName = "inputmethod_test_window";
|
||||
sptr<WindowOption> winOption = new OHOS::Rosen::WindowOption();
|
||||
winOption->SetFocusable(true);
|
||||
std::shared_ptr<AbilityRuntime::Context> context = nullptr;
|
||||
WMError wmError = WMError::WM_OK;
|
||||
window_ = Window::Create(windowName, winOption, context, wmError);
|
||||
IMSA_HILOGI("Create window ret:%{public}d", wmError);
|
||||
}
|
||||
|
||||
void TddUtil::WindowManager::ShowWindow()
|
||||
{
|
||||
if (window_ != nullptr) {
|
||||
window_->Show();
|
||||
}
|
||||
}
|
||||
|
||||
void TddUtil::WindowManager::HideWindow()
|
||||
{
|
||||
if (window_ != nullptr) {
|
||||
window_->Hide();
|
||||
}
|
||||
}
|
||||
|
||||
void TddUtil::WindowManager::DestroyWindow()
|
||||
{
|
||||
if (window_ != nullptr) {
|
||||
window_->Destroy();
|
||||
}
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -43,6 +43,7 @@
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using WindowMgr = TddUtil::WindowManager;
|
||||
constexpr uint32_t DEALY_TIME = 1;
|
||||
class InputMethodAbilityTest : public testing::Test {
|
||||
public:
|
||||
@ -101,7 +102,8 @@ public:
|
||||
inputMethodAbility_->SetCoreAndAgent();
|
||||
TddUtil::RestoreSelfTokenID();
|
||||
|
||||
TddUtil::SetFocusWindow();
|
||||
WindowMgr::CreateWindow();
|
||||
WindowMgr::ShowWindow();
|
||||
sptr<OnTextChangedListener> textListener = new TextListener();
|
||||
imc_ = InputMethodController::GetInstance();
|
||||
imc_->Attach(textListener);
|
||||
@ -113,7 +115,8 @@ public:
|
||||
imc_->Close();
|
||||
TddUtil::KillImsaProcess();
|
||||
TextListener::ResetParam();
|
||||
TddUtil::RestoreFocusWindow();
|
||||
WindowMgr::HideWindow();
|
||||
WindowMgr::DestroyWindow();
|
||||
}
|
||||
void SetUp()
|
||||
{
|
||||
|
@ -27,6 +27,7 @@
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using WindowMgr = TddUtil::WindowManager;
|
||||
constexpr int32_t WAIT_DATA_CHANNEL = 1000;
|
||||
class InputMethodAttachTest : public testing::Test {
|
||||
public:
|
||||
@ -76,13 +77,15 @@ public:
|
||||
inputMethodAbility_->SetCoreAndAgent();
|
||||
TddUtil::RestoreSelfTokenID();
|
||||
|
||||
TddUtil::SetFocusWindow();
|
||||
WindowMgr::CreateWindow();
|
||||
WindowMgr::ShowWindow();
|
||||
inputMethodController_ = InputMethodController::GetInstance();
|
||||
}
|
||||
static void TearDownTestCase(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAttachTest::TearDownTestCase");
|
||||
TddUtil::RestoreFocusWindow();
|
||||
WindowMgr::HideWindow();
|
||||
WindowMgr::DestroyWindow();
|
||||
}
|
||||
void SetUp()
|
||||
{
|
||||
|
@ -58,6 +58,7 @@ using namespace testing;
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using WindowMgr = TddUtil::WindowManager;
|
||||
constexpr uint32_t DEALY_TIME = 1;
|
||||
constexpr uint32_t KEY_EVENT_DELAY_TIME = 100;
|
||||
|
||||
@ -255,7 +256,8 @@ constexpr uint32_t KEY_EVENT_DELAY_TIME = 100;
|
||||
keyEvent_->SetFunctionKey(MMI::KeyEvent::SCROLL_LOCK_FUNCTION_KEY, 1);
|
||||
TddUtil::SetTestTokenID(TddUtil::AllocTestTokenID(false, true, "undefine"));
|
||||
|
||||
TddUtil::SetFocusWindow();
|
||||
WindowMgr::CreateWindow();
|
||||
WindowMgr::ShowWindow();
|
||||
SetInputDeathRecipient();
|
||||
TextListener::ResetParam();
|
||||
}
|
||||
@ -264,8 +266,9 @@ constexpr uint32_t KEY_EVENT_DELAY_TIME = 100;
|
||||
{
|
||||
IMSA_HILOGI("InputMethodControllerTest::TearDownTestCase");
|
||||
TddUtil::RestoreSelfTokenID();
|
||||
TddUtil::RestoreFocusWindow();
|
||||
TextListener::ResetParam();
|
||||
WindowMgr::HideWindow();
|
||||
WindowMgr::DestroyWindow();
|
||||
}
|
||||
|
||||
void InputMethodControllerTest::SetUp(void)
|
||||
|
@ -40,6 +40,7 @@ using namespace testing::ext;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using WindowMgr = TddUtil::WindowManager;
|
||||
constexpr const char *CMD1 = "hidumper -s 3703 -a -a";
|
||||
constexpr const char *CMD2 = "hidumper -s 3703 -a -h";
|
||||
constexpr const char *CMD3 = "hidumper -s 3703 -a -test";
|
||||
@ -161,7 +162,8 @@ void InputMethodDfxTest::SetUpTestCase(void)
|
||||
|
||||
inputMethodController_ = InputMethodController::GetInstance();
|
||||
textListener_ = new TextListener();
|
||||
TddUtil::SetFocusWindow();
|
||||
WindowMgr::CreateWindow();
|
||||
WindowMgr::ShowWindow();
|
||||
}
|
||||
|
||||
void InputMethodDfxTest::TearDownTestCase(void)
|
||||
@ -169,7 +171,8 @@ void InputMethodDfxTest::TearDownTestCase(void)
|
||||
IMSA_HILOGI("InputMethodDfxTest::TearDownTestCase");
|
||||
TddUtil::RestoreSelfTokenID();
|
||||
TddUtil::KillImsaProcess();
|
||||
TddUtil::RestoreFocusWindow();
|
||||
WindowMgr::HideWindow();
|
||||
WindowMgr::DestroyWindow();
|
||||
}
|
||||
|
||||
void InputMethodDfxTest::SetUp(void)
|
||||
|
@ -43,6 +43,7 @@
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using WindowMgr = TddUtil::WindowManager;
|
||||
class KeyboardListenerImpl : public KeyboardListener {
|
||||
public:
|
||||
KeyboardListenerImpl(){};
|
||||
@ -168,6 +169,7 @@ void InputMethodEditorTest::SetUpTestCase(void)
|
||||
keyEvent_->SetKeyAction(keyAction);
|
||||
keyEvent_->SetKeyCode(keyCode);
|
||||
TextListener::ResetParam();
|
||||
WindowMgr::CreateWindow();
|
||||
}
|
||||
|
||||
void InputMethodEditorTest::TearDownTestCase(void)
|
||||
@ -176,6 +178,7 @@ void InputMethodEditorTest::TearDownTestCase(void)
|
||||
TddUtil::RestoreSelfTokenID();
|
||||
TddUtil::KillImsaProcess();
|
||||
TextListener::ResetParam();
|
||||
WindowMgr::DestroyWindow();
|
||||
}
|
||||
|
||||
void InputMethodEditorTest::SetUp(void)
|
||||
@ -238,7 +241,7 @@ HWTEST_F(InputMethodEditorTest, testShowTextInputUnfocused, TestSize.Level0)
|
||||
HWTEST_F(InputMethodEditorTest, testAttachFocused, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodEditorTest Attach Focused Test START");
|
||||
TddUtil::SetFocusWindow();
|
||||
WindowMgr::ShowWindow();
|
||||
InputMethodEditorTest::imeListener_->isInputStart_ = false;
|
||||
InputMethodEditorTest::imeListener_->keyboardState_ = false;
|
||||
int32_t ret = InputMethodEditorTest::inputMethodController_->Attach(InputMethodEditorTest::textListener_, false);
|
||||
@ -257,7 +260,7 @@ HWTEST_F(InputMethodEditorTest, testAttachFocused, TestSize.Level0)
|
||||
EXPECT_TRUE(TextListener::WaitIMACallback());
|
||||
EXPECT_TRUE(imeListener_->isInputStart_ && imeListener_->keyboardState_);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
TddUtil::RestoreFocusWindow();
|
||||
WindowMgr::HideWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -270,7 +273,7 @@ HWTEST_F(InputMethodEditorTest, testShowSoftKeyboard, TestSize.Level0)
|
||||
IMSA_HILOGI("InputMethodEditorTest ShowSoftKeyboard Test START");
|
||||
InputMethodEditorTest::inputMethodController_->Close();
|
||||
TddUtil::SetTestTokenID(TddUtil::AllocTestTokenID(true, true, "undefined"));
|
||||
TddUtil::SetFocusWindow();
|
||||
WindowMgr::ShowWindow();
|
||||
InputMethodEditorTest::imeListener_->keyboardState_ = false;
|
||||
TextListener::keyboardStatus_ = KeyboardStatus::NONE;
|
||||
int32_t ret = InputMethodEditorTest::inputMethodController_->Attach(InputMethodEditorTest::textListener_, false);
|
||||
@ -279,7 +282,7 @@ HWTEST_F(InputMethodEditorTest, testShowSoftKeyboard, TestSize.Level0)
|
||||
EXPECT_TRUE(TextListener::WaitIMACallback());
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
EXPECT_TRUE(imeListener_->keyboardState_ && TextListener::keyboardStatus_ == KeyboardStatus::SHOW);
|
||||
TddUtil::RestoreFocusWindow();
|
||||
WindowMgr::HideWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -291,7 +294,7 @@ HWTEST_F(InputMethodEditorTest, testIMCHideTextInput, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodEditorTest HideTextInputAndShowTextInput Test START");
|
||||
InputMethodEditorTest::inputMethodController_->Close();
|
||||
TddUtil::SetFocusWindow();
|
||||
WindowMgr::ShowWindow();
|
||||
int32_t ret = InputMethodEditorTest::inputMethodController_->Attach(InputMethodEditorTest::textListener_, true);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
|
||||
@ -310,7 +313,7 @@ HWTEST_F(InputMethodEditorTest, testIMCHideTextInput, TestSize.Level0)
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_EDITABLE);
|
||||
ret = InputMethodEditorTest::inputMethodController_->HideCurrentInput();
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_EDITABLE);
|
||||
TddUtil::RestoreFocusWindow();
|
||||
WindowMgr::HideWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -322,7 +325,7 @@ HWTEST_F(InputMethodEditorTest, testShowTextInput, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodEditorTest ShowTextInput Test START");
|
||||
InputMethodEditorTest::inputMethodController_->Close();
|
||||
TddUtil::SetFocusWindow();
|
||||
WindowMgr::ShowWindow();
|
||||
int32_t ret = InputMethodEditorTest::inputMethodController_->Attach(InputMethodEditorTest::textListener_, true);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
InputMethodEditorTest::inputMethodController_->HideTextInput();
|
||||
@ -334,7 +337,7 @@ HWTEST_F(InputMethodEditorTest, testShowTextInput, TestSize.Level0)
|
||||
ret = ret && kbListener_->keyCode_ == keyEvent_->GetKeyCode()
|
||||
&& kbListener_->keyStatus_ == keyEvent_->GetKeyAction();
|
||||
EXPECT_TRUE(result);
|
||||
TddUtil::RestoreFocusWindow();
|
||||
WindowMgr::HideWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -345,7 +348,7 @@ HWTEST_F(InputMethodEditorTest, testShowTextInput, TestSize.Level0)
|
||||
HWTEST_F(InputMethodEditorTest, testIMCClose, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("IMC Close Test START");
|
||||
TddUtil::SetFocusWindow();
|
||||
WindowMgr::ShowWindow();
|
||||
int32_t ret = InputMethodEditorTest::inputMethodController_->Attach(InputMethodEditorTest::textListener_, true);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
InputMethodEditorTest::inputMethodController_->Close();
|
||||
@ -364,7 +367,7 @@ HWTEST_F(InputMethodEditorTest, testIMCClose, TestSize.Level0)
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_EDITABLE);
|
||||
ret = InputMethodEditorTest::inputMethodController_->HideCurrentInput();
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_EDITABLE);
|
||||
TddUtil::RestoreFocusWindow();
|
||||
WindowMgr::HideWindow();
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -34,6 +34,7 @@
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using WindowMgr = TddUtil::WindowManager;
|
||||
class PermissionVerificationExceptionTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
@ -61,12 +62,14 @@ void PermissionVerificationExceptionTest::SetUpTestCase(void)
|
||||
auto property = InputMethodController::GetInstance()->GetCurrentInputMethod();
|
||||
EXPECT_NE(property, nullptr);
|
||||
tokenId_ = TddUtil::GetTestTokenID(property->name);
|
||||
WindowMgr::CreateWindow();
|
||||
}
|
||||
|
||||
void PermissionVerificationExceptionTest::TearDownTestCase(void)
|
||||
{
|
||||
IMSA_HILOGI("PermissionVerificationExceptionTest::TearDownTestCase");
|
||||
TddUtil::KillImsaProcess();
|
||||
WindowMgr::DestroyWindow();
|
||||
}
|
||||
|
||||
void PermissionVerificationExceptionTest::SetUp(void)
|
||||
@ -92,13 +95,13 @@ HWTEST_F(PermissionVerificationExceptionTest, ShowAndHideSoftKeyboard, TestSize.
|
||||
PermissionVerificationExceptionTest::ima_->SetCoreAndAgent();
|
||||
TddUtil::RestoreSelfTokenID();
|
||||
|
||||
TddUtil::SetFocusWindow();
|
||||
WindowMgr::ShowWindow();
|
||||
PermissionVerificationExceptionTest::imc_->Attach(PermissionVerificationExceptionTest::textListener_);
|
||||
int32_t ret = PermissionVerificationExceptionTest::imc_->ShowSoftKeyboard();
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_PERMISSION_DENIED);
|
||||
ret = PermissionVerificationExceptionTest::imc_->HideSoftKeyboard();
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_PERMISSION_DENIED);
|
||||
TddUtil::RestoreFocusWindow();
|
||||
WindowMgr::HideWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user