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 #include <gtest/gtest.h>
16 #include "session/host/include/scene_session.h"
17 #include "window_helper.h"
18 #include "wm_common.h"
19
20 using namespace testing;
21 using namespace testing::ext;
22 namespace OHOS {
23 namespace Rosen {
24 class WindowFocusSceneSessionTest : public testing::Test {
25 public:
26 static void SetUpTestCase();
27 static void TearDownTestCase();
28 void SetUp() override;
29 void TearDown() override;
30 };
31
SetUpTestCase()32 void WindowFocusSceneSessionTest::SetUpTestCase() {}
33
TearDownTestCase()34 void WindowFocusSceneSessionTest::TearDownTestCase() {}
35
SetUp()36 void WindowFocusSceneSessionTest::SetUp() {}
37
TearDown()38 void WindowFocusSceneSessionTest::TearDown() {}
39
40 namespace {
41
42 /**
43 * @tc.name: IsAppSession
44 * @tc.desc: IsAppSession true
45 * @tc.type: FUNC
46 */
47 HWTEST_F(WindowFocusSceneSessionTest, IsAppSession01, TestSize.Level1)
48 {
49 SessionInfo info;
50 info.abilityName_ = "IsAppSession01";
51 info.bundleName_ = "IsAppSession01";
52 info.windowType_ = 1;
53 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
54 EXPECT_NE(sceneSession, nullptr);
55 ASSERT_EQ(true, sceneSession->IsAppSession());
56 }
57
58 /**
59 * @tc.name: IsAppSession
60 * @tc.desc: IsAppSession false
61 * @tc.type: FUNC
62 */
63 HWTEST_F(WindowFocusSceneSessionTest, IsAppSession02, TestSize.Level1)
64 {
65 SessionInfo info;
66 info.abilityName_ = "IsAppSession02";
67 info.bundleName_ = "IsAppSession02";
68 info.windowType_ = 2106;
69 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
70 EXPECT_NE(sceneSession, nullptr);
71 ASSERT_EQ(false, sceneSession->IsAppSession());
72
73 SessionInfo parentInfo;
74 parentInfo.abilityName_ = "testSession1";
75 parentInfo.moduleName_ = "testSession2";
76 parentInfo.bundleName_ = "testSession3";
77 sptr<Session> parentSession = sptr<Session>::MakeSptr(parentInfo);
78 ASSERT_NE(parentSession, nullptr);
79
80 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
81 EXPECT_NE(property, nullptr);
82 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
83 parentSession->SetSessionProperty(property);
84 sceneSession->SetParentSession(parentSession);
85 ASSERT_EQ(false, sceneSession->IsAppSession());
86
87 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
88 parentSession->SetSessionProperty(property);
89 sceneSession->SetParentSession(parentSession);
90 ASSERT_EQ(true, sceneSession->IsAppSession());
91 }
92
93 /**
94 * @tc.name: IsAppOrLowerSystemSession
95 * @tc.desc: IsAppOrLowerSystemSession true
96 * @tc.type: FUNC
97 */
98 HWTEST_F(WindowFocusSceneSessionTest, IsAppOrLowerSystemSession01, TestSize.Level1)
99 {
100 SessionInfo info;
101 info.abilityName_ = "Background01";
102 info.bundleName_ = "IsAppOrLowerSystemSession01";
103 info.windowType_ = 2126;
104
105 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
106 EXPECT_NE(sceneSession, nullptr);
107 ASSERT_EQ(true, sceneSession->IsAppOrLowerSystemSession());
108 }
109
110 /**
111 * @tc.name: IsAppOrLowerSystemSession
112 * @tc.desc: IsAppOrLowerSystemSession false
113 * @tc.type: FUNC
114 */
115 HWTEST_F(WindowFocusSceneSessionTest, IsAppOrLowerSystemSession02, TestSize.Level1)
116 {
117 SessionInfo info;
118 info.abilityName_ = "Background02";
119 info.bundleName_ = "IsAppOrLowerSystemSession02";
120 info.windowType_ = 2106;
121
122 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
123 EXPECT_NE(sceneSession, nullptr);
124 ASSERT_EQ(false, sceneSession->IsAppOrLowerSystemSession());
125
126 SessionInfo parentInfo;
127 parentInfo.abilityName_ = "testSession1";
128 parentInfo.moduleName_ = "testSession2";
129 parentInfo.bundleName_ = "testSession3";
130 sptr<Session> parentSession = sptr<Session>::MakeSptr(parentInfo);
131 ASSERT_NE(parentSession, nullptr);
132
133 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
134 EXPECT_NE(property, nullptr);
135 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
136 parentSession->SetSessionProperty(property);
137 sceneSession->SetParentSession(parentSession);
138 ASSERT_EQ(false, sceneSession->IsAppOrLowerSystemSession());
139
140 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
141 parentSession->SetSessionProperty(property);
142 sceneSession->SetParentSession(parentSession);
143 ASSERT_EQ(true, sceneSession->IsAppOrLowerSystemSession());
144 }
145
146 /**
147 * @tc.name: IsSystemSessionAboveApp
148 * @tc.desc: IsSystemSessionAboveApp true
149 * @tc.type: FUNC
150 */
151 HWTEST_F(WindowFocusSceneSessionTest, IsSystemSessionAboveApp01, TestSize.Level1)
152 {
153 SessionInfo info1;
154 info1.abilityName_ = "HighZOrder01";
155 info1.bundleName_ = "IsSystemSessionAboveApp01";
156 info1.windowType_ = 2122;
157
158 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info1, nullptr);
159 ASSERT_EQ(true, sceneSession1->IsSystemSessionAboveApp());
160
161 SessionInfo info2;
162 info2.abilityName_ = "HighZOrder02";
163 info2.bundleName_ = "IsSystemSessionAboveApp02";
164 info2.windowType_ = 2104;
165
166 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(info2, nullptr);
167 ASSERT_EQ(true, sceneSession2->IsSystemSessionAboveApp());
168
169 SessionInfo info3;
170 info3.abilityName_ = "HighZOrder03";
171 info3.bundleName_ = "SCBDropdownPanel13";
172 info3.windowType_ = 2109;
173
174 sptr<SceneSession> sceneSession3 = sptr<SceneSession>::MakeSptr(info3, nullptr);
175 ASSERT_EQ(true, sceneSession3->IsSystemSessionAboveApp());
176
177 SessionInfo info4;
178 info4.abilityName_ = "HighZOrder04";
179 info4.bundleName_ = "IsSystemSessionAboveApp04";
180 info4.windowType_ = 2109;
181
182 sptr<SceneSession> sceneSession4 = sptr<SceneSession>::MakeSptr(info4, nullptr);
183 ASSERT_EQ(false, sceneSession4->IsSystemSessionAboveApp());
184
185 SessionInfo info5;
186 info5.abilityName_ = "HighZOrderGestureDock";
187 info5.bundleName_ = "SCBGestureDock21";
188 info5.windowType_ = 2106;
189
190 sptr<SceneSession> sceneSession5 = sptr<SceneSession>::MakeSptr(info5, nullptr);
191 ASSERT_EQ(true, sceneSession5->IsSystemSessionAboveApp());
192 }
193
194 /**
195 * @tc.name: IsSystemSessionAboveApp
196 * @tc.desc: IsSystemSessionAboveApp false
197 * @tc.type: FUNC
198 */
199 HWTEST_F(WindowFocusSceneSessionTest, IsSystemSessionAboveApp02, TestSize.Level1)
200 {
201 SessionInfo info;
202 info.abilityName_ = "HighZOrder05";
203 info.bundleName_ = "IsSystemSessionAboveApp05";
204 info.windowType_ = 1;
205
206 sptr<SceneSession> sceneSession;
207 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
208 EXPECT_NE(sceneSession, nullptr);
209 ASSERT_EQ(false, sceneSession->IsSystemSessionAboveApp());
210 }
211 } // namespace
212 } // namespace Rosen
213 } // namespace OHOS