• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 
19 #include "display_manager_adapter.h"
20 #include "scene_board_judgement.h"
21 #include "iremote_object_mocker.h"
22 #include "window_manager_agent_proxy.h"
23 #include "test/mock/mock_message_parcel.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 namespace {
28     std::string g_logMsg;
MyLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)29     void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char* tag,
30         const char* msg)
31     {
32         g_logMsg = msg;
33     }
34 }
35 
36 namespace OHOS {
37 namespace Rosen {
38 class WindowManagerAgentProxyTest : public testing::Test {
39 public:
40     static void SetUpTestSuite();
41     void SetUp() override;
42     void TearDown() override;
43     sptr<WindowManagerAgentProxy> windowManagerAgentProxy;
44 
45 private:
46     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
47 };
48 
SetUpTestSuite()49 void WindowManagerAgentProxyTest::SetUpTestSuite()
50 {
51 }
52 
SetUp()53 void WindowManagerAgentProxyTest::SetUp()
54 {
55     if (windowManagerAgentProxy) {
56         return;
57     }
58 
59     sptr<IRemoteObject> impl;
60     impl = sptr<IRemoteObjectMocker>::MakeSptr();
61 
62     windowManagerAgentProxy = sptr<WindowManagerAgentProxy>::MakeSptr(impl);
63     ASSERT_NE(windowManagerAgentProxy, nullptr);
64 }
65 
TearDown()66 void WindowManagerAgentProxyTest::TearDown()
67 {
68     usleep(WAIT_SYNC_IN_NS);
69 }
70 
71 namespace {
72 /**
73  * @tc.name: UpdateFocusChangeInfo01
74  * @tc.desc: test InterfaceToken check failed
75  * @tc.type: FUNC
76  */
77 HWTEST_F(WindowManagerAgentProxyTest, UpdateFocusChangeInfo01, TestSize.Level1)
78 {
79     g_logMsg.clear();
80     LOG_SetCallback(MyLogCallback);
81     sptr<FocusChangeInfo> focusChangeInfo = sptr<FocusChangeInfo>::MakeSptr();
82     ASSERT_TRUE(focusChangeInfo != nullptr);
83     bool focused = true;
84 
85     MockMessageParcel::ClearAllErrorFlag();
86     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
87     windowManagerAgentProxy->UpdateFocusChangeInfo(focusChangeInfo, focused);
88     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
89 }
90 
91 /**
92  * @tc.name: UpdateFocusChangeInfo02
93  * @tc.desc: test write focusChangeInfo failed
94  * @tc.type: FUNC
95  */
96 HWTEST_F(WindowManagerAgentProxyTest, UpdateFocusChangeInfo02, TestSize.Level1)
97 {
98     g_logMsg.clear();
99     LOG_SetCallback(MyLogCallback);
100     sptr<FocusChangeInfo> focusChangeInfo = new(std::nothrow) FocusChangeInfo();
101     ASSERT_TRUE(focusChangeInfo != nullptr);
102     bool focused = true;
103 
104     MockMessageParcel::ClearAllErrorFlag();
105     MockMessageParcel::SetWriteParcelableErrorFlag(true);
106     windowManagerAgentProxy->UpdateFocusChangeInfo(focusChangeInfo, focused);
107     EXPECT_TRUE(g_logMsg.find("Write displayId failed") != std::string::npos);
108 }
109 
110 /**
111  * @tc.name: UpdateFocusChangeInfo03
112  * @tc.desc: test write focused failed
113  * @tc.type: FUNC
114  */
115 HWTEST_F(WindowManagerAgentProxyTest, UpdateFocusChangeInfo03, TestSize.Level1)
116 {
117     g_logMsg.clear();
118     LOG_SetCallback(MyLogCallback);
119     sptr<FocusChangeInfo> focusChangeInfo = new(std::nothrow) FocusChangeInfo();
120     ASSERT_TRUE(focusChangeInfo != nullptr);
121     bool focused = true;
122 
123     MockMessageParcel::ClearAllErrorFlag();
124     MockMessageParcel::SetWriteBoolErrorFlag(true);
125     windowManagerAgentProxy->UpdateFocusChangeInfo(focusChangeInfo, focused);
126     EXPECT_TRUE(g_logMsg.find("Write Focus failed") != std::string::npos);
127 }
128 
129 /**
130  * @tc.name: UpdateFocusChangeInfo04
131  * @tc.desc: test focusChangeInfo
132  * @tc.type: FUNC
133  */
134 HWTEST_F(WindowManagerAgentProxyTest, UpdateFocusChangeInfo04, TestSize.Level1)
135 {
136     g_logMsg.clear();
137     LOG_SetCallback(MyLogCallback);
138     bool focused = true;
139 
140     MockMessageParcel::ClearAllErrorFlag();
141     windowManagerAgentProxy->UpdateFocusChangeInfo(nullptr, focused);
142     EXPECT_TRUE(g_logMsg.find("Invalid focus change info") != std::string::npos);
143 }
144 
145 /**
146  * @tc.name: UpdateWindowModeTypeInfo01
147  * @tc.desc: test InterfaceToken check failed
148  * @tc.type: FUNC
149  */
150 HWTEST_F(WindowManagerAgentProxyTest, UpdateWindowModeTypeInfo01, TestSize.Level1)
151 {
152     g_logMsg.clear();
153     LOG_SetCallback(MyLogCallback);
154     WindowModeType type = WindowModeType::WINDOW_MODE_SPLIT_FLOATING;
155 
156     MockMessageParcel::ClearAllErrorFlag();
157     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
158     windowManagerAgentProxy->UpdateWindowModeTypeInfo(type);
159     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
160 }
161 
162 /**
163  * @tc.name: UpdateSystemBarRegionTints01
164  * @tc.desc: test InterfaceToken check failed
165  * @tc.type: FUNC
166  */
167 HWTEST_F(WindowManagerAgentProxyTest, UpdateSystemBarRegionTints01, TestSize.Level1)
168 {
169     g_logMsg.clear();
170     LOG_SetCallback(MyLogCallback);
171     DisplayId displayId = 0;
172     SystemBarRegionTints tints = {};
173 
174     MockMessageParcel::ClearAllErrorFlag();
175     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
176     windowManagerAgentProxy->UpdateSystemBarRegionTints(displayId, tints);
177     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
178 }
179 
180 /**
181  * @tc.name: UpdateSystemBarRegionTints02
182  * @tc.desc: test write tints and displayId failed
183  * @tc.type: FUNC
184  */
185 HWTEST_F(WindowManagerAgentProxyTest, UpdateSystemBarRegionTints02, TestSize.Level1)
186 {
187     g_logMsg.clear();
188     LOG_SetCallback(MyLogCallback);
189     DisplayId displayId = 0;
190     SystemBarRegionTints tints = {};
191 
192     MockMessageParcel::ClearAllErrorFlag();
193     MockMessageParcel::SetWriteUint64ErrorFlag(true);
194     windowManagerAgentProxy->UpdateSystemBarRegionTints(displayId, tints);
195     EXPECT_TRUE(g_logMsg.find("Write displayId failed") != std::string::npos);
196 
197     MockMessageParcel::ClearAllErrorFlag();
198     MockMessageParcel::SetWriteInt32ErrorFlag(true);
199     windowManagerAgentProxy->UpdateSystemBarRegionTints(displayId, tints);
200     EXPECT_TRUE(g_logMsg.find("Write SystemBarRegionTint failed") != std::string::npos);
201 }
202 
203 /**
204  * @tc.name: NotifyAccessibilityWindowInfo
205  * @tc.desc: test InterfaceToken check failed
206  * @tc.type: FUNC
207  */
208 HWTEST_F(WindowManagerAgentProxyTest, NotifyAccessibilityWindowInfo, TestSize.Level1)
209 {
210     g_logMsg.clear();
211     LOG_SetCallback(MyLogCallback);
212     std::vector<sptr<AccessibilityWindowInfo>> infos = {};
213     WindowUpdateType type = WindowUpdateType::WINDOW_UPDATE_REMOVED;
214 
215     MockMessageParcel::ClearAllErrorFlag();
216     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
217     windowManagerAgentProxy->NotifyAccessibilityWindowInfo(infos, type);
218     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
219 }
220 
221 /**
222  * @tc.name: NotifyAccessibilityWindowInfo01
223  * @tc.desc: test write infos failed
224  * @tc.type: FUNC
225  */
226 HWTEST_F(WindowManagerAgentProxyTest, NotifyAccessibilityWindowInfo01, TestSize.Level1)
227 {
228     g_logMsg.clear();
229     LOG_SetCallback(MyLogCallback);
230     std::vector<sptr<AccessibilityWindowInfo>> infos;
231     sptr<AccessibilityWindowInfo> info = sptr<AccessibilityWindowInfo>::MakeSptr();
232     infos.push_back(info);
233     WindowUpdateType type = WindowUpdateType::WINDOW_UPDATE_REMOVED;
234 
235     MockMessageParcel::ClearAllErrorFlag();
236     MockMessageParcel::SetWriteParcelableErrorFlag(true);
237     windowManagerAgentProxy->NotifyAccessibilityWindowInfo(infos, type);
238     EXPECT_TRUE(g_logMsg.find("Write accessibility window infos failed") != std::string::npos);
239 }
240 
241 /**
242  * @tc.name: UpdateWindowVisibilityInfo01
243  * @tc.desc: test InterfaceToken check failed
244  * @tc.type: FUNC
245  */
246 HWTEST_F(WindowManagerAgentProxyTest, UpdateWindowVisibilityInfo01, TestSize.Level1)
247 {
248     g_logMsg.clear();
249     LOG_SetCallback(MyLogCallback);
250     std::vector<sptr<WindowVisibilityInfo>> visibilityInfos = {};
251 
252     MockMessageParcel::ClearAllErrorFlag();
253     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
254     windowManagerAgentProxy->UpdateWindowVisibilityInfo(visibilityInfos);
255     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
256 }
257 
258 /**
259  * @tc.name: UpdateWindowVisibilityInfo02
260  * @tc.desc: test write visibilityInfos failed
261  * @tc.type: FUNC
262  */
263 HWTEST_F(WindowManagerAgentProxyTest, UpdateWindowVisibilityInfo02, TestSize.Level1)
264 {
265     g_logMsg.clear();
266     LOG_SetCallback(MyLogCallback);
267     std::vector<sptr<WindowVisibilityInfo>> visibilityInfos = {};
268 
269     MockMessageParcel::ClearAllErrorFlag();
270     MockMessageParcel::SetWriteUint32ErrorFlag(true);
271     windowManagerAgentProxy->UpdateWindowVisibilityInfo(visibilityInfos);
272     EXPECT_TRUE(g_logMsg.find("write windowVisibilityInfos size failed") != std::string::npos);
273 }
274 
275 /**
276  * @tc.name: UpdateWindowVisibilityInfo03
277  * @tc.desc: test write visibilityInfos failed
278  * @tc.type: FUNC
279  */
280 HWTEST_F(WindowManagerAgentProxyTest, UpdateWindowVisibilityInfo03, TestSize.Level1)
281 {
282     g_logMsg.clear();
283     LOG_SetCallback(MyLogCallback);
284     std::vector<sptr<WindowVisibilityInfo>> visibilityInfos = {};
285     sptr<WindowVisibilityInfo> visibilityInfo = sptr<WindowVisibilityInfo>::MakeSptr();
286     visibilityInfos.push_back(visibilityInfo);
287 
288     MockMessageParcel::ClearAllErrorFlag();
289     MockMessageParcel::SetWriteParcelableErrorFlag(true);
290     windowManagerAgentProxy->UpdateWindowVisibilityInfo(visibilityInfos);
291     EXPECT_TRUE(g_logMsg.find("Write windowVisibilityInfo failed") != std::string::npos);
292 }
293 
294 /**
295  * @tc.name: UpdateWindowDrawingContentInfo01
296  * @tc.desc: test InterfaceToken check failed
297  * @tc.type: FUNC
298  */
299 HWTEST_F(WindowManagerAgentProxyTest, UpdateWindowDrawingContentInfo01, TestSize.Level1)
300 {
301     g_logMsg.clear();
302     LOG_SetCallback(MyLogCallback);
303     std::vector<sptr<WindowDrawingContentInfo>> windowDrawingContentInfos = {};
304     MockMessageParcel::ClearAllErrorFlag();
305     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
306     windowManagerAgentProxy->UpdateWindowDrawingContentInfo(windowDrawingContentInfos);
307     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
308 }
309 
310 /**
311  * @tc.name: UpdateWindowDrawingContentInfo02
312  * @tc.desc: test InterfaceToken check failed
313  * @tc.type: FUNC
314  */
315 HWTEST_F(WindowManagerAgentProxyTest, UpdateWindowDrawingContentInfo02, TestSize.Level1)
316 {
317     g_logMsg.clear();
318     LOG_SetCallback(MyLogCallback);
319     std::vector<sptr<WindowDrawingContentInfo>> windowDrawingContentInfos = {};
320     MockMessageParcel::ClearAllErrorFlag();
321     MockMessageParcel::SetWriteUint32ErrorFlag(true);
322     windowManagerAgentProxy->UpdateWindowDrawingContentInfo(windowDrawingContentInfos);
323     EXPECT_TRUE(g_logMsg.find("write windowDrawingContentInfos size failed") != std::string::npos);
324 }
325 
326 /**
327  * @tc.name: UpdateWindowDrawingContentInfo03
328  * @tc.desc: test wirte windowDrawingContentInfos failed
329  * @tc.type: FUNC
330  */
331 HWTEST_F(WindowManagerAgentProxyTest, UpdateWindowDrawingContentInfo03, TestSize.Level1)
332 {
333     g_logMsg.clear();
334     LOG_SetCallback(MyLogCallback);
335     std::vector<sptr<WindowDrawingContentInfo>> windowDrawingContentInfos = {};
336     sptr<WindowDrawingContentInfo> windowDrawingContentInfo = sptr<WindowDrawingContentInfo>::MakeSptr();
337     windowDrawingContentInfos.push_back(windowDrawingContentInfo);
338 
339     MockMessageParcel::ClearAllErrorFlag();
340     MockMessageParcel::SetWriteParcelableErrorFlag(true);
341     windowManagerAgentProxy->UpdateWindowDrawingContentInfo(windowDrawingContentInfos);
342     EXPECT_TRUE(g_logMsg.find("Write windowDrawingContentInfos failed") != std::string::npos);
343 }
344 
345 /**
346  * @tc.name: UpdateCameraFloatWindowStatus
347  * @tc.desc: test InterfaceToken check failed
348  * @tc.type: FUNC
349  */
350 HWTEST_F(WindowManagerAgentProxyTest, UpdateCameraFloatWindowStatus, TestSize.Level1)
351 {
352     g_logMsg.clear();
353     LOG_SetCallback(MyLogCallback);
354     uint32_t accessTokenId = 0;
355     bool isShowing = true;
356 
357     MockMessageParcel::ClearAllErrorFlag();
358     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
359     windowManagerAgentProxy->UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
360     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
361 }
362 
363 /**
364  * @tc.name: UpdateCameraFloatWindowStatus01
365  * @tc.desc: test InterfaceToken check failed
366  * @tc.type: FUNC
367  */
368 HWTEST_F(WindowManagerAgentProxyTest, UpdateCameraFloatWindowStatus01, TestSize.Level1)
369 {
370     g_logMsg.clear();
371     LOG_SetCallback(MyLogCallback);
372     uint32_t accessTokenId = 0;
373     bool isShowing = true;
374 
375     MockMessageParcel::ClearAllErrorFlag();
376     MockMessageParcel::SetWriteUint32ErrorFlag(true);
377     windowManagerAgentProxy->UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
378     EXPECT_TRUE(g_logMsg.find("Write accessTokenId failed") != std::string::npos);
379 }
380 
381 /**
382  * @tc.name: UpdateCameraFloatWindowStatus02
383  * @tc.desc: test InterfaceToken check failed
384  * @tc.type: FUNC
385  */
386 HWTEST_F(WindowManagerAgentProxyTest, UpdateCameraFloatWindowStatus02, TestSize.Level1)
387 {
388     g_logMsg.clear();
389     LOG_SetCallback(MyLogCallback);
390     uint32_t accessTokenId = 0;
391     bool isShowing = true;
392 
393     MockMessageParcel::ClearAllErrorFlag();
394     MockMessageParcel::SetWriteBoolErrorFlag(true);
395     windowManagerAgentProxy->UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
396     EXPECT_TRUE(g_logMsg.find("Write is showing status failed") != std::string::npos);
397 }
398 
399 /**
400  * @tc.name: NotifyWaterMarkFlagChangedResult
401  * @tc.desc: test InterfaceToken check failed
402  * @tc.type: FUNC
403  */
404 HWTEST_F(WindowManagerAgentProxyTest, NotifyWaterMarkFlagChangedResult, TestSize.Level1)
405 {
406     g_logMsg.clear();
407     LOG_SetCallback(MyLogCallback);
408     bool showWaterMark = true;
409 
410     MockMessageParcel::ClearAllErrorFlag();
411     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
412     windowManagerAgentProxy->NotifyWaterMarkFlagChangedResult(showWaterMark);
413     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
414 }
415 
416 /**
417  * @tc.name: NotifyWaterMarkFlagChangedResult01
418  * @tc.desc: test InterfaceToken check failed
419  * @tc.type: FUNC
420  */
421 HWTEST_F(WindowManagerAgentProxyTest, NotifyWaterMarkFlagChangedResult01, TestSize.Level1)
422 {
423     g_logMsg.clear();
424     LOG_SetCallback(MyLogCallback);
425     bool showWaterMark = true;
426 
427     MockMessageParcel::ClearAllErrorFlag();
428     MockMessageParcel::SetWriteBoolErrorFlag(true);
429     windowManagerAgentProxy->NotifyWaterMarkFlagChangedResult(showWaterMark);
430     EXPECT_TRUE(g_logMsg.find("Write is showing status failed") != std::string::npos);
431 }
432 
433 /**
434  * @tc.name: UpdateVisibleWindowNum
435  * @tc.desc: test InterfaceToken check failed
436  * @tc.type: FUNC
437  */
438 HWTEST_F(WindowManagerAgentProxyTest, UpdateVisibleWindowNum, TestSize.Level1)
439 {
440     g_logMsg.clear();
441     LOG_SetCallback(MyLogCallback);
442     VisibleWindowNumInfo info;
443     info.displayId = 1;
444     info.visibleWindowNum = 1;
445     std::vector<VisibleWindowNumInfo> visibleWindowNumInfo;
446     visibleWindowNumInfo.push_back(info);
447 
448     MockMessageParcel::ClearAllErrorFlag();
449     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
450     windowManagerAgentProxy->UpdateVisibleWindowNum(visibleWindowNumInfo);
451     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
452 }
453 
454 /**
455  * @tc.name: UpdateVisibleWindowNum01
456  * @tc.desc: test InterfaceToken check failed
457  * @tc.type: FUNC
458  */
459 HWTEST_F(WindowManagerAgentProxyTest, UpdateVisibleWindowNum01, TestSize.Level1)
460 {
461     g_logMsg.clear();
462     LOG_SetCallback(MyLogCallback);
463     VisibleWindowNumInfo info;
464     info.displayId = 1;
465     info.visibleWindowNum = 1;
466     std::vector<VisibleWindowNumInfo> visibleWindowNumInfo;
467     visibleWindowNumInfo.push_back(info);
468 
469     MockMessageParcel::ClearAllErrorFlag();
470     MockMessageParcel::SetWriteUint32ErrorFlag(true);
471     windowManagerAgentProxy->UpdateVisibleWindowNum(visibleWindowNumInfo);
472     EXPECT_TRUE(g_logMsg.find("Write VisibleWindowNumInfo failed") != std::string::npos);
473 }
474 
475 /**
476  * @tc.name: NotifyGestureNavigationEnabledResult
477  * @tc.desc: test InterfaceToken check failed
478  * @tc.type: FUNC
479  */
480 HWTEST_F(WindowManagerAgentProxyTest, NotifyGestureNavigationEnabledResult, TestSize.Level1)
481 {
482     g_logMsg.clear();
483     LOG_SetCallback(MyLogCallback);
484     bool enable = true;
485 
486     MockMessageParcel::ClearAllErrorFlag();
487     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
488     windowManagerAgentProxy->NotifyGestureNavigationEnabledResult(enable);
489     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
490 }
491 
492 /**
493  * @tc.name: NotifyGestureNavigationEnabledResult01
494  * @tc.desc: test InterfaceToken check failed
495  * @tc.type: FUNC
496  */
497 HWTEST_F(WindowManagerAgentProxyTest, NotifyGestureNavigationEnabledResult01, TestSize.Level1)
498 {
499     g_logMsg.clear();
500     LOG_SetCallback(MyLogCallback);
501     bool enable = true;
502 
503     MockMessageParcel::ClearAllErrorFlag();
504     MockMessageParcel::SetWriteBoolErrorFlag(true);
505     windowManagerAgentProxy->NotifyGestureNavigationEnabledResult(enable);
506     EXPECT_TRUE(g_logMsg.find("Write is showing status failed") != std::string::npos);
507 }
508 
509 
510 /**
511  * @tc.name: UpdateCameraWindowStatus
512  * @tc.desc: test InterfaceToken check failed
513  * @tc.type: FUNC
514  */
515 HWTEST_F(WindowManagerAgentProxyTest, UpdateCameraWindowStatus, TestSize.Level1)
516 {
517     g_logMsg.clear();
518     LOG_SetCallback(MyLogCallback);
519     uint32_t accessTokenId = 1;
520     bool isShowing = false;
521 
522     MockMessageParcel::ClearAllErrorFlag();
523     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
524     windowManagerAgentProxy->UpdateCameraWindowStatus(accessTokenId, isShowing);
525     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
526 }
527 
528 /**
529  * @tc.name: UpdateCameraWindowStatus01
530  * @tc.desc: test InterfaceToken check failed
531  * @tc.type: FUNC
532  */
533 HWTEST_F(WindowManagerAgentProxyTest, UpdateCameraWindowStatus01, TestSize.Level1)
534 {
535     g_logMsg.clear();
536     LOG_SetCallback(MyLogCallback);
537     uint32_t accessTokenId = 1;
538     bool isShowing = false;
539 
540     MockMessageParcel::ClearAllErrorFlag();
541     MockMessageParcel::SetWriteUint32ErrorFlag(true);
542     windowManagerAgentProxy->UpdateCameraWindowStatus(accessTokenId, isShowing);
543     EXPECT_TRUE(g_logMsg.find("Write accessTokenId failed") != std::string::npos);
544 }
545 
546 /**
547  * @tc.name: UpdateCameraWindowStatus02
548  * @tc.desc: test InterfaceToken check failed
549  * @tc.type: FUNC
550  */
551 HWTEST_F(WindowManagerAgentProxyTest, UpdateCameraWindowStatus02, TestSize.Level1)
552 {
553     g_logMsg.clear();
554     LOG_SetCallback(MyLogCallback);
555     uint32_t accessTokenId = 1;
556     bool isShowing = false;
557 
558     MockMessageParcel::ClearAllErrorFlag();
559     MockMessageParcel::SetWriteBoolErrorFlag(true);
560     windowManagerAgentProxy->UpdateCameraWindowStatus(accessTokenId, isShowing);
561     EXPECT_TRUE(g_logMsg.find("Write isShowing status failed") != std::string::npos);
562 }
563 
564 /**
565  * @tc.name: NotifyWindowStyleChange
566  * @tc.desc: test NotifyWindowStyleChange
567  * @tc.type: FUNC
568  */
569 HWTEST_F(WindowManagerAgentProxyTest, NotifyWindowStyleChange, TestSize.Level1)
570 {
571     g_logMsg.clear();
572     LOG_SetCallback(MyLogCallback);
573     WindowStyleType type = Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT;
574 
575     MockMessageParcel::ClearAllErrorFlag();
576     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
577     windowManagerAgentProxy->NotifyWindowStyleChange(type);
578     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
579 }
580 
581 /**
582  * @tc.name: NotifyCallingWindowDisplayChanged01
583  * @tc.desc: test InterfaceToken check failed
584  * @tc.type: FUNC
585  */
586 HWTEST_F(WindowManagerAgentProxyTest, NotifyCallingWindowDisplayChanged01, TestSize.Level1)
587 {
588     g_logMsg.clear();
589     LOG_SetCallback(MyLogCallback);
590     CallingWindowInfo windowInfo;
591 
592     MockMessageParcel::ClearAllErrorFlag();
593     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
594     windowManagerAgentProxy->NotifyCallingWindowDisplayChanged(windowInfo);
595     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
596 }
597 
598 /**
599  * @tc.name: NotifyCallingWindowDisplayChanged02
600  * @tc.desc: test InterfaceToken check failed
601  * @tc.type: FUNC
602  */
603 HWTEST_F(WindowManagerAgentProxyTest, NotifyCallingWindowDisplayChanged02, TestSize.Level1)
604 {
605     g_logMsg.clear();
606     LOG_SetCallback(MyLogCallback);
607     CallingWindowInfo windowInfo;
608 
609     MockMessageParcel::ClearAllErrorFlag();
610     MockMessageParcel::SetWriteParcelableErrorFlag(true);
611     windowManagerAgentProxy->NotifyCallingWindowDisplayChanged(windowInfo);
612     EXPECT_TRUE(g_logMsg.find("Write callingWindowInfo failed") != std::string::npos);
613 }
614 
615 /**
616  * @tc.name: NotifyWindowSystemBarPropertyChange
617  * @tc.desc: test NotifyWindowSystemBarPropertyChange
618  * @tc.type: FUNC
619  */
620 HWTEST_F(WindowManagerAgentProxyTest, NotifyWindowSystemBarPropertyChange, TestSize.Level1)
621 {
622     g_logMsg.clear();
623     LOG_SetCallback(MyLogCallback);
624     MockMessageParcel::ClearAllErrorFlag();
625     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
626     SystemBarProperty systemBarProperty;
627     windowManagerAgentProxy->NotifyWindowSystemBarPropertyChange(
628         WindowType::WINDOW_TYPE_STATUS_BAR, systemBarProperty);
629     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
630 }
631 
632 /**
633  * @tc.name: NotifyWindowPidVisibilityChanged
634  * @tc.desc: test NotifyWindowPidVisibilityChanged
635  * @tc.type: FUNC
636  */
637 HWTEST_F(WindowManagerAgentProxyTest, NotifyWindowPidVisibilityChanged, TestSize.Level1)
638 {
639     g_logMsg.clear();
640     LOG_SetCallback(MyLogCallback);
641     sptr<WindowPidVisibilityInfo> info = sptr<WindowPidVisibilityInfo>::MakeSptr();
642 
643     MockMessageParcel::ClearAllErrorFlag();
644     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
645     windowManagerAgentProxy->NotifyWindowPidVisibilityChanged(info);
646     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
647 }
648 
649 /**
650  * @tc.name: NotifyWindowPidVisibilityChanged01
651  * @tc.desc: test NotifyWindowPidVisibilityChanged
652  * @tc.type: FUNC
653  */
654 HWTEST_F(WindowManagerAgentProxyTest, NotifyWindowPidVisibilityChanged01, TestSize.Level1)
655 {
656     g_logMsg.clear();
657     LOG_SetCallback(MyLogCallback);
658     sptr<WindowPidVisibilityInfo> info = sptr<WindowPidVisibilityInfo>::MakeSptr();
659 
660     MockMessageParcel::ClearAllErrorFlag();
661     MockMessageParcel::SetWriteParcelableErrorFlag(true);
662     windowManagerAgentProxy->NotifyWindowPidVisibilityChanged(info);
663     EXPECT_TRUE(g_logMsg.find("Write windowPidVisibilityInfo failed") != std::string::npos);
664 }
665 
666 /**
667  * @tc.name: NotifyWindowPidVisibilityChanged02
668  * @tc.desc: test NotifyWindowPidVisibilityChanged02
669  * @tc.type: FUNC
670  */
671 HWTEST_F(WindowManagerAgentProxyTest, NotifyWindowPidVisibilityChanged02, TestSize.Level1)
672 {
673     g_logMsg.clear();
674     LOG_SetCallback(MyLogCallback);
675 
676     MockMessageParcel::ClearAllErrorFlag();
677     MockMessageParcel::SetWriteParcelableErrorFlag(true);
678     windowManagerAgentProxy->NotifyWindowPidVisibilityChanged(nullptr);
679     EXPECT_TRUE(g_logMsg.find("Invalid window pid visibility info") != std::string::npos);
680 }
681 
682 /**
683  * @tc.name: UpdatePiPWindowStateChanged
684  * @tc.desc: test UpdatePiPWindowStateChanged
685  * @tc.type: FUNC
686  */
687 HWTEST_F(WindowManagerAgentProxyTest, UpdatePiPWindowStateChanged, TestSize.Level1)
688 {
689     g_logMsg.clear();
690     LOG_SetCallback(MyLogCallback);
691     std::string bundleName = "test";
692     bool isForeground = false;
693 
694     MockMessageParcel::ClearAllErrorFlag();
695     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
696     windowManagerAgentProxy->UpdatePiPWindowStateChanged(bundleName, isForeground);
697     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
698 }
699 
700 /**
701  * @tc.name: NotifyWindowPropertyChange
702  * @tc.desc: test NotifyWindowPropertyChange
703  * @tc.type: FUNC
704  */
705 HWTEST_F(WindowManagerAgentProxyTest, NotifyWindowPropertyChange, TestSize.Level1)
706 {
707     g_logMsg.clear();
708     LOG_SetCallback(MyLogCallback);
709     uint32_t propertyDirtyFlags = 0;
710     std::vector<std::unordered_map<WindowInfoKey, WindowChangeInfoType>> windowInfoList;
711 
712     MockMessageParcel::ClearAllErrorFlag();
713     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
714     windowManagerAgentProxy->NotifyWindowPropertyChange(propertyDirtyFlags, windowInfoList);
715     EXPECT_TRUE(g_logMsg.find("WriteInterfaceToken failed") != std::string::npos);
716 }
717 
718 /**
719  * @tc.name: NotifyWindowPropertyChange01
720  * @tc.desc: test NotifyWindowPropertyChange
721  * @tc.type: FUNC
722  */
723 HWTEST_F(WindowManagerAgentProxyTest, NotifyWindowPropertyChange01, TestSize.Level1)
724 {
725     g_logMsg.clear();
726     LOG_SetCallback(MyLogCallback);
727     uint32_t propertyDirtyFlags = 0;
728     std::vector<std::unordered_map<WindowInfoKey, WindowChangeInfoType>> windowInfoList;
729 
730     MockMessageParcel::ClearAllErrorFlag();
731     MockMessageParcel::SetWriteUint32ErrorFlag(true);
732     windowManagerAgentProxy->NotifyWindowPropertyChange(propertyDirtyFlags, windowInfoList);
733     EXPECT_TRUE(g_logMsg.find("Write propertyDirtyFlags failed") != std::string::npos);
734 }
735 
736 /**
737  * @tc.name: NotifyWindowPropertyChange02
738  * @tc.desc: test NotifyWindowPropertyChange
739  * @tc.type: FUNC
740  */
741 HWTEST_F(WindowManagerAgentProxyTest, NotifyWindowPropertyChange02, TestSize.Level1)
742 {
743     g_logMsg.clear();
744     LOG_SetCallback(MyLogCallback);
745     uint32_t propertyDirtyFlags = 0;
746     std::vector<std::unordered_map<WindowInfoKey, WindowChangeInfoType>> windowInfoList;
747     std::unordered_map<WindowInfoKey, WindowChangeInfoType> info = {
748         { WindowInfoKey::APP_INDEX, 0 },
749     };
750     windowInfoList.push_back(info);
751 
752     MockMessageParcel::ClearAllErrorFlag();
753     MockMessageParcel::SetWriteInt32ErrorFlag(true);
754     windowManagerAgentProxy->NotifyWindowPropertyChange(propertyDirtyFlags, windowInfoList);
755     EXPECT_TRUE(g_logMsg.find("Write window change info value failed") != std::string::npos);
756 }
757 
758 /**
759  * @tc.name: WriteWindowChangeInfoValue
760  * @tc.desc: test WriteWindowChangeInfoValue
761  * @tc.type: FUNC
762  */
763 HWTEST_F(WindowManagerAgentProxyTest, WriteWindowChangeInfoValue, TestSize.Level1)
764 {
765     g_logMsg.clear();
766     LOG_SetCallback(MyLogCallback);
767     MessageParcel data;
768     std::pair<WindowInfoKey, WindowChangeInfoType> windowInfoPair;
769 
770     MockMessageParcel::ClearAllErrorFlag();
771     MockMessageParcel::SetWriteInt32ErrorFlag(true);
772     windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
773     EXPECT_TRUE(g_logMsg.find("Write windowInfoKey failed") != std::string::npos);
774 }
775 
776 /**
777  * @tc.name: WriteWindowChangeInfoValue01
778  * @tc.desc: test WriteWindowChangeInfoValue
779  * @tc.type: FUNC
780  */
781 HWTEST_F(WindowManagerAgentProxyTest, WriteWindowChangeInfoValue01, TestSize.Level1)
782 {
783     g_logMsg.clear();
784     LOG_SetCallback(MyLogCallback);
785     MockMessageParcel::ClearAllErrorFlag();
786     MessageParcel data;
787     std::pair<WindowInfoKey, WindowChangeInfoType> windowInfoPair;
788 
789     WindowChangeInfoType windowInfo = 0;
790     windowInfoPair = std::make_pair(WindowInfoKey::WINDOW_ID, windowInfo);
791     bool ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
792     EXPECT_EQ(ret, true);
793 
794     windowInfo = std::string("test");
795     windowInfoPair = std::make_pair(WindowInfoKey::BUNDLE_NAME, windowInfo);
796     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
797     EXPECT_EQ(ret, true);
798 
799     windowInfoPair = std::make_pair(WindowInfoKey::ABILITY_NAME, windowInfo);
800     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
801     EXPECT_EQ(ret, true);
802 
803     windowInfo = 0;
804     windowInfoPair = std::make_pair(WindowInfoKey::APP_INDEX, windowInfo);
805     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
806     EXPECT_EQ(ret, true);
807 
808     windowInfo = WindowVisibilityState::START;
809     windowInfoPair = std::make_pair(WindowInfoKey::VISIBILITY_STATE, windowInfo);
810     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
811     EXPECT_EQ(ret, true);
812 
813     windowInfo = static_cast<uint64_t>(0);
814     windowInfoPair = std::make_pair(WindowInfoKey::DISPLAY_ID, windowInfo);
815     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
816     EXPECT_EQ(ret, true);
817 
818     windowInfo = Rect({0, 0, 0, 0});
819     windowInfoPair = std::make_pair(WindowInfoKey::WINDOW_RECT, windowInfo);
820     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
821     EXPECT_EQ(ret, true);
822 
823     windowInfo = WindowMode::WINDOW_MODE_FULLSCREEN;
824     windowInfoPair = std::make_pair(WindowInfoKey::WINDOW_MODE, windowInfo);
825     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
826     EXPECT_EQ(ret, true);
827 
828     windowInfo = 1.0f;
829     windowInfoPair = std::make_pair(WindowInfoKey::FLOATING_SCALE, windowInfo);
830     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
831     EXPECT_EQ(ret, true);
832 
833     windowInfo = 0;
834     windowInfoPair = std::make_pair(WindowInfoKey::NONE, windowInfo);
835     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
836     EXPECT_EQ(ret, false);
837 }
838 
839 /**
840  * @tc.name: WriteWindowChangeInfoValue02
841  * @tc.desc: test WriteWindowChangeInfoValue fail 1
842  * @tc.type: FUNC
843  */
844 HWTEST_F(WindowManagerAgentProxyTest, WriteWindowChangeInfoValue02, TestSize.Level1)
845 {
846     g_logMsg.clear();
847     LOG_SetCallback(MyLogCallback);
848     MockMessageParcel::ClearAllErrorFlag();
849     MessageParcel data;
850     std::pair<WindowInfoKey, WindowChangeInfoType> windowInfoPair;
851 
852     MockMessageParcel::SetWriteUint32ErrorFlag(true);
853     WindowChangeInfoType windowInfo = 0;
854     windowInfoPair = std::make_pair(WindowInfoKey::WINDOW_ID, windowInfo);
855     bool ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
856     EXPECT_EQ(ret, false);
857 
858     MockMessageParcel::SetWriteStringErrorFlag(true);
859     windowInfo = std::string("test");
860     windowInfoPair = std::make_pair(WindowInfoKey::BUNDLE_NAME, windowInfo);
861     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
862     EXPECT_EQ(ret, false);
863 
864     windowInfoPair = std::make_pair(WindowInfoKey::ABILITY_NAME, windowInfo);
865     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
866     EXPECT_EQ(ret, false);
867 
868     MockMessageParcel::SetWriteInt32ErrorFlag(true);
869     windowInfo = 0;
870     windowInfoPair = std::make_pair(WindowInfoKey::APP_INDEX, windowInfo);
871     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
872     EXPECT_EQ(ret, false);
873 
874     MockMessageParcel::SetWriteUint32ErrorFlag(true);
875     windowInfo = WindowVisibilityState::START;
876     windowInfoPair = std::make_pair(WindowInfoKey::VISIBILITY_STATE, windowInfo);
877     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
878     EXPECT_EQ(ret, false);
879 }
880 
881 /**
882  * @tc.name: WriteWindowChangeInfoValue03
883  * @tc.desc: test WriteWindowChangeInfoValue fail 2
884  * @tc.type: FUNC
885  */
886 HWTEST_F(WindowManagerAgentProxyTest, WriteWindowChangeInfoValue03, TestSize.Level1)
887 {
888     g_logMsg.clear();
889     LOG_SetCallback(MyLogCallback);
890     MockMessageParcel::ClearAllErrorFlag();
891     MessageParcel data;
892     std::pair<WindowInfoKey, WindowChangeInfoType> windowInfoPair;
893 
894     MockMessageParcel::SetWriteUint64ErrorFlag(true);
895     WindowChangeInfoType windowInfo = static_cast<uint64_t>(0);
896     windowInfoPair = std::make_pair(WindowInfoKey::DISPLAY_ID, windowInfo);
897     auto ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
898     EXPECT_EQ(ret, false);
899 
900     MockMessageParcel::SetWriteUint32ErrorFlag(true);
901     MockMessageParcel::SetWriteInt32ErrorFlag(true);
902     windowInfo = Rect({0, 0, 0, 0});
903     windowInfoPair = std::make_pair(WindowInfoKey::WINDOW_RECT, windowInfo);
904     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
905     EXPECT_EQ(ret, false);
906 
907     MockMessageParcel::SetWriteUint32ErrorFlag(true);
908     windowInfo = WindowMode::WINDOW_MODE_FULLSCREEN;
909     windowInfoPair = std::make_pair(WindowInfoKey::WINDOW_MODE, windowInfo);
910     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
911     EXPECT_EQ(ret, false);
912 
913     MockMessageParcel::SetWriteFloatErrorFlag(true);
914     windowInfo = 1.0f;
915     windowInfoPair = std::make_pair(WindowInfoKey::FLOATING_SCALE, windowInfo);
916     ret = windowManagerAgentProxy->WriteWindowChangeInfoValue(data, windowInfoPair);
917     EXPECT_EQ(ret, false);
918 
919     MockMessageParcel::ClearAllErrorFlag();
920 }
921 } // namespace
922 } // namespace Rosen
923 } // namespace OHOS
924