1 /*
2 * Copyright (c) 2024 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 <filesystem>
17 #include <fstream>
18 #include <gtest/gtest.h>
19
20 #include "ability_context_impl.h"
21 #include "accessibility_event_info.h"
22 #include "color_parser.h"
23 #include "mock_session.h"
24 #include "mock_session_stub.h"
25 #include "mock_uicontent.h"
26 #include "mock_window.h"
27 #include "parameters.h"
28 #include "scene_board_judgement.h"
29 #include "window_accessibility_controller.h"
30 #include "window_helper.h"
31 #include "window_session_impl.h"
32 #include "wm_common.h"
33
34 using namespace testing;
35 using namespace testing::ext;
36
37 namespace OHOS {
38 namespace Rosen {
39 class WindowSessionImplTest4 : public testing::Test {
40 public:
41 static void SetUpTestCase();
42 static void TearDownTestCase();
43 void SetUp() override;
44 void TearDown() override;
45
46 std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
47
48 private:
49 static constexpr uint32_t WAIT_SYNC_IN_NS = 50000;
50 };
51
SetUpTestCase()52 void WindowSessionImplTest4::SetUpTestCase() {}
53
TearDownTestCase()54 void WindowSessionImplTest4::TearDownTestCase() {}
55
SetUp()56 void WindowSessionImplTest4::SetUp()
57 {
58 abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
59 }
60
TearDown()61 void WindowSessionImplTest4::TearDown()
62 {
63 usleep(WAIT_SYNC_IN_NS);
64 abilityContext_ = nullptr;
65 }
66
67 namespace {
68 /**
69 * @tc.name: GetRequestWindowStatetest01
70 * @tc.desc: GetRequestWindowState
71 * @tc.type: FUNC
72 */
73 HWTEST_F(WindowSessionImplTest4, GetRequestWindowState, Function | SmallTest | Level2)
74 {
75 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetRequestWindowStatetest01 start";
76 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
77 option->SetWindowName("GetRequestWindowState");
78 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
79 auto ret = window->GetRequestWindowState();
80 ASSERT_EQ(ret, WindowState::STATE_INITIAL);
81 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetRequestWindowStatetest01 end";
82 }
83
84 /**
85 * @tc.name: GetFocusabletest01
86 * @tc.desc: GetFocusable
87 * @tc.type: FUNC
88 */
89 HWTEST_F(WindowSessionImplTest4, GetFocusable, Function | SmallTest | Level2)
90 {
91 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetFocusabletest01 start";
92 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
93 option->SetWindowName("GetFocusable");
94 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
95 bool ret = window->GetFocusable();
96 ASSERT_EQ(ret, true);
97 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetFocusabletest01 end";
98 }
99
100 /**
101 * @tc.name: TransferAccessibilityEvent
102 * @tc.desc: TransferAccessibilityEvent
103 * @tc.type: FUNC
104 */
105 HWTEST_F(WindowSessionImplTest4, TransferAccessibilityEvent, Function | SmallTest | Level2)
106 {
107 GTEST_LOG_(INFO) << "WindowSessionImplTest4: TransferAccessibilityEvent start";
108 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
109 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
110 Accessibility::AccessibilityEventInfo info;
111 int64_t uiExtensionIdLevel = 0;
112 ASSERT_EQ(WMError::WM_OK, window->TransferAccessibilityEvent(info, uiExtensionIdLevel));
113 GTEST_LOG_(INFO) << "WindowSessionImplTest4: TransferAccessibilityEvent end";
114 }
115
116 /**
117 * @tc.name: SetSingleFrameComposerEnabled01
118 * @tc.desc: SetSingleFrameComposerEnabled and check the retCode
119 * @tc.type: FUNC
120 */
121 HWTEST_F(WindowSessionImplTest4, SetSingleFrameComposerEnabled01, Function | SmallTest | Level2)
122 {
123 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
124 option->SetWindowName("SetSingleFrameComposerEnabled01");
125 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
126 WMError retCode = window->SetSingleFrameComposerEnabled(false);
127 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
128 window->property_->SetPersistentId(1);
129 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
130 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
131 ASSERT_NE(nullptr, session);
132 window->hostSession_ = session;
133 window->state_ = WindowState::STATE_CREATED;
134 retCode = window->SetSingleFrameComposerEnabled(false);
135 ASSERT_EQ(retCode, WMError::WM_OK);
136
137 window->surfaceNode_ = nullptr;
138 retCode = window->SetSingleFrameComposerEnabled(false);
139 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
140 }
141
142 /**
143 * @tc.name: SetTopmost
144 * @tc.desc: SetTopmost
145 * @tc.type: FUNC
146 */
147 HWTEST_F(WindowSessionImplTest4, SetTopmost, Function | SmallTest | Level2)
148 {
149 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
150 option->SetWindowName("SetTopmost");
151 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
152 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
153 WMError res = window->SetTopmost(true);
154 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, res);
155 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
156 res = window->SetTopmost(true);
157 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, res);
158
159 window->property_->SetPersistentId(1);
160 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
161 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
162 ASSERT_NE(nullptr, session);
163 window->hostSession_ = session;
164 window->state_ = WindowState::STATE_CREATED;
165 res = window->SetTopmost(true);
166 ASSERT_EQ(WMError::WM_OK, res);
167 }
168
169 /**
170 * @tc.name: IsTopmost
171 * @tc.desc: IsTopmost
172 * @tc.type: FUNC
173 */
174 HWTEST_F(WindowSessionImplTest4, IsTopmost, Function | SmallTest | Level2)
175 {
176 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
177 option->SetWindowName("IsTopmost");
178 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
179 ASSERT_NE(window, nullptr);
180 bool res = window->IsTopmost();
181 ASSERT_FALSE(res);
182 }
183
184 /**
185 * @tc.name: SetMainWindowTopmost
186 * @tc.desc: SetMainWindowTopmost
187 * @tc.type: FUNC
188 */
189 HWTEST_F(WindowSessionImplTest4, SetMainWindowTopmost, Function | SmallTest | Level2)
190 {
191 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
192 option->SetWindowName("SetMainWindowTopmost");
193 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
194 WMError res = window->SetMainWindowTopmost(false);
195 EXPECT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
196 window->property_->SetPersistentId(1);
197 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
198 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
199 window->hostSession_ = session;
200 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
201 res = window->SetMainWindowTopmost(true);
202 EXPECT_EQ(res, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
203 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
204 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
205 res = window->SetMainWindowTopmost(true);
206 EXPECT_EQ(res, WMError::WM_ERROR_INVALID_CALLING);
207 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
208 res = window->SetMainWindowTopmost(true);
209 EXPECT_EQ(res, WMError::WM_OK);
210 res = window->SetMainWindowTopmost(false);
211 EXPECT_EQ(res, WMError::WM_OK);
212 }
213
214 /**
215 * @tc.name: IsMainWindowTopmost
216 * @tc.desc: IsMainWindowTopmost
217 * @tc.type: FUNC
218 */
219 HWTEST_F(WindowSessionImplTest4, IsMainWindowTopmost, Function | SmallTest | Level2)
220 {
221 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
222 option->SetWindowName("IsMainWindowTopmost");
223 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
224 bool res = window->IsMainWindowTopmost();
225 ASSERT_FALSE(res);
226 }
227
228 /**
229 * @tc.name: SetDecorVisible
230 * @tc.desc: SetDecorVisible and check the retCode
231 * @tc.type: FUNC
232 */
233 HWTEST_F(WindowSessionImplTest4, SetDecorVisible, Function | SmallTest | Level2)
234 {
235 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetDecorVisibletest01 start";
236 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
237 option->SetWindowName("SetDecorVisible");
238 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
239 ASSERT_NE(window->property_, nullptr);
240 window->property_->SetPersistentId(1);
241 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
242 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
243 ASSERT_NE(nullptr, session);
244 window->hostSession_ = session;
245
246 bool isVisible = true;
247 WMError res = window->SetDecorVisible(isVisible);
248 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
249
250 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
251 res = window->SetDecorVisible(isVisible);
252 ASSERT_EQ(res, WMError::WM_OK);
253 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetDecorVisibletest01 end";
254 }
255
256 /**
257 * @tc.name: GetDecorVisible
258 * @tc.desc: GetDecorVisible and check the retCode
259 * @tc.type: FUNC
260 */
261 HWTEST_F(WindowSessionImplTest4, GetDecorVisible, Function | SmallTest | Level2)
262 {
263 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorVisible start";
264 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
265 option->SetWindowName("GetDecorVisible");
266 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
267 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
268 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
269 window->hostSession_ = session;
270 window->property_->SetPersistentId(INVALID_SESSION_ID);
271 bool isVisible = true;
272 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->GetDecorVisible(isVisible));
273 window->property_->SetPersistentId(1);
274 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
275 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->GetDecorVisible(isVisible));
276 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
277 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->GetDecorVisible(isVisible));
278 auto uiContent = std::make_unique<Ace::UIContentMocker>();
279 EXPECT_CALL(*uiContent, GetContainerModalTitleVisible(_)).WillRepeatedly(Return(false));
280 window->uiContent_ = std::move(uiContent);
281 ASSERT_EQ(WMError::WM_OK, window->GetDecorVisible(isVisible));
282 ASSERT_FALSE(isVisible);
283 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorVisible end";
284 }
285
286 /**
287 * @tc.name: SetWindowTitleMoveEnabled
288 * @tc.desc: SetWindowTitleMoveEnabled and check the retCode
289 * @tc.type: FUNC
290 */
291 HWTEST_F(WindowSessionImplTest4, SetWindowTitleMoveEnabled, Function | SmallTest | Level2)
292 {
293 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowTitleMoveEnabledtest01 start";
294 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
295 option->SetWindowName("SetWindowTitleMoveEnabled");
296 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
297 WMError res = window->SetWindowTitleMoveEnabled(true);
298 EXPECT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
299 window->property_->SetPersistentId(1);
300 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
301 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
302 window->hostSession_ = session;
303 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
304 res = window->SetWindowTitleMoveEnabled(true);
305 EXPECT_EQ(res, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
306 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
307 window->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
308 res = window->SetWindowTitleMoveEnabled(true);
309 EXPECT_EQ(res, WMError::WM_ERROR_INVALID_CALLING);
310 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
311 res = window->SetWindowTitleMoveEnabled(true);
312 EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
313 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
314 res = window->SetWindowTitleMoveEnabled(true);
315 EXPECT_EQ(res, WMError::WM_OK);
316 res = window->SetWindowTitleMoveEnabled(false);
317 EXPECT_EQ(res, WMError::WM_OK);
318 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowTitleMoveEnabledtest01 end";
319 }
320
321 /**
322 * @tc.name: SetSubWindowModal
323 * @tc.desc: SetSubWindowModal and check the retCode
324 * @tc.type: FUNC
325 */
326 HWTEST_F(WindowSessionImplTest4, SetSubWindowModal, Function | SmallTest | Level2)
327 {
328 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest01 start";
329 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
330 option->SetWindowName("SetSubWindowModal");
331 sptr<WindowSessionImpl> mainWindow = sptr<WindowSessionImpl>::MakeSptr(option);
332 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
333 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
334 mainWindow->hostSession_ = session;
335 ASSERT_NE(nullptr, mainWindow->property_);
336 mainWindow->property_->SetPersistentId(1); // 1 is main window id
337 mainWindow->state_ = WindowState::STATE_CREATED;
338 WMError res = mainWindow->SetSubWindowModal(true); // main window is invalid
339 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, res);
340
341 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
342 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
343 ASSERT_NE(window, nullptr);
344 res = window->SetSubWindowModal(true); // sub window is valid
345 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, res); // window state is invalid
346
347 window->hostSession_ = session;
348 ASSERT_NE(nullptr, window->property_);
349 window->property_->SetPersistentId(2); // 2 is sub window id
350 window->state_ = WindowState::STATE_CREATED;
351 res = window->SetSubWindowModal(true); // sub window is valid
352 ASSERT_EQ(WMError::WM_OK, res);
353 res = window->SetSubWindowModal(false);
354 ASSERT_EQ(WMError::WM_OK, res);
355 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest01 end";
356 }
357
358 /**
359 * @tc.name: SetSubWindowModal02
360 * @tc.desc: SetSubWindowModal and check the retCode
361 * @tc.type: FUNC
362 */
363 HWTEST_F(WindowSessionImplTest4, SetSubWindowModal02, Function | SmallTest | Level2)
364 {
365 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest02 start";
366 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
367 option->SetWindowName("SetSubWindowModal02");
368 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
369 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
370 ASSERT_NE(nullptr, window->property_);
371 window->property_->SetPersistentId(1);
372 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
373 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
374 window->hostSession_ = session;
375 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
376 WMError res = window->SetSubWindowModal(true, ModalityType::WINDOW_MODALITY);
377 ASSERT_EQ(res, WMError::WM_OK);
378 res = window->SetSubWindowModal(true, ModalityType::APPLICATION_MODALITY);
379 ASSERT_EQ(res, WMError::WM_OK);
380 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest02 end";
381 }
382
383 /**
384 * @tc.name: SetSubWindowModal03
385 * @tc.desc: SetSubWindowModal and check the retcode
386 * @tc.type: FUNC
387 */
388 HWTEST_F(WindowSessionImplTest4, SetSubWindowModal03, Function | SmallTest | Level2)
389 {
390 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest03 start";
391 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
392 option->SetWindowName("SetSubWindowModal03");
393 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
394 WMError res = window->SetSubWindowModal(true, ModalityType::WINDOW_MODALITY);
395 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
396 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest03 end";
397 }
398
399 /**
400 * @tc.name: SetSubWindowModal04
401 * @tc.desc: SetSubWindowModal SetSubWindowModal and check the retcode
402 * @tc.type: FUNC
403 */
404 HWTEST_F(WindowSessionImplTest4, SetSubWindowModal04, Function | SmallTest | Level2)
405 {
406 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest04 start";
407 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
408 option->SetWindowName("SetSubWindowModal04");
409 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
410
411 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
412 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
413 window->hostSession_ = session;
414 window->property_->SetPersistentId(1);
415 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
416 WMError res = window->SetSubWindowModal(true, ModalityType::WINDOW_MODALITY);
417 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_CALLING);
418 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest04 end";
419 }
420
421 /**
422 * @tc.name: SetWindowModal
423 * @tc.desc: SetWindowModal and check the retCode
424 * @tc.type: FUNC
425 */
426 HWTEST_F(WindowSessionImplTest4, SetWindowModal, Function | SmallTest | Level2)
427 {
428 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowModal start";
429 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
430 option->SetWindowName("SetWindowModal");
431 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
432 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
433 window->property_->SetPersistentId(1);
434 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
435 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
436 window->hostSession_ = session;
437 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
438 WMError res = window->SetWindowModal(true);
439 ASSERT_EQ(res, WMError::WM_OK);
440 res = window->SetWindowModal(false);
441 ASSERT_EQ(res, WMError::WM_OK);
442 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
443 res = window->SetWindowModal(true);
444 ASSERT_EQ(res, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
445 res = window->SetWindowModal(false);
446 ASSERT_EQ(res, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
447 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowModal end";
448 }
449
450 /**
451 * @tc.name: IsPcWindow
452 * @tc.desc: IsPcWindow
453 * @tc.type: FUNC
454 */
455 HWTEST_F(WindowSessionImplTest4, IsPcWindow, Function | SmallTest | Level2)
456 {
457 GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcWindow start";
458 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
459 option->SetWindowName("IsPcWindow");
460 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
461 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
462 window->property_->SetPersistentId(1);
463 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
464 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
465 window->hostSession_ = session;
466 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
467 ASSERT_EQ(true, window->IsPcWindow());
468 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
469 ASSERT_EQ(false, window->IsPcWindow());
470 GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcWindow end";
471 }
472
473 /**
474 * @tc.name: IsPcOrPadFreeMultiWindowMode
475 * @tc.desc: IsPcOrPadFreeMultiWindowMode
476 * @tc.type: FUNC
477 */
478 HWTEST_F(WindowSessionImplTest4, IsPcOrPadFreeMultiWindowMode, Function | SmallTest | Level2)
479 {
480 GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadFreeMultiWindowMode start";
481 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
482 option->SetWindowName("IsPcOrPadFreeMultiWindowMode");
483 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
484 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
485 window->property_->SetPersistentId(1);
486 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
487 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
488 window->hostSession_ = session;
489 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
490 ASSERT_EQ(true, window->IsPcOrPadFreeMultiWindowMode());
491 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
492 ASSERT_EQ(false, window->IsPcOrPadFreeMultiWindowMode());
493 GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadFreeMultiWindowMode end";
494 }
495
496 /**
497 * @tc.name: GetVirtualPixelRatio01
498 * @tc.desc: GetVirtualPixelRatio
499 * @tc.type: FUNC
500 */
501 HWTEST_F(WindowSessionImplTest4, GetVirtualPixelRatio01, Function | SmallTest | Level2)
502 {
503 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetVirtualPixelRatio01 start";
504 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
505 option->SetWindowName("GetVirtualPixelRatio01");
506 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
507 window->property_->SetPersistentId(1);
508 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
509 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
510 window->hostSession_ = session;
511 float vpr = 0.f;
512 window->property_->SetDisplayId(-1);
513 auto res = window->GetVirtualPixelRatio(vpr);
514 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
515 window->property_->SetDisplayId(0);
516 res = window->GetVirtualPixelRatio(vpr);
517 ASSERT_EQ(res, WMError::WM_OK);
518 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetVirtualPixelRatio01 end";
519 }
520
521 /**
522 * @tc.name: GetDecorHeight
523 * @tc.desc: GetDecorHeight and check the retCode
524 * @tc.type: FUNC
525 */
526 HWTEST_F(WindowSessionImplTest4, GetDecorHeight, Function | SmallTest | Level2)
527 {
528 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorHeighttest01 start";
529 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
530 option->SetWindowName("GetDecorHeight");
531 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
532 ASSERT_NE(window->property_, nullptr);
533 window->property_->SetPersistentId(1);
534 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
535 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
536 window->hostSession_ = session;
537 int32_t height = 0;
538 WMError res = window->GetDecorHeight(height);
539 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
540 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorHeighttest01 end";
541 }
542
543 /**
544 * @tc.name: GetDecorButtonStyle
545 * @tc.desc: GetDecorButtonStyle and check the retCode
546 * @tc.type: FUNC
547 */
548 HWTEST_F(WindowSessionImplTest4, GetDecorButtonStyle, Function | SmallTest | Level2)
549 {
550 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorButtonStyle start";
551 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
552 option->SetWindowName("GetDecorButtonStyle");
553 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
554 window->property_->SetPersistentId(1);
555 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
556 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
557 window->hostSession_ = session;
558 window->state_ = WindowState::STATE_CREATED;
559
560 // check window type
561 DecorButtonStyle style;
562 window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
563 WMError res = window->GetDecorButtonStyle(style);
564 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_CALLING);
565
566 // check default set
567 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
568 res = window->GetDecorButtonStyle(style);
569 ASSERT_EQ(style.buttonBackgroundSize, DEFAULT_BUTTON_BACKGROUND_SIZE);
570 ASSERT_EQ(style.closeButtonRightMargin, DEFAULT_CLOSE_BUTTON_RIGHT_MARGIN);
571 ASSERT_EQ(style.spacingBetweenButtons, DEFAULT_SPACING_BETWEEN_BUTTONS);
572 ASSERT_EQ(style.colorMode, DEFAULT_COLOR_MODE);
573 ASSERT_EQ(res, WMError::WM_OK);
574 }
575
576 /**
577 * @tc.name: SetDecorButtonStyle
578 * @tc.desc: SetDecorButtonStyle and check the retCode
579 * @tc.type: FUNC
580 */
581 HWTEST_F(WindowSessionImplTest4, SetDecorButtonStyle, Function | SmallTest | Level2)
582 {
583 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetDecorButtonStyle start";
584 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
585 option->SetWindowName("SetDecorButtonStyle");
586 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
587 ASSERT_NE(window, nullptr);
588 // check window type
589 window->property_->SetPersistentId(1);
590 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
591 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
592 window->hostSession_ = session;
593 window->state_ = WindowState::STATE_CREATED;
594
595 // check window type
596 DecorButtonStyle style;
597 window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
598 WMError res = window->SetDecorButtonStyle(style);
599 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_CALLING);
600
601 // check get value
602 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
603 style.buttonBackgroundSize = -1;
604 res = window->SetDecorButtonStyle(style);
605 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_PARAM);
606
607 // check uiContent is null
608 style.buttonBackgroundSize = 24;
609 res = window->SetDecorButtonStyle(style);
610 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
611
612 // check same style data
613 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
614 res = window->SetDecorButtonStyle(style);
615 ASSERT_EQ(res, WMError::WM_OK);
616 DecorButtonStyle styleRes;
617 res = window->GetDecorButtonStyle(styleRes);
618 ASSERT_EQ(styleRes.buttonBackgroundSize, style.buttonBackgroundSize);
619 }
620
621 /**
622 * @tc.name: GetTitleButtonArea
623 * @tc.desc: GetTitleButtonArea and check the retCode
624 * @tc.type: FUNC
625 */
626 HWTEST_F(WindowSessionImplTest4, GetTitleButtonArea, Function | SmallTest | Level2)
627 {
628 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetTitleButtonAreatest01 start";
629 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
630 option->SetWindowName("GetTitleButtonArea");
631 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
632 ASSERT_NE(window->property_, nullptr);
633 window->property_->SetPersistentId(1);
634 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
635 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
636 ASSERT_NE(nullptr, session);
637 window->hostSession_ = session;
638 TitleButtonRect titleButtonRect;
639 WMError res = window->GetTitleButtonArea(titleButtonRect);
640 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
641 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorHeighttest01 end";
642 }
643
644 /**
645 * @tc.name: GetUIContentRemoteObj
646 * @tc.desc: GetUIContentRemoteObj and check the retCode
647 * @tc.type: FUNC
648 */
649 HWTEST_F(WindowSessionImplTest4, GetUIContentRemoteObj, Function | SmallTest | Level2)
650 {
651 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetUIContentRemoteObj start";
652 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
653 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
654 sptr<IRemoteObject> remoteObj;
655 WSError res = window->GetUIContentRemoteObj(remoteObj);
656 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
657 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
658 res = window->GetUIContentRemoteObj(remoteObj);
659 ASSERT_EQ(res, WSError::WS_OK);
660 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetUIContentRemoteObj end";
661 }
662
663 /**
664 * @tc.name: RegisterExtensionAvoidAreaChangeListener
665 * @tc.desc: RegisterExtensionAvoidAreaChangeListener Test
666 * @tc.type: FUNC
667 */
668 HWTEST_F(WindowSessionImplTest4, RegisterExtensionAvoidAreaChangeListener, Function | SmallTest | Level2)
669 {
670 GTEST_LOG_(INFO) << "WindowSessionImplTest4: RegisterExtensionAvoidAreaChangeListener start";
671 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
672 option->SetWindowName("GetTitleButtonArea");
673 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
674 sptr<IAvoidAreaChangedListener> listener = nullptr;
675 WMError res = window->RegisterExtensionAvoidAreaChangeListener(listener);
676 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
677
678 listener = sptr<IAvoidAreaChangedListener>::MakeSptr();
679 vector<sptr<IAvoidAreaChangedListener>> holder;
680 window->avoidAreaChangeListeners_[window->property_->GetPersistentId()] = holder;
681 res = window->RegisterExtensionAvoidAreaChangeListener(listener);
682 ASSERT_EQ(res, WMError::WM_OK);
683 holder = window->avoidAreaChangeListeners_[window->property_->GetPersistentId()];
684 auto existsListener = std::find(holder.begin(), holder.end(), listener);
685 ASSERT_NE(existsListener, holder.end());
686
687 // already registered
688 res = window->RegisterExtensionAvoidAreaChangeListener(listener);
689 ASSERT_EQ(res, WMError::WM_OK);
690 GTEST_LOG_(INFO) << "WindowSessionImplTest4: RegisterExtensionAvoidAreaChangeListener end";
691 }
692
693 /**
694 * @tc.name: UnregisterExtensionAvoidAreaChangeListener
695 * @tc.desc: UnregisterExtensionAvoidAreaChangeListener Test
696 * @tc.type: FUNC
697 */
698 HWTEST_F(WindowSessionImplTest4, UnregisterExtensionAvoidAreaChangeListener, Function | SmallTest | Level2)
699 {
700 GTEST_LOG_(INFO) << "WindowSessionImplTest4: UnregisterExtensionAvoidAreaChangeListener start";
701 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
702 option->SetWindowName("GetTitleButtonArea");
703 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
704 sptr<IAvoidAreaChangedListener> listener = nullptr;
705 WMError res = window->UnregisterExtensionAvoidAreaChangeListener(listener);
706 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
707
708 listener = sptr<IAvoidAreaChangedListener>::MakeSptr();
709 vector<sptr<IAvoidAreaChangedListener>> holder;
710 window->avoidAreaChangeListeners_[window->property_->GetPersistentId()] = holder;
711 window->RegisterExtensionAvoidAreaChangeListener(listener);
712
713 res = window->UnregisterExtensionAvoidAreaChangeListener(listener);
714 ASSERT_EQ(res, WMError::WM_OK);
715
716 holder = window->avoidAreaChangeListeners_[window->property_->GetPersistentId()];
717 auto existsListener = std::find(holder.begin(), holder.end(), listener);
718 ASSERT_EQ(existsListener, holder.end());
719 GTEST_LOG_(INFO) << "WindowSessionImplTest4: UnregisterExtensionAvoidAreaChangeListener end";
720 }
721
722 /**
723 * @tc.name: SetPipActionEvent
724 * @tc.desc: SetPipActionEvent Test
725 * @tc.type: FUNC
726 */
727 HWTEST_F(WindowSessionImplTest4, SetPipActionEvent, Function | SmallTest | Level2)
728 {
729 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPipActionEvent start";
730 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
731 option->SetWindowName("GetTitleButtonArea");
732 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
733 ASSERT_EQ(nullptr, window->GetUIContentWithId(10000));
734 window->property_->SetPersistentId(1);
735
736 SessionInfo sessionInfo = { "CreateTestBundle", "TestGetUIContentWithId", "CreateTestAbility" };
737 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
738 ASSERT_NE(nullptr, session);
739 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
740 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
741 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
742 ASSERT_EQ(window->FindWindowById(1), nullptr);
743 ASSERT_EQ(nullptr, window->GetUIContentWithId(1));
744 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
745 }
746 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPipActionEvent end";
747 }
748
749 /**
750 * @tc.name: SetPiPControlEvent
751 * @tc.desc: SetPiPControlEvent Test
752 * @tc.type: FUNC
753 */
754 HWTEST_F(WindowSessionImplTest4, SetPiPControlEvent, Function | SmallTest | Level2)
755 {
756 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPiPControlEvent start";
757 auto option = sptr<WindowOption>::MakeSptr();
758 option->SetWindowName("GetTitleButtonArea");
759 auto window = sptr<WindowSessionImpl>::MakeSptr(option);
760 auto controlType = WsPiPControlType::VIDEO_PLAY_PAUSE;
761 auto status = WsPiPControlStatus::PLAY;
762 WSError res = window->SetPiPControlEvent(controlType, status);
763 ASSERT_EQ(res, WSError::WS_OK);
764 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPiPControlEvent end";
765 }
766
767 /**
768 * @tc.name: SetUIContentInner
769 * @tc.desc: SetUIContentInner Test
770 * @tc.type: FUNC
771 */
772 HWTEST_F(WindowSessionImplTest4, SetUIContentInner, Function | SmallTest | Level2)
773 {
774 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetUIContentInner start";
775 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
776 option->SetWindowName("SetUIContentInner");
777 option->SetIsUIExtFirstSubWindow(true);
778 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
779 window->property_->SetPersistentId(1);
780 std::string url = "";
781 EXPECT_TRUE(window->IsWindowSessionInvalid());
782 WMError res1 = window->SetUIContentInner(
783 url, nullptr, nullptr, WindowSetUIContentType::DEFAULT, BackupAndRestoreType::NONE, nullptr);
784 ASSERT_EQ(res1, WMError::WM_ERROR_INVALID_WINDOW);
785 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetUIContentInner end";
786 }
787
788 /**
789 * @tc.name: TestGetUIContentWithId
790 * @tc.desc: Get uicontent with id
791 * @tc.type: FUNC
792 */
793 HWTEST_F(WindowSessionImplTest4, TestGetUIContentWithId, Function | SmallTest | Level2)
794 {
795 GTEST_LOG_(INFO) << "WindowSessionImplTest4: TestGetUIContentWithId start";
796 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
797 option->SetWindowName("TestGetUIContentWithId");
798 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
799 ASSERT_EQ(nullptr, window->GetUIContentWithId(10000));
800 window->property_->SetPersistentId(1);
801
802 SessionInfo sessionInfo = { "CreateTestBundle", "TestGetUIContentWithId", "CreateTestAbility" };
803 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
804 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
805 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
806 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
807 ASSERT_NE(window->FindWindowById(1), nullptr);
808 ASSERT_EQ(nullptr, window->GetUIContentWithId(1));
809 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
810 }
811 GTEST_LOG_(INFO) << "WindowSessionImplTest4: TestGetUIContentWithId end";
812 }
813
814 /**
815 * @tc.name: GetCallingWindowRect
816 * @tc.desc: GetCallingWindowRect Test
817 * @tc.type: FUNC
818 */
819 HWTEST_F(WindowSessionImplTest4, GetCallingWindowRect, Function | SmallTest | Level2)
820 {
821 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
822 option->SetWindowName("GetCallingWindowRect");
823 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
824 Rect rect = { 0, 0, 0, 0 };
825 WMError retCode = window->GetCallingWindowRect(rect);
826 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
827 window->property_->SetPersistentId(1);
828 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
829 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
830 window->hostSession_ = session;
831 window->state_ = WindowState::STATE_CREATED;
832 window->GetCallingWindowRect(rect);
833 }
834
835 /**
836 * @tc.name: GetCallingWindowWindowStatus
837 * @tc.desc: GetCallingWindowWindowStatus Test
838 * @tc.type: FUNC
839 */
840 HWTEST_F(WindowSessionImplTest4, GetCallingWindowWindowStatus, Function | SmallTest | Level2)
841 {
842 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
843 option->SetWindowName("GetCallingWindowWindowStatus");
844 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
845 ASSERT_NE(nullptr, window);
846 WindowStatus windowStatus = WindowStatus::WINDOW_STATUS_UNDEFINED;
847 WMError retCode = window->GetCallingWindowWindowStatus(windowStatus);
848 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
849 window->property_->SetPersistentId(1);
850 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
851 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
852 ASSERT_NE(nullptr, session);
853 window->hostSession_ = session;
854 window->state_ = WindowState::STATE_CREATED;
855 window->GetCallingWindowWindowStatus(windowStatus);
856 }
857
858 /**
859 * @tc.name: GetParentId
860 * @tc.desc: GetParentId Test
861 * @tc.type: FUNC
862 */
863 HWTEST_F(WindowSessionImplTest4, GetParentId, Function | SmallTest | Level2)
864 {
865 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
866 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
867 const int32_t res = window->GetParentId();
868 ASSERT_EQ(res, 0);
869 ASSERT_EQ(true, window->IsSupportWideGamut());
870 }
871
872 /**
873 * @tc.name: PreNotifyKeyEvent
874 * @tc.desc: PreNotifyKeyEvent Test
875 * @tc.type: FUNC
876 */
877 HWTEST_F(WindowSessionImplTest4, PreNotifyKeyEvent, Function | SmallTest | Level2)
878 {
879 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
880 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
881 std::shared_ptr<MMI::PointerEvent> pointerEvent;
882 window->ConsumePointerEvent(pointerEvent);
883
884 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
885 window->ConsumeKeyEvent(keyEvent);
886 ASSERT_EQ(nullptr, window->GetUIContentSharedPtr());
887 ASSERT_EQ(false, window->PreNotifyKeyEvent(keyEvent));
888 ASSERT_EQ(false, window->NotifyOnKeyPreImeEvent(keyEvent));
889 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
890 ASSERT_NE(nullptr, window->GetUIContentSharedPtr());
891 ASSERT_EQ(false, window->PreNotifyKeyEvent(keyEvent));
892 ASSERT_EQ(false, window->NotifyOnKeyPreImeEvent(keyEvent));
893 }
894
895 /**
896 * @tc.name: CheckIfNeedCommitRsTransaction
897 * @tc.desc: CheckIfNeedCommitRsTransaction
898 * @tc.type: FUNC
899 */
900 HWTEST_F(WindowSessionImplTest4, CheckIfNeedCommitRsTransaction, Function | SmallTest | Level2)
901 {
902 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
903 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
904
905 bool res = false;
906 WindowSizeChangeReason wmReason = WindowSizeChangeReason::UNDEFINED;
907 for (uint32_t i = static_cast<uint32_t>(WindowSizeChangeReason::UNDEFINED);
908 i < static_cast<uint32_t>(WindowSizeChangeReason::END);
909 i++) {
910 wmReason = static_cast<WindowSizeChangeReason>(i);
911 res = window->CheckIfNeedCommitRsTransaction(wmReason);
912 if (wmReason == WindowSizeChangeReason::FULL_TO_SPLIT || wmReason == WindowSizeChangeReason::FULL_TO_FLOATING ||
913 wmReason == WindowSizeChangeReason::RECOVER || wmReason == WindowSizeChangeReason::MAXIMIZE) {
914 ASSERT_EQ(res, false);
915 } else {
916 ASSERT_EQ(res, true);
917 }
918 }
919 window->Destroy();
920 }
921
922 /**
923 * @tc.name: UpdateRectForRotation
924 * @tc.desc: UpdateRectForRotation Test
925 * @tc.type: FUNC
926 */
927 HWTEST_F(WindowSessionImplTest4, UpdateRectForRotation, Function | SmallTest | Level2)
928 {
929 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
930 option->SetWindowName("WindowSessionCreateCheck");
931 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
932
933 Rect wmRect;
934 wmRect.posX_ = 0;
935 wmRect.posY_ = 0;
936 wmRect.height_ = 50;
937 wmRect.width_ = 50;
938
939 WSRect rect;
940 wmRect.posX_ = 0;
941 wmRect.posY_ = 0;
942 wmRect.height_ = 50;
943 wmRect.width_ = 50;
944
945 Rect preRect;
946 preRect.posX_ = 0;
947 preRect.posY_ = 0;
948 preRect.height_ = 200;
949 preRect.width_ = 200;
950
951 window->property_->SetWindowRect(preRect);
952 WindowSizeChangeReason wmReason = WindowSizeChangeReason{ 0 };
953 std::shared_ptr<RSTransaction> rsTransaction;
954 SceneAnimationConfig config{ .rsTransaction_ = rsTransaction };
955 window->UpdateRectForRotation(wmRect, preRect, wmReason, config);
956
957 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
958 auto res = window->UpdateRect(rect, reason);
959 ASSERT_EQ(res, WSError::WS_OK);
960 }
961
962 /**
963 * @tc.name: NotifyRotationAnimationEnd
964 * @tc.desc: NotifyRotationAnimationEnd Test
965 * @tc.type: FUNC
966 */
967 HWTEST_F(WindowSessionImplTest4, NotifyRotationAnimationEnd, Function | SmallTest | Level2)
968 {
969 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
970 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
971 window->NotifyRotationAnimationEnd();
972
973 OHOS::Ace::UIContentErrorCode aceRet = OHOS::Ace::UIContentErrorCode::NO_ERRORS;
974 window->InitUIContent(
975 "", nullptr, nullptr, WindowSetUIContentType::BY_ABC, BackupAndRestoreType::NONE, nullptr, aceRet);
976 window->NotifyRotationAnimationEnd();
977 ASSERT_NE(nullptr, window->uiContent_);
978 }
979
980 /**
981 * @tc.name: SetTitleButtonVisible
982 * @tc.desc: SetTitleButtonVisible and GetTitleButtonVisible
983 * @tc.type: FUNC
984 */
985 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible, Function | SmallTest | Level2)
986 {
987 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
988 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
989 bool isMaximizeVisible = true;
990 bool isMinimizeVisible = true;
991 bool isSplitVisible = true;
992 bool isCloseVisible = true;
993 auto res = window->SetTitleButtonVisible(isMaximizeVisible, isMinimizeVisible, isSplitVisible, isCloseVisible);
994
995 bool& hideMaximizeButton = isMaximizeVisible;
996 bool& hideMinimizeButton = isMinimizeVisible;
997 bool& hideSplitButton = isSplitVisible;
998 bool& hideCloseButton = isCloseVisible;
999 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1000 window->GetTitleButtonVisible(hideMaximizeButton, hideMinimizeButton, hideSplitButton, hideCloseButton);
1001 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1002 }
1003
1004 /**
1005 * @tc.name: IsFocused
1006 * @tc.desc: IsFocused
1007 * @tc.type: FUNC
1008 */
1009 HWTEST_F(WindowSessionImplTest4, IsFocused, Function | SmallTest | Level2)
1010 {
1011 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1012 option->SetWindowName("WindowSessionCreateCheck");
1013 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1014 bool res = window->IsFocused();
1015 ASSERT_EQ(res, false);
1016
1017 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->RequestFocus());
1018
1019 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1020 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1021 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1022 int32_t persistentId = window->GetPersistentId();
1023 if (persistentId == INVALID_SESSION_ID) {
1024 persistentId = 1;
1025 window->property_->SetPersistentId(persistentId);
1026 }
1027 if (window->state_ == WindowState::STATE_DESTROYED) {
1028 window->state_ = WindowState::STATE_SHOWN;
1029 }
1030 window->hostSession_ = session;
1031 window->RequestFocus();
1032 ASSERT_FALSE(window->IsWindowSessionInvalid());
1033 ASSERT_EQ(persistentId, window->GetPersistentId());
1034 ASSERT_EQ(WMError::WM_OK, window->Destroy());
1035 }
1036
1037 /**
1038 * @tc.name: NapiSetUIContent
1039 * @tc.desc: NapiSetUIContent Test
1040 * @tc.type: FUNC
1041 */
1042 HWTEST_F(WindowSessionImplTest4, NapiSetUIContent, Function | SmallTest | Level2)
1043 {
1044 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1045 option->SetWindowName("NapiSetUIContent");
1046 option->SetIsUIExtFirstSubWindow(true);
1047 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1048 window->property_->SetPersistentId(1);
1049 std::string url = "";
1050 AppExecFwk::Ability* ability = nullptr;
1051
1052 window->SetUIContentByName(url, nullptr, nullptr, nullptr);
1053 window->SetUIContentByAbc(url, nullptr, nullptr, nullptr);
1054 WMError res1 =
1055 window->NapiSetUIContent(url, nullptr, nullptr, BackupAndRestoreType::CONTINUATION, nullptr, ability);
1056 ASSERT_EQ(res1, WMError::WM_ERROR_INVALID_WINDOW);
1057 }
1058
1059 /**
1060 * @tc.name: GetAbcContent
1061 * @tc.desc: GetAbcContent Test
1062 * @tc.type: FUNC
1063 */
1064 HWTEST_F(WindowSessionImplTest4, GetAbcContent, Function | SmallTest | Level2)
1065 {
1066 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1067 option->SetWindowName("GetAbcContent");
1068 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1069 std::string abcPath = "";
1070 std::shared_ptr<std::vector<uint8_t>> res = window->GetAbcContent(abcPath);
1071 std::filesystem::path abcFile{ abcPath };
1072 ASSERT_TRUE(abcFile.empty());
1073 ASSERT_TRUE(!abcFile.is_absolute());
1074 ASSERT_TRUE(!std::filesystem::exists(abcFile));
1075 ASSERT_EQ(res, nullptr);
1076
1077 abcPath = "/abc";
1078 res = window->GetAbcContent(abcPath);
1079 std::filesystem::path abcFile2{ abcPath };
1080 ASSERT_FALSE(abcFile2.empty());
1081 ASSERT_FALSE(!abcFile2.is_absolute());
1082 ASSERT_TRUE(!std::filesystem::exists(abcFile2));
1083 ASSERT_EQ(res, nullptr);
1084
1085 abcPath = "abc";
1086 res = window->GetAbcContent(abcPath);
1087 std::filesystem::path abcFile3{ abcPath };
1088 ASSERT_FALSE(abcFile3.empty());
1089 ASSERT_TRUE(!abcFile3.is_absolute());
1090 ASSERT_TRUE(!std::filesystem::exists(abcFile3));
1091 ASSERT_EQ(res, nullptr);
1092
1093 abcPath = "/log";
1094 res = window->GetAbcContent(abcPath);
1095 std::filesystem::path abcFile4{ abcPath };
1096 ASSERT_FALSE(abcFile4.empty());
1097 ASSERT_FALSE(!abcFile4.is_absolute());
1098 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
1099 ASSERT_FALSE(!std::filesystem::exists(abcFile4));
1100 ASSERT_NE(res, nullptr);
1101 std::fstream file(abcFile, std::ios::in | std::ios::binary);
1102 ASSERT_FALSE(file);
1103 }
1104 window->Destroy();
1105 }
1106
1107 /**
1108 * @tc.name: SetLandscapeMultiWindow
1109 * @tc.desc: SetLandscapeMultiWindow and check the retCode
1110 * @tc.type: FUNC
1111 */
1112 HWTEST_F(WindowSessionImplTest4, SetLandscapeMultiWindow, Function | SmallTest | Level2)
1113 {
1114 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1115 option->SetWindowName("SetLandscapeMultiWindow");
1116 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1117 WMError retCode = window->SetLandscapeMultiWindow(false);
1118 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
1119 window->property_->SetPersistentId(1);
1120 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1121 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1122 window->hostSession_ = session;
1123 window->state_ = WindowState::STATE_CREATED;
1124 retCode = window->SetLandscapeMultiWindow(false);
1125 ASSERT_EQ(retCode, WMError::WM_OK);
1126 }
1127
1128 /**
1129 * @tc.name: GetTouchable
1130 * @tc.desc: GetTouchable
1131 * @tc.type: FUNC
1132 */
1133 HWTEST_F(WindowSessionImplTest4, GetTouchable, Function | SmallTest | Level2)
1134 {
1135 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1136 option->SetWindowName("GetTouchable");
1137 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1138 window->GetTouchable();
1139 window->GetBrightness();
1140 ASSERT_NE(window, nullptr);
1141 }
1142
1143 /**
1144 * @tc.name: Notify03
1145 * @tc.desc: NotifyCloseExistPipWindow NotifyAfterResumed NotifyAfterPaused
1146 * @tc.type: FUNC
1147 */
1148 HWTEST_F(WindowSessionImplTest4, Notify03, Function | SmallTest | Level2)
1149 {
1150 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1151 option->SetWindowName("Notify03");
1152 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1153
1154 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1155 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1156 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1157
1158 window->NotifyAfterResumed();
1159 window->NotifyAfterPaused();
1160 WSError res = window->NotifyCloseExistPipWindow();
1161 ASSERT_EQ(res, WSError::WS_OK);
1162 AAFwk::WantParams wantParams;
1163 WSError ret = window->NotifyTransferComponentData(wantParams);
1164 ASSERT_EQ(ret, WSError::WS_OK);
1165 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1166 }
1167
1168 /**
1169 * @tc.name: Filter
1170 * @tc.desc: Filter
1171 * @tc.type: FUNC
1172 */
1173 HWTEST_F(WindowSessionImplTest4, Filter, Function | SmallTest | Level2)
1174 {
1175 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1176 option->SetWindowName("Filter");
1177 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1178 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
1179 window->FilterKeyEvent(keyEvent);
1180 ASSERT_EQ(window->keyEventFilter_, nullptr);
__anondd219bd80202(const MMI::KeyEvent& keyEvent) 1181 window->SetKeyEventFilter([](const MMI::KeyEvent& keyEvent) {
1182 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetKeyEventFilter";
1183 return true;
1184 });
1185 ASSERT_NE(window->keyEventFilter_, nullptr);
1186 window->FilterKeyEvent(keyEvent);
1187 auto ret = window->ClearKeyEventFilter();
1188 ASSERT_EQ(ret, WMError::WM_OK);
1189 }
1190
1191 /**
1192 * @tc.name: UpdateOrientation
1193 * @tc.desc: UpdateOrientation
1194 * @tc.type: FUNC
1195 */
1196 HWTEST_F(WindowSessionImplTest4, UpdateOrientation, Function | SmallTest | Level2)
1197 {
1198 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1199 option->SetWindowName("UpdateOrientation");
1200 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1201 auto ret = window->UpdateOrientation();
1202 ASSERT_EQ(WSError::WS_OK, ret);
1203 }
1204
1205 /**
1206 * @tc.name: SetTitleButtonVisible01
1207 * @tc.desc: SetTitleButtonVisible
1208 * @tc.type: FUNC
1209 */
1210 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible01, Function | SmallTest | Level2)
1211 {
1212 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible01 start";
1213 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1214 option->SetWindowName("SetTitleButtonVisible");
1215 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1216 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1217 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1218 window->hostSession_ = session;
1219 ASSERT_NE(window->property_, nullptr);
1220 window->property_->SetPersistentId(1);
1221 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1222 WMError res = window->SetTitleButtonVisible(false, false, false, true);
1223 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_CALLING);
1224 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible01 end";
1225 }
1226
1227 /**
1228 * @tc.name: SetTitleButtonVisible02
1229 * @tc.desc: SetTitleButtonVisible
1230 * @tc.type: FUNC
1231 */
1232 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible02, Function | SmallTest | Level2)
1233 {
1234 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible02 start";
1235 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1236 option->SetWindowName("SetTitleButtonVisible");
1237 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1238 ASSERT_NE(window->property_, nullptr);
1239 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1240 WMError res = window->SetTitleButtonVisible(false, false, false, true);
1241 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1242 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible02 end";
1243 }
1244
1245 /**
1246 * @tc.name: SetTitleButtonVisible03
1247 * @tc.desc: SetTitleButtonVisible
1248 * @tc.type: FUNC
1249 */
1250 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible03, Function | SmallTest | Level2)
1251 {
1252 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible03 start";
1253 sptr option = sptr<WindowOption>::MakeSptr();
1254 option->SetWindowName("SetTitleButtonVisible");
1255 sptr window = sptr<WindowSessionImpl>::MakeSptr(option);
1256 ASSERT_NE(window->property_, nullptr);
1257 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1258 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1259 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1260 window->windowSystemConfig_.freeMultiWindowSupport_ = true;
1261 window->windowSystemConfig_.isSystemDecorEnable_ = true;
1262 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1263 WMError res = window->SetTitleButtonVisible(false, false, false, true);
1264 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1265 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1266 res = window->SetTitleButtonVisible(false, false, false, true);
1267 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1268 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible03 end";
1269 }
1270
1271 /**
1272 * @tc.name: GetTitleButtonVisible01
1273 * @tc.desc: GetTitleButtonVisible
1274 * @tc.type: FUNC
1275 */
1276 HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible01, Function | SmallTest | Level2)
1277 {
1278 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1279 option->SetWindowName("GetTitleButtonVisible01");
1280 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1281 ASSERT_NE(window->property_, nullptr);
1282 uint32_t windowModeSupportType = 1 | (1 << 1) | (1 << 2);
1283 window->property_->SetWindowModeSupportType(windowModeSupportType);
1284 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1285 // show Maximize, Minimize, Split buttons.
1286 window->windowTitleVisibleFlags_ = { false, false, false, false };
1287 bool hideMaximizeButton = false;
1288 bool hideMinimizeButton = false;
1289 bool hideSplitButton = false;
1290 bool hideCloseButton = false;
1291 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1292 window->GetTitleButtonVisible(hideMaximizeButton, hideMinimizeButton, hideSplitButton, hideCloseButton);
1293 ASSERT_EQ(hideMaximizeButton, true);
1294 ASSERT_EQ(hideMinimizeButton, true);
1295 ASSERT_EQ(hideSplitButton, true);
1296 ASSERT_EQ(hideCloseButton, true);
1297 }
1298
1299 /**
1300 * @tc.name: UpdateRect03
1301 * @tc.desc: UpdateRect
1302 * @tc.type: FUNC
1303 */
1304 HWTEST_F(WindowSessionImplTest4, UpdateRect03, Function | SmallTest | Level2)
1305 {
1306 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1307 option->SetWindowName("WindowSessionCreateCheck");
1308 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1309
1310 WSRect rect;
1311 rect.posX_ = 0;
1312 rect.posY_ = 0;
1313 rect.height_ = 0;
1314 rect.width_ = 0;
1315
1316 Rect rectW; // GetRect().IsUninitializedRect is true
1317 rectW.posX_ = 0;
1318 rectW.posY_ = 0;
1319 rectW.height_ = 0; // rectW - rect > 50
1320 rectW.width_ = 0; // rectW - rect > 50
1321
1322 window->property_->SetWindowRect(rectW);
1323 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1324 WSError res = window->UpdateRect(rect, reason);
1325 ASSERT_EQ(res, WSError::WS_OK);
1326
1327 rect.height_ = 50;
1328 rect.width_ = 50;
1329 rectW.height_ = 50;
1330 rectW.width_ = 50;
1331 window->property_->SetWindowRect(rectW);
1332 res = window->UpdateRect(rect, reason);
1333 ASSERT_EQ(res, WSError::WS_OK);
1334 }
1335
1336 /**
1337 * @tc.name: GetTitleButtonVisible02
1338 * @tc.desc: GetTitleButtonVisible
1339 * @tc.type: FUNC
1340 */
1341 HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible02, Function | SmallTest | Level2)
1342 {
1343 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1344 option->SetWindowName("GetTitleButtonVisible02");
1345 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1346 ASSERT_NE(window->property_, nullptr);
1347 // only not support WINDOW_MODE_SUPPORT_SPLIT
1348 uint32_t windowModeSupportType = 1 | (1 << 1);
1349 window->property_->SetWindowModeSupportType(windowModeSupportType);
1350 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1351 // show Maximize, Minimize, Split buttons.
1352 window->windowTitleVisibleFlags_ = { true, true, true, true };
1353 bool hideMaximizeButton = false;
1354 bool hideMinimizeButton = false;
1355 bool hideSplitButton = false;
1356 bool hideCloseButton = false;
1357 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1358 window->GetTitleButtonVisible(hideMaximizeButton, hideMinimizeButton, hideSplitButton, hideCloseButton);
1359 ASSERT_EQ(hideMaximizeButton, false);
1360 ASSERT_EQ(hideMinimizeButton, false);
1361 ASSERT_EQ(hideSplitButton, false);
1362 ASSERT_EQ(hideCloseButton, false);
1363 }
1364
1365 /**
1366 * @tc.name: GetTitleButtonVisible03
1367 * @tc.desc: GetTitleButtonVisible
1368 * @tc.type: FUNC
1369 */
1370 HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible03, Function | SmallTest | Level2)
1371 {
1372 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1373 option->SetWindowName("GetTitleButtonVisible03");
1374 option->SetDisplayId(1);
1375 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1376 ASSERT_NE(window->property_, nullptr);
1377 ASSERT_EQ(1, window->GetDisplayId());
1378 // only not support WINDOW_MODE_SUPPORT_SPLIT
1379 uint32_t windowModeSupportType = 1 | (1 << 1) | (1 << 2);
1380 window->property_->SetWindowModeSupportType(windowModeSupportType);
1381 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1382 // show Maximize, Minimize, Split buttons.
1383 window->windowTitleVisibleFlags_ = { false, false, false, false };
1384 bool hideMaximizeButton = true;
1385 bool hideMinimizeButton = true;
1386 bool hideSplitButton = true;
1387 bool hideCloseButton = true;
1388 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1389 window->GetTitleButtonVisible(hideMaximizeButton, hideMinimizeButton, hideSplitButton, hideCloseButton);
1390 ASSERT_EQ(hideMaximizeButton, true);
1391 ASSERT_EQ(hideMinimizeButton, true);
1392 ASSERT_EQ(hideSplitButton, true);
1393 ASSERT_EQ(hideCloseButton, true);
1394 }
1395
1396 /**
1397 * @tc.name: GetAppForceLandscapeConfig01
1398 * @tc.desc: GetAppForceLandscapeConfig
1399 * @tc.type: FUNC
1400 */
1401 HWTEST_F(WindowSessionImplTest4, GetAppForceLandscapeConfig01, Function | SmallTest | Level2)
1402 {
1403 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1404 option->SetWindowName("GetAppForceLandscapeConfig01");
1405 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1406 ASSERT_NE(window->property_, nullptr);
1407 window->property_->SetPersistentId(1);
1408 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1409 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1410 window->hostSession_ = session;
1411 AppForceLandscapeConfig config = {};
1412 window->GetAppForceLandscapeConfig(config);
1413 window->hostSession_ = nullptr;
1414 WMError res = window->GetAppForceLandscapeConfig(config);
1415 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1416 }
1417
1418 /**
1419 * @tc.name: UpdatePiPControlStatus01
1420 * @tc.desc: UpdatePiPControlStatus
1421 * @tc.type: FUNC
1422 */
1423 HWTEST_F(WindowSessionImplTest4, UpdatePiPControlStatus01, Function | SmallTest | Level2)
1424 {
1425 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1426 option->SetWindowName("UpdatePiPControlStatus01");
1427 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1428 ASSERT_NE(window->property_, nullptr);
1429 window->property_->SetPersistentId(1);
1430 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1431 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1432 window->hostSession_ = session;
1433 auto controlType = PiPControlType::VIDEO_PLAY_PAUSE;
1434 auto status = PiPControlStatus::ENABLED;
1435 window->UpdatePiPControlStatus(controlType, status);
1436 window->hostSession_ = nullptr;
1437 window->UpdatePiPControlStatus(controlType, status);
1438 }
1439
1440 /**
1441 * @tc.name: SetAutoStartPiP
1442 * @tc.desc: SetAutoStartPiP
1443 * @tc.type: FUNC
1444 */
1445 HWTEST_F(WindowSessionImplTest4, SetAutoStartPiP, Function | SmallTest | Level2)
1446 {
1447 auto option = sptr<WindowOption>::MakeSptr();
1448 ASSERT_NE(option, nullptr);
1449 option->SetWindowName("SetAutoStartPiP");
1450 auto window = sptr<WindowSessionImpl>::MakeSptr(option);
1451 ASSERT_NE(window, nullptr);
1452 window->property_->SetPersistentId(1);
1453 SessionInfo sessionInfo = { "SetAutoStartPiP", "SetAutoStartPiP", "SetAutoStartPiP" };
1454 auto session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1455 ASSERT_NE(nullptr, session);
1456 window->hostSession_ = session;
1457 bool isAutoStart = true;
1458 uint32_t priority = 1;
1459 uint32_t width = 1;
1460 uint32_t height = 1;
1461 window->SetAutoStartPiP(isAutoStart, priority, width, height);
1462 window->hostSession_ = nullptr;
1463 window->SetAutoStartPiP(isAutoStart, priority, width, height);
1464 }
1465
1466 /**
1467 * @tc.name: NotifyWindowVisibility01
1468 * @tc.desc: NotifyWindowVisibility
1469 * @tc.type: FUNC
1470 */
1471 HWTEST_F(WindowSessionImplTest4, NotifyWindowVisibility01, Function | SmallTest | Level2)
1472 {
1473 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1474 option->SetWindowName("NotifyWindowVisibility01");
1475 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1476 ASSERT_NE(window->property_, nullptr);
1477 window->property_->SetPersistentId(1);
1478 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1479 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1480 window->hostSession_ = session;
1481 window->NotifyWindowVisibility(false);
1482 sptr<IWindowVisibilityChangedListener> listener = sptr<IWindowVisibilityChangedListener>::MakeSptr();
1483 window->RegisterWindowVisibilityChangeListener(listener);
1484 window->NotifyWindowVisibility(false);
1485 window->UnregisterWindowVisibilityChangeListener(listener);
1486 }
1487
1488 /**
1489 * @tc.name: UpdateVirtualPixelRatio
1490 * @tc.desc: test UpdateVirtualPixelRatio
1491 * @tc.type: FUNC
1492 */
1493 HWTEST_F(WindowSessionImplTest4, UpdateVirtualPixelRatio, Function | SmallTest | Level2)
1494 {
1495 GTEST_LOG_(INFO) << "WindowSessionImplTest4: UpdateVirtualPixelRatio start";
1496 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1497 option->SetWindowName("UpdateVirtualPixelRatio");
1498 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1499 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1500 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1501
1502 window->property_->SetDisplayId(-1);
1503 sptr<Display> display = nullptr;
1504 window->UpdateVirtualPixelRatio(display);
1505 ASSERT_EQ(window->virtualPixelRatio_, 1.0f);
1506
1507 window->property_->SetDisplayId(0);
1508 display = SingletonContainer::Get<DisplayManager>().GetDisplayById(window->property_->GetDisplayId());
1509 window->UpdateVirtualPixelRatio(display);
1510 ASSERT_NE(window->virtualPixelRatio_, 1.0f);
1511 GTEST_LOG_(INFO) << "WindowSessionImplTest4: UpdateVirtualPixelRatio end";
1512 }
1513
1514 /**
1515 * @tc.name: NotifyMainWindowClose01
1516 * @tc.desc: NotifyMainWindowClose
1517 * @tc.type: FUNC
1518 */
1519 HWTEST_F(WindowSessionImplTest4, NotifyMainWindowClose01, Function | SmallTest | Level2)
1520 {
1521 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1522 option->SetWindowName("NotifyMainWindowClose01");
1523 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1524 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1525 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1526 window->hostSession_ = session;
1527 window->property_->SetPersistentId(1);
1528
1529 bool terminateCloseProcess = false;
1530 WMError res = window->NotifyMainWindowClose(terminateCloseProcess);
1531 EXPECT_EQ(terminateCloseProcess, false);
1532 EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
1533 sptr<IMainWindowCloseListener> listener = sptr<IMainWindowCloseListener>::MakeSptr();
1534 window->RegisterMainWindowCloseListeners(listener);
1535 res = window->NotifyMainWindowClose(terminateCloseProcess);
1536 EXPECT_EQ(terminateCloseProcess, false);
1537 EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
1538 window->UnregisterMainWindowCloseListeners(listener);
1539 }
1540
1541 /**
1542 * @tc.name: NotifyWindowWillClose
1543 * @tc.desc: NotifyWindowWillClose
1544 * @tc.type: FUNC
1545 */
1546 HWTEST_F(WindowSessionImplTest4, NotifyWindowWillClose, Function | SmallTest | Level2)
1547 {
1548 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1549 option->SetWindowName("NotifyWindowWillClose");
1550 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1551 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1552 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1553 window->hostSession_ = session;
1554 window->property_->SetPersistentId(1);
1555 WMError res = window->NotifyWindowWillClose(window);
1556 EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
1557
1558 sptr<IWindowWillCloseListener> listener = sptr<MockIWindowWillCloseListener>::MakeSptr();
1559 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1560 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1561 res = window->RegisterWindowWillCloseListeners(listener);
1562 EXPECT_EQ(res, WMError::WM_OK);
1563 res = window->NotifyWindowWillClose(window);
1564 EXPECT_EQ(res, WMError::WM_OK);
1565 res = window->UnRegisterWindowWillCloseListeners(listener);
1566 EXPECT_EQ(res, WMError::WM_OK);
1567 res = window->NotifyWindowWillClose(window);
1568 EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
1569 }
1570
1571 /**
1572 * @tc.name: SetWindowContainerColor01
1573 * @tc.desc: SetWindowContainerColor
1574 * @tc.type: FUNC
1575 */
1576 HWTEST_F(WindowSessionImplTest4, SetWindowContainerColor01, Function | SmallTest | Level2)
1577 {
1578 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor01 start";
1579 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1580 option->SetWindowName("SetWindowContainerColor");
1581 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1582 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1583 std::string activeColor = "#00000000";
1584 std::string inactiveColor = "#00000000";
1585 WMError res = window->SetWindowContainerColor(activeColor, inactiveColor);
1586 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_CALLING);
1587 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor01 end";
1588 }
1589
1590 /**
1591 * @tc.name: SetWindowContainerColor02
1592 * @tc.desc: SetWindowContainerColor
1593 * @tc.type: FUNC
1594 */
1595 HWTEST_F(WindowSessionImplTest4, SetWindowContainerColor02, Function | SmallTest | Level2)
1596 {
1597 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor02 start";
1598 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1599 option->SetWindowName("SetWindowContainerColor");
1600 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1601 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1602 std::string activeColor = "#00000000";
1603 std::string inactiveColor = "#00000000";
1604 WMError res = window->SetWindowContainerColor(activeColor, inactiveColor);
1605 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1606 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor02 end";
1607 }
1608
1609 /**
1610 * @tc.name: SetWindowContainerColor03
1611 * @tc.desc: SetWindowContainerColor
1612 * @tc.type: FUNC
1613 */
1614 HWTEST_F(WindowSessionImplTest4, SetWindowContainerColor03, Function | SmallTest | Level2)
1615 {
1616 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor03 start";
1617 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1618 option->SetWindowName("SetWindowContainerColor");
1619 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1620 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1621 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1622 window->windowSystemConfig_.freeMultiWindowSupport_ = true;
1623 window->windowSystemConfig_.isSystemDecorEnable_ = true;
1624 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1625 std::string activeColor = "#00000000";
1626 std::string inactiveColor = "#00000000";
1627 WMError res = window->SetWindowContainerColor(activeColor, inactiveColor);
1628 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1629 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor03 end";
1630 }
1631
1632 /**
1633 * @tc.name: SetWindowContainerColor04
1634 * @tc.desc: SetWindowContainerColor
1635 * @tc.type: FUNC
1636 */
1637 HWTEST_F(WindowSessionImplTest4, SetWindowContainerColor04, Function | SmallTest | Level2)
1638 {
1639 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor04 start";
1640 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1641 option->SetWindowName("SetWindowContainerColor");
1642 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1643 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1644 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1645 window->windowSystemConfig_.freeMultiWindowSupport_ = true;
1646 window->windowSystemConfig_.isSystemDecorEnable_ = true;
1647 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1648 std::string activeColor = "color";
1649 std::string inactiveColor = "123";
1650 WMError res = window->SetWindowContainerColor(activeColor, inactiveColor);
1651 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1652 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetWindowContainerColor04 end";
1653 }
1654
1655 /**
1656 * @tc.name: IsPcOrPadCapabilityEnabled
1657 * @tc.desc: IsPcOrPadCapabilityEnabled test
1658 * @tc.type: FUNC
1659 */
1660 HWTEST_F(WindowSessionImplTest4, IsPcOrPadCapabilityEnabled, Function | SmallTest | Level2)
1661 {
1662 GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadCapabilityEnabled start";
1663 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1664 option->SetWindowName("IsPcOrPadCapabilityEnabled");
1665 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1666 ASSERT_NE(window->property_, nullptr);
1667 window->property_->SetPersistentId(1);
1668 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1669 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1670 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1671 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1672 ASSERT_NE(nullptr, session);
1673 window->hostSession_ = session;
1674
1675 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1676 EXPECT_EQ(true, window->IsPcOrPadCapabilityEnabled());
1677 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1678 EXPECT_EQ(false, window->IsPcOrPadCapabilityEnabled());
1679 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
1680 EXPECT_EQ(false, window->IsPcOrPadCapabilityEnabled());
1681 window->property_->SetIsPcAppInPad(true);
1682 EXPECT_EQ(true, window->IsPcOrPadCapabilityEnabled());
1683 EXPECT_EQ(WMError::WM_OK, window->Destroy(true));
1684 GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadCapabilityEnabled end";
1685 }
1686
1687 /**
1688 * @tc.name: DestroySubWindow
1689 * @tc.desc: DestroySubWindow test
1690 * @tc.type: FUNC
1691 */
1692 HWTEST_F(WindowSessionImplTest4, DestroySubWindow, Function | SmallTest | Level2)
1693 {
1694 GTEST_LOG_(INFO) << "WindowSessionImplTest4: DestroySubWindow start";
1695 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1696 option->SetWindowName("DestroySubWindow");
1697 option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1698 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1699 ASSERT_NE(window->property_, nullptr);
1700 window->property_->SetPersistentId(1);
1701 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1702 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1703 window->hostSession_ = session;
1704 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1705
1706 sptr<WindowOption> subOption = sptr<WindowOption>::MakeSptr();
1707 subOption->SetWindowName("DestroySubWindow01");
1708 subOption->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1709 sptr<WindowSessionImpl> subWindow = sptr<WindowSessionImpl>::MakeSptr(subOption);
1710 ASSERT_NE(subWindow->property_, nullptr);
1711 subWindow->property_->SetPersistentId(2);
1712 SessionInfo subSessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1713 sptr<SessionMocker> subSession = sptr<SessionMocker>::MakeSptr(subSessionInfo);
1714 subWindow->hostSession_ = subSession;
1715 subWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1716 std::vector<sptr<WindowSessionImpl>> vec;
1717 WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t, std::vector<sptr<WindowSessionImpl>>>(1, vec));
1718 WindowSessionImpl::subWindowSessionMap_[1].push_back(subWindow);
1719 window->DestroySubWindow();
1720 EXPECT_EQ(WMError::WM_OK, window->Destroy(true));
1721 }
1722
1723 /**
1724 * @tc.name: UpdateSubWindowStateAndNotify01
1725 * @tc.desc: UpdateSubWindowStateAndNotify
1726 * @tc.type: FUNC
1727 */
1728 HWTEST_F(WindowSessionImplTest4, UpdateSubWindowStateAndNotify01, Function | SmallTest | Level2)
1729 {
1730 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1731 option->SetWindowName("UpdateSubWindowStateAndNotify01");
1732 option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1733 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1734 ASSERT_NE(window->property_, nullptr);
1735 window->property_->SetPersistentId(1);
1736 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1737 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1738 window->hostSession_ = session;
1739 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1740
1741 sptr<WindowOption> subOption = sptr<WindowOption>::MakeSptr();
1742 subOption->SetWindowName("UpdateSubWindowStateAndNotify011");
1743 subOption->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1744 sptr<WindowSessionImpl> subWindow = sptr<WindowSessionImpl>::MakeSptr(subOption);
1745 ASSERT_NE(subWindow->property_, nullptr);
1746 subWindow->property_->SetPersistentId(2);
1747 SessionInfo subSessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1748 sptr<SessionMocker> subSession = sptr<SessionMocker>::MakeSptr(subSessionInfo);
1749 ASSERT_NE(nullptr, subSession);
1750 subWindow->hostSession_ = subSession;
1751 subWindow->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1752 std::vector<sptr<WindowSessionImpl>> vec;
1753 WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t, std::vector<sptr<WindowSessionImpl>>>(1, vec));
1754 subWindow->UpdateSubWindowStateAndNotify(1, WindowState::STATE_HIDDEN);
1755 WindowSessionImpl::subWindowSessionMap_[1].push_back(subWindow);
1756 subWindow->state_ = WindowState::STATE_SHOWN;
1757 window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_HIDDEN);
1758 window->state_ = WindowState::STATE_HIDDEN;
1759 window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_HIDDEN);
1760 window->state_ = WindowState::STATE_SHOWN;
1761 window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_SHOWN);
1762 window->state_ = WindowState::STATE_SHOWN;
1763 window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_SHOWN);
1764 EXPECT_EQ(WMError::WM_OK, subWindow->Destroy(true));
1765 EXPECT_EQ(WMError::WM_OK, window->Destroy(true));
1766 }
1767
1768 /**
1769 * @tc.name: NotifyRotationAnimationEnd
1770 * @tc.desc: test NotifyRotationAnimationEnd
1771 * @tc.type: FUNC
1772 */
1773 HWTEST_F(WindowSessionImplTest4, NotifyRotationAnimationEnd001, Function | SmallTest | Level2)
1774 {
1775 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1776 option->SetWindowName("NotifyRotationAnimationEnd001");
1777 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1778
1779 ASSERT_NE(window->handler_, nullptr);
1780 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1781 ASSERT_NE(window->uiContent_, nullptr);
1782 window->NotifyRotationAnimationEnd();
1783
1784 window->uiContent_ = nullptr;
1785 ASSERT_EQ(window->uiContent_, nullptr);
1786 window->NotifyRotationAnimationEnd();
1787
1788 window->handler_ = nullptr;
1789 ASSERT_EQ(window->handler_, nullptr);
1790 window->NotifyRotationAnimationEnd();
1791 }
1792
1793 /**
1794 * @tc.name: SetEnableDragBySystem
1795 * @tc.desc: test SetEnableDragBySystem
1796 * @tc.type: FUNC
1797 */
1798 HWTEST_F(WindowSessionImplTest4, SetEnableDragBySystem, Function | SmallTest | Level2)
1799 {
1800 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetSubWindow start";
1801 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1802 option->SetWindowName("GetSubWindow");
1803 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1804 window->property_->SetDragEnabled(true);
1805 window->SetEnableDragBySystem(false);
1806 ASSERT_FALSE(window->property_->GetDragEnabled());
1807 }
1808
1809 /**
1810 * @tc.name: GetSubWindow
1811 * @tc.desc: test GetSubWindow
1812 * @tc.type: FUNC
1813 */
1814 HWTEST_F(WindowSessionImplTest4, GetSubWindow, Function | SmallTest | Level2)
1815 {
1816 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetSubWindow start";
1817 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1818 option->SetWindowName("GetSubWindow");
1819 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1820 ASSERT_NE(nullptr, window);
1821 ASSERT_NE(nullptr, window->property_);
1822 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1823 window->property_->SetParentId(101); // this subWindow's parentId is 101
1824 std::vector<sptr<Window>> subWindows = window->GetSubWindow(101); // 101 is parentId
1825 ASSERT_EQ(0, subWindows.size());
1826 WindowSessionImpl::subWindowSessionMap_.insert(
1827 std::pair<int32_t, std::vector<sptr<WindowSessionImpl>>>(101, { window }));
1828 subWindows = window->GetSubWindow(101); // 101 is parentId
1829 ASSERT_EQ(1, subWindows.size());
1830 WindowSessionImpl::subWindowSessionMap_.erase(101); // 101
1831 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetVirtualPixelRatio end";
1832 }
1833
1834 /**
1835 * @tc.name: ClearListenersById_displayMoveListeners
1836 * @tc.desc: ClearListenersById_displayMoveListeners
1837 * @tc.type: FUNC
1838 */
1839 HWTEST_F(WindowSessionImplTest4, ClearListenersById_displayMoveListeners, Function | SmallTest | Level2)
1840 {
1841 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_displayMoveListeners start";
1842 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1843 option_->SetWindowName("ClearListenersById_displayMoveListeners");
1844 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1845
1846 int persistentId = window_->GetPersistentId();
1847 window_->ClearListenersById(persistentId);
1848
1849 sptr<IDisplayMoveListener> listener_ = new (std::nothrow) MockIDisplayMoveListener();
1850 window_->RegisterDisplayMoveListener(listener_);
1851 ASSERT_NE(window_->displayMoveListeners_.find(persistentId), window_->displayMoveListeners_.end());
1852
1853 window_->ClearListenersById(persistentId);
1854 ASSERT_EQ(window_->displayMoveListeners_.find(persistentId), window_->displayMoveListeners_.end());
1855
1856 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_displayMoveListeners end";
1857 }
1858
1859 /**
1860 * @tc.name: ClearListenersById_lifecycleListeners
1861 * @tc.desc: ClearListenersById_lifecycleListeners
1862 * @tc.type: FUNC
1863 */
1864 HWTEST_F(WindowSessionImplTest4, ClearListenersById_lifecycleListeners, Function | SmallTest | Level2)
1865 {
1866 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_lifecycleListeners start";
1867 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1868 option_->SetWindowName("ClearListenersById_lifecycleListeners");
1869 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1870
1871 int persistentId = window_->GetPersistentId();
1872 window_->ClearListenersById(persistentId);
1873
1874 sptr<IWindowLifeCycle> listener_ = new (std::nothrow) MockWindowLifeCycleListener();
1875 window_->RegisterLifeCycleListener(listener_);
1876 ASSERT_NE(window_->lifecycleListeners_.find(persistentId), window_->lifecycleListeners_.end());
1877
1878 window_->ClearListenersById(persistentId);
1879 ASSERT_EQ(window_->lifecycleListeners_.find(persistentId), window_->lifecycleListeners_.end());
1880
1881 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_lifecycleListeners end";
1882 }
1883
1884 /**
1885 * @tc.name: ClearListenersById_windowChangeListeners
1886 * @tc.desc: ClearListenersById_windowChangeListeners
1887 * @tc.type: FUNC
1888 */
1889 HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowChangeListeners, Function | SmallTest | Level2)
1890 {
1891 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowChangeListeners start";
1892 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1893 option_->SetWindowName("ClearListenersById_windowChangeListeners");
1894 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1895
1896 int persistentId = window_->GetPersistentId();
1897 window_->ClearListenersById(persistentId);
1898
1899 sptr<IWindowChangeListener> listener_ = new (std::nothrow) MockWindowChangeListener();
1900 window_->RegisterWindowChangeListener(listener_);
1901 ASSERT_NE(window_->windowChangeListeners_.find(persistentId), window_->windowChangeListeners_.end());
1902
1903 window_->ClearListenersById(persistentId);
1904 ASSERT_EQ(window_->windowChangeListeners_.find(persistentId), window_->windowChangeListeners_.end());
1905
1906 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowChangeListeners end";
1907 }
1908
1909 /**
1910 * @tc.name: ClearListenersById_avoidAreaChangeListeners
1911 * @tc.desc: ClearListenersById_avoidAreaChangeListeners
1912 * @tc.type: FUNC
1913 */
1914 HWTEST_F(WindowSessionImplTest4, ClearListenersById_avoidAreaChangeListeners, Function | SmallTest | Level2)
1915 {
1916 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_avoidAreaChangeListeners start";
1917 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1918 option_->SetWindowName("ClearListenersById_avoidAreaChangeListeners");
1919 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1920
1921 int persistentId = window_->GetPersistentId();
1922 window_->ClearListenersById(persistentId);
1923
1924 sptr<IAvoidAreaChangedListener> listener_ = new (std::nothrow) MockAvoidAreaChangedListener();
1925 window_->RegisterExtensionAvoidAreaChangeListener(listener_);
1926 ASSERT_NE(window_->avoidAreaChangeListeners_.find(persistentId), window_->avoidAreaChangeListeners_.end());
1927
1928 window_->ClearListenersById(persistentId);
1929 ASSERT_EQ(window_->avoidAreaChangeListeners_.find(persistentId), window_->avoidAreaChangeListeners_.end());
1930
1931 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_avoidAreaChangeListeners end";
1932 }
1933
1934 /**
1935 * @tc.name: ClearListenersById_dialogDeathRecipientListeners
1936 * @tc.desc: ClearListenersById_dialogDeathRecipientListeners
1937 * @tc.type: FUNC
1938 */
1939 HWTEST_F(WindowSessionImplTest4, ClearListenersById_dialogDeathRecipientListeners, Function | SmallTest | Level2)
1940 {
1941 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_dialogDeathRecipientListeners start";
1942 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1943 option_->SetWindowName("ClearListenersById_dialogDeathRecipientListeners");
1944 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1945
1946 int persistentId = window_->GetPersistentId();
1947 window_->ClearListenersById(persistentId);
1948
1949 sptr<IDialogDeathRecipientListener> listener_ = new (std::nothrow) MockIDialogDeathRecipientListener();
1950 window_->RegisterDialogDeathRecipientListener(listener_);
1951 ASSERT_NE(window_->dialogDeathRecipientListeners_.find(persistentId),
1952 window_->dialogDeathRecipientListeners_.end());
1953
1954 window_->ClearListenersById(persistentId);
1955 ASSERT_EQ(window_->dialogDeathRecipientListeners_.find(persistentId),
1956 window_->dialogDeathRecipientListeners_.end());
1957
1958 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_dialogDeathRecipientListeners end";
1959 }
1960
1961 /**
1962 * @tc.name: ClearListenersById_dialogTargetTouchListener
1963 * @tc.desc: ClearListenersById_dialogTargetTouchListener
1964 * @tc.type: FUNC
1965 */
1966 HWTEST_F(WindowSessionImplTest4, ClearListenersById_dialogTargetTouchListener, Function | SmallTest | Level2)
1967 {
1968 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_dialogTargetTouchListener start";
1969 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1970 option_->SetWindowName("ClearListenersById_dialogTargetTouchListener");
1971 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1972
1973 int persistentId = window_->GetPersistentId();
1974 window_->ClearListenersById(persistentId);
1975
1976 sptr<IDialogTargetTouchListener> listener_ = new (std::nothrow) MockIDialogTargetTouchListener();
1977 window_->RegisterDialogTargetTouchListener(listener_);
1978 ASSERT_NE(window_->dialogTargetTouchListener_.find(persistentId), window_->dialogTargetTouchListener_.end());
1979
1980 window_->ClearListenersById(persistentId);
1981 ASSERT_EQ(window_->dialogTargetTouchListener_.find(persistentId), window_->dialogTargetTouchListener_.end());
1982
1983 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_dialogTargetTouchListener end";
1984 }
1985
1986 /**
1987 * @tc.name: ClearListenersById_screenshotListeners
1988 * @tc.desc: ClearListenersById_screenshotListeners
1989 * @tc.type: FUNC
1990 */
1991 HWTEST_F(WindowSessionImplTest4, ClearListenersById_screenshotListeners, Function | SmallTest | Level2)
1992 {
1993 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_screenshotListeners start";
1994 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
1995 option_->SetWindowName("ClearListenersById_screenshotListeners");
1996 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
1997
1998 int persistentId = window_->GetPersistentId();
1999 window_->ClearListenersById(persistentId);
2000
2001 sptr<IScreenshotListener> listener_ = new (std::nothrow) MockIScreenshotListener();
2002 window_->RegisterScreenshotListener(listener_);
2003 ASSERT_NE(window_->screenshotListeners_.find(persistentId), window_->screenshotListeners_.end());
2004
2005 window_->ClearListenersById(persistentId);
2006 ASSERT_EQ(window_->screenshotListeners_.find(persistentId), window_->screenshotListeners_.end());
2007
2008 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_screenshotListeners end";
2009 }
2010
2011 /**
2012 * @tc.name: ClearListenersById_windowStatusChangeListeners
2013 * @tc.desc: ClearListenersById_windowStatusChangeListeners
2014 * @tc.type: FUNC
2015 */
2016 HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowStatusChangeListeners, Function | SmallTest | Level2)
2017 {
2018 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowStatusChangeListeners start";
2019 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
2020 option_->SetWindowName("ClearListenersById_windowStatusChangeListeners");
2021 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
2022
2023 int persistentId = window_->GetPersistentId();
2024 window_->ClearListenersById(persistentId);
2025
2026 sptr<IWindowStatusChangeListener> listener_ = new (std::nothrow) MockWindowStatusChangeListener();
2027 window_->RegisterWindowStatusChangeListener(listener_);
2028 ASSERT_NE(window_->windowStatusChangeListeners_.find(persistentId), window_->windowStatusChangeListeners_.end());
2029
2030 window_->ClearListenersById(persistentId);
2031 ASSERT_EQ(window_->windowStatusChangeListeners_.find(persistentId), window_->windowStatusChangeListeners_.end());
2032
2033 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowStatusChangeListeners end";
2034 }
2035
2036 /**
2037 * @tc.name: ClearListenersById_windowTitleButtonRectChangeListeners
2038 * @tc.desc: ClearListenersById_windowTitleButtonRectChangeListeners
2039 * @tc.type: FUNC
2040 */
2041 HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowTitleButtonRectChangeListeners, Function | SmallTest | Level2)
2042 {
2043 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowTitleButtonRectChangeListeners start";
2044 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
2045 option_->SetWindowName("ClearListenersById_windowTitleButtonRectChangeListeners");
2046 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
2047
2048 int persistentId = window_->GetPersistentId();
2049 window_->ClearListenersById(persistentId);
2050
2051 sptr<IWindowTitleButtonRectChangedListener> listener_ =
2052 new (std::nothrow) MockWindowTitleButtonRectChangedListener();
2053 window_->windowTitleButtonRectChangeListeners_[persistentId].emplace_back(listener_);
2054 ASSERT_NE(window_->windowTitleButtonRectChangeListeners_.find(persistentId),
2055 window_->windowTitleButtonRectChangeListeners_.end());
2056
2057 window_->ClearListenersById(persistentId);
2058 ASSERT_EQ(window_->windowTitleButtonRectChangeListeners_.find(persistentId),
2059 window_->windowTitleButtonRectChangeListeners_.end());
2060
2061 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowTitleButtonRectChangeListeners end";
2062 }
2063
2064 /**
2065 * @tc.name: ClearListenersById_windowNoInteractionListeners
2066 * @tc.desc: ClearListenersById_windowNoInteractionListeners
2067 * @tc.type: FUNC
2068 */
2069 HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowNoInteractionListeners, Function | SmallTest | Level2)
2070 {
2071 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowNoInteractionListeners start";
2072 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
2073 option_->SetWindowName("ClearListenersById_windowNoInteractionListeners");
2074 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
2075
2076 int persistentId = window_->GetPersistentId();
2077 window_->ClearListenersById(persistentId);
2078
2079 sptr<IWindowNoInteractionListener> listener_ = new (std::nothrow) MockWindowNoInteractionListener();
2080 window_->RegisterWindowNoInteractionListener(listener_);
2081 ASSERT_NE(window_->windowNoInteractionListeners_.find(persistentId), window_->windowNoInteractionListeners_.end());
2082
2083 window_->ClearListenersById(persistentId);
2084 ASSERT_EQ(window_->windowNoInteractionListeners_.find(persistentId), window_->windowNoInteractionListeners_.end());
2085
2086 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowNoInteractionListeners end";
2087 }
2088
2089 /**
2090 * @tc.name: ClearListenersById_windowRectChangeListeners
2091 * @tc.desc: ClearListenersById_windowRectChangeListeners
2092 * @tc.type: FUNC
2093 */
2094 HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowRectChangeListeners, Function | SmallTest | Level2)
2095 {
2096 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowRectChangeListeners start";
2097 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
2098 option_->SetWindowName("ClearListenersById_windowRectChangeListeners");
2099 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
2100
2101 int persistentId = window_->GetPersistentId();
2102 window_->ClearListenersById(persistentId);
2103
2104 sptr<IWindowRectChangeListener> listener_ = new (std::nothrow) MockWindowRectChangeListener();
2105 window_->RegisterWindowRectChangeListener(listener_);
2106 ASSERT_NE(window_->windowRectChangeListeners_.find(persistentId), window_->windowRectChangeListeners_.end());
2107
2108 window_->ClearListenersById(persistentId);
2109 ASSERT_EQ(window_->windowRectChangeListeners_.find(persistentId), window_->windowRectChangeListeners_.end());
2110
2111 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowRectChangeListeners end";
2112 }
2113
2114 /**
2115 * @tc.name: ClearListenersById_subWindowCloseListeners
2116 * @tc.desc: ClearListenersById_subWindowCloseListeners
2117 * @tc.type: FUNC
2118 */
2119 HWTEST_F(WindowSessionImplTest4, ClearListenersById_subWindowCloseListeners, Function | SmallTest | Level2)
2120 {
2121 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_subWindowCloseListeners start";
2122 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
2123 option_->SetWindowName("ClearListenersById_subWindowCloseListeners");
2124 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
2125
2126 int persistentId = window_->GetPersistentId();
2127 window_->ClearListenersById(persistentId);
2128
2129 sptr<ISubWindowCloseListener> listener_ = new (std::nothrow) MockISubWindowCloseListener();
2130 window_->subWindowCloseListeners_[persistentId] = listener_;
2131 ASSERT_NE(window_->subWindowCloseListeners_.find(persistentId), window_->subWindowCloseListeners_.end());
2132
2133 window_->ClearListenersById(persistentId);
2134 ASSERT_EQ(window_->subWindowCloseListeners_.find(persistentId), window_->subWindowCloseListeners_.end());
2135
2136 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_subWindowCloseListeners end";
2137 }
2138
2139 /**
2140 * @tc.name: ClearListenersById_mainWindowCloseListeners
2141 * @tc.desc: ClearListenersById_mainWindowCloseListeners
2142 * @tc.type: FUNC
2143 */
2144 HWTEST_F(WindowSessionImplTest4, ClearListenersById_mainWindowCloseListeners, Function | SmallTest | Level2)
2145 {
2146 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_mainWindowCloseListeners start";
2147 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
2148 option_->SetWindowName("ClearListenersById_mainWindowCloseListeners");
2149 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
2150
2151 int persistentId = window_->GetPersistentId();
2152 window_->ClearListenersById(persistentId);
2153
2154 sptr<IMainWindowCloseListener> listener_ = new (std::nothrow) MockIMainWindowCloseListener();
2155 window_->mainWindowCloseListeners_[persistentId] = listener_;
2156 ASSERT_NE(window_->mainWindowCloseListeners_.find(persistentId), window_->mainWindowCloseListeners_.end());
2157
2158 window_->ClearListenersById(persistentId);
2159 ASSERT_EQ(window_->mainWindowCloseListeners_.find(persistentId), window_->mainWindowCloseListeners_.end());
2160
2161 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_mainWindowCloseListeners end";
2162 }
2163
2164 /**
2165 * @tc.name: ClearListenersById_windowWillCloseListeners
2166 * @tc.desc: ClearListenersById_windowWillCloseListeners
2167 * @tc.type: FUNC
2168 */
2169 HWTEST_F(WindowSessionImplTest4, ClearListenersById_windowWillCloseListeners, Function | SmallTest | Level2)
2170 {
2171 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowWillCloseListeners start";
2172 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
2173 option_->SetWindowName("ClearListenersById_windowWillCloseListeners");
2174 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
2175 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2176 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2177 window_->hostSession_ = session;
2178 window_->property_->SetPersistentId(1);
2179 int persistentId = window_->GetPersistentId();
2180 window_->ClearListenersById(persistentId);
2181
2182 sptr<IWindowWillCloseListener> listener_ = sptr<MockIWindowWillCloseListener>::MakeSptr();
2183 window_->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
2184 ASSERT_EQ(WMError::WM_OK, window_->RegisterWindowWillCloseListeners(listener_));
2185 ASSERT_NE(window_->windowWillCloseListeners_.find(persistentId), window_->windowWillCloseListeners_.end());
2186
2187 window_->ClearListenersById(persistentId);
2188 ASSERT_EQ(window_->windowWillCloseListeners_.find(persistentId), window_->windowWillCloseListeners_.end());
2189
2190 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_windowWillCloseListeners end";
2191 }
2192
2193 /**
2194 * @tc.name: ClearListenersById_occupiedAreaChangeListeners
2195 * @tc.desc: ClearListenersById_occupiedAreaChangeListeners
2196 * @tc.type: FUNC
2197 */
2198 HWTEST_F(WindowSessionImplTest4, ClearListenersById_occupiedAreaChangeListeners, Function | SmallTest | Level2)
2199 {
2200 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_occupiedAreaChangeListeners start";
2201 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
2202 option_->SetWindowName("ClearListenersById_occupiedAreaChangeListeners");
2203 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
2204
2205 int persistentId = window_->GetPersistentId();
2206 window_->ClearListenersById(persistentId);
2207
2208 sptr<IOccupiedAreaChangeListener> listener_ = new (std::nothrow) MockIOccupiedAreaChangeListener();
2209 window_->RegisterOccupiedAreaChangeListener(listener_);
2210 ASSERT_NE(window_->occupiedAreaChangeListeners_.find(persistentId), window_->occupiedAreaChangeListeners_.end());
2211
2212 window_->ClearListenersById(persistentId);
2213 ASSERT_EQ(window_->occupiedAreaChangeListeners_.find(persistentId), window_->occupiedAreaChangeListeners_.end());
2214
2215 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_occupiedAreaChangeListeners end";
2216 }
2217
2218 /**
2219 * @tc.name: ClearListenersById_keyboardDidShowListeners
2220 * @tc.desc: ClearListenersById_keyboardDidShowListeners
2221 * @tc.type: FUNC
2222 */
2223 HWTEST_F(WindowSessionImplTest4, ClearListenersById_keyboardDidShowListeners, Function | SmallTest | Level2)
2224 {
2225 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_keyboardDidShowListeners start";
2226 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
2227 option_->SetWindowName("ClearListenersById_keyboardDidShowListeners");
2228 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
2229
2230 int persistentId = window_->GetPersistentId();
2231 window_->ClearListenersById(persistentId);
2232
2233 sptr<IKeyboardDidShowListener> listener_ = new (std::nothrow) MockIKeyboardDidShowListener();
2234 window_->RegisterKeyboardDidShowListener(listener_);
2235 ASSERT_NE(window_->keyboardDidShowListeners_.find(persistentId), window_->keyboardDidShowListeners_.end());
2236
2237 window_->ClearListenersById(persistentId);
2238 ASSERT_EQ(window_->keyboardDidShowListeners_.find(persistentId), window_->keyboardDidShowListeners_.end());
2239
2240 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_keyboardDidShowListeners end";
2241 }
2242
2243 /**
2244 * @tc.name: ClearListenersById_keyboardDidHideListeners
2245 * @tc.desc: ClearListenersById_keyboardDidHideListeners
2246 * @tc.type: FUNC
2247 */
2248 HWTEST_F(WindowSessionImplTest4, ClearListenersById_keyboardDidHideListeners, Function | SmallTest | Level2)
2249 {
2250 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_keyboardDidHideListeners start";
2251 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
2252 option_->SetWindowName("ClearListenersById_keyboardDidHideListeners");
2253 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
2254
2255 int persistentId = window_->GetPersistentId();
2256 window_->ClearListenersById(persistentId);
2257
2258 sptr<IKeyboardDidHideListener> listener_ = new (std::nothrow) MockIKeyboardDidHideListener();
2259 window_->RegisterKeyboardDidHideListener(listener_);
2260 ASSERT_NE(window_->keyboardDidHideListeners_.find(persistentId), window_->keyboardDidHideListeners_.end());
2261
2262 window_->ClearListenersById(persistentId);
2263 ASSERT_EQ(window_->keyboardDidHideListeners_.find(persistentId), window_->keyboardDidHideListeners_.end());
2264
2265 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_keyboardDidHideListeners end";
2266 }
2267
2268 /**
2269 * @tc.name: ClearListenersById_switchFreeMultiWindowListeners
2270 * @tc.desc: ClearListenersById_switchFreeMultiWindowListeners
2271 * @tc.type: FUNC
2272 */
2273 HWTEST_F(WindowSessionImplTest4, ClearListenersById_switchFreeMultiWindowListeners, Function | SmallTest | Level2)
2274 {
2275 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_switchFreeMultiWindowListeners start";
2276 sptr<WindowOption> option_ = sptr<WindowOption>::MakeSptr();
2277 option_->SetWindowName("ClearListenersById_switchFreeMultiWindowListeners");
2278 sptr<WindowSessionImpl> window_ = sptr<WindowSessionImpl>::MakeSptr(option_);
2279
2280 int persistentId = window_->GetPersistentId();
2281 window_->ClearListenersById(persistentId);
2282
2283 sptr<ISwitchFreeMultiWindowListener> listener_ = new (std::nothrow) MockISwitchFreeMultiWindowListener();
2284 window_->RegisterSwitchFreeMultiWindowListener(listener_);
2285 ASSERT_NE(window_->switchFreeMultiWindowListeners_.find(persistentId),
2286 window_->switchFreeMultiWindowListeners_.end());
2287
2288 window_->ClearListenersById(persistentId);
2289 ASSERT_EQ(window_->switchFreeMultiWindowListeners_.find(persistentId),
2290 window_->switchFreeMultiWindowListeners_.end());
2291
2292 WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
2293 sleep(1);
2294 WindowAccessibilityController::GetInstance().SetAnchorOffset(0, 0);
2295 sleep(1);
2296 WindowAccessibilityController::GetInstance().OffWindowZoom();
2297 sleep(1);
2298
2299 GTEST_LOG_(INFO) << "WindowSessionImplTest4: ClearListenersById_switchFreeMultiWindowListeners end";
2300 }
2301
2302 /**
2303 * @tc.name: FlushLayoutSize
2304 * @tc.desc: FlushLayoutSize
2305 * @tc.type: FUNC
2306 */
2307 HWTEST_F(WindowSessionImplTest4, FlushLayoutSize, Function | SmallTest | Level2)
2308 {
2309 #undef private
2310 GTEST_LOG_(INFO) << "WindowSessionImplTest4: FlushLayoutSize start";
2311 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2312 option->SetWindowName("FlushLayoutSize");
2313 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2314 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
2315 int32_t width = 1320;
2316 int32_t height = 2710;
2317 WSRect rect = { 0, 0, width, height };
2318 window->FlushLayoutSize(width, height);
2319
2320 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
2321 window->windowSizeChanged_ = true;
2322 window->FlushLayoutSize(width, height);
2323 ASSERT_EQ(window->windowSizeChanged_, false);
2324
2325 window->layoutRect_ = { 0, 0, 2710, 1320 };
2326 window->FlushLayoutSize(width, height);
2327 ASSERT_EQ(window->layoutRect_, rect);
2328
2329 window->enableFrameLayoutFinishCb_ = true;
2330 window->FlushLayoutSize(width, height);
2331 ASSERT_EQ(window->enableFrameLayoutFinishCb_, false);
2332
2333 GTEST_LOG_(INFO) << "WindowSessionImplTest4: FlushLayoutSize end";
2334 }
2335
2336 /**
2337 * @tc.name: RegisterDisplayIdChangeListener01
2338 * @tc.desc: RegisterDisplayIdChangeListener01
2339 * @tc.type: FUNC
2340 */
2341 HWTEST_F(WindowSessionImplTest4, RegisterDisplayIdChangeListener01, Function | SmallTest | Level2)
2342 {
2343 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2344 option->SetWindowName("RegisterDisplayIdChangeListener01");
2345
2346 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2347 sptr<IDisplayIdChangeListener> listener = nullptr;
2348 WMError ret = window->RegisterDisplayIdChangeListener(listener);
2349 ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
2350
2351 listener = sptr<IDisplayIdChangeListener>::MakeSptr();
2352 std::vector<sptr<IDisplayIdChangeListener>> holder;
2353 window->displayIdChangeListeners_[window->property_->GetPersistentId()] = holder;
2354 ret = window->RegisterDisplayIdChangeListener(listener);
2355 ASSERT_EQ(ret, WMError::WM_OK);
2356 holder = window->displayIdChangeListeners_[window->property_->GetPersistentId()];
2357 auto existsListener = std::find(holder.begin(), holder.end(), listener);
2358 ASSERT_NE(existsListener, holder.end());
2359
2360 ret = window->RegisterDisplayIdChangeListener(listener);
2361 ASSERT_EQ(ret, WMError::WM_OK);
2362 }
2363
2364 /**
2365 * @tc.name: UnregisterDisplayIdChangeListener01
2366 * @tc.desc: UnregisterDisplayIdChangeListener01
2367 * @tc.type: FUNC
2368 */
2369 HWTEST_F(WindowSessionImplTest4, UnregisterDisplayIdChangeListener01, Function | SmallTest | Level2)
2370 {
2371 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2372 option->SetWindowName("UnregisterDisplayIdChangeListener01");
2373
2374 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2375 sptr<IDisplayIdChangeListener> listener = nullptr;
2376 WMError ret = window->UnregisterDisplayIdChangeListener(listener);
2377 ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
2378
2379 listener = sptr<IDisplayIdChangeListener>::MakeSptr();
2380 std::vector<sptr<IDisplayIdChangeListener>> holder;
2381 window->displayIdChangeListeners_[window->property_->GetPersistentId()] = holder;
2382 window->UnregisterDisplayIdChangeListener(listener);
2383
2384 ret = window->UnregisterDisplayIdChangeListener(listener);
2385 ASSERT_EQ(ret, WMError::WM_OK);
2386
2387 holder = window->displayIdChangeListeners_[window->property_->GetPersistentId()];
2388 auto existsListener = std::find(holder.begin(), holder.end(), listener);
2389 ASSERT_EQ(existsListener, holder.end());
2390 }
2391
2392 /**
2393 * @tc.name: NotifyDisplayIdChange01
2394 * @tc.desc: NotifyDisplayIdChange01
2395 * @tc.type: FUNC
2396 */
2397 HWTEST_F(WindowSessionImplTest4, NotifyDisplayIdChange01, Function | SmallTest | Level2)
2398 {
2399 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2400 option->SetWindowName("NotifyDisplayIdChange01");
2401
2402 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2403
2404 SessionInfo sessioninfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2405 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessioninfo);
2406 ASSERT_NE(session, nullptr);
2407 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
2408 DisplayId displayId = 12;
2409 auto ret = window->NotifyDisplayIdChange(displayId);
2410 ASSERT_EQ(WSError::WS_OK, ret);
2411 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
2412 }
2413
2414 /**
2415 * @tc.name: RegisterSystemDensityChangeListener01
2416 * @tc.desc: RegisterSystemDensityChangeListener01
2417 * @tc.type: FUNC
2418 */
2419 HWTEST_F(WindowSessionImplTest4, RegisterSystemDensityChangeListener01, Function | SmallTest | Level2)
2420 {
2421 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2422 option->SetWindowName("RegisterSystemDensityChangeListener01");
2423
2424 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2425 sptr<ISystemDensityChangeListener> listener = nullptr;
2426 WMError ret = window->RegisterSystemDensityChangeListener(listener);
2427 ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
2428
2429 listener = sptr<ISystemDensityChangeListener>::MakeSptr();
2430 std::vector<sptr<ISystemDensityChangeListener>> holder;
2431 window->systemDensityChangeListeners_[window->property_->GetPersistentId()] = holder;
2432 ret = window->RegisterSystemDensityChangeListener(listener);
2433 ASSERT_EQ(ret, WMError::WM_OK);
2434 holder = window->systemDensityChangeListeners_[window->property_->GetPersistentId()];
2435 auto existsListener = std::find(holder.begin(), holder.end(), listener);
2436 ASSERT_NE(existsListener, holder.end());
2437
2438 ret = window->RegisterSystemDensityChangeListener(listener);
2439 ASSERT_EQ(ret, WMError::WM_OK);
2440 holder = window->systemDensityChangeListeners_[window->property_->GetPersistentId()];
2441 ASSERT_EQ(holder.size(), 1);
2442 }
2443
2444 /**
2445 * @tc.name: UnregisterSystemDensityChangeListener01
2446 * @tc.desc: UnregisterSystemDensityChangeListener01
2447 * @tc.type: FUNC
2448 */
2449 HWTEST_F(WindowSessionImplTest4, UnregisterSystemDensityChangeListener01, Function | SmallTest | Level2)
2450 {
2451 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2452 option->SetWindowName("UnregisterSystemDensityChangeListener01");
2453
2454 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2455 sptr<ISystemDensityChangeListener> listener = nullptr;
2456 WMError ret = window->UnregisterSystemDensityChangeListener(listener);
2457 ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
2458
2459 listener = sptr<ISystemDensityChangeListener>::MakeSptr();
2460 std::vector<sptr<ISystemDensityChangeListener>> holder;
2461 window->systemDensityChangeListeners_[window->property_->GetPersistentId()] = holder;
2462 ret = window->UnregisterSystemDensityChangeListener(listener);
2463 ASSERT_EQ(ret, WMError::WM_OK);
2464
2465 holder = window->systemDensityChangeListeners_[window->property_->GetPersistentId()];
2466 auto existsListener = std::find(holder.begin(), holder.end(), listener);
2467 ASSERT_EQ(existsListener, holder.end());
2468 }
2469
2470 /**
2471 * @tc.name: NotifySystemDensityChange01
2472 * @tc.desc: NotifySystemDensityChange01
2473 * @tc.type: FUNC
2474 */
2475 HWTEST_F(WindowSessionImplTest4, NotifySystemDensityChange01, Function | SmallTest | Level2)
2476 {
2477 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2478 option->SetWindowName("NotifySystemDensityChange01");
2479
2480 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2481 SessionInfo sessioninfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2482 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessioninfo);
2483 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
2484
2485 float density = 1.5f;
2486 auto ret = window->NotifySystemDensityChange(density);
2487 ASSERT_EQ(WSError::WS_OK, ret);
2488 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
2489 }
2490
2491 /**
2492 * @tc.name: GetIsMidScene
2493 * @tc.desc: GetIsMidScene
2494 * @tc.type: FUNC
2495 */
2496 HWTEST_F(WindowSessionImplTest4, GetIsMidScene, Function | SmallTest | Level2)
2497 {
2498 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2499 option->SetWindowName("GetIsMidScene");
2500
2501 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2502 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2503 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2504 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
2505
2506 bool isMidScene = false;
2507 auto ret = window->GetIsMidScene(isMidScene);
2508 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret);
2509 ASSERT_EQ(false, isMidScene);
2510 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
2511 }
2512
2513 /**
2514 * @tc.name: GetLayoutTransform
2515 * @tc.desc: GetLayoutTransform
2516 * @tc.type: FUNC
2517 */
2518 HWTEST_F(WindowSessionImplTest4, GetLayoutTransform, Function | SmallTest | Level2)
2519 {
2520 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2521 option->SetWindowName("GetLayoutTransform");
2522 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2523
2524 Transform transform;
2525 transform.scaleX_ = 1.0;
2526 transform.scaleY_ = 1.0;
2527 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
2528 window->NotifyTransformChange(transform);
2529 Transform layoutTransform = window->GetLayoutTransform();
2530 ASSERT_EQ(transform.scaleX_, layoutTransform.scaleX_);
2531 ASSERT_EQ(transform.scaleY_, layoutTransform.scaleY_);
2532 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
2533 }
2534
2535 /**
2536 * @tc.name: SetExclusivelyHighlighted
2537 * @tc.desc: SetExclusivelyHighlighted
2538 * @tc.type: FUNC
2539 */
2540 HWTEST_F(WindowSessionImplTest4, SetExclusivelyHighlighted, Function | SmallTest | Level2)
2541 {
2542 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2543 option->SetWindowName("SetExclusivelyHighlighted");
2544 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2545 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2546 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2547 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
2548 window->hostSession_ = session;
2549 window->property_->SetPersistentId(INVALID_SESSION_ID);
2550 ASSERT_EQ(window->SetExclusivelyHighlighted(true), WMError::WM_ERROR_INVALID_WINDOW);
2551 window->property_->SetPersistentId(1);
2552 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
2553 ASSERT_EQ(window->SetExclusivelyHighlighted(true), WMError::WM_ERROR_INVALID_CALLING);
2554 window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
2555 ASSERT_EQ(window->SetExclusivelyHighlighted(true), WMError::WM_ERROR_INVALID_CALLING);
2556 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
2557 window->property_->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL);
2558 ASSERT_EQ(window->SetExclusivelyHighlighted(true), WMError::WM_ERROR_INVALID_CALLING);
2559 window->property_->flags_ = 0;
2560 ASSERT_EQ(window->SetExclusivelyHighlighted(true), WMError::WM_OK);
2561 ASSERT_EQ(window->SetExclusivelyHighlighted(false), WMError::WM_OK);
2562 }
2563
2564 /**
2565 * @tc.name: GetExclusivelyHighlighted
2566 * @tc.desc: GetExclusivelyHighlighted
2567 * @tc.type: FUNC
2568 */
2569 HWTEST_F(WindowSessionImplTest4, GetExclusivelyHighlighted, Function | SmallTest | Level2)
2570 {
2571 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2572 option->SetWindowName("GetExclusivelyHighlighted");
2573 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2574 ASSERT_EQ(window->GetExclusivelyHighlighted(), true);
2575 }
2576
2577 /**
2578 * @tc.name: NotifyHighlightChange
2579 * @tc.desc: NotifyHighlightChange
2580 * @tc.type: FUNC
2581 */
2582 HWTEST_F(WindowSessionImplTest4, NotifyHighlightChange, Function | SmallTest | Level2)
2583 {
2584 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2585 option->SetWindowName("NotifyHighlightChange01");
2586 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2587 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2588 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2589 window->hostSession_ = session;
2590 window->property_->SetPersistentId(1);
2591
2592 bool highlight = false;
2593 WSError res = window->NotifyHighlightChange(highlight);
2594 EXPECT_EQ(highlight, false);
2595 EXPECT_EQ(res, WSError::WS_OK);
2596 sptr<IWindowHighlightChangeListener> listener = sptr<IWindowHighlightChangeListener>::MakeSptr();
2597 window->RegisterWindowHighlightChangeListeners(listener);
2598 res = window->NotifyHighlightChange(highlight);
2599 EXPECT_EQ(highlight, false);
2600 EXPECT_EQ(res, WSError::WS_OK);
2601 window->UnregisterWindowHighlightChangeListeners(listener);
2602 }
2603
2604 /**
2605 * @tc.name: IsWindowHighlighted
2606 * @tc.desc: IsWindowHighlighted
2607 * @tc.type: FUNC
2608 */
2609 HWTEST_F(WindowSessionImplTest4, IsWindowHighlighted, Function | SmallTest | Level2)
2610 {
2611 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2612 option->SetWindowName("IsWindowHighlighted");
2613 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2614 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2615 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2616 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
2617 bool isHighlighted = false;
2618 window->hostSession_ = session;
2619 window->property_->SetPersistentId(INVALID_SESSION_ID);
2620 ASSERT_EQ(window->IsWindowHighlighted(isHighlighted), WMError::WM_ERROR_INVALID_WINDOW);
2621 window->property_->SetPersistentId(1);
2622 ASSERT_EQ(window->IsWindowHighlighted(isHighlighted), WMError::WM_OK);
2623 ASSERT_EQ(isHighlighted, false);
2624 }
2625
2626 /**
2627 * @tc.name: NotifyWindowCrossAxisChange
2628 * @tc.desc: NotifyWindowCrossAxisChange
2629 * @tc.type: FUNC
2630 */
2631 HWTEST_F(WindowSessionImplTest4, NotifyWindowCrossAxisChange, Function | SmallTest | Level2)
2632 {
2633 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2634 option->SetWindowName("NotifyWindowCrossAxisChange");
2635 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2636 sptr<MockIWindowCrossAxisListener> crossListener = sptr<MockIWindowCrossAxisListener>::MakeSptr();
2637 WindowSessionImpl::windowCrossAxisListeners_[window->property_->persistentId_].push_back(crossListener);
2638 EXPECT_CALL(*crossListener, OnCrossAxisChange(CrossAxisState::STATE_CROSS)).Times(1);
2639 window->NotifyWindowCrossAxisChange(CrossAxisState::STATE_CROSS);
2640 EXPECT_EQ(window->crossAxisState_.load(), CrossAxisState::STATE_CROSS);
2641 WindowSessionImpl::windowCrossAxisListeners_[window->property_->persistentId_].clear();
2642 }
2643
2644 /**
2645 * @tc.name: GetCrossAxisState
2646 * @tc.desc: GetCrossAxisState
2647 * @tc.type: FUNC
2648 */
2649 HWTEST_F(WindowSessionImplTest4, GetCrossAxisState, Function | SmallTest | Level2)
2650 {
2651 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2652 option->SetWindowName("GetCrossAxisState");
2653 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2654 window->crossAxisState_ = CrossAxisState::STATE_CROSS;
2655 EXPECT_EQ(window->GetCrossAxisState(), CrossAxisState::STATE_CROSS);
2656 window->crossAxisState_ = CrossAxisState::STATE_INVALID;
2657 window->hostSession_ = nullptr;
2658 EXPECT_EQ(window->GetCrossAxisState(), CrossAxisState::STATE_INVALID);
2659 auto mockHostSession = sptr<SessionStubMocker>::MakeSptr();
2660 window->hostSession_ = mockHostSession;
2661 window->property_->persistentId_ = 1234;
2662 EXPECT_CALL(*mockHostSession, GetCrossAxisState(_))
2663 .WillOnce(DoAll(SetArgReferee<0>(CrossAxisState::STATE_CROSS), Return(WSError::WS_OK)));
2664 EXPECT_EQ(window->GetCrossAxisState(), CrossAxisState::STATE_CROSS);
2665 }
2666
2667 /**
2668 * @tc.name: SendContainerModalEvent
2669 * @tc.desc: SendContainerModalEvent
2670 * @tc.type: FUNC
2671 */
2672 HWTEST_F(WindowSessionImplTest4, SendContainerModalEvent, Function | SmallTest | Level2)
2673 {
2674 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2675 option->SetWindowName("SendContainerModalEvent");
2676 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2677 auto ret = window->SendContainerModalEvent("scb_back_visibility", "true");
2678 EXPECT_EQ(ret, WSError::WS_OK);
2679 ret = window->SendContainerModalEvent("scb_back_visibility", "false");
2680 EXPECT_EQ(ret, WSError::WS_OK);
2681 ret = window->SendContainerModalEvent("win_waterfall_visibility", "true");
2682 EXPECT_EQ(ret, WSError::WS_OK);
2683 ret = window->SendContainerModalEvent("win_waterfall_visibility", "false");
2684 EXPECT_EQ(ret, WSError::WS_OK);
2685 }
2686
2687 /**
2688 * @tc.name: SetSubWindowZLevelToProperty
2689 * @tc.desc: SetSubWindowZLevelToProperty
2690 * @tc.type: FUNC
2691 */
2692 HWTEST_F(WindowSessionImplTest4, SetSubWindowZLevelToProperty, Function | SmallTest | Level2)
2693 {
2694 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2695 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
2696 option->SetSubWindowZLevel(1);
2697 sptr<WindowSessionImpl> mainWindowSessionImpl = sptr<WindowSessionImpl>::MakeSptr(option);
2698 mainWindowSessionImpl->SetSubWindowZLevelToProperty();
2699 int32_t zLevel = mainWindowSessionImpl->property_->zLevel_;
2700 EXPECT_EQ(1, zLevel);
2701
2702 sptr<WindowSessionImpl> subWindowSessionImpl = sptr<WindowSessionImpl>::MakeSptr(option);
2703 subWindowSessionImpl->SetSubWindowZLevelToProperty();
2704 zLevel = subWindowSessionImpl->property_->zLevel_;
2705 EXPECT_EQ(1, zLevel);
2706 }
2707 } // namespace
2708 } // namespace Rosen
2709 } // namespace OHOS
2710