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 {
46 }
47
TearDownTestCase()48 void KeyboardSessionLayoutTest::TearDownTestCase()
49 {
50 }
51
SetUp()52 void KeyboardSessionLayoutTest::SetUp()
53 {
54 }
55
TearDown()56 void KeyboardSessionLayoutTest::TearDown()
57 {
58 }
59
GetSceneSession(const std::string & abilityName,const std::string & bundleName)60 sptr<SceneSession> KeyboardSessionLayoutTest::GetSceneSession(const std::string& abilityName,
61 const std::string& bundleName)
62 {
63 SessionInfo info;
64 info.abilityName_ = abilityName;
65 info.bundleName_ = bundleName;
66 auto specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
67 return sptr<SceneSession>::MakeSptr(info, specificCb);
68 }
69
70 namespace {
71 /**
72 * @tc.name: NotifyClientToUpdateRect01
73 * @tc.desc: NotifyClientToUpdateRect
74 * @tc.type: FUNC
75 */
76 HWTEST_F(KeyboardSessionLayoutTest, NotifyClientToUpdateRect01, Function | SmallTest | Level2)
77 {
78 SessionInfo info;
79 info.abilityName_ = "NotifyClientToUpdateRect01";
80 info.bundleName_ = "NotifyClientToUpdateRect01";
81 auto specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
82 auto keyboardCb = sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
83 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
84 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
85 keyboardSession->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
86 keyboardSession->sessionStage_ = mockSessionStage;
87 auto ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr);
88 ASSERT_EQ(ret, WSError::WS_OK);
89 }
90
91 /**
92 * @tc.name: NotifyClientToUpdateRect02
93 * @tc.desc: NotifyClientToUpdateRect
94 * @tc.type: FUNC
95 */
96 HWTEST_F(KeyboardSessionLayoutTest, NotifyClientToUpdateRect02, Function | SmallTest | Level2)
97 {
98 SessionInfo info;
99 info.abilityName_ = "NotifyClientToUpdateRect02";
100 info.bundleName_ = "NotifyClientToUpdateRect02";
101 auto specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
102 auto keyboardCb = sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
103 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
104 keyboardSession->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
105 keyboardSession->reason_ = SizeChangeReason::MOVE;
106 keyboardSession->isKeyboardPanelEnabled_ = true;
107 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
108 windowSessionProperty->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
109 keyboardSession->SetSessionProperty(windowSessionProperty);
110 auto ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr);
111 ASSERT_EQ(ret, WSError::WS_OK);
112 }
113
114 /**
115 * @tc.name: NotifyClientToUpdateRect03
116 * @tc.desc: NotifyClientToUpdateRect
117 * @tc.type: FUNC
118 */
119 HWTEST_F(KeyboardSessionLayoutTest, NotifyClientToUpdateRect03, Function | SmallTest | Level2)
120 {
121 SessionInfo info;
122 info.abilityName_ = "NotifyClientToUpdateRect03";
123 info.bundleName_ = "NotifyClientToUpdateRect03";
124 auto specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
125 auto keyboardCb = sptr<KeyboardSession::KeyboardSessionCallback>::MakeSptr();
126 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, specificCb, keyboardCb);
127
128 // NotifyClientToUpdateRectTask return not ok
129 WSError ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr);
130 ASSERT_EQ(ret, WSError::WS_OK);
131
132 // NotifyClientToUpdateRectTask return ok and session->reason_ is UNDEFINED
133 keyboardSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
134 keyboardSession->state_ = SessionState::STATE_CONNECT;
135 ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr);
136 ASSERT_EQ(ret, WSError::WS_OK);
137
138 // NotifyClientToUpdateRectTask return ok and session->reason_ is DRAG
139 keyboardSession->reason_ = SizeChangeReason::DRAG;
140 keyboardSession->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
141 ret = keyboardSession->NotifyClientToUpdateRect("KeyboardSessionLayoutTest", nullptr);
142 ASSERT_EQ(ret, WSError::WS_OK);
143 }
144 } // namespace
145 } // namespace Rosen
146 } // namespace OHOS
147