1 /*
2  * Copyright (c) 2024 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 #include <filesystem>
16 #include <fstream>
17 #include <gtest/gtest.h>
18 
19 #include "ability_context_impl.h"
20 #include "accessibility_event_info.h"
21 #include "color_parser.h"
22 #include "mock_session.h"
23 #include "window_helper.h"
24 #include "window_session_impl.h"
25 #include "wm_common.h"
26 #include "mock_uicontent.h"
27 #include "mock_window.h"
28 #include "parameters.h"
29 #include "scene_board_judgement.h"
30 
31 using namespace testing;
32 using namespace testing::ext;
33 
34 namespace OHOS {
35 namespace Rosen {
36 class WindowSessionImplTest4 : public testing::Test {
37 public:
38     static void SetUpTestCase();
39     static void TearDownTestCase();
40     void SetUp() override;
41     void TearDown() override;
42 
43     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
44 private:
45     static constexpr uint32_t WAIT_SYNC_IN_NS = 50000;
46 };
47 
SetUpTestCase()48 void WindowSessionImplTest4::SetUpTestCase()
49 {
50 }
51 
TearDownTestCase()52 void WindowSessionImplTest4::TearDownTestCase()
53 {
54 }
55 
SetUp()56 void WindowSessionImplTest4::SetUp()
57 {
58     abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
59 }
60 
TearDown()61 void WindowSessionImplTest4::TearDown()
62 {
63     usleep(WAIT_SYNC_IN_NS);
64     abilityContext_ = nullptr;
65 }
66 
67 namespace {
68 /**
69  * @tc.name: GetRequestWindowStatetest01
70  * @tc.desc: GetRequestWindowState
71  * @tc.type: FUNC
72  */
HWTEST_F(WindowSessionImplTest4, GetRequestWindowState, Function | SmallTest | Level2)73 HWTEST_F(WindowSessionImplTest4, GetRequestWindowState, Function | SmallTest | Level2)
74 {
75     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetRequestWindowStatetest01 start";
76     sptr<WindowOption> option = new WindowOption();
77     ASSERT_NE(option, nullptr);
78     option->SetWindowName("GetRequestWindowState");
79     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
80     ASSERT_NE(window, nullptr);
81     auto ret = window->GetRequestWindowState();
82     ASSERT_EQ(ret, WindowState::STATE_INITIAL);
83     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetRequestWindowStatetest01 end";
84 }
85 
86 /**
87  * @tc.name: GetFocusabletest01
88  * @tc.desc: GetFocusable
89  * @tc.type: FUNC
90  */
HWTEST_F(WindowSessionImplTest4, GetFocusable, Function | SmallTest | Level2)91 HWTEST_F(WindowSessionImplTest4, GetFocusable, Function | SmallTest | Level2)
92 {
93     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetFocusabletest01 start";
94     sptr<WindowOption> option = new WindowOption();
95     ASSERT_NE(option, nullptr);
96     option->SetWindowName("GetFocusable");
97     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
98     ASSERT_NE(window, nullptr);
99     bool ret = window->GetFocusable();
100     ASSERT_EQ(ret, true);
101     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetFocusabletest01 end";
102 }
103 
104 
105 /**
106  * @tc.name: TransferAccessibilityEvent
107  * @tc.desc: TransferAccessibilityEvent
108  * @tc.type: FUNC
109  */
HWTEST_F(WindowSessionImplTest4, TransferAccessibilityEvent, Function | SmallTest | Level2)110 HWTEST_F(WindowSessionImplTest4, TransferAccessibilityEvent, Function | SmallTest | Level2)
111 {
112     GTEST_LOG_(INFO) << "WindowSessionImplTest4: TransferAccessibilityEvent start";
113     sptr<WindowOption> option = new WindowOption();
114     ASSERT_NE(option, nullptr);
115     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
116     ASSERT_NE(window, nullptr);
117     Accessibility::AccessibilityEventInfo info;
118     int64_t uiExtensionIdLevel = 0;
119     ASSERT_EQ(WMError::WM_OK, window->TransferAccessibilityEvent(info, uiExtensionIdLevel));
120     GTEST_LOG_(INFO) << "WindowSessionImplTest4: TransferAccessibilityEvent end";
121 }
122 
123 /**
124  * @tc.name: SetSingleFrameComposerEnabled01
125  * @tc.desc: SetSingleFrameComposerEnabled and check the retCode
126  * @tc.type: FUNC
127  */
HWTEST_F(WindowSessionImplTest4, SetSingleFrameComposerEnabled01, Function | SmallTest | Level2)128 HWTEST_F(WindowSessionImplTest4, SetSingleFrameComposerEnabled01, Function | SmallTest | Level2)
129 {
130     sptr<WindowOption> option = new WindowOption();
131     option->SetWindowName("SetSingleFrameComposerEnabled01");
132     sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
133     ASSERT_NE(nullptr, window);
134     WMError retCode = window->SetSingleFrameComposerEnabled(false);
135     ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
136     window->property_->SetPersistentId(1);
137     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
138     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
139     ASSERT_NE(nullptr, session);
140     window->hostSession_ = session;
141     window->state_ = WindowState::STATE_CREATED;
142     retCode = window->SetSingleFrameComposerEnabled(false);
143     ASSERT_EQ(retCode, WMError::WM_OK);
144 
145     window->surfaceNode_ = nullptr;
146     retCode = window->SetSingleFrameComposerEnabled(false);
147     ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
148 }
149 
150 /**
151  * @tc.name: SetTopmost
152  * @tc.desc: SetTopmost
153  * @tc.type: FUNC
154  */
HWTEST_F(WindowSessionImplTest4, SetTopmost, Function | SmallTest | Level2)155 HWTEST_F(WindowSessionImplTest4, SetTopmost, Function | SmallTest | Level2)
156 {
157     sptr<WindowOption> option = new WindowOption();
158     option->SetWindowName("SetTopmost");
159     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
160     ASSERT_NE(nullptr, window);
161     window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
162     WMError res = window->SetTopmost(true);
163     ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, res);
164     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
165     res = window->SetTopmost(true);
166     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, res);
167 
168     window->property_->SetPersistentId(1);
169     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
170     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
171     ASSERT_NE(nullptr, session);
172     window->hostSession_ = session;
173     window->state_ = WindowState::STATE_CREATED;
174     res = window->SetTopmost(true);
175     ASSERT_EQ(WMError::WM_OK, res);
176 }
177 
178 /**
179  * @tc.name: IsTopmost
180  * @tc.desc: IsTopmost
181  * @tc.type: FUNC
182  */
HWTEST_F(WindowSessionImplTest4, IsTopmost, Function | SmallTest | Level2)183 HWTEST_F(WindowSessionImplTest4, IsTopmost, Function | SmallTest | Level2)
184 {
185     sptr<WindowOption> option = new WindowOption();
186     option->SetWindowName("IsTopmost");
187     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
188     ASSERT_NE(window, nullptr);
189     bool res = window->IsTopmost();
190     ASSERT_FALSE(res);
191 }
192 
193 /**
194  * @tc.name: SetMainWindowTopmost
195  * @tc.desc: SetMainWindowTopmost
196  * @tc.type: FUNC
197  */
HWTEST_F(WindowSessionImplTest4, SetMainWindowTopmost, Function | SmallTest | Level2)198 HWTEST_F(WindowSessionImplTest4, SetMainWindowTopmost, Function | SmallTest | Level2)
199 {
200     sptr<WindowOption> option = new WindowOption();
201     ASSERT_NE(option, nullptr);
202     option->SetWindowName("SetMainWindowTopmost");
203     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
204     ASSERT_NE(nullptr, window);
205 
206     window->property_->SetPersistentId(1);
207     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
208     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
209     ASSERT_NE(nullptr, session);
210     window->hostSession_ = session;
211     window->state_ = WindowState::STATE_CREATED;
212     WMError res = window->SetMainWindowTopmost(true);
213     ASSERT_EQ(WMError::WM_OK, res);
214 }
215 
216 /**
217  * @tc.name: IsMainWindowTopmost
218  * @tc.desc: IsMainWindowTopmost
219  * @tc.type: FUNC
220  */
HWTEST_F(WindowSessionImplTest4, IsMainWindowTopmost, Function | SmallTest | Level2)221 HWTEST_F(WindowSessionImplTest4, IsMainWindowTopmost, Function | SmallTest | Level2)
222 {
223     sptr<WindowOption> option = new WindowOption();
224     ASSERT_NE(option, nullptr);
225     option->SetWindowName("IsMainWindowTopmost");
226     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
227     ASSERT_NE(window, nullptr);
228     bool res = window->IsMainWindowTopmost();
229     ASSERT_FALSE(res);
230 }
231 
232 /**
233  * @tc.name: SetDecorVisible
234  * @tc.desc: SetDecorVisible and check the retCode
235  * @tc.type: FUNC
236  */
HWTEST_F(WindowSessionImplTest4, SetDecorVisible, Function | SmallTest | Level2)237 HWTEST_F(WindowSessionImplTest4, SetDecorVisible, Function | SmallTest | Level2)
238 {
239     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetDecorVisibletest01 start";
240     sptr<WindowOption> option = new WindowOption();
241     ASSERT_NE(option, nullptr);
242     option->SetWindowName("SetDecorVisible");
243     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
244     ASSERT_NE(window, nullptr);
245     ASSERT_NE(window->property_, nullptr);
246     window->property_->SetPersistentId(1);
247     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
248     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
249     ASSERT_NE(nullptr, session);
250     window->hostSession_ = session;
251 
252     bool isVisible = true;
253     WMError res = window->SetDecorVisible(isVisible);
254     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
255 
256     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
257     res = window->SetDecorVisible(isVisible);
258     ASSERT_EQ(res, WMError::WM_OK);
259     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetDecorVisibletest01 end";
260 }
261 
262 /**
263  * @tc.name: SetSubWindowModal
264  * @tc.desc: SetSubWindowModal and check the retCode
265  * @tc.type: FUNC
266  */
HWTEST_F(WindowSessionImplTest4, SetSubWindowModal, Function | SmallTest | Level2)267 HWTEST_F(WindowSessionImplTest4, SetSubWindowModal, Function | SmallTest | Level2)
268 {
269     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest01 start";
270     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
271     ASSERT_NE(option, nullptr);
272     option->SetWindowName("SetSubWindowModal");
273     sptr<WindowSessionImpl> mainWindow = sptr<WindowSessionImpl>::MakeSptr(option);
274     ASSERT_NE(nullptr, mainWindow);
275     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
276     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
277     ASSERT_NE(nullptr, session);
278     mainWindow->hostSession_ = session;
279     ASSERT_NE(nullptr, mainWindow->property_);
280     mainWindow->property_->SetPersistentId(1); // 1 is main window id
281     mainWindow->state_ = WindowState::STATE_CREATED;
282     WMError res = mainWindow->SetSubWindowModal(true); // main window is invalid
283     ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, res);
284 
285     option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
286     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
287     ASSERT_NE(window, nullptr);
288     res = window->SetSubWindowModal(true); // sub window is valid
289     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, res); // window state is invalid
290 
291     window->hostSession_ = session;
292     ASSERT_NE(nullptr, window->property_);
293     window->property_->SetPersistentId(2); // 2 is sub window id
294     window->state_ = WindowState::STATE_CREATED;
295     res = window->SetSubWindowModal(true); // sub window is valid
296     ASSERT_EQ(WMError::WM_OK, res);
297     res = window->SetSubWindowModal(false);
298     ASSERT_EQ(WMError::WM_OK, res);
299     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest01 end";
300 }
301 
302 /**
303  * @tc.name: SetSubWindowModal02
304  * @tc.desc: SetSubWindowModal and check the retCode
305  * @tc.type: FUNC
306  */
HWTEST_F(WindowSessionImplTest4, SetSubWindowModal02, Function | SmallTest | Level2)307 HWTEST_F(WindowSessionImplTest4, SetSubWindowModal02, Function | SmallTest | Level2)
308 {
309     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest02 start";
310     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
311     ASSERT_NE(option, nullptr);
312     option->SetWindowName("SetSubWindowModal02");
313     option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
314     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
315     ASSERT_NE(window, nullptr);
316     ASSERT_NE(nullptr, window->property_);
317     window->property_->SetPersistentId(1);
318     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
319     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
320     ASSERT_NE(nullptr, session);
321     window->hostSession_ = session;
322     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
323     WMError res = window->SetSubWindowModal(true, ModalityType::WINDOW_MODALITY);
324     ASSERT_EQ(res, WMError::WM_OK);
325     res = window->SetSubWindowModal(true, ModalityType::APPLICATION_MODALITY);
326     ASSERT_EQ(res, WMError::WM_OK);
327     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest02 end";
328 }
329 
330 /**
331  * @tc.name: IsPcOrPadFreeMultiWindowMode
332  * @tc.desc: IsPcOrPadFreeMultiWindowMode
333  * @tc.type: FUNC
334  */
HWTEST_F(WindowSessionImplTest4, IsPcOrPadFreeMultiWindowMode, Function | SmallTest | Level2)335 HWTEST_F(WindowSessionImplTest4, IsPcOrPadFreeMultiWindowMode, Function | SmallTest | Level2)
336 {
337     GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadFreeMultiWindowMode start";
338     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
339     ASSERT_NE(option, nullptr);
340     option->SetWindowName("IsPcOrPadFreeMultiWindowMode");
341     option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
342     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
343     ASSERT_NE(window, nullptr);
344     window->property_->SetPersistentId(1);
345     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
346     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
347     ASSERT_NE(nullptr, session);
348     window->hostSession_ = session;
349     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
350     ASSERT_EQ(true, window->IsPcOrPadFreeMultiWindowMode());
351     window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
352     ASSERT_EQ(false, window->IsPcOrPadFreeMultiWindowMode());
353     GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadFreeMultiWindowMode end";
354 }
355 
356 /**
357  * @tc.name: GetDecorHeight
358  * @tc.desc: GetDecorHeight and check the retCode
359  * @tc.type: FUNC
360  */
HWTEST_F(WindowSessionImplTest4, GetDecorHeight, Function | SmallTest | Level2)361 HWTEST_F(WindowSessionImplTest4, GetDecorHeight, Function | SmallTest | Level2)
362 {
363     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorHeighttest01 start";
364     sptr<WindowOption> option = new WindowOption();
365     ASSERT_NE(option, nullptr);
366     option->SetWindowName("GetDecorHeight");
367     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
368     ASSERT_NE(window, nullptr);
369     ASSERT_NE(window->property_, nullptr);
370     window->property_->SetPersistentId(1);
371     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
372     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
373     ASSERT_NE(nullptr, session);
374     window->hostSession_ = session;
375     int32_t height = 0;
376     WMError res = window->GetDecorHeight(height);
377     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
378     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorHeighttest01 end";
379 }
380 
381 /**
382  * @tc.name: GetTitleButtonArea
383  * @tc.desc: GetTitleButtonArea and check the retCode
384  * @tc.type: FUNC
385  */
HWTEST_F(WindowSessionImplTest4, GetTitleButtonArea, Function | SmallTest | Level2)386 HWTEST_F(WindowSessionImplTest4, GetTitleButtonArea, Function | SmallTest | Level2)
387 {
388     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetTitleButtonAreatest01 start";
389     sptr<WindowOption> option = new WindowOption();
390     ASSERT_NE(option, nullptr);
391     option->SetWindowName("GetTitleButtonArea");
392     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
393     ASSERT_NE(window, nullptr);
394     ASSERT_NE(window->property_, nullptr);
395     window->property_->SetPersistentId(1);
396     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
397     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
398     ASSERT_NE(nullptr, session);
399     window->hostSession_ = session;
400     TitleButtonRect titleButtonRect;
401     WMError res = window->GetTitleButtonArea(titleButtonRect);
402     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
403     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorHeighttest01 end";
404 }
405 
406 /**
407  * @tc.name: GetUIContentRemoteObj
408  * @tc.desc: GetUIContentRemoteObj and check the retCode
409  * @tc.type: FUNC
410  */
HWTEST_F(WindowSessionImplTest4, GetUIContentRemoteObj, Function | SmallTest | Level2)411 HWTEST_F(WindowSessionImplTest4, GetUIContentRemoteObj, Function | SmallTest | Level2)
412 {
413     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetUIContentRemoteObj start";
414     sptr<WindowOption> option = new WindowOption();
415     ASSERT_NE(option, nullptr);
416     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
417     ASSERT_NE(window, nullptr);
418     sptr<IRemoteObject> remoteObj;
419     WSError res = window->GetUIContentRemoteObj(remoteObj);
420     ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
421     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
422     res = window->GetUIContentRemoteObj(remoteObj);
423     ASSERT_EQ(res, WSError::WS_OK);
424     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetUIContentRemoteObj end";
425 }
426 
427 /**
428  * @tc.name: RegisterExtensionAvoidAreaChangeListener
429  * @tc.desc: RegisterExtensionAvoidAreaChangeListener Test
430  * @tc.type: FUNC
431  */
HWTEST_F(WindowSessionImplTest4, RegisterExtensionAvoidAreaChangeListener, Function | SmallTest | Level2)432 HWTEST_F(WindowSessionImplTest4, RegisterExtensionAvoidAreaChangeListener, Function | SmallTest | Level2)
433 {
434     GTEST_LOG_(INFO) << "WindowSessionImplTest4: RegisterExtensionAvoidAreaChangeListener start";
435     sptr<WindowOption> option = new WindowOption();
436     ASSERT_NE(option, nullptr);
437     option->SetWindowName("GetTitleButtonArea");
438     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
439     ASSERT_NE(window, nullptr);
440     sptr<IAvoidAreaChangedListener> listener = nullptr;
441     WMError res = window->RegisterExtensionAvoidAreaChangeListener(listener);
442     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
443 
444     listener = sptr<IAvoidAreaChangedListener>::MakeSptr();
445     vector<sptr<IAvoidAreaChangedListener>> holder;
446     window->avoidAreaChangeListeners_[window->property_->GetPersistentId()] = holder;
447     res = window->RegisterExtensionAvoidAreaChangeListener(listener);
448     ASSERT_EQ(res, WMError::WM_OK);
449     holder = window->avoidAreaChangeListeners_[window->property_->GetPersistentId()];
450     auto existsListener = std::find(holder.begin(), holder.end(), listener);
451     ASSERT_NE(existsListener, holder.end());
452 
453     // already registered
454     res = window->RegisterExtensionAvoidAreaChangeListener(listener);
455     ASSERT_EQ(res, WMError::WM_OK);
456     GTEST_LOG_(INFO) << "WindowSessionImplTest4: RegisterExtensionAvoidAreaChangeListener end";
457 }
458 
459 /**
460  * @tc.name: UnregisterExtensionAvoidAreaChangeListener
461  * @tc.desc: UnregisterExtensionAvoidAreaChangeListener Test
462  * @tc.type: FUNC
463  */
HWTEST_F(WindowSessionImplTest4, UnregisterExtensionAvoidAreaChangeListener, Function | SmallTest | Level2)464 HWTEST_F(WindowSessionImplTest4, UnregisterExtensionAvoidAreaChangeListener, Function | SmallTest | Level2)
465 {
466     GTEST_LOG_(INFO) << "WindowSessionImplTest4: UnregisterExtensionAvoidAreaChangeListener start";
467     sptr<WindowOption> option = new WindowOption();
468     ASSERT_NE(option, nullptr);
469     option->SetWindowName("GetTitleButtonArea");
470     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
471     ASSERT_NE(window, nullptr);
472     sptr<IAvoidAreaChangedListener> listener = nullptr;
473     WMError res = window->UnregisterExtensionAvoidAreaChangeListener(listener);
474     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
475 
476     listener = sptr<IAvoidAreaChangedListener>::MakeSptr();
477     vector<sptr<IAvoidAreaChangedListener>> holder;
478     window->avoidAreaChangeListeners_[window->property_->GetPersistentId()] = holder;
479     window->RegisterExtensionAvoidAreaChangeListener(listener);
480 
481     res = window->UnregisterExtensionAvoidAreaChangeListener(listener);
482     ASSERT_EQ(res, WMError::WM_OK);
483 
484     holder = window->avoidAreaChangeListeners_[window->property_->GetPersistentId()];
485     auto existsListener = std::find(holder.begin(), holder.end(), listener);
486     ASSERT_EQ(existsListener, holder.end());
487     GTEST_LOG_(INFO) << "WindowSessionImplTest4: UnregisterExtensionAvoidAreaChangeListener end";
488 }
489 
490 /**
491  * @tc.name: SetPipActionEvent
492  * @tc.desc: SetPipActionEvent Test
493  * @tc.type: FUNC
494  */
HWTEST_F(WindowSessionImplTest4, SetPipActionEvent, Function | SmallTest | Level2)495 HWTEST_F(WindowSessionImplTest4, SetPipActionEvent, Function | SmallTest | Level2)
496 {
497     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPipActionEvent start";
498     sptr<WindowOption> option = new WindowOption();
499     ASSERT_NE(option, nullptr);
500     option->SetWindowName("GetTitleButtonArea");
501     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
502     ASSERT_NE(window, nullptr);
503     ASSERT_EQ(nullptr, window->GetUIContentWithId(10000));
504     window->property_->SetPersistentId(1);
505 
506     SessionInfo sessionInfo = { "CreateTestBundle", "TestGetUIContentWithId", "CreateTestAbility" };
507     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
508     ASSERT_NE(nullptr, session);
509     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
510     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
511     ASSERT_EQ(window->FindWindowById(1), nullptr);
512     ASSERT_EQ(nullptr, window->GetUIContentWithId(1));
513     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
514     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPipActionEvent end";
515 }
516 
517 /**
518  * @tc.name: SetPiPControlEvent
519  * @tc.desc: SetPiPControlEvent Test
520  * @tc.type: FUNC
521  */
HWTEST_F(WindowSessionImplTest4, SetPiPControlEvent, Function | SmallTest | Level2)522 HWTEST_F(WindowSessionImplTest4, SetPiPControlEvent, Function | SmallTest | Level2)
523 {
524     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPiPControlEvent start";
525     auto option = sptr<WindowOption>::MakeSptr();
526     ASSERT_NE(option, nullptr);
527     option->SetWindowName("GetTitleButtonArea");
528     auto window = sptr<WindowSessionImpl>::MakeSptr(option);
529     ASSERT_NE(window, nullptr);
530     auto controlType = WsPiPControlType::VIDEO_PLAY_PAUSE;
531     auto status = WsPiPControlStatus::PLAY;
532     WSError res = window->SetPiPControlEvent(controlType, status);
533     ASSERT_EQ(res, WSError::WS_OK);
534     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPiPControlEvent end";
535 }
536 
537 /**
538  * @tc.name: SetUIContentInner
539  * @tc.desc: SetUIContentInner Test
540  * @tc.type: FUNC
541  */
HWTEST_F(WindowSessionImplTest4, SetUIContentInner, Function | SmallTest | Level2)542 HWTEST_F(WindowSessionImplTest4, SetUIContentInner, Function | SmallTest | Level2)
543 {
544     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetUIContentInner start";
545     sptr<WindowOption> option = new WindowOption();
546     ASSERT_NE(option, nullptr);
547     option->SetWindowName("SetUIContentInner");
548     option->SetIsUIExtFirstSubWindow(true);
549     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
550     ASSERT_NE(window, nullptr);
551     window->property_->SetPersistentId(1);
552     std::string url = "";
553     EXPECT_TRUE(window->IsWindowSessionInvalid());
554     WMError res1 = window->SetUIContentInner(url, nullptr, nullptr, WindowSetUIContentType::DEFAULT,
555         BackupAndRestoreType::NONE, nullptr);
556     ASSERT_EQ(res1, WMError::WM_ERROR_INVALID_WINDOW);
557     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetUIContentInner end";
558 }
559 
560 /**
561  * @tc.name: TestGetUIContentWithId
562  * @tc.desc: Get uicontent with id
563  * @tc.type: FUNC
564  */
HWTEST_F(WindowSessionImplTest4, TestGetUIContentWithId, Function | SmallTest | Level2)565 HWTEST_F(WindowSessionImplTest4, TestGetUIContentWithId, Function | SmallTest | Level2)
566 {
567     GTEST_LOG_(INFO) << "WindowSessionImplTest4: TestGetUIContentWithId start";
568     sptr<WindowOption> option = new WindowOption();
569     ASSERT_NE(nullptr, option);
570     option->SetWindowName("TestGetUIContentWithId");
571     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
572     ASSERT_NE(nullptr, window);
573     ASSERT_EQ(nullptr, window->GetUIContentWithId(10000));
574     window->property_->SetPersistentId(1);
575 
576     SessionInfo sessionInfo = { "CreateTestBundle", "TestGetUIContentWithId", "CreateTestAbility" };
577     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
578     ASSERT_NE(nullptr, session);
579     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
580     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
581     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
582         ASSERT_NE(window->FindWindowById(1), nullptr);
583         ASSERT_EQ(nullptr, window->GetUIContentWithId(1));
584         ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
585     }
586     GTEST_LOG_(INFO) << "WindowSessionImplTest4: TestGetUIContentWithId end";
587 }
588 
589 /**
590  * @tc.name: GetCallingWindowRect
591  * @tc.desc: GetCallingWindowRect Test
592  * @tc.type: FUNC
593  */
HWTEST_F(WindowSessionImplTest4, GetCallingWindowRect, Function | SmallTest | Level2)594 HWTEST_F(WindowSessionImplTest4, GetCallingWindowRect, Function | SmallTest | Level2)
595 {
596     sptr<WindowOption> option = new WindowOption();
597     option->SetWindowName("GetCallingWindowRect");
598     sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
599     ASSERT_NE(nullptr, window);
600     Rect rect = {0, 0, 0, 0};
601     WMError retCode = window->GetCallingWindowRect(rect);
602     ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
603     window->property_->SetPersistentId(1);
604     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
605     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
606     ASSERT_NE(nullptr, session);
607     window->hostSession_ = session;
608     window->state_ = WindowState::STATE_CREATED;
609     window->GetCallingWindowRect(rect);
610 }
611 
612 
613 /**
614  * @tc.name: EnableDrag
615  * @tc.desc: EnableDrag Test
616  * @tc.type: FUNC
617  */
HWTEST_F(WindowSessionImplTest4, EnableDrag, Function | SmallTest | Level2)618 HWTEST_F(WindowSessionImplTest4, EnableDrag, Function | SmallTest | Level2)
619 {
620     sptr<WindowOption> option = new (std::nothrow) WindowOption();
621     option->SetWindowName("EnableDrag");
622     sptr<WindowSessionImpl> windowSession = new (std::nothrow) WindowSessionImpl(option);
623     ASSERT_NE(nullptr, windowSession);
624     windowSession->property_->SetPersistentId(1);
625     windowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH);
626     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
627     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
628     ASSERT_NE(nullptr, session);
629 
630     windowSession->hostSession_ = session;
631     windowSession->EnableDrag(true);
632 }
633 
634 /**
635  * @tc.name: GetCallingWindowWindowStatus
636  * @tc.desc: GetCallingWindowWindowStatus Test
637  * @tc.type: FUNC
638  */
HWTEST_F(WindowSessionImplTest4, GetCallingWindowWindowStatus, Function | SmallTest | Level2)639 HWTEST_F(WindowSessionImplTest4, GetCallingWindowWindowStatus, Function | SmallTest | Level2)
640 {
641     sptr<WindowOption> option = new WindowOption();
642     option->SetWindowName("GetCallingWindowWindowStatus");
643     sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
644     ASSERT_NE(nullptr, window);
645     WindowStatus windowStatus = WindowStatus::WINDOW_STATUS_UNDEFINED;
646     WMError retCode = window->GetCallingWindowWindowStatus(windowStatus);
647     ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
648     window->property_->SetPersistentId(1);
649     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
650     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
651     ASSERT_NE(nullptr, session);
652     window->hostSession_ = session;
653     window->state_ = WindowState::STATE_CREATED;
654     window->GetCallingWindowWindowStatus(windowStatus);
655 }
656 
657 /**
658  * @tc.name: GetParentId
659  * @tc.desc: GetParentId Test
660  * @tc.type: FUNC
661  */
HWTEST_F(WindowSessionImplTest4, GetParentId, Function | SmallTest | Level2)662 HWTEST_F(WindowSessionImplTest4, GetParentId, Function | SmallTest | Level2)
663 {
664     sptr<WindowOption> option = new WindowOption();
665     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
666     const int32_t res = window->GetParentId();
667     ASSERT_EQ(res, 0);
668     ASSERT_EQ(true, window->IsSupportWideGamut());
669 }
670 
671 /**
672  * @tc.name: PreNotifyKeyEvent
673  * @tc.desc: PreNotifyKeyEvent Test
674  * @tc.type: FUNC
675  */
HWTEST_F(WindowSessionImplTest4, PreNotifyKeyEvent, Function | SmallTest | Level2)676 HWTEST_F(WindowSessionImplTest4, PreNotifyKeyEvent, Function | SmallTest | Level2)
677 {
678     sptr<WindowOption> option = new (std::nothrow) WindowOption();
679     ASSERT_NE(nullptr, option);
680     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
681     ASSERT_NE(nullptr, window);
682     std::shared_ptr<MMI::PointerEvent> pointerEvent;
683     window->ConsumePointerEvent(pointerEvent);
684 
685     std::shared_ptr<MMI::KeyEvent> keyEvent;
686     window->ConsumeKeyEvent(keyEvent);
687     ASSERT_EQ(nullptr, window->GetUIContentSharedPtr());
688     ASSERT_EQ(false, window->PreNotifyKeyEvent(keyEvent));
689     ASSERT_EQ(false, window->NotifyOnKeyPreImeEvent(keyEvent));
690     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
691     ASSERT_NE(nullptr, window->GetUIContentSharedPtr());
692     ASSERT_EQ(false, window->PreNotifyKeyEvent(keyEvent));
693     ASSERT_EQ(false, window->NotifyOnKeyPreImeEvent(keyEvent));
694 }
695 
696 /**
697  * @tc.name: CheckIfNeedCommitRsTransaction
698  * @tc.desc: CheckIfNeedCommitRsTransaction
699  * @tc.type: FUNC
700  */
HWTEST_F(WindowSessionImplTest4, CheckIfNeedCommitRsTransaction, Function | SmallTest | Level2)701 HWTEST_F(WindowSessionImplTest4, CheckIfNeedCommitRsTransaction, Function | SmallTest | Level2)
702 {
703     sptr<WindowOption> option = new (std::nothrow) WindowOption();
704     ASSERT_NE(nullptr, option);
705     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
706     ASSERT_NE(nullptr, window);
707 
708     bool res = false;
709     WindowSizeChangeReason wmReason = WindowSizeChangeReason::UNDEFINED;
710     for (uint32_t i = static_cast<uint32_t>(WindowSizeChangeReason::UNDEFINED);
711          i < static_cast<uint32_t>(WindowSizeChangeReason::END); i++) {
712         wmReason = static_cast<WindowSizeChangeReason>(i);
713         res = window->CheckIfNeedCommitRsTransaction(wmReason);
714         if (wmReason == WindowSizeChangeReason::FULL_TO_SPLIT ||
715             wmReason == WindowSizeChangeReason::FULL_TO_FLOATING || wmReason == WindowSizeChangeReason::RECOVER ||
716             wmReason == WindowSizeChangeReason::MAXIMIZE) {
717             ASSERT_EQ(res, false);
718         } else {
719             ASSERT_EQ(res, true);
720         }
721     }
722     window->Destroy();
723 }
724 
725 /**
726  * @tc.name: UpdateRectForRotation
727  * @tc.desc: UpdateRectForRotation Test
728  * @tc.type: FUNC
729  */
HWTEST_F(WindowSessionImplTest4, UpdateRectForRotation, Function | SmallTest | Level2)730 HWTEST_F(WindowSessionImplTest4, UpdateRectForRotation, Function | SmallTest | Level2)
731 {
732     sptr<WindowOption> option = new WindowOption();
733     option->SetWindowName("WindowSessionCreateCheck");
734     sptr<WindowSessionImpl> window =
735         new (std::nothrow) WindowSessionImpl(option);
736     ASSERT_NE(window, nullptr);
737 
738     Rect wmRect;
739     wmRect.posX_ = 0;
740     wmRect.posY_ = 0;
741     wmRect.height_ = 50;
742     wmRect.width_ = 50;
743 
744     WSRect rect;
745     wmRect.posX_ = 0;
746     wmRect.posY_ = 0;
747     wmRect.height_ = 50;
748     wmRect.width_ = 50;
749 
750     Rect preRect;
751     preRect.posX_ = 0;
752     preRect.posY_ = 0;
753     preRect.height_ = 200;
754     preRect.width_ = 200;
755 
756     window->property_->SetWindowRect(preRect);
757     WindowSizeChangeReason wmReason = WindowSizeChangeReason{0};
758     std::shared_ptr<RSTransaction> rsTransaction;
759     SceneAnimationConfig config { .rsTransaction_ = rsTransaction };
760     window->UpdateRectForRotation(wmRect, preRect, wmReason, config);
761 
762     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
763     auto res = window->UpdateRect(rect, reason);
764     ASSERT_EQ(res, WSError::WS_OK);
765 }
766 
767 /**
768  * @tc.name: NotifyRotationAnimationEnd
769  * @tc.desc: NotifyRotationAnimationEnd Test
770  * @tc.type: FUNC
771  */
HWTEST_F(WindowSessionImplTest4, NotifyRotationAnimationEnd, Function | SmallTest | Level2)772 HWTEST_F(WindowSessionImplTest4, NotifyRotationAnimationEnd, Function | SmallTest | Level2)
773 {
774     sptr<WindowOption> option = new WindowOption();
775     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
776     ASSERT_NE(window, nullptr);
777     window->NotifyRotationAnimationEnd();
778 
779     OHOS::Ace::UIContentErrorCode aceRet = OHOS::Ace::UIContentErrorCode::NO_ERRORS;
780     window->InitUIContent("", nullptr, nullptr, WindowSetUIContentType::BY_ABC, BackupAndRestoreType::NONE,
781                           nullptr, aceRet);
782     window->NotifyRotationAnimationEnd();
783     ASSERT_NE(nullptr, window->uiContent_);
784 }
785 
786 /**
787  * @tc.name: SetTitleButtonVisible
788  * @tc.desc: SetTitleButtonVisible and GetTitleButtonVisible
789  * @tc.type: FUNC
790  */
HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible, Function | SmallTest | Level2)791 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible, Function | SmallTest | Level2)
792 {
793     sptr<WindowOption> option = new WindowOption();
794     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
795     ASSERT_NE(window, nullptr);
796     bool isMaximizeVisible = true;
797     bool isMinimizeVisible = true;
798     bool isSplitVisible = true;
799     bool isCloseVisible = true;
800     auto res = window->SetTitleButtonVisible(isMaximizeVisible, isMinimizeVisible,
801         isSplitVisible, isCloseVisible);
802 
803     bool &hideMaximizeButton = isMaximizeVisible;
804     bool &hideMinimizeButton = isMinimizeVisible;
805     bool &hideSplitButton = isSplitVisible;
806     bool &hideCloseButton = isCloseVisible;
807     window->GetTitleButtonVisible(true, hideMaximizeButton, hideMinimizeButton,
808         hideSplitButton, hideCloseButton);
809     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
810 }
811 
812 /**
813  * @tc.name: IsFocused
814  * @tc.desc: IsFocused
815  * @tc.type: FUNC
816  */
HWTEST_F(WindowSessionImplTest4, IsFocused, Function | SmallTest | Level2)817 HWTEST_F(WindowSessionImplTest4, IsFocused, Function | SmallTest | Level2)
818 {
819     sptr<WindowOption> option = new WindowOption();
820     option->SetWindowName("WindowSessionCreateCheck");
821     sptr<WindowSessionImpl> window =
822         new (std::nothrow) WindowSessionImpl(option);
823     ASSERT_NE(window, nullptr);
824     bool res = window->IsFocused();
825     ASSERT_EQ(res, false);
826 
827     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->RequestFocus());
828 
829     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
830                                "CreateTestAbility"};
831     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
832     ASSERT_NE(nullptr, session);
833     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
834     int32_t persistentId = window->GetPersistentId();
835     if (persistentId == INVALID_SESSION_ID) {
836         persistentId = 1;
837         window->property_->SetPersistentId(persistentId);
838     }
839     if (window->state_ == WindowState::STATE_DESTROYED) {
840         window->state_ = WindowState::STATE_SHOWN;
841     }
842     window->hostSession_ = session;
843     window->RequestFocus();
844     ASSERT_FALSE(window->IsWindowSessionInvalid());
845     ASSERT_EQ(persistentId, window->GetPersistentId());
846     ASSERT_EQ(WMError::WM_OK, window->Destroy());
847 }
848 
849 /**
850  * @tc.name: NapiSetUIContent
851  * @tc.desc: NapiSetUIContent Test
852  * @tc.type: FUNC
853  */
HWTEST_F(WindowSessionImplTest4, NapiSetUIContent, Function | SmallTest | Level2)854 HWTEST_F(WindowSessionImplTest4, NapiSetUIContent, Function | SmallTest | Level2)
855 {
856     sptr<WindowOption> option = new WindowOption();
857     ASSERT_NE(option, nullptr);
858     option->SetWindowName("NapiSetUIContent");
859     option->SetIsUIExtFirstSubWindow(true);
860     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
861     ASSERT_NE(window, nullptr);
862     window->property_->SetPersistentId(1);
863     std::string url = "";
864     AppExecFwk::Ability* ability = nullptr;
865 
866     window->SetUIContentByName(url, nullptr, nullptr, nullptr);
867     window->SetUIContentByAbc(url, nullptr, nullptr, nullptr);
868     WMError res1 = window->NapiSetUIContent(url, nullptr, nullptr, BackupAndRestoreType::CONTINUATION,
869         nullptr, ability);
870     ASSERT_EQ(res1, WMError::WM_ERROR_INVALID_WINDOW);
871 }
872 
873 /**
874  * @tc.name: GetAbcContent
875  * @tc.desc: GetAbcContent Test
876  * @tc.type: FUNC
877  */
HWTEST_F(WindowSessionImplTest4, GetAbcContent, Function | SmallTest | Level2)878 HWTEST_F(WindowSessionImplTest4, GetAbcContent, Function | SmallTest | Level2)
879 {
880     sptr<WindowOption> option = new WindowOption();
881     ASSERT_NE(option, nullptr);
882     option->SetWindowName("GetAbcContent");
883     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
884     ASSERT_NE(window, nullptr);
885     std::string abcPath = "";
886     std::shared_ptr<std::vector<uint8_t>> res = window->GetAbcContent(abcPath);
887     std::filesystem::path abcFile{abcPath};
888     ASSERT_TRUE(abcFile.empty());
889     ASSERT_TRUE(!abcFile.is_absolute());
890     ASSERT_TRUE(!std::filesystem::exists(abcFile));
891     ASSERT_EQ(res, nullptr);
892 
893     abcPath = "/abc";
894     res = window->GetAbcContent(abcPath);
895     std::filesystem::path abcFile2{abcPath};
896     ASSERT_FALSE(abcFile2.empty());
897     ASSERT_FALSE(!abcFile2.is_absolute());
898     ASSERT_TRUE(!std::filesystem::exists(abcFile2));
899     ASSERT_EQ(res, nullptr);
900 
901     abcPath = "abc";
902     res = window->GetAbcContent(abcPath);
903     std::filesystem::path abcFile3{abcPath};
904     ASSERT_FALSE(abcFile3.empty());
905     ASSERT_TRUE(!abcFile3.is_absolute());
906     ASSERT_TRUE(!std::filesystem::exists(abcFile3));
907     ASSERT_EQ(res, nullptr);
908 
909     abcPath = "/log";
910     res = window->GetAbcContent(abcPath);
911     std::filesystem::path abcFile4{abcPath};
912     ASSERT_FALSE(abcFile4.empty());
913     ASSERT_FALSE(!abcFile4.is_absolute());
914     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
915         ASSERT_FALSE(!std::filesystem::exists(abcFile4));
916         ASSERT_NE(res, nullptr);
917         std::fstream file(abcFile, std::ios::in | std::ios::binary);
918         ASSERT_FALSE(file);
919     }
920     window->Destroy();
921 }
922 
923 /**
924  * @tc.name: SetLandscapeMultiWindow
925  * @tc.desc: SetLandscapeMultiWindow and check the retCode
926  * @tc.type: FUNC
927  */
HWTEST_F(WindowSessionImplTest4, SetLandscapeMultiWindow, Function | SmallTest | Level2)928 HWTEST_F(WindowSessionImplTest4, SetLandscapeMultiWindow, Function | SmallTest | Level2)
929 {
930     sptr<WindowOption> option = new WindowOption();
931     option->SetWindowName("SetLandscapeMultiWindow");
932     sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
933     ASSERT_NE(nullptr, window);
934     WMError retCode = window->SetLandscapeMultiWindow(false);
935     ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
936     window->property_->SetPersistentId(1);
937     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
938     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
939     ASSERT_NE(nullptr, session);
940     window->hostSession_ = session;
941     window->state_ = WindowState::STATE_CREATED;
942     retCode = window->SetLandscapeMultiWindow(false);
943     ASSERT_EQ(retCode, WMError::WM_OK);
944 }
945 
946 /**
947  * @tc.name: GetTouchable
948  * @tc.desc: GetTouchable
949  * @tc.type: FUNC
950  */
HWTEST_F(WindowSessionImplTest4, GetTouchable, Function | SmallTest | Level2)951 HWTEST_F(WindowSessionImplTest4, GetTouchable, Function | SmallTest | Level2)
952 {
953     sptr<WindowOption> option = new WindowOption();
954     ASSERT_NE(option, nullptr);
955     option->SetWindowName("GetTouchable");
956     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
957     ASSERT_NE(window, nullptr);
958     window->GetTouchable();
959     window->GetBrightness();
960     ASSERT_NE(window, nullptr);
961 }
962 
963 /**
964  * @tc.name: Notify03
965  * @tc.desc: NotifyCloseExistPipWindow NotifyAfterResumed NotifyAfterPaused
966  * @tc.type: FUNC
967  */
HWTEST_F(WindowSessionImplTest4, Notify03, Function | SmallTest | Level2)968 HWTEST_F(WindowSessionImplTest4, Notify03, Function | SmallTest | Level2)
969 {
970     sptr<WindowOption> option = new WindowOption();
971     option->SetWindowName("Notify03");
972     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
973 
974     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
975                                "CreateTestAbility"};
976     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
977     ASSERT_NE(nullptr, session);
978     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
979 
980     window->NotifyAfterResumed();
981     window->NotifyAfterPaused();
982     WSError res = window->NotifyCloseExistPipWindow();
983     ASSERT_EQ(res, WSError::WS_OK);
984     AAFwk::WantParams wantParams;
985     WSError ret = window->NotifyTransferComponentData(wantParams);
986     ASSERT_EQ(ret, WSError::WS_OK);
987     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
988 }
989 
990 /**
991  * @tc.name: Filter
992  * @tc.desc: Filter
993  * @tc.type: FUNC
994  */
HWTEST_F(WindowSessionImplTest4, Filter, Function | SmallTest | Level2)995 HWTEST_F(WindowSessionImplTest4, Filter, Function | SmallTest | Level2)
996 {
997     sptr<WindowOption> option = new WindowOption();
998     ASSERT_NE(option, nullptr);
999     option->SetWindowName("Filter");
1000     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1001     ASSERT_NE(window, nullptr);
1002     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
1003     window->FilterKeyEvent(keyEvent);
1004     ASSERT_EQ(window->keyEventFilter_, nullptr);
1005     window->SetKeyEventFilter([](MMI::KeyEvent& keyEvent) {
1006         GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetKeyEventFilter";
1007         return true;
1008     });
1009     ASSERT_NE(window->keyEventFilter_, nullptr);
1010     window->FilterKeyEvent(keyEvent);
1011     auto ret = window->ClearKeyEventFilter();
1012     ASSERT_EQ(ret, WMError::WM_OK);
1013 }
1014 
1015 /**
1016  * @tc.name: UpdateOrientation
1017  * @tc.desc: UpdateOrientation
1018  * @tc.type: FUNC
1019  */
HWTEST_F(WindowSessionImplTest4, UpdateOrientation, Function | SmallTest | Level2)1020 HWTEST_F(WindowSessionImplTest4, UpdateOrientation, Function | SmallTest | Level2)
1021 {
1022     sptr<WindowOption> option = new WindowOption();
1023     ASSERT_NE(option, nullptr);
1024     option->SetWindowName("UpdateOrientation");
1025     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1026     ASSERT_NE(window, nullptr);
1027     auto ret = window->UpdateOrientation();
1028     ASSERT_EQ(WSError::WS_OK, ret);
1029 }
1030 
1031 /**
1032  * @tc.name: SetTitleButtonVisible01
1033  * @tc.desc: SetTitleButtonVisible
1034  * @tc.type: FUNC
1035 */
HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible01, Function | SmallTest | Level2)1036 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible01, Function | SmallTest | Level2)
1037 {
1038     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible01 start";
1039     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1040     ASSERT_NE(option, nullptr);
1041     option->SetWindowName("SetTitleButtonVisible");
1042     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1043     ASSERT_NE(window, nullptr);
1044     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1045     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1046     ASSERT_NE(nullptr, session);
1047     window->hostSession_ = session;
1048     ASSERT_NE(window->property_, nullptr);
1049     window->property_->SetPersistentId(1);
1050     window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1051     WMError res = window->SetTitleButtonVisible(false, false, false, true);
1052     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_CALLING);
1053     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible01 end";
1054 }
1055 
1056 /**
1057  * @tc.name: SetTitleButtonVisible02
1058  * @tc.desc: SetTitleButtonVisible
1059  * @tc.type: FUNC
1060 */
HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible02, Function | SmallTest | Level2)1061 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible02, Function | SmallTest | Level2)
1062 {
1063     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible02 start";
1064     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1065     ASSERT_NE(option, nullptr);
1066     option->SetWindowName("SetTitleButtonVisible");
1067     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1068     ASSERT_NE(window, nullptr);
1069     ASSERT_NE(window->property_, nullptr);
1070     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1071     WMError res = window->SetTitleButtonVisible(false, false, false, true);
1072     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1073     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible02 end";
1074 }
1075 
1076 /**
1077  * @tc.name: SetTitleButtonVisible03
1078  * @tc.desc: SetTitleButtonVisible
1079  * @tc.type: FUNC
1080 */
HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible03, Function | SmallTest | Level2)1081 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible03, Function | SmallTest | Level2)
1082 {
1083     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible03 start";
1084     sptr option = new (std::nothrow) WindowOption();
1085     ASSERT_NE(option, nullptr);
1086     option->SetWindowName("SetTitleButtonVisible");
1087     sptr window = new (std::nothrow) WindowSessionImpl(option);
1088     ASSERT_NE(window, nullptr);
1089     ASSERT_NE(window->property_, nullptr);
1090     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1091     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1092     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1093     window->windowSystemConfig_.freeMultiWindowSupport_ = true;
1094     window->windowSystemConfig_.isSystemDecorEnable_ = true;
1095     window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1096     WMError res = window->SetTitleButtonVisible(false, false, false, true);
1097     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1098     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1099     res = window->SetTitleButtonVisible(false, false, false, true);
1100     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1101     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible03 end";
1102 }
1103 
1104 /**
1105  * @tc.name: GetTitleButtonVisible01
1106  * @tc.desc: GetTitleButtonVisible
1107  * @tc.type: FUNC
1108 */
HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible01, Function | SmallTest | Level2)1109 HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible01, Function | SmallTest | Level2)
1110 {
1111     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1112     ASSERT_NE(option, nullptr);
1113     option->SetWindowName("GetTitleButtonVisible01");
1114     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1115     ASSERT_NE(window, nullptr);
1116     ASSERT_NE(window->property_, nullptr);
1117     uint32_t modeSupportInfo = 1 | (1 << 1) | (1 << 2);
1118     window->property_->SetModeSupportInfo(modeSupportInfo);
1119     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1120     // show Maximize, Minimize, Split buttons.
1121     window->windowTitleVisibleFlags_ = { false, false, false, false };
1122     bool hideMaximizeButton = false;
1123     bool hideMinimizeButton = false;
1124     bool hideSplitButton = false;
1125     bool hideCloseButton = false;
1126     window->GetTitleButtonVisible(true, hideMaximizeButton, hideMinimizeButton, hideSplitButton,
1127         hideCloseButton);
1128     ASSERT_EQ(hideMaximizeButton, true);
1129     ASSERT_EQ(hideMinimizeButton, true);
1130     ASSERT_EQ(hideSplitButton, true);
1131     ASSERT_EQ(hideCloseButton, true);
1132 }
1133 
1134 /**
1135  * @tc.name: UpdateRect03
1136  * @tc.desc: UpdateRect
1137  * @tc.type: FUNC
1138  */
HWTEST_F(WindowSessionImplTest4, UpdateRect03, Function | SmallTest | Level2)1139 HWTEST_F(WindowSessionImplTest4, UpdateRect03, Function | SmallTest | Level2)
1140 {
1141     sptr<WindowOption> option = new WindowOption();
1142     option->SetWindowName("WindowSessionCreateCheck");
1143     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1144     ASSERT_NE(window, nullptr);
1145 
1146     WSRect rect;
1147     rect.posX_ = 0;
1148     rect.posY_ = 0;
1149     rect.height_ = 0;
1150     rect.width_ = 0;
1151 
1152     Rect rectW; // GetRect().IsUninitializedRect is true
1153     rectW.posX_ = 0;
1154     rectW.posY_ = 0;
1155     rectW.height_ = 0; // rectW - rect > 50
1156     rectW.width_ = 0;  // rectW - rect > 50
1157 
1158     window->property_->SetWindowRect(rectW);
1159     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1160     WSError res = window->UpdateRect(rect, reason);
1161     ASSERT_EQ(res, WSError::WS_OK);
1162 
1163     rect.height_ = 50;
1164     rect.width_ = 50;
1165     rectW.height_ = 50;
1166     rectW.width_ = 50;
1167     window->property_->SetWindowRect(rectW);
1168     res = window->UpdateRect(rect, reason);
1169     ASSERT_EQ(res, WSError::WS_OK);
1170 }
1171 
1172 /**
1173  * @tc.name: GetTitleButtonVisible02
1174  * @tc.desc: GetTitleButtonVisible
1175  * @tc.type: FUNC
1176 */
HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible02, Function | SmallTest | Level2)1177 HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible02, Function | SmallTest | Level2)
1178 {
1179     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1180     ASSERT_NE(option, nullptr);
1181     option->SetWindowName("GetTitleButtonVisible02");
1182     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1183     ASSERT_NE(window, nullptr);
1184     ASSERT_NE(window->property_, nullptr);
1185     // only not support WINDOW_MODE_SUPPORT_SPLIT
1186     uint32_t modeSupportInfo = 1 | (1 << 1);
1187     window->property_->SetModeSupportInfo(modeSupportInfo);
1188     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1189     // show Maximize, Minimize, Split buttons.
1190     window->windowTitleVisibleFlags_ = { true, true, true, true };
1191     bool hideMaximizeButton = false;
1192     bool hideMinimizeButton = false;
1193     bool hideSplitButton = false;
1194     bool hideCloseButton = false;
1195     window->GetTitleButtonVisible(true, hideMaximizeButton, hideMinimizeButton, hideSplitButton, hideCloseButton);
1196     ASSERT_EQ(hideMaximizeButton, false);
1197     ASSERT_EQ(hideMinimizeButton, false);
1198     ASSERT_EQ(hideSplitButton, false);
1199     ASSERT_EQ(hideCloseButton, false);
1200 }
1201 
1202 /**
1203  * @tc.name: GetTitleButtonVisible03
1204  * @tc.desc: GetTitleButtonVisible
1205  * @tc.type: FUNC
1206 */
HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible03, Function | SmallTest | Level2)1207 HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible03, Function | SmallTest | Level2)
1208 {
1209     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1210     ASSERT_NE(option, nullptr);
1211     option->SetWindowName("GetTitleButtonVisible03");
1212     option->SetDisplayId(1);
1213     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1214     ASSERT_NE(window, nullptr);
1215     ASSERT_NE(window->property_, nullptr);
1216     ASSERT_EQ(1, window->GetDisplayId());
1217     // only not support WINDOW_MODE_SUPPORT_SPLIT
1218     uint32_t modeSupportInfo = 1 | (1 << 1) | (1 << 2);
1219     window->property_->SetModeSupportInfo(modeSupportInfo);
1220     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1221     // show Maximize, Minimize, Split buttons.
1222     window->windowTitleVisibleFlags_ = { false, false, false, false };
1223     bool hideMaximizeButton = true;
1224     bool hideMinimizeButton = true;
1225     bool hideSplitButton = true;
1226     bool hideCloseButton = true;
1227     window->GetTitleButtonVisible(false, hideMaximizeButton, hideMinimizeButton, hideSplitButton, hideCloseButton);
1228     ASSERT_EQ(hideMaximizeButton, true);
1229     ASSERT_EQ(hideMinimizeButton, true);
1230     ASSERT_EQ(hideSplitButton, true);
1231     ASSERT_EQ(hideCloseButton, true);
1232 }
1233 
1234 /**
1235  * @tc.name: GetAppForceLandscapeConfig01
1236  * @tc.desc: GetAppForceLandscapeConfig
1237  * @tc.type: FUNC
1238 */
HWTEST_F(WindowSessionImplTest4, GetAppForceLandscapeConfig01, Function | SmallTest | Level2)1239 HWTEST_F(WindowSessionImplTest4, GetAppForceLandscapeConfig01, Function | SmallTest | Level2)
1240 {
1241     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1242     ASSERT_NE(option, nullptr);
1243     option->SetWindowName("GetAppForceLandscapeConfig01");
1244     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1245     ASSERT_NE(window, nullptr);
1246     ASSERT_NE(window->property_, nullptr);
1247     window->property_->SetPersistentId(1);
1248     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1249     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
1250     ASSERT_NE(nullptr, session);
1251     window->hostSession_ = session;
1252     AppForceLandscapeConfig config = {};
1253     window->GetAppForceLandscapeConfig(config);
1254     window->hostSession_ = nullptr;
1255     WMError res = window->GetAppForceLandscapeConfig(config);
1256     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1257 }
1258 
1259 /**
1260  * @tc.name: UpdatePiPControlStatus01
1261  * @tc.desc: UpdatePiPControlStatus
1262  * @tc.type: FUNC
1263 */
HWTEST_F(WindowSessionImplTest4, UpdatePiPControlStatus01, Function | SmallTest | Level2)1264 HWTEST_F(WindowSessionImplTest4, UpdatePiPControlStatus01, Function | SmallTest | Level2)
1265 {
1266     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1267     ASSERT_NE(option, nullptr);
1268     option->SetWindowName("UpdatePiPControlStatus01");
1269     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1270     ASSERT_NE(window, nullptr);
1271     ASSERT_NE(window->property_, nullptr);
1272     window->property_->SetPersistentId(1);
1273     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1274     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
1275     ASSERT_NE(nullptr, session);
1276     window->hostSession_ = session;
1277     auto controlType = PiPControlType::VIDEO_PLAY_PAUSE;
1278     auto status = PiPControlStatus::ENABLED;
1279     window->UpdatePiPControlStatus(controlType, status);
1280     window->hostSession_ = nullptr;
1281     window->UpdatePiPControlStatus(controlType, status);
1282 }
1283 
1284 /**
1285  * @tc.name: SetAutoStartPiP
1286  * @tc.desc: SetAutoStartPiP
1287  * @tc.type: FUNC
1288 */
HWTEST_F(WindowSessionImplTest4, SetAutoStartPiP, Function | SmallTest | Level2)1289 HWTEST_F(WindowSessionImplTest4, SetAutoStartPiP, Function | SmallTest | Level2)
1290 {
1291     auto option = sptr<WindowOption>::MakeSptr();
1292     ASSERT_NE(option, nullptr);
1293     option->SetWindowName("SetAutoStartPiP");
1294     auto window = sptr<WindowSessionImpl>::MakeSptr(option);
1295     ASSERT_NE(window, nullptr);
1296     window->property_->SetPersistentId(1);
1297     SessionInfo sessionInfo = { "SetAutoStartPiP", "SetAutoStartPiP", "SetAutoStartPiP" };
1298     auto session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1299     ASSERT_NE(nullptr, session);
1300     window->hostSession_ = session;
1301     bool isAutoStart = true;
1302     window->SetAutoStartPiP(isAutoStart);
1303     window->hostSession_ = nullptr;
1304     window->SetAutoStartPiP(isAutoStart);
1305 }
1306 
1307 /**
1308  * @tc.name: NotifyWindowVisibility01
1309  * @tc.desc: NotifyWindowVisibility
1310  * @tc.type: FUNC
1311 */
HWTEST_F(WindowSessionImplTest4, NotifyWindowVisibility01, Function | SmallTest | Level2)1312 HWTEST_F(WindowSessionImplTest4, NotifyWindowVisibility01, Function | SmallTest | Level2)
1313 {
1314     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1315     ASSERT_NE(option, nullptr);
1316     option->SetWindowName("NotifyWindowVisibility01");
1317     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1318     ASSERT_NE(window, nullptr);
1319     ASSERT_NE(window->property_, nullptr);
1320     window->property_->SetPersistentId(1);
1321     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1322     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
1323     ASSERT_NE(nullptr, session);
1324     window->hostSession_ = session;
1325     window->NotifyWindowVisibility(false);
1326     sptr<IWindowVisibilityChangedListener> listener = new IWindowVisibilityChangedListener();
1327     window->RegisterWindowVisibilityChangeListener(listener);
1328     window->NotifyWindowVisibility(false);
1329     window->UnregisterWindowVisibilityChangeListener(listener);
1330 }
1331 
1332 /**
1333  * @tc.name: NotifyMainWindowClose01
1334  * @tc.desc: NotifyMainWindowClose
1335  * @tc.type: FUNC
1336 */
HWTEST_F(WindowSessionImplTest4, NotifyMainWindowClose01, Function | SmallTest | Level2)1337 HWTEST_F(WindowSessionImplTest4, NotifyMainWindowClose01, Function | SmallTest | Level2)
1338 {
1339     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1340     ASSERT_NE(option, nullptr);
1341     option->SetWindowName("NotifyMainWindowClose01");
1342     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1343     ASSERT_NE(window, nullptr);
1344     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1345     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1346     ASSERT_NE(nullptr, session);
1347     window->hostSession_ = session;
1348     ASSERT_NE(window->property_, nullptr);
1349     window->property_->SetPersistentId(1);
1350 
1351     bool terminateCloseProcess = false;
1352     WMError res = window->NotifyMainWindowClose(terminateCloseProcess);
1353     EXPECT_EQ(terminateCloseProcess, false);
1354     EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
1355     sptr<IMainWindowCloseListener> listener = sptr<IMainWindowCloseListener>::MakeSptr();
1356     window->RegisterMainWindowCloseListeners(listener);
1357     res = window->NotifyMainWindowClose(terminateCloseProcess);
1358     EXPECT_EQ(terminateCloseProcess, false);
1359     EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
1360     window->UnregisterMainWindowCloseListeners(listener);
1361 }
1362 
1363 /**
1364  * @tc.name: SetWindowContainerColor01
1365  * @tc.desc: SetWindowContainerColor
1366  * @tc.type: FUNC
1367  */
HWTEST_F(WindowSessionImplTest4, SetWindowContainerColor01, Function | SmallTest | Level2)1368 HWTEST_F(WindowSessionImplTest4, SetWindowContainerColor01, Function | SmallTest | Level2)
1369 {
1370     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor01 start";
1371     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1372     ASSERT_NE(option, nullptr);
1373     option->SetWindowName("SetWindowContainerColor");
1374     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1375     ASSERT_NE(window, nullptr);
1376     window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1377     std::string activeColor = "#00000000";
1378     std::string inactiveColor = "#00000000";
1379     WMError res = window->SetWindowContainerColor(activeColor, inactiveColor);
1380     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_CALLING);
1381     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor01 end";
1382 }
1383 
1384 /**
1385  * @tc.name: SetWindowContainerColor02
1386  * @tc.desc: SetWindowContainerColor
1387  * @tc.type: FUNC
1388  */
HWTEST_F(WindowSessionImplTest4, SetWindowContainerColor02, Function | SmallTest | Level2)1389 HWTEST_F(WindowSessionImplTest4, SetWindowContainerColor02, Function | SmallTest | Level2)
1390 {
1391     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor02 start";
1392     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1393     ASSERT_NE(option, nullptr);
1394     option->SetWindowName("SetWindowContainerColor");
1395     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1396     ASSERT_NE(window, nullptr);
1397     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1398     std::string activeColor = "#00000000";
1399     std::string inactiveColor = "#00000000";
1400     WMError res = window->SetWindowContainerColor(activeColor, inactiveColor);
1401     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1402     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor02 end";
1403 }
1404 
1405 /**
1406  * @tc.name: SetWindowContainerColor03
1407  * @tc.desc: SetWindowContainerColor
1408  * @tc.type: FUNC
1409  */
HWTEST_F(WindowSessionImplTest4, SetWindowContainerColor03, Function | SmallTest | Level2)1410 HWTEST_F(WindowSessionImplTest4, SetWindowContainerColor03, Function | SmallTest | Level2)
1411 {
1412     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor03 start";
1413     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1414     ASSERT_NE(option, nullptr);
1415     option->SetWindowName("SetWindowContainerColor");
1416     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1417     ASSERT_NE(window, nullptr);
1418     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1419     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1420     window->windowSystemConfig_.freeMultiWindowSupport_ = true;
1421     window->windowSystemConfig_.isSystemDecorEnable_ = true;
1422     window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1423     std::string activeColor = "#00000000";
1424     std::string inactiveColor = "#00000000";
1425     WMError res = window->SetWindowContainerColor(activeColor, inactiveColor);
1426     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1427     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor03 end";
1428 }
1429 
1430 /**
1431  * @tc.name: SetWindowContainerColor04
1432  * @tc.desc: SetWindowContainerColor
1433  * @tc.type: FUNC
1434  */
HWTEST_F(WindowSessionImplTest4, SetWindowContainerColor04, Function | SmallTest | Level2)1435 HWTEST_F(WindowSessionImplTest4, SetWindowContainerColor04, Function | SmallTest | Level2)
1436 {
1437     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor04 start";
1438     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1439     ASSERT_NE(option, nullptr);
1440     option->SetWindowName("SetWindowContainerColor");
1441     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1442     ASSERT_NE(window, nullptr);
1443     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1444     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1445     window->windowSystemConfig_.freeMultiWindowSupport_ = true;
1446     window->windowSystemConfig_.isSystemDecorEnable_ = true;
1447     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1448     std::string activeColor = "color";
1449     std::string inactiveColor = "123";
1450     WMError res = window->SetWindowContainerColor(activeColor, inactiveColor);
1451     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1452     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor04 end";
1453 }
1454 
1455 /**
1456  * @tc.name: IsPcOrPadCapabilityEnabled
1457  * @tc.desc: IsPcOrPadCapabilityEnabled test
1458  * @tc.type: FUNC
1459  */
HWTEST_F(WindowSessionImplTest4, IsPcOrPadCapabilityEnabled, Function | SmallTest | Level2)1460 HWTEST_F(WindowSessionImplTest4, IsPcOrPadCapabilityEnabled, Function | SmallTest | Level2)
1461 {
1462     GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadCapabilityEnabled start";
1463     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1464     option->SetWindowName("IsPcOrPadCapabilityEnabled");
1465     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1466     ASSERT_NE(window->property_, nullptr);
1467     window->property_->SetPersistentId(1);
1468     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1469     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1470     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1471     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1472     ASSERT_NE(nullptr, session);
1473     window->hostSession_ = session;
1474 
1475     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1476     EXPECT_EQ(true, window->IsPcOrPadCapabilityEnabled());
1477     window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1478     EXPECT_EQ(false, window->IsPcOrPadCapabilityEnabled());
1479     window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
1480     EXPECT_EQ(false, window->IsPcOrPadCapabilityEnabled());
1481     window->property_->SetIsPcAppInPad(true);
1482     EXPECT_EQ(true, window->IsPcOrPadCapabilityEnabled());
1483     EXPECT_EQ(WMError::WM_OK, window->Destroy(true));
1484     GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadCapabilityEnabled end";
1485 }
1486 
1487 /**
1488  * @tc.name: DestroySubWindow
1489  * @tc.desc: DestroySubWindow test
1490  * @tc.type: FUNC
1491  */
HWTEST_F(WindowSessionImplTest4, DestroySubWindow, Function | SmallTest | Level2)1492 HWTEST_F(WindowSessionImplTest4, DestroySubWindow, Function | SmallTest | Level2)
1493 {
1494     GTEST_LOG_(INFO) << "WindowSessionImplTest4: DestroySubWindow start";
1495     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1496     ASSERT_NE(option, nullptr);
1497     option->SetWindowName("DestroySubWindow");
1498     option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1499     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1500     ASSERT_NE(window->property_, nullptr);
1501     window->property_->SetPersistentId(1);
1502     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1503     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1504     ASSERT_NE(nullptr, session);
1505     window->hostSession_ = session;
1506     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1507 
1508     sptr<WindowOption> subOption = sptr<WindowOption>::MakeSptr();
1509     ASSERT_NE(subOption, nullptr);
1510     subOption->SetWindowName("DestroySubWindow01");
1511     subOption->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1512     sptr<WindowSessionImpl> subWindow = sptr<WindowSessionImpl>::MakeSptr(subOption);
1513     ASSERT_NE(subWindow, nullptr);
1514     ASSERT_NE(subWindow->property_, nullptr);
1515     subWindow->property_->SetPersistentId(2);
1516     SessionInfo subSessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1517     sptr<SessionMocker> subSession = sptr<SessionMocker>::MakeSptr(subSessionInfo);
1518     ASSERT_NE(nullptr, subSession);
1519     subWindow->hostSession_ = subSession;
1520     subWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1521     std::vector<sptr<WindowSessionImpl>> vec;
1522     WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
1523         std::vector<sptr<WindowSessionImpl>>>(1, vec));
1524     WindowSessionImpl::subWindowSessionMap_[1].push_back(subWindow);
1525     window->DestroySubWindow();
1526     EXPECT_EQ(WMError::WM_OK, window->Destroy(true));
1527 }
1528 
1529 /**
1530  * @tc.name: UpdateSubWindowStateAndNotify01
1531  * @tc.desc: UpdateSubWindowStateAndNotify
1532  * @tc.type: FUNC
1533  */
HWTEST_F(WindowSessionImplTest4, UpdateSubWindowStateAndNotify01, Function | SmallTest | Level2)1534 HWTEST_F(WindowSessionImplTest4, UpdateSubWindowStateAndNotify01, Function | SmallTest | Level2)
1535 {
1536     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1537     ASSERT_NE(option, nullptr);
1538     option->SetWindowName("UpdateSubWindowStateAndNotify01");
1539     option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1540     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1541     ASSERT_NE(window->property_, nullptr);
1542     window->property_->SetPersistentId(1);
1543     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1544     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1545     ASSERT_NE(nullptr, session);
1546     window->hostSession_ = session;
1547     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1548 
1549     sptr<WindowOption> subOption = sptr<WindowOption>::MakeSptr();
1550     ASSERT_NE(subOption, nullptr);
1551     subOption->SetWindowName("UpdateSubWindowStateAndNotify011");
1552     subOption->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1553     sptr<WindowSessionImpl> subWindow = sptr<WindowSessionImpl>::MakeSptr(subOption);
1554     ASSERT_NE(subWindow, nullptr);
1555     ASSERT_NE(subWindow->property_, nullptr);
1556     subWindow->property_->SetPersistentId(2);
1557     SessionInfo subSessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1558     sptr<SessionMocker> subSession = sptr<SessionMocker>::MakeSptr(subSessionInfo);
1559     ASSERT_NE(nullptr, subSession);
1560     subWindow->hostSession_ = subSession;
1561     subWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1562     std::vector<sptr<WindowSessionImpl>> vec;
1563     WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
1564         std::vector<sptr<WindowSessionImpl>>>(1, vec));
1565     subWindow->UpdateSubWindowStateAndNotify(1, WindowState::STATE_HIDDEN);
1566     WindowSessionImpl::subWindowSessionMap_[1].push_back(subWindow);
1567     subWindow->state_ = WindowState::STATE_SHOWN;
1568     window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_HIDDEN);
1569     window->state_ = WindowState::STATE_HIDDEN;
1570     window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_HIDDEN);
1571     window->state_ = WindowState::STATE_SHOWN;
1572     window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_SHOWN);
1573     window->state_ = WindowState::STATE_SHOWN;
1574     window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_SHOWN);
1575     EXPECT_EQ(WMError::WM_OK, subWindow->Destroy(true));
1576     EXPECT_EQ(WMError::WM_OK, window->Destroy(true));
1577 }
1578 
1579 /**
1580  * @tc.name: GetVirtualPixelRatio
1581  * @tc.desc: test GetVirtualPixelRatio
1582  * @tc.type: FUNC
1583  */
HWTEST_F(WindowSessionImplTest4, GetVirtualPixelRatio, Function | SmallTest | Level2)1584 HWTEST_F(WindowSessionImplTest4, GetVirtualPixelRatio, Function | SmallTest | Level2)
1585 {
1586     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetVirtualPixelRatio start";
1587     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1588     option->SetWindowName("GetVirtualPixelRatio");
1589     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1590     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1591     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1592 
1593     float vpr = -1.0f;
1594     window->property_->SetDisplayId(-1);
1595     vpr = window->GetVirtualPixelRatio();
1596     ASSERT_EQ(vpr, 0.0f);
1597 
1598     window->property_->SetDisplayId(0);
1599     vpr = window->GetVirtualPixelRatio();
1600     ASSERT_NE(vpr, 0.0f);
1601     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetVirtualPixelRatio end";
1602 }
1603 
1604 /**
1605  * @tc.name: NotifyRotationAnimationEnd
1606  * @tc.desc: test NotifyRotationAnimationEnd
1607  * @tc.type: FUNC
1608  */
HWTEST_F(WindowSessionImplTest4, NotifyRotationAnimationEnd001, Function | SmallTest | Level2)1609 HWTEST_F(WindowSessionImplTest4, NotifyRotationAnimationEnd001, Function | SmallTest | Level2)
1610 {
1611     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1612     ASSERT_NE(option, nullptr);
1613     option->SetWindowName("NotifyRotationAnimationEnd001");
1614     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1615     ASSERT_NE(window, nullptr);
1616 
1617     ASSERT_NE(window->handler_, nullptr);
1618     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1619     ASSERT_NE(window->uiContent_, nullptr);
1620     window->NotifyRotationAnimationEnd();
1621 
1622     window->uiContent_ = nullptr;
1623     ASSERT_EQ(window->uiContent_, nullptr);
1624     window->NotifyRotationAnimationEnd();
1625 
1626     window->handler_ = nullptr;
1627     ASSERT_EQ(window->handler_, nullptr);
1628     window->NotifyRotationAnimationEnd();
1629 }
1630 
1631 /**
1632  * @tc.name: GetSubWindow
1633  * @tc.desc: test GetSubWindow
1634  * @tc.type: FUNC
1635  */
HWTEST_F(WindowSessionImplTest4, GetSubWindow, Function | SmallTest | Level2)1636 HWTEST_F(WindowSessionImplTest4, GetSubWindow, Function | SmallTest | Level2)
1637 {
1638     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetSubWindow start";
1639     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1640     option->SetWindowName("GetSubWindow");
1641     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1642     ASSERT_NE(nullptr, window);
1643     ASSERT_NE(nullptr, window->property_);
1644     window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1645     window->property_->SetParentId(101); // this subWindow's parentId is 101
1646     std::vector<sptr<Window> > subWindows = window->GetSubWindow(101); // 101 is parentId
1647     ASSERT_EQ(0, subWindows.size());
1648     WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
1649         std::vector<sptr<WindowSessionImpl> > >(101, { window }));
1650     subWindows = window->GetSubWindow(101); // 101 is parentId
1651     ASSERT_EQ(1, subWindows.size());
1652     WindowSessionImpl::subWindowSessionMap_.erase(101); // 101
1653     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetVirtualPixelRatio end";
1654 }
1655 
1656 /**
1657  * @tc.name: ClearListenersById_displayMoveListeners
1658  * @tc.desc: ClearListenersById_displayMoveListeners
1659  * @tc.type: FUNC
1660  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_displayMoveListeners, Function | SmallTest | Level2)1661 HWTEST_F(WindowSessionImplTest4, ClearListenersById_displayMoveListeners, Function | SmallTest | Level2)
1662 {
1663     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_displayMoveListeners start";
1664     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1665     option_->SetWindowName("ClearListenersById_displayMoveListeners");
1666     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1667     ASSERT_NE(window_, nullptr);
1668 
1669     int persistentId = window_->GetPersistentId();
1670     window_->ClearListenersById(persistentId);
1671 
1672     sptr<IDisplayMoveListener> listener_ = new (std::nothrow) MockIDisplayMoveListener();
1673     window_->RegisterDisplayMoveListener(listener_);
1674     ASSERT_NE(window_->displayMoveListeners_.find(persistentId), window_->displayMoveListeners_.end());
1675 
1676     window_->ClearListenersById(persistentId);
1677     ASSERT_EQ(window_->displayMoveListeners_.find(persistentId), window_->displayMoveListeners_.end());
1678 
1679     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_displayMoveListeners end";
1680 }
1681 
1682 /**
1683  * @tc.name: ClearListenersById_lifecycleListeners
1684  * @tc.desc: ClearListenersById_lifecycleListeners
1685  * @tc.type: FUNC
1686  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_lifecycleListeners, Function | SmallTest | Level2)1687 HWTEST_F(WindowSessionImplTest4, ClearListenersById_lifecycleListeners, Function | SmallTest | Level2)
1688 {
1689     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_lifecycleListeners start";
1690     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1691     option_->SetWindowName("ClearListenersById_lifecycleListeners");
1692     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1693     ASSERT_NE(window_, nullptr);
1694 
1695     int persistentId = window_->GetPersistentId();
1696     window_->ClearListenersById(persistentId);
1697 
1698     sptr<IWindowLifeCycle> listener_ = new (std::nothrow) MockWindowLifeCycleListener();
1699     window_->RegisterLifeCycleListener(listener_);
1700     ASSERT_NE(window_->lifecycleListeners_.find(persistentId), window_->lifecycleListeners_.end());
1701 
1702     window_->ClearListenersById(persistentId);
1703     ASSERT_EQ(window_->lifecycleListeners_.find(persistentId), window_->lifecycleListeners_.end());
1704 
1705     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_lifecycleListeners end";
1706 }
1707 
1708 /**
1709  * @tc.name: ClearListenersById_windowChangeListeners
1710  * @tc.desc: ClearListenersById_windowChangeListeners
1711  * @tc.type: FUNC
1712  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowChangeListeners, Function | SmallTest | Level2)1713 HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowChangeListeners, Function | SmallTest | Level2)
1714 {
1715     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowChangeListeners start";
1716     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1717     option_->SetWindowName("ClearListenersById_windowChangeListeners");
1718     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1719     ASSERT_NE(window_, nullptr);
1720 
1721     int persistentId = window_->GetPersistentId();
1722     window_->ClearListenersById(persistentId);
1723 
1724     sptr<IWindowChangeListener> listener_ = new (std::nothrow) MockWindowChangeListener();
1725     window_->RegisterWindowChangeListener(listener_);
1726     ASSERT_NE(window_->windowChangeListeners_.find(persistentId), window_->windowChangeListeners_.end());
1727 
1728     window_->ClearListenersById(persistentId);
1729     ASSERT_EQ(window_->windowChangeListeners_.find(persistentId), window_->windowChangeListeners_.end());
1730 
1731     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowChangeListeners end";
1732 }
1733 
1734 /**
1735  * @tc.name: ClearListenersById_avoidAreaChangeListeners
1736  * @tc.desc: ClearListenersById_avoidAreaChangeListeners
1737  * @tc.type: FUNC
1738  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_avoidAreaChangeListeners, Function | SmallTest | Level2)1739 HWTEST_F(WindowSessionImplTest4, ClearListenersById_avoidAreaChangeListeners, Function | SmallTest | Level2)
1740 {
1741     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_avoidAreaChangeListeners start";
1742     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1743     option_->SetWindowName("ClearListenersById_avoidAreaChangeListeners");
1744     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1745     ASSERT_NE(window_, nullptr);
1746 
1747     int persistentId = window_->GetPersistentId();
1748     window_->ClearListenersById(persistentId);
1749 
1750     sptr<IAvoidAreaChangedListener> listener_ = new (std::nothrow) MockAvoidAreaChangedListener();
1751     window_->RegisterExtensionAvoidAreaChangeListener(listener_);
1752     ASSERT_NE(window_->avoidAreaChangeListeners_.find(persistentId), window_->avoidAreaChangeListeners_.end());
1753 
1754     window_->ClearListenersById(persistentId);
1755     ASSERT_EQ(window_->avoidAreaChangeListeners_.find(persistentId), window_->avoidAreaChangeListeners_.end());
1756 
1757     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_avoidAreaChangeListeners end";
1758 }
1759 
1760 /**
1761  * @tc.name: ClearListenersById_dialogDeathRecipientListeners
1762  * @tc.desc: ClearListenersById_dialogDeathRecipientListeners
1763  * @tc.type: FUNC
1764  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_dialogDeathRecipientListeners, Function | SmallTest | Level2)1765 HWTEST_F(WindowSessionImplTest4, ClearListenersById_dialogDeathRecipientListeners, Function | SmallTest | Level2)
1766 {
1767     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_dialogDeathRecipientListeners start";
1768     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1769     option_->SetWindowName("ClearListenersById_dialogDeathRecipientListeners");
1770     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1771     ASSERT_NE(window_, nullptr);
1772 
1773     int persistentId = window_->GetPersistentId();
1774     window_->ClearListenersById(persistentId);
1775 
1776     sptr<IDialogDeathRecipientListener> listener_ = new (std::nothrow) MockIDialogDeathRecipientListener();
1777     window_->RegisterDialogDeathRecipientListener(listener_);
1778     ASSERT_NE(window_->dialogDeathRecipientListeners_.find(persistentId),
1779               window_->dialogDeathRecipientListeners_.end());
1780 
1781     window_->ClearListenersById(persistentId);
1782     ASSERT_EQ(window_->dialogDeathRecipientListeners_.find(persistentId),
1783               window_->dialogDeathRecipientListeners_.end());
1784 
1785     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_dialogDeathRecipientListeners end";
1786 }
1787 
1788 /**
1789  * @tc.name: ClearListenersById_dialogTargetTouchListener
1790  * @tc.desc: ClearListenersById_dialogTargetTouchListener
1791  * @tc.type: FUNC
1792  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_dialogTargetTouchListener, Function | SmallTest | Level2)1793 HWTEST_F(WindowSessionImplTest4, ClearListenersById_dialogTargetTouchListener, Function | SmallTest | Level2)
1794 {
1795     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_dialogTargetTouchListener start";
1796     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1797     option_->SetWindowName("ClearListenersById_dialogTargetTouchListener");
1798     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1799     ASSERT_NE(window_, nullptr);
1800 
1801     int persistentId = window_->GetPersistentId();
1802     window_->ClearListenersById(persistentId);
1803 
1804     sptr<IDialogTargetTouchListener> listener_ = new (std::nothrow) MockIDialogTargetTouchListener();
1805     window_->RegisterDialogTargetTouchListener(listener_);
1806     ASSERT_NE(window_->dialogTargetTouchListener_.find(persistentId), window_->dialogTargetTouchListener_.end());
1807 
1808     window_->ClearListenersById(persistentId);
1809     ASSERT_EQ(window_->dialogTargetTouchListener_.find(persistentId), window_->dialogTargetTouchListener_.end());
1810 
1811     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_dialogTargetTouchListener end";
1812 }
1813 
1814 /**
1815  * @tc.name: ClearListenersById_screenshotListeners
1816  * @tc.desc: ClearListenersById_screenshotListeners
1817  * @tc.type: FUNC
1818  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_screenshotListeners, Function | SmallTest | Level2)1819 HWTEST_F(WindowSessionImplTest4, ClearListenersById_screenshotListeners, Function | SmallTest | Level2)
1820 {
1821     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_screenshotListeners start";
1822     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1823     option_->SetWindowName("ClearListenersById_screenshotListeners");
1824     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1825     ASSERT_NE(window_, nullptr);
1826 
1827     int persistentId = window_->GetPersistentId();
1828     window_->ClearListenersById(persistentId);
1829 
1830     sptr<IScreenshotListener> listener_ = new (std::nothrow) MockIScreenshotListener();
1831     window_->RegisterScreenshotListener(listener_);
1832     ASSERT_NE(window_->screenshotListeners_.find(persistentId), window_->screenshotListeners_.end());
1833 
1834     window_->ClearListenersById(persistentId);
1835     ASSERT_EQ(window_->screenshotListeners_.find(persistentId), window_->screenshotListeners_.end());
1836 
1837     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_screenshotListeners end";
1838 }
1839 
1840 /**
1841  * @tc.name: ClearListenersById_windowStatusChangeListeners
1842  * @tc.desc: ClearListenersById_windowStatusChangeListeners
1843  * @tc.type: FUNC
1844  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowStatusChangeListeners, Function | SmallTest | Level2)1845 HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowStatusChangeListeners, Function | SmallTest | Level2)
1846 {
1847     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowStatusChangeListeners start";
1848     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1849     option_->SetWindowName("ClearListenersById_windowStatusChangeListeners");
1850     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1851     ASSERT_NE(window_, nullptr);
1852 
1853     int persistentId = window_->GetPersistentId();
1854     window_->ClearListenersById(persistentId);
1855 
1856     sptr<IWindowStatusChangeListener> listener_ = new (std::nothrow) MockWindowStatusChangeListener();
1857     window_->RegisterWindowStatusChangeListener(listener_);
1858     ASSERT_NE(window_->windowStatusChangeListeners_.find(persistentId), window_->windowStatusChangeListeners_.end());
1859 
1860     window_->ClearListenersById(persistentId);
1861     ASSERT_EQ(window_->windowStatusChangeListeners_.find(persistentId), window_->windowStatusChangeListeners_.end());
1862 
1863     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowStatusChangeListeners end";
1864 }
1865 
1866 /**
1867  * @tc.name: ClearListenersById_windowTitleButtonRectChangeListeners
1868  * @tc.desc: ClearListenersById_windowTitleButtonRectChangeListeners
1869  * @tc.type: FUNC
1870  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowTitleButtonRectChangeListeners, Function | SmallTest | Level2)1871 HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowTitleButtonRectChangeListeners, Function | SmallTest | Level2)
1872 {
1873     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowTitleButtonRectChangeListeners start";
1874     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1875     option_->SetWindowName("ClearListenersById_windowTitleButtonRectChangeListeners");
1876     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1877     ASSERT_NE(window_, nullptr);
1878 
1879     int persistentId = window_->GetPersistentId();
1880     window_->ClearListenersById(persistentId);
1881 
1882     sptr<IWindowTitleButtonRectChangedListener> listener_ =
1883         new (std::nothrow) MockWindowTitleButtonRectChangedListener();
1884     window_->windowTitleButtonRectChangeListeners_[persistentId].emplace_back(listener_);
1885     ASSERT_NE(window_->windowTitleButtonRectChangeListeners_.find(persistentId),
1886               window_->windowTitleButtonRectChangeListeners_.end());
1887 
1888     window_->ClearListenersById(persistentId);
1889     ASSERT_EQ(window_->windowTitleButtonRectChangeListeners_.find(persistentId),
1890               window_->windowTitleButtonRectChangeListeners_.end());
1891 
1892     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowTitleButtonRectChangeListeners end";
1893 }
1894 
1895 /**
1896  * @tc.name: ClearListenersById_windowNoInteractionListeners
1897  * @tc.desc: ClearListenersById_windowNoInteractionListeners
1898  * @tc.type: FUNC
1899  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowNoInteractionListeners, Function | SmallTest | Level2)1900 HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowNoInteractionListeners, Function | SmallTest | Level2)
1901 {
1902     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowNoInteractionListeners start";
1903     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1904     option_->SetWindowName("ClearListenersById_windowNoInteractionListeners");
1905     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1906     ASSERT_NE(window_, nullptr);
1907 
1908     int persistentId = window_->GetPersistentId();
1909     window_->ClearListenersById(persistentId);
1910 
1911     sptr<IWindowNoInteractionListener> listener_ = new (std::nothrow) MockWindowNoInteractionListener();
1912     window_->RegisterWindowNoInteractionListener(listener_);
1913     ASSERT_NE(window_->windowNoInteractionListeners_.find(persistentId), window_->windowNoInteractionListeners_.end());
1914 
1915     window_->ClearListenersById(persistentId);
1916     ASSERT_EQ(window_->windowNoInteractionListeners_.find(persistentId), window_->windowNoInteractionListeners_.end());
1917 
1918     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowNoInteractionListeners end";
1919 }
1920 
1921 /**
1922  * @tc.name: ClearListenersById_windowRectChangeListeners
1923  * @tc.desc: ClearListenersById_windowRectChangeListeners
1924  * @tc.type: FUNC
1925  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowRectChangeListeners, Function | SmallTest | Level2)1926 HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowRectChangeListeners, Function | SmallTest | Level2)
1927 {
1928     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowRectChangeListeners start";
1929     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1930     option_->SetWindowName("ClearListenersById_windowRectChangeListeners");
1931     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1932     ASSERT_NE(window_, nullptr);
1933 
1934     int persistentId = window_->GetPersistentId();
1935     window_->ClearListenersById(persistentId);
1936 
1937     sptr<IWindowRectChangeListener> listener_ = new (std::nothrow) MockWindowRectChangeListener();
1938     window_->RegisterWindowRectChangeListener(listener_);
1939     ASSERT_NE(window_->windowRectChangeListeners_.find(persistentId), window_->windowRectChangeListeners_.end());
1940 
1941     window_->ClearListenersById(persistentId);
1942     ASSERT_EQ(window_->windowRectChangeListeners_.find(persistentId), window_->windowRectChangeListeners_.end());
1943 
1944     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowRectChangeListeners end";
1945 }
1946 
1947 /**
1948  * @tc.name: ClearListenersById_subWindowCloseListeners
1949  * @tc.desc: ClearListenersById_subWindowCloseListeners
1950  * @tc.type: FUNC
1951  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_subWindowCloseListeners, Function | SmallTest | Level2)1952 HWTEST_F(WindowSessionImplTest4, ClearListenersById_subWindowCloseListeners, Function | SmallTest | Level2)
1953 {
1954     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_subWindowCloseListeners start";
1955     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1956     option_->SetWindowName("ClearListenersById_subWindowCloseListeners");
1957     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1958     ASSERT_NE(window_, nullptr);
1959 
1960     int persistentId = window_->GetPersistentId();
1961     window_->ClearListenersById(persistentId);
1962 
1963     sptr<ISubWindowCloseListener> listener_ = new (std::nothrow) MockISubWindowCloseListener();
1964     window_->subWindowCloseListeners_[persistentId] = listener_;
1965     ASSERT_NE(window_->subWindowCloseListeners_.find(persistentId), window_->subWindowCloseListeners_.end());
1966 
1967     window_->ClearListenersById(persistentId);
1968     ASSERT_EQ(window_->subWindowCloseListeners_.find(persistentId), window_->subWindowCloseListeners_.end());
1969 
1970     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_subWindowCloseListeners end";
1971 }
1972 
1973 /**
1974  * @tc.name: ClearListenersById_mainWindowCloseListeners
1975  * @tc.desc: ClearListenersById_mainWindowCloseListeners
1976  * @tc.type: FUNC
1977  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_mainWindowCloseListeners, Function | SmallTest | Level2)1978 HWTEST_F(WindowSessionImplTest4, ClearListenersById_mainWindowCloseListeners, Function | SmallTest | Level2)
1979 {
1980     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_mainWindowCloseListeners start";
1981     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1982     option_->SetWindowName("ClearListenersById_mainWindowCloseListeners");
1983     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1984     ASSERT_NE(window_, nullptr);
1985 
1986     int persistentId = window_->GetPersistentId();
1987     window_->ClearListenersById(persistentId);
1988 
1989     sptr<IMainWindowCloseListener> listener_ = new (std::nothrow) MockIMainWindowCloseListener();
1990     window_->mainWindowCloseListeners_[persistentId] = listener_;
1991     ASSERT_NE(window_->mainWindowCloseListeners_.find(persistentId), window_->mainWindowCloseListeners_.end());
1992 
1993     window_->ClearListenersById(persistentId);
1994     ASSERT_EQ(window_->mainWindowCloseListeners_.find(persistentId), window_->mainWindowCloseListeners_.end());
1995 
1996     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_mainWindowCloseListeners end";
1997 }
1998 
1999 /**
2000  * @tc.name: ClearListenersById_occupiedAreaChangeListeners
2001  * @tc.desc: ClearListenersById_occupiedAreaChangeListeners
2002  * @tc.type: FUNC
2003  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_occupiedAreaChangeListeners, Function | SmallTest | Level2)2004 HWTEST_F(WindowSessionImplTest4, ClearListenersById_occupiedAreaChangeListeners, Function | SmallTest | Level2)
2005 {
2006     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_occupiedAreaChangeListeners start";
2007     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
2008     option_->SetWindowName("ClearListenersById_occupiedAreaChangeListeners");
2009     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
2010     ASSERT_NE(window_, nullptr);
2011 
2012     int persistentId = window_->GetPersistentId();
2013     window_->ClearListenersById(persistentId);
2014 
2015     sptr<IOccupiedAreaChangeListener> listener_ = new (std::nothrow) MockIOccupiedAreaChangeListener();
2016     window_->RegisterOccupiedAreaChangeListener(listener_);
2017     ASSERT_NE(window_->occupiedAreaChangeListeners_.find(persistentId), window_->occupiedAreaChangeListeners_.end());
2018 
2019     window_->ClearListenersById(persistentId);
2020     ASSERT_EQ(window_->occupiedAreaChangeListeners_.find(persistentId), window_->occupiedAreaChangeListeners_.end());
2021 
2022     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_occupiedAreaChangeListeners end";
2023 }
2024 
2025 /**
2026  * @tc.name: ClearListenersById_switchFreeMultiWindowListeners
2027  * @tc.desc: ClearListenersById_switchFreeMultiWindowListeners
2028  * @tc.type: FUNC
2029  */
HWTEST_F(WindowSessionImplTest4, ClearListenersById_switchFreeMultiWindowListeners, Function | SmallTest | Level2)2030 HWTEST_F(WindowSessionImplTest4, ClearListenersById_switchFreeMultiWindowListeners, Function | SmallTest | Level2)
2031 {
2032     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_switchFreeMultiWindowListeners start";
2033     sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
2034     option_->SetWindowName("ClearListenersById_switchFreeMultiWindowListeners");
2035     sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
2036     ASSERT_NE(window_, nullptr);
2037 
2038     int persistentId = window_->GetPersistentId();
2039     window_->ClearListenersById(persistentId);
2040 
2041     sptr<ISwitchFreeMultiWindowListener> listener_ = new (std::nothrow) MockISwitchFreeMultiWindowListener();
2042     window_->RegisterSwitchFreeMultiWindowListener(listener_);
2043     ASSERT_NE(window_->switchFreeMultiWindowListeners_.find(persistentId),
2044               window_->switchFreeMultiWindowListeners_.end());
2045 
2046     window_->ClearListenersById(persistentId);
2047     ASSERT_EQ(window_->switchFreeMultiWindowListeners_.find(persistentId),
2048               window_->switchFreeMultiWindowListeners_.end());
2049 
2050     GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_switchFreeMultiWindowListeners end";
2051 }
2052 }
2053 } // namespace Rosen
2054 } // namespace OHOS
2055