• 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 <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 {
43 }
44 
TearDownTestCase()45 void SCBSystemSessionTest::TearDownTestCase()
46 {
47 }
48 
SetUp()49 void SCBSystemSessionTest::SetUp()
50 {
51     SessionInfo info;
52     info.abilityName_ = "testSCBSystemSession1";
53     info.moduleName_ = "testSCBSystemSession2";
54     info.bundleName_ = "testSCBSystemSession3";
55     scbSystemSession_ = sptr<SCBSystemSession>::MakeSptr(info, specificCallback);
56     EXPECT_NE(nullptr, scbSystemSession_);
57 }
58 
TearDown()59 void SCBSystemSessionTest::TearDown()
60 {
61     scbSystemSession_ = nullptr;
62 }
63 
64 namespace {
65 /**
66  * @tc.name: TransferKeyEvent01
67  * @tc.desc: check func TransferKeyEvent
68  * @tc.type: FUNC
69  */
70 HWTEST_F(SCBSystemSessionTest, TransferKeyEvent01, Function | SmallTest | Level1)
71 {
72     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, scbSystemSession_->TransferKeyEvent(nullptr));
73 }
74 
75 /**
76  * @tc.name: TransferKeyEvent02
77  * @tc.desc: check func TransferKeyEvent
78  * @tc.type: FUNC
79  */
80 HWTEST_F(SCBSystemSessionTest, TransferKeyEvent02, Function | SmallTest | Level1)
81 {
82     scbSystemSession_->state_ = SessionState::STATE_CONNECT;
83     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
84     ASSERT_NE(keyEvent, nullptr);
85     scbSystemSession_->windowEventChannel_ = nullptr;
86 
87     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, scbSystemSession_->TransferKeyEvent(keyEvent));
88 }
89 
90 /**
91  * @tc.name: UpdateFocus01
92  * @tc.desc: check func UpdateFocus
93  * @tc.type: FUNC
94  */
95 HWTEST_F(SCBSystemSessionTest, UpdateFocus01, Function | SmallTest | Level1)
96 {
97     bool isFocused = scbSystemSession_->isFocused_;
98 
99     ASSERT_EQ(WSError::WS_DO_NOTHING, scbSystemSession_->UpdateFocus(isFocused));
100 }
101 
102 /**
103  * @tc.name: UpdateFocus02
104  * @tc.desc: check func UpdateFocus
105  * @tc.type: FUNC
106  */
107 HWTEST_F(SCBSystemSessionTest, UpdateFocus02, Function | SmallTest | Level1)
108 {
109     scbSystemSession_->isFocused_ = true;
110     bool isFocused = scbSystemSession_->isFocused_;
111 
112     ASSERT_EQ(WSError::WS_OK, scbSystemSession_->UpdateFocus(!isFocused));
113 
114     scbSystemSession_->isFocused_ = false;
115     isFocused = scbSystemSession_->isFocused_;
116 
117     ASSERT_EQ(WSError::WS_OK, scbSystemSession_->UpdateFocus(!isFocused));
118 }
119 
120 /**
121  * @tc.name: BindKeyboardSession01
122  * @tc.desc: check func BindKeyboardSession
123  * @tc.type: FUNC
124  */
125 HWTEST_F(SCBSystemSessionTest, BindKeyboardSession01, Function | SmallTest | Level3)
126 {
127     ASSERT_NE(nullptr, scbSystemSession_);
128     scbSystemSession_->BindKeyboardSession(nullptr);
129 }
130 
131 /**
132  * @tc.name: BindKeyboardSession02
133  * @tc.desc: check func BindKeyboardSession
134  * @tc.type: FUNC
135  */
136 HWTEST_F(SCBSystemSessionTest, BindKeyboardSession02, Function | SmallTest | Level3)
137 {
138     ASSERT_NE(nullptr, scbSystemSession_);
139     SessionInfo info;
140     info.bundleName_ = "IntentionEventManager";
141     info.moduleName_ = "InputEventListener";
142     info.isSystem_ = true;
143     sptr<SceneSession::SpecificSessionCallback> callback =
144         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
145     sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, callback);
146     scbSystemSession_->BindKeyboardSession(session);
147 }
148 
149 /**
150  * @tc.name: SetSystemSceneBlockingFocus
151  * @tc.desc: check func SetSystemSceneBlockingFocus
152  * @tc.type: FUNC
153  */
154 HWTEST_F(SCBSystemSessionTest, SetSystemSceneBlockingFocus01, Function | SmallTest | Level3)
155 {
156     ASSERT_NE(nullptr, scbSystemSession_);
157     WSError ret = scbSystemSession_->SetSystemSceneBlockingFocus(true);
158     ASSERT_EQ(WSError::WS_OK, ret);
159 }
160 
161 /**
162  * @tc.name: PresentFocusIfPointDown
163  * @tc.desc: check func PresentFocusIfPointDown
164  * @tc.type: FUNC
165  */
166 HWTEST_F(SCBSystemSessionTest, PresentFocusIfPointDown01, Function | SmallTest | Level3)
167 {
168     ASSERT_NE(nullptr, scbSystemSession_);
169     scbSystemSession_->PresentFocusIfPointDown();
170 }
171 
172 /**
173  * @tc.name: GetKeyboardSession
174  * @tc.desc: check func GetKeyboardSession
175  * @tc.type: FUNC
176  */
177 HWTEST_F(SCBSystemSessionTest, GetKeyboardSession01, Function | SmallTest | Level3)
178 {
179     ASSERT_NE(nullptr, scbSystemSession_);
180     scbSystemSession_->GetKeyboardSession();
181 }
182 
183 /**
184  * @tc.name: ProcessPointDownSession
185  * @tc.desc: check func ProcessPointDownSession
186  * @tc.type: FUNC
187  */
188 HWTEST_F(SCBSystemSessionTest, ProcessPointDownSession, Function | SmallTest | Level3)
189 {
190     int32_t posX = 0;
191     int32_t posY = 0;
192     WSError ret = scbSystemSession_->ProcessPointDownSession(posX, posY);
193     ASSERT_EQ(WSError::WS_OK, ret);
194 }
195 
196 /**
197  * @tc.name: PresentFocusIfPointDown02
198  * @tc.desc: check func PresentFocusIfPointDown
199  * @tc.type: FUNC
200  */
201 HWTEST_F(SCBSystemSessionTest, PresentFocusIfPointDown02, Function | SmallTest | Level3)
202 {
203     scbSystemSession_->isFocused_ = true;
204     auto ret = scbSystemSession_->SetFocusable(false);
205     ASSERT_EQ(WSError::WS_OK, ret);
206     scbSystemSession_->PresentFocusIfPointDown();
207     scbSystemSession_->PresentFoucusIfNeed(2);
208     ASSERT_EQ(scbSystemSession_->isFocused_, true);
209 
210     scbSystemSession_->isFocused_ = false;
211     ret = scbSystemSession_->SetFocusable(false);
212     ASSERT_EQ(WSError::WS_OK, ret);
213     scbSystemSession_->PresentFocusIfPointDown();
214     scbSystemSession_->PresentFoucusIfNeed(2);
215     ASSERT_EQ(scbSystemSession_->isFocused_, false);
216 
217     scbSystemSession_->isFocused_ = true;
218     ret = scbSystemSession_->SetFocusable(true);
219     ASSERT_EQ(WSError::WS_OK, ret);
220     scbSystemSession_->PresentFocusIfPointDown();
221     scbSystemSession_->PresentFoucusIfNeed(2);
222     ASSERT_EQ(scbSystemSession_->isFocused_, true);
223 }
224 
225 /**
226  * @tc.name: PresentFoucusIfNeed
227  * @tc.desc: check func PresentFoucusIfNeed
228  * @tc.type: FUNC
229  */
230 HWTEST_F(SCBSystemSessionTest, PresentFoucusIfNeed, Function | SmallTest | Level3)
231 {
232     int32_t pointerAction = 8;
233     scbSystemSession_->PresentFoucusIfNeed(pointerAction);
234     ASSERT_EQ(pointerAction, 8);
235 
236     pointerAction = 100;
237     scbSystemSession_->PresentFoucusIfNeed(pointerAction);
238     ASSERT_EQ(pointerAction, 100);
239 }
240 } //namespace
241 } //namespace Rosen
242 } //namespace OHOS