• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #include <ability_context_impl.h>
19 #include <context_impl.h>
20 #include <float_wrapper.h>
21 #include <int_wrapper.h>
22 #include <transaction/rs_transaction.h>
23 #include <want_params_wrapper.h>
24 
25 #include "accessibility_event_info.h"
26 #include "display_info.h"
27 #include "extension/extension_business_info.h"
28 #include "extension_data_handler.h"
29 #include "extension_data_handler_mock.h"
30 #include "iremote_object_mocker.h"
31 #include "mock_session.h"
32 #include "mock_uicontent.h"
33 #include "mock_window.h"
34 #include "mock_window_adapter.h"
35 #include "singleton_mocker.h"
36 #include "ui_extension/provider_data_handler.h"
37 #include "window_extension_session_impl.h"
38 #include "wm_common.h"
39 
40 using namespace testing;
41 using namespace testing::ext;
42 using namespace OHOS::Accessibility;
43 using namespace std;
44 
45 namespace {
46     std::string logMsg;
WindowExtensionSessionImplLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)47     void WindowExtensionSessionImplLogCallback(const LogType type, const LogLevel level, const unsigned int domain,
48         const char* tag, const char* msg)
49     {
50         logMsg = msg;
51     }
52 }
53 
54 namespace OHOS {
55 namespace Rosen {
56 using WindowAdapterMocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
57 class WindowExtensionSessionImplTest : public testing::Test {
58 public:
59     static void SetUpTestCase();
60     static void TearDownTestCase();
61     void SetUp() override;
62     void TearDown() override;
63 private:
64     sptr<WindowExtensionSessionImpl> window_ = nullptr;
65     std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
66     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
67 };
68 
SetUpTestCase()69 void WindowExtensionSessionImplTest::SetUpTestCase()
70 {
71 }
72 
TearDownTestCase()73 void WindowExtensionSessionImplTest::TearDownTestCase()
74 {
75 }
76 
SetUp()77 void WindowExtensionSessionImplTest::SetUp()
78 {
79     sptr<WindowOption> option = new(std::nothrow) WindowOption();
80     ASSERT_NE(nullptr, option);
81     option->SetWindowName("WindowExtensionSessionImplTest");
82     window_ = new(std::nothrow) WindowExtensionSessionImpl(option);
83     ASSERT_NE(nullptr, window_);
84     if (!handler_) {
85         auto runner = AppExecFwk::EventRunner::Create("WindowExtensionSessionImplTest");
86         handler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
87     }
88     window_->handler_ = handler_;
89 }
90 
TearDown()91 void WindowExtensionSessionImplTest::TearDown()
92 {
93     window_ = nullptr;
94 }
95 
96 namespace {
97 /**
98  * @tc.name: WindowExtensionSessionImpl
99  * @tc.desc: WindowExtensionSessionImpl contructor
100  * @tc.type: FUNC
101  */
102 HWTEST_F(WindowExtensionSessionImplTest, WindowExtensionSessionImpl, TestSize.Level1)
103 {
104     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
105     ASSERT_NE(nullptr, option);
106     option->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
107     option->uiExtensionUsage_ = static_cast<uint32_t>(UIExtensionUsage::CONSTRAINED_EMBEDDED);
108     option->SetWindowName("WindowExtensionSessionImplTest");
109     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
110     ASSERT_NE(nullptr, window);
111     window = nullptr;
112 }
113 
114 /**
115  * @tc.name: Create01
116  * @tc.desc: normal test
117  * @tc.type: FUNC
118  */
119 HWTEST_F(WindowExtensionSessionImplTest, Create01, TestSize.Level0)
120 {
121     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
122     ASSERT_NE(nullptr, abilityContext);
123     SessionInfo sessionInfo;
124     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
125     ASSERT_NE(nullptr, session);
126     ASSERT_NE(nullptr, window_->property_);
127     window_->property_->SetPersistentId(1);
128     ASSERT_EQ(WMError::WM_OK, window_->Create(abilityContext, session));
129     ASSERT_EQ(WMError::WM_OK, window_->Destroy(false));
130 }
131 
132 /**
133  * @tc.name: Create02
134  * @tc.desc: context is nullptr, session is nullptr
135  * @tc.type: FUNC
136  */
137 HWTEST_F(WindowExtensionSessionImplTest, Create02, TestSize.Level1)
138 {
139     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->Create(nullptr, nullptr));
140 }
141 
142 /**
143  * @tc.name: Create03
144  * @tc.desc: context is not nullptr, session is nullptr
145  * @tc.type: FUNC
146  */
147 HWTEST_F(WindowExtensionSessionImplTest, Create03, TestSize.Level1)
148 {
149     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
150     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->Create(abilityContext, nullptr));
151 }
152 
153 /**
154  * @tc.name: Create04
155  * @tc.desc: connet failed
156  * @tc.type: FUNC
157  */
158 HWTEST_F(WindowExtensionSessionImplTest, Create04, TestSize.Level1)
159 {
160     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
161     ASSERT_NE(nullptr, abilityContext);
162     SessionInfo sessionInfo;
163     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
164     ASSERT_NE(nullptr, session);
165     ASSERT_NE(nullptr, window_->property_);
166     window_->property_->SetPersistentId(1);
167     EXPECT_CALL(*session, Connect).WillOnce(Return(WSError::WS_ERROR_NULLPTR));
168     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->Create(abilityContext, session));
169 }
170 
171 /**
172  * @tc.name: Create05
173  * @tc.desc: normal test, create modal uiextension
174  * @tc.type: FUNC
175  */
176 HWTEST_F(WindowExtensionSessionImplTest, Create05, TestSize.Level1)
177 {
178     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
179     ASSERT_NE(nullptr, abilityContext);
180     SessionInfo sessionInfo;
181     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
182     window_->property_->SetPersistentId(1);
183     window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
184     ASSERT_EQ(WMError::WM_OK, window_->Create(abilityContext, session));
185     ASSERT_EQ(WMError::WM_OK, window_->Destroy(false));
186 }
187 
188 /**
189  * @tc.name: Create06
190  * @tc.desc: normal test, create secure uiextension
191  * @tc.type: FUNC
192  */
193 HWTEST_F(WindowExtensionSessionImplTest, Create06, TestSize.Level1)
194 {
195     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
196     ASSERT_NE(nullptr, abilityContext);
197     SessionInfo sessionInfo;
198     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
199     window_->property_->SetPersistentId(1);
200     window_->property_->SetUIExtensionUsage(UIExtensionUsage::CONSTRAINED_EMBEDDED);
201     ASSERT_EQ(WMError::WM_OK, window_->Create(abilityContext, session));
202     ASSERT_EQ(WMError::WM_OK, window_->Destroy(false));
203 }
204 
205 /**
206  * @tc.name: Destroy01
207  * @tc.desc: Destroy Test
208  * @tc.type: FUNC
209  */
210 HWTEST_F(WindowExtensionSessionImplTest, Destroy01, TestSize.Level0)
211 {
212     SessionInfo sessionInfo;
213     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
214     ASSERT_NE(nullptr, session);
215     window_->hostSession_ = session;
216     ASSERT_NE(nullptr, window_->property_);
217     window_->property_->SetPersistentId(1);
218     window_->dataHandler_ = std::make_shared<Extension::ProviderDataHandler>();
219     ASSERT_EQ(WMError::WM_OK, window_->Destroy(false, false));
220 }
221 
222 /**
223  * @tc.name: Destroy02
224  * @tc.desc: Destroy Test, window session is invalid
225  * @tc.type: FUNC
226  */
227 HWTEST_F(WindowExtensionSessionImplTest, Destroy02, TestSize.Level1)
228 {
229     ASSERT_NE(nullptr, window_->property_);
230     window_->hostSession_ = nullptr;
231     window_->property_->SetPersistentId(0);
232     window_->state_= WindowState::STATE_DESTROYED;
233     ASSERT_NE(WMError::WM_OK, window_->Destroy(false, false));
234 }
235 
236 /**
237  * @tc.name: AddExtensionWindowStageToSCB
238  * @tc.desc: AddExtensionWindowStageToSCB Test
239  * @tc.type: FUNC
240  */
241 HWTEST_F(WindowExtensionSessionImplTest, AddExtensionWindowStageToSCB, TestSize.Level1)
242 {
243     ASSERT_NE(nullptr, window_);
244     window_->AddExtensionWindowStageToSCB();
245 
246     sptr<IRemoteObject> iRemoteObject = new IRemoteObjectMocker();
247     ASSERT_NE(nullptr, iRemoteObject);
248     window_->abilityToken_ = iRemoteObject;
249     window_->AddExtensionWindowStageToSCB();
250 
251     window_->surfaceNode_ = nullptr;
252     window_->AddExtensionWindowStageToSCB();
253 }
254 
255 /**
256  * @tc.name: RemoveExtensionWindowStageFromSCB
257  * @tc.desc: RemoveExtensionWindowStageFromSCB Test
258  * @tc.type: FUNC
259  */
260 HWTEST_F(WindowExtensionSessionImplTest, RemoveExtensionWindowStageFromSCB, TestSize.Level1)
261 {
262     ASSERT_NE(nullptr, window_);
263     window_->RemoveExtensionWindowStageFromSCB();
264 
265     sptr<IRemoteObject> iRemoteObject = new IRemoteObjectMocker();
266     ASSERT_NE(nullptr, iRemoteObject);
267     window_->abilityToken_ = iRemoteObject;
268     window_->RemoveExtensionWindowStageFromSCB();
269 }
270 
271 /**
272  * @tc.name: UpdateConfiguration01
273  * @tc.desc: UpdateConfiguration Test
274  * @tc.type: FUNC
275  */
276 HWTEST_F(WindowExtensionSessionImplTest, UpdateConfiguration01, TestSize.Level1)
277 {
278     std::shared_ptr<AppExecFwk::Configuration> configuration;
279     ASSERT_NE(nullptr, window_);
280     window_->UpdateConfiguration(configuration);
281 }
282 
283 /**
284  * @tc.name: UpdateConfiguration02
285  * @tc.desc: UpdateConfiguration Test
286  * @tc.type: FUNC
287  */
288 HWTEST_F(WindowExtensionSessionImplTest, UpdateConfiguration02, TestSize.Level1)
289 {
290     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
291     ASSERT_NE(nullptr, window_->uiContent_);
292     std::shared_ptr<AppExecFwk::Configuration> configuration;
293     window_->UpdateConfiguration(configuration);
294     usleep(WAIT_SYNC_IN_NS);
295 }
296 
297 /**
298  * @tc.name: UpdateConfigurationForAll01
299  * @tc.desc: UpdateConfigurationForAll01 Test
300  * @tc.type: FUNC
301  */
302 HWTEST_F(WindowExtensionSessionImplTest, UpdateConfigurationForAll01, TestSize.Level1)
303 {
304     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
305     ASSERT_NE(nullptr, window_);
306     window_->UpdateConfigurationForAll(configuration);
307 }
308 
309 /**
310  * @tc.name: UpdateConfigurationForAll02
311  * @tc.desc: UpdateConfigurationForAll02 Test
312  * @tc.type: FUNC
313  */
314 HWTEST_F(WindowExtensionSessionImplTest, UpdateConfigurationForAll02, TestSize.Level1)
315 {
316     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
317     ASSERT_NE(nullptr, window_);
318     window_->GetWindowExtensionSessionSet().insert(window_);
319     window_->UpdateConfigurationForAll(configuration);
320     window_->GetWindowExtensionSessionSet().erase(window_);
321 }
322 
323 /**
324  * @tc.name: UpdateConfigurationForAll03
325  * @tc.desc: UpdateConfigurationForAll03 Test
326  * @tc.type: FUNC
327  */
328 HWTEST_F(WindowExtensionSessionImplTest, UpdateConfigurationForAll03, TestSize.Level1)
329 {
330     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
331     ASSERT_NE(nullptr, abilityContext);
332     SessionInfo sessionInfo;
333     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
334     ASSERT_NE(nullptr, session);
335     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
336     ASSERT_NE(nullptr, window_->property_);
337     window_->property_->SetPersistentId(1);
338     ASSERT_EQ(WMError::WM_OK, window_->Create(abilityContext, session));
339     ASSERT_NE(nullptr, window_);
340     window_->GetWindowExtensionSessionSet().insert(window_);
341     std::vector<std::shared_ptr<AbilityRuntime::Context>> ignoreWindowContexts;
342     ignoreWindowContexts.push_back(abilityContext);
343     window_->UpdateConfigurationForAll(configuration, ignoreWindowContexts);
344     window_->GetWindowExtensionSessionSet().erase(window_);
345 }
346 
347 /**
348  * @tc.name: MoveTo01
349  * @tc.desc: MoveTo
350  * @tc.type: FUNC
351  */
352 HWTEST_F(WindowExtensionSessionImplTest, MoveTo01, TestSize.Level1)
353 {
354     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->MoveTo(0, 1));
355 }
356 
357 /**
358  * @tc.name: MoveTo02
359  * @tc.desc: MoveTo
360  * @tc.type: FUNC
361  */
362 HWTEST_F(WindowExtensionSessionImplTest, MoveTo02, TestSize.Level1)
363 {
364     SessionInfo sessionInfo;
365     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
366     ASSERT_NE(nullptr, window_->hostSession_);
367     ASSERT_NE(nullptr, window_->property_);
368     window_->property_->SetPersistentId(1);
369     ASSERT_EQ(WMError::WM_OK, window_->MoveTo(0, 1));
370 }
371 
372 /**
373  * @tc.name: Resize01
374  * @tc.desc: Resize
375  * @tc.type: FUNC
376  */
377 HWTEST_F(WindowExtensionSessionImplTest, Resize01, TestSize.Level1)
378 {
379     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->Resize(0, 1));
380 }
381 
382 /**
383  * @tc.name: Resize02
384  * @tc.desc: Resize
385  * @tc.type: FUNC
386  */
387 HWTEST_F(WindowExtensionSessionImplTest, Resize02, TestSize.Level1)
388 {
389     SessionInfo sessionInfo;
390     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
391     ASSERT_NE(nullptr, window_->hostSession_);
392     ASSERT_NE(nullptr, window_->property_);
393     window_->property_->SetPersistentId(1);
394     ASSERT_EQ(WMError::WM_OK, window_->Resize(0, 1));
395 }
396 
397 /**
398  * @tc.name: TransferAbilityResult01
399  * @tc.desc: TransferAbilityResult
400  * @tc.type: FUNC
401  */
402 HWTEST_F(WindowExtensionSessionImplTest, TransferAbilityResult01, TestSize.Level1)
403 {
404     AAFwk::Want want;
405     ASSERT_EQ(WMError::WM_ERROR_REPEAT_OPERATION, window_->TransferAbilityResult(1, want));
406 }
407 
408 /**
409  * @tc.name: TransferAbilityResult02
410  * @tc.desc: TransferAbilityResult
411  * @tc.type: FUNC
412  */
413 HWTEST_F(WindowExtensionSessionImplTest, TransferAbilityResult02, TestSize.Level0)
414 {
415     SessionInfo sessionInfo;
416     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
417     ASSERT_NE(nullptr, window_->hostSession_);
418     ASSERT_NE(nullptr, window_->property_);
419     window_->property_->SetPersistentId(1);
420     AAFwk::Want want;
421     ASSERT_EQ(WMError::WM_OK, window_->TransferAbilityResult(1, want));
422 }
423 
424 /**
425  * @tc.name: TransferExtensionData01
426  * @tc.desc: TransferExtensionData
427  * @tc.type: FUNC
428  */
429 HWTEST_F(WindowExtensionSessionImplTest, TransferExtensionData01, TestSize.Level1)
430 {
431     AAFwk::WantParams wantParams;
432     ASSERT_EQ(WMError::WM_ERROR_REPEAT_OPERATION, window_->TransferExtensionData(wantParams));
433 }
434 
435 /**
436  * @tc.name: TransferExtensionData02
437  * @tc.desc: TransferExtensionData
438  * @tc.type: FUNC
439  */
440 HWTEST_F(WindowExtensionSessionImplTest, TransferExtensionData02, TestSize.Level1)
441 {
442     SessionInfo sessionInfo;
443     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
444     ASSERT_NE(nullptr, window_->hostSession_);
445     ASSERT_NE(nullptr, window_->property_);
446     window_->property_->SetPersistentId(1);
447     AAFwk::WantParams wantParams;
448     ASSERT_EQ(WMError::WM_OK, window_->TransferExtensionData(wantParams));
449 }
450 
451 /**
452  * @tc.name: RegisterTransferComponentDataListener01
453  * @tc.desc: RegisterTransferComponentDataListener Test
454  * @tc.type: FUNC
455  */
456 HWTEST_F(WindowExtensionSessionImplTest, RegisterTransferComponentDataListener01, TestSize.Level1)
457 {
458     NotifyTransferComponentDataFunc func;
459     window_->RegisterTransferComponentDataListener(func);
460     ASSERT_EQ(nullptr, window_->notifyTransferComponentDataFunc_);
461 }
462 
463 /**
464  * @tc.name: RegisterTransferComponentDataListener02
465  * @tc.desc: RegisterTransferComponentDataListener Test
466  * @tc.type: FUNC
467  */
468 HWTEST_F(WindowExtensionSessionImplTest, RegisterTransferComponentDataListener02, TestSize.Level1)
469 {
470     SessionInfo sessionInfo;
471     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
472     ASSERT_NE(nullptr, window_->hostSession_);
473     ASSERT_NE(nullptr, window_->property_);
474     window_->property_->SetPersistentId(1);
475     NotifyTransferComponentDataFunc func;
476     window_->RegisterTransferComponentDataListener(func);
477 }
478 
479 /**
480  * @tc.name: NotifyTransferComponentData01
481  * @tc.desc: NotifyTransferComponentData Test
482  * @tc.type: FUNC
483  */
484 HWTEST_F(WindowExtensionSessionImplTest, NotifyTransferComponentData01, TestSize.Level1)
485 {
486     AAFwk::WantParams wantParams;
487     ASSERT_EQ(WSError::WS_OK, window_->NotifyTransferComponentData(wantParams));
488 }
489 
490 /**
491  * @tc.name: NotifyTransferComponentData02
492  * @tc.desc: NotifyTransferComponentData Test
493  * @tc.type: FUNC
494  */
495 HWTEST_F(WindowExtensionSessionImplTest, NotifyTransferComponentData02, TestSize.Level0)
496 {
497     SessionInfo sessionInfo;
498     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
499     ASSERT_NE(nullptr, window_->hostSession_);
500     ASSERT_NE(nullptr, window_->property_);
501     window_->property_->SetPersistentId(1);
__anondbd7fd8b0302(const AAFwk::WantParams& wantParams) 502     NotifyTransferComponentDataFunc func = [](const AAFwk::WantParams& wantParams) -> AAFwk::WantParams {
503         AAFwk::WantParams retWantParams;
504         return retWantParams;
505     };
506     window_->RegisterTransferComponentDataListener(func);
507     AAFwk::WantParams wantParams;
508     ASSERT_EQ(WSError::WS_OK, window_->NotifyTransferComponentData(wantParams));
509 }
510 
511 /**
512  * @tc.name: NotifyTransferComponentDataSync01
513  * @tc.desc: NotifyTransferComponentDataSync Test
514  * @tc.type: FUNC
515  */
516 HWTEST_F(WindowExtensionSessionImplTest, NotifyTransferComponentDataSync01, TestSize.Level1)
517 {
518     AAFwk::WantParams wantParams;
519     AAFwk::WantParams reWantParams;
520     ASSERT_EQ(WSErrorCode::WS_ERROR_NOT_REGISTER_SYNC_CALLBACK,
521         window_->NotifyTransferComponentDataSync(wantParams, reWantParams));
522 }
523 
524 /**
525  * @tc.name: NotifyTransferComponentDataSync02
526  * @tc.desc: NotifyTransferComponentDataSync Test
527  * @tc.type: FUNC
528  */
529 HWTEST_F(WindowExtensionSessionImplTest, NotifyTransferComponentDataSync02, TestSize.Level1)
530 {
531     SessionInfo sessionInfo;
532     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
533     ASSERT_NE(nullptr, window_->hostSession_);
534     ASSERT_NE(nullptr, window_->property_);
535     window_->property_->SetPersistentId(1);
__anondbd7fd8b0402(const AAFwk::WantParams& wantParams) 536     NotifyTransferComponentDataForResultFunc func = [](const AAFwk::WantParams& wantParams) -> AAFwk::WantParams {
537         AAFwk::WantParams retWantParams;
538         return retWantParams;
539     };
540     window_->RegisterTransferComponentDataForResultListener(func);
541     AAFwk::WantParams wantParams;
542     AAFwk::WantParams reWantParams;
543     ASSERT_EQ(WSErrorCode::WS_OK,
544         window_->NotifyTransferComponentDataSync(wantParams, reWantParams));
545 }
546 
547 /**
548  * @tc.name: RegisterTransferComponentDataForResultListener01
549  * @tc.desc: RegisterTransferComponentDataForResultListener Test
550  * @tc.type: FUNC
551  */
552 HWTEST_F(WindowExtensionSessionImplTest, RegisterTransferComponentDataForResultListen01, TestSize.Level1)
553 {
554     NotifyTransferComponentDataForResultFunc func;
555     window_->RegisterTransferComponentDataForResultListener(func);
556     ASSERT_EQ(nullptr, window_->notifyTransferComponentDataForResultFunc_);
557 }
558 
559 /**
560  * @tc.name: RegisterTransferComponentDataForResultListener02
561  * @tc.desc: RegisterTransferComponentDataForResultListener Test
562  * @tc.type: FUNC
563  */
564 HWTEST_F(WindowExtensionSessionImplTest, RegisterTransferComponentDataForResultListen02, TestSize.Level1)
565 {
566     SessionInfo sessionInfo;
567     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
568     ASSERT_NE(nullptr, window_->hostSession_);
569     ASSERT_NE(nullptr, window_->property_);
570     window_->property_->SetPersistentId(1);
571     NotifyTransferComponentDataForResultFunc func;
572     window_->RegisterTransferComponentDataForResultListener(func);
573 }
574 
575 /**
576  * @tc.name: RegisterHostWindowRectChangeListener
577  * @tc.desc: RegisterHostWindowRectChangeListener Test
578  * @tc.type: FUNC
579  */
580 HWTEST_F(WindowExtensionSessionImplTest, RegisterHostWindowRectChangeListener, TestSize.Level1)
581 {
582     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
583     option->SetWindowName("RegisterHostWindowRectChangeListener");
584     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
585     SessionInfo sessionInfo;
586     window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
587     window->property_->SetPersistentId(1);
588     ASSERT_NE(0, window->GetPersistentId());
589     window->dataHandler_ = nullptr;
590     sptr<IWindowRectChangeListener> listener = nullptr;
591 
592     EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->RegisterHostWindowRectChangeListener(listener));
593     window->dataHandler_ = std::make_shared<Extension::MockDataHandler>();
594     EXPECT_EQ(WMError::WM_ERROR_NULLPTR, window->RegisterHostWindowRectChangeListener(listener));
595     listener = sptr<MockWindowRectChangeListener>::MakeSptr();
596     EXPECT_EQ(WMError::WM_OK, window->RegisterHostWindowRectChangeListener(listener));
597     // Test listener alreday registered
598     EXPECT_EQ(WMError::WM_OK, window->RegisterHostWindowRectChangeListener(listener));
599 }
600 
601 /**
602  * @tc.name: UnregisterHostWindowRectChangeListener
603  * @tc.desc: UnregisterHostWindowRectChangeListener Test
604  * @tc.type: FUNC
605  */
606 HWTEST_F(WindowExtensionSessionImplTest, UnregisterHostWindowRectChangeListener, TestSize.Level1)
607 {
608     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
609     option->SetWindowName("UnregisterHostWindowRectChangeListener");
610     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
611     SessionInfo sessionInfo;
612     window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
613     window->property_->SetPersistentId(1);
614     ASSERT_NE(0, window->GetPersistentId());
615     window->dataHandler_ = nullptr;
616     sptr<IWindowRectChangeListener> listener = nullptr;
617 
618     EXPECT_EQ(WMError::WM_ERROR_NULLPTR, window->UnregisterHostWindowRectChangeListener(listener));
619     listener = sptr<MockWindowRectChangeListener>::MakeSptr();
620     window->rectChangeUIExtListenerIds_.emplace(111);
621     ASSERT_FALSE(window->rectChangeUIExtListenerIds_.empty());
622     EXPECT_EQ(WMError::WM_OK, window->UnregisterHostWindowRectChangeListener(listener));
623     window->rectChangeUIExtListenerIds_.clear();
624     EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->UnregisterHostWindowRectChangeListener(listener));
625     window->dataHandler_ = std::make_shared<Extension::MockDataHandler>();
626     EXPECT_EQ(WMError::WM_OK, window->UnregisterHostWindowRectChangeListener(listener));
627 }
628 
629 /**
630  * @tc.name: TriggerBindModalUIExtension01
631  * @tc.desc: TriggerBindModalUIExtension01 Test
632  * @tc.type: FUNC
633  */
634 HWTEST_F(WindowExtensionSessionImplTest, TriggerBindModalUIExtension01, TestSize.Level1)
635 {
636     ASSERT_NE(nullptr, window_);
637     window_->TriggerBindModalUIExtension();
638 }
639 
640 /**
641  * @tc.name: TriggerBindModalUIExtension02
642  * @tc.desc: TriggerBindModalUIExtension02 Test
643  * @tc.type: FUNC
644  */
645 HWTEST_F(WindowExtensionSessionImplTest, TriggerBindModalUIExtension02, TestSize.Level1)
646 {
647     SessionInfo sessionInfo;
648     window_->hostSession_ = new (std::nothrow) SessionMocker(sessionInfo);
649     ASSERT_NE(nullptr, window_->hostSession_);
650     window_->TriggerBindModalUIExtension();
651 }
652 
653 /**
654  * @tc.name: SetPrivacyMode01
655  * @tc.desc: SetPrivacyMode Test
656  * @tc.type: FUNC
657  */
658 HWTEST_F(WindowExtensionSessionImplTest, SetPrivacyMode01, TestSize.Level1)
659 {
660     ASSERT_EQ(WMError::WM_OK, window_->SetPrivacyMode(false));
661     ASSERT_FALSE(window_->extensionWindowFlags_.privacyModeFlag);
662     ASSERT_EQ(WMError::WM_OK, window_->SetPrivacyMode(true));
663     ASSERT_TRUE(window_->extensionWindowFlags_.privacyModeFlag);
664 }
665 
666 /**
667  * @tc.name: SetPrivacyMode02
668  * @tc.desc: SetPrivacyMod
669  * @tc.type: FUNC
670  */
671 HWTEST_F(WindowExtensionSessionImplTest, SetPrivacyMod02, TestSize.Level1)
672 {
673     bool isPrivacyMode = true;
674     window_->surfaceNode_ = nullptr;
675     auto ret = window_->SetPrivacyMode(isPrivacyMode);
676 
677     struct RSSurfaceNodeConfig config;
678 
679     if (ret == WMError::WM_ERROR_NULLPTR) {
680         window_->surfaceNode_ = RSSurfaceNode::Create(config);
681     }
682     ASSERT_NE(WMError::WM_OK, ret);
683 }
684 
685 /**
686  * @tc.name: SetPrivacyMod03
687  * @tc.desc: SetPrivacyMod03
688  * @tc.type: FUNC
689  */
690 HWTEST_F(WindowExtensionSessionImplTest, SetPrivacyMod03, TestSize.Level1)
691 {
692     struct RSSurfaceNodeConfig config;
693     window_->surfaceNode_ = RSSurfaceNode::Create(config);
694     window_->state_ = WindowState::STATE_SHOWN;
695     ASSERT_NE(WMError::WM_OK, window_->SetPrivacyMode(true));
696 }
697 
698 /**
699  * @tc.name: SetPrivacyMod04
700  * @tc.desc: SetPrivacyMod04
701  * @tc.type: FUNC
702  */
703 HWTEST_F(WindowExtensionSessionImplTest, SetPrivacyMod04, TestSize.Level1)
704 {
705     struct RSSurfaceNodeConfig config;
706     window_->surfaceNode_ = RSSurfaceNode::Create(config);
707     window_->state_ = WindowState::STATE_SHOWN;
708     ASSERT_NE(WMError::WM_ERROR_INVALID_WINDOW, window_->SetPrivacyMode(false));
709 }
710 
711 /**
712  * @tc.name: SetPrivacyMod05
713  * @tc.desc: SetPrivacyMod05
714  * @tc.type: FUNC
715  */
716 HWTEST_F(WindowExtensionSessionImplTest, SetPrivacyMod05, TestSize.Level1)
717 {
718     struct RSSurfaceNodeConfig config;
719     window_->surfaceNode_ = RSSurfaceNode::Create(config);
720     window_->state_ = WindowState::STATE_SHOWN;
721     SessionInfo sessionInfo;
722     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
723     ASSERT_NE(nullptr, window_->hostSession_);
724     ASSERT_NE(WMError::WM_OK, window_->SetPrivacyMode(true));
725 }
726 
727 HWTEST_F(WindowExtensionSessionImplTest, HidePrivacyContentForHost, TestSize.Level1)
728 {
729     struct RSSurfaceNodeConfig config;
730     window_->surfaceNode_ = RSSurfaceNode::Create(config);
731     SessionInfo sessionInfo;
732     window_->hostSession_ = new (std::nothrow) SessionMocker(sessionInfo);
733     ASSERT_NE(nullptr, window_->hostSession_);
734     ASSERT_EQ(WMError::WM_OK, window_->HidePrivacyContentForHost(true));
735 }
736 
737 /**
738  * @tc.name: NotifyFocusStateEvent01
739  * @tc.desc: NotifyFocusStateEvent Test
740  * @tc.type: FUNC
741  */
742 HWTEST_F(WindowExtensionSessionImplTest, NotifyFocusStateEvent01, TestSize.Level1)
743 {
744     ASSERT_NE(nullptr, window_);
745     window_->NotifyFocusStateEvent(false);
746 }
747 
748 /**
749  * @tc.name: NotifyFocusStateEvent02
750  * @tc.desc: NotifyFocusStateEvent Test
751  * @tc.type: FUNC
752  */
753 HWTEST_F(WindowExtensionSessionImplTest, NotifyFocusStateEvent02, TestSize.Level1)
754 {
755     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
756     ASSERT_NE(nullptr, window_->uiContent_);
757     window_->NotifyFocusStateEvent(true);
758     usleep(WAIT_SYNC_IN_NS);
759 }
760 
761 /**
762  * @tc.name: NotifyFocusActiveEvent01
763  * @tc.desc: NotifyFocusActiveEvent Test
764  * @tc.type: FUNC
765  */
766 HWTEST_F(WindowExtensionSessionImplTest, NotifyFocusActiveEvent01, TestSize.Level1)
767 {
768     ASSERT_NE(nullptr, window_);
769     window_->NotifyFocusActiveEvent(false);
770 }
771 
772 /**
773  * @tc.name: NotifyFocusActiveEvent02
774  * @tc.desc: NotifyFocusActiveEvent Test
775  * @tc.type: FUNC
776  */
777 HWTEST_F(WindowExtensionSessionImplTest, NotifyFocusActiveEvent02, TestSize.Level1)
778 {
779     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
780     ASSERT_NE(nullptr, window_->uiContent_);
781     window_->NotifyFocusActiveEvent(true);
782     usleep(WAIT_SYNC_IN_NS);
783 }
784 
785 /**
786  * @tc.name: NotifyBackpressedEvent01
787  * @tc.desc: NotifyFocusActiveEvent Test
788  * @tc.type: FUNC
789  */
790 HWTEST_F(WindowExtensionSessionImplTest, NotifyBackpressedEvent01, TestSize.Level1)
791 {
792     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
793     ASSERT_NE(nullptr, window_->uiContent_);
794     bool isConsumed = false;
795     window_->NotifyBackpressedEvent(isConsumed);
796     usleep(WAIT_SYNC_IN_NS);
797 }
798 
799 /**
800  * @tc.name: NotifyBackpressedEvent02
801  * @tc.desc: NotifyFocusActiveEvent Test
802  * @tc.type: FUNC
803  */
804 HWTEST_F(WindowExtensionSessionImplTest, NotifyBackpressedEvent02, TestSize.Level1)
805 {
806     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
807     ASSERT_NE(nullptr, window_->uiContent_);
808     bool isConsumed = true;
809     window_->NotifyBackpressedEvent(isConsumed);
810     usleep(WAIT_SYNC_IN_NS);
811 }
812 
813 /**
814  * @tc.name: NotifyBackpressedEvent03
815  * @tc.desc: NotifyFocusActiveEvent Test
816  * @tc.type: FUNC
817  */
818 HWTEST_F(WindowExtensionSessionImplTest, NotifyBackpressedEvent03, TestSize.Level1)
819 {
820     ASSERT_NE(nullptr, window_);
821     window_->uiContent_ = nullptr;
822     bool isConsumed = true;
823     window_->NotifyBackpressedEvent(isConsumed);
824     usleep(WAIT_SYNC_IN_NS);
825 }
826 
827 /**
828  * @tc.name: InputMethodKeyEventResultCallback01
829  * @tc.desc: InputMethodKeyEventResultCallback01 Test
830  * @tc.type: FUNC
831  */
832 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback01, TestSize.Level1)
833 {
834     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
835     bool consumed = false;
836     auto isConsumedPromise = std::make_shared<std::promise<bool>>();
837     auto isTimeout = std::make_shared<bool>(false);
838     ASSERT_NE(nullptr, window_);
839     window_->InputMethodKeyEventResultCallback(keyEvent, consumed, isConsumedPromise, isTimeout);
840 }
841 
842 /**
843  * @tc.name: InputMethodKeyEventResultCallback02
844  * @tc.desc: InputMethodKeyEventResultCallback02 Test
845  * @tc.type: FUNC
846  */
847 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback02, TestSize.Level1)
848 {
849     bool consumed = false;
850     auto isConsumedPromise = std::make_shared<std::promise<bool>>();
851     auto isTimeout = std::make_shared<bool>(false);
852     ASSERT_NE(nullptr, window_);
853     window_->InputMethodKeyEventResultCallback(nullptr, consumed, isConsumedPromise, isTimeout);
854 }
855 
856 /**
857  * @tc.name: InputMethodKeyEventResultCallback03
858  * @tc.desc: InputMethodKeyEventResultCallback03 Test
859  * @tc.type: FUNC
860  */
861 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback03, TestSize.Level1)
862 {
863     bool consumed = false;
864     auto isTimeout = std::make_shared<bool>(false);
865     ASSERT_NE(nullptr, window_);
866     window_->InputMethodKeyEventResultCallback(nullptr, consumed, nullptr, isTimeout);
867 }
868 
869 /**
870  * @tc.name: InputMethodKeyEventResultCallback04
871  * @tc.desc: InputMethodKeyEventResultCallback04 Test
872  * @tc.type: FUNC
873  */
874 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback04, TestSize.Level1)
875 {
876     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
877     bool consumed = false;
878     auto isTimeout = std::make_shared<bool>(false);
879     ASSERT_NE(nullptr, window_);
880     window_->InputMethodKeyEventResultCallback(keyEvent, consumed, nullptr, isTimeout);
881 }
882 
883 /**
884  * @tc.name: InputMethodKeyEventResultCallback05
885  * @tc.desc: InputMethodKeyEventResultCallback05 Test
886  * @tc.type: FUNC
887  */
888 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback05, TestSize.Level1)
889 {
890     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
891     bool consumed = false;
892     auto isConsumedPromise = std::make_shared<std::promise<bool>>();
893     ASSERT_NE(nullptr, window_);
894     window_->InputMethodKeyEventResultCallback(keyEvent, consumed, isConsumedPromise, nullptr);
895 }
896 
897 /**
898  * @tc.name: InputMethodKeyEventResultCallback06
899  * @tc.desc: InputMethodKeyEventResultCallback06 Test
900  * @tc.type: FUNC
901  */
902 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback06, TestSize.Level1)
903 {
904     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
905     auto isConsumedPromise = std::make_shared<std::promise<bool>>();
906     auto isTimeout = std::make_shared<bool>(false);
907     ASSERT_NE(nullptr, window_);
908     window_->InputMethodKeyEventResultCallback(keyEvent, true, isConsumedPromise, isTimeout);
909 }
910 
911 /**
912  * @tc.name: InputMethodKeyEventResultCallback07
913  * @tc.desc: InputMethodKeyEventResultCallback07 Test
914  * @tc.type: FUNC
915  */
916 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback07, TestSize.Level1)
917 {
918     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
919     auto isConsumedPromise = std::make_shared<std::promise<bool>>();
920     auto isTimeout = std::make_shared<bool>(true);
921     ASSERT_NE(nullptr, window_);
922     window_->InputMethodKeyEventResultCallback(keyEvent, true, isConsumedPromise, isTimeout);
923 }
924 
925 /**
926  * @tc.name: NotifyKeyEvent01
927  * @tc.desc: NotifyKeyEvent01 Test
928  * @tc.type: FUNC
929  */
930 HWTEST_F(WindowExtensionSessionImplTest, NotifyKeyEvent01, TestSize.Level0)
931 {
932     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
933     keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_FN);
934     bool consumed = false;
935     bool notifyInputMethod = true;
936     ASSERT_NE(nullptr, window_);
937     window_->NotifyKeyEvent(keyEvent, consumed, notifyInputMethod);
938 }
939 
940 /**
941  * @tc.name: NotifyKeyEvent02
942  * @tc.desc: NotifyKeyEvent02 Test
943  * @tc.type: FUNC
944  */
945 HWTEST_F(WindowExtensionSessionImplTest, NotifyKeyEvent02, TestSize.Level1)
946 {
947     bool consumed = false;
948     bool notifyInputMethod = true;
949     ASSERT_NE(nullptr, window_);
950     window_->NotifyKeyEvent(nullptr, consumed, notifyInputMethod);
951 }
952 
953 /**
954  * @tc.name: NotifyKeyEvent03
955  * @tc.desc: NotifyKeyEvent03 Test
956  * @tc.type: FUNC
957  */
958 HWTEST_F(WindowExtensionSessionImplTest, NotifyKeyEvent03, TestSize.Level1)
959 {
960     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
961     bool consumed = false;
962     bool notifyInputMethod = true;
963     ASSERT_NE(nullptr, window_);
964     window_->NotifyKeyEvent(keyEvent, consumed, notifyInputMethod);
965 }
966 
967 /**
968  * @tc.name: NotifyKeyEvent04
969  * @tc.desc: NotifyKeyEvent04 Test
970  * @tc.type: FUNC
971  */
972 HWTEST_F(WindowExtensionSessionImplTest, NotifyKeyEvent04, TestSize.Level1)
973 {
974     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
975     keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_FN);
976     bool consumed = false;
977     bool notifyInputMethod = false;
978     ASSERT_NE(nullptr, window_);
979     window_->NotifyKeyEvent(keyEvent, consumed, notifyInputMethod);
980 }
981 
982 /**
983  * @tc.name: NotifyKeyEvent05
984  * @tc.desc: NotifyKeyEvent05 Test branch: uiExtensionUsage_ == UIExtensionUsage::PREVIEW_EMBEDDED
985  * @tc.type: FUNC
986  */
987 HWTEST_F(WindowExtensionSessionImplTest, NotifyKeyEvent05, TestSize.Level1)
988 {
989     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
990     bool consumed = false;
991     bool notifyInputMethod = false;
992     ASSERT_NE(nullptr, window_);
993     window_->property_->SetUIExtensionUsage(UIExtensionUsage::PREVIEW_EMBEDDED);
994     window_->NotifyKeyEvent(keyEvent, consumed, notifyInputMethod);
995     ASSERT_EQ(false, consumed);
996 }
997 
998 /**
999  * @tc.name: ArkUIFrameworkSupport01
1000  * @tc.desc: ArkUIFrameworkSupport01 Test, context_ is nullptr
1001  * @tc.type: FUNC
1002  */
1003 HWTEST_F(WindowExtensionSessionImplTest, ArkUIFrameworkSupport01, TestSize.Level1)
1004 {
1005     ASSERT_NE(nullptr, window_);
1006     window_->context_ = nullptr;
1007     window_->ArkUIFrameworkSupport();
1008 }
1009 
1010 /**
1011  * @tc.name: ArkUIFrameworkSupport02
1012  * @tc.desc: ArkUIFrameworkSupport02 Test, context_->GetApplicationInfo() == nullptr
1013  * @tc.type: FUNC
1014  */
1015 HWTEST_F(WindowExtensionSessionImplTest, ArkUIFrameworkSupport02, TestSize.Level1)
1016 {
1017     ASSERT_NE(nullptr, window_);
1018     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
1019     ASSERT_NE(nullptr, abilityContext);
1020     abilityContext->stageContext_ = nullptr;
1021     window_->context_ = abilityContext;
1022     window_->ArkUIFrameworkSupport();
1023 }
1024 
1025 /**
1026  * @tc.name: ArkUIFrameworkSupport03
1027  * @tc.desc: ArkUIFrameworkSupport03 Test, version < 10 and isSystembarPropertiesSet_ is true
1028  * @tc.type: FUNC
1029  */
1030 HWTEST_F(WindowExtensionSessionImplTest, ArkUIFrameworkSupport03, TestSize.Level1)
1031 {
1032     ASSERT_NE(nullptr, window_);
1033     window_->context_ = nullptr;
1034     window_->isSystembarPropertiesSet_ = true;
1035     window_->ArkUIFrameworkSupport();
1036 }
1037 
1038 /**
1039  * @tc.name: ArkUIFrameworkSupport04
1040  * @tc.desc: ArkUIFrameworkSupport04 Test, version < 10 and isSystembarPropertiesSet_ is false
1041  * @tc.type: FUNC
1042  */
1043 HWTEST_F(WindowExtensionSessionImplTest, ArkUIFrameworkSupport04, TestSize.Level1)
1044 {
1045     ASSERT_NE(nullptr, window_);
1046     window_->context_ = nullptr;
1047     window_->isSystembarPropertiesSet_ = false;
1048     window_->ArkUIFrameworkSupport();
1049 }
1050 
1051 /**
1052  * @tc.name: ArkUIFrameworkSupport05
1053  * @tc.desc: ArkUIFrameworkSupport05 Test, version >= 10 and isIgnoreSafeAreaNeedNotify_ is false
1054  * @tc.type: FUNC
1055  */
1056 HWTEST_F(WindowExtensionSessionImplTest, ArkUIFrameworkSupport05, TestSize.Level1)
1057 {
1058     ASSERT_NE(nullptr, window_);
1059     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
1060     ASSERT_NE(nullptr, abilityContext);
1061     auto stageContent = std::make_shared<AbilityRuntime::ContextImpl>();
1062     ASSERT_NE(nullptr, stageContent);
1063     std::shared_ptr<AppExecFwk::ApplicationInfo> applicationInfo = std::make_shared<AppExecFwk::ApplicationInfo>();
1064     ASSERT_NE(nullptr, applicationInfo);
1065     applicationInfo->apiCompatibleVersion = 12;
1066     stageContent->SetApplicationInfo(applicationInfo);
1067     abilityContext->stageContext_ = stageContent;
1068     window_->context_ = abilityContext;
1069     window_->isIgnoreSafeAreaNeedNotify_ = false;
1070     window_->ArkUIFrameworkSupport();
1071 }
1072 
1073 /**
1074  * @tc.name: ArkUIFrameworkSupport06
1075  * @tc.desc: ArkUIFrameworkSupport06 Test, version >= 10 and isIgnoreSafeAreaNeedNotify_ is true
1076  * @tc.type: FUNC
1077  */
1078 HWTEST_F(WindowExtensionSessionImplTest, ArkUIFrameworkSupport06, TestSize.Level1)
1079 {
1080     ASSERT_NE(nullptr, window_);
1081     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
1082     ASSERT_NE(nullptr, abilityContext);
1083     auto stageContent = std::make_shared<AbilityRuntime::ContextImpl>();
1084     ASSERT_NE(nullptr, stageContent);
1085     std::shared_ptr<AppExecFwk::ApplicationInfo> applicationInfo = std::make_shared<AppExecFwk::ApplicationInfo>();
1086     ASSERT_NE(nullptr, applicationInfo);
1087     applicationInfo->apiCompatibleVersion = 12;
1088     stageContent->SetApplicationInfo(applicationInfo);
1089     abilityContext->stageContext_ = stageContent;
1090     window_->context_ = abilityContext;
1091     window_->isIgnoreSafeAreaNeedNotify_ = true;
1092     window_->ArkUIFrameworkSupport();
1093 }
1094 
1095 /**
1096  * @tc.name: NapiSetUIContent
1097  * @tc.desc: NapiSetUIContent Test
1098  * @tc.type: FUNC
1099  */
1100 HWTEST_F(WindowExtensionSessionImplTest, NapiSetUIContent, Function | SmallTest | Level3)
1101 {
1102     ASSERT_NE(nullptr, window_);
1103     std::string contentInfo = "NapiSetUIContent test";
1104     napi_env env = napi_env();
1105     napi_value storage = napi_value();
1106     sptr<IRemoteObject> token;
1107     window_->uiContent_ = nullptr;
1108     window_->property_->SetUIExtensionUsage(UIExtensionUsage::UIEXTENSION_USAGE_END);
1109     window_->focusState_ = std::nullopt;
1110     window_->state_ = WindowState::STATE_HIDDEN;
1111     ASSERT_EQ(WMError::WM_OK,
1112         window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
1113 
1114     auto uiContent = std::make_shared<Ace::UIContentMocker>();
1115     ASSERT_NE(nullptr, uiContent);
1116     window_->uiContent_ = uiContent;
1117     window_->property_->SetUIExtensionUsage(UIExtensionUsage::CONSTRAINED_EMBEDDED);
1118     window_->focusState_ = true;
1119     window_->state_ = WindowState::STATE_SHOWN;
1120     ASSERT_EQ(WMError::WM_OK,
1121         window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
1122     usleep(WAIT_SYNC_IN_NS);
1123 
1124     window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
1125     ASSERT_EQ(WMError::WM_OK,
1126         window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
1127     window_->property_->SetUIExtensionUsage(UIExtensionUsage::EMBEDDED);
1128     ASSERT_EQ(WMError::WM_OK,
1129         window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
1130     window_->property_->SetUIExtensionUsage(UIExtensionUsage::PREVIEW_EMBEDDED);
1131     ASSERT_EQ(WMError::WM_OK,
1132         window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
1133     window_->property_->SetUIExtensionUsage(UIExtensionUsage::UIEXTENSION_USAGE_END);
1134     ASSERT_EQ(WMError::WM_OK,
1135         window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
1136 }
1137 
1138 /**
1139  * @tc.name: NapiSetUIContentByName
1140  * @tc.desc: NapiSetUIContentByName Test
1141  * @tc.type: FUNC
1142  */
1143 HWTEST_F(WindowExtensionSessionImplTest, NapiSetUIContentByName, Function | SmallTest | Level3)
1144 {
1145     ASSERT_NE(nullptr, window_);
1146     std::string contentInfo = "NapiSetUIContentByName test";
1147     napi_env env = napi_env();
1148     napi_value storage = napi_value();
1149     sptr<IRemoteObject> token;
1150     window_->uiContent_ = nullptr;
1151     window_->property_->SetUIExtensionUsage(UIExtensionUsage::UIEXTENSION_USAGE_END);
1152     window_->focusState_ = std::nullopt;
1153     window_->state_ = WindowState::STATE_HIDDEN;
1154     ASSERT_EQ(WMError::WM_OK,
1155         window_->NapiSetUIContentByName(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
1156 
1157     auto uiContent = std::make_shared<Ace::UIContentMocker>();
1158     window_->uiContent_ = uiContent;
1159     window_->property_->SetUIExtensionUsage(UIExtensionUsage::CONSTRAINED_EMBEDDED);
1160     window_->focusState_ = true;
1161     window_->state_ = WindowState::STATE_SHOWN;
1162     ASSERT_EQ(WMError::WM_OK,
1163         window_->NapiSetUIContentByName(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
1164     usleep(WAIT_SYNC_IN_NS);
1165 }
1166 
1167 /**
1168  * @tc.name: UpdateRect01
1169  * @tc.desc: UpdateRect Test
1170  * @tc.type: FUNC
1171  */
1172 HWTEST_F(WindowExtensionSessionImplTest, UpdateRect01, TestSize.Level0)
1173 {
1174     WSRect rect;
1175     rect.posX_ = 0;
1176     rect.posY_ = 0;
1177     rect.height_ = 50;
1178     rect.width_ = 50;
1179 
1180     Rect preRect;
1181     preRect.posX_ = 0;
1182     preRect.posY_ = 0;
1183     preRect.height_ = 200;
1184     preRect.width_ = 200;
1185 
1186     ASSERT_NE(nullptr, window_->property_);
1187     window_->property_->SetWindowRect(preRect);
1188     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1189     ASSERT_EQ(WSError::WS_OK, window_->UpdateRect(rect, reason));
1190 
1191     preRect.height_ = 50;
1192     window_->property_->SetWindowRect(preRect);
1193     ASSERT_EQ(WSError::WS_OK, window_->UpdateRect(rect, reason));
1194 
1195     preRect.height_ = 200;
1196     preRect.width_ = 50;
1197     window_->property_->SetWindowRect(preRect);
1198     ASSERT_EQ(WSError::WS_OK, window_->UpdateRect(rect, reason));
1199 
1200     preRect.height_ = 50;
1201     preRect.width_ = 50;
1202     window_->property_->SetWindowRect(preRect);
1203     reason = SizeChangeReason::ROTATION;
1204     ASSERT_EQ(WSError::WS_OK, window_->UpdateRect(rect, reason));
1205 
1206     window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
1207     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, window_->UpdateRect(rect, reason));
1208 }
1209 
1210 /**
1211  * @tc.name: NotifyAccessibilityHoverEvent01
1212  * @tc.desc: NotifyAccessibilityHoverEvent Test
1213  * @tc.type: FUNC
1214  */
1215 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityHoverEvent01, TestSize.Level1)
1216 {
1217     float pointX = 0.0f;
1218     float pointY = 0.0f;
1219     int32_t sourceType = 0;
1220     int32_t eventType = 0;
1221     int64_t timeMs = 0;
1222     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1223     ASSERT_NE(nullptr, window_->uiContent_);
1224     ASSERT_EQ(WSError::WS_OK,
1225         window_->NotifyAccessibilityHoverEvent(pointX, pointY, sourceType, eventType, timeMs));
1226     usleep(WAIT_SYNC_IN_NS);
1227 }
1228 
1229 /**
1230  * @tc.name: NotifyAccessibilityHoverEvent02
1231  * @tc.desc: NotifyAccessibilityHoverEvent Test
1232  * @tc.type: FUNC
1233  */
1234 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityHoverEvent02, TestSize.Level1)
1235 {
1236     float pointX = 0.0f;
1237     float pointY = 0.0f;
1238     int32_t sourceType = 0;
1239     int32_t eventType = 0;
1240     int64_t timeMs = 0;
1241     window_->uiContent_ = nullptr;
1242     ASSERT_EQ(WSError::WS_ERROR_NO_UI_CONTENT_ERROR,
1243         window_->NotifyAccessibilityHoverEvent(pointX, pointY, sourceType, eventType, timeMs));
1244     usleep(WAIT_SYNC_IN_NS);
1245 }
1246 
1247 /**
1248  * @tc.name: TransferAccessibilityEvent
1249  * @tc.desc: TransferAccessibilityEvent Test
1250  * @tc.type: FUNC
1251  */
1252 HWTEST_F(WindowExtensionSessionImplTest, TransferAccessibilityEvent, TestSize.Level1)
1253 {
1254     SessionInfo sessionInfo;
1255     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1256     ASSERT_NE(nullptr, window_->hostSession_);
1257     Accessibility::AccessibilityEventInfo info;
1258     int64_t uiExtensionIdLevel = 1;
1259     ASSERT_NE(WMError::WM_OK, window_->TransferAccessibilityEvent(info, uiExtensionIdLevel));
1260 
1261     window_->hostSession_ = nullptr;
1262     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->TransferAccessibilityEvent(info, uiExtensionIdLevel));
1263 }
1264 
1265 /**
1266  * @tc.name: UpdateSessionViewportConfig1
1267  * @tc.desc: Normal test
1268  * @tc.type: FUNC
1269  */
1270 HWTEST_F(WindowExtensionSessionImplTest, UpdateSessionViewportConfig1, TestSize.Level0)
1271 {
1272     ASSERT_NE(nullptr, window_);
1273     ASSERT_NE(nullptr, window_->property_);
1274     window_->property_->SetDisplayId(0);
1275     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1276     ASSERT_NE(nullptr, window_->uiContent_);
1277 
1278     SessionViewportConfig config;
1279     window_->lastDensity_ = 1.0f;
1280     window_->lastOrientation_ = 0;
1281     config.isDensityFollowHost_ = true;
1282     config.density_ = 1.0f;
1283     config.orientation_ = 0;
1284     ASSERT_EQ(window_->UpdateSessionViewportConfig(config), WSError::WS_OK);
1285     usleep(WAIT_SYNC_IN_NS);
1286 
1287     window_->lastDensity_ = 1.0f;
1288     window_->lastOrientation_ = 0;
1289     config.density_ = 2.0f;
1290     config.orientation_ = 0;
1291     ASSERT_EQ(window_->UpdateSessionViewportConfig(config), WSError::WS_OK);
1292     usleep(WAIT_SYNC_IN_NS);
1293 
1294     window_->lastDensity_ = 1.0f;
1295     window_->lastOrientation_ = 0;
1296     config.density_ = 1.0f;
1297     config.orientation_ = 1;
1298     ASSERT_EQ(window_->UpdateSessionViewportConfig(config), WSError::WS_OK);
1299     usleep(WAIT_SYNC_IN_NS);
1300 
1301     config.isDensityFollowHost_ = false;
1302     window_->lastDensity_ = 0.0f;
1303     window_->lastOrientation_ = 0;
1304     config.density_ = 1.0f;
1305     config.orientation_ = 0;
1306     ASSERT_EQ(window_->UpdateSessionViewportConfig(config), WSError::WS_OK);
1307     usleep(WAIT_SYNC_IN_NS);
1308 }
1309 
1310 /**
1311  * @tc.name: UpdateSessionViewportConfig2
1312  * @tc.desc: invalid density
1313  * @tc.type: FUNC
1314  */
1315 HWTEST_F(WindowExtensionSessionImplTest, UpdateSessionViewportConfig2, TestSize.Level1)
1316 {
1317     ASSERT_NE(nullptr, window_);
1318     SessionViewportConfig config;
1319     config.isDensityFollowHost_ = true;
1320     config.density_ = -1.0f;
1321     ASSERT_EQ(window_->UpdateSessionViewportConfig(config), WSError::WS_ERROR_INVALID_PARAM);
1322 }
1323 
1324 /**
1325  * @tc.name: UpdateSessionViewportConfig3
1326  * @tc.desc: handler_ is null
1327  * @tc.type: FUNC
1328  */
1329 HWTEST_F(WindowExtensionSessionImplTest, UpdateSessionViewportConfig3, TestSize.Level1)
1330 {
1331     ASSERT_NE(nullptr, window_);
1332     SessionViewportConfig config;
1333     window_->handler_ = nullptr;
1334     ASSERT_EQ(window_->UpdateSessionViewportConfig(config), WSError::WS_ERROR_NULLPTR);
1335 }
1336 
1337 /**
1338  * @tc.name: UpdateSessionViewportConfig4
1339  * @tc.desc: displayId is changed
1340  * @tc.type: FUNC
1341  */
1342 HWTEST_F(WindowExtensionSessionImplTest, UpdateSessionViewportConfig4, TestSize.Level1)
1343 {
1344     window_->property_->SetDisplayId(0);
1345     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1346     ASSERT_NE(nullptr, window_->uiContent_);
1347 
1348     SessionViewportConfig config;
1349     window_->lastDensity_ = 1.0f;
1350     window_->lastOrientation_ = 0;
1351     config.density_ = 1.0f;
1352     config.orientation_ = 0;
1353     config.displayId_ = 999;
1354     ASSERT_EQ(window_->UpdateSessionViewportConfig(config), WSError::WS_OK);
1355     usleep(WAIT_SYNC_IN_NS);
1356     ASSERT_EQ(999, window_->GetDisplayId());
1357 }
1358 
1359 /**
1360  * @tc.name: UpdateSystemViewportConfig1
1361  * @tc.desc: handler_ is null
1362  * @tc.type: FUNC
1363  */
1364 HWTEST_F(WindowExtensionSessionImplTest, UpdateSystemViewportConfig1, TestSize.Level1)
1365 {
1366     ASSERT_NE(nullptr, window_);
1367     window_->handler_ = nullptr;
1368     window_->UpdateSystemViewportConfig();
1369 }
1370 
1371 /**
1372  * @tc.name: UpdateSystemViewportConfig2
1373  * @tc.desc: Follow host
1374  * @tc.type: FUNC
1375  */
1376 HWTEST_F(WindowExtensionSessionImplTest, UpdateSystemViewportConfig2, TestSize.Level1)
1377 {
1378     ASSERT_NE(nullptr, window_);
1379     window_->isDensityFollowHost_ = true;
1380     window_->UpdateSystemViewportConfig();
1381     usleep(WAIT_SYNC_IN_NS);
1382 }
1383 
1384 /**
1385  * @tc.name: UpdateSystemViewportConfig3
1386  * @tc.desc: Do not follow host
1387  * @tc.type: FUNC
1388  */
1389 HWTEST_F(WindowExtensionSessionImplTest, UpdateSystemViewportConfig3, TestSize.Level1)
1390 {
1391     ASSERT_NE(nullptr, window_->property_);
1392     window_->isDensityFollowHost_ = false;
1393     window_->property_->SetDisplayId(0);
1394     window_->UpdateSystemViewportConfig();
1395     usleep(WAIT_SYNC_IN_NS);
1396 }
1397 
1398 /**
1399  * @tc.name: NotifyDisplayInfoChange1
1400  * @tc.desc: Normal test
1401  * @tc.type: FUNC
1402  */
1403 HWTEST_F(WindowExtensionSessionImplTest, NotifyDisplayInfoChange1, TestSize.Level1)
1404 {
1405     ASSERT_NE(nullptr, window_);
1406     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
1407     ASSERT_NE(nullptr, abilityContext);
1408     sptr<IRemoteObject> contextToken = sptr<IRemoteObjectMocker>::MakeSptr();
1409     abilityContext->SetToken(contextToken);
1410     window_->context_ = abilityContext;
1411     EXPECT_NE(nullptr, window_->context_->GetToken());
1412     SessionViewportConfig config;
1413     config.displayId_ = 999;
1414     window_->lastDisplayId_ = 0;
1415     window_->NotifyDisplayInfoChange(config);
1416     window_->lastDisplayId_ = 999;
1417     window_->NotifyDisplayInfoChange(config);
1418 }
1419 
1420 /**
1421  * @tc.name: NotifyDisplayInfoChange2
1422  * @tc.desc: context_ is nullptr
1423  * @tc.type: FUNC
1424  */
1425 HWTEST_F(WindowExtensionSessionImplTest, NotifyDisplayInfoChange2, TestSize.Level1)
1426 {
1427     ASSERT_NE(nullptr, window_);
1428     window_->context_ = nullptr;
1429     SessionViewportConfig config;
1430     window_->NotifyDisplayInfoChange(config);
1431 }
1432 
1433 /**
1434  * @tc.name: NotifyDisplayInfoChange3
1435  * @tc.desc: system demsity change
1436  * @tc.type: FUNC
1437  */
1438 HWTEST_F(WindowExtensionSessionImplTest, NotifyDisplayInfoChange3, TestSize.Level1)
1439 {
1440     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1441     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
1442     SessionViewportConfig config;
1443     config.displayId_ = -1ULL;
1444     auto lastDensity = window->lastSystemDensity_;
1445     window->NotifyDisplayInfoChange(config);
1446     EXPECT_EQ(lastDensity, window->lastSystemDensity_);
1447 
1448     config.displayId_ = 0;
1449     auto display = SingletonContainer::Get<DisplayManager>().GetDisplayById(config.displayId_);
1450     ASSERT_NE(nullptr, display);
1451     auto displayInfo = display->GetDisplayInfo();
1452     ASSERT_NE(nullptr, displayInfo);
1453     auto vpr = displayInfo->GetVirtualPixelRatio();
1454     window->NotifyDisplayInfoChange(config);
1455     EXPECT_EQ(vpr, window->lastSystemDensity_);
1456     window->lastSystemDensity_ = vpr;
1457     window->NotifyDisplayInfoChange(config);
1458     EXPECT_EQ(vpr, window->lastSystemDensity_);
1459 }
1460 
1461 /**
1462  * @tc.name: NotifyAccessibilityChildTreeRegister01
1463  * @tc.desc: NotifyAccessibilityChildTreeRegister Test
1464  * @tc.type: FUNC
1465  */
1466 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityChildTreeRegister01, TestSize.Level1)
1467 {
1468     uint32_t windowId = 0;
1469     int32_t treeId = 0;
1470     int64_t accessibilityId = 0;
1471     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1472     ASSERT_NE(nullptr, window_->uiContent_);
1473     auto ret = window_->NotifyAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
1474     ASSERT_EQ(WSError::WS_OK, ret);
1475 
1476     window_->uiContent_ = nullptr;
1477     ret = window_->NotifyAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
1478     ASSERT_EQ(WSError::WS_OK, ret);
1479 
1480     window_->handler_ = nullptr;
1481     ret = window_->NotifyAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
1482     ASSERT_EQ(WSError::WS_ERROR_INTERNAL_ERROR, ret);
1483     usleep(WAIT_SYNC_IN_NS);
1484 }
1485 
1486 /**
1487  * @tc.name: NotifyAccessibilityChildTreeUnregister01
1488  * @tc.desc: NotifyAccessibilityChildTreeUnregister Test
1489  * @tc.type: FUNC
1490  */
1491 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityChildTreeUnregister01, TestSize.Level1)
1492 {
1493     window_->uiContent_ = nullptr;
1494     ASSERT_EQ(WSError::WS_OK, window_->NotifyAccessibilityChildTreeUnregister());
1495 
1496     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1497     ASSERT_NE(nullptr, window_->uiContent_);
1498     ASSERT_EQ(WSError::WS_OK, window_->NotifyAccessibilityChildTreeUnregister());
1499 
1500     window_->handler_ = nullptr;
1501     ASSERT_EQ(WSError::WS_ERROR_INTERNAL_ERROR, window_->NotifyAccessibilityChildTreeUnregister());
1502     usleep(WAIT_SYNC_IN_NS);
1503 }
1504 
1505 /**
1506  * @tc.name: NotifyAccessibilityDumpChildInfo01
1507  * @tc.desc: NotifyAccessibilityDumpChildInfo Test
1508  * @tc.type: FUNC
1509  */
1510 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityDumpChildInfo01, TestSize.Level1)
1511 {
1512     std::vector<std::string> params;
1513     std::vector<std::string> info;
1514     window_->uiContent_ = nullptr;
1515     ASSERT_EQ(WSError::WS_OK, window_->NotifyAccessibilityDumpChildInfo(params, info));
1516 
1517     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1518     ASSERT_NE(nullptr, window_->uiContent_);
1519     ASSERT_EQ(WSError::WS_OK, window_->NotifyAccessibilityDumpChildInfo(params, info));
1520 
1521     window_->handler_ = nullptr;
1522     ASSERT_EQ(WSError::WS_ERROR_INTERNAL_ERROR, window_->NotifyAccessibilityDumpChildInfo(params, info));
1523     usleep(WAIT_SYNC_IN_NS);
1524 }
1525 
1526 /**
1527  * @tc.name: UpdateAccessibilityTreeInfo
1528  * @tc.desc: UpdateAccessibilityTreeInfo Test
1529  * @tc.type: FUNC
1530  */
1531 HWTEST_F(WindowExtensionSessionImplTest, UpdateAccessibilityTreeInfo, TestSize.Level1)
1532 {
1533     std::optional<AccessibilityChildTreeInfo> accessibilityChildTreeInfo =
1534 		std::make_optional<AccessibilityChildTreeInfo>();
1535     ASSERT_NE(accessibilityChildTreeInfo, std::nullopt);
1536     window_->accessibilityChildTreeInfo_ = accessibilityChildTreeInfo;
1537     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1538     ASSERT_NE(nullptr, window_->uiContent_);
1539     window_->UpdateAccessibilityTreeInfo();
1540 
1541     window_->uiContent_ = nullptr;
1542     window_->UpdateAccessibilityTreeInfo();
1543 
1544     window_->accessibilityChildTreeInfo_= std::nullopt;
1545     window_->UpdateAccessibilityTreeInfo();
1546     usleep(WAIT_SYNC_IN_NS);
1547 }
1548 
1549 /**
1550  * @tc.name: NotifyOccupiedAreaChangeInfo01
1551  * @tc.desc: NotifyExecuteAction Test
1552  * @tc.type: FUNC
1553  */
1554 HWTEST_F(WindowExtensionSessionImplTest, NotifyOccupiedAreaChangeInfo01, TestSize.Level1)
1555 {
1556     sptr<OccupiedAreaChangeInfo> info = new(std::nothrow) OccupiedAreaChangeInfo();
1557     ASSERT_NE(nullptr, info);
1558     window_->NotifyOccupiedAreaChangeInfo(info, nullptr, {}, {});
1559 }
1560 
1561 /**
1562  * @tc.name: NotifyOccupiedAreaChangeInfo02
1563  * @tc.desc: NotifyExecuteAction Test
1564  * @tc.type: FUNC
1565  */
1566 HWTEST_F(WindowExtensionSessionImplTest, NotifyOccupiedAreaChangeInfo02, TestSize.Level1)
1567 {
1568     sptr<IOccupiedAreaChangeListener> iOccupiedAreaChangeListener = new(std::nothrow) IOccupiedAreaChangeListener();
1569     ASSERT_NE(nullptr, iOccupiedAreaChangeListener);
1570     window_->RegisterOccupiedAreaChangeListener(iOccupiedAreaChangeListener);
1571     sptr<OccupiedAreaChangeInfo> info = new(std::nothrow) OccupiedAreaChangeInfo();
1572     ASSERT_NE(nullptr, info);
1573     window_->NotifyOccupiedAreaChangeInfo(info, nullptr, {}, {});
1574 }
1575 
1576 /**
1577  * @tc.name: GetAvoidAreaByType01
1578  * @tc.desc: NotifyExecuteAction Test
1579  * @tc.type: FUNC
1580  */
1581 HWTEST_F(WindowExtensionSessionImplTest, GetAvoidAreaByType01, TestSize.Level0)
1582 {
1583     AvoidAreaType avoidAreaType = AvoidAreaType::TYPE_SYSTEM;
1584     AvoidArea avoidArea;
1585     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1586     avoidAreaType = AvoidAreaType::TYPE_CUTOUT;
1587     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1588     avoidAreaType = AvoidAreaType::TYPE_SYSTEM_GESTURE;
1589     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1590     avoidAreaType = AvoidAreaType::TYPE_KEYBOARD;
1591     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1592     avoidAreaType = AvoidAreaType::TYPE_NAVIGATION_INDICATOR;
1593     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1594 }
1595 
1596 /**
1597  * @tc.name: GetAvoidAreaByType02
1598  * @tc.desc: NotifyExecuteAction Test
1599  * @tc.type: FUNC
1600  */
1601 HWTEST_F(WindowExtensionSessionImplTest, GetAvoidAreaByType02, TestSize.Level1)
1602 {
1603     SessionInfo sessionInfo;
1604     sptr<SessionMocker> mockHostSession = sptr<SessionMocker>::MakeSptr(sessionInfo);
1605     ASSERT_NE(mockHostSession, nullptr);
1606     window_->hostSession_ = mockHostSession;
1607     AvoidAreaType avoidAreaType = AvoidAreaType::TYPE_SYSTEM;
1608     AvoidArea avoidArea;
1609     EXPECT_CALL(*mockHostSession, GetAvoidAreaByType).Times(5);
1610     ASSERT_EQ(WMError::WM_OK, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1611     avoidAreaType = AvoidAreaType::TYPE_CUTOUT;
1612     ASSERT_EQ(WMError::WM_OK, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1613     avoidAreaType = AvoidAreaType::TYPE_SYSTEM_GESTURE;
1614     ASSERT_EQ(WMError::WM_OK, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1615     avoidAreaType = AvoidAreaType::TYPE_KEYBOARD;
1616     ASSERT_EQ(WMError::WM_OK, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1617     avoidAreaType = AvoidAreaType::TYPE_NAVIGATION_INDICATOR;
1618     ASSERT_EQ(WMError::WM_OK, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1619 
1620     AvoidArea expectedAvoidArea;
1621     expectedAvoidArea.topRect_ = {10, 20, 30, 40};
1622     EXPECT_CALL(*mockHostSession, GetAvoidAreaByType).Times(1).WillOnce(Return(expectedAvoidArea));
1623     ASSERT_EQ(WMError::WM_OK, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1624     ASSERT_EQ(avoidArea, expectedAvoidArea);
1625 }
1626 
1627 /**
1628  * @tc.name: RegisterAvoidAreaChangeListener
1629  * @tc.desc: RegisterAvoidAreaChangeListener Test
1630  * @tc.type: FUNC
1631  */
1632 HWTEST_F(WindowExtensionSessionImplTest, RegisterAvoidAreaChangeListener, TestSize.Level1)
1633 {
1634     sptr<IAvoidAreaChangedListener> listener = nullptr;
1635     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->RegisterAvoidAreaChangeListener(listener));
1636 }
1637 
1638 /**
1639  * @tc.name: UnregisterAvoidAreaChangeListener
1640  * @tc.desc: UnregisterAvoidAreaChangeListener Test
1641  * @tc.type: FUNC
1642  */
1643 HWTEST_F(WindowExtensionSessionImplTest, UnregisterAvoidAreaChangeListener, TestSize.Level1)
1644 {
1645     sptr<IAvoidAreaChangedListener> listener = nullptr;
1646     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->UnregisterAvoidAreaChangeListener(listener));
1647 }
1648 
1649 /**
1650  * @tc.name: Show
1651  * @tc.desc: Show
1652  * @tc.type: FUNC
1653  */
1654 HWTEST_F(WindowExtensionSessionImplTest, Show, TestSize.Level0)
1655 {
1656     ASSERT_NE(nullptr, window_->property_);
1657     window_->property_->persistentId_ = 12345;
1658 
1659     SessionInfo sessionInfo;
1660     sptr<SessionMocker> mockHostSession = new (std::nothrow) SessionMocker(sessionInfo);
1661     ASSERT_NE(mockHostSession, nullptr);
1662     window_->hostSession_ = mockHostSession;
1663 
1664     window_->property_->SetDisplayId(0);
1665     EXPECT_CALL(*mockHostSession, Foreground).Times(1).WillOnce(Return(WSError::WS_DO_NOTHING));
1666     ASSERT_EQ(static_cast<WMError>(WSError::WS_DO_NOTHING), window_->Show());
1667     EXPECT_CALL(*mockHostSession, Foreground).Times(1).WillOnce(Return(WSError::WS_OK));
1668     ASSERT_EQ(WMError::WM_OK, window_->Show());
1669 }
1670 
1671 /**
1672  * @tc.name: Hide
1673  * @tc.desc: Hide
1674  * @tc.type: FUNC
1675  */
1676 HWTEST_F(WindowExtensionSessionImplTest, Hide, TestSize.Level0)
1677 {
1678     ASSERT_NE(nullptr, window_->property_);
1679 
1680     SessionInfo sessionInfo;
1681     sptr<SessionMocker> mockHostSession = new (std::nothrow) SessionMocker(sessionInfo);
1682     ASSERT_NE(mockHostSession, nullptr);
1683     window_->hostSession_ = mockHostSession;
1684 
1685     window_->property_->persistentId_ = INVALID_SESSION_ID;
1686     auto res = window_->Hide(0, false, false);
1687     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1688 
1689     window_->property_->persistentId_ = 12345;
1690     window_->state_ = WindowState::STATE_HIDDEN;
1691     EXPECT_CALL(*mockHostSession, Background).Times(0);
1692     res = window_->Hide(0, false, false);
1693     ASSERT_EQ(res, WMError::WM_OK);
1694 
1695     window_->state_ = WindowState::STATE_CREATED;
1696     EXPECT_CALL(*mockHostSession, Background).Times(0);
1697     res = window_->Hide(0, false, false);
1698     ASSERT_EQ(res, WMError::WM_OK);
1699 
1700     window_->state_ = WindowState::STATE_SHOWN;
1701     EXPECT_CALL(*mockHostSession, Background).Times(1).WillOnce(Return(WSError::WS_OK));
1702     res = window_->Hide(0, false, false);
1703     ASSERT_EQ(res, WMError::WM_OK);
1704     ASSERT_EQ(window_->state_, WindowState::STATE_HIDDEN);
1705 
1706     window_->state_ = WindowState::STATE_SHOWN;
1707     EXPECT_CALL(*mockHostSession, Background).Times(1).WillOnce(Return(WSError::WS_DO_NOTHING));
1708     res = window_->Hide(0, false, false);
1709     ASSERT_EQ(res, WMError::WM_OK);
1710     ASSERT_EQ(window_->state_, WindowState::STATE_SHOWN);
1711 }
1712 
1713 /**
1714  * @tc.name: NotifyDensityFollowHost01
1715  * @tc.desc: test isFollowHost is true
1716  * @tc.type: FUNC
1717  */
1718 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost01, TestSize.Level1)
1719 {
1720     DisplayId displayId = 0;
1721     ASSERT_NE(nullptr, window_->property_);
1722     window_->property_->SetDisplayId(displayId);
1723 
1724     auto isFollowHost = true;
1725     auto densityValue = 0.1f;
1726 
1727     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1728     ASSERT_NE(nullptr, window_->uiContent_);
1729     Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
1730     Rect preRect;
1731     preRect.posX_ = 0;
1732     preRect.posY_ = 0;
1733     preRect.height_ = 200;
1734     preRect.width_ = 200;
1735     window_->property_->SetWindowRect(preRect);
1736     EXPECT_CALL(*content, UpdateViewportConfig(Field(&Ace::ViewportConfig::density_, densityValue), _, _, _, _));
1737 
1738     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1739     usleep(WAIT_SYNC_IN_NS);
1740 }
1741 
1742 /**
1743  * @tc.name: NotifyDensityFollowHost02
1744  * @tc.desc: test isFollowHost is true -> false
1745  * @tc.type: FUNC
1746  */
1747 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost02, TestSize.Level1)
1748 {
1749     DisplayId displayId = 0;
1750     ASSERT_NE(nullptr, window_->property_);
1751     window_->property_->SetDisplayId(displayId);
1752 
1753     auto isFollowHost = false;
1754     auto densityValue = 0.1f;
1755 
1756     auto display = SingletonContainer::Get<DisplayManager>().GetDisplayById(window_->property_->GetDisplayId());
1757     ASSERT_NE(display, nullptr);
1758     ASSERT_NE(display->GetDisplayInfo(), nullptr);
1759     auto vpr = display->GetDisplayInfo()->GetVirtualPixelRatio();
1760 
1761     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1762     ASSERT_NE(nullptr, window_->uiContent_);
1763     Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
1764     Rect preRect;
1765     preRect.posX_ = 0;
1766     preRect.posY_ = 0;
1767     preRect.height_ = 100;
1768     preRect.width_ = 100;
1769     window_->property_->SetWindowRect(preRect);
1770     EXPECT_CALL(*content, UpdateViewportConfig(Field(&Ace::ViewportConfig::density_, vpr), _, _, _, _));
1771 
1772     window_->isDensityFollowHost_ = true;
1773     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1774     usleep(WAIT_SYNC_IN_NS);
1775 }
1776 
1777 /**
1778  * @tc.name: NotifyDensityFollowHost03
1779  * @tc.desc: test isFollowHost not change
1780  * @tc.type: FUNC
1781  */
1782 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost03, TestSize.Level1)
1783 {
1784     DisplayId displayId = 0;
1785     ASSERT_NE(nullptr, window_->property_);
1786     window_->property_->SetDisplayId(displayId);
1787 
1788     auto isFollowHost = false;
1789     auto densityValue = 0.1f;
1790     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1791     ASSERT_NE(nullptr, window_->uiContent_);
1792     Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
1793     EXPECT_CALL(*content, UpdateViewportConfig(_, _, _, _, _)).Times(0);
1794 
1795     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1796     usleep(WAIT_SYNC_IN_NS);
1797 }
1798 
1799 /**
1800  * @tc.name: NotifyDensityFollowHost04
1801  * @tc.desc: test densityValue invalid
1802  * @tc.type: FUNC
1803  */
1804 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost04, TestSize.Level1)
1805 {
1806     DisplayId displayId = 0;
1807     ASSERT_NE(nullptr, window_->property_);
1808     window_->property_->SetDisplayId(displayId);
1809 
1810     auto isFollowHost = true;
1811     auto densityValue = 0.0f;
1812     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_ERROR_INVALID_PARAM);
1813     densityValue = -0.1f;
1814     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_ERROR_INVALID_PARAM);
1815 }
1816 
1817 /**
1818  * @tc.name: NotifyDensityFollowHost05
1819  * @tc.desc: test densityValue not change
1820  * @tc.type: FUNC
1821  */
1822 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost05, TestSize.Level1)
1823 {
1824     DisplayId displayId = 0;
1825     ASSERT_NE(nullptr, window_->property_);
1826     window_->property_->SetDisplayId(displayId);
1827     window_->property_->windowRect_ = {1, 1, 1, 1};
1828 
1829     auto isFollowHost = true;
1830     auto densityValue = 0.1f;
1831     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1832     ASSERT_NE(nullptr, window_->uiContent_);
1833     Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
1834     EXPECT_CALL(*content, UpdateViewportConfig(_, _, _, _, _)).Times(3);
1835 
1836     window_->hostDensityValue_ = densityValue;
1837     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1838     ASSERT_FALSE(window_->isDensityFollowHost_);
1839 
1840     window_->hostDensityValue_ = 0.2f;
1841     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1842     ASSERT_TRUE(window_->isDensityFollowHost_);
1843     ASSERT_EQ(window_->hostDensityValue_, densityValue);
1844 
1845     densityValue = FLT_MAX;
1846     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1847     ASSERT_TRUE(window_->isDensityFollowHost_);
1848     ASSERT_EQ(window_->hostDensityValue_, densityValue);
1849 
1850     densityValue = FLT_MIN;
1851     window_->isDensityFollowHost_ = false;
1852     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1853     ASSERT_TRUE(window_->isDensityFollowHost_);
1854     ASSERT_EQ(window_->hostDensityValue_, densityValue);
1855     usleep(WAIT_SYNC_IN_NS);
1856 }
1857 
1858 /**
1859  * @tc.name: GetVirtualPixelRatio01
1860  * @tc.desc: follow host density value
1861  * @tc.type: FUNC
1862  */
1863 HWTEST_F(WindowExtensionSessionImplTest, GetVirtualPixelRatio01, TestSize.Level1)
1864 {
1865     sptr<DisplayInfo> displayInfo = new DisplayInfo();
1866     displayInfo->SetVirtualPixelRatio(3.25f);
1867     window_->isDensityFollowHost_ = true;
1868     window_->hostDensityValue_ = 2.0f;
1869     ASSERT_EQ(window_->hostDensityValue_, window_->GetVirtualPixelRatio(displayInfo));
1870 }
1871 
1872 /**
1873  * @tc.name: GetVirtualPixelRatio02
1874  * @tc.desc: follow system density value
1875  * @tc.type: FUNC
1876  */
1877 HWTEST_F(WindowExtensionSessionImplTest, GetVirtualPixelRatio02, TestSize.Level1)
1878 {
1879     auto systemDensity = 3.25;
1880     sptr<DisplayInfo> displayInfo = new DisplayInfo();
1881     displayInfo->SetVirtualPixelRatio(systemDensity);
1882     window_->isDensityFollowHost_ = false;
1883     window_->hostDensityValue_ = 2.0f;
1884     ASSERT_EQ(systemDensity, window_->GetVirtualPixelRatio(displayInfo));
1885 }
1886 
1887 /**
1888  * @tc.name: GetVirtualPixelRatio03
1889  * @tc.desc: hostDensityValue_ is nullptr
1890  * @tc.type: FUNC
1891  */
1892 HWTEST_F(WindowExtensionSessionImplTest, GetVirtualPixelRatio03, TestSize.Level1)
1893 {
1894     auto systemDensity = 3.25;
1895     sptr<DisplayInfo> displayInfo = new DisplayInfo();
1896     displayInfo->SetVirtualPixelRatio(systemDensity);
1897     window_->isDensityFollowHost_ = true;
1898     ASSERT_EQ(systemDensity, window_->GetVirtualPixelRatio(displayInfo));
1899 }
1900 
1901 /**
1902  * @tc.name: GetVirtualPixelRatio04
1903  * @tc.desc: GetVirtualPixelRatio04 test
1904  * @tc.type: FUNC
1905  */
1906 HWTEST_F(WindowExtensionSessionImplTest, GetVirtualPixelRatio04, TestSize.Level1)
1907 {
1908     ASSERT_EQ(1.0f, window_->GetVirtualPixelRatio(nullptr));
1909 }
1910 
1911 /**
1912  * @tc.name: GetVirtualPixelRatio_compat
1913  * @tc.desc: GetVirtualPixelRatio_compat test
1914  * @tc.type: FUNC
1915  */
1916 HWTEST_F(WindowExtensionSessionImplTest, GetVirtualPixelRatio_compat, TestSize.Level1)
1917 {
1918     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1919     option->SetWindowName("GetVirtualPixelRatio_compat");
1920     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
1921     SessionInfo sessionInfo;
1922     window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
1923     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
1924     compatibleModeProperty->SetIsAdaptToSimulationScale(true);
1925     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
1926     auto value = window->GetVirtualPixelRatio(nullptr);
1927     EXPECT_NEAR(value, COMPACT_SIMULATION_SCALE_DPI, 0.00001f);
1928 }
1929 
1930 /**
1931  * @tc.name: HideNonSecureWindows01
1932  * @tc.desc: HideNonSecureWindows Test
1933  * @tc.type: FUNC
1934  */
1935 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows01, TestSize.Level0)
1936 {
1937     ASSERT_EQ(WMError::WM_OK, window_->HideNonSecureWindows(false));
1938     ASSERT_FALSE(window_->extensionWindowFlags_.hideNonSecureWindowsFlag);
1939     ASSERT_EQ(WMError::WM_OK, window_->HideNonSecureWindows(true));
1940     ASSERT_TRUE(window_->extensionWindowFlags_.hideNonSecureWindowsFlag);
1941 }
1942 
1943 /**
1944  * @tc.name: HideNonSecureWindows02
1945  * @tc.desc: HideNonSecureWindows Test
1946  * @tc.type: FUNC
1947  */
1948 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows02, TestSize.Level1)
1949 {
1950     window_->state_ = WindowState::STATE_SHOWN;
1951     ASSERT_EQ(WMError::WM_OK, window_->HideNonSecureWindows(false));
1952 
1953     sptr<IRemoteObject> iRemoteObject = new IRemoteObjectMocker();
1954     ASSERT_NE(nullptr, iRemoteObject);
1955     window_->abilityToken_ = iRemoteObject;
1956     SessionInfo sessionInfo;
1957     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1958     ASSERT_NE(nullptr, window_->hostSession_);
1959     ASSERT_NE(nullptr, window_->property_);
1960     window_->property_->SetPersistentId(1);
1961 
1962     ASSERT_EQ(WMError::WM_OK, window_->HideNonSecureWindows(false));
1963 }
1964 
1965 /**
1966  * @tc.name: HideNonSecureWindows03
1967  * @tc.desc: HideNonSecureWindows Test
1968  * @tc.type: FUNC
1969  */
1970 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows03, TestSize.Level1)
1971 {
1972     window_->state_ = WindowState::STATE_SHOWN;
1973     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->HideNonSecureWindows(true));
1974 }
1975 
1976 /**
1977  * @tc.name: HideNonSecureWindows04
1978  * @tc.desc: HideNonSecureWindows Test
1979  * @tc.type: FUNC
1980  */
1981 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows04, TestSize.Level1)
1982 {
1983     SessionInfo sessionInfo;
1984     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1985     ASSERT_NE(nullptr, window_->hostSession_);
1986     ASSERT_NE(nullptr, window_->property_);
1987     window_->property_->SetPersistentId(1);
1988     window_->state_ = WindowState::STATE_SHOWN;
1989     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->HideNonSecureWindows(true));
1990 }
1991 
1992 /**
1993  * @tc.name: HideNonSecureWindows06
1994  * @tc.desc: HideNonSecureWindows Test
1995  * @tc.type: FUNC
1996  */
1997 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows06, TestSize.Level1)
1998 {
1999     ASSERT_NE(nullptr, window_->property_);
2000     window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
2001     ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, window_->HideNonSecureWindows(false));
2002 }
2003 
2004 /**
2005  * @tc.name: SetWaterMarkFlag01
2006  * @tc.desc: SetWaterMarkFlag Test
2007  * @tc.type: FUNC
2008  */
2009 HWTEST_F(WindowExtensionSessionImplTest, SetWaterMarkFlag01, TestSize.Level1)
2010 {
2011     ASSERT_EQ(WMError::WM_OK, window_->SetWaterMarkFlag(false));
2012     ASSERT_FALSE(window_->extensionWindowFlags_.waterMarkFlag);
2013     ASSERT_EQ(WMError::WM_OK, window_->SetWaterMarkFlag(true));
2014     ASSERT_TRUE(window_->extensionWindowFlags_.waterMarkFlag);
2015 }
2016 
2017 /**
2018  * @tc.name: SetWaterMarkFlag02
2019  * @tc.desc: SetWaterMarkFlag Test
2020  * @tc.type: FUNC
2021  */
2022 HWTEST_F(WindowExtensionSessionImplTest, SetWaterMarkFlag02, TestSize.Level1)
2023 {
2024     window_->state_ = WindowState::STATE_SHOWN;
2025     ASSERT_EQ(WMError::WM_OK, window_->SetWaterMarkFlag(false));
2026 }
2027 
2028 /**
2029  * @tc.name: SetWaterMarkFlag03
2030  * @tc.desc: SetWaterMarkFlag Test
2031  * @tc.type: FUNC
2032  */
2033 HWTEST_F(WindowExtensionSessionImplTest, SetWaterMarkFlag03, TestSize.Level1)
2034 {
2035     window_->state_ = WindowState::STATE_SHOWN;
2036     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->SetWaterMarkFlag(true));
2037 }
2038 
2039 /**
2040  * @tc.name: SetWaterMarkFlag04
2041  * @tc.desc: SetWaterMarkFlag Test
2042  * @tc.type: FUNC
2043  */
2044 HWTEST_F(WindowExtensionSessionImplTest, SetWaterMarkFlag04, TestSize.Level1)
2045 {
2046     SessionInfo sessionInfo;
2047     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
2048     ASSERT_NE(nullptr, window_->hostSession_);
2049     ASSERT_NE(nullptr, window_->property_);
2050     window_->property_->SetPersistentId(1);
2051     window_->state_ = WindowState::STATE_SHOWN;
2052     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->SetWaterMarkFlag(true));
2053 }
2054 
2055 /**
2056  * @tc.name: CheckAndAddExtWindowFlags01
2057  * @tc.desc: CheckAndAddExtWindowFlags01 Test
2058  * @tc.type: FUNC
2059  */
2060 HWTEST_F(WindowExtensionSessionImplTest, CheckAndAddExtWindowFlags01, TestSize.Level1)
2061 {
2062     ASSERT_NE(nullptr, window_);
2063     window_->CheckAndAddExtWindowFlags();
2064 }
2065 
2066 /**
2067  * @tc.name: CheckAndAddExtWindowFlags02
2068  * @tc.desc: CheckAndAddExtWindowFlags02 Test
2069  * @tc.type: FUNC
2070  */
2071 HWTEST_F(WindowExtensionSessionImplTest, CheckAndAddExtWindowFlags02, TestSize.Level1)
2072 {
2073     ASSERT_NE(nullptr, window_);
2074     window_->extensionWindowFlags_.bitData = 1;
2075     window_->CheckAndAddExtWindowFlags();
2076 }
2077 
2078 /**
2079  * @tc.name: CheckAndRemoveExtWindowFlags01
2080  * @tc.desc: CheckAndRemoveExtWindowFlags01 Test
2081  * @tc.type: FUNC
2082  */
2083 HWTEST_F(WindowExtensionSessionImplTest, CheckAndRemoveExtWindowFlags01, TestSize.Level1)
2084 {
2085     ASSERT_NE(nullptr, window_);
2086     window_->CheckAndRemoveExtWindowFlags();
2087 }
2088 
2089 /**
2090  * @tc.name: CheckAndRemoveExtWindowFlags02
2091  * @tc.desc: CheckAndRemoveExtWindowFlags02 Test
2092  * @tc.type: FUNC
2093  */
2094 HWTEST_F(WindowExtensionSessionImplTest, CheckAndRemoveExtWindowFlags02, TestSize.Level1)
2095 {
2096     ASSERT_NE(nullptr, window_);
2097     window_->extensionWindowFlags_.bitData = 1;
2098     window_->CheckAndRemoveExtWindowFlags();
2099 }
2100 
2101 /**
2102  * @tc.name: UpdateExtWindowFlags01
2103  * @tc.desc: UpdateExtWindowFlags Test
2104  * @tc.type: FUNC
2105  */
2106 HWTEST_F(WindowExtensionSessionImplTest, UpdateExtWindowFlags01, TestSize.Level1)
2107 {
2108     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->UpdateExtWindowFlags(ExtensionWindowFlags(),
2109         ExtensionWindowFlags()));
2110 }
2111 
2112 /**
2113  * @tc.name: UpdateExtWindowFlags02
2114  * @tc.desc: UpdateExtWindowFlags Test
2115  * @tc.type: FUNC
2116  */
2117 HWTEST_F(WindowExtensionSessionImplTest, UpdateExtWindowFlags02, TestSize.Level1)
2118 {
2119     SessionInfo sessionInfo;
2120     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
2121     ASSERT_NE(nullptr, window_->hostSession_);
2122     ASSERT_NE(nullptr, window_->property_);
2123     window_->property_->SetPersistentId(1);
2124     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->UpdateExtWindowFlags(ExtensionWindowFlags(), ExtensionWindowFlags()));
2125 
2126     sptr<IRemoteObject> iRemoteObject = new IRemoteObjectMocker();
2127     ASSERT_NE(nullptr, iRemoteObject);
2128     window_->abilityToken_ = iRemoteObject;
2129     ASSERT_NE(WMError::WM_ERROR_NULLPTR, window_->UpdateExtWindowFlags(ExtensionWindowFlags(), ExtensionWindowFlags()));
2130 }
2131 
2132 /**
2133  * @tc.name: UpdateExtWindowFlags03
2134  * @tc.desc: UpdateExtWindowFlags Test
2135  * @tc.type: FUNC
2136  */
2137 HWTEST_F(WindowExtensionSessionImplTest, UpdateExtWindowFlags03, TestSize.Level1)
2138 {
2139     SessionInfo sessionInfo;
2140     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
2141     ASSERT_NE(nullptr, window_->hostSession_);
2142     ASSERT_NE(nullptr, window_->property_);
2143     window_->property_->SetPersistentId(1);
2144     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->UpdateExtWindowFlags(ExtensionWindowFlags(), ExtensionWindowFlags()));
2145 }
2146 
2147 /**
2148  * @tc.name: GetHostWindowRect01
2149  * @tc.desc: GetHostWindowRect Test
2150  * @tc.type: FUNC
2151  */
2152 HWTEST_F(WindowExtensionSessionImplTest, GetHostWindowRect01, TestSize.Level1)
2153 {
2154     Rect rect;
2155     ASSERT_EQ(rect, window_->GetHostWindowRect(-1));
2156 }
2157 
2158 /**
2159  * @tc.name: GetHostWindowRect02
2160  * @tc.desc: GetHostWindowRect Test
2161  * @tc.type: FUNC
2162  */
2163 HWTEST_F(WindowExtensionSessionImplTest, GetHostWindowRect02, TestSize.Level1)
2164 {
2165     Rect rect;
2166     ASSERT_EQ(rect, window_->GetHostWindowRect(0));
2167 }
2168 
2169 /**
2170  * @tc.name: GetGlobalScaledRect
2171  * @tc.desc: GetGlobalScaledRect Test
2172  * @tc.type: FUNC
2173  */
2174 HWTEST_F(WindowExtensionSessionImplTest, GetGlobalScaledRect, TestSize.Level1)
2175 {
2176     Rect rect;
2177     ASSERT_EQ(WMError::WM_ERROR_INVALID_SESSION, window_->GetGlobalScaledRect(rect));
2178 }
2179 
2180 /**
2181  * @tc.name: ConsumePointerEvent
2182  * @tc.desc: ConsumePointerEvent Test
2183  * @tc.type: FUNC
2184  */
2185 HWTEST_F(WindowExtensionSessionImplTest, ConsumePointerEvent, TestSize.Level0)
2186 {
2187     struct RSSurfaceNodeConfig config;
2188     window_->surfaceNode_ = RSSurfaceNode::Create(config);
2189     window_->state_ = WindowState::STATE_SHOWN;
2190 
2191     auto pointerEvent = MMI::PointerEvent::Create();
2192     window_->ConsumePointerEvent(nullptr);
2193 
2194     window_->ConsumePointerEvent(pointerEvent);
2195 
2196     SessionInfo sessionInfo;
2197     window_->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2198     ASSERT_NE(nullptr, window_->hostSession_);
2199     window_->ConsumePointerEvent(pointerEvent);
2200 
2201     MMI::PointerEvent::PointerItem item;
2202     pointerEvent->SetPointerId(0);
2203     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
2204     item.SetPointerId(0);
2205     item.SetDisplayX(15); // 15 : position x
2206     item.SetDisplayY(15); // 15 : position y
2207     item.SetWindowX(15); // 15 : position x
2208     item.SetWindowY(15); // 15 : position y
2209     pointerEvent->AddPointerItem(item);
2210     window_->ConsumePointerEvent(pointerEvent);
2211 
2212     ASSERT_NE(nullptr, window_->property_);
2213     window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
2214     window_->ConsumePointerEvent(pointerEvent);
2215 
2216     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_MOVE);
2217     pointerEvent->UpdatePointerItem(0, item);
2218     window_->ConsumePointerEvent(pointerEvent);
2219 
2220     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
2221     pointerEvent->UpdatePointerItem(0, item);
2222     window_->ConsumePointerEvent(pointerEvent);
2223 }
2224 
2225 /**
2226  * @tc.name: ConsumePointerEvent02
2227  * @tc.desc: ConsumePointerEvent02 Test branch: uiExtensionUsage_ == UIExtensionUsage::PREVIEW_EMBEDDED
2228  * @tc.type: FUNC
2229  */
2230 HWTEST_F(WindowExtensionSessionImplTest, ConsumePointerEvent02, TestSize.Level1)
2231 {
2232     ASSERT_NE(nullptr, window_);
2233     window_->property_->SetUIExtensionUsage(UIExtensionUsage::PREVIEW_EMBEDDED);
2234     auto pointerEvent = MMI::PointerEvent::Create();
2235     ASSERT_NE(nullptr, pointerEvent);
2236     window_->ConsumePointerEvent(pointerEvent);
2237 }
2238 /**
2239  * @tc.name: NotifyPointerEvent
2240  * @tc.desc: NotifyPointerEvent Test
2241  * @tc.type: FUNC
2242  */
2243 HWTEST_F(WindowExtensionSessionImplTest, NotifyPointerEvent, TestSize.Level1)
2244 {
2245     logMsg.clear();
2246     LOG_SetCallback(WindowExtensionSessionImplLogCallback);
2247     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2248     option->SetWindowName("NotifyPointerEvent");
2249     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
2250     SessionInfo sessionInfo;
2251     window->uiContent_ = nullptr;
2252     window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2253     window->property_->SetPersistentId(1);
2254     ASSERT_NE(0, window->GetPersistentId());
2255     std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
2256     window->NotifyPointerEvent(pointerEvent);
2257     EXPECT_TRUE(logMsg.find("pointerEvent is nullptr") != std::string::npos);
2258     logMsg.clear();
2259 
2260     pointerEvent = MMI::PointerEvent::Create();
2261     window->inputEventConsumer_ = std::make_shared<MockInputEventConsumer>();
2262     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UNKNOWN);
2263     EXPECT_EQ(pointerEvent->GetPointerAction(), MMI::PointerEvent::POINTER_ACTION_UNKNOWN);
2264     window->NotifyPointerEvent(pointerEvent);
2265 
2266     bool isHostWindowDelayRaiseEnabled = true;
2267     window->property_->SetWindowDelayRaiseEnabled(isHostWindowDelayRaiseEnabled);
2268     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
2269     window->NotifyPointerEvent(pointerEvent);
2270     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_UP);
2271     window->NotifyPointerEvent(pointerEvent);
2272     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
2273     window->NotifyPointerEvent(pointerEvent);
2274     EXPECT_TRUE(logMsg.find("uiContent is null") != std::string::npos);
2275     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
2276     window->NotifyPointerEvent(pointerEvent);
2277 
2278     window->inputEventConsumer_ = nullptr;
2279     window->NotifyPointerEvent(pointerEvent);
2280 }
2281 
2282 /**
2283  * @tc.name: ProcessPointerEventWithHostWindowDelayRaise
2284  * @tc.desc: ProcessPointerEventWithHostWindowDelayRaise Test
2285  * @tc.type: FUNC
2286  */
2287 HWTEST_F(WindowExtensionSessionImplTest, ProcessPointerEventWithHostWindowDelayRaise, TestSize.Level1)
2288 {
2289     logMsg.clear();
2290     LOG_SetCallback(WindowExtensionSessionImplLogCallback);
2291     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2292     option->SetWindowName("ProcessPointerEventWithHostWindowDelayRaise");
2293     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
2294     std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
2295     bool isHitTargetDraggable = false;
2296     window->ProcessPointerEventWithHostWindowDelayRaise(pointerEvent, isHitTargetDraggable);
2297     EXPECT_TRUE(logMsg.find("pointerEvent is nullptr") != std::string::npos);
2298     logMsg.clear();
2299 
2300     pointerEvent = MMI::PointerEvent::Create();
2301     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
2302     window->ProcessPointerEventWithHostWindowDelayRaise(pointerEvent, isHitTargetDraggable);
2303 
2304     isHitTargetDraggable = true;
2305     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
2306     window->dataHandler_ = nullptr;
2307     window->ProcessPointerEventWithHostWindowDelayRaise(pointerEvent, isHitTargetDraggable);
2308     EXPECT_TRUE(logMsg.find("No need to notify") != std::string::npos);
2309     logMsg.clear();
2310 
2311     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_UP);
2312     window->ProcessPointerEventWithHostWindowDelayRaise(pointerEvent, isHitTargetDraggable);
2313     window->dataHandler_ = std::make_shared<Extension::MockDataHandler>();
2314     window->ProcessPointerEventWithHostWindowDelayRaise(pointerEvent, isHitTargetDraggable);
2315     EXPECT_TRUE(logMsg.find("Notify host window to raise") != std::string::npos);
2316 }
2317 
2318 /**
2319  * @tc.name: PreNotifyKeyEvent
2320  * @tc.desc: PreNotifyKeyEvent Test
2321  * @tc.type: FUNC
2322  */
2323 HWTEST_F(WindowExtensionSessionImplTest, PreNotifyKeyEvent, TestSize.Level1)
2324 {
2325     bool ret = window_->PreNotifyKeyEvent(nullptr);
2326     ASSERT_EQ(ret, false);
2327 
2328     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
2329     ASSERT_NE(nullptr, keyEvent);
2330     ASSERT_NE(nullptr, window_->property_);
2331     window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
2332     ret = window_->PreNotifyKeyEvent(keyEvent);
2333     ASSERT_EQ(ret, false);
2334 
2335     std::shared_ptr<Ace::UIContent> uiContent = std::make_unique<Ace::UIContentMocker>();
2336     ASSERT_NE(nullptr, uiContent);
2337     window_->uiContent_ = uiContent;
2338     Ace::UIContentMocker* uiContentMocker = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
2339     EXPECT_CALL(*uiContentMocker, ProcessKeyEvent).Times(2).WillOnce(Return(true));
2340     ret = window_->PreNotifyKeyEvent(keyEvent);
2341     ASSERT_EQ(ret, true);
2342 
2343     window_->property_->SetUIExtensionUsage(UIExtensionUsage::CONSTRAINED_EMBEDDED);
2344     ret = window_->PreNotifyKeyEvent(keyEvent);
2345     ASSERT_EQ(ret, true);
2346 
2347     window_->focusState_ = false;
2348     ret = window_->PreNotifyKeyEvent(keyEvent);
2349     ASSERT_EQ(ret, true);
2350 
2351     window_->focusState_ = true;
2352     ret = window_->PreNotifyKeyEvent(keyEvent);
2353     ASSERT_EQ(ret, false);
2354     usleep(WAIT_SYNC_IN_NS);
2355 }
2356 
2357 /**
2358  * @tc.name: PreNotifyKeyEvent02
2359  * @tc.desc: PreNotifyKeyEvent02 Test branch: uiExtensionUsage_ == UIExtensionUsage::PREVIEW_EMBEDDED
2360  * @tc.type: FUNC
2361  */
2362 HWTEST_F(WindowExtensionSessionImplTest, PreNotifyKeyEvent02, TestSize.Level1)
2363 {
2364     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
2365     ASSERT_NE(nullptr, keyEvent);
2366     ASSERT_NE(nullptr, window_);
2367     window_->property_->SetUIExtensionUsage(UIExtensionUsage::PREVIEW_EMBEDDED);
2368     ASSERT_FALSE(window_->PreNotifyKeyEvent(keyEvent));
2369 }
2370 
2371 /**
2372  * @tc.name: GetFreeMultiWindowModeEnabledState
2373  * @tc.desc: GetFreeMultiWindowModeEnabledState Test
2374  * @tc.type: FUNC
2375  */
2376 HWTEST_F(WindowExtensionSessionImplTest, GetFreeMultiWindowModeEnabledState, TestSize.Level1)
2377 {
2378     ASSERT_EQ(false, window_->GetFreeMultiWindowModeEnabledState());
2379 }
2380 
2381 /**
2382  * @tc.name: NotifyExtensionTimeout
2383  * @tc.desc: NotifyExtensionTimeout Test
2384  * @tc.type: FUNC
2385  */
2386 HWTEST_F(WindowExtensionSessionImplTest, NotifyExtensionTimeout, TestSize.Level1)
2387 {
2388     ASSERT_NE(nullptr, window_);
2389     SessionInfo sessionInfo;
2390     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2391 
2392     window_->hostSession_ = session;
2393     EXPECT_CALL(*session, NotifyExtensionTimeout).Times(1);
2394     window_->NotifyExtensionTimeout(WindowExtensionSessionImpl::TimeoutErrorCode::SET_UICONTENT_TIMEOUT);
2395 
2396     window_->hostSession_ = nullptr;
2397     EXPECT_CALL(*session, NotifyExtensionTimeout).Times(0);
2398     window_->NotifyExtensionTimeout(WindowExtensionSessionImpl::TimeoutErrorCode::SET_UICONTENT_TIMEOUT);
2399     usleep(WAIT_SYNC_IN_NS);
2400 }
2401 
2402 /**
2403  * @tc.name: GetRealParentId
2404  * @tc.desc: GetRealParentId Test
2405  * @tc.type: FUNC
2406  */
2407 HWTEST_F(WindowExtensionSessionImplTest, GetRealParentId, TestSize.Level1)
2408 {
2409     ASSERT_NE(window_->property_, nullptr);
2410     window_->property_->SetRealParentId(12345);
2411     EXPECT_EQ(window_->GetRealParentId(), 12345);
2412 }
2413 
2414 /**
2415  * @tc.name: GetParentWindowType
2416  * @tc.desc: GetParentWindowType Test
2417  * @tc.type: FUNC
2418  */
2419 HWTEST_F(WindowExtensionSessionImplTest, GetParentWindowType, TestSize.Level1)
2420 {
2421     ASSERT_NE(window_->property_, nullptr);
2422     window_->property_->SetParentWindowType(WindowType::WINDOW_TYPE_TOAST);
2423     EXPECT_EQ(window_->GetParentWindowType(), WindowType::WINDOW_TYPE_TOAST);
2424 }
2425 
2426 /**
2427  * @tc.name: CheckHideNonSecureWindowsPermission
2428  * @tc.desc: CheckHideNonSecureWindowsPermission Test
2429  * @tc.type: FUNC
2430  */
2431 HWTEST_F(WindowExtensionSessionImplTest, CheckHideNonSecureWindowsPermission, TestSize.Level1)
2432 {
2433     ASSERT_NE(window_->property_, nullptr);
2434 
2435     window_->property_->uiExtensionUsage_ = UIExtensionUsage::EMBEDDED;
2436     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(true), WMError::WM_OK);
2437     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(false), WMError::WM_OK);
2438 
2439     window_->property_->uiExtensionUsage_ = UIExtensionUsage::MODAL;
2440     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(true), WMError::WM_OK);
2441     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(false), WMError::WM_ERROR_INVALID_OPERATION);
2442 
2443     window_->property_->uiExtensionUsage_ = UIExtensionUsage::CONSTRAINED_EMBEDDED;
2444     window_->modalUIExtensionMayBeCovered_ = true;
2445     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(true), WMError::WM_OK);
2446     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(false), WMError::WM_ERROR_INVALID_OPERATION);
2447 
2448     window_->property_->uiExtensionUsage_ = UIExtensionUsage::PREVIEW_EMBEDDED;
2449     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(true), WMError::WM_OK);
2450     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(false), WMError::WM_ERROR_INVALID_OPERATION);
2451 }
2452 
2453 /**
2454  * @tc.name: NotifyModalUIExtensionMayBeCovered
2455  * @tc.desc: NotifyModalUIExtensionMayBeCovered Test
2456  * @tc.type: FUNC
2457  */
2458 HWTEST_F(WindowExtensionSessionImplTest, NotifyModalUIExtensionMayBeCovered, TestSize.Level1)
2459 {
2460     ASSERT_NE(window_, nullptr);
2461     ASSERT_NE(window_->property_, nullptr);
2462 
2463     window_->property_->uiExtensionUsage_ = UIExtensionUsage::EMBEDDED;
2464     window_->NotifyModalUIExtensionMayBeCovered(true);
2465 
2466     window_->property_->uiExtensionUsage_ = UIExtensionUsage::MODAL;
2467     window_->extensionWindowFlags_.hideNonSecureWindowsFlag = true;
2468     window_->NotifyModalUIExtensionMayBeCovered(true);
2469     ASSERT_TRUE(window_->modalUIExtensionMayBeCovered_);
2470     ASSERT_TRUE(window_->modalUIExtensionSelfLoadContent_);
2471 
2472     window_->property_->uiExtensionUsage_ = UIExtensionUsage::CONSTRAINED_EMBEDDED;
2473     window_->extensionWindowFlags_.hideNonSecureWindowsFlag = false;
2474     window_->NotifyModalUIExtensionMayBeCovered(false);
2475     ASSERT_TRUE(window_->modalUIExtensionMayBeCovered_);
2476     ASSERT_TRUE(window_->modalUIExtensionSelfLoadContent_);
2477 
2478     window_->property_->uiExtensionUsage_ = UIExtensionUsage::PREVIEW_EMBEDDED;
2479     window_->extensionWindowFlags_.hideNonSecureWindowsFlag = false;
2480     window_->NotifyModalUIExtensionMayBeCovered(false);
2481     ASSERT_TRUE(window_->modalUIExtensionMayBeCovered_);
2482     ASSERT_TRUE(window_->modalUIExtensionSelfLoadContent_);
2483 }
2484 
2485 /**
2486  * @tc.name: ReportModalUIExtensionMayBeCovered
2487  * @tc.desc: ReportModalUIExtensionMayBeCovered Test
2488  * @tc.type: FUNC
2489  */
2490 HWTEST_F(WindowExtensionSessionImplTest, ReportModalUIExtensionMayBeCovered, TestSize.Level1)
2491 {
2492     ASSERT_NE(window_, nullptr);
2493     window_->ReportModalUIExtensionMayBeCovered(true);
2494     window_->NotifyModalUIExtensionMayBeCovered(false);
2495 }
2496 
2497 /**
2498  * @tc.name: NotifyExtensionEventAsync
2499  * @tc.desc: NotifyExtensionEventAsync Test
2500  * @tc.type: FUNC
2501  */
2502 HWTEST_F(WindowExtensionSessionImplTest, NotifyExtensionEventAsync, TestSize.Level1)
2503 {
2504     window_->NotifyExtensionEventAsync(0);
2505 
2506     SessionInfo sessionInfo;
2507     window_->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2508     ASSERT_NE(nullptr, window_->hostSession_);
2509     window_->property_->SetPersistentId(1);
2510     window_->NotifyExtensionEventAsync(0);
2511 }
2512 
2513 /**
2514  * @tc.name: NotifyDumpInfo
2515  * @tc.desc: NotifyDumpInfo Test
2516  * @tc.type: FUNC
2517  */
2518 HWTEST_F(WindowExtensionSessionImplTest, NotifyDumpInfo, TestSize.Level1)
2519 {
2520     ASSERT_NE(nullptr, window_);
2521     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
2522     ASSERT_NE(nullptr, window_->uiContent_);
2523     std::vector<std::string> params;
2524     std::vector<std::string> info;
2525     auto ret = window_->NotifyDumpInfo(params, info);
2526     ASSERT_EQ(WSError::WS_OK, ret);
2527 
2528     window_->uiContent_ = nullptr;
2529     ret = window_->NotifyDumpInfo(params, info);
2530     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, ret);
2531     usleep(WAIT_SYNC_IN_NS);
2532 }
2533 
2534 /**
2535  * @tc.name: UpdateConfigurationSyncForAll
2536  * @tc.desc: UpdateConfigurationSyncForAll Test
2537  * @tc.type: FUNC
2538  */
2539 HWTEST_F(WindowExtensionSessionImplTest, UpdateConfigurationSyncForAll, TestSize.Level1)
2540 {
2541     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
2542     ASSERT_NE(nullptr, window_);
2543     window_->GetWindowExtensionSessionSet().insert(window_);
2544     window_->UpdateConfigurationSyncForAll(configuration);
2545     window_->GetWindowExtensionSessionSet().erase(window_);
2546 }
2547 
2548 /**
2549  * @tc.name: SetCompatInfo
2550  * @tc.desc: SetCompatInfo Test
2551  * @tc.type: FUNC
2552  */
2553 HWTEST_F(WindowExtensionSessionImplTest, SetCompatInfo, TestSize.Level1)
2554 {
2555     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2556     option->SetWindowName("SetCompatInfo");
2557     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
2558     SessionInfo sessionInfo;
2559     window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2560     AAFwk::WantParams configParam;
2561     EXPECT_EQ(WMError::WM_DO_NOTHING, window->SetCompatInfo(configParam));
2562 
2563     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
2564     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
2565     EXPECT_EQ(WMError::WM_OK, window->SetCompatInfo(configParam));
2566 
2567     window->property_->SetCompatibleModeProperty(nullptr);
2568     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
2569     configParam.SetParam(Extension::COMPAT_IS_SIMULATION_SCALE_FIELD,
2570         AAFwk::Integer::Box(static_cast<int32_t>(true)));
2571     float compatScaleX = 0.5f;
2572     float compatScaleY = 0.55f;
2573     configParam.SetParam(Extension::COMPAT_SCALE_X_FIELD, AAFwk::Float::Box(compatScaleX));
2574     configParam.SetParam(Extension::COMPAT_SCALE_Y_FIELD, AAFwk::Float::Box(compatScaleY));
2575     EXPECT_EQ(WMError::WM_OK, window->SetCompatInfo(configParam));
2576     EXPECT_NEAR(window->compatScaleX_, compatScaleX, 0.00001f);
2577     EXPECT_NEAR(window->compatScaleY_, compatScaleY, 0.00001f);
2578 }
2579 
2580 /**
2581  * @tc.name: OnHostWindowCompatInfoChange
2582  * @tc.desc: OnHostWindowCompatInfoChange Test
2583  * @tc.type: FUNC
2584  */
2585 HWTEST_F(WindowExtensionSessionImplTest, OnHostWindowCompatInfoChange, TestSize.Level1)
2586 {
2587     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2588     option->SetWindowName("OnHostWindowCompatInfoChange");
2589     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
2590     SessionInfo sessionInfo;
2591     window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2592     AAFwk::Want want;
2593     std::optional<AAFwk::Want> reply = std::make_optional<AAFwk::Want>();
2594     want.SetParam(Extension::COMPAT_IS_SIMULATION_SCALE_FIELD, false);
2595     auto res = window->OnHostWindowCompatInfoChange(std::move(want), reply);
2596     EXPECT_EQ(WMError::WM_DO_NOTHING, res);
2597 
2598     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
2599     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
2600     res = window->OnHostWindowCompatInfoChange(std::move(want), reply);
2601     EXPECT_EQ(WMError::WM_OK, res);
2602 
2603     window->property_->SetCompatibleModeProperty(nullptr);
2604     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
2605     want.SetParam(Extension::COMPAT_IS_SIMULATION_SCALE_FIELD, true);
2606     float compatScaleX = 0.5f;
2607     float compatScaleY = 0.55f;
2608     want.SetParam(Extension::COMPAT_SCALE_X_FIELD, compatScaleX);
2609     want.SetParam(Extension::COMPAT_SCALE_Y_FIELD, compatScaleY);
2610     res = window->OnHostWindowCompatInfoChange(std::move(want), reply);
2611     EXPECT_EQ(WMError::WM_OK, res);
2612     EXPECT_NEAR(window->compatScaleX_, compatScaleX, 0.00001f);
2613     EXPECT_NEAR(window->compatScaleY_, compatScaleY, 0.00001f);
2614 }
2615 
2616 /**
2617  * @tc.name: GetSystemViewportConfig
2618  * @tc.desc: GetSystemViewportConfig Test
2619  * @tc.type: FUNC
2620  */
2621 HWTEST_F(WindowExtensionSessionImplTest, GetSystemViewportConfig, TestSize.Level1)
2622 {
2623     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2624     option->SetWindowName("GetSystemViewportConfig");
2625     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
2626     SessionInfo sessionInfo;
2627     window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2628     window->property_->SetDisplayId(0);
2629     auto display = SingletonContainer::Get<DisplayManager>().GetDisplayById(window->property_->GetDisplayId());
2630     ASSERT_NE(display, nullptr);
2631     ASSERT_NE(display->GetDisplayInfo(), nullptr);
2632     auto vpr = display->GetDisplayInfo()->GetVirtualPixelRatio();
2633     SessionViewportConfig config;
2634     EXPECT_EQ(WMError::WM_OK, window->GetSystemViewportConfig(config));
2635     EXPECT_NEAR(config.density_, vpr, 0.00001f);
2636     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
2637     compatibleModeProperty->SetIsAdaptToSimulationScale(true);
2638     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
2639     EXPECT_EQ(WMError::WM_OK, window->GetSystemViewportConfig(config));
2640     EXPECT_NEAR(config.density_, COMPACT_SIMULATION_SCALE_DPI, 0.00001f);
2641 }
2642 
2643 /**
2644  * @tc.name: UpdateExtensionDensity
2645  * @tc.desc: UpdateExtensionDensity Test
2646  * @tc.type: FUNC
2647  */
2648 HWTEST_F(WindowExtensionSessionImplTest, UpdateExtensionDensity, TestSize.Level1)
2649 {
2650     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2651     option->SetWindowName("UpdateExtensionDensity");
2652     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
2653     SessionInfo sessionInfo;
2654     window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2655     window->property_->SetDisplayId(0);
2656     auto display = SingletonContainer::Get<DisplayManager>().GetDisplayById(window->property_->GetDisplayId());
2657     ASSERT_NE(display, nullptr);
2658     ASSERT_NE(display->GetDisplayInfo(), nullptr);
2659     auto vpr = display->GetDisplayInfo()->GetVirtualPixelRatio();
2660     SessionViewportConfig config;
2661     config.displayId_ = window->property_->GetDisplayId();
2662     config.isDensityFollowHost_ = true;
2663     config.density_ = 2.0f;
2664     window->UpdateExtensionDensity(config);
2665     EXPECT_TRUE(window->isDensityFollowHost_);
2666     if (window->hostDensityValue_ != std::nullopt) {
2667         EXPECT_NEAR(config.density_, window->hostDensityValue_->load(), 0.00001f);
2668     }
2669     config.isDensityFollowHost_ = false;
2670     window->UpdateExtensionDensity(config);
2671     EXPECT_FALSE(window->isDensityFollowHost_);
2672     EXPECT_NEAR(config.density_, vpr, 0.00001f);
2673     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
2674     compatibleModeProperty->SetIsAdaptToSimulationScale(true);
2675     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
2676     window->UpdateExtensionDensity(config);
2677     EXPECT_FALSE(window->isDensityFollowHost_);
2678     EXPECT_NEAR(config.density_, COMPACT_SIMULATION_SCALE_DPI, 0.00001f);
2679 }
2680 
2681 /**
2682  * @tc.name: GetDefaultDensity
2683  * @tc.desc: GetDefaultDensity Test
2684  * @tc.type: FUNC
2685  */
2686 HWTEST_F(WindowExtensionSessionImplTest, GetDefaultDensity, TestSize.Level1)
2687 {
2688     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2689     option->SetWindowName("GetDefaultDensity");
2690     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
2691     sptr<DisplayInfo> displayInfo = nullptr;
2692     EXPECT_NEAR(1.0f, window->GetDefaultDensity(displayInfo), 0.00001f);
2693     auto systemDensity = 2.0;
2694     displayInfo = sptr<DisplayInfo>::MakeSptr();
2695     displayInfo->SetVirtualPixelRatio(systemDensity);
2696     EXPECT_NEAR(systemDensity, window->GetDefaultDensity(displayInfo), 0.00001f);
2697     sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
2698     compatibleModeProperty->SetIsAdaptToSimulationScale(true);
2699     window->property_->SetCompatibleModeProperty(compatibleModeProperty);
2700     EXPECT_NEAR(COMPACT_SIMULATION_SCALE_DPI, window->GetDefaultDensity(displayInfo), 0.00001f);
2701 }
2702 
2703 /**
2704  * @tc.name: NotifyExtensionDataConsumer01
2705  * @tc.desc: Test NotifyExtensionDataConsumer with valid window mode data
2706  * @tc.type: FUNC
2707  */
2708 HWTEST_F(WindowExtensionSessionImplTest, NotifyExtensionDataConsumer01, TestSize.Level1)
2709 {
2710     // Prepare and write config
2711     MessageParcel data;
2712     MessageParcel reply;
2713     Extension::DataTransferConfig config;
2714     config.subSystemId = SubSystemId::WM_UIEXT;
2715     config.customId = static_cast<uint32_t>(Extension::Businesscode::SYNC_HOST_WINDOW_MODE);
2716     config.needReply = false;
2717     config.needSyncSend = true;
2718     ASSERT_TRUE(data.WriteParcelable(&config));
2719 
2720     // Prepare and write want data
2721     AAFwk::Want want;
2722     want.SetParam(Extension::WINDOW_MODE_FIELD, static_cast<int32_t>(WindowMode::WINDOW_MODE_FLOATING));
2723     ASSERT_TRUE(data.WriteParcelable(&want));
2724 
2725     // Send data
2726     MessageOption option;
2727     window_->SendExtensionData(data, reply, option);
2728 
2729     // Verify reply contains success code
2730     uint32_t replyCode;
2731     ASSERT_TRUE(reply.ReadUint32(replyCode));
2732     ASSERT_EQ(static_cast<uint32_t>(DataHandlerErr::OK), replyCode);
2733 
2734     // Verify window mode was updated
2735     ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window_->GetWindowMode());
2736 }
2737 
2738 /**
2739  * @tc.name: RegisterConsumer
2740  * @tc.desc: RegisterConsumer Test
2741  * @tc.type: FUNC
2742  */
2743 HWTEST_F(WindowExtensionSessionImplTest, RegisterConsumer, TestSize.Level1)
2744 {
2745     window_->RegisterConsumer(Extension::Businesscode::SYNC_CROSS_AXIS_STATE,
2746         std::bind(&WindowExtensionSessionImpl::OnCrossAxisStateChange,
2747         window_, std::placeholders::_1, std::placeholders::_2));
2748     ASSERT_NE(nullptr,
2749         window_->dataConsumers_[static_cast<uint32_t>(Extension::Businesscode::SYNC_CROSS_AXIS_STATE)]);
2750 }
2751 
2752 /**
2753  * @tc.name: OnCrossAxisStateChange
2754  * @tc.desc: OnCrossAxisStateChange Test
2755  * @tc.type: FUNC
2756  */
2757 HWTEST_F(WindowExtensionSessionImplTest, OnCrossAxisStateChange, TestSize.Level1)
2758 {
2759     AAFwk::Want want;
2760     std::optional<AAFwk::Want> reply = std::make_optional<AAFwk::Want>();
2761     want.SetParam(Extension::CROSS_AXIS_FIELD, static_cast<int32_t>(CrossAxisState::STATE_CROSS));
2762     ASSERT_EQ(WMError::WM_OK, window_->OnCrossAxisStateChange(std::move(want), reply));
2763     ASSERT_EQ(CrossAxisState::STATE_CROSS, window_->crossAxisState_.load());
2764 }
2765 
2766 /**
2767  * @tc.name: OnWaterfallModeChange
2768  * @tc.desc: OnWaterfallModeChange Test
2769  * @tc.type: FUNC
2770  */
2771 HWTEST_F(WindowExtensionSessionImplTest, OnWaterfallModeChange, TestSize.Level1)
2772 {
2773     AAFwk::Want want;
2774     std::optional<AAFwk::Want> reply = std::make_optional<AAFwk::Want>();
2775     want.SetParam(Extension::WATERFALL_MODE_FIELD, true);
2776     EXPECT_EQ(WMError::WM_OK, window_->OnWaterfallModeChange(std::move(want), reply));
2777     EXPECT_TRUE(window_->IsWaterfallModeEnabled());
2778 }
2779 
2780 /**
2781  * @tc.name: OnHostWindowDelayRaiseStateChange
2782  * @tc.desc: OnHostWindowDelayRaiseStateChange Test
2783  * @tc.type: FUNC
2784  */
2785 HWTEST_F(WindowExtensionSessionImplTest, OnHostWindowDelayRaiseStateChange, TestSize.Level1)
2786 {
2787     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2788     option->SetWindowName("OnHostWindowDelayRaiseStateChange");
2789     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
2790     SessionInfo sessionInfo;
2791     window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2792     window->property_->SetPersistentId(1);
2793     ASSERT_NE(0, window->GetPersistentId());
2794     AAFwk::Want want;
2795     std::optional<AAFwk::Want> reply = std::make_optional<AAFwk::Want>();
2796     bool isHostWindowDelayRaiseEnabled = true;
2797     want.SetParam(Extension::HOST_WINDOW_DELAY_RAISE_STATE_FIELD, isHostWindowDelayRaiseEnabled);
2798     window->property_->SetWindowDelayRaiseEnabled(isHostWindowDelayRaiseEnabled);
2799     EXPECT_EQ(WMError::WM_OK, window->OnHostWindowDelayRaiseStateChange(std::move(want), reply));
2800 
2801     window->property_->SetWindowDelayRaiseEnabled(false);
2802     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
2803     EXPECT_EQ(WMError::WM_OK, window->OnHostWindowDelayRaiseStateChange(std::move(want), reply));
2804     EXPECT_TRUE(window->IsWindowDelayRaiseEnabled());
2805     isHostWindowDelayRaiseEnabled = false;
2806     want.SetParam(Extension::HOST_WINDOW_DELAY_RAISE_STATE_FIELD, isHostWindowDelayRaiseEnabled);
2807     EXPECT_EQ(WMError::WM_OK, window->OnHostWindowDelayRaiseStateChange(std::move(want), reply));
2808     EXPECT_FALSE(window->IsWindowDelayRaiseEnabled());
2809 }
2810 
2811 /**
2812  * @tc.name: OnHostWindowRectChange
2813  * @tc.desc: OnHostWindowRectChange Test
2814  * @tc.type: FUNC
2815  */
2816 HWTEST_F(WindowExtensionSessionImplTest, OnHostWindowRectChange, TestSize.Level1)
2817 {
2818     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2819     option->SetWindowName("OnHostWindowRectChange");
2820     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
2821     SessionInfo sessionInfo;
2822     window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2823     window->property_->SetPersistentId(1);
2824     ASSERT_NE(0, window->GetPersistentId());
2825     AAFwk::Want want;
2826     std::optional<AAFwk::Want> reply = std::make_optional<AAFwk::Want>();
2827 
2828     EXPECT_EQ(WMError::WM_OK, window->OnHostWindowRectChange(std::move(want), reply));
2829     window->rectChangeUIExtListenerIds_.emplace(111);
2830     ASSERT_FALSE(window->rectChangeUIExtListenerIds_.empty());
2831     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
2832     EXPECT_EQ(WMError::WM_OK, window->OnHostWindowRectChange(std::move(want), reply));
2833 }
2834 
2835 /**
2836  * @tc.name: OnResyncExtensionConfig
2837  * @tc.desc: OnResyncExtensionConfig Test
2838  * @tc.type: FUNC
2839  */
2840 HWTEST_F(WindowExtensionSessionImplTest, OnResyncExtensionConfig, Function | SmallTest | Level3)
2841 {
2842     AAFwk::Want want;
2843     AAFwk::WantParams configParam;
2844     AAFwk::WantParams wantParam;
2845     configParam.SetParam(Extension::CROSS_AXIS_FIELD,
2846         AAFwk::Integer::Box(static_cast<int32_t>(CrossAxisState::STATE_CROSS)));
2847     configParam.SetParam(Extension::WATERFALL_MODE_FIELD, AAFwk::Integer::Box(static_cast<int32_t>(1)));
2848     configParam.SetParam(Extension::HOST_WINDOW_DELAY_RAISE_STATE_FIELD,
2849         AAFwk::Integer::Box(static_cast<int32_t>(true)));
2850     wantParam.SetParam(Extension::UIEXTENSION_CONFIG_FIELD, AAFwk::WantParamWrapper::Box(configParam));
2851     want.SetParams(wantParam);
2852     std::optional<AAFwk::Want> reply = std::make_optional<AAFwk::Want>();
2853     EXPECT_EQ(WMError::WM_OK, window_->OnResyncExtensionConfig(std::move(want), reply));
2854     EXPECT_EQ(CrossAxisState::STATE_CROSS, window_->crossAxisState_.load());
2855     EXPECT_TRUE(window_->IsWaterfallModeEnabled());
2856     EXPECT_TRUE(window_->IsWindowDelayRaiseEnabled());
2857 }
2858 
2859 /**
2860  * @tc.name: SendExtensionMessageToHost
2861  * @tc.desc: SendExtensionMessageToHost Test
2862  * @tc.type: FUNC
2863  */
2864 HWTEST_F(WindowExtensionSessionImplTest, SendExtensionMessageToHost, TestSize.Level1)
2865 {
2866     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2867     option->SetWindowName("SendExtensionMessageToHost");
2868     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
2869     SessionInfo sessionInfo;
2870     window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2871     window->property_->SetPersistentId(1);
2872     ASSERT_NE(0, window->GetPersistentId());
2873     window->dataHandler_ = nullptr;
2874     uint32_t code = 111;
2875     AAFwk::Want data;
2876 
2877     EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SendExtensionMessageToHost(code, data));
2878     window->dataHandler_ = std::make_shared<Extension::ProviderDataHandler>();
2879     EXPECT_EQ(WMError::WM_ERROR_IPC_FAILED, window->SendExtensionMessageToHost(code, data));
2880     window->dataHandler_ = std::make_shared<Extension::MockDataHandler>();
2881     EXPECT_EQ(WMError::WM_OK, window->SendExtensionMessageToHost(code, data));
2882 }
2883 
2884 /**
2885  * @tc.name: OnExtensionMessage
2886  * @tc.desc: OnExtensionMessage test
2887  * @tc.type: FUNC
2888  */
2889 HWTEST_F(WindowExtensionSessionImplTest, OnExtensionMessage, TestSize.Level1)
2890 {
2891     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2892     option->SetWindowName("OnExtensionMessage");
2893     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
2894     SessionInfo sessionInfo;
2895     window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2896     uint32_t code = 9999;
2897     int32_t persistentId = 1111;
2898     AAFwk::Want want;
2899     window->dataHandler_ = nullptr;
2900     auto ret = window->OnExtensionMessage(code, persistentId, want);
2901     EXPECT_EQ(WMError::WM_OK, ret);
2902 
2903     code = static_cast<uint32_t>(Extension::Businesscode::NOTIFY_HOST_WINDOW_TO_RAISE);
2904     EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->OnExtensionMessage(code, persistentId, want));
2905     code = static_cast<uint32_t>(Extension::Businesscode::REGISTER_HOST_WINDOW_RECT_CHANGE_LISTENER);
2906     EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->OnExtensionMessage(code, persistentId, want));
2907     code = static_cast<uint32_t>(Extension::Businesscode::UNREGISTER_HOST_WINDOW_RECT_CHANGE_LISTENER);
2908     EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->OnExtensionMessage(code, persistentId, want));
2909 
2910     window->dataHandler_ = std::make_shared<Extension::MockDataHandler>();
2911     code = static_cast<uint32_t>(Extension::Businesscode::NOTIFY_HOST_WINDOW_TO_RAISE);
2912     EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want));
2913     code = static_cast<uint32_t>(Extension::Businesscode::REGISTER_HOST_WINDOW_RECT_CHANGE_LISTENER);
2914     EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want));
2915     code = static_cast<uint32_t>(Extension::Businesscode::UNREGISTER_HOST_WINDOW_RECT_CHANGE_LISTENER);
2916     window->rectChangeUIExtListenerIds_.emplace(111);
2917     ASSERT_FALSE(window->rectChangeUIExtListenerIds_.empty());
2918     EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want));
2919     window->rectChangeUIExtListenerIds_.clear();
2920     EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want));
2921 }
2922 
2923 /**
2924  * @tc.name: OnExtensionMessage_KeyboardListener
2925  * @tc.desc: OnExtensionMessage_KeyboardListener test
2926  * @tc.type: FUNC
2927  */
2928 HWTEST_F(WindowExtensionSessionImplTest, OnExtensionMessage_KeyboardListener, TestSize.Level1)
2929 {
2930     SessionInfo sessionInfo;
2931     window_->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2932     uint32_t code = 9999;
2933     int32_t persistentId = 1111;
2934     AAFwk::Want want;
2935     code = static_cast<uint32_t>(Extension::Businesscode::REGISTER_KEYBOARD_DID_SHOW_LISTENER);
2936     EXPECT_EQ(WMError::WM_OK, window_->OnExtensionMessage(code, persistentId, want));
2937     code = static_cast<uint32_t>(Extension::Businesscode::REGISTER_KEYBOARD_DID_HIDE_LISTENER);
2938     EXPECT_EQ(WMError::WM_OK, window_->OnExtensionMessage(code, persistentId, want));
2939     code = static_cast<uint32_t>(Extension::Businesscode::UNREGISTER_KEYBOARD_DID_SHOW_LISTENER);
2940     EXPECT_EQ(WMError::WM_OK, window_->OnExtensionMessage(code, persistentId, want));
2941     code = static_cast<uint32_t>(Extension::Businesscode::UNREGISTER_KEYBOARD_DID_HIDE_LISTENER);
2942     EXPECT_EQ(WMError::WM_OK, window_->OnExtensionMessage(code, persistentId, want));
2943 }
2944 
2945 /**
2946  * @tc.name: UpdateExtensionConfig
2947  * @tc.desc: UpdateExtensionConfig test
2948  * @tc.type: FUNC
2949  */
2950 HWTEST_F(WindowExtensionSessionImplTest, UpdateExtensionConfig, TestSize.Level1)
2951 {
2952     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2953     option->SetWindowName("UpdateExtensionConfig");
2954     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
2955     SessionInfo sessionInfo;
2956     window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2957     window->crossAxisState_ = CrossAxisState::STATE_INVALID;
2958     auto want = std::make_shared<AAFwk::Want>();
2959     window->UpdateExtensionConfig(want);
2960     EXPECT_EQ(window->crossAxisState_.load(), CrossAxisState::STATE_INVALID);
2961 
2962     AAFwk::WantParams configParam;
2963     AAFwk::WantParams wantParam(want->GetParams());
2964     configParam.SetParam(Extension::CROSS_AXIS_FIELD,
2965         AAFwk::Integer::Box(static_cast<int32_t>(CrossAxisState::STATE_CROSS)));
2966     wantParam.SetParam(Extension::UIEXTENSION_CONFIG_FIELD, AAFwk::WantParamWrapper::Box(configParam));
2967     want->SetParams(wantParam);
2968     window->UpdateExtensionConfig(want);
2969     EXPECT_EQ(window->crossAxisState_.load(), CrossAxisState::STATE_CROSS);
2970     configParam.SetParam(Extension::CROSS_AXIS_FIELD,
2971         AAFwk::Integer::Box(static_cast<int32_t>(CrossAxisState::STATE_INVALID)));
2972     wantParam.SetParam(Extension::UIEXTENSION_CONFIG_FIELD, AAFwk::WantParamWrapper::Box(configParam));
2973     want->SetParams(wantParam);
2974     window->UpdateExtensionConfig(want);
2975     EXPECT_EQ(window->crossAxisState_.load(), CrossAxisState::STATE_INVALID);
2976     configParam.SetParam(Extension::CROSS_AXIS_FIELD,
2977         AAFwk::Integer::Box(static_cast<int32_t>(CrossAxisState::STATE_NO_CROSS)));
2978     wantParam.SetParam(Extension::UIEXTENSION_CONFIG_FIELD, AAFwk::WantParamWrapper::Box(configParam));
2979     want->SetParams(wantParam);
2980     window->UpdateExtensionConfig(want);
2981     EXPECT_EQ(window->crossAxisState_.load(), CrossAxisState::STATE_NO_CROSS);
2982     configParam.SetParam(Extension::CROSS_AXIS_FIELD,
2983         AAFwk::Integer::Box(static_cast<int32_t>(CrossAxisState::STATE_END)));
2984     wantParam.SetParam(Extension::UIEXTENSION_CONFIG_FIELD, AAFwk::WantParamWrapper::Box(configParam));
2985     want->SetParams(wantParam);
2986     window->UpdateExtensionConfig(want);
2987     EXPECT_EQ(window->crossAxisState_.load(), CrossAxisState::STATE_NO_CROSS);
2988 
2989     bool isHostWindowDelayRaiseEnabled = true;
2990     configParam.SetParam(Extension::HOST_WINDOW_DELAY_RAISE_STATE_FIELD,
2991         AAFwk::Integer::Box(static_cast<int32_t>(isHostWindowDelayRaiseEnabled)));
2992     wantParam.SetParam(Extension::UIEXTENSION_CONFIG_FIELD, AAFwk::WantParamWrapper::Box(configParam));
2993     want->SetParams(wantParam);
2994     window->UpdateExtensionConfig(want);
2995     EXPECT_EQ(window->IsWindowDelayRaiseEnabled(), isHostWindowDelayRaiseEnabled);
2996     isHostWindowDelayRaiseEnabled = false;
2997     configParam.SetParam(Extension::HOST_WINDOW_DELAY_RAISE_STATE_FIELD,
2998         AAFwk::Integer::Box(static_cast<int32_t>(isHostWindowDelayRaiseEnabled)));
2999     wantParam.SetParam(Extension::UIEXTENSION_CONFIG_FIELD, AAFwk::WantParamWrapper::Box(configParam));
3000     want->SetParams(wantParam);
3001     window->UpdateExtensionConfig(want);
3002     EXPECT_EQ(window->IsWindowDelayRaiseEnabled(), isHostWindowDelayRaiseEnabled);
3003 }
3004 
3005 /**
3006  * @tc.name: IsComponentFocused
3007  * @tc.desc: IsComponentFocused test
3008  * @tc.type: FUNC
3009  */
3010 HWTEST_F(WindowExtensionSessionImplTest, IsComponentFocused, TestSize.Level1)
3011 {
3012     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
3013     option->SetWindowName("IsComponentFocused");
3014     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
3015     EXPECT_FALSE(window->IsComponentFocused());
3016 
3017     SessionInfo sessionInfo;
3018     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
3019     window->hostSession_ = session;
3020     window->property_->SetPersistentId(1);
3021     EXPECT_FALSE(window->IsComponentFocused());
3022     window->focusState_ = false;
3023     EXPECT_FALSE(window->IsComponentFocused());
3024     window->focusState_ = true;
3025     EXPECT_TRUE(window->IsComponentFocused());
3026 }
3027 
3028 /**
3029  * @tc.name: GetGestureBackEnabled
3030  * @tc.desc: GetGestureBackEnabled test
3031  * @tc.type: FUNC
3032  */
3033 HWTEST_F(WindowExtensionSessionImplTest, GetGestureBackEnabled, TestSize.Level1)
3034 {
3035     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
3036     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
3037     window->property_->SetWindowName("GetGestureBackEnabled");
3038     bool enable = false;
3039     window->hostGestureBackEnabled_ = false;
3040     EXPECT_EQ(WMError::WM_OK, window->GetGestureBackEnabled(enable));
3041     EXPECT_EQ(false, enable);
3042     window->hostGestureBackEnabled_ = true;
3043     EXPECT_EQ(WMError::WM_OK, window->GetGestureBackEnabled(enable));
3044     EXPECT_EQ(true, enable);
3045 }
3046 
3047 /**
3048  * @tc.name: SetLayoutFullScreen
3049  * @tc.desc: SetLayoutFullScreen test
3050  * @tc.type: FUNC
3051  */
3052 HWTEST_F(WindowExtensionSessionImplTest, SetLayoutFullScreen, TestSize.Level1)
3053 {
3054     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
3055     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
3056     window->property_->SetWindowName("SetLayoutFullScreen");
3057     EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetLayoutFullScreen(false));
3058 
3059     SessionInfo sessionInfo;
3060     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
3061     window->hostSession_ = session;
3062     window->property_->SetPersistentId(1);
3063     EXPECT_EQ(WMError::WM_OK, window->SetLayoutFullScreen(false));
3064     EXPECT_EQ(false, window->isIgnoreSafeArea_);
3065     EXPECT_EQ(WMError::WM_OK, window->SetLayoutFullScreen(true));
3066     EXPECT_EQ(true, window->isIgnoreSafeArea_);
3067 }
3068 
3069 /**
3070  * @tc.name: UpdateSystemBarProperties
3071  * @tc.desc: UpdateSystemBarProperties test
3072  * @tc.type: FUNC
3073  */
3074 HWTEST_F(WindowExtensionSessionImplTest, UpdateSystemBarProperties, TestSize.Level1)
3075 {
3076     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
3077     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
3078     window->property_->SetWindowName("UpdateSystemBarProperties");
3079     std::unordered_map<WindowType, SystemBarProperty> systemBarProperties;
3080     std::unordered_map<WindowType, SystemBarPropertyFlag> systemBarPropertyFlags;
3081     systemBarProperties[WindowType::WINDOW_TYPE_STATUS_BAR].enable_ = false;
3082     systemBarProperties[WindowType::WINDOW_TYPE_NAVIGATION_BAR].enable_ = false;
3083     EXPECT_EQ(WMError::WM_ERROR_IPC_FAILED,
3084         window->UpdateSystemBarProperties(systemBarProperties, systemBarPropertyFlags));
3085 
3086     SessionInfo sessionInfo;
3087     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
3088     window->hostSession_ = session;
3089     window->property_->SetPersistentId(1);
3090     EXPECT_CALL(*session, TransferExtensionData).WillOnce(Return(ERR_NONE));
3091     EXPECT_EQ(WMError::WM_OK, window->UpdateSystemBarProperties(systemBarProperties, systemBarPropertyFlags));
3092 }
3093 
3094 /**
3095  * @tc.name: SetGestureBackEnabled
3096  * @tc.desc: SetGestureBackEnabled test
3097  * @tc.type: FUNC
3098  */
3099 HWTEST_F(WindowExtensionSessionImplTest, SetGestureBackEnabled, TestSize.Level1)
3100 {
3101     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
3102     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
3103     window->property_->SetWindowName("SetGestureBackEnabled");
3104     EXPECT_EQ(WMError::WM_ERROR_IPC_FAILED, window->SetGestureBackEnabled(true));
3105 
3106     SessionInfo sessionInfo;
3107     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
3108     window->hostSession_ = session;
3109     window->property_->SetPersistentId(1);
3110     EXPECT_CALL(*session, TransferExtensionData).WillOnce(Return(ERR_NONE));
3111     EXPECT_EQ(WMError::WM_OK, window->SetGestureBackEnabled(true));
3112 }
3113 
3114 /**
3115  * @tc.name: SetImmersiveModeEnabledState
3116  * @tc.desc: SetImmersiveModeEnabledState test
3117  * @tc.type: FUNC
3118  */
3119 HWTEST_F(WindowExtensionSessionImplTest, SetImmersiveModeEnabledState, TestSize.Level1)
3120 {
3121     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
3122     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
3123     window->property_->SetWindowName("SetImmersiveModeEnabledState");
3124     EXPECT_EQ(WMError::WM_ERROR_IPC_FAILED, window->SetImmersiveModeEnabledState(true));
3125 
3126     SessionInfo sessionInfo;
3127     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
3128     window->hostSession_ = session;
3129     window->property_->SetPersistentId(1);
3130     EXPECT_CALL(*session, TransferExtensionData).WillOnce(Return(ERR_NONE));
3131     EXPECT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(true));
3132 }
3133 
3134 /**
3135  * @tc.name: GetImmersiveModeEnabledState
3136  * @tc.desc: GetImmersiveModeEnabledState test
3137  * @tc.type: FUNC
3138  */
3139 HWTEST_F(WindowExtensionSessionImplTest, GetImmersiveModeEnabledState, TestSize.Level1)
3140 {
3141     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
3142     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
3143     window->property_->SetWindowName("GetImmersiveModeEnabledState");
3144     window->hostImmersiveModeEnabled_ = false;
3145     EXPECT_EQ(false, window->GetImmersiveModeEnabledState());
3146     window->hostImmersiveModeEnabled_ = true;
3147     EXPECT_EQ(true, window->GetImmersiveModeEnabledState());
3148 }
3149 
3150 /**
3151  * @tc.name: UpdateHostSpecificSystemBarEnabled
3152  * @tc.desc: UpdateHostSpecificSystemBarEnabled test
3153  * @tc.type: FUNC
3154  */
3155 HWTEST_F(WindowExtensionSessionImplTest, UpdateHostSpecificSystemBarEnabled, TestSize.Level1)
3156 {
3157     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
3158     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
3159     window->property_->SetWindowName("UpdateHostSpecificSystemBarEnabled");
3160     EXPECT_EQ(WMError::WM_ERROR_IPC_FAILED, window->UpdateHostSpecificSystemBarEnabled("status", true, true));
3161 
3162     SessionInfo sessionInfo;
3163     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
3164     window->hostSession_ = session;
3165     window->property_->SetPersistentId(1);
3166     EXPECT_CALL(*session, TransferExtensionData).WillOnce(Return(ERR_NONE));
3167     EXPECT_EQ(WMError::WM_OK, window->UpdateHostSpecificSystemBarEnabled("status", true, true));
3168 }
3169 
3170 /**
3171  * @tc.name: ExtensionSetKeepScreenOn
3172  * @tc.desc: ExtensionSetKeepScreenOn test
3173  * @tc.type: FUNC
3174  */
3175 HWTEST_F(WindowExtensionSessionImplTest, ExtensionSetKeepScreenOn, TestSize.Level1)
3176 {
3177     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
3178     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
3179     window->property_->SetWindowName("ExtensionSetKeepScreenOn");
3180     EXPECT_EQ(WMError::WM_ERROR_IPC_FAILED, window->ExtensionSetKeepScreenOn(true));
3181 
3182     SessionInfo sessionInfo;
3183     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
3184     window->hostSession_ = session;
3185     window->property_->SetPersistentId(1);
3186     EXPECT_CALL(*session, TransferExtensionData).WillOnce(Return(ERR_NONE));
3187     EXPECT_EQ(WMError::WM_OK, window->ExtensionSetKeepScreenOn(true));
3188 }
3189 
3190 /**
3191  * @tc.name: ExtensionSetBrightness
3192  * @tc.desc: ExtensionSetBrightness test
3193  * @tc.type: FUNC
3194  */
3195 HWTEST_F(WindowExtensionSessionImplTest, ExtensionSetBrightness, TestSize.Level1)
3196 {
3197     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
3198     sptr<WindowExtensionSessionImpl> window = sptr<WindowExtensionSessionImpl>::MakeSptr(option);
3199     window->property_->SetWindowName("ExtensionSetBrightness");
3200     EXPECT_EQ(WMError::WM_ERROR_IPC_FAILED, window->ExtensionSetBrightness(0.5));
3201 
3202     SessionInfo sessionInfo;
3203     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
3204     window->hostSession_ = session;
3205     window->property_->SetPersistentId(1);
3206     EXPECT_CALL(*session, TransferExtensionData).WillOnce(Return(ERR_NONE));
3207     EXPECT_EQ(WMError::WM_OK, window->ExtensionSetBrightness(0.5));
3208 }
3209 
3210 /**
3211  * @tc.name: OnScreenshot
3212  * @tc.desc: OnScreenshot Test
3213  * @tc.type: FUNC
3214  */
3215 HWTEST_F(WindowExtensionSessionImplTest, OnScreenshot, TestSize.Level1)
3216 {
3217     AAFwk::Want want;
3218     std::optional<AAFwk::Want> reply = std::make_optional<AAFwk::Want>();
3219     EXPECT_EQ(WMError::WM_OK, window_->OnScreenshot(std::move(want), reply));
3220 }
3221 
3222 /**
3223  * @tc.name: OnExtensionSecureLimitChange
3224  * @tc.desc: OnExtensionSecureLimitChange Test
3225  * @tc.type: FUNC
3226  */
3227 HWTEST_F(WindowExtensionSessionImplTest, OnExtensionSecureLimitChange, TestSize.Level1)
3228 {
3229     AAFwk::Want want;
3230     want.SetParam(Extension::EXTENSION_SECURE_LIMIT_CHANGE, true);
3231     std::optional<AAFwk::Want> reply = std::make_optional<AAFwk::Want>();
3232     EXPECT_EQ(WMError::WM_OK, window_->OnExtensionSecureLimitChange(std::move(want), reply));
3233 }
3234 
3235 /**
3236  * @tc.name: RegisterKeyboardDidShowListener
3237  * @tc.desc: RegisterKeyboardDidShowListener Test
3238  * @tc.type: FUNC
3239  */
3240 HWTEST_F(WindowExtensionSessionImplTest, RegisterKeyboardDidShowListener, TestSize.Level1)
3241 {
3242     window_->dataHandler_ = nullptr;
3243     sptr<IKeyboardDidShowListener> listener = sptr<IKeyboardDidShowListener>::MakeSptr();
3244     EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window_->RegisterKeyboardDidShowListener(listener));
3245     window_->dataHandler_ = std::make_shared<Extension::MockDataHandler>();
3246 
3247     EXPECT_EQ(WMError::WM_OK, window_->RegisterKeyboardDidShowListener(listener));
3248     // Test listener already registered
3249     EXPECT_EQ(WMError::WM_OK, window_->RegisterKeyboardDidShowListener(listener));
3250 }
3251 
3252 /**
3253  * @tc.name: UnregisterKeyboardDidShowListener
3254  * @tc.desc: UnregisterKeyboardDidShowListener Test
3255  * @tc.type: FUNC
3256  */
3257 HWTEST_F(WindowExtensionSessionImplTest, UnregisterKeyboardDidShowListener, TestSize.Level1)
3258 {
3259     window_->dataHandler_ = nullptr;
3260     sptr<IKeyboardDidShowListener> listener = nullptr;
3261     EXPECT_EQ(WMError::WM_ERROR_NULLPTR, window_->UnregisterKeyboardDidShowListener(listener));
3262 
3263     // Test need notify host
3264     listener = sptr<IKeyboardDidShowListener>::MakeSptr();
3265     window_->dataHandler_ = std::make_shared<Extension::MockDataHandler>();
3266     window_->RegisterKeyboardDidShowListener(listener);
3267     EXPECT_EQ(WMError::WM_OK, window_->UnregisterKeyboardDidShowListener(listener));
3268     ASSERT_TRUE(window_->keyboardDidShowListenerList_.empty());
3269 
3270     // Test no need notify host
3271     window_->keyboardDidShowUIExtListeners_[1] = listener;
3272     EXPECT_EQ(WMError::WM_OK, window_->UnregisterKeyboardDidShowListener(listener));
3273 }
3274 
3275 /**
3276  * @tc.name: RegisterKeyboardDidHideListener
3277  * @tc.desc: RegisterKeyboardDidHideListener Test
3278  * @tc.type: FUNC
3279  */
3280 HWTEST_F(WindowExtensionSessionImplTest, RegisterKeyboardDidHideListener, TestSize.Level1)
3281 {
3282     window_->dataHandler_ = nullptr;
3283     sptr<IKeyboardDidHideListener> listener = sptr<IKeyboardDidHideListener>::MakeSptr();
3284     EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window_->RegisterKeyboardDidHideListener(listener));
3285     window_->dataHandler_ = std::make_shared<Extension::MockDataHandler>();
3286 
3287     EXPECT_EQ(WMError::WM_OK, window_->RegisterKeyboardDidHideListener(listener));
3288     // Test listener already registered
3289     EXPECT_EQ(WMError::WM_OK, window_->RegisterKeyboardDidHideListener(listener));
3290 }
3291 
3292 /**
3293  * @tc.name: UnregisterKeyboardDidHideListener
3294  * @tc.desc: UnregisterKeyboardDidHideListener Test
3295  * @tc.type: FUNC
3296  */
3297 HWTEST_F(WindowExtensionSessionImplTest, UnregisterKeyboardDidHideListener, TestSize.Level1)
3298 {
3299     window_->dataHandler_ = nullptr;
3300     sptr<IKeyboardDidHideListener> listener = nullptr;
3301     EXPECT_EQ(WMError::WM_ERROR_NULLPTR, window_->UnregisterKeyboardDidHideListener(listener));
3302 
3303     // Test need notify host
3304     listener = sptr<IKeyboardDidHideListener>::MakeSptr();
3305     window_->dataHandler_ = std::make_shared<Extension::MockDataHandler>();
3306     window_->RegisterKeyboardDidHideListener(listener);
3307     EXPECT_EQ(WMError::WM_OK, window_->UnregisterKeyboardDidHideListener(listener));
3308     ASSERT_TRUE(window_->keyboardDidHideListenerList_.empty());
3309 
3310     // Test no need notify host
3311     window_->keyboardDidHideUIExtListeners_[1] = listener;
3312     EXPECT_EQ(WMError::WM_OK, window_->UnregisterKeyboardDidHideListener(listener));
3313 }
3314 
3315 /**
3316  * @tc.name: OnKeyboardDidShow
3317  * @tc.desc: OnKeyboardDidShow Test
3318  * @tc.type: FUNC
3319  */
3320 HWTEST_F(WindowExtensionSessionImplTest, OnKeyboardDidShow, TestSize.Level1)
3321 {
3322     AAFwk::Want want;
3323     std::optional<AAFwk::Want> reply;
3324     sptr<IKeyboardDidShowListener> listener = sptr<IKeyboardDidShowListener>::MakeSptr();
3325     window_->dataHandler_ = std::make_shared<Extension::MockDataHandler>();
3326     window_->RegisterKeyboardDidShowListener(listener);
3327     EXPECT_EQ(WMError::WM_OK, window_->OnKeyboardDidShow(std::move(want), reply));
3328     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
3329     EXPECT_EQ(WMError::WM_OK, window_->OnKeyboardDidShow(std::move(want), reply));
3330 }
3331 
3332 /**
3333  * @tc.name: OnKeyboardDidHide
3334  * @tc.desc: OnKeyboardDidHide Test
3335  * @tc.type: FUNC
3336  */
3337 HWTEST_F(WindowExtensionSessionImplTest, OnKeyboardDidHide, TestSize.Level1)
3338 {
3339     AAFwk::Want want;
3340     std::optional<AAFwk::Want> reply;
3341     sptr<IKeyboardDidHideListener> listener = sptr<IKeyboardDidHideListener>::MakeSptr();
3342     window_->dataHandler_ = std::make_shared<Extension::MockDataHandler>();
3343     window_->RegisterKeyboardDidHideListener(listener);
3344     EXPECT_EQ(WMError::WM_OK, window_->OnKeyboardDidHide(std::move(want), reply));
3345     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
3346     EXPECT_EQ(WMError::WM_OK, window_->OnKeyboardDidHide(std::move(want), reply));
3347 }
3348 
3349 /**
3350  * @tc.name: OnHostStatusBarContentColorChange
3351  * @tc.desc: OnHostStatusBarContentColorChange Test
3352  * @tc.type: FUNC
3353  */
3354 HWTEST_F(WindowExtensionSessionImplTest, OnHostStatusBarContentColorChange, TestSize.Level1)
3355 {
3356     AAFwk::Want want;
3357     std::optional<AAFwk::Want> reply;
3358     want.SetParam(Extension::HOST_STATUS_BAR_CONTENT_COLOR, static_cast<int32_t>(8888));
3359     EXPECT_EQ(WMError::WM_OK, window_->OnHostStatusBarContentColorChange(std::move(want), reply));
3360     EXPECT_EQ(8888, window_->GetHostStatusBarContentColor());
3361 }
3362 
3363 /**
3364  * @tc.name: RegisterOccupiedAreaChangeListener
3365  * @tc.desc: RegisterOccupiedAreaChangeListener Test
3366  * @tc.type: FUNC
3367  */
3368 HWTEST_F(WindowExtensionSessionImplTest, RegisterOccupiedAreaChangeListener, TestSize.Level1)
3369 {
3370     sptr<IOccupiedAreaChangeListener> listener = sptr<IOccupiedAreaChangeListener>::MakeSptr();
3371     EXPECT_EQ(WMError::WM_OK, window_->RegisterOccupiedAreaChangeListener(listener));
3372     sptr<OccupiedAreaChangeInfo> info = sptr<OccupiedAreaChangeInfo>::MakeSptr();
3373     window_->NotifyOccupiedAreaChange(info);
3374     EXPECT_EQ(WMError::WM_OK, window_->UnregisterOccupiedAreaChangeListener(listener));
3375 }
3376 
3377 /**
3378  * @tc.name: UpdateRotateDuration
3379  * @tc.desc: UpdateRotateDuration Test
3380  * @tc.type: FUNC
3381  */
3382 HWTEST_F(WindowExtensionSessionImplTest, UpdateRotateDuration, TestSize.Level2)
3383 {
3384     WindowSizeChangeReason reason = WindowSizeChangeReason::SNAPSHOT_ROTATION;
3385     int32_t duration = -1;
3386     int32_t transactionDuration = 123;
3387     std::shared_ptr<RSTransaction> rsTransaction = std::make_shared<RSTransaction>();
3388     rsTransaction->duration_ = transactionDuration;
3389     window_->UpdateRotateDuration(reason, duration, rsTransaction);
3390     EXPECT_EQ(duration, transactionDuration);
3391     EXPECT_EQ(reason, WindowSizeChangeReason::ROTATION);
3392 
3393     duration = -1;
3394     reason = WindowSizeChangeReason::ROTATION;
3395     window_->UpdateRotateDuration(reason, duration, rsTransaction);
3396     EXPECT_EQ(duration, transactionDuration);
3397     EXPECT_EQ(reason, WindowSizeChangeReason::ROTATION);
3398 }
3399 }
3400 } // namespace Rosen
3401 } // namespace OHOS