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