1 /*
2  * Copyright (c) 2023 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_manager/include/scene_session_manager.h"
18 #include "session_manager/include/session_manager_agent_controller.h"
19 #include "session_info.h"
20 #include "session/host/include/scene_session.h"
21 #include "window_manager_agent.h"
22 #include "zidl/window_manager_agent_interface.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 class SessionManagerAgentControllerTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     void SetUp() override;
34     void TearDown() override;
35 };
36 
SetUpTestCase()37 void SessionManagerAgentControllerTest::SetUpTestCase()
38 {
39 }
40 
TearDownTestCase()41 void SessionManagerAgentControllerTest::TearDownTestCase()
42 {
43 }
44 
SetUp()45 void SessionManagerAgentControllerTest::SetUp()
46 {
47 }
48 
TearDown()49 void SessionManagerAgentControllerTest::TearDown()
50 {
51 }
52 
53 /**
54  * @tc.name: RegisterWindowManagerAgent
55  * @tc.desc: SesionManagerAgentController rigister window manager agent
56  * @tc.type: FUNC
57  */
58 HWTEST_F(SessionManagerAgentControllerTest, RegisterWindowManagerAgent, Function | SmallTest | Level3)
59 {
60     sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
61     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
62     int32_t pid = 65535;
63     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
64         windowManagerAgent, type, pid));
65     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(
66         windowManagerAgent, type, pid));
67 }
68 
69 /**
70  * @tc.name: UpdateCameraFloatWindowStatus
71  * @tc.desc: UpdateCameraFloatWindowStatus Test
72  * @tc.type: FUNC
73  */
74 HWTEST_F(SessionManagerAgentControllerTest, UpdateCameraFloatWindowStatus, Function | SmallTest | Level3)
75 {
76     sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
77     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
78     int32_t pid = 65535;
79     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
80         windowManagerAgent, type, pid));
81     SessionManagerAgentController::GetInstance().UpdateCameraFloatWindowStatus(0, false);
82     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(
83         windowManagerAgent, type, pid));
84 }
85 
86 /**
87  * @tc.name: UpdateFocusChangeInfo
88  * @tc.desc: UpdateFocusChangeInfo Test
89  * @tc.type: FUNC
90  */
91 HWTEST_F(SessionManagerAgentControllerTest, UpdateFocusChangeInfo, Function | SmallTest | Level3)
92 {
93     sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
94     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
95     int32_t pid = 65535;
96     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
97         windowManagerAgent, type, pid));
98     sptr<FocusChangeInfo> focusChangeInfo = new FocusChangeInfo();
99     SessionManagerAgentController::GetInstance().UpdateFocusChangeInfo(focusChangeInfo, false);
100     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(
101         windowManagerAgent, type, pid));
102 }
103 
104 /**
105  * @tc.name: UpdateWindowModeTypeInfo
106  * @tc.desc: UpdateWindowModeTypeInfo Test
107  * @tc.type: FUNC
108  */
109 HWTEST_F(SessionManagerAgentControllerTest, UpdateWindowModeTypeInfo, Function | SmallTest | Level3)
110 {
111     sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
112     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE;
113     int32_t pid = 65535;
114     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
115         windowManagerAgent, type, pid));
116     SessionManagerAgentController::GetInstance().UpdateWindowModeTypeInfo(WindowModeType::WINDOW_MODE_SPLIT);
117     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(
118         windowManagerAgent, type, pid));
119 }
120 
121 /**
122  * @tc.name: NotifyAccessibilityWindowInfo
123  * @tc.desc: NotifyAccessibilityWindowInfo Test
124  * @tc.type: FUNC
125  */
126 HWTEST_F(SessionManagerAgentControllerTest, NotifyAccessibilityWindowInfo, Function | SmallTest | Level3)
127 {
128     int32_t pid = 65535;
129     sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
130     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
131     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
132         windowManagerAgent, type, pid));
133     std::vector<sptr<AccessibilityWindowInfo>> infos;
134     SessionManagerAgentController::GetInstance().NotifyAccessibilityWindowInfo(infos,
135         WindowUpdateType::WINDOW_UPDATE_ACTIVE);
136     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(
137         windowManagerAgent, type, pid));
138 }
139 
140 /**
141  * @tc.name: NotifyWaterMarkFlagChangedResult
142  * @tc.desc: NotifyWaterMarkFlagChangedResult Test
143  * @tc.type: FUNC
144  */
145 HWTEST_F(SessionManagerAgentControllerTest, NotifyWaterMarkFlagChangedResult, Function | SmallTest | Level3)
146 {
147     sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
148     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
149     int32_t pid = 65535;
150     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
151         windowManagerAgent, type, pid));
152     SessionManagerAgentController::GetInstance().NotifyWaterMarkFlagChangedResult(false);
153     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(
154         windowManagerAgent, type, pid));
155 }
156 
157 /**
158  * @tc.name: UpdateWindowVisibilityInfo
159  * @tc.desc: UpdateWindowVisibilityInfo Test
160  * @tc.type: FUNC
161  */
162 HWTEST_F(SessionManagerAgentControllerTest, UpdateWindowVisibilityInfo, Function | SmallTest | Level3)
163 {
164     sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
165     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
166     int32_t pid = 65535;
167     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
168         windowManagerAgent, type, pid));
169     std::vector<sptr<WindowVisibilityInfo>> windowVisibilityInfos;
170     SessionManagerAgentController::GetInstance().UpdateWindowVisibilityInfo(windowVisibilityInfos);
171     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(
172         windowManagerAgent, type, pid));
173 }
174 
175 /**
176  * @tc.name: UpdateVisibleWindowNum
177  * @tc.desc: UpdateVisibleWindowNum Test
178  * @tc.type: FUNC
179  */
180 HWTEST_F(SessionManagerAgentControllerTest, UpdateVisibleWindowNum, Function | SmallTest | Level3)
181 {
182     std::vector<VisibleWindowNumInfo> visibleWindowNumInfo;
183     SessionManagerAgentController::GetInstance().UpdateVisibleWindowNum(visibleWindowNumInfo);
184     int32_t pid = 65535;
185     sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
186     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM;
187     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
188         windowManagerAgent, type, pid));
189 }
190 
191 /**
192  * @tc.name: UpdateWindowDrawingContentInfo
193  * @tc.desc: UpdateWindowDrawingContentInfo Test
194  * @tc.type: FUNC
195  */
196 HWTEST_F(SessionManagerAgentControllerTest, UpdateWindowDrawingContentInfo, Function | SmallTest | Level3)
197 {
198     std::vector<sptr<WindowDrawingContentInfo>> windowDrawingContentInfos;
199     SessionManagerAgentController::GetInstance().UpdateWindowDrawingContentInfo(windowDrawingContentInfos);
200     int32_t pid = 65535;
201     sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
202     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
203     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
204         windowManagerAgent, type, pid));
205 }
206 
207 /**
208  * @tc.name: UpdateCameraWindowStatus
209  * @tc.desc: UpdateCameraWindowStatus Test
210  * @tc.type: FUNC
211  */
212 HWTEST_F(SessionManagerAgentControllerTest, UpdateCameraWindowStatus, Function | SmallTest | Level3)
213 {
214     sptr<IWindowManagerAgent> windowMangerAgent = new WindowManagerAgent();
215     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_WINDOW;
216     int32_t pid = 65535;
217     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
218         windowMangerAgent, type, pid));
219     SessionManagerAgentController::GetInstance().UpdateCameraWindowStatus(0, false);
220     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(
221         windowMangerAgent, type, pid));
222 }
223 
224 /**
225  * @tc.name: NotifyWindowStyleChange
226  * @tc.desc: NotifyWindowStyleChange Test
227  * @tc.type: FUNC
228  */
229 HWTEST_F(SessionManagerAgentControllerTest, NotifyWindowStyleChange, Function | SmallTest | Level3)
230 {
231     int32_t pid = 65535;
232     sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
233     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE;
234     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
235         windowManagerAgent, type, pid));
236     SessionManagerAgentController::GetInstance().NotifyWindowStyleChange(Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT);
237     ASSERT_EQ(WMError::WM_OK, SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(
238         windowManagerAgent, type, pid));
239 }
240 
241 } // namespace Rosen
242 } // namespace OHOS
243 
244