提接口文件

Signed-off-by: cy7717 <chenyu301@huawei.com>
This commit is contained in:
cy7717 2024-03-29 11:47:08 +08:00
parent 4f4577e91b
commit 17a964bdb4
17 changed files with 385 additions and 255 deletions

View File

@ -16,7 +16,7 @@
#include "js_get_input_method_setting.h"
#include "event_checker.h"
#include "ime_event_monitor_manager.h"
#include "ime_event_monitor_manager_impl.h"
#include "input_client_info.h"
#include "input_method_controller.h"
#include "input_method_status.h"
@ -491,7 +491,7 @@ napi_value JsGetInputMethodSetting::Subscribe(napi_env env, napi_callback_info i
}
std::shared_ptr<JSCallbackObject> callback =
std::make_shared<JSCallbackObject>(env, argv[ARGC_ONE], std::this_thread::get_id());
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ iter->second }, inputMethod_);
auto ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ iter->second }, inputMethod_);
if (ret == ErrorCode::NO_ERROR) {
engine->RegisterListener(argv[ARGC_ONE], type, callback);
} else {
@ -572,7 +572,7 @@ napi_value JsGetInputMethodSetting::UnSubscribe(napi_env env, napi_callback_info
return nullptr;
}
if (isUpdateFlag) {
auto ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ iter->second }, inputMethod_);
auto ret = ImeEventMonitorManagerImpl::GetInstance().UnRegisterImeEventListener({ iter->second }, inputMethod_);
IMSA_HILOGI("UpdateListenEventFlag, ret: %{public}d, type: %{public}s", ret, type.c_str());
}
napi_value result = nullptr;

View File

@ -0,0 +1,47 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_IME_EVENT_MONITOR_MANAGER_IMPL_H
#define FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_IME_EVENT_MONITOR_MANAGER_IMPL_H
#include <map>
#include <set>
#include "ime_event_listener.h"
#include "visibility.h"
namespace OHOS {
namespace MiscServices {
class ImeEventMonitorManagerImpl {
public:
static ImeEventMonitorManagerImpl &GetInstance();
int32_t RegisterImeEventListener(
const std::set<EventType> &types, const std::shared_ptr<ImeEventListener> &listener);
int32_t UnRegisterImeEventListener(
const std::set<EventType> &types, const std::shared_ptr<ImeEventListener> &listener);
int32_t OnImeChange(const Property &property, const SubProperty &subProperty);
int32_t OnPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info);
private:
ImeEventMonitorManagerImpl();
~ImeEventMonitorManagerImpl();
std::set<std::shared_ptr<ImeEventListener>> GetListeners(EventType type);
std::mutex lock_;
std::map<EventType, std::set<std::shared_ptr<ImeEventListener>>> listeners_{};
};
} // namespace MiscServices
} // namespace OHOS
#endif // FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_IME_EVENT_MONITOR_MANAGER_IMPL_H

View File

@ -15,11 +15,13 @@
#include "ime_event_monitor_manager.h"
#include "input_method_controller.h"
#include <algorithm>
#include "global.h"
#include "ime_event_monitor_manager_impl.h"
namespace OHOS {
namespace MiscServices {
;
ImeEventMonitorManager::ImeEventMonitorManager()
{
}
@ -40,21 +42,7 @@ int32_t ImeEventMonitorManager::RegisterImeEventListener(
if (!IsParamValid(types, listener)) {
return ErrorCode::ERROR_BAD_PARAMETERS;
}
std::lock_guard<std::mutex> lock(lock_);
for (const auto &type : types) {
auto it = listeners_.find(type);
if (it == listeners_.end()) {
auto ret = InputMethodController::GetInstance()->UpdateListenEventFlag(type, true);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGI("UpdateListenEventFlag failed: %{public}d", ret);
return ret;
}
listeners_.insert({ type, { listener } });
} else {
it->second.insert(listener);
}
}
return ErrorCode::NO_ERROR;
return ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener(types, listener);
}
int32_t ImeEventMonitorManager::UnRegisterImeEventListener(
@ -63,94 +51,27 @@ int32_t ImeEventMonitorManager::UnRegisterImeEventListener(
if (!IsParamValid(types, listener)) {
return ErrorCode::ERROR_BAD_PARAMETERS;
}
bool isContainInvalidParam = false;
std::lock_guard<std::mutex> lock(lock_);
for (const auto &type : types) {
auto it = listeners_.find(type);
if (it == listeners_.end()) {
isContainInvalidParam = true;
continue;
}
auto iter = it->second.find(listener);
if (iter == it->second.end()) {
isContainInvalidParam = true;
continue;
}
it->second.erase(iter);
if (it->second.empty()) {
auto ret = InputMethodController::GetInstance()->UpdateListenEventFlag(type, false);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGI("UpdateListenEventFlag failed: %{public}d", ret);
}
listeners_.erase(it);
}
}
return isContainInvalidParam ? ErrorCode::ERROR_BAD_PARAMETERS : ErrorCode::NO_ERROR;
return ImeEventMonitorManagerImpl::GetInstance().UnRegisterImeEventListener(types, listener);
}
bool ImeEventMonitorManager::IsParamValid(
const std::set<EventType> &types, const std::shared_ptr<ImeEventListener> &listener)
{
if (listener == nullptr) {
IMSA_HILOGI("listener is nullptr");
IMSA_HILOGE("listener is nullptr");
return false;
}
if (types.size() > EventType::IME_NONE) {
IMSA_HILOGI("over the max num");
if (types.empty()) {
IMSA_HILOGE("no eventType");
return false;
}
for (const auto &type : types) {
if (type >= EventType::IME_NONE) {
IMSA_HILOGI("eventType is error");
return false;
}
if (types.size() > EVENT_NUM) {
IMSA_HILOGE("over eventNum");
return false;
}
return true;
}
int32_t ImeEventMonitorManager::OnImeChange(const Property &property, const SubProperty &subProperty)
{
auto listeners = GetListeners(EventType::IME_CHANGE);
if (listeners.empty()) {
IMSA_HILOGD("not has IME_CHANGE listeners");
return ErrorCode::ERROR_BAD_PARAMETERS;
}
for (const auto &listener : listeners) {
listener->OnImeChange(property, subProperty);
}
return ErrorCode::NO_ERROR;
}
int32_t ImeEventMonitorManager::OnPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info)
{
if (status != InputWindowStatus::HIDE && status != InputWindowStatus::SHOW) {
IMSA_HILOGE("status:%{public}d is invalid", status);
return ErrorCode::ERROR_BAD_PARAMETERS;
}
auto type = status == InputWindowStatus::HIDE ? EventType::IME_HIDE : EventType::IME_SHOW;
auto listeners = GetListeners(type);
if (listeners.empty()) {
IMSA_HILOGD("not has %{public}d listeners", type);
return ErrorCode::ERROR_BAD_PARAMETERS;
}
for (const auto &listener : listeners) {
if (type == EventType::IME_HIDE) {
listener->OnImeHide(info);
} else {
listener->OnImeShow(info);
}
}
return ErrorCode::NO_ERROR;
}
std::set<std::shared_ptr<ImeEventListener>> ImeEventMonitorManager::GetListeners(EventType type)
{
std::lock_guard<std::mutex> lock(lock_);
auto it = listeners_.find(type);
if (it == listeners_.end()) {
return {};
}
return it->second;
auto it = std::find_if(
types.begin(), types.end(), [this](EventType type) { return EVENT_TYPE.find(type) == EVENT_TYPE.end(); });
return it == types.end();
}
} // namespace MiscServices
} // namespace OHOS

