• 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 
19 #include "interfaces/include/ws_common.h"
20 #include "mock/mock_session_stage.h"
21 #include "mock/mock_keyboard_session.h"
22 #include "session/host/include/session.h"
23 #include "session/host/include/scene_session.h"
24 #include "window_helper.h"
25 #include "window_manager_hilog.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace Rosen {
32 namespace {
33 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "KeyboardSessionTest2"};
34 }
35 
36 constexpr int WAIT_ASYNC_US = 1000000;
37 class KeyboardSessionTest2 : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp() override;
42     void TearDown() override;
43 
44 private:
45     sptr<KeyboardSession> GetKeyboardSession(const std::string& abilityName, const std::string& bundleName);
46     sptr<SceneSession> GetSceneSession(const std::string& abilityName, const std::string& bundleName);
47     sptr<KSSceneSessionMocker> GetSceneSessionMocker(const std::string& abilityName, const std::string& bundleName);
48 };
49 
SetUpTestCase()50 void KeyboardSessionTest2::SetUpTestCase()
51 {
52 }
53 
TearDownTestCase()54 void KeyboardSessionTest2::TearDownTestCase()
55 {
56 }
57 
SetUp()58 void KeyboardSessionTest2::SetUp()
59 {
60 }
61 
TearDown()62 void KeyboardSessionTest2::TearDown()
63 {
64 }
65 
GetKeyboardSession(const std::string & abilityName,const std::string & bundleName)66 sptr<KeyboardSession> KeyboardSessionTest2::GetKeyboardSession(const std::string& abilityName,
67     const std::string& bundleName)
68 {
69     SessionInfo info;
70     info.abilityName_ = abilityName;
71     info.bundleName_ = bundleName;
72     sptr<SceneSession::SpecificSessionCallback> specificCb =
73         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
74     EXPECT_NE(specificCb, nullptr);
75     sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
76         sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
77     EXPECT_NE(keyboardCb, nullptr);
78     sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
79     EXPECT_NE(keyboardSession, nullptr);
80 
81     sptr<WindowSessionProperty> keyboardProperty = sptr<WindowSessionProperty>::MakeSptr();
82     EXPECT_NE(keyboardProperty, nullptr);
83     keyboardProperty->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
84     keyboardSession->SetSessionProperty(keyboardProperty);
85 
86     return keyboardSession;
87 }
88 
GetSceneSession(const std::string & abilityName,const std::string & bundleName)89 sptr<SceneSession> KeyboardSessionTest2::GetSceneSession(const std::string& abilityName,
90     const std::string& bundleName)
91 {
92     SessionInfo info;
93     info.abilityName_ = abilityName;
94     info.bundleName_ = bundleName;
95     sptr<SceneSession::SpecificSessionCallback> specificCb =
96         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
97     EXPECT_NE(specificCb, nullptr);
98     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
99 
100     return sceneSession;
101 }
102 
GetSceneSessionMocker(const std::string & abilityName,const std::string & bundleName)103 sptr<KSSceneSessionMocker> KeyboardSessionTest2::GetSceneSessionMocker(const std::string& abilityName,
104     const std::string& bundleName)
105 {
106     SessionInfo info;
107     info.abilityName_ = abilityName;
108     info.bundleName_ = bundleName;
109     sptr<SceneSession::SpecificSessionCallback> specificCb =
110         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
111     EXPECT_NE(specificCb, nullptr);
112     sptr<KSSceneSessionMocker> mockSession = sptr<KSSceneSessionMocker>::MakeSptr(info, nullptr);
113 
114     return mockSession;
115 }
116 
117 namespace {
118 /**
119  * @tc.name: AdjustKeyboardLayout01
120  * @tc.desc: AdjustKeyboardLayout
121  * @tc.type: FUNC
122  */
123 HWTEST_F(KeyboardSessionTest2, AdjustKeyboardLayout01, Function | SmallTest | Level1)
124 {
125     SessionInfo info;
126     info.abilityName_ = "AdjustKeyboardLayout01";
127     info.bundleName_ = "AdjustKeyboardLayout01";
128     sptr<SceneSession::SpecificSessionCallback> specificCb =
129         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
130     EXPECT_NE(specificCb, nullptr);
131     sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
132         sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
133     EXPECT_NE(keyboardCb, nullptr);
134     sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
135     EXPECT_NE(keyboardSession, nullptr);
136     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
137     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
138     keyboardSession->SetSessionProperty(property);
139 
140     KeyboardLayoutParams params;
141     ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
142 
143     keyboardSession->adjustKeyboardLayoutFunc_ = nullptr;
144     ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
145 
__anon9e9290bf0302(const KeyboardLayoutParams& params)146     keyboardSession->adjustKeyboardLayoutFunc_ = [](const KeyboardLayoutParams& params){};
147     ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
148 }
149 
150 /**
151  * @tc.name: AdjustKeyboardLayout01
152  * @tc.desc: AdjustKeyboardLayout
153  * @tc.type: FUNC
154  */
155 HWTEST_F(KeyboardSessionTest2, AdjustKeyboardLayout02, Function | SmallTest | Level1)
156 {
157     SessionInfo info;
158     info.abilityName_ = "AdjustKeyboardLayout02";
159     info.bundleName_ = "AdjustKeyboardLayout02";
160     sptr<SceneSession::SpecificSessionCallback> specificCb =
161         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
162     EXPECT_NE(specificCb, nullptr);
163     sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
164         sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
165     EXPECT_NE(keyboardCb, nullptr);
166     sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
167     EXPECT_NE(keyboardSession, nullptr);
168 
169     KeyboardLayoutParams params;
170     // params gravity is WINDOW_GRAVITY_BOTTOM
171     ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
172     keyboardSession->state_ = SessionState::STATE_FOREGROUND;
173     ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
174 
175     // params gravity is WINDOW_GRAVITY_FLOAT
176     params.gravity_ = WindowGravity::WINDOW_GRAVITY_FLOAT;
177     ASSERT_EQ(keyboardSession->AdjustKeyboardLayout(params), WSError::WS_OK);
178 }
179 
180 /**
181  * @tc.name: CheckIfNeedRaiseCallingSession
182  * @tc.desc: CheckIfNeedRaiseCallingSession
183  * @tc.type: FUNC
184  */
185 HWTEST_F(KeyboardSessionTest2, CheckIfNeedRaiseCallingSession, Function | SmallTest | Level1)
186 {
187     WLOGFI("CheckIfNeedRaiseCallingSession begin!");
188     SessionInfo info;
189     info.abilityName_ = "CheckIfNeedRaiseCallingSession";
190     info.bundleName_ = "CheckIfNeedRaiseCallingSession";
191     sptr<SceneSession::SpecificSessionCallback> specificCb =
192         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
193     EXPECT_NE(specificCb, nullptr);
194     sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
195         sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
196     EXPECT_NE(keyboardCb, nullptr);
197     sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
198     EXPECT_NE(keyboardSession, nullptr);
199     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
200     EXPECT_NE(property, nullptr);
201     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
202     keyboardSession->SetSessionProperty(property);
203 
204     ASSERT_FALSE(keyboardSession->CheckIfNeedRaiseCallingSession(nullptr, true));
205 
206     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
207     EXPECT_NE(sceneSession, nullptr);
208 
209     keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_FLOAT;
210     ASSERT_FALSE(keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, true));
211 
212     keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
213     ASSERT_TRUE(keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, false));
214 
215     property->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
216 
217     keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
218     ASSERT_FALSE(keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, true));
219 
220     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
221     keyboardSession->CheckIfNeedRaiseCallingSession(sceneSession, true);
222 
223     WLOGFI("CheckIfNeedRaiseCallingSession end!");
224 }
225 
226 /**
227  * @tc.name: OpenKeyboardSyncTransaction
228  * @tc.desc: OpenKeyboardSyncTransaction
229  * @tc.type: FUNC
230  */
231 HWTEST_F(KeyboardSessionTest2, OpenKeyboardSyncTransaction, Function | SmallTest | Level1)
232 {
233     std::string abilityName = "OpenKeyboardSyncTransaction";
234     std::string bundleName = "OpenKeyboardSyncTransaction";
235     sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
236 
237     WSRect keyboardPanelRect = { 0, 0, 0, 0 };
238     bool isKeyboardShow = true;
239     bool isRotating = false;
240 
241     // isKeyBoardSyncTransactionOpen_ is false
242     keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, isRotating);
243     keyboardSession->OpenKeyboardSyncTransaction();
244 
245     // isKeyBoardSyncTransactionOpen_ is true
246     keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, isRotating);
247     keyboardSession->OpenKeyboardSyncTransaction();
248     ASSERT_EQ(keyboardSession->isKeyboardSyncTransactionOpen_, true);
249 }
250 
251 /**
252  * @tc.name: BindKeyboardPanelSession
253  * @tc.desc: BindKeyboardPanelSession
254  * @tc.type: FUNC
255  */
256 HWTEST_F(KeyboardSessionTest2, BindKeyboardPanelSession, Function | SmallTest | Level1)
257 {
258     SessionInfo info;
259     info.abilityName_ = "BindKeyboardPanelSession";
260     info.bundleName_ = "BindKeyboardPanelSession";
261     sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
262     ASSERT_NE(keyboardSession, nullptr);
263     sptr<SceneSession> panelSession = nullptr;
264     keyboardSession->BindKeyboardPanelSession(panelSession);
265     sptr<SceneSession> getPanelSession = keyboardSession->GetKeyboardPanelSession();
266     ASSERT_EQ(getPanelSession, nullptr);
267     panelSession = sptr<SceneSession>::MakeSptr(info, nullptr);
268     ASSERT_NE(panelSession, nullptr);
269     keyboardSession->BindKeyboardPanelSession(panelSession);
270     getPanelSession = keyboardSession->GetKeyboardPanelSession();
271     EXPECT_EQ(getPanelSession, panelSession);
272 }
273 
274 /**
275  * @tc.name: GetKeyboardGravity01
276  * @tc.desc: GetKeyboardGravity01
277  * @tc.type: FUNC
278  */
279 HWTEST_F(KeyboardSessionTest2, GetKeyboardGravity01, Function | SmallTest | Level1)
280 {
281     SessionInfo info;
282     info.abilityName_ = "GetKeyboardGravity";
283     info.bundleName_ = "GetKeyboardGravity";
284     sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
285     sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
286     keyboardSession->property_ = windowSessionProperty;
287     keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
288     auto ret = keyboardSession->GetKeyboardGravity();
289     EXPECT_EQ(SessionGravity::SESSION_GRAVITY_BOTTOM, ret);
290 }
291 
292 /**
293  * @tc.name: NotifyKeyboardPanelInfoChange
294  * @tc.desc: NotifyKeyboardPanelInfoChange
295  * @tc.type: FUNC
296  */
297 HWTEST_F(KeyboardSessionTest2, NotifyKeyboardPanelInfoChange, Function | SmallTest | Level1)
298 {
299     WSRect rect = {800, 800, 1200, 1200};
300     SessionInfo info;
301     info.abilityName_ = "NotifyKeyboardPanelInfoChange";
302     info.bundleName_ = "NotifyKeyboardPanelInfoChange";
303     sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
304     ASSERT_NE(keyboardSession, nullptr);
305     keyboardSession->isKeyboardPanelEnabled_ = false;
306     keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
307     keyboardSession->isKeyboardPanelEnabled_ = true;
308     keyboardSession->sessionStage_ = nullptr;
309     keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
310     sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
311     ASSERT_NE(mockSessionStage, nullptr);
312     keyboardSession->sessionStage_ = mockSessionStage;
313     ASSERT_NE(keyboardSession->sessionStage_, nullptr);
314     keyboardSession->NotifyKeyboardPanelInfoChange(rect, true);
315 }
316 
317 /**
318  * @tc.name: CheckIfNeedRaiseCallingSession01
319  * @tc.desc: CheckIfNeedRaiseCallingSession01
320  * @tc.type: FUNC
321  */
322 HWTEST_F(KeyboardSessionTest2, CheckIfNeedRaiseCallingSession01, Function | SmallTest | Level1)
323 {
324     SessionInfo info;
325     info.abilityName_ = "CheckIfNeedRaiseCallingSession";
326     info.bundleName_ = "CheckIfNeedRaiseCallingSession";
327     sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
328     ASSERT_NE(specificCb, nullptr);
329     sptr<SceneSession> callingSession = sptr<SceneSession>::MakeSptr(info, specificCb);
330     ASSERT_NE(callingSession, nullptr);
331     sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
332     ASSERT_NE(keyboardSession, nullptr);
333     ASSERT_NE(keyboardSession->property_, nullptr);
334     keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
335     keyboardSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
336     keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
337     callingSession->systemConfig_.freeMultiWindowSupport_ = true;
338     callingSession->systemConfig_.freeMultiWindowEnable_ = true;
339     auto ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
340     EXPECT_EQ(ret, false);
341     callingSession->systemConfig_.freeMultiWindowEnable_ = false;
342     ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
343     EXPECT_EQ(ret, false);
344     callingSession->systemConfig_.freeMultiWindowEnable_ = true;
345     keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
346     ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
347     EXPECT_EQ(ret, true);
348     keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
349     callingSession->systemConfig_.freeMultiWindowEnable_ = false;
350     ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
351     EXPECT_EQ(ret, true);
352     keyboardSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
353     ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, true);
354     EXPECT_EQ(ret, true);
355     ret = keyboardSession->CheckIfNeedRaiseCallingSession(callingSession, false);
356     EXPECT_EQ(ret, true);
357 }
358 
359 /**
360  * @tc.name: UpdateCallingSessionIdAndPosition01
361  * @tc.desc: UpdateCallingSessionIdAndPosition01
362  * @tc.type: FUNC
363  */
364 HWTEST_F(KeyboardSessionTest2, UpdateCallingSessionIdAndPosition01, Function | SmallTest | Level1)
365 {
366     SessionInfo info;
367     info.abilityName_ = "UpdateCallingSessionIdAndPosition";
368     info.bundleName_ = "UpdateCallingSessionIdAndPosition";
369     sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
370     ASSERT_NE(keyboardSession, nullptr);
371     ASSERT_NE(keyboardSession->property_, nullptr);
372     keyboardSession->UpdateCallingSessionIdAndPosition(0);
373     keyboardSession->property_->SetCallingSessionId(-1);
374     keyboardSession->UpdateCallingSessionIdAndPosition(0);
375     keyboardSession->UpdateCallingSessionIdAndPosition(-1);
376     keyboardSession->property_->SetCallingSessionId(0);
377     keyboardSession->UpdateCallingSessionIdAndPosition(0);
378 }
379 
380 /**
381  * @tc.name: OpenKeyboardSyncTransaction01
382  * @tc.desc: OpenKeyboardSyncTransaction
383  * @tc.type: FUNC
384  */
385 HWTEST_F(KeyboardSessionTest2, OpenKeyboardSyncTransaction01, Function | SmallTest | Level1)
386 {
387     SessionInfo info;
388     info.abilityName_ = "UpdateCallingSessionIdAndPosition";
389     info.bundleName_ = "UpdateCallingSessionIdAndPosition";
390     sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
391     ASSERT_NE(keyboardSession, nullptr);
392     keyboardSession->isKeyboardSyncTransactionOpen_ = true;
393     keyboardSession->OpenKeyboardSyncTransaction();
394     keyboardSession->isKeyboardSyncTransactionOpen_ = false;
395     keyboardSession->OpenKeyboardSyncTransaction();
396     WSRect keyboardPanelRect = {0, 0, 0, 0};
397     keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, true, true);
398     keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, false);
399 }
400 
401 /**
402  * @tc.name: Hide01
403  * @tc.desc: test function : Hide
404  * @tc.type: FUNC
405  */
406 HWTEST_F(KeyboardSessionTest2, Hide01, Function | SmallTest | Level1)
407 {
408     SessionInfo info;
409     info.abilityName_ = "Hide";
410     info.bundleName_ = "Hide";
411     sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
412     ASSERT_NE(specificCb, nullptr);
413     sptr<KeyboardSession::KeyboardSessionCallback> keyboardCb =
414         sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
415     ASSERT_NE(keyboardCb, nullptr);
416     sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
417     ASSERT_NE(keyboardSession, nullptr);
418 
419     // setActive false return not ok
420     keyboardSession->state_ = SessionState::STATE_DISCONNECT;
421     EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
422 
423     // setActive false return ok and deviceType is phone
424     keyboardSession->state_ = SessionState::STATE_CONNECT;
425     keyboardSession->isActive_ = true;
426     keyboardSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
427     ASSERT_NE(keyboardSession->sessionStage_, nullptr);
428     keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
429     EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
430 
431     // deviceType is pc and property is not nullptr
432     ASSERT_NE(keyboardSession->property_, nullptr);
433     keyboardSession->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
434     EXPECT_EQ(WSError::WS_OK, keyboardSession->Hide());
435 
436     // Hide system keyboard
437     ASSERT_EQ(false, keyboardSession->IsSystemKeyboard());
438     keyboardSession->SetIsSystemKeyboard(true);
439     ASSERT_EQ(true, keyboardSession->IsSystemKeyboard());
440     ASSERT_EQ(WSError::WS_OK, keyboardSession->Hide());
441 }
442 
443 /**
444  * @tc.name: RaiseCallingSession01
445  * @tc.desc: test function : RaiseCallingSession
446  * @tc.type: FUNC
447  */
448 HWTEST_F(KeyboardSessionTest2, RaiseCallingSession01, Function | SmallTest | Level1)
449 {
450     auto keyboardSession = GetKeyboardSession("RaiseCallingSession01",
451         "RaiseCallingSession01");
452     ASSERT_NE(keyboardSession, nullptr);
453     keyboardSession->state_ = SessionState::STATE_FOREGROUND;
454     keyboardSession->isVisible_ = true;
455 
456     Rosen::WSRect resultRect{ 0, 0, 0, 0 };
457     sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
458     ASSERT_NE(callingSession, nullptr);
459 
__anon9e9290bf0402(const WSRect& rect, SizeChangeReason reason) 460     callingSession->updateRectCallback_ = [&resultRect](const WSRect& rect, SizeChangeReason reason) {
461         resultRect.posX_ = rect.posX_;
462         resultRect.posY_ = rect.posY_;
463         resultRect.width_ = rect.width_;
464         resultRect.height_ = rect.height_;
465     };
466     callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
467     callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
468 
469     Rosen::WSRect keyboardPanelRect{ 0, 0, 0, 0 };
470     Rosen::WSRect emptyRect{ 0, 0, 0, 0 };
471     std::shared_ptr<RSTransaction> rsTransaction = nullptr;
472     keyboardSession->state_ = SessionState::STATE_FOREGROUND;
473     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, rsTransaction);
474     ASSERT_EQ(resultRect, emptyRect);
475 
476     // for cover GetSceneSession
477     keyboardSession->keyboardCallback_->onGetSceneSession =
__anon9e9290bf0502(int32_t persistentId)478         [callingSession](int32_t persistentId)->sptr<SceneSession> {
479         return callingSession;
480     };
481     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, rsTransaction);
482     // for cover CheckIfNeedRaiseCallingSession
483     keyboardSession->property_->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
484 
485     // for empty rect check;
486     keyboardSession->winRect_.posX_ = 1;
487     keyboardSession->winRect_.posY_ = 1;
488     keyboardSession->winRect_.posX_ = 1;
489     keyboardSession->winRect_.posX_ = 1;
490 
491     // for cover oriPosYBeforeRaisedBykeyboard == 0
492     callingSession->SetOriPosYBeforeRaisedByKeyboard(0);
493     ASSERT_EQ(resultRect, emptyRect);
494 }
495 
496 /**
497  * @tc.name: RaiseCallingSession02
498  * @tc.desc: test function : RaiseCallingSession
499  * @tc.type: FUNC
500  */
501 HWTEST_F(KeyboardSessionTest2, RaiseCallingSession02, Function | SmallTest | Level1)
502 {
503     Rosen::WSRect keyboardPanelRect{ 1, 1, 1, 1 };
504     auto keyboardSession = GetKeyboardSession("RaiseCallingSession02",
505         "RaiseCallingSession02");
506     ASSERT_NE(keyboardSession, nullptr);
507     sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
508     ASSERT_NE(callingSession, nullptr);
509     keyboardSession->state_ = SessionState::STATE_FOREGROUND;
510     ASSERT_NE(callingSession->property_, nullptr);
511     callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
512     callingSession->winRect_ = { 1, 1, 1, 1 };
__anon9e9290bf0602(int32_t persistentId) 513     keyboardSession->keyboardCallback_->onGetSceneSession = [callingSession](int32_t persistentId) {
514         return callingSession;
515     };
516     keyboardSession->state_ = SessionState::STATE_FOREGROUND;
517     keyboardSession->isVisible_ = true;
518     callingSession->oriPosYBeforeRaisedByKeyboard_ = 0;
519     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
520     ASSERT_EQ(callingSession->winRect_.posY_, 1);
521 
522     callingSession->oriPosYBeforeRaisedByKeyboard_ = 10;
523     callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
524     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
525     ASSERT_EQ(callingSession->winRect_.posY_, 1);
526 
527     keyboardPanelRect = { 0, 0, 0, 0 };
528     callingSession->oriPosYBeforeRaisedByKeyboard_ = 10;
529     callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
530     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
531     ASSERT_EQ(callingSession->winRect_.posY_, 1);
532 }
533 
534 /**
535  * @tc.name: RaiseCallingSession03
536  * @tc.desc: test function : RaiseCallingSession
537  * @tc.type: FUNC
538  */
539 HWTEST_F(KeyboardSessionTest2, RaiseCallingSession03, Function | SmallTest | Level1)
540 {
541     Rosen::WSRect keyboardPanelRect{ 1, 1, 1, 1 };
542     auto keyboardSession = GetKeyboardSession("RaiseCallingSession03",
543         "RaiseCallingSession03");
544     ASSERT_NE(keyboardSession, nullptr);
545     sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
546     ASSERT_NE(callingSession, nullptr);
547     callingSession->winRect_ = { 1, 1, 1, 1 };
548     callingSession->oriPosYBeforeRaisedByKeyboard_ = 0;
__anon9e9290bf0702(const WSRect& rect, SizeChangeReason reason) 549     callingSession->updateRectCallback_ = [](const WSRect& rect, SizeChangeReason reason) {};
__anon9e9290bf0802(int32_t persistentId) 550     keyboardSession->keyboardCallback_->onGetSceneSession = [callingSession](int32_t persistentId) {
551         return callingSession;
552     };
553     keyboardSession->state_ = SessionState::STATE_FOREGROUND;
554     keyboardSession->isVisible_ = true;
555     auto callingOriPosY = 0;
556     ASSERT_NE(callingSession->property_, nullptr);
557     callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
558     callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
559     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
560     callingOriPosY = callingSession->oriPosYBeforeRaisedByKeyboard_;
561     ASSERT_EQ(callingOriPosY, 0);
562 
563     callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
564     callingSession->winRect_.posY_ = 200;
565     keyboardPanelRect.posY_ = 200;
566     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
567     callingOriPosY = callingSession->oriPosYBeforeRaisedByKeyboard_;
568     ASSERT_EQ(callingOriPosY, 200);
569 
570     callingSession->oriPosYBeforeRaisedByKeyboard_ = 10;
571     callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
572     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
573     callingOriPosY = callingSession->oriPosYBeforeRaisedByKeyboard_;
574     ASSERT_EQ(callingOriPosY, 10);
575 
576     keyboardSession->ActivateKeyboardAvoidArea(false, false);
577     ASSERT_EQ(false, keyboardSession->keyboardAvoidAreaActive_);
578     keyboardSession->EnableCallingSessionAvoidArea();
579     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
580     ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 10); // 10 is calling session position
581 }
582 
583 /**
584  * @tc.name: IsCallingSessionSplitMode01
585  * @tc.desc: test function : IsCallingSessionSplitMode
586  * @tc.type: FUNC
587  */
588 HWTEST_F(KeyboardSessionTest2, IsCallingSessionSplitMode01, Function | SmallTest | Level1)
589 {
590     Rosen::WSRect keyboardPanelRect{ 0, 0, 0, 0 };
591     auto keyboardSession = GetKeyboardSession("IsCallingSessionSplitMode01",
592         "IsCallingSessionSplitMode01");
593     ASSERT_NE(keyboardSession, nullptr);
594     sptr<KSSceneSessionMocker> callingSession = GetSceneSessionMocker("callingSession", "callingSession");
595     ASSERT_NE(callingSession, nullptr);
596     callingSession->oriPosYBeforeRaisedByKeyboard_ = 0;
597     callingSession->winRect_ = { 0, 0, 0, 0 };
__anon9e9290bf0902(const WSRect& rect, SizeChangeReason reason) 598     callingSession->updateRectCallback_ = [](const WSRect& rect, SizeChangeReason reason) {};
__anon9e9290bf0a02(int32_t persistentId) 599     keyboardSession->keyboardCallback_->onGetSceneSession = [callingSession](int32_t persistentId) {
600         return callingSession;
601     };
602     keyboardSession->state_ = SessionState::STATE_FOREGROUND;
603 
604     auto callingParentSession = GetSceneSession("callingParentSession", "callingParentSession");
605     ASSERT_NE(callingSession, nullptr);
606     callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
607     callingSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
608     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
609     ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
610 
611     callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
612     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
613     ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
614 
615     callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
616     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
617     ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
618 
619     callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
620     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
621     ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
622 
623     callingSession->parentSession_ = callingParentSession;
624     callingSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
625     callingParentSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
626     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
627     ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
628 
629     callingParentSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
630     keyboardSession->RaiseCallingSession(keyboardPanelRect, true, nullptr);
631     ASSERT_EQ(callingSession->oriPosYBeforeRaisedByKeyboard_, 0);
632 }
633 
634 /**
635  * @tc.name: CloseKeyBoardSyncTransaction3
636  * @tc.desc: test function : CloseKeyBoardSyncTransaction
637  * @tc.type: FUNC
638  */
639 HWTEST_F(KeyboardSessionTest2, CloseKeyBoardSyncTransaction3, Function | SmallTest | Level1)
640 {
641     std::string abilityName = "CloseKeyBoardSyncTransaction3";
642     std::string bundleName = "CloseKeyBoardSyncTransaction3";
643     sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
644     ASSERT_NE(keyboardSession, nullptr);
645 
646     WSRect keyboardPanelRect = { 0, 0, 0, 0 };
647     bool isKeyboardShow = true;
648     bool isRotating = false;
649 
650     keyboardSession->dirtyFlags_ = 0;
__anon9e9290bf0b02(uint32_t callingSessionId) 651     keyboardSession->specificCallback_->onUpdateAvoidArea_ = [](uint32_t callingSessionId) {};
652     keyboardSession->isKeyboardSyncTransactionOpen_ = true;
653     // isKeyBoardSyncTransactionOpen_ is true
654     keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, isKeyboardShow, isRotating);
655     usleep(WAIT_ASYNC_US);
656     ASSERT_EQ(keyboardSession->isKeyboardSyncTransactionOpen_, false);
657 }
658 
659 /**
660  * @tc.name: CloseKeyboardSyncTransaction4
661  * @tc.desc: test function : CloseKeyboardSyncTransaction
662  * @tc.type: FUNC
663  */
664 HWTEST_F(KeyboardSessionTest2, CloseKeyboardSyncTransaction4, Function | SmallTest | Level1)
665 {
666     std::string abilityName = "CloseKeyboardSyncTransaction4";
667     std::string bundleName = "CloseKeyboardSyncTransaction4";
668     sptr<KeyboardSession> keyboardSession = GetKeyboardSession(abilityName, bundleName);
669     ASSERT_NE(keyboardSession, nullptr);
670     WSRect keyboardPanelRect = { 0, 0, 0, 0 };
671     keyboardSession->dirtyFlags_ = 0;
672 
673     keyboardSession->isKeyboardSyncTransactionOpen_ = false;
674     ASSERT_NE(keyboardSession->property_, nullptr);
675     keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, false);
676     usleep(WAIT_ASYNC_US);
677     ASSERT_EQ(0, keyboardSession->dirtyFlags_);
678     keyboardSession->isKeyboardSyncTransactionOpen_ = true;
679     keyboardSession->property_->SetCallingSessionId(1);
680     keyboardSession->CloseKeyboardSyncTransaction(keyboardPanelRect, false, false);
681     usleep(WAIT_ASYNC_US);
682     auto callingSessionId = keyboardSession->property_->GetCallingSessionId();
683     ASSERT_EQ(callingSessionId, INVALID_WINDOW_ID);
684 }
685 }  // namespace
686 }  // namespace Rosen
687 }  // namespace OHOS
688