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, Function | MediumTest | Level0)
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, Function | MediumTest | Level0)
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, Function | MediumTest | Level0)
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, Function | MediumTest | Level0)
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, Function | MediumTest | Level0)
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 =
205 sptr<IWindowTitleButtonRectChangedListener>::MakeSptr();
206 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->RegisterWindowTitleButtonRectChangeListener(listener1));
207 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->UnregisterWindowTitleButtonRectChangeListener(listener1));
208
209 window->Destroy(true, true);
210 }
211
212 /**
213 * @tc.name: WindowTitleButtonRectChange02
214 * @tc.desc: windowTitleButtonRectChange
215 * @tc.type: FUNC
216 */
217 HWTEST_F(WindowCallbackTest, WindowTitleButtonRectChange02, Function | MediumTest | Level0)
218 {
219 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
220 option->SetWindowName("Window2_2");
221 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
222 option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
223
224 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
225 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
226 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
227 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
228
229 window->property_->SetPersistentId(10022);
230 window->hostSession_ = session;
231
232 sptr<IWindowTitleButtonRectChangedListener> listener =
233 sptr<IWindowTitleButtonRectChangedListener>::MakeSptr();
234
235 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
236 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
237 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
238
239 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
240 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
241 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
242
243 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
244 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
245 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
246
247 window->Destroy(true, true);
248 }
249
250 /**
251 * @tc.name: WindowTitleButtonRectChange03
252 * @tc.desc: windowTitleButtonRectChange
253 * @tc.type: FUNC
254 */
255 HWTEST_F(WindowCallbackTest, WindowTitleButtonRectChange03, Function | MediumTest | Level0)
256 {
257 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
258 option->SetWindowName("Window2_3");
259 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
260 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
261
262 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
263 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
264 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
265 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
266
267 window->property_->SetPersistentId(10023);
268 window->hostSession_ = session;
269
270 sptr<IWindowTitleButtonRectChangedListener> listener =
271 sptr<IWindowTitleButtonRectChangedListener>::MakeSptr();
272
273 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
274 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
275 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
276
277 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
278 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
279 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
280
281 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
282 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
283 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
284
285 window->Destroy(true, true);
286 }
287
288 /**
289 * @tc.name: WindowTitleButtonRectChange04
290 * @tc.desc: windowTitleButtonRectChange
291 * @tc.type: FUNC
292 */
293 HWTEST_F(WindowCallbackTest, WindowTitleButtonRectChange04, Function | MediumTest | Level0)
294 {
295 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
296 option->SetWindowName("Window2_4");
297 option->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
298 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
299
300 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
301 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
302 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
303 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
304
305 window->property_->SetPersistentId(10024);
306 window->hostSession_ = session;
307
308 sptr<IWindowTitleButtonRectChangedListener> listener =
309 sptr<IWindowTitleButtonRectChangedListener>::MakeSptr();
310
311 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_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::PC_WINDOW;
316 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
317 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
318
319 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
320 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowTitleButtonRectChangeListener(listener));
321 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowTitleButtonRectChangeListener(listener));
322
323 window->Destroy(true, true);
324 }
325
326 /**
327 * @tc.name: MainWindowClose01
328 * @tc.desc: MainWindowClose
329 * @tc.type: FUNC
330 */
331 HWTEST_F(WindowCallbackTest, MainWindowClose01, Function | MediumTest | Level0)
332 {
333 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
334 option->SetWindowName("Window3_1");
335 option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
336 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
337
338 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
339 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
340 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
341 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
342
343 sptr<IMainWindowCloseListener> listener = nullptr;
344 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->RegisterMainWindowCloseListeners(listener));
345 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->UnregisterMainWindowCloseListeners(listener));
346
347 sptr<IMainWindowCloseListener> listener1 = sptr<IMainWindowCloseListener>::MakeSptr();
348 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->RegisterMainWindowCloseListeners(listener1));
349 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->UnregisterMainWindowCloseListeners(listener1));
350
351 window->Destroy(true, true);
352 }
353
354 /**
355 * @tc.name: MainWindowClose02
356 * @tc.desc: MainWindowClose
357 * @tc.type: FUNC
358 */
359 HWTEST_F(WindowCallbackTest, MainWindowClose02, Function | MediumTest | Level0)
360 {
361 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
362 option->SetWindowName("Window3_2");
363 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
364 option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
365
366 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
367 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
368 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
369 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
370
371 window->property_->SetPersistentId(10032);
372 window->hostSession_ = session;
373
374 sptr<IMainWindowCloseListener> listener = sptr<IMainWindowCloseListener>::MakeSptr();
375
376 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
377 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->RegisterMainWindowCloseListeners(listener));
378 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->UnregisterMainWindowCloseListeners(listener));
379
380 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
381 ASSERT_EQ(WMError::WM_OK, window->RegisterMainWindowCloseListeners(listener));
382 ASSERT_EQ(WMError::WM_OK, window->UnregisterMainWindowCloseListeners(listener));
383
384 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
385 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->RegisterMainWindowCloseListeners(listener));
386 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->UnregisterMainWindowCloseListeners(listener));
387
388 window->Destroy(true, true);
389 }
390
391 /**
392 * @tc.name: MainWindowClose03
393 * @tc.desc: MainWindowClose
394 * @tc.type: FUNC
395 */
396 HWTEST_F(WindowCallbackTest, MainWindowClose03, Function | MediumTest | Level0)
397 {
398 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
399 option->SetWindowName("Window3_3");
400 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
401 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
402
403 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
404 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
405 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
406 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
407
408 window->property_->SetPersistentId(10033);
409 window->hostSession_ = session;
410
411 sptr<IMainWindowCloseListener> listener = sptr<IMainWindowCloseListener>::MakeSptr();
412
413 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
414 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->RegisterMainWindowCloseListeners(listener));
415 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->UnregisterMainWindowCloseListeners(listener));
416
417 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
418 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->RegisterMainWindowCloseListeners(listener));
419 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->UnregisterMainWindowCloseListeners(listener));
420
421 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
422 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->RegisterMainWindowCloseListeners(listener));
423 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->UnregisterMainWindowCloseListeners(listener));
424
425 window->Destroy(true, true);
426 }
427
428 /**
429 * @tc.name: MainWindowClose04
430 * @tc.desc: MainWindowClose
431 * @tc.type: FUNC
432 */
433 HWTEST_F(WindowCallbackTest, MainWindowClose04, Function | MediumTest | Level0)
434 {
435 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
436 option->SetWindowName("Window3_4");
437 option->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
438 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
439
440 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
441 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
442 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
443 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
444
445 window->property_->SetPersistentId(10034);
446 window->hostSession_ = session;
447
448 sptr<IMainWindowCloseListener> listener = sptr<IMainWindowCloseListener>::MakeSptr();
449
450 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
451 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->RegisterMainWindowCloseListeners(listener));
452 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->UnregisterMainWindowCloseListeners(listener));
453
454 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
455 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->RegisterMainWindowCloseListeners(listener));
456 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->UnregisterMainWindowCloseListeners(listener));
457
458 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
459 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->RegisterMainWindowCloseListeners(listener));
460 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->UnregisterMainWindowCloseListeners(listener));
461
462 window->Destroy(true, true);
463 }
464
465 }
466 } // namespace Rosen
467 } // namespace OHOS