1 /*
2 * Copyright (c) 2022-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_stub_impl.h"
18
19 using namespace testing;
20 using namespace testing::ext;
21 namespace OHOS {
22 namespace Rosen {
23 class WindowManagerStubTest : public testing::Test {
24 public:
25 static void SetUpTestCase();
26 static void TearDownTestCase();
27 void SetUp() override;
28 void TearDown() override;
29 sptr<WindowManagerStub> stub_;
30 };
31
SetUpTestCase()32 void WindowManagerStubTest::SetUpTestCase()
33 {
34 }
35
TearDownTestCase()36 void WindowManagerStubTest::TearDownTestCase()
37 {
38 }
39
SetUp()40 void WindowManagerStubTest::SetUp()
41 {
42 stub_ = new WindowManagerStubImpl();
43 }
44
TearDown()45 void WindowManagerStubTest::TearDown()
46 {
47 }
48
49 namespace {
50 /**
51 * @tc.name: OnRemoteRequest01
52 * @tc.desc: test InterfaceToken check failed
53 * @tc.type: FUNC
54 */
55 HWTEST_F(WindowManagerStubTest, OnRemoteRequest01, Function | SmallTest | Level2)
56 {
57 MessageParcel data;
58 MessageParcel reply;
59 MessageOption option;
60
61 data.WriteInterfaceToken(u"error.GetDescriptor");
62
63 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_CREATE_WINDOW);
64
65 int res = stub_->OnRemoteRequest(code, data, reply, option);
66 EXPECT_EQ(res, -1);
67 }
68
69 /**
70 * @tc.name: OnRemoteRequest02
71 * @tc.desc: test TRANS_ID_REMOVE_WINDOW
72 * @tc.type: FUNC
73 */
74 HWTEST_F(WindowManagerStubTest, OnRemoteRequest02, Function | SmallTest | Level2)
75 {
76 MessageParcel data;
77 MessageParcel reply;
78 MessageOption option;
79
80 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
81
82 data.WriteUint32(1);
83
84 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_REMOVE_WINDOW);
85
86 int res = stub_->OnRemoteRequest(code, data, reply, option);
87 EXPECT_EQ(res, 0);
88 }
89
90 /**
91 * @tc.name: OnRemoteRequest03
92 * @tc.desc: test TRANS_ID_REQUEST_FOCUS success
93 * @tc.type: FUNC
94 */
95 HWTEST_F(WindowManagerStubTest, OnRemoteRequest03, Function | SmallTest | Level2)
96 {
97 MessageParcel data;
98 MessageParcel reply;
99 MessageOption option;
100
101 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
102 data.WriteUint32(1);
103
104 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_REQUEST_FOCUS);
105
106 int res = stub_->OnRemoteRequest(code, data, reply, option);
107 EXPECT_EQ(res, 0);
108 }
109
110 /**
111 * @tc.name: OnRemoteRequest04
112 * @tc.desc: test TRANS_ID_GET_AVOID_AREA success
113 * @tc.type: FUNC
114 */
115 HWTEST_F(WindowManagerStubTest, OnRemoteRequest04, Function | SmallTest | Level2)
116 {
117 MessageParcel data;
118 MessageParcel reply;
119 MessageOption option;
120
121 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
122 data.WriteUint32(1);
123 data.WriteUint32(static_cast<uint32_t>(AvoidAreaType::TYPE_CUTOUT));
124
125 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_GET_AVOID_AREA);
126
127 int res = stub_->OnRemoteRequest(code, data, reply, option);
128 EXPECT_EQ(res, 0);
129 }
130
131 /**
132 * @tc.name: OnRemoteRequest05
133 * @tc.desc: test TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT success
134 * @tc.type: FUNC
135 */
136 HWTEST_F(WindowManagerStubTest, OnRemoteRequest05, Function | SmallTest | Level2)
137 {
138 MessageParcel data;
139 MessageParcel reply;
140 MessageOption option;
141
142 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
143 data.WriteUint32(static_cast<uint32_t>(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT));
144 sptr<IWindowManagerAgent> focusChangedListenerAgent = new WindowManagerAgent();
145 data.WriteRemoteObject(focusChangedListenerAgent->AsObject());
146
147 uint32_t code =
148 static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT);
149
150 int res = stub_->OnRemoteRequest(code, data, reply, option);
151 EXPECT_EQ(res, 0);
152 }
153
154 /**
155 * @tc.name: OnRemoteRequest06
156 * @tc.desc: test TRANS_ID_NOTIFY_READY_MOVE_OR_DRAG success
157 * @tc.type: FUNC
158 */
159 HWTEST_F(WindowManagerStubTest, OnRemoteRequest06, Function | SmallTest | Level2)
160 {
161 MessageParcel data;
162 MessageParcel reply;
163 MessageOption option;
164
165 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
166 data.WriteUint32(1);
167 sptr<WindowProperty> windowProperty = new WindowProperty();
168 data.WriteParcelable(windowProperty.GetRefPtr());
169 sptr<MoveDragProperty> moveDragProperty = new MoveDragProperty();
170 data.WriteParcelable(moveDragProperty.GetRefPtr());
171
172 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_NOTIFY_READY_MOVE_OR_DRAG);
173
174 int res = stub_->OnRemoteRequest(code, data, reply, option);
175 EXPECT_EQ(res, 0);
176 }
177
178 /**
179 * @tc.name: OnRemoteRequest07
180 * @tc.desc: test TRANS_ID_PROCESS_POINT_DOWN success
181 * @tc.type: FUNC
182 */
183 HWTEST_F(WindowManagerStubTest, OnRemoteRequest07, Function | SmallTest | Level2)
184 {
185 MessageParcel data;
186 MessageParcel reply;
187 MessageOption option;
188
189 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
190 data.WriteUint32(1);
191
192 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_PROCESS_POINT_DOWN);
193
194 int res = stub_->OnRemoteRequest(code, data, reply, option);
195 EXPECT_EQ(res, 0);
196 }
197
198 /**
199 * @tc.name: OnRemoteRequest08
200 * @tc.desc: test TRANS_ID_PROCESS_POINT_UP success
201 * @tc.type: FUNC
202 */
203 HWTEST_F(WindowManagerStubTest, OnRemoteRequest08, Function | SmallTest | Level2)
204 {
205 MessageParcel data;
206 MessageParcel reply;
207 MessageOption option;
208
209 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
210 data.WriteUint32(1);
211
212 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_PROCESS_POINT_UP);
213
214 int res = stub_->OnRemoteRequest(code, data, reply, option);
215 EXPECT_EQ(res, 0);
216 }
217
218 /**
219 * @tc.name: OnRemoteRequest09
220 * @tc.desc: test TRANS_ID_GET_TOP_WINDOW_ID success
221 * @tc.type: FUNC
222 */
223 HWTEST_F(WindowManagerStubTest, OnRemoteRequest09, Function | SmallTest | Level2)
224 {
225 MessageParcel data;
226 MessageParcel reply;
227 MessageOption option;
228
229 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
230 data.WriteUint32(1);
231
232 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_GET_TOP_WINDOW_ID);
233
234 int res = stub_->OnRemoteRequest(code, data, reply, option);
235 EXPECT_EQ(res, 0);
236 }
237
238 /**
239 * @tc.name: OnRemoteRequest10
240 * @tc.desc: test TRANS_ID_MINIMIZE_ALL_APP_WINDOWS success
241 * @tc.type: FUNC
242 */
243 HWTEST_F(WindowManagerStubTest, OnRemoteRequest10, Function | SmallTest | Level2)
244 {
245 MessageParcel data;
246 MessageParcel reply;
247 MessageOption option;
248
249 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
250 data.WriteUint32(0);
251
252 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_MINIMIZE_ALL_APP_WINDOWS);
253
254 int res = stub_->OnRemoteRequest(code, data, reply, option);
255 EXPECT_EQ(res, 0);
256 }
257
258 /**
259 * @tc.name: OnRemoteRequest11
260 * @tc.desc: test TRANS_ID_TOGGLE_SHOWN_STATE_FOR_ALL_APP_WINDOWS success
261 * @tc.type: FUNC
262 */
263 HWTEST_F(WindowManagerStubTest, OnRemoteRequest11, Function | SmallTest | Level2)
264 {
265 MessageParcel data;
266 MessageParcel reply;
267 MessageOption option;
268
269 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
270
271 uint32_t code =
272 static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_TOGGLE_SHOWN_STATE_FOR_ALL_APP_WINDOWS);
273
274 int res = stub_->OnRemoteRequest(code, data, reply, option);
275 EXPECT_EQ(res, 0);
276 }
277
278 /**
279 * @tc.name: OnRemoteRequest12
280 * @tc.desc: test TRANS_ID_UPDATE_LAYOUT_MODE success
281 * @tc.type: FUNC
282 */
283 HWTEST_F(WindowManagerStubTest, OnRemoteRequest12, Function | SmallTest | Level2)
284 {
285 MessageParcel data;
286 MessageParcel reply;
287 MessageOption option;
288
289 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
290 data.WriteUint32(static_cast<uint32_t>(WindowLayoutMode::CASCADE));
291
292 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_UPDATE_LAYOUT_MODE);
293
294 int res = stub_->OnRemoteRequest(code, data, reply, option);
295 EXPECT_EQ(res, 0);
296 }
297
298 /**
299 * @tc.name: OnRemoteRequest13
300 * @tc.desc: test TRANS_ID_UPDATE_PROPERTY success
301 * @tc.type: FUNC
302 */
303 HWTEST_F(WindowManagerStubTest, OnRemoteRequest13, Function | SmallTest | Level2)
304 {
305 MessageParcel data;
306 MessageParcel reply;
307 MessageOption option;
308
309 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
310 data.WriteUint32(static_cast<uint32_t>(PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG));
311 sptr<WindowProperty> windowProperty = new WindowProperty();
312 windowProperty->Write(data, PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG);
313
314 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_UPDATE_PROPERTY);
315
316 int res = stub_->OnRemoteRequest(code, data, reply, option);
317 EXPECT_EQ(res, 0);
318 }
319
320 /**
321 * @tc.name: OnRemoteRequest14
322 * @tc.desc: test TRANS_ID_ANIMATION_SET_CONTROLLER success
323 * @tc.type: FUNC
324 */
325 HWTEST_F(WindowManagerStubTest, OnRemoteRequest14, Function | SmallTest | Level2)
326 {
327 MessageParcel data;
328 MessageParcel reply;
329 MessageOption option;
330
331 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
332
333 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_ANIMATION_SET_CONTROLLER);
334
335 int res = stub_->OnRemoteRequest(code, data, reply, option);
336 EXPECT_EQ(res, 0);
337 }
338
339 /**
340 * @tc.name: OnRemoteRequest15
341 * @tc.desc: test TRANS_ID_NOTIFY_WINDOW_TRANSITION success
342 * @tc.type: FUNC
343 */
344 HWTEST_F(WindowManagerStubTest, OnRemoteRequest15, Function | SmallTest | Level2)
345 {
346 MessageParcel data;
347 MessageParcel reply;
348 MessageOption option;
349
350 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
351 sptr<WindowTransitionInfo> from = new WindowTransitionInfo();
352 sptr<WindowTransitionInfo> to = new WindowTransitionInfo();
353 data.WriteParcelable(from);
354 data.WriteParcelable(to);
355 data.WriteBool(false);
356
357 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_NOTIFY_WINDOW_TRANSITION);
358
359 int res = stub_->OnRemoteRequest(code, data, reply, option);
360 EXPECT_EQ(res, 0);
361 }
362
363 /**
364 * @tc.name: OnRemoteRequest16
365 * @tc.desc: test TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE success
366 * @tc.type: FUNC
367 */
368 HWTEST_F(WindowManagerStubTest, OnRemoteRequest16, Function | SmallTest | Level2)
369 {
370 MessageParcel data;
371 MessageParcel reply;
372 MessageOption option;
373
374 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
375 DisplayId displayId = 0;
376 data.WriteUint64(displayId);
377
378 uint32_t code =
379 static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE);
380
381 int res = stub_->OnRemoteRequest(code, data, reply, option);
382 EXPECT_EQ(res, 0);
383 }
384
385 /**
386 * @tc.name: OnRemoteRequest17
387 * @tc.desc: test TRANS_ID_GET_ANIMATION_CALLBACK success
388 * @tc.type: FUNC
389 */
390 HWTEST_F(WindowManagerStubTest, OnRemoteRequest17, Function | SmallTest | Level2)
391 {
392 MessageParcel data;
393 MessageParcel reply;
394 MessageOption option;
395
396 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
397 std::vector<uint32_t> windowIds;
398 windowIds.emplace_back(1);
399 windowIds.emplace_back(10);
400 bool isAnimated = false;
401 data.WriteUInt32Vector(windowIds);
402 data.WriteBool(isAnimated);
403
404 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_GET_ANIMATION_CALLBACK);
405
406 int res = stub_->OnRemoteRequest(code, data, reply, option);
407 EXPECT_EQ(res, 0);
408 }
409
410 /**
411 * @tc.name: OnRemoteRequest18
412 * @tc.desc: test TRANS_ID_UPDATE_RS_TREE success
413 * @tc.type: FUNC
414 */
415 HWTEST_F(WindowManagerStubTest, OnRemoteRequest18, Function | SmallTest | Level2)
416 {
417 MessageParcel data;
418 MessageParcel reply;
419 MessageOption option;
420
421 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
422 uint32_t windowId = 1;
423 bool isAdd = false;
424 data.WriteUint32(windowId);
425 data.WriteBool(isAdd);
426
427 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_UPDATE_RS_TREE);
428
429 int res = stub_->OnRemoteRequest(code, data, reply, option);
430 EXPECT_EQ(res, 0);
431 }
432
433 /**
434 * @tc.name: OnRemoteRequest19
435 * @tc.desc: test TRANS_ID_CREATE_WINDOW success
436 * @tc.type: FUNC
437 */
438 HWTEST_F(WindowManagerStubTest, OnRemoteRequest19, Function | SmallTest | Level2)
439 {
440 MessageParcel data;
441 MessageParcel reply;
442 MessageOption option;
443
444 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
445 sptr<WindowOption> windowOption = new WindowOption();
446 sptr<WindowImpl> windowImpl = new WindowImpl(windowOption);
447 sptr<IWindow> window = new WindowAgent(windowImpl);
448 sptr<WindowProperty> property = nullptr;
449 struct RSSurfaceNodeConfig surfaceNodeConfig;
450 surfaceNodeConfig.SurfaceNodeName = "SurfaceNode";
451 std::shared_ptr<RSSurfaceNode> surNode = RSSurfaceNode::Create(surfaceNodeConfig, RSSurfaceNodeType::DEFAULT);
452 sptr<IRemoteObject> token;
453
454 data.WriteRemoteObject(window->AsObject());
455 data.WriteParcelable(property.GetRefPtr());
456 surNode->Marshalling(data);
457 data.WriteRemoteObject(token);
458
459 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_CREATE_WINDOW);
460
461 int res = stub_->OnRemoteRequest(code, data, reply, option);
462 EXPECT_EQ(res, 0);
463 }
464
465 /**
466 * @tc.name: OnRemoteRequest20
467 * @tc.desc: test TRANS_ID_CREATE_WINDOW success
468 * @tc.type: FUNC
469 */
470 HWTEST_F(WindowManagerStubTest, OnRemoteRequest20, Function | SmallTest | Level2)
471 {
472 MessageParcel data;
473 MessageParcel reply;
474 MessageOption option;
475
476 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
477 sptr<WindowOption> windowOption = new WindowOption();
478 sptr<WindowImpl> windowImpl = new WindowImpl(windowOption);
479 sptr<IWindow> window = new WindowAgent(windowImpl);
480 sptr<WindowProperty> property = new WindowProperty();
481 property->SetTokenState(false);
482 struct RSSurfaceNodeConfig surfaceNodeConfig;
483 surfaceNodeConfig.SurfaceNodeName = "SurfaceNode";
484 std::shared_ptr<RSSurfaceNode> surNode = RSSurfaceNode::Create(surfaceNodeConfig, RSSurfaceNodeType::DEFAULT);
485 sptr<IRemoteObject> token;
486
487 data.WriteRemoteObject(window->AsObject());
488 data.WriteParcelable(property.GetRefPtr());
489 surNode->Marshalling(data);
490 data.WriteRemoteObject(token);
491
492 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_CREATE_WINDOW);
493
494 int res = stub_->OnRemoteRequest(code, data, reply, option);
495 EXPECT_EQ(res, 0);
496 }
497
498 /**
499 * @tc.name: OnRemoteRequest21
500 * @tc.desc: test TRANS_ID_RAISE_WINDOW_Z_ORDER success
501 * @tc.type: FUNC
502 */
503 HWTEST_F(WindowManagerStubTest, OnRemoteRequest21, Function | SmallTest | Level2)
504 {
505 MessageParcel data;
506 MessageParcel reply;
507 MessageOption option;
508
509 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
510 data.WriteUint32(100);
511
512 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_RAISE_WINDOW_Z_ORDER);
513
514 int res = stub_->OnRemoteRequest(code, data, reply, option);
515 EXPECT_EQ(res, 0);
516 }
517
518 /**
519 * @tc.name: OnRemoteRequest22
520 * @tc.desc: test TRANS_ID_RAISE_WINDOW_Z_ORDER success
521 * @tc.type: FUNC
522 */
523 HWTEST_F(WindowManagerStubTest, OnRemoteRequest22, Function | SmallTest | Level2)
524 {
525 MessageParcel data;
526 MessageParcel reply;
527 MessageOption option;
528
529 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
530 data.WriteBool(true);
531 uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_GESTURE_NAVIGATION_ENABLED);
532 int res = stub_->OnRemoteRequest(code, data, reply, option);
533 EXPECT_EQ(res, 0);
534 }
535
536 /**
537 * @tc.name: OnRemoteRequest23
538 * @tc.desc: test TRANS_ID_GET_UNRELIABLE_WINDOW_INFO_ID success
539 * @tc.type: FUNC
540 */
541 HWTEST_F(WindowManagerStubTest, OnRemoteRequest23, Function | SmallTest | Level2)
542 {
543 MessageParcel data;
544 MessageParcel reply;
545 MessageOption option;
546
547 data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
548 data.WriteInt32(0);
549 uint32_t code = static_cast<uint32_t>(
550 IWindowManager::WindowManagerMessage::TRANS_ID_GET_UNRELIABLE_WINDOW_INFO_ID);
551 int res = stub_->OnRemoteRequest(code, data, reply, option);
552 EXPECT_EQ(res, 0);
553 }
554 }
555 }
556 }
557