View File

@ -0,0 +1,131 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ime_event_monitor_manager_impl.h"
#include <algorithm>
#include "input_method_controller.h"
namespace OHOS {
namespace MiscServices {
ImeEventMonitorManagerImpl::ImeEventMonitorManagerImpl()
{
}
ImeEventMonitorManagerImpl::~ImeEventMonitorManagerImpl()
{
}
ImeEventMonitorManagerImpl &ImeEventMonitorManagerImpl::GetInstance()
{
static ImeEventMonitorManagerImpl manager;
return manager;
}
int32_t ImeEventMonitorManagerImpl::RegisterImeEventListener(
const std::set<EventType> &types, const std::shared_ptr<ImeEventListener> &listener)
{
std::lock_guard<std::mutex> lock(lock_);
for (const auto &type : types) {
auto it = listeners_.find(type);
if (it == listeners_.end()) {
auto ret = InputMethodController::GetInstance()->UpdateListenEventFlag(type, true);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("UpdateListenEventFlag failed: %{public}d", ret);
return ret;
}
listeners_.insert({ type, { listener } });
} else {
it->second.insert(listener);
}
}
return ErrorCode::NO_ERROR;
}
int32_t ImeEventMonitorManagerImpl::UnRegisterImeEventListener(
const std::set<EventType> &types, const std::shared_ptr<ImeEventListener> &listener)
{
bool isAbsentParam = false;
std::lock_guard<std::mutex> lock(lock_);
for (const auto &type : types) {
auto it = listeners_.find(type);
if (it == listeners_.end()) {
isAbsentParam = true;
continue;
}
auto iter = it->second.find(listener);
if (iter == it->second.end()) {
isAbsentParam = true;
continue;
}
it->second.erase(iter);
if (it->second.empty()) {
auto ret = InputMethodController::GetInstance()->UpdateListenEventFlag(type, false);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("UpdateListenEventFlag failed: %{public}d", ret);
}
listeners_.erase(it);
}
}
return isAbsentParam ? ErrorCode::ERROR_BAD_PARAMETERS : ErrorCode::NO_ERROR;
}
int32_t ImeEventMonitorManagerImpl::OnImeChange(const Property &property, const SubProperty &subProperty)
{
auto listeners = GetListeners(EventType::IME_CHANGE);
if (listeners.empty()) {
IMSA_HILOGD("not has IME_CHANGE listeners");
return ErrorCode::ERROR_BAD_PARAMETERS;
}
for (const auto &listener : listeners) {
listener->OnImeChange(property, subProperty);
}
return ErrorCode::NO_ERROR;
}
int32_t ImeEventMonitorManagerImpl::OnPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info)
{
if (status != InputWindowStatus::HIDE && status != InputWindowStatus::SHOW) {
IMSA_HILOGE("status:%{public}d is invalid", status);
return ErrorCode::ERROR_BAD_PARAMETERS;
}
auto type = status == InputWindowStatus::HIDE ? EventType::IME_HIDE : EventType::IME_SHOW;
auto listeners = GetListeners(type);
if (listeners.empty()) {
IMSA_HILOGD("not has %{public}d listeners", type);
return ErrorCode::ERROR_BAD_PARAMETERS;
}
for (const auto &listener : listeners) {
if (type == EventType::IME_HIDE) {
listener->OnImeHide(info);
} else {
listener->OnImeShow(info);
}
}
return ErrorCode::NO_ERROR;
}
std::set<std::shared_ptr<ImeEventListener>> ImeEventMonitorManagerImpl::GetListeners(EventType type)
{
std::lock_guard<std::mutex> lock(lock_);
auto it = listeners_.find(type);
if (it == listeners_.end()) {
return {};
}
return it->second;
}
} // namespace MiscServices
} // namespace OHOS

