1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17
18 #include "common/include/session_permission.h"
19 #include "key_event.h"
20 #include "mock/mock_session_stage.h"
21 #include "session/host/include/scb_system_session.h"
22 #include "session/host/include/session.h"
23 #include "window_helper.h"
24 #include "window_manager_hilog.h"
25
26 using namespace testing;
27 using namespace testing::ext;
28
29 namespace OHOS {
30 namespace Rosen {
31 class SCBSystemSessionLayoutTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp() override;
36 void TearDown() override;
37 sptr<SCBSystemSession::SpecificSessionCallback> specificCallback_ = nullptr;
38 sptr<SCBSystemSession> scbSystemSession_;
39 };
40
SetUpTestCase()41 void SCBSystemSessionLayoutTest::SetUpTestCase() {}
42
TearDownTestCase()43 void SCBSystemSessionLayoutTest::TearDownTestCase() {}
44
SetUp()45 void SCBSystemSessionLayoutTest::SetUp()
46 {
47 SessionInfo info;
48 info.abilityName_ = "testSCBSystemSession1";
49 info.moduleName_ = "testSCBSystemSession2";
50 info.bundleName_ = "testSCBSystemSession3";
51 scbSystemSession_ = sptr<SCBSystemSession>::MakeSptr(info, specificCallback_);
52 }
53
TearDown()54 void SCBSystemSessionLayoutTest::TearDown()
55 {
56 scbSystemSession_ = nullptr;
57 }
58
59 namespace {
60 /**
61 * @tc.name: UpdateWindowMode
62 * @tc.desc: check func UpdateWindowMode
63 * @tc.type: FUNC
64 */
65 HWTEST_F(SCBSystemSessionLayoutTest, UpdateWindowMode, TestSize.Level1)
66 {
67 scbSystemSession_->PresentFocusIfPointDown();
68 scbSystemSession_->PresentFocusIfNeed(2, 0);
69 ASSERT_EQ(WSError::WS_OK, scbSystemSession_->SetSystemSceneBlockingFocus(true));
70 WSRect rect = { 0, 0, 0, 0 };
71 scbSystemSession_->UpdatePointerArea(rect);
72 auto ret = scbSystemSession_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
73 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, ret);
74 }
75
76 /**
77 * @tc.name: NotifyClientToUpdateRect02
78 * @tc.desc: check func NotifyClientToUpdateRect
79 * @tc.type: FUNC
80 */
81 HWTEST_F(SCBSystemSessionLayoutTest, NotifyClientToUpdateRect02, TestSize.Level1)
82 {
83 auto specificCallback1 = sptr<SCBSystemSession::SpecificSessionCallback>::MakeSptr();
84 SessionInfo info;
85 sptr<SCBSystemSession> scbSystemSession = sptr<SCBSystemSession>::MakeSptr(info, specificCallback1);
86 UpdateAvoidAreaCallback onUpdateAvoidArea;
87 ClearDisplayStatusBarTemporarilyFlags onClearDisplayStatusBarTemporarilyFlags;
88 scbSystemSession->specificCallback_ = specificCallback1;
89 scbSystemSession->specificCallback_->onUpdateAvoidArea_ = onUpdateAvoidArea;
90 scbSystemSession->specificCallback_->onClearDisplayStatusBarTemporarilyFlags_ =
91 onClearDisplayStatusBarTemporarilyFlags;
92 auto ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
93 ASSERT_EQ(WSError::WS_OK, ret);
94
95 scbSystemSession->specificCallback_->onClearDisplayStatusBarTemporarilyFlags_ = nullptr;
96 ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
97 ASSERT_EQ(WSError::WS_OK, ret);
98
99 scbSystemSession->specificCallback_->onUpdateAvoidArea_ = nullptr;
100 ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
101 ASSERT_EQ(WSError::WS_OK, ret);
102
103 scbSystemSession->specificCallback_->onClearDisplayStatusBarTemporarilyFlags_ =
104 onClearDisplayStatusBarTemporarilyFlags;
105 ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
106 ASSERT_EQ(WSError::WS_OK, ret);
107
108 scbSystemSession->specificCallback_ = nullptr;
109 ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
110 ASSERT_EQ(WSError::WS_OK, ret);
111 }
112
113 /**
114 * @tc.name: NotifyClientToUpdateRect03
115 * @tc.desc: check func NotifyClientToUpdateRect
116 * @tc.type: FUNC
117 */
118 HWTEST_F(SCBSystemSessionLayoutTest, NotifyClientToUpdateRect03, TestSize.Level1)
119 {
120 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
121 property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
122
123 auto ret = scbSystemSession_->SetSessionProperty(property);
124 ASSERT_EQ(WSError::WS_OK, ret);
125 scbSystemSession_->isKeyboardPanelEnabled_ = true;
126 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
127 ASSERT_EQ(WSError::WS_OK, ret);
128
129 scbSystemSession_->isKeyboardPanelEnabled_ = false;
130 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
131 ASSERT_EQ(WSError::WS_OK, ret);
132
133 scbSystemSession_->isKeyboardPanelEnabled_ = true;
134 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
135 ASSERT_EQ(WSError::WS_OK, ret);
136
137 scbSystemSession_->isKeyboardPanelEnabled_ = false;
138 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
139 ASSERT_EQ(WSError::WS_OK, ret);
140
141 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
142 ret = scbSystemSession_->SetSessionProperty(property);
143 ASSERT_EQ(WSError::WS_OK, ret);
144 scbSystemSession_->isKeyboardPanelEnabled_ = true;
145 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
146 ASSERT_EQ(WSError::WS_OK, ret);
147
148 scbSystemSession_->isKeyboardPanelEnabled_ = false;
149 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
150 ASSERT_EQ(WSError::WS_OK, ret);
151
152 scbSystemSession_->isKeyboardPanelEnabled_ = true;
153 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
154 ASSERT_EQ(WSError::WS_OK, ret);
155
156 scbSystemSession_->isKeyboardPanelEnabled_ = false;
157 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
158 ASSERT_EQ(WSError::WS_OK, ret);
159
160 scbSystemSession_->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG);
161 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
162 ASSERT_EQ(WSError::WS_OK, ret);
163 }
164
165 /**
166 * @tc.name: NotifyClientToUpdateRect04
167 * @tc.desc: check func NotifyClientToUpdateRect
168 * @tc.type: FUNC
169 */
170 HWTEST_F(SCBSystemSessionLayoutTest, NotifyClientToUpdateRect04, TestSize.Level1)
171 {
172 scbSystemSession_->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
173 auto ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
174 ASSERT_EQ(WSError::WS_OK, ret);
175 }
176 } // namespace
177 } // namespace Rosen
178 } // namespace OHOS