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