1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #define private public
16 #define protected public
17 #include "input_method_panel.h"
18 
19 #include "input_method_ability.h"
20 #include "input_method_ability_utils.h"
21 #include "input_method_controller.h"
22 #include "input_method_system_ability.h"
23 #undef private
24 
25 #include <gtest/gtest.h>
26 #include <sys/time.h>
27 #include <unistd.h>
28 
29 #include <condition_variable>
30 #include <cstdint>
31 #include <string>
32 
33 #include "common_event_data.h"
34 #include "common_event_manager.h"
35 #include "common_event_subscribe_info.h"
36 #include "common_event_subscriber.h"
37 #include "common_event_support.h"
38 #include "display_manager.h"
39 #include "global.h"
40 #include "identity_checker_mock.h"
41 #include "ime_event_monitor_manager.h"
42 #include "input_method_ability.h"
43 #include "input_method_controller.h"
44 #include "input_method_engine_listener_impl.h"
45 #include "matching_skills.h"
46 #include "panel_status_listener.h"
47 #include "scene_board_judgement.h"
48 #include "scope_utils.h"
49 #include "tdd_util.h"
50 #include "text_listener.h"
51 
52 using namespace testing::ext;
53 namespace OHOS {
54 namespace MiscServices {
55 constexpr uint32_t IMC_WAIT_PANEL_STATUS_LISTEN_TIME = 500;
56 constexpr float FIXED_SOFT_KEYBOARD_PANEL_RATIO = 0.7;
57 constexpr float NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO = 1;
58 constexpr const char *COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED = "usual.event.imf.input_panel_status_changed";
59 constexpr const char *COMMON_EVENT_PARAM_PANEL_STATE = "panelState";
60 enum ListeningStatus : uint32_t { ON, OFF, NONE };
61 class InputMethodPanelTest : public testing::Test {
62 public:
63     static void SetUpTestCase(void);
64     static void TearDownTestCase(void);
65     void SetUp();
66     void TearDown();
67     static std::shared_ptr<InputMethodPanel> CreatePanel();
68     static void DestroyPanel(const std::shared_ptr<InputMethodPanel> &panel);
69     static void Attach();
70     static bool TriggerShowCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel);
71     static bool TriggerHideCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel);
72     static void ImaCreatePanel(const PanelInfo &info, std::shared_ptr<InputMethodPanel> &panel);
73     static void ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> &panel);
74     static void ImcPanelListeningTestRestore();
75     static void ImcPanelShowNumCheck(uint32_t num);
76     static void ImcPanelHideNumCheck(uint32_t num);
77     static void ImcPanelShowInfoCheck(const InputWindowInfo &windowInfo);
78     static void ImcPanelHideInfoCheck(const InputWindowInfo &windowInfo);
79     static void TestShowPanel(const std::shared_ptr<InputMethodPanel> &panel);
80     static void TestHidePanel(const std::shared_ptr<InputMethodPanel> &panel);
81     static void TestIsPanelShown(const PanelInfo &info, bool expectedResult);
82     static void TriggerPanelStatusChangeToImc(const std::shared_ptr<InputMethodPanel> &panel, InputWindowStatus status);
83     class PanelStatusListenerImpl : public PanelStatusListener {
84     public:
PanelStatusListenerImpl()85         PanelStatusListenerImpl()
86         {
87             std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("InputMethodPanelTest");
88             panelHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
89         }
90         ~PanelStatusListenerImpl() = default;
OnPanelStatus(uint32_t windowId,bool isShow)91         void OnPanelStatus(uint32_t windowId, bool isShow)
92         {
93             {
94                 std::unique_lock<std::mutex> lock(InputMethodPanelTest::panelListenerLock_);
95                 if (isShow) {
96                     InputMethodPanelTest::status_ = InputWindowStatus::SHOW;
97                 } else {
98                     InputMethodPanelTest::status_ = InputWindowStatus::HIDE;
99                 }
100             }
101             InputMethodPanelTest::panelListenerCv_.notify_one();
102             IMSA_HILOGI("PanelStatusListenerImpl OnPanelStatus in, isShow is %{public}s", isShow ? "true" : "false");
103         }
OnSizeChange(uint32_t windowId,const WindowSize & size)104         void OnSizeChange(uint32_t windowId, const WindowSize &size) {}
105     };
106     static std::mutex imcPanelStatusListenerLock_;
107     static std::condition_variable imcPanelStatusListenerCv_;
108     static InputWindowStatus status_;
109     static InputWindowInfo windowInfo_;
110     static uint32_t imeShowCallbackNum_;
111     static uint32_t imeHideCallbackNum_;
112 
113     static sptr<InputMethodController> imc_;
114     static sptr<InputMethodAbility> ima_;
115     static sptr<InputMethodSystemAbility> imsa_;
116     static uint32_t windowWidth_;
117     static uint32_t windowHeight_;
118     static std::condition_variable panelListenerCv_;
119     static std::mutex panelListenerLock_;
120     static constexpr uint32_t DELAY_TIME = 100;
121     static constexpr int32_t INTERVAL = 10;
122     static std::shared_ptr<AppExecFwk::EventHandler> panelHandler_;
123     static int32_t currentImeUid_;
124     static uint64_t currentImeTokenId_;
125     static sptr<OnTextChangedListener> textListener_;
126     static std::shared_ptr<InputMethodEngineListener> imeListener_;
127     static bool isScbEnable_;
128 };
129 class InputMethodSettingListenerImpl : public ImeEventListener {
130 public:
131     InputMethodSettingListenerImpl() = default;
132     ~InputMethodSettingListenerImpl() = default;
OnImeShow(const ImeWindowInfo & info)133     void OnImeShow(const ImeWindowInfo &info) override
134     {
135         IMSA_HILOGI("InputMethodPanelTest::OnImeShow");
136         std::unique_lock<std::mutex> lock(InputMethodPanelTest::imcPanelStatusListenerLock_);
137         InputMethodPanelTest::status_ = InputWindowStatus::SHOW;
138         InputMethodPanelTest::windowInfo_ = info.windowInfo;
139         InputMethodPanelTest::imeShowCallbackNum_++;
140         InputMethodPanelTest::imcPanelStatusListenerCv_.notify_one();
141     }
OnImeHide(const ImeWindowInfo & info)142     void OnImeHide(const ImeWindowInfo &info) override
143     {
144         IMSA_HILOGI("InputMethodPanelTest::OnImeHide");
145         std::unique_lock<std::mutex> lock(InputMethodPanelTest::imcPanelStatusListenerLock_);
146         InputMethodPanelTest::status_ = InputWindowStatus::HIDE;
147         InputMethodPanelTest::windowInfo_ = info.windowInfo;
148         InputMethodPanelTest::imeHideCallbackNum_++;
149         InputMethodPanelTest::imcPanelStatusListenerCv_.notify_one();
150     }
151 };
152 
153 class TestEventSubscriber : public EventFwk::CommonEventSubscriber {
154 public:
TestEventSubscriber(const EventFwk::CommonEventSubscribeInfo & subscribeInfo)155     explicit TestEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo)
156         : EventFwk::CommonEventSubscriber(subscribeInfo)
157     {
158     }
OnReceiveEvent(const EventFwk::CommonEventData & data)159     void OnReceiveEvent(const EventFwk::CommonEventData &data)
160     {
161         std::unique_lock<std::mutex> lock(InputMethodPanelTest::imcPanelStatusListenerLock_);
162         auto const &want = data.GetWant();
163         action_ = want.GetAction();
164         bool visible = want.GetBoolParam(COMMON_EVENT_PARAM_PANEL_STATE, false);
165         status_ = visible ? InputWindowStatus::SHOW : InputWindowStatus::HIDE;
166         InputMethodPanelTest::imcPanelStatusListenerCv_.notify_one();
167     }
ResetParam()168     void ResetParam()
169     {
170         action_ = "";
171         status_ = InputWindowStatus::NONE;
172     }
173     std::string action_;
174     InputWindowStatus status_{ InputWindowStatus::NONE };
175 };
176 
177 std::condition_variable InputMethodPanelTest::panelListenerCv_;
178 std::mutex InputMethodPanelTest::panelListenerLock_;
179 std::shared_ptr<AppExecFwk::EventHandler> InputMethodPanelTest::panelHandler_{ nullptr };
180 std::condition_variable InputMethodPanelTest::imcPanelStatusListenerCv_;
181 std::mutex InputMethodPanelTest::imcPanelStatusListenerLock_;
182 InputWindowStatus InputMethodPanelTest::status_{ InputWindowStatus::NONE };
183 InputWindowInfo InputMethodPanelTest::windowInfo_;
184 uint32_t InputMethodPanelTest::imeShowCallbackNum_{ 0 };
185 uint32_t InputMethodPanelTest::imeHideCallbackNum_{ 0 };
186 sptr<InputMethodController> InputMethodPanelTest::imc_{ nullptr };
187 sptr<InputMethodAbility> InputMethodPanelTest::ima_{ nullptr };
188 sptr<InputMethodSystemAbility> InputMethodPanelTest::imsa_{ nullptr };
189 uint32_t InputMethodPanelTest::windowWidth_ = 0;
190 uint32_t InputMethodPanelTest::windowHeight_ = 0;
191 uint64_t InputMethodPanelTest::currentImeTokenId_ = 0;
192 int32_t InputMethodPanelTest::currentImeUid_ = 0;
193 sptr<OnTextChangedListener> InputMethodPanelTest::textListener_{ nullptr };
194 std::shared_ptr<InputMethodEngineListener> InputMethodPanelTest::imeListener_{ nullptr };
195 bool InputMethodPanelTest::isScbEnable_{ false };
SetUpTestCase(void)196 void InputMethodPanelTest::SetUpTestCase(void)
197 {
198     IMSA_HILOGI("InputMethodPanelTest::SetUpTestCase");
199     IdentityCheckerMock::ResetParam();
200     isScbEnable_ = Rosen::SceneBoardJudgement::IsSceneBoardEnabled();
201     // storage current token id
202     TddUtil::StorageSelfTokenID();
203 
204     auto listener = std::make_shared<InputMethodSettingListenerImpl>();
205     imc_ = InputMethodController::GetInstance();
206     textListener_ = new (std::nothrow) TextListener();
207     imeListener_ = std::make_shared<InputMethodEngineListenerImpl>();
208     // set token as current input method
209     std::shared_ptr<Property> property = InputMethodController::GetInstance()->GetCurrentInputMethod();
210     std::string bundleName = property != nullptr ? property->name : "default.inputmethod.unittest";
211     currentImeTokenId_ = TddUtil::GetTestTokenID(bundleName);
212     currentImeUid_ = TddUtil::GetUid(bundleName);
213 
214     imsa_ = new (std::nothrow) InputMethodSystemAbility();
215     if (imsa_ == nullptr) {
216         return;
217     }
218     imsa_->OnStart();
219     imsa_->userId_ = TddUtil::GetCurrentUserId();
220     imsa_->identityChecker_ = std::make_shared<IdentityCheckerMock>();
221 
222     imc_->abilityManager_ = imsa_;
223 
224     ima_ = InputMethodAbility::GetInstance();
225     ima_->abilityManager_ = imsa_;
226     TddUtil::InitCurrentImePermissionInfo();
227     IdentityCheckerMock::SetBundleName(TddUtil::currentBundleNameMock_);
228     ima_->SetCoreAndAgent();
229     InputMethodPanelTest::ima_->SetImeListener(imeListener_);
230 
231     ImaUtils::abilityManager_ = imsa_;
232 }
233 
TearDownTestCase(void)234 void InputMethodPanelTest::TearDownTestCase(void)
235 {
236     IMSA_HILOGI("InputMethodPanelTest::TearDownTestCase");
237     TddUtil::RestoreSelfTokenID();
238     IdentityCheckerMock::ResetParam();
239     imsa_->OnStop();
240     ImaUtils::abilityManager_ = nullptr;
241 }
242 
SetUp(void)243 void InputMethodPanelTest::SetUp(void)
244 {
245     IMSA_HILOGI("InputMethodPanelTest::SetUp");
246 }
247 
TearDown(void)248 void InputMethodPanelTest::TearDown(void)
249 {
250     TddUtil::RestoreSelfTokenID();
251     IMSA_HILOGI("InputMethodPanelTest::TearDown");
252 }
253 
CreatePanel()254 std::shared_ptr<InputMethodPanel> InputMethodPanelTest::CreatePanel()
255 {
256     AccessScope scope(currentImeTokenId_, currentImeUid_);
257     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
258     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
259     auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
260     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
261     return inputMethodPanel;
262 }
263 
DestroyPanel(const std::shared_ptr<InputMethodPanel> & panel)264 void InputMethodPanelTest::DestroyPanel(const std::shared_ptr<InputMethodPanel> &panel)
265 {
266     ASSERT_NE(panel, nullptr);
267     AccessScope scope(currentImeTokenId_, currentImeUid_);
268     auto ret = panel->DestroyPanel();
269     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
270 }
271 
ImaCreatePanel(const PanelInfo & info,std::shared_ptr<InputMethodPanel> & panel)272 void InputMethodPanelTest::ImaCreatePanel(const PanelInfo &info, std::shared_ptr<InputMethodPanel> &panel)
273 {
274     AccessScope scope(currentImeTokenId_, currentImeUid_);
275     auto ret = ima_->CreatePanel(nullptr, info, panel);
276     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
277 }
278 
ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> & panel)279 void InputMethodPanelTest::ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> &panel)
280 {
281     AccessScope scope(currentImeTokenId_, currentImeUid_);
282     auto ret = ima_->DestroyPanel(panel);
283     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
284 }
285 
Attach()286 void InputMethodPanelTest::Attach()
287 {
288     IdentityCheckerMock::SetFocused(true);
289     auto ret = imc_->Attach(textListener_, false);
290     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
291     IdentityCheckerMock::SetFocused(false);
292 }
293 
TriggerShowCallback(std::shared_ptr<InputMethodPanel> & inputMethodPanel)294 bool InputMethodPanelTest::TriggerShowCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel)
295 {
296     IMSA_HILOGI("start");
297     status_ = InputWindowStatus::NONE;
298     panelHandler_->PostTask([&inputMethodPanel]() { TestShowPanel(inputMethodPanel); }, InputMethodPanelTest::INTERVAL);
299     {
300         std::unique_lock<std::mutex> lock(panelListenerLock_);
301         return panelListenerCv_.wait_for(lock, std::chrono::milliseconds(InputMethodPanelTest::DELAY_TIME),
302             [] { return status_ == InputWindowStatus::SHOW; });
303     }
304 }
305 
TriggerHideCallback(std::shared_ptr<InputMethodPanel> & inputMethodPanel)306 bool InputMethodPanelTest::TriggerHideCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel)
307 {
308     IMSA_HILOGI("start");
309     status_ = InputWindowStatus::NONE;
310     panelHandler_->PostTask([&inputMethodPanel]() { TestHidePanel(inputMethodPanel); }, InputMethodPanelTest::INTERVAL);
311     {
312         std::unique_lock<std::mutex> lock(panelListenerLock_);
313         return panelListenerCv_.wait_for(lock, std::chrono::milliseconds(InputMethodPanelTest::DELAY_TIME),
314             [] { return status_ == InputWindowStatus::HIDE; });
315     }
316 }
317 
ImcPanelShowNumCheck(uint32_t num)318 void InputMethodPanelTest::ImcPanelShowNumCheck(uint32_t num)
319 {
320     std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
321     if (num == 0) {
322         auto ret =
323             imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME));
324         EXPECT_EQ(ret, std::cv_status::timeout);
325         return;
326     }
327     bool ret = imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME),
328         [&num] { return num == imeShowCallbackNum_; });
329     EXPECT_TRUE(ret);
330 }
331 
ImcPanelHideNumCheck(uint32_t num)332 void InputMethodPanelTest::ImcPanelHideNumCheck(uint32_t num)
333 {
334     std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
335     if (num == 0) {
336         auto ret =
337             imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME));
338         EXPECT_EQ(ret, std::cv_status::timeout);
339         return;
340     }
341     bool ret = imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME),
342         [&num] { return num <= imeHideCallbackNum_; });
343     EXPECT_TRUE(ret);
344 }
345 
ImcPanelShowInfoCheck(const InputWindowInfo & windowInfo)346 void InputMethodPanelTest::ImcPanelShowInfoCheck(const InputWindowInfo &windowInfo)
347 {
348     std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
349     bool ret = imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME),
350         [] { return status_ == InputWindowStatus::SHOW; });
351     EXPECT_TRUE(ret);
352     IMSA_HILOGI("InputMethodPanelTest::name: %{public}s, ret:[%{public}d, %{public}d,%{public}d, %{public}d]",
353         windowInfo_.name.c_str(), windowInfo_.top, windowInfo_.left, windowInfo_.width, windowInfo_.height);
354     EXPECT_FALSE(windowInfo_.name.empty());
355 }
356 
ImcPanelHideInfoCheck(const InputWindowInfo & windowInfo)357 void InputMethodPanelTest::ImcPanelHideInfoCheck(const InputWindowInfo &windowInfo)
358 {
359     std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
360     bool ret = imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME),
361         [] { return status_ == InputWindowStatus::HIDE; });
362     EXPECT_TRUE(ret);
363     IMSA_HILOGI("InputMethodPanelTest::name: %{public}s, ret:[%{public}d, %{public}d,%{public}d, %{public}d]",
364         windowInfo_.name.c_str(), windowInfo_.top, windowInfo_.left, windowInfo_.width, windowInfo_.height);
365     EXPECT_FALSE(windowInfo_.name.empty());
366 }
367 
ImcPanelListeningTestRestore()368 void InputMethodPanelTest::ImcPanelListeningTestRestore()
369 {
370     status_ = InputWindowStatus::NONE;
371     windowInfo_ = {};
372     imeShowCallbackNum_ = 0;
373     imeHideCallbackNum_ = 0;
374 }
375 
TestShowPanel(const std::shared_ptr<InputMethodPanel> & panel)376 void InputMethodPanelTest::TestShowPanel(const std::shared_ptr<InputMethodPanel> &panel)
377 {
378     ASSERT_NE(panel, nullptr);
379     // set tokenId and uid as current ime
380     AccessScope scope(currentImeTokenId_, currentImeUid_);
381     auto ret = panel->ShowPanel();
382     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
383 }
384 
TestHidePanel(const std::shared_ptr<InputMethodPanel> & panel)385 void InputMethodPanelTest::TestHidePanel(const std::shared_ptr<InputMethodPanel> &panel)
386 {
387     ASSERT_NE(panel, nullptr);
388     // set tokenId and uid as current ime
389     AccessScope scope(currentImeTokenId_, currentImeUid_);
390     auto ret = panel->HidePanel();
391     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
392 }
393 
TestIsPanelShown(const PanelInfo & info,bool expectedResult)394 void InputMethodPanelTest::TestIsPanelShown(const PanelInfo &info, bool expectedResult)
395 {
396     IdentityCheckerMock::SetSystemApp(true);
397     bool result = !expectedResult;
398     auto ret = imc_->IsPanelShown(info, result);
399     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
400     EXPECT_EQ(result, expectedResult);
401     IdentityCheckerMock::SetSystemApp(false);
402 }
403 
TriggerPanelStatusChangeToImc(const std::shared_ptr<InputMethodPanel> & panel,InputWindowStatus status)404 void InputMethodPanelTest::TriggerPanelStatusChangeToImc(
405     const std::shared_ptr<InputMethodPanel> &panel, InputWindowStatus status)
406 {
407     ASSERT_NE(panel, nullptr);
408     if (isScbEnable_) {
409         IdentityCheckerMock::SetBundleNameValid(true);
410         // add for SetTestTokenID in mainThread, but has no effect for other thread ipc
411         panel->PanelStatusChangeToImc(status, { 0, 0, 0, 0 });
412         IdentityCheckerMock::SetBundleNameValid(false);
413     }
414 }
415 
416 /**
417 * @tc.name: testCreatePanel
418 * @tc.desc: Test CreatePanel.
419 * @tc.type: FUNC
420 */
421 HWTEST_F(InputMethodPanelTest, testCreatePanel, TestSize.Level0)
422 {
423     IMSA_HILOGI("InputMethodPanelTest::testCreatePanel start.");
424     AccessScope scope(currentImeTokenId_, currentImeUid_);
425     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
426     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
427     auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
428     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
429     ret = inputMethodPanel->DestroyPanel();
430     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
431 }
432 
433 /**
434 * @tc.name: testDestroyPanel
435 * @tc.desc: Test DestroyPanel.
436 * @tc.type: FUNC
437 */
438 HWTEST_F(InputMethodPanelTest, testDestroyPanel, TestSize.Level0)
439 {
440     IMSA_HILOGI("InputMethodPanelTest::testDestroyPanel start.");
441     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
442     // not CreatePanel, DestroyPanel failed
443     auto ret = inputMethodPanel->DestroyPanel();
444     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
445 }
446 
447 /**
448 * @tc.name: testResizePanel001
449 * @tc.desc: Test Resize panel. Panels non fixed soft keyboard.
450 * @tc.type: FUNC
451 */
452 HWTEST_F(InputMethodPanelTest, testResizePanel001, TestSize.Level0)
453 {
454     IMSA_HILOGI("InputMethodPanelTest::testResizePanel001 start.");
455     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
456     // not CreatePanel, Resize failed
457     auto ret = inputMethodPanel->Resize(1, 1);
458     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
459 
460     AccessScope scope(currentImeTokenId_, currentImeUid_);
461     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
462     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
463     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
464     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
465     ASSERT_TRUE(defaultDisplay != nullptr);
466     int32_t width = defaultDisplay->GetWidth();
467     int32_t height = defaultDisplay->GetHeight();
468 
469     ret = inputMethodPanel->Resize(width - 1, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1);
470     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
471 
472     ret = inputMethodPanel->Resize(width, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO);
473     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
474 
475     ret = inputMethodPanel->Resize(width + 1, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO);
476     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
477 
478     ret = inputMethodPanel->Resize(width, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
479     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
480 
481     ret = inputMethodPanel->Resize(width + 1, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
482     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
483 
484     ret = inputMethodPanel->DestroyPanel();
485     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
486 }
487 
488 /**
489 * @tc.name: testResizePanel002
490 * @tc.desc: Test Resize panel. Fixed soft keyboard panel .
491 * @tc.type: FUNC
492 */
493 HWTEST_F(InputMethodPanelTest, testResizePanel002, TestSize.Level0)
494 {
495     IMSA_HILOGI("InputMethodPanelTest::testResizePanel002 start.");
496     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
497     // not CreatePanel, Resize failed
498     auto ret = inputMethodPanel->Resize(1, 1);
499     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
500 
501     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
502     AccessScope scope(currentImeTokenId_, currentImeUid_);
503     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
504     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
505     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
506     ASSERT_TRUE(defaultDisplay != nullptr);
507     int32_t width = defaultDisplay->GetWidth();
508     int32_t height = defaultDisplay->GetHeight();
509 
510     ret = inputMethodPanel->Resize(width - 1, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1);
511     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
512 
513     ret = inputMethodPanel->Resize(width, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO);
514     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
515 
516     ret = inputMethodPanel->Resize(width + 1, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO);
517     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
518 
519     ret = inputMethodPanel->Resize(width, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
520     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
521 
522     ret = inputMethodPanel->Resize(width + 1, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
523     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
524 
525     ret = inputMethodPanel->DestroyPanel();
526     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
527 }
528 
529 /**
530 * @tc.name: testMovePanel
531 * @tc.desc: Test Move panel. SOFT_KEYBOARD panel with FLG_FIXED can not be moved.
532 * @tc.type: FUNC
533 */
534 HWTEST_F(InputMethodPanelTest, testMovePanel, TestSize.Level0)
535 {
536     IMSA_HILOGI("InputMethodPanelTest::testMovePanel start.");
537     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
538     // not CreatePanel, MoveTo failed
539     auto ret = inputMethodPanel->MoveTo(10, 100);
540     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
541 
542     AccessScope scope(currentImeTokenId_, currentImeUid_);
543     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
544     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
545     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
546 
547     ret = inputMethodPanel->MoveTo(10, 100);
548     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
549 
550     ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_FLOATING);
551     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
552     ret = inputMethodPanel->MoveTo(10, 100);
553     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
554 
555     ret = inputMethodPanel->DestroyPanel();
556     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
557 
558     panelInfo.panelType = STATUS_BAR;
559     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
560     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
561     ret = inputMethodPanel->MoveTo(10, 100);
562     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
563     ret = inputMethodPanel->DestroyPanel();
564     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
565 }
566 
567 /**
568 * @tc.name: testShowPanel
569 * @tc.desc: Test Show panel.
570 * @tc.type: FUNC
571 */
572 HWTEST_F(InputMethodPanelTest, testShowPanel, TestSize.Level0)
573 {
574     IMSA_HILOGI("InputMethodPanelTest::testShowPanel start.");
575     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
576     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
577     // 0、not create panel, show panel failed.
578     auto ret = inputMethodPanel->ShowPanel();
579     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
580 
581     // 1 create panel, show success
582     AccessScope scope(currentImeTokenId_, currentImeUid_);
583     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
584     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
585     ret = inputMethodPanel->ShowPanel();
586     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
587 
588     auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
589     EXPECT_TRUE(statusListener != nullptr);
590     std::string type = "show";
591     inputMethodPanel->SetPanelStatusListener(statusListener, type);
592     ret = inputMethodPanel->ShowPanel();
593     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
594 
595     // 2、show floating type panel.
596     ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_FLOATING);
597     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
598     ret = inputMethodPanel->ShowPanel();
599     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
600 
601     ret = inputMethodPanel->DestroyPanel();
602     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
603 
604     // 4、show status bar.
605     panelInfo.panelType = STATUS_BAR;
606     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
607     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
608     ret = inputMethodPanel->ShowPanel();
609     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
610     ret = inputMethodPanel->HidePanel();
611     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
612     ret = inputMethodPanel->DestroyPanel();
613     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
614 }
615 
616 /**
617  * @tc.name: testIsPanelShown_001
618  * @tc.desc: Test is panel shown.
619  * @tc.type: FUNC
620  */
621 HWTEST_F(InputMethodPanelTest, testIsPanelShown_001, TestSize.Level0)
622 {
623     IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_001 start.");
624     InputMethodPanelTest::Attach();
625     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
626     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
627     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
628 
629     // query when fixed soft keyboard is showing
630     InputMethodPanelTest::TestShowPanel(inputMethodPanel);
631     InputMethodPanelTest::TestIsPanelShown(panelInfo, true);
632 
633     // query when fixed soft keyboard is hidden
634     InputMethodPanelTest::TestHidePanel(inputMethodPanel);
635     InputMethodPanelTest::TestIsPanelShown(panelInfo, false);
636 
637     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
638     InputMethodPanelTest::imc_->Close();
639 }
640 
641 /**
642  * @tc.name: testIsPanelShown_002
643  * @tc.desc: Test is panel shown.
644  * @tc.type: FUNC
645  */
646 HWTEST_F(InputMethodPanelTest, testIsPanelShown_002, TestSize.Level0)
647 {
648     IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_002 start.");
649     InputMethodPanelTest::Attach();
650     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
651     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
652     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
653 
654     // query panel with old info when panel changes its flag.
655     auto ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_FLOATING);
656     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
657     InputMethodPanelTest::TestShowPanel(inputMethodPanel);
658     InputMethodPanelTest::TestIsPanelShown(panelInfo, false);
659 
660     // query panel with updated shown one's info when panel changes its flag.
661     panelInfo.panelFlag = PanelFlag::FLG_FLOATING;
662     InputMethodPanelTest::TestIsPanelShown(panelInfo, true);
663 
664     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
665     InputMethodPanelTest::imc_->Close();
666 }
667 
668 /**
669  * @tc.name: testIsPanelShown_003
670  * @tc.desc: Test is panel shown.
671  * @tc.type: FUNC
672  */
673 HWTEST_F(InputMethodPanelTest, testIsPanelShown_003, TestSize.Level0)
674 {
675     IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_003 start.");
676     InputMethodPanelTest::Attach();
677     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
678     PanelInfo panelInfo = { .panelType = STATUS_BAR };
679     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
680 
681     // query status bar's status when it is showing
682     InputMethodPanelTest::TestShowPanel(inputMethodPanel);
683     InputMethodPanelTest::TestIsPanelShown(panelInfo, true);
684 
685     // query status bar's status when it is hidden
686     InputMethodPanelTest::TestHidePanel(inputMethodPanel);
687     InputMethodPanelTest::TestIsPanelShown(panelInfo, false);
688 
689     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
690     InputMethodPanelTest::imc_->Close();
691 }
692 
693 /**
694 * @tc.name: testSetPanelStatusListener01
695 * @tc.desc: Test testSetPanelStatusListener01.
696 * @tc.type: FUNC
697 */
698 HWTEST_F(InputMethodPanelTest, testSetPanelStatusListener01, TestSize.Level0)
699 {
700     IMSA_HILOGI("InputMethodPanelTest::testSetPanelStatusListener01 start.");
701     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
702     auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
703     // on('show')->on('hide')->show->hide
704     inputMethodPanel->SetPanelStatusListener(statusListener, "show");
705     inputMethodPanel->SetPanelStatusListener(statusListener, "hide");
706 
707     AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
708     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
709     auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
710     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
711 
712     EXPECT_TRUE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
713     EXPECT_TRUE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
714 
715     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
716 }
717 
718 /**
719 * @tc.name: testSetPanelStatusListener02
720 * @tc.desc: Test testSetPanelStatusListener02.
721 * @tc.type: FUNC
722 */
723 HWTEST_F(InputMethodPanelTest, testSetPanelStatusListener02, TestSize.Level0)
724 {
725     IMSA_HILOGI("InputMethodPanelTest::testSetPanelStatusListener02 start.");
726     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
727     auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
728 
729     AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
730     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
731     auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
732     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
733 
734     // panelStatusListener_ not nullptr
735     inputMethodPanel->panelStatusListener_ = statusListener;
736 
737     // subscribe 'show' after panel shown, get 'show' callback
738     InputMethodPanelTest::status_ = InputWindowStatus::NONE;
739     InputMethodPanelTest::TestShowPanel(inputMethodPanel);
740     inputMethodPanel->SetPanelStatusListener(statusListener, "show");
741     EXPECT_EQ(status_, InputWindowStatus::SHOW);
742 
743     // subscribe 'hide' after panel hidden, get 'hide' callback
744     InputMethodPanelTest::status_ = InputWindowStatus::NONE;
745     InputMethodPanelTest::TestHidePanel(inputMethodPanel);
746     inputMethodPanel->SetPanelStatusListener(statusListener, "hide");
747     EXPECT_EQ(status_, InputWindowStatus::HIDE);
748 
749     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
750 }
751 
752 /**
753 * @tc.name: testGetPanelType
754 * @tc.desc: Test GetPanelType.
755 * @tc.type: FUNC
756 */
757 HWTEST_F(InputMethodPanelTest, testGetPanelType, TestSize.Level0)
758 {
759     IMSA_HILOGI("InputMethodPanelTest::testGetPanelType start.");
760     AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
761     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
762     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
763     auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
764     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
765     auto type = inputMethodPanel->GetPanelType();
766     EXPECT_EQ(type, panelInfo.panelType);
767     ret = inputMethodPanel->DestroyPanel();
768     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
769 }
770 
771 /**
772  * @tc.name: testGetPanelFlag
773  * @tc.desc: Test GetPanelFlag.
774  * @tc.type: FUNC
775  */
776 HWTEST_F(InputMethodPanelTest, testGetPanelFlag, TestSize.Level0)
777 {
778     IMSA_HILOGI("InputMethodPanelTest::testGetPanelFlag start.");
779     AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
780     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
781     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
782     auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
783     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
784     auto flag = inputMethodPanel->GetPanelFlag();
785     EXPECT_EQ(flag, panelInfo.panelFlag);
786 
787     ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_CANDIDATE_COLUMN);
788     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
789     flag = inputMethodPanel->GetPanelFlag();
790     EXPECT_EQ(flag, PanelFlag::FLG_CANDIDATE_COLUMN);
791 
792     ret = inputMethodPanel->DestroyPanel();
793     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
794 }
795 
796 /**
797 * @tc.name: testChangePanelFlag
798 * @tc.desc: Test ChangePanelFlag.
799 * @tc.type: FUNC
800 */
801 HWTEST_F(InputMethodPanelTest, testChangePanelFlag, TestSize.Level0)
802 {
803     IMSA_HILOGI("InputMethodPanelTest::testChangePanelFlag start.");
804     AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
805     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
806     PanelFlag flag = FLG_FLOATING;
807 
808     // not CreatePanel, ChangePanelFlag failed
809     auto ret = inputMethodPanel->ChangePanelFlag(flag);
810     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
811 
812     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
813     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
814     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
815 
816     // panelFlag is same with the original
817     ret = inputMethodPanel->ChangePanelFlag(flag);
818     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
819 
820     // panelFlag modify to FLG_FIXED
821     flag = FLG_FIXED;
822     ret = inputMethodPanel->ChangePanelFlag(flag);
823     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
824 
825     inputMethodPanel->DestroyPanel();
826 
827     panelInfo = { .panelType = STATUS_BAR, .panelFlag = FLG_FLOATING };
828     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
829     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
830     // panelType is STATUS_BAR, not allow ChangePanelFlag
831     ret = inputMethodPanel->ChangePanelFlag(flag);
832     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
833 
834     inputMethodPanel->DestroyPanel();
835 }
836 
837 /**
838 * @tc.name: testClearPanelListener
839 * @tc.desc: Test ClearPanelListener.
840 * @tc.type: FUNC
841 */
842 HWTEST_F(InputMethodPanelTest, testClearPanelListener, TestSize.Level0)
843 {
844     IMSA_HILOGI("InputMethodPanelTest::testClearPanelListener start.");
845     auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
846     auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
847     inputMethodPanel->SetPanelStatusListener(statusListener, "show");
848     inputMethodPanel->SetPanelStatusListener(statusListener, "hide");
849 
850     inputMethodPanel->ClearPanelListener("show");
851     EXPECT_FALSE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
852     EXPECT_TRUE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
853 
854     inputMethodPanel->ClearPanelListener("hide");
855     EXPECT_FALSE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
856     EXPECT_FALSE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
857 
858     InputMethodPanelTest::DestroyPanel(inputMethodPanel);
859 }
860 
861 /**
862 * @tc.name: testRegisterListener
863 * @tc.desc: Test ClearPanelListener.
864 * @tc.type: FUNC
865 */
866 HWTEST_F(InputMethodPanelTest, testRegisterListener, TestSize.Level0)
867 {
868     // on('show')->on('hide')->show->hide->off('show')->show->hide->on('show')->show
869     IMSA_HILOGI("InputMethodPanelTest::testRegisterListener start.");
870     auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
871 
872     auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
873     inputMethodPanel->SetPanelStatusListener(statusListener, "show");
874     inputMethodPanel->SetPanelStatusListener(statusListener, "hide");
875     EXPECT_TRUE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
876     EXPECT_TRUE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
877 
878     inputMethodPanel->ClearPanelListener("show");
879     EXPECT_FALSE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
880     EXPECT_TRUE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
881 
882     inputMethodPanel->SetPanelStatusListener(statusListener, "show");
883     EXPECT_TRUE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
884 
885     InputMethodPanelTest::DestroyPanel(inputMethodPanel);
886 }
887 
888 /*
889 * @tc.name: testImcPanelListening_001
890 * @tc.desc: SOFT_KEYBOARD/FLG_FIXED, listener(system app)
891 * @tc.type: FUNC
892 */
893 HWTEST_F(InputMethodPanelTest, testImcPanelListening_001, TestSize.Level0)
894 {
895     IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_001 start.");
896     // system app for RegisterImeEventListener and currentIme for PanelStatusChangeToImc
897     IdentityCheckerMock::SetSystemApp(true);
898     IdentityCheckerMock::SetBundleNameValid(true);
899     auto listener = std::make_shared<InputMethodSettingListenerImpl>();
900     ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
901     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
902     std::shared_ptr<InputMethodPanel> panel = nullptr;
903     ImaCreatePanel(panelInfo, panel);
904     // imeShow
905     InputMethodPanelTest::ImcPanelListeningTestRestore();
906     InputMethodPanelTest::TestShowPanel(panel);
907     InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::SHOW);
908     InputMethodPanelTest::ImcPanelShowNumCheck(1);
909     // imeHide
910     InputMethodPanelTest::ImcPanelListeningTestRestore();
911     InputMethodPanelTest::TestHidePanel(panel);
912     InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::HIDE);
913     InputMethodPanelTest::ImcPanelHideNumCheck(1);
914     ImaDestroyPanel(panel);
915     ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
916         EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
917     IdentityCheckerMock::SetSystemApp(false);
918     IdentityCheckerMock::SetBundleNameValid(false);
919 }
920 
921 /*
922 * @tc.name: testImcPanelListening_002
923 * @tc.desc: SOFT_KEYBOARD/FLG_FLOATING, listener(system app)
924 * @tc.type: FUNC
925 */
926 HWTEST_F(InputMethodPanelTest, testImcPanelListening_002, TestSize.Level0)
927 {
928     IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_002 start.");
929     // system app for RegisterImeEventListener and currentIme for PanelStatusChangeToImc
930     IdentityCheckerMock::SetSystemApp(true);
931     IdentityCheckerMock::SetBundleNameValid(true);
932     auto listener = std::make_shared<InputMethodSettingListenerImpl>();
933     ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
934 
935     AccessScope scope(currentImeTokenId_, currentImeUid_);
936     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
937     std::shared_ptr<InputMethodPanel> panel = nullptr;
938     ImaCreatePanel(panelInfo, panel);
939     // imeShow
940     InputMethodPanelTest::ImcPanelListeningTestRestore();
941     InputMethodPanelTest::TestShowPanel(panel);
942     InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::SHOW);
943     InputMethodPanelTest::ImcPanelShowNumCheck(1);
944     // imeHide
945     InputMethodPanelTest::ImcPanelListeningTestRestore();
946     InputMethodPanelTest::TestHidePanel(panel);
947     InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::HIDE);
948     InputMethodPanelTest::ImcPanelHideNumCheck(1);
949     ImaDestroyPanel(panel);
950 
951     ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
952         EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
953     IdentityCheckerMock::SetSystemApp(false);
954     IdentityCheckerMock::SetBundleNameValid(false);
955 }
956 
957 /*
958 * @tc.name: testImcPanelListening_003
959 * @tc.desc: SOFT_KEYBOARD/FLG_CANDIDATE_COLUMN, listener(system app)
960 * @tc.type: FUNC
961 */
962 HWTEST_F(InputMethodPanelTest, testImcPanelListening_003, TestSize.Level0)
963 {
964     IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_003 start.");
965     // system app for RegisterImeEventListener and currentIme for PanelStatusChangeToImc
966     IdentityCheckerMock::SetSystemApp(true);
967     IdentityCheckerMock::SetBundleNameValid(true);
968     auto listener = std::make_shared<InputMethodSettingListenerImpl>();
969 
970     ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
971 
972     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_CANDIDATE_COLUMN };
973     std::shared_ptr<InputMethodPanel> panel = nullptr;
974     ImaCreatePanel(panelInfo, panel);
975     // imeShow
976     InputMethodPanelTest::ImcPanelListeningTestRestore();
977     InputMethodPanelTest::TestShowPanel(panel);
978     InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::SHOW);
979     InputMethodPanelTest::ImcPanelShowNumCheck(0);
980     // imeHide
981     InputMethodPanelTest::ImcPanelListeningTestRestore();
982     InputMethodPanelTest::TestHidePanel(panel);
983     InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::HIDE);
984     InputMethodPanelTest::ImcPanelHideNumCheck(0);
985     ImaDestroyPanel(panel);
986 
987     ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
988         EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
989     IdentityCheckerMock::SetSystemApp(false);
990     IdentityCheckerMock::SetBundleNameValid(false);
991 }
992 
993 /**
994 * @tc.name: testImcPanelListening_004
995 * @tc.desc: STATUS_BAR, listener(system app)
996 * @tc.type: FUNC
997 */
998 HWTEST_F(InputMethodPanelTest, testImcPanelListening_004, TestSize.Level0)
999 {
1000     IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_004 start.");
1001     // system app for RegisterImeEventListener and currentIme for PanelStatusChangeToImc
1002     IdentityCheckerMock::SetSystemApp(true);
1003     IdentityCheckerMock::SetBundleNameValid(true);
1004     auto listener = std::make_shared<InputMethodSettingListenerImpl>();
1005 
1006     ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
1007 
1008     PanelInfo panelInfo = { .panelType = STATUS_BAR };
1009     std::shared_ptr<InputMethodPanel> panel = nullptr;
1010     ImaCreatePanel(panelInfo, panel);
1011     // imeShow
1012     InputMethodPanelTest::ImcPanelListeningTestRestore();
1013     InputMethodPanelTest::TestShowPanel(panel);
1014     InputMethodPanelTest::ImcPanelShowNumCheck(0);
1015     // imeHide
1016     InputMethodPanelTest::ImcPanelListeningTestRestore();
1017     InputMethodPanelTest::TestHidePanel(panel);
1018     InputMethodPanelTest::ImcPanelHideNumCheck(0);
1019     ImaDestroyPanel(panel);
1020 
1021     ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
1022         EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
1023     IdentityCheckerMock::SetSystemApp(false);
1024     IdentityCheckerMock::SetBundleNameValid(false);
1025 }
1026 
1027 /*
1028 * @tc.name: testPanelStatusChangeEventPublicTest
1029 * @tc.desc: test subscriber can receive the panel status change event published by IMSA
1030 * @tc.type: FUNC
1031 */
1032 HWTEST_F(InputMethodPanelTest, testPanelStatusChangeEventPublicTest, TestSize.Level0)
1033 {
1034     IMSA_HILOGI("InputMethodPanelTest::testPanelStatusChangeEventPublicTest start.");
1035     // currentIme for PanelStatusChangeToImc
1036     IdentityCheckerMock::SetBundleNameValid(true);
1037     EventFwk::MatchingSkills matchingSkills;
1038     matchingSkills.AddEvent(COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED);
1039     EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
1040     auto subscriber = std::make_shared<TestEventSubscriber>(subscriberInfo);
1041     auto ret = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber);
1042     EXPECT_TRUE(ret);
1043     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1044     std::shared_ptr<InputMethodPanel> panel = nullptr;
1045     ImaCreatePanel(panelInfo, panel);
1046     // imeShow
1047     subscriber->ResetParam();
1048     InputMethodPanelTest::TestShowPanel(panel);
1049     InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::SHOW);
1050     {
1051         std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
1052         auto waitRet = imcPanelStatusListenerCv_.wait_for(
__anon68f8610b0902() 1053             lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [subscriber]() {
1054                 return subscriber->action_ == COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED
1055                        && subscriber->status_ == InputWindowStatus::SHOW;
1056             });
1057         EXPECT_TRUE(waitRet);
1058     }
1059     // imeHide
1060     subscriber->ResetParam();
1061     InputMethodPanelTest::TestHidePanel(panel);
1062     InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::HIDE);
1063     {
1064         std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
1065         auto waitRet = imcPanelStatusListenerCv_.wait_for(
__anon68f8610b0a02() 1066             lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [subscriber]() {
1067                 return subscriber->action_ == COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED
1068                        && subscriber->status_ == InputWindowStatus::HIDE;
1069             });
1070         EXPECT_TRUE(waitRet);
1071     }
1072     ImaDestroyPanel(panel);
1073     IdentityCheckerMock::SetBundleNameValid(false);
1074 }
1075 
1076 /**
1077 * @tc.name: testSetCallingWindow
1078 * @tc.desc: test SetCallingWindow
1079 * @tc.type: FUNC
1080 */
1081 HWTEST_F(InputMethodPanelTest, testSetCallingWindow, TestSize.Level0)
1082 {
1083     IMSA_HILOGI("InputMethodPanelTest::testSetCallingWindow start.");
1084     AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
1085     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1086     // not CreatePanel, SetCallingWindow failed
1087     uint32_t windowId = 8;
1088     auto ret = inputMethodPanel->SetCallingWindow(windowId);
1089     EXPECT_EQ(ret, ErrorCode::ERROR_PANEL_NOT_FOUND);
1090 
1091     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1092     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
1093     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1094 
1095     ret = inputMethodPanel->SetCallingWindow(windowId);
1096     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1097 
1098     ret = inputMethodPanel->DestroyPanel();
1099     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1100 }
1101 
1102 /*
1103 * @tc.name: testKeyboardPanelInfoChangeListenerRegister_001
1104 * @tc.desc: SOFT_KEYBOARD
1105 * @tc.type: FUNC
1106 */
1107 HWTEST_F(InputMethodPanelTest, testKeyboardPanelInfoChangeListenerRegister_001, TestSize.Level0)
1108 {
1109     IMSA_HILOGI("InputMethodPanelTest::testKeyboardPanelInfoChangeListenerRegister_001 start.");
1110     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
1111     std::shared_ptr<InputMethodPanel> panel = nullptr;
1112     ImaCreatePanel(panelInfo, panel);
1113     ASSERT_NE(panel, nullptr);
1114     if (isScbEnable_) {
1115         EXPECT_NE(panel->kbPanelInfoListener_, nullptr);
1116     } else {
1117         EXPECT_EQ(panel->kbPanelInfoListener_, nullptr);
1118     }
1119     ImaDestroyPanel(panel);
1120     EXPECT_EQ(panel->kbPanelInfoListener_, nullptr);
1121 }
1122 
1123 /*
1124 * @tc.name: testKeyboardPanelInfoChangeListenerRegister_002
1125 * @tc.desc: STATUS_BAR
1126 * @tc.type: FUNC
1127 */
1128 HWTEST_F(InputMethodPanelTest, testKeyboardPanelInfoChangeListenerRegister_002, TestSize.Level0)
1129 {
1130     IMSA_HILOGI("InputMethodPanelTest::testKeyboardPanelInfoChangeListenerRegister_002 start.");
1131     PanelInfo panelInfo = { .panelType = STATUS_BAR };
1132     std::shared_ptr<InputMethodPanel> panel = nullptr;
1133     ImaCreatePanel(panelInfo, panel);
1134     ASSERT_NE(panel, nullptr);
1135     EXPECT_EQ(panel->kbPanelInfoListener_, nullptr);
1136     ImaDestroyPanel(panel);
1137 }
1138 
1139 /**
1140 * @tc.name: testAdjustPanelRect_001
1141 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1142 * @tc.type: FUNC
1143 */
1144 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_001, TestSize.Level0)
1145 {
1146     InputMethodPanelTest::Attach();
1147     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1148     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1149     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1150     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1151     LayoutParams layoutParams;
1152     layoutParams.landscapeRect = {0, 0, 0, 0};
1153     layoutParams.portraitRect = {0, 0, 0, 0};
1154     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1155     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1156     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1157     InputMethodPanelTest::imc_->Close();
1158     TddUtil::DestroyWindow();
1159 }
1160 
1161 /**
1162 * @tc.name: testAdjustPanelRect_002
1163 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1164 * @tc.type: FUNC
1165 */
1166 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_002, TestSize.Level0)
1167 {
1168     InputMethodPanelTest::Attach();
1169     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1170     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1171     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1172     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1173     LayoutParams layoutParams;
1174     layoutParams.landscapeRect = {-1, 0, 0, 0};
1175     layoutParams.portraitRect = {-1, 0, 0, 0};
1176     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1177     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1178     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1179     InputMethodPanelTest::imc_->Close();
1180     TddUtil::DestroyWindow();
1181 }
1182 
1183 /**
1184 * @tc.name: testAdjustPanelRect_003
1185 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1186 * @tc.type: FUNC
1187 */
1188 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_003, TestSize.Level0)
1189 {
1190     InputMethodPanelTest::Attach();
1191     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1192     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1193     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1194     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1195     LayoutParams layoutParams;
1196     layoutParams.landscapeRect = {0, -1, 0, 0};
1197     layoutParams.portraitRect = {0, -1, 0, 0};
1198     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1199     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1200     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1201     InputMethodPanelTest::imc_->Close();
1202     TddUtil::DestroyWindow();
1203 }
1204 
1205 /**
1206 * @tc.name: testAdjustPanelRect_004
1207 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1208 * @tc.type: FUNC
1209 */
1210 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_004, TestSize.Level0)
1211 {
1212     InputMethodPanelTest::Attach();
1213     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1214     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1215     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1216     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1217     LayoutParams layoutParams;
1218     layoutParams.landscapeRect = {0, 0, -1, 0};
1219     layoutParams.portraitRect = {0, 0, -1, 0};
1220     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1221     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1222     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1223     InputMethodPanelTest::imc_->Close();
1224     TddUtil::DestroyWindow();
1225 }
1226 
1227 /**
1228 * @tc.name: testAdjustPanelRect_005
1229 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1230 * @tc.type: FUNC
1231 */
1232 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_005, TestSize.Level0)
1233 {
1234     InputMethodPanelTest::Attach();
1235     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1236     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1237     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1238     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1239     LayoutParams layoutParams;
1240     layoutParams.landscapeRect = {0, 0, 0, -1};
1241     layoutParams.portraitRect = {0, 0, 0, -1};
1242     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1243     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1244     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1245     InputMethodPanelTest::imc_->Close();
1246     TddUtil::DestroyWindow();
1247 }
1248 
1249 /**
1250 * @tc.name: testAdjustPanelRect_006
1251 * @tc.desc: Test AdjustPanelRect with FLG_FIXED valid params.
1252 * @tc.type: FUNC
1253 */
1254 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_006, TestSize.Level0)
1255 {
1256     InputMethodPanelTest::Attach();
1257     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1258     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1259     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1260     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1261     ASSERT_TRUE(defaultDisplay != nullptr);
1262     windowWidth_ = defaultDisplay->GetWidth();
1263     windowHeight_ = defaultDisplay->GetHeight();
1264     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1265     LayoutParams layoutParams;
1266     layoutParams.landscapeRect = {0, 0, windowHeight_, 0};
1267     layoutParams.portraitRect = {0, 0, windowWidth_, 0};
1268     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1269     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1270     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1271     InputMethodPanelTest::imc_->Close();
1272     TddUtil::DestroyWindow();
1273 }
1274 
1275 /**
1276 * @tc.name: testAdjustPanelRect_007
1277 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1278 * @tc.type: FUNC
1279 */
1280 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_007, TestSize.Level0)
1281 {
1282     InputMethodPanelTest::Attach();
1283     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1284     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1285     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1286     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1287     ASSERT_TRUE(defaultDisplay != nullptr);
1288     windowWidth_ = defaultDisplay->GetWidth();
1289     windowHeight_ = defaultDisplay->GetHeight();
1290     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1291     LayoutParams layoutParams;
1292     layoutParams.landscapeRect = {0, 0, windowHeight_ + 1, 0};
1293     layoutParams.portraitRect = {0, 0, windowWidth_ + 1, 0};
1294     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1295     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1296     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1297     InputMethodPanelTest::imc_->Close();
1298     TddUtil::DestroyWindow();
1299 }
1300 
1301 
1302 /**
1303 * @tc.name: testAdjustPanelRect_008
1304 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1305 * @tc.type: FUNC
1306 */
1307 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_008, TestSize.Level0)
1308 {
1309     InputMethodPanelTest::Attach();
1310     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1311     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1312     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1313     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1314     ASSERT_TRUE(defaultDisplay != nullptr);
1315     windowWidth_ = defaultDisplay->GetWidth();
1316     windowHeight_ = defaultDisplay->GetHeight();
1317     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1318     LayoutParams layoutParams;
1319     layoutParams.landscapeRect = {0, 0, windowHeight_, windowWidth_*0.7 + 1};
1320     layoutParams.portraitRect = {0, 0, windowWidth_, windowHeight_*0.7 + 1};
1321     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1322     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1323     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1324     InputMethodPanelTest::imc_->Close();
1325     TddUtil::DestroyWindow();
1326 }
1327 
1328 /**
1329 * @tc.name: testAdjustPanelRect_009
1330 * @tc.desc: Test AdjustPanelRect with FLG_FIXED valid params.
1331 * @tc.type: FUNC
1332 */
1333 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_009, TestSize.Level0)
1334 {
1335     InputMethodPanelTest::Attach();
1336     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1337     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1338     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1339     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1340     ASSERT_TRUE(defaultDisplay != nullptr);
1341     windowWidth_ = defaultDisplay->GetWidth();
1342     windowHeight_ = defaultDisplay->GetHeight();
1343     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1344     LayoutParams layoutParams;
1345     layoutParams.landscapeRect = {0, 0, windowHeight_, windowWidth_*0.7};
1346     layoutParams.portraitRect = {0, 0, windowWidth_, windowHeight_*0.7};
1347     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1348     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1349     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1350     InputMethodPanelTest::imc_->Close();
1351     TddUtil::DestroyWindow();
1352 }
1353 
1354 /**
1355 * @tc.name: testAdjustPanelRect_010
1356 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING valid params.
1357 * @tc.type: FUNC
1358 */
1359 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_010, TestSize.Level0)
1360 {
1361     InputMethodPanelTest::Attach();
1362     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1363     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1364     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1365     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1366     LayoutParams layoutParams;
1367     layoutParams.landscapeRect = {0, 0, 0, 0};
1368     layoutParams.portraitRect = {0, 0, 0, 0};
1369     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1370     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1371     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1372     InputMethodPanelTest::imc_->Close();
1373     TddUtil::DestroyWindow();
1374 }
1375 
1376 /**
1377 * @tc.name: testAdjustPanelRect_011
1378 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
1379 * @tc.type: FUNC
1380 */
1381 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_011, TestSize.Level0)
1382 {
1383     InputMethodPanelTest::Attach();
1384     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1385     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1386     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1387     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1388     LayoutParams layoutParams;
1389     layoutParams.landscapeRect = {-1, 0, 0, 0};
1390     layoutParams.portraitRect = {-1, 0, 0, 0};
1391     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1392     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1393     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1394     InputMethodPanelTest::imc_->Close();
1395     TddUtil::DestroyWindow();
1396 }
1397 
1398 /**
1399 * @tc.name: testAdjustPanelRect_012
1400 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
1401 * @tc.type: FUNC
1402 */
1403 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_012, TestSize.Level0)
1404 {
1405     InputMethodPanelTest::Attach();
1406     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1407     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1408     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1409     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1410     LayoutParams layoutParams;
1411     layoutParams.landscapeRect = {0, -1, 0, 0};
1412     layoutParams.portraitRect = {0, -1, 0, 0};
1413     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1414     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1415     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1416     InputMethodPanelTest::imc_->Close();
1417     TddUtil::DestroyWindow();
1418 }
1419 
1420 /**
1421 * @tc.name: testAdjustPanelRect_013
1422 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
1423 * @tc.type: FUNC
1424 */
1425 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_013, TestSize.Level0)
1426 {
1427     InputMethodPanelTest::Attach();
1428     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1429     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1430     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1431     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1432     LayoutParams layoutParams;
1433     layoutParams.landscapeRect = {0, 0, -1, 0};
1434     layoutParams.portraitRect = {0, 0, -1, 0};
1435     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1436     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1437     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1438     InputMethodPanelTest::imc_->Close();
1439     TddUtil::DestroyWindow();
1440 }
1441 
1442 /**
1443 * @tc.name: testAdjustPanelRect_014
1444 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING valid params.
1445 * @tc.type: FUNC
1446 */
1447 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_014, TestSize.Level0)
1448 {
1449     InputMethodPanelTest::Attach();
1450     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1451     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1452     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1453     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1454     ASSERT_TRUE(defaultDisplay != nullptr);
1455     windowWidth_ = defaultDisplay->GetWidth();
1456     windowHeight_ = defaultDisplay->GetHeight();
1457     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1458     LayoutParams layoutParams;
1459     layoutParams.landscapeRect = {0, 0, windowWidth_, 0};
1460     layoutParams.portraitRect = {0, 0, windowWidth_, 0};
1461     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1462     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1463     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1464     InputMethodPanelTest::imc_->Close();
1465     TddUtil::DestroyWindow();
1466 }
1467 
1468 /**
1469 * @tc.name: testAdjustPanelRect_015
1470 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
1471 * @tc.type: FUNC
1472 */
1473 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_015, TestSize.Level0)
1474 {
1475     InputMethodPanelTest::Attach();
1476     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1477     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1478     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1479     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1480     ASSERT_TRUE(defaultDisplay != nullptr);
1481     windowWidth_ = defaultDisplay->GetWidth();
1482     windowHeight_ = defaultDisplay->GetHeight();
1483     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1484     LayoutParams layoutParams;
1485     layoutParams.landscapeRect = {0, 0, windowHeight_+1, 0};
1486     layoutParams.portraitRect = {0, 0, windowWidth_+1, 0};
1487     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1488     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1489     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1490     InputMethodPanelTest::imc_->Close();
1491     TddUtil::DestroyWindow();
1492 }
1493 
1494 /**
1495 * @tc.name: testAdjustPanelRect_016
1496 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING valid params.
1497 * @tc.type: FUNC
1498 */
1499 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_016, TestSize.Level0)
1500 {
1501     InputMethodPanelTest::Attach();
1502     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1503     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1504     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1505     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1506     ASSERT_TRUE(defaultDisplay != nullptr);
1507     windowWidth_ = defaultDisplay->GetWidth();
1508     windowHeight_ = defaultDisplay->GetHeight();
1509     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1510     LayoutParams layoutParams;
1511     layoutParams.landscapeRect = {0, 0, windowHeight_, windowWidth_*0.7 + 1};
1512     layoutParams.portraitRect = {0, 0, windowWidth_, windowHeight_*0.7 + 1};
1513     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1514     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1515     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1516     InputMethodPanelTest::imc_->Close();
1517     TddUtil::DestroyWindow();
1518 }
1519 
1520 /**
1521 * @tc.name: testAdjustPanelRect_017
1522 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING valid params.
1523 * @tc.type: FUNC
1524 */
1525 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_017, TestSize.Level0)
1526 {
1527     InputMethodPanelTest::Attach();
1528     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1529     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1530     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1531     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1532     ASSERT_TRUE(defaultDisplay != nullptr);
1533     windowWidth_ = defaultDisplay->GetWidth();
1534     windowHeight_ = defaultDisplay->GetHeight();
1535     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1536     LayoutParams layoutParams;
1537     layoutParams.landscapeRect = {0, 0, windowHeight_, windowWidth_};
1538     layoutParams.portraitRect = {0, 0, windowWidth_, windowHeight_};
1539     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1540     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1541     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1542     InputMethodPanelTest::imc_->Close();
1543     TddUtil::DestroyWindow();
1544 }
1545 
1546 /**
1547 * @tc.name: testAdjustPanelRect_018
1548 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
1549 * @tc.type: FUNC
1550 */
1551 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_018, TestSize.Level0)
1552 {
1553     InputMethodPanelTest::Attach();
1554     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1555     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1556     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1557     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1558     ASSERT_TRUE(defaultDisplay != nullptr);
1559     windowWidth_ = defaultDisplay->GetWidth();
1560     windowHeight_ = defaultDisplay->GetHeight();
1561     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1562     LayoutParams layoutParams;
1563     layoutParams.landscapeRect = {0, 0, windowHeight_, windowWidth_ + 1};
1564     layoutParams.portraitRect = {0, 0, windowWidth_, windowHeight_ + 1};
1565     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1566     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1567     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1568     InputMethodPanelTest::imc_->Close();
1569     TddUtil::DestroyWindow();
1570 }
1571 
1572 /**
1573 * @tc.name: testSetPrivacyMode
1574 * @tc.desc: Test SetPrivacyMode.
1575 * @tc.type: FUNC
1576 */
1577 HWTEST_F(InputMethodPanelTest, testSetPrivacyMode, TestSize.Level0)
1578 {
1579     InputMethodPanelTest::Attach();
1580     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1581     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1582     InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1583     auto ret = inputMethodPanel->SetPrivacyMode(true);
1584     EXPECT_NE(ret, ErrorCode::NO_ERROR);
1585     InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1586     InputMethodPanelTest::imc_->Close();
1587     TddUtil::DestroyWindow();
1588 }
1589 
1590 } // namespace MiscServices
1591 } // namespace OHOS