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 "ime_info_inquirer.h"
18 #include "input_method_ability.h"
19 #include "input_method_ability_utils.h"
20 #include "input_method_controller.h"
21 #include "input_method_panel.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 "display_manager.h"
35 #include "global.h"
36 #include "identity_checker_mock.h"
37 #include "ime_event_monitor_manager.h"
38 #include "input_method_ability.h"
39 #include "input_method_controller.h"
40 #include "input_method_engine_listener_impl.h"
41 #include "matching_skills.h"
42 #include "panel_status_listener.h"
43 #include "scene_board_judgement.h"
44 #include "scope_utils.h"
45 #include "tdd_util.h"
46 #include "text_listener.h"
47
48 using namespace testing::ext;
49 namespace OHOS {
50 namespace MiscServices {
51 constexpr float FIXED_SOFT_KEYBOARD_PANEL_RATIO = 0.7;
52 constexpr float GRADIENT_HEIGHT_RATIO = 0.15;
53 const constexpr char *IMMERSIVE_EFFECT = "immersive_effect";
54 class InputMethodPanelAdjustTest : public testing::Test {
55 public:
56 static void SetUpTestCase(void);
57 static void TearDownTestCase(void);
58 void SetUp();
59 void TearDown();
60 static std::shared_ptr<InputMethodPanel> CreatePanel();
61 static void DestroyPanel(const std::shared_ptr<InputMethodPanel> &panel);
62 static void Attach();
63 static void ImaCreatePanel(const PanelInfo &info, std::shared_ptr<InputMethodPanel> &panel);
64 static void ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> &panel);
65 static int32_t GetDisplaySize(DisplaySize &size);
66 static void SetImmersiveCapacitySupport(bool isSupport);
67
68 static sptr<InputMethodController> imc_;
69 static InputMethodAbility &ima_;
70 static sptr<InputMethodSystemAbility> imsa_;
71 static int32_t currentImeUid_;
72 static uint64_t currentImeTokenId_;
73 static sptr<OnTextChangedListener> textListener_;
74 static std::shared_ptr<InputMethodEngineListener> imeListener_;
75 static bool isScbEnable_;
76 };
77 sptr<InputMethodController> InputMethodPanelAdjustTest::imc_{ nullptr };
78 InputMethodAbility &InputMethodPanelAdjustTest::ima_ = InputMethodAbility::GetInstance();
79 sptr<InputMethodSystemAbility> InputMethodPanelAdjustTest::imsa_{ nullptr };
80 uint64_t InputMethodPanelAdjustTest::currentImeTokenId_ = 0;
81 int32_t InputMethodPanelAdjustTest::currentImeUid_ = 0;
82 sptr<OnTextChangedListener> InputMethodPanelAdjustTest::textListener_{ nullptr };
83 std::shared_ptr<InputMethodEngineListener> InputMethodPanelAdjustTest::imeListener_{ nullptr };
84 bool InputMethodPanelAdjustTest::isScbEnable_{ false };
SetUpTestCase(void)85 void InputMethodPanelAdjustTest::SetUpTestCase(void)
86 {
87 IMSA_HILOGI("InputMethodPanelAdjustTest::SetUpTestCase");
88 IdentityCheckerMock::ResetParam();
89 isScbEnable_ = Rosen::SceneBoardJudgement::IsSceneBoardEnabled();
90 // storage current token id
91 TddUtil::StorageSelfTokenID();
92
93 imc_ = InputMethodController::GetInstance();
94 textListener_ = new (std::nothrow) TextListener();
95 imeListener_ = std::make_shared<InputMethodEngineListenerImpl>();
96 // set token as current input method
97 std::shared_ptr<Property> property = InputMethodController::GetInstance()->GetCurrentInputMethod();
98 std::string bundleName = property != nullptr ? property->name : "default.inputmethod.unittest";
99 currentImeTokenId_ = TddUtil::GetTestTokenID(bundleName);
100 currentImeUid_ = TddUtil::GetUid(bundleName);
101
102 imsa_ = new (std::nothrow) InputMethodSystemAbility();
103 if (imsa_ == nullptr) {
104 return;
105 }
106 imsa_->OnStart();
107 imsa_->userId_ = TddUtil::GetCurrentUserId();
108 imsa_->identityChecker_ = std::make_shared<IdentityCheckerMock>();
109 imc_->abilityManager_ = imsa_;
110 {
111 TokenScope scope(currentImeTokenId_);
112 ima_.InitConnect();
113 }
114 ima_.abilityManager_ = imsa_;
115 TddUtil::InitCurrentImePermissionInfo();
116 IdentityCheckerMock::SetBundleName(TddUtil::currentBundleNameMock_);
117 ima_.SetCoreAndAgent();
118 InputMethodPanelAdjustTest::ima_.SetImeListener(imeListener_);
119
120 ImaUtils::abilityManager_ = imsa_;
121 }
122
TearDownTestCase(void)123 void InputMethodPanelAdjustTest::TearDownTestCase(void)
124 {
125 IMSA_HILOGI("InputMethodPanelAdjustTest::TearDownTestCase");
126 TddUtil::RestoreSelfTokenID();
127 IdentityCheckerMock::ResetParam();
128 imsa_->OnStop();
129 ImaUtils::abilityManager_ = nullptr;
130 }
131
SetUp(void)132 void InputMethodPanelAdjustTest::SetUp(void)
133 {
134 IMSA_HILOGI("InputMethodPanelAdjustTest::SetUp");
135 TaskManager::GetInstance().SetInited(true);
136 InputMethodPanelAdjustTest::Attach();
137 }
138
TearDown(void)139 void InputMethodPanelAdjustTest::TearDown(void)
140 {
141 InputMethodPanelAdjustTest::imc_->Close();
142 TddUtil::DestroyWindow();
143 TddUtil::RestoreSelfTokenID();
144 IMSA_HILOGI("InputMethodPanelAdjustTest::TearDown");
145 std::this_thread::sleep_for(std::chrono::seconds(1));
146 TaskManager::GetInstance().Reset();
147 }
148
CreatePanel()149 std::shared_ptr<InputMethodPanel> InputMethodPanelAdjustTest::CreatePanel()
150 {
151 AccessScope scope(currentImeTokenId_, currentImeUid_);
152 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
153 PanelInfo panelInfo;
154 panelInfo.panelType = SOFT_KEYBOARD;
155 panelInfo.panelFlag = FLG_FIXED;
156 auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
157 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
158 return inputMethodPanel;
159 }
160
DestroyPanel(const std::shared_ptr<InputMethodPanel> & panel)161 void InputMethodPanelAdjustTest::DestroyPanel(const std::shared_ptr<InputMethodPanel> &panel)
162 {
163 ASSERT_NE(panel, nullptr);
164 AccessScope scope(currentImeTokenId_, currentImeUid_);
165 auto ret = panel->DestroyPanel();
166 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
167 }
168
ImaCreatePanel(const PanelInfo & info,std::shared_ptr<InputMethodPanel> & panel)169 void InputMethodPanelAdjustTest::ImaCreatePanel(const PanelInfo &info, std::shared_ptr<InputMethodPanel> &panel)
170 {
171 AccessScope scope(currentImeTokenId_, currentImeUid_);
172 auto ret = ima_.CreatePanel(nullptr, info, panel);
173 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
174 }
175
ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> & panel)176 void InputMethodPanelAdjustTest::ImaDestroyPanel(const std::shared_ptr<InputMethodPanel> &panel)
177 {
178 AccessScope scope(currentImeTokenId_, currentImeUid_);
179 auto ret = ima_.DestroyPanel(panel);
180 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
181 }
182
Attach()183 void InputMethodPanelAdjustTest::Attach()
184 {
185 IdentityCheckerMock::SetFocused(true);
186 auto ret = imc_->Attach(textListener_, false);
187 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
188 std::this_thread::sleep_for(std::chrono::seconds(1));
189 IdentityCheckerMock::SetFocused(false);
190 }
191
GetDisplaySize(DisplaySize & size)192 int32_t InputMethodPanelAdjustTest::GetDisplaySize(DisplaySize &size)
193 {
194 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
195 if (defaultDisplay == nullptr) {
196 IMSA_HILOGE("GetDefaultDisplay failed!");
197 return ErrorCode::ERROR_WINDOW_MANAGER;
198 }
199 auto width = defaultDisplay->GetWidth();
200 auto height = defaultDisplay->GetHeight();
201 if (width < height) {
202 size.portrait = { .width = width, .height = height };
203 size.landscape = { .width = height, .height = width };
204 } else {
205 size.portrait = { .width = height, .height = width };
206 size.landscape = { .width = width, .height = height };
207 }
208 return ErrorCode::NO_ERROR;
209 }
210
SetImmersiveCapacitySupport(bool isSupport)211 void InputMethodPanelAdjustTest::SetImmersiveCapacitySupport(bool isSupport)
212 {
213 IMSA_HILOGI("InputMethodPanelAdjustTest isSupport: %{public}d", isSupport);
214 auto supportedCapacityList = ImeInfoInquirer::GetInstance().GetSystemConfig().supportedCapacityList;
215 if (isSupport) {
216 supportedCapacityList.insert(IMMERSIVE_EFFECT);
217 } else {
218 supportedCapacityList.erase(IMMERSIVE_EFFECT);
219 }
220 ImeInfoInquirer::GetInstance().systemConfig_.supportedCapacityList = supportedCapacityList;
221 }
222
223 /**
224 * @tc.name: testAdjustEnhancedPanelRect_001
225 * @tc.desc: Test AdjustPanelRect with invalid panel type.
226 * @tc.type: FUNC
227 */
228 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_001, TestSize.Level0)
229 {
230 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_001 Test START");
231 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
232 PanelInfo panelInfo;
233 panelInfo.panelType = STATUS_BAR;
234 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
235 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
236 EnhancedLayoutParams params;
237 HotAreas hotAreas;
238 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
239 EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_PANEL_TYPE);
240 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
241 }
242
243 /**
244 * @tc.name: testAdjustEnhancedPanelRect_002
245 * @tc.desc: Test AdjustPanelRect with invalid portrait rect position.
246 * @tc.type: FUNC
247 */
248 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_002, TestSize.Level0)
249 {
250 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_002 Test START");
251 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
252 PanelInfo panelInfo;
253 panelInfo.panelType = SOFT_KEYBOARD;
254 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
255 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
256 Rosen::Rect portraitRect = { -1, -1, 100, 100 };
257 Rosen::Rect validRect = { 1, 1, 100, 100 };
258 EnhancedLayoutParams params = {
259 .isFullScreen = false,
260 .portrait = { portraitRect, {}, 50, 50 },
261 .landscape = { validRect, {}, 50, 50 },
262 };
263 HotAreas hotAreas;
264 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
265 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
266 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
267 }
268
269 /**
270 * @tc.name: testAdjustEnhancedPanelRect_003
271 * @tc.desc: Test AdjustPanelRect with invalid landscape rect position.
272 * @tc.type: FUNC
273 */
274 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_003, TestSize.Level0)
275 {
276 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_003 Test START");
277 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
278 PanelInfo panelInfo;
279 panelInfo.panelType = SOFT_KEYBOARD;
280 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
281 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
282 Rosen::Rect portraitRect = { -1, -1, 100, 100 };
283 Rosen::Rect validRect = { 1, 1, 100, 100 };
284 EnhancedLayoutParams params = {
285 .isFullScreen = false,
286 .portrait = { validRect, {}, 50, 50 },
287 .landscape = { portraitRect, {}, 50, 50 },
288 };
289 HotAreas hotAreas;
290 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
291 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
292 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
293 }
294
295 /**
296 * @tc.name: testAdjustEnhancedPanelRect_004
297 * @tc.desc: Test AdjustPanelRect with invalid portrait rect width.
298 * @tc.type: FUNC
299 */
300 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_004, TestSize.Level0)
301 {
302 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_004 Test START");
303 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
304 PanelInfo panelInfo;
305 panelInfo.panelType = SOFT_KEYBOARD;
306 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
307 DisplaySize display;
308 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
309 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
310 Rosen::Rect portraitRect = { 0, 0, display.portrait.width + 1, display.portrait.height - 1 };
311 Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 };
312 EnhancedLayoutParams params = {
313 .isFullScreen = false,
314 .portrait = { portraitRect, {}, 50, 50 },
315 .landscape = { landscapeRect, {}, 50, 50 },
316 };
317 HotAreas hotAreas;
318 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
319 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
320 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
321 }
322
323 /**
324 * @tc.name: testAdjustEnhancedPanelRect_005
325 * @tc.desc: Test AdjustPanelRect with invalid portrait rect height.
326 * @tc.type: FUNC
327 */
328 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_005, TestSize.Level0)
329 {
330 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_005 Test START");
331 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
332 PanelInfo panelInfo;
333 panelInfo.panelType = SOFT_KEYBOARD;
334 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
335 DisplaySize display;
336 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
337 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
338 Rosen::Rect portraitRect = { 0, 0, display.portrait.width - 1, display.portrait.height + 1 };
339 Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 };
340 EnhancedLayoutParams params = {
341 .isFullScreen = false,
342 .portrait = { portraitRect, {}, 50, 50 },
343 .landscape = { landscapeRect, {}, 50, 50 },
344 };
345 HotAreas hotAreas;
346 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
347 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
348 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
349 }
350
351 /**
352 * @tc.name: testAdjustEnhancedPanelRect_006
353 * @tc.desc: Test AdjustPanelRect with invalid landscape rect width.
354 * @tc.type: FUNC
355 */
356 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_006, TestSize.Level0)
357 {
358 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_006 Test START");
359 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
360 PanelInfo panelInfo;
361 panelInfo.panelType = SOFT_KEYBOARD;
362 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
363 DisplaySize display;
364 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
365 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
366 Rosen::Rect portraitRect = { 0, 0, display.portrait.width - 1, display.portrait.height - 1 };
367 Rosen::Rect landscapeRect = { 0, 0, display.landscape.width + 1, display.landscape.height - 1 };
368 EnhancedLayoutParams params = {
369 .isFullScreen = false,
370 .portrait = { portraitRect, {}, 50, 50 },
371 .landscape = { landscapeRect, {}, 50, 50 },
372 };
373 HotAreas hotAreas;
374 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
375 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
376 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
377 }
378
379 /**
380 * @tc.name: testAdjustEnhancedPanelRect_007
381 * @tc.desc: Test AdjustPanelRect with invalid landscape rect height.
382 * @tc.type: FUNC
383 */
384 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_007, TestSize.Level0)
385 {
386 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_007 Test START");
387 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
388 PanelInfo panelInfo;
389 panelInfo.panelType = SOFT_KEYBOARD;
390 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
391 DisplaySize display;
392 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
393 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
394 Rosen::Rect portraitRect = { 0, 0, display.portrait.width - 1, display.portrait.height - 1 };
395 Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height + 1 };
396 EnhancedLayoutParams params = {
397 .isFullScreen = false,
398 .portrait = { portraitRect, {}, 50, 50 },
399 .landscape = { landscapeRect, {}, 50, 50 },
400 };
401 HotAreas hotAreas;
402 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
403 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
404 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
405 }
406
407 /**
408 * @tc.name: testAdjustEnhancedPanelRect_008
409 * @tc.desc: Test AdjustPanelRect with invalid portrait avoid Y(< 0).
410 * @tc.type: FUNC
411 */
412 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_008, TestSize.Level0)
413 {
414 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_008 Test START");
415 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
416 PanelInfo panelInfo;
417 panelInfo.panelType = SOFT_KEYBOARD;
418 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
419 DisplaySize display;
420 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
421 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
422 Rosen::Rect portraitRect = { 0, 0, display.portrait.width - 1, display.portrait.height - 1 };
423 Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 };
424 EnhancedLayoutParams params = {
425 .isFullScreen = false,
426 .portrait = { portraitRect, {}, -1, 0 },
427 .landscape = { landscapeRect, {}, 1, 0 },
428 };
429 HotAreas hotAreas;
430 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
431 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
432 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
433 }
434
435 /**
436 * @tc.name: testAdjustEnhancedPanelRect_009
437 * @tc.desc: Test AdjustPanelRect with invalid portrait avoid Y(> keyboard height).
438 * @tc.type: FUNC
439 */
440 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_009, TestSize.Level0)
441 {
442 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_009 Test START");
443 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
444 PanelInfo panelInfo;
445 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, {}, static_cast<int32_t>(portraitRect.height_) + 1, 0 },
455 .landscape = { landscapeRect, {}, static_cast<int32_t>(landscapeRect.height_) - 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_010
465 * @tc.desc: Test AdjustPanelRect with invalid landscape avoid Y(< 0).
466 * @tc.type: FUNC
467 */
468 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_010, TestSize.Level0)
469 {
470 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_010 Test START");
471 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
472 PanelInfo panelInfo;
473 panelInfo.panelType = SOFT_KEYBOARD;
474 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
475 DisplaySize display;
476 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
477 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
478 Rosen::Rect portraitRect = { 0, 0, display.portrait.width - 1, display.portrait.height - 1 };
479 Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 };
480 EnhancedLayoutParams params = {
481 .isFullScreen = false,
482 .portrait = { portraitRect, {}, 1, 0 },
483 .landscape = { landscapeRect, {}, -1, 0 },
484 };
485 HotAreas hotAreas;
486 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
487 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
488 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
489 }
490
491 /**
492 * @tc.name: testAdjustEnhancedPanelRect_011
493 * @tc.desc: Test AdjustPanelRect with invalid landscape avoid Y(> keyboard height).
494 * @tc.type: FUNC
495 */
496 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_011, TestSize.Level0)
497 {
498 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_011 Test START");
499 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
500 PanelInfo panelInfo;
501 panelInfo.panelType = SOFT_KEYBOARD;
502 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
503 DisplaySize display;
504 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
505 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
506 Rosen::Rect portraitRect = { 0, 0, display.portrait.width - 1, display.portrait.height - 1 };
507 Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 };
508 EnhancedLayoutParams params = {
509 .isFullScreen = false,
510 .portrait = { portraitRect, {}, static_cast<int32_t>(portraitRect.height_) - 1, 0 },
511 .landscape = { landscapeRect, {}, static_cast<int32_t>(landscapeRect.height_) + 1, 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_012
521 * @tc.desc: Test AdjustPanelRect with fixed, full screen, invalid portrait avoidHeight(> displayHeight * 0.7).
522 * @tc.type: FUNC
523 */
524 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_012, TestSize.Level0)
525 {
526 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_012 Test START");
527 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
528 PanelInfo panelInfo;
529 panelInfo.panelType = SOFT_KEYBOARD;
530 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
531 DisplaySize display;
532 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
533 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
534 uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1;
535 uint32_t portraitAvoidY = display.portrait.height - portraitAvoidHeight;
536 uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
537 uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight;
538 EnhancedLayoutParams params = {
539 .isFullScreen = true,
540 .portrait = { {}, {}, static_cast<int32_t>(portraitAvoidY), 0 },
541 .landscape = { {}, {}, static_cast<int32_t>(landscapeAvoidY), 0 },
542 };
543 HotAreas hotAreas;
544 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
545 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
546 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
547 }
548
549 /**
550 * @tc.name: testAdjustEnhancedPanelRect_013
551 * @tc.desc: Test AdjustPanelRect with fixed, full screen, invalid landscape avoidHeight(> displayHeight * 0.7).
552 * @tc.type: FUNC
553 */
554 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_013, TestSize.Level0)
555 {
556 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_013 Test START");
557 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
558 PanelInfo panelInfo;
559 panelInfo.panelType = SOFT_KEYBOARD;
560 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
561 DisplaySize display;
562 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
563 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
564 uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
565 uint32_t portraitAvoidY = display.portrait.height - portraitAvoidHeight;
566 uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1;
567 uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight;
568 EnhancedLayoutParams params = {
569 .isFullScreen = true,
570 .portrait = { {}, {}, static_cast<int32_t>(portraitAvoidY), 0 },
571 .landscape = { {}, {}, 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_014
581 * @tc.desc: Test AdjustPanelRect with fixed, non full screen, invalid portrait avoidHeight(> displayHeight * 0.7).
582 * @tc.type: FUNC
583 */
584 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_014, TestSize.Level0)
585 {
586 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_014 Test START");
587 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
588 PanelInfo panelInfo;
589 panelInfo.panelType = SOFT_KEYBOARD;
590 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
591 DisplaySize display;
592 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
593 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
594 Rosen::Rect portraitRect = { 0, 0, 100, static_cast<uint32_t>(display.portrait.height * 0.8) };
595 Rosen::Rect landscapeRect = { 0, 0, 100, static_cast<uint32_t>(display.landscape.height * 0.8) };
596 uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1;
597 uint32_t portraitAvoidY = portraitRect.height_ - portraitAvoidHeight;
598 uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
599 uint32_t landscapeAvoidY = landscapeRect.height_ - landscapeAvoidHeight;
600 EnhancedLayoutParams params = {
601 .isFullScreen = false,
602 .portrait = { portraitRect, {}, static_cast<int32_t>(portraitAvoidY), 0 },
603 .landscape = { landscapeRect, {}, static_cast<int32_t>(landscapeAvoidY), 0 },
604 };
605 HotAreas hotAreas;
606 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
607 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
608 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
609 }
610
611 /**
612 * @tc.name: testAdjustEnhancedPanelRect_015
613 * @tc.desc: Test AdjustPanelRect with fixed, non full screen, invalid landscape avoidHeight(> displayHeight * 0.7).
614 * @tc.type: FUNC
615 */
616 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_015, TestSize.Level0)
617 {
618 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_015 Test START");
619 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
620 PanelInfo panelInfo;
621 panelInfo.panelType = SOFT_KEYBOARD;
622 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
623 DisplaySize display;
624 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
625 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
626 Rosen::Rect portraitRect = { 0, 0, 100, static_cast<uint32_t>(display.portrait.height * 0.8) };
627 Rosen::Rect landscapeRect = { 0, 0, 100, static_cast<uint32_t>(display.landscape.height * 0.8) };
628 uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
629 uint32_t portraitAvoidY = portraitRect.height_ - portraitAvoidHeight;
630 uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1;
631 uint32_t landscapeAvoidY = landscapeRect.height_ - landscapeAvoidHeight;
632 EnhancedLayoutParams params = {
633 .isFullScreen = false,
634 .portrait = { portraitRect, {}, static_cast<int32_t>(portraitAvoidY), 0 },
635 .landscape = { landscapeRect, {}, static_cast<int32_t>(landscapeAvoidY), 0 },
636 };
637 HotAreas hotAreas;
638 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
639 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
640 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
641 }
642
643 /**
644 * @tc.name: testAdjustEnhancedPanelRect_016
645 * @tc.desc: Test AdjustPanelRect with fixed, non full screen, success.
646 * @tc.type: FUNC
647 */
648 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_016, TestSize.Level0)
649 {
650 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_016 Test START");
651 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
652 PanelInfo panelInfo;
653 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, 100, static_cast<uint32_t>(display.portrait.height * 0.8) };
659 Rosen::Rect landscapeRect = { 0, 0, 100, static_cast<uint32_t>(display.landscape.height * 0.8) };
660 uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
661 uint32_t portraitAvoidY = display.portrait.height - portraitAvoidHeight;
662 uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
663 uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight;
664 EnhancedLayoutParams params = {
665 .isFullScreen = true,
666 .portrait = { portraitRect, {}, static_cast<int32_t>(portraitAvoidY), 0 },
667 .landscape = { landscapeRect, {}, static_cast<int32_t>(landscapeAvoidY), 0 },
668 };
669 HotAreas hotAreas;
670 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
671 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
672 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
673 }
674
675 /**
676 * @tc.name: testAdjustEnhancedPanelRect_017
677 * @tc.desc: Test old AdjustPanelRect with 0 width input, then UpdateRegion success.
678 * @tc.type: FUNC
679 */
680 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_017, TestSize.Level0)
681 {
682 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_017 Test START");
683 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
684 PanelInfo panelInfo;
685 panelInfo.panelType = SOFT_KEYBOARD;
686 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
687 DisplaySize display;
688 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
689 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
690 Rosen::Rect portraitRect = { 0, 0, 0, static_cast<uint32_t>(display.portrait.height * 0.4) };
691 Rosen::Rect landscapeRect = { 0, 0, 0, static_cast<uint32_t>(display.landscape.height * 0.4) };
692 LayoutParams layoutParams = { .landscapeRect = landscapeRect, .portraitRect = portraitRect };
693 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true);
694 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
695
696 Rosen::Rect keyboardHotArea = {};
697 bool isPortrait = inputMethodPanel->IsDisplayPortrait();
698 if (isPortrait) {
699 keyboardHotArea = { 0, 0, static_cast<uint32_t>(display.portrait.width * 0.5), portraitRect.height_ };
700 } else {
701 keyboardHotArea = { 0, 0, static_cast<uint32_t>(display.landscape.width * 0.5), landscapeRect.height_ };
702 }
703 std::vector<Rosen::Rect> region = { keyboardHotArea };
704 ret = inputMethodPanel->UpdateRegion(region);
705 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
706 if (isPortrait) {
707 EXPECT_EQ(inputMethodPanel->hotAreas_.portrait.keyboardHotArea.size(), 1);
708 EXPECT_EQ(inputMethodPanel->hotAreas_.portrait.keyboardHotArea[0], keyboardHotArea);
709 } else {
710 EXPECT_EQ(inputMethodPanel->hotAreas_.landscape.keyboardHotArea.size(), 1);
711 EXPECT_EQ(inputMethodPanel->hotAreas_.landscape.keyboardHotArea[0], keyboardHotArea);
712 }
713 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
714 }
715
716 /**
717 * @tc.name: testAdjustEnhancedPanelRect_018
718 * @tc.desc: Test old AdjustPanelRect, then UpdateRegion, then moveTo can not change hot Areas.
719 * @tc.type: FUNC
720 */
721 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_018, TestSize.Level0)
722 {
723 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_018 Test START");
724 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
725 PanelInfo panelInfo;
726 panelInfo.panelType = SOFT_KEYBOARD;
727 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
728 DisplaySize display;
729 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
730 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
731 Rosen::Rect portraitRect = { 0, 0, display.portrait.width, static_cast<uint32_t>(display.portrait.height * 0.5) };
732 Rosen::Rect landscapeRect = { 0, 0, display.landscape.width,
733 static_cast<uint32_t>(display.landscape.height * 0.5) };
734 LayoutParams layoutParams = { .landscapeRect = landscapeRect, .portraitRect = portraitRect };
735 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true);
736 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
737
738 Rosen::Rect keyboardHotArea = {};
739 bool isPortrait = inputMethodPanel->IsDisplayPortrait();
740 if (isPortrait) {
741 keyboardHotArea = { 0, 0, static_cast<uint32_t>(portraitRect.width_ * 0.5), portraitRect.height_ };
742 } else {
743 keyboardHotArea = { 0, 0, static_cast<uint32_t>(landscapeRect.width_ * 0.5), landscapeRect.height_ };
744 }
745 std::vector<Rosen::Rect> region = { keyboardHotArea };
746 ret = inputMethodPanel->UpdateRegion(region);
747 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
748 ret = inputMethodPanel->MoveTo(1, 1);
749 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
750 if (isPortrait) {
751 EXPECT_EQ(inputMethodPanel->hotAreas_.portrait.keyboardHotArea.size(), 1);
752 EXPECT_EQ(inputMethodPanel->hotAreas_.portrait.keyboardHotArea[0], keyboardHotArea);
753 } else {
754 EXPECT_EQ(inputMethodPanel->hotAreas_.landscape.keyboardHotArea.size(), 1);
755 EXPECT_EQ(inputMethodPanel->hotAreas_.landscape.keyboardHotArea[0], keyboardHotArea);
756 }
757 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
758 }
759
760 /**
761 * @tc.name: testAdjustEnhancedPanelRect_019
762 * @tc.desc: Test old AdjustPanelRect, then Resize.
763 * @tc.type: FUNC
764 */
765 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_019, TestSize.Level0)
766 {
767 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_019 Test START");
768 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
769 PanelInfo panelInfo;
770 panelInfo.panelType = SOFT_KEYBOARD;
771 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
772 inputMethodPanel->isScbEnable_ = true;
773 DisplaySize display;
774 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
775 PanelFlag panelFlag = PanelFlag::FLG_FLOATING;
776 Rosen::Rect portraitRect = { 0, 0, display.portrait.width, static_cast<uint32_t>(display.portrait.height * 0.5) };
777 Rosen::Rect landscapeRect = { 0, 0, display.landscape.width,
778 static_cast<uint32_t>(display.landscape.height * 0.5) };
779 LayoutParams layoutParams = { .landscapeRect = landscapeRect, .portraitRect = portraitRect };
780 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true);
781 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
782
783 WindowSize size = {};
784 bool isPortrait = inputMethodPanel->IsDisplayPortrait();
785 if (isPortrait) {
786 size = { static_cast<uint32_t>(portraitRect.width_ * 0.5), static_cast<uint32_t>(portraitRect.height_ * 0.5) };
787 inputMethodPanel->resizePanelUnfoldParams_.landscapeRect.width_ = display.landscape.width + 1;
788 inputMethodPanel->resizePanelFoldParams_.landscapeRect.width_ = display.landscape.width + 1;
789 } else {
790 size = { static_cast<uint32_t>(landscapeRect.width_ * 0.5),
791 static_cast<uint32_t>(landscapeRect.height_ * 0.5) };
792 inputMethodPanel->resizePanelUnfoldParams_.portraitRect.width_ = display.portrait.width + 1;
793 inputMethodPanel->resizePanelFoldParams_.portraitRect.width_ = display.portrait.width + 1;
794 }
795 ret = inputMethodPanel->Resize(size.width, size.height);
796 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
797 Rosen::Rect newRect = { 0, 0, size.width, size.height };
798 if (isPortrait) {
799 EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.PortraitKeyboardRect_, newRect);
800 EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.LandscapeKeyboardRect_, landscapeRect);
801 } else {
802 EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.PortraitKeyboardRect_, portraitRect);
803 EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.LandscapeKeyboardRect_, newRect);
804 }
805 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
806 }
807
808 /**
809 * @tc.name: testAdjustEnhancedPanelRect_020
810 * @tc.desc: Test new AdjustPanelRect, then Resize.
811 * @tc.type: FUNC
812 */
813 HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_020, TestSize.Level0)
814 {
815 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustEnhancedPanelRect_020 Test START");
816 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
817 PanelInfo panelInfo;
818 panelInfo.panelType = SOFT_KEYBOARD;
819 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
820 inputMethodPanel->isScbEnable_ = true;
821 DisplaySize display;
822 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
823 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
824 Rosen::Rect portraitRect = { 0, 0, 0, static_cast<uint32_t>(display.portrait.height * 0.8) };
825 Rosen::Rect landscapeRect = { 0, 0, 0, static_cast<uint32_t>(display.landscape.height * 0.8) };
826 uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
827 uint32_t portraitAvoidY = display.portrait.height - portraitAvoidHeight;
828 uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
829 uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight;
830 EnhancedLayoutParams params = {
831 .isFullScreen = false,
832 .portrait = { portraitRect, {}, static_cast<int32_t>(portraitAvoidY), 0 },
833 .landscape = { landscapeRect, {}, static_cast<int32_t>(landscapeAvoidY), 0 },
834 };
835 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, {});
836 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
837
838 WindowSize size = {};
839 bool isPortrait = inputMethodPanel->IsDisplayPortrait();
840 if (isPortrait) {
841 size = { 100, static_cast<uint32_t>(portraitRect.height_ * 0.5) };
842 } else {
843 size = { 100, static_cast<uint32_t>(landscapeRect.height_ * 0.5) };
844 }
845 ret = inputMethodPanel->Resize(size.width, size.height);
846 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
847 if (isPortrait) {
848 Rosen::Rect newPortraitRect = { 0, static_cast<int32_t>(display.portrait.height - size.height),
849 display.portrait.width, size.height };
850 Rosen::Rect newLandRect = { 0, static_cast<int32_t>(display.landscape.height - landscapeRect.height_),
851 display.landscape.width, landscapeRect.height_ };
852 EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.PortraitKeyboardRect_, newPortraitRect);
853 EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.LandscapeKeyboardRect_, newLandRect);
854 } else {
855 Rosen::Rect newPortraitRect = { 0, static_cast<int32_t>(display.portrait.height - portraitRect.height_),
856 display.portrait.width, portraitRect.height_ };
857 Rosen::Rect newLandRect = { 0, static_cast<int32_t>(display.landscape.height - size.height),
858 display.landscape.width, size.height };
859 EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.PortraitKeyboardRect_, newPortraitRect);
860 EXPECT_EQ(inputMethodPanel->keyboardLayoutParams_.LandscapeKeyboardRect_, newLandRect);
861 }
862 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
863 }
864
865 /**
866 * @tc.name: testSetImmersiveEffect_001
867 * @tc.desc: Test SetImmersiveEffect device not supported.
868 * @tc.type: FUNC
869 */
870 HWTEST_F(InputMethodPanelAdjustTest, testSetImmersiveEffect_001, TestSize.Level0)
871 {
872 IMSA_HILOGI("InputMethodPanelAdjustTest testSetImmersiveEffect_001 Test START");
873 InputMethodPanelAdjustTest::SetImmersiveCapacitySupport(true);
874 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
875 PanelInfo panelInfo;
876 panelInfo.panelType = SOFT_KEYBOARD;
877 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
878
879 ImmersiveEffect immersiveEffect = {
880 .gradientHeight = 20, .gradientMode = GradientMode::LINEAR_GRADIENT, .fluidLightMode = FluidLightMode::NONE
881 };
882 int32_t ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
883 EXPECT_NE(ret, ErrorCode::ERROR_DEVICE_UNSUPPORTED);
884 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
885 }
886
887 /**
888 * @tc.name: testSetImmersiveEffect_002
889 * @tc.desc: Test SetImmersiveEffect invalid GradientMode or invalid FluidLightMode.
890 * @tc.type: FUNC
891 */
892 HWTEST_F(InputMethodPanelAdjustTest, testSetImmersiveEffect_002, TestSize.Level0)
893 {
894 IMSA_HILOGI("InputMethodPanelAdjustTest testSetImmersiveEffect_002 Test START");
895 InputMethodPanelAdjustTest::SetImmersiveCapacitySupport(true);
896 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
897 PanelInfo panelInfo;
898 panelInfo.panelType = SOFT_KEYBOARD;
899 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
900 ImmersiveEffect immersiveEffect;
901
902 immersiveEffect.gradientMode = static_cast<GradientMode>(-1);
903 int32_t ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
904 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
905
906 immersiveEffect.gradientMode = GradientMode::END;
907 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
908 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
909
910 immersiveEffect.gradientMode = GradientMode::LINEAR_GRADIENT;
911 immersiveEffect.fluidLightMode = static_cast<FluidLightMode>(-1);
912 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
913 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
914
915 immersiveEffect.gradientMode = GradientMode::LINEAR_GRADIENT;
916 immersiveEffect.fluidLightMode = FluidLightMode::END;
917 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
918 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
919 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
920 }
921
922 /**
923 * @tc.name: testSetImmersiveEffect_003
924 * @tc.desc: Test SetImmersiveEffect when not in immersive mode
925 * @tc.type: FUNC
926 */
927 HWTEST_F(InputMethodPanelAdjustTest, testSetImmersiveEffect_003, TestSize.Level0)
928 {
929 IMSA_HILOGI("InputMethodPanelAdjustTest testSetImmersiveEffect_003 Test START");
930 InputMethodPanelAdjustTest::SetImmersiveCapacitySupport(true);
931 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
932 PanelInfo panelInfo;
933 panelInfo.panelType = SOFT_KEYBOARD;
934 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
935 ImmersiveEffect immersiveEffect;
936
937 inputMethodPanel->immersiveMode_ = ImmersiveMode::NONE_IMMERSIVE;
938 immersiveEffect = { .gradientMode = GradientMode::LINEAR_GRADIENT, .fluidLightMode = FluidLightMode::NONE };
939 int32_t ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
940 EXPECT_EQ(ret, ErrorCode::ERROR_IMA_INVALID_IMMERSIVE_EFFECT);
941 immersiveEffect = { .gradientMode = GradientMode::NONE, .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
942 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
943 EXPECT_EQ(ret, ErrorCode::ERROR_IMA_INVALID_IMMERSIVE_EFFECT);
944 immersiveEffect = { .gradientHeight = 1,
945 .gradientMode = GradientMode::NONE,
946 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
947 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
948 EXPECT_EQ(ret, ErrorCode::ERROR_IMA_INVALID_IMMERSIVE_EFFECT);
949 immersiveEffect = { .gradientMode = GradientMode::NONE, .fluidLightMode = FluidLightMode::NONE };
950 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
951 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
952 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
953 }
954
955 /**
956 * @tc.name: testSetImmersiveEffect_004
957 * @tc.desc: Test SetImmersiveEffect invalid parameter.
958 * @tc.type: FUNC
959 */
960 HWTEST_F(InputMethodPanelAdjustTest, testSetImmersiveEffect_004, TestSize.Level0)
961 {
962 IMSA_HILOGI("InputMethodPanelAdjustTest testSetImmersiveEffect_004 Test START");
963 InputMethodPanelAdjustTest::SetImmersiveCapacitySupport(true);
964 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
965 PanelInfo panelInfo;
966 panelInfo.panelType = SOFT_KEYBOARD;
967 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
968 ImmersiveEffect immersiveEffect;
969
970 // The fluid light mode can only be used when the gradient mode is enabled.
971 inputMethodPanel->immersiveMode_ = ImmersiveMode::IMMERSIVE;
972 immersiveEffect = { .gradientMode = GradientMode::NONE, .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
973 int32_t ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
974 EXPECT_EQ(ret, ErrorCode::ERROR_IMA_INVALID_IMMERSIVE_EFFECT);
975
976 // Only system applications can set the fluid light mode.
977 IdentityCheckerMock::SetSystemApp(false);
978 immersiveEffect = { .gradientMode = GradientMode::LINEAR_GRADIENT,
979 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
980 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
981 EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION);
982 immersiveEffect = { .gradientMode = GradientMode::LINEAR_GRADIENT, .fluidLightMode = FluidLightMode::NONE };
983 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
984 EXPECT_NE(ret, ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION);
985
986 // gradientHeight can not over INT32_MAX or display height
987 IdentityCheckerMock::SetSystemApp(true);
988 DisplaySize displaySize;
989 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
990 bool isPortrait = inputMethodPanel->IsDisplayPortrait();
991 uint32_t gradientHeight = static_cast<uint32_t>(INT32_MAX) + 1;
992 immersiveEffect = { .gradientHeight = gradientHeight,
993 .gradientMode = GradientMode::LINEAR_GRADIENT,
994 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
995 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
996 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
997 if (isPortrait) {
998 gradientHeight = displaySize.portrait.height + 1;
999 } else {
1000 gradientHeight = displaySize.landscape.height + 1;
1001 }
1002 immersiveEffect = { .gradientHeight = gradientHeight,
1003 .gradientMode = GradientMode::LINEAR_GRADIENT,
1004 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
1005 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
1006 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1007
1008 // The SetImmersiveEffect API must be called after the AdjustPanelRect API is called.
1009 IdentityCheckerMock::SetSystemApp(true);
1010 immersiveEffect = { .gradientHeight = 0,
1011 .gradientMode = GradientMode::LINEAR_GRADIENT,
1012 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
1013 Rosen::KeyboardLayoutParams emptyParams;
1014 inputMethodPanel->keyboardLayoutParams_ = emptyParams;
1015 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
1016 EXPECT_EQ(ret, ErrorCode::ERROR_IMA_PRECONDITION_REQUIRED);
1017 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
1018 }
1019
1020 /**
1021 * @tc.name: testSetImmersiveEffect_005
1022 * @tc.desc: Test SetImmersiveEffect, NormalImePrepare check parameter failed.
1023 * @tc.type: FUNC
1024 */
1025 HWTEST_F(InputMethodPanelAdjustTest, testSetImmersiveEffect_005, TestSize.Level0)
1026 {
1027 IMSA_HILOGI("InputMethodPanelAdjustTest testSetImmersiveEffect_005 Test START");
1028 InputMethodPanelAdjustTest::SetImmersiveCapacitySupport(true);
1029 IdentityCheckerMock::SetSystemApp(true);
1030 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1031 PanelInfo panelInfo;
1032 panelInfo.panelType = SOFT_KEYBOARD;
1033 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1034 inputMethodPanel->immersiveMode_ = ImmersiveMode::IMMERSIVE;
1035
1036 DisplaySize display;
1037 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
1038 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1039 Rosen::Rect portraitRect = { 0, 0, 0, static_cast<uint32_t>(display.portrait.height * 0.4) };
1040 Rosen::Rect landscapeRect = { 0, 0, 0, static_cast<uint32_t>(display.landscape.height * 0.4) };
1041 LayoutParams layoutParams = { .landscapeRect = landscapeRect, .portraitRect = portraitRect };
1042 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true);
1043 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1044
1045 ImmersiveEffect immersiveEffect;
1046 immersiveEffect = { .gradientHeight =
1047 static_cast<uint32_t>(display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO),
1048 .gradientMode = GradientMode::LINEAR_GRADIENT,
1049 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
1050 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
1051 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1052
1053 immersiveEffect = { .gradientHeight =
1054 static_cast<uint32_t>(display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO)
1055 - landscapeRect.height_ + 1,
1056 .gradientMode = GradientMode::LINEAR_GRADIENT,
1057 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
1058 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
1059 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1060 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
1061 }
1062
1063 /**
1064 * @tc.name: testSetImmersiveEffect_006
1065 * @tc.desc: Test SetImmersiveEffect, invalid gradient height.
1066 * @tc.type: FUNC
1067 */
1068 HWTEST_F(InputMethodPanelAdjustTest, testSetImmersiveEffect_006, TestSize.Level0)
1069 {
1070 IMSA_HILOGI("InputMethodPanelAdjustTest testSetImmersiveEffect_006 Test START");
1071 InputMethodPanelAdjustTest::SetImmersiveCapacitySupport(true);
1072 IdentityCheckerMock::SetSystemApp(true);
1073 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1074 PanelInfo panelInfo;
1075 panelInfo.panelType = SOFT_KEYBOARD;
1076 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1077 inputMethodPanel->immersiveMode_ = ImmersiveMode::IMMERSIVE;
1078
1079 DisplaySize display;
1080 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
1081 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1082 uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO;
1083 uint32_t portraitAvoidY = display.portrait.height - portraitAvoidHeight;
1084 uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO;
1085 uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight;
1086 EnhancedLayoutParams params = {
1087 .isFullScreen = true,
1088 .portrait = { {}, {}, static_cast<int32_t>(portraitAvoidY), 0 },
1089 .landscape = { {}, {}, static_cast<int32_t>(landscapeAvoidY), 0 },
1090 };
1091 HotAreas hotAreas;
1092 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
1093 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1094
1095 DisplaySize displaySize;
1096 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
1097 uint32_t gradientHeight = displaySize.portrait.height * GRADIENT_HEIGHT_RATIO + 1;
1098 ImmersiveEffect immersiveEffect = { .gradientHeight = gradientHeight,
1099 .gradientMode = GradientMode::LINEAR_GRADIENT,
1100 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
1101 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
1102 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1103 gradientHeight = displaySize.landscape.height * GRADIENT_HEIGHT_RATIO + 1;
1104 immersiveEffect = { .gradientHeight = gradientHeight,
1105 .gradientMode = GradientMode::LINEAR_GRADIENT,
1106 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
1107 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
1108 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1109 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
1110 }
1111
1112 /**
1113 * @tc.name: testSetImmersiveEffect_007
1114 * @tc.desc: Test SetImmersiveEffect, check invalid gradient height.
1115 * @tc.type: FUNC
1116 */
1117 HWTEST_F(InputMethodPanelAdjustTest, testSetImmersiveEffect_007, TestSize.Level0)
1118 {
1119 IMSA_HILOGI("InputMethodPanelAdjustTest testSetImmersiveEffect_007 Test START");
1120 InputMethodPanelAdjustTest::SetImmersiveCapacitySupport(true);
1121 IdentityCheckerMock::SetSystemApp(true);
1122 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1123 PanelInfo panelInfo;
1124 panelInfo.panelType = SOFT_KEYBOARD;
1125 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1126 inputMethodPanel->immersiveMode_ = ImmersiveMode::IMMERSIVE;
1127
1128 DisplaySize display;
1129 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
1130 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1131 uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO;
1132 uint32_t portraitAvoidY = display.portrait.height - portraitAvoidHeight;
1133 uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO;
1134 uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight;
1135 EnhancedLayoutParams params = {
1136 .isFullScreen = true,
1137 .portrait = { {}, {}, static_cast<int32_t>(portraitAvoidY), 0 },
1138 .landscape = { {}, {}, static_cast<int32_t>(landscapeAvoidY), 0 },
1139 };
1140 HotAreas hotAreas;
1141 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
1142 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1143
1144 DisplaySize displaySize;
1145 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
1146 bool isPortrait = inputMethodPanel->IsDisplayPortrait();
1147 uint32_t gradientHeight = 0;
1148 if (isPortrait) {
1149 gradientHeight = displaySize.portrait.height * GRADIENT_HEIGHT_RATIO + 1;
1150 } else {
1151 gradientHeight = displaySize.landscape.height * GRADIENT_HEIGHT_RATIO + 1;
1152 }
1153 ImmersiveEffect immersiveEffect = { .gradientHeight = gradientHeight,
1154 .gradientMode = GradientMode::LINEAR_GRADIENT,
1155 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
1156 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
1157 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1158 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
1159 }
1160 /**
1161 * @tc.name: testSetImmersiveEffect_008
1162 * @tc.desc: Test SetImmersiveEffect, NormalImePrepare success.
1163 * @tc.type: FUNC
1164 */
1165 HWTEST_F(InputMethodPanelAdjustTest, testSetImmersiveEffect_008, TestSize.Level0)
1166 {
1167 IMSA_HILOGI("InputMethodPanelAdjustTest testSetImmersiveEffect_008 Test START");
1168 InputMethodPanelAdjustTest::SetImmersiveCapacitySupport(true);
1169 IdentityCheckerMock::SetSystemApp(true);
1170 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1171 PanelInfo panelInfo;
1172 panelInfo.panelType = SOFT_KEYBOARD;
1173 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1174 inputMethodPanel->immersiveMode_ = ImmersiveMode::IMMERSIVE;
1175
1176 DisplaySize display;
1177 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
1178 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1179 Rosen::Rect portraitRect = { 0, 0, 0, static_cast<uint32_t>(display.portrait.height * 0.4) };
1180 Rosen::Rect landscapeRect = { 0, 0, 0, static_cast<uint32_t>(display.landscape.height * 0.4) };
1181 LayoutParams layoutParams = { .landscapeRect = landscapeRect, .portraitRect = portraitRect };
1182 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, layoutParams, true);
1183 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1184 AccessScope scope(currentImeTokenId_, currentImeUid_);
1185 ret = inputMethodPanel->ShowPanel();
1186 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1187
1188 ImmersiveEffect immersiveEffect;
1189 immersiveEffect = { .gradientHeight = static_cast<uint32_t>(display.landscape.height * 0.1),
1190 .gradientMode = GradientMode::LINEAR_GRADIENT,
1191 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
1192 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
1193 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1194 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
1195 }
1196
1197 /**
1198 * @tc.name: testSetImmersiveEffect_009
1199 * @tc.desc: Test SetImmersiveEffect, FullScreenPrepare success.
1200 * @tc.type: FUNC
1201 */
1202 HWTEST_F(InputMethodPanelAdjustTest, testSetImmersiveEffect_009, TestSize.Level0)
1203 {
1204 IMSA_HILOGI("InputMethodPanelAdjustTest testSetImmersiveEffect_009 Test START");
1205 InputMethodPanelAdjustTest::SetImmersiveCapacitySupport(true);
1206 IdentityCheckerMock::SetSystemApp(true);
1207 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1208 PanelInfo panelInfo;
1209 panelInfo.panelType = SOFT_KEYBOARD;
1210 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1211 inputMethodPanel->immersiveMode_ = ImmersiveMode::IMMERSIVE;
1212
1213 DisplaySize display;
1214 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
1215 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1216 uint32_t portraitAvoidHeight = display.portrait.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
1217 uint32_t portraitAvoidY = display.portrait.height - portraitAvoidHeight;
1218 uint32_t landscapeAvoidHeight = display.landscape.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1;
1219 uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight;
1220 EnhancedLayoutParams params = {
1221 .isFullScreen = true,
1222 .portrait = { {}, {}, static_cast<int32_t>(portraitAvoidY), 0 },
1223 .landscape = { {}, {}, static_cast<int32_t>(landscapeAvoidY), 0 },
1224 };
1225 HotAreas hotAreas;
1226 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas);
1227 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1228 AccessScope scope(currentImeTokenId_, currentImeUid_);
1229 ret = inputMethodPanel->ShowPanel();
1230 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1231
1232 ImmersiveEffect immersiveEffect;
1233 immersiveEffect = { .gradientHeight = 1,
1234 .gradientMode = GradientMode::LINEAR_GRADIENT,
1235 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
1236 ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
1237 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1238 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
1239 }
1240
1241 /**
1242 * @tc.name: testSetImmersiveEffect_010
1243 * @tc.desc: Test SetImmersiveEffect, invalid gradientHeight.
1244 * @tc.type: FUNC
1245 */
1246 HWTEST_F(InputMethodPanelAdjustTest, testSetImmersiveEffect_010, TestSize.Level0)
1247 {
1248 IMSA_HILOGI("InputMethodPanelAdjustTest testSetImmersiveEffect_010 Test START");
1249 InputMethodPanelAdjustTest::SetImmersiveCapacitySupport(true);
1250 IdentityCheckerMock::SetSystemApp(true);
1251 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1252 PanelInfo panelInfo;
1253 panelInfo.panelType = SOFT_KEYBOARD;
1254 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1255 inputMethodPanel->immersiveMode_ = ImmersiveMode::IMMERSIVE;
1256
1257 DisplaySize displaySize;
1258 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(displaySize), ErrorCode::NO_ERROR);
1259 bool isPortrait = inputMethodPanel->IsDisplayPortrait();
1260 uint32_t gradientHeight = 0;
1261 if (isPortrait) {
1262 gradientHeight = displaySize.portrait.width * GRADIENT_HEIGHT_RATIO + 1;
1263 } else {
1264 gradientHeight = displaySize.landscape.width * GRADIENT_HEIGHT_RATIO + 1;
1265 }
1266 ImmersiveEffect immersiveEffect = { .gradientHeight = gradientHeight,
1267 .gradientMode = GradientMode::LINEAR_GRADIENT,
1268 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
1269 auto ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
1270 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1271 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
1272 }
1273
1274 /**
1275 * @tc.name: testSetImmersiveEffect_011
1276 * @tc.desc: Test SetImmersiveEffect, invalid gradientHeight.
1277 * @tc.type: FUNC
1278 */
1279 HWTEST_F(InputMethodPanelAdjustTest, testSetImmersiveEffect_011, TestSize.Level0)
1280 {
1281 IMSA_HILOGI("InputMethodPanelAdjustTest testSetImmersiveEffect_011 Test START");
1282 InputMethodPanelAdjustTest::SetImmersiveCapacitySupport(true);
1283 IdentityCheckerMock::SetSystemApp(true);
1284 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1285 PanelInfo panelInfo;
1286 panelInfo.panelType = SOFT_KEYBOARD;
1287 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1288 inputMethodPanel->immersiveMode_ = ImmersiveMode::IMMERSIVE;
1289
1290 ImmersiveEffect immersiveEffect;
1291 immersiveEffect = { .gradientHeight = INT32_MAX + 1,
1292 .gradientMode = GradientMode::LINEAR_GRADIENT,
1293 .fluidLightMode = FluidLightMode::BACKGROUND_FLUID_LIGHT };
1294 auto ret = inputMethodPanel->SetImmersiveEffect(immersiveEffect);
1295 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1296 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
1297 }
1298
1299 /**
1300 * @tc.name: testAdjustPanelRect_001
1301 * @tc.desc: Test AdjustPanelRect window_ nullptr.
1302 * @tc.type: FUNC
1303 */
1304 HWTEST_F(InputMethodPanelAdjustTest, testAdjustPanelRect_001, TestSize.Level0)
1305 {
1306 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustPanelRect_001 Test START");
1307 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1308 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1309 LayoutParams params;
1310 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params);
1311 EXPECT_EQ(ret, ErrorCode::ERROR_WINDOW_MANAGER);
1312 }
1313
1314 /**
1315 * @tc.name: testAdjustPanelRect_002
1316 * @tc.desc: Test AdjustPanelRect ParseParams failed: invalid portrait rect.
1317 * @tc.type: FUNC
1318 */
1319 HWTEST_F(InputMethodPanelAdjustTest, testAdjustPanelRect_002, TestSize.Level0)
1320 {
1321 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustPanelRect_002 Test START");
1322 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1323 PanelInfo panelInfo;
1324 panelInfo.panelType = SOFT_KEYBOARD;
1325 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1326
1327 DisplaySize display;
1328 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
1329 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1330 LayoutParams params;
1331 // 1 - posX < 0
1332 params.portraitRect = { -1, 0, display.portrait.width, 0 };
1333 params.landscapeRect = { 0, 0, display.landscape.width, 0 };
1334 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params);
1335 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1336 // 2 - posY < 0
1337 params.portraitRect = { 0, -1, display.portrait.width, 0 };
1338 params.landscapeRect = { 0, 0, display.landscape.width, 0 };
1339 ret = inputMethodPanel->AdjustPanelRect(panelFlag, params);
1340 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1341 // 3 - width > INT32_MAX
1342 params.portraitRect = { 0, 0, static_cast<uint32_t>(INT32_MAX) + 1, 0 };
1343 params.landscapeRect = { 0, 0, display.landscape.width, 0 };
1344 ret = inputMethodPanel->AdjustPanelRect(panelFlag, params);
1345 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1346 // 4 - height > INT32_MAX
1347 params.portraitRect = { 0, 0, display.portrait.width, static_cast<uint32_t>(INT32_MAX) + 1 };
1348 params.landscapeRect = { 0, 0, display.landscape.width, 0 };
1349 ret = inputMethodPanel->AdjustPanelRect(panelFlag, params);
1350 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1351 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
1352 }
1353
1354 /**
1355 * @tc.name: testAdjustPanelRect_003
1356 * @tc.desc: Test AdjustPanelRect ParseParams failed: invalid landscape rect.
1357 * @tc.type: FUNC
1358 */
1359 HWTEST_F(InputMethodPanelAdjustTest, testAdjustPanelRect_003, TestSize.Level0)
1360 {
1361 IMSA_HILOGI("InputMethodPanelAdjustTest testAdjustPanelRect_003 Test START");
1362 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1363 PanelInfo panelInfo;
1364 panelInfo.panelType = SOFT_KEYBOARD;
1365 InputMethodPanelAdjustTest::ImaCreatePanel(panelInfo, inputMethodPanel);
1366
1367 DisplaySize display;
1368 ASSERT_EQ(InputMethodPanelAdjustTest::GetDisplaySize(display), ErrorCode::NO_ERROR);
1369 PanelFlag panelFlag = PanelFlag::FLG_FIXED;
1370 LayoutParams params;
1371 // 1 - posX < 0
1372 params.portraitRect = { 0, 0, display.portrait.width, 0 };
1373 params.landscapeRect = { -1, 0, display.landscape.width, 0 };
1374 auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params);
1375 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1376 // 2 - posY < 0
1377 params.portraitRect = { 0, 0, display.portrait.width, 0 };
1378 params.landscapeRect = { 0, -1, display.landscape.width, 0 };
1379 ret = inputMethodPanel->AdjustPanelRect(panelFlag, params);
1380 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1381 // 3 - width > INT32_MAX
1382 params.portraitRect = { 0, 0, display.portrait.width, 0 };
1383 params.landscapeRect = { 0, 0, static_cast<uint32_t>(INT32_MAX) + 1, 0 };
1384 ret = inputMethodPanel->AdjustPanelRect(panelFlag, params);
1385 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1386 // 4 - height > INT32_MAX
1387 params.portraitRect = { 0, 0, display.portrait.width, 0 };
1388 params.landscapeRect = { 0, 0, display.landscape.width, static_cast<uint32_t>(INT32_MAX) + 1 };
1389 ret = inputMethodPanel->AdjustPanelRect(panelFlag, params);
1390 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
1391 InputMethodPanelAdjustTest::ImaDestroyPanel(inputMethodPanel);
1392 }
1393 } // namespace MiscServices
1394 } // namespace OHOS