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