• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <filesystem>
17 #include <fstream>
18 #include <gtest/gtest.h>
19 
20 #include "ability_context_impl.h"
21 #include "color_parser.h"
22 #include "extension/extension_business_info.h"
23 #include "mock_ability_context_impl.h"
24 #include "mock_session.h"
25 #include "mock_session_stub.h"
26 #include "mock_uicontent.h"
27 #include "mock_window.h"
28 #include "parameters.h"
29 #include "scene_board_judgement.h"
30 #include "window_helper.h"
31 #include "window_session_impl.h"
32 #include "wm_common.h"
33 
34 using namespace testing;
35 using namespace testing::ext;
36 
37 namespace OHOS {
38 namespace Rosen {
39 class WindowSessionImplTest5 : public testing::Test {
40 public:
41     static void SetUpTestCase();
42     static void TearDownTestCase();
43     void SetUp() override;
44     void TearDown() override;
45 
46 private:
47     static constexpr int32_t PERSISTENT_ID_ONE = 1;
48     static constexpr int32_t PERSISTENT_ID_TWO = 2;
49 };
50 
SetUpTestCase()51 void WindowSessionImplTest5::SetUpTestCase() {}
52 
TearDownTestCase()53 void WindowSessionImplTest5::TearDownTestCase() {}
54 
SetUp()55 void WindowSessionImplTest5::SetUp()
56 {
57 }
58 
TearDown()59 void WindowSessionImplTest5::TearDown()
60 {
61 }
62 
63 namespace {
64 /**
65  * @tc.name: GetSubWindows
66  * @tc.desc: GetSubWindows
67  * @tc.type: FUNC
68  */
69 HWTEST_F(WindowSessionImplTest5, GetSubWindows, TestSize.Level1)
70 {
71     GTEST_LOG_(INFO) << "WindowSessionImplTest5: GetSubWindows start";
72     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
73     option->SetWindowName("GetSubWindows");
74     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
75     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
76     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
77     window->hostSession_ = session;
78     window->property_->SetPersistentId(1);
79     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
80     std::vector<sptr<WindowSessionImpl>> subWindows;
81     window->GetSubWindows(1, subWindows);
82     EXPECT_EQ(subWindows.size(), 0);
83 
84     sptr<WindowOption> subWindowOption = sptr<WindowOption>::MakeSptr();
85     subWindowOption->SetWindowName("GetSubWindows_subWindow");
86     sptr<WindowSessionImpl> subWindow = sptr<WindowSessionImpl>::MakeSptr(subWindowOption);
87     subWindow->property_->SetPersistentId(2);
88     subWindow->property_->SetParentPersistentId(1);
89     subWindow->hostSession_ = session;
90     subWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
91     subWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
92     WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
93         std::vector<sptr<WindowSessionImpl>>>(1, { subWindow }));
94 
95     subWindows.clear();
96     window->GetSubWindows(1, subWindows);
97     ASSERT_EQ(subWindows.size(), 1);
98     EXPECT_EQ(subWindows[0], subWindow);
99     GTEST_LOG_(INFO) << "WindowSessionImplTest5: GetSubWindows end";
100 }
101 
102 /**
103  * @tc.name: RemoveSubWindow
104  * @tc.desc: RemoveSubWindow
105  * @tc.type: FUNC
106  */
107 HWTEST_F(WindowSessionImplTest5, RemoveSubWindow, TestSize.Level1)
108 {
109     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
110     option->SetWindowName("RemoveSubWindow");
111     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
112     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
113     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
114     window->hostSession_ = session;
115     window->property_->SetPersistentId(1);
116     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
117 
118     sptr<WindowOption> subWindowOption = sptr<WindowOption>::MakeSptr();
119     subWindowOption->SetWindowName("RemoveSubWindow_subWindow");
120     sptr<WindowSessionImpl> subWindow = sptr<WindowSessionImpl>::MakeSptr(subWindowOption);
121     subWindow->property_->SetPersistentId(2);
122     subWindow->property_->SetParentPersistentId(1);
123     subWindow->hostSession_ = session;
124     subWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
125     subWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
126     WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
127         std::vector<sptr<WindowSessionImpl>>>(1, { subWindow }));
128 
129     sptr<WindowOption> subWindowOption2 = sptr<WindowOption>::MakeSptr();
130     subWindowOption2->SetWindowName("RemoveSubWindow_subWindow2");
131     sptr<WindowSessionImpl> subWindow2 = sptr<WindowSessionImpl>::MakeSptr(subWindowOption2);
132     subWindow2->property_->SetPersistentId(3);
133     subWindow2->property_->SetParentPersistentId(1);
134     subWindow2->hostSession_ = session;
135     subWindow2->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
136     subWindow2->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
137     WindowSessionImpl::subWindowSessionMap_[1].push_back(subWindow2);
138 
139     subWindow->RemoveSubWindow(2);
140     std::vector<sptr<WindowSessionImpl>> subWindows;
141     window->GetSubWindows(1, subWindows);
142     ASSERT_EQ(subWindows.size(), 2);
143     EXPECT_EQ(subWindows[0], subWindow);
144     subWindow->RemoveSubWindow(1);
145     subWindows.clear();
146     window->GetSubWindows(1, subWindows);
147     ASSERT_EQ(subWindows.size(), 1);
148     EXPECT_NE(subWindows[0], subWindow);
149 }
150 
151 /**
152  * @tc.name: DestroySubWindow01
153  * @tc.desc: DestroySubWindow test
154  * @tc.type: FUNC
155  */
156 HWTEST_F(WindowSessionImplTest5, DestroySubWindow01, TestSize.Level1)
157 {
158     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
159     option->SetWindowName("DestroySubWindow01");
160     option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
161     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
162     window->property_->SetPersistentId(1);
163 
164     sptr<WindowOption> subOption01 = sptr<WindowOption>::MakeSptr();
165     subOption01->SetWindowName("DestroySubWindow01_subwindow01");
166     subOption01->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
167     sptr<WindowSessionImpl> subWindow01 = sptr<WindowSessionImpl>::MakeSptr(subOption01);
168     subWindow01->property_->SetPersistentId(2);
169     subWindow01->property_->SetParentPersistentId(1);
170     SessionInfo sessionInfo1 = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
171     sptr<SessionMocker> session1 = sptr<SessionMocker>::MakeSptr(sessionInfo1);
172     subWindow01->hostSession_ = session1;
173     subWindow01->state_ = WindowState::STATE_CREATED;
174     WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
175         std::vector<sptr<WindowSessionImpl>>>(1, { subWindow01 }));
176 
177     sptr<WindowOption> subOption02 = sptr<WindowOption>::MakeSptr();
178     subOption02->SetWindowName("DestroySubWindow01_subwindow02");
179     subOption02->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
180     sptr<WindowSessionImpl> subWindow02 = sptr<WindowSessionImpl>::MakeSptr(subOption01);
181     subWindow02->property_->SetPersistentId(3);
182     subWindow02->property_->SetParentPersistentId(2);
183     SessionInfo sessionInfo2 = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
184     sptr<SessionMocker> session2 = sptr<SessionMocker>::MakeSptr(sessionInfo2);
185     subWindow02->hostSession_ = session2;
186     subWindow02->state_ = WindowState::STATE_CREATED;
187     WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
188         std::vector<sptr<WindowSessionImpl>>>(2, { subWindow02 }));
189 
190     std::vector<sptr<WindowSessionImpl>> subWindows;
191     window->GetSubWindows(1, subWindows);
192     EXPECT_EQ(subWindows.size(), 1);
193     subWindows.clear();
194     window->GetSubWindows(2, subWindows);
195     EXPECT_EQ(subWindows.size(), 1);
196     window->DestroySubWindow();
197     EXPECT_EQ(subWindow01->state_, WindowState::STATE_DESTROYED);
198     EXPECT_EQ(subWindow02->state_, WindowState::STATE_DESTROYED);
199     EXPECT_EQ(subWindow01->hostSession_, nullptr);
200     EXPECT_EQ(subWindow02->hostSession_, nullptr);
201     subWindows.clear();
202     window->GetSubWindows(1, subWindows);
203     EXPECT_EQ(subWindows.size(), 0);
204     subWindows.clear();
205     window->GetSubWindows(2, subWindows);
206     EXPECT_EQ(subWindows.size(), 0);
207 }
208 
209 /**
210  * @tc.name: SetUniqueVirtualPixelRatioForSub
211  * @tc.desc: SetUniqueVirtualPixelRatioForSub test
212  * @tc.type: FUNC
213  */
214 HWTEST_F(WindowSessionImplTest5, SetUniqueVirtualPixelRatioForSub, TestSize.Level1)
215 {
216     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
217     option->SetWindowName("SetUniqueVirtualPixelRatioForSub");
218     option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
219     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
220     window->property_->SetPersistentId(1);
221 
222     sptr<WindowOption> subOption01 = sptr<WindowOption>::MakeSptr();
223     subOption01->SetWindowName("SetUniqueVirtualPixelRatioForSub_subwindow01");
224     subOption01->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
225     sptr<WindowSessionImpl> subWindow01 = sptr<WindowSessionImpl>::MakeSptr(subOption01);
226     subWindow01->property_->SetPersistentId(2);
227     subWindow01->property_->SetParentPersistentId(1);
228     subWindow01->useUniqueDensity_ = false;
229     subWindow01->virtualPixelRatio_ = 0.5f;
230     WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
231         std::vector<sptr<WindowSessionImpl>>>(1, { subWindow01 }));
232 
233     sptr<WindowOption> subOption02 = sptr<WindowOption>::MakeSptr();
234     subOption02->SetWindowName("SetUniqueVirtualPixelRatioForSub_subwindow02");
235     subOption02->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
236     sptr<WindowSessionImpl> subWindow02 = sptr<WindowSessionImpl>::MakeSptr(subOption01);
237     subWindow02->property_->SetPersistentId(3);
238     subWindow02->property_->SetParentPersistentId(2);
239     subWindow01->useUniqueDensity_ = false;
240     subWindow01->virtualPixelRatio_ = 0.3f;
241     WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
242         std::vector<sptr<WindowSessionImpl>>>(2, { subWindow02 }));
243 
244     bool useUniqueDensity = true;
245     float virtualPixelRatio = 1.0f;
246     window->SetUniqueVirtualPixelRatioForSub(useUniqueDensity, virtualPixelRatio);
247     EXPECT_EQ(subWindow01->useUniqueDensity_, useUniqueDensity);
248     EXPECT_EQ(subWindow02->useUniqueDensity_, useUniqueDensity);
249     EXPECT_NEAR(subWindow01->virtualPixelRatio_, virtualPixelRatio, 0.00001f);
250     EXPECT_NEAR(subWindow02->virtualPixelRatio_, virtualPixelRatio, 0.00001f);
251 }
252 
253 /**
254  * @tc.name: RegisterWindowRotationChangeListener
255  * @tc.desc: RegisterWindowRotationChangeListener
256  * @tc.type: FUNC
257  */
258 HWTEST_F(WindowSessionImplTest5, RegisterWindowRotationChangeListener, Function | SmallTest | Level2)
259 {
260     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
261     option->SetWindowName("RegisterWindowRotationChangeListener");
262     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
263     sptr<IWindowRotationChangeListener> listener = nullptr;
264     WMError ret = window->RegisterWindowRotationChangeListener(listener);
265     EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
266 
267     listener = sptr<IWindowRotationChangeListener>::MakeSptr();
268     std::vector<sptr<IWindowRotationChangeListener>> holder;
269     window->windowRotationChangeListeners_[window->property_->GetPersistentId()] = holder;
270     ret = window->RegisterWindowRotationChangeListener(listener);
271     EXPECT_EQ(ret, WMError::WM_OK);
272     holder = window->windowRotationChangeListeners_[window->property_->GetPersistentId()];
273     auto existsListener = std::find(holder.begin(), holder.end(), listener);
274     ASSERT_NE(existsListener, holder.end());
275 
276     ret = window->RegisterWindowRotationChangeListener(listener);
277     EXPECT_EQ(ret, WMError::WM_OK);
278 }
279 
280 /**
281  * @tc.name: UnregisterWindowRotationChangeListener
282  * @tc.desc: UnregisterWindowRotationChangeListener
283  * @tc.type: FUNC
284  */
285 HWTEST_F(WindowSessionImplTest5, UnregisterWindowRotationChangeListener, Function | SmallTest | Level2)
286 {
287     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
288     option->SetWindowName("UnregisterWindowRotationChangeListener");
289 
290     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
291     sptr<IWindowRotationChangeListener> listener = nullptr;
292     WMError ret = window->UnregisterWindowRotationChangeListener(listener);
293     EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
294 
295     listener = sptr<IWindowRotationChangeListener>::MakeSptr();
296     std::vector<sptr<IWindowRotationChangeListener>> holder;
297     window->windowRotationChangeListeners_[window->property_->GetPersistentId()] = holder;
298     window->RegisterWindowRotationChangeListener(listener);
299     ret = window->UnregisterWindowRotationChangeListener(listener);
300     EXPECT_EQ(ret, WMError::WM_OK);
301 
302     holder = window->windowRotationChangeListeners_[window->property_->GetPersistentId()];
303     auto existsListener = std::find(holder.begin(), holder.end(), listener);
304     EXPECT_EQ(existsListener, holder.end());
305 }
306 
307 /**
308  * @tc.name: CheckMultiWindowRect
309  * @tc.desc: CheckMultiWindowRect
310  * @tc.type: FUNC
311  */
312 HWTEST_F(WindowSessionImplTest5, CheckMultiWindowRect, Function | SmallTest | Level2)
313 {
314     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
315     option->SetWindowName("CheckMultiWindowRect");
316     option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
317     sptr<WindowSessionImpl> windowSessionImpl = sptr<WindowSessionImpl>::MakeSptr(option);
318     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
319     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
320     uint32_t width = 100;
321     uint32_t height = 100;
322     windowSessionImpl->property_->SetPersistentId(1);
323     windowSessionImpl->hostSession_ = session;
324     windowSessionImpl->state_ = WindowState::STATE_SHOWN;
325     auto ret = windowSessionImpl->CheckMultiWindowRect(width, height);
326     EXPECT_EQ(WMError::WM_OK, ret);
327 
328     windowSessionImpl->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
329     windowSessionImpl->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
330     ret = windowSessionImpl->CheckMultiWindowRect(width, height);
331     EXPECT_EQ(WMError::WM_OK, ret);
332 }
333 
334 /**
335  * @tc.name: IsDeviceFeatureCapableFor
336  * @tc.desc: IsDeviceFeatureCapableFor
337  * @tc.type: FUNC
338  */
339 HWTEST_F(WindowSessionImplTest5, IsDeviceFeatureCapableFor, Function | SmallTest | Level2)
340 {
341     const std::string feature = "free_multi_window";
342     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
343     option->SetWindowName("IsDeviceFeatureCapableFor");
344     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
345     EXPECT_EQ(window->IsDeviceFeatureCapableFor(feature), false);
346     auto context = std::make_shared<MockAbilityContextImpl>();
347     window->context_ = context;
348     context->hapModuleInfo_ = std::make_shared<AppExecFwk::HapModuleInfo>();
349     EXPECT_EQ(window->IsDeviceFeatureCapableFor(feature), false);
350     std::string deviceType = system::GetParameter("const.product.devicetype", "");
351     context->hapModuleInfo_->requiredDeviceFeatures = {{deviceType, {}}};
352     EXPECT_EQ(window->IsDeviceFeatureCapableFor(feature), false);
353     context->hapModuleInfo_->requiredDeviceFeatures = {{deviceType, {feature}}};
354     EXPECT_EQ(window->IsDeviceFeatureCapableFor(feature), true);
355 }
356 
357 /**
358  * @tc.name: IsDeviceFeatureCapableForFreeMultiWindow
359  * @tc.desc: IsDeviceFeatureCapableForFreeMultiWindow
360  * @tc.type: FUNC
361  */
362 HWTEST_F(WindowSessionImplTest5, IsDeviceFeatureCapableForFreeMultiWindow, Function | SmallTest | Level2)
363 {
364     const std::string feature = "free_multi_window";
365     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
366     option->SetWindowName("IsDeviceFeatureCapableForFreeMultiWindow");
367     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
368     EXPECT_EQ(window->IsDeviceFeatureCapableForFreeMultiWindow(), false);
369     auto context = std::make_shared<MockAbilityContextImpl>();
370     window->context_ = context;
371     context->hapModuleInfo_ = std::make_shared<AppExecFwk::HapModuleInfo>();
372     EXPECT_EQ(window->IsDeviceFeatureCapableForFreeMultiWindow(), false);
373     std::string deviceType = system::GetParameter("const.product.devicetype", "");
374     context->hapModuleInfo_->requiredDeviceFeatures = {{deviceType, {feature}}};
375     EXPECT_EQ(window->IsDeviceFeatureCapableForFreeMultiWindow(),
376         system::GetParameter("const.window.device_feature_support_type", "0") == "1");
377 }
378 
379 /**
380  * @tc.name: NotifyRotationChange
381  * @tc.desc: NotifyRotationChange
382  * @tc.type: FUNC
383  */
384 HWTEST_F(WindowSessionImplTest5, NotifyRotationChange, Function | SmallTest | Level2)
385 {
386     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
387     option->SetWindowName("NotifyRotationChange");
388     option->SetWindowType(WindowType::APP_WINDOW_BASE);
389     sptr<WindowSessionImpl> windowSessionImpl = sptr<WindowSessionImpl>::MakeSptr(option);
390     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
391     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
392     windowSessionImpl->property_->SetPersistentId(1);
393     windowSessionImpl->hostSession_ = session;
394     windowSessionImpl->state_ = WindowState::STATE_SHOWN;
395     RotationChangeInfo info = { RotationChangeType::WINDOW_WILL_ROTATE, 0, 1, { 0, 0, 2720, 1270 } };
396     RotationChangeResult res = windowSessionImpl->NotifyRotationChange(info);
397     EXPECT_EQ(RectType::RELATIVE_TO_SCREEN, res.rectType_);
398 
399     sptr<IWindowRotationChangeListener> listener = sptr<IWindowRotationChangeListener>::MakeSptr();
400     std::vector<sptr<IWindowRotationChangeListener>> holder;
401     windowSessionImpl->windowRotationChangeListeners_[windowSessionImpl->property_->GetPersistentId()] = holder;
402     WMError ret = windowSessionImpl->RegisterWindowRotationChangeListener(listener);
403     EXPECT_EQ(WMError::WM_OK, ret);
404     res = windowSessionImpl->NotifyRotationChange(info);
405     EXPECT_EQ(RectType::RELATIVE_TO_SCREEN, res.rectType_);
406 
407     info.type_ = RotationChangeType::WINDOW_DID_ROTATE;
408     res = windowSessionImpl->NotifyRotationChange(info);
409     EXPECT_EQ(RectType::RELATIVE_TO_SCREEN, res.rectType_);
410 }
411 
412 /**
413  * @tc.name: UpdateRectForPageRotation
414  * @tc.desc: UpdateRectForPageRotation
415  * @tc.type: FUNC
416  */
417 HWTEST_F(WindowSessionImplTest5, UpdateRectForPageRotation, Function | SmallTest | Level2)
418 {
419     GTEST_LOG_(INFO) << "WindowSessionImplTest4: UpdateRectForPageRotation start";
420     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
421     option->SetDisplayId(0);
422     option->SetWindowName("UpdateRectForPageRotation");
423     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
424     Rect wmRect = { 0, 0, 0, 0 };
425     Rect preRect = { 0, 0, 0, 0 };
426     WindowSizeChangeReason wmReason = WindowSizeChangeReason::PAGE_ROTATION;
427     std::shared_ptr<RSTransaction> rsTransaction;
428     SceneAnimationConfig config { .rsTransaction_ = rsTransaction };
429     std::map<AvoidAreaType, AvoidArea> avoidAreas;
430     std::shared_ptr<AvoidArea> avoidArea = std::make_shared<AvoidArea>();
431     avoidArea->topRect_ = { 1, 0, 0, 0 };
432     avoidArea->leftRect_ = { 0, 1, 0, 0 };
433     avoidArea->rightRect_ = { 0, 0, 1, 0 };
434     avoidArea->bottomRect_ = { 0, 0, 0, 1 };
435     AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM;
436     avoidAreas[type] = *avoidArea;
437 
438     window->property_->SetWindowRect(preRect);
439     window->postTaskDone_ = false;
440     window->UpdateRectForPageRotation(wmRect, preRect, wmReason, config, avoidAreas);
441     EXPECT_EQ(window->postTaskDone_, false);
442 
443     WSRect rect = { 0, 0, 50, 50 };
444     SizeChangeReason reason = SizeChangeReason::PAGE_ROTATION;
445     auto res = window->UpdateRect(rect, reason, config, avoidAreas);
446     EXPECT_EQ(res, WSError::WS_OK);
447     GTEST_LOG_(INFO) << "WindowSessionImplTest4: UpdateRectForPageRotation end";
448 }
449 
450 /**
451  * @tc.name: RegisterPreferredOrientationChangeListener
452  * @tc.desc: RegisterPreferredOrientationChangeListener Test
453  * @tc.type: FUNC
454  */
455 HWTEST_F(WindowSessionImplTest5, RegisterPreferredOrientationChangeListener, Function | SmallTest | Level2)
456 {
457     GTEST_LOG_(INFO) << "WindowSessionImplTest4: RegisterPreferredOrientationChangeListener start";
458     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
459     option->SetWindowName("PreferredOrientationChange");
460     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
461     sptr<IPreferredOrientationChangeListener> listener = nullptr;
462     WMError res = window->RegisterPreferredOrientationChangeListener(listener);
463     EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
464 
465     listener = sptr<IPreferredOrientationChangeListener>::MakeSptr();
466     sptr<IPreferredOrientationChangeListener> holder;
467     window->preferredOrientationChangeListener_[window->property_->GetPersistentId()] = holder;
468     res = window->RegisterPreferredOrientationChangeListener(listener);
469     EXPECT_EQ(res, WMError::WM_OK);
470     holder = window->preferredOrientationChangeListener_[window->property_->GetPersistentId()];
471     EXPECT_EQ(holder, listener);
472 
473     // already registered
474     res = window->RegisterPreferredOrientationChangeListener(listener);
475     EXPECT_EQ(res, WMError::WM_OK);
476     GTEST_LOG_(INFO) << "WindowSessionImplTest4: RegisterPreferredOrientationChangeListener end";
477 }
478 
479 /**
480  * @tc.name: UnregisterPreferredOrientationChangeListener
481  * @tc.desc: UnregisterPreferredOrientationChangeListener Test
482  * @tc.type: FUNC
483  */
484 HWTEST_F(WindowSessionImplTest5, UnregisterPreferredOrientationChangeListener, Function | SmallTest | Level2)
485 {
486     GTEST_LOG_(INFO) << "WindowSessionImplTest4: UnregisterPreferredOrientationChangeListener start";
487     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
488     option->SetWindowName("PreferredOrientationChange");
489     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
490     sptr<IPreferredOrientationChangeListener> listener = nullptr;
491     WMError res = window->UnregisterPreferredOrientationChangeListener(listener);
492     EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
493 
494     listener = sptr<IPreferredOrientationChangeListener>::MakeSptr();
495     sptr<IPreferredOrientationChangeListener> holder;
496     window->preferredOrientationChangeListener_[window->property_->GetPersistentId()] = holder;
497     window->RegisterPreferredOrientationChangeListener(listener);
498 
499     res = window->UnregisterPreferredOrientationChangeListener(listener);
500     EXPECT_EQ(res, WMError::WM_OK);
501 
502     holder = window->preferredOrientationChangeListener_[window->property_->GetPersistentId()];
503     EXPECT_NE(holder, listener);
504     GTEST_LOG_(INFO) << "WindowSessionImplTest4: UnregisterPreferredOrientationChangeListener end";
505 }
506 
507 /**
508  * @tc.name: NotifyPreferredOrientationChange
509  * @tc.desc: NotifyPreferredOrientationChange
510  * @tc.type: FUNC
511  */
512 HWTEST_F(WindowSessionImplTest5, NotifyPreferredOrientationChange, Function | SmallTest | Level2)
513 {
514     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
515     option->SetWindowName("NotifyPreferredOrientationChange");
516     option->SetWindowType(WindowType::APP_WINDOW_BASE);
517     sptr<WindowSessionImpl> windowSessionImpl = sptr<WindowSessionImpl>::MakeSptr(option);
518     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
519     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
520     windowSessionImpl->property_->SetPersistentId(1);
521     windowSessionImpl->hostSession_ = session;
522     windowSessionImpl->state_ = WindowState::STATE_SHOWN;
523 
524     Orientation orientation = Orientation::USER_ROTATION_PORTRAIT;
525     windowSessionImpl->NotifyPreferredOrientationChange(orientation);
526 
527     sptr<IPreferredOrientationChangeListener> listener = sptr<IPreferredOrientationChangeListener>::MakeSptr();
528     sptr<IPreferredOrientationChangeListener> holder;
529     windowSessionImpl->preferredOrientationChangeListener_[windowSessionImpl->property_->GetPersistentId()] = holder;
530     WMError res = windowSessionImpl->RegisterPreferredOrientationChangeListener(listener);
531     EXPECT_EQ(WMError::WM_OK, res);
532 }
533 
534 /**
535  * @tc.name: RegisterOrientationChangeListener
536  * @tc.desc: RegisterOrientationChangeListener Test
537  * @tc.type: FUNC
538  */
539 HWTEST_F(WindowSessionImplTest5, RegisterOrientationChangeListener, Function | SmallTest | Level2)
540 {
541     GTEST_LOG_(INFO) << "WindowSessionImplTest4: RegisterOrientationChangeListener start";
542     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
543     option->SetWindowName("OrientationChange");
544     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
545     sptr<IWindowOrientationChangeListener> listener = nullptr;
546     WMError res = window->RegisterOrientationChangeListener(listener);
547     EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
548 
549     listener = sptr<IWindowOrientationChangeListener>::MakeSptr();
550     sptr<IWindowOrientationChangeListener> holder;
551     window->windowOrientationChangeListener_[window->property_->GetPersistentId()] = holder;
552     res = window->RegisterOrientationChangeListener(listener);
553     EXPECT_EQ(res, WMError::WM_OK);
554     holder = window->windowOrientationChangeListener_[window->property_->GetPersistentId()];
555     EXPECT_EQ(holder, listener);
556 
557     // already registered
558     res = window->RegisterOrientationChangeListener(listener);
559     EXPECT_EQ(res, WMError::WM_OK);
560     GTEST_LOG_(INFO) << "WindowSessionImplTest4: RegisterOrientationChangeListener end";
561 }
562 
563 /**
564  * @tc.name: UnregisterOrientationChangeListener
565  * @tc.desc: UnregisterOrientationChangeListener Test
566  * @tc.type: FUNC
567  */
568 HWTEST_F(WindowSessionImplTest5, UnregisterOrientationChangeListener, Function | SmallTest | Level2)
569 {
570     GTEST_LOG_(INFO) << "WindowSessionImplTest4: UnregisterOrientationChangeListener start";
571     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
572     option->SetWindowName("OrientationChange");
573     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
574     sptr<IWindowOrientationChangeListener> listener = nullptr;
575     WMError res = window->UnregisterOrientationChangeListener(listener);
576     EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
577 
578     listener = sptr<IWindowOrientationChangeListener>::MakeSptr();
579     sptr<IWindowOrientationChangeListener> holder;
580     window->windowOrientationChangeListener_[window->property_->GetPersistentId()] = holder;
581     window->RegisterOrientationChangeListener(listener);
582 
583     res = window->UnregisterOrientationChangeListener(listener);
584     EXPECT_EQ(res, WMError::WM_OK);
585 
586     holder = window->windowOrientationChangeListener_[window->property_->GetPersistentId()];
587     EXPECT_NE(holder, listener);
588     GTEST_LOG_(INFO) << "WindowSessionImplTest4: UnregisterOrientationChangeListener end";
589 }
590 
591 /**
592  * @tc.name: NotifyClientOrientationChange
593  * @tc.desc: NotifyClientOrientationChange
594  * @tc.type: FUNC
595  */
596 HWTEST_F(WindowSessionImplTest5, NotifyClientOrientationChange, Function | SmallTest | Level2)
597 {
598     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
599     option->SetWindowName("NotifyClientOrientationChange");
600     option->SetWindowType(WindowType::APP_WINDOW_BASE);
601     sptr<WindowSessionImpl> windowSessionImpl = sptr<WindowSessionImpl>::MakeSptr(option);
602     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
603     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
604     windowSessionImpl->property_->SetPersistentId(1);
605     windowSessionImpl->hostSession_ = session;
606     windowSessionImpl->state_ = WindowState::STATE_SHOWN;
607 
608     windowSessionImpl->NotifyClientOrientationChange();
609 
610     sptr<IWindowOrientationChangeListener> listener = sptr<IWindowOrientationChangeListener>::MakeSptr();
611     sptr<IWindowOrientationChangeListener> holder;
612     windowSessionImpl->windowOrientationChangeListener_[windowSessionImpl->property_->GetPersistentId()] = holder;
613     WMError res = windowSessionImpl->RegisterOrientationChangeListener(listener);
614     EXPECT_EQ(WMError::WM_OK, res);
615 }
616 
617 /**
618  * @tc.name: GetCurrentWindowOrientation
619  * @tc.desc: GetCurrentWindowOrientation
620  * @tc.type: FUNC
621  */
622 HWTEST_F(WindowSessionImplTest5, GetCurrentWindowOrientation, Function | SmallTest | Level2)
623 {
624     GTEST_LOG_(INFO) << "WindowSessionImplTest5: GetCurrentWindowOrientation start";
625     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
626     option->SetDisplayId(0);
627     option->SetWindowName("GetCurrentWindowOrientation");
628     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
629 
630     window->UpdateCurrentWindowOrientation(DisplayOrientation::PORTRAIT);
631     EXPECT_EQ(window->GetCurrentWindowOrientation(), DisplayOrientation::PORTRAIT);
632     window->UpdateCurrentWindowOrientation(DisplayOrientation::UNKNOWN);
633     EXPECT_EQ(window->GetCurrentWindowOrientation(), DisplayOrientation::UNKNOWN);
634     window->UpdateCurrentWindowOrientation(DisplayOrientation::LANDSCAPE);
635     EXPECT_EQ(window->GetCurrentWindowOrientation(), DisplayOrientation::LANDSCAPE);
636     window->UpdateCurrentWindowOrientation(DisplayOrientation::PORTRAIT_INVERTED);
637     EXPECT_EQ(window->GetCurrentWindowOrientation(), DisplayOrientation::PORTRAIT_INVERTED);
638     window->UpdateCurrentWindowOrientation(DisplayOrientation::LANDSCAPE_INVERTED);
639     EXPECT_EQ(window->GetCurrentWindowOrientation(), DisplayOrientation::LANDSCAPE_INVERTED);
640     GTEST_LOG_(INFO) << "WindowSessionImplTest5: GetCurrentWindowOrientation end";
641 }
642 
643 /**
644  * @tc.name: GetRequestedOrientation
645  * @tc.desc: GetRequestedOrientation
646  * @tc.type: FUNC
647  */
648 HWTEST_F(WindowSessionImplTest5, GetRequestedOrientation, Function | SmallTest | Level2)
649 {
650     GTEST_LOG_(INFO) << "WindowSessionImplTest5: GetRequestedOrientation start";
651     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
652     option->SetDisplayId(0);
653     option->SetWindowName("GetRequestedOrientation");
654     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
655     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
656     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
657     window->hostSession_ = session;
658     window->property_->SetPersistentId(1);
659     window->state_ = WindowState::STATE_CREATED;
660 
661     window->SetUserRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT);
662     EXPECT_EQ(window->GetRequestedOrientation(), Orientation::USER_ROTATION_PORTRAIT);
663     window->SetUserRequestedOrientation(Orientation::VERTICAL);
664     EXPECT_EQ(window->GetRequestedOrientation(), Orientation::VERTICAL);
665     window->SetUserRequestedOrientation(Orientation::HORIZONTAL);
666     EXPECT_EQ(window->GetRequestedOrientation(), Orientation::HORIZONTAL);
667     window->SetUserRequestedOrientation(Orientation::SENSOR);
668     EXPECT_EQ(window->GetRequestedOrientation(), Orientation::SENSOR);
669     window->SetUserRequestedOrientation(Orientation::FOLLOW_DESKTOP);
670     EXPECT_EQ(window->GetRequestedOrientation(), Orientation::FOLLOW_DESKTOP);
671     GTEST_LOG_(INFO) << "WindowSessionImplTest5: GetRequestedOrientation end";
672 }
673 
674 /**
675  * @tc.name: isNeededForciblySetOrientation
676  * @tc.desc: isNeededForciblySetOrientation
677  * @tc.type: FUNC
678  */
679 HWTEST_F(WindowSessionImplTest5, isNeededForciblySetOrientation, Function | SmallTest | Level2)
680 {
681     GTEST_LOG_(INFO) << "WindowSessionImplTest5: isNeededForciblySetOrientation start";
682     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
683     option->SetDisplayId(0);
684     option->SetWindowName("isNeededForciblySetOrientation");
685     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
686     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
687     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
688     window->hostSession_ = session;
689     window->property_->SetPersistentId(1);
690     window->state_ = WindowState::STATE_CREATED;
691 
692     Orientation ori = Orientation::VERTICAL;
693     window->SetRequestedOrientation(ori);
694     EXPECT_EQ(window->isNeededForciblySetOrientation(Orientation::USER_ROTATION_PORTRAIT), true);
695     EXPECT_EQ(window->isNeededForciblySetOrientation(Orientation::VERTICAL), false);
696     EXPECT_EQ(window->isNeededForciblySetOrientation(Orientation::HORIZONTAL), true);
697     EXPECT_EQ(window->isNeededForciblySetOrientation(Orientation::SENSOR), true);
698     EXPECT_EQ(window->isNeededForciblySetOrientation(Orientation::FOLLOW_DESKTOP), true);
699     EXPECT_EQ(window->isNeededForciblySetOrientation(Orientation::INVALID), false);
700     window->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT, false);
701     EXPECT_EQ(window->isNeededForciblySetOrientation(Orientation::INVALID), true);
702     window->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT);
703     EXPECT_EQ(window->isNeededForciblySetOrientation(Orientation::INVALID), false);
704     window->SetRequestedOrientation(Orientation::HORIZONTAL, false);
705     EXPECT_EQ(window->isNeededForciblySetOrientation(Orientation::INVALID), true);
706     GTEST_LOG_(INFO) << "WindowSessionImplTest5: isNeededForciblySetOrientation end";
707 }
708 
709 /**
710  * @tc.name: ConvertInvalidOrientation()
711  * @tc.desc: ConvertInvalidOrientation()
712  * @tc.type: FUNC
713  */
714 HWTEST_F(WindowSessionImplTest5, ConvertInvalidOrientation, Function | SmallTest | Level2)
715 {
716     GTEST_LOG_(INFO) << "WindowSessionImplTest5: ConvertInvalidOrientation start";
717     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
718     option->SetDisplayId(0);
719     option->SetWindowName("ConvertInvalidOrientation");
720     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
721     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
722     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
723     window->hostSession_ = session;
724     window->property_->SetPersistentId(1);
725     window->state_ = WindowState::STATE_CREATED;
726 
727     Orientation ori = Orientation::USER_ROTATION_PORTRAIT;
728     window->SetRequestedOrientation(ori);
729     window->SetRequestedOrientation(Orientation::INVALID, false);
730     EXPECT_EQ(window->ConvertInvalidOrientation(), Orientation::USER_PAGE_ROTATION_PORTRAIT);
731     GTEST_LOG_(INFO) << "WindowSessionImplTest5: ConvertInvalidOrientation end";
732 }
733 
734 /**
735  * @tc.name: IsUserPageOrientation()
736  * @tc.desc: IsUserPageOrientation()
737  * @tc.type: FUNC
738  */
739 HWTEST_F(WindowSessionImplTest5, IsUserPageOrientation, Function | SmallTest | Level2)
740 {
741     GTEST_LOG_(INFO) << "WindowSessionImplTest5: IsUserPageOrientation start";
742     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
743     option->SetDisplayId(0);
744     option->SetWindowName("IsUserPageOrientation");
745     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
746     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
747     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
748     window->hostSession_ = session;
749     window->property_->SetPersistentId(1);
750     window->state_ = WindowState::STATE_CREATED;
751 
752     Orientation ori = Orientation::USER_ROTATION_PORTRAIT;
753     window->IsUserPageOrientation(ori);
754     EXPECT_EQ(window->IsUserPageOrientation(Orientation::USER_ROTATION_PORTRAIT), false);
755     EXPECT_EQ(window->IsUserPageOrientation(Orientation::USER_PAGE_ROTATION_PORTRAIT), true);
756     EXPECT_EQ(window->IsUserPageOrientation(Orientation::USER_PAGE_ROTATION_LANDSCAPE), true);
757     EXPECT_EQ(window->IsUserPageOrientation(Orientation::USER_PAGE_ROTATION_PORTRAIT_INVERTED), true);
758     EXPECT_EQ(window->IsUserPageOrientation(Orientation::USER_PAGE_ROTATION_LANDSCAPE_INVERTED), true);
759     GTEST_LOG_(INFO) << "WindowSessionImplTest5: IsUserPageOrientation end";
760 }
761 
762 /**
763  * @tc.name: SetFollowScreenChange
764  * @tc.desc: SetFollowScreenChange
765  * @tc.type: FUNC
766  */
767 HWTEST_F(WindowSessionImplTest5, SetFollowScreenChange, Function | SmallTest | Level2)
768 {
769     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
770     option->SetWindowName("SetFollowScreenChange");
771 
772     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
773     window->property_->SetPersistentId(0);
774     WMError ret = window->SetFollowScreenChange(true);
775     EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret);
776 
777     window->property_->SetPersistentId(1);
778     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
779     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
780     ASSERT_NE(nullptr, session);
781     window->hostSession_ = session;
782     window->state_ = WindowState::STATE_CREATED;
783     window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_END);
784     ret = window->SetFollowScreenChange(true);
785     EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE, ret);
786 
787     window->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
788     ret = window->SetFollowScreenChange(true);
789     EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE, ret);
790 
791     window->property_->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
792     ret = window->SetFollowScreenChange(true);
793     EXPECT_EQ(WMError::WM_OK, ret);
794 }
795 
796 /**
797  * @tc.name: GetScaleWindow
798  * @tc.desc: GetScaleWindow
799  * @tc.type: FUNC
800  */
801 HWTEST_F(WindowSessionImplTest5, GetScaleWindow, Function | SmallTest | Level2)
802 {
803     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
804     option->SetWindowName("GetScaleWindow_window1");
805     sptr<WindowSessionImpl> mainWindow = sptr<WindowSessionImpl>::MakeSptr(option);
806     int32_t id = 1;
807     mainWindow->property_->SetPersistentId(id);
808     mainWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
809     mainWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
810     WindowSessionImpl::windowSessionMap_.clear();
811     WindowSessionImpl::windowSessionMap_.insert(std::make_pair(mainWindow->GetWindowName(),
812         std::pair<uint64_t, sptr<WindowSessionImpl>>(mainWindow->GetWindowId(), mainWindow)));
813     auto res = mainWindow->GetScaleWindow(id);
814     EXPECT_NE(res, nullptr);
815 
816     sptr<WindowOption> option2 = sptr<WindowOption>::MakeSptr();
817     option2->SetWindowName("GetScaleWindow_extensionWindow");
818     sptr<WindowSessionImpl> extensionWindow = sptr<WindowSessionImpl>::MakeSptr(option2);
819     WindowSessionImpl::GetWindowExtensionSessionSet().clear();
820     WindowSessionImpl::GetWindowExtensionSessionSet().insert(extensionWindow);
821     extensionWindow->property_->SetPersistentId(2);
822     extensionWindow->isUIExtensionAbilityProcess_ = true;
823     int32_t testId = 3;
824     res = mainWindow->GetScaleWindow(testId);
825     EXPECT_EQ(res, nullptr);
826     extensionWindow->property_->SetParentPersistentId(testId);
827     extensionWindow->property_->SetParentId(testId);
828     res = mainWindow->GetScaleWindow(testId);
829     EXPECT_NE(res, nullptr);
830     mainWindow->isFocused_ = true;
831     extensionWindow->isUIExtensionAbilityProcess_ = false;
832     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
833     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
834     mainWindow->hostSession_ = session;
835     res = mainWindow->GetScaleWindow(testId);
836     EXPECT_NE(res, nullptr);
837     mainWindow->isFocused_ = false;
838     res = mainWindow->GetScaleWindow(testId);
839     EXPECT_EQ(res, nullptr);
840     WindowSessionImpl::windowSessionMap_.clear();
841     WindowSessionImpl::GetWindowExtensionSessionSet().clear();
842 }
843 
844 /**
845  * @tc.name: GetWindowScaleCoordinate01
846  * @tc.desc: GetWindowScaleCoordinate
847  * @tc.type: FUNC
848  */
849 HWTEST_F(WindowSessionImplTest5, GetWindowScaleCoordinate01, Function | SmallTest | Level2)
850 {
851     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
852     option->SetWindowName("GetWindowScaleCoordinate01_mainWindow");
853     sptr<WindowSessionImpl> mainWindow = sptr<WindowSessionImpl>::MakeSptr(option);
854     int32_t id = 1;
855     mainWindow->property_->SetPersistentId(id);
856     mainWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
857     CursorInfo cursorInfo;
858     auto res = mainWindow->GetWindowScaleCoordinate(id, cursorInfo);
859     EXPECT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
860     WindowSessionImpl::windowSessionMap_.clear();
861     WindowSessionImpl::windowSessionMap_.insert(std::make_pair(mainWindow->GetWindowName(),
862         std::pair<uint64_t, sptr<WindowSessionImpl>>(mainWindow->GetWindowId(), mainWindow)));
863     res = mainWindow->GetWindowScaleCoordinate(id, cursorInfo);
864     EXPECT_EQ(res, WMError::WM_OK);
865 
866     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
867     compatibleModeProperty->SetIsAdaptToSimulationScale(true);
868     mainWindow->property_->SetCompatibleModeProperty(compatibleModeProperty);
869     res = mainWindow->GetWindowScaleCoordinate(id, cursorInfo);
870     EXPECT_EQ(res, WMError::WM_OK);
871 
872     sptr<WindowOption> subWindowOption = sptr<WindowOption>::MakeSptr();
873     subWindowOption->SetWindowName("GetWindowScaleCoordinate01_subWindow");
874     sptr<WindowSessionImpl> subWindow = sptr<WindowSessionImpl>::MakeSptr(subWindowOption);
875     subWindow->property_->SetPersistentId(2);
876     subWindow->property_->SetParentPersistentId(id);
877     subWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
878     WindowSessionImpl::windowSessionMap_.insert(std::make_pair(subWindow->GetWindowName(),
879         std::pair<uint64_t, sptr<WindowSessionImpl>>(subWindow->GetWindowId(), subWindow)));
880     res = subWindow->GetWindowScaleCoordinate(subWindow->GetPersistentId(), cursorInfo);
881     EXPECT_EQ(res, WMError::WM_OK);
882     mainWindow->context_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
883     subWindow->context_ = mainWindow->context_;
884     subWindow->property_->SetIsUIExtensionAbilityProcess(true);
885     res = mainWindow->GetWindowScaleCoordinate(id, cursorInfo);
886     EXPECT_EQ(res, WMError::WM_OK);
887     subWindow->property_->SetIsUIExtensionAbilityProcess(false);
888     res = mainWindow->GetWindowScaleCoordinate(id, cursorInfo);
889     EXPECT_EQ(res, WMError::WM_OK);
890     mainWindow->compatScaleX_ = 0.5;
891     res = mainWindow->GetWindowScaleCoordinate(id, cursorInfo);
892     EXPECT_EQ(res, WMError::WM_OK);
893     WindowSessionImpl::windowSessionMap_.clear();
894 }
895 
896 /**
897  * @tc.name: GetWindowScaleCoordinate02
898  * @tc.desc: GetWindowScaleCoordinate
899  * @tc.type: FUNC
900  */
901 HWTEST_F(WindowSessionImplTest5, GetWindowScaleCoordinate02, Function | SmallTest | Level2)
902 {
903     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
904     option->SetWindowName("GetWindowScaleCoordinate02_extensionWindow");
905     sptr<WindowSessionImpl> extensionWindow = sptr<WindowSessionImpl>::MakeSptr(option);
906     WindowSessionImpl::GetWindowExtensionSessionSet().clear();
907     WindowSessionImpl::GetWindowExtensionSessionSet().insert(extensionWindow);
908     extensionWindow->property_->SetPersistentId(2);
909     extensionWindow->isUIExtensionAbilityProcess_ = true;
910     extensionWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
911     int32_t id = 1;
912     CursorInfo cursorInfo;
913     auto res = extensionWindow->GetWindowScaleCoordinate(id, cursorInfo);
914     EXPECT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
915     extensionWindow->property_->SetParentPersistentId(id);
916     extensionWindow->property_->SetParentId(id);
917     res = extensionWindow->GetWindowScaleCoordinate(id, cursorInfo);
918     EXPECT_EQ(res, WMError::WM_OK);
919     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
920     compatibleModeProperty->SetIsAdaptToSimulationScale(true);
921     extensionWindow->property_->SetCompatibleModeProperty(compatibleModeProperty);
922     res = extensionWindow->GetWindowScaleCoordinate(id, cursorInfo);
923     EXPECT_EQ(res, WMError::WM_OK);
924     extensionWindow->compatScaleX_ = 0.5;
925     res = extensionWindow->GetWindowScaleCoordinate(id, cursorInfo);
926     EXPECT_EQ(res, WMError::WM_OK);
927     WindowSessionImpl::GetWindowExtensionSessionSet().clear();
928 }
929 
930 /**
931  * @tc.name: SetCurrentTransform
932  * @tc.desc: SetCurrentTransform
933  * @tc.type: FUNC
934  */
935 HWTEST_F(WindowSessionImplTest5, SetCurrentTransform, TestSize.Level1)
936 {
937     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
938     option->SetWindowName("SetCurrentTransform");
939     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
940     window->property_->SetPersistentId(1);
941     Transform transform;
942     transform.scaleX_ = 0.5f;
943     transform.scaleY_ = 0.6f;
944     window->SetCurrentTransform(transform);
945     EXPECT_NEAR(window->currentTransform_.scaleX_, transform.scaleX_, 0.00001f);
946     EXPECT_NEAR(window->currentTransform_.scaleY_, transform.scaleY_, 0.00001f);
947     auto res = window->GetCurrentTransform();
948     EXPECT_TRUE(res == transform);
949 }
950 
951 /**
952  * @tc.name: UpdateCompatScaleInfo
953  * @tc.desc: UpdateCompatScaleInfo
954  * @tc.type: FUNC
955  */
956 HWTEST_F(WindowSessionImplTest5, UpdateCompatScaleInfo, TestSize.Level1)
957 {
958     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
959     option->SetWindowName("UpdateCompatScaleInfo");
960     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
961     window->property_->SetPersistentId(1);
962     window->context_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
963     Transform transform;
964     transform.scaleX_ = 0.5f;
965     transform.scaleY_ = 0.6f;
966     EXPECT_EQ(window->UpdateCompatScaleInfo(transform), WMError::WM_DO_NOTHING);
967     EXPECT_NEAR(window->compatScaleX_, 1.0f, 0.00001f);
968     EXPECT_NEAR(window->compatScaleY_, 1.0f, 0.00001f);
969     window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
970     EXPECT_EQ(window->UpdateCompatScaleInfo(transform), WMError::WM_DO_NOTHING);
971     EXPECT_NEAR(window->compatScaleX_, 1.0f, 0.00001f);
972     EXPECT_NEAR(window->compatScaleY_, 1.0f, 0.00001f);
973     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
974     EXPECT_NEAR(window->compatScaleX_, 1.0f, 0.00001f);
975     EXPECT_NEAR(window->compatScaleY_, 1.0f, 0.00001f);
976     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
977     compatibleModeProperty->SetIsAdaptToSimulationScale(true);
978     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
979     EXPECT_EQ(window->UpdateCompatScaleInfo(transform), WMError::WM_OK);
980     EXPECT_NEAR(window->compatScaleX_, transform.scaleX_, 0.00001f);
981     EXPECT_NEAR(window->compatScaleY_, transform.scaleY_, 0.00001f);
982     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
983     EXPECT_EQ(window->UpdateCompatScaleInfo(transform), WMError::WM_OK);
984 }
985 
986 /**
987  * @tc.name: SetCompatInfoInExtensionConfig
988  * @tc.desc: SetCompatInfoInExtensionConfig
989  * @tc.type: FUNC
990  */
991 HWTEST_F(WindowSessionImplTest5, SetCompatInfoInExtensionConfig, TestSize.Level1)
992 {
993     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
994     option->SetWindowName("SetCompatInfoInExtensionConfig");
995     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
996     AAFwk::WantParams want;
997     window->SetCompatInfoInExtensionConfig(want);
998     bool isAdaptToSimulationScale =
999         static_cast<bool>(want.GetIntParam(Extension::COMPAT_IS_SIMULATION_SCALE_FIELD, 0));
1000     EXPECT_FALSE(isAdaptToSimulationScale);
1001     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
1002     compatibleModeProperty->SetIsAdaptToSimulationScale(true);
1003     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
1004     window->SetCompatInfoInExtensionConfig(want);
1005     isAdaptToSimulationScale =
1006         static_cast<bool>(want.GetIntParam(Extension::COMPAT_IS_SIMULATION_SCALE_FIELD, 0));
1007     EXPECT_TRUE(isAdaptToSimulationScale);
1008 }
1009 
1010 /**
1011  * @tc.name: IsAdaptToProportionalScale
1012  * @tc.desc: IsAdaptToProportionalScale
1013  * @tc.type: FUNC
1014  */
1015 HWTEST_F(WindowSessionImplTest5, IsAdaptToProportionalScale, TestSize.Level1)
1016 {
1017     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1018     option->SetWindowName("IsAdaptToProportionalScale");
1019     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1020     EXPECT_FALSE(window->IsAdaptToProportionalScale());
1021     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
1022     compatibleModeProperty->SetIsAdaptToProportionalScale(true);
1023     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
1024     EXPECT_TRUE(window->IsAdaptToProportionalScale());
1025 }
1026 
1027 /**
1028  * @tc.name: IsInCompatScaleMode
1029  * @tc.desc: IsInCompatScaleMode
1030  * @tc.type: FUNC
1031  */
1032 HWTEST_F(WindowSessionImplTest5, IsInCompatScaleMode, TestSize.Level1)
1033 {
1034     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1035     option->SetWindowName("IsInCompatScaleMode");
1036     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1037     EXPECT_FALSE(window->IsInCompatScaleMode());
1038     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
1039     compatibleModeProperty->SetIsAdaptToProportionalScale(true);
1040     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
1041     EXPECT_TRUE(window->IsInCompatScaleMode());
1042     compatibleModeProperty->SetIsAdaptToProportionalScale(false);
1043     compatibleModeProperty->SetIsAdaptToSimulationScale(true);
1044     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
1045     EXPECT_TRUE(window->IsInCompatScaleMode());
1046 }
1047 
1048 /**
1049  * @tc.name: IsInCompatScaleStatus
1050  * @tc.desc: IsInCompatScaleStatus
1051  * @tc.type: FUNC
1052  */
1053 HWTEST_F(WindowSessionImplTest5, IsInCompatScaleStatus, TestSize.Level1)
1054 {
1055     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1056     option->SetWindowName("IsInCompatScaleStatus");
1057     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1058     EXPECT_FALSE(window->IsInCompatScaleStatus());
1059     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
1060     compatibleModeProperty->SetIsAdaptToProportionalScale(true);
1061     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
1062     EXPECT_FALSE(window->IsInCompatScaleStatus());
1063     window->compatScaleX_ = 0.5f;
1064     EXPECT_TRUE(window->IsInCompatScaleStatus());
1065     window->compatScaleX_ = 1.0f;
1066     window->compatScaleX_ = 1.5f;
1067     EXPECT_TRUE(window->IsInCompatScaleStatus());
1068 }
1069 
1070 /**
1071  * @tc.name: GetPropertyByContext
1072  * @tc.desc: GetPropertyByContext
1073  * @tc.type: FUNC
1074  */
1075 HWTEST_F(WindowSessionImplTest5, GetPropertyByContext, Function | SmallTest | Level2)
1076 {
1077     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1078     option->SetWindowName("GetPropertyByContext");
1079     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1080     window->context_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
1081     int32_t persistentId = 663;
1082     window->property_->SetPersistentId(persistentId);
1083     window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1084     auto property = window->GetPropertyByContext();
1085     EXPECT_EQ(property->GetPersistentId(), persistentId);
1086 
1087     sptr<WindowOption> option1 = sptr<WindowOption>::MakeSptr();
1088     option1->SetWindowName("GetPropertyByContext_mainWindow");
1089     sptr<WindowSessionImpl> mainWindow = sptr<WindowSessionImpl>::MakeSptr(option1);
1090     int32_t mainPersistentId = 666;
1091     mainWindow->property_->SetPersistentId(mainPersistentId);
1092     window->windowSessionMap_.insert({mainWindow->GetWindowName(),
1093         std::pair<int32_t, sptr<WindowSessionImpl>>(mainPersistentId, mainWindow) });
1094     window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1095     mainWindow->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1096     property = window->GetPropertyByContext();
1097     EXPECT_EQ(property->GetPersistentId(), persistentId);
1098     mainWindow->context_ = window->context_;
1099     property = window->GetPropertyByContext();
1100     EXPECT_EQ(property->GetPersistentId(), mainPersistentId);
1101 
1102     window->property_->SetIsUIExtensionAbilityProcess(true);
1103     mainWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
1104     property = window->GetPropertyByContext();
1105     EXPECT_EQ(property->GetPersistentId(), persistentId);
1106     window->GetWindowExtensionSessionSet().insert(mainWindow);
1107     property = window->GetPropertyByContext();
1108     EXPECT_EQ(property->GetPersistentId(), mainPersistentId);
1109 }
1110 
1111 /**
1112  * @tc.name: IsAdaptToSimulationScale
1113  * @tc.desc: IsAdaptToSimulationScale
1114  * @tc.type: FUNC
1115  */
1116 HWTEST_F(WindowSessionImplTest5, IsAdaptToSimulationScale, Function | SmallTest | Level2)
1117 {
1118     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1119     option->SetWindowName("IsAdaptToSimulationScale");
1120     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1121     window->context_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
1122     window->property_->SetPersistentId(704);
1123     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
1124     compatibleModeProperty->SetIsAdaptToSimulationScale(true);
1125     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
1126     EXPECT_EQ(window->IsAdaptToSimulationScale(), true);
1127 
1128     sptr<WindowOption> option1 = sptr<WindowOption>::MakeSptr();
1129     option1->SetWindowName("IsAdaptToSimulationScale_mainWindow");
1130     sptr<WindowSessionImpl> mainWindow = sptr<WindowSessionImpl>::MakeSptr(option1);
1131     int32_t mainPersistentId = 666;
1132     mainWindow->property_->SetPersistentId(mainPersistentId);
1133     window->windowSessionMap_.insert({mainWindow->GetWindowName(),
1134         std::pair<int32_t, sptr<WindowSessionImpl>>(mainPersistentId, mainWindow) });
1135     window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1136     mainWindow->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1137     mainWindow->context_ = window->context_;
1138     EXPECT_EQ(window->IsAdaptToSimulationScale(), false);
1139 }
1140 
1141 /**
1142  * @tc.name: IsAdaptToSubWindow
1143  * @tc.desc: IsAdaptToSubWindow
1144  * @tc.type: FUNC
1145  */
1146 HWTEST_F(WindowSessionImplTest5, IsAdaptToSubWindow, Function | SmallTest | Level2)
1147 {
1148     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1149     option->SetWindowName("IsAdaptToSubWindow");
1150     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1151     window->context_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
1152     window->property_->SetPersistentId(772);
1153     EXPECT_EQ(window->IsAdaptToSubWindow(), false);
1154     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
1155     compatibleModeProperty->SetIsAdaptToSubWindow(true);
1156     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
1157     EXPECT_EQ(window->IsAdaptToSubWindow(), true);
1158 }
1159 
1160 /**
1161  * @tc.name: SetIntentParam
1162  * @tc.desc: SetIntentParam
1163  * @tc.type: FUNC
1164  */
1165 HWTEST_F(WindowSessionImplTest5, SetIntentParam, Function | SmallTest | Level2)
1166 {
1167     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1168     option->SetWindowName("SetIntentParam");
1169     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1170 
__anon2df214fb0202()1171     auto testCallback = [](){};
1172     bool isColdStart = true;
1173     std::string intentParam = "testIntent";
1174     window->SetIntentParam(intentParam, testCallback, isColdStart);
1175     EXPECT_EQ(window->isColdStart_, true);
1176     EXPECT_EQ(window->intentParam_, intentParam);
1177 }
1178 
1179 /**
1180  * @tc.name: SetNavDestinationInfo
1181  * @tc.desc: SetNavDestinationInfo
1182  * @tc.type: FUNC
1183  */
1184 HWTEST_F(WindowSessionImplTest5, SetNavDestinationInfo, Function | SmallTest | Level2)
1185 {
1186     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1187     option->SetWindowName("SetNavDestinationInfo");
1188     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1189 
1190     std::string navInfo = "testInfo";
1191     window->SetNavDestinationInfo(navInfo);
1192     EXPECT_EQ(window->navDestinationInfo_, navInfo);
1193 }
1194 
1195 /**
1196  * @tc.name: OnNewWant01
1197  * @tc.desc: OnNewWant01
1198  * @tc.type: FUNC
1199  */
1200 HWTEST_F(WindowSessionImplTest5, OnNewWant01, Function | SmallTest | Level2)
1201 {
1202     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1203     option->SetWindowName("OnNewWant01");
1204     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1205 
1206     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1207     std::string navInfo = "testInfo";
1208     AAFwk::Want want;
1209     want.SetParam(AAFwk::Want::ATOMIC_SERVICE_SHARE_ROUTER, navInfo);
1210     window->OnNewWant(want);
1211 
1212     EXPECT_EQ(window->navDestinationInfo_, "");
1213 }
1214 
1215 /**
1216  * @tc.name: OnNewWant02
1217  * @tc.desc: OnNewWant when uiContent is nullptr.
1218  * @tc.type: FUNC
1219  */
1220 HWTEST_F(WindowSessionImplTest5, OnNewWant02, Function | SmallTest | Level2)
1221 {
1222     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1223     option->SetWindowName("OnNewWant02");
1224     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1225 
1226     std::string navInfo = "testInfo";
1227     AAFwk::Want want;
1228     want.SetParam(AAFwk::Want::ATOMIC_SERVICE_SHARE_ROUTER, navInfo);
1229     window->uiContent_ = nullptr;
1230     window->OnNewWant(want);
1231 
1232     EXPECT_EQ(window->navDestinationInfo_, "testInfo");
1233 }
1234 
1235 /**
1236  * @tc.name: NapiSetUIContent01
1237  * @tc.desc: NapiSetUIContent01
1238  * @tc.type: FUNC
1239  */
1240 HWTEST_F(WindowSessionImplTest5, NapiSetUIContent01, Function | SmallTest | Level2)
1241 {
1242     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1243     option->SetWindowName("NapiSetUIContent01");
1244     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1245 
1246     SessionInfo sessionInfo = {"NapiSetUIContent01", "NapiSetUIContent01", "NapiSetUIContent01"};
1247     auto hostSession = sptr<SessionMocker>::MakeSptr(sessionInfo);
1248     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1249     property->SetPersistentId(1);
1250     window->property_ = property;
1251     window->hostSession_ = hostSession;
1252     sptr<IRemoteObject> token;
1253     window->state_ = WindowState::STATE_SHOWN;
1254 
1255     std::string navInfo = "testInfo";
1256     window->SetNavDestinationInfo(navInfo);
1257 
1258     window->NapiSetUIContent("info", (napi_env)nullptr, nullptr, BackupAndRestoreType::NONE, nullptr, nullptr);
1259     EXPECT_EQ(window->navDestinationInfo_, "");
1260 }
1261 
1262 /**
1263  * @tc.name: HideTitleButton01
1264  * @tc.desc: HideTitleButton01
1265  * @tc.type: FUNC
1266  */
1267 HWTEST_F(WindowSessionImplTest5, HideTitleButton01, Function | SmallTest | Level2) {
1268     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1269     option->SetWindowName("HideTitleButton");
1270     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1271 
1272     bool hideSplitButton = false;
1273     bool hideMaximizeButton = false;
1274     bool hideMinimizeButton = false;
1275     bool hideCloseButton = false;
1276     window->HideTitleButton(hideSplitButton, hideMaximizeButton, hideMinimizeButton, hideCloseButton);
1277 
1278     EXPECT_FALSE(hideSplitButton);
1279     EXPECT_FALSE(hideMaximizeButton);
1280     EXPECT_FALSE(hideMinimizeButton);
1281     EXPECT_FALSE(hideCloseButton);
1282 }
1283 
1284 /**
1285  * @tc.name: HideTitleButton02
1286  * @tc.desc: HideTitleButton02
1287  * @tc.type: FUNC
1288  */
1289 HWTEST_F(WindowSessionImplTest5, HideTitleButton02, Function | SmallTest | Level2) {
1290     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1291     option->SetWindowName("HideTitleButton");
1292     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1293 
1294     bool hideSplitButton = false;
1295     bool hideMaximizeButton = false;
1296     bool hideMinimizeButton = false;
1297     bool hideCloseButton = false;
1298     window->uiContent_ = nullptr;
1299     window->HideTitleButton(hideSplitButton, hideMaximizeButton, hideMinimizeButton, hideCloseButton);
1300 
1301     EXPECT_FALSE(hideSplitButton);
1302     EXPECT_FALSE(hideMaximizeButton);
1303     EXPECT_FALSE(hideMinimizeButton);
1304     EXPECT_FALSE(hideCloseButton);
1305 }
1306 
1307 /**
1308  * @tc.name: HideTitleButton03
1309  * @tc.desc: HideTitleButton03
1310  * @tc.type: FUNC
1311  */
1312 HWTEST_F(WindowSessionImplTest5, HideTitleButton03, Function | SmallTest | Level2) {
1313     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1314     option->SetWindowName("HideTitleButton");
1315     option->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1316     option->SetSubWindowMaximizeSupported(false);
1317     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1318 
1319     bool hideSplitButton = false;
1320     bool hideMaximizeButton = false;
1321     bool hideMinimizeButton = false;
1322     bool hideCloseButton = false;
1323     window->property_->SetDecorEnable(true);
1324     window->windowSystemConfig_.isSystemDecorEnable_ = true;
1325     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1326     window->HideTitleButton(hideSplitButton, hideMaximizeButton, hideMinimizeButton, hideCloseButton);
1327 
1328     EXPECT_FALSE(hideSplitButton);
1329     EXPECT_FALSE(hideMaximizeButton);
1330     EXPECT_FALSE(hideMinimizeButton);
1331     EXPECT_FALSE(hideCloseButton);
1332 }
1333 
1334 /**
1335  * @tc.name: SetUIContentByName
1336  * @tc.desc: SetUIContentByName, load content by name
1337  * @tc.type: FUNC
1338  */
1339 HWTEST_F(WindowSessionImplTest5, SetUIContentByName, Function | SmallTest | Level2)
1340 {
1341     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1342     option->SetWindowName("SetUIContentByName");
1343     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1344 
1345     SessionInfo sessionInfo = {"SetUIContentByName", "SetUIContentByName", "SetUIContentByName"};
1346     auto hostSession = sptr<SessionMocker>::MakeSptr(sessionInfo);
1347     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1348     property->SetPersistentId(1);
1349     window->property_ = property;
1350     window->hostSession_ = hostSession;
1351     sptr<IRemoteObject> token;
1352     window->state_ = WindowState::STATE_SHOWN;
1353 
__anon2df214fb0302()1354     auto testCallback = [](){};
1355     bool isColdStart = true;
1356     std::string intentParam = "test";
1357     window->SetIntentParam(intentParam, testCallback, isColdStart);
1358 
1359     window->SetUIContentByName("info", (napi_env)nullptr, nullptr, nullptr);
1360     EXPECT_EQ(window->intentParam_, "");
1361 
1362     intentParam = "";
1363     window->SetUIContentByName("info", (napi_env)nullptr, nullptr, nullptr);
1364     EXPECT_EQ(window->intentParam_, "");
1365 }
1366 
1367 /**
1368  * @tc.name: HideTitleButton04
1369  * @tc.desc: HideTitleButton04
1370  * @tc.type: FUNC
1371  */
1372 HWTEST_F(WindowSessionImplTest5, HideTitleButton04, Function | SmallTest | Level2) {
1373     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1374     option->SetWindowName("HideTitleButton");
1375     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1376 
1377     bool hideSplitButton = false;
1378     bool hideMaximizeButton = false;
1379     bool hideMinimizeButton = false;
1380     bool hideCloseButton = false;
1381     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
1382     compatibleModeProperty->SetIsSupportRotateFullScreen(true);
1383     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
1384     window->property_->SetIsLayoutFullScreen(true);
1385     window->HideTitleButton(hideSplitButton, hideMaximizeButton, hideMinimizeButton, hideCloseButton);
1386 
1387     EXPECT_FALSE(hideSplitButton);
1388     EXPECT_FALSE(hideMaximizeButton);
1389     EXPECT_FALSE(hideMinimizeButton);
1390     EXPECT_FALSE(hideCloseButton);
1391 }
1392 
1393 /**
1394  * @tc.name: HideTitleButton05
1395  * @tc.desc: HideTitleButton05
1396  * @tc.type: FUNC
1397  */
1398 HWTEST_F(WindowSessionImplTest5, HideTitleButton05, Function | SmallTest | Level2) {
1399     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1400     option->SetWindowName("HideTitleButton");
1401     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1402 
1403     bool hideSplitButton = false;
1404     bool hideMaximizeButton = false;
1405     bool hideMinimizeButton = false;
1406     bool hideCloseButton = false;
1407     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
1408     compatibleModeProperty->SetDisableFullScreen(true);
1409     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
1410     window->HideTitleButton(hideSplitButton, hideMaximizeButton, hideMinimizeButton, hideCloseButton);
1411 
1412     EXPECT_FALSE(hideSplitButton);
1413     EXPECT_FALSE(hideMaximizeButton);
1414     EXPECT_FALSE(hideMinimizeButton);
1415     EXPECT_FALSE(hideCloseButton);
1416 }
1417 
1418 /**
1419  * @tc.name: HideTitleButton06
1420  * @tc.desc: HideTitleButton06
1421  * @tc.type: FUNC
1422  */
1423 HWTEST_F(WindowSessionImplTest5, HideTitleButton06, Function | SmallTest | Level2) {
1424     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1425     option->SetWindowName("HideTitleButton");
1426     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1427 
1428     bool hideSplitButton = false;
1429     bool hideMaximizeButton = false;
1430     bool hideMinimizeButton = false;
1431     bool hideCloseButton = false;
1432     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
1433     compatibleModeProperty->SetIsAdaptToImmersive(true);
1434     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
1435     window->property_->SetIsAtomicService(false);
1436     window->HideTitleButton(hideSplitButton, hideMaximizeButton, hideMinimizeButton, hideCloseButton);
1437 
1438     EXPECT_FALSE(hideSplitButton);
1439     EXPECT_FALSE(hideMaximizeButton);
1440     EXPECT_FALSE(hideMinimizeButton);
1441     EXPECT_FALSE(hideCloseButton);
1442 }
1443 
1444 /**
1445  * @tc.name: HideTitleButton07
1446  * @tc.desc: HideTitleButton07
1447  * @tc.type: FUNC
1448  */
1449 HWTEST_F(WindowSessionImplTest5, HideTitleButton07, Function | SmallTest | Level2) {
1450     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1451     option->SetWindowName("HideTitleButton");
1452     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1453 
1454     bool hideSplitButton = false;
1455     bool hideMaximizeButton = false;
1456     bool hideMinimizeButton = false;
1457     bool hideCloseButton = false;
1458     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
1459     compatibleModeProperty->SetIsAdaptToProportionalScale(true);
1460     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
1461     window->property_->SetIsAtomicService(false);
1462     window->HideTitleButton(hideSplitButton, hideMaximizeButton, hideMinimizeButton, hideCloseButton);
1463 
1464     EXPECT_FALSE(hideSplitButton);
1465     EXPECT_FALSE(hideMaximizeButton);
1466     EXPECT_FALSE(hideMinimizeButton);
1467     EXPECT_FALSE(hideCloseButton);
1468 }
1469 
1470 /**
1471  * @tc.name: HideTitleButton08
1472  * @tc.desc: HideTitleButton08
1473  * @tc.type: FUNC
1474  */
1475 HWTEST_F(WindowSessionImplTest5, HideTitleButton08, Function | SmallTest | Level2) {
1476     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1477     option->SetWindowName("HideTitleButton");
1478     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1479 
1480     bool hideSplitButton = false;
1481     bool hideMaximizeButton = false;
1482     bool hideMinimizeButton = false;
1483     bool hideCloseButton = false;
1484     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
1485     compatibleModeProperty->SetIsAdaptToBackButton(true);
1486     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
1487     window->HideTitleButton(hideSplitButton, hideMaximizeButton, hideMinimizeButton, hideCloseButton);
1488 
1489     EXPECT_FALSE(hideSplitButton);
1490     EXPECT_FALSE(hideMaximizeButton);
1491     EXPECT_FALSE(hideMinimizeButton);
1492     EXPECT_FALSE(hideCloseButton);
1493 }
1494 
1495 /**
1496  * @tc.name: GetFloatingBallWindowId
1497  * @tc.desc: GetFloatingBallWindowId
1498  * @tc.type: FUNC
1499  */
1500 HWTEST_F(WindowSessionImplTest5, GetFloatingBallWindowId, TestSize.Level1)
1501 {
1502     uint32_t windowId = 0;
1503     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1504     option->SetWindowName("GetFloatingBallWindowId");
1505     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1506     window->hostSession_ = nullptr;
1507     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->GetFloatingBallWindowId(windowId));
1508 
1509     auto session = sptr<SessionStubMocker>::MakeSptr();
1510     window->hostSession_ = session;
1511     window->property_->persistentId_ = 1234;
1512     EXPECT_CALL(*session, GetFloatingBallWindowId(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_INVALID_OPERATION));
1513     ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, window->GetFloatingBallWindowId(windowId));
1514 
1515     EXPECT_CALL(*session, GetFloatingBallWindowId(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1516     ASSERT_EQ(WMError::WM_OK, window->GetFloatingBallWindowId(windowId));
1517 }
1518 
1519 /**
1520  * @tc.name: SendFbActionEvent
1521  * @tc.desc: SendFbActionEvent
1522  * @tc.type: FUNC
1523  */
1524 HWTEST_F(WindowSessionImplTest5, SendFbActionEvent, TestSize.Level1)
1525 {
1526     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1527     option->SetWindowName("SendFbActionEvent");
1528     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1529     window->hostSession_ = nullptr;
1530     std::string action = "click";
1531     ASSERT_EQ(WSError::WS_OK, window->SendFbActionEvent(action));
1532 }
1533 
1534 /**
1535  * @tc.name: UpdateFloatingBall
1536  * @tc.desc: UpdateFloatingBall
1537  * @tc.type: FUNC
1538  */
1539 HWTEST_F(WindowSessionImplTest5, UpdateFloatingBall, TestSize.Level1)
1540 {
1541     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1542     option->SetWindowName("UpdateFloatingBall");
1543     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1544     window->hostSession_ = nullptr;
1545     FloatingBallTemplateBaseInfo fbTemplateInfo;
1546     std::shared_ptr<Media::PixelMap> icon = nullptr;
1547 
1548     EXPECT_EQ(window->GetHostSession(), nullptr);
1549     auto error = window->UpdateFloatingBall(fbTemplateInfo, icon);
1550     EXPECT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, error);
1551 
1552     auto session = sptr<SessionStubMocker>::MakeSptr();
1553     window->hostSession_ = session;
1554     window->property_->persistentId_ = 1234;
1555 
1556     FloatingBallTemplateInfo windowFbTemplateInfo;
1557     windowFbTemplateInfo.template_ = static_cast<uint32_t>(FloatingBallTemplate::STATIC);
1558     window->GetProperty()->SetFbTemplateInfo(windowFbTemplateInfo);
1559     EXPECT_EQ(WMError::WM_ERROR_FB_UPDATE_STATIC_TEMPLATE_DENIED, window->UpdateFloatingBall(fbTemplateInfo, icon));
1560 
1561     windowFbTemplateInfo.template_ = static_cast<uint32_t>(FloatingBallTemplate::NORMAL);
1562     window->GetProperty()->SetFbTemplateInfo(windowFbTemplateInfo);
1563     fbTemplateInfo.template_ = static_cast<uint32_t>(FloatingBallTemplate::STATIC);
1564     EXPECT_EQ(WMError::WM_ERROR_FB_UPDATE_TEMPLATE_TYPE_DENIED, window->UpdateFloatingBall(fbTemplateInfo, icon));
1565 
1566     fbTemplateInfo.template_ = static_cast<uint32_t>(FloatingBallTemplate::NORMAL);
1567     EXPECT_FALSE(window->IsWindowSessionInvalid());
1568     error = window->UpdateFloatingBall(fbTemplateInfo, icon);
1569     EXPECT_EQ(WMError::WM_OK, error);
1570 }
1571 
1572 /**
1573  * @tc.name: NotifyPrepareCloseFloatingBall
1574  * @tc.desc: NotifyPrepareCloseFloatingBall
1575  * @tc.type: FUNC
1576  */
1577 HWTEST_F(WindowSessionImplTest5, NotifyPrepareCloseFloatingBall, TestSize.Level1)
1578 {
1579     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1580     option->SetWindowName("NotifyPrepareCloseFloatingBall");
1581     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1582     window->hostSession_ = nullptr;
1583 
1584     EXPECT_EQ(window->GetHostSession(), nullptr);
1585     window->NotifyPrepareCloseFloatingBall();
1586 
1587     auto session = sptr<SessionStubMocker>::MakeSptr();
1588     window->hostSession_ = session;
1589     EXPECT_TRUE(window->IsWindowSessionInvalid());
1590     window->NotifyPrepareCloseFloatingBall();
1591 
1592     window->property_->persistentId_ = 1234;
1593     EXPECT_FALSE(window->IsWindowSessionInvalid());
1594     window->NotifyPrepareCloseFloatingBall();
1595 }
1596 
1597 /**
1598  * @tc.name: RestoreFbMainWindow
1599  * @tc.desc: RestoreFbMainWindow
1600  * @tc.type: FUNC
1601  */
1602 HWTEST_F(WindowSessionImplTest5, RestoreFbMainWindow, TestSize.Level1)
1603 {
1604     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1605     option->SetWindowName("RestoreFbMainWindow");
1606     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1607     window->hostSession_ = nullptr;
1608 
1609     std::shared_ptr<AAFwk::Want> want = nullptr;
1610     ASSERT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, window->RestoreFbMainWindow(want));
1611 
1612     auto session = sptr<SessionStubMocker>::MakeSptr();
1613     window->hostSession_ = session;
1614     window->property_->persistentId_ = 1234;
1615 
1616     EXPECT_CALL(*session, RestoreFbMainWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_FB_STATE_ABNORMALLY));
1617     ASSERT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, window->RestoreFbMainWindow(want));
1618 
1619     EXPECT_CALL(*session, RestoreFbMainWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1620     ASSERT_EQ(WMError::WM_OK, window->RestoreFbMainWindow(want));
1621 }
1622 
1623 /**
1624  * @tc.name: TestGetGlobalDisplayRect
1625  * @tc.desc: Get global display rect from window property
1626  * @tc.type: FUNC
1627  */
1628 HWTEST_F(WindowSessionImplTest5, TestGetGlobalDisplayRect, TestSize.Level1)
1629 {
1630     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1631     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1632 
1633     Rect expected { 100, 200, 300, 400 };
1634     window->property_->SetGlobalDisplayRect(expected);
1635 
1636     Rect actual = window->GetGlobalDisplayRect();
1637     EXPECT_EQ(actual, expected);
1638 }
1639 
1640 /**
1641  * @tc.name: TestClientToGlobalDisplay
1642  * @tc.desc: Convert client position to global display position
1643  * @tc.type: FUNC
1644  */
1645 HWTEST_F(WindowSessionImplTest5, TestClientToGlobalDisplay, TestSize.Level1)
1646 {
1647     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1648     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1649 
1650     Position inPosition;
1651     Position outPosition;
1652 
1653     // Case 1: Scaled window does not support coordinate conversion
1654     Transform transform;
1655     transform.scaleX_ = 0.5f;
1656     window->SetCurrentTransform(transform);
1657     auto ret = window->ClientToGlobalDisplay(inPosition, outPosition);
1658     EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS);
1659     transform.scaleX_ = 1.0f;
1660     transform.scaleY_ = 1.0f;
1661     window->SetCurrentTransform(transform);
1662 
1663     // Case 2: Conversion overflow
1664     inPosition = { INT32_MAX, INT32_MAX };
1665     Rect globalRect { 100, 200, 300, 400 };
1666     window->property_->SetGlobalDisplayRect(globalRect);
1667     ret = window->ClientToGlobalDisplay(inPosition, outPosition);
1668     EXPECT_EQ(ret, WMError::WM_ERROR_ILLEGAL_PARAM);
1669 
1670     // Case 3: Successful conversion
1671     inPosition = { 10, 20 };
1672     Position expectedPosition { 110, 220 };
1673     ret = window->ClientToGlobalDisplay(inPosition, outPosition);
1674     EXPECT_EQ(ret, WMError::WM_OK);
1675     EXPECT_NE(outPosition, inPosition);
1676     EXPECT_EQ(outPosition, expectedPosition);
1677 }
1678 
1679 /**
1680  * @tc.name: TestGlobalDisplayToClient
1681  * @tc.desc: Convert global display position to client position
1682  * @tc.type: FUNC
1683  */
1684 HWTEST_F(WindowSessionImplTest5, TestGlobalDisplayToClient, TestSize.Level1)
1685 {
1686     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1687     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1688 
1689     Position inPosition;
1690     Position outPosition;
1691 
1692     // Case 1: Scaled window does not support coordinate conversion
1693     Transform transform;
1694     transform.scaleX_ = 0.5f;
1695     window->SetCurrentTransform(transform);
1696     auto ret = window->GlobalDisplayToClient(inPosition, outPosition);
1697     EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS);
1698     transform.scaleX_ = 1.0f;
1699     transform.scaleY_ = 1.0f;
1700     window->SetCurrentTransform(transform);
1701 
1702     // Case 2: Conversion overflow
1703     inPosition = { INT32_MIN, INT32_MIN };
1704     Rect globalRect { 100, 200, 300, 400 };
1705     window->property_->SetGlobalDisplayRect(globalRect);
1706     ret = window->GlobalDisplayToClient(inPosition, outPosition);
1707     EXPECT_EQ(ret, WMError::WM_ERROR_ILLEGAL_PARAM);
1708 
1709     // Case 3: Successful conversion
1710     inPosition = { 110, 220 };
1711     Position expectedPosition { 10, 20 };
1712     ret = window->GlobalDisplayToClient(inPosition, outPosition);
1713     EXPECT_EQ(ret, WMError::WM_OK);
1714     EXPECT_NE(outPosition, inPosition);
1715     EXPECT_EQ(outPosition, expectedPosition);
1716 }
1717 
1718 /**
1719  * @tc.name: TestUpdateGlobalDisplayRectFromServer
1720  * @tc.desc: Update global display rect if different
1721  * @tc.type: FUNC
1722  */
1723 HWTEST_F(WindowSessionImplTest5, TestUpdateGlobalDisplayRectFromServer, TestSize.Level1)
1724 {
1725     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1726     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1727     window->property_->SetPersistentId(1001);
1728 
1729     WSRect rect = { 10, 20, 200, 100 };
1730     window->property_->SetGlobalDisplayRect({ 10, 20, 200, 100 });
1731     window->globalDisplayRectSizeChangeReason_ = SizeChangeReason::RESIZE;
1732 
1733     // Case 1: No change, should do nothing
1734     Rect expectedRect { 10, 20, 200, 100 };
1735     auto ret = window->UpdateGlobalDisplayRectFromServer(rect, SizeChangeReason::RESIZE);
1736     EXPECT_EQ(ret, WSError::WS_DO_NOTHING);
1737     EXPECT_EQ(window->GetGlobalDisplayRect(), expectedRect);
1738     EXPECT_EQ(window->globalDisplayRectSizeChangeReason_, SizeChangeReason::RESIZE);
1739 
1740     // Case 2: Change reason, should update
1741     ret = window->UpdateGlobalDisplayRectFromServer(rect, SizeChangeReason::MOVE);
1742     EXPECT_EQ(ret, WSError::WS_OK);
1743     EXPECT_EQ(window->GetGlobalDisplayRect(), expectedRect);
1744     EXPECT_EQ(window->globalDisplayRectSizeChangeReason_, SizeChangeReason::MOVE);
1745 
1746     // Case 3: Change rect, should update
1747     WSRect updated = { 30, 40, 200, 100 };
1748     expectedRect = { 30, 40, 200, 100 };
1749     ret = window->UpdateGlobalDisplayRectFromServer(updated, SizeChangeReason::MOVE);
1750     EXPECT_EQ(ret, WSError::WS_OK);
1751     EXPECT_EQ(window->GetGlobalDisplayRect(), expectedRect);
1752     EXPECT_EQ(window->globalDisplayRectSizeChangeReason_, SizeChangeReason::MOVE);
1753 
1754     // Case 4: Change reason and rect, should update
1755     updated = { 0, 0, 200, 100 };
1756     expectedRect = { 0, 0, 200, 100 };
1757     ret = window->UpdateGlobalDisplayRectFromServer(updated, SizeChangeReason::DRAG);
1758     EXPECT_EQ(ret, WSError::WS_OK);
1759     EXPECT_EQ(window->GetGlobalDisplayRect(), expectedRect);
1760     EXPECT_EQ(window->globalDisplayRectSizeChangeReason_, SizeChangeReason::DRAG);
1761 
1762     // Case 5: Drag move, should update but keep reason as DRAG_MOVE
1763     window->globalDisplayRectSizeChangeReason_ = SizeChangeReason::DRAG_MOVE;
1764     updated = { 20, 20, 200, 100 };
1765     expectedRect = { 20, 20, 200, 100 };
1766     ret = window->UpdateGlobalDisplayRectFromServer(updated, SizeChangeReason::DRAG_END);
1767     EXPECT_EQ(ret, WSError::WS_OK);
1768     EXPECT_EQ(window->GetGlobalDisplayRect(), expectedRect);
1769     EXPECT_EQ(window->globalDisplayRectSizeChangeReason_, SizeChangeReason::DRAG_MOVE);
1770 }
1771 
1772 /**
1773  * @tc.name: TestRegisterRectChangeInGlobalDisplayListener
1774  * @tc.desc: Register a new listener successfully
1775  * @tc.type: FUNC
1776  */
1777 HWTEST_F(WindowSessionImplTest5, TestRegisterRectChangeInGlobalDisplayListener, TestSize.Level1)
1778 {
1779     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1780     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1781     window->property_->SetPersistentId(123);
1782 
1783     auto listener = sptr<MockRectChangeInGlobalDisplayListener>::MakeSptr();
1784 
1785     auto result = window->RegisterRectChangeInGlobalDisplayListener(listener);
1786     EXPECT_EQ(result, WMError::WM_OK);
1787 
1788     {
1789         std::lock_guard<std::mutex> lock(window->rectChangeInGlobalDisplayListenerMutex_);
1790         window->rectChangeInGlobalDisplayListeners_.clear();
1791     }
1792 }
1793 
1794 /**
1795  * @tc.name: TestUnregisterRectChangeInGlobalDisplayListener
1796  * @tc.desc: Unregister an existing listener successfully
1797  * @tc.type: FUNC
1798  */
1799 HWTEST_F(WindowSessionImplTest5, TestUnregisterRectChangeInGlobalDisplayListener, TestSize.Level1)
1800 {
1801     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1802     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1803     window->property_->SetPersistentId(123);
1804 
1805     auto listener = sptr<MockRectChangeInGlobalDisplayListener>::MakeSptr();
1806     window->RegisterRectChangeInGlobalDisplayListener(listener);
1807 
1808     auto result = window->UnregisterRectChangeInGlobalDisplayListener(listener);
1809     EXPECT_EQ(result, WMError::WM_OK);
1810 
1811     {
1812         std::lock_guard<std::mutex> lock(window->rectChangeInGlobalDisplayListenerMutex_);
1813         window->rectChangeInGlobalDisplayListeners_.clear();
1814     }
1815 }
1816 
1817 /**
1818  * @tc.name: TestNotifyGlobalDisplayRectChange
1819  * @tc.desc: Notify all valid listeners and skip nullptr ones
1820  * @tc.type: FUNC
1821  */
1822 HWTEST_F(WindowSessionImplTest5, TestNotifyGlobalDisplayRectChange, TestSize.Level1)
1823 {
1824     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1825     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1826     window->property_->SetPersistentId(1001);
1827 
1828     auto listener1 = sptr<MockRectChangeInGlobalDisplayListener>::MakeSptr();
1829     auto listener2 = sptr<MockRectChangeInGlobalDisplayListener>::MakeSptr();
1830     sptr<IRectChangeInGlobalDisplayListener> nullListener = nullptr;
1831 
1832     {
1833         std::lock_guard<std::mutex> lock(window->rectChangeInGlobalDisplayListenerMutex_);
1834         window->rectChangeInGlobalDisplayListeners_[window->GetPersistentId()] = {
1835             listener1, nullListener, listener2
1836         };
1837     }
1838 
1839     Rect rect { 10, 20, 100, 200 };
1840     WindowSizeChangeReason reason = WindowSizeChangeReason::UNDEFINED;
1841 
1842     EXPECT_CALL(*listener1, OnRectChangeInGlobalDisplay(rect, reason)).Times(1);
1843     EXPECT_CALL(*listener2, OnRectChangeInGlobalDisplay(rect, reason)).Times(1);
1844 
1845     window->NotifyGlobalDisplayRectChange(rect, reason);
1846 
1847     {
1848         std::lock_guard<std::mutex> lock(window->rectChangeInGlobalDisplayListenerMutex_);
1849         window->rectChangeInGlobalDisplayListeners_.clear();
1850     }
1851 }
1852 
1853 /**
1854  * @tc.name: GetPiPSettingSwitchStatus
1855  * @tc.desc: GetPiPSettingSwitchStatus
1856  * @tc.type: FUNC
1857  */
1858 HWTEST_F(WindowSessionImplTest5, GetPiPSettingSwitchStatus, Function | SmallTest | Level2)
1859 {
1860     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1861     option->SetWindowName("GetPiPSettingSwitchStatus");
1862     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1863     bool switchStatus = false;
1864     WMError retCode = window->GetPiPSettingSwitchStatus(switchStatus);
1865     ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
1866     window->property_->SetPersistentId(1);
1867     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1868     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1869     window->hostSession_ = session;
1870     window->state_ = WindowState::STATE_CREATED;
1871     window->GetPiPSettingSwitchStatus(switchStatus);
1872 }
1873 
1874 /**
1875  * @tc.name: OnPointDown
1876  * @tc.desc: OnPointDown
1877  * @tc.type: FUNC
1878  */
1879 HWTEST_F(WindowSessionImplTest5, OnPointDown, TestSize.Level1)
1880 {
1881     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1882     option->SetWindowName("OnPointDown");
1883     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1884 
1885     window->property_->SetCollaboratorType(static_cast<int32_t>(CollaboratorType::RESERVE_TYPE));
1886     EXPECT_TRUE(window->IsAnco());
1887 
1888     EXPECT_EQ(window->GetHostSession(), nullptr);
1889     EXPECT_FALSE(window->OnPointDown(0, 0, 0));
1890 
1891     SessionInfo sessionInfo = {"OnPointDown", "OnPointDown", "OnPointDown"};
1892     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1893     window->hostSession_ = session;
1894 
1895     EXPECT_CALL(*(session), ProcessPointDownSession(_, _)).Times(1).WillOnce(Return(WSError::WS_OK));
1896     EXPECT_TRUE(window->OnPointDown(0, 0, 0));
1897 }
1898 
1899 /**
1900  * @tc.name: UpdateEnableDragWhenSwitchMultiWindow
1901  * @tc.desc: UpdateEnableDragWhenSwitchMultiWindow
1902  * @tc.type: FUNC
1903  */
1904 HWTEST_F(WindowSessionImplTest5, UpdateEnableDragWhenSwitchMultiWindow, Function | SmallTest | Level2)
1905 {
1906     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1907     option->SetWindowName("UpdateEnableDragWhenSwitchMultiWindow");
1908     option->SetWindowType(WindowType::WINDOW_TYPE_MAGNIFICATION);
1909     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1910     window->hasSetEnableDrag_.store(true);
1911     window->UpdateEnableDragWhenSwitchMultiWindow(false);
1912     EXPECT_EQ(true, window->property_->dragEnabled_);
1913 
1914     window->hasSetEnableDrag_.store(false);
1915     window->UpdateEnableDragWhenSwitchMultiWindow(false);
1916     EXPECT_EQ(false, window->property_->dragEnabled_);
1917 
1918     window->property_->type_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
1919     sptr<CompatibleModeProperty> property = sptr<CompatibleModeProperty>::MakeSptr();
1920     property->disableDragResize_ = true;
1921     window->property_->compatibleModeProperty_ = property;
1922     window->UpdateEnableDragWhenSwitchMultiWindow(true);
1923     EXPECT_EQ(false, window->property_->dragEnabled_);
1924 
1925     property->disableDragResize_ = false;
1926     window->UpdateEnableDragWhenSwitchMultiWindow(true);
1927     EXPECT_EQ(true, window->property_->dragEnabled_);
1928 }
1929 
1930 /**
1931  * @tc.name: SwitchSubWindow
1932  * @tc.desc: SwitchSubWindow
1933  * @tc.type: FUNC
1934  */
1935 HWTEST_F(WindowSessionImplTest5, SwitchSubWindow, Function | SmallTest | Level1)
1936 {
1937     sptr<WindowOption> subOption = sptr<WindowOption>::MakeSptr();
1938     subOption->SetWindowName("SwitchSubWindow");
1939     subOption->SetSubWindowDecorEnable(true);
1940     subOption->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1941     sptr<WindowSessionImpl> subWindow = sptr<WindowSessionImpl>::MakeSptr(subOption);
1942     ASSERT_NE(subWindow, nullptr);
1943     ASSERT_NE(subWindow->property_, nullptr);
1944     subWindow->property_->SetPersistentId(PERSISTENT_ID_TWO);
1945     subWindow->property_->SetDecorEnable(true);
1946     subWindow->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1947     subWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
1948     subWindow->windowSystemConfig_.freeMultiWindowSupport_ = true;
1949     subWindow->windowSystemConfig_.isSystemDecorEnable_ = true;
1950     subWindow->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1951     // freemultiwindowmode start
1952     EXPECT_EQ(subWindow->IsDecorEnable(), false);
1953     // cover emprty map
1954     subWindow->SwitchSubWindow(false, PERSISTENT_ID_ONE);
1955 
1956     std::vector<sptr<WindowSessionImpl>> vec;
1957     WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
1958         std::vector<sptr<WindowSessionImpl>>>(PERSISTENT_ID_ONE, vec));
1959     WindowSessionImpl::subWindowSessionMap_[PERSISTENT_ID_ONE].push_back(subWindow);
1960     subWindow->SwitchSubWindow(true, PERSISTENT_ID_ONE);
1961     WindowMode mode = subWindow->property_->GetWindowMode();
1962     bool decorVisible = mode == WindowMode::WINDOW_MODE_FLOATING ||
1963         mode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || mode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY ||
1964         (mode == WindowMode::WINDOW_MODE_FULLSCREEN && !subWindow->property_->IsLayoutFullScreen());
1965     if (subWindow->windowSystemConfig_.freeMultiWindowSupport_) {
1966         auto isSubWindow = WindowHelper::IsSubWindow(subWindow->GetType());
1967         decorVisible = decorVisible && (subWindow->windowSystemConfig_.freeMultiWindowEnable_ ||
1968             (subWindow->property_->GetIsPcAppInPad() && isSubWindow));
1969     }
1970     EXPECT_EQ(decorVisible, true);
1971 }
1972 
1973 /**
1974  * @tc.name: NotifySizeChangeFlag
1975  * @tc.desc: NotifySizeChangeFlag
1976  * @tc.type: FUNC
1977  */
1978 HWTEST_F(WindowSessionImplTest5, NotifySizeChangeFlag, Function | SmallTest | Level1)
1979 {
1980     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1981     option->SetWindowName("NotifySizeChangeFlag");
1982     sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1983     Rect requestRect = { 0, 0, 50, 50 };
1984     Rect windowRect = { 0, 0, 0, 0 };
1985     window->property_->SetWindowRect(windowRect);
1986     window->property_->SetRequestRect(requestRect);
1987 
1988     window->SetNotifySizeChangeFlag(false);
1989     window->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_NAVIGATION);
1990     window->SetNotifySizeChangeFlag(true);
1991     ASSERT_EQ(window->notifySizeChangeFlag_, true);
1992 
1993     window->SetNotifySizeChangeFlag(false);
1994     window->property_->SetWindowRect(requestRect);
1995     window->SetNotifySizeChangeFlag(true);
1996     ASSERT_EQ(window->notifySizeChangeFlag_, false);
1997 
1998     window->SetNotifySizeChangeFlag(false);
1999     window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
2000     window->SetNotifySizeChangeFlag(true);
2001     ASSERT_EQ(window->notifySizeChangeFlag_, false);
2002 }
2003 } // namespace
2004 } // namespace Rosen
2005 } // namespace OHOS
2006