View File

@ -16,6 +16,7 @@
#include "input_client_stub.h"
#include "global.h"
#include "ime_event_monitor_manager_impl.h"
#include "input_method_controller.h"
#include "ipc_object_stub.h"
#include "ipc_skeleton.h"
@ -122,12 +123,12 @@ int32_t InputClientStub::OnInputStop()
int32_t InputClientStub::OnSwitchInput(const Property &property, const SubProperty &subProperty)
{
return ImeEventMonitorManager::GetInstance().OnImeChange(property, subProperty);
return ImeEventMonitorManagerImpl::GetInstance().OnImeChange(property, subProperty);
}
int32_t InputClientStub::OnPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info)
{
return ImeEventMonitorManager::GetInstance().OnPanelStatusChange(status, info);
return ImeEventMonitorManagerImpl::GetInstance().OnPanelStatusChange(status, info);
}
void InputClientStub::DeactivateClient()

View File

@ -196,7 +196,7 @@ int32_t InputMethodSystemAbilityProxy::SwitchInputMethod(
int32_t InputMethodSystemAbilityProxy::PanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info)
{
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::PANEL_STATUS_CHANGE),
[status, info](MessageParcel &data) { return ITypesUtil::Marshal(data, static_cast<uint32_t>(status), info); });
[status, &info](MessageParcel &data) { return ITypesUtil::Marshal(data, static_cast<uint32_t>(status), info); });
}
int32_t InputMethodSystemAbilityProxy::UpdateListenEventFlag(InputClientInfo &clientInfo, EventType eventType)

View File

