• 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 
18 #include "interfaces/include/ws_common.h"
19 #include "iremote_object_mocker.h"
20 #include "session_manager/include/scene_session_manager.h"
21 #include "session_info.h"
22 #include "session/host/include/scene_session.h"
23 #include "session_manager.h"
24 #include "screen_session_manager/include/screen_session_manager_client.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Rosen {
31 
32 class SceneSessionManagerTest10 : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp() override;
37     void TearDown() override;
38 
39     static sptr<SceneSessionManager> ssm_;
40 private:
41     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
42 };
43 
44 sptr<SceneSessionManager> SceneSessionManagerTest10::ssm_ = nullptr;
45 
NotifyRecoverSceneSessionFuncTest(const sptr<SceneSession> & session,const SessionInfo & sessionInfo)46 void NotifyRecoverSceneSessionFuncTest(const sptr<SceneSession>& session, const SessionInfo& sessionInfo)
47 {
48 }
49 
TraverseFuncTest(const sptr<SceneSession> & session)50 bool TraverseFuncTest(const sptr<SceneSession>& session)
51 {
52     return true;
53 }
54 
WindowChangedFuncTest(int32_t persistentId,WindowUpdateType type)55 void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)
56 {
57 }
58 
ProcessStatusBarEnabledChangeFuncTest(bool enable)59 void ProcessStatusBarEnabledChangeFuncTest(bool enable)
60 {
61 }
62 
DumpRootSceneElementInfoFuncTest(const std::vector<std::string> & params,std::vector<std::string> & infos)63 void DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)
64 {
65 }
66 
SetUpTestCase()67 void SceneSessionManagerTest10::SetUpTestCase()
68 {
69     ssm_ = &SceneSessionManager::GetInstance();
70 }
71 
TearDownTestCase()72 void SceneSessionManagerTest10::TearDownTestCase()
73 {
74     ssm_ = nullptr;
75 }
76 
SetUp()77 void SceneSessionManagerTest10::SetUp()
78 {
79 }
80 
TearDown()81 void SceneSessionManagerTest10::TearDown()
82 {
83     usleep(WAIT_SYNC_IN_NS);
84 }
85 
86 namespace {
87 /**
88  * @tc.name: RequestSceneSessionDestructionInner
89  * @tc.desc: RequestSceneSessionDestructionInner
90  * @tc.type: FUNC
91  */
92 HWTEST_F(SceneSessionManagerTest10, RequestSceneSessionDestructionInner, Function | SmallTest | Level3)
93 {
94     ASSERT_NE(ssm_, nullptr);
95 
96     SessionInfo info;
97     sptr<SceneSession::SpecificSessionCallback> specificCallback = nullptr;
98     sptr<SceneSession> scnSession = new (std::nothrow) SceneSession(info, specificCallback);
99     sptr<AAFwk::SessionInfo> scnSessionInfo = new AAFwk::SessionInfo();
100     bool needRemoveSession = true;
101     bool isForceClean = true;
102 
103     SessionInfo sessionInfo;
104     sessionInfo.collaboratorType_ = CollaboratorType::RESERVE_TYPE;
105     ssm_->RequestSceneSessionDestructionInner(scnSession, scnSessionInfo, needRemoveSession, isForceClean);
106 
107     needRemoveSession = false;
108     isForceClean = false;
109     sessionInfo.collaboratorType_ = CollaboratorType::DEFAULT_TYPE;
110     sessionInfo.want = std::make_shared<AAFwk::Want>();
111     ssm_->listenerController_ = std::make_shared<SessionListenerController>();
112     ssm_->RequestSceneSessionDestructionInner(scnSession, scnSessionInfo, needRemoveSession, isForceClean);
113 }
114 
115 /**
116  * @tc.name: RegisterWindowManagerAgent
117  * @tc.desc: RegisterWindowManagerAgent
118  * @tc.type: FUNC
119  */
120 HWTEST_F(SceneSessionManagerTest10, RegisterWindowManagerAgent01, Function | SmallTest | Level3)
121 {
122     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR;
123     sptr<IWindowManagerAgent> windowManagerAgent;
124     ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
125 
126     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED;
127     ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
128 
129     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG;
130     ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
131 
132     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE;
133     ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
134 
135     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY;
136     ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
137 
138     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE;
139     ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
140 
141     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM;
142     ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
143 
144     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
145     ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
146 
147     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE;
148     ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
149 
150     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT;
151     ASSERT_EQ(windowManagerAgent, nullptr);
152     ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
153 }
154 
155 /**
156  * @tc.name: UpdateRotateAnimationConfig
157  * @tc.desc: UpdateRotateAnimationConfig
158  * @tc.type: FUNC
159  */
160 HWTEST_F(SceneSessionManagerTest10, UpdateRotateAnimationConfig, Function | SmallTest | Level3)
161 {
162     ASSERT_NE(ssm_, nullptr);
163     RotateAnimationConfig config = { 400 };
164     ssm_->UpdateRotateAnimationConfig(config);
165     usleep(WAIT_SYNC_IN_NS);
166     ASSERT_EQ(ssm_->rotateAnimationConfig_.duration_, 400);
167 
168     config.duration_ = 600;
169     ssm_->UpdateRotateAnimationConfig(config);
170     usleep(WAIT_SYNC_IN_NS);
171     ASSERT_EQ(ssm_->rotateAnimationConfig_.duration_, 600);
172 }
173 
174 /**
175  * @tc.name: RegisterAcquireRotateAnimationConfigFunc
176  * @tc.desc: RegisterAcquireRotateAnimationConfigFunc
177  * @tc.type: FUNC
178  */
179 HWTEST_F(SceneSessionManagerTest10, RegisterAcquireRotateAnimationConfigFunc, Function | SmallTest | Level3)
180 {
181     ASSERT_NE(ssm_, nullptr);
182     SessionInfo sessionInfo;
183     sessionInfo.bundleName_ = "bundleName";
184     sessionInfo.persistentId_ = 1;
185     sessionInfo.isSystem_ = false;
186     sessionInfo.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
187     ASSERT_NE(sessionInfo.abilityInfo, nullptr);
188     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
189     ASSERT_NE(sceneSession, nullptr);
190     sceneSession->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("bundleName", 1);
191     ASSERT_NE(sceneSession->scenePersistence_, nullptr);
192     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
193     ssm_->RegisterAcquireRotateAnimationConfigFunc(sceneSession);
194     WSRect rect({1, 1, 1, 1});
195     SizeChangeReason reason = SizeChangeReason::ROTATION;
196     WSError result = sceneSession->UpdateRect(rect, reason, "SceneSessionManagerTest10");
197     ASSERT_EQ(result, WSError::WS_OK);
198 }
199 
200 /**
201  * @tc.name: CheckLastFocusedAppSessionFocus
202  * @tc.desc: CheckLastFocusedAppSessionFocus
203  * @tc.type: FUNC
204  */
205 HWTEST_F(SceneSessionManagerTest10, CheckLastFocusedAppSessionFocus, Function | SmallTest | Level3)
206 {
207     ASSERT_NE(ssm_, nullptr);
208 
209     SessionInfo info1;
210     info1.abilityName_ = "focusedSession";
211     info1.bundleName_ = "focusedSession";
212     info1.windowType_ = 1;
213     sptr<SceneSession> focusedSession = new (std::nothrow) SceneSession(info1, nullptr);
214     ASSERT_NE(focusedSession, nullptr);
215 
216     SessionInfo info2;
217     info2.abilityName_ = "nextSession";
218     info2.bundleName_ = "nextSession";
219     info2.windowType_ = 1;
220     sptr<SceneSession> nextSession = new (std::nothrow) SceneSession(info2, nullptr);
221     ASSERT_NE(nextSession, nullptr);
222 
223     ssm_->lastFocusedAppSessionId_ = nextSession->GetPersistentId();
224     ASSERT_EQ(false, ssm_->CheckLastFocusedAppSessionFocus(focusedSession, nextSession));
225 
226     ssm_->lastFocusedAppSessionId_ = 124;
227     focusedSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
228     ASSERT_EQ(false, ssm_->CheckLastFocusedAppSessionFocus(focusedSession, nextSession));
229 
230     nextSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
231     ssm_->CheckLastFocusedAppSessionFocus(focusedSession, nextSession);
232     ASSERT_EQ(0, ssm_->lastFocusedAppSessionId_);
233 }
234 
235 /**
236  * @tc.name: ProcessFocusZOrderChange
237  * @tc.desc: ProcessFocusZOrderChange
238  * @tc.type: FUNC
239  */
240 HWTEST_F(SceneSessionManagerTest10, ProcessFocusZOrderChange, Function | SmallTest | Level3)
241 {
242     ssm_->sceneSessionMap_.clear();
243     ssm_->ProcessFocusZOrderChange(10);
244     ssm_->systemConfig_.uiType_ = "pc";
245     ssm_->ProcessFocusZOrderChange(97);
246 
247     ssm_->systemConfig_.uiType_ = "phone";
248     ssm_->ProcessFocusZOrderChange(97);
249 
250     SessionInfo sessionInfo;
251     sessionInfo.bundleName_ = "focusedSession";
252     sessionInfo.abilityName_ = "focusedSession";
253     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
254     ASSERT_NE(nullptr, sceneSession);
255     ssm_->sceneSessionMap_.emplace(1, sceneSession);
256     ssm_->focusedSessionId_ = 1;
257     ssm_->ProcessFocusZOrderChange(97);
258 
259     sceneSession->lastZOrder_ = 2203;
260     sceneSession->zOrder_ = 101;
261     ssm_->ProcessFocusZOrderChange(97);
262 
263     SessionInfo sessionInfo1;
264     sessionInfo1.bundleName_ = "voiceInteractionSession";
265     sessionInfo1.abilityName_ = "voiceInteractionSession";
266     sessionInfo1.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_VOICE_INTERACTION);
267     sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
268     ASSERT_NE(nullptr, sceneSession1);
269     sceneSession1->zOrder_ = 2109;
270     ssm_->sceneSessionMap_.emplace(2, sceneSession1);
271 
272     sceneSession->lastZOrder_ = 103;
273     sceneSession->zOrder_ = 101;
274     ssm_->ProcessFocusZOrderChange(97);
275 
276     sceneSession->lastZOrder_ = 2203;
277     sceneSession->zOrder_ = 101;
278     ssm_->ProcessFocusZOrderChange(97);
279 }
280 
281 /**
282  * @tc.name: NotifyVisibleChange
283  * @tc.desc: test NotifyVisibleChange
284  * @tc.type: FUNC
285  */
286 HWTEST_F(SceneSessionManagerTest10, NotifyVisibleChange, Function | SmallTest | Level3)
287 {
288     SessionInfo info;
289     info.abilityName_ = "test";
290     info.bundleName_ = "test";
291     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
292     ASSERT_NE(nullptr, sceneSession);
293 
294     ASSERT_FALSE(ssm_->NotifyVisibleChange(sceneSession->GetPersistentId()));
295     ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
296     ASSERT_TRUE(ssm_->NotifyVisibleChange(sceneSession->GetPersistentId()));
297 
298     ssm_->sceneSessionMap_.erase(sceneSession->GetPersistentId());
299 }
300 
301 /**
302  * @tc.name: IsInSecondaryScreen
303  * @tc.desc: test IsInSecondaryScreen
304  * @tc.type: FUNC
305  */
306 HWTEST_F(SceneSessionManagerTest10, IsInSecondaryScreen, Function | SmallTest | Level3)
307 {
308     SessionInfo info;
309     info.abilityName_ = "test";
310     info.bundleName_ = "test";
311     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
312     ASSERT_NE(nullptr, sceneSession);
313     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
314     ASSERT_NE(nullptr, property);
315     DisplayId displayId = ScreenSessionManagerClient::GetInstance().GetDefaultScreenId();
316     property->SetDisplayId(displayId);
317     sceneSession->SetSessionProperty(property);
318     ASSERT_EQ(ssm_->IsInSecondaryScreen(sceneSession), false);
319 
320     displayId = 5;
321     property->SetDisplayId(displayId);
322     sceneSession->SetSessionProperty(property);
323     ASSERT_EQ(ssm_->IsInSecondaryScreen(sceneSession), true);
324 }
325 
326 /**
327  * @tc.name: ProcessUpdateLastFocusedAppId
328  * @tc.desc: test ProcessUpdateLastFocusedAppId
329  * @tc.type: FUNC
330  */
331 HWTEST_F(SceneSessionManagerTest10, ProcessUpdateLastFocusedAppId, Function | SmallTest | Level1)
332 {
333     ssm_->sceneSessionMap_.clear();
334     std::vector<uint32_t> zOrderList;
335     ssm_->lastFocusedAppSessionId_ = INVALID_SESSION_ID;
336     ssm_->ProcessUpdateLastFocusedAppId(zOrderList);
337 
338     SessionInfo sessionInfo;
339     sessionInfo.bundleName_ = "lastFocusedAppSession";
340     sessionInfo.abilityName_ = "lastFocusedAppSession";
341     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
342     ssm_->sceneSessionMap_.emplace(1, sceneSession);
343     ssm_->lastFocusedAppSessionId_ = 1;
344     sceneSession->zOrder_ = 101;
345 
346     ssm_->ProcessUpdateLastFocusedAppId(zOrderList);
347     ASSERT_EQ(1, ssm_->lastFocusedAppSessionId_);
348 
349     zOrderList.push_back(103);
350     ssm_->ProcessUpdateLastFocusedAppId(zOrderList);
351     ASSERT_EQ(INVALID_SESSION_ID, ssm_->lastFocusedAppSessionId_);
352 }
353 }  // namespace
354 }
355 }