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