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 {
43 }
44
TearDownTestCase()45 void SCBSystemSessionLayoutTest::TearDownTestCase()
46 {
47 }
48
SetUp()49 void SCBSystemSessionLayoutTest::SetUp()
50 {
51 SessionInfo info;
52 info.abilityName_ = "testSCBSystemSession1";
53 info.moduleName_ = "testSCBSystemSession2";
54 info.bundleName_ = "testSCBSystemSession3";
55 scbSystemSession_ = sptr<SCBSystemSession>::MakeSptr(info, specificCallback_);
56 }
57
TearDown()58 void SCBSystemSessionLayoutTest::TearDown()
59 {
60 scbSystemSession_ = nullptr;
61 }
62
63 namespace {
64 /**
65 * @tc.name: UpdateWindowMode
66 * @tc.desc: check func UpdateWindowMode
67 * @tc.type: FUNC
68 */
69 HWTEST_F(SCBSystemSessionLayoutTest, UpdateWindowMode, Function | SmallTest | Level1)
70 {
71 scbSystemSession_->PresentFocusIfPointDown();
72 scbSystemSession_->PresentFoucusIfNeed(2);
73 ASSERT_EQ(WSError::WS_OK, scbSystemSession_->SetSystemSceneBlockingFocus(true));
74 WSRect rect = {0, 0, 0, 0};
75 scbSystemSession_->UpdatePointerArea(rect);
76 auto ret = scbSystemSession_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
77 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, ret);
78 }
79
80 /**
81 * @tc.name: NotifyClientToUpdateRect02
82 * @tc.desc: check func NotifyClientToUpdateRect
83 * @tc.type: FUNC
84 */
85 HWTEST_F(SCBSystemSessionLayoutTest, NotifyClientToUpdateRect02, Function | SmallTest | Level3)
86 {
87 auto specificCallback1 = sptr<SCBSystemSession::SpecificSessionCallback>::MakeSptr();
88 SessionInfo info;
89 sptr<SCBSystemSession> scbSystemSession = sptr<SCBSystemSession>::MakeSptr(info, specificCallback1);
90 UpdateAvoidAreaCallback onUpdateAvoidArea;
91 ClearDisplayStatusBarTemporarilyFlags onClearDisplayStatusBarTemporarilyFlags;
92 scbSystemSession->specificCallback_ = specificCallback1;
93 scbSystemSession->specificCallback_->onUpdateAvoidArea_ = onUpdateAvoidArea;
94 scbSystemSession->specificCallback_->onClearDisplayStatusBarTemporarilyFlags_ =
95 onClearDisplayStatusBarTemporarilyFlags;
96 auto ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
97 ASSERT_EQ(WSError::WS_OK, ret);
98
99 scbSystemSession->specificCallback_->onClearDisplayStatusBarTemporarilyFlags_ = nullptr;
100 ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
101 ASSERT_EQ(WSError::WS_OK, ret);
102
103 scbSystemSession->specificCallback_->onUpdateAvoidArea_ = nullptr;
104 ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
105 ASSERT_EQ(WSError::WS_OK, ret);
106
107 scbSystemSession->specificCallback_->onClearDisplayStatusBarTemporarilyFlags_ =
108 onClearDisplayStatusBarTemporarilyFlags;
109 ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
110 ASSERT_EQ(WSError::WS_OK, ret);
111
112 scbSystemSession->specificCallback_ = nullptr;
113 ret = scbSystemSession->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
114 ASSERT_EQ(WSError::WS_OK, ret);
115 }
116
117 /**
118 * @tc.name: NotifyClientToUpdateRect03
119 * @tc.desc: check func NotifyClientToUpdateRect
120 * @tc.type: FUNC
121 */
122 HWTEST_F(SCBSystemSessionLayoutTest, NotifyClientToUpdateRect03, Function | SmallTest | Level1)
123 {
124 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
125 property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
126
127 auto ret = scbSystemSession_->SetSessionProperty(property);
128 ASSERT_EQ(WSError::WS_OK, ret);
129 KeyboardPanelRectUpdateCallback keyboardPanelRectUpdateCallback;
130 scbSystemSession_->keyboardPanelRectUpdateCallback_ = keyboardPanelRectUpdateCallback;
131 scbSystemSession_->isKeyboardPanelEnabled_ = true;
132 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
133 ASSERT_EQ(WSError::WS_OK, ret);
134
135 scbSystemSession_->isKeyboardPanelEnabled_ = false;
136 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
137 ASSERT_EQ(WSError::WS_OK, ret);
138
139 scbSystemSession_->keyboardPanelRectUpdateCallback_ = nullptr;
140 scbSystemSession_->isKeyboardPanelEnabled_ = true;
141 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
142 ASSERT_EQ(WSError::WS_OK, ret);
143
144 scbSystemSession_->isKeyboardPanelEnabled_ = false;
145 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
146 ASSERT_EQ(WSError::WS_OK, ret);
147
148 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
149 ret = scbSystemSession_->SetSessionProperty(property);
150 ASSERT_EQ(WSError::WS_OK, ret);
151 scbSystemSession_->keyboardPanelRectUpdateCallback_ = keyboardPanelRectUpdateCallback;
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_->keyboardPanelRectUpdateCallback_ = nullptr;
161 scbSystemSession_->isKeyboardPanelEnabled_ = true;
162 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
163 ASSERT_EQ(WSError::WS_OK, ret);
164
165 scbSystemSession_->isKeyboardPanelEnabled_ = false;
166 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
167 ASSERT_EQ(WSError::WS_OK, ret);
168
169 scbSystemSession_->reason_ = SizeChangeReason::DRAG;
170 ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
171 ASSERT_EQ(WSError::WS_OK, ret);
172 }
173
174 /**
175 * @tc.name: NotifyClientToUpdateRect04
176 * @tc.desc: check func NotifyClientToUpdateRect
177 * @tc.type: FUNC
178 */
179 HWTEST_F(SCBSystemSessionLayoutTest, NotifyClientToUpdateRect04, Function | SmallTest | Level1)
180 {
181 scbSystemSession_->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
182 auto ret = scbSystemSession_->NotifyClientToUpdateRect("SCBSystemSessionLayoutTest", nullptr);
183 ASSERT_EQ(WSError::WS_OK, ret);
184 }
185 } //namespace
186 } //namespace Rosen
187 } //namespace OHOS