• 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 <transaction/rs_transaction.h>
21 
22 #include "accessibility_event_info.h"
23 #include "display_info.h"
24 #include "extension/extension_business_info.h"
25 #include "extension_data_handler.h"
26 #include "iremote_object_mocker.h"
27 #include "mock_session.h"
28 #include "mock_uicontent.h"
29 #include "window_extension_session_impl.h"
30 
31 using namespace testing;
32 using namespace testing::ext;
33 using namespace OHOS::Accessibility;
34 using namespace std;
35 namespace OHOS {
36 namespace Rosen {
37 class WindowExtensionSessionImplTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp() override;
42     void TearDown() override;
43 private:
44     sptr<WindowExtensionSessionImpl> window_ = nullptr;
45     std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
46     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
47 };
48 
SetUpTestCase()49 void WindowExtensionSessionImplTest::SetUpTestCase()
50 {
51 }
52 
TearDownTestCase()53 void WindowExtensionSessionImplTest::TearDownTestCase()
54 {
55 }
56 
SetUp()57 void WindowExtensionSessionImplTest::SetUp()
58 {
59     sptr<WindowOption> option = new(std::nothrow) WindowOption();
60     ASSERT_NE(nullptr, option);
61     option->SetWindowName("WindowExtensionSessionImplTest");
62     window_ = new(std::nothrow) WindowExtensionSessionImpl(option);
63     ASSERT_NE(nullptr, window_);
64     if (!handler_) {
65         auto runner = AppExecFwk::EventRunner::Create("WindowExtensionSessionImplTest");
66         handler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
67     }
68     window_->handler_ = handler_;
69 }
70 
TearDown()71 void WindowExtensionSessionImplTest::TearDown()
72 {
73     window_ = nullptr;
74 }
75 
76 namespace {
77 /**
78  * @tc.name: WindowExtensionSessionImpl
79  * @tc.desc: WindowExtensionSessionImpl contructor
80  * @tc.type: FUNC
81  */
82 HWTEST_F(WindowExtensionSessionImplTest, WindowExtensionSessionImpl, Function | SmallTest | Level3)
83 {
84     sptr<WindowOption> option = new(std::nothrow) WindowOption();
85     ASSERT_NE(nullptr, option);
86     option->uiExtensionUsage_ = static_cast<uint32_t>(UIExtensionUsage::MODAL);
87     option->uiExtensionUsage_ = static_cast<uint32_t>(UIExtensionUsage::CONSTRAINED_EMBEDDED);
88     ASSERT_NE(nullptr, option);
89     option->SetWindowName("WindowExtensionSessionImplTest");
90     sptr<WindowExtensionSessionImpl> window = new(std::nothrow) WindowExtensionSessionImpl(option);
91     ASSERT_NE(nullptr, window);
92     window = nullptr;
93 }
94 
95 /**
96  * @tc.name: Create01
97  * @tc.desc: normal test
98  * @tc.type: FUNC
99  */
100 HWTEST_F(WindowExtensionSessionImplTest, Create01, Function | SmallTest | Level3)
101 {
102     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
103     ASSERT_NE(nullptr, abilityContext);
104     SessionInfo sessionInfo;
105     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
106     ASSERT_NE(nullptr, session);
107     ASSERT_NE(nullptr, window_->property_);
108     window_->property_->SetPersistentId(1);
109     ASSERT_EQ(WMError::WM_OK, window_->Create(abilityContext, session));
110     ASSERT_EQ(WMError::WM_OK, window_->Destroy(false));
111 }
112 
113 /**
114  * @tc.name: Create02
115  * @tc.desc: context is nullptr, session is nullptr
116  * @tc.type: FUNC
117  */
118 HWTEST_F(WindowExtensionSessionImplTest, Create02, Function | SmallTest | Level3)
119 {
120     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->Create(nullptr, nullptr));
121 }
122 
123 /**
124  * @tc.name: Create03
125  * @tc.desc: context is not nullptr, session is nullptr
126  * @tc.type: FUNC
127  */
128 HWTEST_F(WindowExtensionSessionImplTest, Create03, Function | SmallTest | Level3)
129 {
130     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
131     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->Create(abilityContext, nullptr));
132 }
133 
134 /**
135  * @tc.name: Create04
136  * @tc.desc: connet failed
137  * @tc.type: FUNC
138  */
139 HWTEST_F(WindowExtensionSessionImplTest, Create04, Function | SmallTest | Level3)
140 {
141     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
142     ASSERT_NE(nullptr, abilityContext);
143     SessionInfo sessionInfo;
144     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
145     ASSERT_NE(nullptr, session);
146     ASSERT_NE(nullptr, window_->property_);
147     window_->property_->SetPersistentId(1);
148     EXPECT_CALL(*session, Connect).WillOnce(Return(WSError::WS_ERROR_NULLPTR));
149     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->Create(abilityContext, session));
150 }
151 
152 /**
153  * @tc.name: Destroy01
154  * @tc.desc: Destroy Test
155  * @tc.type: FUNC
156  */
157 HWTEST_F(WindowExtensionSessionImplTest, Destroy01, Function | SmallTest | Level3)
158 {
159     SessionInfo sessionInfo;
160     sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
161     ASSERT_NE(nullptr, session);
162     window_->hostSession_ = session;
163     ASSERT_NE(nullptr, window_->property_);
164     window_->property_->SetPersistentId(1);
165     ASSERT_EQ(WMError::WM_OK, window_->Destroy(false, false));
166 }
167 
168 /**
169  * @tc.name: Destroy02
170  * @tc.desc: Destroy Test, window session is invalid
171  * @tc.type: FUNC
172  */
173 HWTEST_F(WindowExtensionSessionImplTest, Destroy02, Function | SmallTest | Level3)
174 {
175     ASSERT_NE(nullptr, window_->property_);
176     window_->hostSession_ = nullptr;
177     window_->property_->SetPersistentId(0);
178     window_->state_= WindowState::STATE_DESTROYED;
179     ASSERT_NE(WMError::WM_OK, window_->Destroy(false, false));
180 }
181 
182 /**
183  * @tc.name: AddExtensionWindowStageToSCB
184  * @tc.desc: AddExtensionWindowStageToSCB Test
185  * @tc.type: FUNC
186  */
187 HWTEST_F(WindowExtensionSessionImplTest, AddExtensionWindowStageToSCB, Function | SmallTest | Level3)
188 {
189     ASSERT_NE(nullptr, window_);
190     window_->AddExtensionWindowStageToSCB();
191 
192     sptr<IRemoteObject> iRemoteObject = new IRemoteObjectMocker();
193     ASSERT_NE(nullptr, iRemoteObject);
194     window_->abilityToken_ = iRemoteObject;
195     window_->AddExtensionWindowStageToSCB();
196 
197     window_->surfaceNode_ = nullptr;
198     window_->AddExtensionWindowStageToSCB();
199 }
200 
201 /**
202  * @tc.name: RemoveExtensionWindowStageFromSCB
203  * @tc.desc: RemoveExtensionWindowStageFromSCB Test
204  * @tc.type: FUNC
205  */
206 HWTEST_F(WindowExtensionSessionImplTest, RemoveExtensionWindowStageFromSCB, Function | SmallTest | Level3)
207 {
208     ASSERT_NE(nullptr, window_);
209     window_->RemoveExtensionWindowStageFromSCB();
210 
211     sptr<IRemoteObject> iRemoteObject = new IRemoteObjectMocker();
212     ASSERT_NE(nullptr, iRemoteObject);
213     window_->abilityToken_ = iRemoteObject;
214     window_->RemoveExtensionWindowStageFromSCB();
215 }
216 
217 /**
218  * @tc.name: UpdateConfiguration01
219  * @tc.desc: UpdateConfiguration Test
220  * @tc.type: FUNC
221  */
222 HWTEST_F(WindowExtensionSessionImplTest, UpdateConfiguration01, Function | SmallTest | Level3)
223 {
224     std::shared_ptr<AppExecFwk::Configuration> configuration;
225     ASSERT_NE(nullptr, window_);
226     window_->UpdateConfiguration(configuration);
227 }
228 
229 /**
230  * @tc.name: UpdateConfiguration02
231  * @tc.desc: UpdateConfiguration Test
232  * @tc.type: FUNC
233  */
234 HWTEST_F(WindowExtensionSessionImplTest, UpdateConfiguration02, Function | SmallTest | Level3)
235 {
236     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
237     ASSERT_NE(nullptr, window_->uiContent_);
238     std::shared_ptr<AppExecFwk::Configuration> configuration;
239     window_->UpdateConfiguration(configuration);
240     usleep(WAIT_SYNC_IN_NS);
241 }
242 
243 /**
244  * @tc.name: UpdateConfigurationForAll01
245  * @tc.desc: UpdateConfigurationForAll01 Test
246  * @tc.type: FUNC
247  */
248 HWTEST_F(WindowExtensionSessionImplTest, UpdateConfigurationForAll01, Function | SmallTest | Level3)
249 {
250     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
251     ASSERT_NE(nullptr, window_);
252     window_->UpdateConfigurationForAll(configuration);
253 }
254 
255 /**
256  * @tc.name: UpdateConfigurationForAll02
257  * @tc.desc: UpdateConfigurationForAll02 Test
258  * @tc.type: FUNC
259  */
260 HWTEST_F(WindowExtensionSessionImplTest, UpdateConfigurationForAll02, Function | SmallTest | Level3)
261 {
262     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
263     ASSERT_NE(nullptr, window_);
264     window_->windowExtensionSessionSet_.insert(window_);
265     window_->UpdateConfigurationForAll(configuration);
266     window_->windowExtensionSessionSet_.erase(window_);
267 }
268 
269 /**
270  * @tc.name: UpdateConfigurationForAll03
271  * @tc.desc: UpdateConfigurationForAll03 Test
272  * @tc.type: FUNC
273  */
274 HWTEST_F(WindowExtensionSessionImplTest, UpdateConfigurationForAll03, Function | SmallTest | Level3)
275 {
276     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
277     ASSERT_NE(nullptr, abilityContext);
278     SessionInfo sessionInfo;
279     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
280     ASSERT_NE(nullptr, session);
281     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
282     ASSERT_NE(nullptr, window_->property_);
283     window_->property_->SetPersistentId(1);
284     ASSERT_EQ(WMError::WM_OK, window_->Create(abilityContext, session));
285     ASSERT_NE(nullptr, window_);
286     window_->windowExtensionSessionSet_.insert(window_);
287     std::vector<std::shared_ptr<AbilityRuntime::Context>> ignoreWindowContexts;
288     ignoreWindowContexts.push_back(abilityContext);
289     window_->UpdateConfigurationForAll(configuration, ignoreWindowContexts);
290     window_->windowExtensionSessionSet_.erase(window_);
291 }
292 
293 /**
294  * @tc.name: MoveTo01
295  * @tc.desc: MoveTo
296  * @tc.type: FUNC
297  */
298 HWTEST_F(WindowExtensionSessionImplTest, MoveTo01, Function | SmallTest | Level3)
299 {
300     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->MoveTo(0, 1));
301 }
302 
303 /**
304  * @tc.name: MoveTo02
305  * @tc.desc: MoveTo
306  * @tc.type: FUNC
307  */
308 HWTEST_F(WindowExtensionSessionImplTest, MoveTo02, Function | SmallTest | Level3)
309 {
310     SessionInfo sessionInfo;
311     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
312     ASSERT_NE(nullptr, window_->hostSession_);
313     ASSERT_NE(nullptr, window_->property_);
314     window_->property_->SetPersistentId(1);
315     ASSERT_EQ(WMError::WM_OK, window_->MoveTo(0, 1));
316 }
317 
318 /**
319  * @tc.name: Resize01
320  * @tc.desc: Resize
321  * @tc.type: FUNC
322  */
323 HWTEST_F(WindowExtensionSessionImplTest, Resize01, Function | SmallTest | Level3)
324 {
325     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->Resize(0, 1));
326 }
327 
328 /**
329  * @tc.name: Resize02
330  * @tc.desc: Resize
331  * @tc.type: FUNC
332  */
333 HWTEST_F(WindowExtensionSessionImplTest, Resize02, Function | SmallTest | Level3)
334 {
335     SessionInfo sessionInfo;
336     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
337     ASSERT_NE(nullptr, window_->hostSession_);
338     ASSERT_NE(nullptr, window_->property_);
339     window_->property_->SetPersistentId(1);
340     ASSERT_EQ(WMError::WM_OK, window_->Resize(0, 1));
341 }
342 
343 /**
344  * @tc.name: TransferAbilityResult01
345  * @tc.desc: TransferAbilityResult
346  * @tc.type: FUNC
347  */
348 HWTEST_F(WindowExtensionSessionImplTest, TransferAbilityResult01, Function | SmallTest | Level3)
349 {
350     AAFwk::Want want;
351     ASSERT_EQ(WMError::WM_ERROR_REPEAT_OPERATION, window_->TransferAbilityResult(1, want));
352 }
353 
354 /**
355  * @tc.name: TransferAbilityResult02
356  * @tc.desc: TransferAbilityResult
357  * @tc.type: FUNC
358  */
359 HWTEST_F(WindowExtensionSessionImplTest, TransferAbilityResult02, Function | SmallTest | Level3)
360 {
361     SessionInfo sessionInfo;
362     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
363     ASSERT_NE(nullptr, window_->hostSession_);
364     ASSERT_NE(nullptr, window_->property_);
365     window_->property_->SetPersistentId(1);
366     AAFwk::Want want;
367     ASSERT_EQ(WMError::WM_OK, window_->TransferAbilityResult(1, want));
368 }
369 
370 /**
371  * @tc.name: TransferExtensionData01
372  * @tc.desc: TransferExtensionData
373  * @tc.type: FUNC
374  */
375 HWTEST_F(WindowExtensionSessionImplTest, TransferExtensionData01, Function | SmallTest | Level3)
376 {
377     AAFwk::WantParams wantParams;
378     ASSERT_EQ(WMError::WM_ERROR_REPEAT_OPERATION, window_->TransferExtensionData(wantParams));
379 }
380 
381 /**
382  * @tc.name: TransferExtensionData02
383  * @tc.desc: TransferExtensionData
384  * @tc.type: FUNC
385  */
386 HWTEST_F(WindowExtensionSessionImplTest, TransferExtensionData02, Function | SmallTest | Level3)
387 {
388     SessionInfo sessionInfo;
389     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
390     ASSERT_NE(nullptr, window_->hostSession_);
391     ASSERT_NE(nullptr, window_->property_);
392     window_->property_->SetPersistentId(1);
393     AAFwk::WantParams wantParams;
394     ASSERT_EQ(WMError::WM_OK, window_->TransferExtensionData(wantParams));
395 }
396 
397 /**
398  * @tc.name: RegisterTransferComponentDataListener01
399  * @tc.desc: RegisterTransferComponentDataListener Test
400  * @tc.type: FUNC
401  */
402 HWTEST_F(WindowExtensionSessionImplTest, RegisterTransferComponentDataListener01, Function | SmallTest | Level3)
403 {
404     NotifyTransferComponentDataFunc func;
405     window_->RegisterTransferComponentDataListener(func);
406     ASSERT_EQ(nullptr, window_->notifyTransferComponentDataFunc_);
407 }
408 
409 /**
410  * @tc.name: RegisterTransferComponentDataListener02
411  * @tc.desc: RegisterTransferComponentDataListener Test
412  * @tc.type: FUNC
413  */
414 HWTEST_F(WindowExtensionSessionImplTest, RegisterTransferComponentDataListener02, Function | SmallTest | Level3)
415 {
416     SessionInfo sessionInfo;
417     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
418     ASSERT_NE(nullptr, window_->hostSession_);
419     ASSERT_NE(nullptr, window_->property_);
420     window_->property_->SetPersistentId(1);
421     NotifyTransferComponentDataFunc func;
422     window_->RegisterTransferComponentDataListener(func);
423 }
424 
425 /**
426  * @tc.name: NotifyTransferComponentData01
427  * @tc.desc: NotifyTransferComponentData Test
428  * @tc.type: FUNC
429  */
430 HWTEST_F(WindowExtensionSessionImplTest, NotifyTransferComponentData01, Function | SmallTest | Level3)
431 {
432     AAFwk::WantParams wantParams;
433     ASSERT_EQ(WSError::WS_OK, window_->NotifyTransferComponentData(wantParams));
434 }
435 
436 /**
437  * @tc.name: NotifyTransferComponentData02
438  * @tc.desc: NotifyTransferComponentData Test
439  * @tc.type: FUNC
440  */
441 HWTEST_F(WindowExtensionSessionImplTest, NotifyTransferComponentData02, Function | SmallTest | Level3)
442 {
443     SessionInfo sessionInfo;
444     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
445     ASSERT_NE(nullptr, window_->hostSession_);
446     ASSERT_NE(nullptr, window_->property_);
447     window_->property_->SetPersistentId(1);
__anoneb2327690202(const AAFwk::WantParams& wantParams) 448     NotifyTransferComponentDataFunc func = [](const AAFwk::WantParams& wantParams) -> AAFwk::WantParams {
449         AAFwk::WantParams retWantParams;
450         return retWantParams;
451     };
452     window_->RegisterTransferComponentDataListener(func);
453     AAFwk::WantParams wantParams;
454     ASSERT_EQ(WSError::WS_OK, window_->NotifyTransferComponentData(wantParams));
455 }
456 
457 /**
458  * @tc.name: NotifyTransferComponentDataSync01
459  * @tc.desc: NotifyTransferComponentDataSync Test
460  * @tc.type: FUNC
461  */
462 HWTEST_F(WindowExtensionSessionImplTest, NotifyTransferComponentDataSync01, Function | SmallTest | Level3)
463 {
464     AAFwk::WantParams wantParams;
465     AAFwk::WantParams reWantParams;
466     ASSERT_EQ(WSErrorCode::WS_ERROR_NOT_REGISTER_SYNC_CALLBACK,
467         window_->NotifyTransferComponentDataSync(wantParams, reWantParams));
468 }
469 
470 /**
471  * @tc.name: NotifyTransferComponentDataSync02
472  * @tc.desc: NotifyTransferComponentDataSync Test
473  * @tc.type: FUNC
474  */
475 HWTEST_F(WindowExtensionSessionImplTest, NotifyTransferComponentDataSync02, Function | SmallTest | Level3)
476 {
477     SessionInfo sessionInfo;
478     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
479     ASSERT_NE(nullptr, window_->hostSession_);
480     ASSERT_NE(nullptr, window_->property_);
481     window_->property_->SetPersistentId(1);
__anoneb2327690302(const AAFwk::WantParams& wantParams) 482     NotifyTransferComponentDataForResultFunc func = [](const AAFwk::WantParams& wantParams) -> AAFwk::WantParams {
483         AAFwk::WantParams retWantParams;
484         return retWantParams;
485     };
486     window_->RegisterTransferComponentDataForResultListener(func);
487     AAFwk::WantParams wantParams;
488     AAFwk::WantParams reWantParams;
489     ASSERT_EQ(WSErrorCode::WS_OK,
490         window_->NotifyTransferComponentDataSync(wantParams, reWantParams));
491 }
492 
493 /**
494  * @tc.name: RegisterTransferComponentDataForResultListener01
495  * @tc.desc: RegisterTransferComponentDataForResultListener Test
496  * @tc.type: FUNC
497  */
498 HWTEST_F(WindowExtensionSessionImplTest, RegisterTransferComponentDataForResultListen01, Function | SmallTest | Level3)
499 {
500     NotifyTransferComponentDataForResultFunc func;
501     window_->RegisterTransferComponentDataForResultListener(func);
502     ASSERT_EQ(nullptr, window_->notifyTransferComponentDataForResultFunc_);
503 }
504 
505 /**
506  * @tc.name: RegisterTransferComponentDataForResultListener02
507  * @tc.desc: RegisterTransferComponentDataForResultListener Test
508  * @tc.type: FUNC
509  */
510 HWTEST_F(WindowExtensionSessionImplTest, RegisterTransferComponentDataForResultListen02, Function | SmallTest | Level3)
511 {
512     SessionInfo sessionInfo;
513     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
514     ASSERT_NE(nullptr, window_->hostSession_);
515     ASSERT_NE(nullptr, window_->property_);
516     window_->property_->SetPersistentId(1);
517     NotifyTransferComponentDataForResultFunc func;
518     window_->RegisterTransferComponentDataForResultListener(func);
519 }
520 
521 /**
522  * @tc.name: TriggerBindModalUIExtension01
523  * @tc.desc: TriggerBindModalUIExtension01 Test
524  * @tc.type: FUNC
525  */
526 HWTEST_F(WindowExtensionSessionImplTest, TriggerBindModalUIExtension01, Function | SmallTest | Level3)
527 {
528     ASSERT_NE(nullptr, window_);
529     window_->TriggerBindModalUIExtension();
530 }
531 
532 /**
533  * @tc.name: TriggerBindModalUIExtension02
534  * @tc.desc: TriggerBindModalUIExtension02 Test
535  * @tc.type: FUNC
536  */
537 HWTEST_F(WindowExtensionSessionImplTest, TriggerBindModalUIExtension02, Function | SmallTest | Level3)
538 {
539     SessionInfo sessionInfo;
540     window_->hostSession_ = new (std::nothrow) SessionMocker(sessionInfo);
541     ASSERT_NE(nullptr, window_->hostSession_);
542     window_->TriggerBindModalUIExtension();
543 }
544 
545 /**
546  * @tc.name: SetPrivacyMode01
547  * @tc.desc: SetPrivacyMode Test
548  * @tc.type: FUNC
549  */
550 HWTEST_F(WindowExtensionSessionImplTest, SetPrivacyMode01, Function | SmallTest | Level3)
551 {
552     ASSERT_EQ(WMError::WM_OK, window_->SetPrivacyMode(false));
553     ASSERT_FALSE(window_->extensionWindowFlags_.privacyModeFlag);
554     ASSERT_EQ(WMError::WM_OK, window_->SetPrivacyMode(true));
555     ASSERT_TRUE(window_->extensionWindowFlags_.privacyModeFlag);
556 }
557 
558 /**
559  * @tc.name: SetPrivacyMode02
560  * @tc.desc: SetPrivacyMod
561  * @tc.type: FUNC
562  */
563 HWTEST_F(WindowExtensionSessionImplTest, SetPrivacyMod02, Function | SmallTest | Level3)
564 {
565     bool isPrivacyMode = true;
566     window_->surfaceNode_ = nullptr;
567     auto ret = window_->SetPrivacyMode(isPrivacyMode);
568 
569     struct RSSurfaceNodeConfig config;
570 
571     if (ret == WMError::WM_ERROR_NULLPTR) {
572         window_->surfaceNode_ = RSSurfaceNode::Create(config);
573     }
574     ASSERT_NE(WMError::WM_OK, ret);
575 }
576 
577 /**
578  * @tc.name: SetPrivacyMod03
579  * @tc.desc: SetPrivacyMod03
580  * @tc.type: FUNC
581  */
582 HWTEST_F(WindowExtensionSessionImplTest, SetPrivacyMod03, Function | SmallTest | Level3)
583 {
584     struct RSSurfaceNodeConfig config;
585     window_->surfaceNode_ = RSSurfaceNode::Create(config);
586     window_->state_ = WindowState::STATE_SHOWN;
587     ASSERT_NE(WMError::WM_OK, window_->SetPrivacyMode(true));
588 }
589 
590 /**
591  * @tc.name: SetPrivacyMod04
592  * @tc.desc: SetPrivacyMod04
593  * @tc.type: FUNC
594  */
595 HWTEST_F(WindowExtensionSessionImplTest, SetPrivacyMod04, Function | SmallTest | Level3)
596 {
597     struct RSSurfaceNodeConfig config;
598     window_->surfaceNode_ = RSSurfaceNode::Create(config);
599     window_->state_ = WindowState::STATE_SHOWN;
600     ASSERT_NE(WMError::WM_ERROR_INVALID_WINDOW, window_->SetPrivacyMode(false));
601 }
602 
603 /**
604  * @tc.name: SetPrivacyMod05
605  * @tc.desc: SetPrivacyMod05
606  * @tc.type: FUNC
607  */
608 HWTEST_F(WindowExtensionSessionImplTest, SetPrivacyMod05, Function | SmallTest | Level3)
609 {
610     struct RSSurfaceNodeConfig config;
611     window_->surfaceNode_ = RSSurfaceNode::Create(config);
612     window_->state_ = WindowState::STATE_SHOWN;
613     SessionInfo sessionInfo;
614     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
615     ASSERT_NE(nullptr, window_->hostSession_);
616     ASSERT_NE(WMError::WM_OK, window_->SetPrivacyMode(true));
617 }
618 
619 HWTEST_F(WindowExtensionSessionImplTest, HidePrivacyContentForHost, Function | SmallTest | Level3)
620 {
621     struct RSSurfaceNodeConfig config;
622     window_->surfaceNode_ = RSSurfaceNode::Create(config);
623     SessionInfo sessionInfo;
624     window_->hostSession_ = new (std::nothrow) SessionMocker(sessionInfo);
625     ASSERT_NE(nullptr, window_->hostSession_);
626     ASSERT_EQ(WMError::WM_OK, window_->HidePrivacyContentForHost(true));
627 }
628 
629 /**
630  * @tc.name: NotifyFocusStateEvent01
631  * @tc.desc: NotifyFocusStateEvent Test
632  * @tc.type: FUNC
633  */
634 HWTEST_F(WindowExtensionSessionImplTest, NotifyFocusStateEvent01, Function | SmallTest | Level3)
635 {
636     ASSERT_NE(nullptr, window_);
637     window_->NotifyFocusStateEvent(false);
638 }
639 
640 /**
641  * @tc.name: NotifyFocusStateEvent02
642  * @tc.desc: NotifyFocusStateEvent Test
643  * @tc.type: FUNC
644  */
645 HWTEST_F(WindowExtensionSessionImplTest, NotifyFocusStateEvent02, Function | SmallTest | Level3)
646 {
647     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
648     ASSERT_NE(nullptr, window_->uiContent_);
649     window_->NotifyFocusStateEvent(true);
650     usleep(WAIT_SYNC_IN_NS);
651 }
652 
653 /**
654  * @tc.name: NotifyFocusActiveEvent01
655  * @tc.desc: NotifyFocusActiveEvent Test
656  * @tc.type: FUNC
657  */
658 HWTEST_F(WindowExtensionSessionImplTest, NotifyFocusActiveEvent01, Function | SmallTest | Level3)
659 {
660     ASSERT_NE(nullptr, window_);
661     window_->NotifyFocusActiveEvent(false);
662 }
663 
664 /**
665  * @tc.name: NotifyFocusActiveEvent02
666  * @tc.desc: NotifyFocusActiveEvent Test
667  * @tc.type: FUNC
668  */
669 HWTEST_F(WindowExtensionSessionImplTest, NotifyFocusActiveEvent02, Function | SmallTest | Level3)
670 {
671     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
672     ASSERT_NE(nullptr, window_->uiContent_);
673     window_->NotifyFocusActiveEvent(true);
674     usleep(WAIT_SYNC_IN_NS);
675 }
676 
677 /**
678  * @tc.name: NotifyBackpressedEvent01
679  * @tc.desc: NotifyFocusActiveEvent Test
680  * @tc.type: FUNC
681  */
682 HWTEST_F(WindowExtensionSessionImplTest, NotifyBackpressedEvent01, Function | SmallTest | Level3)
683 {
684     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
685     ASSERT_NE(nullptr, window_->uiContent_);
686     bool isConsumed = false;
687     window_->NotifyBackpressedEvent(isConsumed);
688     usleep(WAIT_SYNC_IN_NS);
689 }
690 
691 /**
692  * @tc.name: NotifyBackpressedEvent02
693  * @tc.desc: NotifyFocusActiveEvent Test
694  * @tc.type: FUNC
695  */
696 HWTEST_F(WindowExtensionSessionImplTest, NotifyBackpressedEvent02, Function | SmallTest | Level3)
697 {
698     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
699     ASSERT_NE(nullptr, window_->uiContent_);
700     bool isConsumed = true;
701     window_->NotifyBackpressedEvent(isConsumed);
702     usleep(WAIT_SYNC_IN_NS);
703 }
704 
705 /**
706  * @tc.name: NotifyBackpressedEvent03
707  * @tc.desc: NotifyFocusActiveEvent Test
708  * @tc.type: FUNC
709  */
710 HWTEST_F(WindowExtensionSessionImplTest, NotifyBackpressedEvent03, Function | SmallTest | Level3)
711 {
712     ASSERT_NE(nullptr, window_);
713     window_->uiContent_ = nullptr;
714     bool isConsumed = true;
715     window_->NotifyBackpressedEvent(isConsumed);
716     usleep(WAIT_SYNC_IN_NS);
717 }
718 
719 /**
720  * @tc.name: InputMethodKeyEventResultCallback01
721  * @tc.desc: InputMethodKeyEventResultCallback01 Test
722  * @tc.type: FUNC
723  */
724 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback01, Function | SmallTest | Level3)
725 {
726     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
727     bool consumed = false;
728     auto isConsumedPromise = std::make_shared<std::promise<bool>>();
729     auto isTimeout = std::make_shared<bool>(false);
730     ASSERT_NE(nullptr, window_);
731     window_->InputMethodKeyEventResultCallback(keyEvent, consumed, isConsumedPromise, isTimeout);
732 }
733 
734 /**
735  * @tc.name: InputMethodKeyEventResultCallback02
736  * @tc.desc: InputMethodKeyEventResultCallback02 Test
737  * @tc.type: FUNC
738  */
739 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback02, Function | SmallTest | Level3)
740 {
741     bool consumed = false;
742     auto isConsumedPromise = std::make_shared<std::promise<bool>>();
743     auto isTimeout = std::make_shared<bool>(false);
744     ASSERT_NE(nullptr, window_);
745     window_->InputMethodKeyEventResultCallback(nullptr, consumed, isConsumedPromise, isTimeout);
746 }
747 
748 /**
749  * @tc.name: InputMethodKeyEventResultCallback03
750  * @tc.desc: InputMethodKeyEventResultCallback03 Test
751  * @tc.type: FUNC
752  */
753 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback03, Function | SmallTest | Level3)
754 {
755     bool consumed = false;
756     auto isTimeout = std::make_shared<bool>(false);
757     ASSERT_NE(nullptr, window_);
758     window_->InputMethodKeyEventResultCallback(nullptr, consumed, nullptr, isTimeout);
759 }
760 
761 /**
762  * @tc.name: InputMethodKeyEventResultCallback04
763  * @tc.desc: InputMethodKeyEventResultCallback04 Test
764  * @tc.type: FUNC
765  */
766 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback04, Function | SmallTest | Level3)
767 {
768     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
769     bool consumed = false;
770     auto isTimeout = std::make_shared<bool>(false);
771     ASSERT_NE(nullptr, window_);
772     window_->InputMethodKeyEventResultCallback(keyEvent, consumed, nullptr, isTimeout);
773 }
774 
775 /**
776  * @tc.name: InputMethodKeyEventResultCallback05
777  * @tc.desc: InputMethodKeyEventResultCallback05 Test
778  * @tc.type: FUNC
779  */
780 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback05, Function | SmallTest | Level3)
781 {
782     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
783     bool consumed = false;
784     auto isConsumedPromise = std::make_shared<std::promise<bool>>();
785     ASSERT_NE(nullptr, window_);
786     window_->InputMethodKeyEventResultCallback(keyEvent, consumed, isConsumedPromise, nullptr);
787 }
788 
789 /**
790  * @tc.name: InputMethodKeyEventResultCallback06
791  * @tc.desc: InputMethodKeyEventResultCallback06 Test
792  * @tc.type: FUNC
793  */
794 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback06, Function | SmallTest | Level3)
795 {
796     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
797     auto isConsumedPromise = std::make_shared<std::promise<bool>>();
798     auto isTimeout = std::make_shared<bool>(false);
799     ASSERT_NE(nullptr, window_);
800     window_->InputMethodKeyEventResultCallback(keyEvent, true, isConsumedPromise, isTimeout);
801 }
802 
803 /**
804  * @tc.name: InputMethodKeyEventResultCallback07
805  * @tc.desc: InputMethodKeyEventResultCallback07 Test
806  * @tc.type: FUNC
807  */
808 HWTEST_F(WindowExtensionSessionImplTest, InputMethodKeyEventResultCallback07, Function | SmallTest | Level3)
809 {
810     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
811     auto isConsumedPromise = std::make_shared<std::promise<bool>>();
812     auto isTimeout = std::make_shared<bool>(true);
813     ASSERT_NE(nullptr, window_);
814     window_->InputMethodKeyEventResultCallback(keyEvent, true, isConsumedPromise, isTimeout);
815 }
816 
817 /**
818  * @tc.name: NotifyKeyEvent01
819  * @tc.desc: NotifyKeyEvent01 Test
820  * @tc.type: FUNC
821  */
822 HWTEST_F(WindowExtensionSessionImplTest, NotifyKeyEvent01, Function | SmallTest | Level3)
823 {
824     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
825     keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_FN);
826     bool consumed = false;
827     bool notifyInputMethod = true;
828     ASSERT_NE(nullptr, window_);
829     window_->NotifyKeyEvent(keyEvent, consumed, notifyInputMethod);
830 }
831 
832 /**
833  * @tc.name: NotifyKeyEvent02
834  * @tc.desc: NotifyKeyEvent02 Test
835  * @tc.type: FUNC
836  */
837 HWTEST_F(WindowExtensionSessionImplTest, NotifyKeyEvent02, Function | SmallTest | Level3)
838 {
839     bool consumed = false;
840     bool notifyInputMethod = true;
841     ASSERT_NE(nullptr, window_);
842     window_->NotifyKeyEvent(nullptr, consumed, notifyInputMethod);
843 }
844 
845 /**
846  * @tc.name: NotifyKeyEvent03
847  * @tc.desc: NotifyKeyEvent03 Test
848  * @tc.type: FUNC
849  */
850 HWTEST_F(WindowExtensionSessionImplTest, NotifyKeyEvent03, Function | SmallTest | Level3)
851 {
852     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
853     bool consumed = false;
854     bool notifyInputMethod = true;
855     ASSERT_NE(nullptr, window_);
856     window_->NotifyKeyEvent(keyEvent, consumed, notifyInputMethod);
857 }
858 
859 /**
860  * @tc.name: NotifyKeyEvent04
861  * @tc.desc: NotifyKeyEvent04 Test
862  * @tc.type: FUNC
863  */
864 HWTEST_F(WindowExtensionSessionImplTest, NotifyKeyEvent04, Function | SmallTest | Level3)
865 {
866     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
867     keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_FN);
868     bool consumed = false;
869     bool notifyInputMethod = false;
870     ASSERT_NE(nullptr, window_);
871     window_->NotifyKeyEvent(keyEvent, consumed, notifyInputMethod);
872 }
873 
874 /**
875  * @tc.name: ArkUIFrameworkSupport01
876  * @tc.desc: ArkUIFrameworkSupport01 Test, context_ is nullptr
877  * @tc.type: FUNC
878  */
879 HWTEST_F(WindowExtensionSessionImplTest, ArkUIFrameworkSupport01, Function | SmallTest | Level3)
880 {
881     ASSERT_NE(nullptr, window_);
882     window_->context_ = nullptr;
883     window_->ArkUIFrameworkSupport();
884 }
885 
886 /**
887  * @tc.name: ArkUIFrameworkSupport02
888  * @tc.desc: ArkUIFrameworkSupport02 Test, context_->GetApplicationInfo() == nullptr
889  * @tc.type: FUNC
890  */
891 HWTEST_F(WindowExtensionSessionImplTest, ArkUIFrameworkSupport02, Function | SmallTest | Level3)
892 {
893     ASSERT_NE(nullptr, window_);
894     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
895     ASSERT_NE(nullptr, abilityContext);
896     abilityContext->stageContext_ = nullptr;
897     window_->context_ = abilityContext;
898     window_->ArkUIFrameworkSupport();
899 }
900 
901 /**
902  * @tc.name: ArkUIFrameworkSupport03
903  * @tc.desc: ArkUIFrameworkSupport03 Test, version < 10 and isSystembarPropertiesSet_ is true
904  * @tc.type: FUNC
905  */
906 HWTEST_F(WindowExtensionSessionImplTest, ArkUIFrameworkSupport03, Function | SmallTest | Level3)
907 {
908     ASSERT_NE(nullptr, window_);
909     window_->context_ = nullptr;
910     window_->isSystembarPropertiesSet_ = true;
911     window_->ArkUIFrameworkSupport();
912 }
913 
914 /**
915  * @tc.name: ArkUIFrameworkSupport04
916  * @tc.desc: ArkUIFrameworkSupport04 Test, version < 10 and isSystembarPropertiesSet_ is false
917  * @tc.type: FUNC
918  */
919 HWTEST_F(WindowExtensionSessionImplTest, ArkUIFrameworkSupport04, Function | SmallTest | Level3)
920 {
921     ASSERT_NE(nullptr, window_);
922     window_->context_ = nullptr;
923     window_->isSystembarPropertiesSet_ = false;
924     window_->ArkUIFrameworkSupport();
925 }
926 
927 /**
928  * @tc.name: ArkUIFrameworkSupport05
929  * @tc.desc: ArkUIFrameworkSupport05 Test, version >= 10 and isIgnoreSafeAreaNeedNotify_ is false
930  * @tc.type: FUNC
931  */
932 HWTEST_F(WindowExtensionSessionImplTest, ArkUIFrameworkSupport05, Function | SmallTest | Level3)
933 {
934     ASSERT_NE(nullptr, window_);
935     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
936     ASSERT_NE(nullptr, abilityContext);
937     auto stageContent = std::make_shared<AbilityRuntime::ContextImpl>();
938     ASSERT_NE(nullptr, stageContent);
939     std::shared_ptr<AppExecFwk::ApplicationInfo> applicationInfo = std::make_shared<AppExecFwk::ApplicationInfo>();
940     ASSERT_NE(nullptr, applicationInfo);
941     applicationInfo->apiCompatibleVersion = 12;
942     stageContent->SetApplicationInfo(applicationInfo);
943     abilityContext->stageContext_ = stageContent;
944     window_->context_ = abilityContext;
945     window_->isIgnoreSafeAreaNeedNotify_ = false;
946     window_->ArkUIFrameworkSupport();
947 }
948 
949 /**
950  * @tc.name: ArkUIFrameworkSupport06
951  * @tc.desc: ArkUIFrameworkSupport06 Test, version >= 10 and isIgnoreSafeAreaNeedNotify_ is true
952  * @tc.type: FUNC
953  */
954 HWTEST_F(WindowExtensionSessionImplTest, ArkUIFrameworkSupport06, Function | SmallTest | Level3)
955 {
956     ASSERT_NE(nullptr, window_);
957     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
958     ASSERT_NE(nullptr, abilityContext);
959     auto stageContent = std::make_shared<AbilityRuntime::ContextImpl>();
960     ASSERT_NE(nullptr, stageContent);
961     std::shared_ptr<AppExecFwk::ApplicationInfo> applicationInfo = std::make_shared<AppExecFwk::ApplicationInfo>();
962     ASSERT_NE(nullptr, applicationInfo);
963     applicationInfo->apiCompatibleVersion = 12;
964     stageContent->SetApplicationInfo(applicationInfo);
965     abilityContext->stageContext_ = stageContent;
966     window_->context_ = abilityContext;
967     window_->isIgnoreSafeAreaNeedNotify_ = true;
968     window_->ArkUIFrameworkSupport();
969 }
970 
971 /**
972  * @tc.name: NapiSetUIContent
973  * @tc.desc: NapiSetUIContent Test
974  * @tc.type: FUNC
975  */
976 HWTEST_F(WindowExtensionSessionImplTest, NapiSetUIContent, Function | SmallTest | Level3)
977 {
978     ASSERT_NE(nullptr, window_);
979     std::string contentInfo = "NapiSetUIContent test";
980     napi_env env = napi_env();
981     napi_value storage = napi_value();
982     sptr<IRemoteObject> token;
983     window_->uiContent_ = nullptr;
984     window_->property_->SetUIExtensionUsage(UIExtensionUsage::UIEXTENSION_USAGE_END);
985     window_->focusState_ = std::nullopt;
986     window_->state_ = WindowState::STATE_HIDDEN;
987     ASSERT_EQ(WMError::WM_OK,
988         window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
989 
990     auto uiContent = std::make_shared<Ace::UIContentMocker>();
991     ASSERT_NE(nullptr, uiContent);
992     window_->uiContent_ = uiContent;
993     window_->property_->SetUIExtensionUsage(UIExtensionUsage::CONSTRAINED_EMBEDDED);
994     window_->focusState_ = true;
995     window_->state_ = WindowState::STATE_SHOWN;
996     ASSERT_EQ(WMError::WM_OK,
997         window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
998     usleep(WAIT_SYNC_IN_NS);
999 
1000     window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
1001     ASSERT_EQ(WMError::WM_OK,
1002         window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
1003     window_->property_->SetUIExtensionUsage(UIExtensionUsage::EMBEDDED);
1004     ASSERT_EQ(WMError::WM_OK,
1005         window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
1006     window_->property_->SetUIExtensionUsage(UIExtensionUsage::UIEXTENSION_USAGE_END);
1007     ASSERT_EQ(WMError::WM_OK,
1008         window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
1009 }
1010 
1011 /**
1012  * @tc.name: NapiSetUIContentByName
1013  * @tc.desc: NapiSetUIContentByName Test
1014  * @tc.type: FUNC
1015  */
1016 HWTEST_F(WindowExtensionSessionImplTest, NapiSetUIContentByName, Function | SmallTest | Level3)
1017 {
1018     ASSERT_NE(nullptr, window_);
1019     std::string contentInfo = "NapiSetUIContentByName test";
1020     napi_env env = napi_env();
1021     napi_value storage = napi_value();
1022     sptr<IRemoteObject> token;
1023     window_->uiContent_ = nullptr;
1024     window_->property_->SetUIExtensionUsage(UIExtensionUsage::UIEXTENSION_USAGE_END);
1025     window_->focusState_ = std::nullopt;
1026     window_->state_ = WindowState::STATE_HIDDEN;
1027     ASSERT_EQ(WMError::WM_OK,
1028         window_->NapiSetUIContentByName(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
1029 
1030     auto uiContent = std::make_shared<Ace::UIContentMocker>();
1031     window_->uiContent_ = uiContent;
1032     window_->property_->SetUIExtensionUsage(UIExtensionUsage::CONSTRAINED_EMBEDDED);
1033     window_->focusState_ = true;
1034     window_->state_ = WindowState::STATE_SHOWN;
1035     ASSERT_EQ(WMError::WM_OK,
1036         window_->NapiSetUIContentByName(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
1037     usleep(WAIT_SYNC_IN_NS);
1038 }
1039 
1040 /**
1041  * @tc.name: UpdateRect01
1042  * @tc.desc: UpdateRect Test
1043  * @tc.type: FUNC
1044  */
1045 HWTEST_F(WindowExtensionSessionImplTest, UpdateRect01, Function | SmallTest | Level2)
1046 {
1047     WSRect rect;
1048     rect.posX_ = 0;
1049     rect.posY_ = 0;
1050     rect.height_ = 50;
1051     rect.width_ = 50;
1052 
1053     Rect preRect;
1054     preRect.posX_ = 0;
1055     preRect.posY_ = 0;
1056     preRect.height_ = 200;
1057     preRect.width_ = 200;
1058 
1059     ASSERT_NE(nullptr, window_->property_);
1060     window_->property_->SetWindowRect(preRect);
1061     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1062     ASSERT_EQ(WSError::WS_OK, window_->UpdateRect(rect, reason));
1063 
1064     preRect.height_ = 50;
1065     window_->property_->SetWindowRect(preRect);
1066     ASSERT_EQ(WSError::WS_OK, window_->UpdateRect(rect, reason));
1067 
1068     preRect.height_ = 200;
1069     preRect.width_ = 50;
1070     window_->property_->SetWindowRect(preRect);
1071     ASSERT_EQ(WSError::WS_OK, window_->UpdateRect(rect, reason));
1072 
1073     preRect.height_ = 50;
1074     preRect.width_ = 50;
1075     window_->property_->SetWindowRect(preRect);
1076     reason = SizeChangeReason::ROTATION;
1077     ASSERT_EQ(WSError::WS_OK, window_->UpdateRect(rect, reason));
1078 
1079     window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
1080     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, window_->UpdateRect(rect, reason));
1081 }
1082 
1083 /**
1084  * @tc.name: UpdateRectForRotation01
1085  * @tc.desc: UpdateRect Test
1086  * @tc.type: FUNC
1087  */
1088 HWTEST_F(WindowExtensionSessionImplTest, UpdateRectForRotation01, Function | SmallTest | Level2)
1089 {
1090     Rect rect;
1091     WindowSizeChangeReason wmReason = WindowSizeChangeReason{0};
1092     std::shared_ptr<RSTransaction> rsTransaction = std::make_shared<RSTransaction>();
1093     rsTransaction->syncId_ = 1;
1094     rsTransaction->isOpenSyncTransaction_ = true;
1095     ASSERT_NE(nullptr, window_);
1096     window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
1097 
1098     Rect preRect;
1099     window_->UpdateRectForRotation(rect, preRect, wmReason, rsTransaction);
1100 
1101     rsTransaction->isOpenSyncTransaction_ = false;
1102     window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
1103 
1104     rsTransaction->syncId_ = -1;
1105     window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
1106 
1107     rsTransaction = nullptr;
1108     window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
1109     window_->UpdateRectForOtherReason(rect, wmReason);
1110 
1111     window_->handler_ = nullptr;
1112     window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
1113     usleep(WAIT_SYNC_IN_NS);
1114 }
1115 
1116 /**
1117  * @tc.name: NotifyAccessibilityHoverEvent01
1118  * @tc.desc: NotifyAccessibilityHoverEvent Test
1119  * @tc.type: FUNC
1120  */
1121 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityHoverEvent01, Function | SmallTest | Level3)
1122 {
1123     float pointX = 0.0f;
1124     float pointY = 0.0f;
1125     int32_t sourceType = 0;
1126     int32_t eventType = 0;
1127     int64_t timeMs = 0;
1128     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1129     ASSERT_NE(nullptr, window_->uiContent_);
1130     ASSERT_EQ(WSError::WS_OK,
1131         window_->NotifyAccessibilityHoverEvent(pointX, pointY, sourceType, eventType, timeMs));
1132     usleep(WAIT_SYNC_IN_NS);
1133 }
1134 
1135 /**
1136  * @tc.name: NotifyAccessibilityHoverEvent02
1137  * @tc.desc: NotifyAccessibilityHoverEvent Test
1138  * @tc.type: FUNC
1139  */
1140 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityHoverEvent02, Function | SmallTest | Level3)
1141 {
1142     float pointX = 0.0f;
1143     float pointY = 0.0f;
1144     int32_t sourceType = 0;
1145     int32_t eventType = 0;
1146     int64_t timeMs = 0;
1147     window_->uiContent_ = nullptr;
1148     ASSERT_EQ(WSError::WS_ERROR_NO_UI_CONTENT_ERROR,
1149         window_->NotifyAccessibilityHoverEvent(pointX, pointY, sourceType, eventType, timeMs));
1150     usleep(WAIT_SYNC_IN_NS);
1151 }
1152 
1153 /**
1154  * @tc.name: TransferAccessibilityEvent
1155  * @tc.desc: TransferAccessibilityEvent Test
1156  * @tc.type: FUNC
1157  */
1158 HWTEST_F(WindowExtensionSessionImplTest, TransferAccessibilityEvent, Function | SmallTest | Level3)
1159 {
1160     SessionInfo sessionInfo;
1161     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1162     ASSERT_NE(nullptr, window_->hostSession_);
1163     Accessibility::AccessibilityEventInfo info;
1164     int64_t uiExtensionIdLevel = 1;
1165     ASSERT_NE(WMError::WM_OK, window_->TransferAccessibilityEvent(info, uiExtensionIdLevel));
1166 
1167     window_->hostSession_ = nullptr;
1168     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->TransferAccessibilityEvent(info, uiExtensionIdLevel));
1169 }
1170 
1171 /**
1172  * @tc.name: UpdateSessionViewportConfig1
1173  * @tc.desc: Normal test
1174  * @tc.type: FUNC
1175  */
1176 HWTEST_F(WindowExtensionSessionImplTest, UpdateSessionViewportConfig1, Function | SmallTest | Level2)
1177 {
1178     ASSERT_NE(nullptr, window_);
1179     ASSERT_NE(nullptr, window_->property_);
1180     window_->property_->SetDisplayId(0);
1181     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1182     ASSERT_NE(nullptr, window_->uiContent_);
1183 
1184     SessionViewportConfig config;
1185     window_->lastDensity_ = 1.0f;
1186     window_->lastOrientation_ = 0;
1187     config.isDensityFollowHost_ = true;
1188     config.density_ = 1.0f;
1189     config.orientation_ = 0;
1190     ASSERT_EQ(window_->UpdateSessionViewportConfig(config), WSError::WS_OK);
1191     usleep(WAIT_SYNC_IN_NS);
1192 
1193     window_->lastDensity_ = 1.0f;
1194     window_->lastOrientation_ = 0;
1195     config.density_ = 2.0f;
1196     config.orientation_ = 0;
1197     ASSERT_EQ(window_->UpdateSessionViewportConfig(config), WSError::WS_OK);
1198     usleep(WAIT_SYNC_IN_NS);
1199 
1200     window_->lastDensity_ = 1.0f;
1201     window_->lastOrientation_ = 0;
1202     config.density_ = 1.0f;
1203     config.orientation_ = 1;
1204     ASSERT_EQ(window_->UpdateSessionViewportConfig(config), WSError::WS_OK);
1205     usleep(WAIT_SYNC_IN_NS);
1206 
1207     config.isDensityFollowHost_ = false;
1208     window_->lastDensity_ = 0.0f;
1209     window_->lastOrientation_ = 0;
1210     config.density_ = 1.0f;
1211     config.orientation_ = 0;
1212     ASSERT_EQ(window_->UpdateSessionViewportConfig(config), WSError::WS_OK);
1213     usleep(WAIT_SYNC_IN_NS);
1214 }
1215 
1216 /**
1217  * @tc.name: UpdateSessionViewportConfig2
1218  * @tc.desc: invalid density
1219  * @tc.type: FUNC
1220  */
1221 HWTEST_F(WindowExtensionSessionImplTest, UpdateSessionViewportConfig2, Function | SmallTest | Level2)
1222 {
1223     ASSERT_NE(nullptr, window_);
1224     SessionViewportConfig config;
1225     config.isDensityFollowHost_ = true;
1226     config.density_ = -1.0f;
1227     ASSERT_EQ(window_->UpdateSessionViewportConfig(config), WSError::WS_ERROR_INVALID_PARAM);
1228 }
1229 
1230 /**
1231  * @tc.name: UpdateSessionViewportConfig3
1232  * @tc.desc: handler_ is null
1233  * @tc.type: FUNC
1234  */
1235 HWTEST_F(WindowExtensionSessionImplTest, UpdateSessionViewportConfig3, Function | SmallTest | Level2)
1236 {
1237     ASSERT_NE(nullptr, window_);
1238     SessionViewportConfig config;
1239     window_->handler_ = nullptr;
1240     ASSERT_EQ(window_->UpdateSessionViewportConfig(config), WSError::WS_ERROR_NULLPTR);
1241 }
1242 
1243 /**
1244  * @tc.name: UpdateSystemViewportConfig1
1245  * @tc.desc: handler_ is null
1246  * @tc.type: FUNC
1247  */
1248 HWTEST_F(WindowExtensionSessionImplTest, UpdateSystemViewportConfig1, Function | SmallTest | Level2)
1249 {
1250     ASSERT_NE(nullptr, window_);
1251     window_->handler_ = nullptr;
1252     window_->UpdateSystemViewportConfig();
1253 }
1254 
1255 /**
1256  * @tc.name: UpdateSystemViewportConfig2
1257  * @tc.desc: Follow host
1258  * @tc.type: FUNC
1259  */
1260 HWTEST_F(WindowExtensionSessionImplTest, UpdateSystemViewportConfig2, Function | SmallTest | Level2)
1261 {
1262     ASSERT_NE(nullptr, window_);
1263     window_->isDensityFollowHost_ = true;
1264     window_->UpdateSystemViewportConfig();
1265     usleep(WAIT_SYNC_IN_NS);
1266 }
1267 
1268 /**
1269  * @tc.name: UpdateSystemViewportConfig3
1270  * @tc.desc: Do not follow host
1271  * @tc.type: FUNC
1272  */
1273 HWTEST_F(WindowExtensionSessionImplTest, UpdateSystemViewportConfig3, Function | SmallTest | Level2)
1274 {
1275     ASSERT_NE(nullptr, window_->property_);
1276     window_->isDensityFollowHost_ = false;
1277     window_->property_->SetDisplayId(0);
1278     window_->UpdateSystemViewportConfig();
1279     usleep(WAIT_SYNC_IN_NS);
1280 }
1281 
1282 /**
1283  * @tc.name: NotifyDisplayInfoChange1
1284  * @tc.desc: Normal test
1285  * @tc.type: FUNC
1286  */
1287 HWTEST_F(WindowExtensionSessionImplTest, NotifyDisplayInfoChange1, Function | SmallTest | Level2)
1288 {
1289     ASSERT_NE(nullptr, window_);
1290     auto abilityContext = std::make_shared<AbilityRuntime::AbilityContextImpl>();
1291     ASSERT_NE(nullptr, abilityContext);
1292     window_->context_ = abilityContext;
1293     SessionViewportConfig config;
1294     window_->NotifyDisplayInfoChange(config);
1295 }
1296 
1297 /**
1298  * @tc.name: NotifyDisplayInfoChange2
1299  * @tc.desc: context_ is nullptr
1300  * @tc.type: FUNC
1301  */
1302 HWTEST_F(WindowExtensionSessionImplTest, NotifyDisplayInfoChange2, Function | SmallTest | Level2)
1303 {
1304     ASSERT_NE(nullptr, window_);
1305     window_->context_ = nullptr;
1306     SessionViewportConfig config;
1307     window_->NotifyDisplayInfoChange(config);
1308 }
1309 
1310 /**
1311  * @tc.name: NotifyAccessibilityChildTreeRegister01
1312  * @tc.desc: NotifyAccessibilityChildTreeRegister Test
1313  * @tc.type: FUNC
1314  */
1315 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityChildTreeRegister01, Function | SmallTest | Level3)
1316 {
1317     uint32_t windowId = 0;
1318     int32_t treeId = 0;
1319     int64_t accessibilityId = 0;
1320     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1321     ASSERT_NE(nullptr, window_->uiContent_);
1322     auto ret = window_->NotifyAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
1323     ASSERT_EQ(WSError::WS_OK, ret);
1324 
1325     window_->uiContent_ = nullptr;
1326     ret = window_->NotifyAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
1327     ASSERT_EQ(WSError::WS_OK, ret);
1328 
1329     window_->handler_ = nullptr;
1330     ret = window_->NotifyAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
1331     ASSERT_EQ(WSError::WS_ERROR_INTERNAL_ERROR, ret);
1332     usleep(WAIT_SYNC_IN_NS);
1333 }
1334 
1335 /**
1336  * @tc.name: NotifyAccessibilityChildTreeUnregister01
1337  * @tc.desc: NotifyAccessibilityChildTreeUnregister Test
1338  * @tc.type: FUNC
1339  */
1340 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityChildTreeUnregister01, Function | SmallTest | Level3)
1341 {
1342     window_->uiContent_ = nullptr;
1343     ASSERT_EQ(WSError::WS_OK, window_->NotifyAccessibilityChildTreeUnregister());
1344 
1345     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1346     ASSERT_NE(nullptr, window_->uiContent_);
1347     ASSERT_EQ(WSError::WS_OK, window_->NotifyAccessibilityChildTreeUnregister());
1348 
1349     window_->handler_ = nullptr;
1350     ASSERT_EQ(WSError::WS_ERROR_INTERNAL_ERROR, window_->NotifyAccessibilityChildTreeUnregister());
1351     usleep(WAIT_SYNC_IN_NS);
1352 }
1353 
1354 /**
1355  * @tc.name: NotifyAccessibilityDumpChildInfo01
1356  * @tc.desc: NotifyAccessibilityDumpChildInfo Test
1357  * @tc.type: FUNC
1358  */
1359 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityDumpChildInfo01, Function | SmallTest | Level3)
1360 {
1361     std::vector<std::string> params;
1362     std::vector<std::string> info;
1363     window_->uiContent_ = nullptr;
1364     ASSERT_EQ(WSError::WS_OK, window_->NotifyAccessibilityDumpChildInfo(params, info));
1365 
1366     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1367     ASSERT_NE(nullptr, window_->uiContent_);
1368     ASSERT_EQ(WSError::WS_OK, window_->NotifyAccessibilityDumpChildInfo(params, info));
1369 
1370     window_->handler_ = nullptr;
1371     ASSERT_EQ(WSError::WS_ERROR_INTERNAL_ERROR, window_->NotifyAccessibilityDumpChildInfo(params, info));
1372     usleep(WAIT_SYNC_IN_NS);
1373 }
1374 
1375 /**
1376  * @tc.name: UpdateAccessibilityTreeInfo
1377  * @tc.desc: UpdateAccessibilityTreeInfo Test
1378  * @tc.type: FUNC
1379  */
1380 HWTEST_F(WindowExtensionSessionImplTest, UpdateAccessibilityTreeInfo, Function | SmallTest | Level3)
1381 {
1382     std::optional<AccessibilityChildTreeInfo> accessibilityChildTreeInfo =
1383 		std::make_optional<AccessibilityChildTreeInfo>();
1384     ASSERT_NE(accessibilityChildTreeInfo, std::nullopt);
1385     window_->accessibilityChildTreeInfo_ = accessibilityChildTreeInfo;
1386     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1387     ASSERT_NE(nullptr, window_->uiContent_);
1388     window_->UpdateAccessibilityTreeInfo();
1389 
1390     window_->uiContent_ = nullptr;
1391     window_->UpdateAccessibilityTreeInfo();
1392 
1393     window_->accessibilityChildTreeInfo_= std::nullopt;
1394     window_->UpdateAccessibilityTreeInfo();
1395     usleep(WAIT_SYNC_IN_NS);
1396 }
1397 
1398 /**
1399  * @tc.name: NotifyOccupiedAreaChangeInfo01
1400  * @tc.desc: NotifyExecuteAction Test
1401  * @tc.type: FUNC
1402  */
1403 HWTEST_F(WindowExtensionSessionImplTest, NotifyOccupiedAreaChangeInfo01, Function | SmallTest | Level3)
1404 {
1405     sptr<OccupiedAreaChangeInfo> info = new(std::nothrow) OccupiedAreaChangeInfo();
1406     ASSERT_NE(nullptr, info);
1407     window_->NotifyOccupiedAreaChangeInfo(info);
1408 }
1409 
1410 /**
1411  * @tc.name: NotifyOccupiedAreaChangeInfo02
1412  * @tc.desc: NotifyExecuteAction Test
1413  * @tc.type: FUNC
1414  */
1415 HWTEST_F(WindowExtensionSessionImplTest, NotifyOccupiedAreaChangeInfo02, Function | SmallTest | Level3)
1416 {
1417     sptr<IOccupiedAreaChangeListener> iOccupiedAreaChangeListener = new(std::nothrow) IOccupiedAreaChangeListener();
1418     ASSERT_NE(nullptr, iOccupiedAreaChangeListener);
1419     window_->RegisterOccupiedAreaChangeListener(iOccupiedAreaChangeListener);
1420     sptr<OccupiedAreaChangeInfo> info = new(std::nothrow) OccupiedAreaChangeInfo();
1421     ASSERT_NE(nullptr, info);
1422     window_->NotifyOccupiedAreaChangeInfo(info);
1423 }
1424 
1425 /**
1426  * @tc.name: UnregisterOccupiedAreaChangeListener
1427  * @tc.desc: UnregisterOccupiedAreaChangeListener Test
1428  * @tc.type: FUNC
1429  */
1430 HWTEST_F(WindowExtensionSessionImplTest, UnregisterOccupiedAreaChangeListener, Function | SmallTest | Level3)
1431 {
1432     ASSERT_EQ(WMError::WM_OK, window_->UnregisterOccupiedAreaChangeListener(nullptr));
1433 }
1434 
1435 /**
1436  * @tc.name: GetAvoidAreaByType01
1437  * @tc.desc: NotifyExecuteAction Test
1438  * @tc.type: FUNC
1439  */
1440 HWTEST_F(WindowExtensionSessionImplTest, GetAvoidAreaByType01, Function | SmallTest | Level3)
1441 {
1442     AvoidAreaType avoidAreaType = AvoidAreaType::TYPE_SYSTEM;
1443     AvoidArea avoidArea;
1444     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1445     avoidAreaType = AvoidAreaType::TYPE_CUTOUT;
1446     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1447     avoidAreaType = AvoidAreaType::TYPE_SYSTEM_GESTURE;
1448     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1449     avoidAreaType = AvoidAreaType::TYPE_KEYBOARD;
1450     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1451     avoidAreaType = AvoidAreaType::TYPE_NAVIGATION_INDICATOR;
1452     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1453 }
1454 
1455 /**
1456  * @tc.name: GetAvoidAreaByType02
1457  * @tc.desc: NotifyExecuteAction Test
1458  * @tc.type: FUNC
1459  */
1460 HWTEST_F(WindowExtensionSessionImplTest, GetAvoidAreaByType02, Function | SmallTest | Level3)
1461 {
1462     SessionInfo sessionInfo;
1463     sptr<SessionMocker> mockHostSession = sptr<SessionMocker>::MakeSptr(sessionInfo);
1464     ASSERT_NE(mockHostSession, nullptr);
1465     window_->hostSession_ = mockHostSession;
1466     AvoidAreaType avoidAreaType = AvoidAreaType::TYPE_SYSTEM;
1467     AvoidArea avoidArea;
1468     EXPECT_CALL(*mockHostSession, GetAvoidAreaByType).Times(5);
1469     ASSERT_EQ(WMError::WM_OK, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1470     avoidAreaType = AvoidAreaType::TYPE_CUTOUT;
1471     ASSERT_EQ(WMError::WM_OK, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1472     avoidAreaType = AvoidAreaType::TYPE_SYSTEM_GESTURE;
1473     ASSERT_EQ(WMError::WM_OK, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1474     avoidAreaType = AvoidAreaType::TYPE_KEYBOARD;
1475     ASSERT_EQ(WMError::WM_OK, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1476     avoidAreaType = AvoidAreaType::TYPE_NAVIGATION_INDICATOR;
1477     ASSERT_EQ(WMError::WM_OK, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1478 
1479     AvoidArea expectedAvoidArea;
1480     expectedAvoidArea.topRect_ = {10, 20, 30, 40};
1481     EXPECT_CALL(*mockHostSession, GetAvoidAreaByType).Times(1).WillOnce(Return(expectedAvoidArea));
1482     ASSERT_EQ(WMError::WM_OK, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1483     ASSERT_EQ(avoidArea, expectedAvoidArea);
1484 }
1485 
1486 /**
1487  * @tc.name: RegisterAvoidAreaChangeListener
1488  * @tc.desc: RegisterAvoidAreaChangeListener Test
1489  * @tc.type: FUNC
1490  */
1491 HWTEST_F(WindowExtensionSessionImplTest, RegisterAvoidAreaChangeListener, Function | SmallTest | Level3)
1492 {
1493     sptr<IAvoidAreaChangedListener> listener = nullptr;
1494     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->RegisterAvoidAreaChangeListener(listener));
1495 }
1496 
1497 /**
1498  * @tc.name: UnregisterAvoidAreaChangeListener
1499  * @tc.desc: UnregisterAvoidAreaChangeListener Test
1500  * @tc.type: FUNC
1501  */
1502 HWTEST_F(WindowExtensionSessionImplTest, UnregisterAvoidAreaChangeListener, Function | SmallTest | Level3)
1503 {
1504     sptr<IAvoidAreaChangedListener> listener = nullptr;
1505     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->UnregisterAvoidAreaChangeListener(listener));
1506 }
1507 
1508 /**
1509  * @tc.name: Show
1510  * @tc.desc: Show
1511  * @tc.type: FUNC
1512  */
1513 HWTEST_F(WindowExtensionSessionImplTest, Show, Function | SmallTest | Level3)
1514 {
1515     ASSERT_NE(nullptr, window_->property_);
1516     window_->property_->persistentId_ = 12345;
1517 
1518     SessionInfo sessionInfo;
1519     sptr<SessionMocker> mockHostSession = new (std::nothrow) SessionMocker(sessionInfo);
1520     ASSERT_NE(mockHostSession, nullptr);
1521     window_->hostSession_ = mockHostSession;
1522 
1523     window_->property_->SetDisplayId(0);
1524     EXPECT_CALL(*mockHostSession, Foreground).Times(1).WillOnce(Return(WSError::WS_DO_NOTHING));
1525     ASSERT_EQ(static_cast<WMError>(WSError::WS_DO_NOTHING), window_->Show());
1526     EXPECT_CALL(*mockHostSession, Foreground).Times(1).WillOnce(Return(WSError::WS_OK));
1527     ASSERT_EQ(WMError::WM_OK, window_->Show());
1528 }
1529 
1530 /**
1531  * @tc.name: Hide
1532  * @tc.desc: Hide
1533  * @tc.type: FUNC
1534  */
1535 HWTEST_F(WindowExtensionSessionImplTest, Hide, Function | SmallTest | Level3)
1536 {
1537     ASSERT_NE(nullptr, window_->property_);
1538 
1539     SessionInfo sessionInfo;
1540     sptr<SessionMocker> mockHostSession = new (std::nothrow) SessionMocker(sessionInfo);
1541     ASSERT_NE(mockHostSession, nullptr);
1542     window_->hostSession_ = mockHostSession;
1543 
1544     window_->property_->persistentId_ = INVALID_SESSION_ID;
1545     auto res = window_->Hide(0, false, false);
1546     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1547 
1548     window_->property_->persistentId_ = 12345;
1549     window_->state_ = WindowState::STATE_HIDDEN;
1550     EXPECT_CALL(*mockHostSession, Background).Times(0);
1551     res = window_->Hide(0, false, false);
1552     ASSERT_EQ(res, WMError::WM_OK);
1553 
1554     window_->state_ = WindowState::STATE_CREATED;
1555     EXPECT_CALL(*mockHostSession, Background).Times(0);
1556     res = window_->Hide(0, false, false);
1557     ASSERT_EQ(res, WMError::WM_OK);
1558 
1559     window_->state_ = WindowState::STATE_SHOWN;
1560     EXPECT_CALL(*mockHostSession, Background).Times(1).WillOnce(Return(WSError::WS_OK));
1561     res = window_->Hide(0, false, false);
1562     ASSERT_EQ(res, WMError::WM_OK);
1563     ASSERT_EQ(window_->state_, WindowState::STATE_HIDDEN);
1564 
1565     window_->state_ = WindowState::STATE_SHOWN;
1566     EXPECT_CALL(*mockHostSession, Background).Times(1).WillOnce(Return(WSError::WS_DO_NOTHING));
1567     res = window_->Hide(0, false, false);
1568     ASSERT_EQ(res, WMError::WM_OK);
1569     ASSERT_EQ(window_->state_, WindowState::STATE_SHOWN);
1570 }
1571 
1572 /**
1573  * @tc.name: NotifyDensityFollowHost01
1574  * @tc.desc: test isFollowHost is true
1575  * @tc.type: FUNC
1576  */
1577 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost01, Function | SmallTest | Level3)
1578 {
1579     DisplayId displayId = 0;
1580     ASSERT_NE(nullptr, window_->property_);
1581     window_->property_->SetDisplayId(displayId);
1582 
1583     auto isFollowHost = true;
1584     auto densityValue = 0.1f;
1585 
1586     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1587     ASSERT_NE(nullptr, window_->uiContent_);
1588     Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
1589     Rect preRect;
1590     preRect.posX_ = 0;
1591     preRect.posY_ = 0;
1592     preRect.height_ = 200;
1593     preRect.width_ = 200;
1594     window_->property_->SetWindowRect(preRect);
1595     EXPECT_CALL(*content, UpdateViewportConfig(Field(&Ace::ViewportConfig::density_, densityValue), _, _, _));
1596 
1597     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1598     usleep(WAIT_SYNC_IN_NS);
1599 }
1600 
1601 /**
1602  * @tc.name: NotifyDensityFollowHost02
1603  * @tc.desc: test isFollowHost is true -> false
1604  * @tc.type: FUNC
1605  */
1606 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost02, Function | SmallTest | Level3)
1607 {
1608     DisplayId displayId = 0;
1609     ASSERT_NE(nullptr, window_->property_);
1610     window_->property_->SetDisplayId(displayId);
1611 
1612     auto isFollowHost = false;
1613     auto densityValue = 0.1f;
1614 
1615     auto display = SingletonContainer::Get<DisplayManager>().GetDisplayById(window_->property_->GetDisplayId());
1616     ASSERT_NE(display, nullptr);
1617     ASSERT_NE(display->GetDisplayInfo(), nullptr);
1618     auto vpr = display->GetDisplayInfo()->GetVirtualPixelRatio();
1619 
1620     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1621     ASSERT_NE(nullptr, window_->uiContent_);
1622     Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
1623     Rect preRect;
1624     preRect.posX_ = 0;
1625     preRect.posY_ = 0;
1626     preRect.height_ = 100;
1627     preRect.width_ = 100;
1628     window_->property_->SetWindowRect(preRect);
1629     EXPECT_CALL(*content, UpdateViewportConfig(Field(&Ace::ViewportConfig::density_, vpr), _, _, _));
1630 
1631     window_->isDensityFollowHost_ = true;
1632     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1633     usleep(WAIT_SYNC_IN_NS);
1634 }
1635 
1636 /**
1637  * @tc.name: NotifyDensityFollowHost03
1638  * @tc.desc: test isFollowHost not change
1639  * @tc.type: FUNC
1640  */
1641 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost03, Function | SmallTest | Level3)
1642 {
1643     DisplayId displayId = 0;
1644     ASSERT_NE(nullptr, window_->property_);
1645     window_->property_->SetDisplayId(displayId);
1646 
1647     auto isFollowHost = false;
1648     auto densityValue = 0.1f;
1649     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1650     ASSERT_NE(nullptr, window_->uiContent_);
1651     Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
1652     EXPECT_CALL(*content, UpdateViewportConfig(_, _, _, _)).Times(0);
1653 
1654     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1655     usleep(WAIT_SYNC_IN_NS);
1656 }
1657 
1658 /**
1659  * @tc.name: NotifyDensityFollowHost04
1660  * @tc.desc: test densityValue invalid
1661  * @tc.type: FUNC
1662  */
1663 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost04, Function | SmallTest | Level3)
1664 {
1665     DisplayId displayId = 0;
1666     ASSERT_NE(nullptr, window_->property_);
1667     window_->property_->SetDisplayId(displayId);
1668 
1669     auto isFollowHost = true;
1670     auto densityValue = 0.0f;
1671     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_ERROR_INVALID_PARAM);
1672     densityValue = -0.1f;
1673     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_ERROR_INVALID_PARAM);
1674 }
1675 
1676 /**
1677  * @tc.name: NotifyDensityFollowHost05
1678  * @tc.desc: test densityValue not change
1679  * @tc.type: FUNC
1680  */
1681 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost05, Function | SmallTest | Level3)
1682 {
1683     DisplayId displayId = 0;
1684     ASSERT_NE(nullptr, window_->property_);
1685     window_->property_->SetDisplayId(displayId);
1686     window_->property_->windowRect_ = {1, 1, 1, 1};
1687 
1688     auto isFollowHost = true;
1689     auto densityValue = 0.1f;
1690     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1691     ASSERT_NE(nullptr, window_->uiContent_);
1692     Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
1693     EXPECT_CALL(*content, UpdateViewportConfig(_, _, _, _)).Times(3);
1694 
1695     window_->hostDensityValue_ = densityValue;
1696     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1697     ASSERT_FALSE(window_->isDensityFollowHost_);
1698 
1699     window_->hostDensityValue_ = 0.2f;
1700     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1701     ASSERT_TRUE(window_->isDensityFollowHost_);
1702     ASSERT_EQ(window_->hostDensityValue_, densityValue);
1703 
1704     densityValue = FLT_MAX;
1705     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1706     ASSERT_TRUE(window_->isDensityFollowHost_);
1707     ASSERT_EQ(window_->hostDensityValue_, densityValue);
1708 
1709     densityValue = FLT_MIN;
1710     window_->isDensityFollowHost_ = false;
1711     ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1712     ASSERT_TRUE(window_->isDensityFollowHost_);
1713     ASSERT_EQ(window_->hostDensityValue_, densityValue);
1714     usleep(WAIT_SYNC_IN_NS);
1715 }
1716 
1717 /**
1718  * @tc.name: GetVirtualPixelRatio01
1719  * @tc.desc: follow host density value
1720  * @tc.type: FUNC
1721  */
1722 HWTEST_F(WindowExtensionSessionImplTest, GetVirtualPixelRatio01, Function | SmallTest | Level2)
1723 {
1724     sptr<DisplayInfo> displayInfo = new DisplayInfo();
1725     displayInfo->SetVirtualPixelRatio(3.25f);
1726     window_->isDensityFollowHost_ = true;
1727     window_->hostDensityValue_ = 2.0f;
1728     ASSERT_EQ(window_->hostDensityValue_, window_->GetVirtualPixelRatio(displayInfo));
1729 }
1730 
1731 /**
1732  * @tc.name: GetVirtualPixelRatio02
1733  * @tc.desc: follow system density value
1734  * @tc.type: FUNC
1735  */
1736 HWTEST_F(WindowExtensionSessionImplTest, GetVirtualPixelRatio02, Function | SmallTest | Level2)
1737 {
1738     auto systemDensity = 3.25;
1739     sptr<DisplayInfo> displayInfo = new DisplayInfo();
1740     displayInfo->SetVirtualPixelRatio(systemDensity);
1741     window_->isDensityFollowHost_ = false;
1742     window_->hostDensityValue_ = 2.0f;
1743     ASSERT_EQ(systemDensity, window_->GetVirtualPixelRatio(displayInfo));
1744 }
1745 
1746 /**
1747  * @tc.name: GetVirtualPixelRatio03
1748  * @tc.desc: hostDensityValue_ is nullptr
1749  * @tc.type: FUNC
1750  */
1751 HWTEST_F(WindowExtensionSessionImplTest, GetVirtualPixelRatio03, Function | SmallTest | Level2)
1752 {
1753     auto systemDensity = 3.25;
1754     sptr<DisplayInfo> displayInfo = new DisplayInfo();
1755     displayInfo->SetVirtualPixelRatio(systemDensity);
1756     window_->isDensityFollowHost_ = true;
1757     ASSERT_EQ(systemDensity, window_->GetVirtualPixelRatio(displayInfo));
1758 }
1759 
1760 /**
1761  * @tc.name: GetVirtualPixelRatio04
1762  * @tc.desc: GetVirtualPixelRatio04 test
1763  * @tc.type: FUNC
1764  */
1765 HWTEST_F(WindowExtensionSessionImplTest, GetVirtualPixelRatio04, Function | SmallTest | Level2)
1766 {
1767     ASSERT_EQ(1.0f, window_->GetVirtualPixelRatio(nullptr));
1768 }
1769 
1770 /**
1771  * @tc.name: HideNonSecureWindows01
1772  * @tc.desc: HideNonSecureWindows Test
1773  * @tc.type: FUNC
1774  */
1775 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows01, Function | SmallTest | Level3)
1776 {
1777     ASSERT_EQ(WMError::WM_OK, window_->HideNonSecureWindows(false));
1778     ASSERT_FALSE(window_->extensionWindowFlags_.hideNonSecureWindowsFlag);
1779     ASSERT_EQ(WMError::WM_OK, window_->HideNonSecureWindows(true));
1780     ASSERT_TRUE(window_->extensionWindowFlags_.hideNonSecureWindowsFlag);
1781 }
1782 
1783 /**
1784  * @tc.name: HideNonSecureWindows02
1785  * @tc.desc: HideNonSecureWindows Test
1786  * @tc.type: FUNC
1787  */
1788 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows02, Function | SmallTest | Level3)
1789 {
1790     window_->state_ = WindowState::STATE_SHOWN;
1791     ASSERT_EQ(WMError::WM_OK, window_->HideNonSecureWindows(false));
1792 
1793     sptr<IRemoteObject> iRemoteObject = new IRemoteObjectMocker();
1794     ASSERT_NE(nullptr, iRemoteObject);
1795     window_->abilityToken_ = iRemoteObject;
1796     SessionInfo sessionInfo;
1797     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1798     ASSERT_NE(nullptr, window_->hostSession_);
1799     ASSERT_NE(nullptr, window_->property_);
1800     window_->property_->SetPersistentId(1);
1801 
1802     ASSERT_EQ(WMError::WM_OK, window_->HideNonSecureWindows(false));
1803 }
1804 
1805 /**
1806  * @tc.name: HideNonSecureWindows03
1807  * @tc.desc: HideNonSecureWindows Test
1808  * @tc.type: FUNC
1809  */
1810 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows03, Function | SmallTest | Level3)
1811 {
1812     window_->state_ = WindowState::STATE_SHOWN;
1813     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->HideNonSecureWindows(true));
1814 }
1815 
1816 /**
1817  * @tc.name: HideNonSecureWindows04
1818  * @tc.desc: HideNonSecureWindows Test
1819  * @tc.type: FUNC
1820  */
1821 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows04, Function | SmallTest | Level3)
1822 {
1823     SessionInfo sessionInfo;
1824     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1825     ASSERT_NE(nullptr, window_->hostSession_);
1826     ASSERT_NE(nullptr, window_->property_);
1827     window_->property_->SetPersistentId(1);
1828     window_->state_ = WindowState::STATE_SHOWN;
1829     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->HideNonSecureWindows(true));
1830 }
1831 
1832 /**
1833  * @tc.name: HideNonSecureWindows06
1834  * @tc.desc: HideNonSecureWindows Test
1835  * @tc.type: FUNC
1836  */
1837 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows06, Function | SmallTest | Level3)
1838 {
1839     ASSERT_NE(nullptr, window_->property_);
1840     window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
1841     ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, window_->HideNonSecureWindows(false));
1842 }
1843 
1844 /**
1845  * @tc.name: SetWaterMarkFlag01
1846  * @tc.desc: SetWaterMarkFlag Test
1847  * @tc.type: FUNC
1848  */
1849 HWTEST_F(WindowExtensionSessionImplTest, SetWaterMarkFlag01, Function | SmallTest | Level3)
1850 {
1851     ASSERT_EQ(WMError::WM_OK, window_->SetWaterMarkFlag(false));
1852     ASSERT_FALSE(window_->extensionWindowFlags_.waterMarkFlag);
1853     ASSERT_EQ(WMError::WM_OK, window_->SetWaterMarkFlag(true));
1854     ASSERT_TRUE(window_->extensionWindowFlags_.waterMarkFlag);
1855 }
1856 
1857 /**
1858  * @tc.name: SetWaterMarkFlag02
1859  * @tc.desc: SetWaterMarkFlag Test
1860  * @tc.type: FUNC
1861  */
1862 HWTEST_F(WindowExtensionSessionImplTest, SetWaterMarkFlag02, Function | SmallTest | Level3)
1863 {
1864     window_->state_ = WindowState::STATE_SHOWN;
1865     ASSERT_EQ(WMError::WM_OK, window_->SetWaterMarkFlag(false));
1866 }
1867 
1868 /**
1869  * @tc.name: SetWaterMarkFlag03
1870  * @tc.desc: SetWaterMarkFlag Test
1871  * @tc.type: FUNC
1872  */
1873 HWTEST_F(WindowExtensionSessionImplTest, SetWaterMarkFlag03, Function | SmallTest | Level3)
1874 {
1875     window_->state_ = WindowState::STATE_SHOWN;
1876     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->SetWaterMarkFlag(true));
1877 }
1878 
1879 /**
1880  * @tc.name: SetWaterMarkFlag04
1881  * @tc.desc: SetWaterMarkFlag Test
1882  * @tc.type: FUNC
1883  */
1884 HWTEST_F(WindowExtensionSessionImplTest, SetWaterMarkFlag04, Function | SmallTest | Level3)
1885 {
1886     SessionInfo sessionInfo;
1887     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1888     ASSERT_NE(nullptr, window_->hostSession_);
1889     ASSERT_NE(nullptr, window_->property_);
1890     window_->property_->SetPersistentId(1);
1891     window_->state_ = WindowState::STATE_SHOWN;
1892     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->SetWaterMarkFlag(true));
1893 }
1894 
1895 /**
1896  * @tc.name: CheckAndAddExtWindowFlags01
1897  * @tc.desc: CheckAndAddExtWindowFlags01 Test
1898  * @tc.type: FUNC
1899  */
1900 HWTEST_F(WindowExtensionSessionImplTest, CheckAndAddExtWindowFlags01, Function | SmallTest | Level3)
1901 {
1902     ASSERT_NE(nullptr, window_);
1903     window_->CheckAndAddExtWindowFlags();
1904 }
1905 
1906 /**
1907  * @tc.name: CheckAndAddExtWindowFlags02
1908  * @tc.desc: CheckAndAddExtWindowFlags02 Test
1909  * @tc.type: FUNC
1910  */
1911 HWTEST_F(WindowExtensionSessionImplTest, CheckAndAddExtWindowFlags02, Function | SmallTest | Level3)
1912 {
1913     ASSERT_NE(nullptr, window_);
1914     window_->extensionWindowFlags_.bitData = 1;
1915     window_->CheckAndAddExtWindowFlags();
1916 }
1917 
1918 /**
1919  * @tc.name: CheckAndRemoveExtWindowFlags01
1920  * @tc.desc: CheckAndRemoveExtWindowFlags01 Test
1921  * @tc.type: FUNC
1922  */
1923 HWTEST_F(WindowExtensionSessionImplTest, CheckAndRemoveExtWindowFlags01, Function | SmallTest | Level3)
1924 {
1925     ASSERT_NE(nullptr, window_);
1926     window_->CheckAndRemoveExtWindowFlags();
1927 }
1928 
1929 /**
1930  * @tc.name: CheckAndRemoveExtWindowFlags02
1931  * @tc.desc: CheckAndRemoveExtWindowFlags02 Test
1932  * @tc.type: FUNC
1933  */
1934 HWTEST_F(WindowExtensionSessionImplTest, CheckAndRemoveExtWindowFlags02, Function | SmallTest | Level3)
1935 {
1936     ASSERT_NE(nullptr, window_);
1937     window_->extensionWindowFlags_.bitData = 1;
1938     window_->CheckAndRemoveExtWindowFlags();
1939 }
1940 
1941 /**
1942  * @tc.name: UpdateExtWindowFlags01
1943  * @tc.desc: UpdateExtWindowFlags Test
1944  * @tc.type: FUNC
1945  */
1946 HWTEST_F(WindowExtensionSessionImplTest, UpdateExtWindowFlags01, Function | SmallTest | Level3)
1947 {
1948     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->UpdateExtWindowFlags(ExtensionWindowFlags(),
1949         ExtensionWindowFlags()));
1950 }
1951 
1952 /**
1953  * @tc.name: UpdateExtWindowFlags02
1954  * @tc.desc: UpdateExtWindowFlags Test
1955  * @tc.type: FUNC
1956  */
1957 HWTEST_F(WindowExtensionSessionImplTest, UpdateExtWindowFlags02, Function | SmallTest | Level3)
1958 {
1959     SessionInfo sessionInfo;
1960     window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1961     ASSERT_NE(nullptr, window_->hostSession_);
1962     ASSERT_NE(nullptr, window_->property_);
1963     window_->property_->SetPersistentId(1);
1964     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->UpdateExtWindowFlags(ExtensionWindowFlags(), ExtensionWindowFlags()));
1965 
1966     sptr<IRemoteObject> iRemoteObject = new IRemoteObjectMocker();
1967     ASSERT_NE(nullptr, iRemoteObject);
1968     window_->abilityToken_ = iRemoteObject;
1969     ASSERT_NE(WMError::WM_ERROR_NULLPTR, window_->UpdateExtWindowFlags(ExtensionWindowFlags(), ExtensionWindowFlags()));
1970 }
1971 
1972 /**
1973  * @tc.name: GetHostWindowRect01
1974  * @tc.desc: GetHostWindowRect Test
1975  * @tc.type: FUNC
1976  */
1977 HWTEST_F(WindowExtensionSessionImplTest, GetHostWindowRect01, Function | SmallTest | Level3)
1978 {
1979     Rect rect;
1980     ASSERT_EQ(rect, window_->GetHostWindowRect(-1));
1981 }
1982 
1983 /**
1984  * @tc.name: GetHostWindowRect02
1985  * @tc.desc: GetHostWindowRect Test
1986  * @tc.type: FUNC
1987  */
1988 HWTEST_F(WindowExtensionSessionImplTest, GetHostWindowRect02, Function | SmallTest | Level3)
1989 {
1990     Rect rect;
1991     ASSERT_EQ(rect, window_->GetHostWindowRect(0));
1992 }
1993 
1994 /**
1995  * @tc.name: ConsumePointerEvent
1996  * @tc.desc: ConsumePointerEvent Test
1997  * @tc.type: FUNC
1998  */
1999 HWTEST_F(WindowExtensionSessionImplTest, ConsumePointerEvent, Function | SmallTest | Level3)
2000 {
2001     struct RSSurfaceNodeConfig config;
2002     window_->surfaceNode_ = RSSurfaceNode::Create(config);
2003     window_->state_ = WindowState::STATE_SHOWN;
2004 
2005     auto pointerEvent = MMI::PointerEvent::Create();
2006     window_->ConsumePointerEvent(nullptr);
2007 
2008     window_->ConsumePointerEvent(pointerEvent);
2009 
2010     SessionInfo sessionInfo;
2011     window_->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2012     ASSERT_NE(nullptr, window_->hostSession_);
2013     window_->ConsumePointerEvent(pointerEvent);
2014 
2015     MMI::PointerEvent::PointerItem item;
2016     pointerEvent->SetPointerId(0);
2017     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
2018     item.SetPointerId(0);
2019     item.SetDisplayX(15); // 15 : position x
2020     item.SetDisplayY(15); // 15 : position y
2021     item.SetWindowX(15); // 15 : position x
2022     item.SetWindowY(15); // 15 : position y
2023     pointerEvent->AddPointerItem(item);
2024     window_->ConsumePointerEvent(pointerEvent);
2025 
2026     ASSERT_NE(nullptr, window_->property_);
2027     window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
2028     window_->ConsumePointerEvent(pointerEvent);
2029 
2030     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_MOVE);
2031     pointerEvent->UpdatePointerItem(0, item);
2032     window_->ConsumePointerEvent(pointerEvent);
2033 
2034     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
2035     pointerEvent->UpdatePointerItem(0, item);
2036     window_->ConsumePointerEvent(pointerEvent);
2037 }
2038 
2039 /**
2040  * @tc.name: PreNotifyKeyEvent
2041  * @tc.desc: PreNotifyKeyEvent Test
2042  * @tc.type: FUNC
2043  */
2044 HWTEST_F(WindowExtensionSessionImplTest, PreNotifyKeyEvent, Function | SmallTest | Level3)
2045 {
2046     bool ret = window_->PreNotifyKeyEvent(nullptr);
2047     ASSERT_EQ(ret, false);
2048 
2049     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
2050     ASSERT_NE(nullptr, keyEvent);
2051     ASSERT_NE(nullptr, window_->property_);
2052     window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
2053     ret = window_->PreNotifyKeyEvent(keyEvent);
2054     ASSERT_EQ(ret, false);
2055 
2056     std::shared_ptr<Ace::UIContent> uiContent = std::make_unique<Ace::UIContentMocker>();
2057     ASSERT_NE(nullptr, uiContent);
2058     window_->uiContent_ = uiContent;
2059     Ace::UIContentMocker* uiContentMocker = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
2060     EXPECT_CALL(*uiContentMocker, ProcessKeyEvent).Times(2).WillOnce(Return(true));
2061     ret = window_->PreNotifyKeyEvent(keyEvent);
2062     ASSERT_EQ(ret, true);
2063 
2064     window_->property_->SetUIExtensionUsage(UIExtensionUsage::CONSTRAINED_EMBEDDED);
2065     ret = window_->PreNotifyKeyEvent(keyEvent);
2066     ASSERT_EQ(ret, true);
2067 
2068     window_->focusState_ = false;
2069     ret = window_->PreNotifyKeyEvent(keyEvent);
2070     ASSERT_EQ(ret, true);
2071 
2072     window_->focusState_ = true;
2073     ret = window_->PreNotifyKeyEvent(keyEvent);
2074     ASSERT_EQ(ret, false);
2075     usleep(WAIT_SYNC_IN_NS);
2076 }
2077 
2078 /**
2079  * @tc.name: GetFreeMultiWindowModeEnabledState
2080  * @tc.desc: GetFreeMultiWindowModeEnabledState Test
2081  * @tc.type: FUNC
2082  */
2083 HWTEST_F(WindowExtensionSessionImplTest, GetFreeMultiWindowModeEnabledState, Function | SmallTest | Level3)
2084 {
2085     ASSERT_EQ(false, window_->GetFreeMultiWindowModeEnabledState());
2086 }
2087 
2088 /**
2089  * @tc.name: NotifyExtensionTimeout
2090  * @tc.desc: NotifyExtensionTimeout Test
2091  * @tc.type: FUNC
2092  */
2093 HWTEST_F(WindowExtensionSessionImplTest, NotifyExtensionTimeout, Function | SmallTest | Level3)
2094 {
2095     ASSERT_NE(nullptr, window_);
2096     SessionInfo sessionInfo;
2097     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2098 
2099     window_->hostSession_ = session;
2100     EXPECT_CALL(*session, NotifyExtensionTimeout).Times(1);
2101     window_->NotifyExtensionTimeout(WindowExtensionSessionImpl::TimeoutErrorCode::SET_UICONTENT_TIMEOUT);
2102 
2103     window_->hostSession_ = nullptr;
2104     EXPECT_CALL(*session, NotifyExtensionTimeout).Times(0);
2105     window_->NotifyExtensionTimeout(WindowExtensionSessionImpl::TimeoutErrorCode::SET_UICONTENT_TIMEOUT);
2106     usleep(WAIT_SYNC_IN_NS);
2107 }
2108 
2109 /**
2110  * @tc.name: GetRealParentId
2111  * @tc.desc: GetRealParentId Test
2112  * @tc.type: FUNC
2113  */
2114 HWTEST_F(WindowExtensionSessionImplTest, GetRealParentId, Function | SmallTest | Level3)
2115 {
2116     ASSERT_NE(window_->property_, nullptr);
2117     window_->property_->SetRealParentId(12345);
2118     EXPECT_EQ(window_->GetRealParentId(), 12345);
2119 }
2120 
2121 /**
2122  * @tc.name: GetParentWindowType
2123  * @tc.desc: GetParentWindowType Test
2124  * @tc.type: FUNC
2125  */
2126 HWTEST_F(WindowExtensionSessionImplTest, GetParentWindowType, Function | SmallTest | Level3)
2127 {
2128     ASSERT_NE(window_->property_, nullptr);
2129     window_->property_->SetParentWindowType(WindowType::WINDOW_TYPE_TOAST);
2130     EXPECT_EQ(window_->GetParentWindowType(), WindowType::WINDOW_TYPE_TOAST);
2131 }
2132 
2133 /**
2134  * @tc.name: CheckHideNonSecureWindowsPermission
2135  * @tc.desc: CheckHideNonSecureWindowsPermission Test
2136  * @tc.type: FUNC
2137  */
2138 HWTEST_F(WindowExtensionSessionImplTest, CheckHideNonSecureWindowsPermission, Function | SmallTest | Level3)
2139 {
2140     ASSERT_NE(window_->property_, nullptr);
2141 
2142     window_->property_->uiExtensionUsage_ = UIExtensionUsage::EMBEDDED;
2143     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(true), WMError::WM_OK);
2144     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(false), WMError::WM_OK);
2145 
2146     window_->property_->uiExtensionUsage_ = UIExtensionUsage::MODAL;
2147     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(true), WMError::WM_OK);
2148     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(false), WMError::WM_ERROR_INVALID_OPERATION);
2149 
2150     window_->property_->uiExtensionUsage_ = UIExtensionUsage::CONSTRAINED_EMBEDDED;
2151     window_->modalUIExtensionMayBeCovered_ = true;
2152     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(true), WMError::WM_OK);
2153     EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(false), WMError::WM_ERROR_INVALID_OPERATION);
2154 }
2155 
2156 /**
2157  * @tc.name: NotifyModalUIExtensionMayBeCovered
2158  * @tc.desc: NotifyModalUIExtensionMayBeCovered Test
2159  * @tc.type: FUNC
2160  */
2161 HWTEST_F(WindowExtensionSessionImplTest, NotifyModalUIExtensionMayBeCovered, Function | SmallTest | Level3)
2162 {
2163     ASSERT_NE(window_, nullptr);
2164     ASSERT_NE(window_->property_, nullptr);
2165 
2166     window_->property_->uiExtensionUsage_ = UIExtensionUsage::EMBEDDED;
2167     window_->NotifyModalUIExtensionMayBeCovered(true);
2168 
2169     window_->property_->uiExtensionUsage_ = UIExtensionUsage::MODAL;
2170     window_->extensionWindowFlags_.hideNonSecureWindowsFlag = true;
2171     window_->NotifyModalUIExtensionMayBeCovered(true);
2172     ASSERT_TRUE(window_->modalUIExtensionMayBeCovered_);
2173     ASSERT_TRUE(window_->modalUIExtensionSelfLoadContent_);
2174 
2175     window_->property_->uiExtensionUsage_ = UIExtensionUsage::CONSTRAINED_EMBEDDED;
2176     window_->extensionWindowFlags_.hideNonSecureWindowsFlag = false;
2177     window_->NotifyModalUIExtensionMayBeCovered(false);
2178     ASSERT_TRUE(window_->modalUIExtensionMayBeCovered_);
2179     ASSERT_TRUE(window_->modalUIExtensionSelfLoadContent_);
2180 }
2181 
2182 /**
2183  * @tc.name: ReportModalUIExtensionMayBeCovered
2184  * @tc.desc: ReportModalUIExtensionMayBeCovered Test
2185  * @tc.type: FUNC
2186  */
2187 HWTEST_F(WindowExtensionSessionImplTest, ReportModalUIExtensionMayBeCovered, Function | SmallTest | Level3)
2188 {
2189     ASSERT_NE(window_, nullptr);
2190     window_->ReportModalUIExtensionMayBeCovered(true);
2191     window_->NotifyModalUIExtensionMayBeCovered(false);
2192 }
2193 
2194 /**
2195  * @tc.name: NotifyExtensionEventAsync
2196  * @tc.desc: NotifyExtensionEventAsync Test
2197  * @tc.type: FUNC
2198  */
2199 HWTEST_F(WindowExtensionSessionImplTest, NotifyExtensionEventAsync, Function | SmallTest | Level3)
2200 {
2201     window_->NotifyExtensionEventAsync(0);
2202 
2203     SessionInfo sessionInfo;
2204     window_->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2205     ASSERT_NE(nullptr, window_->hostSession_);
2206     window_->property_->SetPersistentId(1);
2207     window_->NotifyExtensionEventAsync(0);
2208 }
2209 
2210 /**
2211  * @tc.name: NotifyDumpInfo
2212  * @tc.desc: NotifyDumpInfo Test
2213  * @tc.type: FUNC
2214  */
2215 HWTEST_F(WindowExtensionSessionImplTest, NotifyDumpInfo, Function | SmallTest | Level3)
2216 {
2217     ASSERT_NE(nullptr, window_);
2218     window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
2219     ASSERT_NE(nullptr, window_->uiContent_);
2220     std::vector<std::string> params;
2221     std::vector<std::string> info;
2222     auto ret = window_->NotifyDumpInfo(params, info);
2223     ASSERT_EQ(WSError::WS_OK, ret);
2224 
2225     window_->uiContent_ = nullptr;
2226     ret = window_->NotifyDumpInfo(params, info);
2227     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, ret);
2228     usleep(WAIT_SYNC_IN_NS);
2229 }
2230 
2231 /**
2232  * @tc.name: UpdateConfigurationSyncForAll
2233  * @tc.desc: UpdateConfigurationSyncForAll Test
2234  * @tc.type: FUNC
2235  */
2236 HWTEST_F(WindowExtensionSessionImplTest, UpdateConfigurationSyncForAll, Function | SmallTest | Level3)
2237 {
2238     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
2239     ASSERT_NE(nullptr, window_);
2240     window_->windowExtensionSessionSet_.insert(window_);
2241     window_->UpdateConfigurationSyncForAll(configuration);
2242     window_->windowExtensionSessionSet_.erase(window_);
2243 }
2244 
2245 /**
2246  * @tc.name: NotifyExtensionDataConsumer01
2247  * @tc.desc: Test NotifyExtensionDataConsumer with valid window mode data
2248  * @tc.type: FUNC
2249  */
2250 HWTEST_F(WindowExtensionSessionImplTest, NotifyExtensionDataConsumer01, Function | SmallTest | Level3)
2251 {
2252     // Prepare and write config
2253     MessageParcel data;
2254     MessageParcel reply;
2255     Extension::DataTransferConfig config;
2256     config.subSystemId = SubSystemId::WM_UIEXT;
2257     config.customId = static_cast<uint32_t>(Extension::Businesscode::SYNC_HOST_WINDOW_MODE);
2258     config.needReply = false;
2259     config.needSyncSend = true;
2260     ASSERT_TRUE(data.WriteParcelable(&config));
2261 
2262     // Prepare and write want data
2263     AAFwk::Want want;
2264     want.SetParam(Extension::WINDOW_MODE_FIELD, static_cast<int32_t>(WindowMode::WINDOW_MODE_FLOATING));
2265     ASSERT_TRUE(data.WriteParcelable(&want));
2266 
2267     // Send data
2268     MessageOption option;
2269     window_->SendExtensionData(data, reply, option);
2270 
2271     // Verify reply contains success code
2272     uint32_t replyCode;
2273     ASSERT_TRUE(reply.ReadUint32(replyCode));
2274     ASSERT_EQ(static_cast<uint32_t>(DataHandlerErr::OK), replyCode);
2275 
2276     // Verify window mode was updated
2277     ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window_->GetWindowMode());
2278 }
2279 
2280 /**
2281  * @tc.name: RegisterConsumer
2282  * @tc.desc: RegisterConsumer Test
2283  * @tc.type: FUNC
2284  */
2285 HWTEST_F(WindowExtensionSessionImplTest, RegisterConsumer, Function | SmallTest | Level3)
2286 {
2287     window_->RegisterConsumer(Extension::Businesscode::SYNC_CROSS_AXIS_STATE,
2288         std::bind(&WindowExtensionSessionImpl::OnCrossAxisStateChange,
2289         window_, std::placeholders::_1, std::placeholders::_2));
2290     ASSERT_NE(nullptr,
2291         window_->dataConsumers_[static_cast<uint32_t>(Extension::Businesscode::SYNC_CROSS_AXIS_STATE)]);
2292 }
2293 
2294 /**
2295  * @tc.name: OnCrossAxisStateChange
2296  * @tc.desc: OnCrossAxisStateChange Test
2297  * @tc.type: FUNC
2298  */
2299 HWTEST_F(WindowExtensionSessionImplTest, OnCrossAxisStateChange, Function | SmallTest | Level3)
2300 {
2301     AAFwk::Want want;
2302     std::optional<AAFwk::Want> reply = std::make_optional<AAFwk::Want>();
2303     want.SetParam(Extension::CROSS_AXIS_FIELD, static_cast<int32_t>(CrossAxisState::STATE_CROSS));
2304     ASSERT_EQ(WMError::WM_OK, window_->OnCrossAxisStateChange(std::move(want), reply));
2305     ASSERT_EQ(CrossAxisState::STATE_CROSS, window_->crossAxisState_.load());
2306 }
2307 }
2308 } // namespace Rosen
2309 } // namespace OHOS