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