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 "window_manager_agent_stub.h"
18 #include "window_manager_agent.h"
19 #include "marshalling_helper.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 namespace OHOS {
24 namespace Rosen {
25 class WindowManagerAgentStubTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29     void SetUp() override;
30     void TearDown() override;
31     sptr<WindowManagerAgentStub> stub_;
32 };
33 
SetUpTestCase()34 void WindowManagerAgentStubTest::SetUpTestCase()
35 {
36 }
37 
TearDownTestCase()38 void WindowManagerAgentStubTest::TearDownTestCase()
39 {
40 }
41 
SetUp()42 void WindowManagerAgentStubTest::SetUp()
43 {
44     stub_ = new WindowManagerAgent();
45 }
46 
TearDown()47 void WindowManagerAgentStubTest::TearDown()
48 {
49 }
50 
51 namespace {
52 /**
53  * @tc.name: OnRemoteRequest01
54  * @tc.desc: test InterfaceToken check failed
55  * @tc.type: FUNC
56  */
57 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest01, Function | SmallTest | Level2)
58 {
59     MessageParcel data;
60     MessageParcel reply;
61     MessageOption option;
62 
63     data.WriteInterfaceToken(u"error.GetDescriptor");
64 
65     uint32_t code = static_cast<uint32_t>(IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_FOCUS);
66 
67     int res = stub_->OnRemoteRequest(code, data, reply, option);
68     EXPECT_EQ(res, static_cast<int>(ERR_TRANSACTION_FAILED));
69 }
70 
71 /**
72  * @tc.name: OnRemoteRequest02
73  * @tc.desc: test TRANS_ID_UPDATE_FOCUS
74  * @tc.type: FUNC
75  */
76 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest02, Function | SmallTest | Level2)
77 {
78     MessageParcel data;
79     MessageParcel reply;
80     MessageOption option;
81 
82     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
83 
84     sptr<FocusChangeInfo> focusChangeInfo = new FocusChangeInfo();
85     data.WriteParcelable(focusChangeInfo);
86     data.WriteRemoteObject(focusChangeInfo->abilityToken_);
87     data.WriteBool(false);
88 
89     uint32_t code = static_cast<uint32_t>(IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_FOCUS);
90 
91     int res = stub_->OnRemoteRequest(code, data, reply, option);
92     EXPECT_EQ(res, 0);
93 }
94 
95 /**
96  * @tc.name: OnRemoteRequest03
97  * @tc.desc: test TRANS_ID_UPDATE_FOCUS failed
98  * @tc.type: FUNC
99  */
100 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest03, Function | SmallTest | Level2)
101 {
102     MessageParcel data;
103     MessageParcel reply;
104     MessageOption option;
105 
106     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
107 
108     uint32_t code = static_cast<uint32_t>(IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_FOCUS);
109 
110     int res = stub_->OnRemoteRequest(code, data, reply, option);
111     EXPECT_EQ(res, static_cast<int>(ERR_INVALID_DATA));
112 }
113 
114 /**
115  * @tc.name: OnRemoteRequest04
116  * @tc.desc: test TRANS_ID_UPDATE_WINDOW_STATUS success
117  * @tc.type: FUNC
118  */
119 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest04, Function | SmallTest | Level2)
120 {
121     MessageParcel data;
122     MessageParcel reply;
123     MessageOption option;
124 
125     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
126 
127     sptr<AccessibilityWindowInfo> info = new AccessibilityWindowInfo();
128     std::vector<sptr<AccessibilityWindowInfo>> infos;
129     infos.emplace_back(info);
130     MarshallingHelper::MarshallingVectorParcelableObj<AccessibilityWindowInfo>(data, infos);
131 
132     data.WriteUint32(static_cast<uint32_t>(WindowUpdateType::WINDOW_UPDATE_ADDED));
133 
134     uint32_t code = static_cast<uint32_t>(IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STATUS);
135 
136     int res = stub_->OnRemoteRequest(code, data, reply, option);
137     EXPECT_EQ(res, 0);
138 }
139 
140 /**
141  * @tc.name: OnRemoteRequest06
142  * @tc.desc: test TRANS_ID_UPDATE_WINDOW_VISIBILITY success
143  * @tc.type: FUNC
144  */
145 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest06, Function | SmallTest | Level2)
146 {
147     MessageParcel data;
148     MessageParcel reply;
149     MessageOption option;
150 
151     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
152 
153     sptr<WindowVisibilityInfo> visibilityInfo = new WindowVisibilityInfo();
154     std::vector<sptr<WindowVisibilityInfo>> visibilityInfos;
155     visibilityInfos.emplace_back(visibilityInfo);
156     data.WriteUint32(static_cast<uint32_t>(visibilityInfos.size()));
157     for (auto& info : visibilityInfos) {
158         data.WriteParcelable(info);
159     }
160 
161     auto code = static_cast<uint32_t>(IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_VISIBILITY);
162 
163     int res = stub_->OnRemoteRequest(code, data, reply, option);
164     EXPECT_EQ(res, 0);
165 }
166 
167 /**
168  * @tc.name: OnRemoteRequest08
169  * @tc.desc: test TRANS_ID_UPDATE_SYSTEM_BAR_PROPS success
170  * @tc.type: FUNC
171  */
172 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest08, Function | SmallTest | Level2)
173 {
174     MessageParcel data;
175     MessageParcel reply;
176     MessageOption option;
177 
178     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
179 
180     data.WriteUint64(0);
181 
182     SystemBarRegionTints tints;
183     MarshallingHelper::MarshallingVectorObj<SystemBarRegionTint>(data, tints,
__anone81704ed0202(Parcel& parcel, const SystemBarRegionTint& tint) 184         [](Parcel& parcel, const SystemBarRegionTint& tint) {
185             return parcel.WriteUint32(static_cast<uint32_t>(tint.type_)) && parcel.WriteBool(tint.prop_.enable_) &&
186                 parcel.WriteUint32(tint.prop_.backgroundColor_) && parcel.WriteUint32(tint.prop_.contentColor_) &&
187                 parcel.WriteInt32(tint.region_.posX_) && parcel.WriteInt32(tint.region_.posY_) &&
188                 parcel.WriteInt32(tint.region_.width_) && parcel.WriteInt32(tint.region_.height_);
189         }
190     );
191 
192     uint32_t code = static_cast<uint32_t>(IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_SYSTEM_BAR_PROPS);
193 
194     int res = stub_->OnRemoteRequest(code, data, reply, option);
195     EXPECT_EQ(res, 0);
196 }
197 
198 /**
199  * @tc.name: OnRemoteRequest09
200  * @tc.desc: test TRANS_ID_UPDATE_SYSTEM_BAR_PROPS success
201  * @tc.type: FUNC
202  */
203 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest09, Function | SmallTest | Level2)
204 {
205     MessageParcel data;
206     MessageParcel reply;
207     MessageOption option;
208 
209     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
210     data.WriteBool(true);
211     uint32_t code = static_cast<uint32_t>(
212         IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_WATER_MARK_FLAG);
213     int res = stub_->OnRemoteRequest(code, data, reply, option);
214     EXPECT_EQ(res, 0);
215 }
216 
217 /**
218  * @tc.name: OnRemoteRequest10
219  * @tc.desc: test TRANS_ID_UPDATE_SYSTEM_BAR_PROPS success
220  * @tc.type: FUNC
221  */
222 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest10, Function | SmallTest | Level2)
223 {
224     MessageParcel data;
225     MessageParcel reply;
226     MessageOption option;
227 
228     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
229     data.WriteBool(true);
230     uint32_t code = static_cast<uint32_t>(
231         IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_GESTURE_NAVIGATION_ENABLED);
232     int res = stub_->OnRemoteRequest(code, data, reply, option);
233     EXPECT_EQ(res, 0);
234 }
235 
236 /**
237  * @tc.name: OnRemoteRequest11
238  * @tc.desc: test InterfaceToken check failed
239  * @tc.type: FUNC
240  */
241 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest11, Function | SmallTest | Level2)
242 {
243     MessageParcel data;
244     MessageParcel reply;
245     MessageOption option;
246 
247     data.WriteInterfaceToken(u"error.GetDescriptor");
248 
249     uint32_t code = static_cast<uint32_t>(
250         IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_MODE_TYPE);
251     int res = stub_->OnRemoteRequest(code, data, reply, option);
252     EXPECT_EQ(res, static_cast<int>(ERR_TRANSACTION_FAILED));
253 }
254 
255 /**
256  * @tc.name: OnRemoteRequest12
257  * @tc.desc: test TRANS_ID_UPDATE_WINDOW_MODE_TYPE
258  * @tc.type: FUNC
259  */
260 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest12, Function | SmallTest | Level2)
261 {
262     MessageParcel data;
263     MessageParcel reply;
264     MessageOption option;
265 
266     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
267     data.WriteUint8(static_cast<uint8_t>(WindowModeType::WINDOW_MODE_FLOATING));
268     uint32_t code = static_cast<uint32_t>(
269         IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_MODE_TYPE);
270     int res = stub_->OnRemoteRequest(code, data, reply, option);
271     EXPECT_EQ(res, 0);
272 }
273 
274 /**
275  * @tc.name: OnRemoteRequest13
276  * @tc.desc: test TRANS_ID_UPDATE_WINDOW_MODE_TYPE success
277  * @tc.type: FUNC
278  */
279 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest13, Function | SmallTest | Level2)
280 {
281     MessageParcel data;
282     MessageParcel reply;
283     MessageOption option;
284 
285     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
286 
287     uint32_t code = static_cast<uint32_t>(
288         IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_MODE_TYPE);
289     int res = stub_->OnRemoteRequest(code, data, reply, option);
290     EXPECT_EQ(res, 0);
291 }
292 
293 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest14, Function | SmallTest | Level2)
294 {
295     MessageParcel data;
296     MessageParcel reply;
297     MessageOption option;
298 
299     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
300 
301     VisibleWindowNumInfo oneNum;
302     oneNum.displayId = 0;
303     oneNum.visibleWindowNum = 3;
304     std::vector<VisibleWindowNumInfo> visibleWindowNumInfo;
305     visibleWindowNumInfo.push_back(oneNum);
306     MarshallingHelper::MarshallingVectorObj<VisibleWindowNumInfo>(data, visibleWindowNumInfo,
__anone81704ed0302(Parcel& parcel, const VisibleWindowNumInfo& num) 307         [](Parcel& parcel, const VisibleWindowNumInfo& num) {
308             return parcel.WriteUint32(num.displayId) && parcel.WriteUint32(num.visibleWindowNum);
309         }
310     );
311 
312     uint32_t code = static_cast<uint32_t>(
313         IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_VISIBLE_WINDOW_NUM);
314 
315     int res = stub_->OnRemoteRequest(code, data, reply, option);
316     EXPECT_EQ(res, 0);
317 }
318 
319 /**
320  * @tc.name: OnRemoteRequest15
321  * @tc.desc: test TRANS_ID_UPDATE_WINDOW_DRAWING_STATE
322  * @tc.type: FUNC
323  */
324 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest15, Function | SmallTest | Level2)
325 {
326     MessageParcel data;
327     MessageParcel reply;
328     MessageOption option;
329 
330     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
331     uint32_t code = static_cast<uint32_t>(
332         IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_DRAWING_STATE);
333     ASSERT_NE(stub_, nullptr);
334     int res = stub_->OnRemoteRequest(code, data, reply, option);
335     EXPECT_EQ(res, 0);
336 }
337 
338 /**
339  * @tc.name: OnRemoteRequest16
340  * @tc.desc: test TRANS_ID_UPDATE_CAMERA_FLOAT
341  * @tc.type: FUNC
342  */
343 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest16, Function | SmallTest | Level2)
344 {
345     MessageParcel data;
346     MessageParcel reply;
347     MessageOption option;
348 
349     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
350     data.WriteUint8(static_cast<uint8_t>(1));
351     data.WriteBool(true);
352     uint32_t code = static_cast<uint32_t>(
353         IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_FLOAT);
354     ASSERT_NE(stub_, nullptr);
355     int res = stub_->OnRemoteRequest(code, data, reply, option);
356     EXPECT_EQ(res, 0);
357 }
358 
359 /**
360  * @tc.name: OnRemoteRequest17
361  * @tc.desc: test TRANS_ID_UPDATE_CAMERA_WINDOW_STATUS
362  * @tc.type: FUNC
363  */
364 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest17, Function | SmallTest | Level2)
365 {
366     MessageParcel data;
367     MessageParcel reply;
368     MessageOption option;
369 
370     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
371     data.WriteUint8(static_cast<uint8_t>(1));
372     data.WriteBool(true);
373     uint32_t code = static_cast<uint32_t>(
374         IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_WINDOW_STATUS);
375     ASSERT_NE(stub_, nullptr);
376     int res = stub_->OnRemoteRequest(code, data, reply, option);
377     EXPECT_EQ(res, 0);
378 }
379 
380 /**
381  * @tc.name: OnRemoteRequest18
382  * @tc.desc: test default
383  * @tc.type: FUNC
384  */
385 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest18, Function | SmallTest | Level2)
386 {
387     MessageParcel data;
388     MessageParcel reply;
389     MessageOption option;
390 
391     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
392     uint32_t code = static_cast<uint32_t>(12);
393     ASSERT_NE(stub_, nullptr);
394     int res = stub_->OnRemoteRequest(code, data, reply, option);
395     EXPECT_EQ(res, static_cast<int>(ERR_NONE));
396 }
397 
398 /**
399  * @tc.name: OnRemoteRequest19
400  * @tc.desc: test TRANS_ID_UPDATE_WINDOW_STYLE_TYPE success
401  * @tc.type: FUNC
402  */
403 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest19, Function | SmallTest | Level2)
404 {
405     MessageParcel data;
406     MessageParcel reply;
407     MessageOption option;
408     data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
409     uint32_t code = static_cast<uint32_t>(
410         IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STYLE_TYPE);
411     int res = stub_->OnRemoteRequest(code, data, reply, option);
412     EXPECT_EQ(res, 0);
413 }
414 }
415 }
416 }
417