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_proxy.h"
18
19 #include "window_agent.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23 namespace OHOS {
24 namespace Rosen {
25 class WindowProxyTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp() override;
30 void TearDown() override;
31 sptr<WindowAgent> mockWindowAgent_;
32 sptr<WindowProxy> windowProxy_;
33 };
34
SetUpTestCase()35 void WindowProxyTest::SetUpTestCase() {}
36
TearDownTestCase()37 void WindowProxyTest::TearDownTestCase() {}
38
SetUp()39 void WindowProxyTest::SetUp()
40 {
41 sptr<WindowOption> option = new WindowOption();
42 sptr<WindowImpl> window = new WindowImpl(option);
43 mockWindowAgent_ = new WindowAgent(window);
44 windowProxy_ = new WindowProxy(mockWindowAgent_);
45 }
46
TearDown()47 void WindowProxyTest::TearDown() {}
48
49 namespace {
50 /**
51 * @tc.name: UpdateWindowRect01
52 * @tc.desc: normal function
53 * @tc.type: FUNC
54 */
55 HWTEST_F(WindowProxyTest, UpdateWindowRect01, Function | SmallTest | Level2)
56 {
57 WMError err = windowProxy_->UpdateWindowRect(Rect{ 0, 0, 0, 0 }, false, WindowSizeChangeReason::HIDE);
58 ASSERT_EQ(err, WMError::WM_OK);
59 }
60
61 /**
62 * @tc.name: UpdateWindowMode01
63 * @tc.desc: normal function
64 * @tc.type: FUNC
65 */
66 HWTEST_F(WindowProxyTest, UpdateWindowMode01, Function | SmallTest | Level2)
67 {
68 WMError err = windowProxy_->UpdateWindowMode(WindowMode::WINDOW_MODE_FLOATING);
69 ASSERT_EQ(err, WMError::WM_OK);
70 }
71
72 /**
73 * @tc.name: UpdateWindowModeSupportType01
74 * @tc.desc: normal function
75 * @tc.type: FUNC
76 */
77 HWTEST_F(WindowProxyTest, UpdateWindowModeSupportType01, Function | SmallTest | Level2)
78 {
79 WMError err = windowProxy_->UpdateWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY);
80 ASSERT_EQ(err, WMError::WM_OK);
81 }
82
83 /**
84 * @tc.name: UpdateFocusStatus01
85 * @tc.desc: normal function
86 * @tc.type: FUNC
87 */
88 HWTEST_F(WindowProxyTest, UpdateFocusStatus01, Function | SmallTest | Level2)
89 {
90 WMError err = windowProxy_->UpdateFocusStatus(false);
91 ASSERT_EQ(err, WMError::WM_OK);
92 }
93
94 /**
95 * @tc.name: UpdateAvoidArea01
96 * @tc.desc: normal function
97 * @tc.type: FUNC
98 */
99 HWTEST_F(WindowProxyTest, UpdateAvoidArea01, Function | SmallTest | Level2)
100 {
101 const sptr<AvoidArea>& avoidArea = new AvoidArea();
102 WMError err = windowProxy_->UpdateAvoidArea(avoidArea, AvoidAreaType::TYPE_SYSTEM);
103 ASSERT_EQ(err, WMError::WM_OK);
104 }
105
106 /**
107 * @tc.name: UpdateWindowState01
108 * @tc.desc: normal function
109 * @tc.type: FUNC
110 */
111 HWTEST_F(WindowProxyTest, UpdateWindowState01, Function | SmallTest | Level2)
112 {
113 WMError err = windowProxy_->UpdateWindowState(WindowState::STATE_BOTTOM);
114 ASSERT_EQ(err, WMError::WM_OK);
115 }
116
117 /**
118 * @tc.name: UpdateWindowDragInfo01
119 * @tc.desc: normal function
120 * @tc.type: FUNC
121 */
122 HWTEST_F(WindowProxyTest, UpdateWindowDragInfo01, Function | SmallTest | Level2)
123 {
124 PointInfo point;
125 point.x = 1;
126 point.y = 2;
127 WMError err = windowProxy_->UpdateWindowDragInfo(point, DragEvent::DRAG_EVENT_MOVE);
128 ASSERT_EQ(err, WMError::WM_OK);
129 }
130
131 /**
132 * @tc.name: UpdateDisplayId01
133 * @tc.desc: normal function
134 * @tc.type: FUNC
135 */
136 HWTEST_F(WindowProxyTest, UpdateDisplayId01, Function | SmallTest | Level2)
137 {
138 WMError err = windowProxy_->UpdateDisplayId(0, 1);
139 ASSERT_EQ(err, WMError::WM_OK);
140 }
141
142 /**
143 * @tc.name: UpdateOccupiedAreaChangeInfo01
144 * @tc.desc: normal function
145 * @tc.type: FUNC
146 */
147 HWTEST_F(WindowProxyTest, UpdateOccupiedAreaChangeInfo01, Function | SmallTest | Level2)
148 {
149 Rect overlapRect = { 0, 0, 0, 0 };
150 sptr<OccupiedAreaChangeInfo> info = new OccupiedAreaChangeInfo(OccupiedAreaType::TYPE_INPUT, overlapRect);
151 WMError err = windowProxy_->UpdateOccupiedAreaChangeInfo(info);
152 ASSERT_EQ(err, WMError::WM_OK);
153 }
154
155 /**
156 * @tc.name: UpdateActiveStatus01
157 * @tc.desc: normal function
158 * @tc.type: FUNC
159 */
160 HWTEST_F(WindowProxyTest, UpdateActiveStatus01, Function | SmallTest | Level2)
161 {
162 WMError err = windowProxy_->UpdateActiveStatus(false);
163 ASSERT_EQ(err, WMError::WM_OK);
164 }
165
166 /**
167 * @tc.name: NotifyTouchOutside01
168 * @tc.desc: normal function
169 * @tc.type: FUNC
170 */
171 HWTEST_F(WindowProxyTest, NotifyTouchOutside01, Function | SmallTest | Level2)
172 {
173 WMError err = windowProxy_->NotifyTouchOutside();
174 ASSERT_EQ(err, WMError::WM_OK);
175 }
176
177 /**
178 * @tc.name: DumpInfo01
179 * @tc.desc: normal function
180 * @tc.type: FUNC
181 */
182 HWTEST_F(WindowProxyTest, DumpInfo01, Function | SmallTest | Level2)
183 {
184 std::vector<std::string> params;
185 WMError err = windowProxy_->DumpInfo(params);
186 ASSERT_EQ(err, WMError::WM_OK);
187 }
188
189 /**
190 * @tc.name: NotifyDestroy01
191 * @tc.desc: normal function
192 * @tc.type: FUNC
193 */
194 HWTEST_F(WindowProxyTest, NotifyDestroy01, Function | SmallTest | Level2)
195 {
196 WMError err = windowProxy_->NotifyDestroy();
197 ASSERT_EQ(err, WMError::WM_OK);
198 }
199
200 /**
201 * @tc.name: NotifyForeground01
202 * @tc.desc: normal function
203 * @tc.type: FUNC
204 */
205 HWTEST_F(WindowProxyTest, NotifyForeground01, Function | SmallTest | Level2)
206 {
207 WMError err = windowProxy_->NotifyForeground();
208 ASSERT_EQ(err, WMError::WM_OK);
209 }
210
211 /**
212 * @tc.name: NotifyBackground01
213 * @tc.desc: normal function
214 * @tc.type: FUNC
215 */
216 HWTEST_F(WindowProxyTest, NotifyBackground01, Function | SmallTest | Level2)
217 {
218 WMError err = windowProxy_->NotifyBackground();
219 ASSERT_EQ(err, WMError::WM_OK);
220 }
221
222 /**
223 * @tc.name: NotifyWindowClientPointUp01
224 * @tc.desc: param is nullptr
225 * @tc.type: FUNC
226 */
227 HWTEST_F(WindowProxyTest, NotifyWindowClientPointUp01, Function | SmallTest | Level2)
228 {
229 WMError err = windowProxy_->NotifyWindowClientPointUp(nullptr);
230 ASSERT_EQ(err, WMError::WM_ERROR_NULLPTR);
231 }
232
233 /**
234 * @tc.name: NotifyWindowClientPointUp02
235 * @tc.desc: normal function
236 * @tc.type: FUNC
237 */
238 HWTEST_F(WindowProxyTest, NotifyWindowClientPointUp02, Function | SmallTest | Level2)
239 {
240 auto pointerEvent = MMI::PointerEvent::Create();
241 WMError err = windowProxy_->NotifyWindowClientPointUp(pointerEvent);
242 ASSERT_EQ(err, WMError::WM_OK);
243 }
244
245 /**
246 * @tc.name: UpdateZoomTransform01
247 * @tc.desc: normal function
248 * @tc.type: FUNC
249 */
250 HWTEST_F(WindowProxyTest, UpdateZoomTransform01, Function | SmallTest | Level2)
251 {
252 Transform transform;
253 WMError err = windowProxy_->UpdateZoomTransform(transform, false);
254 ASSERT_EQ(err, WMError::WM_OK);
255 }
256
257 /**
258 * @tc.name: RestoreSplitWindowMode01
259 * @tc.desc: normal function
260 * @tc.type: FUNC
261 */
262 HWTEST_F(WindowProxyTest, RestoreSplitWindowMode01, Function | SmallTest | Level2)
263 {
264 WMError err = windowProxy_->RestoreSplitWindowMode(200);
265 ASSERT_EQ(err, WMError::WM_OK);
266 }
267
268 /**
269 * @tc.name: NotifyScreenshot
270 * @tc.desc: normal function
271 * @tc.type: FUNC
272 */
273 HWTEST_F(WindowProxyTest, NotifyScreenshot, Function | SmallTest | Level2)
274 {
275 WMError err = windowProxy_->NotifyScreenshot();
276 ASSERT_EQ(err, WMError::WM_OK);
277 }
278
279 /**
280 * @tc.name: NotifyForegroundInteractiveStatus
281 * @tc.desc: normal function
282 * @tc.type: FUNC
283 */
284 HWTEST_F(WindowProxyTest, NotifyForegroundInteractiveStatus, Function | SmallTest | Level2)
285 {
286 ASSERT_NE(windowProxy_, nullptr);
287 WMError err = WMError::WM_OK;
288 bool interactive = false;
289 windowProxy_->NotifyForegroundInteractiveStatus(interactive);
290 ASSERT_EQ(err, WMError::WM_OK);
291 }
292
293 } // namespace
294 } // namespace Rosen
295 } // namespace OHOS
296