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