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