• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_ability.h"
18 #include "input_method_ability_utils.h"
19 #include "input_method_controller.h"
20 #include "input_method_panel.h"
21 #include "input_method_system_ability.h"
22 #undef private
23 
24 #include <gtest/gtest.h>
25 #include <sys/time.h>
26 #include <unistd.h>
27 
28 #include <condition_variable>
29 #include <cstdint>
30 #include <string>
31 
32 #include "display_manager.h"
33 #include "global.h"
34 #include "identity_checker_mock.h"
35 #include "ime_event_monitor_manager.h"
36 #include "input_method_ability.h"
37 #include "input_method_controller.h"
38 #include "input_method_engine_listener_impl.h"
39 #include "matching_skills.h"
40 #include "panel_status_listener.h"
41 #include "scene_board_judgement.h"
42 #include "scope_utils.h"
43 #include "tdd_util.h"
44 #include "text_listener.h"
45 
46 using namespace testing::ext;
47 namespace OHOS {
48 namespace MiscServices {
49 constexpr float FIXED_SOFT_KEYBOARD_PANEL_RATIO = 0.7;
50 class InputMethodPanelAdjustTest : public testing::Test {
51 public:
52     static void SetUpTestCase(void);
53     static void TearDownTestCase(void);
54     void SetUp();
55     void TearDown();
56     static std::shared_ptr<InputMethodPanel> CreatePanel();
57     static void DestroyPanel(const std::shared_ptr<InputMethodPanel> &panel);
58     static void Attach();
59     static void ImaCreatePanel(const PanelInfo &info, std::shared_ptr<InputMethodPanel> &panel);
60     static void ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> &panel);
61     static int32_t GetDisplaySize(DisplaySize &size);
62 
63     static sptr<InputMethodController> imc_;
64     static sptr<InputMethodAbility> ima_;
65     static sptr<InputMethodSystemAbility> imsa_;
66     static int32_t currentImeUid_;
67     static uint64_t currentImeTokenId_;
68     static sptr<OnTextChangedListener> textListener_;
69     static std::shared_ptr<InputMethodEngineListener> imeListener_;
70     static bool isScbEnable_;
71 };
72 sptr<InputMethodController> InputMethodPanelAdjustTest::imc_{ nullptr };
73 sptr<InputMethodAbility> InputMethodPanelAdjustTest::ima_{ nullptr };
74 sptr<InputMethodSystemAbility> InputMethodPanelAdjustTest::imsa_{ nullptr };
75 uint64_t InputMethodPanelAdjustTest::currentImeTokenId_ = 0;
76 int32_t InputMethodPanelAdjustTest::currentImeUid_ = 0;
77 sptr<OnTextChangedListener> InputMethodPanelAdjustTest::textListener_{ nullptr };
78 std::shared_ptr<InputMethodEngineListener> InputMethodPanelAdjustTest::imeListener_{ nullptr };
79 bool InputMethodPanelAdjustTest::isScbEnable_{ false };
SetUpTestCase(void)80 void InputMethodPanelAdjustTest::SetUpTestCase(void)
81 {
82     IMSA_HILOGI("InputMethodPanelAdjustTest::SetUpTestCase");
83     IdentityCheckerMock::ResetParam();
84     isScbEnable_ = Rosen::SceneBoardJudgement::IsSceneBoardEnabled();
85     // storage current token id
86     TddUtil::StorageSelfTokenID();
87 
88     imc_ = InputMethodController::GetInstance();
89     textListener_ = new (std::nothrow) TextListener();
90     imeListener_ = std::make_shared<InputMethodEngineListenerImpl>();
91     // set token as current input method
92     std::shared_ptr<Property> property = InputMethodController::GetInstance()->GetCurrentInputMethod();
93     std::string bundleName = property != nullptr ? property->name : "default.inputmethod.unittest";
94     currentImeTokenId_ = TddUtil::GetTestTokenID(bundleName);
95     currentImeUid_ = TddUtil::GetUid(bundleName);
96 
97     imsa_ = new (std::nothrow) InputMethodSystemAbility();
98     if (imsa_ == nullptr) {
99         return;
100     }
101     imsa_->OnStart();
102     imsa_->userId_ = TddUtil::GetCurrentUserId();
103     imsa_->identityChecker_ = std::make_shared<IdentityCheckerMock>();
104 
105     imc_->abilityManager_ = imsa_;
106 
107     ima_ = InputMethodAbility::GetInstance();
108     {
109         TokenScope scope(currentImeTokenId_);
110         ima_->InitConnect();
111     }
112     ima_->abilityManager_ = imsa_;
113     TddUtil::InitCurrentImePermissionInfo();
114     IdentityCheckerMock::SetBundleName(TddUtil::currentBundleNameMock_);
115     ima_->SetCoreAndAgent();
116     InputMethodPanelAdjustTest::ima_->SetImeListener(imeListener_);
117 
118     ImaUtils::abilityManager_ = imsa_;
119 }
120 
TearDownTestCase(void)121 void InputMethodPanelAdjustTest::TearDownTestCase(void)
122 {
123     IMSA_HILOGI("InputMethodPanelAdjustTest::TearDownTestCase");
124     TddUtil::RestoreSelfTokenID();
125     IdentityCheckerMock::ResetParam();
126     imsa_->OnStop();
127     ImaUtils::abilityManager_ = nullptr;
128 }
129 
SetUp(void)130 void InputMethodPanelAdjustTest::SetUp(void)
131 {
132     IMSA_HILOGI("InputMethodPanelAdjustTest::SetUp");
133     InputMethodPanelAdjustTest::Attach();
134 }
135 
TearDown(void)136 void InputMethodPanelAdjustTest::TearDown(void)
137 {
138     InputMethodPanelAdjustTest::imc_->Close();
139     TddUtil::DestroyWindow();
140     TddUtil::RestoreSelfTokenID();
141     IMSA_HILOGI("InputMethodPanelAdjustTest::TearDown");
142     std::this_thread::sleep_for(std::chrono::seconds(1));
143 }
144 
CreatePanel()145 std::shared_ptr<InputMethodPanel> InputMethodPanelAdjustTest::CreatePanel()
146 {
147     AccessScope scope(currentImeTokenId_, currentImeUid_);
148     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
149     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
150     auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
151     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
152     return inputMethodPanel;
153 }
154 
DestroyPanel(const std::shared_ptr<InputMethodPanel> & panel)155 void InputMethodPanelAdjustTest::DestroyPanel(const std::shared_ptr<InputMethodPanel> &panel)
156 {
157     ASSERT_NE(panel, nullptr);
158     AccessScope scope(currentImeTokenId_, currentImeUid_);
159     auto ret = panel->DestroyPanel();
160     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
161 }
162 
ImaCreatePanel(const PanelInfo & info,std::shared_ptr<InputMethodPanel> & panel)163 void InputMethodPanelAdjustTest::ImaCreatePanel(const PanelInfo &info, std::shared_ptr<InputMethodPanel> &panel)
164 {
165     AccessScope scope(currentImeTokenId_, currentImeUid_);
166     auto ret = ima_->CreatePanel(nullptr, info, panel);
167     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
168 }
169 
ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> & panel)170 void InputMethodPanelAdjustTest::ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> &panel)
171 {
172     AccessScope scope(currentImeTokenId_, currentImeUid_);
173     auto ret = ima_->DestroyPanel(panel);
174     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
175 }
176 
Attach()177 void InputMethodPanelAdjustTest::Attach()
178 {
179     IdentityCheckerMock::SetFocused(true);
180     auto ret = imc_->Attach(textListener_, false);
181     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
182     std::this_thread::sleep_for(std::chrono::seconds(1));
183     IdentityCheckerMock::SetFocused(false);
184 }
185 
GetDisplaySize(DisplaySize & size)186 int32_t InputMethodPanelAdjustTest::GetDisplaySize(DisplaySize &size)
187 {
188     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
189     if (defaultDisplay == nullptr) {
190         IMSA_HILOGE("GetDefaultDisplay failed!");
191         return ErrorCode::ERROR_WINDOW_MANAGER;
192     }
193     auto width = defaultDisplay->GetWidth();
194     auto height = defaultDisplay->GetHeight();
195     if (width < height) {
196         size.portrait = { .width = width, .height = height };
197         size.landscape = { .width = height, .height = width };
198     } else {
199         size.portrait = { .width = height, .height = width };
200         size.landscape = { .width = width, .height = height };
201     }
202     return ErrorCode::NO_ERROR;
203 }
204 
205 /**
206  * @tc.name: testAdjustEnhancedPanelRect_001
207  * @tc.desc: Test AdjustPanelRect with invalid panel type.
208  * @tc.type: FUNC
209  */
210 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_001, TestSize.Level0)
211 {
212     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_001 Test START");
213     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
214     PanelInfo panelInfo = { .panelType = STATUS_BAR };
215     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
216     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
217     EnhancedLayoutParams params;
218     HotAreas hotAreas;
219     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
220     EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_PANEL_TYPE);
221     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
222 }
223 
224 /**
225  * @tc.name: testAdjustEnhancedPanelRect_002
226  * @tc.desc: Test AdjustPanelRect with invalid portrait rect position.
227  * @tc.type: FUNC
228  */
229 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_002, TestSize.Level0)
230 {
231     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_002 Test START");
232     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
233     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
234     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
235     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
236     Rosen::Rect portraitRect = { -1, -1, 100, 100 };
237     Rosen::Rect validRect = { 1, 1, 100, 100 };
238     EnhancedLayoutParams params = {
239         .isFullScreen = false,
240         .portrait = { portraitRect, 50, 50 },
241         .landscape = { validRect, 50, 50 },
242     };
243     HotAreas hotAreas;
244     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
245     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
246     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
247 }
248 
249 /**
250  * @tc.name: testAdjustEnhancedPanelRect_003
251  * @tc.desc: Test AdjustPanelRect with invalid landscape rect position.
252  * @tc.type: FUNC
253  */
254 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_003, TestSize.Level0)
255 {
256     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_003 Test START");
257     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
258     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
259     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
260     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
261     Rosen::Rect portraitRect = { -1, -1, 100, 100 };
262     Rosen::Rect validRect = { 1, 1, 100, 100 };
263     EnhancedLayoutParams params = {
264         .isFullScreen = false,
265         .portrait = { validRect, 50, 50 },
266         .landscape = { portraitRect, 50, 50 },
267     };
268     HotAreas hotAreas;
269     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
270     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
271     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
272 }
273 
274 /**
275  * @tc.name: testAdjustEnhancedPanelRect_004
276  * @tc.desc: Test AdjustPanelRect with invalid portrait rect width.
277  * @tc.type: FUNC
278  */
279 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_004, TestSize.Level0)
280 {
281     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_004 Test START");
282     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
283     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
284     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
285     DisplaySize display;
286     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
287     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
288     Rosen::Rect portraitRect = { 0, 0, display.portrait.width + 1, display.portrait.height - 1 };
289     Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 };
290     EnhancedLayoutParams params = {
291         .isFullScreen = false,
292         .portrait = { portraitRect, 50, 50 },
293         .landscape = { landscapeRect, 50, 50 },
294     };
295     HotAreas hotAreas;
296     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
297     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
298     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
299 }
300 
301 /**
302  * @tc.name: testAdjustEnhancedPanelRect_005
303  * @tc.desc: Test AdjustPanelRect with invalid portrait rect height.
304  * @tc.type: FUNC
305  */
306 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_005, TestSize.Level0)
307 {
308     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_005 Test START");
309     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
310     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
311     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
312     DisplaySize display;
313     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
314     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
315     Rosen::Rect portraitRect = { 0, 0, display.portrait.width - 1, display.portrait.height + 1 };
316     Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 };
317     EnhancedLayoutParams params = {
318         .isFullScreen = false,
319         .portrait = { portraitRect, 50, 50 },
320         .landscape = { landscapeRect, 50, 50 },
321     };
322     HotAreas hotAreas;
323     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
324     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
325     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
326 }
327 
328 /**
329  * @tc.name: testAdjustEnhancedPanelRect_006
330  * @tc.desc: Test AdjustPanelRect with invalid landscape rect width.
331  * @tc.type: FUNC
332  */
333 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_006, TestSize.Level0)
334 {
335     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_006 Test START");
336     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
337     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
338     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
339     DisplaySize display;
340     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
341     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
342     Rosen::Rect portraitRect = { 0, 0, display.portrait.width - 1, display.portrait.height - 1 };
343     Rosen::Rect landscapeRect = { 0, 0, display.landscape.width + 1, display.landscape.height - 1 };
344     EnhancedLayoutParams params = {
345         .isFullScreen = false,
346         .portrait = { portraitRect, 50, 50 },
347         .landscape = { landscapeRect, 50, 50 },
348     };
349     HotAreas hotAreas;
350     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
351     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
352     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
353 }
354 
355 /**
356  * @tc.name: testAdjustEnhancedPanelRect_007
357  * @tc.desc: Test AdjustPanelRect with invalid landscape rect height.
358  * @tc.type: FUNC
359  */
360 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_007, TestSize.Level0)
361 {
362     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_007 Test START");
363     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
364     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
365     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
366     DisplaySize display;
367     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
368     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
369     Rosen::Rect portraitRect = { 0, 0, display.portrait.width - 1, display.portrait.height - 1 };
370     Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height + 1 };
371     EnhancedLayoutParams params = {
372         .isFullScreen = false,
373         .portrait = { portraitRect, 50, 50 },
374         .landscape = { landscapeRect, 50, 50 },
375     };
376     HotAreas hotAreas;
377     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
378     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
379     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
380 }
381 
382 /**
383  * @tc.name: testAdjustEnhancedPanelRect_008
384  * @tc.desc: Test AdjustPanelRect with invalid portrait avoid Y(< 0).
385  * @tc.type: FUNC
386  */
387 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_008, TestSize.Level0)
388 {
389     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_008 Test START");
390     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
391     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
392     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
393     DisplaySize display;
394     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
395     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
396     Rosen::Rect portraitRect = { 0, 0, display.portrait.width - 1, display.portrait.height - 1 };
397     Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 };
398     EnhancedLayoutParams params = {
399         .isFullScreen = false,
400         .portrait = { portraitRect, -1, 0 },
401         .landscape = { landscapeRect, 1, 0 },
402     };
403     HotAreas hotAreas;
404     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
405     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
406     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
407 }
408 
409 /**
410  * @tc.name: testAdjustEnhancedPanelRect_009
411  * @tc.desc: Test AdjustPanelRect with invalid portrait avoid Y(> keyboard height).
412  * @tc.type: FUNC
413  */
414 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_009, TestSize.Level0)
415 {
416     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_009 Test START");
417     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
418     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
419     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
420     DisplaySize display;
421     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
422     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
423     Rosen::Rect portraitRect = { 0, 0, display.portrait.width - 1, display.portrait.height - 1 };
424     Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 };
425     EnhancedLayoutParams params = {
426         .isFullScreen = false,
427         .portrait = { portraitRect, static_cast<int32_t>(portraitRect.height_) + 1, 0 },
428         .landscape = { landscapeRect, static_cast<int32_t>(landscapeRect.height_) - 1, 0 },
429     };
430     HotAreas hotAreas;
431     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
432     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
433     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
434 }
435 
436 /**
437  * @tc.name: testAdjustEnhancedPanelRect_010
438  * @tc.desc: Test AdjustPanelRect with invalid landscape avoid Y(< 0).
439  * @tc.type: FUNC
440  */
441 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_010, TestSize.Level0)
442 {
443     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_010 Test START");
444     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
445     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
446     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
447     DisplaySize display;
448     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
449     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
450     Rosen::Rect portraitRect = { 0, 0, display.portrait.width - 1, display.portrait.height - 1 };
451     Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 };
452     EnhancedLayoutParams params = {
453         .isFullScreen = false,
454         .portrait = { portraitRect, 1, 0 },
455         .landscape = { landscapeRect, -1, 0 },
456     };
457     HotAreas hotAreas;
458     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
459     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
460     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
461 }
462 
463 /**
464  * @tc.name: testAdjustEnhancedPanelRect_011
465  * @tc.desc: Test AdjustPanelRect with invalid landscape avoid Y(> keyboard height).
466  * @tc.type: FUNC
467  */
468 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_011, TestSize.Level0)
469 {
470     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_011 Test START");
471     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
472     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
473     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
474     DisplaySize display;
475     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
476     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
477     Rosen::Rect portraitRect = { 0, 0, display.portrait.width - 1, display.portrait.height - 1 };
478     Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 };
479     EnhancedLayoutParams params = {
480         .isFullScreen = false,
481         .portrait = { portraitRect, static_cast<int32_t>(portraitRect.height_) - 1, 0 },
482         .landscape = { landscapeRect, static_cast<int32_t>(landscapeRect.height_) + 1, 0 },
483     };
484     HotAreas hotAreas;
485     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
486     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
487     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
488 }
489 
490 /**
491  * @tc.name: testAdjustEnhancedPanelRect_012
492  * @tc.desc: Test AdjustPanelRect with fixed, full screen, invalid portrait avoidHeight(> displayHeight * 0.7).
493  * @tc.type: FUNC
494  */
495 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_012, TestSize.Level0)
496 {
497     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_012 Test START");
498     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
499     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
500     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
501     DisplaySize display;
502     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
503     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
504     uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1;
505     uint32_t portraitAvoidY = display.portrait.height - portraitAvoidHeight;
506     uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
507     uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight;
508     EnhancedLayoutParams params = {
509         .isFullScreen = true,
510         .portrait = { {}, static_cast<int32_t>(portraitAvoidY), 0 },
511         .landscape = { {}, static_cast<int32_t>(landscapeAvoidY), 0 },
512     };
513     HotAreas hotAreas;
514     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
515     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
516     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
517 }
518 
519 /**
520  * @tc.name: testAdjustEnhancedPanelRect_013
521  * @tc.desc: Test AdjustPanelRect with fixed, full screen, invalid landscape avoidHeight(> displayHeight * 0.7).
522  * @tc.type: FUNC
523  */
524 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_013, TestSize.Level0)
525 {
526     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_013 Test START");
527     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
528     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
529     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
530     DisplaySize display;
531     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
532     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
533     uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
534     uint32_t portraitAvoidY = display.portrait.height - portraitAvoidHeight;
535     uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1;
536     uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight;
537     EnhancedLayoutParams params = {
538         .isFullScreen = true,
539         .portrait = { {}, static_cast<int32_t>(portraitAvoidY), 0 },
540         .landscape = { {}, static_cast<int32_t>(landscapeAvoidY), 0 },
541     };
542     HotAreas hotAreas;
543     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
544     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
545     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
546 }
547 
548 /**
549  * @tc.name: testAdjustEnhancedPanelRect_014
550  * @tc.desc: Test AdjustPanelRect with fixed, non full screen, invalid portrait avoidHeight(> displayHeight * 0.7).
551  * @tc.type: FUNC
552  */
553 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_014, TestSize.Level0)
554 {
555     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_014 Test START");
556     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
557     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
558     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
559     DisplaySize display;
560     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
561     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
562     Rosen::Rect portraitRect = { 0, 0, 100, static_cast<uint32_t>(display.portrait.height * 0.8) };
563     Rosen::Rect landscapeRect = { 0, 0, 100, static_cast<uint32_t>(display.landscape.height * 0.8) };
564     uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1;
565     uint32_t portraitAvoidY = portraitRect.height_ - portraitAvoidHeight;
566     uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
567     uint32_t landscapeAvoidY = landscapeRect.height_ - landscapeAvoidHeight;
568     EnhancedLayoutParams params = {
569         .isFullScreen = false,
570         .portrait = { portraitRect, static_cast<int32_t>(portraitAvoidY), 0 },
571         .landscape = { landscapeRect, static_cast<int32_t>(landscapeAvoidY), 0 },
572     };
573     HotAreas hotAreas;
574     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
575     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
576     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
577 }
578 
579 /**
580  * @tc.name: testAdjustEnhancedPanelRect_015
581  * @tc.desc: Test AdjustPanelRect with fixed, non full screen, invalid landscape avoidHeight(> displayHeight * 0.7).
582  * @tc.type: FUNC
583  */
584 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_015, TestSize.Level0)
585 {
586     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_015 Test START");
587     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
588     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
589     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
590     DisplaySize display;
591     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
592     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
593     Rosen::Rect portraitRect = { 0, 0, 100, static_cast<uint32_t>(display.portrait.height * 0.8) };
594     Rosen::Rect landscapeRect = { 0, 0, 100, static_cast<uint32_t>(display.landscape.height * 0.8) };
595     uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
596     uint32_t portraitAvoidY = portraitRect.height_ - portraitAvoidHeight;
597     uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1;
598     uint32_t landscapeAvoidY = landscapeRect.height_ - landscapeAvoidHeight;
599     EnhancedLayoutParams params = {
600         .isFullScreen = false,
601         .portrait = { portraitRect, static_cast<int32_t>(portraitAvoidY), 0 },
602         .landscape = { landscapeRect, static_cast<int32_t>(landscapeAvoidY), 0 },
603     };
604     HotAreas hotAreas;
605     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
606     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
607     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
608 }
609 
610 /**
611  * @tc.name: testAdjustEnhancedPanelRect_016
612  * @tc.desc: Test AdjustPanelRect with fixed, non full screen, success.
613  * @tc.type: FUNC
614  */
615 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_016, TestSize.Level0)
616 {
617     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_016 Test START");
618     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
619     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
620     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
621     DisplaySize display;
622     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
623     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
624     Rosen::Rect portraitRect = { 0, 0, 100, static_cast<uint32_t>(display.portrait.height * 0.8) };
625     Rosen::Rect landscapeRect = { 0, 0, 100, static_cast<uint32_t>(display.landscape.height * 0.8) };
626     uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
627     uint32_t portraitAvoidY = display.portrait.height - portraitAvoidHeight;
628     uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
629     uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight;
630     EnhancedLayoutParams params = {
631         .isFullScreen = true,
632         .portrait = { portraitRect, static_cast<int32_t>(portraitAvoidY), 0 },
633         .landscape = { landscapeRect, static_cast<int32_t>(landscapeAvoidY), 0 },
634     };
635     HotAreas hotAreas;
636     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
637     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
638     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
639 }
640 
641 /**
642  * @tc.name: testAdjustEnhancedPanelRect_017
643  * @tc.desc: Test old AdjustPanelRect with 0 width input, then UpdateRegion success.
644  * @tc.type: FUNC
645  */
646 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_017, TestSize.Level0)
647 {
648     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_017 Test START");
649     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
650     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
651     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
652     DisplaySize display;
653     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
654     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
655     Rosen::Rect portraitRect = { 0, 0, 0, static_cast<uint32_t>(display.portrait.height * 0.4) };
656     Rosen::Rect landscapeRect = { 0, 0, 0, static_cast<uint32_t>(display.landscape.height * 0.4) };
657     LayoutParams layoutParams = { .landscapeRect = landscapeRect, .portraitRect = portraitRect };
658     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true);
659     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
660 
661     Rosen::Rect keyboardHotArea = {};
662     bool isPortrait = inputMethodPanel->IsDisplayPortrait();
663     if (isPortrait) {
664         keyboardHotArea = { 0, 0, static_cast<uint32_t>(display.portrait.width * 0.5), portraitRect.height_ };
665     } else {
666         keyboardHotArea = { 0, 0, static_cast<uint32_t>(display.landscape.width * 0.5), landscapeRect.height_ };
667     }
668     std::vector<Rosen::Rect> region = { keyboardHotArea };
669     ret = inputMethodPanel->UpdateRegion(region);
670     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
671     if (isPortrait) {
672         EXPECT_EQ(inputMethodPanel->hotAreas_.portrait.keyboardHotArea.size(), 1);
673         EXPECT_EQ(inputMethodPanel->hotAreas_.portrait.keyboardHotArea[0], keyboardHotArea);
674     } else {
675         EXPECT_EQ(inputMethodPanel->hotAreas_.landscape.keyboardHotArea.size(), 1);
676         EXPECT_EQ(inputMethodPanel->hotAreas_.landscape.keyboardHotArea[0], keyboardHotArea);
677     }
678     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
679 }
680 
681 /**
682  * @tc.name: testAdjustEnhancedPanelRect_018
683  * @tc.desc: Test old AdjustPanelRect, then UpdateRegion, then moveTo can not change hot Areas.
684  * @tc.type: FUNC
685  */
686 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_018, TestSize.Level0)
687 {
688     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_018 Test START");
689     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
690     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
691     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
692     DisplaySize display;
693     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
694     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
695     Rosen::Rect portraitRect = { 0, 0, display.portrait.width, static_cast<uint32_t>(display.portrait.height * 0.5) };
696     Rosen::Rect landscapeRect = { 0, 0, display.landscape.width,
697         static_cast<uint32_t>(display.landscape.height * 0.5) };
698     LayoutParams layoutParams = { .landscapeRect = landscapeRect, .portraitRect = portraitRect };
699     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true);
700     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
701 
702     Rosen::Rect keyboardHotArea = {};
703     bool isPortrait = inputMethodPanel->IsDisplayPortrait();
704     if (isPortrait) {
705         keyboardHotArea = { 0, 0, static_cast<uint32_t>(portraitRect.width_ * 0.5), portraitRect.height_ };
706     } else {
707         keyboardHotArea = { 0, 0, static_cast<uint32_t>(landscapeRect.width_ * 0.5), landscapeRect.height_ };
708     }
709     std::vector<Rosen::Rect> region = { keyboardHotArea };
710     ret = inputMethodPanel->UpdateRegion(region);
711     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
712     ret = inputMethodPanel->MoveTo(1, 1);
713     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
714     if (isPortrait) {
715         EXPECT_EQ(inputMethodPanel->hotAreas_.portrait.keyboardHotArea.size(), 1);
716         EXPECT_EQ(inputMethodPanel->hotAreas_.portrait.keyboardHotArea[0], keyboardHotArea);
717     } else {
718         EXPECT_EQ(inputMethodPanel->hotAreas_.landscape.keyboardHotArea.size(), 1);
719         EXPECT_EQ(inputMethodPanel->hotAreas_.landscape.keyboardHotArea[0], keyboardHotArea);
720     }
721     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
722 }
723 
724 /**
725  * @tc.name: testAdjustEnhancedPanelRect_019
726  * @tc.desc: Test old AdjustPanelRect, then Resize.
727  * @tc.type: FUNC
728  */
729 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_019, TestSize.Level0)
730 {
731     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_019 Test START");
732     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
733     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD };
734     InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
735     inputMethodPanel->isScbEnable_ = true;
736     DisplaySize display;
737     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
738     PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
739     Rosen::Rect portraitRect = { 0, 0, display.portrait.width, static_cast<uint32_t>(display.portrait.height * 0.5) };
740     Rosen::Rect landscapeRect = { 0, 0, display.landscape.width,
741         static_cast<uint32_t>(display.landscape.height * 0.5) };
742     LayoutParams layoutParams = { .landscapeRect = landscapeRect, .portraitRect = portraitRect };
743     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true);
744     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
745 
746     WindowSize size = {};
747     bool isPortrait = inputMethodPanel->IsDisplayPortrait();
748     if (isPortrait) {
749         size = { static_cast<uint32_t>(portraitRect.width_ * 0.5), static_cast<uint32_t>(portraitRect.height_ * 0.5) };
750     } else {
751         size = { static_cast<uint32_t>(landscapeRect.width_ * 0.5),
752             static_cast<uint32_t>(landscapeRect.height_ * 0.5) };
753     }
754     ret = inputMethodPanel->Resize(size.width, size.height);
755     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
756     Rosen::Rect newRect = { 0, 0, size.width, size.height };
757     if (isPortrait) {
758         EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.PortraitKeyboardRect_, newRect);
759         EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.LandscapeKeyboardRect_, landscapeRect);
760     } else {
761         EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.PortraitKeyboardRect_, portraitRect);
762         EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.LandscapeKeyboardRect_, newRect);
763     }
764     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
765 }
766 
767 /**
768  * @tc.name: testAdjustEnhancedPanelRect_020
769  * @tc.desc: Test new AdjustPanelRect, then Resize.
770  * @tc.type: FUNC
771  */
772 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_020, TestSize.Level0)
773 {
774     IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_020 Test START");
775     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
776     InputMethodPanelAdjustTest::ImaCreatePanel({ .panelType = SOFT_KEYBOARD }, inputMethodPanel);
777     inputMethodPanel->isScbEnable_ = true;
778     DisplaySize display;
779     ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
780     PanelFlag panelFlag = PanelFlag::FLG_FIXED;
781     Rosen::Rect portraitRect = { 0, 0, 0, static_cast<uint32_t>(display.portrait.height * 0.8) };
782     Rosen::Rect landscapeRect = { 0, 0, 0, static_cast<uint32_t>(display.landscape.height * 0.8) };
783     uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
784     uint32_t portraitAvoidY = display.portrait.height - portraitAvoidHeight;
785     uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
786     uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight;
787     EnhancedLayoutParams params = {
788         .isFullScreen = false,
789         .portrait = { portraitRect, static_cast<int32_t>(portraitAvoidY), 0 },
790         .landscape = { landscapeRect, static_cast<int32_t>(landscapeAvoidY), 0 },
791     };
792     auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, {});
793     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
794 
795     WindowSize size = {};
796     bool isPortrait = inputMethodPanel->IsDisplayPortrait();
797     if (isPortrait) {
798         size = { 100, static_cast<uint32_t>(portraitRect.height_ * 0.5) };
799     } else {
800         size = { 100, static_cast<uint32_t>(landscapeRect.height_ * 0.5) };
801     }
802     ret = inputMethodPanel->Resize(size.width, size.height);
803     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
804     if (isPortrait) {
805         Rosen::Rect newPortraitRect = { 0, static_cast<int32_t>(display.portrait.height - size.height),
806             display.portrait.width, size.height };
807         Rosen::Rect newLandRect = { 0, static_cast<int32_t>(display.landscape.height - landscapeRect.height_),
808             display.landscape.width, landscapeRect.height_ };
809         EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.PortraitKeyboardRect_, newPortraitRect);
810         EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.LandscapeKeyboardRect_, newLandRect);
811     } else {
812         Rosen::Rect newPortraitRect = { 0, static_cast<int32_t>(display.portrait.height - portraitRect.height_),
813             display.portrait.width, portraitRect.height_ };
814         Rosen::Rect newLandRect = { 0, static_cast<int32_t>(display.landscape.height - size.height),
815             display.landscape.width, size.height };
816         EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.PortraitKeyboardRect_, newPortraitRect);
817         EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.LandscapeKeyboardRect_, newLandRect);
818     }
819     InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
820 }
821 } // namespace MiscServices
822 } // namespace OHOS