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 #include "session/host/include/scb_system_session.h"
18 #include "common/include/session_permission.h"
19 #include "key_event.h"
20 #include "mock/mock_session_stage.h"
21 #include "session/host/include/session.h"
22 #include "window_helper.h"
23 #include "window_manager_hilog.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Rosen {
30 class SCBSystemSessionTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34 void SetUp() override;
35 void TearDown() override;
36 SessionInfo info;
37 sptr<SCBSystemSession::SpecificSessionCallback> specificCallback = nullptr;
38 sptr<SCBSystemSession> scbSystemSession_;
39 };
40
SetUpTestCase()41 void SCBSystemSessionTest::SetUpTestCase() {}
42
TearDownTestCase()43 void SCBSystemSessionTest::TearDownTestCase() {}
44
SetUp()45 void SCBSystemSessionTest::SetUp()
46 {
47 SessionInfo info;
48 info.abilityName_ = "testSCBSystemSession1";
49 info.moduleName_ = "testSCBSystemSession2";
50 info.bundleName_ = "testSCBSystemSession3";
51 scbSystemSession_ = sptr<SCBSystemSession>::MakeSptr(info, specificCallback);
52 EXPECT_NE(nullptr, scbSystemSession_);
53 }
54
TearDown()55 void SCBSystemSessionTest::TearDown()
56 {
57 scbSystemSession_ = nullptr;
58 }
59
60 namespace {
61 /**
62 * @tc.name: IsVisibleNotBackground
63 * @tc.desc: check func IsVisibleNotBackground
64 * @tc.type: FUNC
65 */
66 HWTEST_F(SCBSystemSessionTest, IsVisibleNotBackground, TestSize.Level1)
67 {
68 ASSERT_NE(scbSystemSession_, nullptr);
69 EXPECT_EQ(false, scbSystemSession_->IsVisibleNotBackground());
70 scbSystemSession_->isVisible_ = true;
71 EXPECT_EQ(true, scbSystemSession_->IsVisibleNotBackground());
72 }
73
74 /**
75 * @tc.name: TransferKeyEvent01
76 * @tc.desc: check func TransferKeyEvent
77 * @tc.type: FUNC
78 */
79 HWTEST_F(SCBSystemSessionTest, TransferKeyEvent01, TestSize.Level1)
80 {
81 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, scbSystemSession_->TransferKeyEvent(nullptr));
82 }
83
84 /**
85 * @tc.name: TransferKeyEvent02
86 * @tc.desc: check func TransferKeyEvent
87 * @tc.type: FUNC
88 */
89 HWTEST_F(SCBSystemSessionTest, TransferKeyEvent02, TestSize.Level1)
90 {
91 scbSystemSession_->state_ = SessionState::STATE_CONNECT;
92 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
93 ASSERT_NE(keyEvent, nullptr);
94 scbSystemSession_->windowEventChannel_ = nullptr;
95
96 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, scbSystemSession_->TransferKeyEvent(keyEvent));
97 }
98
99 /**
100 * @tc.name: UpdateFocus01
101 * @tc.desc: check func UpdateFocus
102 * @tc.type: FUNC
103 */
104 HWTEST_F(SCBSystemSessionTest, UpdateFocus01, TestSize.Level1)
105 {
106 bool isFocused = scbSystemSession_->isFocused_;
107
108 ASSERT_EQ(WSError::WS_DO_NOTHING, scbSystemSession_->UpdateFocus(isFocused));
109 }
110
111 /**
112 * @tc.name: UpdateFocus02
113 * @tc.desc: check func UpdateFocus
114 * @tc.type: FUNC
115 */
116 HWTEST_F(SCBSystemSessionTest, UpdateFocus02, TestSize.Level1)
117 {
118 scbSystemSession_->isFocused_ = true;
119 bool isFocused = scbSystemSession_->isFocused_;
120
121 ASSERT_EQ(WSError::WS_OK, scbSystemSession_->UpdateFocus(!isFocused));
122
123 scbSystemSession_->isFocused_ = false;
124 isFocused = scbSystemSession_->isFocused_;
125
126 ASSERT_EQ(WSError::WS_OK, scbSystemSession_->UpdateFocus(!isFocused));
127 }
128
129 /**
130 * @tc.name: BindKeyboardSession01
131 * @tc.desc: check func BindKeyboardSession
132 * @tc.type: FUNC
133 */
134 HWTEST_F(SCBSystemSessionTest, BindKeyboardSession01, TestSize.Level1)
135 {
136 ASSERT_NE(nullptr, scbSystemSession_);
137 scbSystemSession_->BindKeyboardSession(nullptr);
138 }
139
140 /**
141 * @tc.name: BindKeyboardSession02
142 * @tc.desc: check func BindKeyboardSession
143 * @tc.type: FUNC
144 */
145 HWTEST_F(SCBSystemSessionTest, BindKeyboardSession02, TestSize.Level1)
146 {
147 ASSERT_NE(nullptr, scbSystemSession_);
148 SessionInfo info;
149 info.bundleName_ = "IntentionEventManager";
150 info.moduleName_ = "InputEventListener";
151 info.isSystem_ = true;
152 sptr<SceneSession::SpecificSessionCallback> callback = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
153 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, callback);
154 scbSystemSession_->BindKeyboardSession(session);
155 }
156
157 /**
158 * @tc.name: SetSystemSceneBlockingFocus
159 * @tc.desc: check func SetSystemSceneBlockingFocus
160 * @tc.type: FUNC
161 */
162 HWTEST_F(SCBSystemSessionTest, SetSystemSceneBlockingFocus01, TestSize.Level1)
163 {
164 ASSERT_NE(nullptr, scbSystemSession_);
165 WSError ret = scbSystemSession_->SetSystemSceneBlockingFocus(true);
166 ASSERT_EQ(WSError::WS_OK, ret);
167 }
168
169 /**
170 * @tc.name: PresentFocusIfPointDown
171 * @tc.desc: check func PresentFocusIfPointDown
172 * @tc.type: FUNC
173 */
174 HWTEST_F(SCBSystemSessionTest, PresentFocusIfPointDown01, TestSize.Level1)
175 {
176 ASSERT_NE(nullptr, scbSystemSession_);
177 scbSystemSession_->PresentFocusIfPointDown();
178 }
179
180 /**
181 * @tc.name: GetKeyboardSession
182 * @tc.desc: check func GetKeyboardSession
183 * @tc.type: FUNC
184 */
185 HWTEST_F(SCBSystemSessionTest, GetKeyboardSession01, TestSize.Level1)
186 {
187 ASSERT_NE(nullptr, scbSystemSession_);
188 scbSystemSession_->GetKeyboardSession();
189 }
190
191 /**
192 * @tc.name: ProcessPointDownSession
193 * @tc.desc: check func ProcessPointDownSession
194 * @tc.type: FUNC
195 */
196 HWTEST_F(SCBSystemSessionTest, ProcessPointDownSession, TestSize.Level1)
197 {
198 int32_t posX = 0;
199 int32_t posY = 0;
200 WSError ret = scbSystemSession_->ProcessPointDownSession(posX, posY);
201 ASSERT_EQ(WSError::WS_OK, ret);
202 }
203
204 /**
205 * @tc.name: PresentFocusIfPointDown02
206 * @tc.desc: check func PresentFocusIfPointDown
207 * @tc.type: FUNC
208 */
209 HWTEST_F(SCBSystemSessionTest, PresentFocusIfPointDown02, TestSize.Level1)
210 {
211 scbSystemSession_->isFocused_ = true;
212 auto ret = scbSystemSession_->SetFocusable(false);
213 ASSERT_EQ(WSError::WS_OK, ret);
214 scbSystemSession_->PresentFocusIfPointDown();
215 scbSystemSession_->PresentFocusIfNeed(2, 0);
216 ASSERT_EQ(scbSystemSession_->isFocused_, true);
217
218 scbSystemSession_->isFocused_ = false;
219 ret = scbSystemSession_->SetFocusable(false);
220 ASSERT_EQ(WSError::WS_OK, ret);
221 scbSystemSession_->PresentFocusIfPointDown();
222 scbSystemSession_->PresentFocusIfNeed(2, 0);
223 ASSERT_EQ(scbSystemSession_->isFocused_, false);
224
225 scbSystemSession_->isFocused_ = true;
226 ret = scbSystemSession_->SetFocusable(true);
227 ASSERT_EQ(WSError::WS_OK, ret);
228 scbSystemSession_->PresentFocusIfPointDown();
229 scbSystemSession_->PresentFocusIfNeed(2, 0);
230 ASSERT_EQ(scbSystemSession_->isFocused_, true);
231 }
232
233 /**
234 * @tc.name: PresentFocusIfNeed
235 * @tc.desc: check func PresentFocusIfNeed
236 * @tc.type: FUNC
237 */
238 HWTEST_F(SCBSystemSessionTest, PresentFocusIfNeed, TestSize.Level1)
239 {
240 int32_t pointerAction = 8;
241 scbSystemSession_->PresentFocusIfNeed(pointerAction, 0);
242 ASSERT_EQ(pointerAction, 8);
243
244 pointerAction = 100;
245 scbSystemSession_->PresentFocusIfNeed(pointerAction, 0);
246 ASSERT_EQ(pointerAction, 100);
247 }
248
249 /**
250 * @tc.name: SetSkipEventOnCastPlus01
251 * @tc.desc: check func SetSkipEventOnCastPlus
252 * @tc.type: FUNC
253 */
254 HWTEST_F(SCBSystemSessionTest, SetSkipEventOnCastPlus01, TestSize.Level1)
255 {
256 scbSystemSession_->SetSkipEventOnCastPlus(false);
257 ASSERT_EQ(false, scbSystemSession_->GetSessionProperty()->GetSkipEventOnCastPlus());
258 }
259
260 /**
261 * @tc.name: SCBSystemSession
262 * @tc.desc: check func SCBSystemSession Construction method
263 * @tc.type: FUNC
264 */
265 HWTEST_F(SCBSystemSessionTest, SCBSystemSessionConstruction001, TestSize.Level1)
266 {
267 SessionInfo info1;
268 info1.abilityName_ = "testSCBSystemSession1";
269 info1.moduleName_ = "testSCBSystemSession2";
270 info1.bundleName_ = "SCBDesktop";
271 info1.isSystem_ = true;
272 auto scbSystemSession1 = sptr<SCBSystemSession>::MakeSptr(info1, specificCallback);
273 EXPECT_NE(nullptr, scbSystemSession1);
274
275 SessionInfo info2;
276 info2.abilityName_ = "testSCBSystemSession1";
277 info2.moduleName_ = "testSCBSystemSession2";
278 info2.bundleName_ = "SCBWallpaper";
279 info2.isSystem_ = true;
280 auto scbSystemSession2 = sptr<SCBSystemSession>::MakeSptr(info2, specificCallback);
281 EXPECT_NE(nullptr, scbSystemSession2);
282
283 SessionInfo info3;
284 info3.abilityName_ = "testSCBSystemSession1";
285 info3.moduleName_ = "testSCBSystemSession2";
286 info3.bundleName_ = "SCBScreenLock";
287 info3.isSystem_ = true;
288 auto scbSystemSession3 = sptr<SCBSystemSession>::MakeSptr(info3, specificCallback);
289 EXPECT_NE(nullptr, scbSystemSession3);
290
291 SessionInfo info4;
292 info4.abilityName_ = "testSCBSystemSession1";
293 info4.moduleName_ = "testSCBSystemSession2";
294 info4.bundleName_ = "SCBNegativeScreen";
295 info4.isSystem_ = true;
296 auto scbSystemSession4 = sptr<SCBSystemSession>::MakeSptr(info4, specificCallback);
297 EXPECT_NE(nullptr, scbSystemSession4);
298
299 SessionInfo info5;
300 info5.abilityName_ = "testSCBSystemSession1";
301 info5.moduleName_ = "testSCBSystemSession2";
302 info5.bundleName_ = "SCBDropdownPanel";
303 info5.isSystem_ = true;
304 auto scbSystemSession5 = sptr<SCBSystemSession>::MakeSptr(info5, specificCallback);
305 EXPECT_NE(nullptr, scbSystemSession5);
306 }
307
308 /**
309 * @tc.name: SCBSystemSession
310 * @tc.desc: check func SCBSystemSession Construction method
311 * @tc.type: FUNC
312 */
313 HWTEST_F(SCBSystemSessionTest, SCBSystemSessionConstruction002, TestSize.Level1)
314 {
315 SessionInfo info6;
316 info6.abilityName_ = "testSCBSystemSession1";
317 info6.moduleName_ = "testSCBSystemSession2";
318 info6.bundleName_ = "SCBVolumePanel";
319 info6.isSystem_ = true;
320 auto scbSystemSession6 = sptr<SCBSystemSession>::MakeSptr(info6, specificCallback);
321 EXPECT_NE(nullptr, scbSystemSession6);
322
323 SessionInfo info7;
324 info7.abilityName_ = "testSCBSystemSession1";
325 info7.moduleName_ = "testSCBSystemSession2";
326 info7.bundleName_ = "SCBBannerNotification";
327 info7.isSystem_ = true;
328 auto scbSystemSession7 = sptr<SCBSystemSession>::MakeSptr(info7, specificCallback);
329 EXPECT_NE(nullptr, scbSystemSession7);
330
331 SessionInfo info8;
332 info8.abilityName_ = "testSCBSystemSession1";
333 info8.moduleName_ = "testSCBSystemSession2";
334 info8.bundleName_ = "SCBGestureBack";
335 info8.isSystem_ = true;
336 auto scbSystemSession8 = sptr<SCBSystemSession>::MakeSptr(info8, specificCallback);
337 EXPECT_NE(nullptr, scbSystemSession8);
338 }
339 } // namespace
340 } // namespace Rosen
341 } // namespace OHOS