@ -51,6 +51,7 @@ ohos_shared_library("inputmethod_client") {
sources = [
"${inputmethod_path}/frameworks/native/inputmethod_ability/src/input_method_agent_proxy.cpp",
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager.cpp",
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager_impl.cpp",
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_proxy.cpp",
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_stub.cpp",
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp",
@ -110,6 +111,7 @@ ohos_static_library("inputmethod_client_static") {
sources = [
"${inputmethod_path}/frameworks/native/inputmethod_ability/src/input_method_agent_proxy.cpp",
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager.cpp",
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager_impl.cpp",
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_proxy.cpp",
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_stub.cpp",
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp",

View File

@ -21,6 +21,7 @@
namespace OHOS {
namespace MiscServices {
enum EventType : uint32_t { IME_CHANGE = 0, IME_SHOW = 1, IME_HIDE = 2, IME_NONE };
class ImeEventListener {
public:
virtual ~ImeEventListener() = default;

View File

@ -13,40 +13,37 @@
* limitations under the License.
*/
#ifndef FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_IME_LISTEN_EVENT_MANAGER_H
#define FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_IME_LISTEN_EVENT_MANAGER_H
#ifndef FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_IME_EVENT_MONITOR_MANAGER_H
#define FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_IME_EVENT_MONITOR_MANAGER_H
#include <map>
#include <set>
#include "ime_event_listener.h"
#include "input_client_stub.h"
#include "visibility.h"
namespace OHOS {
namespace MiscServices {
enum EventType : uint32_t { IME_CHANGE = 0, IME_SHOW = 1, IME_HIDE = 2, IME_NONE };
class ImeEventMonitorManager {
public:
/**
* @brief Get the instance of TmeEventMonitorManager.
* @brief Get the instance of ImeEventMonitorManager.
*
* This function is used to get the instance of TmeEventMonitorManager.
* This function is used to get the instance of ImeEventMonitorManager.
*
* @return The instance of TmeEventMonitorManager.
* @since 11
* @return The instance of ImeEventMonitorManager.
* @since 12
*/
IMF_API static ImeEventMonitorManager &GetInstance();
/**
* @brief Register Ime Event Listener.
*
* This function is used to Register Ime Event Listener.
* This function is used to Register Ime Event Listener, register IME_SHOW and IME_HIDE only supported at present
*
* @param types Indicates the event type.
* @param listener Indicates the the listener to be registered.
* @return Returns 0 for success, others for failure.
* @since 11
* @since 12
*/
IMF_API int32_t RegisterImeEventListener(
const std::set<EventType> &types, const std::shared_ptr<ImeEventListener> &listener);
@ -54,27 +51,23 @@ public:
/**
* @brief UnRegister Ime Event Listener.
*
* This function is used to UnRegister Ime Event Listener.
* This function is used to UnRegister Ime Event Listener, unregister IME_SHOW and IME_HIDE only supported at present
*
* @param types Indicates the event type.
* @param listener Indicates the the listener to be unregistered.
* @return Returns 0 for success, others for failure.
* @since 11
* @since 12
*/
IMF_API int32_t UnRegisterImeEventListener(
const std::set<EventType> &types, const std::shared_ptr<ImeEventListener> &listener);
private:
friend class InputClientStub;
const uint32_t EVENT_NUM = 2;
const std::set<EventType> EVENT_TYPE{ IME_SHOW, IME_HIDE };
ImeEventMonitorManager();
~ImeEventMonitorManager();
std::set<std::shared_ptr<ImeEventListener>>GetListeners(EventType type);
bool IsParamValid(const std::set<EventType> &types, const std::shared_ptr<ImeEventListener> &listener);
int32_t OnImeChange(const Property &property, const SubProperty &subProperty);
int32_t OnPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info);
std::mutex lock_;
std::map<EventType, std::set<std::shared_ptr<ImeEventListener>>> listeners_{};
};
} // namespace MiscServices
} // namespace OHOS
#endif // INTERFACE_KITS_JS_GETINPUT_METHOD_SETTING_H
#endif // FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_IME_EVENT_MONITOR_MANAGER_H

View File

@ -25,7 +25,6 @@
#include "controller_listener.h"
#include "element_name.h"
#include "event_handler.h"
#include "event_status_manager.h"
#include "global.h"
#include "i_input_method_agent.h"
#include "i_input_method_system_ability.h"

View File

@ -16,14 +16,9 @@
#ifndef INPUTMETHOD_IMF_IME_SETTING_LISTENER_TEST_IMPL_H
#define INPUTMETHOD_IMF_IME_SETTING_LISTENER_TEST_IMPL_H
#include <unistd.h>
#include <condition_variable>
#include "input_method_controller.h"
#include "input_method_utils.h"
#include "key_event.h"
#include "string_ex.h"
#include "ime_event_listener.h"
namespace OHOS {
namespace MiscServices {

View File

@ -47,3 +47,4 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
OHOS::FuzzUnRegisterImeEventListener(data, size);
return 0;
}
} // namespace OHOS

View File

@ -16,13 +16,13 @@
#define protected public
#include "ime_event_monitor_manager.h"
#include "ime_event_monitor_manager_impl.h"
#include "input_method_controller.h"
#undef private
#include <gtest/gtest.h>
#include <sys/time.h>
#include <unistd.h>
#include "ime_event_listener.h"
#include "ime_setting_listener_test_impl.h"
#include "tdd_util.h"
@ -58,7 +58,7 @@ void ImeEventMonitorManagerTest::SetUp()
void ImeEventMonitorManagerTest::TearDown()
{
TddUtil::RestoreSelfTokenID();
ImeEventMonitorManager::GetInstance().listeners_.clear();
ImeEventMonitorManagerImpl::GetInstance().listeners_.clear();
InputMethodController::GetInstance()->clientInfo_.eventFlag = 0;
IMSA_HILOGI("ImeEventMonitorManagerTest::TearDown");
}
@ -75,7 +75,7 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_001, TestSize.
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(
{ EventType::IME_HIDE, EventType::IME_SHOW, EventType::IME_CHANGE, static_cast<EventType>(10) }, listener);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
EXPECT_TRUE(ImeEventMonitorManager::GetInstance().listeners_.empty());
EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty());
}
/**
@ -90,22 +90,21 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_002, TestSiz
auto ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
{ EventType::IME_HIDE, EventType::IME_SHOW, EventType::IME_CHANGE, static_cast<EventType>(10) }, listener);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
EXPECT_TRUE(ImeEventMonitorManager::GetInstance().listeners_.empty());
EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty());
}
/**
* @tc.name: testRegisterImeEventListener_003
* @tc.desc: type size over max
* @tc.desc: type is error
* @tc.type: FUNC
*/
HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_003, TestSize.Level0)
{
IMSA_HILOGI("testRegisterImeEventListener_003 start.");
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(
{ EventType::IME_HIDE, static_cast<EventType>(10) }, listener);
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
EXPECT_TRUE(ImeEventMonitorManager::GetInstance().listeners_.empty());
EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty());
}
/**
@ -118,9 +117,9 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_004, TestSiz
IMSA_HILOGI("testUnRegisterImeEventListener_004 start.");
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
auto ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
{ EventType::IME_HIDE, EventType::IME_NONE }, listener);
{ EventType::IME_HIDE, EventType::IME_CHANGE }, listener);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
EXPECT_TRUE(ImeEventMonitorManager::GetInstance().listeners_.empty());
EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty());
}
/**
@ -133,7 +132,7 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_005, TestSize.
IMSA_HILOGI("testRegisterImeEventListener_005 start.");
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, nullptr);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
EXPECT_TRUE(ImeEventMonitorManager::GetInstance().listeners_.empty());
EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty());
}
/**
@ -146,7 +145,7 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_006, TestSiz
IMSA_HILOGI("testUnRegisterImeEventListener_006 start.");
auto ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, nullptr);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
EXPECT_TRUE(ImeEventMonitorManager::GetInstance().listeners_.empty());
EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty());
}
/**
@ -161,7 +160,7 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_007, TestSize.
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener);
EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION);
EXPECT_TRUE(ImeEventMonitorManager::GetInstance().listeners_.empty());
EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty());
}
/**
@ -175,12 +174,12 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_008, TestSiz
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 1);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 4);
TddUtil::RestoreSelfTokenID();
ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_TRUE(ImeEventMonitorManager::GetInstance().listeners_.empty());
EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty());
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 0);
}
@ -195,10 +194,10 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_009, TestSize.
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 1);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 4);
auto it = ImeEventMonitorManager::GetInstance().listeners_.find(EventType::IME_HIDE);
ASSERT_NE(it, ImeEventMonitorManager::GetInstance().listeners_.end());
auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_HIDE);
ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end());
ASSERT_EQ(it->second.size(), 1);
auto iter = it->second.find(listener);
EXPECT_NE(iter, it->second.end());
@ -214,24 +213,18 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_010, TestSize.
IMSA_HILOGI("testRegisterImeEventListener_010 start.");
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(
{ EventType::IME_HIDE, EventType::IME_SHOW, EventType::IME_CHANGE }, listener);
{ EventType::IME_HIDE, EventType::IME_SHOW }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 7);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 3);
auto it = ImeEventMonitorManager::GetInstance().listeners_.find(EventType::IME_HIDE);
ASSERT_NE(it, ImeEventMonitorManager::GetInstance().listeners_.end());
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 6);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2);
auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_HIDE);
ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end());
ASSERT_EQ(it->second.size(), 1);
auto iter = it->second.find(listener);
EXPECT_NE(iter, it->second.end());
it = ImeEventMonitorManager::GetInstance().listeners_.find(EventType::IME_SHOW);
ASSERT_NE(it, ImeEventMonitorManager::GetInstance().listeners_.end());
ASSERT_EQ(it->second.size(), 1);
iter = it->second.find(listener);
EXPECT_NE(iter, it->second.end());
it = ImeEventMonitorManager::GetInstance().listeners_.find(EventType::IME_CHANGE);
ASSERT_NE(it, ImeEventMonitorManager::GetInstance().listeners_.end());
it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW);
ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end());
ASSERT_EQ(it->second.size(), 1);
iter = it->second.find(listener);
EXPECT_NE(iter, it->second.end());
@ -250,9 +243,9 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_011, TestSize.
{ EventType::IME_SHOW, EventType::IME_SHOW }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 1);
auto it = ImeEventMonitorManager::GetInstance().listeners_.find(EventType::IME_SHOW);
ASSERT_NE(it, ImeEventMonitorManager::GetInstance().listeners_.end());
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1);
auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW);
ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end());
ASSERT_EQ(it->second.size(), 1);
auto iter = it->second.find(listener);
EXPECT_NE(iter, it->second.end());
@ -269,22 +262,22 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_012, TestSize.
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
auto listener1 = std::make_shared<ImeSettingListenerTestImpl>();
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(
{ EventType::IME_SHOW, EventType::IME_CHANGE }, listener);
{ EventType::IME_SHOW, EventType::IME_HIDE }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(
{ EventType::IME_SHOW, EventType::IME_CHANGE }, listener1);
{ EventType::IME_SHOW, EventType::IME_HIDE }, listener1);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 3);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 2);
auto it = ImeEventMonitorManager::GetInstance().listeners_.find(EventType::IME_CHANGE);
ASSERT_NE(it, ImeEventMonitorManager::GetInstance().listeners_.end());
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 6);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2);
auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_HIDE);
ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end());
ASSERT_EQ(it->second.size(), 2);
auto iter = it->second.find(listener);
EXPECT_NE(iter, it->second.end());
iter = it->second.find(listener1);
EXPECT_NE(iter, it->second.end());
it = ImeEventMonitorManager::GetInstance().listeners_.find(EventType::IME_SHOW);
ASSERT_NE(it, ImeEventMonitorManager::GetInstance().listeners_.end());
it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW);
ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end());
ASSERT_EQ(it->second.size(), 2);
iter = it->second.find(listener);
EXPECT_NE(iter, it->second.end());
@ -310,16 +303,16 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_013, TestSize.
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 6);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 2);
auto it = ImeEventMonitorManager::GetInstance().listeners_.find(EventType::IME_SHOW);
ASSERT_NE(it, ImeEventMonitorManager::GetInstance().listeners_.end());
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2);
auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW);
ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end());
ASSERT_EQ(it->second.size(), 2);
auto iter = it->second.find(listener);
EXPECT_NE(iter, it->second.end());
iter = it->second.find(listener1);
EXPECT_NE(iter, it->second.end());
it = ImeEventMonitorManager::GetInstance().listeners_.find(EventType::IME_HIDE);
ASSERT_NE(it, ImeEventMonitorManager::GetInstance().listeners_.end());
it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_HIDE);
ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end());
ASSERT_EQ(it->second.size(), 1);
iter = it->second.find(listener1);
EXPECT_NE(iter, it->second.end());
@ -337,16 +330,16 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_014, TestSiz
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 1);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1);
ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_TRUE(ImeEventMonitorManager::GetInstance().listeners_.empty());
EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty());
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 0);
}
/**
* @tc.name: testUnRegisterImeEventListener_015
* @tc.desc: one listener register all events, unregister two events
* @tc.desc: one listener register all events, unregister one events
* @tc.type: FUNC
*/
HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_015, TestSize.Level0)
@ -354,15 +347,14 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_015, TestSiz
IMSA_HILOGI("testUnRegisterImeEventListener_015 start.");
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(
{ EventType::IME_SHOW, EventType::IME_HIDE, EventType::IME_CHANGE }, listener);
{ EventType::IME_SHOW, EventType::IME_HIDE }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 7);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 3);
ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
{ EventType::IME_HIDE, EventType::IME_CHANGE }, listener);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 6);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2);
ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 1);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1);
}
/**
@ -375,14 +367,14 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_016, TestSiz
IMSA_HILOGI("testUnRegisterImeEventListener_016 start.");
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(
{ EventType::IME_SHOW, EventType::IME_HIDE, EventType::IME_CHANGE }, listener);
{ EventType::IME_SHOW, EventType::IME_HIDE }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 7);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 3);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 6);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2);
ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
{ EventType::IME_SHOW, EventType::IME_HIDE, EventType::IME_CHANGE }, listener);
{ EventType::IME_SHOW, EventType::IME_HIDE }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_TRUE(ImeEventMonitorManager::GetInstance().listeners_.empty());
EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty());
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 0);
}
@ -401,13 +393,13 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_017, TestSiz
ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener1);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 1);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1);
ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 1);
auto it = ImeEventMonitorManager::GetInstance().listeners_.find(EventType::IME_SHOW);
ASSERT_NE(it, ImeEventMonitorManager::GetInstance().listeners_.end());
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1);
auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW);
ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end());
ASSERT_EQ(it->second.size(), 1);
auto iter = it->second.find(listener1);
EXPECT_NE(iter, it->second.end());
@ -428,13 +420,13 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_018, TestSiz
ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener1);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 1);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1);
ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 1);
auto it = ImeEventMonitorManager::GetInstance().listeners_.find(EventType::IME_SHOW);
ASSERT_NE(it, ImeEventMonitorManager::GetInstance().listeners_.end());
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1);
auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW);
ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end());
ASSERT_EQ(it->second.size(), 2);
auto iter = it->second.find(listener);
EXPECT_NE(iter, it->second.end());
@ -452,23 +444,67 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_019, TestSiz
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
auto listener1 = std::make_shared<ImeSettingListenerTestImpl>();
auto listener2 = std::make_shared<ImeSettingListenerTestImpl>();
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener);
auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener1);
ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener1);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 1);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 1);
ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_CHANGE }, listener2);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1);
ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener2);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 1);
EXPECT_EQ(ImeEventMonitorManager::GetInstance().listeners_.size(), 1);
auto it = ImeEventMonitorManager::GetInstance().listeners_.find(EventType::IME_CHANGE);
ASSERT_NE(it, ImeEventMonitorManager::GetInstance().listeners_.end());
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1);
auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW);
ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end());
ASSERT_EQ(it->second.size(), 2);
auto iter = it->second.find(listener);
EXPECT_NE(iter, it->second.end());
iter = it->second.find(listener1);
EXPECT_NE(iter, it->second.end());
}
/********************************* all test is for innerkit above ***************************************************/
/**
* @tc.name: testRegisterImeEventListener_020
* @tc.desc: two listener, one is innerkit(register all event), one is js(register one event)
* @tc.type: FUNC
*/
HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_020, TestSize.Level0)
{
IMSA_HILOGI("testRegisterImeEventListener_020 start.");
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
auto listener1 = std::make_shared<ImeSettingListenerTestImpl>();
auto ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW, IME_HIDE }, listener1);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 7);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 3);
}
/**
* @tc.name: testUnRegisterImeEventListener_021
* @tc.desc: two listener, one is innerkit(register all event), one is js(register all event), js unregister IME_CHANGE
* @tc.type: FUNC
*/
HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_021, TestSize.Level0)
{
IMSA_HILOGI("testUnRegisterImeEventListener_021 start.");
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
auto listener1 = std::make_shared<ImeSettingListenerTestImpl>();
auto ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW, IME_HIDE }, listener1);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 7);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 3);
ret = ImeEventMonitorManagerImpl::GetInstance().UnRegisterImeEventListener({ EventType::IME_CHANGE }, listener);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 6);
EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2);
}
} // namespace MiscServices
} // namespace OHOS

