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