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_client/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 SceneSessionManagerAnimationTest : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp() override;
37 void TearDown() override;
38 void InitTestSceneSession(DisplayId displayId, int32_t windowId, int32_t zOrder, bool visible, WSRect rect);
39 void InitTestSceneSessionForListWindowInfo();
40
41 static sptr<SceneSessionManager> ssm_;
42
43 private:
44 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
45 };
46
47 sptr<SceneSessionManager> SceneSessionManagerAnimationTest::ssm_ = nullptr;
48
NotifyRecoverSceneSessionFuncTest(const sptr<SceneSession> & session,const SessionInfo & sessionInfo)49 void NotifyRecoverSceneSessionFuncTest(const sptr<SceneSession>& session, const SessionInfo& sessionInfo) {}
50
TraverseFuncTest(const sptr<SceneSession> & session)51 bool TraverseFuncTest(const sptr<SceneSession>& session)
52 {
53 return true;
54 }
55
WindowChangedFuncTest(int32_t persistentId,WindowUpdateType type)56 void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type) {}
57
ProcessStatusBarEnabledChangeFuncTest(bool enable)58 void ProcessStatusBarEnabledChangeFuncTest(bool enable) {}
59
SetUpTestCase()60 void SceneSessionManagerAnimationTest::SetUpTestCase()
61 {
62 ssm_ = &SceneSessionManager::GetInstance();
63 }
64
TearDownTestCase()65 void SceneSessionManagerAnimationTest::TearDownTestCase()
66 {
67 ssm_ = nullptr;
68 }
69
SetUp()70 void SceneSessionManagerAnimationTest::SetUp() {}
71
TearDown()72 void SceneSessionManagerAnimationTest::TearDown()
73 {
74 usleep(WAIT_SYNC_IN_NS);
75 }
76
InitTestSceneSession(DisplayId displayId,int32_t windowId,int32_t zOrder,bool visible,WSRect rect)77 void SceneSessionManagerAnimationTest::InitTestSceneSession(DisplayId displayId,
78 int32_t windowId,
79 int32_t zOrder,
80 bool visible,
81 WSRect rect)
82 {
83 SessionInfo info;
84 info.bundleName_ = "root";
85 info.persistentId_ = windowId;
86 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, nullptr);
87 ASSERT_NE(nullptr, sceneSession);
88 sceneSession->SetZOrder(zOrder);
89 sceneSession->SetRSVisible(visible);
90 sceneSession->SetSessionRect(rect);
91 sceneSession->property_->SetDisplayId(displayId);
92 ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
93 EXPECT_EQ(windowId, sceneSession->GetPersistentId());
94 }
95
InitTestSceneSessionForListWindowInfo()96 void SceneSessionManagerAnimationTest::InitTestSceneSessionForListWindowInfo()
97 {
98 SessionInfo sessionInfo1;
99 sessionInfo1.isSystem_ = false;
100 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
101 sceneSession1->SetVisibilityState(WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION);
102 WSRect rect = { 0, 0, 100, 100 };
103 sceneSession1->SetSessionRect(rect);
104 sceneSession1->SetSessionGlobalRect(rect);
105 sceneSession1->SetSessionState(SessionState::STATE_FOREGROUND);
106 sceneSession1->GetSessionProperty()->SetDisplayId(0);
107 ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 });
108
109 SessionInfo sessionInfo2;
110 sessionInfo2.isSystem_ = false;
111 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo2, nullptr);
112 sceneSession2->SetVisibilityState(WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION);
113 rect = { 0, 0, 120, 120 };
114 sceneSession2->SetSessionRect(rect);
115 sceneSession2->SetSessionGlobalRect(rect);
116 sceneSession2->SetSessionState(SessionState::STATE_FOREGROUND);
117 sceneSession2->GetSessionProperty()->SetDisplayId(0);
118 ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 });
119
120 SessionInfo sessionInfo3;
121 sessionInfo3.isSystem_ = false;
122 sptr<SceneSession> sceneSession3 = sptr<SceneSession>::MakeSptr(sessionInfo3, nullptr);
123 sceneSession3->SetVisibilityState(WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
124 rect = { 0, 100, 120, 120 };
125 sceneSession3->SetSessionRect(rect);
126 sceneSession3->SetSessionGlobalRect(rect);
127 sceneSession3->SetSessionState(SessionState::STATE_FOREGROUND);
128 sceneSession3->GetSessionProperty()->SetDisplayId(0);
129 ssm_->sceneSessionMap_.insert({ sceneSession3->GetPersistentId(), sceneSession3 });
130
131 SessionInfo sessionInfo4;
132 sessionInfo4.isSystem_ = true;
133 sptr<SceneSession> sceneSession6 = sptr<SceneSession>::MakeSptr(sessionInfo4, nullptr);
134 sceneSession6->SetVisibilityState(WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
135 rect = { 0, 200, 120, 120 };
136 sceneSession6->SetSessionRect(rect);
137 sceneSession6->SetSessionGlobalRect(rect);
138 sceneSession6->SetSessionState(SessionState::STATE_FOREGROUND);
139 constexpr DisplayId SECOND_DISPLAY_ID = 11;
140 sceneSession6->GetSessionProperty()->SetDisplayId(SECOND_DISPLAY_ID);
141 ssm_->sceneSessionMap_.insert({ sceneSession6->GetPersistentId(), sceneSession6 });
142 }
143
144 namespace {
145 /**
146 * @tc.name: TestUpdateRotateAnimationConfig_01
147 * @tc.desc: Test UpdateRotateAnimationConfig with duration_ 400
148 * @tc.type: FUNC
149 */
150 HWTEST_F(SceneSessionManagerAnimationTest, TestUpdateRotateAnimationConfig_01, TestSize.Level1)
151 {
152 ASSERT_NE(ssm_, nullptr);
153 RotateAnimationConfig config = { 400 };
154 ssm_->UpdateRotateAnimationConfig(config);
155 usleep(WAIT_SYNC_IN_NS);
156 ASSERT_EQ(ssm_->rotateAnimationConfig_.duration_, 400);
157 }
158
159 /**
160 * @tc.name: TestUpdateRotateAnimationConfig_02
161 * @tc.desc: Test UpdateRotateAnimationConfig with duration_ 600
162 * @tc.type: FUNC
163 */
164 HWTEST_F(SceneSessionManagerAnimationTest, TestUpdateRotateAnimationConfig_02, TestSize.Level1)
165 {
166 ASSERT_NE(ssm_, nullptr);
167 RotateAnimationConfig config = { 600 };
168 ssm_->UpdateRotateAnimationConfig(config);
169 usleep(WAIT_SYNC_IN_NS);
170 ASSERT_EQ(ssm_->rotateAnimationConfig_.duration_, 600);
171 }
172 } // namespace
173 } // namespace Rosen
174 } // namespace OHOS