View File

@ -17,6 +17,7 @@
#include "ability_manager_client.h"
#include "global.h"
#include "ime_event_monitor_manager_impl.h"
#include "ime_setting_listener_test_impl.h"
#include "input_method_ability_interface.h"
#include "input_method_controller.h"
@ -138,7 +139,7 @@ private:
TddUtil::StorageSelfTokenID();
TddUtil::SetTestTokenID(TddUtil::AllocTestTokenID(true, "ImeProxyTest"));
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener(
ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener(
{ EventType::IME_CHANGE, EventType::IME_HIDE, EventType::IME_SHOW }, listener);
TddUtil::RestoreSelfTokenID();
}

View File

@ -807,16 +807,16 @@ HWTEST_F(InputMethodPanelTest, testRegisterListener, TestSize.Level0)
HWTEST_F(InputMethodPanelTest, testImcPanelListening_001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_001 start.");
// todo 设置系统app
// set system app
TddUtil::SetTestTokenID(testTokenId_);
auto listener = std::make_shared<InputMethodSettingListenerImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener);
ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener);
TddUtil::RestoreSelfTokenID();
// todo 取消系统app设置
// cancel system app
InputWindowInfo info{ "", 0, 0, InputMethodPanelTest::windowWidth_, InputMethodPanelTest::windowHeight_ };
InputMethodPanelTest::ImcPanelListeningTestRestore();
// todo 设置当前ime权限
// set current ime
TddUtil::SetTestTokenID(testTokenId_);
auto ret = InputMethodPanelTest::inputMethodPanel_->ShowPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
@ -826,16 +826,16 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_001, TestSize.Level0)
InputMethodPanelTest::ImcPanelListeningTestRestore();
ret = InputMethodPanelTest::inputMethodPanel_->HidePanel();
TddUtil::RestoreSelfTokenID();
// todo 取消当前ime权限设置
// cancel current ime
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelHideNumCheck(1);
InputMethodPanelTest::ImcPanelHideInfoCheck(info);
// todo 设置系统app
// set system app
TddUtil::SetTestTokenID(testTokenId_);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener);
TddUtil::RestoreSelfTokenID();
// todo 取消系统app设置
// cancel system app
}
/**
@ -846,17 +846,17 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_001, TestSize.Level0)
HWTEST_F(InputMethodPanelTest, testImcPanelListening_002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_002 start.");
// todo 设置系统app
// set system app
TddUtil::SetTestTokenID(testTokenId_);
auto listener = std::make_shared<InputMethodSettingListenerImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener);
ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener);
TddUtil::RestoreSelfTokenID();
// todo 取消系统app设置
// cancel system app
InputWindowInfo info{ "", 0, 0, InputMethodPanelTest::windowWidth_, InputMethodPanelTest::windowHeight_ };
InputMethodPanelTest::inputMethodPanel_->panelFlag_ = FLG_FLOATING;
InputMethodPanelTest::ImcPanelListeningTestRestore();
// todo 设置当前ime权限
// set current ime
TddUtil::SetTestTokenID(testTokenId_);
auto ret = InputMethodPanelTest::inputMethodPanel_->ShowPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
@ -866,16 +866,16 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_002, TestSize.Level0)
InputMethodPanelTest::ImcPanelListeningTestRestore();
ret = InputMethodPanelTest::inputMethodPanel_->HidePanel();
TddUtil::RestoreSelfTokenID();
// todo 取消当前ime权限设置
// cancel current ime
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelHideNumCheck(1);
InputMethodPanelTest::ImcPanelHideInfoCheck(info);
// todo 设置系统app
// set system app
TddUtil::SetTestTokenID(testTokenId_);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener);
TddUtil::RestoreSelfTokenID();
// todo 取消系统app设置
// cancel system app
InputMethodPanelTest::inputMethodPanel_->panelFlag_ = FLG_FIXED;
}
@ -887,16 +887,16 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_002, TestSize.Level0)
HWTEST_F(InputMethodPanelTest, testImcPanelListening_003, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_003 start.");
// todo 设置系统app
// set system app
TddUtil::SetTestTokenID(testTokenId_);
auto listener = std::make_shared<InputMethodSettingListenerImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener);
ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener);
TddUtil::RestoreSelfTokenID();
// todo 取消系统app设置
// cancel system app
InputMethodPanelTest::inputMethodPanel_->panelFlag_ = FLG_CANDIDATE_COLUMN;
InputMethodPanelTest::ImcPanelListeningTestRestore();
// todo 设置当前ime权限
// set current ime
TddUtil::SetTestTokenID(testTokenId_);
auto ret = InputMethodPanelTest::inputMethodPanel_->ShowPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
@ -905,15 +905,15 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_003, TestSize.Level0)
InputMethodPanelTest::ImcPanelListeningTestRestore();
ret = InputMethodPanelTest::inputMethodPanel_->HidePanel();
TddUtil::RestoreSelfTokenID();
// todo 取消当前ime权限设置
// cancel current ime
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelHideNumCheck(0);
// todo 设置系统app
// set system app
TddUtil::SetTestTokenID(testTokenId_);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener);
TddUtil::RestoreSelfTokenID();
// todo 取消系统app设置
// cancel system app
InputMethodPanelTest::inputMethodPanel_->panelFlag_ = FLG_FIXED;
}
@ -925,15 +925,15 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_003, TestSize.Level0)
HWTEST_F(InputMethodPanelTest, testImcPanelListening_004, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_004 start.");
// todo 设置系统app
// set system app
TddUtil::SetTestTokenID(testTokenId_);
auto listener = std::make_shared<InputMethodSettingListenerImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener);
ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener);
TddUtil::RestoreSelfTokenID();
// todo 取消系统app设置
// cancel system app
InputMethodPanelTest::ImcPanelListeningTestRestore();
// todo 设置当前ime权限
// set current ime
TddUtil::SetTestTokenID(testTokenId_);
auto ret = InputMethodPanelTest::inputMethodStatusBar_->ShowPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
@ -942,15 +942,15 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_004, TestSize.Level0)
InputMethodPanelTest::ImcPanelListeningTestRestore();
ret = InputMethodPanelTest::inputMethodStatusBar_->HidePanel();
TddUtil::RestoreSelfTokenID();
// todo 取消当前ime权限设置
// cancel current ime
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelHideNumCheck(0);
// todo 设置系统app
// set system app
TddUtil::SetTestTokenID(testTokenId_);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener);
TddUtil::RestoreSelfTokenID();
// todo 取消系统app设置
// cancel system app
}
/*
@ -961,7 +961,7 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_004, TestSize.Level0)
HWTEST_F(InputMethodPanelTest, testImcPanelListening_005, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_005 start.");
// todo 设置native sa
// set native sa
TddUtil::GrantNativePermission();
auto listener1 = std::make_shared<InputMethodSettingListenerImpl>();
auto listener2 = std::make_shared<InputMethodSettingListenerImpl>();
@ -972,8 +972,8 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_005, TestSize.Level0)
ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener2);
ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener3);
TddUtil::RestoreSelfTokenID();
// todo 取消native sa设置
// todo 设置当前ime权限
// cancel native sa
// set current ime
TddUtil::SetTestTokenID(testTokenId_);
InputMethodPanelTest::ImcPanelListeningTestRestore();
auto ret = InputMethodPanelTest::inputMethodPanel_->ShowPanel();
@ -983,11 +983,11 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_005, TestSize.Level0)
InputMethodPanelTest::ImcPanelListeningTestRestore();
ret = InputMethodPanelTest::inputMethodPanel_->HidePanel();
TddUtil::RestoreSelfTokenID();
// todo 取消当前ime权限设置
// cancel current ime
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelHideNumCheck(2);
// todo 设置native sa
// set native sa
TddUtil::GrantNativePermission();
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener1);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener1);
@ -995,7 +995,7 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_005, TestSize.Level0)
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener2);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener3);
TddUtil::RestoreSelfTokenID();
// todo 取消native sa设置
// cancel native sa
}
/*
@ -1006,7 +1006,7 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_005, TestSize.Level0)
HWTEST_F(InputMethodPanelTest, testImcPanelListening_006, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_006 start.");
// todo 设置native sa
// set native sa
TddUtil::GrantNativePermission();
auto listener1 = std::make_shared<InputMethodSettingListenerImpl>();
auto listener2 = std::make_shared<InputMethodSettingListenerImpl>();
@ -1017,10 +1017,10 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_006, TestSize.Level0)
ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener3);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener1);
TddUtil::RestoreSelfTokenID();
// todo 取消native sa设置
// cancel native sa
// UnRegister one IME_SHOW listener
InputMethodPanelTest::ImcPanelListeningTestRestore();
// todo 设置当前ime权限
// set current ime
TddUtil::SetTestTokenID(testTokenId_);
auto ret = InputMethodPanelTest::inputMethodPanel_->ShowPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
@ -1029,20 +1029,20 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_006, TestSize.Level0)
InputMethodPanelTest::ImcPanelListeningTestRestore();
ret = InputMethodPanelTest::inputMethodPanel_->HidePanel();
TddUtil::RestoreSelfTokenID();
// todo 取消当前ime权限设置
// cancel current ime
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelHideNumCheck(1);
// UnRegister all listener
// todo 设置native sa
// set native sa
TddUtil::GrantNativePermission();
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener2);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener3);
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener1);
TddUtil::RestoreSelfTokenID();
// todo 取消native sa设置
// cancel native sa
InputMethodPanelTest::ImcPanelListeningTestRestore();
// todo 设置当前ime权限
// set current ime
TddUtil::SetTestTokenID(testTokenId_);
ret = InputMethodPanelTest::inputMethodPanel_->ShowPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
@ -1051,7 +1051,7 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_006, TestSize.Level0)
InputMethodPanelTest::ImcPanelListeningTestRestore();
ret = InputMethodPanelTest::inputMethodPanel_->HidePanel();
TddUtil::RestoreSelfTokenID();
// todo 取消当前ime权限设置
// cancel current ime
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelHideNumCheck(0);
}
@ -1064,15 +1064,15 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_006, TestSize.Level0)
HWTEST_F(InputMethodPanelTest, testImcPanelListening_007, TestSize.Level0)
{
IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_007 start.");
// todo 设置native sa
// set native sa
TddUtil::GrantNativePermission();
auto listener = std::make_shared<InputMethodSettingListenerImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener(
{ EventType::IME_SHOW, EventType::IME_HIDE }, listener);
TddUtil::RestoreSelfTokenID();
// todo 取消native sa设置
// cancel native sa
InputMethodPanelTest::ImcPanelListeningTestRestore();
// todo 设置当前ime权限
// set current ime
TddUtil::SetTestTokenID(testTokenId_);
auto ret = InputMethodPanelTest::inputMethodPanel_->ShowPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
@ -1081,28 +1081,28 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_007, TestSize.Level0)
InputMethodPanelTest::ImcPanelListeningTestRestore();
ret = InputMethodPanelTest::inputMethodPanel_->HidePanel();
TddUtil::RestoreSelfTokenID();
// todo 取消当前ime权限设置
// cancel current ime
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelHideNumCheck(1);
// UnRegister all listener
// todo 设置native sa
// set native sa
TddUtil::GrantNativePermission();
ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
{ EventType::IME_SHOW, EventType::IME_HIDE }, listener);
TddUtil::RestoreSelfTokenID();
// todo 取消native sa设置
// cancel native sa
InputMethodPanelTest::ImcPanelListeningTestRestore();
ret = InputMethodPanelTest::inputMethodPanel_->ShowPanel();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelShowNumCheck(0);
InputMethodPanelTest::ImcPanelListeningTestRestore();
// todo 设置当前ime权限
// set current ime
TddUtil::SetTestTokenID(testTokenId_);
ret = InputMethodPanelTest::inputMethodPanel_->HidePanel();
TddUtil::RestoreSelfTokenID();
// todo 取消当前ime权限设置
// cancel current ime
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodPanelTest::ImcPanelHideNumCheck(0);
}

View File

@ -21,6 +21,7 @@
#include <vector>
#include "global.h"
#include "ime_event_monitor_manager_impl.h"
#include "ime_info_inquirer.h"
#include "ime_setting_listener_test_impl.h"
#include "input_method_controller.h"
@ -85,7 +86,7 @@ void InputMethodSwitchTest::SetUpTestCase(void)
TddUtil::AllocTestTokenID(true, "ohos.inputMethod.test", { "ohos.permission.CONNECT_IME_ABILITY" }));
imc_ = InputMethodController::GetInstance();
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener);
ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener);
}
void InputMethodSwitchTest::TearDownTestCase(void)

View File

@ -20,6 +20,7 @@
#include <vector>
#include "global.h"
#include "ime_event_monitor_manager_impl.h"
#include "ime_info_inquirer.h"
#include "ime_setting_listener_test_impl.h"
#include "input_method_controller.h"
@ -78,7 +79,7 @@ void NewImeSwitchTest::SetUpTestCase(void)
TddUtil::AllocTestTokenID(true, "ohos.inputMethod.test", { "ohos.permission.CONNECT_IME_ABILITY" }));
imc_ = InputMethodController::GetInstance();
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener);
ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener);
}
void NewImeSwitchTest::TearDownTestCase(void)