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);
__anone33526ab0202(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);
__anone33526ab0302(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 window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
970 ASSERT_EQ(WMError::WM_OK,
971 window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
972 window_->property_->SetUIExtensionUsage(UIExtensionUsage::EMBEDDED);
973 ASSERT_EQ(WMError::WM_OK,
974 window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
975 window_->property_->SetUIExtensionUsage(UIExtensionUsage::UIEXTENSION_USAGE_END);
976 ASSERT_EQ(WMError::WM_OK,
977 window_->NapiSetUIContent(contentInfo, env, storage, BackupAndRestoreType::NONE, token, nullptr));
978 }
979
980 /**
981 * @tc.name: UpdateRect01
982 * @tc.desc: UpdateRect Test
983 * @tc.type: FUNC
984 */
985 HWTEST_F(WindowExtensionSessionImplTest, UpdateRect01, Function | SmallTest | Level2)
986 {
987 WSRect rect;
988 rect.posX_ = 0;
989 rect.posY_ = 0;
990 rect.height_ = 50;
991 rect.width_ = 50;
992
993 Rect preRect;
994 preRect.posX_ = 0;
995 preRect.posY_ = 0;
996 preRect.height_ = 200;
997 preRect.width_ = 200;
998
999 ASSERT_NE(nullptr, window_->property_);
1000 window_->property_->SetWindowRect(preRect);
1001 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1002 ASSERT_EQ(WSError::WS_OK, window_->UpdateRect(rect, reason));
1003
1004 preRect.height_ = 50;
1005 window_->property_->SetWindowRect(preRect);
1006 ASSERT_EQ(WSError::WS_OK, window_->UpdateRect(rect, reason));
1007
1008 preRect.height_ = 200;
1009 preRect.width_ = 50;
1010 window_->property_->SetWindowRect(preRect);
1011 ASSERT_EQ(WSError::WS_OK, window_->UpdateRect(rect, reason));
1012
1013 preRect.height_ = 50;
1014 preRect.width_ = 50;
1015 window_->property_->SetWindowRect(preRect);
1016 reason = SizeChangeReason::ROTATION;
1017 ASSERT_EQ(WSError::WS_OK, window_->UpdateRect(rect, reason));
1018
1019 window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
1020 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, window_->UpdateRect(rect, reason));
1021 }
1022
1023 /**
1024 * @tc.name: UpdateRectForRotation01
1025 * @tc.desc: UpdateRect Test
1026 * @tc.type: FUNC
1027 */
1028 HWTEST_F(WindowExtensionSessionImplTest, UpdateRectForRotation01, Function | SmallTest | Level2)
1029 {
1030 Rect rect;
1031 WindowSizeChangeReason wmReason = WindowSizeChangeReason{0};
1032 std::shared_ptr<RSTransaction> rsTransaction = std::make_shared<RSTransaction>();
1033 rsTransaction->syncId_ = 1;
1034 rsTransaction->isOpenSyncTransaction_ = true;
1035 ASSERT_NE(nullptr, window_);
1036 window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
1037
1038 Rect preRect;
1039 window_->UpdateRectForRotation(rect, preRect, wmReason, rsTransaction);
1040
1041 rsTransaction->isOpenSyncTransaction_ = false;
1042 window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
1043
1044 rsTransaction->syncId_ = -1;
1045 window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
1046
1047 rsTransaction = nullptr;
1048 window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
1049 window_->UpdateRectForOtherReason(rect, wmReason);
1050
1051 window_->handler_ = nullptr;
1052 window_->UpdateRectForRotation(rect, rect, wmReason, rsTransaction);
1053 usleep(WAIT_SYNC_IN_NS);
1054 }
1055
1056 /**
1057 * @tc.name: NotifyAccessibilityHoverEvent01
1058 * @tc.desc: NotifyAccessibilityHoverEvent Test
1059 * @tc.type: FUNC
1060 */
1061 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityHoverEvent01, Function | SmallTest | Level3)
1062 {
1063 float pointX = 0.0f;
1064 float pointY = 0.0f;
1065 int32_t sourceType = 0;
1066 int32_t eventType = 0;
1067 int64_t timeMs = 0;
1068 window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1069 ASSERT_NE(nullptr, window_->uiContent_);
1070 ASSERT_EQ(WSError::WS_OK,
1071 window_->NotifyAccessibilityHoverEvent(pointX, pointY, sourceType, eventType, timeMs));
1072 }
1073
1074 /**
1075 * @tc.name: NotifyAccessibilityHoverEvent02
1076 * @tc.desc: NotifyAccessibilityHoverEvent Test
1077 * @tc.type: FUNC
1078 */
1079 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityHoverEvent02, Function | SmallTest | Level3)
1080 {
1081 float pointX = 0.0f;
1082 float pointY = 0.0f;
1083 int32_t sourceType = 0;
1084 int32_t eventType = 0;
1085 int64_t timeMs = 0;
1086 window_->uiContent_ = nullptr;
1087 ASSERT_EQ(WSError::WS_ERROR_NO_UI_CONTENT_ERROR,
1088 window_->NotifyAccessibilityHoverEvent(pointX, pointY, sourceType, eventType, timeMs));
1089 }
1090
1091 /**
1092 * @tc.name: TransferAccessibilityEvent
1093 * @tc.desc: TransferAccessibilityEvent Test
1094 * @tc.type: FUNC
1095 */
1096 HWTEST_F(WindowExtensionSessionImplTest, TransferAccessibilityEvent, Function | SmallTest | Level3)
1097 {
1098 SessionInfo sessionInfo;
1099 window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1100 ASSERT_NE(nullptr, window_->hostSession_);
1101 Accessibility::AccessibilityEventInfo info;
1102 int64_t uiExtensionIdLevel = 1;
1103 ASSERT_NE(WMError::WM_OK, window_->TransferAccessibilityEvent(info, uiExtensionIdLevel));
1104
1105 window_->hostSession_ = nullptr;
1106 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->TransferAccessibilityEvent(info, uiExtensionIdLevel));
1107 }
1108
1109 /**
1110 * @tc.name: NotifyAccessibilityChildTreeRegister01
1111 * @tc.desc: NotifyAccessibilityChildTreeRegister Test
1112 * @tc.type: FUNC
1113 */
1114 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityChildTreeRegister01, Function | SmallTest | Level3)
1115 {
1116 uint32_t windowId = 0;
1117 int32_t treeId = 0;
1118 int64_t accessibilityId = 0;
1119 window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1120 ASSERT_NE(nullptr, window_->uiContent_);
1121 auto ret = window_->NotifyAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
1122 ASSERT_EQ(WSError::WS_OK, ret);
1123
1124 window_->uiContent_ = nullptr;
1125 ret = window_->NotifyAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
1126 ASSERT_EQ(WSError::WS_OK, ret);
1127
1128 window_->handler_ = nullptr;
1129 ret = window_->NotifyAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
1130 ASSERT_EQ(WSError::WS_ERROR_INTERNAL_ERROR, ret);
1131 usleep(WAIT_SYNC_IN_NS);
1132 }
1133
1134 /**
1135 * @tc.name: NotifyAccessibilityChildTreeUnregister01
1136 * @tc.desc: NotifyAccessibilityChildTreeUnregister Test
1137 * @tc.type: FUNC
1138 */
1139 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityChildTreeUnregister01, Function | SmallTest | Level3)
1140 {
1141 window_->uiContent_ = nullptr;
1142 ASSERT_EQ(WSError::WS_OK, window_->NotifyAccessibilityChildTreeUnregister());
1143
1144 window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1145 ASSERT_NE(nullptr, window_->uiContent_);
1146 ASSERT_EQ(WSError::WS_OK, window_->NotifyAccessibilityChildTreeUnregister());
1147
1148 window_->handler_ = nullptr;
1149 ASSERT_EQ(WSError::WS_ERROR_INTERNAL_ERROR, window_->NotifyAccessibilityChildTreeUnregister());
1150 usleep(WAIT_SYNC_IN_NS);
1151 }
1152
1153 /**
1154 * @tc.name: NotifyAccessibilityDumpChildInfo01
1155 * @tc.desc: NotifyAccessibilityDumpChildInfo Test
1156 * @tc.type: FUNC
1157 */
1158 HWTEST_F(WindowExtensionSessionImplTest, NotifyAccessibilityDumpChildInfo01, Function | SmallTest | Level3)
1159 {
1160 std::vector<std::string> params;
1161 std::vector<std::string> info;
1162 window_->uiContent_ = nullptr;
1163 ASSERT_EQ(WSError::WS_OK, window_->NotifyAccessibilityDumpChildInfo(params, info));
1164
1165 window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1166 ASSERT_NE(nullptr, window_->uiContent_);
1167 ASSERT_EQ(WSError::WS_OK, window_->NotifyAccessibilityDumpChildInfo(params, info));
1168
1169 window_->handler_ = nullptr;
1170 ASSERT_EQ(WSError::WS_ERROR_INTERNAL_ERROR, window_->NotifyAccessibilityDumpChildInfo(params, info));
1171 usleep(WAIT_SYNC_IN_NS);
1172 }
1173
1174 /**
1175 * @tc.name: UpdateAccessibilityTreeInfo
1176 * @tc.desc: UpdateAccessibilityTreeInfo Test
1177 * @tc.type: FUNC
1178 */
1179 HWTEST_F(WindowExtensionSessionImplTest, UpdateAccessibilityTreeInfo, Function | SmallTest | Level3)
1180 {
1181 std::optional<AccessibilityChildTreeInfo> accessibilityChildTreeInfo =
1182 std::make_optional<AccessibilityChildTreeInfo>();
1183 ASSERT_NE(accessibilityChildTreeInfo, std::nullopt);
1184 window_->accessibilityChildTreeInfo_ = accessibilityChildTreeInfo;
1185 window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1186 ASSERT_NE(nullptr, window_->uiContent_);
1187 window_->UpdateAccessibilityTreeInfo();
1188
1189 window_->uiContent_ = nullptr;
1190 window_->UpdateAccessibilityTreeInfo();
1191
1192 window_->accessibilityChildTreeInfo_= std::nullopt;
1193 window_->UpdateAccessibilityTreeInfo();
1194 }
1195
1196 /**
1197 * @tc.name: NotifyOccupiedAreaChangeInfo01
1198 * @tc.desc: NotifyExecuteAction Test
1199 * @tc.type: FUNC
1200 */
1201 HWTEST_F(WindowExtensionSessionImplTest, NotifyOccupiedAreaChangeInfo01, Function | SmallTest | Level3)
1202 {
1203 sptr<OccupiedAreaChangeInfo> info = new(std::nothrow) OccupiedAreaChangeInfo();
1204 ASSERT_NE(nullptr, info);
1205 window_->NotifyOccupiedAreaChangeInfo(info);
1206 }
1207
1208 /**
1209 * @tc.name: NotifyOccupiedAreaChangeInfo02
1210 * @tc.desc: NotifyExecuteAction Test
1211 * @tc.type: FUNC
1212 */
1213 HWTEST_F(WindowExtensionSessionImplTest, NotifyOccupiedAreaChangeInfo02, Function | SmallTest | Level3)
1214 {
1215 sptr<IOccupiedAreaChangeListener> iOccupiedAreaChangeListener = new(std::nothrow) IOccupiedAreaChangeListener();
1216 ASSERT_NE(nullptr, iOccupiedAreaChangeListener);
1217 window_->RegisterOccupiedAreaChangeListener(iOccupiedAreaChangeListener);
1218 sptr<OccupiedAreaChangeInfo> info = new(std::nothrow) OccupiedAreaChangeInfo();
1219 ASSERT_NE(nullptr, info);
1220 window_->NotifyOccupiedAreaChangeInfo(info);
1221 }
1222
1223 /**
1224 * @tc.name: UnregisterOccupiedAreaChangeListener
1225 * @tc.desc: UnregisterOccupiedAreaChangeListener Test
1226 * @tc.type: FUNC
1227 */
1228 HWTEST_F(WindowExtensionSessionImplTest, UnregisterOccupiedAreaChangeListener, Function | SmallTest | Level3)
1229 {
1230 ASSERT_EQ(WMError::WM_OK, window_->UnregisterOccupiedAreaChangeListener(nullptr));
1231 }
1232
1233 /**
1234 * @tc.name: GetAvoidAreaByType01
1235 * @tc.desc: NotifyExecuteAction Test
1236 * @tc.type: FUNC
1237 */
1238 HWTEST_F(WindowExtensionSessionImplTest, GetAvoidAreaByType01, Function | SmallTest | Level3)
1239 {
1240 AvoidAreaType avoidAreaType = AvoidAreaType::TYPE_SYSTEM;
1241 AvoidArea avoidArea;
1242 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1243 }
1244
1245 /**
1246 * @tc.name: GetAvoidAreaByType02
1247 * @tc.desc: NotifyExecuteAction Test
1248 * @tc.type: FUNC
1249 */
1250 HWTEST_F(WindowExtensionSessionImplTest, GetAvoidAreaByType02, Function | SmallTest | Level3)
1251 {
1252 SessionInfo sessionInfo;
1253 window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1254 ASSERT_NE(nullptr, window_->hostSession_);
1255 AvoidAreaType avoidAreaType = AvoidAreaType::TYPE_SYSTEM;
1256 AvoidArea avoidArea;
1257 ASSERT_EQ(WMError::WM_OK, window_->GetAvoidAreaByType(avoidAreaType, avoidArea));
1258 }
1259
1260 /**
1261 * @tc.name: RegisterAvoidAreaChangeListener
1262 * @tc.desc: RegisterAvoidAreaChangeListener Test
1263 * @tc.type: FUNC
1264 */
1265 HWTEST_F(WindowExtensionSessionImplTest, RegisterAvoidAreaChangeListener, Function | SmallTest | Level3)
1266 {
1267 sptr<IAvoidAreaChangedListener> listener = nullptr;
1268 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->RegisterAvoidAreaChangeListener(listener));
1269 }
1270
1271 /**
1272 * @tc.name: UnregisterAvoidAreaChangeListener
1273 * @tc.desc: UnregisterAvoidAreaChangeListener Test
1274 * @tc.type: FUNC
1275 */
1276 HWTEST_F(WindowExtensionSessionImplTest, UnregisterAvoidAreaChangeListener, Function | SmallTest | Level3)
1277 {
1278 sptr<IAvoidAreaChangedListener> listener = nullptr;
1279 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->UnregisterAvoidAreaChangeListener(listener));
1280 }
1281
1282 /**
1283 * @tc.name: Show
1284 * @tc.desc: Show
1285 * @tc.type: FUNC
1286 */
1287 HWTEST_F(WindowExtensionSessionImplTest, Show, Function | SmallTest | Level3)
1288 {
1289 ASSERT_NE(nullptr, window_->property_);
1290 window_->property_->persistentId_ = 12345;
1291
1292 SessionInfo sessionInfo;
1293 sptr<SessionMocker> mockHostSession = new (std::nothrow) SessionMocker(sessionInfo);
1294 ASSERT_NE(mockHostSession, nullptr);
1295 window_->hostSession_ = mockHostSession;
1296
1297 window_->property_->SetDisplayId(DISPLAY_ID_INVALID);
1298 EXPECT_CALL(*mockHostSession, Foreground).Times(0).WillOnce(Return(WSError::WS_OK));
1299 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->Show());
1300
1301 window_->property_->SetDisplayId(0);
1302 EXPECT_CALL(*mockHostSession, Foreground).Times(1).WillOnce(Return(WSError::WS_DO_NOTHING));
1303 ASSERT_EQ(static_cast<WMError>(WSError::WS_DO_NOTHING), window_->Show());
1304 EXPECT_CALL(*mockHostSession, Foreground).Times(1).WillOnce(Return(WSError::WS_OK));
1305 ASSERT_EQ(WMError::WM_OK, window_->Show());
1306 }
1307
1308 /**
1309 * @tc.name: Hide
1310 * @tc.desc: Hide
1311 * @tc.type: FUNC
1312 */
1313 HWTEST_F(WindowExtensionSessionImplTest, Hide, Function | SmallTest | Level3)
1314 {
1315 ASSERT_NE(nullptr, window_->property_);
1316
1317 SessionInfo sessionInfo;
1318 sptr<SessionMocker> mockHostSession = new (std::nothrow) SessionMocker(sessionInfo);
1319 ASSERT_NE(mockHostSession, nullptr);
1320 window_->hostSession_ = mockHostSession;
1321
1322 window_->property_->persistentId_ = INVALID_SESSION_ID;
1323 auto res = window_->Hide(0, false, false);
1324 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1325
1326 window_->property_->persistentId_ = 12345;
1327 window_->state_ = WindowState::STATE_HIDDEN;
1328 EXPECT_CALL(*mockHostSession, Background).Times(0);
1329 res = window_->Hide(0, false, false);
1330 ASSERT_EQ(res, WMError::WM_OK);
1331
1332 window_->state_ = WindowState::STATE_CREATED;
1333 EXPECT_CALL(*mockHostSession, Background).Times(0);
1334 res = window_->Hide(0, false, false);
1335 ASSERT_EQ(res, WMError::WM_OK);
1336
1337 window_->state_ = WindowState::STATE_SHOWN;
1338 EXPECT_CALL(*mockHostSession, Background).Times(1).WillOnce(Return(WSError::WS_OK));
1339 res = window_->Hide(0, false, false);
1340 ASSERT_EQ(res, WMError::WM_OK);
1341 ASSERT_EQ(window_->state_, WindowState::STATE_HIDDEN);
1342
1343 window_->state_ = WindowState::STATE_SHOWN;
1344 EXPECT_CALL(*mockHostSession, Background).Times(1).WillOnce(Return(WSError::WS_DO_NOTHING));
1345 res = window_->Hide(0, false, false);
1346 ASSERT_EQ(res, WMError::WM_OK);
1347 ASSERT_EQ(window_->state_, WindowState::STATE_SHOWN);
1348 }
1349
1350 /**
1351 * @tc.name: NotifyDensityFollowHost01
1352 * @tc.desc: test isFollowHost is true
1353 * @tc.type: FUNC
1354 */
1355 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost01, Function | SmallTest | Level3)
1356 {
1357 DisplayId displayId = 0;
1358 ASSERT_NE(nullptr, window_->property_);
1359 window_->property_->SetDisplayId(displayId);
1360
1361 auto isFollowHost = true;
1362 auto densityValue = 0.1f;
1363
1364 window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1365 ASSERT_NE(nullptr, window_->uiContent_);
1366 Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
1367 Rect preRect;
1368 preRect.posX_ = 0;
1369 preRect.posY_ = 0;
1370 preRect.height_ = 200;
1371 preRect.width_ = 200;
1372 window_->property_->SetWindowRect(preRect);
1373 EXPECT_CALL(*content, UpdateViewportConfig(Field(&Ace::ViewportConfig::density_, densityValue), _, _, _));
1374
1375 ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1376 }
1377
1378 /**
1379 * @tc.name: NotifyDensityFollowHost02
1380 * @tc.desc: test isFollowHost is true -> false
1381 * @tc.type: FUNC
1382 */
1383 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost02, Function | SmallTest | Level3)
1384 {
1385 DisplayId displayId = 0;
1386 ASSERT_NE(nullptr, window_->property_);
1387 window_->property_->SetDisplayId(displayId);
1388
1389 auto isFollowHost = false;
1390 auto densityValue = 0.1f;
1391
1392 auto display = SingletonContainer::Get<DisplayManager>().GetDisplayById(window_->property_->GetDisplayId());
1393 ASSERT_NE(display, nullptr);
1394 ASSERT_NE(display->GetDisplayInfo(), nullptr);
1395 auto vpr = display->GetDisplayInfo()->GetVirtualPixelRatio();
1396
1397 window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1398 ASSERT_NE(nullptr, window_->uiContent_);
1399 Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
1400 Rect preRect;
1401 preRect.posX_ = 0;
1402 preRect.posY_ = 0;
1403 preRect.height_ = 100;
1404 preRect.width_ = 100;
1405 window_->property_->SetWindowRect(preRect);
1406 EXPECT_CALL(*content, UpdateViewportConfig(Field(&Ace::ViewportConfig::density_, vpr), _, _, _));
1407
1408 window_->isDensityFollowHost_ = true;
1409 ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1410 }
1411
1412 /**
1413 * @tc.name: NotifyDensityFollowHost03
1414 * @tc.desc: test isFollowHost not change
1415 * @tc.type: FUNC
1416 */
1417 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost03, Function | SmallTest | Level3)
1418 {
1419 DisplayId displayId = 0;
1420 ASSERT_NE(nullptr, window_->property_);
1421 window_->property_->SetDisplayId(displayId);
1422
1423 auto isFollowHost = false;
1424 auto densityValue = 0.1f;
1425 window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1426 ASSERT_NE(nullptr, window_->uiContent_);
1427 Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
1428 EXPECT_CALL(*content, UpdateViewportConfig(_, _, _, _)).Times(0);
1429
1430 ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1431 }
1432
1433 /**
1434 * @tc.name: NotifyDensityFollowHost04
1435 * @tc.desc: test densityValue invalid
1436 * @tc.type: FUNC
1437 */
1438 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost04, Function | SmallTest | Level3)
1439 {
1440 DisplayId displayId = 0;
1441 ASSERT_NE(nullptr, window_->property_);
1442 window_->property_->SetDisplayId(displayId);
1443
1444 auto isFollowHost = true;
1445 auto densityValue = 0.0f;
1446 ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_ERROR_INVALID_PARAM);
1447 densityValue = -0.1f;
1448 ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_ERROR_INVALID_PARAM);
1449 }
1450
1451 /**
1452 * @tc.name: NotifyDensityFollowHost05
1453 * @tc.desc: test densityValue not change
1454 * @tc.type: FUNC
1455 */
1456 HWTEST_F(WindowExtensionSessionImplTest, NotifyDensityFollowHost05, Function | SmallTest | Level3)
1457 {
1458 DisplayId displayId = 0;
1459 ASSERT_NE(nullptr, window_->property_);
1460 window_->property_->SetDisplayId(displayId);
1461
1462 auto isFollowHost = true;
1463 auto densityValue = 0.1f;
1464 window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1465 ASSERT_NE(nullptr, window_->uiContent_);
1466 Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
1467 EXPECT_CALL(*content, UpdateViewportConfig(_, _, _, _)).Times(0);
1468
1469 window_->hostDensityValue_ = densityValue;
1470 ASSERT_EQ(window_->NotifyDensityFollowHost(isFollowHost, densityValue), WSError::WS_OK);
1471 }
1472
1473 /**
1474 * @tc.name: GetVirtualPixelRatio01
1475 * @tc.desc: follow host density value
1476 * @tc.type: FUNC
1477 */
1478 HWTEST_F(WindowExtensionSessionImplTest, GetVirtualPixelRatio01, Function | SmallTest | Level2)
1479 {
1480 sptr<DisplayInfo> displayInfo = new DisplayInfo();
1481 displayInfo->SetVirtualPixelRatio(3.25f);
1482 window_->isDensityFollowHost_ = true;
1483 window_->hostDensityValue_ = 2.0f;
1484 ASSERT_EQ(window_->hostDensityValue_, window_->GetVirtualPixelRatio(displayInfo));
1485 }
1486
1487 /**
1488 * @tc.name: GetVirtualPixelRatio02
1489 * @tc.desc: follow system density value
1490 * @tc.type: FUNC
1491 */
1492 HWTEST_F(WindowExtensionSessionImplTest, GetVirtualPixelRatio02, Function | SmallTest | Level2)
1493 {
1494 auto systemDensity = 3.25;
1495 sptr<DisplayInfo> displayInfo = new DisplayInfo();
1496 displayInfo->SetVirtualPixelRatio(systemDensity);
1497 window_->isDensityFollowHost_ = false;
1498 window_->hostDensityValue_ = 2.0f;
1499 ASSERT_EQ(systemDensity, window_->GetVirtualPixelRatio(displayInfo));
1500 }
1501
1502 /**
1503 * @tc.name: GetVirtualPixelRatio03
1504 * @tc.desc: hostDensityValue_ is nullptr
1505 * @tc.type: FUNC
1506 */
1507 HWTEST_F(WindowExtensionSessionImplTest, GetVirtualPixelRatio03, Function | SmallTest | Level2)
1508 {
1509 auto systemDensity = 3.25;
1510 sptr<DisplayInfo> displayInfo = new DisplayInfo();
1511 displayInfo->SetVirtualPixelRatio(systemDensity);
1512 window_->isDensityFollowHost_ = true;
1513 ASSERT_EQ(systemDensity, window_->GetVirtualPixelRatio(displayInfo));
1514 }
1515
1516 /**
1517 * @tc.name: GetVirtualPixelRatio04
1518 * @tc.desc: GetVirtualPixelRatio04 test
1519 * @tc.type: FUNC
1520 */
1521 HWTEST_F(WindowExtensionSessionImplTest, GetVirtualPixelRatio04, Function | SmallTest | Level2)
1522 {
1523 ASSERT_EQ(1.0f, window_->GetVirtualPixelRatio(nullptr));
1524 }
1525
1526 /**
1527 * @tc.name: HideNonSecureWindows01
1528 * @tc.desc: HideNonSecureWindows Test
1529 * @tc.type: FUNC
1530 */
1531 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows01, Function | SmallTest | Level3)
1532 {
1533 ASSERT_EQ(WMError::WM_OK, window_->HideNonSecureWindows(false));
1534 }
1535
1536 /**
1537 * @tc.name: HideNonSecureWindows02
1538 * @tc.desc: HideNonSecureWindows Test
1539 * @tc.type: FUNC
1540 */
1541 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows02, Function | SmallTest | Level3)
1542 {
1543 window_->state_ = WindowState::STATE_SHOWN;
1544 ASSERT_EQ(WMError::WM_OK, window_->HideNonSecureWindows(false));
1545
1546 sptr<IRemoteObject> iRemoteObject = new IRemoteObjectMocker();
1547 ASSERT_NE(nullptr, iRemoteObject);
1548 window_->abilityToken_ = iRemoteObject;
1549 SessionInfo sessionInfo;
1550 window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1551 ASSERT_NE(nullptr, window_->hostSession_);
1552 ASSERT_NE(nullptr, window_->property_);
1553 window_->property_->SetPersistentId(1);
1554
1555 ASSERT_EQ(WMError::WM_OK, window_->HideNonSecureWindows(false));
1556 }
1557
1558 /**
1559 * @tc.name: HideNonSecureWindows03
1560 * @tc.desc: HideNonSecureWindows Test
1561 * @tc.type: FUNC
1562 */
1563 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows03, Function | SmallTest | Level3)
1564 {
1565 window_->state_ = WindowState::STATE_SHOWN;
1566 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->HideNonSecureWindows(true));
1567 }
1568
1569 /**
1570 * @tc.name: HideNonSecureWindows04
1571 * @tc.desc: HideNonSecureWindows Test
1572 * @tc.type: FUNC
1573 */
1574 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows04, Function | SmallTest | Level3)
1575 {
1576 SessionInfo sessionInfo;
1577 window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1578 ASSERT_NE(nullptr, window_->hostSession_);
1579 ASSERT_NE(nullptr, window_->property_);
1580 window_->property_->SetPersistentId(1);
1581 window_->state_ = WindowState::STATE_SHOWN;
1582 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->HideNonSecureWindows(true));
1583 }
1584
1585 /**
1586 * @tc.name: HideNonSecureWindows06
1587 * @tc.desc: HideNonSecureWindows Test
1588 * @tc.type: FUNC
1589 */
1590 HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows06, Function | SmallTest | Level3)
1591 {
1592 ASSERT_NE(nullptr, window_->property_);
1593 window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
1594 ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, window_->HideNonSecureWindows(false));
1595 }
1596
1597 /**
1598 * @tc.name: SetWaterMarkFlag01
1599 * @tc.desc: SetWaterMarkFlag Test
1600 * @tc.type: FUNC
1601 */
1602 HWTEST_F(WindowExtensionSessionImplTest, SetWaterMarkFlag01, Function | SmallTest | Level3)
1603 {
1604 ASSERT_EQ(WMError::WM_OK, window_->SetWaterMarkFlag(false));
1605 }
1606
1607 /**
1608 * @tc.name: SetWaterMarkFlag02
1609 * @tc.desc: SetWaterMarkFlag Test
1610 * @tc.type: FUNC
1611 */
1612 HWTEST_F(WindowExtensionSessionImplTest, SetWaterMarkFlag02, Function | SmallTest | Level3)
1613 {
1614 window_->state_ = WindowState::STATE_SHOWN;
1615 ASSERT_EQ(WMError::WM_OK, window_->SetWaterMarkFlag(false));
1616 }
1617
1618 /**
1619 * @tc.name: SetWaterMarkFlag03
1620 * @tc.desc: SetWaterMarkFlag Test
1621 * @tc.type: FUNC
1622 */
1623 HWTEST_F(WindowExtensionSessionImplTest, SetWaterMarkFlag03, Function | SmallTest | Level3)
1624 {
1625 window_->state_ = WindowState::STATE_SHOWN;
1626 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->SetWaterMarkFlag(true));
1627 }
1628
1629 /**
1630 * @tc.name: SetWaterMarkFlag04
1631 * @tc.desc: SetWaterMarkFlag Test
1632 * @tc.type: FUNC
1633 */
1634 HWTEST_F(WindowExtensionSessionImplTest, SetWaterMarkFlag04, Function | SmallTest | Level3)
1635 {
1636 SessionInfo sessionInfo;
1637 window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1638 ASSERT_NE(nullptr, window_->hostSession_);
1639 ASSERT_NE(nullptr, window_->property_);
1640 window_->property_->SetPersistentId(1);
1641 window_->state_ = WindowState::STATE_SHOWN;
1642 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->SetWaterMarkFlag(true));
1643 }
1644
1645 /**
1646 * @tc.name: CheckAndAddExtWindowFlags01
1647 * @tc.desc: CheckAndAddExtWindowFlags01 Test
1648 * @tc.type: FUNC
1649 */
1650 HWTEST_F(WindowExtensionSessionImplTest, CheckAndAddExtWindowFlags01, Function | SmallTest | Level3)
1651 {
1652 ASSERT_NE(nullptr, window_);
1653 window_->CheckAndAddExtWindowFlags();
1654 }
1655
1656 /**
1657 * @tc.name: CheckAndAddExtWindowFlags02
1658 * @tc.desc: CheckAndAddExtWindowFlags02 Test
1659 * @tc.type: FUNC
1660 */
1661 HWTEST_F(WindowExtensionSessionImplTest, CheckAndAddExtWindowFlags02, Function | SmallTest | Level3)
1662 {
1663 ASSERT_NE(nullptr, window_);
1664 window_->extensionWindowFlags_.bitData = 1;
1665 window_->CheckAndAddExtWindowFlags();
1666 }
1667
1668 /**
1669 * @tc.name: CheckAndRemoveExtWindowFlags01
1670 * @tc.desc: CheckAndRemoveExtWindowFlags01 Test
1671 * @tc.type: FUNC
1672 */
1673 HWTEST_F(WindowExtensionSessionImplTest, CheckAndRemoveExtWindowFlags01, Function | SmallTest | Level3)
1674 {
1675 ASSERT_NE(nullptr, window_);
1676 window_->CheckAndRemoveExtWindowFlags();
1677 }
1678
1679 /**
1680 * @tc.name: CheckAndRemoveExtWindowFlags02
1681 * @tc.desc: CheckAndRemoveExtWindowFlags02 Test
1682 * @tc.type: FUNC
1683 */
1684 HWTEST_F(WindowExtensionSessionImplTest, CheckAndRemoveExtWindowFlags02, Function | SmallTest | Level3)
1685 {
1686 ASSERT_NE(nullptr, window_);
1687 window_->extensionWindowFlags_.bitData = 1;
1688 window_->CheckAndRemoveExtWindowFlags();
1689 }
1690
1691 /**
1692 * @tc.name: UpdateExtWindowFlags01
1693 * @tc.desc: UpdateExtWindowFlags Test
1694 * @tc.type: FUNC
1695 */
1696 HWTEST_F(WindowExtensionSessionImplTest, UpdateExtWindowFlags01, Function | SmallTest | Level3)
1697 {
1698 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window_->UpdateExtWindowFlags(ExtensionWindowFlags(),
1699 ExtensionWindowFlags()));
1700 }
1701
1702 /**
1703 * @tc.name: UpdateExtWindowFlags02
1704 * @tc.desc: UpdateExtWindowFlags Test
1705 * @tc.type: FUNC
1706 */
1707 HWTEST_F(WindowExtensionSessionImplTest, UpdateExtWindowFlags02, Function | SmallTest | Level3)
1708 {
1709 SessionInfo sessionInfo;
1710 window_->hostSession_ = new(std::nothrow) SessionMocker(sessionInfo);
1711 ASSERT_NE(nullptr, window_->hostSession_);
1712 ASSERT_NE(nullptr, window_->property_);
1713 window_->property_->SetPersistentId(1);
1714 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->UpdateExtWindowFlags(ExtensionWindowFlags(), ExtensionWindowFlags()));
1715
1716 sptr<IRemoteObject> iRemoteObject = new IRemoteObjectMocker();
1717 ASSERT_NE(nullptr, iRemoteObject);
1718 window_->abilityToken_ = iRemoteObject;
1719 ASSERT_NE(WMError::WM_ERROR_NULLPTR, window_->UpdateExtWindowFlags(ExtensionWindowFlags(), ExtensionWindowFlags()));
1720 }
1721
1722 /**
1723 * @tc.name: GetHostWindowRect01
1724 * @tc.desc: GetHostWindowRect Test
1725 * @tc.type: FUNC
1726 */
1727 HWTEST_F(WindowExtensionSessionImplTest, GetHostWindowRect01, Function | SmallTest | Level3)
1728 {
1729 Rect rect;
1730 ASSERT_EQ(rect, window_->GetHostWindowRect(-1));
1731 }
1732
1733 /**
1734 * @tc.name: GetHostWindowRect02
1735 * @tc.desc: GetHostWindowRect Test
1736 * @tc.type: FUNC
1737 */
1738 HWTEST_F(WindowExtensionSessionImplTest, GetHostWindowRect02, Function | SmallTest | Level3)
1739 {
1740 Rect rect;
1741 ASSERT_EQ(rect, window_->GetHostWindowRect(0));
1742 }
1743
1744 /**
1745 * @tc.name: ConsumePointerEvent
1746 * @tc.desc: ConsumePointerEvent Test
1747 * @tc.type: FUNC
1748 */
1749 HWTEST_F(WindowExtensionSessionImplTest, ConsumePointerEvent, Function | SmallTest | Level3)
1750 {
1751 struct RSSurfaceNodeConfig config;
1752 window_->surfaceNode_ = RSSurfaceNode::Create(config);
1753 window_->state_ = WindowState::STATE_SHOWN;
1754
1755 auto pointerEvent = MMI::PointerEvent::Create();
1756 window_->ConsumePointerEvent(nullptr);
1757
1758 window_->ConsumePointerEvent(pointerEvent);
1759
1760 SessionInfo sessionInfo;
1761 window_->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
1762 ASSERT_NE(nullptr, window_->hostSession_);
1763 window_->ConsumePointerEvent(pointerEvent);
1764
1765 MMI::PointerEvent::PointerItem item;
1766 pointerEvent->SetPointerId(0);
1767 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
1768 item.SetPointerId(0);
1769 item.SetDisplayX(15); // 15 : position x
1770 item.SetDisplayY(15); // 15 : position y
1771 item.SetWindowX(15); // 15 : position x
1772 item.SetWindowY(15); // 15 : position y
1773 pointerEvent->AddPointerItem(item);
1774 window_->ConsumePointerEvent(pointerEvent);
1775
1776 ASSERT_NE(nullptr, window_->property_);
1777 window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
1778 window_->ConsumePointerEvent(pointerEvent);
1779
1780 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_MOVE);
1781 pointerEvent->UpdatePointerItem(0, item);
1782 window_->ConsumePointerEvent(pointerEvent);
1783
1784 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
1785 pointerEvent->UpdatePointerItem(0, item);
1786 window_->ConsumePointerEvent(pointerEvent);
1787 }
1788
1789 /**
1790 * @tc.name: PreNotifyKeyEvent
1791 * @tc.desc: PreNotifyKeyEvent Test
1792 * @tc.type: FUNC
1793 */
1794 HWTEST_F(WindowExtensionSessionImplTest, PreNotifyKeyEvent, Function | SmallTest | Level3)
1795 {
1796 bool ret = window_->PreNotifyKeyEvent(nullptr);
1797 ASSERT_EQ(ret, false);
1798
1799 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
1800 ASSERT_NE(nullptr, keyEvent);
1801 ASSERT_NE(nullptr, window_->property_);
1802 window_->property_->SetUIExtensionUsage(UIExtensionUsage::MODAL);
1803 ret = window_->PreNotifyKeyEvent(keyEvent);
1804 ASSERT_EQ(ret, false);
1805
1806 std::shared_ptr<Ace::UIContent> uiContent = std::make_unique<Ace::UIContentMocker>();
1807 ASSERT_NE(nullptr, uiContent);
1808 window_->uiContent_ = uiContent;
1809 Ace::UIContentMocker* uiContentMocker = reinterpret_cast<Ace::UIContentMocker*>(window_->uiContent_.get());
1810 EXPECT_CALL(*uiContentMocker, ProcessKeyEvent).Times(2).WillOnce(Return(true));
1811 ret = window_->PreNotifyKeyEvent(keyEvent);
1812 ASSERT_EQ(ret, true);
1813
1814 window_->property_->SetUIExtensionUsage(UIExtensionUsage::CONSTRAINED_EMBEDDED);
1815 ret = window_->PreNotifyKeyEvent(keyEvent);
1816 ASSERT_EQ(ret, true);
1817
1818 window_->focusState_ = false;
1819 ret = window_->PreNotifyKeyEvent(keyEvent);
1820 ASSERT_EQ(ret, true);
1821
1822 window_->focusState_ = true;
1823 ret = window_->PreNotifyKeyEvent(keyEvent);
1824 ASSERT_EQ(ret, false);
1825 }
1826
1827 /**
1828 * @tc.name: GetFreeMultiWindowModeEnabledState
1829 * @tc.desc: GetFreeMultiWindowModeEnabledState Test
1830 * @tc.type: FUNC
1831 */
1832 HWTEST_F(WindowExtensionSessionImplTest, GetFreeMultiWindowModeEnabledState, Function | SmallTest | Level3)
1833 {
1834 ASSERT_EQ(false, window_->GetFreeMultiWindowModeEnabledState());
1835 }
1836
1837 /**
1838 * @tc.name: GetParentWindowType
1839 * @tc.desc: GetParentWindowType Test
1840 * @tc.type: FUNC
1841 */
1842 HWTEST_F(WindowExtensionSessionImplTest, GetParentWindowType, Function | SmallTest | Level3)
1843 {
1844 ASSERT_NE(window_->property_, nullptr);
1845 window_->property_->SetParentWindowType(WindowType::WINDOW_TYPE_TOAST);
1846 EXPECT_EQ(window_->GetParentWindowType(), WindowType::WINDOW_TYPE_TOAST);
1847 }
1848
1849 /**
1850 * @tc.name: CheckHideNonSecureWindowsPermission
1851 * @tc.desc: CheckHideNonSecureWindowsPermission Test
1852 * @tc.type: FUNC
1853 */
1854 HWTEST_F(WindowExtensionSessionImplTest, CheckHideNonSecureWindowsPermission, Function | SmallTest | Level3)
1855 {
1856 ASSERT_NE(window_->property_, nullptr);
1857
1858 window_->property_->uiExtensionUsage_ = UIExtensionUsage::EMBEDDED;
1859 EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(true), WMError::WM_OK);
1860 EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(false), WMError::WM_OK);
1861
1862 window_->property_->uiExtensionUsage_ = UIExtensionUsage::MODAL;
1863 EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(true), WMError::WM_OK);
1864 EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(false), WMError::WM_ERROR_INVALID_OPERATION);
1865
1866 window_->property_->uiExtensionUsage_ = UIExtensionUsage::CONSTRAINED_EMBEDDED;
1867 window_->modalUIExtensionMayBeCovered_ = true;
1868 EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(true), WMError::WM_OK);
1869 EXPECT_EQ(window_->CheckHideNonSecureWindowsPermission(false), WMError::WM_ERROR_INVALID_OPERATION);
1870 }
1871
1872 /**
1873 * @tc.name: NotifyModalUIExtensionMayBeCovered
1874 * @tc.desc: NotifyModalUIExtensionMayBeCovered Test
1875 * @tc.type: FUNC
1876 */
1877 HWTEST_F(WindowExtensionSessionImplTest, NotifyModalUIExtensionMayBeCovered, Function | SmallTest | Level3)
1878 {
1879 ASSERT_NE(window_, nullptr);
1880 ASSERT_NE(window_->property_, nullptr);
1881
1882 window_->property_->uiExtensionUsage_ = UIExtensionUsage::EMBEDDED;
1883 window_->NotifyModalUIExtensionMayBeCovered(true);
1884
1885 window_->property_->uiExtensionUsage_ = UIExtensionUsage::MODAL;
1886 window_->extensionWindowFlags_.hideNonSecureWindowsFlag = true;
1887 window_->NotifyModalUIExtensionMayBeCovered(true);
1888
1889 window_->property_->uiExtensionUsage_ = UIExtensionUsage::CONSTRAINED_EMBEDDED;
1890 window_->extensionWindowFlags_.hideNonSecureWindowsFlag = false;
1891 window_->NotifyModalUIExtensionMayBeCovered(false);
1892 }
1893
1894 /**
1895 * @tc.name: ReportModalUIExtensionMayBeCovered
1896 * @tc.desc: ReportModalUIExtensionMayBeCovered Test
1897 * @tc.type: FUNC
1898 */
1899 HWTEST_F(WindowExtensionSessionImplTest, ReportModalUIExtensionMayBeCovered, Function | SmallTest | Level3)
1900 {
1901 ASSERT_NE(window_, nullptr);
1902 window_->ReportModalUIExtensionMayBeCovered(true);
1903 window_->NotifyModalUIExtensionMayBeCovered(false);
1904 }
1905
1906 /**
1907 * @tc.name: GetRealParentId
1908 * @tc.desc: GetRealParentId Test
1909 * @tc.type: FUNC
1910 */
1911 HWTEST_F(WindowExtensionSessionImplTest, GetRealParentId, Function | SmallTest | Level3)
1912 {
1913 ASSERT_NE(window_->property_, nullptr);
1914 window_->property_->SetRealParentId(12345);
1915 EXPECT_EQ(window_->GetRealParentId(), 12345);
1916 }
1917
1918 /**
1919 * @tc.name: NotifyExtensionEventAsync
1920 * @tc.desc: NotifyExtensionEventAsync Test
1921 * @tc.type: FUNC
1922 */
1923 HWTEST_F(WindowExtensionSessionImplTest, NotifyExtensionEventAsync, Function | SmallTest | Level3)
1924 {
1925 window_->NotifyExtensionEventAsync(0);
1926
1927 SessionInfo sessionInfo;
1928 window_->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
1929 ASSERT_NE(nullptr, window_->hostSession_);
1930 window_->property_->SetPersistentId(1);
1931 window_->NotifyExtensionEventAsync(0);
1932 }
1933
1934 /**
1935 * @tc.name: NotifyDumpInfo
1936 * @tc.desc: NotifyDumpInfo Test
1937 * @tc.type: FUNC
1938 */
1939 HWTEST_F(WindowExtensionSessionImplTest, NotifyDumpInfo, Function | SmallTest | Level3)
1940 {
1941 ASSERT_NE(nullptr, window_);
1942 window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1943 ASSERT_NE(nullptr, window_->uiContent_);
1944 std::vector<std::string> params;
1945 std::vector<std::string> info;
1946 auto ret = window_->NotifyDumpInfo(params, info);
1947 ASSERT_EQ(WSError::WS_OK, ret);
1948
1949 window_->uiContent_ = nullptr;
1950 ret = window_->NotifyDumpInfo(params, info);
1951 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, ret);
1952 }
1953
1954 /**
1955 * @tc.name: UpdateConfigurationSyncForAll
1956 * @tc.desc: UpdateConfigurationSyncForAll Test
1957 * @tc.type: FUNC
1958 */
1959 HWTEST_F(WindowExtensionSessionImplTest, UpdateConfigurationSyncForAll, Function | SmallTest | Level3)
1960 {
1961 std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
1962 ASSERT_NE(nullptr, window_);
1963 window_->windowExtensionSessionSet_.insert(window_);
1964 window_->UpdateConfigurationSyncForAll(configuration);
1965 window_->windowExtensionSessionSet_.erase(window_);
1966 }
1967 }
1968 } // namespace Rosen
1969 } // namespace OHOS