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
16 #include "session/host/include/keyboard_session.h"
17 #include <gtest/gtest.h>
18
19 #include "interfaces/include/ws_common.h"
20 #include "mock/mock_session_stage.h"
21 #include "mock/mock_keyboard_session.h"
22 #include "session/host/include/session.h"
23 #include "session/host/include/scene_session.h"
24 #include "screen_session_manager_client/include/screen_session_manager_client.h"
25 #include "ui/rs_surface_node.h"
26 #include "window_helper.h"
27 #include "window_manager_hilog.h"
28
29 using namespace testing;
30 using namespace testing::ext;
31
32 namespace OHOS {
33 namespace Rosen {
34 namespace {
35 std::string g_logMsg;
MyLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)36 void MyLogCallback(const LogType type, const LogLevel level,
37 const unsigned int domain, const char *tag, const char *msg)
38 {
39 g_logMsg += msg;
40 }
41 }
42
43 constexpr int WAIT_ASYNC_US = 1000000;
44 class KeyboardSessionTest4 : public testing::Test, public IScreenConnectionListener {
45 public:
46 static void SetUpTestCase();
47 static void TearDownTestCase();
48 void SetUp() override;
49 void TearDown() override;
50 void OnScreenConnected(const sptr<ScreenSession>& screenSession) override;
51 void OnScreenDisconnected(const sptr<ScreenSession>& screenSession) override;
52
53 private:
54 sptr<KeyboardSession> GetKeyboardSession(const std::string& abilityName, const std::string& bundleName);
55 sptr<SceneSession> GetSceneSession(const std::string& abilityName, const std::string& bundleName);
56 };
57
SetUpTestCase()58 void KeyboardSessionTest4::SetUpTestCase() {}
59
TearDownTestCase()60 void KeyboardSessionTest4::TearDownTestCase() {}
61
SetUp()62 void KeyboardSessionTest4::SetUp() {}
63
TearDown()64 void KeyboardSessionTest4::TearDown() {}
65
OnScreenConnected(const sptr<ScreenSession> & screenSession)66 void KeyboardSessionTest4::OnScreenConnected(const sptr<ScreenSession>& screenSession) {}
67
OnScreenDisconnected(const sptr<ScreenSession> & screenSession)68 void KeyboardSessionTest4::OnScreenDisconnected(const sptr<ScreenSession>& screenSession) {}
69
GetKeyboardSession(const std::string & abilityName,const std::string & bundleName)70 sptr<KeyboardSession> KeyboardSessionTest4::GetKeyboardSession(const std::string& abilityName,
71 const std::string& bundleName)
72 {
73 SessionInfo info;
74 info.abilityName_ = abilityName;
75 info.bundleName_ = bundleName;
76 sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
77 EXPECT_NE(specificCb, nullptr);
78 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
79 sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
80 EXPECT_NE(keyboardCb, nullptr);
81 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
82 EXPECT_NE(keyboardSession, nullptr);
83
84 sptr<WindowSessionProperty> keyboardProperty = sptr<WindowSessionProperty>::MakeSptr();
85 EXPECT_NE(keyboardProperty, nullptr);
86 keyboardProperty->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
87 keyboardSession->SetSessionProperty(keyboardProperty);
88
89 return keyboardSession;
90 }
91
GetSceneSession(const std::string & abilityName,const std::string & bundleName)92 sptr<SceneSession> KeyboardSessionTest4::GetSceneSession(const std::string& abilityName, const std::string& bundleName)
93 {
94 SessionInfo info;
95 info.abilityName_ = abilityName;
96 info.bundleName_ = bundleName;
97 sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
98 EXPECT_NE(specificCb, nullptr);
99 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
100
101 return sceneSession;
102 }
103
104 namespace {
105 /**
106 * @tc.name: BindKeyboardPanelSession
107 * @tc.desc: BindKeyboardPanelSession
108 * @tc.type: FUNC
109 */
110 HWTEST_F(KeyboardSessionTest4, BindKeyboardPanelSession, TestSize.Level0)
111 {
112 SessionInfo info;
113 info.abilityName_ = "BindKeyboardPanelSession";
114 info.bundleName_ = "BindKeyboardPanelSession";
115 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
116 ASSERT_NE(keyboardSession, nullptr);
117 sptr<SceneSession> panelSession = nullptr;
118 keyboardSession->BindKeyboardPanelSession(panelSession);
119 sptr<SceneSession> getPanelSession = keyboardSession->GetKeyboardPanelSession();
120 ASSERT_EQ(getPanelSession, nullptr);
121 panelSession = sptr<SceneSession>::MakeSptr(info, nullptr);
122 ASSERT_NE(panelSession, nullptr);
123 keyboardSession->BindKeyboardPanelSession(panelSession);
124 getPanelSession = keyboardSession->GetKeyboardPanelSession();
125 EXPECT_EQ(getPanelSession, panelSession);
126 }
127
128 /**
129 * @tc.name: GetKeyboardGravity01
130 * @tc.desc: GetKeyboardGravity01
131 * @tc.type: FUNC
132 */
133 HWTEST_F(KeyboardSessionTest4, GetKeyboardGravity01, TestSize.Level0)
134 {
135 SessionInfo info;
136 info.abilityName_ = "GetKeyboardGravity";
137 info.bundleName_ = "GetKeyboardGravity";
138 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
139 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
140 keyboardSession->property_ = windowSessionProperty;
141 keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
142 auto ret = keyboardSession->GetKeyboardGravity();
143 EXPECT_EQ(SessionGravity::SESSION_GRAVITY_BOTTOM, ret);
144 }
145
146 /**
147 * @tc.name: NotifyKeyboardPanelInfoChange
148 * @tc.desc: NotifyKeyboardPanelInfoChange
149 * @tc.type: FUNC
150 */
151 HWTEST_F(KeyboardSessionTest4, NotifyKeyboardPanelInfoChange, TestSize.Level1)
152 {
153 WSRect rect = { 800, 800, 1200, 1200 };
154 SessionInfo info;
155 info.abilityName_ = "NotifyKeyboardPanelInfoChange";
156 info.bundleName_ = "NotifyKeyboardPanelInfoChange";
157 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
158 ASSERT_NE(keyboardSession, nullptr);
159 keyboardSession->isKeyboardPanelEnabled_ = false;
160 keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
161 keyboardSession->isKeyboardPanelEnabled_ = true;
162 keyboardSession->sessionStage_ = nullptr;
163 keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
164 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
165 ASSERT_NE(mockSessionStage, nullptr);
166 keyboardSession->sessionStage_ = mockSessionStage;
167 ASSERT_NE(keyboardSession->sessionStage_, nullptr);
168 keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
169 }
170
171 /**
172 * @tc.name: Hide01
173 * @tc.desc: test function: Hide
174 * @tc.type: FUNC
175 */
176 HWTEST_F(KeyboardSessionTest4, Hide01, TestSize.Level0)
177 {
178 SessionInfo info;
179 info.abilityName_ = "Hide01";
180 info.bundleName_ = "Hide01";
181 sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
182 ASSERT_NE(specificCb, nullptr);
183 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
184 sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
185 ASSERT_NE(keyboardCb, nullptr);
186 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
187 ASSERT_NE(keyboardSession, nullptr);
188
189 // setActive false return not ok
190 keyboardSession->state_ = SessionState::STATE_DISCONNECT;
191 EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
192
193 // setActive false return ok and deviceType is phone
194 keyboardSession->state_ = SessionState::STATE_CONNECT;
195 keyboardSession->isActive_ = true;
196 keyboardSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
197 ASSERT_NE(keyboardSession->sessionStage_, nullptr);
198 keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
199 EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
200
201 // deviceType is pc and property is not nullptr
202 ASSERT_NE(keyboardSession->property_, nullptr);
203 keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
204 EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
205
206 // Hide system keyboard
207 ASSERT_EQ(false, keyboardSession->IsSystemKeyboard());
208 keyboardSession->SetIsSystemKeyboard(true);
209 ASSERT_EQ(true, keyboardSession->IsSystemKeyboard());
210 ASSERT_EQ(WSError::WS_OK, keyboardSession->Hide());
211 }
212
213 /**
214 * @tc.name: OpenKeyboardSyncTransaction
215 * @tc.desc: OpenKeyboardSyncTransaction
216 * @tc.type: FUNC
217 */
218 HWTEST_F(KeyboardSessionTest4, OpenKeyboardSyncTransaction, TestSize.Level1)
219 {
220 std::string abilityName = "OpenKeyboardSyncTransaction";
221 std::string bundleName = "OpenKeyboardSyncTransaction";
222 sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
223
224 WSRect keyboardPanelRect = { 0, 0, 0, 0 };
225 bool isKeyboardShow = true;
226 WindowAnimationInfo animationInfo;
227
228 // isKeyBoardSyncTransactionOpen_ is false
229 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, animationInfo);
230 keyboardSession->OpenKeyboardSyncTransaction();
231
232 // isKeyBoardSyncTransactionOpen_ is true
233 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, animationInfo);
234 keyboardSession->OpenKeyboardSyncTransaction();
235 ASSERT_EQ(keyboardSession->isKeyboardSyncTransactionOpen_, true);
236 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, animationInfo);
237 ASSERT_EQ(keyboardSession->isKeyboardSyncTransactionOpen_, false);
238 }
239
240 /**
241 * @tc.name: OpenKeyboardSyncTransaction01
242 * @tc.desc: OpenKeyboardSyncTransaction
243 * @tc.type: FUNC
244 */
245 HWTEST_F(KeyboardSessionTest4, OpenKeyboardSyncTransaction01, TestSize.Level1)
246 {
247 SessionInfo info;
248 info.abilityName_ = "OpenKeyboardSyncTransaction01";
249 info.bundleName_ = "OpenKeyboardSyncTransaction01";
250 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
251 ASSERT_NE(keyboardSession, nullptr);
252 keyboardSession->isKeyboardSyncTransactionOpen_ = true;
253 keyboardSession->OpenKeyboardSyncTransaction();
254 keyboardSession->isKeyboardSyncTransactionOpen_ = false;
255 keyboardSession->OpenKeyboardSyncTransaction();
256 WSRect keyboardPanelRect = {0, 0, 0, 0};
257 WindowAnimationInfo animationInfo;
258 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, true, animationInfo);
259 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, animationInfo);
260 }
261
262 /**
263 * @tc.name: CloseKeyBoardSyncTransaction01
264 * @tc.desc: test function: CloseKeyBoardSyncTransaction
265 * @tc.type: FUNC
266 */
267 HWTEST_F(KeyboardSessionTest4, CloseKeyBoardSyncTransaction01, TestSize.Level1)
268 {
269 std::string abilityName = "CloseKeyBoardSyncTransaction01";
270 std::string bundleName = "CloseKeyBoardSyncTransaction01";
271 sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
272 ASSERT_NE(keyboardSession, nullptr);
273
274 WSRect keyboardPanelRect;
275 bool isKeyboardShow = true;
276 WindowAnimationInfo animationInfo;
277
__anonb4e5377a0302(uint32_t callingSessionId) 278 keyboardSession->specificCallback_->onUpdateAvoidArea_ = [](uint32_t callingSessionId) {};
279 keyboardSession->isKeyboardSyncTransactionOpen_ = true;
280 // isKeyBoardSyncTransactionOpen_ is true
281 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, animationInfo);
282 usleep(WAIT_ASYNC_US);
283 ASSERT_EQ(keyboardSession->isKeyboardSyncTransactionOpen_, false);
284
285 ASSERT_NE(keyboardSession->keyboardCallback_, nullptr);
__anonb4e5377a0402(uint32_t persistentId) 286 keyboardSession->keyboardCallback_->onGetSceneSession = [](uint32_t persistentId) {
287 SessionInfo callingSessionInfo;
288 callingSessionInfo.abilityName_ = "CallingSession";
289 callingSessionInfo.bundleName_ = "CallingSession";
290 auto callingSession = sptr<SceneSession>::MakeSptr(callingSessionInfo, nullptr);
291 callingSession->persistentId_ = persistentId;
292 return callingSession;
293 };
294 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, animationInfo);
295 ASSERT_NE(keyboardSession->GetSceneSession(animationInfo.callingId), nullptr);
296 }
297
298 /**
299 * @tc.name: CloseKeyboardSyncTransaction02
300 * @tc.desc: test function: CloseKeyboardSyncTransaction
301 * @tc.type: FUNC
302 */
303 HWTEST_F(KeyboardSessionTest4, CloseKeyboardSyncTransaction02, TestSize.Level1)
304 {
305 std::string abilityName = "CloseKeyboardSyncTransaction02";
306 std::string bundleName = "CloseKeyboardSyncTransaction02";
307 sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
308 ASSERT_NE(keyboardSession, nullptr);
309 WSRect keyboardPanelRect = { 0, 0, 0, 0 };
310 WindowAnimationInfo animationInfo;
311
312 keyboardSession->isKeyboardSyncTransactionOpen_ = false;
313 ASSERT_NE(keyboardSession->property_, nullptr);
314 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, animationInfo);
315 usleep(WAIT_ASYNC_US);
316 keyboardSession->isKeyboardSyncTransactionOpen_ = true;
317 keyboardSession->property_->SetCallingSessionId(1);
318 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, animationInfo);
319 usleep(WAIT_ASYNC_US);
320 auto callingSessionId = keyboardSession->property_->GetCallingSessionId();
321 ASSERT_EQ(callingSessionId, INVALID_WINDOW_ID);
322 }
323
324 /**
325 * @tc.name: CloseKeyboardSyncTransaction03
326 * @tc.name: CloseKeyboardSyncTransaction03
327 * @tc.desc: test function: CloseKeyboardSyncTransaction
328 * @tc.type: FUNC
329 */
330 HWTEST_F(KeyboardSessionTest4, CloseKeyboardSyncTransaction03, TestSize.Level1)
331 {
332 std::string abilityName = "CloseKeyboardSyncTransaction03";
333 std::string bundleName = "CloseKeyboardSyncTransaction03";
334 sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
335 WSRect keyboardPanelRect = { 0, 0, 0, 0 };
336 WindowAnimationInfo animationInfo;
337 animationInfo.callingId = 3;
338 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCallback =
339 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
340 keyboardSession->keyboardCallback_ = keyboardCallback;
341
342 ASSERT_NE(keyboardSession->GetSessionProperty(), nullptr);
343 keyboardSession->GetSessionProperty()->SetCallingSessionId(1);
344 animationInfo.isGravityChanged = true;
345 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, animationInfo);
346 EXPECT_EQ(keyboardSession->GetSessionProperty()->GetCallingSessionId(), 1);
347
348 animationInfo.isGravityChanged = false;
__anonb4e5377a0502() 349 keyboardSession->keyboardCallback_->isLastFrameLayoutFinished = []() { return true; };
350 keyboardSession->state_ = SessionState::STATE_ACTIVE;
351 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, true, animationInfo);
352 EXPECT_EQ(keyboardSession->GetSessionProperty()->GetCallingSessionId(), 1);
353
354 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, animationInfo);
355 EXPECT_EQ(keyboardSession->GetSessionProperty()->GetCallingSessionId(), INVALID_WINDOW_ID);
356
357 animationInfo.isGravityChanged = true;
358 keyboardSession->state_ = SessionState::STATE_ACTIVE;
359 keyboardSession->GetSessionProperty()->SetCallingSessionId(2);
__anonb4e5377a0602() 360 keyboardSession->keyboardCallback_->isLastFrameLayoutFinished = []() { return false; };
361 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, true, animationInfo);
362 EXPECT_EQ(keyboardSession->GetSessionProperty()->GetCallingSessionId(), 2);
363
364 animationInfo.isGravityChanged = false;
365 keyboardSession->state_ = SessionState::STATE_BACKGROUND;
366 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, true, animationInfo);
367 EXPECT_EQ(keyboardSession->GetSessionProperty()->GetCallingSessionId(), 2);
368
369 keyboardSession->state_ = SessionState::STATE_ACTIVE;
370 keyboardSession->GetSessionProperty()->SetCallingSessionId(INVALID_WINDOW_ID);
371 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, true, animationInfo);
372 EXPECT_EQ(keyboardSession->GetSessionProperty()->GetCallingSessionId(), 3);
373 }
374
375 /**
376 * @tc.name: CloseKeyboardSyncTransaction04
377 * @tc.desc: test function: CloseKeyboardSyncTransaction
378 * @tc.type: FUNC
379 */
380 HWTEST_F(KeyboardSessionTest4, CloseKeyboardSyncTransaction04, TestSize.Level1)
381 {
382 std::string abilityName = "CloseKeyboardSyncTransaction04";
383 std::string bundleName = "CloseKeyboardSyncTransaction04";
384 sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
385 WSRect keyboardPanelRect = { 0, 0, 0, 0 };
386 WindowAnimationInfo animationInfo;
387 animationInfo.callingId = 3;
388 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCallback =
389 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
390 keyboardSession->keyboardCallback_ = keyboardCallback;
391
392 animationInfo.isGravityChanged = false;
__anonb4e5377a0702() 393 keyboardSession->keyboardCallback_->isLastFrameLayoutFinished = []() { return true; };
394 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, true, animationInfo);
395 EXPECT_EQ(false, keyboardSession->stateChanged_);
396
__anonb4e5377a0802() 397 keyboardSession->keyboardCallback_->isLastFrameLayoutFinished = []() { return false; };
398 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, true, animationInfo);
399 EXPECT_EQ(true, keyboardSession->stateChanged_);
400
401 keyboardSession->stateChanged_ = false;
402 animationInfo.isGravityChanged = true;
403 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, true, animationInfo);
404 EXPECT_EQ(false, keyboardSession->stateChanged_);
405 }
406
407 /**
408 * @tc.name: EnableCallingSessionAvoidArea01
409 * @tc.desc: test function: EnableCallingSessionAvoidArea
410 * @tc.type: FUNC
411 */
412 HWTEST_F(KeyboardSessionTest4, EnableCallingSessionAvoidArea01, TestSize.Level1)
413 {
414 g_logMsg.clear();
415 LOG_SetCallback(MyLogCallback);
416 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCallback =
417 sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
__anonb4e5377a0902(uint32_t persistentId) 418 keyboardCallback->onGetSceneSession = [](uint32_t persistentId) {
419 SessionInfo callingSessionInfo;
420 callingSessionInfo.abilityName_ = "CallingSession";
421 callingSessionInfo.bundleName_ = "CallingSession";
422 auto callingSession = sptr<SceneSession>::MakeSptr(callingSessionInfo, nullptr);
423 callingSession->persistentId_ = persistentId;
424 return callingSession;
425 };
426
427 sptr<SceneSession::SpecificSessionCallback> specificCallback =
428 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
429 SessionInfo info;
430 info.abilityName_ = "keyboardSession";
431 info.bundleName_ = "keyboardSession";
432 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCallback, keyboardCallback);
433 keyboardSession->EnableCallingSessionAvoidArea();
434 EXPECT_TRUE(g_logMsg.find("Calling session is null") == std::string::npos);
435
__anonb4e5377a0a02(uint32_t persistentId) 436 keyboardCallback->onGetSceneSession = [](uint32_t persistentId) {
437 return nullptr;
438 };
439 keyboardSession->EnableCallingSessionAvoidArea();
440 EXPECT_TRUE(g_logMsg.find("Calling session is null") != std::string::npos);
441 }
442
443 /**
444 * @tc.name: CalculateScaledRect01
445 * @tc.desc: test function: CalculateScaledRect
446 * @tc.type: FUNC
447 */
448 HWTEST_F(KeyboardSessionTest4, CalculateScaledRect01, TestSize.Level1)
449 {
450 std::string abilityName = "CalculateScaledRect01";
451 std::string bundleName = "CalculateScaledRect01";
452 sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
453
454 WSRect rect = {500, 500, 2000, 2000};
455 WSRect scaledRect = keyboardSession->CalculateScaledRect(rect, 1, 1);
456 EXPECT_TRUE(scaledRect == rect);
457
458 scaledRect = keyboardSession->CalculateScaledRect(rect, 1, 1.5);
459 WSRect result = {500, 0, 2000, 3000};
460 EXPECT_TRUE(scaledRect == result);
461
462 scaledRect = keyboardSession->CalculateScaledRect(rect, 1.5, 1);
463 result = {0, 500, 3000, 2000};
464 EXPECT_TRUE(scaledRect == result);
465
466 rect = {922, 277, 1274, 1387};
467 scaledRect = keyboardSession->CalculateScaledRect(rect, 1.399529, 1.399423);
468 result = {667, 0, 1783, 1941};
469 EXPECT_TRUE(scaledRect == result);
470 }
471 } // namespace
472 } // namespace Rosen
473 } // namespace OHOS