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