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  */
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  */
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  */
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  */
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  */
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_.uiType_ = "phone";
162     WMError res = window->SetTopmost(true);
163     ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, res);
164     window->windowSystemConfig_.uiType_ = "pc";
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  */
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  */
198 HWTEST_F(WindowSessionImplTest4, SetMainWindowTopmost, Function | SmallTest | Level2)
199 {
200     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
201     option->SetWindowName("SetMainWindowTopmost");
202     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
203     window->property_->SetPersistentId(1);
204     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
205     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
206     window->hostSession_ = session;
207     window->state_ = WindowState::STATE_CREATED;
208     WMError res = window->SetMainWindowTopmost(true);
209     ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, res);
210 }
211 
212 /**
213  * @tc.name: IsMainWindowTopmost
214  * @tc.desc: IsMainWindowTopmost
215  * @tc.type: FUNC
216  */
217 HWTEST_F(WindowSessionImplTest4, IsMainWindowTopmost, Function | SmallTest | Level2)
218 {
219     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
220     option->SetWindowName("IsMainWindowTopmost");
221     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
222     bool res = window->IsMainWindowTopmost();
223     ASSERT_FALSE(res);
224 }
225 
226 /**
227  * @tc.name: SetDecorVisible
228  * @tc.desc: SetDecorVisible and check the retCode
229  * @tc.type: FUNC
230  */
231 HWTEST_F(WindowSessionImplTest4, SetDecorVisible, Function | SmallTest | Level2)
232 {
233     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetDecorVisibletest01 start";
234     sptr<WindowOption> option = new WindowOption();
235     ASSERT_NE(option, nullptr);
236     option->SetWindowName("SetDecorVisible");
237     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
238     ASSERT_NE(window, nullptr);
239     ASSERT_NE(window->property_, nullptr);
240     window->property_->SetPersistentId(1);
241     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
242     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
243     ASSERT_NE(nullptr, session);
244     window->hostSession_ = session;
245 
246     bool isVisible = true;
247     WMError res = window->SetDecorVisible(isVisible);
248     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
249 
250     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
251     res = window->SetDecorVisible(isVisible);
252     ASSERT_EQ(res, WMError::WM_OK);
253     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetDecorVisibletest01 end";
254 }
255 
256 /**
257  * @tc.name: SetWindowTitleMoveEnabled
258  * @tc.desc: SetWindowTitleMoveEnabled and check the retCode
259  * @tc.type: FUNC
260  */
261 HWTEST_F(WindowSessionImplTest4, SetWindowTitleMoveEnabled, Function | SmallTest | Level2)
262 {
263     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowTitleMoveEnabledtest01 start";
264     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
265     ASSERT_NE(option, nullptr);
266     option->SetWindowName("SetWindowTitleMoveEnabled");
267     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
268     ASSERT_NE(window, nullptr);
269     WMError res = window->SetWindowTitleMoveEnabled(true);
270     EXPECT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
271     window->property_->SetPersistentId(1);
272     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
273     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
274     ASSERT_NE(nullptr, session);
275     window->hostSession_ = session;
276     window->windowSystemConfig_.uiType_ = "phone";
277     res = window->SetWindowTitleMoveEnabled(true);
278     EXPECT_EQ(res, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
279     window->windowSystemConfig_.uiType_ = "pc";
280     window->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
281     res = window->SetWindowTitleMoveEnabled(true);
282     EXPECT_EQ(res, WMError::WM_ERROR_INVALID_CALLING);
283     window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
284     res = window->SetWindowTitleMoveEnabled(true);
285     EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
286     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
287     res = window->SetWindowTitleMoveEnabled(true);
288     EXPECT_EQ(res, WMError::WM_OK);
289     res = window->SetWindowTitleMoveEnabled(false);
290     EXPECT_EQ(res, WMError::WM_OK);
291     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowTitleMoveEnabledtest01 end";
292 }
293 
294 /**
295  * @tc.name: SetSubWindowModal
296  * @tc.desc: SetSubWindowModal and check the retCode
297  * @tc.type: FUNC
298  */
299 HWTEST_F(WindowSessionImplTest4, SetSubWindowModal, Function | SmallTest | Level2)
300 {
301     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest01 start";
302     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
303     ASSERT_NE(option, nullptr);
304     option->SetWindowName("SetSubWindowModal");
305     option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
306     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
307     ASSERT_NE(window, nullptr);
308     window->property_->SetPersistentId(1);
309     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
310     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
311     ASSERT_NE(nullptr, session);
312     window->hostSession_ = session;
313     WMError res = window->SetSubWindowModal(true);
314     ASSERT_EQ(res, WMError::WM_OK);
315     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest01 end";
316 }
317 
318 /**
319  * @tc.name: SetSubWindowModal02
320  * @tc.desc: SetSubWindowModal and check the retCode
321  * @tc.type: FUNC
322  */
323 HWTEST_F(WindowSessionImplTest4, SetSubWindowModal02, Function | SmallTest | Level2)
324 {
325     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest02 start";
326     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
327     ASSERT_NE(option, nullptr);
328     option->SetWindowName("SetSubWindowModal02");
329     option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
330     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
331     ASSERT_NE(window, nullptr);
332     window->property_->SetPersistentId(1);
333     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
334     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
335     ASSERT_NE(nullptr, session);
336     window->hostSession_ = session;
337     window->windowSystemConfig_.uiType_ = "pc";
338     WMError res = window->SetSubWindowModal(true, ModalityType::WINDOW_MODALITY);
339     ASSERT_EQ(res, WMError::WM_OK);
340     res = window->SetSubWindowModal(true, ModalityType::APPLICATION_MODALITY);
341     ASSERT_EQ(res, WMError::WM_OK);
342     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest02 end";
343 }
344 
345 /**
346  * @tc.name: SetWindowModal
347  * @tc.desc: SetWindowModal and check the retCode
348  * @tc.type: FUNC
349  */
350 HWTEST_F(WindowSessionImplTest4, SetWindowModal, Function | SmallTest | Level2)
351 {
352     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowModal start";
353     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
354     ASSERT_NE(option, nullptr);
355     option->SetWindowName("SetWindowModal");
356     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
357     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
358     ASSERT_NE(window, nullptr);
359     window->property_->SetPersistentId(1);
360     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
361     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
362     ASSERT_NE(nullptr, session);
363     window->hostSession_ = session;
364     window->windowSystemConfig_.uiType_ = "pc";
365     WMError res = window->SetWindowModal(true);
366     ASSERT_EQ(res, WMError::WM_OK);
367     res = window->SetWindowModal(false);
368     ASSERT_EQ(res, WMError::WM_OK);
369     window->windowSystemConfig_.uiType_ = "phone";
370     res = window->SetWindowModal(true);
371     ASSERT_EQ(res, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
372     res = window->SetWindowModal(false);
373     ASSERT_EQ(res, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
374     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowModal end";
375 }
376 
377 /**
378  * @tc.name: IsPcWindow
379  * @tc.desc: IsPcWindow
380  * @tc.type: FUNC
381  */
382 HWTEST_F(WindowSessionImplTest4, IsPcWindow, Function | SmallTest | Level2)
383 {
384     GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcWindow start";
385     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
386     option->SetWindowName("IsPcWindow");
387     option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
388     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
389     window->property_->SetPersistentId(1);
390     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
391     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
392     window->hostSession_ = session;
393     window->windowSystemConfig_.uiType_ = UI_TYPE_PC;
394     ASSERT_EQ(true, window->IsPcWindow());
395     window->windowSystemConfig_.uiType_ = UI_TYPE_PHONE;
396     ASSERT_EQ(false, window->IsPcWindow());
397     GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcWindow end";
398 }
399 
400 /**
401  * @tc.name: IsPcOrPadFreeMultiWindowMode
402  * @tc.desc: IsPcOrPadFreeMultiWindowMode
403  * @tc.type: FUNC
404  */
405 HWTEST_F(WindowSessionImplTest4, IsPcOrPadFreeMultiWindowMode, Function | SmallTest | Level2)
406 {
407     GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadFreeMultiWindowMode start";
408     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
409     ASSERT_NE(option, nullptr);
410     option->SetWindowName("IsPcOrPadFreeMultiWindowMode");
411     option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
412     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
413     ASSERT_NE(window, nullptr);
414     window->property_->SetPersistentId(1);
415     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
416     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
417     ASSERT_NE(nullptr, session);
418     window->hostSession_ = session;
419     window->windowSystemConfig_.uiType_ = "pc";
420     ASSERT_EQ(true, window->IsPcOrPadFreeMultiWindowMode());
421     window->windowSystemConfig_.uiType_ = "phone";
422     ASSERT_EQ(false, window->IsPcOrPadFreeMultiWindowMode());
423     GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadFreeMultiWindowMode end";
424 }
425 
426 /**
427  * @tc.name: GetDecorHeight
428  * @tc.desc: GetDecorHeight and check the retCode
429  * @tc.type: FUNC
430  */
431 HWTEST_F(WindowSessionImplTest4, GetDecorHeight, Function | SmallTest | Level2)
432 {
433     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorHeighttest01 start";
434     sptr<WindowOption> option = new WindowOption();
435     ASSERT_NE(option, nullptr);
436     option->SetWindowName("GetDecorHeight");
437     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
438     ASSERT_NE(window, nullptr);
439     ASSERT_NE(window->property_, nullptr);
440     window->property_->SetPersistentId(1);
441     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
442     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
443     ASSERT_NE(nullptr, session);
444     window->hostSession_ = session;
445     int32_t height = 0;
446     WMError res = window->GetDecorHeight(height);
447     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
448     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorHeighttest01 end";
449 }
450 
451 /**
452  * @tc.name: GetTitleButtonArea
453  * @tc.desc: GetTitleButtonArea and check the retCode
454  * @tc.type: FUNC
455  */
456 HWTEST_F(WindowSessionImplTest4, GetTitleButtonArea, Function | SmallTest | Level2)
457 {
458     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetTitleButtonAreatest01 start";
459     sptr<WindowOption> option = new WindowOption();
460     ASSERT_NE(option, nullptr);
461     option->SetWindowName("GetTitleButtonArea");
462     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
463     ASSERT_NE(window, nullptr);
464     ASSERT_NE(window->property_, nullptr);
465     window->property_->SetPersistentId(1);
466     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
467     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
468     ASSERT_NE(nullptr, session);
469     window->hostSession_ = session;
470     TitleButtonRect titleButtonRect;
471     WMError res = window->GetTitleButtonArea(titleButtonRect);
472     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
473     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorHeighttest01 end";
474 }
475 
476 /**
477  * @tc.name: RegisterExtensionAvoidAreaChangeListener
478  * @tc.desc: RegisterExtensionAvoidAreaChangeListener Test
479  * @tc.type: FUNC
480  */
481 HWTEST_F(WindowSessionImplTest4, RegisterExtensionAvoidAreaChangeListener, Function | SmallTest | Level2)
482 {
483     GTEST_LOG_(INFO) << "WindowSessionImplTest4: RegisterExtensionAvoidAreaChangeListener start";
484     sptr<WindowOption> option = new WindowOption();
485     ASSERT_NE(option, nullptr);
486     option->SetWindowName("GetTitleButtonArea");
487     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
488     ASSERT_NE(window, nullptr);
489     sptr<IAvoidAreaChangedListener> listener = nullptr;
490     WMError res = window->RegisterExtensionAvoidAreaChangeListener(listener);
491     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
492     GTEST_LOG_(INFO) << "WindowSessionImplTest4: RegisterExtensionAvoidAreaChangeListener end";
493 }
494 
495 /**
496  * @tc.name: UnregisterExtensionAvoidAreaChangeListener
497  * @tc.desc: UnregisterExtensionAvoidAreaChangeListener Test
498  * @tc.type: FUNC
499  */
500 HWTEST_F(WindowSessionImplTest4, UnregisterExtensionAvoidAreaChangeListener, Function | SmallTest | Level2)
501 {
502     GTEST_LOG_(INFO) << "WindowSessionImplTest4: UnregisterExtensionAvoidAreaChangeListener start";
503     sptr<WindowOption> option = new WindowOption();
504     ASSERT_NE(option, nullptr);
505     option->SetWindowName("GetTitleButtonArea");
506     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
507     ASSERT_NE(window, nullptr);
508     sptr<IAvoidAreaChangedListener> listener = nullptr;
509     WMError res = window->UnregisterExtensionAvoidAreaChangeListener(listener);
510     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
511     GTEST_LOG_(INFO) << "WindowSessionImplTest4: UnregisterExtensionAvoidAreaChangeListener end";
512 }
513 
514 /**
515  * @tc.name: SetPipActionEvent
516  * @tc.desc: SetPipActionEvent Test
517  * @tc.type: FUNC
518  */
519 HWTEST_F(WindowSessionImplTest4, SetPipActionEvent, Function | SmallTest | Level2)
520 {
521     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPipActionEvent start";
522     sptr<WindowOption> option = new WindowOption();
523     ASSERT_NE(option, nullptr);
524     option->SetWindowName("GetTitleButtonArea");
525     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
526     ASSERT_NE(window, nullptr);
527     ASSERT_EQ(nullptr, window->GetUIContentWithId(10000));
528     window->property_->SetPersistentId(1);
529 
530     SessionInfo sessionInfo = { "CreateTestBundle", "TestGetUIContentWithId", "CreateTestAbility" };
531     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
532     ASSERT_NE(nullptr, session);
533     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
534     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
535     ASSERT_EQ(window->FindWindowById(1), nullptr);
536     ASSERT_EQ(nullptr, window->GetUIContentWithId(1));
537     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
538     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPipActionEvent end";
539 }
540 
541 /**
542  * @tc.name: SetPiPControlEvent
543  * @tc.desc: SetPiPControlEvent Test
544  * @tc.type: FUNC
545  */
546 HWTEST_F(WindowSessionImplTest4, SetPiPControlEvent, Function | SmallTest | Level2)
547 {
548     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPiPControlEvent start";
549     auto option = sptr<WindowOption>::MakeSptr();
550     ASSERT_NE(option, nullptr);
551     option->SetWindowName("GetTitleButtonArea");
552     auto window = sptr<WindowSessionImpl>::MakeSptr(option);
553     ASSERT_NE(window, nullptr);
554     auto controlType = WsPiPControlType::VIDEO_PLAY_PAUSE;
555     auto status = WsPiPControlStatus::PLAY;
556     WSError res = window->SetPiPControlEvent(controlType, status);
557     ASSERT_EQ(res, WSError::WS_OK);
558     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPiPControlEvent end";
559 }
560 
561 /**
562  * @tc.name: SetAutoStartPiP
563  * @tc.desc: SetAutoStartPiP
564  * @tc.type: FUNC
565  */
566 HWTEST_F(WindowSessionImplTest4, SetAutoStartPiP, Function | SmallTest | Level2)
567 {
568     auto option = sptr<WindowOption>::MakeSptr();
569     ASSERT_NE(option, nullptr);
570     option->SetWindowName("SetAutoStartPiP");
571     auto window = sptr<WindowSessionImpl>::MakeSptr(option);
572     ASSERT_NE(window, nullptr);
573     window->property_->SetPersistentId(1);
574     SessionInfo sessionInfo = { "SetAutoStartPiP", "SetAutoStartPiP", "SetAutoStartPiP" };
575     auto session = sptr<SessionMocker>::MakeSptr(sessionInfo);
576     ASSERT_NE(nullptr, session);
577     window->hostSession_ = session;
578     bool isAutoStart = true;
579     uint32_t priority = 1;
580     window->SetAutoStartPiP(isAutoStart, priority);
581     window->hostSession_ = nullptr;
582     window->SetAutoStartPiP(isAutoStart, priority);
583 }
584 
585 /**
586  * @tc.name: TestGetUIContentWithId
587  * @tc.desc: Get uicontent with id
588  * @tc.type: FUNC
589  */
590 HWTEST_F(WindowSessionImplTest4, TestGetUIContentWithId, Function | SmallTest | Level2)
591 {
592     GTEST_LOG_(INFO) << "WindowSessionImplTest4: TestGetUIContentWithId start";
593     sptr<WindowOption> option = new WindowOption();
594     ASSERT_NE(nullptr, option);
595     option->SetWindowName("TestGetUIContentWithId");
596     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
597     ASSERT_NE(nullptr, window);
598     ASSERT_EQ(nullptr, window->GetUIContentWithId(10000));
599     window->property_->SetPersistentId(1);
600 
601     SessionInfo sessionInfo = { "CreateTestBundle", "TestGetUIContentWithId", "CreateTestAbility" };
602     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
603     ASSERT_NE(nullptr, session);
604     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
605     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
606     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
607         ASSERT_NE(window->FindWindowById(1), nullptr);
608         ASSERT_EQ(nullptr, window->GetUIContentWithId(1));
609         ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
610     }
611     GTEST_LOG_(INFO) << "WindowSessionImplTest4: TestGetUIContentWithId end";
612 }
613 
614 /**
615  * @tc.name: GetCallingWindowRect
616  * @tc.desc: GetCallingWindowRect Test
617  * @tc.type: FUNC
618  */
619 HWTEST_F(WindowSessionImplTest4, GetCallingWindowRect, Function | SmallTest | Level2)
620 {
621     sptr<WindowOption> option = new WindowOption();
622     option->SetWindowName("GetCallingWindowRect");
623     sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
624     ASSERT_NE(nullptr, window);
625     Rect rect = {0, 0, 0, 0};
626     WMError retCode = window->GetCallingWindowRect(rect);
627     ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
628     window->property_->SetPersistentId(1);
629     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
630     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
631     ASSERT_NE(nullptr, session);
632     window->hostSession_ = session;
633     window->state_ = WindowState::STATE_CREATED;
634     window->GetCallingWindowRect(rect);
635 }
636 
637 /**
638  * @tc.name: GetCallingWindowWindowStatus
639  * @tc.desc: GetCallingWindowWindowStatus Test
640  * @tc.type: FUNC
641  */
642 HWTEST_F(WindowSessionImplTest4, GetCallingWindowWindowStatus, Function | SmallTest | Level2)
643 {
644     sptr<WindowOption> option = new WindowOption();
645     option->SetWindowName("GetCallingWindowWindowStatus");
646     sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
647     ASSERT_NE(nullptr, window);
648     WindowStatus windowStatus = WindowStatus::WINDOW_STATUS_UNDEFINED;
649     WMError retCode = window->GetCallingWindowWindowStatus(windowStatus);
650     ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
651     window->property_->SetPersistentId(1);
652     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
653     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
654     ASSERT_NE(nullptr, session);
655     window->hostSession_ = session;
656     window->state_ = WindowState::STATE_CREATED;
657     window->GetCallingWindowWindowStatus(windowStatus);
658 }
659 
660 /**
661  * @tc.name: GetParentId
662  * @tc.desc: GetParentId Test
663  * @tc.type: FUNC
664  */
665 HWTEST_F(WindowSessionImplTest4, GetParentId, Function | SmallTest | Level2)
666 {
667     sptr<WindowOption> option = new WindowOption();
668     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
669     const int32_t res = window->GetParentId();
670     ASSERT_EQ(res, 0);
671     ASSERT_EQ(true, window->IsSupportWideGamut());
672 }
673 
674 /**
675  * @tc.name: PreNotifyKeyEvent
676  * @tc.desc: PreNotifyKeyEvent Test
677  * @tc.type: FUNC
678  */
679 HWTEST_F(WindowSessionImplTest4, PreNotifyKeyEvent, Function | SmallTest | Level2)
680 {
681     sptr<WindowOption> option = new (std::nothrow) WindowOption();
682     ASSERT_NE(nullptr, option);
683     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
684     ASSERT_NE(nullptr, window);
685     std::shared_ptr<MMI::PointerEvent> pointerEvent;
686     window->ConsumePointerEvent(pointerEvent);
687 
688     std::shared_ptr<MMI::KeyEvent> keyEvent;
689     window->ConsumeKeyEvent(keyEvent);
690     ASSERT_EQ(nullptr, window->GetUIContentSharedPtr());
691     ASSERT_EQ(false, window->PreNotifyKeyEvent(keyEvent));
692     ASSERT_EQ(false, window->NotifyOnKeyPreImeEvent(keyEvent));
693     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
694     ASSERT_NE(nullptr, window->GetUIContentSharedPtr());
695     ASSERT_EQ(false, window->PreNotifyKeyEvent(keyEvent));
696     ASSERT_EQ(false, window->NotifyOnKeyPreImeEvent(keyEvent));
697 }
698 
699 /**
700  * @tc.name: UpdateRectForRotation
701  * @tc.desc: UpdateRectForRotation Test
702  * @tc.type: FUNC
703  */
704 HWTEST_F(WindowSessionImplTest4, UpdateRectForRotation, Function | SmallTest | Level2)
705 {
706     sptr<WindowOption> option = new WindowOption();
707     option->SetWindowName("WindowSessionCreateCheck");
708     sptr<WindowSessionImpl> window =
709         new (std::nothrow) WindowSessionImpl(option);
710     ASSERT_NE(window, nullptr);
711 
712     Rect wmRect;
713     wmRect.posX_ = 0;
714     wmRect.posY_ = 0;
715     wmRect.height_ = 50;
716     wmRect.width_ = 50;
717 
718     WSRect rect;
719     wmRect.posX_ = 0;
720     wmRect.posY_ = 0;
721     wmRect.height_ = 50;
722     wmRect.width_ = 50;
723 
724     Rect preRect;
725     preRect.posX_ = 0;
726     preRect.posY_ = 0;
727     preRect.height_ = 200;
728     preRect.width_ = 200;
729 
730     window->property_->SetWindowRect(preRect);
731     WindowSizeChangeReason wmReason = WindowSizeChangeReason{0};
732     std::shared_ptr<RSTransaction> rsTransaction;
733     SceneAnimationConfig config { .rsTransaction_ = rsTransaction };
734     window->UpdateRectForRotation(wmRect, preRect, wmReason, config);
735 
736     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
737     auto res = window->UpdateRect(rect, reason);
738     ASSERT_EQ(res, WSError::WS_OK);
739 }
740 
741 /**
742  * @tc.name: SetTitleButtonVisible
743  * @tc.desc: SetTitleButtonVisible and GetTitleButtonVisible
744  * @tc.type: FUNC
745  */
746 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible, Function | SmallTest | Level2)
747 {
748     sptr<WindowOption> option = new WindowOption();
749     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
750     ASSERT_NE(window, nullptr);
751     bool isMaximizeVisible = true;
752     bool isMinimizeVisible = true;
753     bool isSplitVisible = true;
754     bool isCloseVisible = true;
755     auto res = window->SetTitleButtonVisible(isMaximizeVisible, isMinimizeVisible,
756         isSplitVisible, isCloseVisible);
757 
758     bool &hideMaximizeButton = isMaximizeVisible;
759     bool &hideMinimizeButton = isMinimizeVisible;
760     bool &hideSplitButton = isSplitVisible;
761     bool &hideCloseButton = isCloseVisible;
762     window->windowSystemConfig_.uiType_ = "pc";
763     window->GetTitleButtonVisible(hideMaximizeButton, hideMinimizeButton,
764         hideSplitButton, hideCloseButton);
765     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
766 }
767 
768 /**
769  * @tc.name: IsFocused
770  * @tc.desc: IsFocused
771  * @tc.type: FUNC
772  */
773 HWTEST_F(WindowSessionImplTest4, IsFocused, Function | SmallTest | Level2)
774 {
775     sptr<WindowOption> option = new WindowOption();
776     option->SetWindowName("WindowSessionCreateCheck");
777     sptr<WindowSessionImpl> window =
778         new (std::nothrow) WindowSessionImpl(option);
779     ASSERT_NE(window, nullptr);
780     bool res = window->IsFocused();
781     ASSERT_EQ(res, false);
782 
783     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->RequestFocus());
784 
785     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
786                                "CreateTestAbility"};
787     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
788     ASSERT_NE(nullptr, session);
789     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
790     int32_t persistentId = window->GetPersistentId();
791     if (persistentId == INVALID_SESSION_ID) {
792         persistentId = 1;
793         window->property_->SetPersistentId(persistentId);
794     }
795     if (window->state_ == WindowState::STATE_DESTROYED) {
796         window->state_ = WindowState::STATE_SHOWN;
797     }
798     window->hostSession_ = session;
799     window->RequestFocus();
800     ASSERT_FALSE(window->IsWindowSessionInvalid());
801     ASSERT_EQ(persistentId, window->GetPersistentId());
802     ASSERT_EQ(WMError::WM_OK, window->Destroy());
803 }
804 
805 /**
806  * @tc.name: GetAbcContent
807  * @tc.desc: GetAbcContent Test
808  * @tc.type: FUNC
809  */
810 HWTEST_F(WindowSessionImplTest4, GetAbcContent, Function | SmallTest | Level2)
811 {
812     sptr<WindowOption> option = new WindowOption();
813     ASSERT_NE(option, nullptr);
814     option->SetWindowName("GetAbcContent");
815     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
816     ASSERT_NE(window, nullptr);
817     std::string abcPath = "";
818     std::shared_ptr<std::vector<uint8_t>> res = window->GetAbcContent(abcPath);
819     std::filesystem::path abcFile{abcPath};
820     ASSERT_TRUE(abcFile.empty());
821     ASSERT_TRUE(!abcFile.is_absolute());
822     ASSERT_TRUE(!std::filesystem::exists(abcFile));
823     ASSERT_EQ(res, nullptr);
824 
825     abcPath = "/abc";
826     res = window->GetAbcContent(abcPath);
827     std::filesystem::path abcFile2{abcPath};
828     ASSERT_FALSE(abcFile2.empty());
829     ASSERT_FALSE(!abcFile2.is_absolute());
830     ASSERT_TRUE(!std::filesystem::exists(abcFile2));
831     ASSERT_EQ(res, nullptr);
832 
833     abcPath = "abc";
834     res = window->GetAbcContent(abcPath);
835     std::filesystem::path abcFile3{abcPath};
836     ASSERT_FALSE(abcFile3.empty());
837     ASSERT_TRUE(!abcFile3.is_absolute());
838     ASSERT_TRUE(!std::filesystem::exists(abcFile3));
839     ASSERT_EQ(res, nullptr);
840 
841     abcPath = "/log";
842     res = window->GetAbcContent(abcPath);
843     std::filesystem::path abcFile4{abcPath};
844     ASSERT_FALSE(abcFile4.empty());
845     ASSERT_FALSE(!abcFile4.is_absolute());
846     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
847         ASSERT_FALSE(!std::filesystem::exists(abcFile4));
848         ASSERT_NE(res, nullptr);
849         std::fstream file(abcFile, std::ios::in | std::ios::binary);
850         ASSERT_FALSE(file);
851     }
852     window->Destroy();
853 }
854 
855 /**
856  * @tc.name: SetLandscapeMultiWindow
857  * @tc.desc: SetLandscapeMultiWindow and check the retCode
858  * @tc.type: FUNC
859  */
860 HWTEST_F(WindowSessionImplTest4, SetLandscapeMultiWindow, Function | SmallTest | Level2)
861 {
862     sptr<WindowOption> option = new WindowOption();
863     option->SetWindowName("SetLandscapeMultiWindow");
864     sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
865     ASSERT_NE(nullptr, window);
866     WMError retCode = window->SetLandscapeMultiWindow(false);
867     ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
868     window->property_->SetPersistentId(1);
869     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
870     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
871     ASSERT_NE(nullptr, session);
872     window->hostSession_ = session;
873     window->state_ = WindowState::STATE_CREATED;
874     retCode = window->SetLandscapeMultiWindow(false);
875     ASSERT_EQ(retCode, WMError::WM_OK);
876 }
877 
878 /**
879  * @tc.name: GetTouchable
880  * @tc.desc: GetTouchable
881  * @tc.type: FUNC
882  */
883 HWTEST_F(WindowSessionImplTest4, GetTouchable, Function | SmallTest | Level2)
884 {
885     sptr<WindowOption> option = new WindowOption();
886     ASSERT_NE(option, nullptr);
887     option->SetWindowName("GetTouchable");
888     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
889     ASSERT_NE(window, nullptr);
890     window->GetTouchable();
891     window->GetBrightness();
892     ASSERT_NE(window, nullptr);
893 }
894 
895 /**
896  * @tc.name: Notify03
897  * @tc.desc: NotifyCloseExistPipWindow NotifyAfterResumed NotifyAfterPaused
898  * @tc.type: FUNC
899  */
900 HWTEST_F(WindowSessionImplTest4, Notify03, Function | SmallTest | Level2)
901 {
902     sptr<WindowOption> option = new WindowOption();
903     option->SetWindowName("Notify03");
904     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
905 
906     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
907                                "CreateTestAbility"};
908     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
909     ASSERT_NE(nullptr, session);
910     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
911 
912     window->NotifyAfterResumed();
913     window->NotifyAfterPaused();
914     WSError res = window->NotifyCloseExistPipWindow();
915     ASSERT_EQ(res, WSError::WS_OK);
916     AAFwk::WantParams wantParams;
917     WSError ret = window->NotifyTransferComponentData(wantParams);
918     ASSERT_EQ(ret, WSError::WS_OK);
919     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
920 }
921 
922 /**
923  * @tc.name: Filter
924  * @tc.desc: Filter
925  * @tc.type: FUNC
926  */
927 HWTEST_F(WindowSessionImplTest4, Filter, Function | SmallTest | Level2)
928 {
929     sptr<WindowOption> option = new WindowOption();
930     ASSERT_NE(option, nullptr);
931     option->SetWindowName("Filter");
932     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
933     ASSERT_NE(window, nullptr);
934     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
935     window->FilterKeyEvent(keyEvent);
936     ASSERT_EQ(window->keyEventFilter_, nullptr);
__anon7dae60d00202(MMI::KeyEvent& keyEvent) 937     window->SetKeyEventFilter([](MMI::KeyEvent& keyEvent) {
938         GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetKeyEventFilter";
939         return true;
940     });
941     ASSERT_NE(window->keyEventFilter_, nullptr);
942     window->FilterKeyEvent(keyEvent);
943     auto ret = window->ClearKeyEventFilter();
944     ASSERT_EQ(ret, WMError::WM_OK);
945 }
946 
947 /**
948  * @tc.name: UpdateOrientation
949  * @tc.desc: UpdateOrientation
950  * @tc.type: FUNC
951  */
952 HWTEST_F(WindowSessionImplTest4, UpdateOrientation, Function | SmallTest | Level2)
953 {
954     sptr<WindowOption> option = new WindowOption();
955     ASSERT_NE(option, nullptr);
956     option->SetWindowName("UpdateOrientation");
957     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
958     ASSERT_NE(window, nullptr);
959     auto ret = window->UpdateOrientation();
960     ASSERT_EQ(WSError::WS_OK, ret);
961 }
962 
963 /**
964  * @tc.name: SetTitleButtonVisible01
965  * @tc.desc: SetTitleButtonVisible
966  * @tc.type: FUNC
967 */
968 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible01, Function | SmallTest | Level2)
969 {
970     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible01 start";
971     sptr<WindowOption> option = new (std::nothrow) WindowOption();
972     ASSERT_NE(option, nullptr);
973     option->SetWindowName("SetTitleButtonVisible");
974     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
975     ASSERT_NE(window, nullptr);
976     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
977     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
978     ASSERT_NE(nullptr, session);
979     window->hostSession_ = session;
980     ASSERT_NE(window->property_, nullptr);
981     window->property_->SetPersistentId(1);
982     window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
983     WMError res = window->SetTitleButtonVisible(false, false, false, true);
984     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_CALLING);
985     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible01 end";
986 }
987 
988 /**
989  * @tc.name: SetTitleButtonVisible02
990  * @tc.desc: SetTitleButtonVisible
991  * @tc.type: FUNC
992 */
993 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible02, Function | SmallTest | Level2)
994 {
995     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible02 start";
996     sptr<WindowOption> option = new (std::nothrow) WindowOption();
997     ASSERT_NE(option, nullptr);
998     option->SetWindowName("SetTitleButtonVisible");
999     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1000     ASSERT_NE(window, nullptr);
1001     ASSERT_NE(window->property_, nullptr);
1002     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1003     WMError res = window->SetTitleButtonVisible(false, false, false, true);
1004     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1005     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible02 end";
1006 }
1007 
1008 /**
1009  * @tc.name: SetTitleButtonVisible03
1010  * @tc.desc: SetTitleButtonVisible
1011  * @tc.type: FUNC
1012 */
1013 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible03, Function | SmallTest | Level2)
1014 {
1015     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible03 start";
1016     sptr option = new (std::nothrow) WindowOption();
1017     ASSERT_NE(option, nullptr);
1018     option->SetWindowName("SetTitleButtonVisible");
1019     sptr window = new (std::nothrow) WindowSessionImpl(option);
1020     ASSERT_NE(window, nullptr);
1021     ASSERT_NE(window->property_, nullptr);
1022     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1023     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1024     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1025     window->windowSystemConfig_.freeMultiWindowSupport_ = true;
1026     window->windowSystemConfig_.isSystemDecorEnable_ = true;
1027     window->windowSystemConfig_.uiType_ = "phone";
1028     WMError res = window->SetTitleButtonVisible(false, false, false, true);
1029     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1030     window->windowSystemConfig_.uiType_ = "pc";
1031     res = window->SetTitleButtonVisible(false, false, false, true);
1032     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1033     GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible03 end";
1034 }
1035 
1036 /**
1037  * @tc.name: GetTitleButtonVisible01
1038  * @tc.desc: GetTitleButtonVisible
1039  * @tc.type: FUNC
1040 */
1041 HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible01, Function | SmallTest | Level2)
1042 {
1043     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1044     ASSERT_NE(option, nullptr);
1045     option->SetWindowName("GetTitleButtonVisible01");
1046     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1047     ASSERT_NE(window, nullptr);
1048     ASSERT_NE(window->property_, nullptr);
1049     uint32_t windowModeSupportType = 1 | (1 << 1) | (1 << 2);
1050     window->property_->SetWindowModeSupportType(windowModeSupportType);
1051     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1052     // show Maximize, Minimize, Split buttons.
1053     window->windowTitleVisibleFlags_ = { false, false, false, false };
1054     bool hideMaximizeButton = false;
1055     bool hideMinimizeButton = false;
1056     bool hideSplitButton = false;
1057     bool hideCloseButton = false;
1058     window->windowSystemConfig_.uiType_ = "pc";
1059     window->GetTitleButtonVisible(hideMaximizeButton, hideMinimizeButton, hideSplitButton,
1060         hideCloseButton);
1061     ASSERT_EQ(hideMaximizeButton, true);
1062     ASSERT_EQ(hideMinimizeButton, true);
1063     ASSERT_EQ(hideSplitButton, true);
1064     ASSERT_EQ(hideCloseButton, true);
1065 }
1066 
1067 /**
1068  * @tc.name: UpdateRect03
1069  * @tc.desc: UpdateRect
1070  * @tc.type: FUNC
1071  */
1072 HWTEST_F(WindowSessionImplTest4, UpdateRect03, Function | SmallTest | Level2)
1073 {
1074     sptr<WindowOption> option = new WindowOption();
1075     option->SetWindowName("WindowSessionCreateCheck");
1076     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1077     ASSERT_NE(window, nullptr);
1078 
1079     WSRect rect;
1080     rect.posX_ = 0;
1081     rect.posY_ = 0;
1082     rect.height_ = 0;
1083     rect.width_ = 0;
1084 
1085     Rect rectW; // GetRect().IsUninitializedRect is true
1086     rectW.posX_ = 0;
1087     rectW.posY_ = 0;
1088     rectW.height_ = 0; // rectW - rect > 50
1089     rectW.width_ = 0;  // rectW - rect > 50
1090 
1091     window->property_->SetWindowRect(rectW);
1092     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1093     WSError res = window->UpdateRect(rect, reason);
1094     ASSERT_EQ(res, WSError::WS_OK);
1095 
1096     rect.height_ = 50;
1097     rect.width_ = 50;
1098     rectW.height_ = 50;
1099     rectW.width_ = 50;
1100     window->property_->SetWindowRect(rectW);
1101     res = window->UpdateRect(rect, reason);
1102     ASSERT_EQ(res, WSError::WS_OK);
1103 }
1104 
1105 /**
1106  * @tc.name: GetTitleButtonVisible02
1107  * @tc.desc: GetTitleButtonVisible
1108  * @tc.type: FUNC
1109  */
1110 HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible02, Function | SmallTest | Level2)
1111 {
1112     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1113     ASSERT_NE(option, nullptr);
1114     option->SetWindowName("GetTitleButtonVisible02");
1115     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1116     ASSERT_NE(window, nullptr);
1117     ASSERT_NE(window->property_, nullptr);
1118     // only not support WINDOW_MODE_SUPPORT_SPLIT
1119     uint32_t windowModeSupportType = 1 | (1 << 1);
1120     window->property_->SetWindowModeSupportType(windowModeSupportType);
1121     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1122     // show Maximize, Minimize, Split buttons.
1123     window->windowTitleVisibleFlags_ = { true, true, true, true };
1124     bool hideMaximizeButton = false;
1125     bool hideMinimizeButton = false;
1126     bool hideSplitButton = false;
1127     bool hideCloseButton = false;
1128     window->windowSystemConfig_.uiType_ = "pc";
1129     window->GetTitleButtonVisible(hideMaximizeButton, hideMinimizeButton, hideSplitButton, hideCloseButton);
1130     ASSERT_EQ(hideMaximizeButton, false);
1131     ASSERT_EQ(hideMinimizeButton, false);
1132     ASSERT_EQ(hideSplitButton, false);
1133     ASSERT_EQ(hideCloseButton, false);
1134 }
1135 
1136 /**
1137  * @tc.name: GetTitleButtonVisible03
1138  * @tc.desc: GetTitleButtonVisible
1139  * @tc.type: FUNC
1140  */
1141 HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible03, Function | SmallTest | Level2)
1142 {
1143     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1144     ASSERT_NE(option, nullptr);
1145     option->SetWindowName("GetTitleButtonVisible03");
1146     option->SetDisplayId(1);
1147     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1148     ASSERT_NE(window, nullptr);
1149     ASSERT_NE(window->property_, nullptr);
1150     ASSERT_EQ(1, window->GetDisplayId());
1151     // only not support WINDOW_MODE_SUPPORT_SPLIT
1152     uint32_t windowModeSupportType = 1 | (1 << 1) | (1 << 2);
1153     window->property_->SetWindowModeSupportType(windowModeSupportType);
1154     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1155     // show Maximize, Minimize, Split buttons.
1156     window->windowTitleVisibleFlags_ = { false, false, false, false };
1157     bool hideMaximizeButton = true;
1158     bool hideMinimizeButton = true;
1159     bool hideSplitButton = true;
1160     bool hideCloseButton = true;
1161     window->windowSystemConfig_.uiType_ = "phone";
1162     window->GetTitleButtonVisible(hideMaximizeButton, hideMinimizeButton, hideSplitButton, hideCloseButton);
1163     ASSERT_EQ(hideMaximizeButton, true);
1164     ASSERT_EQ(hideMinimizeButton, true);
1165     ASSERT_EQ(hideSplitButton, true);
1166     ASSERT_EQ(hideCloseButton, true);
1167 }
1168 
1169 /**
1170  * @tc.name: SetUiDvsyncSwitch
1171  * @tc.desc: SetUiDvsyncSwitch
1172  * @tc.type: FUNC
1173  */
1174 HWTEST_F(WindowSessionImplTest4, SetUiDvsyncSwitch, Function | SmallTest | Level2)
1175 {
1176     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1177     ASSERT_NE(option, nullptr);
1178     option->SetWindowName("SetUiDvsyncSwitch");
1179     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1180     ASSERT_NE(window, nullptr);
1181     window->SetUiDvsyncSwitch(true);
1182     window->vsyncStation_ = nullptr;
1183     window->SetUiDvsyncSwitch(true);
1184 }
1185 
1186 /**
1187  * @tc.name: GetVSyncPeriod
1188  * @tc.desc: GetVSyncPeriod
1189  * @tc.type: FUNC
1190  */
1191 HWTEST_F(WindowSessionImplTest4, GetVSyncPeriod, Function | SmallTest | Level2)
1192 {
1193     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1194     ASSERT_NE(option, nullptr);
1195     option->SetWindowName("GetVSyncPeriod");
1196     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1197     ASSERT_NE(window, nullptr);
1198     window->GetVSyncPeriod();
1199     window->vsyncStation_ = nullptr;
1200     window->GetVSyncPeriod();
1201 }
1202 
1203 /**
1204  * @tc.name: UpdatePiPControlStatus01
1205  * @tc.desc: UpdatePiPControlStatus
1206  * @tc.type: FUNC
1207  */
1208 HWTEST_F(WindowSessionImplTest4, UpdatePiPControlStatus01, Function | SmallTest | Level2)
1209 {
1210     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1211     ASSERT_NE(option, nullptr);
1212     option->SetWindowName("UpdatePiPControlStatus01");
1213     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1214     ASSERT_NE(window, nullptr);
1215     ASSERT_NE(window->property_, nullptr);
1216     window->property_->SetPersistentId(1);
1217     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1218     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
1219     ASSERT_NE(nullptr, session);
1220     window->hostSession_ = session;
1221     auto controlType = PiPControlType::VIDEO_PLAY_PAUSE;
1222     auto status = PiPControlStatus::ENABLED;
1223     window->UpdatePiPControlStatus(controlType, status);
1224     window->hostSession_ = nullptr;
1225     window->UpdatePiPControlStatus(controlType, status);
1226 }
1227 
1228 /**
1229  * @tc.name: NotifyWindowVisibility01
1230  * @tc.desc: NotifyWindowVisibility
1231  * @tc.type: FUNC
1232  */
1233 HWTEST_F(WindowSessionImplTest4, NotifyWindowVisibility01, Function | SmallTest | Level2)
1234 {
1235     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1236     ASSERT_NE(option, nullptr);
1237     option->SetWindowName("NotifyWindowVisibility01");
1238     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1239     ASSERT_NE(window, nullptr);
1240     ASSERT_NE(window->property_, nullptr);
1241     window->property_->SetPersistentId(1);
1242     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1243     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
1244     ASSERT_NE(nullptr, session);
1245     window->hostSession_ = session;
1246     window->NotifyWindowVisibility(false);
1247     sptr<IWindowVisibilityChangedListener> listener = new IWindowVisibilityChangedListener();
1248     window->RegisterWindowVisibilityChangeListener(listener);
1249     window->NotifyWindowVisibility(false);
1250     window->UnregisterWindowVisibilityChangeListener(listener);
1251 }
1252 
1253 /**
1254  * @tc.name: NotifyMainWindowClose01
1255  * @tc.desc: NotifyMainWindowClose
1256  * @tc.type: FUNC
1257  */
1258 HWTEST_F(WindowSessionImplTest4, NotifyMainWindowClose01, Function | SmallTest | Level2)
1259 {
1260     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1261     ASSERT_NE(option, nullptr);
1262     option->SetWindowName("NotifyMainWindowClose01");
1263     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1264     ASSERT_NE(window, nullptr);
1265     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1266     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1267     ASSERT_NE(nullptr, session);
1268     window->hostSession_ = session;
1269     window->property_->SetPersistentId(1);
1270 
1271     bool terminateCloseProcess = false;
1272     WMError res = window->NotifyMainWindowClose(terminateCloseProcess);
1273     EXPECT_EQ(terminateCloseProcess, false);
1274     EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
1275     sptr<IMainWindowCloseListener> listener = sptr<IMainWindowCloseListener>::MakeSptr();
1276     window->RegisterMainWindowCloseListeners(listener);
1277     res = window->NotifyMainWindowClose(terminateCloseProcess);
1278     EXPECT_EQ(terminateCloseProcess, false);
1279     EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
1280     window->UnregisterMainWindowCloseListeners(listener);
1281 }
1282 
1283 /**
1284  * @tc.name: UpdateVirtualPixelRatio
1285  * @tc.desc: test UpdateVirtualPixelRatio
1286  * @tc.type: FUNC
1287  */
1288 HWTEST_F(WindowSessionImplTest4, UpdateVirtualPixelRatio, Function | SmallTest | Level2)
1289 {
1290     GTEST_LOG_(INFO) << "WindowSessionImplTest4: UpdateVirtualPixelRatio start";
1291     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1292     option->SetWindowName("UpdateVirtualPixelRatio");
1293     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1294     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1295     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1296 
1297     window->property_->SetDisplayId(-1);
1298     sptr<Display> display = nullptr;
1299     window->UpdateVirtualPixelRatio(display);
1300     ASSERT_EQ(window->virtualPixelRatio_, 1.0f);
1301 
1302     window->property_->SetDisplayId(0);
1303     display = SingletonContainer::Get<DisplayManager>().GetDisplayById(window->property_->GetDisplayId());
1304     window->UpdateVirtualPixelRatio(display);
1305     ASSERT_NE(window->virtualPixelRatio_, 1.0f);
1306     GTEST_LOG_(INFO) << "WindowSessionImplTest4: UpdateVirtualPixelRatio end";
1307 }
1308 
1309 /**
1310  * @tc.name: IsPcOrPadCapabilityEnabled
1311  * @tc.desc: IsPcOrPadCapabilityEnabled test
1312  * @tc.type: FUNC
1313  */
1314 HWTEST_F(WindowSessionImplTest4, IsPcOrPadCapabilityEnabled, Function | SmallTest | Level2)
1315 {
1316     GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadCapabilityEnabled start";
1317     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1318     option->SetWindowName("IsPcOrPadCapabilityEnabled");
1319     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1320     ASSERT_NE(window->property_, nullptr);
1321     window->property_->SetPersistentId(1);
1322     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1323     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1324     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1325     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1326     ASSERT_NE(nullptr, session);
1327     window->hostSession_ = session;
1328 
1329     window->windowSystemConfig_.uiType_ = "pc";
1330     EXPECT_EQ(true, window->IsPcOrPadCapabilityEnabled());
1331     window->windowSystemConfig_.uiType_ = "phone";
1332     EXPECT_EQ(false, window->IsPcOrPadCapabilityEnabled());
1333     window->windowSystemConfig_.uiType_ = "pad";
1334     EXPECT_EQ(false, window->IsPcOrPadCapabilityEnabled());
1335     window->property_->SetIsPcAppInPad(true);
1336     EXPECT_EQ(true, window->IsPcOrPadCapabilityEnabled());
1337     EXPECT_EQ(WMError::WM_OK, window->Destroy(true));
1338     GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadCapabilityEnabled end";
1339 }
1340 
1341 /**
1342  * @tc.name: DestroySubWindow
1343  * @tc.desc: DestroySubWindow test
1344  * @tc.type: FUNC
1345  */
1346 HWTEST_F(WindowSessionImplTest4, DestroySubWindow, Function | SmallTest | Level2)
1347 {
1348     GTEST_LOG_(INFO) << "WindowSessionImplTest4: DestroySubWindow start";
1349     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1350     ASSERT_NE(option, nullptr);
1351     option->SetWindowName("DestroySubWindow");
1352     option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1353     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1354     ASSERT_NE(window->property_, nullptr);
1355     window->property_->SetPersistentId(1);
1356     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1357     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1358     ASSERT_NE(nullptr, session);
1359     window->hostSession_ = session;
1360     window->windowSystemConfig_.uiType_ = "pc";
1361 
1362     sptr<WindowOption> subOption = sptr<WindowOption>::MakeSptr();
1363     ASSERT_NE(subOption, nullptr);
1364     subOption->SetWindowName("DestroySubWindow01");
1365     subOption->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1366     sptr<WindowSessionImpl> subWindow = sptr<WindowSessionImpl>::MakeSptr(subOption);
1367     ASSERT_NE(subWindow, nullptr);
1368     ASSERT_NE(subWindow->property_, nullptr);
1369     subWindow->property_->SetPersistentId(2);
1370     SessionInfo subSessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1371     sptr<SessionMocker> subSession = sptr<SessionMocker>::MakeSptr(subSessionInfo);
1372     ASSERT_NE(nullptr, subSession);
1373     subWindow->hostSession_ = subSession;
1374     subWindow->windowSystemConfig_.uiType_ = "pc";
1375     std::vector<sptr<WindowSessionImpl>> vec;
1376     WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
1377         std::vector<sptr<WindowSessionImpl>>>(1, vec));
1378     WindowSessionImpl::subWindowSessionMap_[1].push_back(subWindow);
1379     window->DestroySubWindow();
1380     EXPECT_EQ(WMError::WM_OK, window->Destroy(true));
1381 }
1382 
1383 /**
1384  * @tc.name: UpdateSubWindowStateAndNotify01
1385  * @tc.desc: UpdateSubWindowStateAndNotify
1386  * @tc.type: FUNC
1387  */
1388 HWTEST_F(WindowSessionImplTest4, UpdateSubWindowStateAndNotify01, Function | SmallTest | Level2)
1389 {
1390     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1391     ASSERT_NE(option, nullptr);
1392     option->SetWindowName("UpdateSubWindowStateAndNotify01");
1393     option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1394     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1395     ASSERT_NE(window->property_, nullptr);
1396     window->property_->SetPersistentId(1);
1397     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1398     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1399     ASSERT_NE(nullptr, session);
1400     window->hostSession_ = session;
1401     window->windowSystemConfig_.uiType_ = "pc";
1402 
1403     sptr<WindowOption> subOption = sptr<WindowOption>::MakeSptr();
1404     ASSERT_NE(subOption, nullptr);
1405     subOption->SetWindowName("UpdateSubWindowStateAndNotify011");
1406     subOption->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1407     sptr<WindowSessionImpl> subWindow = sptr<WindowSessionImpl>::MakeSptr(subOption);
1408     ASSERT_NE(subWindow, nullptr);
1409     ASSERT_NE(subWindow->property_, nullptr);
1410     subWindow->property_->SetPersistentId(2);
1411     SessionInfo subSessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1412     sptr<SessionMocker> subSession = sptr<SessionMocker>::MakeSptr(subSessionInfo);
1413     ASSERT_NE(nullptr, subSession);
1414     subWindow->hostSession_ = subSession;
1415     subWindow->windowSystemConfig_.uiType_ = "pc";
1416     std::vector<sptr<WindowSessionImpl>> vec;
1417     WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
1418         std::vector<sptr<WindowSessionImpl>>>(1, vec));
1419     subWindow->UpdateSubWindowStateAndNotify(1, WindowState::STATE_HIDDEN);
1420     WindowSessionImpl::subWindowSessionMap_[1].push_back(subWindow);
1421     subWindow->state_ = WindowState::STATE_SHOWN;
1422     window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_HIDDEN);
1423     window->state_ = WindowState::STATE_HIDDEN;
1424     window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_HIDDEN);
1425     window->state_ = WindowState::STATE_SHOWN;
1426     window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_SHOWN);
1427     window->state_ = WindowState::STATE_SHOWN;
1428     window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_SHOWN);
1429     EXPECT_EQ(WMError::WM_OK, subWindow->Destroy(true));
1430     EXPECT_EQ(WMError::WM_OK, window->Destroy(true));
1431 }
1432 
1433 /**
1434  * @tc.name: SetEnableDragBySystem
1435  * @tc.desc: test SetEnableDragBySystem
1436  * @tc.type: FUNC
1437  */
1438 HWTEST_F(WindowSessionImplTest4, SetEnableDragBySystem, Function | SmallTest | Level2)
1439 {
1440     GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetSubWindow start";
1441     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1442     option->SetWindowName("GetSubWindow");
1443     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1444     ASSERT_NE(nullptr, window);
1445     window->property_->SetDragEnabled(true);
1446     window->SetEnableDragBySystem(false);
1447     ASSERT_FALSE(window->property_->GetDragEnabled());
1448 }
1449 
1450 /**
1451  * @tc.name: FlushLayoutSize
1452  * @tc.desc: FlushLayoutSize
1453  * @tc.type: FUNC
1454  */
1455 HWTEST_F(WindowSessionImplTest4, FlushLayoutSize, Function | SmallTest | Level2)
1456 {
1457 #undef private
1458     GTEST_LOG_(INFO) << "WindowSessionImplTest4: FlushLayoutSize start";
1459     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1460     option->SetWindowName("FlushLayoutSize");
1461     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1462     window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1463     int32_t width = 1320;
1464     int32_t height = 2710;
1465     WSRect rect = { 0, 0, width, height };
1466     window->FlushLayoutSize(width, height);
1467 
1468     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1469     window->windowSizeChanged_ = true;
1470     window->FlushLayoutSize(width, height);
1471     ASSERT_EQ(window->windowSizeChanged_, false);
1472 
1473     window->layoutRect_ = { 0, 0, 2710, 1320 };
1474     window->FlushLayoutSize(width, height);
1475     ASSERT_EQ(window->layoutRect_, rect);
1476 
1477     window->enableFrameLayoutFinishCb_ = true;
1478     window->FlushLayoutSize(width, height);
1479     ASSERT_EQ(window->enableFrameLayoutFinishCb_, false);
1480 
1481     GTEST_LOG_(INFO) << "WindowSessionImplTest4: FlushLayoutSize end";
1482 }
1483 
1484 /**
1485  * @tc.name: RegisterDisplayIdChangeListener01
1486  * @tc.desc: RegisterDisplayIdChangeListener01
1487  * @tc.type: FUNC
1488  */
1489 HWTEST_F(WindowSessionImplTest4, RegisterDisplayIdChangeListener01, Function | SmallTest | Level2)
1490 {
1491     sptr<WindowOption> option = new WindowOption();
1492     ASSERT_NE(option, nullptr);
1493     option->SetWindowName("RegisterDisplayIdChangeListener01");
1494 
1495     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1496     ASSERT_NE(window, nullptr);
1497     sptr<IDisplayIdChangeListener> listener = nullptr;
1498     WMError ret = window->RegisterDisplayIdChangeListener(listener);
1499     ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
1500 
1501     listener = sptr<IDisplayIdChangeListener>::MakeSptr();
1502     std::vector<sptr<IDisplayIdChangeListener>> holder;
1503     window->displayIdChangeListeners_[window->property_->GetPersistentId()] = holder;
1504     ret = window->RegisterDisplayIdChangeListener(listener);
1505     ASSERT_EQ(ret, WMError::WM_OK);
1506     holder = window->displayIdChangeListeners_[window->property_->GetPersistentId()];
1507     auto existsListener = std::find(holder.begin(), holder.end(), listener);
1508     ASSERT_NE(existsListener, holder.end());
1509 
1510     ret = window->RegisterDisplayIdChangeListener(listener);
1511     ASSERT_EQ(ret, WMError::WM_OK);
1512 }
1513 
1514 /**
1515  * @tc.name: UnregisterDisplayIdChangeListener01
1516  * @tc.desc: UnregisterDisplayIdChangeListener01
1517  * @tc.type: FUNC
1518  */
1519 HWTEST_F(WindowSessionImplTest4, UnregisterDisplayIdChangeListener01, Function | SmallTest | Level2)
1520 {
1521     sptr<WindowOption> option = new WindowOption();
1522     ASSERT_NE(option, nullptr);
1523     option->SetWindowName("UnregisterDisplayIdChangeListener01");
1524 
1525     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1526     ASSERT_NE(window, nullptr);
1527     sptr<IDisplayIdChangeListener> listener = nullptr;
1528     WMError ret = window->UnregisterDisplayIdChangeListener(listener);
1529     ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
1530 
1531     listener = sptr<IDisplayIdChangeListener>::MakeSptr();
1532     std::vector<sptr<IDisplayIdChangeListener>> holder;
1533     window->displayIdChangeListeners_[window->property_->GetPersistentId()] = holder;
1534     window->UnregisterDisplayIdChangeListener(listener);
1535 
1536     ret = window->UnregisterDisplayIdChangeListener(listener);
1537     ASSERT_EQ(ret, WMError::WM_OK);
1538 
1539     holder = window->displayIdChangeListeners_[window->property_->GetPersistentId()];
1540     auto existsListener = std::find(holder.begin(), holder.end(), listener);
1541     ASSERT_EQ(existsListener, holder.end());
1542 }
1543 
1544 /**
1545  * @tc.name: NotifyDisplayIdChange01
1546  * @tc.desc: NotifyDisplayIdChange01
1547  * @tc.type: FUNC
1548  */
1549 HWTEST_F(WindowSessionImplTest4, NotifyDisplayIdChange01, Function | SmallTest | Level2)
1550 {
1551     sptr<WindowOption> option = new WindowOption();
1552     ASSERT_NE(option, nullptr);
1553     option->SetWindowName("NotifyDisplayIdChange01");
1554 
1555     sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1556     ASSERT_NE(window, nullptr);
1557 
1558     SessionInfo sessioninfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1559     sptr<SessionMocker> session = new SessionMocker(sessioninfo);
1560     ASSERT_NE(session, nullptr);
1561     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1562     DisplayId displayId = 12;
1563     auto ret = window->NotifyDisplayIdChange(displayId);
1564     ASSERT_EQ(WSError::WS_OK, ret);
1565     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1566 }
1567 }
1568 } // namespace Rosen
1569 } // namespace OHOS
1570