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 <gtest/gtest.h>
17
18 #include "interfaces/include/ws_common.h"
19 #include "mock/mock_keyboard_session.h"
20 #include "mock/mock_session_stage.h"
21 #include "session/host/include/keyboard_session.h"
22 #include "session/host/include/scene_session.h"
23 #include "session/host/include/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
33 class KeyboardSessionLayoutTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp() override;
38 void TearDown() override;
39
40 private:
41 sptr<SceneSession> GetSceneSession(const std::string& abilityName, const std::string& bundleName);
42 };
43
SetUpTestCase()44 void KeyboardSessionLayoutTest::SetUpTestCase() {}
45
TearDownTestCase()46 void KeyboardSessionLayoutTest::TearDownTestCase() {}
47
SetUp()48 void KeyboardSessionLayoutTest::SetUp() {}
49
TearDown()50 void KeyboardSessionLayoutTest::TearDown() {}
51
GetSceneSession(const std::string & abilityName,const std::string & bundleName)52 sptr<SceneSession> KeyboardSessionLayoutTest::GetSceneSession(const std::string& abilityName,
53 const std::string& bundleName)
54 {
55 SessionInfo info;
56 info.abilityName_ = abilityName;
57 info.bundleName_ = bundleName;
58 auto specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
59 return sptr<SceneSession>::MakeSptr(info, specificCb);
60 }
61
62 namespace {
63 /**
64 * @tc.name: NotifyClientToUpdateRect01
65 * @tc.desc: NotifyClientToUpdateRect
66 * @tc.type: FUNC
67 */
68 HWTEST_F(KeyboardSessionLayoutTest, NotifyClientToUpdateRect01, TestSize.Level1)
69 {
70 SessionInfo info;
71 info.abilityName_ = "NotifyClientToUpdateRect01";
72 info.bundleName_ = "NotifyClientToUpdateRect01";
73 auto specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
74 auto keyboardCb = sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
75 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
76 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
77 keyboardSession->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
78 keyboardSession->sessionStage_ = mockSessionStage;
79 auto ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr);
80 ASSERT_EQ(ret, WSError::WS_OK);
81 }
82
83 /**
84 * @tc.name: NotifyClientToUpdateRect02
85 * @tc.desc: NotifyClientToUpdateRect
86 * @tc.type: FUNC
87 */
88 HWTEST_F(KeyboardSessionLayoutTest, NotifyClientToUpdateRect02, TestSize.Level1)
89 {
90 SessionInfo info;
91 info.abilityName_ = "NotifyClientToUpdateRect02";
92 info.bundleName_ = "NotifyClientToUpdateRect02";
93 auto specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
94 auto keyboardCb = sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
95 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
96 keyboardSession->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
97 keyboardSession->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE);
98 keyboardSession->isKeyboardPanelEnabled_ = true;
99 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
100 windowSessionProperty->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
101 keyboardSession->SetSessionProperty(windowSessionProperty);
102 auto ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr);
103 ASSERT_EQ(ret, WSError::WS_OK);
104 }
105
106 /**
107 * @tc.name: NotifyClientToUpdateRect03
108 * @tc.desc: NotifyClientToUpdateRect
109 * @tc.type: FUNC
110 */
111 HWTEST_F(KeyboardSessionLayoutTest, NotifyClientToUpdateRect03, TestSize.Level1)
112 {
113 SessionInfo info;
114 info.abilityName_ = "NotifyClientToUpdateRect03";
115 info.bundleName_ = "NotifyClientToUpdateRect03";
116 auto specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
117 auto keyboardCb = sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
118 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
119
120 // NotifyClientToUpdateRectTask return not ok
121 WSError ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr);
122 ASSERT_EQ(ret, WSError::WS_OK);
123
124 // NotifyClientToUpdateRectTask return ok and GetSizeChangeReason() is UNDEFINED
125 keyboardSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
126 keyboardSession->state_ = SessionState::STATE_CONNECT;
127 ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr);
128 ASSERT_EQ(ret, WSError::WS_OK);
129
130 // NotifyClientToUpdateRectTask return ok and GetSizeChangeReason() is DRAG
131 keyboardSession->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG);
132 keyboardSession->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
133 ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr);
134 ASSERT_EQ(ret, WSError::WS_OK);
135 }
136 } // namespace
137 } // namespace Rosen
138 } // namespace OHOS
139