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