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