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