• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <bundle_mgr_interface.h>
17 #include <bundlemgr/launcher_service.h>
18 #include <gtest/gtest.h>
19 
20 #include "interfaces/include/ws_common.h"
21 #include "iremote_object_mocker.h"
22 #include "screen_session_manager_client/include/screen_session_manager_client.h"
23 #include "session_manager/include/scene_session_manager.h"
24 #include "session_info.h"
25 #include "session/host/include/scene_session.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace Rosen {
32 namespace {
33 const std::string EMPTY_DEVICE_ID = "";
34 constexpr float SINGLE_HAND_SCALE = 0.75f;
35 constexpr float SINGLE_HAND_DEFAULT_SCALE = 1.0f;
36 }
37 class SceneSessionManagerLayoutTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp() override;
42     void TearDown() override;
43     static sptr<SceneSessionManager> ssm_;
44 private:
45     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
46 };
47 
48 sptr<SceneSessionManager> SceneSessionManagerLayoutTest::ssm_ = nullptr;
49 
SetUpTestCase()50 void SceneSessionManagerLayoutTest::SetUpTestCase()
51 {
52     ssm_ = &SceneSessionManager::GetInstance();
53 }
54 
TearDownTestCase()55 void SceneSessionManagerLayoutTest::TearDownTestCase()
56 {
57     ssm_ = nullptr;
58 }
59 
SetUp()60 void SceneSessionManagerLayoutTest::SetUp()
61 {
62     ssm_->sceneSessionMap_.clear();
63 }
64 
TearDown()65 void SceneSessionManagerLayoutTest::TearDown()
66 {
67     usleep(WAIT_SYNC_IN_NS);
68     ssm_->sceneSessionMap_.clear();
69 }
70 
71 namespace {
72 /**
73  * @tc.name: GetNormalSingleHandTransform
74  * @tc.desc: test function : GetNormalSingleHandTransform
75  * @tc.type: FUNC
76  */
77 HWTEST_F(SceneSessionManagerLayoutTest, GetNormalSingleHandTransform, Function | SmallTest | Level3)
78 {
79     SingleHandTransform preTransform = ssm_->singleHandTransform_;
80     ssm_->singleHandTransform_.posX = 100;
81     EXPECT_EQ(100, ssm_->GetNormalSingleHandTransform().posX);
82     ssm_->singleHandTransform_ = preTransform;
83 }
84 
85 /**
86  * @tc.name: NotifySingleHandInfoChange_TestUIType
87  * @tc.desc: test function : NotifySingleHandInfoChange
88  * @tc.type: FUNC
89  */
90 HWTEST_F(SceneSessionManagerLayoutTest, NotifySingleHandInfoChange_TestUIType, Function | SmallTest | Level3)
91 {
92     SingleHandTransform singleHandTransform;
93     ssm_->singleHandTransform_ = singleHandTransform;
94     SingleHandScreenInfo singleHandScreenInfo;
95     WSRect originRect, singleHandRect;
96     singleHandScreenInfo.scaleRatio = SINGLE_HAND_SCALE;
97     singleHandScreenInfo.mode = SingleHandMode::LEFT;
98     originRect = {0, 0, 400, 600};
99     singleHandRect = {0, 100, 200, 300};
100     ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
101     sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr();
102     ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(0, screenSession));
103 
104     ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
105     ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect);
106     usleep(WAIT_SYNC_IN_NS);
107     EXPECT_NE(singleHandScreenInfo.scaleRatio, ssm_->singleHandTransform_.scaleX);
108 
109     ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
110     ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect);
111     usleep(WAIT_SYNC_IN_NS);
112     EXPECT_EQ(singleHandScreenInfo.scaleRatio, ssm_->singleHandTransform_.scaleX);
113     ssm_->singleHandTransform_ = singleHandTransform;
114 }
115 
116 /**
117  * @tc.name: NotifySingleHandInfoChange_TestWindowName
118  * @tc.desc: test function : NotifySingleHandInfoChange
119  * @tc.type: FUNC
120  */
121 HWTEST_F(SceneSessionManagerLayoutTest, NotifySingleHandInfoChange_TestWindowName, Function | SmallTest | Level3)
122 {
123     SingleHandTransform singleHandTransform;
124     ssm_->singleHandTransform_ = singleHandTransform;
125     SessionInfo sessionInfo;
126     sessionInfo.bundleName_ = "OneHandModeBackground_testWindow";
127     sessionInfo.abilityName_ = "OneHandModeBackground_testWindow";
128     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
129     EXPECT_NE(sceneSession, nullptr);
130     sceneSession->property_->SetWindowName("OneHandModeBackground_testWindow");
131     ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
132     ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
133     sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr();
134     ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(0, screenSession));
135     SingleHandScreenInfo singleHandScreenInfo;
136     WSRect originRect, singleHandRect;
137     originRect = {0, 0, 400, 600};
138     singleHandRect = {0, 100, 200, 300};
139     singleHandScreenInfo.scaleRatio = SINGLE_HAND_SCALE;
140     singleHandScreenInfo.mode = SingleHandMode::LEFT;
141     ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
142     ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect);
143     usleep(WAIT_SYNC_IN_NS);
144     EXPECT_NE(singleHandScreenInfo.scaleRatio, sceneSession->singleHandTransform_.scaleX);
145 }
146 
147 /**
148  * @tc.name: NotifySingleHandInfoChange_TestDisplayId
149  * @tc.desc: test function : NotifySingleHandInfoChange
150  * @tc.type: FUNC
151  */
152 HWTEST_F(SceneSessionManagerLayoutTest, NotifySingleHandInfoChange_TestDisplayId, Function | SmallTest | Level3)
153 {
154     SingleHandTransform singleHandTransform;
155     ssm_->singleHandTransform_ = singleHandTransform;
156     SingleHandScreenInfo singleHandScreenInfo;
157     WSRect originRect, singleHandRect;
158     originRect = {0, 0, 400, 600};
159     singleHandRect = {0, 100, 200, 300};
160     singleHandScreenInfo.scaleRatio = SINGLE_HAND_SCALE;
161     singleHandScreenInfo.mode = SingleHandMode::LEFT;
162     ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
163     ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
164     sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr();
165     ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(0, screenSession));
166     SessionInfo sessionInfo;
167     sessionInfo.bundleName_ = "NotifySingleHandInfoChange_TestDisplayId";
168     sessionInfo.abilityName_ = "NotifySingleHandInfoChange_TestDisplayId";
169     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
170     EXPECT_NE(sceneSession, nullptr);
171 
172     sceneSession->GetSessionProperty()->SetDisplayId(2025);
173     ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
174     ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect);
175     usleep(WAIT_SYNC_IN_NS);
176     EXPECT_NE(singleHandScreenInfo.scaleRatio, sceneSession->singleHandTransform_.scaleX);
177 
178     sceneSession->GetSessionProperty()->SetDisplayId(0);
179     ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect);
180     usleep(WAIT_SYNC_IN_NS);
181     EXPECT_EQ(singleHandScreenInfo.scaleRatio, sceneSession->singleHandTransform_.scaleY);
182     ssm_->singleHandTransform_ = singleHandTransform;
183 }
184 
185 /**
186  * @tc.name: NotifySingleHandInfoChange_TestMode
187  * @tc.desc: test function : NotifySingleHandInfoChange
188  * @tc.type: FUNC
189  */
190 HWTEST_F(SceneSessionManagerLayoutTest, NotifySingleHandInfoChange_TestMode, Function | SmallTest | Level3)
191 {
192     SingleHandTransform singleHandTransform;
193     ssm_->singleHandTransform_ = singleHandTransform;
194     ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
195     ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
196     sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr();
197     ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(0, screenSession));
198 
199     SingleHandScreenInfo singleHandScreenInfo;
200     WSRect originRect, singleHandRect;
201     originRect = {0, 0, 400, 600};
202     singleHandRect = {0, 100, 200, 300};
203     singleHandScreenInfo.scaleRatio = SINGLE_HAND_SCALE;
204     singleHandScreenInfo.mode = SingleHandMode::LEFT;
205     ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect);
206     usleep(WAIT_SYNC_IN_NS);
207     EXPECT_EQ(100, ssm_->singleHandTransform_.posY);
208     EXPECT_EQ(0, ssm_->singleHandTransform_.posX);
209     ssm_->singleHandTransform_ = singleHandTransform;
210 
211     singleHandScreenInfo.mode = SingleHandMode::RIGHT;
212     singleHandRect = {50, 100, 200, 300};
213     ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect);
214     usleep(WAIT_SYNC_IN_NS);
215     EXPECT_EQ(100, ssm_->singleHandTransform_.posY);
216     EXPECT_EQ(50, ssm_->singleHandTransform_.posX);
217     ssm_->singleHandTransform_ = singleHandTransform;
218 
219     singleHandScreenInfo.scaleRatio = SINGLE_HAND_DEFAULT_SCALE;
220     singleHandScreenInfo.mode = SingleHandMode::MIDDLE;
221     singleHandRect = {0, 0, 200, 300};
222     ssm_->NotifySingleHandInfoChange(singleHandScreenInfo, originRect, singleHandRect);
223     usleep(WAIT_SYNC_IN_NS);
224     EXPECT_EQ(0, ssm_->singleHandTransform_.posY);
225     EXPECT_EQ(0, ssm_->singleHandTransform_.posX);
226     ssm_->singleHandTransform_ = singleHandTransform;
227 }
228 
229 /**
230  * @tc.name: GetDisplaySizeById_TestDisplayId
231  * @tc.desc: test function : GetDisplaySizeById
232  * @tc.type: FUNC
233  */
234 HWTEST_F(SceneSessionManagerLayoutTest, GetDisplaySizeById_TestDisplayId, Function | SmallTest | Level3)
235 {
236     DisplayId displayId = 2025;
237     int32_t displayWidth = 0;
238     int32_t displayHeight = 0;
239     EXPECT_EQ(false, ssm_->GetDisplaySizeById(displayId, displayWidth, displayHeight));
240 
241     displayId = 0;
242     EXPECT_EQ(true, ssm_->GetDisplaySizeById(displayId, displayWidth, displayHeight));
243 }
244 }
245 } // namespace Rosen
246 } // namespace OHOS
247