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
TearDownTestCase()39 void SessionManagerAgentControllerTest::TearDownTestCase() {}
40
SetUp()41 void SessionManagerAgentControllerTest::SetUp() {}
42
TearDown()43 void SessionManagerAgentControllerTest::TearDown() {}
44
45 /**
46 * @tc.name: RegisterWindowManagerAgent
47 * @tc.desc: SesionManagerAgentController rigister window manager agent
48 * @tc.type: FUNC
49 */
50 HWTEST_F(SessionManagerAgentControllerTest, RegisterWindowManagerAgent, TestSize.Level1)
51 {
52 sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
53 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
54 int32_t pid = 65535;
55 SessionManagerAgentController::GetInstance().windowManagementMode_ = WindowManagementMode::FREEFORM;
56 ASSERT_EQ(WMError::WM_OK,
57 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type, pid));
58 ASSERT_EQ(WMError::WM_OK,
59 SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type, pid));
60 SessionManagerAgentController::GetInstance().windowManagementMode_ = WindowManagementMode::UNDEFINED;
61 }
62
63 /**
64 * @tc.name: UpdateCameraFloatWindowStatus
65 * @tc.desc: UpdateCameraFloatWindowStatus Test
66 * @tc.type: FUNC
67 */
68 HWTEST_F(SessionManagerAgentControllerTest, UpdateCameraFloatWindowStatus, TestSize.Level1)
69 {
70 sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
71 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
72 int32_t pid = 65535;
73 ASSERT_EQ(WMError::WM_OK,
74 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type, pid));
75 SessionManagerAgentController::GetInstance().UpdateCameraFloatWindowStatus(0, false);
76 ASSERT_EQ(WMError::WM_OK,
77 SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type, pid));
78 }
79
80 /**
81 * @tc.name: UpdateFocusChangeInfo
82 * @tc.desc: UpdateFocusChangeInfo Test
83 * @tc.type: FUNC
84 */
85 HWTEST_F(SessionManagerAgentControllerTest, UpdateFocusChangeInfo, TestSize.Level1)
86 {
87 sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
88 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
89 int32_t pid = 65535;
90 ASSERT_EQ(WMError::WM_OK,
91 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type, pid));
92 sptr<FocusChangeInfo> focusChangeInfo = sptr<FocusChangeInfo>::MakeSptr();
93 SessionManagerAgentController::GetInstance().UpdateFocusChangeInfo(focusChangeInfo, false);
94 ASSERT_EQ(WMError::WM_OK,
95 SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type, pid));
96 }
97
98 /**
99 * @tc.name: UpdateWindowModeTypeInfo
100 * @tc.desc: UpdateWindowModeTypeInfo Test
101 * @tc.type: FUNC
102 */
103 HWTEST_F(SessionManagerAgentControllerTest, UpdateWindowModeTypeInfo, TestSize.Level1)
104 {
105 int32_t pid = 65535;
106 sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
107 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE;
108 ASSERT_EQ(WMError::WM_OK,
109 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type, pid));
110 SessionManagerAgentController::GetInstance().UpdateWindowModeTypeInfo(WindowModeType::WINDOW_MODE_SPLIT);
111 ASSERT_EQ(WMError::WM_OK,
112 SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type, pid));
113 }
114
115 /**
116 * @tc.name: NotifyAccessibilityWindowInfo
117 * @tc.desc: NotifyAccessibilityWindowInfo Test
118 * @tc.type: FUNC
119 */
120 HWTEST_F(SessionManagerAgentControllerTest, NotifyAccessibilityWindowInfo, TestSize.Level1)
121 {
122 sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
123 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
124 int32_t pid = 65535;
125 ASSERT_EQ(WMError::WM_OK,
126 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type, pid));
127 std::vector<sptr<AccessibilityWindowInfo>> infos;
128 SessionManagerAgentController::GetInstance().NotifyAccessibilityWindowInfo(infos,
129 WindowUpdateType::WINDOW_UPDATE_ACTIVE);
130 ASSERT_EQ(WMError::WM_OK,
131 SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type, pid));
132 }
133
134 /**
135 * @tc.name: NotifyWaterMarkFlagChangedResult
136 * @tc.desc: NotifyWaterMarkFlagChangedResult Test
137 * @tc.type: FUNC
138 */
139 HWTEST_F(SessionManagerAgentControllerTest, NotifyWaterMarkFlagChangedResult, TestSize.Level1)
140 {
141 sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
142 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
143 int32_t pid = 65535;
144 ASSERT_EQ(WMError::WM_OK,
145 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type, pid));
146 SessionManagerAgentController::GetInstance().NotifyWaterMarkFlagChangedResult(false);
147 ASSERT_EQ(WMError::WM_OK,
148 SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type, pid));
149 }
150
151 /**
152 * @tc.name: UpdateWindowVisibilityInfo
153 * @tc.desc: UpdateWindowVisibilityInfo Test
154 * @tc.type: FUNC
155 */
156 HWTEST_F(SessionManagerAgentControllerTest, UpdateWindowVisibilityInfo, TestSize.Level1)
157 {
158 sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
159 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
160 int32_t pid = 65535;
161 ASSERT_EQ(WMError::WM_OK,
162 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type, pid));
163 std::vector<sptr<WindowVisibilityInfo>> windowVisibilityInfos;
164 SessionManagerAgentController::GetInstance().UpdateWindowVisibilityInfo(windowVisibilityInfos);
165 ASSERT_EQ(WMError::WM_OK,
166 SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type, pid));
167 }
168
169 /**
170 * @tc.name: UpdateVisibleWindowNum
171 * @tc.desc: UpdateVisibleWindowNum Test
172 * @tc.type: FUNC
173 */
174 HWTEST_F(SessionManagerAgentControllerTest, UpdateVisibleWindowNum, TestSize.Level1)
175 {
176 std::vector<VisibleWindowNumInfo> visibleWindowNumInfo;
177 SessionManagerAgentController::GetInstance().UpdateVisibleWindowNum(visibleWindowNumInfo);
178 int32_t pid = 65535;
179 sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
180 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM;
181 ASSERT_EQ(WMError::WM_OK,
182 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type, pid));
183 }
184
185 /**
186 * @tc.name: UpdateWindowDrawingContentInfo
187 * @tc.desc: UpdateWindowDrawingContentInfo Test
188 * @tc.type: FUNC
189 */
190 HWTEST_F(SessionManagerAgentControllerTest, UpdateWindowDrawingContentInfo, TestSize.Level1)
191 {
192 std::vector<sptr<WindowDrawingContentInfo>> windowDrawingContentInfos;
193 SessionManagerAgentController::GetInstance().UpdateWindowDrawingContentInfo(windowDrawingContentInfos);
194 int32_t pid = 65535;
195 sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
196 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
197 ASSERT_EQ(WMError::WM_OK,
198 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type, pid));
199 }
200
201 /**
202 * @tc.name: UpdateCameraWindowStatus
203 * @tc.desc: UpdateCameraWindowStatus Test
204 * @tc.type: FUNC
205 */
206 HWTEST_F(SessionManagerAgentControllerTest, UpdateCameraWindowStatus, TestSize.Level1)
207 {
208 sptr<IWindowManagerAgent> windowMangerAgent = sptr<WindowManagerAgent>::MakeSptr();
209 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_WINDOW;
210 int32_t pid = 65535;
211 ASSERT_EQ(WMError::WM_OK,
212 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowMangerAgent, type, pid));
213 SessionManagerAgentController::GetInstance().UpdateCameraWindowStatus(0, false);
214 ASSERT_EQ(WMError::WM_OK,
215 SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowMangerAgent, type, pid));
216 }
217
218 /**
219 * @tc.name: NotifyWindowStyleChange
220 * @tc.desc: NotifyWindowStyleChange Test
221 * @tc.type: FUNC
222 */
223 HWTEST_F(SessionManagerAgentControllerTest, NotifyWindowStyleChange, TestSize.Level1)
224 {
225 int32_t pid = 65535;
226 sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
227 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE;
228 SessionManagerAgentController::GetInstance().NotifyWindowStyleChange(Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT);
229 ASSERT_EQ(WMError::WM_OK,
230 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type, pid));
231 SessionManagerAgentController::GetInstance().NotifyWindowStyleChange(Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT);
232 ASSERT_EQ(WMError::WM_OK,
233 SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type, pid));
234 }
235
236 /**
237 * @tc.name: NotifyWindowSystemBarPropertyChange
238 * @tc.desc: NotifyWindowSystemBarPropertyChange Test
239 * @tc.type: FUNC
240 */
241 HWTEST_F(SessionManagerAgentControllerTest, NotifyWindowSystemBarPropertyChange, TestSize.Level1)
242 {
243 int32_t pid = 65535;
244 sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
245 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_STATUS_BAR_PROPERTY;
246 EXPECT_EQ(WMError::WM_OK,
247 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type, pid));
248 SystemBarProperty systemBarProperty;
249 SessionManagerAgentController::GetInstance().NotifyWindowSystemBarPropertyChange(
250 WindowType::WINDOW_TYPE_STATUS_BAR, systemBarProperty);
251 EXPECT_EQ(WMError::WM_OK,
252 SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type, pid));
253 }
254
255 /**
256 * @tc.name: NotifyWindowPropertyChange01
257 * @tc.desc: NotifyWindowPropertyChange Test
258 * @tc.type: FUNC
259 */
260 HWTEST_F(SessionManagerAgentControllerTest, NotifyWindowPropertyChange01, TestSize.Level1)
261 {
262 int32_t pid = 65535;
263 sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
264 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_PROPERTY;
265 uint32_t propertyDirtyFlags = 0;
266 std::vector<std::unordered_map<WindowInfoKey, WindowChangeInfoType>> windowInfoList;
267
268 EXPECT_EQ(WMError::WM_OK,
269 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type, pid));
270 SessionManagerAgentController::GetInstance().NotifyWindowPropertyChange(propertyDirtyFlags, windowInfoList);
271 EXPECT_EQ(WMError::WM_OK,
272 SessionManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type, pid));
273 }
274
275 } // namespace Rosen
276 } // namespace OHOS
277