• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <pointer_event.h>
18 
19 #include "display_manager.h"
20 #include "input_event.h"
21 #include "key_event.h"
22 
23 
24 #include "screen_manager.h"
25 #include "screen_session_manager_client/include/screen_session_manager_client.h"
26 #include "session/host/include/sub_session.h"
27 #include "session/host/include/main_session.h"
28 #include "session/host/include/scene_session.h"
29 #include "session/host/include/system_session.h"
30 #include <ui/rs_surface_node.h>
31 #include "wm_common.h"
32 
33 using namespace testing;
34 using namespace testing::ext;
35 namespace OHOS {
36 namespace Rosen {
37 
38 class SceneSessionTest6 : public testing::Test {
39 public:
40     static void SetUpTestCase();
41     static void TearDownTestCase();
42     void SetUp() override;
43     void TearDown() override;
44 };
45 
SetUpTestCase()46 void SceneSessionTest6::SetUpTestCase()
47 {
48 }
49 
TearDownTestCase()50 void SceneSessionTest6::TearDownTestCase()
51 {
52 }
53 
SetUp()54 void SceneSessionTest6::SetUp()
55 {
56 }
57 
TearDown()58 void SceneSessionTest6::TearDown()
59 {
60 }
61 
62 namespace {
63 
64 /**
65  * @tc.name: RegisterNotifySurfaceBoundsChangeFunc
66  * @tc.desc: RegisterNotifySurfaceBoundsChangeFunc
67  * @tc.type: FUNC
68  */
69 HWTEST_F(SceneSessionTest6, RegisterNotifySurfaceBoundsChangeFunc01, Function | SmallTest | Level1)
70 {
71     SessionInfo info;
72     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
73     constexpr int sessionId = 10001;
74     sceneSession->RegisterNotifySurfaceBoundsChangeFunc(sessionId, nullptr);
75     ASSERT_EQ(nullptr, sceneSession->notifySurfaceBoundsChangeFuncMap_[sessionId]);
76 
__anon694166e00202(const WSRect& rect, bool isGlobal, bool needFlush) 77     auto task = [](const WSRect& rect, bool isGlobal, bool needFlush) {};
78     sceneSession->RegisterNotifySurfaceBoundsChangeFunc(sessionId, std::move(task));
79     ASSERT_NE(nullptr, sceneSession->notifySurfaceBoundsChangeFuncMap_[sessionId]);
80 
81     sceneSession->UnregisterNotifySurfaceBoundsChangeFunc(sessionId);
82     ASSERT_EQ(nullptr, sceneSession->notifySurfaceBoundsChangeFuncMap_[sessionId]);
83 }
84 
85 /**
86  * @tc.name: NotifyUpdateGravity
87  * @tc.desc: NotifyUpdateGravity
88  * @tc.type: FUNC
89  */
90 HWTEST_F(SceneSessionTest6, NotifyUpdateGravity01, Function | SmallTest | Level1)
91 {
92     SessionInfo info;
93     sptr<SceneSession> subSession = sptr<SceneSession>::MakeSptr(info, nullptr);
94     int32_t subSessionId = subSession->GetPersistentId();
95 
96     sptr<MainSession> mainSession = sptr<MainSession>::MakeSptr(info, nullptr);
97     ASSERT_NE(nullptr, mainSession);
98 
99     constexpr int sessionId = 10001;
__anon694166e00302(const WSRect& rect, bool isGlobal, bool needFlush) 100     auto task = [](const WSRect& rect, bool isGlobal, bool needFlush) {};
101     mainSession->RegisterNotifySurfaceBoundsChangeFunc(sessionId, std::move(task));
102     mainSession->NotifyUpdateGravity();
103     ASSERT_NE(nullptr, mainSession->notifySurfaceBoundsChangeFuncMap_[sessionId]);
104 
105     subSession->isFollowParentLayout_ = false;
106     mainSession->RegisterNotifySurfaceBoundsChangeFunc(subSessionId, std::move(task));
107     mainSession->NotifyUpdateGravity();
108     ASSERT_NE(nullptr, mainSession->notifySurfaceBoundsChangeFuncMap_[subSessionId]);
109 
110     subSession->isFollowParentLayout_ = true;
111     mainSession->NotifyUpdateGravity();
112     ASSERT_NE(nullptr, mainSession->notifySurfaceBoundsChangeFuncMap_[subSessionId]);
113 
114     sptr<MoveDragController> followController =
115         sptr<MoveDragController>::MakeSptr(subSessionId, subSession->GetWindowType());
116     ASSERT_NE(nullptr, followController);
117     struct RSSurfaceNodeConfig config;
118     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
119     ASSERT_NE(nullptr, surfaceNode);
120     subSession->surfaceNode_ = nullptr;
121     subSession->moveDragController_ = nullptr;
122     mainSession->NotifyUpdateGravity();
123     ASSERT_NE(nullptr, mainSession->notifySurfaceBoundsChangeFuncMap_[subSessionId]);
124 
125     subSession->surfaceNode_ = surfaceNode;
126     mainSession->NotifyUpdateGravity();
127     ASSERT_NE(nullptr, mainSession->notifySurfaceBoundsChangeFuncMap_[subSessionId]);
128 
129     subSession->moveDragController_ = followController;
130     mainSession->NotifyUpdateGravity();
131     ASSERT_NE(nullptr, mainSession->notifySurfaceBoundsChangeFuncMap_[subSessionId]);
132 }
133 
134 /**
135  * @tc.name: GetSceneSessionById
136  * @tc.desc: GetSceneSessionById
137  * @tc.type: FUNC
138  */
139 HWTEST_F(SceneSessionTest6, GetSceneSessionById01, Function | SmallTest | Level1)
140 {
141     SessionInfo info;
142     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
143     sptr<SceneSession> findSession = sptr<SceneSession>::MakeSptr(info, nullptr);
144 
145     sceneSession->specificCallback_ = nullptr;
146     sptr<SceneSession> ret = sceneSession->GetSceneSessionById(findSession->GetPersistentId());
147     ASSERT_EQ(nullptr, ret);
148 
149     sptr<SceneSession::SpecificSessionCallback> callBack = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
150     ASSERT_NE(nullptr, callBack);
151     sceneSession->specificCallback_ = callBack;
152     ret = sceneSession->GetSceneSessionById(findSession->GetPersistentId());
153     ASSERT_EQ(nullptr, ret);
154 
__anon694166e00402(int32_t persistentId) 155     auto task = [&findSession](int32_t persistentId) {
156         return findSession;
157     };
158     callBack->onGetSceneSessionByIdCallback_ = task;
159     ret = sceneSession->GetSceneSessionById(findSession->GetPersistentId());
160     ASSERT_EQ(findSession->GetPersistentId(), ret->GetPersistentId());
161 }
162 
163 /**
164  * @tc.name: SetFollowParentRectFunc
165  * @tc.desc: SetFollowParentRectFunc
166  * @tc.type: FUNC
167  */
168 HWTEST_F(SceneSessionTest6, SetFollowParentRectFunc01, Function | SmallTest | Level1)
169 {
170     SessionInfo info;
171     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
172 
173     sceneSession->SetFollowParentRectFunc(nullptr);
174     ASSERT_EQ(nullptr, sceneSession->followParentRectFunc_);
175 
__anon694166e00502(bool isFollow) 176     NotifyFollowParentRectFunc func = [](bool isFollow) {};
177     sceneSession->SetFollowParentRectFunc(std::move(func));
178     ASSERT_NE(nullptr, sceneSession->followParentRectFunc_);
179 }
180 
181 /**
182  * @tc.name: SetFollowParentWindowLayoutEnabled
183  * @tc.desc: SetFollowParentWindowLayoutEnabled01, check the param
184  * @tc.type: FUNC
185  */
186 HWTEST_F(SceneSessionTest6, SetFollowParentWindowLayoutEnabled01, Function | SmallTest | Level1)
187 {
188     SessionInfo info;
189     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
190 
191     WSError ret = sceneSession->SetFollowParentWindowLayoutEnabled(true);
192     ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
193 
194     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
195     ASSERT_NE(nullptr, property);
196     sceneSession->property_ = property;
197     property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
198     ret = sceneSession->SetFollowParentWindowLayoutEnabled(true);
199     ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
200 
201     property->subWindowLevel_ = 100;
202     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
203     ret = sceneSession->SetFollowParentWindowLayoutEnabled(true);
204     ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
205 
206     property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
207     ret = sceneSession->SetFollowParentWindowLayoutEnabled(true);
208     ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
209 
210     property->subWindowLevel_ = 1;
211     ret = sceneSession->SetFollowParentWindowLayoutEnabled(true);
212     ASSERT_EQ(ret, WSError::WS_OK);
213 }
214 
215 /**
216  * @tc.name: SetFollowParentWindowLayoutEnabled
217  * @tc.desc: SetFollowParentWindowLayoutEnabled02
218  * @tc.type: FUNC
219  */
220 HWTEST_F(SceneSessionTest6, SetFollowParentWindowLayoutEnabled02, Function | SmallTest | Level1)
221 {
222     SessionInfo info;
223     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
224     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
225     ASSERT_NE(nullptr, property);
226     property->subWindowLevel_ = 1;
227     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
228     sceneSession->property_ = property;
229     // test set isFollowParentLayout_
230     sceneSession->isFollowParentLayout_ = false;
231     sceneSession->SetFollowParentWindowLayoutEnabled(true);
232     ASSERT_TRUE(sceneSession->isFollowParentLayout_);
233     //test after set flag, call func
234     bool isCall = false;
__anon694166e00602(bool isFollow) 235     NotifyFollowParentRectFunc func = [&isCall](bool isFollow) {
236         isCall = true;
237     };
238     sceneSession->SetFollowParentRectFunc(std::move(func));
239     ASSERT_NE(nullptr, sceneSession->followParentRectFunc_);
240     sceneSession->SetFollowParentWindowLayoutEnabled(true);
241     ASSERT_TRUE(isCall);
242 }
243 
244 /**
245  * @tc.name: SetFollowParentWindowLayoutEnabled
246  * @tc.desc: SetFollowParentWindowLayoutEnabled03, test register callback
247  * @tc.type: FUNC
248  */
249 HWTEST_F(SceneSessionTest6, SetFollowParentWindowLayoutEnabled03, Function | SmallTest | Level1)
250 {
251     SessionInfo info;
252     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
253 
254     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
255     property->subWindowLevel_ = 1;
256     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
257     sceneSession->property_ = property;
258 
259     sptr<MainSession> parentSession = sptr<MainSession>::MakeSptr(info, nullptr);
260     ASSERT_NE(nullptr, parentSession);
261 
262     sceneSession->parentSession_ = parentSession;
263     sceneSession->SetFollowParentWindowLayoutEnabled(true);
264     ASSERT_NE(nullptr, parentSession->notifySurfaceBoundsChangeFuncMap_[sceneSession->GetPersistentId()]);
265     WSRect rect;
266     parentSession->NotifySubAndDialogFollowRectChange(rect, false, false);
267 
268     sceneSession->SetFollowParentWindowLayoutEnabled(false);
269     ASSERT_EQ(nullptr, parentSession->notifySurfaceBoundsChangeFuncMap_[sceneSession->GetPersistentId()]);
270 }
271 
272 /**
273  * @tc.name: GetSystemAvoidArea
274  * @tc.desc: GetSystemAvoidArea function
275  * @tc.type: FUNC
276  */
277  HWTEST_F(SceneSessionTest6, GetSystemAvoidArea, Function | SmallTest | Level1)
278  {
279     SessionInfo info;
280     info.abilityName_ = "GetSystemAvoidArea";
281     info.bundleName_ = "GetSystemAvoidArea";
282 
283     sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
284     ASSERT_NE(session, nullptr);
285     ASSERT_NE(session->GetSessionProperty(), nullptr);
286     session->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
287     EXPECT_EQ(WindowMode::WINDOW_MODE_FLOATING, session->GetSessionProperty()->GetWindowMode());
288     info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
289 
290     SystemSessionConfig systemConfig;
291     systemConfig.windowUIType_ = WindowUIType::PHONE_WINDOW;
292     session->SetSystemConfig(systemConfig);
293     ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
294     session->GetSessionProperty()->SetDisplayId(2025);
295     session->SetIsMidScene(false);
296     EXPECT_EQ(session->GetIsMidScene(), false);
297 
298     WSRect rect;
299     AvoidArea avoidArea;
300     session->GetSystemAvoidArea(rect, avoidArea);
301     int32_t height = session->GetStatusBarHeight();
302     EXPECT_EQ(height, avoidArea.topRect_.height_);
303 }
304 } // namespace
305 } // namespace Rosen
306 } // namespace OHOS