1 /*
2  * Copyright (c) 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 
16 #include <gtest/gtest.h>
17 #include "display_manager_adapter.h"
18 #include <functional>
19 #include "window_manager_agent_proxy.h"
20 #include "window_manager_agent.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 namespace OHOS {
25 namespace Rosen {
26 class WindowManagerAgentProxyTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp() override;
31     void TearDown() override;
32 private:
33     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
34 };
35 
SetUpTestCase()36 void WindowManagerAgentProxyTest::SetUpTestCase()
37 {
38 }
39 
TearDownTestCase()40 void WindowManagerAgentProxyTest::TearDownTestCase()
41 {
42 }
43 
SetUp()44 void WindowManagerAgentProxyTest::SetUp()
45 {
46 }
47 
TearDown()48 void WindowManagerAgentProxyTest::TearDown()
49 {
50     usleep(WAIT_SYNC_IN_NS);
51 }
52 
53 namespace {
54 /**
55  * @tc.name: UpdateFocusChangeInfo01
56  * @tc.desc: test InterfaceToken check failed
57  * @tc.type: FUNC
58  */
HWTEST_F(WindowManagerAgentProxyTest, UpdateFocusChangeInfo01, Function | SmallTest | Level2)59 HWTEST_F(WindowManagerAgentProxyTest, UpdateFocusChangeInfo01, Function | SmallTest | Level2)
60 {
61     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
62     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
63     sptr<FocusChangeInfo> focusChangeInfo = new (std::nothrow) FocusChangeInfo();
64     ASSERT_TRUE(focusChangeInfo != nullptr);
65     bool focused = true;
66 
67     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
68     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
69 
70     int resultValue = 0;
71     std::function<void()> func = [&]()
72     {
73         windowManagerAgentProxy->UpdateFocusChangeInfo(focusChangeInfo, focused);
74         resultValue = 1;
75     };
76     func();
77     ASSERT_EQ(resultValue, 1);
78 }
79 
80 /**
81  * @tc.name: UpdateFocusChangeInfo02
82  * @tc.desc: test InterfaceToken check failed
83  * @tc.type: FUNC
84  */
HWTEST_F(WindowManagerAgentProxyTest, UpdateFocusChangeInfo02, Function | SmallTest | Level2)85 HWTEST_F(WindowManagerAgentProxyTest, UpdateFocusChangeInfo02, Function | SmallTest | Level2)
86 {
87     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
88     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
89     ASSERT_TRUE(impl != nullptr);
90     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
91     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
92 
93     int resultValue = 0;
94     std::function<void()> func = [&]()
95     {
96         windowManagerAgentProxy->UpdateFocusChangeInfo(nullptr, false);
97         resultValue = 1;
98     };
99     func();
100     ASSERT_EQ(resultValue, 1);
101 }
102 
103 /**
104  * @tc.name: UpdateWindowModeTypeInfo
105  * @tc.desc: test InterfaceToken check failed
106  * @tc.type: FUNC
107  */
HWTEST_F(WindowManagerAgentProxyTest, UpdateWindowModeTypeInfo, Function | SmallTest | Level2)108 HWTEST_F(WindowManagerAgentProxyTest, UpdateWindowModeTypeInfo, Function | SmallTest | Level2)
109 {
110     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
111     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
112     ASSERT_TRUE(impl != nullptr);
113     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
114     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
115 
116     int resultValue = 0;
117     WindowModeType type = WindowModeType::WINDOW_MODE_SPLIT_FLOATING;
118     std::function<void()> func = [&]()
119     {
120         windowManagerAgentProxy->UpdateWindowModeTypeInfo(type);
121         resultValue = 1;
122     };
123     func();
124     ASSERT_EQ(resultValue, 1);
125 }
126 
127 /**
128  * @tc.name: UpdateSystemBarRegionTints
129  * @tc.desc: test InterfaceToken check failed
130  * @tc.type: FUNC
131  */
HWTEST_F(WindowManagerAgentProxyTest, UpdateSystemBarRegionTints, Function | SmallTest | Level2)132 HWTEST_F(WindowManagerAgentProxyTest, UpdateSystemBarRegionTints, Function | SmallTest | Level2)
133 {
134     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
135     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
136     ASSERT_TRUE(impl != nullptr);
137     DisplayId displayId = 0;
138     SystemBarRegionTints tints = {};
139 
140     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
141     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
142 
143     int resultValue = 0;
144     std::function<void()> func = [&]()
145     {
146         windowManagerAgentProxy->UpdateSystemBarRegionTints(displayId, tints);
147         resultValue = 1;
148     };
149     func();
150     ASSERT_EQ(resultValue, 1);
151 }
152 
153 /**
154  * @tc.name: NotifyAccessibilityWindowInfo
155  * @tc.desc: test InterfaceToken check failed
156  * @tc.type: FUNC
157  */
HWTEST_F(WindowManagerAgentProxyTest, NotifyAccessibilityWindowInfo, Function | SmallTest | Level2)158 HWTEST_F(WindowManagerAgentProxyTest, NotifyAccessibilityWindowInfo, Function | SmallTest | Level2)
159 {
160     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
161     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
162     ASSERT_TRUE(impl != nullptr);
163     std::vector<sptr<AccessibilityWindowInfo>> infos = {};
164     WindowUpdateType type = WindowUpdateType::WINDOW_UPDATE_REMOVED;
165 
166     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
167     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
168 
169     int resultValue = 0;
170     std::function<void()> func = [&]()
171     {
172         windowManagerAgentProxy->NotifyAccessibilityWindowInfo(infos, type);
173         resultValue = 1;
174     };
175     func();
176     ASSERT_EQ(resultValue, 1);
177 }
178 
179 /**
180  * @tc.name: UpdateWindowVisibilityInfo
181  * @tc.desc: test InterfaceToken check failed
182  * @tc.type: FUNC
183  */
HWTEST_F(WindowManagerAgentProxyTest, UpdateWindowVisibilityInfo, Function | SmallTest | Level2)184 HWTEST_F(WindowManagerAgentProxyTest, UpdateWindowVisibilityInfo, Function | SmallTest | Level2)
185 {
186     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
187     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
188     ASSERT_TRUE(impl != nullptr);
189     std::vector<sptr<WindowVisibilityInfo>> visibilityInfos = {};
190 
191     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
192     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
193 
194     int resultValue = 0;
195     std::function<void()> func = [&]()
196     {
197         windowManagerAgentProxy->UpdateWindowVisibilityInfo(visibilityInfos);
198         resultValue = 1;
199     };
200     func();
201     ASSERT_EQ(resultValue, 1);
202 }
203 
204 /**
205  * @tc.name: UpdateWindowDrawingContentInfo
206  * @tc.desc: test InterfaceToken check failed
207  * @tc.type: FUNC
208  */
HWTEST_F(WindowManagerAgentProxyTest, UpdateWindowDrawingContentInfo, Function | SmallTest | Level2)209 HWTEST_F(WindowManagerAgentProxyTest, UpdateWindowDrawingContentInfo, Function | SmallTest | Level2)
210 {
211     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
212     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
213     ASSERT_TRUE(impl != nullptr);
214     std::vector<sptr<WindowDrawingContentInfo>> windowDrawingContentInfos = {};
215 
216     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
217     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
218 
219     int resultValue = 0;
220     std::function<void()> func = [&]()
221     {
222         windowManagerAgentProxy->UpdateWindowDrawingContentInfo(windowDrawingContentInfos);
223         resultValue = 1;
224     };
225     func();
226     ASSERT_EQ(resultValue, 1);
227 }
228 
229 /**
230  * @tc.name: UpdateCameraFloatWindowStatus
231  * @tc.desc: test InterfaceToken check failed
232  * @tc.type: FUNC
233  */
HWTEST_F(WindowManagerAgentProxyTest, UpdateCameraFloatWindowStatus, Function | SmallTest | Level2)234 HWTEST_F(WindowManagerAgentProxyTest, UpdateCameraFloatWindowStatus, Function | SmallTest | Level2)
235 {
236     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
237     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
238     ASSERT_TRUE(impl != nullptr);
239     uint32_t accessTokenId = 0;
240     bool isShowing = true;
241 
242     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
243     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
244 
245     int resultValue = 0;
246     std::function<void()> func = [&]()
247     {
248         windowManagerAgentProxy->UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
249         resultValue = 1;
250     };
251     func();
252     ASSERT_EQ(resultValue, 1);
253 }
254 
255 /**
256  * @tc.name: NotifyWaterMarkFlagChangedResult
257  * @tc.desc: test InterfaceToken check failed
258  * @tc.type: FUNC
259  */
HWTEST_F(WindowManagerAgentProxyTest, NotifyWaterMarkFlagChangedResult, Function | SmallTest | Level2)260 HWTEST_F(WindowManagerAgentProxyTest, NotifyWaterMarkFlagChangedResult, Function | SmallTest | Level2)
261 {
262     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
263     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
264     ASSERT_TRUE(impl != nullptr);
265     bool showWaterMark = true;
266 
267     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
268     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
269 
270     int resultValue = 0;
271     std::function<void()> func = [&]()
272     {
273         windowManagerAgentProxy->NotifyWaterMarkFlagChangedResult(showWaterMark);
274         resultValue = 1;
275     };
276     func();
277     ASSERT_EQ(resultValue, 1);
278 }
279 
280 /**
281  * @tc.name: UpdateVisibleWindowNum
282  * @tc.desc: test InterfaceToken check failed
283  * @tc.type: FUNC
284  */
HWTEST_F(WindowManagerAgentProxyTest, UpdateVisibleWindowNum, Function | SmallTest | Level2)285 HWTEST_F(WindowManagerAgentProxyTest, UpdateVisibleWindowNum, Function | SmallTest | Level2)
286 {
287     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
288     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
289     ASSERT_TRUE(impl != nullptr);
290     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
291     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
292     int resultValue = 0;
293     VisibleWindowNumInfo info;
294     info.displayId = 1;
295     info.visibleWindowNum = 1;
296     std::vector<VisibleWindowNumInfo> visibleWindowNumInfo;
297     visibleWindowNumInfo.push_back(info);
298     std::function<void()> func = [&]()
299     {
300         windowManagerAgentProxy->UpdateVisibleWindowNum(visibleWindowNumInfo);
301         resultValue = 1;
302     };
303     func();
304     ASSERT_EQ(resultValue, 1);
305 }
306 
307 /**
308  * @tc.name: NotifyGestureNavigationEnabledResult
309  * @tc.desc: test InterfaceToken check failed
310  * @tc.type: FUNC
311  */
HWTEST_F(WindowManagerAgentProxyTest, NotifyGestureNavigationEnabledResult, Function | SmallTest | Level2)312 HWTEST_F(WindowManagerAgentProxyTest, NotifyGestureNavigationEnabledResult, Function | SmallTest | Level2)
313 {
314     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
315     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
316     ASSERT_TRUE(impl != nullptr);
317     bool enable = true;
318 
319     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
320     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
321 
322     int resultValue = 0;
323     std::function<void()> func = [&]()
324     {
325         windowManagerAgentProxy->NotifyGestureNavigationEnabledResult(enable);
326         resultValue = 1;
327     };
328     func();
329     ASSERT_EQ(resultValue, 1);
330 }
331 
332 /**
333  * @tc.name: UpdateCameraWindowStatus
334  * @tc.desc: test InterfaceToken check failed
335  * @tc.type: FUNC
336  */
HWTEST_F(WindowManagerAgentProxyTest, UpdateCameraWindowStatus, Function | SmallTest | Level2)337 HWTEST_F(WindowManagerAgentProxyTest, UpdateCameraWindowStatus, Function | SmallTest | Level2)
338 {
339     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
340     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
341     ASSERT_TRUE(impl != nullptr);
342     uint32_t accessTokenId = 1;
343     bool isShowing = false;
344 
345     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
346     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
347 
348     int resultValue = 0;
349     std::function<void()> func = [&]()
350     {
351         windowManagerAgentProxy->UpdateCameraWindowStatus(accessTokenId, isShowing);
352         resultValue = 1;
353     };
354     func();
355     ASSERT_EQ(resultValue, 1);
356 }
357 
358 /**
359  * @tc.name: NotifyWindowStyleChange
360  * @tc.desc: test NotifyWindowStyleChange
361  * @tc.type: FUNC
362  */
HWTEST_F(WindowManagerAgentProxyTest, NotifyWindowStyleChange, Function | SmallTest | Level2)363 HWTEST_F(WindowManagerAgentProxyTest, NotifyWindowStyleChange, Function | SmallTest | Level2)
364 {
365     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
366     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
367     ASSERT_TRUE(impl != nullptr);
368     WindowStyleType type = Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT;
369 
370     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
371     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
372 
373     int resultValue = 0;
374     std::function<void()> func = [&]()
375     {
376         windowManagerAgentProxy->NotifyWindowStyleChange(type);
377         resultValue = 1;
378     };
379     func();
380     ASSERT_EQ(resultValue, 1);
381 }
382 
383 /**
384  * @tc.name: NotifyWindowPidVisibilityChanged
385  * @tc.desc: test NotifyWindowPidVisibilityChanged
386  * @tc.type: FUNC
387  */
HWTEST_F(WindowManagerAgentProxyTest, NotifyWindowPidVisibilityChanged, Function | SmallTest | Level2)388 HWTEST_F(WindowManagerAgentProxyTest, NotifyWindowPidVisibilityChanged, Function | SmallTest | Level2)
389 {
390     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
391     sptr<IRemoteObject> impl = SingletonContainer::Get<ScreenManagerAdapter>().displayManagerServiceProxy_->AsObject();
392     ASSERT_TRUE(impl != nullptr);
393 
394     sptr<WindowManagerAgentProxy> windowManagerAgentProxy = new (std::nothrow) WindowManagerAgentProxy(impl);
395     ASSERT_TRUE(windowManagerAgentProxy != nullptr);
396 
397     sptr<WindowPidVisibilityInfo> info = new WindowPidVisibilityInfo();
398 
399     int resultValue = 0;
400     std::function<void()> func = [&]()
401     {
402         windowManagerAgentProxy->NotifyWindowPidVisibilityChanged(info);
403         resultValue = 1;
404     };
405     func();
406     ASSERT_EQ(resultValue, 1);
407 }
408 
409 } // namespace
410 } // namespace Rosen
411 } // namespace OHOS