1 /*
2 * Copyright (c) 2021-2022 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 // gtest
17 #include <gtest/gtest.h>
18 #include "window_test_utils.h"
19 #include "scene_board_judgement.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 using Utils = WindowTestUtils;
27 class WindowMultiAbilityTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 virtual void SetUp() override;
32 virtual void TearDown() override;
33 };
34
SetUpTestCase()35 void WindowMultiAbilityTest::SetUpTestCase()
36 {
37 }
38
TearDownTestCase()39 void WindowMultiAbilityTest::TearDownTestCase()
40 {
41 }
42
SetUp()43 void WindowMultiAbilityTest::SetUp()
44 {
45 }
46
TearDown()47 void WindowMultiAbilityTest::TearDown()
48 {
49 }
50
DoSceneResource(sptr<WindowScene> windowscene)51 static void DoSceneResource(sptr<WindowScene> windowscene){
52 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
53 ASSERT_EQ(WMError::WM_OK, windowscene->GoBackground());
54 ASSERT_EQ(WMError::WM_OK, windowscene->GoDestroy());
55 }else {
56 ASSERT_NE(WMError::WM_OK, windowscene->GoBackground());
57 ASSERT_NE(WMError::WM_OK, windowscene->GoDestroy());
58 }
59 }
60
61 /**
62 * @tc.name: MultiAbilityWindow01
63 * @tc.desc: Five scene process in one thread
64 * @tc.type: FUNC
65 */
66 HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow01, Function | MediumTest | Level2)
67 {
68 sptr<WindowScene> scene1 = Utils::CreateWindowScene();
69 sptr<WindowScene> scene2 = Utils::CreateWindowScene();
70 sptr<WindowScene> scene3 = Utils::CreateWindowScene();
71 sptr<WindowScene> scene4 = Utils::CreateWindowScene();
72 sptr<WindowScene> scene5 = Utils::CreateWindowScene();
73
74 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
75 ASSERT_EQ(WMError::WM_OK, scene1->GoForeground());
76 ASSERT_EQ(WMError::WM_OK, scene2->GoForeground());
77 ASSERT_EQ(WMError::WM_OK, scene3->GoForeground());
78 ASSERT_EQ(WMError::WM_OK, scene4->GoForeground());
79 ASSERT_EQ(WMError::WM_OK, scene5->GoForeground());
80 } else {
81 ASSERT_NE(WMError::WM_OK, scene1->GoForeground());
82 ASSERT_NE(WMError::WM_OK, scene2->GoForeground());
83 ASSERT_NE(WMError::WM_OK, scene3->GoForeground());
84 ASSERT_NE(WMError::WM_OK, scene4->GoForeground());
85 ASSERT_NE(WMError::WM_OK, scene5->GoForeground());
86 }
87 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
88 ASSERT_EQ(WMError::WM_OK, scene5->GoBackground());
89 ASSERT_EQ(WMError::WM_OK, scene4->GoBackground());
90 ASSERT_EQ(WMError::WM_OK, scene3->GoBackground());
91 ASSERT_EQ(WMError::WM_OK, scene2->GoBackground());
92 ASSERT_EQ(WMError::WM_OK, scene1->GoBackground());
93 }else {
94 ASSERT_NE(WMError::WM_OK, scene5->GoBackground());
95 ASSERT_NE(WMError::WM_OK, scene4->GoBackground());
96 ASSERT_NE(WMError::WM_OK, scene3->GoBackground());
97 ASSERT_NE(WMError::WM_OK, scene2->GoBackground());
98 ASSERT_NE(WMError::WM_OK, scene1->GoBackground());
99 }
100 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
101 ASSERT_EQ(WMError::WM_OK, scene1->GoDestroy());
102 ASSERT_EQ(WMError::WM_OK, scene2->GoDestroy());
103 ASSERT_EQ(WMError::WM_OK, scene3->GoDestroy());
104 ASSERT_EQ(WMError::WM_OK, scene4->GoDestroy());
105 ASSERT_EQ(WMError::WM_OK, scene5->GoDestroy());
106 } else {
107 ASSERT_NE(WMError::WM_OK, scene1->GoDestroy());
108 ASSERT_NE(WMError::WM_OK, scene2->GoDestroy());
109 ASSERT_NE(WMError::WM_OK, scene3->GoDestroy());
110 ASSERT_NE(WMError::WM_OK, scene4->GoDestroy());
111 ASSERT_NE(WMError::WM_OK, scene5->GoDestroy());
112 }
113 }
114
115 /**
116 * @tc.name: MultiAbilityWindow02
117 * @tc.desc: Five scene process in one thread, create/show/hide/destroy in order
118 * @tc.type: FUNC
119 */
120 HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow02, Function | MediumTest | Level3)
121 {
122 sptr<WindowScene> scene1 = Utils::CreateWindowScene();
123 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
124 ASSERT_EQ(WMError::WM_OK, scene1->GoForeground());
125 } else {
126 ASSERT_NE(WMError::WM_OK, scene1->GoForeground());
127 }
128
129 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
130 ASSERT_EQ(WMError::WM_OK, scene1->GoBackground());
131 } else {
132 ASSERT_NE(WMError::WM_OK, scene1->GoBackground());
133 }
134 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
135 ASSERT_EQ(WMError::WM_OK, scene1->GoDestroy());
136 } else {
137 ASSERT_NE(WMError::WM_OK, scene1->GoDestroy());
138 }
139 sptr<WindowScene> scene2 = Utils::CreateWindowScene();
140 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
141 ASSERT_EQ(WMError::WM_OK, scene2->GoForeground());
142 } else {
143 ASSERT_NE(WMError::WM_OK, scene2->GoForeground());
144 }
145 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
146 ASSERT_EQ(WMError::WM_OK, scene2->GoBackground());
147 } else {
148 ASSERT_NE(WMError::WM_OK, scene2->GoBackground());
149 }
150 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
151 ASSERT_EQ(WMError::WM_OK, scene2->GoDestroy());
152 } else {
153 ASSERT_NE(WMError::WM_OK, scene2->GoDestroy());
154 }
155 sptr<WindowScene> scene3 = Utils::CreateWindowScene();
156 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
157 ASSERT_EQ(WMError::WM_OK, scene3->GoForeground());
158 } else {
159 ASSERT_NE(WMError::WM_OK, scene3->GoForeground());
160 }
161 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
162 ASSERT_EQ(WMError::WM_OK, scene3->GoBackground());
163 ASSERT_EQ(WMError::WM_OK, scene3->GoDestroy());
164 } else {
165 ASSERT_NE(WMError::WM_OK, scene3->GoBackground());
166 ASSERT_NE(WMError::WM_OK, scene3->GoDestroy());
167 }
168 }
169
170 /**
171 * @tc.name: MultiAbilityWindow2
172 * @tc.desc: Five scene process in one thread, create/show/hide/destroy in order
173 * @tc.type: FUNC
174 */
175 HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow2, Function | MediumTest | Level3)
176 {
177 sptr<WindowScene> scene4 = Utils::CreateWindowScene();
178 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
179 ASSERT_EQ(WMError::WM_OK, scene4->GoForeground());
180 } else {
181 ASSERT_NE(WMError::WM_OK, scene4->GoForeground());
182 }
183 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
184 ASSERT_EQ(WMError::WM_OK, scene4->GoBackground());
185 } else {
186 ASSERT_NE(WMError::WM_OK, scene4->GoBackground());
187 }
188 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
189 ASSERT_EQ(WMError::WM_OK, scene4->GoDestroy());
190 } else {
191 ASSERT_NE(WMError::WM_OK, scene4->GoDestroy());
192 }
193 sptr<WindowScene> scene5 = Utils::CreateWindowScene();
194 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
195 ASSERT_EQ(WMError::WM_OK, scene5->GoForeground());
196 } else {
197 ASSERT_NE(WMError::WM_OK, scene5->GoForeground());
198 }
199 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
200 ASSERT_EQ(WMError::WM_OK, scene5->GoBackground());
201 } else {
202 ASSERT_NE(WMError::WM_OK, scene5->GoBackground());
203 }
204 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
205 ASSERT_EQ(WMError::WM_OK, scene5->GoDestroy());
206 } else {
207 ASSERT_NE(WMError::WM_OK, scene5->GoDestroy());
208 }
209 }
210
211 /**
212 * @tc.name: MultiAbilityWindow05
213 * @tc.desc: Five scene process in one thread, create/show/hide/destroy out of order
214 * @tc.type: FUNC
215 */
216 HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow03, Function | MediumTest | Level3)
217 {
218 sptr<WindowScene> scene1 = Utils::CreateWindowScene();
219 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
220 ASSERT_EQ(WMError::WM_OK, scene1->GoForeground());
221 } else {
222 ASSERT_NE(WMError::WM_OK, scene1->GoForeground());
223 }
224 sptr<WindowScene> scene2 = Utils::CreateWindowScene();
225 sptr<WindowScene> scene3 = Utils::CreateWindowScene();
226 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
227 ASSERT_EQ(WMError::WM_OK, scene3->GoForeground());
228 } else {
229 ASSERT_NE(WMError::WM_OK, scene3->GoForeground());
230 }
231 DoSceneResource(scene1);
232 sptr<WindowScene> scene4 = Utils::CreateWindowScene();
233 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
234 ASSERT_EQ(WMError::WM_OK, scene3->GoBackground());
235 ASSERT_EQ(WMError::WM_OK, scene2->GoForeground());
236 ASSERT_EQ(WMError::WM_OK, scene4->GoForeground());
237 ASSERT_EQ(WMError::WM_OK, scene2->GoBackground());
238 } else {
239 ASSERT_NE(WMError::WM_OK, scene3->GoBackground());
240 ASSERT_NE(WMError::WM_OK, scene2->GoForeground());
241 ASSERT_NE(WMError::WM_OK, scene4->GoForeground());
242 ASSERT_NE(WMError::WM_OK, scene2->GoBackground());
243 }
244 sptr<WindowScene> scene5 = Utils::CreateWindowScene();
245 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
246 ASSERT_EQ(WMError::WM_OK, scene3->GoDestroy());
247 ASSERT_EQ(WMError::WM_OK, scene5->GoForeground());
248 ASSERT_EQ(WMError::WM_OK, scene5->GoBackground());
249 } else {
250 ASSERT_NE(WMError::WM_OK, scene3->GoDestroy());
251 ASSERT_NE(WMError::WM_OK, scene5->GoForeground());
252 ASSERT_NE(WMError::WM_OK, scene5->GoBackground());
253 }
254 DoSceneResource(scene4);
255 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
256 ASSERT_EQ(WMError::WM_OK, scene5->GoDestroy());
257 ASSERT_EQ(WMError::WM_OK, scene2->GoDestroy());
258 } else {
259 ASSERT_NE(WMError::WM_OK, scene5->GoDestroy());
260 ASSERT_NE(WMError::WM_OK, scene2->GoDestroy());
261 }
262 }
263 } // namespace Rosen
264 } // namespace OHOS
265