1 /*
2 * Copyright (c) 2022-2022 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 #include "display_manager_proxy.h"
16 #include "display_manager_adapter.h"
17 #include "display_manager.h"
18 #include <gtest/gtest.h>
19 #include "hilog/log.h"
20 #include <iremote_broker.h>
21 #include <iservice_registry.h>
22 #include <system_ability_definition.h>
23 #include "scene_board_judgement.h"
24 #include "screen_manager.h"
25 #include "window_manager_hilog.h"
26 #include "window_scene.h"
27 #include "zidl/display_manager_agent_proxy.h"
28
29 using namespace testing;
30 using namespace testing::ext;
31
32 namespace OHOS {
33 namespace Rosen {
34
35 class DisplayManagerAgentProxyTest : public testing::Test {
36 public:
37 static void SetUpTestCase();
38 static void TearDownTestCase();
39 void SetUp() override;
40 void TearDown() override;
41 };
42
SetUpTestCase()43 void DisplayManagerAgentProxyTest::SetUpTestCase()
44 {
45 }
46
TearDownTestCase()47 void DisplayManagerAgentProxyTest::TearDownTestCase()
48 {
49 }
50
SetUp()51 void DisplayManagerAgentProxyTest::SetUp()
52 {
53 }
54
TearDown()55 void DisplayManagerAgentProxyTest::TearDown()
56 {
57 }
58
59 namespace {
60 /**
61 * @tc.name: NotifyDisplayPowerEvent
62 * @tc.desc: NotifyDisplayPowerEvent
63 * @tc.type: FUNC
64 */
65 HWTEST_F(DisplayManagerAgentProxyTest, NotifyDisplayPowerEvent, Function | SmallTest | Level1)
66 {
67 SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
68 sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
69
70 DisplayPowerEvent event = DisplayPowerEvent::DESKTOP_READY;
71 EventStatus status = EventStatus::BEGIN;
72 sptr<DisplayManagerAgentProxy> displayManagerAgentProxy = new DisplayManagerAgentProxy(impl);
73 GTEST_LOG_(INFO) << "WindowSessionImplTest:1";
74 displayManagerAgentProxy->NotifyDisplayPowerEvent(event, status);
75
76 int resultValue = 0;
77 std::function<void()> func = [&]()
__anona9da5a5c0202() 78 {
79 displayManagerAgentProxy->NotifyDisplayPowerEvent(event, status);
80 resultValue = 1;
81 };
82 func();
83 ASSERT_EQ(resultValue, 1);
84 }
85
86
87 /**
88 * @tc.name: OnScreenConnect
89 * @tc.desc: OnScreenConnect
90 * @tc.type: FUNC
91 */
92 HWTEST_F(DisplayManagerAgentProxyTest, OnScreenConnect, Function | SmallTest | Level1)
93 {
94 sptr<ScreenInfo> screenInfo = nullptr;
95
96 SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
97 sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
98 sptr<DisplayManagerAgentProxy> displayManagerAgentProxy = new DisplayManagerAgentProxy(impl);
99
100 int resultValue = 0;
101 std::function<void()> func = [&]()
__anona9da5a5c0302() 102 {
103 displayManagerAgentProxy->OnScreenConnect(screenInfo);
104 resultValue = 1;
105 };
106 func();
107 ASSERT_EQ(resultValue, 1);
108 }
109
110
111 /**
112 * @tc.name: OnScreenDisconnect
113 * @tc.desc: OnScreenDisconnect
114 * @tc.type: FUNC
115 */
116 HWTEST_F(DisplayManagerAgentProxyTest, OnScreenDisconnect, Function | SmallTest | Level1)
117 {
118 ScreenId screenId = 0;
119
120 sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
121 sptr<DisplayManagerAgentProxy> displayManagerAgentProxy = new DisplayManagerAgentProxy(impl);
122
123 int resultValue = 0;
124 std::function<void()> func = [&]()
__anona9da5a5c0402() 125 {
126 displayManagerAgentProxy->OnScreenDisconnect(screenId);
127 resultValue = 1;
128 };
129 func();
130 ASSERT_EQ(resultValue, 1);
131 }
132
133 /**
134 * @tc.name: OnScreenChange
135 * @tc.desc: OnScreenChange
136 * @tc.type: FUNC
137 */
138 HWTEST_F(DisplayManagerAgentProxyTest, OnScreenChange, Function | SmallTest | Level1)
139 {
140 sptr<ScreenInfo> screenInfo = new ScreenInfo();
141 ScreenChangeEvent event = ScreenChangeEvent::CHANGE_MODE;
142
143 sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
144 sptr<DisplayManagerAgentProxy> displayManagerAgentProxy = new DisplayManagerAgentProxy(impl);
145
146 int resultValue = 0;
147 std::function<void()> func = [&]()
__anona9da5a5c0502() 148 {
149 displayManagerAgentProxy->OnScreenChange(screenInfo, event);
150 resultValue = 1;
151 };
152 func();
153 ASSERT_EQ(resultValue, 1);
154 }
155
156 /**
157 * @tc.name: OnScreenGroupChange
158 * @tc.desc: OnScreenGroupChange
159 * @tc.type: FUNC
160 */
161 HWTEST_F(DisplayManagerAgentProxyTest, OnScreenGroupChange, Function | SmallTest | Level1)
162 {
163 std::string trigger = " ";
164 std::vector<sptr<ScreenInfo>> screenInfos = {};
165 ScreenGroupChangeEvent event = ScreenGroupChangeEvent::CHANGE_GROUP;
166
167 sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
168 sptr<DisplayManagerAgentProxy> displayManagerAgentProxy = new DisplayManagerAgentProxy(impl);
169
170 int resultValue = 0;
171 std::function<void()> func = [&]()
__anona9da5a5c0602() 172 {
173 displayManagerAgentProxy->OnScreenGroupChange(trigger, screenInfos, event);
174 resultValue = 1;
175 };
176 func();
177 ASSERT_EQ(resultValue, 1);
178 }
179
180 /**
181 * @tc.name: OnDisplayCreate
182 * @tc.desc: OnDisplayCreate
183 * @tc.type: FUNC
184 */
185 HWTEST_F(DisplayManagerAgentProxyTest, OnDisplayCreate, Function | SmallTest | Level1)
186 {
187 sptr<DisplayInfo> displayInfo = new DisplayInfo();
188
189 sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
190 sptr<DisplayManagerAgentProxy> displayManagerAgentProxy = new DisplayManagerAgentProxy(impl);
191
192 int resultValue = 0;
193 std::function<void()> func = [&]()
__anona9da5a5c0702() 194 {
195 displayManagerAgentProxy->OnDisplayCreate(displayInfo);
196 resultValue = 1;
197 };
198 func();
199 ASSERT_EQ(resultValue, 1);
200 }
201
202 /**
203 * @tc.name: OnDisplayDestroy
204 * @tc.desc: OnDisplayDestroy
205 * @tc.type: FUNC
206 */
207 HWTEST_F(DisplayManagerAgentProxyTest, OnDisplayDestroy, Function | SmallTest | Level1)
208 {
209 DisplayId displayId = 0;
210
211 sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
212 sptr<DisplayManagerAgentProxy> displayManagerAgentProxy = new DisplayManagerAgentProxy(impl);
213
214 int resultValue = 0;
215 std::function<void()> func = [&]()
__anona9da5a5c0802() 216 {
217 displayManagerAgentProxy->OnDisplayDestroy(displayId);
218 resultValue = 1;
219 };
220 func();
221 ASSERT_EQ(resultValue, 1);
222 }
223
224 /**
225 * @tc.name: OnDisplayChange
226 * @tc.desc: OnDisplayChange
227 * @tc.type: FUNC
228 */
229 HWTEST_F(DisplayManagerAgentProxyTest, OnDisplayChange, Function | SmallTest | Level1)
230 {
231 sptr<DisplayInfo> displayInfo = new DisplayInfo();
232 DisplayChangeEvent event = DisplayChangeEvent::DISPLAY_FREEZED;
233
234 sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
235 sptr<DisplayManagerAgentProxy> displayManagerAgentProxy = new DisplayManagerAgentProxy(impl);
236
237 int resultValue = 0;
238 std::function<void()> func = [&]()
__anona9da5a5c0902() 239 {
240 displayManagerAgentProxy->OnDisplayChange(displayInfo, event);
241 resultValue = 1;
242 };
243 func();
244 ASSERT_EQ(resultValue, 1);
245 }
246
247 /**
248 * @tc.name: OnScreenshot
249 * @tc.desc: OnScreenshot
250 * @tc.type: FUNC
251 */
252 HWTEST_F(DisplayManagerAgentProxyTest, OnScreenshot, Function | SmallTest | Level1)
253 {
254 sptr<ScreenshotInfo> snapshotInfo = new ScreenshotInfo();
255
256 sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
257 sptr<DisplayManagerAgentProxy> displayManagerAgentProxy = new DisplayManagerAgentProxy(impl);
258
259 int resultValue = 0;
260 std::function<void()> func = [&]()
__anona9da5a5c0a02() 261 {
262 displayManagerAgentProxy->OnScreenshot(snapshotInfo);
263 resultValue = 1;
264 };
265 func();
266 ASSERT_EQ(resultValue, 1);
267 }
268
269 /**
270 * @tc.name: NotifyPrivateWindowStateChanged
271 * @tc.desc: NotifyPrivateWindowStateChanged
272 * @tc.type: FUNC
273 */
274 HWTEST_F(DisplayManagerAgentProxyTest, NotifyPrivateWindowStateChanged, Function | SmallTest | Level1)
275 {
276 bool hasPrivate = false;
277
278 sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
279 sptr<DisplayManagerAgentProxy> displayManagerAgentProxy = new DisplayManagerAgentProxy(impl);
280
281 int resultValue = 0;
282 std::function<void()> func = [&]()
__anona9da5a5c0b02() 283 {
284 displayManagerAgentProxy->NotifyPrivateWindowStateChanged(hasPrivate);
285 resultValue = 1;
286 };
287 func();
288 ASSERT_EQ(resultValue, 1);
289 }
290
291 /**
292 * @tc.name: NotifyPrivateStateWindowListChanged
293 * @tc.desc: NotifyPrivateStateWindowListChanged
294 * @tc.type: FUNC
295 */
296 HWTEST_F(DisplayManagerAgentProxyTest, NotifyPrivateStateWindowListChanged, Function | SmallTest | Level1)
297 {
298 SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
299 DisplayId id = 0;
300 std::vector<std::string> privacyWindowList{"win0", "win1"};
301
302 sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
303 sptr<DisplayManagerAgentProxy> displayManagerAgentProxy = new DisplayManagerAgentProxy(impl);
304
305 int resultValue = 0;
306 std::function<void()> func = [&]()
__anona9da5a5c0c02() 307 {
308 displayManagerAgentProxy->NotifyPrivateStateWindowListChanged(id, privacyWindowList);
309 resultValue = 1;
310 };
311 func();
312 ASSERT_EQ(resultValue, 1);
313 }
314
315 /**
316 * @tc.name: NotifyFoldStatusChanged
317 * @tc.desc: NotifyFoldStatusChanged
318 * @tc.type: FUNC
319 */
320 HWTEST_F(DisplayManagerAgentProxyTest, NotifyFoldStatusChanged, Function | SmallTest | Level1)
321 {
322 sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
323 sptr<DisplayManagerAgentProxy> displayManagerAgentProxy = new DisplayManagerAgentProxy(impl);
324
325 int resultValue = 0;
326 std::function<void()> func = [&]()
__anona9da5a5c0d02() 327 {
328 displayManagerAgentProxy->NotifyFoldStatusChanged(FoldStatus::EXPAND);
329 resultValue = 1;
330 };
331 func();
332
333 ASSERT_EQ(resultValue, 1);
334 }
335 }
336 }
337 }