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 <transaction/rs_sync_transaction_controller.h>
18
19 #include "window_stub.h"
20 #include "window_agent.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace Rosen {
27 class WindowAgentTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp() override;
32 void TearDown() override;
33 sptr<WindowAgent> windowAgent_;
34 };
35
SetUpTestCase()36 void WindowAgentTest::SetUpTestCase()
37 {
38 }
39
TearDownTestCase()40 void WindowAgentTest::TearDownTestCase()
41 {
42 }
43
SetUp()44 void WindowAgentTest::SetUp()
45 {
46 sptr<WindowOption> option = new WindowOption();
47 sptr<WindowImpl> window = new WindowImpl(option);
48 windowAgent_ = new WindowAgent(window);
49 }
50
TearDown()51 void WindowAgentTest::TearDown()
52 {
53 windowAgent_ = nullptr;
54 }
55
56 namespace {
57 /**
58 * @tc.name: UpdateWindowRect
59 * @tc.desc: UpdateWindowRect
60 * @tc.type: FUNC
61 */
62 HWTEST_F(WindowAgentTest, UpdateWindowRect, Function | SmallTest | Level2)
63 {
64 Rect rect = Rect{0, 0, 0, 0};
65 bool status = true;
66 WMError err = windowAgent_->UpdateWindowRect(rect, status, WindowSizeChangeReason::HIDE);
67 ASSERT_EQ(err, WMError::WM_OK);
68
69 windowAgent_->window_ = nullptr;
70 err = windowAgent_->UpdateWindowRect(rect, status, WindowSizeChangeReason::HIDE);
71 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
72 }
73
74 /**
75 * @tc.name: UpdateWindowMode
76 * @tc.desc: UpdateWindowMode
77 * @tc.type: FUNC
78 */
79 HWTEST_F(WindowAgentTest, UpdateWindowMode, Function | SmallTest | Level2)
80 {
81 WMError err = windowAgent_->UpdateWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
82 ASSERT_EQ(err, WMError::WM_OK);
83
84 windowAgent_->window_ = nullptr;
85 err = windowAgent_->UpdateWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
86 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
87 }
88
89 /**
90 * @tc.name: UpdateWindowModeSupportType
91 * @tc.desc: UpdateWindowModeSupportType
92 * @tc.type: FUNC
93 */
94 HWTEST_F(WindowAgentTest, UpdateWindowModeSupportType, Function | SmallTest | Level2)
95 {
96 WMError err = windowAgent_->UpdateWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN);
97 ASSERT_EQ(err, WMError::WM_OK);
98
99 windowAgent_->window_ = nullptr;
100 err = windowAgent_->UpdateWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN);
101 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
102 }
103
104 /**
105 * @tc.name: UpdateFocusStatus
106 * @tc.desc: UpdateFocusStatus
107 * @tc.type: FUNC
108 */
109 HWTEST_F(WindowAgentTest, UpdateFocusStatus, Function | SmallTest | Level2)
110 {
111 WMError err = windowAgent_->UpdateFocusStatus(true);
112 ASSERT_EQ(err, WMError::WM_OK);
113
114 windowAgent_->window_ = nullptr;
115 err = windowAgent_->UpdateFocusStatus(true);
116 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
117 }
118
119 /**
120 * @tc.name: UpdateAvoidArea
121 * @tc.desc: UpdateAvoidArea
122 * @tc.type: FUNC
123 */
124 HWTEST_F(WindowAgentTest, UpdateAvoidArea, Function | SmallTest | Level2)
125 {
126 const sptr<AvoidArea>& avoidArea = new AvoidArea();
127 WMError err = windowAgent_->UpdateAvoidArea(avoidArea, AvoidAreaType::TYPE_SYSTEM);
128 ASSERT_EQ(err, WMError::WM_OK);
129
130 windowAgent_->window_ = nullptr;
131 err = windowAgent_->UpdateAvoidArea(avoidArea, AvoidAreaType::TYPE_SYSTEM);
132 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
133 }
134
135 /**
136 * @tc.name: UpdateWindowState
137 * @tc.desc: UpdateWindowState
138 * @tc.type: FUNC
139 */
140 HWTEST_F(WindowAgentTest, UpdateWindowState, Function | SmallTest | Level2)
141 {
142 WMError err = windowAgent_->UpdateWindowState(WindowState::STATE_BOTTOM);
143 ASSERT_EQ(err, WMError::WM_OK);
144
145 windowAgent_->window_ = nullptr;
146 err = windowAgent_->UpdateWindowState(WindowState::STATE_SHOWN);
147 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
148 }
149
150 /**
151 * @tc.name: UpdateWindowDragInfo
152 * @tc.desc: UpdateWindowDragInfo
153 * @tc.type: FUNC
154 */
155 HWTEST_F(WindowAgentTest, UpdateWindowDragInfo, Function | SmallTest | Level2)
156 {
157 PointInfo point;
158 point.x = 1;
159 point.y = 2;
160 WMError err = windowAgent_->UpdateWindowDragInfo(point, DragEvent::DRAG_EVENT_MOVE);
161 ASSERT_EQ(err, WMError::WM_OK);
162
163 windowAgent_->window_ = nullptr;
164 err = windowAgent_->UpdateWindowDragInfo(point, DragEvent::DRAG_EVENT_MOVE);
165 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
166 }
167
168 /**
169 * @tc.name: UpdateDisplayId
170 * @tc.desc: UpdateDisplayId
171 * @tc.type: FUNC
172 */
173 HWTEST_F(WindowAgentTest, UpdateDisplayId, Function | SmallTest | Level2)
174 {
175 WMError err = windowAgent_->UpdateDisplayId(0, 1);
176 ASSERT_EQ(err, WMError::WM_OK);
177
178 windowAgent_->window_ = nullptr;
179 err = windowAgent_->UpdateDisplayId(0, 1);
180 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
181 }
182
183 /**
184 * @tc.name: UpdateOccupiedAreaChangeInfo
185 * @tc.desc: UpdateOccupiedAreaChangeInfo
186 * @tc.type: FUNC
187 */
188 HWTEST_F(WindowAgentTest, UpdateOccupiedAreaChangeInfo, Function | SmallTest | Level2)
189 {
190 Rect overlapRect = {0, 0, 0, 0};
191 sptr<OccupiedAreaChangeInfo> info = new OccupiedAreaChangeInfo(OccupiedAreaType::TYPE_INPUT, overlapRect);
192 WMError err = windowAgent_->UpdateOccupiedAreaChangeInfo(info);
193 ASSERT_EQ(err, WMError::WM_OK);
194
195 windowAgent_->window_ = nullptr;
196 err = windowAgent_->UpdateOccupiedAreaChangeInfo(info);
197 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
198 }
199
200 /**
201 * @tc.name: UpdateOccupiedAreaAndRect
202 * @tc.desc: UpdateOccupiedAreaAndRect
203 * @tc.type: FUNC
204 */
205 HWTEST_F(WindowAgentTest, UpdateOccupiedAreaAndRect, Function | SmallTest | Level2)
206 {
207 Rect overlapRect = {0, 0, 0, 0};
208 sptr<OccupiedAreaChangeInfo> info = new OccupiedAreaChangeInfo(OccupiedAreaType::TYPE_INPUT, overlapRect);
209 auto syncTransactionController = RSSyncTransactionController::GetInstance();
210
211 WMError err = windowAgent_->UpdateOccupiedAreaAndRect(
212 info, overlapRect, syncTransactionController->GetRSTransaction());
213 ASSERT_EQ(err, WMError::WM_OK);
214
215 windowAgent_->window_ = nullptr;
216 err = windowAgent_->UpdateOccupiedAreaAndRect(info, overlapRect, syncTransactionController->GetRSTransaction());
217 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
218 }
219
220 /**
221 * @tc.name: UpdateActiveStatus
222 * @tc.desc: UpdateActiveStatus
223 * @tc.type: FUNC
224 */
225 HWTEST_F(WindowAgentTest, UpdateActiveStatus, Function | SmallTest | Level2)
226 {
227 WMError err = windowAgent_->UpdateActiveStatus(false);
228 ASSERT_EQ(err, WMError::WM_OK);
229
230 windowAgent_->window_ = nullptr;
231 err = windowAgent_->UpdateActiveStatus(false);
232 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
233 }
234
235 /**
236 * @tc.name: GetWindowProperty
237 * @tc.desc: GetWindowProperty
238 * @tc.type: FUNC
239 */
240 HWTEST_F(WindowAgentTest, GetWindowProperty, Function | SmallTest | Level2)
241 {
242 auto windowProperty = windowAgent_->GetWindowProperty();
243 ASSERT_NE(windowProperty, nullptr);
244
245 windowAgent_->window_ = nullptr;
246 windowProperty = windowAgent_->GetWindowProperty();
247 ASSERT_EQ(windowProperty, nullptr);
248 }
249
250 /**
251 * @tc.name: RestoreSplitWindowMode
252 * @tc.desc: RestoreSplitWindowMode
253 * @tc.type: FUNC
254 */
255 HWTEST_F(WindowAgentTest, RestoreSplitWindowMode, Function | SmallTest | Level2)
256 {
257 WMError err = windowAgent_->RestoreSplitWindowMode(static_cast<uint32_t>(WindowMode::WINDOW_MODE_SPLIT_PRIMARY));
258 ASSERT_EQ(err, WMError::WM_OK);
259
260 windowAgent_->window_ = nullptr;
261 err = windowAgent_->RestoreSplitWindowMode(static_cast<uint32_t>(WindowMode::WINDOW_MODE_SPLIT_PRIMARY));
262 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
263 }
264
265 /**
266 * @tc.name: NotifyTouchOutside
267 * @tc.desc: NotifyTouchOutside
268 * @tc.type: FUNC
269 */
270 HWTEST_F(WindowAgentTest, NotifyTouchOutside, Function | SmallTest | Level2)
271 {
272 WMError err = windowAgent_->NotifyTouchOutside();
273 ASSERT_EQ(err, WMError::WM_OK);
274
275 windowAgent_->window_ = nullptr;
276 err = windowAgent_->NotifyTouchOutside();
277 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
278 }
279
280 /**
281 * @tc.name: NotifyScreenshot
282 * @tc.desc: NotifyScreenshot
283 * @tc.type: FUNC
284 */
285 HWTEST_F(WindowAgentTest, NotifyScreenshot, Function | SmallTest | Level2)
286 {
287 WMError err = windowAgent_->NotifyScreenshot();
288 ASSERT_EQ(err, WMError::WM_OK);
289
290 windowAgent_->window_ = nullptr;
291 err = windowAgent_->NotifyScreenshot();
292 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
293 }
294
295 /**
296 * @tc.name: DumpInfo
297 * @tc.desc: DumpInfo
298 * @tc.type: FUNC
299 */
300 HWTEST_F(WindowAgentTest, DumpInfo, Function | SmallTest | Level2)
301 {
302 std::vector<std::string> params;
303 WMError err = windowAgent_->DumpInfo(params);
304 ASSERT_EQ(err, WMError::WM_OK);
305
306 windowAgent_->window_ = nullptr;
307 err = windowAgent_->DumpInfo(params);
308 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
309 }
310
311 /**
312 * @tc.name: UpdateZoomTransform
313 * @tc.desc: UpdateZoomTransform
314 * @tc.type: FUNC
315 */
316 HWTEST_F(WindowAgentTest, UpdateZoomTransform, Function | SmallTest | Level2)
317 {
318 Transform transform;
319 WMError err = windowAgent_->UpdateZoomTransform(transform, false);
320 ASSERT_EQ(err, WMError::WM_OK);
321
322 windowAgent_->window_ = nullptr;
323 err = windowAgent_->UpdateZoomTransform(transform, false);
324 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
325 }
326
327 /**
328 * @tc.name: NotifyDestroy
329 * @tc.desc: NotifyDestroy
330 * @tc.type: FUNC
331 */
332 HWTEST_F(WindowAgentTest, NotifyDestroy, Function | SmallTest | Level2)
333 {
334 WMError err = windowAgent_->NotifyDestroy();
335 ASSERT_EQ(err, WMError::WM_OK);
336
337 windowAgent_->window_ = nullptr;
338 err = windowAgent_->NotifyDestroy();
339 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
340 }
341
342 /**
343 * @tc.name: NotifyForeground
344 * @tc.desc: NotifyForeground
345 * @tc.type: FUNC
346 */
347 HWTEST_F(WindowAgentTest, NotifyForeground, Function | SmallTest | Level2)
348 {
349 WMError err = windowAgent_->NotifyForeground();
350 ASSERT_EQ(err, WMError::WM_OK);
351
352 windowAgent_->window_ = nullptr;
353 err = windowAgent_->NotifyForeground();
354 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
355 }
356
357 /**
358 * @tc.name: NotifyBackground
359 * @tc.desc: NotifyBackground
360 * @tc.type: FUNC
361 */
362 HWTEST_F(WindowAgentTest, NotifyBackground, Function | SmallTest | Level2)
363 {
364 WMError err = windowAgent_->NotifyBackground();
365 ASSERT_EQ(err, WMError::WM_OK);
366
367 windowAgent_->window_ = nullptr;
368 err = windowAgent_->NotifyBackground();
369 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
370 }
371
372 /**
373 * @tc.name: NotifyWindowClientPointUp
374 * @tc.desc: NotifyWindowClientPointUp
375 * @tc.type: FUNC
376 */
377 HWTEST_F(WindowAgentTest, NotifyWindowClientPointUp, Function | SmallTest | Level2)
378 {
379 auto pointerEvent = MMI::PointerEvent::Create();
380 WMError err = windowAgent_->NotifyWindowClientPointUp(pointerEvent);
381 ASSERT_EQ(err, WMError::WM_OK);
382
383 windowAgent_->window_ = nullptr;
384 err = windowAgent_->NotifyWindowClientPointUp(pointerEvent);
385 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
386 }
387
388 /**
389 * @tc.name: ConsumeKeyEvent
390 * @tc.desc: ConsumeKeyEvent
391 * @tc.type: FUNC
392 */
393 HWTEST_F(WindowAgentTest, ConsumeKeyEvent, Function | SmallTest | Level2)
394 {
395 auto res = 0;
396 auto keyEvent = MMI::KeyEvent::Create();
397 windowAgent_->ConsumeKeyEvent(keyEvent);
398 ASSERT_EQ(0, res);
399
400 windowAgent_->window_ = nullptr;
401 windowAgent_->ConsumeKeyEvent(keyEvent);
402 ASSERT_EQ(0, res);
403 }
404
405 /**
406 * @tc.name: NotifyForegroundInteractiveStatus
407 * @tc.desc: NotifyForegroundInteractiveStatus
408 * @tc.type: FUNC
409 */
410 HWTEST_F(WindowAgentTest, NotifyForegroundInteractiveStatus, Function | SmallTest | Level2)
411 {
412 auto res = 0;
413 bool interactive = false;
414 windowAgent_->NotifyForegroundInteractiveStatus(interactive);
415 ASSERT_EQ(0, res);
416
417 interactive = true;
418 windowAgent_->window_ = nullptr;
419 windowAgent_->NotifyForegroundInteractiveStatus(interactive);
420 ASSERT_EQ(0, res);
421 }
422
423 }
424 }
425 }