1 /*
2 * Copyright (c) 2024 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 #include <parameters.h>
19
20 #include "mock/mock_keyboard_session.h"
21 #include "common/include/session_permission.h"
22 #include "interfaces/include/ws_common.h"
23 #include "mock/mock_session_stage.h"
24 #include "mock/mock_keyboard_session.h"
25 #include "session/host/include/session.h"
26 #include "screen_session_manager/include/screen_session_manager_client.h"
27 #include "session/host/include/scene_session.h"
28 #include "window_helper.h"
29 #include "window_manager_hilog.h"
30
31 using namespace testing;
32 using namespace testing::ext;
33
34 namespace OHOS {
35 namespace Rosen {
36 namespace {
37 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "KeyboardSessionTest"};
38 }
39
40 class KeyboardSessionTest : public testing::Test {
41 public:
42 static void SetUpTestCase();
43 static void TearDownTestCase();
44 void SetUp() override;
45 void TearDown() override;
46 private:
47 sptr<KeyboardSession> GetKeyboardSession(const std::string& abilityName, const std::string& bundleName);
48 sptr<SceneSession> GetSceneSession(const std::string& abilityName, const std::string& bundleName);
49 sptr<KSSceneSessionMocker> GetSceneSessionMocker(const std::string& abilityName, const std::string& bundleName);
50 };
51
SetUpTestCase()52 void KeyboardSessionTest::SetUpTestCase()
53 {
54 }
55
TearDownTestCase()56 void KeyboardSessionTest::TearDownTestCase()
57 {
58 }
59
SetUp()60 void KeyboardSessionTest::SetUp()
61 {
62 }
63
TearDown()64 void KeyboardSessionTest::TearDown()
65 {
66 }
67
GetKeyboardSession(const std::string & abilityName,const std::string & bundleName)68 sptr<KeyboardSession> KeyboardSessionTest::GetKeyboardSession(const std::string& abilityName,
69 const std::string& bundleName)
70 {
71 SessionInfo info;
72 info.abilityName_ = abilityName;
73 info.bundleName_ = bundleName;
74 sptr<SceneSession::SpecificSessionCallback> specificCb =
75 new (std::nothrow) SceneSession::SpecificSessionCallback();
76 EXPECT_NE(specificCb, nullptr);
77 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
78 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
79 EXPECT_NE(keyboardCb, nullptr);
80 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
81 EXPECT_NE(keyboardSession, nullptr);
82
83 sptr<WindowSessionProperty> keyboardProperty = new (std::nothrow) WindowSessionProperty();
84 EXPECT_NE(keyboardProperty, nullptr);
85 keyboardProperty->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
86 keyboardSession->SetSessionProperty(keyboardProperty);
87
88 return keyboardSession;
89 }
90
GetSceneSession(const std::string & abilityName,const std::string & bundleName)91 sptr<SceneSession> KeyboardSessionTest::GetSceneSession(const std::string& abilityName,
92 const std::string& bundleName)
93 {
94 SessionInfo info;
95 info.abilityName_ = abilityName;
96 info.bundleName_ = bundleName;
97 sptr<SceneSession::SpecificSessionCallback> specificCb =
98 new (std::nothrow) SceneSession::SpecificSessionCallback();
99 EXPECT_NE(specificCb, nullptr);
100 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
101
102 return sceneSession;
103 }
104
GetSceneSessionMocker(const std::string & abilityName,const std::string & bundleName)105 sptr<KSSceneSessionMocker> KeyboardSessionTest::GetSceneSessionMocker(const std::string& abilityName,
106 const std::string& bundleName)
107 {
108 SessionInfo info;
109 info.abilityName_ = abilityName;
110 info.bundleName_ = bundleName;
111 sptr<SceneSession::SpecificSessionCallback> specificCb =
112 new (std::nothrow) SceneSession::SpecificSessionCallback();
113 EXPECT_NE(specificCb, nullptr);
114 sptr<KSSceneSessionMocker> mockSession = sptr<KSSceneSessionMocker>::MakeSptr(info, nullptr);
115
116 return mockSession;
117 }
118
119 namespace {
120 /**
121 * @tc.name: Show
122 * @tc.desc: test function : Show
123 * @tc.type: FUNC
124 */
125 HWTEST_F(KeyboardSessionTest, GetKeyboardGravity, Function | SmallTest | Level1)
126 {
127 SessionInfo info;
128 info.abilityName_ = "GetKeyboardGravity";
129 info.bundleName_ = "GetKeyboardGravity";
130 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, nullptr, nullptr);
131 ASSERT_TRUE((keyboardSession != nullptr));
132 ASSERT_EQ(SessionGravity::SESSION_GRAVITY_DEFAULT, keyboardSession->GetKeyboardGravity());
133
134 sptr<SceneSession::SpecificSessionCallback> specificCb =
135 new (std::nothrow) SceneSession::SpecificSessionCallback();
136 EXPECT_NE(specificCb, nullptr);
137 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCb);
138 sptr<WindowSessionProperty> windowSessionProperty = new (std::nothrow) WindowSessionProperty();
139 EXPECT_NE(windowSessionProperty, nullptr);
140 sceneSession->property_ = windowSessionProperty;
141 keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, nullptr);
142 ASSERT_EQ(SessionGravity::SESSION_GRAVITY_DEFAULT, keyboardSession->GetKeyboardGravity());
143 }
144
145 /**
146 * @tc.name: Show01
147 * @tc.desc: test function : Show
148 * @tc.type: FUNC
149 */
150 HWTEST_F(KeyboardSessionTest, Show01, Function | SmallTest | Level1)
151 {
152 SessionInfo info;
153 info.abilityName_ = "Show01";
154 info.bundleName_ = "Show01";
155 sptr<SceneSession::SpecificSessionCallback> specificCb =
156 new (std::nothrow) SceneSession::SpecificSessionCallback();
157 EXPECT_NE(specificCb, nullptr);
158 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
159 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
160 EXPECT_NE(keyboardCb, nullptr);
161 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
162 ASSERT_TRUE((keyboardSession != nullptr));
163 sptr<WindowSessionProperty> property = new WindowSessionProperty();
164 ASSERT_NE(nullptr, property);
165
166 keyboardSession->isKeyboardPanelEnabled_ = true;
167 ASSERT_EQ(WSError::WS_OK, keyboardSession->Show(property));
168
169 keyboardSession->isKeyboardPanelEnabled_ = false;
170 ASSERT_EQ(WSError::WS_OK, keyboardSession->Show(property));
171 }
172
173 /**
174 * @tc.name: Show02
175 * @tc.desc: test function : Show
176 * @tc.type: FUNC
177 */
178 HWTEST_F(KeyboardSessionTest, Show02, Function | SmallTest | Level1)
179 {
180 SessionInfo info;
181 info.abilityName_ = "Show02";
182 info.bundleName_ = "Show02";
183 sptr<SceneSession::SpecificSessionCallback> specificCb =
184 new (std::nothrow) SceneSession::SpecificSessionCallback();
185 EXPECT_NE(specificCb, nullptr);
186 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
187 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
188 EXPECT_NE(keyboardCb, nullptr);
189 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
190 ASSERT_TRUE((keyboardSession != nullptr));
191 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, keyboardSession->Show(nullptr));
192 }
193
194 /**
195 * @tc.name: Hide
196 * @tc.desc: test function : Hide
197 * @tc.type: FUNC
198 */
199 HWTEST_F(KeyboardSessionTest, Hide, Function | SmallTest | Level1)
200 {
201 SessionInfo info;
202 info.abilityName_ = "Hide";
203 info.bundleName_ = "Hide";
204 sptr<SceneSession::SpecificSessionCallback> specificCb =
205 new (std::nothrow) SceneSession::SpecificSessionCallback();
206 EXPECT_NE(specificCb, nullptr);
207 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
208 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
209 EXPECT_NE(keyboardCb, nullptr);
210 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
211 ASSERT_TRUE((keyboardSession != nullptr));
212
213 ASSERT_EQ(WSError::WS_OK, keyboardSession->Hide());
214 }
215
216 /**
217 * @tc.name: Disconnect
218 * @tc.desc: normal function
219 * @tc.type: FUNC
220 */
221 HWTEST_F(KeyboardSessionTest, Disconnect, Function | SmallTest | Level2)
222 {
223 SessionInfo info;
224 info.abilityName_ = "Disconnect";
225 info.bundleName_ = "Disconnect";
226 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, nullptr, nullptr);
227 EXPECT_NE(keyboardSession, nullptr);
228 sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
229 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
230 keyboardSession->SetSessionProperty(property);
231 keyboardSession->isActive_ = true;
232 auto result = keyboardSession->Disconnect();
233 ASSERT_EQ(result, WSError::WS_OK);
234 }
235
236 /**
237 * @tc.name: NotifyClientToUpdateRect
238 * @tc.desc: NotifyClientToUpdateRect
239 * @tc.type: FUNC
240 */
241 HWTEST_F(KeyboardSessionTest, NotifyClientToUpdateRect, Function | SmallTest | Level2)
242 {
243 SessionInfo info;
244 info.abilityName_ = "NotifyClientToUpdateRect";
245 info.bundleName_ = "NotifyClientToUpdateRect";
246 sptr<SceneSession::SpecificSessionCallback> specificCb =
247 new (std::nothrow) SceneSession::SpecificSessionCallback();
248 EXPECT_NE(specificCb, nullptr);
249 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
250 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
251 EXPECT_NE(keyboardCb, nullptr);
252 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
253 EXPECT_NE(keyboardSession, nullptr);
254 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
255 ASSERT_NE(mockSessionStage, nullptr);
256 keyboardSession->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
257 keyboardSession->sessionStage_ = mockSessionStage;
258 auto ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionTest", nullptr);
259 ASSERT_EQ(ret, WSError::WS_OK);
260 }
261
262 /**
263 * @tc.name: SetKeyboardSessionGravity
264 * @tc.desc: SetKeyboardSessionGravity
265 * @tc.type: FUNC
266 */
267 HWTEST_F(KeyboardSessionTest, SetKeyboardSessionGravity, Function | SmallTest | Level1)
268 {
269 SessionInfo info;
270 info.abilityName_ = "SetKeyboardSessionGravity";
271 info.bundleName_ = "SetKeyboardSessionGravity";
272 sptr<SceneSession::SpecificSessionCallback> specificCb =
273 new (std::nothrow) SceneSession::SpecificSessionCallback();
274 EXPECT_NE(specificCb, nullptr);
275 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
276 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
277 EXPECT_NE(keyboardCb, nullptr);
278 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
279 EXPECT_NE(keyboardSession, nullptr);
280
281 auto ret = keyboardSession->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, 0);
282 ASSERT_EQ(ret, WSError::WS_OK);
283
284 sptr<SceneSession::SessionChangeCallback> sessionChangeCb =
285 new (std::nothrow) SceneSession::SessionChangeCallback();
286 EXPECT_NE(sessionChangeCb, nullptr);
287 keyboardSession->sessionChangeCallback_ = sessionChangeCb;
288 ret = keyboardSession->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, 0);
289 ASSERT_EQ(ret, WSError::WS_OK);
290
__anon7353ffcd0302(SessionGravity) 291 keyboardSession->keyboardGravityChangeFunc_ = [](SessionGravity) {
292 return 0;
293 };
294 ret = keyboardSession->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, 0);
295 ASSERT_EQ(ret, WSError::WS_OK);
296
297 keyboardSession->isKeyboardPanelEnabled_ = true;
298 ret = keyboardSession->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, 0);
299 ASSERT_EQ(ret, WSError::WS_OK);
300
301 keyboardSession->state_ = SessionState::STATE_FOREGROUND;
302 keyboardSession->isKeyboardPanelEnabled_ = false;
303 ret = keyboardSession->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, 0);
304 ASSERT_EQ(ret, WSError::WS_OK);
305
306 keyboardSession->isKeyboardPanelEnabled_ = true;
307 ret = keyboardSession->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, 0);
308 ASSERT_EQ(ret, WSError::WS_OK);
309
310 keyboardSession->state_ = SessionState::STATE_FOREGROUND;
311 ret = keyboardSession->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_FLOAT, 0);
312 ASSERT_EQ(ret, WSError::WS_OK);
313
314 keyboardSession->state_ = SessionState::STATE_DISCONNECT;
315 ret = keyboardSession->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_FLOAT, 0);
316 ASSERT_EQ(ret, WSError::WS_OK);
317 }
318
319 /**
320 * @tc.name: GetSceneSession01
321 * @tc.desc: GetSceneSession
322 * @tc.type: FUNC
323 */
324 HWTEST_F(KeyboardSessionTest, GetSceneSession01, Function | SmallTest | Level1)
325 {
326 SessionInfo info;
327 info.abilityName_ = "GetSceneSession01";
328 info.bundleName_ = "GetSceneSession01";
329 sptr<SceneSession::SpecificSessionCallback> specificCb =
330 new (std::nothrow) SceneSession::SpecificSessionCallback();
331 EXPECT_NE(specificCb, nullptr);
332 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
333 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
334 EXPECT_NE(keyboardCb, nullptr);
335 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
336 EXPECT_NE(keyboardSession, nullptr);
337 info.windowType_ = 1;
338 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCb);
339 EXPECT_NE(sceneSession, nullptr);
340 auto id = sceneSession->GetPersistentId();
341 EXPECT_NE(id, 0);
342 auto ret = keyboardSession->GetSceneSession(id);
343
__anon7353ffcd0402(uint32_t) 344 keyboardCb->onGetSceneSession_ = [](uint32_t) {
345 return nullptr;
346 };
347 EXPECT_NE(keyboardCb->onGetSceneSession_, nullptr);
348 ret = keyboardSession->GetSceneSession(id);
349 }
350
351 /**
352 * @tc.name: NotifyOccupiedAreaChangeInfo
353 * @tc.desc: NotifyOccupiedAreaChangeInfo
354 * @tc.type: FUNC
355 */
356 HWTEST_F(KeyboardSessionTest, NotifyOccupiedAreaChangeInfo, Function | SmallTest | Level1)
357 {
358 SessionInfo info;
359 info.abilityName_ = "NotifyOccupiedAreaChangeInfo";
360 info.bundleName_ = "NotifyOccupiedAreaChangeInfo";
361 sptr<SceneSession::SpecificSessionCallback> specificCb =
362 new (std::nothrow) SceneSession::SpecificSessionCallback();
363 EXPECT_NE(specificCb, nullptr);
364 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
365 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
366 EXPECT_NE(keyboardCb, nullptr);
367 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
368 EXPECT_NE(keyboardSession, nullptr);
369 sptr<SceneSession> callingSession = new (std::nothrow) SceneSession(info, nullptr);
370 WSRect rect = { 0, 0, 0, 0 };
371 WSRect occupiedArea = { 0, 0, 0, 0 };
372 keyboardSession->NotifyOccupiedAreaChangeInfo(callingSession, rect, occupiedArea);
373
374 WSRect lastSR = {1, 1, 1, 1};
375 callingSession->lastSafeRect = lastSR;
376 keyboardSession->NotifyOccupiedAreaChangeInfo(callingSession, rect, occupiedArea);
377
378 sptr<WindowSessionProperty> windowSessionProperty = new (std::nothrow) WindowSessionProperty();
379 EXPECT_NE(windowSessionProperty, nullptr);
380 keyboardSession->property_ = windowSessionProperty;
381 keyboardSession->NotifyOccupiedAreaChangeInfo(callingSession, rect, occupiedArea);
382 }
383
384 /**
385 * @tc.name: RestoreCallingSession
386 * @tc.desc: RestoreCallingSession
387 * @tc.type: FUNC
388 */
389 HWTEST_F(KeyboardSessionTest, RestoreCallingSession, Function | SmallTest | Level1)
390 {
391 SessionInfo info;
392 info.abilityName_ = "RestoreCallingSession";
393 info.bundleName_ = "RestoreCallingSession";
394 sptr<SceneSession::SpecificSessionCallback> specificCb =
395 new (std::nothrow) SceneSession::SpecificSessionCallback();
396 EXPECT_NE(specificCb, nullptr);
397 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
398 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
399 EXPECT_NE(keyboardCb, nullptr);
400 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
401 EXPECT_NE(keyboardSession, nullptr);
402
403 info.windowType_ = 1;
404 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCb);
405 EXPECT_NE(sceneSession, nullptr);
406 auto id = sceneSession->GetPersistentId();
407 EXPECT_NE(id, 0);
408
409 keyboardSession->GetSessionProperty()->SetCallingSessionId(id);
410 keyboardSession->RestoreCallingSession();
411 }
412
413 /**
414 * @tc.name: UseFocusIdIfCallingSessionIdInvalid
415 * @tc.desc: UseFocusIdIfCallingSessionIdInvalid
416 * @tc.type: FUNC
417 */
418 HWTEST_F(KeyboardSessionTest, UseFocusIdIfCallingSessionIdInvalid, Function | SmallTest | Level1)
419 {
420 SessionInfo info;
421 info.abilityName_ = "UseFocusIdIfCallingSessionIdInvalid";
422 info.bundleName_ = "UseFocusIdIfCallingSessionIdInvalid";
423 sptr<SceneSession::SpecificSessionCallback> specificCb =
424 new (std::nothrow) SceneSession::SpecificSessionCallback();
425 EXPECT_NE(specificCb, nullptr);
426 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
427 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
428 EXPECT_NE(keyboardCb, nullptr);
429 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
430 EXPECT_NE(keyboardSession, nullptr);
431
432 info.windowType_ = 1;
433 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCb);
434 EXPECT_NE(sceneSession, nullptr);
435 auto id = sceneSession->GetPersistentId();
436 EXPECT_NE(id, 0);
437
438 keyboardSession->GetSessionProperty()->SetCallingSessionId(id);
439 keyboardSession->UseFocusIdIfCallingSessionIdInvalid();
440 }
441
442 /**
443 * @tc.name: UpdateCallingSessionIdAndPosition
444 * @tc.desc: UpdateCallingSessionIdAndPosition
445 * @tc.type: FUNC
446 */
447 HWTEST_F(KeyboardSessionTest, UpdateCallingSessionIdAndPosition, Function | SmallTest | Level1)
448 {
449 SessionInfo info;
450 info.abilityName_ = "UpdateCallingSessionIdAndPosition";
451 info.bundleName_ = "UpdateCallingSessionIdAndPosition";
452 sptr<SceneSession::SpecificSessionCallback> specificCb =
453 new (std::nothrow) SceneSession::SpecificSessionCallback();
454 EXPECT_NE(specificCb, nullptr);
455 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
456 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
457 EXPECT_NE(keyboardCb, nullptr);
458 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
459 EXPECT_NE(keyboardSession, nullptr);
460
461 info.windowType_ = 1;
462 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCb);
463 EXPECT_NE(sceneSession, nullptr);
464 auto id = sceneSession->GetPersistentId();
465 EXPECT_NE(id, 0);
466
467 keyboardSession->UpdateCallingSessionIdAndPosition(id);
468 }
469
470 /**
471 * @tc.name: RelayoutKeyBoard
472 * @tc.desc: RelayoutKeyBoard
473 * @tc.type: FUNC
474 */
475 HWTEST_F(KeyboardSessionTest, RelayoutKeyBoard, Function | SmallTest | Level1)
476 {
477 SessionInfo info;
478 info.abilityName_ = "RelayoutKeyBoard";
479 info.bundleName_ = "RelayoutKeyBoard";
480 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, nullptr, nullptr);
481 EXPECT_NE(keyboardSession, nullptr);
482
483 keyboardSession->RelayoutKeyBoard();
484 }
485
486 /**
487 * @tc.name: GetFocusedSessionId
488 * @tc.desc: GetFocusedSessionId
489 * @tc.type: FUNC
490 */
491 HWTEST_F(KeyboardSessionTest, GetFocusedSessionId, Function | SmallTest | Level1)
492 {
493 SessionInfo info;
494 info.abilityName_ = "RelayoutKeyBoard";
495 info.bundleName_ = "RelayoutKeyBoard";
496 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
497 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
498 EXPECT_NE(keyboardCb, nullptr);
499 keyboardCb->onGetFocusedSessionId_ = []()
__anon7353ffcd0502() 500 {
501 return 0;
502 };
503 EXPECT_NE(keyboardCb->onGetFocusedSessionId_, nullptr);
504 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, nullptr, keyboardCb);
505 EXPECT_NE(keyboardSession, nullptr);
506 ASSERT_EQ(INVALID_WINDOW_ID, keyboardSession->GetFocusedSessionId());
507
508 keyboardSession = new (std::nothrow) KeyboardSession(info, nullptr, nullptr);
509 EXPECT_NE(keyboardSession, nullptr);
510
511 ASSERT_EQ(INVALID_WINDOW_ID, keyboardSession->GetFocusedSessionId());
512 }
513
514 /**
515 * @tc.name: GetStatusBarHeight
516 * @tc.desc: GetStatusBarHeight
517 * @tc.type: FUNC
518 */
519 HWTEST_F(KeyboardSessionTest, GetStatusBarHeight, Function | SmallTest | Level1)
520 {
521 SessionInfo info;
522 info.abilityName_ = "RelayoutKeyBoard";
523 info.bundleName_ = "RelayoutKeyBoard";
524 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, nullptr, nullptr);
525 EXPECT_NE(keyboardSession, nullptr);
526
527 int32_t statusBarHeight = keyboardSession->GetStatusBarHeight();
528 ASSERT_EQ(statusBarHeight, 0);
529
530 sptr<SceneSession::SpecificSessionCallback> specificCb =
531 new (std::nothrow) SceneSession::SpecificSessionCallback();
532 EXPECT_NE(specificCb, nullptr);
533 keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, nullptr);
534 EXPECT_NE(keyboardSession, nullptr);
535 statusBarHeight = keyboardSession->GetStatusBarHeight();
536 ASSERT_EQ(statusBarHeight, 0);
537
538 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCb);
539 EXPECT_NE(sceneSession, nullptr);
540 WSRect rect({0, 0, 0, 0});
541 sceneSession->winRect_ = rect;
542 sceneSession->specificCallback_->onGetSceneSessionVectorByType_ =
543 [&](WindowType, uint64_t)->std::vector<sptr<SceneSession>>
__anon7353ffcd0602(WindowType, uint64_t)544 {
545 std::vector<sptr<SceneSession>> vec;
546 vec.push_back(nullptr);
547 return vec;
548 };
549 EXPECT_NE(specificCb->onGetSceneSessionVectorByType_, nullptr);
550 statusBarHeight = keyboardSession->GetStatusBarHeight();
551 ASSERT_EQ(statusBarHeight, 0);
552
553 sptr<WindowSessionProperty> windowSessionProperty = new (std::nothrow) WindowSessionProperty();
554 EXPECT_NE(windowSessionProperty, nullptr);
555 sceneSession->property_ = windowSessionProperty;
556 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb=
557 new (std::nothrow) KeyboardSession::KeyboardSessionCallback;
558 EXPECT_NE(keyboardCb, nullptr);
559 keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
560 EXPECT_NE(keyboardSession, nullptr);
561 sceneSession->specificCallback_->onGetSceneSessionVectorByType_ =
562 [&](WindowType, uint64_t)->std::vector<sptr<SceneSession>>
__anon7353ffcd0702(WindowType, uint64_t)563 {
564 std::vector<sptr<SceneSession>> vec;
565 vec.push_back(sceneSession);
566 return vec;
567 };
568 statusBarHeight = keyboardSession->GetStatusBarHeight();
569 ASSERT_EQ(statusBarHeight, 0);
570 }
571
572 /**
573 * @tc.name: GetStatusBarHeight
574 * @tc.desc: GetStatusBarHeight
575 * @tc.type: FUNC
576 */
577 HWTEST_F(KeyboardSessionTest, GetStatusBarHeight02, Function | SmallTest | Level1)
578 {
579 SessionInfo info;
580 info.abilityName_ = "RelayoutKeyBoard";
581 info.bundleName_ = "RelayoutKeyBoard";
582 sptr<SceneSession::SpecificSessionCallback> specificCb =
583 new (std::nothrow) SceneSession::SpecificSessionCallback();
584 EXPECT_NE(specificCb, nullptr);
585 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCb);
586 EXPECT_NE(sceneSession, nullptr);
587 sptr<WindowSessionProperty> windowSessionProperty = new (std::nothrow) WindowSessionProperty();
588 EXPECT_NE(windowSessionProperty, nullptr);
589 sceneSession->property_ = windowSessionProperty;
590 WSRect rect3({0, 0, 0, 1});
591 sceneSession->winRect_ = rect3;
592 sceneSession->specificCallback_->onGetSceneSessionVectorByType_ =
593 [&](WindowType, uint64_t)->std::vector<sptr<SceneSession>>
__anon7353ffcd0802(WindowType, uint64_t)594 {
595 std::vector<sptr<SceneSession>> vec;
596 vec.push_back(sceneSession);
597 return vec;
598 };
599 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
600 new (std::nothrow) KeyboardSession::KeyboardSessionCallback;
601 EXPECT_NE(keyboardCb, nullptr);
602 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
603 EXPECT_NE(keyboardSession, nullptr);
604 int32_t statusBarHeight = keyboardSession->GetStatusBarHeight();
605 ASSERT_EQ(statusBarHeight, 1);
606 }
607
608 /**
609 * @tc.name: OnKeyboardPanelUpdated
610 * @tc.desc: OnKeyboardPanelUpdated
611 * @tc.type: FUNC
612 */
613 HWTEST_F(KeyboardSessionTest, OnKeyboardPanelUpdated, Function | SmallTest | Level1)
614 {
615 WLOGFI("OnKeyboardPanelUpdated begin!");
616 int ret = 0;
617
618 SessionInfo info;
619 info.abilityName_ = "OnKeyboardPanelUpdated";
620 info.bundleName_ = "OnKeyboardPanelUpdated";
621 sptr<SceneSession::SpecificSessionCallback> specificCb =
622 new (std::nothrow) SceneSession::SpecificSessionCallback();
623 EXPECT_NE(specificCb, nullptr);
624 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
625 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
626 EXPECT_NE(keyboardCb, nullptr);
627 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
628 EXPECT_NE(keyboardSession, nullptr);
629 keyboardSession->isKeyboardPanelEnabled_ = false;
630 keyboardSession->OnKeyboardPanelUpdated();
631
632 keyboardSession->isKeyboardPanelEnabled_ = true;
633 keyboardSession->specificCallback_ = nullptr;
634 keyboardSession->OnKeyboardPanelUpdated();
635
636 keyboardSession->specificCallback_ = specificCb;
637 auto onUpdateAvoidArea = specificCb->onUpdateAvoidArea_;
638 if (onUpdateAvoidArea == nullptr) {
__anon7353ffcd0902(const int32_t& id)639 onUpdateAvoidArea = [](const int32_t& id){};
640 }
641 specificCb->onUpdateAvoidArea_ = nullptr;
642 keyboardSession->OnKeyboardPanelUpdated();
643
644 specificCb->onUpdateAvoidArea_ = onUpdateAvoidArea;
645 keyboardSession->OnKeyboardPanelUpdated();
646
647 ASSERT_EQ(ret, 0);
648 WLOGFI("OnKeyboardPanelUpdated end!");
649 }
650
651 /**
652 * @tc.name: SetCallingSessionId
653 * @tc.desc: SetCallingSessionId
654 * @tc.type: FUNC
655 */
656 HWTEST_F(KeyboardSessionTest, SetCallingSessionId, Function | SmallTest | Level1)
657 {
658 WLOGFI("SetCallingSessionId begin!");
659 SessionInfo info;
660 info.abilityName_ = "SetCallingSessionId";
661 info.bundleName_ = "SetCallingSessionId";
662 sptr<SceneSession::SpecificSessionCallback> specificCb =
663 new (std::nothrow) SceneSession::SpecificSessionCallback();
664 EXPECT_NE(specificCb, nullptr);
665 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
666 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
667 EXPECT_NE(keyboardCb, nullptr);
668 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
669 EXPECT_NE(keyboardSession, nullptr);
670
671 keyboardSession->keyboardCallback_ = nullptr;
672 keyboardSession->SetCallingSessionId(0);
673
674 keyboardSession->keyboardCallback_ = keyboardCb;
675 auto onCallingSessionIdChange = keyboardSession->keyboardCallback_->onCallingSessionIdChange_;
676 if (onCallingSessionIdChange == nullptr) {
__anon7353ffcd0a02(uint32_t Id)677 onCallingSessionIdChange = [](uint32_t Id){};
678 }
679 keyboardSession->keyboardCallback_->onCallingSessionIdChange_ = nullptr;
680 keyboardSession->SetCallingSessionId(0);
681
682 keyboardSession->keyboardCallback_->onCallingSessionIdChange_ = onCallingSessionIdChange;
683 keyboardSession->SetCallingSessionId(0);
684
685 WLOGFI("SetCallingSessionId end!");
686 }
687
688 /**
689 * @tc.name: GetCallingSessionId
690 * @tc.desc: GetCallingSessionId
691 * @tc.type: FUNC
692 */
693 HWTEST_F(KeyboardSessionTest, GetCallingSessionId, Function | SmallTest | Level1)
694 {
695 SessionInfo info;
696 info.abilityName_ = "GetCallingSessionId";
697 info.bundleName_ = "GetCallingSessionId";
698 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, nullptr, nullptr);
699 EXPECT_NE(keyboardSession, nullptr);
700 auto ret = keyboardSession->GetCallingSessionId();
701 ASSERT_EQ(ret, INVALID_WINDOW_ID);
702 }
703
704 /**
705 * @tc.name: AdjustKeyboardLayout01
706 * @tc.desc: AdjustKeyboardLayout
707 * @tc.type: FUNC
708 */
709 HWTEST_F(KeyboardSessionTest, AdjustKeyboardLayout01, Function | SmallTest | Level1)
710 {
711 SessionInfo info;
712 info.abilityName_ = "AdjustKeyboardLayout01";
713 info.bundleName_ = "AdjustKeyboardLayout01";
714 sptr<SceneSession::SpecificSessionCallback> specificCb =
715 new (std::nothrow) SceneSession::SpecificSessionCallback();
716 EXPECT_NE(specificCb, nullptr);
717 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
718 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
719 EXPECT_NE(keyboardCb, nullptr);
720 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
721 EXPECT_NE(keyboardSession, nullptr);
722 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
723 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
724 keyboardSession->SetSessionProperty(property);
725 keyboardSession->RegisterSessionChangeCallback(nullptr);
726
727 KeyboardLayoutParams params;
728 ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
729
730 sptr<SceneSession::SessionChangeCallback> sessionChangeCallback =
731 new (std::nothrow) SceneSession::SessionChangeCallback();
732 EXPECT_NE(sessionChangeCallback, nullptr);
733 keyboardSession->adjustKeyboardLayoutFunc_ = nullptr;
734 keyboardSession->RegisterSessionChangeCallback(sessionChangeCallback);
735 ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
736
__anon7353ffcd0b02(const KeyboardLayoutParams& params)737 keyboardSession->adjustKeyboardLayoutFunc_ = [](const KeyboardLayoutParams& params){};
738 ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
739 }
740
741 /**
742 * @tc.name: AdjustKeyboardLayout01
743 * @tc.desc: AdjustKeyboardLayout
744 * @tc.type: FUNC
745 */
746 HWTEST_F(KeyboardSessionTest, AdjustKeyboardLayout02, Function | SmallTest | Level1)
747 {
748 SessionInfo info;
749 info.abilityName_ = "AdjustKeyboardLayout02";
750 info.bundleName_ = "AdjustKeyboardLayout02";
751 sptr<SceneSession::SpecificSessionCallback> specificCb =
752 new (std::nothrow) SceneSession::SpecificSessionCallback();
753 EXPECT_NE(specificCb, nullptr);
754 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
755 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
756 EXPECT_NE(keyboardCb, nullptr);
757 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
758 EXPECT_NE(keyboardSession, nullptr);
759 keyboardSession->SetSessionProperty(nullptr);
760
761 KeyboardLayoutParams params;
762 ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
763 }
764
765 /**
766 * @tc.name: CheckIfNeedRaiseCallingSession
767 * @tc.desc: CheckIfNeedRaiseCallingSession
768 * @tc.type: FUNC
769 */
770 HWTEST_F(KeyboardSessionTest, CheckIfNeedRaiseCallingSession, Function | SmallTest | Level1)
771 {
772 WLOGFI("CheckIfNeedRaiseCallingSession begin!");
773 SessionInfo info;
774 info.abilityName_ = "CheckIfNeedRaiseCallingSession";
775 info.bundleName_ = "CheckIfNeedRaiseCallingSession";
776 sptr<SceneSession::SpecificSessionCallback> specificCb =
777 new (std::nothrow) SceneSession::SpecificSessionCallback();
778 EXPECT_NE(specificCb, nullptr);
779 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
780 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
781 EXPECT_NE(keyboardCb, nullptr);
782 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
783 EXPECT_NE(keyboardSession, nullptr);
784 sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
785 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
786 keyboardSession->SetSessionProperty(property);
787
788 ASSERT_FALSE(keyboardSession->CheckIfNeedRaiseCallingSession(nullptr, true));
789
790 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCb);
791 EXPECT_NE(sceneSession, nullptr);
792 property->sessionGravity_ = SessionGravity::SESSION_GRAVITY_FLOAT;
793 ASSERT_FALSE(keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, true));
794
795 property->sessionGravity_ = SessionGravity::SESSION_GRAVITY_BOTTOM;
796 ASSERT_TRUE(keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, false));
797
798 property->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
799
800 keyboardSession->systemConfig_.uiType_ = "phone";
801 ASSERT_FALSE(keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, true));
802
803 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
804 keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, true);
805
806 WLOGFI("CheckIfNeedRaiseCallingSession end!");
807 }
808
809 /**
810 * @tc.name: OpenKeyboardSyncTransaction
811 * @tc.desc: OpenKeyboardSyncTransaction
812 * @tc.type: FUNC
813 */
814 HWTEST_F(KeyboardSessionTest, OpenKeyboardSyncTransaction, Function | SmallTest | Level1)
815 {
816 SessionInfo info;
817 info.abilityName_ = "OpenKeyboardSyncTransaction";
818 info.bundleName_ = "OpenKeyboardSyncTransaction";
819 sptr<SceneSession::SpecificSessionCallback> specificCb =
820 new (std::nothrow) SceneSession::SpecificSessionCallback();
821 EXPECT_NE(specificCb, nullptr);
822 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
823 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
824 EXPECT_NE(keyboardCb, nullptr);
825 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
826 EXPECT_NE(keyboardSession, nullptr);
827
828 // isKeyBoardSyncTransactionOpen_ is false
829 keyboardSession->OpenKeyboardSyncTransaction();
830
831 // isKeyBoardSyncTransactionOpen_ is true
832 keyboardSession->OpenKeyboardSyncTransaction();
833 }
834
835 /**
836 * @tc.name: CloseKeyboardSyncTransaction1
837 * @tc.desc: CloseKeyboardSyncTransaction1
838 * @tc.type: FUNC
839 */
840 HWTEST_F(KeyboardSessionTest, CloseKeyboardSyncTransaction1, Function | SmallTest | Level1)
841 {
842 SessionInfo info;
843 info.abilityName_ = "CloseKeyboardSyncTransaction1";
844 info.bundleName_ = "CloseKeyboardSyncTransaction1";
845 sptr<SceneSession::SpecificSessionCallback> specificCb =
846 new (std::nothrow) SceneSession::SpecificSessionCallback();
847 EXPECT_NE(specificCb, nullptr);
848 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
849 new (std::nothrow) KeyboardSession::KeyboardSessionCallback();
850 EXPECT_NE(keyboardCb, nullptr);
851 sptr<KeyboardSession> keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb);
852 EXPECT_NE(keyboardSession, nullptr);
853
854 sptr<WindowSessionProperty> keyboardProperty = new (std::nothrow) WindowSessionProperty();
855 keyboardProperty->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
856 keyboardSession->SetSessionProperty(keyboardProperty);
857
858 WSRect keyboardPanelRect = { 0, 0, 0, 0 };
859 bool isKeyboardShow = true;
860 bool isRotating = false;
861
862 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, isRotating);
863 }
864
865 /**
866 * @tc.name: BindKeyboardPanelSession
867 * @tc.desc: BindKeyboardPanelSession
868 * @tc.type: FUNC
869 */
870 HWTEST_F(KeyboardSessionTest, BindKeyboardPanelSession, Function | SmallTest | Level1)
871 {
872 SessionInfo info;
873 info.abilityName_ = "BindKeyboardPanelSession";
874 info.bundleName_ = "BindKeyboardPanelSession";
875 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
876 ASSERT_NE(keyboardSession, nullptr);
877 sptr<SceneSession> panelSession = nullptr;
878 keyboardSession->BindKeyboardPanelSession(panelSession);
879 panelSession = sptr<SceneSession>::MakeSptr(info, nullptr);
880 ASSERT_NE(panelSession, nullptr);
881 keyboardSession->BindKeyboardPanelSession(panelSession);
882 EXPECT_EQ(keyboardSession->keyboardPanelSession_, panelSession);
883 }
884
885 /**
886 * @tc.name: GetKeyboardGravity01
887 * @tc.desc: GetKeyboardGravity01
888 * @tc.type: FUNC
889 */
890 HWTEST_F(KeyboardSessionTest, GetKeyboardGravity01, Function | SmallTest | Level1)
891 {
892 SessionInfo info;
893 info.abilityName_ = "GetKeyboardGravity";
894 info.bundleName_ = "GetKeyboardGravity";
895 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
896 ASSERT_NE(keyboardSession, nullptr);
897 keyboardSession->property_ = nullptr;
898 auto ret = keyboardSession->GetKeyboardGravity();
899 EXPECT_EQ(SessionGravity::SESSION_GRAVITY_DEFAULT, ret);
900 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
901 ASSERT_NE(windowSessionProperty, nullptr);
902 keyboardSession->property_ = windowSessionProperty;
903 ASSERT_NE(keyboardSession->property_, nullptr);
904 keyboardSession->property_->sessionGravity_ = SessionGravity::SESSION_GRAVITY_BOTTOM;
905 ASSERT_NE(keyboardSession, nullptr);
906 ret = keyboardSession->GetKeyboardGravity();
907 EXPECT_EQ(SessionGravity::SESSION_GRAVITY_BOTTOM, ret);
908 }
909
910 /**
911 * @tc.name: GetCallingSessionId01
912 * @tc.desc: GetCallingSessionId01
913 * @tc.type: FUNC
914 */
915 HWTEST_F(KeyboardSessionTest, GetCallingSessionId01, Function | SmallTest | Level1)
916 {
917 SessionInfo info;
918 info.abilityName_ = "GetCallingSessionId";
919 info.bundleName_ = "GetCallingSessionId";
920 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
921 ASSERT_NE(keyboardSession, nullptr);
922 keyboardSession->property_ = nullptr;
923 auto ret = keyboardSession->GetCallingSessionId();
924 EXPECT_EQ(ret, INVALID_SESSION_ID);
925 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
926 ASSERT_NE(windowSessionProperty, nullptr);
927 keyboardSession->property_ = windowSessionProperty;
928 ASSERT_NE(keyboardSession->property_, nullptr);
929 keyboardSession->property_->SetCallingSessionId(1);
930 ret = keyboardSession->GetCallingSessionId();
931 EXPECT_EQ(ret, 1);
932 }
933
934 /**
935 * @tc.name: NotifyKeyboardPanelInfoChange
936 * @tc.desc: NotifyKeyboardPanelInfoChange
937 * @tc.type: FUNC
938 */
939 HWTEST_F(KeyboardSessionTest, NotifyKeyboardPanelInfoChange, Function | SmallTest | Level1)
940 {
941 WSRect rect = {800, 800, 1200, 1200};
942 SessionInfo info;
943 info.abilityName_ = "NotifyKeyboardPanelInfoChange";
944 info.bundleName_ = "NotifyKeyboardPanelInfoChange";
945 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
946 ASSERT_NE(keyboardSession, nullptr);
947 keyboardSession->isKeyboardPanelEnabled_ = false;
948 keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
949 keyboardSession->isKeyboardPanelEnabled_ = true;
950 keyboardSession->sessionStage_ = nullptr;
951 keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
952 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
953 ASSERT_NE(mockSessionStage, nullptr);
954 keyboardSession->sessionStage_ = mockSessionStage;
955 ASSERT_NE(keyboardSession->sessionStage_, nullptr);
956 keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
957 }
958
959 /**
960 * @tc.name: CheckIfNeedRaiseCallingSession01
961 * @tc.desc: CheckIfNeedRaiseCallingSession01
962 * @tc.type: FUNC
963 */
964 HWTEST_F(KeyboardSessionTest, CheckIfNeedRaiseCallingSession01, Function | SmallTest | Level1)
965 {
966 SessionInfo info;
967 info.abilityName_ = "CheckIfNeedRaiseCallingSession";
968 info.bundleName_ = "CheckIfNeedRaiseCallingSession";
969 sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
970 ASSERT_NE(specificCb, nullptr);
971 sptr<SceneSession> callingSession = sptr<SceneSession>::MakeSptr(info, specificCb);
972 ASSERT_NE(callingSession, nullptr);
973 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
974 ASSERT_NE(keyboardSession, nullptr);
975 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
976 ASSERT_NE(windowSessionProperty, nullptr);
977 keyboardSession->property_ = windowSessionProperty;
978 ASSERT_NE(keyboardSession->property_, nullptr);
979 keyboardSession->property_->sessionGravity_ = SessionGravity::SESSION_GRAVITY_BOTTOM;
980 keyboardSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
981 keyboardSession->systemConfig_.uiType_ = "phone";
982 callingSession->systemConfig_.freeMultiWindowSupport_ = true;
983 callingSession->systemConfig_.freeMultiWindowEnable_ = true;
984 auto ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
985 EXPECT_EQ(ret, false);
986 callingSession->systemConfig_.freeMultiWindowEnable_ = false;
987 ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
988 EXPECT_EQ(ret, false);
989 callingSession->systemConfig_.freeMultiWindowEnable_ = true;
990 keyboardSession->systemConfig_.uiType_ = "pad";
991 ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
992 EXPECT_EQ(ret, true);
993 keyboardSession->systemConfig_.uiType_ = "pc";
994 callingSession->systemConfig_.freeMultiWindowEnable_ = false;
995 ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
996 EXPECT_EQ(ret, true);
997 keyboardSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
998 ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
999 EXPECT_EQ(ret, true);
1000 ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, false);
1001 EXPECT_EQ(ret, true);
1002 }
1003
1004 /**
1005 * @tc.name: UpdateCallingSessionIdAndPosition01
1006 * @tc.desc: UpdateCallingSessionIdAndPosition01
1007 * @tc.type: FUNC
1008 */
1009 HWTEST_F(KeyboardSessionTest, UpdateCallingSessionIdAndPosition01, Function | SmallTest | Level1)
1010 {
1011 SessionInfo info;
1012 info.abilityName_ = "UpdateCallingSessionIdAndPosition";
1013 info.bundleName_ = "UpdateCallingSessionIdAndPosition";
1014 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
1015 ASSERT_NE(keyboardSession, nullptr);
1016 keyboardSession->property_ = nullptr;
1017 keyboardSession->UpdateCallingSessionIdAndPosition(0);
1018 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
1019 ASSERT_NE(windowSessionProperty, nullptr);
1020 keyboardSession->property_ = windowSessionProperty;
1021 ASSERT_NE(keyboardSession->property_, nullptr);
1022 keyboardSession->property_->SetCallingSessionId(-1);
1023 keyboardSession->UpdateCallingSessionIdAndPosition(0);
1024 keyboardSession->UpdateCallingSessionIdAndPosition(-1);
1025 keyboardSession->property_->SetCallingSessionId(0);
1026 keyboardSession->UpdateCallingSessionIdAndPosition(0);
1027 }
1028
1029 /**
1030 * @tc.name: OpenKeyboardSyncTransaction01
1031 * @tc.desc: OpenKeyboardSyncTransaction
1032 * @tc.type: FUNC
1033 */
1034 HWTEST_F(KeyboardSessionTest, OpenKeyboardSyncTransaction01, Function | SmallTest | Level1)
1035 {
1036 SessionInfo info;
1037 info.abilityName_ = "UpdateCallingSessionIdAndPosition";
1038 info.bundleName_ = "UpdateCallingSessionIdAndPosition";
1039 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
1040 ASSERT_NE(keyboardSession, nullptr);
1041 keyboardSession->isKeyboardSyncTransactionOpen_ = true;
1042 keyboardSession->OpenKeyboardSyncTransaction();
1043 keyboardSession->isKeyboardSyncTransactionOpen_ = false;
1044 keyboardSession->OpenKeyboardSyncTransaction();
1045 WSRect keyboardPanelRect = {0, 0, 0, 0};
1046 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, true, true);
1047 keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, false);
1048 }
1049
1050 /**
1051 * @tc.name: RelayoutKeyBoard01
1052 * @tc.desc: RelayoutKeyBoard01
1053 * @tc.type: FUNC
1054 */
1055 HWTEST_F(KeyboardSessionTest, RelayoutKeyBoard01, Function | SmallTest | Level1)
1056 {
1057 SessionInfo info;
1058 info.abilityName_ = "RelayoutKeyBoard";
1059 info.bundleName_ = "RelayoutKeyBoard";
1060 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
1061 ASSERT_NE(keyboardSession, nullptr);
1062 keyboardSession->property_ = nullptr;
1063 keyboardSession->RelayoutKeyBoard();
1064 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
1065 ASSERT_NE(windowSessionProperty, nullptr);
1066 keyboardSession->property_ = windowSessionProperty;
1067 ASSERT_NE(keyboardSession->property_, nullptr);
1068 keyboardSession->property_->sessionGravity_ = SessionGravity::SESSION_GRAVITY_BOTTOM;
1069 keyboardSession->property_->sessionGravitySizePercent_ = 0;
1070 keyboardSession->RelayoutKeyBoard();
1071 keyboardSession->property_->sessionGravitySizePercent_ = 100;
1072 keyboardSession->RelayoutKeyBoard();
1073 }
1074
1075 /**
1076 * @tc.name: Hide01
1077 * @tc.desc: test function : Hide
1078 * @tc.type: FUNC
1079 */
1080 HWTEST_F(KeyboardSessionTest, Hide01, Function | SmallTest | Level1)
1081 {
1082 SessionInfo info;
1083 info.abilityName_ = "Hide";
1084 info.bundleName_ = "Hide";
1085 sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1086 ASSERT_NE(specificCb, nullptr);
1087 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
1088 sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
1089 ASSERT_NE(keyboardCb, nullptr);
1090 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
1091 ASSERT_NE(keyboardSession, nullptr);
1092 keyboardSession->state_ = SessionState::STATE_DISCONNECT;
1093 EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
1094 keyboardSession->state_ = SessionState::STATE_CONNECT;
1095 keyboardSession->isActive_ = true;
1096 keyboardSession->systemConfig_.uiType_ = "phone";
1097 EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
1098 keyboardSession->systemConfig_.uiType_ = "pc";
1099 keyboardSession->property_ = nullptr;
1100 EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
1101 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
1102 ASSERT_NE(windowSessionProperty, nullptr);
1103 keyboardSession->property_ = windowSessionProperty;
1104 ASSERT_NE(keyboardSession->property_, nullptr);
1105 EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
1106 }
1107
1108 /**
1109 * @tc.name: RaiseCallingSession01
1110 * @tc.desc: test function : RaiseCallingSession
1111 * @tc.type: FUNC
1112 */
1113 HWTEST_F(KeyboardSessionTest, RaiseCallingSession01, Function | SmallTest | Level1)
1114 {
1115 auto keyboardSession = GetKeyboardSession("RaiseCallingSession01",
1116 "RaiseCallingSession01");
1117 ASSERT_NE(keyboardSession, nullptr);
1118
1119 Rosen::WSRect resultRect{ 0, 0, 0, 0 };
1120 sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
1121 ASSERT_NE(callingSession, nullptr);
1122
__anon7353ffcd0c02(const WSRect& rect, const SizeChangeReason reason) 1123 callingSession->updateRectCallback_ = [&resultRect](const WSRect& rect, const SizeChangeReason reason) {
1124 resultRect.posX_ = rect.posX_;
1125 resultRect.posY_ = rect.posY_;
1126 resultRect.width_ = rect.width_;
1127 resultRect.height_ = rect.height_;
1128 };
1129 callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1130 callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1131
1132 Rosen::WSRect keyboardPanelRect{ 0, 0, 0, 0 };
1133 Rosen::WSRect emptyRect{ 0, 0, 0, 0 };
1134 std::shared_ptr<RSTransaction> rsTransaction = nullptr;
1135 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, rsTransaction);
1136 ASSERT_EQ(resultRect, emptyRect);
1137
1138 // for cover GetSceneSession
__anon7353ffcd0d02(int32_t persistentId) 1139 keyboardSession->keyboardCallback_->onGetSceneSession_ = [callingSession](int32_t persistentId) {
1140 return callingSession;
1141 };
1142 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, rsTransaction);
1143 // for cover CheckIfNeedRaiseCallingSession
1144 keyboardSession->property_->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, 0);
1145
1146 // for empty rect check;
1147 keyboardSession->winRect_.posX_ = 1;
1148 keyboardSession->winRect_.posY_ = 1;
1149 keyboardSession->winRect_.posX_ = 1;
1150 keyboardSession->winRect_.posX_ = 1;
1151
1152 // for cover oriPosYBeforeRaisedBykeyboard == 0
1153 callingSession->SetOriPosYBeforeRaisedByKeyboard(0);
1154 ASSERT_EQ(resultRect, emptyRect);
1155 }
1156
1157 /**
1158 * @tc.name: RaiseCallingSession02
1159 * @tc.desc: test function : RaiseCallingSession
1160 * @tc.type: FUNC
1161 */
1162 HWTEST_F(KeyboardSessionTest, RaiseCallingSession02, Function | SmallTest | Level1)
1163 {
1164 Rosen::WSRect keyboardPanelRect{ 1, 1, 1, 1 };
1165 auto keyboardSession = GetKeyboardSession("RaiseCallingSession02",
1166 "RaiseCallingSession02");
1167 ASSERT_NE(keyboardSession, nullptr);
1168 sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
1169 ASSERT_NE(callingSession, nullptr);
1170 callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1171 callingSession->winRect_ = { 1, 1, 1, 1 };
__anon7353ffcd0e02(int32_t persistentId) 1172 keyboardSession->keyboardCallback_->onGetSceneSession_ = [callingSession](int32_t persistentId) {
1173 return callingSession;
1174 };
1175 callingSession->oriPosYBeforeRaisedByKeyboard_ = 0;
1176 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
1177 ASSERT_EQ(callingSession->winRect_.posY_, 1);
1178
1179 callingSession->oriPosYBeforeRaisedByKeyboard_ = 10;
1180 callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1181 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
1182 ASSERT_EQ(callingSession->winRect_.posY_, 1);
1183
1184 keyboardPanelRect = { 0, 0, 0, 0 };
1185 callingSession->oriPosYBeforeRaisedByKeyboard_ = 10;
1186 callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1187 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
1188 ASSERT_EQ(callingSession->winRect_.posY_, 1);
1189 }
1190
1191 /**
1192 * @tc.name: RaiseCallingSession03
1193 * @tc.desc: test function : RaiseCallingSession
1194 * @tc.type: FUNC
1195 */
1196 HWTEST_F(KeyboardSessionTest, RaiseCallingSession03, Function | SmallTest | Level1)
1197 {
1198 Rosen::WSRect keyboardPanelRect{ 1, 1, 1, 1 };
1199 auto keyboardSession = GetKeyboardSession("RaiseCallingSession03",
1200 "RaiseCallingSession03");
1201 ASSERT_NE(keyboardSession, nullptr);
1202 sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
1203 ASSERT_NE(callingSession, nullptr);
1204 callingSession->winRect_ = { 1, 1, 1, 1 };
1205 callingSession->oriPosYBeforeRaisedByKeyboard_ = 0;
__anon7353ffcd0f02(const WSRect& rect, const SizeChangeReason reason) 1206 callingSession->updateRectCallback_ = [](const WSRect& rect, const SizeChangeReason reason) {};
__anon7353ffcd1002(int32_t persistentId) 1207 keyboardSession->keyboardCallback_->onGetSceneSession_ = [callingSession](int32_t persistentId) {
1208 return callingSession;
1209 };
1210
1211 keyboardSession->isVisible_ = true;
1212 auto callingOriPosY = 0;
1213 callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1214 callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1215 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
1216 callingOriPosY = callingSession->oriPosYBeforeRaisedByKeyboard_;
1217 ASSERT_EQ(callingOriPosY, 0);
1218
1219 callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1220 callingSession->winRect_.posY_ = 200;
1221 keyboardPanelRect.posY_ = 200;
1222 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
1223 callingOriPosY = callingSession->oriPosYBeforeRaisedByKeyboard_;
1224 ASSERT_EQ(callingOriPosY, 0);
1225
1226 callingSession->oriPosYBeforeRaisedByKeyboard_ = 10;
1227 callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1228 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
1229 callingOriPosY = callingSession->oriPosYBeforeRaisedByKeyboard_;
1230 ASSERT_EQ(callingOriPosY, 10);
1231 }
1232
1233 /**
1234 * @tc.name: IsCallingSessionSplitMode01
1235 * @tc.desc: test function : IsCallingSessionSplitMode
1236 * @tc.type: FUNC
1237 */
1238 HWTEST_F(KeyboardSessionTest, IsCallingSessionSplitMode01, Function | SmallTest | Level1)
1239 {
1240 Rosen::WSRect keyboardPanelRect{ 0, 0, 0, 0 };
1241 auto keyboardSession = GetKeyboardSession("IsCallingSessionSplitMode01",
1242 "IsCallingSessionSplitMode01");
1243 ASSERT_NE(keyboardSession, nullptr);
1244 sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
1245 ASSERT_NE(callingSession, nullptr);
1246 callingSession->oriPosYBeforeRaisedByKeyboard_ = 0;
1247 callingSession->winRect_ = { 0, 0, 0, 0 };
__anon7353ffcd1102(const WSRect& rect, const SizeChangeReason reason) 1248 callingSession->updateRectCallback_ = [](const WSRect& rect, const SizeChangeReason reason) {};
__anon7353ffcd1202(int32_t persistentId) 1249 keyboardSession->keyboardCallback_->onGetSceneSession_ = [callingSession](int32_t persistentId) {
1250 return callingSession;
1251 };
1252
1253 auto callingParentSession = GetSceneSession("callingParentSession", "callingParentSession");
1254 ASSERT_NE(callingSession, nullptr);
1255
1256 callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1257 callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1258 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
1259 ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
1260
1261 callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1262 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
1263 ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
1264
1265 callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1266 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
1267 ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
1268
1269 callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1270 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
1271 ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
1272
1273 callingSession->parentSession_ = callingParentSession;
1274 callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1275 callingParentSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1276 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
1277 ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
1278
1279 callingParentSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1280 keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
1281 ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
1282 }
1283
1284 /**
1285 * @tc.name: GetRSTransaction01
1286 * @tc.desc: test function : GetRSTransaction
1287 * @tc.type: FUNC
1288 */
1289 HWTEST_F(KeyboardSessionTest, GetRSTransaction01, Function | SmallTest | Level1)
1290 {
1291 auto keyboardSession = GetKeyboardSession("GetRSTransaction01",
1292 "GetRSTransaction01");
1293 ASSERT_NE(keyboardSession, nullptr);
1294
1295 auto rsTransaction = keyboardSession->GetRSTransaction();
1296 ASSERT_EQ(rsTransaction, nullptr);
1297 }
1298
1299 /**
1300 * @tc.name: GetSessionScreenName01
1301 * @tc.desc: test function : GetSessionScreenName
1302 * @tc.type: FUNC
1303 */
1304 HWTEST_F(KeyboardSessionTest, GetSessionScreenName01, Function | SmallTest | Level1)
1305 {
1306 auto keyboardSession = GetKeyboardSession("GetSessionScreenName01",
1307 "GetSessionScreenName01");
1308 ASSERT_NE(keyboardSession, nullptr);
1309 keyboardSession->property_ = nullptr;
1310 auto resultStr = keyboardSession->GetSessionScreenName();
1311 ASSERT_EQ(resultStr, "");
1312
1313 sptr<WindowSessionProperty> keyboardProperty = sptr<WindowSessionProperty>::MakeSptr();
1314 ASSERT_NE(keyboardProperty, nullptr);
1315 keyboardSession->property_ = keyboardProperty;
1316 keyboardSession->property_->displayId_ = 100;
1317
1318 sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr();
1319 ASSERT_NE(screenSession, nullptr);
1320 screenSession->name_ = "testScreenSession";
1321 screenSession->screenId_ = 100;
1322 ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(100, screenSession);
1323
1324 resultStr = keyboardSession->GetSessionScreenName();
1325 ASSERT_EQ(resultStr, screenSession->name_);
1326 }
1327
1328 /**
1329 * @tc.name: UseFocusIdIfCallingSessionIdInvalid01
1330 * @tc.desc: test function : UseFocusIdIfCallingSessionIdInvalid
1331 * @tc.type: FUNC
1332 */
1333 HWTEST_F(KeyboardSessionTest, UseFocusIdIfCallingSessionIdInvalid01, Function | SmallTest | Level1)
1334 {
1335 auto keyboardSession = GetKeyboardSession("UseFocusIdIfCallingSessionIdInvalid01",
1336 "UseFocusIdIfCallingSessionIdInvalid01");
1337 ASSERT_NE(keyboardSession, nullptr);
1338 sptr<KeyboardSession::KeyboardSessionCallback> keyboardCallback =
1339 sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
1340 ASSERT_NE(keyboardCallback, nullptr);
1341 keyboardSession->keyboardCallback_ = keyboardCallback;
1342 sptr<SceneSession> sceneSession = GetSceneSession("TestSceneSession", "TestSceneSession");
1343 ASSERT_NE(sceneSession, nullptr);
1344 sceneSession->persistentId_ = 100;
1345 keyboardSession->keyboardCallback_->onGetSceneSession_ =
__anon7353ffcd1302(uint32_t callingSessionId)1346 [sceneSession](uint32_t callingSessionId)->sptr<SceneSession> {
1347 if (sceneSession->persistentId_ != callingSessionId) {
1348 return nullptr;
1349 }
1350 return sceneSession;
1351 };
1352
1353 keyboardSession->GetSessionProperty()->SetCallingSessionId(100);
1354 keyboardSession->UseFocusIdIfCallingSessionIdInvalid();
1355 auto resultId = keyboardSession->GetCallingSessionId();
1356 ASSERT_EQ(resultId, 100);
1357
1358 keyboardSession->GetSessionProperty()->SetCallingSessionId(101);
__anon7353ffcd1402()1359 keyboardSession->keyboardCallback_->onGetFocusedSessionId_ = []()->int32_t {
1360 return 100;
1361 };
1362 keyboardSession->UseFocusIdIfCallingSessionIdInvalid();
1363 resultId = keyboardSession->GetCallingSessionId();
1364 ASSERT_EQ(resultId, 100);
1365 }
1366 } // namespace
1367 } // namespace Rosen
1368 } // namespace OHOS
1369