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