1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include "ability_context_impl.h"
18 #include "mock_session.h"
19 #include "window_session_impl.h"
20 #include "mock_uicontent.h"
21 #include "window_scene_session_impl.h"
22 #include "mock_window_adapter.h"
23 #include "singleton_mocker.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Rosen {
30 using Mocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
31 uint32_t MaxWith = 32;
32 class MockWindowChangeListener : public IWindowChangeListener {
33 public:
34 MOCK_METHOD3(OnSizeChange,
35 void(Rect rect, WindowSizeChangeReason reason, const std::shared_ptr<RSTransaction> &rsTransaction));
36 };
37
38 class MockWindowLifeCycleListener : public IWindowLifeCycle {
39 public:
40 MOCK_METHOD0(AfterForeground, void(void));
41 MOCK_METHOD0(AfterBackground, void(void));
42 MOCK_METHOD0(AfterFocused, void(void));
43 MOCK_METHOD0(AfterUnfocused, void(void));
44 MOCK_METHOD1(ForegroundFailed, void(int32_t));
45 MOCK_METHOD0(AfterActive, void(void));
46 MOCK_METHOD0(AfterInactive, void(void));
47 };
48
49 class WindowSceneSessionImplTest : 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 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
58
59 private:
60 RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
61 };
62
SetUpTestCase()63 void WindowSceneSessionImplTest::SetUpTestCase() {}
64
TearDownTestCase()65 void WindowSceneSessionImplTest::TearDownTestCase() {}
66
SetUp()67 void WindowSceneSessionImplTest::SetUp()
68 {
69 abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
70 }
71
TearDown()72 void WindowSceneSessionImplTest::TearDown()
73 {
74 abilityContext_ = nullptr;
75 }
76
CreateRSSurfaceNode()77 RSSurfaceNode::SharedPtr WindowSceneSessionImplTest::CreateRSSurfaceNode()
78 {
79 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
80 rsSurfaceNodeConfig.SurfaceNodeName = "startingWindowTestSurfaceNode";
81 auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig, RSSurfaceNodeType::DEFAULT);
82 return surfaceNode;
83 }
84
85 namespace {
86 /**
87 * @tc.name: CreateWindowAndDestroy01
88 * @tc.desc: Create window and destroy window
89 * @tc.type: FUNC
90 */
91 HWTEST_F(WindowSceneSessionImplTest, CreateWindowAndDestroy01, Function | SmallTest | Level2)
92 {
93 sptr<WindowOption> option = new (std::nothrow) WindowOption();
94 option->SetWindowName("CreateWindow01");
95 sptr<WindowSceneSessionImpl> window = new WindowSceneSessionImpl(option);
96
97 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
98 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
99 ASSERT_NE(nullptr, session);
100
101 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
102 ASSERT_EQ(WMError::WM_ERROR_REPEAT_OPERATION, window->Create(abilityContext_, session));
103 window->property_->SetPersistentId(1);
104 ASSERT_EQ(WMError::WM_OK, window->Destroy(false));
105 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
106 }
107
108 /**
109 * @tc.name: CreateAndConnectSpecificSession01
110 * @tc.desc: CreateAndConnectSpecificSession
111 * @tc.type: FUNC
112 */
113 HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession01, Function | SmallTest | Level2)
114 {
115 sptr<WindowOption> option = new (std::nothrow) WindowOption();
116 option->SetWindowName("CreateAndConnectSpecificSession01");
117 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
118 ASSERT_NE(nullptr, windowscenesession);
119
120 windowscenesession->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
121 if (windowscenesession->CreateAndConnectSpecificSession() == WMError::WM_ERROR_NULLPTR)
122 {
123 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, windowscenesession->CreateAndConnectSpecificSession());
124 }
125 windowscenesession->property_->SetPersistentId(102);
126 windowscenesession->property_->SetParentPersistentId(100);
127 windowscenesession->property_->SetParentId(100);
128 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
129 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
130 ASSERT_NE(nullptr, session);
131
132 ASSERT_EQ(WMError::WM_OK, windowscenesession->Create(abilityContext_, session));
133 }
134
135 /**
136 * @tc.name: CreateAndConnectSpecificSession02
137 * @tc.desc: CreateAndConnectSpecificSession
138 * @tc.type: FUNC
139 */
140 HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession02, Function | SmallTest | Level2)
141 {
142 sptr<WindowOption> option_ = new (std::nothrow) WindowOption();
143 option_->SetWindowTag(WindowTag::SUB_WINDOW);
144 option_->SetWindowName("ChildWindow0002");
145 sptr<WindowSceneSessionImpl> parentscenesession_ = new (std::nothrow) WindowSceneSessionImpl(option_);
146 ASSERT_NE(nullptr, parentscenesession_);
147
148 SessionInfo sessionInfo_ = { "CreateTestBundle0", "CreateTestModule0", "CreateTestAbility0" };
149 sptr<SessionMocker> session_ = new (std::nothrow) SessionMocker(sessionInfo_);
150 ASSERT_NE(nullptr, session_);
151 ASSERT_EQ(WMError::WM_OK, parentscenesession_->Create(abilityContext_, session_));
152
153 parentscenesession_->property_->SetParentPersistentId(102);
154 parentscenesession_->property_->SetParentId(102);
155 parentscenesession_->property_->type_ = WindowType::APP_MAIN_WINDOW_BASE;
156 parentscenesession_->hostSession_ = session_;
157
158 parentscenesession_->property_->type_ = WindowType::APP_SUB_WINDOW_BASE;
159 if (parentscenesession_->CreateAndConnectSpecificSession() == WMError::WM_OK) {
160 ASSERT_EQ(WMError::WM_OK, parentscenesession_->CreateAndConnectSpecificSession());
161 }
162 }
163
164 /**
165 * @tc.name: IsValidSystemWindowType01
166 * @tc.desc: IsValidSystemWindowType
167 * @tc.type: FUNC
168 */
169 HWTEST_F(WindowSceneSessionImplTest, IsValidSystemWindowType01, Function | SmallTest | Level2)
170 {
171 sptr<WindowOption> option = new (std::nothrow) WindowOption();
172 option->SetWindowName("Connect01");
173 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
174 ASSERT_NE(nullptr, windowscenesession);
175 ASSERT_FALSE(!windowscenesession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW));
176 ASSERT_FALSE(!windowscenesession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT));
177 ASSERT_FALSE(!windowscenesession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA));
178 ASSERT_FALSE(!windowscenesession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_DIALOG));
179 ASSERT_FALSE(!windowscenesession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_FLOAT));
180 ASSERT_FALSE(!windowscenesession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_SCREENSHOT));
181 ASSERT_FALSE(!windowscenesession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_VOICE_INTERACTION));
182 ASSERT_FALSE(!windowscenesession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_POINTER));
183 ASSERT_FALSE(!windowscenesession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_TOAST));
184 ASSERT_TRUE(!windowscenesession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_DOCK_SLICE));
185 ASSERT_TRUE(!windowscenesession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_APP_LAUNCHING));
186 }
187
188 /*
189 * @tc.name: InvalidWindow
190 * @tc.desc: InvalidWindow test
191 * @tc.type: FUNC
192 */
193 HWTEST_F(WindowSceneSessionImplTest, InvalidWindow, Function | SmallTest | Level3)
194 {
195 sptr<WindowOption> option = new (std::nothrow) WindowOption();
196 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
197 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->MoveTo(0, 0));
198 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Resize(0, 0));
199 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetBackgroundColor(std::string("???")));
200 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetTransparent(false));
201 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Show(2, false));
202 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Resize(2, 2));
203 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Minimize());
204 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Maximize());
205 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->MaximizeFloating());
206 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Recover());
207 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->MaximizeFloating());
208 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetGlobalMaximizeMode(MaximizeMode::MODE_AVOID_SYSTEM_BAR));
209 }
210
211 /**
212 * @tc.name: FindParentSessionByParentId01
213 * @tc.desc: FindParentSessionByParentId
214 * @tc.type: FUNC
215 */
216 HWTEST_F(WindowSceneSessionImplTest, FindParentSessionByParentId01, Function | SmallTest | Level2)
217 {
218 sptr<WindowOption> option = new (std::nothrow) WindowOption();
219 option->SetWindowTag(WindowTag::MAIN_WINDOW);
220 option->SetWindowName("FindParentSessionByParentId01");
221 sptr<WindowSceneSessionImpl> parentscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
222 ASSERT_NE(nullptr, parentscenesession);
223
224 parentscenesession->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
225 ASSERT_TRUE(parentscenesession->FindMainWindowWithContext() == nullptr);
226 parentscenesession->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_END);
227 ASSERT_TRUE(parentscenesession->FindMainWindowWithContext() == nullptr);
228
229 parentscenesession->property_->SetPersistentId(1112);
230 parentscenesession->property_->SetParentId(1000);
231 parentscenesession->property_->SetParentPersistentId(1000);
232 parentscenesession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
233 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
234 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
235 ASSERT_NE(nullptr, session);
236
237 ASSERT_EQ(WMError::WM_OK, parentscenesession->Create(abilityContext_, session));
238 parentscenesession->hostSession_ = session;
239 ASSERT_TRUE(nullptr != parentscenesession->FindParentSessionByParentId(1112));
240 }
241
242 /**
243 * @tc.name: FindMainWindowWithContext01
244 * @tc.desc: FindMainWindowWithContext
245 * @tc.type: FUNC
246 */
247 HWTEST_F(WindowSceneSessionImplTest, FindMainWindowWithContext01, Function | SmallTest | Level2)
248 {
249 sptr<WindowOption> option = new (std::nothrow) WindowOption();
250 option->SetWindowTag(WindowTag::MAIN_WINDOW);
251 option->SetWindowName("FindMainWindowWithContext01");
252 sptr<WindowSceneSessionImpl> parentscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
253 ASSERT_NE(nullptr, parentscenesession);
254
255 parentscenesession->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
256 ASSERT_TRUE(parentscenesession->FindMainWindowWithContext() == nullptr);
257 parentscenesession->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_END);
258 ASSERT_TRUE(parentscenesession->FindMainWindowWithContext() == nullptr);
259
260 parentscenesession->property_->SetPersistentId(1002);
261 parentscenesession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
262 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
263 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
264 ASSERT_NE(nullptr, session);
265
266 ASSERT_EQ(WMError::WM_OK, parentscenesession->Create(abilityContext_, session));
267 parentscenesession->hostSession_ = session;
268 ASSERT_TRUE(nullptr != parentscenesession->FindParentSessionByParentId(1002));
269
270 sptr<WindowOption> option_ = new (std::nothrow) WindowOption();
271 option_->SetWindowTag(WindowTag::MAIN_WINDOW);
272 option_->SetWindowName("FindMainWindowWithContext02");
273 sptr<WindowSceneSessionImpl> parentscenesession_ = new (std::nothrow) WindowSceneSessionImpl(option_);
274 ASSERT_NE(nullptr, parentscenesession_);
275
276 SessionInfo sessionInfo_ = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
277 sptr<SessionMocker> session_ = new (std::nothrow) SessionMocker(sessionInfo_);
278 ASSERT_NE(nullptr, session_);
279 ASSERT_EQ(WMError::WM_OK, parentscenesession_->Create(abilityContext_, session_));
280
281 parentscenesession_->hostSession_ = session_;
282 parentscenesession_->property_->type_ = WindowType::WINDOW_TYPE_DIALOG;
283 ASSERT_FALSE(parentscenesession_->FindMainWindowWithContext() == nullptr);
284 }
285
286 /**
287 * @tc.name: DisableAppWindowDecor01
288 * @tc.desc: DisableAppWindowDecor
289 * @tc.type: FUNC
290 */
291 HWTEST_F(WindowSceneSessionImplTest, DisableAppWindowDecor01, Function | SmallTest | Level3)
292 {
293 sptr<WindowOption> option = new (std::nothrow) WindowOption();
294 option->SetWindowName("Connect01");
295 sptr<WindowSessionImpl> windowession = new (std::nothrow) WindowSessionImpl(option);
296 ASSERT_NE(nullptr, windowession);
297
298 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
299 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
300
301 ASSERT_NE(nullptr, session);
302 std::shared_ptr<AbilityRuntime::Context> context;
303 ASSERT_EQ(WMError::WM_OK, windowession->Create(context, session));
304
305 windowession->UpdateDecorEnable(false);
306 windowession->windowSystemConfig_.isSystemDecorEnable_ = false;
307
308 windowession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
309 windowession->DisableAppWindowDecor();
310 ASSERT_FALSE(windowession->IsDecorEnable());
311 windowession->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
312 windowession->DisableAppWindowDecor();
313 }
314
315 /**
316 * @tc.name: HandleBackEvent01
317 * @tc.desc: HandleBackEvent
318 * @tc.type: FUNC
319 */
320 HWTEST_F(WindowSceneSessionImplTest, HandleBackEvent01, Function | SmallTest | Level3)
321 {
322 sptr<WindowOption> option = new (std::nothrow) WindowOption();
323 option->SetWindowName("Connect01");
324 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
325 ASSERT_NE(nullptr, windowscenesession);
326
327 windowscenesession->uiContent_ = std::make_unique<Ace::UIContentMocker>();
328 ASSERT_EQ(WSError::WS_OK, windowscenesession->HandleBackEvent());
329 }
330
331 /**
332 * @tc.name: RaiseToAppTop01
333 * @tc.desc: RaiseToAppTop
334 * @tc.type: FUNC
335 */
336 HWTEST_F(WindowSceneSessionImplTest, RaiseToAppTop01, Function | SmallTest | Level2)
337 {
338 sptr<WindowOption> option = new (std::nothrow) WindowOption();
339 option->SetWindowName("Connect01");
340 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
341 ASSERT_NE(nullptr, windowscenesession);
342
343 windowscenesession->property_->SetPersistentId(6);
344 windowscenesession->property_->SetParentPersistentId(6);
345 windowscenesession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
346 ASSERT_EQ(WmErrorCode::WM_ERROR_INVALID_CALLING, windowscenesession->RaiseToAppTop());
347
348 windowscenesession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
349 windowscenesession->state_ = WindowState::STATE_HIDDEN;
350 ASSERT_EQ(WmErrorCode::WM_ERROR_STATE_ABNORMALLY, windowscenesession->RaiseToAppTop());
351
352 windowscenesession->state_ = WindowState::STATE_SHOWN;
353 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
354 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
355 ASSERT_NE(nullptr, session);
356 windowscenesession->hostSession_ = session;
357 ASSERT_EQ(WmErrorCode::WM_OK, windowscenesession->RaiseToAppTop());
358 }
359
360 /**
361 * @tc.name: Resize01
362 * @tc.desc: Resize
363 * @tc.type: FUNC
364 */
365 HWTEST_F(WindowSceneSessionImplTest, Resize01, Function | SmallTest | Level2)
366 {
367 sptr<WindowOption> option = new (std::nothrow) WindowOption();
368 option->SetWindowName("Resize01");
369 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
370 ASSERT_NE(nullptr, windowscenesession);
371
372 windowscenesession->property_->SetPersistentId(888);
373 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
374 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
375 ASSERT_NE(nullptr, session);
376 windowscenesession->hostSession_ = session;
377 Rect rect = {2, 2, 2, 2};
378 windowscenesession->property_->SetWindowRect(rect);
379 windowscenesession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
380 windowscenesession->state_ = WindowState::STATE_FROZEN;
381 windowscenesession->hostSession_ = session;
382 ASSERT_EQ(WMError::WM_OK, windowscenesession->Resize(1, 1));
383 }
384
385 /**
386 * @tc.name: MoveTo01
387 * @tc.desc: MoveTo
388 * @tc.type: FUNC
389 */
390 HWTEST_F(WindowSceneSessionImplTest, MoveTo01, Function | SmallTest | Level2)
391 {
392 sptr<WindowOption> option = new (std::nothrow) WindowOption();
393 option->SetWindowName("MoveTo01");
394 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
395 ASSERT_NE(nullptr, windowscenesession);
396
397 windowscenesession->property_->SetPersistentId(1);
398 windowscenesession->state_ = WindowState::STATE_HIDDEN;
399 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
400 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
401 ASSERT_NE(nullptr, session);
402 windowscenesession->hostSession_ = session;
403 ASSERT_EQ(WMError::WM_OK, windowscenesession->MoveTo(2, 2));
404 }
405
406 /**
407 * @tc.name: Minimize01
408 * @tc.desc: Minimize
409 * @tc.type: FUNC
410 */
411 HWTEST_F(WindowSceneSessionImplTest, Minimize01, Function | SmallTest | Level2)
412 {
413 sptr<WindowOption> option = new (std::nothrow) WindowOption();
414 option->SetWindowName("Connect01");
415 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
416 ASSERT_NE(nullptr, windowscenesession);
417
418 windowscenesession->property_->SetPersistentId(1);
419 windowscenesession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
420 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
421 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
422 ASSERT_NE(nullptr, session);
423 windowscenesession->hostSession_ = session;
424 ASSERT_EQ(WMError::WM_OK, windowscenesession->Minimize());
425 }
426
427 /**
428 * @tc.name: StartMove01
429 * @tc.desc: StartMove
430 * @tc.type: FUNC
431 */
432 HWTEST_F(WindowSceneSessionImplTest, StartMove01, Function | SmallTest | Level2)
433 {
434 sptr<WindowOption> option = new (std::nothrow) WindowOption();
435 option->SetWindowName("Connect01");
436 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
437 ASSERT_NE(nullptr, windowscenesession);
438 windowscenesession->property_->SetPersistentId(1);
439 // show with null session
440
441 windowscenesession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
442 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
443 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
444 windowscenesession->hostSession_ = session;
445 windowscenesession->StartMove();
446 ASSERT_NE(nullptr, session);
447 }
448
449 /**
450 * @tc.name: Close01
451 * @tc.desc: Close
452 * @tc.type: FUNC
453 */
454 HWTEST_F(WindowSceneSessionImplTest, Close01, Function | SmallTest | Level2)
455 {
456 sptr<WindowOption> option = new (std::nothrow) WindowOption();
457 option->SetWindowName("Connect01");
458 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
459 ASSERT_NE(nullptr, windowscenesession);
460 windowscenesession->property_->SetPersistentId(1);
461 windowscenesession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
462 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
463 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
464 ASSERT_NE(nullptr, session);
465 windowscenesession->hostSession_ = session;
466 ASSERT_EQ(WMError::WM_OK, windowscenesession->Close());
467 }
468
469 /**
470 * @tc.name: SetActive01
471 * @tc.desc: SetActive
472 * @tc.type: FUNC
473 */
474 HWTEST_F(WindowSceneSessionImplTest, SetActive01, Function | SmallTest | Level2)
475 {
476 sptr<WindowOption> option = new (std::nothrow) WindowOption();
477 option->SetWindowName("Connect01");
478 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
479 ASSERT_NE(nullptr, windowscenesession);
480 windowscenesession->property_->SetPersistentId(1);
481 windowscenesession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
482 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
483 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
484 ASSERT_NE(nullptr, session);
485
486 windowscenesession->hostSession_ = session;
487 ASSERT_EQ(WSError::WS_OK, windowscenesession->SetActive(false));
488 }
489
490 /**
491 * @tc.name: Recover01
492 * @tc.desc: Recover
493 * @tc.type: FUNC
494 */
495 HWTEST_F(WindowSceneSessionImplTest, Recover01, Function | SmallTest | Level2)
496 {
497 sptr<WindowOption> option = new (std::nothrow) WindowOption();
498 option->SetWindowName("Connect01");
499 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
500 ASSERT_NE(nullptr, windowscenesession);
501
502 windowscenesession->property_->SetPersistentId(1);
503 windowscenesession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
504 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
505 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
506 ASSERT_NE(nullptr, session);
507 windowscenesession->hostSession_ = session;
508 ASSERT_EQ(WMError::WM_OK, windowscenesession->Recover());
509 }
510
511 /**
512 * @tc.name: Maximize01
513 * @tc.desc: Maximize
514 * @tc.type: FUNC
515 */
516 HWTEST_F(WindowSceneSessionImplTest, Maximize01, Function | SmallTest | Level2)
517 {
518 sptr<WindowOption> option = new (std::nothrow) WindowOption();
519 option->SetWindowName("Connect01");
520 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
521 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
522 ASSERT_NE(nullptr, windowscenesession);
523 windowscenesession->property_->SetPersistentId(1);
524 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
525 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
526 ASSERT_NE(nullptr, session);
527 windowscenesession->hostSession_ = session;
528 ASSERT_EQ(WMError::WM_OK, windowscenesession->Maximize());
529 }
530
531 /**
532 * @tc.name: Hide01
533 * @tc.desc: Hide session
534 * @tc.type: FUNC
535 */
536 HWTEST_F(WindowSceneSessionImplTest, Hide01, Function | SmallTest | Level2)
537 {
538 sptr<WindowOption> option = new (std::nothrow) WindowOption();
539 option->SetWindowName("Hide01");
540 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
541 ASSERT_NE(nullptr, window);
542 window->property_->SetPersistentId(1);
543 // show with null session
544 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Hide(2, false, false));
545
546 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
547 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
548 ASSERT_NE(nullptr, session);
549 window->hostSession_ = session;
550 ASSERT_EQ(WMError::WM_OK, window->Hide(2, false, false));
551 ASSERT_EQ(WMError::WM_OK, window->Hide(2, false, false));
552
553 window->state_ = WindowState::STATE_CREATED;
554 ASSERT_EQ(WMError::WM_OK, window->Hide(2, false, false));
555 window->state_ = WindowState::STATE_SHOWN;
556 window->property_->type_ = WindowType::APP_SUB_WINDOW_BASE;
557 ASSERT_EQ(WMError::WM_OK, window->Hide(2, false, false));
558
559 window->property_->type_ = WindowType::APP_SUB_WINDOW_BASE;
560 if (window->Destroy(false) == WMError::WM_OK) {
561 ASSERT_EQ(WMError::WM_OK, window->Destroy(false));
562 }
563 }
564
565 /**
566 * @tc.name: Show01
567 * @tc.desc: Show session
568 * @tc.type: FUNC
569 */
570 HWTEST_F(WindowSceneSessionImplTest, Show01, Function | SmallTest | Level2)
571 {
572 sptr<WindowOption> option = new (std::nothrow) WindowOption();
573 option->SetWindowName("Show01");
574 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
575 ASSERT_NE(nullptr, window);
576 window->property_->SetPersistentId(1);
577
578 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
579 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
580 ASSERT_NE(nullptr, session);
581
582 window->hostSession_ = session;
583 ASSERT_EQ(WMError::WM_OK, window->Show(2, false));
584
585 window->state_ = WindowState::STATE_CREATED;
586 ASSERT_EQ(WMError::WM_OK, window->Show(2, false));
587 ASSERT_EQ(WMError::WM_OK, window->Destroy(false));
588 }
589
590 /**
591 * @tc.name: SetBackgroundColor01
592 * @tc.desc: test SetBackgroundColor withow uiContent
593 * @tc.type: FUNC
594 */
595 HWTEST_F(WindowSceneSessionImplTest, SetBackgroundColor01, Function | SmallTest | Level3)
596 {
597 sptr<WindowOption> option = new (std::nothrow) WindowOption();
598 option->SetWindowName("SetBackgroundColor01");
599 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
600 option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
601 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
602 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
603 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
604 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
605 ASSERT_NE(nullptr, session);
606
607 std::shared_ptr<AbilityRuntime::Context> context;
608 ASSERT_EQ(WMError::WM_OK, window->Create(context, session));
609
610 window->property_->SetPersistentId(1);
611 window->Show();
612 }
613
614 /*
615 * @tc.name: SetTransparent
616 * @tc.desc: SetTransparent test
617 * @tc.type: FUNC
618 */
619 HWTEST_F(WindowSceneSessionImplTest, SetTransparent, Function | SmallTest | Level3)
620 {
621 sptr<WindowOption> option = new (std::nothrow) WindowOption();
622 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
623 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetTransparent(true));
624 window->property_->SetPersistentId(1);
625 option->SetWindowName("SetTransparent");
626 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
627 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
628 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
629 ASSERT_NE(nullptr, session);
630 window->hostSession_ = session;
631 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
632 window->SetBackgroundColor(333);
633 if (window->SetTransparent(true) == WMError::WM_OK) {
634 ASSERT_EQ(WMError::WM_OK, window->SetTransparent(true));
635 }
636 }
637
638 /*
639 * @tc.name: SetAspectRatio
640 * @tc.desc: SetAspectRatio test
641 * @tc.type: FUNC
642 */
643 HWTEST_F(WindowSceneSessionImplTest, SetAspectRatio, Function | SmallTest | Level3)
644 {
645 sptr<WindowOption> option = new (std::nothrow) WindowOption();
646 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
647 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
648 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetAspectRatio(0.1));
649
650 window->property_->SetPersistentId(1);
651 window->property_->SetDisplayId(3);
652 WindowLimits windowLimits = { 3, 3, 3, 3, 2.0, 2.0 };
653 window->property_->SetWindowLimits(windowLimits);
654 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
655 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
656 ASSERT_NE(nullptr, session);
657 window->hostSession_ = session;
658 ASSERT_EQ(WMError::WM_OK, window->SetAspectRatio(0.1));
659 }
660
661 /*
662 * @tc.name: ResetAspectRatio
663 * @tc.desc: ResetAspectRatio test GetAvoidAreaByType
664 * @tc.type: FUNC
665 */
666 HWTEST_F(WindowSceneSessionImplTest, ResetAspectRatio, Function | SmallTest | Level3)
667 {
668 sptr<WindowOption> option = new (std::nothrow) WindowOption();
669 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
670 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
671 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
672 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
673 ASSERT_NE(nullptr, session);
674 window->hostSession_ = session;
675 ASSERT_EQ(WMError::WM_OK, window->ResetAspectRatio());
676 }
677
678 /*
679 * @tc.name: GetAvoidAreaByType
680 * @tc.desc: GetAvoidAreaByType test
681 * @tc.type: FUNC
682 */
683 HWTEST_F(WindowSceneSessionImplTest, GetAvoidAreaByType, Function | SmallTest | Level3)
684 {
685 sptr<WindowOption> option = new (std::nothrow) WindowOption();
686 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
687 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
688
689 window->property_->SetPersistentId(1);
690 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
691 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
692 ASSERT_NE(nullptr, session);
693 AvoidArea avoidarea;
694 ASSERT_EQ(WMError::WM_OK, window->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT, avoidarea));
695 }
696
697 /*
698 * @tc.name: Immersive
699 * @tc.desc: Immersive01 test
700 * @tc.type: FUNC
701 */
702 HWTEST_F(WindowSceneSessionImplTest, Immersive, Function | SmallTest | Level3)
703 {
704 sptr<WindowOption> option = new (std::nothrow) WindowOption();
705 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
706 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
707
708
709 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetLayoutFullScreen(false));
710 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetFullScreen(false));
711 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
712 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
713 ASSERT_NE(nullptr, session);
714 window->hostSession_ = session;
715
716 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetFullScreen(false));
717 ASSERT_EQ(false, window->IsLayoutFullScreen());
718 ASSERT_EQ(false, window->IsFullScreen());
719 }
720
721 /*
722 * @tc.name: SystemBarProperty
723 * @tc.desc: SystemBarProperty01 test
724 * @tc.type: FUNC
725 */
726 HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty, Function | SmallTest | Level3)
727 {
728 sptr<WindowOption> option = new (std::nothrow) WindowOption();
729 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
730 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
731
732 SystemBarProperty property = SystemBarProperty();
733 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW,
734 window->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
735 }
736
737 /*
738 * @tc.name: LimitCameraFloatWindowMininumSize
739 * @tc.desc: LimitCameraFloatWindowMininumSize01 test
740 * @tc.type: FUNC
741 */
742 HWTEST_F(WindowSceneSessionImplTest, LimitCameraFloatWindowMininumSize, Function | SmallTest | Level3)
743 {
744 sptr<WindowOption> option = new (std::nothrow) WindowOption();
745 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
746 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
747 uint32_t width = 33;
748 uint32_t height = 31;
749 window->LimitCameraFloatWindowMininumSize(width, height);
750 }
751
752 /*
753 * @tc.name: NotifyWindowNeedAvoid
754 * @tc.desc: NotifyWindowNeedAvoid test
755 * @tc.type: FUNC
756 */
757 HWTEST_F(WindowSceneSessionImplTest, NotifyWindowNeedAvoid, Function | SmallTest | Level3)
758 {
759 sptr<WindowOption> option = new (std::nothrow) WindowOption();
760 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
761 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->NotifyWindowNeedAvoid(false));
762
763 window->state_ = WindowState::STATE_SHOWN;
764 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
765 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
766 ASSERT_NE(nullptr, session);
767 window->property_->SetPersistentId(190);
768 window->hostSession_ = session;
769 ASSERT_EQ(WMError::WM_OK, window->NotifyWindowNeedAvoid(false));
770 }
771
772 /*
773 * @tc.name: SetLayoutFullScreenByApiVersion
774 * @tc.desc: SetLayoutFullScreenByApiVersion test
775 * @tc.type: FUNC
776 */
777 HWTEST_F(WindowSceneSessionImplTest, SetLayoutFullScreenByApiVersion, Function | SmallTest | Level3)
778 {
779 sptr<WindowOption> option = new (std::nothrow) WindowOption();
780 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
781 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetLayoutFullScreenByApiVersion(false));
782 window->state_ = WindowState::STATE_SHOWN;
783 window->property_->SetPersistentId(190);
784 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
785 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
786 ASSERT_NE(nullptr, session);
787 window->hostSession_ = session;
788 ASSERT_EQ(WMError::WM_OK, window->SetLayoutFullScreenByApiVersion(false));
789 }
790
791 /*
792 * @tc.name: SetGlobalMaximizeMode
793 * @tc.desc: SetGlobalMaximizeMode test
794 * @tc.type: FUNC
795 */
796 HWTEST_F(WindowSceneSessionImplTest, SetGlobalMaximizeMode, Function | SmallTest | Level3)
797 {
798 sptr<WindowOption> option = new (std::nothrow) WindowOption();
799 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
800 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetGlobalMaximizeMode(MaximizeMode::MODE_RECOVER));
801
802 window->state_ = WindowState::STATE_SHOWN;
803 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
804 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
805 ASSERT_NE(nullptr, session);
806 window->property_->SetPersistentId(190);
807 window->hostSession_ = session;
808 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
809 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetGlobalMaximizeMode(MaximizeMode::MODE_RECOVER));
810
811 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
812 ASSERT_EQ(WMError::WM_OK, window->SetGlobalMaximizeMode(MaximizeMode::MODE_RECOVER));
813 }
814
815 /*
816 * @tc.name: CheckParmAndPermission
817 * @tc.desc: CheckParmAndPermission test
818 * @tc.type: FUNC
819 */
820 HWTEST_F(WindowSceneSessionImplTest, CheckParmAndPermission, Function | SmallTest | Level3)
821 {
822 sptr<WindowOption> option = new (std::nothrow) WindowOption();
823 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
824 window->property_->SetWindowName("CheckParmAndPermission");
825 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
826
827 auto surfaceNode = window->GetSurfaceNode();
828 if (surfaceNode == nullptr) {
829 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->CheckParmAndPermission());
830 } else {
831 ASSERT_EQ(WMError::WM_OK, window->CheckParmAndPermission());
832 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
833 ASSERT_EQ(WMError::WM_OK, window->CheckParmAndPermission());
834 }
835 }
836
837 /*
838 * @tc.name: SetBackdropBlurStyle
839 * @tc.desc: SetBackdropBlurStyle test
840 * @tc.type: FUNC
841 */
842 HWTEST_F(WindowSceneSessionImplTest, SetBackdropBlurStyle, Function | SmallTest | Level3)
843 {
844 sptr<WindowOption> option = new (std::nothrow) WindowOption();
845 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
846 window->property_->SetWindowName("SetBackdropBlurStyle");
847 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
848 window->property_->SetDisplayId(3);
849
850 auto surfaceNode = window->GetSurfaceNode();
851 if (surfaceNode == nullptr) {
852 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->CheckParmAndPermission());
853 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_OFF));
854 } else {
855 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_OFF));
856 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THICK));
857 }
858 }
859
860 /*
861 * @tc.name: SetTurnScreenOn
862 * @tc.desc: SetTurnScreenOn test
863 * @tc.type: FUNC
864 */
865 HWTEST_F(WindowSceneSessionImplTest, SetTurnScreenOn, Function | SmallTest | Level3)
866 {
867 sptr<WindowOption> option = new (std::nothrow) WindowOption();
868 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
869 window->property_->SetWindowName("SetBackdropBlurStyle");
870 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
871 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetTurnScreenOn(false));
872
873 window->property_->SetPersistentId(1);
874 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
875 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
876 ASSERT_NE(nullptr, session);
877 window->hostSession_ = session;
878 ASSERT_EQ(WMError::WM_OK, window->SetTurnScreenOn(false));
879 }
880
881 /*
882 * @tc.name: SetBlur
883 * @tc.desc: SetBlur test
884 * @tc.type: FUNC
885 */
886 HWTEST_F(WindowSceneSessionImplTest, SetBlur, Function | SmallTest | Level3)
887 {
888 sptr<WindowOption> option = new (std::nothrow) WindowOption();
889 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
890 window->property_->SetWindowName("SetBlur");
891
892 auto surfaceNode = window->GetSurfaceNode();
893 if (surfaceNode == nullptr) {
894 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->CheckParmAndPermission());
895 } else {
896 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
897 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBlur(-1.0));
898 ASSERT_EQ(WMError::WM_OK, window->SetBlur(1.0));
899 }
900 }
901
902 /*
903 * @tc.name: SetKeepScreenOn
904 * @tc.desc: SetKeepScreenOn test
905 * @tc.type: FUNC
906 */
907 HWTEST_F(WindowSceneSessionImplTest, SetKeepScreenOn, Function | SmallTest | Level3)
908 {
909 sptr<WindowOption> option = new (std::nothrow) WindowOption();
910 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
911 window->property_->SetWindowName("SetKeepScreenOn");
912 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
913 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetKeepScreenOn(false));
914
915 window->property_->SetPersistentId(1);
916 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
917 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
918 ASSERT_NE(nullptr, session);
919 window->hostSession_ = session;
920 ASSERT_EQ(WMError::WM_OK, window->SetKeepScreenOn(false));
921 ASSERT_FALSE(window->IsKeepScreenOn());
922 }
923
924 /*
925 * @tc.name: SetPrivacyMode
926 * @tc.desc: SetPrivacyMode test
927 * @tc.type: FUNC
928 */
929 HWTEST_F(WindowSceneSessionImplTest, SetPrivacyMode, Function | SmallTest | Level3)
930 {
931 sptr<WindowOption> option = new (std::nothrow) WindowOption();
932 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
933 window->property_->SetWindowName("SetPrivacyMode");
934 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
935 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetPrivacyMode(false));
936
937 window->property_->SetPersistentId(1);
938 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
939 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
940 ASSERT_NE(nullptr, session);
941 window->hostSession_ = session;
942 if (WMError::WM_OK == window->SetPrivacyMode(false)) {
943 ASSERT_EQ(WMError::WM_OK, window->SetPrivacyMode(false));
944 ASSERT_EQ(false, window->IsPrivacyMode());
945 }else if (WMError::WM_DO_NOTHING == window->SetPrivacyMode(false)) {
946 ASSERT_EQ(WMError::WM_DO_NOTHING, window->SetPrivacyMode(false));
947 }
948 }
949
950 /*
951 * @tc.name: IsPrivacyMode
952 * @tc.desc: IsPrivacyMode test
953 * @tc.type: FUNC
954 */
955 HWTEST_F(WindowSceneSessionImplTest, IsPrivacyModec, Function | SmallTest | Level3)
956 {
957 sptr<WindowOption> option = new (std::nothrow) WindowOption();
958 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
959 window->property_->SetWindowName("IsPrivacyModec");
960 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
961 window->SetPrivacyMode(false);
962 }
963
964 /*
965 * @tc.name: SetSystemPrivacyMode
966 * @tc.desc: SetSystemPrivacyMode test
967 * @tc.type: FUNC
968 */
969 HWTEST_F(WindowSceneSessionImplTest, SetSystemPrivacyMode, Function | SmallTest | Level3)
970 {
971 sptr<WindowOption> option = new (std::nothrow) WindowOption();
972 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
973 window->property_->SetWindowName("SetSystemPrivacyMode");
974 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
975 window->SetSystemPrivacyMode(false);
976 ASSERT_EQ(false, window->property_->GetSystemPrivacyMode());
977 }
978
979 /*
980 * @tc.name: SetSnapshotSkip
981 * @tc.desc: SetSnapshotSkip test
982 * @tc.type: FUNC
983 */
984 HWTEST_F(WindowSceneSessionImplTest, SetSnapshotSkip, Function | SmallTest | Level3)
985 {
986 sptr<WindowOption> option = new (std::nothrow) WindowOption();
987 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
988 window->property_->SetWindowName("SetSnapshotSkip");
989 window->property_->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
990 window->property_->SetPersistentId(1);
991 auto surfaceNode_mocker = CreateRSSurfaceNode();
992 if (surfaceNode_mocker != nullptr) {
993 ASSERT_NE(nullptr, surfaceNode_mocker);
994 }
995
996 window->surfaceNode_ = surfaceNode_mocker;
997 auto surfaceNode = window->GetSurfaceNode();
998
999 if (surfaceNode != nullptr) {
1000 ASSERT_EQ(WMError::WM_OK, window->SetSnapshotSkip(false));
1001 } else {
1002 ASSERT_EQ(nullptr, surfaceNode);
1003 }
1004 }
1005
1006 /*
1007 * @tc.name: SetLayoutFullScreen
1008 * @tc.desc: SetLayoutFullScreen test
1009 * @tc.type: FUNC
1010 */
1011 HWTEST_F(WindowSceneSessionImplTest, SetLayoutFullScreen, Function | SmallTest | Level3)
1012 {
1013 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1014 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1015 window->property_->SetWindowName("SetLayoutFullScreen");
1016 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1017 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetLayoutFullScreen(false));
1018
1019 window->property_->SetPersistentId(1);
1020 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1021 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1022 ASSERT_NE(nullptr, session);
1023 window->hostSession_ = session;
1024 ASSERT_EQ(WMError::WM_OK, window->SetLayoutFullScreen(false));
1025 ASSERT_EQ(false, window->IsLayoutFullScreen());
1026 }
1027
1028 /*
1029 * @tc.name: SetFullScreen
1030 * @tc.desc: SetFullScreen test
1031 * @tc.type: FUNC
1032 */
1033 HWTEST_F(WindowSceneSessionImplTest, SetFullScreen, Function | SmallTest | Level3)
1034 {
1035 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1036 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1037 window->property_->SetWindowName("SetFullScreen");
1038 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1039 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetFullScreen(false));
1040 window->property_->SetPersistentId(1);
1041 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1042 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1043 ASSERT_NE(nullptr, session);
1044 window->hostSession_ = session;
1045
1046 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetFullScreen(false));
1047 ASSERT_EQ(false, window->IsFullScreen());
1048 }
1049
1050 /*
1051 * @tc.name: SetShadowOffsetX
1052 * @tc.desc: SetShadowOffsetX test
1053 * @tc.type: FUNC
1054 */
1055 HWTEST_F(WindowSceneSessionImplTest, SetShadowOffsetX, Function | SmallTest | Level3)
1056 {
1057 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1058 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1059 window->property_->SetWindowName("SetKeepScreenOn");
1060 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1061 auto surfaceNode = window->GetSurfaceNode();
1062 if (surfaceNode == nullptr) {
1063 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->CheckParmAndPermission());
1064 } else {
1065 ASSERT_EQ(WMError::WM_OK, window->SetShadowOffsetX(1.0));
1066 }
1067 }
1068
1069 /*
1070 * @tc.name: SetShadowOffsetY
1071 * @tc.desc: SetShadowOffsetY test
1072 * @tc.type: FUNC
1073 */
1074 HWTEST_F(WindowSceneSessionImplTest, SetShadowOffsetY, Function | SmallTest | Level3)
1075 {
1076 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1077 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1078 window->property_->SetWindowName("SetShadowOffsetY");
1079 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1080
1081 auto surfaceNode = window->GetSurfaceNode();
1082 if (surfaceNode == nullptr) {
1083 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->CheckParmAndPermission());
1084 } else {
1085 ASSERT_EQ(WMError::WM_OK, window->SetShadowOffsetY(1.0));
1086 }
1087 }
1088
1089 /*
1090 * @tc.name: SetBackdropBlur
1091 * @tc.desc: SetBackdropBlur test
1092 * @tc.type: FUNC
1093 */
1094 HWTEST_F(WindowSceneSessionImplTest, SetBackdropBlur, Function | SmallTest | Level3)
1095 {
1096 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1097 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1098 window->property_->SetWindowName("SetBackdropBlur");
1099 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1100
1101 auto surfaceNode = window->GetSurfaceNode();
1102 if (surfaceNode == nullptr) {
1103 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->CheckParmAndPermission());
1104 } else {
1105 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlur(-1.0));
1106 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(1.0));
1107 }
1108 }
1109
1110 /*
1111 * @tc.name: SetShadowColor
1112 * @tc.desc: SetShadowColor test
1113 * @tc.type: FUNC
1114 */
1115 HWTEST_F(WindowSceneSessionImplTest, SetShadowColor, Function | SmallTest | Level3)
1116 {
1117 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1118 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1119 window->property_->SetWindowName("SetShadowColor");
1120 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1121
1122 auto surfaceNode = window->GetSurfaceNode();
1123 if (surfaceNode == nullptr) {
1124 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->CheckParmAndPermission());
1125 }else {
1126 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("111ff22ee44"));
1127 ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#ff22ee44"));
1128 ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#000999"));
1129 }
1130 }
1131
1132 /*
1133 * @tc.name: SetCornerRadius
1134 * @tc.desc: SetCornerRadius test
1135 * @tc.type: FUNC
1136 */
1137 HWTEST_F(WindowSceneSessionImplTest, SetCornerRadius, Function | SmallTest | Level3)
1138 {
1139 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1140 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1141 window->property_->SetWindowName("SetCornerRadius");
1142 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1143
1144 auto surfaceNode = window->GetSurfaceNode();
1145 if (surfaceNode == nullptr) {
1146 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetCornerRadius(1.0));
1147 } else {
1148 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(1.0));
1149 }
1150 }
1151
1152 /*
1153 * @tc.name: SetShadowRadius
1154 * @tc.desc: SetShadowRadius test
1155 * @tc.type: FUNC
1156 */
1157 HWTEST_F(WindowSceneSessionImplTest, SetShadowRadius, Function | SmallTest | Level3)
1158 {
1159 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1160 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1161 window->property_->SetWindowName("SetShadowRadius");
1162 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1163
1164 auto surfaceNode = window->GetSurfaceNode();
1165 if (surfaceNode == nullptr) {
1166 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->CheckParmAndPermission());
1167 } else {
1168 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowRadius(-1.0));
1169 ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(1.0));
1170 }
1171 }
1172
1173 /**
1174 * @tc.name: SetTransform01
1175 * @tc.desc: set transform
1176 * @tc.type: FUNC
1177 * @tc.require:issueI7IJVV
1178 */
1179 HWTEST_F(WindowSceneSessionImplTest, SetTransform01, Function | SmallTest | Level3)
1180 {
1181 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1182 sptr<WindowOption> option = new WindowOption();
1183 option->SetWindowName("SetTransform01");
1184 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1185 ASSERT_NE(nullptr, window);
1186 window->property_->SetPersistentId(1);
1187 Transform trans_;
1188 window->SetTransform(trans_);
1189 ASSERT_TRUE(trans_ == window->GetTransform());
1190 ASSERT_EQ(WMError::WM_OK, window->Destroy(false));
1191 }
1192
1193 /**
1194 * @tc.name: RegisterAnimationTransitionController01
1195 * @tc.desc: RegisterAnimationTransitionController
1196 * @tc.type: FUNC
1197 * @tc.require:issueI7IJVV
1198 */
1199 HWTEST_F(WindowSceneSessionImplTest, RegisterAnimationTransitionController01, Function | SmallTest | Level3)
1200 {
1201 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1202 sptr<WindowOption> option = new WindowOption();
1203 option->SetWindowName("RegisterAnimationTransitionController01");
1204 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1205 ASSERT_NE(nullptr, window);
1206 window->property_->SetPersistentId(1);
1207 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->RegisterAnimationTransitionController(nullptr));
1208 }
1209
1210 /**
1211 * @tc.name: SetNeedDefaultAnimation01
1212 * @tc.desc: SetNeedDefaultAnimation
1213 * @tc.type: FUNC
1214 * @tc.require:issueI7IJVV
1215 */
1216 HWTEST_F(WindowSceneSessionImplTest, SetNeedDefaultAnimation01, Function | SmallTest | Level3)
1217 {
1218 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1219 sptr<WindowOption> option = new WindowOption();
1220 option->SetWindowName("SetNeedDefaultAnimation01");
1221 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1222 ASSERT_NE(nullptr, window);
1223 auto ret = true;
1224 window->property_->SetPersistentId(1);
1225
1226 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1227 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1228 ASSERT_NE(nullptr, session);
1229 window->hostSession_ = session;
1230 window->SetNeedDefaultAnimation(false);
1231 ASSERT_TRUE(ret);
1232 }
1233
1234 /**
1235 * @tc.desc: UpdateSurfaceNodeAfterCustomAnimation01
1236 * @tc.desc: UpdateSurfaceNodeAfterCustomAnimation
1237 * @tc.type: FUNC
1238 * @tc.require:issueI7IJVV
1239 */
1240 HWTEST_F(WindowSceneSessionImplTest, UpdateSurfaceNodeAfterCustomAnimation, Function | SmallTest | Level3)
1241 {
1242 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
1243 sptr<WindowOption> option = new WindowOption();
1244 option->SetWindowName("UpdateSurfaceNodeAfterCustomAnimation");
1245 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1246 ASSERT_NE(nullptr, window);
1247
1248 window->property_->SetPersistentId(1);
1249
1250 window->UpdateSurfaceNodeAfterCustomAnimation(false);
1251 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->UpdateSurfaceNodeAfterCustomAnimation(false));
1252 window->property_->SetPersistentId(1);
1253 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1254 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1255 ASSERT_NE(nullptr, session);
1256 window->hostSession_ = session;
1257 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1258 ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, window->UpdateSurfaceNodeAfterCustomAnimation(false));
1259 }
1260
1261 /**
1262 * @tc.name: SetAlpha01
1263 * @tc.desc: SetAlpha
1264 * @tc.type: FUNC
1265 */
1266 HWTEST_F(WindowSceneSessionImplTest, SetAlpha01, Function | SmallTest | Level2)
1267 {
1268 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1269 option->SetWindowName("SetAlpha01");
1270 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1271
1272 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1273
1274 ASSERT_NE(nullptr, windowscenesession);
1275 windowscenesession->property_->SetPersistentId(11);
1276 windowscenesession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1277
1278 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, windowscenesession->SetAlpha(1.0));
1279 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1280 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1281 ASSERT_NE(nullptr, session);
1282
1283 ASSERT_EQ(WMError::WM_OK, windowscenesession->Create(abilityContext_, session));
1284 windowscenesession->hostSession_ = session;
1285
1286 auto surfaceNode = windowscenesession->GetSurfaceNode();
1287 if (surfaceNode == nullptr) {
1288 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, windowscenesession->CheckParmAndPermission());
1289 } else {
1290 ASSERT_EQ(WMError::WM_OK, windowscenesession->SetAlpha(1.0));
1291 }
1292 }
1293
1294 /**
1295 * @tc.name: DestroySubWindow01
1296 * @tc.desc: DestroySubWindow
1297 * @tc.type: FUNC
1298 */
1299 HWTEST_F(WindowSceneSessionImplTest, DestroySubWindow01, Function | SmallTest | Level2)
1300 {
1301 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1302 option->SetWindowName("DestroySubWindow");
1303 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1304
1305 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1306
1307 ASSERT_NE(nullptr, windowscenesession);
1308 int ret = 0;
1309 windowscenesession->DestroySubWindow();
1310 ASSERT_EQ(0, ret);
1311 }
1312
1313 /**
1314 * @tc.name: UpdateFloatingWindowSizeBySizeLimits01
1315 * @tc.desc: UpdateFloatingWindowSizeBySizeLimits
1316 * @tc.type: FUNC
1317 */
1318 HWTEST_F(WindowSceneSessionImplTest, UpdateFloatingWindowSizeBySizeLimits01, Function | SmallTest | Level2)
1319 {
1320 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1321 option->SetWindowName("DestroySubWindow");
1322 option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
1323
1324 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1325 ASSERT_NE(nullptr, windowscenesession);
1326 int ret = 0;
1327 windowscenesession->UpdateFloatingWindowSizeBySizeLimits(MaxWith, MaxWith);
1328 ASSERT_EQ(0, ret);
1329 }
1330
1331 /**
1332 * @tc.name: UpdateAnimationFlagProperty01
1333 * @tc.desc: UpdateAnimationFlagProperty
1334 * @tc.type: FUNC
1335 */
1336 HWTEST_F(WindowSceneSessionImplTest, UpdateAnimationFlagProperty01, Function | SmallTest | Level2)
1337 {
1338 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1339 option->SetWindowName("DestroySubWindow");
1340 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1341
1342 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1343 ASSERT_NE(nullptr, windowscenesession);
1344 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, windowscenesession->UpdateAnimationFlagProperty(false));
1345 }
1346
1347 /**
1348 * @tc.name: UpdateWindowModeImmediately01
1349 * @tc.desc: UpdateWindowModeImmediately
1350 * @tc.type: FUNC
1351 */
1352 HWTEST_F(WindowSceneSessionImplTest, UpdateWindowModeImmediately01, Function | SmallTest | Level2)
1353 {
1354 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1355 option->SetWindowName("DestroySubWindow");
1356 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1357
1358 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1359 ASSERT_NE(nullptr, windowscenesession);
1360 ASSERT_EQ(WMError::WM_OK, windowscenesession->UpdateWindowModeImmediately(WindowMode::WINDOW_MODE_UNDEFINED));
1361 windowscenesession->state_ = WindowState::STATE_CREATED;
1362 ASSERT_EQ(WMError::WM_OK, windowscenesession->UpdateWindowModeImmediately(WindowMode::WINDOW_MODE_UNDEFINED));
1363 }
1364
1365 /**
1366 * @tc.name: UpdateWindowMode01
1367 * @tc.desc: UpdateWindowMode
1368 * @tc.type: FUNC
1369 */
1370 HWTEST_F(WindowSceneSessionImplTest, UpdateWindowMode01, Function | SmallTest | Level2)
1371 {
1372 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1373 option->SetWindowName("DestroySubWindow");
1374 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1375
1376 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1377 ASSERT_NE(nullptr, windowscenesession);
1378 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW,
1379 windowscenesession->UpdateWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
1380 windowscenesession->state_ = WindowState::STATE_CREATED;
1381 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW,
1382 windowscenesession->UpdateWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
1383
1384 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1385 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1386 ASSERT_NE(nullptr, session);
1387 windowscenesession->hostSession_ = session;
1388 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW,
1389 windowscenesession->UpdateWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
1390 }
1391
1392 /**
1393 * @tc.name: RemoveWindowFlag01
1394 * @tc.desc: RemoveWindowFlag
1395 * @tc.type: FUNC
1396 */
1397 HWTEST_F(WindowSceneSessionImplTest, RemoveWindowFlag01, Function | SmallTest | Level2)
1398 {
1399 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1400 option->SetWindowName("DestroySubWindow");
1401 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1402
1403 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1404 ASSERT_NE(nullptr, windowscenesession);
1405 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW,
1406 windowscenesession->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID));
1407 windowscenesession->state_ = WindowState::STATE_CREATED;
1408 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW,
1409 windowscenesession->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID));
1410
1411 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1412 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1413 ASSERT_NE(nullptr, session);
1414 windowscenesession->hostSession_ = session;
1415 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW,
1416 windowscenesession->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID));
1417 }
1418
1419 /**
1420 * @tc.name: GetConfigurationFromAbilityInfo01
1421 * @tc.desc: GetConfigurationFromAbilityInfo
1422 * @tc.type: FUNC
1423 */
1424 HWTEST_F(WindowSceneSessionImplTest, GetConfigurationFromAbilityInfo01, Function | SmallTest | Level2)
1425 {
1426 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1427 option->SetWindowName("GetConfigurationFromAbilityInfo");
1428 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1429 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1430 ASSERT_NE(nullptr, windowscenesession);
1431 int ret = 0;
1432 windowscenesession->GetConfigurationFromAbilityInfo();
1433 ASSERT_EQ(ret, 0);
1434 }
1435
1436 /**
1437 * @tc.name: PreProcessCreate01
1438 * @tc.desc: PreProcessCreate
1439 * @tc.type: FUNC
1440 */
1441 HWTEST_F(WindowSceneSessionImplTest, PreProcessCreate01, Function | SmallTest | Level2)
1442 {
1443 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1444 option->SetWindowName("PreProcessCreate");
1445 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1446 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1447 ASSERT_NE(nullptr, windowscenesession);
1448 int ret = 0;
1449 windowscenesession->PreProcessCreate();
1450 ASSERT_EQ(ret, 0);
1451 }
1452
1453 /**
1454 * @tc.name: SetDefaultProperty01
1455 * @tc.desc: SetDefaultProperty
1456 * @tc.type: FUNC
1457 */
1458 HWTEST_F(WindowSceneSessionImplTest, SetDefaultProperty01, Function | SmallTest | Level2)
1459 {
1460 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1461 option->SetWindowName("PreProcessCreate");
1462 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1463 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1464 ASSERT_NE(nullptr, windowscenesession);
1465 int ret = 0;
1466 windowscenesession->SetDefaultProperty();
1467 ASSERT_EQ(ret, 0);
1468 }
1469
1470 /**
1471 * @tc.name: UpdateConfiguration01
1472 * @tc.desc: UpdateConfiguration
1473 * @tc.type: FUNC
1474 */
1475 HWTEST_F(WindowSceneSessionImplTest, UpdateConfiguration01, Function | SmallTest | Level2)
1476 {
1477 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1478 option->SetWindowName("PreProcessCreate");
1479 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1480 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1481 ASSERT_NE(nullptr, windowscenesession);
1482 int ret = 0;
1483 std::shared_ptr<AppExecFwk::Configuration> configuration;
1484 windowscenesession->UpdateConfiguration(configuration);
1485 windowscenesession->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1486 windowscenesession->UpdateConfiguration(configuration);
1487 ASSERT_EQ(ret, 0);
1488 }
1489
1490
1491 /**
1492 * @tc.name: UpdateConfigurationForAll01
1493 * @tc.desc: UpdateConfigurationForAll
1494 * @tc.type: FUNC
1495 */
1496 HWTEST_F(WindowSceneSessionImplTest, UpdateConfigurationForAll01, Function | SmallTest | Level2)
1497 {
1498 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1499 option->SetWindowName("UpdateConfigurationForAll");
1500 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1501 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1502 ASSERT_NE(nullptr, windowscenesession);
1503 int ret = 0;
1504 std::shared_ptr<AppExecFwk::Configuration> configuration;
1505 windowscenesession->UpdateConfigurationForAll(configuration);
1506 ASSERT_EQ(ret, 0);
1507 }
1508
1509 /**
1510 * @tc.name: GetTopWindowWithContext01
1511 * @tc.desc: GetTopWindowWithContext
1512 * @tc.type: FUNC
1513 */
1514 HWTEST_F(WindowSceneSessionImplTest, GetTopWindowWithContext01, Function | SmallTest | Level2)
1515 {
1516 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1517 option->SetWindowName("GetTopWindowWithContext");
1518 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1519 std::shared_ptr<AbilityRuntime::Context> context;
1520 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1521 ASSERT_NE(nullptr, windowscenesession);
1522 if (windowscenesession->GetTopWindowWithContext(context) == nullptr) {
1523 ASSERT_EQ(nullptr, windowscenesession->GetTopWindowWithContext(context));
1524 }
1525 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1526 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1527 ASSERT_NE(nullptr, session);
1528 ASSERT_EQ(WMError::WM_OK, windowscenesession->Create(abilityContext_, session));
1529 ASSERT_NE(nullptr, windowscenesession->GetTopWindowWithContext(context));
1530 }
1531
1532 /**
1533 * @tc.name: NotifyMemoryLevel01
1534 * @tc.desc: NotifyMemoryLevel
1535 * @tc.type: FUNC
1536 */
1537 HWTEST_F(WindowSceneSessionImplTest, NotifyMemoryLevel01, Function | SmallTest | Level2)
1538 {
1539 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1540 option->SetWindowName("NotifyMemoryLevel");
1541 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1542 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1543 ASSERT_NE(nullptr, windowscenesession);
1544 std::shared_ptr<AppExecFwk::Configuration> configuration;
1545 windowscenesession->NotifyMemoryLevel(2);
1546 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, windowscenesession->NotifyMemoryLevel(2));
1547 windowscenesession->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1548 ASSERT_EQ(WMError::WM_OK, windowscenesession->NotifyMemoryLevel(2));
1549 }
1550
1551 /**
1552 * @tc.name: GetSystemSizeLimits01
1553 * @tc.desc: GetSystemSizeLimits
1554 * @tc.type: FUNC
1555 */
1556 HWTEST_F(WindowSceneSessionImplTest, GetSystemSizeLimits01, Function | SmallTest | Level2)
1557 {
1558 constexpr uint32_t minMainWidth = 10;
1559 constexpr uint32_t minMainHeight = 20;
1560 constexpr uint32_t minSubWidth = 30;
1561 constexpr uint32_t minSubHeight = 40;
1562 constexpr uint32_t displayWidth = 100;
1563 constexpr uint32_t displayHeight = 100;
1564 constexpr float displayVpr = 1;
1565
1566 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1567 option->SetWindowName("GetSystemSizeLimits01");
1568 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1569
1570 sptr<WindowSceneSessionImpl> windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option);
1571
1572 ASSERT_NE(nullptr, windowscenesession);
1573 windowscenesession->windowSystemConfig_.miniWidthOfMainWindow_ = minMainWidth;
1574 windowscenesession->windowSystemConfig_.miniHeightOfMainWindow_ = minMainHeight;
1575 windowscenesession->windowSystemConfig_.miniWidthOfSubWindow_ = minSubWidth;
1576 windowscenesession->windowSystemConfig_.miniHeightOfSubWindow_ = minSubHeight;
1577
1578 WindowLimits limits = windowscenesession->GetSystemSizeLimits(displayWidth, displayHeight, displayVpr);
1579 ASSERT_EQ(limits.minWidth_, minMainWidth);
1580 ASSERT_EQ(limits.minHeight_, minMainHeight);
1581
1582 windowscenesession->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1583 limits = windowscenesession->GetSystemSizeLimits(displayWidth, displayHeight, displayVpr);
1584 ASSERT_NE(limits.minWidth_, minMainWidth);
1585 ASSERT_NE(limits.minHeight_, minMainHeight);
1586 }
1587
1588 /**
1589 * @tc.name: DumpSessionElementInfo
1590 * @tc.desc: DumpSessionElementInfo 1: params num
1591 * @tc.type: FUNC
1592 */
1593 HWTEST_F(WindowSceneSessionImplTest, DumpSessionElementInfo1, Function | SmallTest | Level2)
1594 {
1595 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1596 option->SetWindowName("DumpSessionElementInfo");
1597 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1598 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1599 ASSERT_NE(nullptr, window);
1600 std::vector<std::string> params;
1601 params.push_back("-h");
1602 window->DumpSessionElementInfo(params);
1603 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1604 ASSERT_EQ(WMError::WM_OK, window->NotifyMemoryLevel(2));
1605 delete option;
1606 ASSERT_EQ(WMError::WM_OK, window->Destroy(false));
1607 }
1608
1609 /**
1610 * @tc.name: DumpSessionElementInfo
1611 * @tc.desc: DumpSessionElementInfo2
1612 * @tc.type: FUNC
1613 */
1614 HWTEST_F(WindowSceneSessionImplTest, DumpSessionElementInfo2, Function | SmallTest | Level2)
1615 {
1616 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1617 option->SetWindowName("DumpSessionElementInfo2");
1618 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1619 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1620 ASSERT_NE(nullptr, window);
1621 std::vector<std::string> params;
1622 params.push_back("-h");
1623 window->DumpSessionElementInfo(params);
1624 params.push_back("-s");
1625 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1626 window->DumpSessionElementInfo(params);
1627 ASSERT_EQ(WMError::WM_OK, window->NotifyMemoryLevel(2));
1628 delete option;
1629 ASSERT_EQ(WMError::WM_OK, window->Destroy(false));
1630 }
1631
1632 /**
1633 * @tc.name: DumpSessionElementInfo
1634 * @tc.desc: DumpSessionElementInfo3
1635 * @tc.type: FUNC
1636 */
1637 HWTEST_F(WindowSceneSessionImplTest, DumpSessionElementInfo3, Function | SmallTest | Level2)
1638 {
1639 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1640 option->SetWindowName("DumpSessionElementInfo3");
1641 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1642 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1643 ASSERT_NE(nullptr, window);
1644 std::vector<std::string> params;
1645 params.push_back("-s");
1646 window->DumpSessionElementInfo(params);
1647 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1648 ASSERT_EQ(WMError::WM_OK, window->NotifyMemoryLevel(2));
1649 delete option;
1650 ASSERT_EQ(WMError::WM_OK, window->Destroy(false));
1651 }
1652 }
1653 } // namespace Rosen
1654 } // namespace OHOS
1655