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
c32c2a0254
commit
cb4eeaa16d
@ -261,6 +261,7 @@ ohos_unittest("InputMethodSwitchTest") {
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"input:libmmi-client",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
}
|
||||
|
||||
@ -339,5 +340,6 @@ ohos_unittest("NewImeSwitchTest") {
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"input:libmmi-client",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
}
|
||||
|
@ -19,6 +19,9 @@
|
||||
#include <string>
|
||||
|
||||
#include "bundle_mgr_interface.h"
|
||||
#include "window.h"
|
||||
#include "window_option.h"
|
||||
#include "wm_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@ -30,12 +33,11 @@ public:
|
||||
static void DeleteTestTokenID(uint64_t tokenId);
|
||||
static void SetTestTokenID(uint64_t tokenId);
|
||||
static void RestoreSelfTokenID();
|
||||
static void StorageSelfUid();
|
||||
static void SetTestUid();
|
||||
static void RestoreSelfUid();
|
||||
static bool ExecuteCmd(const std::string &cmd, std::string &result);
|
||||
static pid_t GetImsaPid();
|
||||
static void KillImsaProcess();
|
||||
static void SetFocusWindow();
|
||||
static void RestoreFocusWindow();
|
||||
|
||||
private:
|
||||
static int32_t GetCurrentUserId();
|
||||
@ -44,7 +46,8 @@ private:
|
||||
static uint64_t selfTokenID_;
|
||||
static uint64_t testTokenID_;
|
||||
static int32_t userID_;
|
||||
static int64_t selfUid_;
|
||||
static sptr<Rosen::Window> window_;
|
||||
static sptr<Rosen::WindowOption> winOption_;
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -44,8 +44,9 @@ constexpr const uint16_t EACH_LINE_LENGTH = 500;
|
||||
constexpr int32_t BUFF_LENGTH = 10;
|
||||
constexpr const char *CMD_PIDOF_IMS = "pidof inputmethod_ser";
|
||||
uint64_t TddUtil::selfTokenID_ = 0;
|
||||
int64_t TddUtil::selfUid_ = -1;
|
||||
int32_t TddUtil::userID_ = INVALID_USER_ID;
|
||||
sptr<Window> TddUtil::window_ = nullptr;
|
||||
sptr<WindowOption> TddUtil::winOption_ = nullptr;
|
||||
int32_t TddUtil::GetCurrentUserId()
|
||||
{
|
||||
if (userID_ != INVALID_USER_ID) {
|
||||
@ -114,21 +115,28 @@ void TddUtil::RestoreSelfTokenID()
|
||||
IMSA_HILOGI("SetSelfTokenID ret = %{public}d", ret);
|
||||
}
|
||||
|
||||
void TddUtil::StorageSelfUid()
|
||||
void TddUtil::SetFocusWindow()
|
||||
{
|
||||
selfUid_ = getuid();
|
||||
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");
|
||||
usleep(100000); // the time wait for showing succeed
|
||||
}
|
||||
}
|
||||
|
||||
void TddUtil::SetTestUid()
|
||||
void TddUtil::RestoreFocusWindow()
|
||||
{
|
||||
FocusChangeInfo info;
|
||||
WindowManager::GetInstance().GetFocusWindowInfo(info);
|
||||
IMSA_HILOGI("uid: %{public}d", info.uid_);
|
||||
setuid(info.uid_);
|
||||
}
|
||||
void TddUtil::RestoreSelfUid()
|
||||
{
|
||||
setuid(selfUid_);
|
||||
if (window_ != nullptr) {
|
||||
window_->Hide();
|
||||
window_->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
bool TddUtil::ExecuteCmd(const std::string &cmd, std::string &result)
|
||||
|
@ -101,13 +101,10 @@ public:
|
||||
inputMethodAbility_->SetCoreAndAgent();
|
||||
TddUtil::RestoreSelfTokenID();
|
||||
|
||||
// Set the uid to the uid of the focus app
|
||||
TddUtil::StorageSelfUid();
|
||||
TddUtil::SetTestUid();
|
||||
TddUtil::SetFocusWindow();
|
||||
sptr<OnTextChangedListener> textListener = new TextListener();
|
||||
imc_ = InputMethodController::GetInstance();
|
||||
imc_->Attach(textListener);
|
||||
TddUtil::RestoreSelfUid();
|
||||
TextListener::ResetParam();
|
||||
}
|
||||
static void TearDownTestCase(void)
|
||||
@ -116,6 +113,7 @@ public:
|
||||
imc_->Close();
|
||||
TddUtil::KillImsaProcess();
|
||||
TextListener::ResetParam();
|
||||
TddUtil::RestoreFocusWindow();
|
||||
}
|
||||
void SetUp()
|
||||
{
|
||||
|
@ -76,15 +76,13 @@ public:
|
||||
inputMethodAbility_->SetCoreAndAgent();
|
||||
TddUtil::RestoreSelfTokenID();
|
||||
|
||||
// Set the uid to the uid of the focus app
|
||||
TddUtil::StorageSelfUid();
|
||||
TddUtil::SetTestUid();
|
||||
TddUtil::SetFocusWindow();
|
||||
inputMethodController_ = InputMethodController::GetInstance();
|
||||
}
|
||||
static void TearDownTestCase(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAttachTest::TearDownTestCase");
|
||||
TddUtil::RestoreSelfUid();
|
||||
TddUtil::RestoreFocusWindow();
|
||||
}
|
||||
void SetUp()
|
||||
{
|
||||
|
@ -254,9 +254,8 @@ constexpr uint32_t KEY_EVENT_DELAY_TIME = 100;
|
||||
keyEvent_->SetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, 1);
|
||||
keyEvent_->SetFunctionKey(MMI::KeyEvent::SCROLL_LOCK_FUNCTION_KEY, 1);
|
||||
TddUtil::SetTestTokenID(TddUtil::AllocTestTokenID(false, true, "undefine"));
|
||||
// Set the uid to the uid of the focus app
|
||||
TddUtil::StorageSelfUid();
|
||||
TddUtil::SetTestUid();
|
||||
|
||||
TddUtil::SetFocusWindow();
|
||||
SetInputDeathRecipient();
|
||||
TextListener::ResetParam();
|
||||
}
|
||||
@ -265,7 +264,7 @@ constexpr uint32_t KEY_EVENT_DELAY_TIME = 100;
|
||||
{
|
||||
IMSA_HILOGI("InputMethodControllerTest::TearDownTestCase");
|
||||
TddUtil::RestoreSelfTokenID();
|
||||
TddUtil::RestoreSelfUid();
|
||||
TddUtil::RestoreFocusWindow();
|
||||
TextListener::ResetParam();
|
||||
}
|
||||
|
||||
|
@ -136,9 +136,7 @@ bool InputMethodDfxTest::WriteAndWatch(std::shared_ptr<Watcher> watcher, InputMe
|
||||
return false;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(watcher->cvMutex_);
|
||||
TddUtil::SetTestUid();
|
||||
exec();
|
||||
TddUtil::RestoreSelfUid();
|
||||
bool result = watcher->watcherCv_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout;
|
||||
ret = OHOS::HiviewDFX::HiSysEventManager::RemoveListener(watcher);
|
||||
if (ret != SUCCESS || !result) {
|
||||
@ -163,7 +161,7 @@ void InputMethodDfxTest::SetUpTestCase(void)
|
||||
|
||||
inputMethodController_ = InputMethodController::GetInstance();
|
||||
textListener_ = new TextListener();
|
||||
TddUtil::StorageSelfUid();
|
||||
TddUtil::SetFocusWindow();
|
||||
}
|
||||
|
||||
void InputMethodDfxTest::TearDownTestCase(void)
|
||||
@ -171,6 +169,7 @@ void InputMethodDfxTest::TearDownTestCase(void)
|
||||
IMSA_HILOGI("InputMethodDfxTest::TearDownTestCase");
|
||||
TddUtil::RestoreSelfTokenID();
|
||||
TddUtil::KillImsaProcess();
|
||||
TddUtil::RestoreFocusWindow();
|
||||
}
|
||||
|
||||
void InputMethodDfxTest::SetUp(void)
|
||||
|
@ -167,7 +167,6 @@ void InputMethodEditorTest::SetUpTestCase(void)
|
||||
constexpr int32_t keyCode = 2001;
|
||||
keyEvent_->SetKeyAction(keyAction);
|
||||
keyEvent_->SetKeyCode(keyCode);
|
||||
TddUtil::StorageSelfUid();
|
||||
TextListener::ResetParam();
|
||||
}
|
||||
|
||||
@ -239,7 +238,7 @@ HWTEST_F(InputMethodEditorTest, testShowTextInputUnfocused, TestSize.Level0)
|
||||
HWTEST_F(InputMethodEditorTest, testAttachFocused, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodEditorTest Attach Focused Test START");
|
||||
TddUtil::SetTestUid();
|
||||
TddUtil::SetFocusWindow();
|
||||
InputMethodEditorTest::imeListener_->isInputStart_ = false;
|
||||
InputMethodEditorTest::imeListener_->keyboardState_ = false;
|
||||
int32_t ret = InputMethodEditorTest::inputMethodController_->Attach(InputMethodEditorTest::textListener_, false);
|
||||
@ -258,7 +257,7 @@ HWTEST_F(InputMethodEditorTest, testAttachFocused, TestSize.Level0)
|
||||
EXPECT_TRUE(TextListener::WaitIMACallback());
|
||||
EXPECT_TRUE(imeListener_->isInputStart_ && imeListener_->keyboardState_);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
TddUtil::RestoreSelfUid();
|
||||
TddUtil::RestoreFocusWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,7 +270,7 @@ HWTEST_F(InputMethodEditorTest, testShowSoftKeyboard, TestSize.Level0)
|
||||
IMSA_HILOGI("InputMethodEditorTest ShowSoftKeyboard Test START");
|
||||
InputMethodEditorTest::inputMethodController_->Close();
|
||||
TddUtil::SetTestTokenID(TddUtil::AllocTestTokenID(true, true, "undefined"));
|
||||
TddUtil::SetTestUid();
|
||||
TddUtil::SetFocusWindow();
|
||||
InputMethodEditorTest::imeListener_->keyboardState_ = false;
|
||||
TextListener::keyboardStatus_ = KeyboardStatus::NONE;
|
||||
int32_t ret = InputMethodEditorTest::inputMethodController_->Attach(InputMethodEditorTest::textListener_, false);
|
||||
@ -280,7 +279,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::RestoreSelfUid();
|
||||
TddUtil::RestoreFocusWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -292,7 +291,7 @@ HWTEST_F(InputMethodEditorTest, testIMCHideTextInput, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodEditorTest HideTextInputAndShowTextInput Test START");
|
||||
InputMethodEditorTest::inputMethodController_->Close();
|
||||
TddUtil::SetTestUid();
|
||||
TddUtil::SetFocusWindow();
|
||||
int32_t ret = InputMethodEditorTest::inputMethodController_->Attach(InputMethodEditorTest::textListener_, true);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
|
||||
@ -311,7 +310,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::RestoreSelfUid();
|
||||
TddUtil::RestoreFocusWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -323,7 +322,7 @@ HWTEST_F(InputMethodEditorTest, testShowTextInput, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodEditorTest ShowTextInput Test START");
|
||||
InputMethodEditorTest::inputMethodController_->Close();
|
||||
TddUtil::SetTestUid();
|
||||
TddUtil::SetFocusWindow();
|
||||
int32_t ret = InputMethodEditorTest::inputMethodController_->Attach(InputMethodEditorTest::textListener_, true);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
InputMethodEditorTest::inputMethodController_->HideTextInput();
|
||||
@ -335,7 +334,7 @@ HWTEST_F(InputMethodEditorTest, testShowTextInput, TestSize.Level0)
|
||||
ret = ret && kbListener_->keyCode_ == keyEvent_->GetKeyCode()
|
||||
&& kbListener_->keyStatus_ == keyEvent_->GetKeyAction();
|
||||
EXPECT_TRUE(result);
|
||||
TddUtil::RestoreSelfUid();
|
||||
TddUtil::RestoreFocusWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -346,7 +345,7 @@ HWTEST_F(InputMethodEditorTest, testShowTextInput, TestSize.Level0)
|
||||
HWTEST_F(InputMethodEditorTest, testIMCClose, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("IMC Close Test START");
|
||||
TddUtil::SetTestUid();
|
||||
TddUtil::SetFocusWindow();
|
||||
int32_t ret = InputMethodEditorTest::inputMethodController_->Attach(InputMethodEditorTest::textListener_, true);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
InputMethodEditorTest::inputMethodController_->Close();
|
||||
@ -365,7 +364,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::RestoreSelfUid();
|
||||
TddUtil::RestoreFocusWindow();
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -233,7 +233,7 @@ HWTEST_F(InputMethodPrivateMemberTest, PerUserSessionClientError, TestSize.Level
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
|
||||
ret = userSession->OnShowKeyboardSelf();
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
|
||||
bool result = userSession->CheckFocused(1);
|
||||
bool result = userSession->IsFocused(1, 1);
|
||||
EXPECT_FALSE(result);
|
||||
|
||||
userSession->SetCurrentClient(imc->clientInfo_.client);
|
||||
|
@ -61,7 +61,6 @@ void PermissionVerificationExceptionTest::SetUpTestCase(void)
|
||||
auto property = InputMethodController::GetInstance()->GetCurrentInputMethod();
|
||||
EXPECT_NE(property, nullptr);
|
||||
tokenId_ = TddUtil::GetTestTokenID(property->name);
|
||||
TddUtil::StorageSelfUid();
|
||||
}
|
||||
|
||||
void PermissionVerificationExceptionTest::TearDownTestCase(void)
|
||||
@ -93,13 +92,13 @@ HWTEST_F(PermissionVerificationExceptionTest, ShowAndHideSoftKeyboard, TestSize.
|
||||
PermissionVerificationExceptionTest::ima_->SetCoreAndAgent();
|
||||
TddUtil::RestoreSelfTokenID();
|
||||
|
||||
TddUtil::SetTestUid();
|
||||
TddUtil::SetFocusWindow();
|
||||
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::RestoreSelfUid();
|
||||
TddUtil::RestoreFocusWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user