• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <filesystem>
17 #include <fstream>
18 #include <gtest/gtest.h>
19 #include <int_wrapper.h>
20 #include <want_params_wrapper.h>
21 
22 #include "ability_context_impl.h"
23 #include "accessibility_event_info.h"
24 #include "color_parser.h"
25 #include "extension/extension_business_info.h"
26 #include "mock_session.h"
27 #include "mock_uicontent.h"
28 #include "mock_window.h"
29 #include "parameters.h"
30 #include "window_helper.h"
31 #include "window_session_impl.h"
32 #include "wm_common.h"
33 
34 using namespace testing;
35 using namespace testing::ext;
36 
37 namespace OHOS {
38 namespace Rosen {
39 class WindowSessionImplTest : public testing::Test {
40 public:
41     static void SetUpTestCase();
42     static void TearDownTestCase();
43     void SetUp() override;
44     void TearDown() override;
45 
46     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
47 
48 private:
49     static constexpr uint32_t WAIT_SYNC_IN_NS = 50000;
50 };
51 
SetUpTestCase()52 void WindowSessionImplTest::SetUpTestCase() {}
53 
TearDownTestCase()54 void WindowSessionImplTest::TearDownTestCase() {}
55 
SetUp()56 void WindowSessionImplTest::SetUp()
57 {
58     abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
59 }
60 
TearDown()61 void WindowSessionImplTest::TearDown()
62 {
63     usleep(WAIT_SYNC_IN_NS);
64     abilityContext_ = nullptr;
65 }
66 
67 namespace {
68 /**
69  * @tc.name: CreateWindowAndDestroy01
70  * @tc.desc: Create window and destroy window
71  * @tc.type: FUNC
72  */
73 HWTEST_F(WindowSessionImplTest, CreateWindowAndDestroy01, Function | SmallTest | Level2)
74 {
75     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
76     option->SetWindowName("CreateWindow01");
77     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
78 
79     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
80     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
81     ASSERT_NE(nullptr, session);
82     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
83     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
84     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
85     window->property_->SetPersistentId(1);
86     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
87     // session is null
88     window = sptr<WindowSessionImpl>::MakeSptr(option);
89     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr));
90     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
91 
92     window = sptr<WindowSessionImpl>::MakeSptr(option);
93     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
94     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false));
95 }
96 
97 /**
98  * @tc.name: CreateWindowAndDestroy02
99  * @tc.desc: Create window and destroy window
100  * @tc.type: FUNC
101  */
102 HWTEST_F(WindowSessionImplTest, CreateWindowAndDestroy02, Function | SmallTest | Level2)
103 {
104     std::string identityToken = "testToken";
105     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
106     option->SetWindowName("CreateWindow01");
107     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
108 
109     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
110     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
111     ASSERT_NE(nullptr, session);
112     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session, identityToken));
113     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session, identityToken));
114     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session, identityToken));
115     window->property_->SetPersistentId(1);
116     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
117     // session is null
118     window = sptr<WindowSessionImpl>::MakeSptr(option);
119     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr));
120     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
121 
122     window = sptr<WindowSessionImpl>::MakeSptr(option);
123     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session, identityToken));
124     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false));
125 }
126 
127 /**
128  * @tc.name: Connect01
129  * @tc.desc: Connect session
130  * @tc.type: FUNC
131  */
132 HWTEST_F(WindowSessionImplTest, Connect01, Function | SmallTest | Level2)
133 {
134     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
135     option->SetWindowName("Connect01");
136     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
137     window->property_->SetPersistentId(1);
138     // connect with null session
139     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Connect());
140 
141     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
142     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
143     ASSERT_NE(nullptr, session);
144     window->hostSession_ = session;
145     EXPECT_CALL(*(session), Connect(_, _, _, _, _, _, _)).WillOnce(Return(WSError::WS_ERROR_NULLPTR));
146     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Connect());
147     EXPECT_CALL(*(session), Connect(_, _, _, _, _, _, _)).WillOnce(Return(WSError::WS_OK));
148     ASSERT_EQ(WMError::WM_OK, window->Connect());
149     ASSERT_EQ(WMError::WM_OK, window->Destroy());
150 }
151 
152 /**
153  * @tc.name: Show01
154  * @tc.desc: Show session
155  * @tc.type: FUNC
156  */
157 HWTEST_F(WindowSessionImplTest, Show01, Function | SmallTest | Level2)
158 {
159     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
160     option->SetWindowName("Show01");
161     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
162     ASSERT_NE(nullptr, window);
163     window->property_->SetPersistentId(1);
164     // show with null session
165     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Show());
166 
167     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
168     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
169     ASSERT_NE(nullptr, session);
170     window->hostSession_ = session;
171     EXPECT_CALL(*(session), Foreground(_, _, _)).WillOnce(Return(WSError::WS_OK));
172     ASSERT_EQ(WMError::WM_OK, window->Show());
173     ASSERT_EQ(WMError::WM_OK, window->Show());
174     window->state_ = WindowState::STATE_CREATED;
175     EXPECT_CALL(*(session), Foreground(_, _, _)).WillOnce(Return(WSError::WS_ERROR_INVALID_SESSION));
176     ASSERT_EQ(WMError::WM_ERROR_INVALID_SESSION, window->Show());
177     ASSERT_EQ(WMError::WM_OK, window->Destroy());
178 }
179 
180 /**
181  * @tc.name: Hide01
182  * @tc.desc: Hide session
183  * @tc.type: FUNC
184  */
185 HWTEST_F(WindowSessionImplTest, Hide01, Function | SmallTest | Level2)
186 {
187     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
188     option->SetWindowName("Hide01");
189     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
190     ASSERT_NE(nullptr, window);
191     window->property_->SetPersistentId(1);
192     // show with null session
193     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Hide());
194 
195     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
196     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
197     ASSERT_NE(nullptr, session);
198     window->hostSession_ = session;
199     ASSERT_EQ(WMError::WM_OK, window->Hide());
200     ASSERT_EQ(WMError::WM_OK, window->Hide());
201     window->state_ = WindowState::STATE_CREATED;
202     ASSERT_EQ(WMError::WM_OK, window->Hide());
203     window->state_ = WindowState::STATE_SHOWN;
204     window->property_->type_ = WindowType::WINDOW_TYPE_FLOAT;
205     ASSERT_EQ(WMError::WM_OK, window->Hide());
206     window->property_->type_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
207     ASSERT_EQ(WMError::WM_OK, window->Destroy());
208 }
209 
210 /**
211  * @tc.name: SetWindowType01
212  * @tc.desc: SetWindowType
213  * @tc.type: FUNC
214  */
215 HWTEST_F(WindowSessionImplTest, SetWindowType01, Function | SmallTest | Level2)
216 {
217     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetWindowType01 start";
218     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
219     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
220     ASSERT_NE(window->property_, nullptr);
221 
222     window->property_->SetPersistentId(1);
223     option->SetWindowName("SetWindowType01");
224     WindowType type = WindowType::WINDOW_TYPE_BOOT_ANIMATION;
225     option->SetWindowType(type);
226     window = sptr<WindowSessionImpl>::MakeSptr(option);
227     ASSERT_NE(window, nullptr);
228 
229     WindowType type1 = WindowType::WINDOW_TYPE_POINTER;
230     option->SetWindowType(type1);
231     window = sptr<WindowSessionImpl>::MakeSptr(option);
232     ASSERT_NE(window, nullptr);
233 
234     WindowType type2 = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
235     option->SetWindowType(type2);
236     window = sptr<WindowSessionImpl>::MakeSptr(option);
237     ASSERT_NE(window, nullptr);
238 
239     WindowType type3 = WindowType::APP_MAIN_WINDOW_END;
240     option->SetWindowType(type3);
241     window = sptr<WindowSessionImpl>::MakeSptr(option);
242     ASSERT_NE(window, nullptr);
243 
244     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetWindowType01 end";
245 }
246 
247 /**
248  * @tc.name: ColorSpace
249  * @tc.desc: SetColorSpace and GetColorSpace
250  * @tc.type: FUNC
251  */
252 HWTEST_F(WindowSessionImplTest, ColorSpace, Function | SmallTest | Level2)
253 {
254     GTEST_LOG_(INFO) << "WindowSessionImplTest: ColorSpace start";
255     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
256     option->SetWindowName("ColorSpace");
257     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
258     ASSERT_NE(window, nullptr);
259     ASSERT_NE(window->property_, nullptr);
260     window->property_->SetPersistentId(1);
261 
262     window->SetColorSpace(ColorSpace::COLOR_SPACE_DEFAULT);
263     ColorSpace colorSpace = window->GetColorSpace();
264     ASSERT_EQ(colorSpace, ColorSpace::COLOR_SPACE_DEFAULT);
265 
266     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
267     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
268     ASSERT_NE(session, nullptr);
269     window->hostSession_ = session;
270     window->state_ = WindowState::STATE_CREATED;
271     ASSERT_FALSE(window->IsWindowSessionInvalid());
272     window->surfaceNode_ = nullptr;
273     window->SetColorSpace(ColorSpace::COLOR_SPACE_WIDE_GAMUT);
274     ColorSpace colorSpace1 = window->GetColorSpace();
275     ASSERT_EQ(colorSpace1, ColorSpace::COLOR_SPACE_DEFAULT);
276 
277     struct RSSurfaceNodeConfig config;
278     window->surfaceNode_ = RSSurfaceNode::Create(config);
279     window->SetColorSpace(ColorSpace::COLOR_SPACE_WIDE_GAMUT);
280     ColorSpace colorSpace2 = window->GetColorSpace();
281     ASSERT_EQ(colorSpace2, ColorSpace::COLOR_SPACE_WIDE_GAMUT);
282     GTEST_LOG_(INFO) << "WindowSessionImplTest: ColorSpace end";
283 }
284 
285 /**
286  * @tc.name: MakeSubOrDialogWindowDragableAndMoveble02
287  * @tc.desc: MakeSubOrDialogWindowDragableAndMoveble
288  * @tc.type: FUNC
289  */
290 HWTEST_F(WindowSessionImplTest, MakeSubOrDialogWindowDragableAndMoveble02, Function | SmallTest | Level2)
291 {
292     GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble02 start";
293     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
294     option->SetDialogDecorEnable(true);
295     option->SetWindowName("MakeSubOrDialogWindowDragableAndMoveble02");
296     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
297     ASSERT_NE(nullptr, window);
298     window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
299     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
300     window->MakeSubOrDialogWindowDragableAndMoveble();
301     ASSERT_EQ(true, window->property_->IsDecorEnable());
302     GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble02 end";
303 }
304 
305 /**
306  * @tc.name: MakeSubOrDialogWindowDragableAndMoveble03
307  * @tc.desc: MakeSubOrDialogWindowDragableAndMoveble
308  * @tc.type: FUNC
309  */
310 HWTEST_F(WindowSessionImplTest, MakeSubOrDialogWindowDragableAndMoveble03, Function | SmallTest | Level2)
311 {
312     GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble03 start";
313     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
314     option->SetDialogDecorEnable(true);
315     option->SetWindowName("MakeSubOrDialogWindowDragableAndMoveble03");
316     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
317     ASSERT_NE(nullptr, window);
318     window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
319     window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
320     window->MakeSubOrDialogWindowDragableAndMoveble();
321     ASSERT_EQ(false, window->property_->IsDecorEnable());
322     GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble03 end";
323 }
324 
325 /**
326  * @tc.name: MakeSubOrDialogWindowDragableAndMoveble
327  * @tc.desc: MakeSubOrDialogWindowDragableAndMoveble04
328  * @tc.type: FUNC
329  */
330 HWTEST_F(WindowSessionImplTest, MakeSubOrDialogWindowDragableAndMoveble04, Function | SmallTest | Level2)
331 {
332     GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble04 start";
333     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
334     ASSERT_NE(nullptr, option);
335     option->SetSubWindowDecorEnable(true);
336     option->SetWindowName("MakeSubOrDialogWindowDragableAndMoveble04");
337     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
338     ASSERT_NE(nullptr, window);
339     window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
340     window->windowSystemConfig_.freeMultiWindowSupport_ = true;
341     window->windowSystemConfig_.freeMultiWindowEnable_ = true;
342     window->MakeSubOrDialogWindowDragableAndMoveble();
343     ASSERT_TRUE(window->property_->IsDecorEnable());
344     GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble04 end";
345 }
346 
347 /**
348  * @tc.name: WindowSessionCreateCheck01
349  * @tc.desc: WindowSessionCreateCheck01
350  * @tc.type: FUNC
351  */
352 HWTEST_F(WindowSessionImplTest, WindowSessionCreateCheck01, Function | SmallTest | Level2)
353 {
354     GTEST_LOG_(INFO) << "WindowSessionImplTest: WindowSessionCreateCheck01 start";
355     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
356     option->SetWindowName("WindowSessionCreateCheck");
357     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
358     ASSERT_NE(nullptr, window);
359 
360     sptr<WindowOption> option1 = sptr<WindowOption>::MakeSptr();
361     option1->SetWindowName("WindowSessionCreateCheck"); // set the same name
362     sptr<WindowSessionImpl> window1 = new (std::nothrow) WindowSessionImpl(option1);
363     ASSERT_NE(nullptr, window1);
364 
365     WMError res = window1->WindowSessionCreateCheck();
366     ASSERT_EQ(res, WMError::WM_OK);
367     GTEST_LOG_(INFO) << "WindowSessionImplTest: WindowSessionCreateCheck01 end";
368 }
369 
370 /**
371  * @tc.name: WindowSessionCreateCheck
372  * @tc.desc: WindowSessionCreateCheck03
373  * @tc.type: FUNC
374  */
375 HWTEST_F(WindowSessionImplTest, WindowSessionCreateCheck03, Function | SmallTest | Level2)
376 {
377     GTEST_LOG_(INFO) << "WindowSessionImplTest: WindowSessionCreateCheck03 start";
378     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
379     std::string name = "WindowSessionCreateCheck03";
380     option->SetWindowName(name);
381     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
382     ASSERT_NE(window, nullptr);
383     window->windowSessionMap_[name] = std::pair<int32_t, sptr<WindowSessionImpl>>(1, window);
384     WMError res = window->WindowSessionCreateCheck();
385     ASSERT_EQ(res, WMError::WM_ERROR_REPEAT_OPERATION);
386     GTEST_LOG_(INFO) << "WindowSessionImplTest: WindowSessionCreateCheck03 end";
387 }
388 
389 /**
390  * @tc.name: SetActive
391  * @tc.desc: SetActive
392  * @tc.type: FUNC
393  */
394 HWTEST_F(WindowSessionImplTest, SetActive, Function | SmallTest | Level2)
395 {
396     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetActive start";
397     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
398     option->SetWindowName("WindowSessionCreateCheck");
399     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
400     ASSERT_NE(window, nullptr);
401 
402     WSError res1 = window->SetActive(true);
403     ASSERT_EQ(res1, WSError::WS_OK);
404     res1 = window->SetActive(false);
405     ASSERT_EQ(res1, WSError::WS_OK);
406 
407     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetActive end";
408 }
409 
410 /**
411  * @tc.name: UpdateFocus
412  * @tc.desc: UpdateFocus
413  * @tc.type: FUNC
414  */
415 HWTEST_F(WindowSessionImplTest, UpdateFocus, Function | SmallTest | Level2)
416 {
417     GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateFocus start";
418     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
419     option->SetWindowName("WindowSessionCreateCheck");
420     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
421     ASSERT_NE(window, nullptr);
422 
423     WSError res = window->UpdateFocus(true);
424     ASSERT_EQ(res, WSError::WS_OK);
425     res = window->UpdateFocus(false);
426     ASSERT_EQ(res, WSError::WS_OK);
427 
428     GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateFocus end";
429 }
430 
431 /**
432  * @tc.name: RequestFocusByClient
433  * @tc.desc: RequestFocusByClient Test
434  * @tc.type: FUNC
435  */
436 HWTEST_F(WindowSessionImplTest, RequestFocusByClient, Function | SmallTest | Level2)
437 {
438     GTEST_LOG_(INFO) << "WindowSessionImplTest: RequestFocusByClient start";
439     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
440     option->SetWindowName("WindowRequestFocusByClientCheck");
441     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
442     ASSERT_NE(window, nullptr);
443 
444     WMError res = window->RequestFocusByClient(true);
445     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
446     res = window->RequestFocusByClient(false);
447     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
448 
449     window->property_->SetPersistentId(1);
450     SessionInfo sessionInfo = { "RequestFocusByClient", "RequestFocusByClient", "RequestFocusByClient" };
451     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
452     ASSERT_NE(session, nullptr);
453     window->hostSession_ = session;
454     window->state_ = WindowState::STATE_INITIAL;
455     res = window->RequestFocusByClient(true);
456     ASSERT_EQ(res, WMError::WM_OK);
457     res = window->RequestFocusByClient(false);
458     ASSERT_EQ(res, WMError::WM_OK);
459 
460     GTEST_LOG_(INFO) << "WindowSessionImplTest: RequestFocusByClient end";
461 }
462 
463 /**
464  * @tc.name: CreateWindowAndDestroy01
465  * @tc.desc: GetPersistentId
466  * @tc.type: FUNC
467  */
468 HWTEST_F(WindowSessionImplTest, GetPersistentId01, Function | SmallTest | Level2)
469 {
470     GTEST_LOG_(INFO) << "WindowSessionImplTest: GetPersistentId start";
471     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
472     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
473     ASSERT_NE(window->property_, nullptr);
474 
475     window->property_->SetPersistentId(1);
476     const int32_t res2 = window->GetPersistentId();
477     ASSERT_EQ(res2, 1);
478     GTEST_LOG_(INFO) << "WindowSessionImplTest: GetPersistentId end";
479 }
480 
481 /**
482  * @tc.name: GetFloatingWindowParentId
483  * @tc.desc: GetFloatingWindowParentId and UpdateTitleButtonVisibility
484  * @tc.type: FUNC
485  */
486 HWTEST_F(WindowSessionImplTest, GetFloatingWindowParentId, Function | SmallTest | Level2)
487 {
488     GTEST_LOG_(INFO) << "WindowSessionImplTest: GetFloatingWindowParentId start";
489     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
490     option->SetWindowName("Connect");
491     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
492     ASSERT_NE(nullptr, window);
493     window->property_->SetPersistentId(1);
494     // connect with null session
495     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Connect());
496 
497     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
498     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
499     ASSERT_NE(nullptr, session);
500     window->hostSession_ = session;
501     EXPECT_CALL(*(session), Connect(_, _, _, _, _, _, _)).WillOnce(Return(WSError::WS_ERROR_NULLPTR));
502     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Connect());
503     EXPECT_CALL(*(session), Connect(_, _, _, _, _, _, _)).WillOnce(Return(WSError::WS_OK));
504     ASSERT_EQ(WMError::WM_OK, window->Connect());
505 
506     window->UpdateTitleButtonVisibility();
507     int32_t res = window->GetFloatingWindowParentId();
508     ASSERT_EQ(res, INVALID_SESSION_ID);
509     GTEST_LOG_(INFO) << "WindowSessionImplTest: GetFloatingWindowParentId start";
510 }
511 
512 /**
513  * @tc.name: UpdateDecorEnable
514  * @tc.desc: UpdateDecorEnable
515  * @tc.type: FUNC
516  */
517 HWTEST_F(WindowSessionImplTest, UpdateDecorEnable, Function | SmallTest | Level2)
518 {
519     GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDecorEnable start";
520     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
521     option->SetWindowName("UpdateDecorEnable");
522     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
523     ASSERT_NE(window, nullptr);
524 
525     int res = 1;
526     window->UpdateDecorEnable(true);
527     window->UpdateDecorEnable(false);
528     ASSERT_EQ(res, 1);
529     GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDecorEnable end";
530 }
531 
532 /**
533  * @tc.name: NotifyModeChange
534  * @tc.desc: NotifyModeChange
535  * @tc.type: FUNC
536  */
537 HWTEST_F(WindowSessionImplTest, NotifyModeChange, Function | SmallTest | Level2)
538 {
539     GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyModeChange start";
540     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
541     option->SetWindowName("NotifyModeChange");
542     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
543     ASSERT_NE(window, nullptr);
544 
545     WindowMode mode = WindowMode::WINDOW_MODE_UNDEFINED;
546     int res = 1;
547     window->NotifyModeChange(mode, true);
548     window->NotifyModeChange(mode, false);
549     ASSERT_EQ(res, 1);
550     GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyModeChange end";
551 }
552 
553 /**
554  * @tc.name: RequestVsyncSucc
555  * @tc.desc: RequestVsync Test Succ
556  * @tc.type: FUNC
557  */
558 HWTEST_F(WindowSessionImplTest, RequestVsyncSucc, Function | SmallTest | Level2)
559 {
560     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
561     option->SetWindowName("RequestVsyncSucc");
562     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
563     ASSERT_NE(window, nullptr);
564     std::shared_ptr<VsyncCallback> vsyncCallback = std::make_shared<VsyncCallback>();
565     window->state_ = WindowState::STATE_SHOWN;
566     ASSERT_EQ(WindowState::STATE_SHOWN, window->GetWindowState());
567     ASSERT_NE(window->vsyncStation_, nullptr);
568     window->RequestVsync(vsyncCallback);
569     window->vsyncStation_ = nullptr;
570     window->RequestVsync(vsyncCallback);
571 }
572 
573 /**
574  * @tc.name: RequestVsyncErr
575  * @tc.desc: RequestVsync Test Err
576  * @tc.type: FUNC
577  */
578 HWTEST_F(WindowSessionImplTest, RequestVsyncErr, Function | SmallTest | Level2)
579 {
580     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
581     option->SetWindowName("RequestVsyncErr");
582     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
583     ASSERT_NE(window, nullptr);
584     std::shared_ptr<VsyncCallback> vsyncCallback = std::make_shared<VsyncCallback>();
585     window->state_ = WindowState::STATE_DESTROYED;
586     ASSERT_EQ(WindowState::STATE_DESTROYED, window->GetWindowState());
587     window->vsyncStation_ = nullptr;
588     window->RequestVsync(vsyncCallback);
589 }
590 
591 /**
592  * @tc.name: ClearVsync
593  * @tc.desc: Clear vsync test
594  * @tc.type: FUNC
595  */
596 HWTEST_F(WindowSessionImplTest, ClearVsync, Function | SmallTest | Level2)
597 {
598     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
599     option->SetWindowName("ClearVsync");
600     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
601     ASSERT_NE(window, nullptr);
602     window->ClearVsyncStation();
603     ASSERT_NE(window, nullptr);
604 }
605 
606 /**
607  * @tc.name: SetFocusable
608  * @tc.desc: SetFocusable
609  * @tc.type: FUNC
610  */
611 HWTEST_F(WindowSessionImplTest, SetFocusable, Function | SmallTest | Level2)
612 {
613     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetFocusable start";
614     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
615     option->SetWindowName("SetFocusable");
616     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
617 
618     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
619     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
620     ASSERT_NE(nullptr, session);
621     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
622     window->hostSession_ = session;
623     window->property_->SetPersistentId(1);
624     ASSERT_FALSE(window->GetPersistentId() == INVALID_SESSION_ID);
625     ASSERT_FALSE(window->IsWindowSessionInvalid());
626     WMError res = window->SetFocusable(true);
627     ASSERT_EQ(res, WMError::WM_OK);
628     ASSERT_EQ(WMError::WM_OK, window->Destroy());
629 
630     // session is null
631     window = sptr<WindowSessionImpl>::MakeSptr(option);
632     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr));
633     res = window->SetFocusable(true);
634     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
635     res = window->SetFocusable(false);
636     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
637     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
638     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetFocusable end";
639 }
640 
641 /**
642  * @tc.name: SetTouchable
643  * @tc.desc: SetTouchable
644  * @tc.type: FUNC
645  */
646 HWTEST_F(WindowSessionImplTest, SetTouchable, Function | SmallTest | Level2)
647 {
648     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetTouchable start";
649     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
650     option->SetWindowName("SetTouchable");
651     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
652 
653     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
654     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
655     ASSERT_NE(nullptr, session);
656     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
657     ASSERT_NE(window->property_, nullptr);
658     window->hostSession_ = session;
659     window->property_->SetPersistentId(1);
660     ASSERT_FALSE(window->IsWindowSessionInvalid());
661     WMError res = window->SetTouchable(true);
662     ASSERT_EQ(res, WMError::WM_OK);
663     ASSERT_NE(window->property_, nullptr);
664     ASSERT_TRUE(window->property_->touchable_);
665     ASSERT_EQ(WMError::WM_OK, window->Destroy());
666 
667     // session is null
668     window = sptr<WindowSessionImpl>::MakeSptr(option);
669     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr));
670     res = window->SetTouchable(true);
671     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
672     res = window->SetTouchable(false);
673     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
674     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
675     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetTouchable end";
676 }
677 
678 /**
679  * @tc.name: SetBrightness01
680  * @tc.desc: SetBrightness
681  * @tc.type: FUNC
682  */
683 HWTEST_F(WindowSessionImplTest, SetBrightness01, Function | SmallTest | Level2)
684 {
685     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBrightness01 start";
686     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
687     option->SetWindowName("SetBrightness01");
688     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
689 
690     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
691     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
692     ASSERT_NE(nullptr, session);
693     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
694     ASSERT_NE(nullptr, window->property_);
695     window->property_->SetPersistentId(1);
696 
697     float brightness = -0.5f; // brightness < 0
698     WMError res = window->SetBrightness(brightness);
699     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_PARAM);
700     brightness = 2.0f; // brightness > 1
701     res = window->SetBrightness(brightness);
702     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_PARAM);
703 
704     brightness = 0.5f;
705     window->hostSession_ = session;
706     ASSERT_FALSE(window->IsWindowSessionInvalid());
707     res = window->SetBrightness(brightness);
708     ASSERT_EQ(res, WMError::WM_OK);
709     ASSERT_EQ(WMError::WM_OK, window->Destroy());
710     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBrightness01 end";
711 }
712 
713 /**
714  * @tc.name: SetBrightness02
715  * @tc.desc: SetBrightness
716  * @tc.type: FUNC
717  */
718 HWTEST_F(WindowSessionImplTest, SetBrightness02, Function | SmallTest | Level2)
719 {
720     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBrightness02 start";
721     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
722     option->SetWindowName("SetBrightness02");
723     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
724 
725     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
726     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
727     ASSERT_NE(nullptr, session);
728     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
729     window->hostSession_ = session;
730     ASSERT_NE(nullptr, window->property_);
731     window->property_->SetPersistentId(1);
732     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
733     float brightness = 0.5f;
734     WMError res = window->SetBrightness(brightness);
735     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_TYPE);
736 
737     window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
738     res = window->SetBrightness(brightness);
739     ASSERT_EQ(res, WMError::WM_OK);
740     ASSERT_EQ(WMError::WM_OK, window->Destroy());
741     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBrightness02 end";
742 }
743 
744 /**
745  * @tc.name: SetRequestedOrientation
746  * @tc.desc: SetRequestedOrientation
747  * @tc.type: FUNC
748  */
749 HWTEST_F(WindowSessionImplTest, SetRequestedOrientation, Function | SmallTest | Level2)
750 {
751     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetRequestedOrientation start";
752     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
753     option->SetWindowName("SetRequestedOrientation");
754     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
755 
756     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
757     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
758     ASSERT_NE(nullptr, session);
759     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
760 
761     window->hostSession_ = session;
762     window->property_->SetPersistentId(1);
763 
764     Orientation ori = Orientation::VERTICAL;
765     window->SetRequestedOrientation(ori);
766     Orientation ret = window->GetRequestedOrientation();
767     ASSERT_EQ(ret, ori);
768 
769     window->SetRequestedOrientation(Orientation::AUTO_ROTATION_UNSPECIFIED);
770     Orientation ret1 = window->GetRequestedOrientation();
771     ASSERT_EQ(ret1, Orientation::AUTO_ROTATION_UNSPECIFIED);
772 
773     window->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT);
774     Orientation ret2 = window->GetRequestedOrientation();
775     ASSERT_EQ(ret2, Orientation::USER_ROTATION_PORTRAIT);
776 
777     window->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE);
778     Orientation ret3 = window->GetRequestedOrientation();
779     ASSERT_EQ(ret3, Orientation::USER_ROTATION_LANDSCAPE);
780 
781     window->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT_INVERTED);
782     Orientation ret4 = window->GetRequestedOrientation();
783     ASSERT_EQ(ret4, Orientation::USER_ROTATION_PORTRAIT_INVERTED);
784 
785     window->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
786     Orientation ret5 = window->GetRequestedOrientation();
787     ASSERT_EQ(ret5, Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
788 
789     window->SetRequestedOrientation(Orientation::FOLLOW_DESKTOP);
790     Orientation ret6 = window->GetRequestedOrientation();
791     ASSERT_EQ(ret6, Orientation::FOLLOW_DESKTOP);
792     ASSERT_EQ(WMError::WM_OK, window->Destroy());
793     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetRequestedOrientation end";
794 }
795 
796 /**
797  * @tc.name: GetRequestedOrientationtest01
798  * @tc.desc: GetRequestedOrientation
799  * @tc.type: FUNC
800  */
801 HWTEST_F(WindowSessionImplTest, GetRequestedOrientation, Function | SmallTest | Level2)
802 {
803     GTEST_LOG_(INFO) << "WindowSessionImplTest: GetRequestedOrientationtest01 start";
804     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
805 
806     option->SetWindowName("GetRequestedOrientation");
807 
808     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
809     ASSERT_NE(window, nullptr);
810 
811     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
812     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
813     ASSERT_NE(nullptr, session);
814     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
815 
816     window->hostSession_ = session;
817     window->property_->SetPersistentId(1);
818 
819     Orientation ori = Orientation::HORIZONTAL;
820     window->SetRequestedOrientation(ori);
821     Orientation ret = window->GetRequestedOrientation();
822     ASSERT_EQ(ret, ori);
823 
824     window->SetRequestedOrientation(Orientation::AUTO_ROTATION_UNSPECIFIED);
825     Orientation ret1 = window->GetRequestedOrientation();
826     ASSERT_EQ(ret1, Orientation::AUTO_ROTATION_UNSPECIFIED);
827 
828     window->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT);
829     Orientation ret2 = window->GetRequestedOrientation();
830     ASSERT_EQ(ret2, Orientation::USER_ROTATION_PORTRAIT);
831 
832     window->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE);
833     Orientation ret3 = window->GetRequestedOrientation();
834     ASSERT_EQ(ret3, Orientation::USER_ROTATION_LANDSCAPE);
835 
836     window->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT_INVERTED);
837     Orientation ret4 = window->GetRequestedOrientation();
838     ASSERT_EQ(ret4, Orientation::USER_ROTATION_PORTRAIT_INVERTED);
839 
840     window->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
841     Orientation ret5 = window->GetRequestedOrientation();
842     ASSERT_EQ(ret5, Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
843 
844     window->SetRequestedOrientation(Orientation::FOLLOW_DESKTOP);
845     Orientation ret6 = window->GetRequestedOrientation();
846     ASSERT_EQ(ret6, Orientation::FOLLOW_DESKTOP);
847 
848     GTEST_LOG_(INFO) << "WindowSessionImplTest: GetRequestedOrientationtest01 end";
849 }
850 
851 /**
852  * @tc.name: GetContentInfo
853  * @tc.desc: GetContentInfo
854  * @tc.type: FUNC
855  */
856 HWTEST_F(WindowSessionImplTest, GetContentInfo, Function | SmallTest | Level2)
857 {
858     GTEST_LOG_(INFO) << "WindowSessionImplTest: GetContentInfo start";
859     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
860     option->SetWindowName("GetContentInfo");
861     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
862 
863     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
864     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
865     ASSERT_NE(nullptr, session);
866     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
867 
868     std::string res = window->GetContentInfo();
869     ASSERT_EQ(res, "");
870     window->uiContent_ = nullptr;
871     res = window->GetContentInfo();
872     ASSERT_EQ(res, "");
873     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
874     GTEST_LOG_(INFO) << "WindowSessionImplTest: GetContentInfo end";
875 }
876 
877 /**
878  * @tc.name: OnNewWant
879  * @tc.desc: OnNewWant
880  * @tc.type: FUNC
881  */
882 HWTEST_F(WindowSessionImplTest, OnNewWant, Function | SmallTest | Level2)
883 {
884     GTEST_LOG_(INFO) << "WindowSessionImplTest: OnNewWant start";
885     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
886     option->SetWindowName("OnNewWant");
887     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
888 
889     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
890     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
891     ASSERT_NE(nullptr, session);
892     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
893 
894     AAFwk::Want want;
895     window->uiContent_ = nullptr;
896     window->OnNewWant(want);
897     ASSERT_EQ(window->GetUIContentSharedPtr(), nullptr);
898     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
899     window->OnNewWant(want);
900     ASSERT_NE(window->GetUIContentSharedPtr(), nullptr);
901 
902     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
903     GTEST_LOG_(INFO) << "WindowSessionImplTest: OnNewWant end";
904 }
905 
906 /**
907  * @tc.name: SetAPPWindowLabel
908  * @tc.desc: SetAPPWindowLabel
909  * @tc.type: FUNC
910  */
911 HWTEST_F(WindowSessionImplTest, SetAPPWindowLabel, Function | SmallTest | Level2)
912 {
913     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAPPWindowLabel start";
914     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
915     option->SetWindowName("SetAPPWindowLabel");
916     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
917 
918     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
919     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
920     ASSERT_NE(nullptr, session);
921     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
922 
923     std::string label = "label";
924     window->uiContent_ = nullptr;
925     WMError res = window->SetAPPWindowLabel(label);
926     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
927 
928     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
929     res = window->SetAPPWindowLabel(label);
930     ASSERT_EQ(res, WMError::WM_OK);
931     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
932     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAPPWindowLabel end";
933 }
934 
935 /**
936  * @tc.name: RegisterListener01
937  * @tc.desc: RegisterListener and UnregisterListener
938  * @tc.type: FUNC
939  */
940 HWTEST_F(WindowSessionImplTest, RegisterListener01, Function | SmallTest | Level2)
941 {
942     GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener01 start";
943     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
944     option->SetWindowName("RegisterListener01");
945     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
946 
947     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
948     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
949     ASSERT_NE(nullptr, session);
950     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
951     window->hostSession_ = session;
952     ASSERT_NE(window->property_, nullptr);
953     window->property_->SetPersistentId(1);
954 
955     sptr<IWindowLifeCycle> listener = nullptr;
956     WMError res = window->RegisterLifeCycleListener(listener);
957     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
958     res = window->UnregisterLifeCycleListener(listener);
959     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
960 
961     sptr<IOccupiedAreaChangeListener> listener1 = nullptr;
962     res = window->RegisterOccupiedAreaChangeListener(listener1);
963     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
964     res = window->UnregisterOccupiedAreaChangeListener(listener1);
965     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
966 
967     sptr<IWindowChangeListener> listener2 = nullptr;
968     res = window->RegisterWindowChangeListener(listener2);
969     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
970     res = window->UnregisterWindowChangeListener(listener2);
971     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
972 
973     sptr<IDialogDeathRecipientListener> listener3 = nullptr;
974     window->RegisterDialogDeathRecipientListener(listener3);
975     window->UnregisterDialogDeathRecipientListener(listener3);
976 
977     sptr<IDialogTargetTouchListener> listener4 = nullptr;
978     res = window->RegisterDialogTargetTouchListener(listener4);
979     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
980     res = window->UnregisterDialogTargetTouchListener(listener4);
981     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
982     sptr<IWindowStatusChangeListener> listener5 = nullptr;
983     res = window->RegisterWindowStatusChangeListener(listener5);
984     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
985     res = window->UnregisterWindowStatusChangeListener(listener5);
986     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
987     sptr<IWindowCrossAxisListener> listener6 = nullptr;
988     res = window->RegisterWindowCrossAxisListener(listener6);
989     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
990     res = window->UnregisterWindowCrossAxisListener(listener6);
991     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
992     ASSERT_EQ(WMError::WM_OK, window->Destroy());
993     GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener01 end";
994 }
995 
996 /**
997  * @tc.name: RegisterListener02
998  * @tc.desc: RegisterListener and UnregisterListener
999  * @tc.type: FUNC
1000  */
1001 HWTEST_F(WindowSessionImplTest, RegisterListener02, Function | SmallTest | Level2)
1002 {
1003     GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener02 start";
1004     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1005     option->SetWindowName("RegisterListener02");
1006     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1007     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1008     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1009     ASSERT_NE(nullptr, session);
1010     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1011     window->hostSession_ = session;
1012     ASSERT_NE(window->property_, nullptr);
1013     window->property_->SetPersistentId(1);
1014 
1015     sptr<IScreenshotListener> listener5 = nullptr;
1016     WMError res = window->RegisterScreenshotListener(listener5);
1017     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1018     res = window->UnregisterScreenshotListener(listener5);
1019     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1020 
1021     sptr<IAvoidAreaChangedListener> listener6 = nullptr;
1022     res = window->RegisterAvoidAreaChangeListener(listener6);
1023     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1024     res = window->UnregisterAvoidAreaChangeListener(listener6);
1025     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1026 
1027     sptr<ITouchOutsideListener> listener7 = nullptr;
1028     res = window->RegisterTouchOutsideListener(listener7);
1029     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1030     res = window->UnregisterTouchOutsideListener(listener7);
1031     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1032 
1033     IWindowVisibilityListenerSptr listener8 = nullptr;
1034     res = window->RegisterWindowVisibilityChangeListener(listener8);
1035     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1036     res = window->UnregisterWindowVisibilityChangeListener(listener8);
1037     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1038 
1039     IDisplayIdChangeListenerSptr listener9 = nullptr;
1040     res = window->RegisterDisplayIdChangeListener(listener9);
1041     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1042     res = window->UnregisterDisplayIdChangeListener(listener9);
1043     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1044 
1045     sptr<IWindowTitleButtonRectChangedListener> listener10 = nullptr;
1046     res = window->RegisterWindowTitleButtonRectChangeListener(listener10);
1047     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1048     res = window->UnregisterWindowTitleButtonRectChangeListener(listener10);
1049     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1050     ASSERT_EQ(WMError::WM_OK, window->Destroy());
1051     GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener02 end";
1052 }
1053 
1054 /**
1055  * @tc.name: RegisterListener03
1056  * @tc.desc: RegisterListener and UnregisterListener
1057  * @tc.type: FUNC
1058  */
1059 HWTEST_F(WindowSessionImplTest, RegisterListener03, Function | SmallTest | Level2)
1060 {
1061     GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener03 start";
1062     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1063     option->SetWindowName("RegisterListener03");
1064     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1065 
1066     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1067     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1068     ASSERT_NE(nullptr, session);
1069     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1070     window->hostSession_ = session;
1071     ASSERT_NE(window->property_, nullptr);
1072     window->property_->SetPersistentId(1);
1073 
1074     sptr<IDisplayMoveListener> listener6 = nullptr;
1075     WMError res = window->RegisterDisplayMoveListener(listener6);
1076     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1077     res = window->UnregisterDisplayMoveListener(listener6);
1078     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1079 
1080     sptr<IWindowRectChangeListener> listener7 = nullptr;
1081     res = window->RegisterWindowRectChangeListener(listener7);
1082     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1083 
1084     sptr<ISubWindowCloseListener> listener10 = nullptr;
1085     res = window->RegisterSubWindowCloseListeners(listener10);
1086     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1087     res = window->UnregisterSubWindowCloseListeners(listener10);
1088     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1089 
1090     sptr<ISwitchFreeMultiWindowListener> listener11 = nullptr;
1091     res = window->RegisterSwitchFreeMultiWindowListener(listener11);
1092     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1093     res = window->UnregisterSwitchFreeMultiWindowListener(listener11);
1094     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1095 
1096     sptr<IMainWindowCloseListener> listener12 = nullptr;
1097     res = window->RegisterMainWindowCloseListeners(listener12);
1098     EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
1099     res = window->UnregisterMainWindowCloseListeners(listener12);
1100     EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
1101 
1102     ISystemDensityChangeListenerSptr listener13 = nullptr;
1103     res = window->RegisterSystemDensityChangeListener(listener13);
1104     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1105     res = window->UnregisterSystemDensityChangeListener(listener13);
1106     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1107     EXPECT_EQ(WMError::WM_OK, window->Destroy());
1108     GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener03 end";
1109 }
1110 
1111 /**
1112  * @tc.name: RegisterListener04
1113  * @tc.desc: RegisterListener and UnregisterListener
1114  * @tc.type: FUNC
1115  */
1116 HWTEST_F(WindowSessionImplTest, RegisterListener04, Function | SmallTest | Level2)
1117 {
1118     GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener04 start";
1119     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1120     option->SetWindowName("RegisterListener04");
1121     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1122 
1123     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1124     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1125     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1126     window->hostSession_ = session;
1127     window->property_->SetPersistentId(1);
1128 
1129     sptr<IWindowWillCloseListener> listener14 = nullptr;
1130     WMError res = window->RegisterWindowWillCloseListeners(listener14);
1131     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1132     res = window->UnRegisterWindowWillCloseListeners(listener14);
1133     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1134 
1135     EXPECT_EQ(WMError::WM_OK, window->Destroy());
1136     GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener04 end";
1137 }
1138 
1139 /**
1140  * @tc.name: NotifyDisplayMove
1141  * @tc.desc: NotifyDisplayMove
1142  * @tc.type: FUNC
1143  */
1144 HWTEST_F(WindowSessionImplTest, NotifyDisplayMove, Function | SmallTest | Level2)
1145 {
1146     GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyDisplayMove start";
1147     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1148     option->SetWindowName("NotifyDisplayMove");
1149     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1150 
1151     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1152     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1153     ASSERT_NE(nullptr, session);
1154     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1155 
1156     int res = 0;
1157     DisplayId from = 0;
1158     DisplayId to = 2;
1159     window->NotifyDisplayMove(from, to);
1160     ASSERT_EQ(res, 0);
1161     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1162     GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyDisplayMove end";
1163 }
1164 
1165 /**
1166  * @tc.name: NotifyAfterForeground
1167  * @tc.desc: NotifyAfterForeground
1168  * @tc.type: FUNC
1169  */
1170 HWTEST_F(WindowSessionImplTest, NotifyAfterForeground, Function | SmallTest | Level2)
1171 {
1172     GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterForeground start";
1173     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1174     option->SetWindowName("NotifyAfterForeground");
1175     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1176 
1177     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1178     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1179     ASSERT_NE(nullptr, session);
1180     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1181 
1182     int res = 0;
1183     window->NotifyAfterForeground(true, true);
1184     window->NotifyAfterForeground(false, false);
1185     window->vsyncStation_ = nullptr;
1186     window->NotifyAfterForeground(false, false);
1187     ASSERT_EQ(res, 0);
1188     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1189     GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterForeground end";
1190 }
1191 
1192 /**
1193  * @tc.name: NotifyAfterBackground
1194  * @tc.desc: NotifyAfterBackground
1195  * @tc.type: FUNC
1196  */
1197 HWTEST_F(WindowSessionImplTest, NotifyAfterBackground, Function | SmallTest | Level2)
1198 {
1199     GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterBackground start";
1200     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1201     option->SetWindowName("NotifyAfterBackground");
1202     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1203 
1204     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1205     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1206     ASSERT_NE(nullptr, session);
1207     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1208 
1209     int res = 0;
1210     window->NotifyAfterBackground(true, true);
1211     window->NotifyAfterBackground(false, false);
1212     window->vsyncStation_ = nullptr;
1213     window->NotifyAfterBackground(false, false);
1214     ASSERT_EQ(res, 0);
1215     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1216     GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterBackground end";
1217 }
1218 
1219 /**
1220  * @tc.name: NotifyForegroundInteractiveStatus
1221  * @tc.desc: NotifyForegroundInteractiveStatus
1222  * @tc.type: FUNC
1223  */
1224 HWTEST_F(WindowSessionImplTest, NotifyForegroundInteractiveStatus, Function | SmallTest | Level2)
1225 {
1226     GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyForegroundInteractiveStatus start";
1227     sptr<WindowOption> option = new WindowOption();
1228     ASSERT_NE(option, nullptr);
1229     option->SetWindowName("NotifyForegroundInteractiveStatus");
1230     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1231     ASSERT_NE(window, nullptr);
1232 
1233     int res = 0;
1234     window->NotifyForegroundInteractiveStatus(true);
1235     window->NotifyForegroundInteractiveStatus(false);
1236     ASSERT_EQ(res, 0);
1237 
1238     GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyForegroundInteractiveStatus end";
1239 }
1240 
1241 /**
1242  * @tc.name: MarkProcessed
1243  * @tc.desc: MarkProcessed
1244  * @tc.type: FUNC
1245  */
1246 HWTEST_F(WindowSessionImplTest, MarkProcessed, Function | SmallTest | Level2)
1247 {
1248     GTEST_LOG_(INFO) << "WindowSessionImplTest: MarkProcessed start";
1249     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1250     option->SetWindowName("MarkProcessed");
1251     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1252 
1253     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1254     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1255     ASSERT_NE(nullptr, session);
1256     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1257 
1258     int32_t eventId = 1;
1259     window->state_ = WindowState::STATE_DESTROYED;
1260     window->hostSession_ = session;
1261     ASSERT_EQ(window->GetPersistentId(), INVALID_SESSION_ID);
1262     ASSERT_EQ(window->state_, WindowState::STATE_DESTROYED);
1263     WSError res = window->MarkProcessed(eventId);
1264     ASSERT_EQ(res, WSError::WS_DO_NOTHING);
1265     window->hostSession_ = nullptr;
1266     res = window->MarkProcessed(eventId);
1267     ASSERT_EQ(res, WSError::WS_DO_NOTHING);
1268     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1269     GTEST_LOG_(INFO) << "WindowSessionImplTest: MarkProcessed end";
1270 }
1271 
1272 /**
1273  * @tc.name: Notify01
1274  * @tc.desc: NotifyDestroy NotifyTouchDialogTarget NotifyScreenshot
1275  * @tc.type: FUNC
1276  */
1277 HWTEST_F(WindowSessionImplTest, Notify01, Function | SmallTest | Level2)
1278 {
1279     GTEST_LOG_(INFO) << "WindowSessionImplTest: Notify01 start";
1280     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1281     option->SetWindowName("Notify01");
1282     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1283 
1284     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1285     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1286     ASSERT_NE(nullptr, session);
1287     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1288 
1289     window->NotifyTouchDialogTarget();
1290     window->NotifyScreenshot();
1291     WSError res = window->NotifyDestroy();
1292     ASSERT_EQ(res, WSError::WS_OK);
1293     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1294     GTEST_LOG_(INFO) << "WindowSessionImplTest: Notify01 end";
1295 }
1296 
1297 /**
1298  * @tc.name: NotifyKeyEvent
1299  * @tc.desc: NotifyKeyEvent
1300  * @tc.type: FUNC
1301  */
1302 HWTEST_F(WindowSessionImplTest, NotifyKeyEvent, Function | SmallTest | Level2)
1303 {
1304     GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyKeyEvent start";
1305     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1306     option->SetWindowName("NotifyKeyEvent");
1307     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1308 
1309     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1310     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1311     ASSERT_NE(nullptr, session);
1312     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1313 
1314     int res = 0;
1315     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
1316     bool isConsumed = false;
1317     bool notifyInputMethod = false;
1318     keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_VIRTUAL_MULTITASK);
1319     window->NotifyKeyEvent(keyEvent, isConsumed, notifyInputMethod);
1320 
1321     keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_BACK);
1322     window->NotifyKeyEvent(keyEvent, isConsumed, notifyInputMethod);
1323 
1324     notifyInputMethod = true;
1325     window->NotifyKeyEvent(keyEvent, isConsumed, notifyInputMethod);
1326 
1327     keyEvent = nullptr;
1328     window->NotifyKeyEvent(keyEvent, isConsumed, notifyInputMethod);
1329     ASSERT_EQ(res, 0);
1330     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1331     GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyKeyEvent end";
1332 }
1333 
1334 /**
1335  * @tc.name: UpdateProperty01
1336  * @tc.desc: UpdateProperty
1337  * @tc.type: FUNC
1338  */
1339 HWTEST_F(WindowSessionImplTest, UpdateProperty01, Function | SmallTest | Level2)
1340 {
1341     GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateProperty01 start";
1342     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1343     option->SetWindowName("UpdateProperty01");
1344     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1345     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1346     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1347     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1348 
1349     ASSERT_NE(nullptr, window->property_);
1350     window->property_->SetPersistentId(1);
1351     WMError res = window->UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_RECT);
1352     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1353     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1354 }
1355 
1356 /**
1357  * @tc.name: UpdateProperty02
1358  * @tc.desc: UpdateProperty
1359  * @tc.type: FUNC
1360  */
1361 HWTEST_F(WindowSessionImplTest, UpdateProperty02, Function | SmallTest | Level2)
1362 {
1363     GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateProperty02 start";
1364     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1365     option->SetWindowName("UpdateProperty02");
1366 
1367     // session is null
1368     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1369     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr));
1370     WMError res = window->UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_RECT);
1371     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1372     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1373     GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateProperty02 end";
1374 }
1375 
1376 /**
1377  * @tc.name: Find
1378  * @tc.desc: Find
1379  * @tc.type: FUNC
1380  */
1381 HWTEST_F(WindowSessionImplTest, Find, Function | SmallTest | Level2)
1382 {
1383     GTEST_LOG_(INFO) << "WindowSessionImplTest: Find start";
1384     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1385     option->SetWindowName("Find");
1386     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1387 
1388     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1389     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1390     ASSERT_NE(nullptr, session);
1391     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1392 
1393     std::string name = "Find";
1394     sptr<Window> res = window->Find(name);
1395     ASSERT_EQ(res, nullptr);
1396 
1397     name = "111";
1398     res = window->Find(name);
1399     ASSERT_EQ(res, nullptr);
1400     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1401     GTEST_LOG_(INFO) << "WindowSessionImplTest: Find end";
1402 }
1403 
1404 /**
1405  * @tc.name: SetBackgroundColor01
1406  * @tc.desc: SetBackgroundColor string
1407  * @tc.type: FUNC
1408  */
1409 HWTEST_F(WindowSessionImplTest, SetBackgroundColor01, Function | SmallTest | Level2)
1410 {
1411     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBackgroundColor01 start";
1412     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1413     option->SetWindowName("SetBackgroundColor01");
1414     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1415 
1416     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1417     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1418     ASSERT_NE(nullptr, session);
1419     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
1420 
1421     std::string color = "Blue";
1422     WMError res = window->SetBackgroundColor(color);
1423     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1424 
1425     color = "111";
1426     res = window->SetBackgroundColor(color);
1427     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1428     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1429     // session is null
1430     window = new WindowSessionImpl(option);
1431     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr));
1432     res = window->SetBackgroundColor(color);
1433     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1434     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1435     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBackgroundColor01 end";
1436 }
1437 
1438 /**
1439  * @tc.name: SetBackgroundColor02
1440  * @tc.desc: SetBackgroundColor(uint32_t) and GetBackgroundColor
1441  * @tc.type: FUNC
1442  */
1443 HWTEST_F(WindowSessionImplTest, SetBackgroundColor02, Function | SmallTest | Level2)
1444 {
1445     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBackgroundColor02 start";
1446     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1447     option->SetWindowName("SetBackgroundColor02");
1448     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1449 
1450     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1451     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1452     ASSERT_NE(nullptr, session);
1453     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1454 
1455     WMError res = window->SetBackgroundColor(0xffffffff);
1456     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_OPERATION);
1457     uint32_t ret = window->GetBackgroundColor();
1458     ASSERT_EQ(ret, 0xffffffff);
1459     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1460     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBackgroundColor02 end";
1461 }
1462 
1463 /**
1464  * @tc.name: SetAPPWindowIcon
1465  * @tc.desc: SetAPPWindowIcon
1466  * @tc.type: FUNC
1467  */
1468 HWTEST_F(WindowSessionImplTest, SetAPPWindowIcon, Function | SmallTest | Level2)
1469 {
1470     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAPPWindowIcon start";
1471     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1472     option->SetWindowName("SetAPPWindowIcon");
1473     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1474 
1475     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1476     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1477     ASSERT_NE(nullptr, session);
1478     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1479     std::shared_ptr<Media::PixelMap> icon1(nullptr);
1480     WMError res = window->SetAPPWindowIcon(icon1);
1481     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1482 
1483     std::shared_ptr<Media::PixelMap> icon2 = std::shared_ptr<Media::PixelMap>();
1484     res = window->SetAPPWindowIcon(icon2);
1485     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1486 
1487     Media::InitializationOptions opts;
1488     opts.size.width = 200;  // 200: test width
1489     opts.size.height = 300; // 300: test height
1490     opts.pixelFormat = Media::PixelFormat::ARGB_8888;
1491     opts.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
1492     std::unique_ptr<Media::PixelMap> pixelMapPtr = Media::PixelMap::Create(opts);
1493     ASSERT_NE(pixelMapPtr.get(), nullptr);
1494     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1495     res = window->SetAPPWindowIcon(std::shared_ptr<Media::PixelMap>(pixelMapPtr.release()));
1496     ASSERT_EQ(res, WMError::WM_OK);
1497     ASSERT_NE(window->GetUIContentSharedPtr(), nullptr);
1498     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1499     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAPPWindowIcon end";
1500 }
1501 
1502 /**
1503  * @tc.name: Notify02
1504  * @tc.desc: NotifyAvoidAreaChange NotifyPointerEvent NotifyTouchOutside NotifyWindowVisibility
1505  * @tc.type: FUNC
1506  */
1507 HWTEST_F(WindowSessionImplTest, Notify02, Function | SmallTest | Level2)
1508 {
1509     GTEST_LOG_(INFO) << "WindowSessionImplTest: Notify02 start";
1510     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1511     option->SetWindowName("Notify02");
1512     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1513 
1514     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1515     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1516     ASSERT_NE(nullptr, session);
1517     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1518 
1519     sptr<AvoidArea> avoidArea = new AvoidArea();
1520     avoidArea->topRect_ = { 1, 0, 0, 0 };
1521     avoidArea->leftRect_ = { 0, 1, 0, 0 };
1522     avoidArea->rightRect_ = { 0, 0, 1, 0 };
1523     avoidArea->bottomRect_ = { 0, 0, 0, 1 };
1524     AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM;
1525     window->NotifyAvoidAreaChange(avoidArea, type);
1526 
1527     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
1528     window->NotifyPointerEvent(pointerEvent);
1529     WSError res = window->NotifyTouchOutside();
1530     ASSERT_EQ(res, WSError::WS_OK);
1531 
1532     res = window->NotifyWindowVisibility(true);
1533     ASSERT_EQ(res, WSError::WS_OK);
1534     bool terminateCloseProcess = false;
1535     window->NotifySubWindowClose(terminateCloseProcess);
1536     ASSERT_EQ(terminateCloseProcess, false);
1537 
1538     bool enable = false;
1539     window->NotifySwitchFreeMultiWindow(enable);
1540 
1541     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1542     GTEST_LOG_(INFO) << "WindowSessionImplTest: Notify02 end";
1543 }
1544 
1545 /**
1546  * @tc.name: SetAceAbilityHandler
1547  * @tc.desc: SetAceAbilityHandler
1548  * @tc.type: FUNC
1549  */
1550 HWTEST_F(WindowSessionImplTest, SetAceAbilityHandler, Function | SmallTest | Level2)
1551 {
1552     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAceAbilityHandler start";
1553     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1554     option->SetWindowName("SetAceAbilityHandler");
1555     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1556 
1557     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1558     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1559     ASSERT_NE(nullptr, session);
1560     ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1561 
1562     int res = 0;
1563     sptr<IAceAbilityHandler> handler = sptr<IAceAbilityHandler>();
1564     ASSERT_EQ(handler, nullptr);
1565     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAceAbilityHandler 111";
1566     window->SetAceAbilityHandler(handler);
1567     ASSERT_EQ(res, 0);
1568     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1569     GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAceAbilityHandler end";
1570 }
1571 
1572 /**
1573  * @tc.name: SetRaiseByClickEnabled01
1574  * @tc.desc: SetRaiseByClickEnabled and check the retCode
1575  * @tc.type: FUNC
1576  */
1577 HWTEST_F(WindowSessionImplTest, SetRaiseByClickEnabled01, Function | SmallTest | Level2)
1578 {
1579     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1580     option->SetWindowName("SetRaiseByClickEnabled01");
1581     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1582     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1583     ASSERT_NE(nullptr, window);
1584 
1585     WMError retCode = window->SetRaiseByClickEnabled(true);
1586     ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_PARENT);
1587 
1588     option->SetWindowName("SetRaiseByClickForFloatWindow");
1589     option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1590     sptr<WindowSessionImpl> floatWindow = new (std::nothrow) WindowSessionImpl(option);
1591     floatWindow->property_->SetParentPersistentId(1);
1592 
1593     retCode = floatWindow->SetRaiseByClickEnabled(true);
1594     ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_CALLING);
1595 
1596     option->SetWindowName("SetRaiseByClickForSubWindow");
1597     option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1598     sptr<WindowSessionImpl> subWindow = new (std::nothrow) WindowSessionImpl(option);
1599     ASSERT_NE(nullptr, subWindow);
1600 
1601     subWindow->property_->SetParentPersistentId(1);
1602     subWindow->Hide();
1603     retCode = subWindow->SetRaiseByClickEnabled(true);
1604     ASSERT_EQ(retCode, WMError::WM_DO_NOTHING);
1605 
1606     subWindow->state_ = WindowState::STATE_SHOWN;
1607     retCode = subWindow->SetRaiseByClickEnabled(true);
1608     ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
1609 
1610     subWindow->property_->SetParentPersistentId(2);
1611     subWindow->SetRaiseByClickEnabled(true);
1612     ASSERT_EQ(subWindow->property_->GetRaiseEnabled(), true);
1613 }
1614 
1615 /**
1616  * @tc.name: HideNonSystemFloatingWindows01
1617  * @tc.desc: HideNonSystemFloatingWindows and check the retCode
1618  * @tc.type: FUNC
1619  */
1620 HWTEST_F(WindowSessionImplTest, HideNonSystemFloatingWindows01, Function | SmallTest | Level2)
1621 {
1622     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1623     option->SetWindowName("HideNonSystemFloatingWindows01");
1624     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1625     ASSERT_NE(nullptr, window);
1626     WMError retCode = window->HideNonSystemFloatingWindows(false);
1627     ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
1628     window->property_->SetPersistentId(1);
1629     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1630     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1631     ASSERT_NE(nullptr, session);
1632     window->hostSession_ = session;
1633     window->state_ = WindowState::STATE_CREATED;
1634     window->HideNonSystemFloatingWindows(false);
1635 }
1636 
1637 /**
1638  * @tc.name: UpdateWindowModetest01
1639  * @tc.desc: UpdateWindowMode
1640  * @tc.type: FUNC
1641  */
1642 HWTEST_F(WindowSessionImplTest, UpdateWindowMode, Function | SmallTest | Level2)
1643 {
1644     GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateWindowModetest01 start";
1645     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1646     ASSERT_NE(option, nullptr);
1647     option->SetWindowName("UpdateWindowMode");
1648     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1649     ASSERT_NE(window, nullptr);
1650     WindowMode mode = WindowMode{ 0 };
1651     auto ret = window->UpdateWindowMode(mode);
1652     ASSERT_EQ(ret, WSError::WS_OK);
1653     GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateWindowModetest01 end";
1654 }
1655 
1656 /**
1657  * @tc.name: UpdateDensitytest01
1658  * @tc.desc: UpdateDensity
1659  * @tc.type: FUNC
1660  */
1661 HWTEST_F(WindowSessionImplTest, UpdateDensity, Function | SmallTest | Level2)
1662 {
1663     GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDensitytest01 start";
1664     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1665     option->SetWindowName("UpdateDensity");
1666     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1667     ASSERT_NE(window, nullptr);
1668     ASSERT_NE(window->property_, nullptr);
1669 
1670     Rect rect1;
1671     rect1.posX_ = 1;
1672     rect1.posY_ = 2;
1673     rect1.height_ = 3;
1674     rect1.width_ = 4;
1675     window->property_->SetWindowRect(rect1);
1676     auto rect2 = window->GetRect();
1677     ASSERT_EQ(1, rect2.posX_);
1678     ASSERT_EQ(2, rect2.posY_);
1679     ASSERT_EQ(3, rect2.height_);
1680     ASSERT_EQ(4, rect2.width_);
1681 
1682     window->UpdateDensity();
1683     GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDensitytest01 end";
1684 }
1685 
1686 /**
1687  * @tc.name: UpdateDisplayIdtest01
1688  * @tc.desc: UpdateDisplayId
1689  * @tc.type: FUNC
1690  */
1691 HWTEST_F(WindowSessionImplTest, UpdateDisplayId, Function | SmallTest | Level2)
1692 {
1693     GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDisplayIdtest01 start";
1694     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1695     option->SetWindowName("UpdateDisplayId");
1696     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1697     ASSERT_NE(window, nullptr);
1698     uint64_t newDisplayId = 2;
1699     auto ret = window->UpdateDisplayId(newDisplayId);
1700     ASSERT_EQ(ret, WSError::WS_OK);
1701     uint64_t displayId = window->property_->GetDisplayId();
1702     ASSERT_EQ(newDisplayId, displayId);
1703     GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDisplayIdtest01 end";
1704 }
1705 
1706 /**
1707  * @tc.name: IsFloatingWindowAppTypetest01
1708  * @tc.desc: IsFloatingWindowAppType
1709  * @tc.type: FUNC
1710  */
1711 HWTEST_F(WindowSessionImplTest, IsFloatingWindowAppType, Function | SmallTest | Level2)
1712 {
1713     GTEST_LOG_(INFO) << "WindowSessionImplTest: IsFloatingWindowAppTypetest01 start";
1714     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1715     option->SetWindowName("IsFloatingWindowAppType");
1716     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1717     ASSERT_NE(window, nullptr);
1718     window->IsFloatingWindowAppType();
1719     ASSERT_NE(window, nullptr);
1720     GTEST_LOG_(INFO) << "WindowSessionImplTest: IsFloatingWindowAppTypetest01 end";
1721 }
1722 
1723 /**
1724  * @tc.name: SetUniqueVirtualPixelRatio
1725  * @tc.desc: SetUniqueVirtualPixelRatio
1726  * @tc.type: FUNC
1727  */
1728 HWTEST_F(WindowSessionImplTest, SetUniqueVirtualPixelRatio, Function | SmallTest | Level2)
1729 {
1730     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1731     ASSERT_NE(option, nullptr);
1732     option->SetWindowName("SetUniqueVirtualPixelRatio");
1733     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1734     ASSERT_NE(window, nullptr);
1735     window->SetUniqueVirtualPixelRatio(true, 3.25f);
1736     window->SetUniqueVirtualPixelRatio(false, 3.25f);
1737 }
1738 
1739 /**
1740  * @tc.name: EnableDrag
1741  * @tc.desc: EnableDrag Test
1742  * @tc.type: FUNC
1743  */
1744 HWTEST_F(WindowSessionImplTest, EnableDrag, Function | SmallTest | Level2)
1745 {
1746     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1747     option->SetWindowName("EnableDrag");
1748     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1749     window->property_->SetPersistentId(2101);
1750     window->property_->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH);
1751     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1752     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1753     window->hostSession_ = session;
1754 
1755     window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1756     auto result = window->EnableDrag(true);
1757     ASSERT_EQ(result, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
1758 
1759     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1760     result = window->EnableDrag(true);
1761     ASSERT_NE(result, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
1762 
1763     window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
1764     window->windowSystemConfig_.freeMultiWindowEnable_ = true;
1765     window->windowSystemConfig_.freeMultiWindowSupport_ = true;
1766     result = window->EnableDrag(true);
1767     ASSERT_NE(result, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
1768 }
1769 
1770 /**
1771  * @tc.name: AddSetUIContentTimeoutCheck
1772  * @tc.desc: AddSetUIContentTimeoutCheck
1773  * @tc.type: FUNC
1774  */
1775 HWTEST_F(WindowSessionImplTest, AddSetUIContentTimeoutCheck_test, Function | SmallTest | Level2)
1776 {
1777     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1778     ASSERT_NE(option, nullptr);
1779     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1780     ASSERT_NE(window, nullptr);
1781     window->handler_ = nullptr;
1782 
1783     option->SetWindowName("AddSetUIContentTimeoutCheck_test");
1784     option->SetBundleName("UTtest");
1785     WindowType type1 = WindowType::APP_MAIN_WINDOW_BASE;
1786     option->SetWindowType(type1);
1787     sptr<WindowSessionImpl> window1 = new (std::nothrow) WindowSessionImpl(option);
1788     ASSERT_NE(window1, nullptr);
1789     window1->AddSetUIContentTimeoutCheck();
1790 
1791     WindowType type2 = WindowType::WINDOW_TYPE_UI_EXTENSION;
1792     option->SetWindowType(type2);
1793     sptr<WindowSessionImpl> window2 = new (std::nothrow) WindowSessionImpl(option);
1794     ASSERT_NE(window2, nullptr);
1795     window2->AddSetUIContentTimeoutCheck();
1796     EXPECT_EQ(WindowType::WINDOW_TYPE_UI_EXTENSION, window2->property_->GetWindowType());
1797 }
1798 
1799 /**
1800  * @tc.name: FindMainWindowWithContext01
1801  * @tc.desc: FindMainWindowWithContext
1802  * @tc.type: FUNC
1803  */
1804 HWTEST_F(WindowSessionImplTest, FindMainWindowWithContext01, Function | SmallTest | Level2)
1805 {
1806     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1807     option->SetWindowTag(WindowTag::MAIN_WINDOW);
1808     option->SetWindowName("FindMainWindowWithContext01");
1809     sptr<WindowSessionImpl> windowSession = new (std::nothrow) WindowSessionImpl(option);
1810     ASSERT_NE(nullptr, windowSession);
1811 
1812     windowSession->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1813     ASSERT_TRUE(windowSession->FindMainWindowWithContext() == nullptr);
1814     windowSession->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_END);
1815     ASSERT_TRUE(windowSession->FindMainWindowWithContext() == nullptr);
1816 
1817     windowSession->property_->SetPersistentId(1002);
1818     windowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1819     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1820     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1821     ASSERT_NE(nullptr, session);
1822     ASSERT_EQ(WMError::WM_OK, windowSession->Create(abilityContext_, session));
1823     windowSession->Destroy(true);
1824 }
1825 
1826 /**
1827  * @tc.name: FindExtensionWindowWithContext01
1828  * @tc.desc: FindExtensionWindowWithContext
1829  * @tc.type: FUNC
1830  */
1831 HWTEST_F(WindowSessionImplTest, FindExtensionWindowWithContext01, Function | SmallTest | Level2)
1832 {
1833     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1834     option->SetWindowName("FindExtensionWindowWithContext01");
1835     sptr<WindowSessionImpl> windowSession = sptr<WindowSessionImpl>::MakeSptr(option);
1836 
1837     ASSERT_TRUE(windowSession->FindExtensionWindowWithContext() == nullptr);
1838 
1839     windowSession->property_->SetPersistentId(12345);
1840     windowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
1841     windowSession->context_ = abilityContext_;
1842     WindowSessionImpl::windowExtensionSessionSet_.insert(windowSession);
1843     ASSERT_TRUE(nullptr != windowSession->FindExtensionWindowWithContext());
1844     windowSession->Destroy(true);
1845 }
1846 
1847 /**
1848  * @tc.name: SetUIContentComplete
1849  * @tc.desc: SetUIContentComplete
1850  * @tc.type: FUNC
1851  */
1852 HWTEST_F(WindowSessionImplTest, SetUIContentComplete, Function | SmallTest | Level2)
1853 {
1854     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1855     ASSERT_NE(option, nullptr);
1856     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1857     ASSERT_NE(window, nullptr);
1858     window->SetUIContentComplete();
1859     EXPECT_EQ(window->setUIContentCompleted_.load(), true);
1860 
1861     window->SetUIContentComplete();
1862     EXPECT_EQ(window->setUIContentCompleted_.load(), true);
1863 }
1864 
1865 /**
1866  * @tc.name: NotifySetUIContentComplete
1867  * @tc.desc: NotifySetUIContentComplete
1868  * @tc.type: FUNC
1869  */
1870 HWTEST_F(WindowSessionImplTest, NotifySetUIContentComplete, Function | SmallTest | Level2)
1871 {
1872     sptr<WindowOption> option = new (std::nothrow) WindowOption();
1873     ASSERT_NE(nullptr, option);
1874     option->SetWindowName("NotifySetUIContent");
1875     option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1876     sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1877     ASSERT_NE(nullptr, window);
1878     window->NotifySetUIContentComplete();
1879     EXPECT_EQ(window->setUIContentCompleted_.load(), true);
1880 
1881     option->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1882     window = new (std::nothrow) WindowSessionImpl(option);
1883     ASSERT_NE(nullptr, window);
1884     window->NotifySetUIContentComplete();
1885     EXPECT_EQ(window->setUIContentCompleted_.load(), true);
1886 
1887     option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1888     window = new (std::nothrow) WindowSessionImpl(option);
1889     ASSERT_NE(nullptr, window);
1890     window->NotifySetUIContentComplete();
1891     EXPECT_EQ(window->setUIContentCompleted_.load(), true);
1892 }
1893 
1894 /**
1895  * @tc.name: SetUIExtensionDestroyComplete
1896  * @tc.desc: SetUIExtensionDestroyComplete
1897  * @tc.type: FUNC
1898  */
1899 HWTEST_F(WindowSessionImplTest, SetUIExtensionDestroyComplete, Function | SmallTest | Level2)
1900 {
1901     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1902     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1903     window->SetUIExtensionDestroyComplete();
1904     EXPECT_EQ(window->setUIExtensionDestroyCompleted_.load(), true);
1905     window->SetUIExtensionDestroyComplete();
1906     EXPECT_EQ(window->setUIExtensionDestroyCompleted_.load(), true);
1907 }
1908 
1909 /**
1910  * @tc.name: SetUIExtensionDestroyCompleteInSubWindow
1911  * @tc.desc: SetUIExtensionDestroyCompleteInSubWindow
1912  * @tc.type: FUNC
1913  */
1914 HWTEST_F(WindowSessionImplTest, SetUIExtensionDestroyCompleteInSubWindow, Function | SmallTest | Level2)
1915 {
1916     sptr<WindowOption> subWindowOption = sptr<WindowOption>::MakeSptr();
1917     subWindowOption->SetWindowName("subWindow");
1918     sptr<WindowSessionImpl> subWindowSession = sptr<WindowSessionImpl>::MakeSptr(subWindowOption);
1919     subWindowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1920     subWindowSession->context_ = abilityContext_;
1921     subWindowSession->SetUIExtensionDestroyCompleteInSubWindow();
1922 
1923     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1924     option->SetWindowName("SetUIExtensionDestroyCompleteInSubWindow");
1925     sptr<WindowSessionImpl> windowSession = sptr<WindowSessionImpl>::MakeSptr(option);
1926     ASSERT_TRUE(windowSession->FindExtensionWindowWithContext() == nullptr);
1927     windowSession->property_->SetPersistentId(12345);
1928     windowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
1929     windowSession->context_ = abilityContext_;
1930     WindowSessionImpl::windowExtensionSessionSet_.insert(windowSession);
1931     ASSERT_TRUE(nullptr != windowSession->FindExtensionWindowWithContext());
1932     windowSession->AddSetUIExtensionDestroyTimeoutCheck();
1933     EXPECT_EQ(windowSession->startUIExtensionDestroyTimer_.load(), true);
1934     subWindowSession->SetUIExtensionDestroyCompleteInSubWindow();
1935     EXPECT_EQ(windowSession->startUIExtensionDestroyTimer_.load(), false);
1936 }
1937 
1938 /**
1939  * @tc.name: AddSetUIExtensionDestroyTimeoutCheck
1940  * @tc.desc: AddSetUIExtensionDestroyTimeoutCheck
1941  * @tc.type: FUNC
1942  */
1943 HWTEST_F(WindowSessionImplTest, AddSetUIExtensionDestroyTimeoutCheck, Function | SmallTest | Level2)
1944 {
1945     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1946     option->SetWindowName("AddSetUIExtensionDestroyTimeoutCheck");
1947     option->SetBundleName("UTtest");
1948     option->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
1949     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1950     window->AddSetUIExtensionDestroyTimeoutCheck();
1951     EXPECT_EQ(WindowType::WINDOW_TYPE_UI_EXTENSION, window->property_->GetWindowType());
1952     EXPECT_EQ(window->startUIExtensionDestroyTimer_.load(), true);
1953 }
1954 
1955 /**
1956  * @tc.name: GetStatusBarHeight
1957  * @tc.desc: GetStatusBarHeight test
1958  * @tc.type: FUNC
1959  */
1960 HWTEST_F(WindowSessionImplTest, GetStatusBarHeight, Function | SmallTest | Level3)
1961 {
1962     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1963     option->SetWindowName("GetStatusBarHeight");
1964     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1965     ASSERT_NE(window, nullptr);
1966     ASSERT_EQ(0, window->GetStatusBarHeight());
1967 }
1968 
1969 /**
1970  * @tc.name: GetWindowStatusInner
1971  * @tc.desc: GetWindowStatusInner test
1972  * @tc.type: FUNC
1973  */
1974 HWTEST_F(WindowSessionImplTest, GetWindowStatusInner, Function | SmallTest | Level3)
1975 {
1976     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1977     option->SetWindowName("GetWindowStatusInner");
1978     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1979     window->property_->SetPersistentId(1);
1980     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1981     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1982     window->hostSession_ = session;
1983     EXPECT_EQ(WindowStatus::WINDOW_STATUS_UNDEFINED, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_PIP));
1984 
1985     window->SetTargetAPIVersion(14);
1986     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1987     EXPECT_EQ(WindowStatus::WINDOW_STATUS_FULLSCREEN, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_FULLSCREEN));
1988     window->SetTargetAPIVersion(12);
1989     EXPECT_EQ(WindowStatus::WINDOW_STATUS_FULLSCREEN, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_FULLSCREEN));
1990 
1991     EXPECT_EQ(WindowStatus::WINDOW_STATUS_SPLITSCREEN,
1992     window->GetWindowStatusInner(WindowMode::WINDOW_MODE_SPLIT_PRIMARY));
1993     EXPECT_EQ(WindowStatus::WINDOW_STATUS_SPLITSCREEN,
1994     window->GetWindowStatusInner(WindowMode::WINDOW_MODE_SPLIT_SECONDARY));
1995 
1996     window->property_->maximizeMode_ = MaximizeMode::MODE_AVOID_SYSTEM_BAR;
1997     EXPECT_EQ(WindowStatus::WINDOW_STATUS_MAXIMIZE, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_FLOATING));
1998     window->property_->maximizeMode_ = MaximizeMode::MODE_FULL_FILL;
1999     EXPECT_EQ(WindowStatus::WINDOW_STATUS_FLOATING, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_FLOATING));
2000 
2001     window->state_ = WindowState::STATE_HIDDEN;
2002     EXPECT_EQ(WindowStatus::WINDOW_STATUS_MINIMIZE, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_PIP));
2003 }
2004 
2005 /**
2006  * @tc.name: GetBackgroundColor01
2007  * @tc.desc: GetBackgroundColor01 test
2008  * @tc.type: FUNC
2009  */
2010 HWTEST_F(WindowSessionImplTest, GetBackgroundColor01, Function | SmallTest | Level3)
2011 {
2012     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2013     option->SetWindowName("GetBackgroundColor01");
2014     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2015     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
2016     EXPECT_EQ(0, window->GetBackgroundColor());
2017 }
2018 
2019 /**
2020  * @tc.name: GetBackgroundColor02
2021  * @tc.desc: GetBackgroundColor02 test
2022  * @tc.type: FUNC
2023  */
2024 HWTEST_F(WindowSessionImplTest, GetBackgroundColor02, Function | SmallTest | Level3)
2025 {
2026     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2027     option->SetWindowName("GetBackgroundColor02");
2028     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2029     sptr<IAceAbilityHandler> handler = sptr<IAceAbilityHandler>();
2030     window->SetAceAbilityHandler(handler);
2031     EXPECT_EQ(0xffffffff, window->GetBackgroundColor());
2032 }
2033 
2034 /**
2035  * @tc.name: GetBackgroundColor03
2036  * @tc.desc: GetBackgroundColor03 test
2037  * @tc.type: FUNC
2038  */
2039 HWTEST_F(WindowSessionImplTest, GetBackgroundColor03, Function | SmallTest | Level3)
2040 {
2041     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2042     option->SetWindowName("GetBackgroundColor03");
2043     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2044     EXPECT_EQ(0xffffffff, window->GetBackgroundColor());
2045 }
2046 
2047 /**
2048  * @tc.name: GetExtensionConfig
2049  * @tc.desc: GetExtensionConfig test
2050  * @tc.type: FUNC
2051  */
2052 HWTEST_F(WindowSessionImplTest, GetExtensionConfig, Function | SmallTest | Level3)
2053 {
2054     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2055     option->SetWindowName("GetExtensionConfig");
2056     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2057     window->crossAxisState_ = CrossAxisState::STATE_CROSS;
2058     AAFwk::WantParams want;
2059     window->GetExtensionConfig(want);
2060     EXPECT_EQ(want.GetIntParam(Extension::CROSS_AXIS_FIELD, 0), static_cast<int32_t>(CrossAxisState::STATE_CROSS));
2061     window->crossAxisState_ = CrossAxisState::STATE_INVALID;
2062     window->GetExtensionConfig(want);
2063     EXPECT_EQ(want.GetIntParam(Extension::CROSS_AXIS_FIELD, 0), static_cast<int32_t>(CrossAxisState::STATE_INVALID));
2064     window->crossAxisState_ = CrossAxisState::STATE_NO_CROSS;
2065     window->GetExtensionConfig(want);
2066     EXPECT_EQ(want.GetIntParam(Extension::CROSS_AXIS_FIELD, 0), static_cast<int32_t>(CrossAxisState::STATE_NO_CROSS));
2067     window->crossAxisState_ = CrossAxisState::STATE_END;
2068     window->GetExtensionConfig(want);
2069     EXPECT_EQ(want.GetIntParam(Extension::CROSS_AXIS_FIELD, 0), static_cast<int32_t>(CrossAxisState::STATE_END));
2070 }
2071 
2072 /**
2073  * @tc.name: UpdateExtensionConfig
2074  * @tc.desc: UpdateExtensionConfig test
2075  * @tc.type: FUNC
2076  */
2077 HWTEST_F(WindowSessionImplTest, UpdateExtensionConfig, Function | SmallTest | Level3)
2078 {
2079     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2080     option->SetWindowName("UpdateExtensionConfig");
2081     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2082     window->crossAxisState_ = CrossAxisState::STATE_INVALID;
2083     auto want = std::make_shared<AAFwk::Want>();
2084     window->UpdateExtensionConfig(want);
2085     EXPECT_EQ(window->crossAxisState_.load(), CrossAxisState::STATE_INVALID);
2086 
2087     AAFwk::WantParams configParam;
2088     AAFwk::WantParams wantParam(want->GetParams());
2089     configParam.SetParam(Extension::CROSS_AXIS_FIELD,
2090         AAFwk::Integer::Box(static_cast<int32_t>(CrossAxisState::STATE_CROSS)));
2091     wantParam.SetParam(Extension::UIEXTENSION_CONFIG_FIELD, AAFwk::WantParamWrapper::Box(configParam));
2092     want->SetParams(wantParam);
2093     window->UpdateExtensionConfig(want);
2094     EXPECT_EQ(window->crossAxisState_.load(), CrossAxisState::STATE_CROSS);
2095     configParam.SetParam(Extension::CROSS_AXIS_FIELD,
2096         AAFwk::Integer::Box(static_cast<int32_t>(CrossAxisState::STATE_INVALID)));
2097     wantParam.SetParam(Extension::UIEXTENSION_CONFIG_FIELD, AAFwk::WantParamWrapper::Box(configParam));
2098     want->SetParams(wantParam);
2099     window->UpdateExtensionConfig(want);
2100     EXPECT_EQ(window->crossAxisState_.load(), CrossAxisState::STATE_INVALID);
2101     configParam.SetParam(Extension::CROSS_AXIS_FIELD,
2102         AAFwk::Integer::Box(static_cast<int32_t>(CrossAxisState::STATE_NO_CROSS)));
2103     wantParam.SetParam(Extension::UIEXTENSION_CONFIG_FIELD, AAFwk::WantParamWrapper::Box(configParam));
2104     want->SetParams(wantParam);
2105     window->UpdateExtensionConfig(want);
2106     EXPECT_EQ(window->crossAxisState_.load(), CrossAxisState::STATE_NO_CROSS);
2107     configParam.SetParam(Extension::CROSS_AXIS_FIELD,
2108         AAFwk::Integer::Box(static_cast<int32_t>(CrossAxisState::STATE_END)));
2109     wantParam.SetParam(Extension::UIEXTENSION_CONFIG_FIELD, AAFwk::WantParamWrapper::Box(configParam));
2110     want->SetParams(wantParam);
2111     window->UpdateExtensionConfig(want);
2112     EXPECT_EQ(window->crossAxisState_.load(), CrossAxisState::STATE_NO_CROSS);
2113 }
2114 } // namespace
2115 } // namespace Rosen
2116 } // namespace OHOS
2117