• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "session/host/include/system_session.h"
18 
19 #include "common/include/session_permission.h"
20 #include "key_event.h"
21 #include "mock/mock_session_stage.h"
22 #include "session/host/include/session.h"
23 #include <ui/rs_surface_node.h>
24 #include "window_event_channel_base.h"
25 #include "window_helper.h"
26 #include "window_manager_hilog.h"
27 #include "pointer_event.h"
28 
29 using namespace testing;
30 using namespace testing::ext;
31 
32 namespace OHOS {
33 namespace Rosen {
34 class SystemSessionLifecycleTest : public testing::Test {
35 public:
36     static void SetUpTestCase();
37     static void TearDownTestCase();
38     void SetUp() override;
39     void TearDown() override;
40     SessionInfo info;
41     sptr<SystemSession::SpecificSessionCallback> specificCallback = nullptr;
42     sptr<SystemSession> systemSession_;
43 
44 private:
45     RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
46 };
47 
SetUpTestCase()48 void SystemSessionLifecycleTest::SetUpTestCase() {}
49 
TearDownTestCase()50 void SystemSessionLifecycleTest::TearDownTestCase() {}
51 
SetUp()52 void SystemSessionLifecycleTest::SetUp()
53 {
54     SessionInfo info;
55     info.abilityName_ = "testSystemSession1";
56     info.moduleName_ = "testSystemSession2";
57     info.bundleName_ = "testSystemSession3";
58     systemSession_ = sptr<SystemSession>::MakeSptr(info, specificCallback);
59     EXPECT_NE(nullptr, systemSession_);
60 }
61 
TearDown()62 void SystemSessionLifecycleTest::TearDown()
63 {
64     systemSession_ = nullptr;
65 }
66 
CreateRSSurfaceNode()67 RSSurfaceNode::SharedPtr SystemSessionLifecycleTest::CreateRSSurfaceNode()
68 {
69     struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
70     rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTestSurfaceNode";
71     auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
72     return surfaceNode;
73 }
74 
75 namespace {
76 
77 /**
78  * @tc.name: Show
79  * @tc.desc: test function : Show
80  * @tc.type: FUNC
81  */
82 HWTEST_F(SystemSessionLifecycleTest, Show01, TestSize.Level1)
83 {
84     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
85 
86     ASSERT_TRUE((systemSession_ != nullptr));
87     ASSERT_EQ(WSError::WS_OK, systemSession_->Show(property));
88 }
89 
90 /**
91  * @tc.name: Show
92  * @tc.desc: test function : Show
93  * @tc.type: FUNC
94  */
95 HWTEST_F(SystemSessionLifecycleTest, Show02, TestSize.Level1)
96 {
97     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
98     ASSERT_TRUE((property != nullptr));
99     property->SetWindowType(WindowType::WINDOW_TYPE_TOAST);
100     ASSERT_TRUE((systemSession_ != nullptr));
101     systemSession_->SetSessionProperty(property);
102     ASSERT_EQ(WSError::WS_OK, systemSession_->Show(property));
103 }
104 
105 /**
106  * @tc.name: Show
107  * @tc.desc: test function : Show
108  * @tc.type: FUNC
109  */
110 HWTEST_F(SystemSessionLifecycleTest, Show03, TestSize.Level1)
111 {
112     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
113     ASSERT_TRUE((property != nullptr));
114     property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
115     ASSERT_TRUE((systemSession_ != nullptr));
116     systemSession_->SetSessionProperty(property);
117     ASSERT_EQ(WSError::WS_OK, systemSession_->Show(property));
118 }
119 
120 /**
121  * @tc.name: Reconnect01
122  * @tc.desc: check func Reconnect
123  * @tc.type: FUNC
124  */
125 HWTEST_F(SystemSessionLifecycleTest, Reconnect01, TestSize.Level1)
126 {
127     auto surfaceNode = CreateRSSurfaceNode();
128     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
129     ASSERT_NE(nullptr, property);
130     sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
131     EXPECT_NE(nullptr, mockSessionStage);
132     sptr<TestWindowEventChannel> testWindowEventChannel = sptr<TestWindowEventChannel>::MakeSptr();
133     EXPECT_NE(nullptr, testWindowEventChannel);
134 
135     auto result = systemSession_->Reconnect(nullptr, nullptr, nullptr, property);
136     ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
137 
138     result = systemSession_->Reconnect(nullptr, testWindowEventChannel, surfaceNode, property);
139     ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
140 
141     result = systemSession_->Reconnect(mockSessionStage, nullptr, surfaceNode, property);
142     ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
143 
144     result = systemSession_->Reconnect(mockSessionStage, testWindowEventChannel, surfaceNode, nullptr);
145     ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
146 
147     property->windowState_ = WindowState::STATE_INITIAL;
148     result = systemSession_->Reconnect(mockSessionStage, testWindowEventChannel, surfaceNode, property);
149     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
150 
151     property->windowState_ = WindowState::STATE_CREATED;
152     result = systemSession_->Reconnect(mockSessionStage, testWindowEventChannel, surfaceNode, property);
153     ASSERT_EQ(result, WSError::WS_OK);
154 
155     property->windowState_ = WindowState::STATE_SHOWN;
156     result = systemSession_->Reconnect(mockSessionStage, testWindowEventChannel, surfaceNode, property);
157     ASSERT_EQ(result, WSError::WS_OK);
158 
159     property->windowState_ = WindowState::STATE_HIDDEN;
160     result = systemSession_->Reconnect(mockSessionStage, testWindowEventChannel, surfaceNode, property);
161     ASSERT_EQ(result, WSError::WS_OK);
162 
163     property->windowState_ = WindowState::STATE_DESTROYED;
164     result = systemSession_->Reconnect(mockSessionStage, testWindowEventChannel, surfaceNode, property);
165     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
166 }
167 
168 /**
169  * @tc.name: Hide
170  * @tc.desc: test function : Hide
171  * @tc.type: FUNC
172  */
173 HWTEST_F(SystemSessionLifecycleTest, Hide, TestSize.Level1)
174 {
175     ASSERT_TRUE(systemSession_ != nullptr);
176 
177     auto ret = systemSession_->Hide();
178     ASSERT_EQ(WSError::WS_OK, ret);
179 }
180 
181 /**
182  * @tc.name: Disconnect
183  * @tc.desc: test function : Disconnect
184  * @tc.type: FUNC
185  */
186 HWTEST_F(SystemSessionLifecycleTest, Disconnect, TestSize.Level1)
187 {
188     ASSERT_TRUE(systemSession_ != nullptr);
189 
190     bool isFromClient = true;
191     auto ret = systemSession_->Disconnect(isFromClient);
192     ASSERT_EQ(WSError::WS_OK, ret);
193 }
194 
195 /**
196  * @tc.name: Disconnect02
197  * @tc.desc: test function : Disconnect
198  * @tc.type: FUNC
199  */
200 HWTEST_F(SystemSessionLifecycleTest, Disconnect02, TestSize.Level1)
201 {
202     SessionInfo info;
203     info.abilityName_ = "Disconnect02";
204     info.bundleName_ = "Disconnect02Func";
205     info.windowType_ = 2122;
206     sptr<SceneSession::SpecificSessionCallback> specificCallback =
207         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
208     ASSERT_NE(specificCallback, nullptr);
209     sptr<SystemSession> sysSession = sptr<SystemSession>::MakeSptr(info, specificCallback);
210     ASSERT_NE(sysSession, nullptr);
211 
212     bool isFromClient = true;
213     auto ret = sysSession->Disconnect(isFromClient);
214     ASSERT_EQ(WSError::WS_OK, ret);
215 }
216 
217 /**
218  * @tc.name: Disconnect03
219  * @tc.desc: test function : Disconnect
220  * @tc.type: FUNC
221  */
222 HWTEST_F(SystemSessionLifecycleTest, Disconnect03, TestSize.Level1)
223 {
224     SessionInfo info;
225     info.abilityName_ = "Disconnect03";
226     info.bundleName_ = "Disconnect03Func";
227     info.windowType_ = 2122;
228     sptr<SceneSession::SpecificSessionCallback> specificCallback =
229         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
230     ASSERT_NE(specificCallback, nullptr);
231     sptr<SystemSession> sysSession = sptr<SystemSession>::MakeSptr(info, specificCallback);
232     ASSERT_NE(sysSession, nullptr);
233 
234     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
235     WindowType type = WindowType::WINDOW_TYPE_FLOAT_CAMERA;
236     property->SetWindowType(type);
237     sysSession->property_ = property;
238 
239     bool isFromClient = true;
240     auto ret = sysSession->Disconnect(isFromClient);
241     ASSERT_EQ(WSError::WS_OK, ret);
242 }
243 } // namespace
244 } // namespace Rosen
245 } // namespace OHOS