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