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 <parameters.h>
18 #include "display_info.h"
19 #include "ability_context_impl.h"
20 #include "mock_session.h"
21 #include "window_session_impl.h"
22 #include "mock_uicontent.h"
23 #include "window_scene_session_impl.h"
24 #include "mock_window_adapter.h"
25 #include "singleton_mocker.h"
26 #include "session/host/include/scene_session.h"
27
28 using namespace testing;
29 using namespace testing::ext;
30
31 namespace OHOS {
32 namespace Rosen {
33 using Mocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
34
35 class MockWindowChangeListener : public IWindowChangeListener {
36 public:
37 MOCK_METHOD3(OnSizeChange,
38 void(Rect rect, WindowSizeChangeReason reason, const std::shared_ptr<RSTransaction>& rsTransaction));
39 };
40
41 class MockWindowLifeCycleListener : public IWindowLifeCycle {
42 public:
43 MOCK_METHOD0(AfterForeground, void(void));
44 MOCK_METHOD0(AfterBackground, void(void));
45 MOCK_METHOD0(AfterFocused, void(void));
46 MOCK_METHOD0(AfterUnfocused, void(void));
47 MOCK_METHOD1(ForegroundFailed, void(int32_t));
48 MOCK_METHOD0(AfterActive, void(void));
49 MOCK_METHOD0(AfterInactive, void(void));
50 MOCK_METHOD0(AfterResumed, void(void));
51 MOCK_METHOD0(AfterPaused, void(void));
52 };
53
54 class WindowSceneSessionImplTest : public testing::Test {
55 public:
56 static void SetUpTestCase();
57 static void TearDownTestCase();
58 void SetUp() override;
59 void TearDown() override;
60
61 std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
62 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
63
64 private:
65 RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
66 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
67 };
68
SetUpTestCase()69 void WindowSceneSessionImplTest::SetUpTestCase() {}
70
TearDownTestCase()71 void WindowSceneSessionImplTest::TearDownTestCase() {}
72
SetUp()73 void WindowSceneSessionImplTest::SetUp()
74 {
75 abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
76 }
77
TearDown()78 void WindowSceneSessionImplTest::TearDown()
79 {
80 usleep(WAIT_SYNC_IN_NS);
81 abilityContext_ = nullptr;
82 }
83
CreateRSSurfaceNode()84 RSSurfaceNode::SharedPtr WindowSceneSessionImplTest::CreateRSSurfaceNode()
85 {
86 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
87 rsSurfaceNodeConfig.SurfaceNodeName = "startingWindowTestSurfaceNode";
88 auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig, RSSurfaceNodeType::DEFAULT);
89 return surfaceNode;
90 }
91
92 namespace {
93 /**
94 * @tc.name: CreateWindowAndDestroy01
95 * @tc.desc: Create window and destroy window
96 * @tc.type: FUNC
97 */
HWTEST_F(WindowSceneSessionImplTest, CreateWindowAndDestroy01, Function | SmallTest | Level2)98 HWTEST_F(WindowSceneSessionImplTest, CreateWindowAndDestroy01, Function | SmallTest | Level2)
99 {
100 sptr<WindowOption> option = new (std::nothrow) WindowOption();
101 ASSERT_NE(nullptr, option);
102 option->SetWindowName("CreateWindowAndDestroy01");
103 sptr<WindowSceneSessionImpl> window = new WindowSceneSessionImpl(option);
104
105 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
106 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
107 ASSERT_NE(nullptr, session);
108
109 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
110 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false));
111 ASSERT_EQ(WMError::WM_ERROR_REPEAT_OPERATION, window->Create(abilityContext_, session));
112 window->property_->SetPersistentId(1);
113 ASSERT_EQ(WMError::WM_OK, window->Destroy(false));
114 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Create(abilityContext_, session));
115 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(true));
116 }
117
118 /**
119 * @tc.name: CreateWindowAndDestroy02
120 * @tc.desc: Create window and destroy window
121 * @tc.type: FUNC
122 */
HWTEST_F(WindowSceneSessionImplTest, CreateWindowAndDestroy02, Function | SmallTest | Level2)123 HWTEST_F(WindowSceneSessionImplTest, CreateWindowAndDestroy02, Function | SmallTest | Level2)
124 {
125 sptr<WindowOption> option = new (std::nothrow) WindowOption();
126 ASSERT_NE(nullptr, option);
127 option->SetWindowName("CreateWindowAndDestroy02");
128 sptr<WindowSceneSessionImpl> window = new WindowSceneSessionImpl(option);
129 ASSERT_NE(nullptr, window);
130 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
131 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
132 ASSERT_NE(nullptr, session);
133 std::string identityToken = "testToken";
134 window->Create(abilityContext_, session);
135 ASSERT_EQ(WMError::WM_ERROR_REPEAT_OPERATION, window->Create(abilityContext_, session, identityToken));
136 window->property_->SetPersistentId(1);
137 window->Destroy(false);
138 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Create(abilityContext_, session, identityToken));
139 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false));
140 }
141
142 /**
143 * @tc.name: CreateAndConnectSpecificSession01
144 * @tc.desc: CreateAndConnectSpecificSession
145 * @tc.type: FUNC
146 */
HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession01, Function | SmallTest | Level2)147 HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession01, Function | SmallTest | Level2)
148 {
149 sptr<WindowOption> option = new (std::nothrow) WindowOption();
150 ASSERT_NE(nullptr, option);
151 option->SetWindowName("CreateAndConnectSpecificSession01");
152 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
153 ASSERT_NE(nullptr, windowSceneSession);
154
155 windowSceneSession->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
156 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, windowSceneSession->CreateAndConnectSpecificSession());
157 windowSceneSession->property_->SetPersistentId(102);
158 windowSceneSession->property_->SetParentPersistentId(100);
159 windowSceneSession->property_->SetParentId(100);
160 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
161 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
162 ASSERT_NE(nullptr, session);
163
164 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Create(abilityContext_, session));
165 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Destroy(true));
166 }
167
168 /**
169 * @tc.name: CreateAndConnectSpecificSession02
170 * @tc.desc: CreateAndConnectSpecificSession
171 * @tc.type: FUNC
172 */
HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession02, Function | SmallTest | Level2)173 HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession02, Function | SmallTest | Level2)
174 {
175 sptr<WindowOption> option = new (std::nothrow) WindowOption();
176 ASSERT_NE(nullptr, option);
177 option->SetWindowTag(WindowTag::SUB_WINDOW);
178 option->SetWindowName("CreateAndConnectSpecificSession02");
179 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
180 ASSERT_NE(nullptr, windowSceneSession);
181
182 SessionInfo sessionInfo = { "CreateTestBundle0", "CreateTestModule0", "CreateTestAbility0" };
183 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
184 ASSERT_NE(nullptr, session);
185 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Create(abilityContext_, session));
186 windowSceneSession->property_->SetPersistentId(103);
187 windowSceneSession->property_->SetParentPersistentId(102);
188 windowSceneSession->property_->SetParentId(102);
189 windowSceneSession->hostSession_ = session;
190
191 windowSceneSession->property_->type_ = WindowType::APP_SUB_WINDOW_BASE;
192 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, windowSceneSession->CreateAndConnectSpecificSession());
193 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Destroy(true));
194 }
195
196 /**
197 * @tc.name: CreateAndConnectSpecificSession03
198 * @tc.desc: CreateAndConnectSpecificSession
199 * @tc.type: FUNC
200 */
HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession03, Function | SmallTest | Level2)201 HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession03, Function | SmallTest | Level2)
202 {
203 sptr<WindowOption> option = new (std::nothrow) WindowOption();
204 ASSERT_NE(nullptr, option);
205 option->SetWindowTag(WindowTag::SUB_WINDOW);
206 option->SetWindowName("CreateAndConnectSpecificSession03");
207 option->SetIsUIExtFirstSubWindow(true);
208 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
209 ASSERT_NE(nullptr, windowSceneSession);
210
211 SessionInfo sessionInfo = { "CreateTestBundle0", "CreateTestModule0", "CreateTestAbility0" };
212 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
213 ASSERT_NE(nullptr, session);
214 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Create(abilityContext_, session));
215
216 windowSceneSession->property_->SetParentPersistentId(102);
217 windowSceneSession->property_->SetParentId(102);
218 windowSceneSession->hostSession_ = session;
219
220 windowSceneSession->property_->type_ = WindowType::APP_SUB_WINDOW_BASE;
221 ASSERT_EQ(WMError::WM_OK, windowSceneSession->CreateAndConnectSpecificSession());
222 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Destroy(true));
223 }
224
225 /**
226 * @tc.name: CreateAndConnectSpecificSession04
227 * @tc.desc: CreateAndConnectSpecificSession
228 * @tc.type: FUNC
229 */
HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession04, Function | SmallTest | Level2)230 HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession04, Function | SmallTest | Level2)
231 {
232 sptr<WindowOption> option = new (std::nothrow) WindowOption();
233 ASSERT_NE(nullptr, option);
234 option->SetWindowTag(WindowTag::SUB_WINDOW);
235 option->SetWindowName("CreateAndConnectSpecificSession04");
236 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
237 ASSERT_NE(nullptr, windowSceneSession);
238
239 SessionInfo sessionInfo = { "CreateTestBundle4", "CreateTestModule4", "CreateTestAbility4" };
240 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
241 ASSERT_NE(nullptr, session);
242 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Create(abilityContext_, session));
243
244 windowSceneSession->property_->SetPersistentId(104);
245 windowSceneSession->property_->SetParentPersistentId(103);
246 windowSceneSession->property_->SetParentId(103);
247 windowSceneSession->property_->type_ = WindowType::APP_MAIN_WINDOW_BASE;
248 windowSceneSession->hostSession_ = session;
249
250 windowSceneSession->property_->type_ = WindowType::APP_SUB_WINDOW_BASE;
251 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, windowSceneSession->CreateAndConnectSpecificSession());
252 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Destroy(true));
253 }
254
255 /**
256 * @tc.name: CreateAndConnectSpecificSession05
257 * @tc.desc: CreateAndConnectSpecificSession
258 * @tc.type: FUNC
259 */
HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession05, Function | SmallTest | Level2)260 HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession05, Function | SmallTest | Level2)
261 {
262 sptr<WindowOption> option = new (std::nothrow) WindowOption();
263 ASSERT_NE(nullptr, option);
264 option->SetWindowTag(WindowTag::SUB_WINDOW);
265 option->SetWindowName("CreateAndConnectSpecificSession05");
266 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
267 ASSERT_NE(nullptr, windowSceneSession);
268
269 SessionInfo sessionInfo = { "CreateTestBundle5", "CreateTestModule5", "CreateTestAbility5" };
270 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
271 ASSERT_NE(nullptr, session);
272 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Create(abilityContext_, session));
273
274 windowSceneSession->property_->SetParentPersistentId(104);
275 windowSceneSession->property_->SetParentId(104);
276 windowSceneSession->hostSession_ = session;
277
278 windowSceneSession->property_->type_ = WindowType::APP_SUB_WINDOW_BASE;
279 ASSERT_NE(WMError::WM_ERROR_INVALID_TYPE, windowSceneSession->CreateAndConnectSpecificSession());
280 ASSERT_NE(WMError::WM_OK, windowSceneSession->Destroy(true));
281 }
282
283 /**
284 * @tc.name: CreateAndConnectSpecificSession06
285 * @tc.desc: CreateAndConnectSpecificSession
286 * @tc.type: FUNC
287 */
HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession06, Function | SmallTest | Level2)288 HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession06, Function | SmallTest | Level2)
289 {
290 sptr<WindowOption> option = new (std::nothrow) WindowOption();
291 ASSERT_NE(nullptr, option);
292 option->SetWindowTag(WindowTag::SYSTEM_WINDOW);
293 option->SetWindowName("CreateAndConnectSpecificSession06");
294 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
295 ASSERT_NE(nullptr, windowSceneSession);
296
297 SessionInfo sessionInfo = { "CreateTestBundle6", "CreateTestModule6", "CreateTestAbility6" };
298 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
299 ASSERT_NE(nullptr, session);
300 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Create(abilityContext_, session));
301
302 windowSceneSession->property_->SetPersistentId(105);
303 windowSceneSession->property_->SetParentPersistentId(102);
304 windowSceneSession->property_->SetParentId(102);
305 windowSceneSession->hostSession_ = session;
306
307 windowSceneSession->property_->type_ = WindowType::SYSTEM_WINDOW_BASE;
308 ASSERT_EQ(WMError::WM_OK, windowSceneSession->CreateAndConnectSpecificSession());
309 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Destroy(true));
310 }
311
312 /**
313 * @tc.name: CreateAndConnectSpecificSession07
314 * @tc.desc: CreateAndConnectSpecificSession
315 * @tc.type: FUNC
316 */
HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession07, Function | SmallTest | Level2)317 HWTEST_F(WindowSceneSessionImplTest, CreateAndConnectSpecificSession07, Function | SmallTest | Level2)
318 {
319 sptr<WindowOption> option = new (std::nothrow) WindowOption();
320 ASSERT_NE(nullptr, option);
321 option->SetWindowTag(WindowTag::SYSTEM_WINDOW);
322 option->SetWindowName("CreateAndConnectSpecificSession07");
323 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
324 ASSERT_NE(nullptr, windowSceneSession);
325
326 SessionInfo sessionInfo = { "CreateTestBundle7", "CreateTestModule7", "CreateTestAbility7" };
327 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
328 ASSERT_NE(nullptr, session);
329 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Create(abilityContext_, session));
330
331 windowSceneSession->property_->SetPersistentId(106);
332 windowSceneSession->property_->SetParentPersistentId(105);
333 windowSceneSession->property_->SetParentId(105);
334 windowSceneSession->hostSession_ = session;
335
336 windowSceneSession->property_->type_ = WindowType::SYSTEM_SUB_WINDOW_BASE;
337 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, windowSceneSession->CreateAndConnectSpecificSession());
338 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Destroy(true));
339 }
340
341 /**
342 * @tc.name: RecoverAndReconnectSceneSession
343 * @tc.desc: RecoverAndReconnectSceneSession
344 * @tc.type: FUNC
345 */
HWTEST_F(WindowSceneSessionImplTest, RecoverAndReconnectSceneSession, Function | SmallTest | Level2)346 HWTEST_F(WindowSceneSessionImplTest, RecoverAndReconnectSceneSession, Function | SmallTest | Level2)
347 {
348 sptr<WindowOption> option = new WindowOption();
349 option->SetWindowName("RecoverAndReconnectSceneSession");
350 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
351 ASSERT_NE(nullptr, windowSceneSession);
352 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, windowSceneSession->RecoverAndReconnectSceneSession());
353 }
354
355 /**
356 * @tc.name: IsValidSystemWindowType01
357 * @tc.desc: IsValidSystemWindowType
358 * @tc.type: FUNC
359 */
HWTEST_F(WindowSceneSessionImplTest, IsValidSystemWindowType01, Function | SmallTest | Level2)360 HWTEST_F(WindowSceneSessionImplTest, IsValidSystemWindowType01, Function | SmallTest | Level2)
361 {
362 sptr<WindowOption> option = new (std::nothrow) WindowOption();
363 option->SetWindowName("IsValidSystemWindowType01");
364 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
365 ASSERT_NE(nullptr, windowSceneSession);
366 ASSERT_FALSE(!windowSceneSession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW));
367 ASSERT_FALSE(!windowSceneSession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT));
368 ASSERT_FALSE(!windowSceneSession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA));
369 ASSERT_FALSE(!windowSceneSession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_DIALOG));
370 ASSERT_FALSE(!windowSceneSession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_FLOAT));
371 ASSERT_FALSE(!windowSceneSession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_SCREENSHOT));
372 ASSERT_FALSE(!windowSceneSession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH));
373 ASSERT_FALSE(!windowSceneSession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_VOICE_INTERACTION));
374 ASSERT_FALSE(!windowSceneSession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_POINTER));
375 ASSERT_FALSE(!windowSceneSession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_TOAST));
376 ASSERT_FALSE(!windowSceneSession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_DOCK_SLICE));
377 ASSERT_TRUE(!windowSceneSession->IsValidSystemWindowType(WindowType::WINDOW_TYPE_APP_LAUNCHING));
378 }
379
380 /*
381 * @tc.name: InvalidWindow
382 * @tc.desc: InvalidWindow test
383 * @tc.type: FUNC
384 */
HWTEST_F(WindowSceneSessionImplTest, InvalidWindow, Function | SmallTest | Level3)385 HWTEST_F(WindowSceneSessionImplTest, InvalidWindow, Function | SmallTest | Level3)
386 {
387 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
388 option->SetWindowName("InvalidWindow");
389 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
390 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->MoveTo(0, 0));
391 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->Resize(0, 0));
392 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetBackgroundColor(std::string("???")));
393 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetTransparent(false));
394 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Show(2, false));
395 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Resize(2, 2));
396 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Minimize());
397 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Maximize());
398 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->MaximizeFloating());
399 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Recover());
400 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->MaximizeFloating());
401 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetGlobalMaximizeMode(MaximizeMode::MODE_AVOID_SYSTEM_BAR));
402 }
403
404 /**
405 * @tc.name: FindParentSessionByParentId01
406 * @tc.desc: FindParentSessionByParentId
407 * @tc.type: FUNC
408 */
HWTEST_F(WindowSceneSessionImplTest, FindParentSessionByParentId01, Function | SmallTest | Level2)409 HWTEST_F(WindowSceneSessionImplTest, FindParentSessionByParentId01, Function | SmallTest | Level2)
410 {
411 sptr<WindowOption> option = new (std::nothrow) WindowOption();
412 option->SetWindowTag(WindowTag::MAIN_WINDOW);
413 option->SetWindowName("FindParentSessionByParentId01");
414 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
415 ASSERT_NE(nullptr, windowSceneSession);
416
417 windowSceneSession->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
418 ASSERT_TRUE(windowSceneSession->FindMainWindowWithContext() == nullptr);
419 windowSceneSession->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_END);
420 ASSERT_TRUE(windowSceneSession->FindMainWindowWithContext() == nullptr);
421
422 windowSceneSession->property_->SetPersistentId(1112);
423 windowSceneSession->property_->SetParentId(1000);
424 windowSceneSession->property_->SetParentPersistentId(1000);
425 windowSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
426 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
427 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
428 ASSERT_NE(nullptr, session);
429
430 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Create(abilityContext_, session));
431 windowSceneSession->hostSession_ = session;
432 ASSERT_TRUE(nullptr != windowSceneSession->FindParentSessionByParentId(1112));
433 windowSceneSession->Destroy(true);
434 }
435
436 /**
437 * @tc.name: DisableAppWindowDecor01
438 * @tc.desc: DisableAppWindowDecor
439 * @tc.type: FUNC
440 */
HWTEST_F(WindowSceneSessionImplTest, DisableAppWindowDecor01, Function | SmallTest | Level3)441 HWTEST_F(WindowSceneSessionImplTest, DisableAppWindowDecor01, Function | SmallTest | Level3)
442 {
443 sptr<WindowOption> option = new (std::nothrow) WindowOption();
444 option->SetWindowName("DisableAppWindowDecor01");
445 sptr<WindowSceneSessionImpl> windowSession = sptr<WindowSceneSessionImpl>::MakeSptr(option);
446 ASSERT_NE(nullptr, windowSession);
447
448 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
449 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
450
451 ASSERT_NE(nullptr, session);
452 std::shared_ptr<AbilityRuntime::Context> context;
453 ASSERT_EQ(WMError::WM_OK, windowSession->Create(context, session));
454 windowSession->property_->SetPersistentId(1);
455
456 windowSession->UpdateDecorEnable(false);
457 windowSession->windowSystemConfig_.isSystemDecorEnable_ = false;
458
459 windowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
460 windowSession->DisableAppWindowDecor();
461 ASSERT_FALSE(windowSession->IsDecorEnable());
462 windowSession->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
463 windowSession->DisableAppWindowDecor();
464 windowSession->Destroy(true);
465 }
466
467 /**
468 * @tc.name: RaiseToAppTop01
469 * @tc.desc: RaiseToAppTop
470 * @tc.type: FUNC
471 */
HWTEST_F(WindowSceneSessionImplTest, RaiseToAppTop01, Function | SmallTest | Level2)472 HWTEST_F(WindowSceneSessionImplTest, RaiseToAppTop01, Function | SmallTest | Level2)
473 {
474 sptr<WindowOption> option = new (std::nothrow) WindowOption();
475 option->SetWindowName("RaiseToAppTop01");
476 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
477 ASSERT_NE(nullptr, windowSceneSession);
478
479 windowSceneSession->property_->SetPersistentId(6);
480 windowSceneSession->property_->SetParentPersistentId(6);
481 windowSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
482 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, windowSceneSession->RaiseToAppTop());
483
484 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
485 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
486 windowSceneSession->hostSession_ = session;
487 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, windowSceneSession->RaiseToAppTop());
488
489 windowSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
490 windowSceneSession->state_ = WindowState::STATE_HIDDEN;
491 ASSERT_EQ(WMError::WM_DO_NOTHING, windowSceneSession->RaiseToAppTop());
492
493 windowSceneSession->state_ = WindowState::STATE_SHOWN;
494 ASSERT_EQ(WMError::WM_OK, windowSceneSession->RaiseToAppTop());
495 }
496
497 /**
498 * @tc.name: MoveTo01
499 * @tc.desc: MoveTo
500 * @tc.type: FUNC
501 */
HWTEST_F(WindowSceneSessionImplTest, MoveTo01, Function | SmallTest | Level2)502 HWTEST_F(WindowSceneSessionImplTest, MoveTo01, Function | SmallTest | Level2)
503 {
504 sptr<WindowOption> option = new (std::nothrow) WindowOption();
505 option->SetWindowName("MoveTo01");
506 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
507 ASSERT_NE(nullptr, windowSceneSession);
508
509 windowSceneSession->property_->SetPersistentId(1);
510 windowSceneSession->state_ = WindowState::STATE_HIDDEN;
511 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
512 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
513 ASSERT_NE(nullptr, session);
514 windowSceneSession->hostSession_ = session;
515 ASSERT_EQ(WMError::WM_OK, windowSceneSession->MoveTo(2, 2));
516 }
517
518 /**
519 * @tc.name: Minimize01
520 * @tc.desc: Minimize
521 * @tc.type: FUNC
522 */
HWTEST_F(WindowSceneSessionImplTest, Minimize01, Function | SmallTest | Level2)523 HWTEST_F(WindowSceneSessionImplTest, Minimize01, Function | SmallTest | Level2)
524 {
525 sptr<WindowOption> option = new (std::nothrow) WindowOption();
526 option->SetWindowName("Minimize01");
527 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
528 ASSERT_NE(nullptr, windowSceneSession);
529
530 windowSceneSession->property_->SetPersistentId(1);
531 windowSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
532 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
533 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
534 ASSERT_NE(nullptr, session);
535 windowSceneSession->hostSession_ = session;
536 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Minimize());
537 }
538
539 /**
540 * @tc.name: StartMove01
541 * @tc.desc: StartMove
542 * @tc.type: FUNC
543 */
HWTEST_F(WindowSceneSessionImplTest, StartMove01, Function | SmallTest | Level2)544 HWTEST_F(WindowSceneSessionImplTest, StartMove01, Function | SmallTest | Level2)
545 {
546 sptr<WindowOption> option = new (std::nothrow) WindowOption();
547 option->SetWindowName("StartMove01");
548 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
549 ASSERT_NE(nullptr, windowSceneSession);
550 windowSceneSession->property_->SetPersistentId(1);
551 // show with null session
552
553 windowSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
554 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
555 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
556 windowSceneSession->hostSession_ = session;
557 windowSceneSession->StartMove();
558 ASSERT_NE(nullptr, session);
559 }
560
561 /**
562 * @tc.name: StartMoveSystemWindow01
563 * @tc.desc: StartMoveSystemWindow
564 * @tc.type: FUNC
565 */
HWTEST_F(WindowSceneSessionImplTest, StartMoveSystemWindow01, Function | SmallTest | Level2)566 HWTEST_F(WindowSceneSessionImplTest, StartMoveSystemWindow01, Function | SmallTest | Level2)
567 {
568 sptr<WindowOption> option = new (std::nothrow) WindowOption();
569 option->SetWindowName("StartMoveSystemWindow01");
570 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
571 ASSERT_NE(nullptr, windowSceneSession);
572 windowSceneSession->property_->SetPersistentId(1);
573 // show with null session
574
575 windowSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH);
576 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
577 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
578 windowSceneSession->hostSession_ = session;
579 windowSceneSession->StartMoveSystemWindow();
580 ASSERT_NE(nullptr, session);
581 }
582
583 /**
584 * @tc.name: Close01
585 * @tc.desc: Close
586 * @tc.type: FUNC
587 */
HWTEST_F(WindowSceneSessionImplTest, Close01, Function | SmallTest | Level2)588 HWTEST_F(WindowSceneSessionImplTest, Close01, Function | SmallTest | Level2)
589 {
590 sptr<WindowOption> option = new (std::nothrow) WindowOption();
591 option->SetWindowName("Close01");
592 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
593 ASSERT_NE(nullptr, windowSceneSession);
594 windowSceneSession->property_->SetPersistentId(1);
595 windowSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
596 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
597 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
598 ASSERT_NE(nullptr, session);
599 windowSceneSession->hostSession_ = session;
600 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Close());
601 }
602
603 /**
604 * @tc.name: Close02
605 * @tc.desc: Close
606 * @tc.type: FUNC
607 */
HWTEST_F(WindowSceneSessionImplTest, Close02, Function | SmallTest | Level2)608 HWTEST_F(WindowSceneSessionImplTest, Close02, Function | SmallTest | Level2)
609 {
610 sptr<WindowOption> option = new (std::nothrow) WindowOption();
611 option->SetWindowName("Close02");
612 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
613 ASSERT_NE(nullptr, windowSceneSession);
614 windowSceneSession->property_->SetPersistentId(-1);
615 windowSceneSession->property_->SetParentPersistentId(-1);
616 windowSceneSession->property_->SetPersistentId(1);
617 windowSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
618 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
619 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
620 ASSERT_NE(nullptr, session);
621 }
622
623 /**
624 * @tc.name: SetActive01
625 * @tc.desc: SetActive
626 * @tc.type: FUNC
627 */
HWTEST_F(WindowSceneSessionImplTest, SetActive01, Function | SmallTest | Level2)628 HWTEST_F(WindowSceneSessionImplTest, SetActive01, Function | SmallTest | Level2)
629 {
630 sptr<WindowOption> option = new (std::nothrow) WindowOption();
631 option->SetWindowName("SetActive01");
632 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
633 ASSERT_NE(nullptr, windowSceneSession);
634 windowSceneSession->property_->SetPersistentId(1);
635 windowSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
636 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
637 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
638 ASSERT_NE(nullptr, session);
639
640 windowSceneSession->hostSession_ = session;
641 ASSERT_EQ(WSError::WS_OK, windowSceneSession->SetActive(false));
642 ASSERT_EQ(WSError::WS_OK, windowSceneSession->SetActive(true));
643 }
644
645 /**
646 * @tc.name: Recover01
647 * @tc.desc: Recover
648 * @tc.type: FUNC
649 */
HWTEST_F(WindowSceneSessionImplTest, Recover01, Function | SmallTest | Level2)650 HWTEST_F(WindowSceneSessionImplTest, Recover01, Function | SmallTest | Level2)
651 {
652 sptr<WindowOption> option = new (std::nothrow) WindowOption();
653 option->SetWindowName("Recover01");
654 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
655 ASSERT_NE(nullptr, windowSceneSession);
656
657 windowSceneSession->property_->SetPersistentId(1);
658 windowSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
659 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
660 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
661 ASSERT_NE(nullptr, session);
662 windowSceneSession->hostSession_ = session;
663 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Recover());
664 }
665
666 /**
667 * @tc.name: Maximize01
668 * @tc.desc: Maximize
669 * @tc.type: FUNC
670 */
HWTEST_F(WindowSceneSessionImplTest, Maximize01, Function | SmallTest | Level2)671 HWTEST_F(WindowSceneSessionImplTest, Maximize01, Function | SmallTest | Level2)
672 {
673 sptr<WindowOption> option = new (std::nothrow) WindowOption();
674 option->SetWindowName("Maximize01");
675 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
676 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
677 ASSERT_NE(nullptr, windowSceneSession);
678 windowSceneSession->property_->SetPersistentId(1);
679 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
680 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
681 ASSERT_NE(nullptr, session);
682 windowSceneSession->hostSession_ = session;
683 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Maximize());
684 }
685
686 /**
687 * @tc.name: Hide01
688 * @tc.desc: Hide session
689 * @tc.type: FUNC
690 */
HWTEST_F(WindowSceneSessionImplTest, Hide01, Function | SmallTest | Level2)691 HWTEST_F(WindowSceneSessionImplTest, Hide01, Function | SmallTest | Level2)
692 {
693 sptr<WindowOption> option = new (std::nothrow) WindowOption();
694 option->SetWindowName("Hide01");
695 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
696 ASSERT_NE(nullptr, window);
697 window->property_->SetPersistentId(1);
698 // show with null session
699 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Hide(2, false, false));
700
701 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
702 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
703 ASSERT_NE(nullptr, session);
704 window->hostSession_ = session;
705 ASSERT_EQ(WMError::WM_OK, window->Hide(2, false, false));
706 ASSERT_EQ(WMError::WM_OK, window->Hide(2, false, false));
707
708 window->state_ = WindowState::STATE_CREATED;
709 ASSERT_EQ(WMError::WM_OK, window->Hide(2, false, false));
710 window->state_ = WindowState::STATE_SHOWN;
711 window->property_->type_ = WindowType::APP_SUB_WINDOW_BASE;
712 ASSERT_EQ(WMError::WM_OK, window->Hide(2, false, false));
713
714 window->property_->type_ = WindowType::APP_SUB_WINDOW_BASE;
715 if (window->Destroy(false) == WMError::WM_OK) {
716 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false));
717 }
718 }
719
720 /**
721 * @tc.name: Show01
722 * @tc.desc: Show session
723 * @tc.type: FUNC
724 */
HWTEST_F(WindowSceneSessionImplTest, Show01, Function | SmallTest | Level2)725 HWTEST_F(WindowSceneSessionImplTest, Show01, Function | SmallTest | Level2)
726 {
727 sptr<WindowOption> option = new (std::nothrow) WindowOption();
728 option->SetWindowName("Show01");
729 option->SetDisplayId(0);
730 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
731 ASSERT_NE(nullptr, window);
732 window->property_->SetPersistentId(1);
733
734 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
735 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
736 ASSERT_NE(nullptr, session);
737
738 window->hostSession_ = session;
739 ASSERT_EQ(WMError::WM_OK, window->Show(2, false));
740
741 window->state_ = WindowState::STATE_CREATED;
742 ASSERT_EQ(WMError::WM_OK, window->Show(2, false));
743 ASSERT_EQ(WMError::WM_OK, window->Destroy(false));
744 }
745
746 /**
747 * @tc.name: NotifyDrawingCompleted
748 * @tc.desc: NotifyDrawingCompleted session
749 * @tc.type: FUNC
750 */
HWTEST_F(WindowSceneSessionImplTest, NotifyDrawingCompleted, Function | SmallTest | Level2)751 HWTEST_F(WindowSceneSessionImplTest, NotifyDrawingCompleted, Function | SmallTest | Level2)
752 {
753 sptr<WindowOption> option = new (std::nothrow) WindowOption();
754 ASSERT_NE(nullptr, option);
755 option->SetWindowName("NotifyDrawingCompleted");
756 option->SetDisplayId(0);
757 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
758 ASSERT_NE(nullptr, window);
759 ASSERT_NE(nullptr, window->property_);
760 window->property_->SetPersistentId(1);
761
762 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
763 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
764 ASSERT_NE(nullptr, session);
765
766 window->hostSession_ = session;
767 window->NotifyDrawingCompleted();
768 }
769
770 /*
771 * @tc.name: SetTransparent
772 * @tc.desc: SetTransparent test
773 * @tc.type: FUNC
774 */
HWTEST_F(WindowSceneSessionImplTest, SetTransparent, Function | SmallTest | Level3)775 HWTEST_F(WindowSceneSessionImplTest, SetTransparent, Function | SmallTest | Level3)
776 {
777 sptr<WindowOption> option = new (std::nothrow) WindowOption();
778 option->SetWindowName("SetTransparent");
779 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
780 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetTransparent(true));
781 window->property_->SetPersistentId(1);
782 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
783 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
784 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
785 ASSERT_NE(nullptr, session);
786 window->hostSession_ = session;
787 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
788 window->SetBackgroundColor(333);
789 if (window->SetTransparent(true) == WMError::WM_OK) {
790 ASSERT_EQ(WMError::WM_OK, window->SetTransparent(true));
791 }
792 }
793
794 /*
795 * @tc.name: GetTopwindowWithId
796 * @tc.desc: GetTopwindowWithId test
797 * @tc.type: FUNC
798 */
HWTEST_F(WindowSceneSessionImplTest, GetTopwindowWithId, Function | SmallTest | Level3)799 HWTEST_F(WindowSceneSessionImplTest, GetTopwindowWithId, Function | SmallTest | Level3)
800 {
801 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
802 option->SetWindowName("GetTopwindowWithId");
803 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
804 sptr<WindowSessionImpl> session = sptr<WindowSessionImpl>::MakeSptr(option);
805 uint32_t windowId = 1;
806 string winName = "test";
807 WindowSessionImpl::windowSessionMap_.insert(
808 std::make_pair(winName, std::pair<int32_t, sptr<WindowSessionImpl>>(windowId, session)));
809 EXPECT_CALL(m->Mock(), GetTopWindowId(_, _)).Times(1).WillOnce(Return(WMError::WM_DO_NOTHING));
810 uint32_t mainWinId = 1;
811 ASSERT_EQ(nullptr, window->GetTopWindowWithId(mainWinId));
812
813 EXPECT_CALL(m->Mock(), GetTopWindowId(_, _)).Times(1).WillOnce(DoAll(
814 SetArgReferee<1>(windowId),
815 Return(WMError::WM_OK)
816 ));
817 ASSERT_NE(nullptr, window->GetTopWindowWithId(mainWinId));
818
819 int32_t tempWinId = 3;
820 EXPECT_CALL(m->Mock(), GetTopWindowId(_, _)).Times(1).WillOnce(DoAll(
821 SetArgReferee<1>(tempWinId),
822 Return(WMError::WM_OK)
823 ));
824 ASSERT_EQ(nullptr, window->GetTopWindowWithId(mainWinId));
825
826 WindowSessionImpl::windowSessionMap_.erase(winName);
827 }
828
829 /*
830 * @tc.name: SetAspectRatio01
831 * @tc.desc: SetAspectRatio test
832 * @tc.type: FUNC
833 */
HWTEST_F(WindowSceneSessionImplTest, SetAspectRatio01, Function | SmallTest | Level3)834 HWTEST_F(WindowSceneSessionImplTest, SetAspectRatio01, Function | SmallTest | Level3)
835 {
836 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
837 option->SetWindowName("SetAspectRatio01");
838 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
839 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
840 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetAspectRatio(0.1));
841 }
842
843 /*
844 * @tc.name: SetAspectRatio02
845 * @tc.desc: SetAspectRatio test
846 * @tc.type: FUNC
847 */
HWTEST_F(WindowSceneSessionImplTest, SetAspectRatio02, Function | SmallTest | Level3)848 HWTEST_F(WindowSceneSessionImplTest, SetAspectRatio02, Function | SmallTest | Level3)
849 {
850 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
851 option->SetWindowName("SetAspectRatio02");
852 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
853 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
854 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetAspectRatio(0.1));
855
856 window->property_->SetPersistentId(1);
857 window->property_->SetDisplayId(0);
858 WindowLimits windowLimits = { 3000, 3000, 2000, 2000, 2.0, 2.0 };
859 window->property_->SetWindowLimits(windowLimits);
860 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
861 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
862 window->hostSession_ = session;
863 session->GetSessionProperty()->SetWindowLimits(windowLimits);
864 const float ratio = 1.2;
865 ASSERT_EQ(WMError::WM_OK, window->SetAspectRatio(ratio));
866 ASSERT_EQ(ratio, session->GetAspectRatio());
867 }
868
869 /*
870 * @tc.name: ResetAspectRatio
871 * @tc.desc: ResetAspectRatio test GetAvoidAreaByType
872 * @tc.type: FUNC
873 */
HWTEST_F(WindowSceneSessionImplTest, ResetAspectRatio, Function | SmallTest | Level3)874 HWTEST_F(WindowSceneSessionImplTest, ResetAspectRatio, Function | SmallTest | Level3)
875 {
876 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
877 option->SetWindowName("ResetAspectRatio");
878 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
879 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
880 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
881 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
882 window->hostSession_ = session;
883 ASSERT_EQ(WMError::WM_OK, window->ResetAspectRatio());
884 ASSERT_EQ(0, session->GetAspectRatio());
885 }
886
887 /*
888 * @tc.name: GetAvoidAreaByType
889 * @tc.desc: GetAvoidAreaByType test
890 * @tc.type: FUNC
891 */
HWTEST_F(WindowSceneSessionImplTest, GetAvoidAreaByType, Function | SmallTest | Level3)892 HWTEST_F(WindowSceneSessionImplTest, GetAvoidAreaByType, Function | SmallTest | Level3)
893 {
894 sptr<WindowOption> option = new (std::nothrow) WindowOption();
895 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
896 option->SetWindowName("GetAvoidAreaByType");
897 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
898
899 window->property_->SetPersistentId(1);
900 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
901 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
902 ASSERT_NE(nullptr, session);
903 AvoidArea avoidarea;
904 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT, avoidarea));
905 }
906
907 /*
908 * @tc.name: Immersive
909 * @tc.desc: Immersive01 test
910 * @tc.type: FUNC
911 */
HWTEST_F(WindowSceneSessionImplTest, Immersive, Function | SmallTest | Level3)912 HWTEST_F(WindowSceneSessionImplTest, Immersive, Function | SmallTest | Level3)
913 {
914 sptr<WindowOption> option = new (std::nothrow) WindowOption();
915 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
916 option->SetWindowName("Immersive");
917 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
918
919
920 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetLayoutFullScreen(false));
921 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetFullScreen(false));
922 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
923 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
924 ASSERT_NE(nullptr, session);
925 window->hostSession_ = session;
926
927 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetFullScreen(false));
928 ASSERT_EQ(false, window->IsLayoutFullScreen());
929 ASSERT_EQ(false, window->IsFullScreen());
930 }
931
932 /*
933 * @tc.name: SystemBarProperty
934 * @tc.desc: SystemBarProperty01 test
935 * @tc.type: FUNC
936 */
HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty, Function | SmallTest | Level3)937 HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty, Function | SmallTest | Level3)
938 {
939 sptr<WindowOption> option = new (std::nothrow) WindowOption();
940 option->SetWindowName("SystemBarProperty");
941 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
942 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
943
944 SystemBarProperty property = SystemBarProperty();
945 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW,
946 window->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
947 }
948
949 /*
950 * @tc.name: SystemBarProperty02
951 * @tc.desc: SystemBarProperty02 test
952 * @tc.type: FUNC
953 */
HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty02, Function | SmallTest | Level3)954 HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty02, Function | SmallTest | Level3)
955 {
956 sptr<WindowOption> option = new (std::nothrow) WindowOption();
957 option->SetWindowName("SystemBarProperty02");
958 ASSERT_NE(nullptr, option);
959 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
960 ASSERT_NE(nullptr, window);
961
962 window->state_ = WindowState::STATE_SHOWN;
963 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
964 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
965 ASSERT_NE(nullptr, session);
966 window->property_->SetPersistentId(1);
967 window->hostSession_ = session;
968
969 SystemBarProperty property;
970 ASSERT_EQ(WMError::WM_OK, window->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
971 ASSERT_FALSE(window->property_->GetSystemBarProperty()[WindowType::WINDOW_TYPE_STATUS_BAR].enableAnimation_);
972
973 property.enableAnimation_ = false;
974 ASSERT_EQ(WMError::WM_OK, window->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
975 ASSERT_FALSE(window->property_->GetSystemBarProperty()[WindowType::WINDOW_TYPE_STATUS_BAR].enableAnimation_);
976 }
977
978 /*
979 * @tc.name: SystemBarProperty03
980 * @tc.desc: SystemBarProperty03 test
981 * @tc.type: FUNC
982 */
HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty03, Function | SmallTest | Level3)983 HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty03, Function | SmallTest | Level3)
984 {
985 sptr<WindowOption> option = new (std::nothrow) WindowOption();
986 option->SetWindowName("SystemBarProperty03");
987 ASSERT_NE(nullptr, option);
988 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
989 ASSERT_NE(nullptr, window);
990
991 window->state_ = WindowState::STATE_SHOWN;
992 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
993 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
994 ASSERT_NE(nullptr, session);
995 window->property_->SetPersistentId(1);
996 window->hostSession_ = session;
997
998 SystemBarProperty property;
999 property.enableAnimation_ = true;
1000 ASSERT_EQ(WMError::WM_OK, window->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1001 ASSERT_TRUE(window->property_->GetSystemBarProperty()[WindowType::WINDOW_TYPE_STATUS_BAR].enableAnimation_);
1002 }
1003
1004 /*
1005 * @tc.name: SystemBarProperty04
1006 * @tc.desc: SystemBarProperty04 test
1007 * @tc.type: FUNC
1008 */
HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty04, Function | SmallTest | Level3)1009 HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty04, Function | SmallTest | Level3)
1010 {
1011 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1012 option->SetWindowName("SystemBarProperty04");
1013 ASSERT_NE(nullptr, option);
1014 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1015 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1016 ASSERT_NE(nullptr, window);
1017
1018 SystemBarProperty property;
1019 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW,
1020 window->SetSpecificBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1021 }
1022
1023 /*
1024 * @tc.name: SystemBarProperty05
1025 * @tc.desc: SystemBarProperty05 test
1026 * @tc.type: FUNC
1027 */
HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty05, Function | SmallTest | Level3)1028 HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty05, Function | SmallTest | Level3)
1029 {
1030 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1031 option->SetWindowName("SystemBarProperty05");
1032 ASSERT_NE(nullptr, option);
1033 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1034 ASSERT_NE(nullptr, window);
1035
1036 window->state_ = WindowState::STATE_SHOWN;
1037 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1038 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1039 ASSERT_NE(nullptr, session);
1040 window->property_->SetPersistentId(1);
1041 window->hostSession_ = session;
1042
1043 SystemBarProperty property;
1044 ASSERT_EQ(WMError::WM_OK, window->SetSpecificBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1045 ASSERT_FALSE(window->property_->GetSystemBarProperty()[WindowType::WINDOW_TYPE_STATUS_BAR].enableAnimation_);
1046
1047 property.enableAnimation_ = false;
1048 ASSERT_EQ(WMError::WM_OK, window->SetSpecificBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1049 ASSERT_FALSE(window->property_->GetSystemBarProperty()[WindowType::WINDOW_TYPE_STATUS_BAR].enableAnimation_);
1050 }
1051
1052 /*
1053 * @tc.name: SystemBarProperty06
1054 * @tc.desc: SystemBarProperty06 test
1055 * @tc.type: FUNC
1056 */
HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty06, Function | SmallTest | Level3)1057 HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty06, Function | SmallTest | Level3)
1058 {
1059 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1060 option->SetWindowName("SystemBarProperty06");
1061 ASSERT_NE(nullptr, option);
1062 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1063 ASSERT_NE(nullptr, window);
1064
1065 window->state_ = WindowState::STATE_SHOWN;
1066 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1067 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1068 ASSERT_NE(nullptr, session);
1069 window->property_->SetPersistentId(1);
1070 window->hostSession_ = session;
1071
1072 SystemBarProperty property;
1073 property.enableAnimation_ = true;
1074 ASSERT_EQ(WMError::WM_OK, window->SetSpecificBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1075 ASSERT_TRUE(window->property_->GetSystemBarProperty()[WindowType::WINDOW_TYPE_STATUS_BAR].enableAnimation_);
1076 }
1077
1078 /*
1079 * @tc.name: SystemBarProperty07
1080 * @tc.desc: SystemBarProperty07 test
1081 * @tc.type: FUNC
1082 */
HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty07, Function | SmallTest | Level3)1083 HWTEST_F(WindowSceneSessionImplTest, SystemBarProperty07, Function | SmallTest | Level3)
1084 {
1085 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1086 option->SetWindowName("SystemBarProperty07");
1087 ASSERT_NE(nullptr, option);
1088 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1089 ASSERT_NE(nullptr, window);
1090
1091 window->state_ = WindowState::STATE_SHOWN;
1092 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1093 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1094 ASSERT_NE(nullptr, session);
1095 window->property_->SetPersistentId(1);
1096 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
1097 window->hostSession_ = session;
1098
1099 SystemBarProperty property;
1100 ASSERT_EQ(WMError::WM_OK, window->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1101 ASSERT_EQ(SystemBarSettingFlag::DEFAULT_SETTING,
1102 window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR).settingFlag_);
1103
1104 property.enable_ = false;
1105 property.settingFlag_ = SystemBarSettingFlag::ENABLE_SETTING;
1106 ASSERT_EQ(WMError::WM_OK, window->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1107 ASSERT_EQ(SystemBarSettingFlag::ENABLE_SETTING,
1108 window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR).settingFlag_);
1109
1110 property.backgroundColor_ = 0xB3000000;
1111 property.settingFlag_ = SystemBarSettingFlag::COLOR_SETTING;
1112 ASSERT_EQ(WMError::WM_OK, window->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1113 ASSERT_EQ(SystemBarSettingFlag::COLOR_SETTING,
1114 window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR).settingFlag_);
1115
1116 property.enable_ = true;
1117 property.backgroundColor_ = 0x4C000000;
1118 property.settingFlag_ = SystemBarSettingFlag::ALL_SETTING;
1119 ASSERT_EQ(WMError::WM_OK, window->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1120 ASSERT_EQ(WMError::WM_OK, window->Destroy(true));
1121 }
1122
1123 /*
1124 * @tc.name: SetSystemBarProperties
1125 * @tc.desc: SetSystemBarProperties test
1126 * @tc.type: FUNC
1127 */
HWTEST_F(WindowSceneSessionImplTest, SetSystemBarProperties, Function | SmallTest | Level3)1128 HWTEST_F(WindowSceneSessionImplTest, SetSystemBarProperties, Function | SmallTest | Level3)
1129 {
1130 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1131 ASSERT_NE(nullptr, option);
1132 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1133 option->SetWindowName("SetSystemBarProperties");
1134 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1135 ASSERT_NE(nullptr, window);
1136 window->state_ = WindowState::STATE_SHOWN;
1137 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1138 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1139 ASSERT_NE(nullptr, session);
1140 window->property_->SetPersistentId(1);
1141 window->hostSession_ = session;
1142 std::map<WindowType, SystemBarProperty> properties;
1143 std::map<WindowType, SystemBarPropertyFlag> propertyFlags;
1144 SystemBarProperty current = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR);
1145 SystemBarProperty property;
1146 properties[WindowType::WINDOW_TYPE_STATUS_BAR] = property;
1147 SystemBarPropertyFlag propertyFlag;
1148 propertyFlag.contentColorFlag = true;
1149 propertyFlags[WindowType::WINDOW_TYPE_STATUS_BAR] = propertyFlag;
1150 ASSERT_EQ(WMError::WM_OK, window->SetSystemBarProperties(properties, propertyFlags));
1151 if (property.contentColor_ != current.contentColor_) {
1152 std::map<WindowType, SystemBarProperty> currProperties;
1153 ASSERT_EQ(WMError::WM_OK, window->GetSystemBarProperties(currProperties));
1154 ASSERT_EQ(currProperties[WindowType::WINDOW_TYPE_STATUS_BAR].contentColor_, property.contentColor_);
1155 }
1156 }
1157
1158 /*
1159 * @tc.name: GetSystemBarProperties
1160 * @tc.desc: GetSystemBarProperties test
1161 * @tc.type: FUNC
1162 */
HWTEST_F(WindowSceneSessionImplTest, GetSystemBarProperties, Function | SmallTest | Level3)1163 HWTEST_F(WindowSceneSessionImplTest, GetSystemBarProperties, Function | SmallTest | Level3)
1164 {
1165 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1166 ASSERT_NE(nullptr, option);
1167 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1168 option->SetWindowName("GetSystemBarProperties");
1169 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1170 ASSERT_NE(nullptr, window);
1171 std::map<WindowType, SystemBarProperty> properties;
1172 ASSERT_EQ(WMError::WM_OK, window->GetSystemBarProperties(properties));
1173 }
1174
1175 /*
1176 * @tc.name: SpecificBarProperty
1177 * @tc.desc: SpecificBarProperty01 test
1178 * @tc.type: FUNC
1179 */
HWTEST_F(WindowSceneSessionImplTest, SpecificBarProperty, Function | SmallTest | Level3)1180 HWTEST_F(WindowSceneSessionImplTest, SpecificBarProperty, Function | SmallTest | Level3)
1181 {
1182 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1183 option->SetWindowName("SpecificBarProperty");
1184 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1185 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1186
1187 SystemBarProperty property = SystemBarProperty();
1188 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW,
1189 window->SetSpecificBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1190 if (window->property_ == nullptr) {
1191 ASSERT_EQ(WMError::WM_ERROR_NULLPTR,
1192 window->SetSpecificBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1193 }
1194 }
1195
1196 /*
1197 * @tc.name: NotifySpecificWindowSessionProperty
1198 * @tc.desc: NotifySpecificWindowSessionProperty01 test
1199 * @tc.type: FUNC
1200 */
HWTEST_F(WindowSceneSessionImplTest, NotifySpecificWindowSessionProperty, Function | SmallTest | Level3)1201 HWTEST_F(WindowSceneSessionImplTest, NotifySpecificWindowSessionProperty, Function | SmallTest | Level3)
1202 {
1203 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1204 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1205 option->SetWindowName("NotifySpecificWindowSessionProperty");
1206 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1207
1208 SystemBarProperty property = SystemBarProperty();
1209 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW,
1210 window->NotifySpecificWindowSessionProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1211 window->property_->SetPersistentId(190);
1212 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1213 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1214 ASSERT_NE(nullptr, session);
1215 window->hostSession_ = session;
1216 window->state_ = WindowState::STATE_HIDDEN;
1217 ASSERT_EQ(WMError::WM_OK,
1218 window->NotifySpecificWindowSessionProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1219 window->state_ = WindowState::STATE_SHOWN;
1220 ASSERT_EQ(WMError::WM_OK,
1221 window->NotifySpecificWindowSessionProperty(WindowType::WINDOW_TYPE_STATUS_BAR, property));
1222 }
1223
1224 /*
1225 * @tc.name: LimitCameraFloatWindowMininumSize
1226 * @tc.desc: LimitCameraFloatWindowMininumSize01 test
1227 * @tc.type: FUNC
1228 */
HWTEST_F(WindowSceneSessionImplTest, LimitCameraFloatWindowMininumSize, Function | SmallTest | Level3)1229 HWTEST_F(WindowSceneSessionImplTest, LimitCameraFloatWindowMininumSize, Function | SmallTest | Level3)
1230 {
1231 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1232 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1233 option->SetWindowName("LimitCameraFloatWindowMininumSize");
1234 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1235 uint32_t width = 33;
1236 uint32_t height = 31;
1237 float vpr = 0.0f;
1238 window->LimitCameraFloatWindowMininumSize(width, height, vpr);
1239 }
1240
1241 /*
1242 * @tc.name: NotifyWindowNeedAvoid
1243 * @tc.desc: NotifyWindowNeedAvoid test
1244 * @tc.type: FUNC
1245 */
HWTEST_F(WindowSceneSessionImplTest, NotifyWindowNeedAvoid, Function | SmallTest | Level3)1246 HWTEST_F(WindowSceneSessionImplTest, NotifyWindowNeedAvoid, Function | SmallTest | Level3)
1247 {
1248 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1249 option->SetWindowName("NotifyWindowNeedAvoid");
1250 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1251 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->NotifyWindowNeedAvoid(false));
1252
1253 window->state_ = WindowState::STATE_SHOWN;
1254 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1255 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1256 ASSERT_NE(nullptr, session);
1257 window->property_->SetPersistentId(190);
1258 window->hostSession_ = session;
1259 ASSERT_EQ(WMError::WM_OK, window->NotifyWindowNeedAvoid(false));
1260 }
1261
1262 /*
1263 * @tc.name: SetLayoutFullScreenByApiVersion
1264 * @tc.desc: SetLayoutFullScreenByApiVersion test
1265 * @tc.type: FUNC
1266 */
HWTEST_F(WindowSceneSessionImplTest, SetLayoutFullScreenByApiVersion, Function | SmallTest | Level3)1267 HWTEST_F(WindowSceneSessionImplTest, SetLayoutFullScreenByApiVersion, Function | SmallTest | Level3)
1268 {
1269 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1270 option->SetWindowName("SetLayoutFullScreenByApiVersion");
1271 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1272 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetLayoutFullScreenByApiVersion(false));
1273 window->state_ = WindowState::STATE_SHOWN;
1274 window->property_->SetPersistentId(190);
1275 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1276 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1277 ASSERT_NE(nullptr, session);
1278 window->hostSession_ = session;
1279 ASSERT_EQ(WMError::WM_OK, window->SetLayoutFullScreenByApiVersion(false));
1280 }
1281
1282 /*
1283 * @tc.name: SetGlobalMaximizeMode
1284 * @tc.desc: SetGlobalMaximizeMode test
1285 * @tc.type: FUNC
1286 */
HWTEST_F(WindowSceneSessionImplTest, SetGlobalMaximizeMode, Function | SmallTest | Level3)1287 HWTEST_F(WindowSceneSessionImplTest, SetGlobalMaximizeMode, Function | SmallTest | Level3)
1288 {
1289 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1290 option->SetWindowName("SetGlobalMaximizeMode");
1291 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1292 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetGlobalMaximizeMode(MaximizeMode::MODE_RECOVER));
1293
1294 window->state_ = WindowState::STATE_SHOWN;
1295 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1296 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1297 ASSERT_NE(nullptr, session);
1298 window->property_->SetPersistentId(190);
1299 window->hostSession_ = session;
1300 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1301 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetGlobalMaximizeMode(MaximizeMode::MODE_RECOVER));
1302
1303 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1304 ASSERT_EQ(WMError::WM_OK, window->SetGlobalMaximizeMode(MaximizeMode::MODE_RECOVER));
1305 }
1306
1307 /*
1308 * @tc.name: CheckParmAndPermission
1309 * @tc.desc: CheckParmAndPermission test
1310 * @tc.type: FUNC
1311 */
HWTEST_F(WindowSceneSessionImplTest, CheckParmAndPermission, Function | SmallTest | Level3)1312 HWTEST_F(WindowSceneSessionImplTest, CheckParmAndPermission, Function | SmallTest | Level3)
1313 {
1314 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1315 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1316 window->property_->SetWindowName("CheckParmAndPermission");
1317 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1318
1319 auto surfaceNode = window->GetSurfaceNode();
1320 if (surfaceNode == nullptr) {
1321 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->CheckParmAndPermission());
1322 } else {
1323 ASSERT_EQ(WMError::WM_OK, window->CheckParmAndPermission());
1324 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1325 ASSERT_EQ(WMError::WM_OK, window->CheckParmAndPermission());
1326 }
1327 }
1328
1329 /*
1330 * @tc.name: SetBackdropBlurStyle
1331 * @tc.desc: SetBackdropBlurStyle test
1332 * @tc.type: FUNC
1333 */
HWTEST_F(WindowSceneSessionImplTest, SetBackdropBlurStyle, Function | SmallTest | Level3)1334 HWTEST_F(WindowSceneSessionImplTest, SetBackdropBlurStyle, Function | SmallTest | Level3)
1335 {
1336 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1337 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
1338 window->property_->SetWindowName("SetBackdropBlurStyle");
1339 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1340 window->property_->SetDisplayId(3);
1341
1342 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_OFF));
1343 window->Destroy(true);
1344 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THICK));
1345 window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
1346 window->surfaceNode_ = nullptr;
1347 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_OFF));
1348 }
1349
1350 /*
1351 * @tc.name: SetTurnScreenOn
1352 * @tc.desc: SetTurnScreenOn test
1353 * @tc.type: FUNC
1354 */
HWTEST_F(WindowSceneSessionImplTest, SetTurnScreenOn, Function | SmallTest | Level3)1355 HWTEST_F(WindowSceneSessionImplTest, SetTurnScreenOn, Function | SmallTest | Level3)
1356 {
1357 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1358 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1359 window->property_->SetWindowName("SetTurnScreenOn");
1360 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1361 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetTurnScreenOn(false));
1362
1363 window->property_->SetPersistentId(1);
1364 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1365 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1366 ASSERT_NE(nullptr, session);
1367 window->hostSession_ = session;
1368 window->SetTurnScreenOn(false);
1369 }
1370
1371 /*
1372 * @tc.name: SetBlur
1373 * @tc.desc: SetBlur test
1374 * @tc.type: FUNC
1375 */
HWTEST_F(WindowSceneSessionImplTest, SetBlur, Function | SmallTest | Level3)1376 HWTEST_F(WindowSceneSessionImplTest, SetBlur, Function | SmallTest | Level3)
1377 {
1378 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1379 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
1380 window->property_->SetWindowName("SetBlur");
1381
1382 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBlur(-1.0));
1383 ASSERT_EQ(WMError::WM_OK, window->SetBlur(1.0));
1384 ASSERT_EQ(WMError::WM_OK, window->SetBlur(0.0));
1385 window->surfaceNode_ = nullptr;
1386 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetBlur(1.0));
1387 }
1388
1389 /*
1390 * @tc.name: SetKeepScreenOn
1391 * @tc.desc: SetKeepScreenOn test
1392 * @tc.type: FUNC
1393 */
HWTEST_F(WindowSceneSessionImplTest, SetKeepScreenOn, Function | SmallTest | Level3)1394 HWTEST_F(WindowSceneSessionImplTest, SetKeepScreenOn, Function | SmallTest | Level3)
1395 {
1396 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1397 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1398 window->property_->SetWindowName("SetKeepScreenOn");
1399 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1400 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetKeepScreenOn(false));
1401 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetKeepScreenOn(true));
1402
1403 window->property_->SetPersistentId(1);
1404 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1405 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1406 ASSERT_NE(nullptr, session);
1407 window->hostSession_ = session;
1408 ASSERT_EQ(WMError::WM_OK, window->SetKeepScreenOn(true));
1409 ASSERT_TRUE(window->IsKeepScreenOn());
1410 ASSERT_EQ(WMError::WM_OK, window->SetKeepScreenOn(false));
1411 ASSERT_FALSE(window->IsKeepScreenOn());
1412 }
1413
1414 /*
1415 * @tc.name: SetPrivacyMode01
1416 * @tc.desc: SetPrivacyMode as true
1417 * @tc.type: FUNC
1418 */
HWTEST_F(WindowSceneSessionImplTest, SetPrivacyMode01, Function | SmallTest | Level3)1419 HWTEST_F(WindowSceneSessionImplTest, SetPrivacyMode01, Function | SmallTest | Level3)
1420 {
1421 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1422 ASSERT_NE(nullptr, option);
1423 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1424 ASSERT_NE(nullptr, window);
1425 window->property_->SetWindowName("SetPrivacyMode");
1426 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1427 window->property_->SetPersistentId(1);
1428 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1429 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1430 ASSERT_NE(nullptr, session);
1431 window->hostSession_ = session;
1432 ASSERT_EQ(WMError::WM_OK, window->SetPrivacyMode(true));
1433 ASSERT_EQ(true, window->IsPrivacyMode());
1434 }
1435
1436 /*
1437 * @tc.name: SetPrivacyMode02
1438 * @tc.desc: SetPrivacyMode as false
1439 * @tc.type: FUNC
1440 */
HWTEST_F(WindowSceneSessionImplTest, SetPrivacyMode02, Function | SmallTest | Level3)1441 HWTEST_F(WindowSceneSessionImplTest, SetPrivacyMode02, Function | SmallTest | Level3)
1442 {
1443 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1444 ASSERT_NE(nullptr, option);
1445 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1446 ASSERT_NE(nullptr, window);
1447 window->property_->SetWindowName("SetPrivacyMode");
1448 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1449 window->property_->SetPersistentId(1);
1450 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1451 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1452 ASSERT_NE(nullptr, session);
1453 window->hostSession_ = session;
1454 ASSERT_EQ(WMError::WM_OK, window->SetPrivacyMode(false));
1455 ASSERT_EQ(false, window->IsPrivacyMode());
1456 }
1457
1458 /*
1459 * @tc.name: SetPrivacyMode03
1460 * @tc.desc: Window is invalid
1461 * @tc.type: FUNC
1462 */
HWTEST_F(WindowSceneSessionImplTest, SetPrivacyMode03, Function | SmallTest | Level3)1463 HWTEST_F(WindowSceneSessionImplTest, SetPrivacyMode03, Function | SmallTest | Level3)
1464 {
1465 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1466 ASSERT_NE(nullptr, option);
1467 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1468 ASSERT_NE(nullptr, window);
1469 window->property_->SetWindowName("SetPrivacyMode");
1470 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1471 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetPrivacyMode(false));
1472 }
1473
1474 /*
1475 * @tc.name: IsPrivacyMode
1476 * @tc.desc: Set window privacy mode as true and false
1477 * @tc.type: FUNC
1478 */
HWTEST_F(WindowSceneSessionImplTest, IsPrivacyModec, Function | SmallTest | Level3)1479 HWTEST_F(WindowSceneSessionImplTest, IsPrivacyModec, Function | SmallTest | Level3)
1480 {
1481 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1482 ASSERT_NE(nullptr, option);
1483 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1484 ASSERT_NE(nullptr, window);
1485 window->property_->SetWindowName("IsPrivacyModec");
1486 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1487 window->property_->SetPersistentId(1);
1488 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1489 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1490 ASSERT_NE(nullptr, session);
1491 window->hostSession_ = session;
1492 window->SetPrivacyMode(true);
1493 ASSERT_EQ(true, window->IsPrivacyMode());
1494 window->SetPrivacyMode(false);
1495 ASSERT_EQ(false, window->IsPrivacyMode());
1496 }
1497
1498 /*
1499 * @tc.name: SetSystemPrivacyMode
1500 * @tc.desc: Set Ststemwindow privacy mode as true and false
1501 * @tc.type: FUNC
1502 */
HWTEST_F(WindowSceneSessionImplTest, SetSystemPrivacyMode, Function | SmallTest | Level3)1503 HWTEST_F(WindowSceneSessionImplTest, SetSystemPrivacyMode, Function | SmallTest | Level3)
1504 {
1505 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1506 ASSERT_NE(nullptr, option);
1507 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1508 ASSERT_NE(nullptr, window);
1509 window->property_->SetWindowName("SetSystemPrivacyMode");
1510 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1511 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1512 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1513 ASSERT_NE(nullptr, session);
1514 window->hostSession_ = session;
1515 window->SetSystemPrivacyMode(true);
1516 ASSERT_EQ(true, window->property_->GetSystemPrivacyMode());
1517 window->SetSystemPrivacyMode(false);
1518 ASSERT_EQ(false, window->property_->GetSystemPrivacyMode());
1519 }
1520
1521 /*
1522 * @tc.name: SetSnapshotSkip
1523 * @tc.desc: SetSnapshotSkip test
1524 * @tc.type: FUNC
1525 */
HWTEST_F(WindowSceneSessionImplTest, SetSnapshotSkip, Function | SmallTest | Level3)1526 HWTEST_F(WindowSceneSessionImplTest, SetSnapshotSkip, Function | SmallTest | Level3)
1527 {
1528 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1529 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1530 window->property_->SetWindowName("SetSnapshotSkip");
1531 window->property_->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
1532 window->property_->SetPersistentId(1);
1533 auto surfaceNode_mocker = CreateRSSurfaceNode();
1534 if (surfaceNode_mocker != nullptr) {
1535 ASSERT_NE(nullptr, surfaceNode_mocker);
1536 }
1537
1538 window->surfaceNode_ = surfaceNode_mocker;
1539 auto surfaceNode = window->GetSurfaceNode();
1540
1541 if (surfaceNode != nullptr) {
1542 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetSnapshotSkip(false));
1543 } else {
1544 ASSERT_EQ(nullptr, surfaceNode);
1545 }
1546 }
1547
1548 /*
1549 * @tc.name: SetImmersiveModeEnabledState
1550 * @tc.desc: SetImmersiveModeEnabledState test
1551 * @tc.type: FUNC
1552 */
HWTEST_F(WindowSceneSessionImplTest, SetImmersiveModeEnabledState, Function | SmallTest | Level3)1553 HWTEST_F(WindowSceneSessionImplTest, SetImmersiveModeEnabledState, Function | SmallTest | Level3)
1554 {
1555 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1556 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1557 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetImmersiveModeEnabledState(false));
1558
1559 window->property_->SetPersistentId(1);
1560 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1561 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1562 ASSERT_NE(nullptr, session);
1563 window->hostSession_ = session;
1564 window->property_->SetWindowName("SetImmersiveModeEnabledState");
1565 window->property_->SetWindowType(WindowType::WINDOW_TYPE_PIP);
1566 window->state_ = WindowState::STATE_CREATED;
1567 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetImmersiveModeEnabledState(false));
1568
1569 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1570 ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(true));
1571 ASSERT_EQ(true, window->GetImmersiveModeEnabledState());
1572 ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(false));
1573 ASSERT_EQ(false, window->GetImmersiveModeEnabledState());
1574
1575 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1576 ASSERT_EQ(WMError::WM_OK, window->SetLayoutFullScreen(true));
1577 ASSERT_EQ(true, window->IsLayoutFullScreen());
1578 ASSERT_EQ(WMError::WM_OK, window->SetLayoutFullScreen(false));
1579 ASSERT_EQ(false, window->IsLayoutFullScreen());
1580 ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(true));
1581 ASSERT_EQ(true, window->IsLayoutFullScreen());
1582 ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(false));
1583 ASSERT_EQ(false, window->IsLayoutFullScreen());
1584
1585 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1586 ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(true));
1587 ASSERT_EQ(true, window->IsLayoutFullScreen());
1588 ASSERT_EQ(true, window->GetImmersiveModeEnabledState());
1589 ASSERT_EQ(WMError::WM_OK, window->MaximizeFloating());
1590 ASSERT_EQ(true, window->IsLayoutFullScreen());
1591 }
1592
1593 /*
1594 * @tc.name: SetLayoutFullScreen01
1595 * @tc.desc: SetLayoutFullScreen test
1596 * @tc.type: FUNC
1597 */
HWTEST_F(WindowSceneSessionImplTest, SetLayoutFullScreen01, Function | SmallTest | Level3)1598 HWTEST_F(WindowSceneSessionImplTest, SetLayoutFullScreen01, Function | SmallTest | Level3)
1599 {
1600 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1601 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
1602 window->property_->SetWindowName("SetLayoutFullScreen01");
1603 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1604 window->property_->SetPersistentId(1);
1605 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1606 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1607 ASSERT_NE(nullptr, session);
1608 window->hostSession_ = session;
1609 WMError res = window->SetLayoutFullScreen(false);
1610 ASSERT_EQ(WMError::WM_OK, res);
1611 ASSERT_EQ(false, window->IsLayoutFullScreen());
1612 }
1613
1614 /*
1615 * @tc.name: SetLayoutFullScreen02
1616 * @tc.desc: SetLayoutFullScreen test
1617 * @tc.type: FUNC
1618 */
HWTEST_F(WindowSceneSessionImplTest, SetLayoutFullScreen02, Function | SmallTest | Level3)1619 HWTEST_F(WindowSceneSessionImplTest, SetLayoutFullScreen02, Function | SmallTest | Level3)
1620 {
1621 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1622 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
1623 window->property_->SetWindowName("SetLayoutFullScreen02");
1624 window->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
1625
1626 window->hostSession_ = nullptr;
1627 window->property_->SetCompatibleModeInPc(true);
1628 WMError res = window->SetLayoutFullScreen(false);
1629 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, res);
1630 }
1631
1632 /*
1633 * @tc.name: SetTitleAndDockHoverShown
1634 * @tc.desc: SetTitleAndDockHoverShown test
1635 * @tc.type: FUNC
1636 */
HWTEST_F(WindowSceneSessionImplTest, SetTitleAndDockHoverShown, Function | SmallTest | Level3)1637 HWTEST_F(WindowSceneSessionImplTest, SetTitleAndDockHoverShown, Function | SmallTest | Level3)
1638 {
1639 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1640 ASSERT_NE(nullptr, option);
1641 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
1642 ASSERT_NE(nullptr, window);
1643
1644 window->property_->SetPersistentId(1);
1645 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1646 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1647 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1648 ASSERT_NE(nullptr, session);
1649 window->hostSession_ = session;
1650 EXPECT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->SetTitleAndDockHoverShown(true, true));
1651
1652 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1653 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1654 EXPECT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetTitleAndDockHoverShown(true, true));
1655
1656 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1657 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1658 EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetTitleAndDockHoverShown(true, true));
1659 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1660 EXPECT_EQ(WMError::WM_OK, window->SetTitleAndDockHoverShown(true, true));
1661 }
1662
1663 /*
1664 * @tc.name: SetFullScreen
1665 * @tc.desc: SetFullScreen test
1666 * @tc.type: FUNC
1667 */
HWTEST_F(WindowSceneSessionImplTest, SetFullScreen, Function | SmallTest | Level3)1668 HWTEST_F(WindowSceneSessionImplTest, SetFullScreen, Function | SmallTest | Level3)
1669 {
1670 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1671 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1672 window->property_->SetWindowName("SetFullScreen");
1673 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1674 window->SetFullScreen(false);
1675 window->property_->SetPersistentId(1);
1676 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1677 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1678 ASSERT_NE(nullptr, session);
1679 window->hostSession_ = session;
1680
1681 ASSERT_EQ(WMError::WM_OK, window->SetFullScreen(false));
1682 ASSERT_EQ(false, window->IsFullScreen());
1683 }
1684
1685 /*
1686 * @tc.name: SetShadowOffsetX
1687 * @tc.desc: SetShadowOffsetX test
1688 * @tc.type: FUNC
1689 */
HWTEST_F(WindowSceneSessionImplTest, SetShadowOffsetX, Function | SmallTest | Level3)1690 HWTEST_F(WindowSceneSessionImplTest, SetShadowOffsetX, Function | SmallTest | Level3)
1691 {
1692 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1693 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
1694 window->property_->SetWindowName("SetShadowOffsetX");
1695 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1696
1697 ASSERT_EQ(WMError::WM_OK, window->SetShadowOffsetX(1.0));
1698 window->surfaceNode_ = nullptr;
1699 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetShadowOffsetX(1.0));
1700 }
1701
1702 /*
1703 * @tc.name: SetShadowOffsetY
1704 * @tc.desc: SetShadowOffsetY test
1705 * @tc.type: FUNC
1706 */
HWTEST_F(WindowSceneSessionImplTest, SetShadowOffsetY, Function | SmallTest | Level3)1707 HWTEST_F(WindowSceneSessionImplTest, SetShadowOffsetY, Function | SmallTest | Level3)
1708 {
1709 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1710 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
1711 window->property_->SetWindowName("SetShadowOffsetY");
1712 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1713
1714 ASSERT_EQ(WMError::WM_OK, window->SetShadowOffsetY(1.0));
1715 window->surfaceNode_ = nullptr;
1716 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetShadowOffsetY(1.0));
1717 }
1718
1719 /*
1720 * @tc.name: GetStatusBarHeight
1721 * @tc.desc: GetStatusBarHeight test
1722 * @tc.type: FUNC
1723 */
HWTEST_F(WindowSceneSessionImplTest, GetStatusBarHeight, Function | SmallTest | Level3)1724 HWTEST_F(WindowSceneSessionImplTest, GetStatusBarHeight, Function | SmallTest | Level3)
1725 {
1726 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1727 option->SetWindowName("GetStatusBarHeight");
1728 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1729 ASSERT_NE(window, nullptr);
1730 ASSERT_EQ(0, window->GetStatusBarHeight());
1731 }
1732
1733 /*
1734 * @tc.name: SetGestureBackEnabled
1735 * @tc.desc: SetGestureBackEnabled test
1736 * @tc.type: FUNC
1737 */
HWTEST_F(WindowSceneSessionImplTest, SetGestureBackEnabled, Function | SmallTest | Level3)1738 HWTEST_F(WindowSceneSessionImplTest, SetGestureBackEnabled, Function | SmallTest | Level3)
1739 {
1740 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1741 ASSERT_NE(nullptr, option);
1742 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
1743 ASSERT_NE(nullptr, window);
1744 window->property_->SetPersistentId(1);
1745 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1746 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1747 ASSERT_NE(nullptr, session);
1748 window->hostSession_ = session;
1749 window->property_->SetWindowName("SetGestureBackEnabled");
1750 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1751 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetGestureBackEnabled(false));
1752 window->property_->SetWindowType(WindowType::WINDOW_TYPE_PIP);
1753 window->state_ = WindowState::STATE_CREATED;
1754 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1755 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetGestureBackEnabled(false));
1756 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1757 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1758 ASSERT_EQ(WMError::WM_OK, window->SetGestureBackEnabled(true));
1759 ASSERT_EQ(true, window->GetGestureBackEnabled());
1760 ASSERT_EQ(WMError::WM_OK, window->SetGestureBackEnabled(false));
1761 ASSERT_EQ(false, window->GetGestureBackEnabled());
1762 }
1763
1764 /*
1765 * @tc.name: CompatibleFullScreenRecover
1766 * @tc.desc: CompatibleFullScreenRecover test
1767 * @tc.type: FUNC
1768 */
HWTEST_F(WindowSceneSessionImplTest, CompatibleFullScreenRecover, Function | SmallTest | Level2)1769 HWTEST_F(WindowSceneSessionImplTest, CompatibleFullScreenRecover, Function | SmallTest | Level2)
1770 {
1771 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1772 ASSERT_NE(option, nullptr);
1773 option->SetWindowName("CompatibleFullScreenRecover");
1774 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
1775 ASSERT_NE(window, nullptr);
1776 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1777 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1778 ASSERT_NE(nullptr, session);
1779 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW, window->CompatibleFullScreenRecover());
1780
1781 window->hostSession_ = session;
1782 window->property_->SetPersistentId(1);
1783 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW, window->CompatibleFullScreenRecover());
1784
1785 window->property_->SetCompatibleModeInPc(true);
1786 ASSERT_EQ(WSError::WS_OK, window->CompatibleFullScreenRecover());
1787 }
1788
1789 /*
1790 * @tc.name: CompatibleFullScreenMinimize
1791 * @tc.desc: CompatibleFullScreenMinimize test
1792 * @tc.type: FUNC
1793 */
HWTEST_F(WindowSceneSessionImplTest, CompatibleFullScreenMinimize, Function | SmallTest | Level2)1794 HWTEST_F(WindowSceneSessionImplTest, CompatibleFullScreenMinimize, Function | SmallTest | Level2)
1795 {
1796 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1797 ASSERT_NE(option, nullptr);
1798 option->SetWindowName("CompatibleFullScreenMinimize");
1799 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
1800 ASSERT_NE(window, nullptr);
1801 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1802 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1803 ASSERT_NE(nullptr, session);
1804 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW, window->CompatibleFullScreenMinimize());
1805
1806 window->hostSession_ = session;
1807 window->property_->SetPersistentId(1);
1808 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW, window->CompatibleFullScreenMinimize());
1809
1810 window->property_->SetCompatibleModeInPc(true);
1811 ASSERT_EQ(WSError::WS_OK, window->CompatibleFullScreenMinimize());
1812 }
1813
1814 /*
1815 * @tc.name: CompatibleFullScreenClose
1816 * @tc.desc: CompatibleFullScreenClose test
1817 * @tc.type: FUNC
1818 */
HWTEST_F(WindowSceneSessionImplTest, CompatibleFullScreenClose, Function | SmallTest | Level2)1819 HWTEST_F(WindowSceneSessionImplTest, CompatibleFullScreenClose, Function | SmallTest | Level2)
1820 {
1821 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1822 ASSERT_NE(option, nullptr);
1823 option->SetWindowName("CompatibleFullScreenClose");
1824 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
1825 ASSERT_NE(window, nullptr);
1826 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1827 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1828 ASSERT_NE(nullptr, session);
1829 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW, window->CompatibleFullScreenClose());
1830
1831 window->hostSession_ = session;
1832 window->property_->SetPersistentId(1);
1833 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW, window->CompatibleFullScreenClose());
1834
1835 window->property_->SetCompatibleModeInPc(true);
1836 ASSERT_EQ(WSError::WS_OK, window->CompatibleFullScreenClose());
1837 }
1838 }
1839 } // namespace Rosen
1840 } // namespace OHOS
1841