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