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 #include "task_manager.h"
24 #undef private
25
26 #include <gtest/gtest.h>
27 #include <sys/time.h>
28 #include <unistd.h>
29
30 #include <condition_variable>
31 #include <cstdint>
32 #include <string>
33
34 #include "common_event_data.h"
35 #include "common_event_manager.h"
36 #include "common_event_subscribe_info.h"
37 #include "common_event_subscriber.h"
38 #include "common_event_support.h"
39 #include "display_manager.h"
40 #include "global.h"
41 #include "identity_checker_mock.h"
42 #include "ime_event_monitor_manager.h"
43 #include "input_method_ability.h"
44 #include "input_method_controller.h"
45 #include "input_method_engine_listener_impl.h"
46 #include "matching_skills.h"
47 #include "panel_status_listener.h"
48 #include "scene_board_judgement.h"
49 #include "scope_utils.h"
50 #include "tdd_util.h"
51 #include "text_listener.h"
52
53 using namespace testing::ext;
54 using namespace OHOS::Rosen;
55 namespace OHOS {
56 namespace MiscServices {
57 constexpr uint32_t IMC_WAIT_PANEL_STATUS_LISTEN_TIME = 500;
58 constexpr float FIXED_SOFT_KEYBOARD_PANEL_RATIO = 0.7;
59 constexpr float NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO = 1;
60 constexpr const char *COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED = "usual.event.imf.input_panel_status_changed";
61 constexpr const char *COMMON_EVENT_PARAM_PANEL_STATE = "panelState";
62 enum ListeningStatus : uint32_t {
63 ON,
64 OFF,
65 NONE
66 };
67 class InputMethodPanelTest : public testing::Test {
68 public:
69 static void SetUpTestCase(void);
70 static void TearDownTestCase(void);
71 void SetUp();
72 void TearDown();
73 static std::shared_ptr<InputMethodPanel> CreatePanel();
74 static void DestroyPanel(const std::shared_ptr<InputMethodPanel> &panel);
75 static void Attach();
76 static bool TriggerShowCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel);
77 static bool TriggerHideCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel);
78 static void ImaCreatePanel(const PanelInfo &info, std::shared_ptr<InputMethodPanel> &panel);
79 static void ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> &panel);
80 static void ImcPanelListeningTestRestore();
81 static void ImcPanelShowNumCheck(uint32_t num);
82 static void ImcPanelHideNumCheck(uint32_t num);
83 static void ImcPanelShowInfoCheck(const InputWindowInfo &windowInfo);
84 static void ImcPanelHideInfoCheck(const InputWindowInfo &windowInfo);
85 static void TestShowPanel(const std::shared_ptr<InputMethodPanel> &panel);
86 static void TestHidePanel(const std::shared_ptr<InputMethodPanel> &panel);
87 static void TestIsPanelShown(const PanelInfo &info, bool expectedResult);
88 static void TriggerPanelStatusChangeToImc(const std::shared_ptr<InputMethodPanel> &panel, InputWindowStatus status);
89 class PanelStatusListenerImpl : public PanelStatusListener {
90 public:
PanelStatusListenerImpl()91 PanelStatusListenerImpl()
92 {
93 std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("InputMethodPanelTest");
94 panelHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
95 }
96 ~PanelStatusListenerImpl() = default;
OnPanelStatus(uint32_t windowId,bool isShow)97 void OnPanelStatus(uint32_t windowId, bool isShow)
98 {
99 {
100 std::unique_lock<std::mutex> lock(InputMethodPanelTest::panelListenerLock_);
101 if (isShow) {
102 InputMethodPanelTest::status_ = InputWindowStatus::SHOW;
103 } else {
104 InputMethodPanelTest::status_ = InputWindowStatus::HIDE;
105 }
106 }
107 InputMethodPanelTest::panelListenerCv_.notify_one();
108 IMSA_HILOGI("PanelStatusListenerImpl OnPanelStatus in, isShow is %{public}s", isShow ? "true" : "false");
109 }
OnSizeChange(uint32_t windowId,const WindowSize & size)110 void OnSizeChange(uint32_t windowId, const WindowSize &size) {}
OnSizeChange(uint32_t windowId,const WindowSize & size,const PanelAdjustInfo & keyboardArea,const std::string & event)111 void OnSizeChange(
112 uint32_t windowId, const WindowSize &size, const PanelAdjustInfo &keyboardArea, const std::string &event)
113 {
114 }
115 };
116 static std::mutex imcPanelStatusListenerLock_;
117 static std::condition_variable imcPanelStatusListenerCv_;
118 static InputWindowStatus status_;
119 static InputWindowInfo windowInfo_;
120 static uint32_t imeShowCallbackNum_;
121 static uint32_t imeHideCallbackNum_;
122
123 static sptr<InputMethodController> imc_;
124 static sptr<InputMethodAbility> ima_;
125 static sptr<InputMethodSystemAbility> imsa_;
126 static uint32_t windowWidth_;
127 static uint32_t windowHeight_;
128 static std::condition_variable panelListenerCv_;
129 static std::mutex panelListenerLock_;
130 static constexpr uint32_t DELAY_TIME = 100;
131 static constexpr int32_t INTERVAL = 10;
132 static std::shared_ptr<AppExecFwk::EventHandler> panelHandler_;
133 static int32_t currentImeUid_;
134 static uint64_t currentImeTokenId_;
135 static sptr<OnTextChangedListener> textListener_;
136 static std::shared_ptr<InputMethodEngineListener> imeListener_;
137 static bool isScbEnable_;
138 };
139 class InputMethodSettingListenerImpl : public ImeEventListener {
140 public:
141 InputMethodSettingListenerImpl() = default;
142 ~InputMethodSettingListenerImpl() = default;
OnImeShow(const ImeWindowInfo & info)143 void OnImeShow(const ImeWindowInfo &info) override
144 {
145 IMSA_HILOGI("InputMethodPanelTest::OnImeShow");
146 std::unique_lock<std::mutex> lock(InputMethodPanelTest::imcPanelStatusListenerLock_);
147 InputMethodPanelTest::status_ = InputWindowStatus::SHOW;
148 InputMethodPanelTest::windowInfo_ = info.windowInfo;
149 InputMethodPanelTest::imeShowCallbackNum_++;
150 InputMethodPanelTest::imcPanelStatusListenerCv_.notify_one();
151 }
OnImeHide(const ImeWindowInfo & info)152 void OnImeHide(const ImeWindowInfo &info) override
153 {
154 IMSA_HILOGI("InputMethodPanelTest::OnImeHide");
155 std::unique_lock<std::mutex> lock(InputMethodPanelTest::imcPanelStatusListenerLock_);
156 InputMethodPanelTest::status_ = InputWindowStatus::HIDE;
157 InputMethodPanelTest::windowInfo_ = info.windowInfo;
158 InputMethodPanelTest::imeHideCallbackNum_++;
159 InputMethodPanelTest::imcPanelStatusListenerCv_.notify_one();
160 }
161 };
162
163 class TestEventSubscriber : public EventFwk::CommonEventSubscriber {
164 public:
TestEventSubscriber(const EventFwk::CommonEventSubscribeInfo & subscribeInfo)165 explicit TestEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo)
166 : EventFwk::CommonEventSubscriber(subscribeInfo)
167 {
168 }
OnReceiveEvent(const EventFwk::CommonEventData & data)169 void OnReceiveEvent(const EventFwk::CommonEventData &data)
170 {
171 std::unique_lock<std::mutex> lock(InputMethodPanelTest::imcPanelStatusListenerLock_);
172 auto const &want = data.GetWant();
173 action_ = want.GetAction();
174 bool visible = want.GetBoolParam(COMMON_EVENT_PARAM_PANEL_STATE, false);
175 status_ = visible ? InputWindowStatus::SHOW : InputWindowStatus::HIDE;
176 InputMethodPanelTest::imcPanelStatusListenerCv_.notify_one();
177 }
ResetParam()178 void ResetParam()
179 {
180 action_ = "";
181 status_ = InputWindowStatus::NONE;
182 }
183 std::string action_;
184 InputWindowStatus status_ { InputWindowStatus::NONE };
185 };
186
187 std::condition_variable InputMethodPanelTest::panelListenerCv_;
188 std::mutex InputMethodPanelTest::panelListenerLock_;
189 std::shared_ptr<AppExecFwk::EventHandler> InputMethodPanelTest::panelHandler_ { nullptr };
190 std::condition_variable InputMethodPanelTest::imcPanelStatusListenerCv_;
191 std::mutex InputMethodPanelTest::imcPanelStatusListenerLock_;
192 InputWindowStatus InputMethodPanelTest::status_ { InputWindowStatus::NONE };
193 InputWindowInfo InputMethodPanelTest::windowInfo_;
194 uint32_t InputMethodPanelTest::imeShowCallbackNum_ { 0 };
195 uint32_t InputMethodPanelTest::imeHideCallbackNum_ { 0 };
196 sptr<InputMethodController> InputMethodPanelTest::imc_ { nullptr };
197 sptr<InputMethodAbility> InputMethodPanelTest::ima_ { nullptr };
198 sptr<InputMethodSystemAbility> InputMethodPanelTest::imsa_ { nullptr };
199 uint32_t InputMethodPanelTest::windowWidth_ = 0;
200 uint32_t InputMethodPanelTest::windowHeight_ = 0;
201 uint64_t InputMethodPanelTest::currentImeTokenId_ = 0;
202 int32_t InputMethodPanelTest::currentImeUid_ = 0;
203 sptr<OnTextChangedListener> InputMethodPanelTest::textListener_ { nullptr };
204 std::shared_ptr<InputMethodEngineListener> InputMethodPanelTest::imeListener_ { nullptr };
205 bool InputMethodPanelTest::isScbEnable_ { false };
SetUpTestCase(void)206 void InputMethodPanelTest::SetUpTestCase(void)
207 {
208 IMSA_HILOGI("InputMethodPanelTest::SetUpTestCase");
209 IdentityCheckerMock::ResetParam();
210 isScbEnable_ = Rosen::SceneBoardJudgement::IsSceneBoardEnabled();
211 // storage current token id
212 TddUtil::StorageSelfTokenID();
213
214 auto listener = std::make_shared<InputMethodSettingListenerImpl>();
215 imc_ = InputMethodController::GetInstance();
216 textListener_ = new (std::nothrow) TextListener();
217 imeListener_ = std::make_shared<InputMethodEngineListenerImpl>();
218 // set token as current input method
219 std::shared_ptr<Property> property = InputMethodController::GetInstance()->GetCurrentInputMethod();
220 std::string bundleName = property != nullptr ? property->name : "default.inputmethod.unittest";
221 currentImeTokenId_ = TddUtil::GetTestTokenID(bundleName);
222 currentImeUid_ = TddUtil::GetUid(bundleName);
223
224 imsa_ = new (std::nothrow) InputMethodSystemAbility();
225 if (imsa_ == nullptr) {
226 return;
227 }
228 imsa_->OnStart();
229 imsa_->userId_ = TddUtil::GetCurrentUserId();
230 imsa_->identityChecker_ = std::make_shared<IdentityCheckerMock>();
231
232 imc_->abilityManager_ = imsa_;
233
234 ima_ = InputMethodAbility::GetInstance();
235 {
236 TokenScope scope(currentImeTokenId_);
237 ima_->InitConnect();
238 }
239 ima_->abilityManager_ = imsa_;
240 TddUtil::InitCurrentImePermissionInfo();
241 IdentityCheckerMock::SetBundleName(TddUtil::currentBundleNameMock_);
242 ima_->SetCoreAndAgent();
243 InputMethodPanelTest::ima_->SetImeListener(imeListener_);
244
245 ImaUtils::abilityManager_ = imsa_;
246 }
247
TearDownTestCase(void)248 void InputMethodPanelTest::TearDownTestCase(void)
249 {
250 IMSA_HILOGI("InputMethodPanelTest::TearDownTestCase");
251 TddUtil::RestoreSelfTokenID();
252 IdentityCheckerMock::ResetParam();
253 imsa_->OnStop();
254 ImaUtils::abilityManager_ = nullptr;
255 }
256
SetUp(void)257 void InputMethodPanelTest::SetUp(void)
258 {
259 IMSA_HILOGI("InputMethodPanelTest::SetUp");
260 TaskManager::GetInstance().SetInited(true);
261 }
262
TearDown(void)263 void InputMethodPanelTest::TearDown(void)
264 {
265 TddUtil::RestoreSelfTokenID();
266 IMSA_HILOGI("InputMethodPanelTest::TearDown");
267 std::this_thread::sleep_for(std::chrono::seconds(1));
268 TaskManager::GetInstance().Reset();
269 }
270
CreatePanel()271 std::shared_ptr<InputMethodPanel> InputMethodPanelTest::CreatePanel()
272 {
273 AccessScope scope(currentImeTokenId_, currentImeUid_);
274 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
275 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
276 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
277 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
278 return inputMethodPanel;
279 }
280
DestroyPanel(const std::shared_ptr<InputMethodPanel> & panel)281 void InputMethodPanelTest::DestroyPanel(const std::shared_ptr<InputMethodPanel> &panel)
282 {
283 ASSERT_NE(panel, nullptr);
284 AccessScope scope(currentImeTokenId_, currentImeUid_);
285 auto ret = panel->DestroyPanel();
286 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
287 }
288
ImaCreatePanel(const PanelInfo & info,std::shared_ptr<InputMethodPanel> & panel)289 void InputMethodPanelTest::ImaCreatePanel(const PanelInfo &info, std::shared_ptr<InputMethodPanel> &panel)
290 {
291 AccessScope scope(currentImeTokenId_, currentImeUid_);
292 auto ret = ima_->CreatePanel(nullptr, info, panel);
293 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
294 }
295
ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> & panel)296 void InputMethodPanelTest::ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> &panel)
297 {
298 AccessScope scope(currentImeTokenId_, currentImeUid_);
299 auto ret = ima_->DestroyPanel(panel);
300 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
301 }
302
Attach()303 void InputMethodPanelTest::Attach()
304 {
305 IdentityCheckerMock::SetFocused(true);
306 auto ret = imc_->Attach(textListener_, false);
307 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
308 std::this_thread::sleep_for(std::chrono::seconds(1));
309 IdentityCheckerMock::SetFocused(false);
310 }
311
TriggerShowCallback(std::shared_ptr<InputMethodPanel> & inputMethodPanel)312 bool InputMethodPanelTest::TriggerShowCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel)
313 {
314 IMSA_HILOGI("start");
315 status_ = InputWindowStatus::NONE;
316 panelHandler_->PostTask(
317 [&inputMethodPanel]() {
318 TestShowPanel(inputMethodPanel);
319 },
320 InputMethodPanelTest::INTERVAL);
321 {
322 std::unique_lock<std::mutex> lock(panelListenerLock_);
323 return panelListenerCv_.wait_for(lock, std::chrono::milliseconds(InputMethodPanelTest::DELAY_TIME), [] {
324 return status_ == InputWindowStatus::SHOW;
325 });
326 }
327 }
328
TriggerHideCallback(std::shared_ptr<InputMethodPanel> & inputMethodPanel)329 bool InputMethodPanelTest::TriggerHideCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel)
330 {
331 IMSA_HILOGI("start");
332 status_ = InputWindowStatus::NONE;
333 panelHandler_->PostTask(
334 [&inputMethodPanel]() {
335 TestHidePanel(inputMethodPanel);
336 },
337 InputMethodPanelTest::INTERVAL);
338 {
339 std::unique_lock<std::mutex> lock(panelListenerLock_);
340 return panelListenerCv_.wait_for(lock, std::chrono::milliseconds(InputMethodPanelTest::DELAY_TIME), [] {
341 return status_ == InputWindowStatus::HIDE;
342 });
343 }
344 }
345
ImcPanelShowNumCheck(uint32_t num)346 void InputMethodPanelTest::ImcPanelShowNumCheck(uint32_t num)
347 {
348 std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
349 if (num == 0) {
350 auto ret =
351 imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME));
352 EXPECT_EQ(ret, std::cv_status::timeout);
353 return;
354 }
355 bool ret =
356 imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [&num] {
357 return num == imeShowCallbackNum_;
358 });
359 EXPECT_TRUE(ret);
360 }
361
ImcPanelHideNumCheck(uint32_t num)362 void InputMethodPanelTest::ImcPanelHideNumCheck(uint32_t num)
363 {
364 std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
365 if (num == 0) {
366 auto ret =
367 imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME));
368 EXPECT_EQ(ret, std::cv_status::timeout);
369 return;
370 }
371 bool ret =
372 imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [&num] {
373 return num == imeHideCallbackNum_;
374 });
375 EXPECT_TRUE(ret);
376 }
377
ImcPanelShowInfoCheck(const InputWindowInfo & windowInfo)378 void InputMethodPanelTest::ImcPanelShowInfoCheck(const InputWindowInfo &windowInfo)
379 {
380 std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
381 bool ret =
382 imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [] {
383 return status_ == InputWindowStatus::SHOW;
384 });
385 EXPECT_TRUE(ret);
386 IMSA_HILOGI("InputMethodPanelTest::name: %{public}s, ret:[%{public}d, %{public}d,%{public}d, %{public}d]",
387 windowInfo_.name.c_str(), windowInfo_.top, windowInfo_.left, windowInfo_.width, windowInfo_.height);
388 EXPECT_FALSE(windowInfo_.name.empty());
389 }
390
ImcPanelHideInfoCheck(const InputWindowInfo & windowInfo)391 void InputMethodPanelTest::ImcPanelHideInfoCheck(const InputWindowInfo &windowInfo)
392 {
393 std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
394 bool ret =
395 imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [] {
396 return status_ == InputWindowStatus::HIDE;
397 });
398 EXPECT_TRUE(ret);
399 IMSA_HILOGI("InputMethodPanelTest::name: %{public}s, ret:[%{public}d, %{public}d,%{public}d, %{public}d]",
400 windowInfo_.name.c_str(), windowInfo_.top, windowInfo_.left, windowInfo_.width, windowInfo_.height);
401 EXPECT_FALSE(windowInfo_.name.empty());
402 }
403
ImcPanelListeningTestRestore()404 void InputMethodPanelTest::ImcPanelListeningTestRestore()
405 {
406 status_ = InputWindowStatus::NONE;
407 windowInfo_ = {};
408 imeShowCallbackNum_ = 0;
409 imeHideCallbackNum_ = 0;
410 }
411
TestShowPanel(const std::shared_ptr<InputMethodPanel> & panel)412 void InputMethodPanelTest::TestShowPanel(const std::shared_ptr<InputMethodPanel> &panel)
413 {
414 ASSERT_NE(panel, nullptr);
415 // set tokenId and uid as current ime
416 AccessScope scope(currentImeTokenId_, currentImeUid_);
417 auto ret = panel->ShowPanel();
418 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
419 }
420
TestHidePanel(const std::shared_ptr<InputMethodPanel> & panel)421 void InputMethodPanelTest::TestHidePanel(const std::shared_ptr<InputMethodPanel> &panel)
422 {
423 ASSERT_NE(panel, nullptr);
424 // set tokenId and uid as current ime
425 AccessScope scope(currentImeTokenId_, currentImeUid_);
426 auto ret = panel->HidePanel();
427 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
428 }
429
TestIsPanelShown(const PanelInfo & info,bool expectedResult)430 void InputMethodPanelTest::TestIsPanelShown(const PanelInfo &info, bool expectedResult)
431 {
432 IdentityCheckerMock::SetSystemApp(true);
433 bool result = !expectedResult;
434 auto ret = imc_->IsPanelShown(info, result);
435 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
436 EXPECT_EQ(result, expectedResult);
437 IdentityCheckerMock::SetSystemApp(false);
438 }
439
TriggerPanelStatusChangeToImc(const std::shared_ptr<InputMethodPanel> & panel,InputWindowStatus status)440 void InputMethodPanelTest::TriggerPanelStatusChangeToImc(
441 const std::shared_ptr<InputMethodPanel> &panel, InputWindowStatus status)
442 {
443 ASSERT_NE(panel, nullptr);
444 if (isScbEnable_) {
445 IdentityCheckerMock::SetBundleNameValid(true);
446 // add for SetTestTokenID in mainThread, but has no effect for other thread ipc
447 panel->PanelStatusChangeToImc(status, { 0, 0, 0, 0 });
448 IdentityCheckerMock::SetBundleNameValid(false);
449 }
450 }
451
452 /**
453 * @tc.name: testCreatePanel
454 * @tc.desc: Test CreatePanel.
455 * @tc.type: FUNC
456 */
457 HWTEST_F(InputMethodPanelTest, testCreatePanel, TestSize.Level0)
458 {
459 IMSA_HILOGI("InputMethodPanelTest::testCreatePanel start.");
460 AccessScope scope(currentImeTokenId_, currentImeUid_);
461 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
462 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
463 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
464 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
465 ret = inputMethodPanel->DestroyPanel();
466 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
467 }
468
469 /**
470 * @tc.name: testDestroyPanel
471 * @tc.desc: Test DestroyPanel.
472 * @tc.type: FUNC
473 */
474 HWTEST_F(InputMethodPanelTest, testDestroyPanel, TestSize.Level0)
475 {
476 IMSA_HILOGI("InputMethodPanelTest::testDestroyPanel start.");
477 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
478 // not CreatePanel, DestroyPanel failed
479 auto ret = inputMethodPanel->DestroyPanel();
480 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
481 }
482
483 /**
484 * @tc.name: testResizePanel001
485 * @tc.desc: Test Resize panel. Panels non fixed soft keyboard.
486 * @tc.type: FUNC
487 */
488 HWTEST_F(InputMethodPanelTest, testResizePanel001, TestSize.Level0)
489 {
490 IMSA_HILOGI("InputMethodPanelTest::testResizePanel001 start.");
491 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
492 // not CreatePanel, Resize failed
493 auto ret = inputMethodPanel->Resize(1, 1);
494 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
495
496 AccessScope scope(currentImeTokenId_, currentImeUid_);
497 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
498 ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
499 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
500 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
501 ASSERT_TRUE(defaultDisplay != nullptr);
502 int32_t width = defaultDisplay->GetWidth();
503 int32_t height = defaultDisplay->GetHeight();
504
505 ret = inputMethodPanel->Resize(width - 1, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1);
506 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
507
508 ret = inputMethodPanel->Resize(width, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO);
509 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
510
511 ret = inputMethodPanel->Resize(width + 1, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO);
512 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
513
514 ret = inputMethodPanel->Resize(width, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
515 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
516
517 ret = inputMethodPanel->Resize(width + 1, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
518 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
519
520 ret = inputMethodPanel->DestroyPanel();
521 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
522 }
523
524 /**
525 * @tc.name: testResizePanel002
526 * @tc.desc: Test Resize panel. Fixed soft keyboard panel .
527 * @tc.type: FUNC
528 */
529 HWTEST_F(InputMethodPanelTest, testResizePanel002, TestSize.Level0)
530 {
531 IMSA_HILOGI("InputMethodPanelTest::testResizePanel002 start.");
532 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
533 // not CreatePanel, Resize failed
534 auto ret = inputMethodPanel->Resize(1, 1);
535 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
536
537 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
538 AccessScope scope(currentImeTokenId_, currentImeUid_);
539 ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
540 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
541 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
542 ASSERT_TRUE(defaultDisplay != nullptr);
543 int32_t width = defaultDisplay->GetWidth();
544 int32_t height = defaultDisplay->GetHeight();
545
546 ret = inputMethodPanel->Resize(width - 1, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1);
547 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
548
549 ret = inputMethodPanel->Resize(width, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO);
550 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
551
552 ret = inputMethodPanel->Resize(width + 1, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO);
553 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
554
555 ret = inputMethodPanel->Resize(width, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
556 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
557
558 ret = inputMethodPanel->Resize(width + 1, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
559 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
560
561 ret = inputMethodPanel->DestroyPanel();
562 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
563 }
564
565 /**
566 * @tc.name: testMovePanel
567 * @tc.desc: Test Move panel. SOFT_KEYBOARD panel with FLG_FIXED can not be moved.
568 * @tc.type: FUNC
569 */
570 HWTEST_F(InputMethodPanelTest, testMovePanel, TestSize.Level0)
571 {
572 IMSA_HILOGI("InputMethodPanelTest::testMovePanel start.");
573 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
574 // not CreatePanel, MoveTo failed
575 auto ret = inputMethodPanel->MoveTo(10, 100);
576 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
577
578 AccessScope scope(currentImeTokenId_, currentImeUid_);
579 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
580 ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
581 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
582
583 ret = inputMethodPanel->MoveTo(10, 100);
584 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
585
586 ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_FLOATING);
587 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
588 ret = inputMethodPanel->MoveTo(10, 100);
589 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
590
591 ret = inputMethodPanel->DestroyPanel();
592 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
593
594 panelInfo.panelType = STATUS_BAR;
595 ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
596 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
597 ret = inputMethodPanel->MoveTo(10, 100);
598 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
599 ret = inputMethodPanel->DestroyPanel();
600 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
601 }
602
603 /**
604 * @tc.name: testShowPanel
605 * @tc.desc: Test Show panel.
606 * @tc.type: FUNC
607 */
608 HWTEST_F(InputMethodPanelTest, testShowPanel, TestSize.Level0)
609 {
610 IMSA_HILOGI("InputMethodPanelTest::testShowPanel start.");
611 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
612 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
613 // 0、not create panel, show panel failed.
614 auto ret = inputMethodPanel->ShowPanel();
615 EXPECT_EQ(ret, ErrorCode::ERROR_IMA_NULLPTR);
616
617 // 1 create panel, show success
618 AccessScope scope(currentImeTokenId_, currentImeUid_);
619 ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
620 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
621 ret = inputMethodPanel->ShowPanel();
622 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
623
624 auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
625 EXPECT_TRUE(statusListener != nullptr);
626 std::string type = "show";
627 inputMethodPanel->SetPanelStatusListener(statusListener, type);
628 ret = inputMethodPanel->ShowPanel();
629 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
630
631 // 2、show floating type panel.
632 ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_FLOATING);
633 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
634 ret = inputMethodPanel->ShowPanel();
635 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
636
637 ret = inputMethodPanel->DestroyPanel();
638 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
639
640 // 4、show status bar.
641 panelInfo.panelType = STATUS_BAR;
642 ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
643 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
644 ret = inputMethodPanel->ShowPanel();
645 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
646 ret = inputMethodPanel->HidePanel();
647 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
648 ret = inputMethodPanel->DestroyPanel();
649 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
650 }
651
652 /**
653 * @tc.name: testIsPanelShown_001
654 * @tc.desc: Test is panel shown.
655 * @tc.type: FUNC
656 */
657 HWTEST_F(InputMethodPanelTest, testIsPanelShown_001, TestSize.Level0)
658 {
659 IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_001 start.");
660 InputMethodPanelTest::Attach();
661 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
662 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
663 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
664
665 // query when fixed soft keyboard is showing
666 InputMethodPanelTest::TestShowPanel(inputMethodPanel);
667 InputMethodPanelTest::TestIsPanelShown(panelInfo, true);
668
669 // query when fixed soft keyboard is hidden
670 InputMethodPanelTest::TestHidePanel(inputMethodPanel);
671 InputMethodPanelTest::TestIsPanelShown(panelInfo, false);
672
673 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
674 InputMethodPanelTest::imc_->Close();
675 }
676
677 /**
678 * @tc.name: testIsPanelShown_002
679 * @tc.desc: Test is panel shown.
680 * @tc.type: FUNC
681 */
682 HWTEST_F(InputMethodPanelTest, testIsPanelShown_002, TestSize.Level0)
683 {
684 IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_002 start.");
685 InputMethodPanelTest::Attach();
686 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
687 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
688 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
689
690 // query panel with old info when panel changes its flag.
691 auto ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_FLOATING);
692 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
693 InputMethodPanelTest::TestShowPanel(inputMethodPanel);
694 InputMethodPanelTest::TestIsPanelShown(panelInfo, false);
695
696 // query panel with updated shown one's info when panel changes its flag.
697 panelInfo.panelFlag = PanelFlag::FLG_FLOATING;
698 InputMethodPanelTest::TestIsPanelShown(panelInfo, true);
699
700 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
701 InputMethodPanelTest::imc_->Close();
702 }
703
704 /**
705 * @tc.name: testIsPanelShown_003
706 * @tc.desc: Test is panel shown.
707 * @tc.type: FUNC
708 */
709 HWTEST_F(InputMethodPanelTest, testIsPanelShown_003, TestSize.Level0)
710 {
711 IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_003 start.");
712 InputMethodPanelTest::Attach();
713 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
714 PanelInfo panelInfo = { .panelType = STATUS_BAR };
715 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
716
717 // query status bar's status when it is showing
718 InputMethodPanelTest::TestShowPanel(inputMethodPanel);
719 InputMethodPanelTest::TestIsPanelShown(panelInfo, true);
720
721 // query status bar's status when it is hidden
722 InputMethodPanelTest::TestHidePanel(inputMethodPanel);
723 InputMethodPanelTest::TestIsPanelShown(panelInfo, false);
724
725 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
726 InputMethodPanelTest::imc_->Close();
727 }
728
729 /**
730 * @tc.name: testSetPanelStatusListener01
731 * @tc.desc: Test testSetPanelStatusListener01.
732 * @tc.type: FUNC
733 */
734 HWTEST_F(InputMethodPanelTest, testSetPanelStatusListener01, TestSize.Level0)
735 {
736 IMSA_HILOGI("InputMethodPanelTest::testSetPanelStatusListener01 start.");
737 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
738 auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
739 // on('show')->on('hide')->show->hide
740 inputMethodPanel->SetPanelStatusListener(statusListener, "show");
741 inputMethodPanel->SetPanelStatusListener(statusListener, "hide");
742
743 AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
744 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
745 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
746 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
747
748 EXPECT_TRUE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
749 EXPECT_TRUE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
750
751 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
752 }
753
754 /**
755 * @tc.name: testSetPanelStatusListener02
756 * @tc.desc: Test testSetPanelStatusListener02.
757 * @tc.type: FUNC
758 */
759 HWTEST_F(InputMethodPanelTest, testSetPanelStatusListener02, TestSize.Level0)
760 {
761 IMSA_HILOGI("InputMethodPanelTest::testSetPanelStatusListener02 start.");
762 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
763 auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
764
765 AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
766 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
767 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
768 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
769
770 // panelStatusListener_ not nullptr
771 inputMethodPanel->panelStatusListener_ = statusListener;
772
773 // subscribe 'show' after panel shown, get 'show' callback
774 InputMethodPanelTest::status_ = InputWindowStatus::NONE;
775 InputMethodPanelTest::TestShowPanel(inputMethodPanel);
776 inputMethodPanel->SetPanelStatusListener(statusListener, "show");
777 EXPECT_EQ(status_, InputWindowStatus::SHOW);
778
779 // subscribe 'hide' after panel hidden, get 'hide' callback
780 InputMethodPanelTest::status_ = InputWindowStatus::NONE;
781 InputMethodPanelTest::TestHidePanel(inputMethodPanel);
782 inputMethodPanel->SetPanelStatusListener(statusListener, "hide");
783 EXPECT_EQ(status_, InputWindowStatus::HIDE);
784
785 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
786 }
787
788 /**
789 * @tc.name: testGetPanelType
790 * @tc.desc: Test GetPanelType.
791 * @tc.type: FUNC
792 */
793 HWTEST_F(InputMethodPanelTest, testGetPanelType, TestSize.Level0)
794 {
795 IMSA_HILOGI("InputMethodPanelTest::testGetPanelType start.");
796 AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
797 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
798 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
799 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
800 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
801 auto type = inputMethodPanel->GetPanelType();
802 EXPECT_EQ(type, panelInfo.panelType);
803 ret = inputMethodPanel->DestroyPanel();
804 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
805 }
806
807 /**
808 * @tc.name: testGetPanelFlag
809 * @tc.desc: Test GetPanelFlag.
810 * @tc.type: FUNC
811 */
812 HWTEST_F(InputMethodPanelTest, testGetPanelFlag, TestSize.Level0)
813 {
814 IMSA_HILOGI("InputMethodPanelTest::testGetPanelFlag start.");
815 AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
816 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
817 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
818 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
819 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
820 auto flag = inputMethodPanel->GetPanelFlag();
821 EXPECT_EQ(flag, panelInfo.panelFlag);
822
823 ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_CANDIDATE_COLUMN);
824 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
825 flag = inputMethodPanel->GetPanelFlag();
826 EXPECT_EQ(flag, PanelFlag::FLG_CANDIDATE_COLUMN);
827
828 ret = inputMethodPanel->DestroyPanel();
829 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
830 }
831
832 /**
833 * @tc.name: testChangePanelFlag
834 * @tc.desc: Test ChangePanelFlag.
835 * @tc.type: FUNC
836 */
837 HWTEST_F(InputMethodPanelTest, testChangePanelFlag, TestSize.Level0)
838 {
839 IMSA_HILOGI("InputMethodPanelTest::testChangePanelFlag start.");
840 AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
841 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
842 PanelFlag flag = FLG_FLOATING;
843
844 // not CreatePanel, ChangePanelFlag failed
845 auto ret = inputMethodPanel->ChangePanelFlag(flag);
846 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
847
848 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
849 ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
850 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
851
852 // panelFlag is same with the original
853 ret = inputMethodPanel->ChangePanelFlag(flag);
854 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
855
856 // panelFlag modify to FLG_FIXED
857 flag = FLG_FIXED;
858 ret = inputMethodPanel->ChangePanelFlag(flag);
859 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
860
861 inputMethodPanel->DestroyPanel();
862
863 panelInfo = { .panelType = STATUS_BAR, .panelFlag = FLG_FLOATING };
864 ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
865 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
866 // panelType is STATUS_BAR, not allow ChangePanelFlag
867 ret = inputMethodPanel->ChangePanelFlag(flag);
868 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
869
870 inputMethodPanel->DestroyPanel();
871 }
872
873 /**
874 * @tc.name: testClearPanelListener
875 * @tc.desc: Test ClearPanelListener.
876 * @tc.type: FUNC
877 */
878 HWTEST_F(InputMethodPanelTest, testClearPanelListener, TestSize.Level0)
879 {
880 IMSA_HILOGI("InputMethodPanelTest::testClearPanelListener start.");
881 auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
882 auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
883 inputMethodPanel->SetPanelStatusListener(statusListener, "show");
884 inputMethodPanel->SetPanelStatusListener(statusListener, "hide");
885
886 inputMethodPanel->ClearPanelListener("show");
887 EXPECT_FALSE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
888 EXPECT_TRUE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
889
890 inputMethodPanel->ClearPanelListener("hide");
891 EXPECT_FALSE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
892 EXPECT_FALSE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
893
894 InputMethodPanelTest::DestroyPanel(inputMethodPanel);
895 }
896
897 /**
898 * @tc.name: testRegisterListener
899 * @tc.desc: Test ClearPanelListener.
900 * @tc.type: FUNC
901 */
902 HWTEST_F(InputMethodPanelTest, testRegisterListener, TestSize.Level0)
903 {
904 // on('show')->on('hide')->show->hide->off('show')->show->hide->on('show')->show
905 IMSA_HILOGI("InputMethodPanelTest::testRegisterListener start.");
906 auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
907
908 auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
909 inputMethodPanel->SetPanelStatusListener(statusListener, "show");
910 inputMethodPanel->SetPanelStatusListener(statusListener, "hide");
911 EXPECT_TRUE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
912 EXPECT_TRUE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
913
914 inputMethodPanel->ClearPanelListener("show");
915 EXPECT_FALSE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
916 EXPECT_TRUE(InputMethodPanelTest::TriggerHideCallback(inputMethodPanel));
917
918 inputMethodPanel->SetPanelStatusListener(statusListener, "show");
919 EXPECT_TRUE(InputMethodPanelTest::TriggerShowCallback(inputMethodPanel));
920
921 InputMethodPanelTest::DestroyPanel(inputMethodPanel);
922 }
923
924 /*
925 * @tc.name: testImcPanelListening_001
926 * @tc.desc: SOFT_KEYBOARD/FLG_FIXED, listener(system app)
927 * @tc.type: FUNC
928 */
929 HWTEST_F(InputMethodPanelTest, testImcPanelListening_001, TestSize.Level0)
930 {
931 IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_001 start.");
932 // system app for RegisterImeEventListener and currentIme for PanelStatusChangeToImc
933 IdentityCheckerMock::SetSystemApp(true);
934 IdentityCheckerMock::SetBundleNameValid(true);
935 auto listener = std::make_shared<InputMethodSettingListenerImpl>();
936 ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
937 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
938 std::shared_ptr<InputMethodPanel> panel = nullptr;
939 ImaCreatePanel(panelInfo, panel);
940 // imeShow
941 InputMethodPanelTest::ImcPanelListeningTestRestore();
942 InputMethodPanelTest::TestShowPanel(panel);
943 InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::SHOW);
944 InputMethodPanelTest::ImcPanelShowNumCheck(1);
945 // imeHide
946 InputMethodPanelTest::ImcPanelListeningTestRestore();
947 InputMethodPanelTest::TestHidePanel(panel);
948 InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::HIDE);
949 InputMethodPanelTest::ImcPanelHideNumCheck(1);
950 ImaDestroyPanel(panel);
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_002
959 * @tc.desc: SOFT_KEYBOARD/FLG_FLOATING, listener(system app)
960 * @tc.type: FUNC
961 */
962 HWTEST_F(InputMethodPanelTest, testImcPanelListening_002, TestSize.Level0)
963 {
964 IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_002 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 ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
970
971 AccessScope scope(currentImeTokenId_, currentImeUid_);
972 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
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(1);
980 // imeHide
981 InputMethodPanelTest::ImcPanelListeningTestRestore();
982 InputMethodPanelTest::TestHidePanel(panel);
983 InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::HIDE);
984 InputMethodPanelTest::ImcPanelHideNumCheck(1);
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_003
995 * @tc.desc: SOFT_KEYBOARD/FLG_CANDIDATE_COLUMN, listener(system app)
996 * @tc.type: FUNC
997 */
998 HWTEST_F(InputMethodPanelTest, testImcPanelListening_003, TestSize.Level0)
999 {
1000 IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_003 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 = SOFT_KEYBOARD, .panelFlag = FLG_CANDIDATE_COLUMN };
1009 std::shared_ptr<InputMethodPanel> panel = nullptr;
1010 ImaCreatePanel(panelInfo, panel);
1011 // imeShow
1012 InputMethodPanelTest::ImcPanelListeningTestRestore();
1013 InputMethodPanelTest::TestShowPanel(panel);
1014 InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::SHOW);
1015 InputMethodPanelTest::ImcPanelShowNumCheck(0);
1016 // imeHide
1017 InputMethodPanelTest::ImcPanelListeningTestRestore();
1018 InputMethodPanelTest::TestHidePanel(panel);
1019 InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::HIDE);
1020 InputMethodPanelTest::ImcPanelHideNumCheck(0);
1021 ImaDestroyPanel(panel);
1022
1023 ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
1024 EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
1025 IdentityCheckerMock::SetSystemApp(false);
1026 IdentityCheckerMock::SetBundleNameValid(false);
1027 }
1028
1029 /**
1030 * @tc.name: testImcPanelListening_004
1031 * @tc.desc: STATUS_BAR, listener(system app)
1032 * @tc.type: FUNC
1033 */
1034 HWTEST_F(InputMethodPanelTest, testImcPanelListening_004, TestSize.Level0)
1035 {
1036 IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_004 start.");
1037 // system app for RegisterImeEventListener and currentIme for PanelStatusChangeToImc
1038 IdentityCheckerMock::SetSystemApp(true);
1039 IdentityCheckerMock::SetBundleNameValid(true);
1040 auto listener = std::make_shared<InputMethodSettingListenerImpl>();
1041
1042 ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
1043
1044 PanelInfo panelInfo = { .panelType = STATUS_BAR };
1045 std::shared_ptr<InputMethodPanel> panel = nullptr;
1046 ImaCreatePanel(panelInfo, panel);
1047 // imeShow
1048 InputMethodPanelTest::ImcPanelListeningTestRestore();
1049 InputMethodPanelTest::TestShowPanel(panel);
1050 InputMethodPanelTest::ImcPanelShowNumCheck(0);
1051 // imeHide
1052 InputMethodPanelTest::ImcPanelListeningTestRestore();
1053 InputMethodPanelTest::TestHidePanel(panel);
1054 InputMethodPanelTest::ImcPanelHideNumCheck(0);
1055 ImaDestroyPanel(panel);
1056
1057 ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(
1058 EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener);
1059 IdentityCheckerMock::SetSystemApp(false);
1060 IdentityCheckerMock::SetBundleNameValid(false);
1061 }
1062
1063 /*
1064 * @tc.name: testPanelStatusChangeEventPublicTest
1065 * @tc.desc: test subscriber can receive the panel status change event published by IMSA
1066 * @tc.type: FUNC
1067 */
1068 HWTEST_F(InputMethodPanelTest, testPanelStatusChangeEventPublicTest, TestSize.Level0)
1069 {
1070 IMSA_HILOGI("InputMethodPanelTest::testPanelStatusChangeEventPublicTest start.");
1071 // currentIme for PanelStatusChangeToImc
1072 IdentityCheckerMock::SetBundleNameValid(true);
1073 EventFwk::MatchingSkills matchingSkills;
1074 matchingSkills.AddEvent(COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED);
1075 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
1076 auto subscriber = std::make_shared<TestEventSubscriber>(subscriberInfo);
1077 auto ret = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber);
1078 EXPECT_TRUE(ret);
1079 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1080 std::shared_ptr<InputMethodPanel> panel = nullptr;
1081 ImaCreatePanel(panelInfo, panel);
1082 // imeShow
1083 subscriber->ResetParam();
1084 InputMethodPanelTest::TestShowPanel(panel);
1085 InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::SHOW);
1086 {
1087 std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
1088 auto waitRet = imcPanelStatusListenerCv_.wait_for(
__anon633758130902() 1089 lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [subscriber]() {
1090 return subscriber->action_ == COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED &&
1091 subscriber->status_ == InputWindowStatus::SHOW;
1092 });
1093 EXPECT_TRUE(waitRet);
1094 }
1095 // imeHide
1096 subscriber->ResetParam();
1097 InputMethodPanelTest::TestHidePanel(panel);
1098 InputMethodPanelTest::TriggerPanelStatusChangeToImc(panel, InputWindowStatus::HIDE);
1099 {
1100 std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
1101 auto waitRet = imcPanelStatusListenerCv_.wait_for(
__anon633758130a02() 1102 lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [subscriber]() {
1103 return subscriber->action_ == COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED &&
1104 subscriber->status_ == InputWindowStatus::HIDE;
1105 });
1106 EXPECT_TRUE(waitRet);
1107 }
1108 ImaDestroyPanel(panel);
1109 IdentityCheckerMock::SetBundleNameValid(false);
1110 }
1111
1112 /**
1113 * @tc.name: testSetCallingWindow
1114 * @tc.desc: test SetCallingWindow
1115 * @tc.type: FUNC
1116 */
1117 HWTEST_F(InputMethodPanelTest, testSetCallingWindow, TestSize.Level0)
1118 {
1119 IMSA_HILOGI("InputMethodPanelTest::testSetCallingWindow start.");
1120 AccessScope scope(InputMethodPanelTest::currentImeTokenId_, InputMethodPanelTest::currentImeUid_);
1121 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1122 // not CreatePanel, SetCallingWindow failed
1123 uint32_t windowId = 8;
1124 auto ret = inputMethodPanel->SetCallingWindow(windowId);
1125 EXPECT_EQ(ret, ErrorCode::ERROR_PANEL_NOT_FOUND);
1126
1127 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1128 ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
1129 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1130
1131 ret = inputMethodPanel->SetCallingWindow(windowId);
1132 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1133
1134 ret = inputMethodPanel->DestroyPanel();
1135 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1136 }
1137
1138 /*
1139 * @tc.name: testKeyboardPanelInfoChangeListenerRegister_001
1140 * @tc.desc: SOFT_KEYBOARD
1141 * @tc.type: FUNC
1142 */
1143 HWTEST_F(InputMethodPanelTest, testKeyboardPanelInfoChangeListenerRegister_001, TestSize.Level0)
1144 {
1145 IMSA_HILOGI("InputMethodPanelTest::testKeyboardPanelInfoChangeListenerRegister_001 start.");
1146 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
1147 std::shared_ptr<InputMethodPanel> panel = nullptr;
1148 ImaCreatePanel(panelInfo, panel);
1149 ASSERT_NE(panel, nullptr);
1150 if (isScbEnable_) {
1151 EXPECT_NE(panel->kbPanelInfoListener_, nullptr);
1152 } else {
1153 EXPECT_EQ(panel->kbPanelInfoListener_, nullptr);
1154 }
1155 ImaDestroyPanel(panel);
1156 EXPECT_EQ(panel->kbPanelInfoListener_, nullptr);
1157 }
1158
1159 /*
1160 * @tc.name: testKeyboardPanelInfoChangeListenerRegister_002
1161 * @tc.desc: STATUS_BAR
1162 * @tc.type: FUNC
1163 */
1164 HWTEST_F(InputMethodPanelTest, testKeyboardPanelInfoChangeListenerRegister_002, TestSize.Level0)
1165 {
1166 IMSA_HILOGI("InputMethodPanelTest::testKeyboardPanelInfoChangeListenerRegister_002 start.");
1167 PanelInfo panelInfo = { .panelType = STATUS_BAR };
1168 std::shared_ptr<InputMethodPanel> panel = nullptr;
1169 ImaCreatePanel(panelInfo, panel);
1170 ASSERT_NE(panel, nullptr);
1171 EXPECT_EQ(panel->kbPanelInfoListener_, nullptr);
1172 ImaDestroyPanel(panel);
1173 }
1174
1175 /**
1176 * @tc.name: testAdjustPanelRect_001
1177 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1178 * @tc.type: FUNC
1179 */
1180 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_001, TestSize.Level0)
1181 {
1182 InputMethodPanelTest::Attach();
1183 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1184 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1185 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1186 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1187 LayoutParams layoutParams;
1188 layoutParams.landscapeRect = { 0, 0, 0, 0 };
1189 layoutParams.portraitRect = { 0, 0, 0, 0 };
1190 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1191 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1192 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1193 InputMethodPanelTest::imc_->Close();
1194 TddUtil::DestroyWindow();
1195 }
1196
1197 /**
1198 * @tc.name: testAdjustPanelRect_002
1199 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1200 * @tc.type: FUNC
1201 */
1202 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_002, TestSize.Level0)
1203 {
1204 InputMethodPanelTest::Attach();
1205 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1206 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1207 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1208 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1209 LayoutParams layoutParams;
1210 layoutParams.landscapeRect = { -1, 0, 0, 0 };
1211 layoutParams.portraitRect = { -1, 0, 0, 0 };
1212 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1213 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1214 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1215 InputMethodPanelTest::imc_->Close();
1216 TddUtil::DestroyWindow();
1217 }
1218
1219 /**
1220 * @tc.name: testAdjustPanelRect_003
1221 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1222 * @tc.type: FUNC
1223 */
1224 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_003, TestSize.Level0)
1225 {
1226 InputMethodPanelTest::Attach();
1227 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1228 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1229 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1230 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1231 LayoutParams layoutParams;
1232 layoutParams.landscapeRect = { 0, -1, 0, 0 };
1233 layoutParams.portraitRect = { 0, -1, 0, 0 };
1234 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1235 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1236 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1237 InputMethodPanelTest::imc_->Close();
1238 TddUtil::DestroyWindow();
1239 }
1240
1241 /**
1242 * @tc.name: testAdjustPanelRect_004
1243 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1244 * @tc.type: FUNC
1245 */
1246 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_004, TestSize.Level0)
1247 {
1248 InputMethodPanelTest::Attach();
1249 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1250 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1251 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1252 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1253 LayoutParams layoutParams;
1254 layoutParams.landscapeRect = { 0, 0, -1, 0 };
1255 layoutParams.portraitRect = { 0, 0, -1, 0 };
1256 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1257 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1258 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1259 InputMethodPanelTest::imc_->Close();
1260 TddUtil::DestroyWindow();
1261 }
1262
1263 /**
1264 * @tc.name: testAdjustPanelRect_005
1265 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1266 * @tc.type: FUNC
1267 */
1268 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_005, TestSize.Level0)
1269 {
1270 InputMethodPanelTest::Attach();
1271 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1272 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1273 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1274 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1275 LayoutParams layoutParams;
1276 layoutParams.landscapeRect = { 0, 0, 0, -1 };
1277 layoutParams.portraitRect = { 0, 0, 0, -1 };
1278 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1279 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1280 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1281 InputMethodPanelTest::imc_->Close();
1282 TddUtil::DestroyWindow();
1283 }
1284
1285 /**
1286 * @tc.name: testAdjustPanelRect_006
1287 * @tc.desc: Test AdjustPanelRect with FLG_FIXED valid params.
1288 * @tc.type: FUNC
1289 */
1290 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_006, TestSize.Level0)
1291 {
1292 InputMethodPanelTest::Attach();
1293 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1294 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1295 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1296 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1297 ASSERT_TRUE(defaultDisplay != nullptr);
1298 windowWidth_ = defaultDisplay->GetWidth();
1299 windowHeight_ = defaultDisplay->GetHeight();
1300 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1301 LayoutParams layoutParams;
1302 layoutParams.landscapeRect = { 0, 0, windowHeight_, 0 };
1303 layoutParams.portraitRect = { 0, 0, windowWidth_, 0 };
1304 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1305 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1306 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1307 InputMethodPanelTest::imc_->Close();
1308 TddUtil::DestroyWindow();
1309 }
1310
1311 /**
1312 * @tc.name: testAdjustPanelRect_007
1313 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1314 * @tc.type: FUNC
1315 */
1316 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_007, TestSize.Level0)
1317 {
1318 InputMethodPanelTest::Attach();
1319 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1320 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1321 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1322 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1323 ASSERT_TRUE(defaultDisplay != nullptr);
1324 windowWidth_ = defaultDisplay->GetWidth();
1325 windowHeight_ = defaultDisplay->GetHeight();
1326 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1327 LayoutParams layoutParams;
1328 layoutParams.landscapeRect = { 0, 0, windowHeight_ + 1, 0 };
1329 layoutParams.portraitRect = { 0, 0, windowWidth_ + 1, 0 };
1330 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1331 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1332 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1333 InputMethodPanelTest::imc_->Close();
1334 TddUtil::DestroyWindow();
1335 }
1336
1337 /**
1338 * @tc.name: testAdjustPanelRect_008
1339 * @tc.desc: Test AdjustPanelRect with FLG_FIXED invalid params.
1340 * @tc.type: FUNC
1341 */
1342 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_008, TestSize.Level0)
1343 {
1344 InputMethodPanelTest::Attach();
1345 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1346 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1347 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1348 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1349 ASSERT_TRUE(defaultDisplay != nullptr);
1350 windowWidth_ = defaultDisplay->GetWidth();
1351 windowHeight_ = defaultDisplay->GetHeight();
1352 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1353 LayoutParams layoutParams;
1354 layoutParams.landscapeRect = { 0, 0, windowHeight_, windowWidth_ * 0.7 + 1 };
1355 layoutParams.portraitRect = { 0, 0, windowWidth_, windowHeight_ * 0.7 + 1 };
1356 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1357 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1358 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1359 InputMethodPanelTest::imc_->Close();
1360 TddUtil::DestroyWindow();
1361 }
1362
1363 /**
1364 * @tc.name: testAdjustPanelRect_009
1365 * @tc.desc: Test AdjustPanelRect with FLG_FIXED valid params.
1366 * @tc.type: FUNC
1367 */
1368 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_009, TestSize.Level0)
1369 {
1370 InputMethodPanelTest::Attach();
1371 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1372 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1373 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1374 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1375 ASSERT_TRUE(defaultDisplay != nullptr);
1376 windowWidth_ = defaultDisplay->GetWidth();
1377 windowHeight_ = defaultDisplay->GetHeight();
1378 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1379 LayoutParams layoutParams;
1380 layoutParams.landscapeRect = { 0, 0, windowHeight_, windowWidth_ * 0.7 };
1381 layoutParams.portraitRect = { 0, 0, windowWidth_, windowHeight_ * 0.7 };
1382 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1383 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1384 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1385 InputMethodPanelTest::imc_->Close();
1386 TddUtil::DestroyWindow();
1387 }
1388
1389 /**
1390 * @tc.name: testAdjustPanelRect_010
1391 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING valid params.
1392 * @tc.type: FUNC
1393 */
1394 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_010, TestSize.Level0)
1395 {
1396 InputMethodPanelTest::Attach();
1397 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1398 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1399 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1400 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1401 LayoutParams layoutParams;
1402 layoutParams.landscapeRect = { 0, 0, 0, 0 };
1403 layoutParams.portraitRect = { 0, 0, 0, 0 };
1404 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1405 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1406 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1407 InputMethodPanelTest::imc_->Close();
1408 TddUtil::DestroyWindow();
1409 }
1410
1411 /**
1412 * @tc.name: testAdjustPanelRect_011
1413 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
1414 * @tc.type: FUNC
1415 */
1416 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_011, TestSize.Level0)
1417 {
1418 InputMethodPanelTest::Attach();
1419 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1420 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1421 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1422 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1423 LayoutParams layoutParams;
1424 layoutParams.landscapeRect = { -1, 0, 0, 0 };
1425 layoutParams.portraitRect = { -1, 0, 0, 0 };
1426 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1427 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1428 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1429 InputMethodPanelTest::imc_->Close();
1430 TddUtil::DestroyWindow();
1431 }
1432
1433 /**
1434 * @tc.name: testAdjustPanelRect_012
1435 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
1436 * @tc.type: FUNC
1437 */
1438 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_012, TestSize.Level0)
1439 {
1440 InputMethodPanelTest::Attach();
1441 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1442 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1443 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1444 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1445 LayoutParams layoutParams;
1446 layoutParams.landscapeRect = { 0, -1, 0, 0 };
1447 layoutParams.portraitRect = { 0, -1, 0, 0 };
1448 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1449 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1450 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1451 InputMethodPanelTest::imc_->Close();
1452 TddUtil::DestroyWindow();
1453 }
1454
1455 /**
1456 * @tc.name: testAdjustPanelRect_013
1457 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
1458 * @tc.type: FUNC
1459 */
1460 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_013, TestSize.Level0)
1461 {
1462 InputMethodPanelTest::Attach();
1463 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1464 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1465 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1466 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1467 LayoutParams layoutParams;
1468 layoutParams.landscapeRect = { 0, 0, -1, 0 };
1469 layoutParams.portraitRect = { 0, 0, -1, 0 };
1470 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1471 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1472 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1473 InputMethodPanelTest::imc_->Close();
1474 TddUtil::DestroyWindow();
1475 }
1476
1477 /**
1478 * @tc.name: testAdjustPanelRect_014
1479 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING valid params.
1480 * @tc.type: FUNC
1481 */
1482 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_014, TestSize.Level0)
1483 {
1484 InputMethodPanelTest::Attach();
1485 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1486 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1487 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1488 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1489 ASSERT_TRUE(defaultDisplay != nullptr);
1490 windowWidth_ = defaultDisplay->GetWidth();
1491 windowHeight_ = defaultDisplay->GetHeight();
1492 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1493 LayoutParams layoutParams;
1494 layoutParams.landscapeRect = { 0, 0, windowWidth_, 0 };
1495 layoutParams.portraitRect = { 0, 0, windowWidth_, 0 };
1496 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1497 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1498 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1499 InputMethodPanelTest::imc_->Close();
1500 TddUtil::DestroyWindow();
1501 }
1502
1503 /**
1504 * @tc.name: testAdjustPanelRect_015
1505 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
1506 * @tc.type: FUNC
1507 */
1508 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_015, TestSize.Level0)
1509 {
1510 InputMethodPanelTest::Attach();
1511 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1512 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1513 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1514 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1515 ASSERT_TRUE(defaultDisplay != nullptr);
1516 windowWidth_ = defaultDisplay->GetWidth();
1517 windowHeight_ = defaultDisplay->GetHeight();
1518 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1519 LayoutParams layoutParams;
1520 layoutParams.landscapeRect = { 0, 0, windowHeight_ + 1, 0 };
1521 layoutParams.portraitRect = { 0, 0, windowWidth_ + 1, 0 };
1522 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1523 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1524 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1525 InputMethodPanelTest::imc_->Close();
1526 TddUtil::DestroyWindow();
1527 }
1528
1529 /**
1530 * @tc.name: testAdjustPanelRect_016
1531 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING valid params.
1532 * @tc.type: FUNC
1533 */
1534 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_016, TestSize.Level0)
1535 {
1536 InputMethodPanelTest::Attach();
1537 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1538 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1539 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1540 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1541 ASSERT_TRUE(defaultDisplay != nullptr);
1542 windowWidth_ = defaultDisplay->GetWidth();
1543 windowHeight_ = defaultDisplay->GetHeight();
1544 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1545 LayoutParams layoutParams;
1546 layoutParams.landscapeRect = { 0, 0, windowHeight_, windowWidth_ * 0.7 + 1 };
1547 layoutParams.portraitRect = { 0, 0, windowWidth_, windowHeight_ * 0.7 + 1 };
1548 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1549 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1550 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1551 InputMethodPanelTest::imc_->Close();
1552 TddUtil::DestroyWindow();
1553 }
1554
1555 /**
1556 * @tc.name: testAdjustPanelRect_017
1557 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING valid params.
1558 * @tc.type: FUNC
1559 */
1560 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_017, TestSize.Level0)
1561 {
1562 InputMethodPanelTest::Attach();
1563 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1564 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1565 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1566 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1567 ASSERT_TRUE(defaultDisplay != nullptr);
1568 windowWidth_ = defaultDisplay->GetWidth();
1569 windowHeight_ = defaultDisplay->GetHeight();
1570 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1571 LayoutParams layoutParams;
1572 layoutParams.landscapeRect = { 0, 0, windowHeight_, windowWidth_ };
1573 layoutParams.portraitRect = { 0, 0, windowWidth_, windowHeight_ };
1574 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1575 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1576 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1577 InputMethodPanelTest::imc_->Close();
1578 TddUtil::DestroyWindow();
1579 }
1580
1581 /**
1582 * @tc.name: testAdjustPanelRect_018
1583 * @tc.desc: Test AdjustPanelRect with FLG_FLOATING invalid params.
1584 * @tc.type: FUNC
1585 */
1586 HWTEST_F(InputMethodPanelTest, testAdjustPanelRect_018, TestSize.Level0)
1587 {
1588 InputMethodPanelTest::Attach();
1589 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1590 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1591 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1592 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1593 ASSERT_TRUE(defaultDisplay != nullptr);
1594 windowWidth_ = defaultDisplay->GetWidth();
1595 windowHeight_ = defaultDisplay->GetHeight();
1596 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
1597 LayoutParams layoutParams;
1598 layoutParams.landscapeRect = { 0, 0, windowHeight_, windowWidth_ + 1 };
1599 layoutParams.portraitRect = { 0, 0, windowWidth_, windowHeight_ + 1 };
1600 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams);
1601 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1602 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1603 InputMethodPanelTest::imc_->Close();
1604 TddUtil::DestroyWindow();
1605 }
1606
1607 /**
1608 * @tc.name: testAdjustKeyboard_001
1609 * @tc.desc: Test AdjustKeyboard
1610 * @tc.type: FUNC
1611 */
1612 HWTEST_F(InputMethodPanelTest, testAdjustKeyboard_001, TestSize.Level0)
1613 {
1614 InputMethodPanelTest::Attach();
1615 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1616 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1617 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1618 auto ret = inputMethodPanel->AdjustKeyboard();
1619 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1620 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1621 InputMethodPanelTest::imc_->Close();
1622 TddUtil::DestroyWindow();
1623 }
1624
1625 /**
1626 * @tc.name: testSetPrivacyMode
1627 * @tc.desc: Test SetPrivacyMode.
1628 * @tc.type: FUNC
1629 */
1630 HWTEST_F(InputMethodPanelTest, testSetPrivacyMode, TestSize.Level0)
1631 {
1632 InputMethodPanelTest::Attach();
1633 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1634 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1635 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1636 auto ret = inputMethodPanel->SetPrivacyMode(true);
1637 EXPECT_NE(ret, ErrorCode::NO_ERROR);
1638 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1639 InputMethodPanelTest::imc_->Close();
1640 TddUtil::DestroyWindow();
1641 }
1642
1643 /**
1644 * @tc.name: testSetPanelProperties
1645 * @tc.desc: Test SetPanelProperties.
1646 * @tc.type: FUNC
1647 */
1648 HWTEST_F(InputMethodPanelTest, testSetPanelProperties, TestSize.Level0)
1649 {
1650 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1651 auto ret = inputMethodPanel->SetPanelProperties();
1652 EXPECT_EQ(ret, ErrorCode::ERROR_OPERATE_PANEL);
1653 inputMethodPanel->UnregisterKeyboardPanelInfoChangeListener();
1654 ret = inputMethodPanel->SetPrivacyMode(false);
1655 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1656 }
1657
1658 /**
1659 * @tc.name: testGetKeyboardSize
1660 * @tc.desc: Test GetKeyboardSize.
1661 * @tc.type: FUNC
1662 */
1663 HWTEST_F(InputMethodPanelTest, testGetKeyboardSize, TestSize.Level0)
1664 {
1665 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1666 auto boardSize = inputMethodPanel->GetKeyboardSize();
1667 EXPECT_EQ(boardSize.width, 0);
1668 EXPECT_EQ(boardSize.height, 0);
1669 }
1670
1671 /**
1672 * @tc.name: testMarkListener
1673 * @tc.desc: Test MarkListener.
1674 * @tc.type: FUNC
1675 */
1676 HWTEST_F(InputMethodPanelTest, testMarkListener, TestSize.Level0)
1677 {
1678 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1679 auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
1680 auto ret = inputMethodPanel->SetPanelStatusListener(statusListener, "text");
1681 EXPECT_FALSE(ret);
1682 inputMethodPanel->ClearPanelListener("text");
1683 ret = inputMethodPanel->MarkListener("contenInfo", true);
1684 EXPECT_FALSE(ret);
1685 ret = inputMethodPanel->MarkListener("sizeChange", true);
1686 EXPECT_TRUE(ret);
1687 }
1688
1689 /**
1690 * @tc.name: testSizeChange
1691 * @tc.desc: Test SizeChange.
1692 * @tc.type: FUNC
1693 */
1694 HWTEST_F(InputMethodPanelTest, testSizeChange, TestSize.Level0)
1695 {
1696 AccessScope scope(currentImeTokenId_, currentImeUid_);
1697 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1698 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1699 auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
1700 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
1701 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1702 inputMethodPanel->panelStatusListener_ = statusListener;
1703 WindowSize windowSize;
1704 ret = inputMethodPanel->SizeChange(windowSize);
1705 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1706 ret = inputMethodPanel->DestroyPanel();
1707 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1708 }
1709
1710 /**
1711 * @tc.name: testSetTextFieldAvoidInfo01
1712 * @tc.desc: Test SetTextFieldAvoidInfo.
1713 * @tc.type: FUNC
1714 */
1715 HWTEST_F(InputMethodPanelTest, testSetTextFieldAvoidInfo01, TestSize.Level0)
1716 {
1717 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1718 auto ret = inputMethodPanel->SetTextFieldAvoidInfo(0, 0);
1719 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1720 }
1721
1722 /**
1723 * @tc.name: testSetTextFieldAvoidInfo02
1724 * @tc.desc: Test SetTextFieldAvoidInfo.
1725 * @tc.type: FUNC
1726 */
1727 HWTEST_F(InputMethodPanelTest, testSetTextFieldAvoidInfo02, TestSize.Level0)
1728 {
1729 InputMethodPanelTest::Attach();
1730 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1731 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1732 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1733 auto ret = inputMethodPanel->SetTextFieldAvoidInfo(0, 0);
1734 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1735 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1736 InputMethodPanelTest::imc_->Close();
1737 TddUtil::DestroyWindow();
1738 }
1739
1740 /**
1741 * @tc.name: testGetCallingWindowInfo01
1742 * @tc.desc: Test GetCallingWindowInfo.
1743 * @tc.type: FUNC
1744 */
1745 HWTEST_F(InputMethodPanelTest, testGetCallingWindowInfo01, TestSize.Level0)
1746 {
1747 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1748 CallingWindowInfo windowInfo;
1749 auto ret = inputMethodPanel->GetCallingWindowInfo(windowInfo);
1750 EXPECT_EQ(ret, ErrorCode::ERROR_PANEL_NOT_FOUND);
1751 }
1752
1753 /**
1754 * @tc.name: testGetCallingWindowInfo02
1755 * @tc.desc: Test GetCallingWindowInfo.
1756 * @tc.type: FUNC
1757 */
1758 HWTEST_F(InputMethodPanelTest, testGetCallingWindowInfo02, TestSize.Level0)
1759 {
1760 InputMethodPanelTest::Attach();
1761 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1762 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1763 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1764 CallingWindowInfo windowInfo;
1765 auto ret = inputMethodPanel->GetCallingWindowInfo(windowInfo);
1766 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1767 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1768 InputMethodPanelTest::imc_->Close();
1769 TddUtil::DestroyWindow();
1770 }
1771
1772 /**
1773 * @tc.name: testSetUiContent01
1774 * @tc.desc: Test SetUiContent.
1775 * @tc.type: FUNC
1776 */
1777 HWTEST_F(InputMethodPanelTest, testSetUiContent01, TestSize.Level0)
1778 {
1779 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1780 auto ret = inputMethodPanel->SetUiContent("text", nullptr, nullptr);
1781 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1782 }
1783
1784 /**
1785 * @tc.name: testSetUiContent02
1786 * @tc.desc: Test SetUiContent.
1787 * @tc.type: FUNC
1788 */
1789 HWTEST_F(InputMethodPanelTest, testSetUiContent02, TestSize.Level0)
1790 {
1791 InputMethodPanelTest::Attach();
1792 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1793 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1794 InputMethodPanelTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1795 auto ret = inputMethodPanel->SetUiContent("text", nullptr, nullptr);
1796 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1797 InputMethodPanelTest::ImaDestroyPanel(inputMethodPanel);
1798 InputMethodPanelTest::imc_->Close();
1799 TddUtil::DestroyWindow();
1800 }
1801
1802 /**
1803 * @tc.name: testIsSizeValid
1804 * @tc.desc: Test IsSizeValid
1805 * @tc.type: FUNC
1806 */
1807 HWTEST_F(InputMethodPanelTest, testIsSizeValid, TestSize.Level0)
1808 {
1809 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1810 EXPECT_FALSE(inputMethodPanel->IsSizeValid(INT32_MAX + 1, INT32_MAX));
1811 EXPECT_FALSE(inputMethodPanel->IsSizeValid(INT32_MAX, INT32_MAX + 1));
1812 }
1813
1814 /**
1815 * @tc.name: testGenerateSequenceId
1816 * @tc.desc: Test GenerateSequenceId
1817 * @tc.type: FUNC
1818 */
1819 HWTEST_F(InputMethodPanelTest, testGenerateSequenceId, TestSize.Level0)
1820 {
1821 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1822 inputMethodPanel->sequenceId_ = std::numeric_limits<uint32_t>::max() - 1;
1823 uint32_t seqId = inputMethodPanel->GenerateSequenceId();
1824 EXPECT_EQ(seqId, 0);
1825 }
1826
1827 /**
1828 * @tc.name: testPanelStatusListener01
1829 * @tc.desc: Test SetPanelStatusListener
1830 * @tc.type: FUNC
1831 */
1832 HWTEST_F(InputMethodPanelTest, testPanelStatusListener01, TestSize.Level0)
1833 {
1834 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1835 inputMethodPanel->panelStatusListener_ = nullptr;
1836 inputMethodPanel->ClearPanelListener("show");
1837
1838 AccessScope scope(currentImeTokenId_, currentImeUid_);
1839 PanelInfo panelInfo = { .panelType = STATUS_BAR, .panelFlag = FLG_FIXED };
1840 auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
1841 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
1842 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1843 inputMethodPanel->panelStatusListener_ = statusListener;
1844 EXPECT_TRUE(inputMethodPanel->SetPanelStatusListener(statusListener, "sizeChange"));
1845 ret = inputMethodPanel->DestroyPanel();
1846 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1847 }
1848
1849 /**
1850 * @tc.name: testPanelStatusListener02
1851 * @tc.desc: Test SetPanelStatusListener
1852 * @tc.type: FUNC
1853 */
1854 HWTEST_F(InputMethodPanelTest, testPanelStatusListener02, TestSize.Level0)
1855 {
1856 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1857 AccessScope scope(currentImeTokenId_, currentImeUid_);
1858 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1859 auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
1860 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
1861 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1862 inputMethodPanel->panelStatusListener_ = statusListener;
1863 EXPECT_TRUE(inputMethodPanel->SetPanelStatusListener(statusListener, "sizeChange"));
1864 EXPECT_TRUE(inputMethodPanel->SetPanelStatusListener(nullptr, "sizeChange"));
1865 inputMethodPanel->panelStatusListener_ = nullptr;
1866 EXPECT_TRUE(inputMethodPanel->SetPanelStatusListener(nullptr, "sizeChange"));
1867 EXPECT_TRUE(inputMethodPanel->SetPanelStatusListener(statusListener, "sizeChange"));
1868 ret = inputMethodPanel->DestroyPanel();
1869 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1870 }
1871
1872 /**
1873 * @tc.name: testStartMoving01
1874 * @tc.desc: Test StartMoving
1875 * @tc.type: FUNC
1876 */
1877 HWTEST_F(InputMethodPanelTest, testStartMoving01, TestSize.Level0)
1878 {
1879 IMSA_HILOGI("InputMethodPanelTest::testStartMoving start.");
1880 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1881 auto ret = inputMethodPanel->StartMoving();
1882 EXPECT_EQ(ret, ErrorCode::ERROR_IME);
1883
1884 AccessScope scope(currentImeTokenId_, currentImeUid_);
1885 PanelInfo panelInfo = { .panelType = STATUS_BAR, .panelFlag = FLG_FLOATING };
1886 ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
1887 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1888 ret = inputMethodPanel->StartMoving();
1889 EXPECT_GE(ret, ErrorCode::NO_ERROR);
1890 ret = inputMethodPanel->DestroyPanel();
1891 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1892
1893 panelInfo.panelType = SOFT_KEYBOARD;
1894 ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
1895 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1896 ret = inputMethodPanel->StartMoving();
1897 EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_PANEL_TYPE);
1898 ret = inputMethodPanel->DestroyPanel();
1899 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1900
1901 panelInfo.panelType = STATUS_BAR;
1902 panelInfo.panelFlag = FLG_FIXED;
1903 ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
1904 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1905 ret = inputMethodPanel->StartMoving();
1906 EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_PANEL_FLAG);
1907 ret = inputMethodPanel->DestroyPanel();
1908 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1909 }
1910
1911 /**
1912 * @tc.name: testGetDisplayId01
1913 * @tc.desc: Test GetDisplayId
1914 * @tc.type: FUNC
1915 */
1916 HWTEST_F(InputMethodPanelTest, testGetDisplayId01, TestSize.Level0)
1917 {
1918 IMSA_HILOGI("InputMethodPanelTest::testGetDisplayId start.");
1919 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1920 uint64_t displayId;
1921 auto ret = inputMethodPanel->GetDisplayId(displayId);
1922 EXPECT_EQ(ret, ErrorCode::ERROR_IME);
1923
1924 AccessScope scope(currentImeTokenId_, currentImeUid_);
1925 PanelInfo panelInfo = { .panelType = STATUS_BAR, .panelFlag = FLG_FLOATING };
1926 ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
1927 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1928
1929 ret = inputMethodPanel->GetDisplayId(displayId);
1930 EXPECT_GE(ret, ErrorCode::NO_ERROR);
1931
1932 ret = inputMethodPanel->DestroyPanel();
1933 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1934 }
1935
1936 /**
1937 * @tc.name: testSetImmersiveMode
1938 * @tc.desc: Test set immersive mode.
1939 * @tc.type: FUNC
1940 */
1941 HWTEST_F(InputMethodPanelTest, testSetImmersiveMode, TestSize.Level0)
1942 {
1943 IMSA_HILOGI("InputMethodPanelTest::testSetImmersiveMode start.");
1944 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1945 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1946
1947 AccessScope scope(currentImeTokenId_, currentImeUid_);
1948 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
1949 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
1950 ret = inputMethodPanel->ShowPanel();
1951 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
1952
1953 ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::NONE_IMMERSIVE);
1954 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
1955 ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::LIGHT_IMMERSIVE);
1956 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
1957 ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::DARK_IMMERSIVE);
1958 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
1959 ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::IMMERSIVE);
1960 EXPECT_EQ(ErrorCode::ERROR_PARAMETER_CHECK_FAILED, ret);
1961
1962 ret = inputMethodPanel->HidePanel();
1963 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
1964 ret = inputMethodPanel->DestroyPanel();
1965 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
1966 }
1967
1968 /**
1969 * @tc.name: testGetImmersiveMode
1970 * @tc.desc: Test get immersive mode.
1971 * @tc.type: FUNC
1972 */
1973 HWTEST_F(InputMethodPanelTest, testGetImmersiveMode, TestSize.Level0)
1974 {
1975 IMSA_HILOGI("InputMethodPanelTest::testGetImmersiveMode start.");
1976 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1977 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1978
1979 AccessScope scope(currentImeTokenId_, currentImeUid_);
1980 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
1981 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
1982 ret = inputMethodPanel->ShowPanel();
1983 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
1984
1985 ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::NONE_IMMERSIVE);
1986 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
1987 auto mode = inputMethodPanel->GetImmersiveMode();
1988 EXPECT_EQ(ImmersiveMode::NONE_IMMERSIVE, mode);
1989
1990 ret = inputMethodPanel->HidePanel();
1991 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
1992 ret = inputMethodPanel->DestroyPanel();
1993 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
1994 }
1995
1996
1997 /**
1998 * @tc.name: testParameterValidationInterface
1999 * @tc.desc: Test Parameter validation interface
2000 * @tc.type: FUNC
2001 */
2002 HWTEST_F(InputMethodPanelTest, testParameterValidationInterface, TestSize.Level0)
2003 {
2004 IMSA_HILOGI("InputMethodPanelTest::testParameterValidationInterface start.");
2005 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
2006 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
2007
2008 AccessScope scope(currentImeTokenId_, currentImeUid_);
2009 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
2010 EnhancedLayoutParams enhancedLayoutParams;
2011 FullPanelAdjustInfo adjustInfo;
2012 enhancedLayoutParams.portrait.avoidY = 10;
2013 enhancedLayoutParams.landscape.avoidY = 20;
2014 adjustInfo.portrait = {0, 0, 100, 100};
2015 adjustInfo.landscape = {0, 0, 200, 200};
2016 PanelAdjustInfo keyboardArea;
2017
2018 ret = inputMethodPanel->GetKeyboardArea(PanelFlag::FLG_FIXED, {100, 200}, keyboardArea);
2019
2020 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
2021 EXPECT_EQ(keyboardArea.top, inputMethodPanel->enhancedLayoutParams_.portrait.avoidY);
2022
2023 uint32_t validWidth = 100;
2024 uint32_t validHeight = 200;
2025 ret = inputMethodPanel->ResizeWithoutAdjust(validWidth, validHeight);
2026 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
2027
2028 ret = inputMethodPanel->ResizeWithoutAdjust(INT32_MAX + 1, INT32_MAX + 1);
2029 EXPECT_EQ(ErrorCode::ERROR_BAD_PARAMETERS, ret);
2030
2031 inputMethodPanel->panelType_ = PanelType::STATUS_BAR;
2032 ret = inputMethodPanel->IsEnhancedParamValid(PanelFlag::FLG_FIXED, enhancedLayoutParams);
2033 EXPECT_EQ(ErrorCode::ERROR_INVALID_PANEL_TYPE, ret);
2034
2035 Rosen::Rect rect1{10, 20, 100, 200};
2036 WindowSize displaySize1 {800, 600};
2037 EXPECT_TRUE(inputMethodPanel->IsRectValid(rect1, displaySize1));
2038
2039 Rosen::Rect rect2{-10, 20, 100, 200};
2040 WindowSize displaySize2{800, 600};
2041 EXPECT_FALSE(inputMethodPanel->IsRectValid(rect2, displaySize2));
2042
2043 Rosen::Rect rect3{10, 20, INT32_MAX, 200};
2044 WindowSize displaySize3{800, 600};
2045 EXPECT_FALSE(inputMethodPanel->IsRectValid(rect3, displaySize3));
2046
2047 Rosen::Rect rect4{10, 20, 9000, 20000};
2048 WindowSize displaySize4{800, 600};
2049 EXPECT_FALSE(inputMethodPanel->IsRectValid(rect4, displaySize4));
2050
2051 inputMethodPanel->window_ = nullptr;
2052 ret= inputMethodPanel->IsEnhancedParamValid(PanelFlag::FLG_FIXED, enhancedLayoutParams);
2053 EXPECT_EQ(ErrorCode::ERROR_WINDOW_MANAGER, ret);
2054
2055 ret = inputMethodPanel->DestroyPanel();
2056 EXPECT_EQ(ErrorCode::ERROR_NULL_POINTER, ret);
2057 }
2058
2059 /**
2060 * @tc.name: testMoveEnhancedPanelRect
2061 * @tc.desc: Test Move Enhanced Panel Rect
2062 * @tc.type: FUNC
2063 */
2064 HWTEST_F(InputMethodPanelTest, testMoveEnhancedPanelRect, TestSize.Level0)
2065 {
2066 IMSA_HILOGI("InputMethodPanelTest::testMoveEnhancedPanelRect start.");
2067 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
2068 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
2069
2070 AccessScope scope(currentImeTokenId_, currentImeUid_);
2071 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
2072 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
2073
2074 int32_t portraitX = 10;
2075 int32_t portraitY = 20;
2076 int32_t portraitRet = inputMethodPanel->MoveEnhancedPanelRect(portraitX, portraitY);
2077 EXPECT_EQ(ErrorCode::NO_ERROR, portraitRet);
2078
2079 int32_t landscapeX = 30;
2080 int32_t landscapeY = 40;
2081 int32_t landscapeRet = inputMethodPanel->MoveEnhancedPanelRect(landscapeX, landscapeY);
2082 EXPECT_EQ(ErrorCode::NO_ERROR, landscapeRet);
2083
2084 int32_t minX = -100;
2085 int32_t minY = -200;
2086 int32_t minRet = inputMethodPanel->MoveEnhancedPanelRect(minX, minY);
2087 EXPECT_EQ(ErrorCode::ERROR_PARAMETER_CHECK_FAILED, minRet);
2088
2089 const std::string type = "sizeUpdate";
2090 EXPECT_TRUE(inputMethodPanel->MarkListener(type, false));
2091
2092 uint32_t windowWidth = 100;
2093 bool isPortrait = false;
2094 ret = inputMethodPanel->GetWindowOrientation(PanelFlag::FLG_FIXED, windowWidth, isPortrait);
2095 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
2096
2097 ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::NONE_IMMERSIVE);
2098 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
2099 inputMethodPanel->window_ = nullptr;
2100 ret = inputMethodPanel->SetImmersiveMode(ImmersiveMode::NONE_IMMERSIVE);
2101 EXPECT_EQ(ErrorCode::ERROR_IME, ret);
2102
2103 ret = inputMethodPanel->DestroyPanel();
2104 EXPECT_EQ(ErrorCode::ERROR_NULL_POINTER, ret);
2105 }
2106 } // namespace MiscServices
2107 } // namespace OHOS