1 /*
2 * Copyright (c) 2021 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 // gtest
17 #include <gtest/gtest.h>
18
19 #include "ability_context_impl.h"
20
21 #include "mock_session.h"
22 #include "window_scene_session_impl.h"
23 #include "window_test_utils.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Rosen {
30 using Utils = WindowTestUtils;
31
32 class WindowCallbackTest : public testing::Test {
33 public:
34 void SetUp() override;
35 void TearDown() override;
36
37 private:
38 static constexpr uint32_t TEST_SLEEP_S = 1; // test sleep time
39 std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
40 };
41
SetUp()42 void WindowCallbackTest::SetUp()
43 {
44 abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
45 }
46
TearDown()47 void WindowCallbackTest::TearDown()
48 {
49 abilityContext_ = nullptr;
50 }
51
52 namespace {
53 /**
54 * @tc.name: WindowRectChange01
55 * @tc.desc: windowRectChange
56 * @tc.type: FUNC
57 */
58 HWTEST_F(WindowCallbackTest, WindowRectChange01, TestSize.Level1)
59 {
60 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
61 option->SetWindowName("Window1_1");
62 option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
63 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
64
65 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
66 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
67 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
68 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
69
70 sptr<IWindowRectChangeListener> listener = nullptr;
71 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->RegisterWindowRectChangeListener(listener));
72 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->UnregisterWindowRectChangeListener(listener));
73
74 sptr<IWindowRectChangeListener> listener1 = sptr<IWindowRectChangeListener>::MakeSptr();
75 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener1));
76 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener1));
77
78 window->Destroy(true, true);
79 }
80
81 /**
82 * @tc.name: WindowRectChange02
83 * @tc.desc: windowRectChange
84 * @tc.type: FUNC
85 */
86 HWTEST_F(WindowCallbackTest, WindowRectChange02, TestSize.Level1)
87 {
88 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
89 option->SetWindowName("Window1_2");
90 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
91 option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
92
93 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
94 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
95 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
96 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
97
98 sptr<IWindowRectChangeListener> listener = sptr<IWindowRectChangeListener>::MakeSptr();
99
100 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
101 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
102 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener));
103
104 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
105 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
106 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener));
107
108 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
109 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
110 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener));
111
112 window->Destroy(true, true);
113 }
114
115 /**
116 * @tc.name: WindowRectChange03
117 * @tc.desc: windowRectChange
118 * @tc.type: FUNC
119 */
120 HWTEST_F(WindowCallbackTest, WindowRectChange03, TestSize.Level1)
121 {
122 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
123 option->SetWindowName("Window1_3");
124 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
125 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
126
127 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
128 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
129 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
130 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
131
132 sptr<IWindowRectChangeListener> listener = sptr<IWindowRectChangeListener>::MakeSptr();
133
134 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
135 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
136 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener));
137
138 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
139 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
140 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener));
141
142 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
143 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
144 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener));
145
146 window->Destroy(true, true);
147 }
148
149 /**
150 * @tc.name: WindowRectChange04
151 * @tc.desc: windowRectChange
152 * @tc.type: FUNC
153 */
154 HWTEST_F(WindowCallbackTest, WindowRectChange04, TestSize.Level1)
155 {
156 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
157 option->SetWindowName("Window1_4");
158 option->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
159 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
160
161 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
162 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
163 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
164 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
165
166 sptr<IWindowRectChangeListener> listener = sptr<IWindowRectChangeListener>::MakeSptr();
167
168 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
169 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
170 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener));
171
172 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
173 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
174 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener));
175
176 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
177 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
178 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener));
179
180 window->Destroy(true, true);
181 }
182
183 /**
184 * @tc.name: WindowTitleButtonRectChange01
185 * @tc.desc: windowTitleButtonRectChange
186 * @tc.type: FUNC
187 */
188 HWTEST_F(WindowCallbackTest, WindowTitleButtonRectChange01, TestSize.Level1)
189 {
190 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
191 option->SetWindowName("Window2_1");
192 option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
193 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
194
195 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
196 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
197 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
198 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
199
200 sptr<IWindowTitleButtonRectChangedListener> listener = nullptr;
201 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->RegisterWindowTitleButtonRectChangeListener(listener));
202 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->UnregisterWindowTitleButtonRectChangeListener(listener));
203
204 sptr<IWindowTitleButtonRectChangedListener> listener1 = sptr<IWindowTitleButtonRectChangedListener>::MakeSptr();
205 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->RegisterWindowTitleButtonRectChangeListener(listener1));
206 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->UnregisterWindowTitleButtonRectChangeListener(listener1));
207
208 window->Destroy(true, true);
209 }
210
211 /**
212 * @tc.name: WindowTitleButtonRectChange02
213 * @tc.desc: windowTitleButtonRectChange
214 * @tc.type: FUNC
215 */
216 HWTEST_F(WindowCallbackTest, WindowTitleButtonRectChange02, TestSize.Level1)
217 {
218 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
219 option->SetWindowName("Window2_2");
220 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
221 option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
222
223 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
224 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
225 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
226 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
227
228 window->property_->SetPersistentId(10022);
229 window->hostSession_ = session;
230
231 sptr<IWindowTitleButtonRectChangedListener> listener = sptr<IWindowTitleButtonRectChangedListener>::MakeSptr();
232
233 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
234 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
235 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
236
237 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
238 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
239 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
240
241 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
242 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
243 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
244
245 window->Destroy(true, true);
246 }
247
248 /**
249 * @tc.name: WindowTitleButtonRectChange03
250 * @tc.desc: windowTitleButtonRectChange
251 * @tc.type: FUNC
252 */
253 HWTEST_F(WindowCallbackTest, WindowTitleButtonRectChange03, TestSize.Level1)
254 {
255 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
256 option->SetWindowName("Window2_3");
257 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
258 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
259
260 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
261 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
262 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
263 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
264
265 window->property_->SetPersistentId(10023);
266 window->hostSession_ = session;
267
268 sptr<IWindowTitleButtonRectChangedListener> listener = sptr<IWindowTitleButtonRectChangedListener>::MakeSptr();
269
270 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
271 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
272 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
273
274 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
275 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
276 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
277
278 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
279 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
280 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
281
282 window->Destroy(true, true);
283 }
284
285 /**
286 * @tc.name: WindowTitleButtonRectChange04
287 * @tc.desc: windowTitleButtonRectChange
288 * @tc.type: FUNC
289 */
290 HWTEST_F(WindowCallbackTest, WindowTitleButtonRectChange04, TestSize.Level1)
291 {
292 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
293 option->SetWindowName("Window2_4");
294 option->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
295 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
296
297 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
298 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
299 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
300 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
301
302 window->property_->SetPersistentId(10024);
303 window->hostSession_ = session;
304
305 sptr<IWindowTitleButtonRectChangedListener> listener = sptr<IWindowTitleButtonRectChangedListener>::MakeSptr();
306
307 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
308 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
309 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
310
311 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
312 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
313 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
314
315 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
316 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
317 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
318
319 window->Destroy(true, true);
320 }
321
322 /**
323 * @tc.name: MainWindowClose01
324 * @tc.desc: MainWindowClose
325 * @tc.type: FUNC
326 */
327 HWTEST_F(WindowCallbackTest, MainWindowClose01, TestSize.Level1)
328 {
329 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
330 option->SetWindowName("Window3_1");
331 option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
332 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
333
334 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
335 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
336 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
337 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
338
339 sptr<IMainWindowCloseListener> listener = nullptr;
340 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->RegisterMainWindowCloseListeners(listener));
341 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->UnregisterMainWindowCloseListeners(listener));
342
343 sptr<IMainWindowCloseListener> listener1 = sptr<IMainWindowCloseListener>::MakeSptr();
344 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->RegisterMainWindowCloseListeners(listener1));
345 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->UnregisterMainWindowCloseListeners(listener1));
346
347 window->Destroy(true, true);
348 }
349
350 /**
351 * @tc.name: MainWindowClose02
352 * @tc.desc: MainWindowClose
353 * @tc.type: FUNC
354 */
355 HWTEST_F(WindowCallbackTest, MainWindowClose02, TestSize.Level1)
356 {
357 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
358 option->SetWindowName("Window3_2");
359 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
360 option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
361
362 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
363 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
364 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
365 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
366
367 window->property_->SetPersistentId(10032);
368 window->hostSession_ = session;
369
370 sptr<IMainWindowCloseListener> listener = sptr<IMainWindowCloseListener>::MakeSptr();
371
372 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
373 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->RegisterMainWindowCloseListeners(listener));
374 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->UnregisterMainWindowCloseListeners(listener));
375
376 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
377 ASSERT_EQ(WMError::WM_OK, window->RegisterMainWindowCloseListeners(listener));
378 ASSERT_EQ(WMError::WM_OK, window->UnregisterMainWindowCloseListeners(listener));
379
380 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
381 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->RegisterMainWindowCloseListeners(listener));
382 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->UnregisterMainWindowCloseListeners(listener));
383
384 window->Destroy(true, true);
385 }
386
387 /**
388 * @tc.name: MainWindowClose03
389 * @tc.desc: MainWindowClose
390 * @tc.type: FUNC
391 */
392 HWTEST_F(WindowCallbackTest, MainWindowClose03, TestSize.Level1)
393 {
394 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
395 option->SetWindowName("Window3_3");
396 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
397 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
398
399 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
400 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
401 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
402 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
403
404 window->property_->SetPersistentId(10033);
405 window->hostSession_ = session;
406
407 sptr<IMainWindowCloseListener> listener = sptr<IMainWindowCloseListener>::MakeSptr();
408
409 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
410 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->RegisterMainWindowCloseListeners(listener));
411 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->UnregisterMainWindowCloseListeners(listener));
412
413 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
414 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->RegisterMainWindowCloseListeners(listener));
415 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->UnregisterMainWindowCloseListeners(listener));
416
417 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
418 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->RegisterMainWindowCloseListeners(listener));
419 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->UnregisterMainWindowCloseListeners(listener));
420
421 window->Destroy(true, true);
422 }
423
424 /**
425 * @tc.name: MainWindowClose04
426 * @tc.desc: MainWindowClose
427 * @tc.type: FUNC
428 */
429 HWTEST_F(WindowCallbackTest, MainWindowClose04, TestSize.Level1)
430 {
431 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
432 option->SetWindowName("Window3_4");
433 option->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
434 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
435
436 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
437 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
438 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
439 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
440
441 window->property_->SetPersistentId(10034);
442 window->hostSession_ = session;
443
444 sptr<IMainWindowCloseListener> listener = sptr<IMainWindowCloseListener>::MakeSptr();
445
446 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
447 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->RegisterMainWindowCloseListeners(listener));
448 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->UnregisterMainWindowCloseListeners(listener));
449
450 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
451 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->RegisterMainWindowCloseListeners(listener));
452 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->UnregisterMainWindowCloseListeners(listener));
453
454 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
455 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->RegisterMainWindowCloseListeners(listener));
456 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->UnregisterMainWindowCloseListeners(listener));
457
458 window->Destroy(true, true);
459 }
460
461 } // namespace
462 } // namespace Rosen
463 } // namespace OHOS