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