• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include <gtest/gtest.h>
17 #include <transaction/rs_transaction.h>
18 
19 #include "display_manager.h"
20 #include "iremote_object_mocker.h"
21 #include "mock_RSIWindowAnimationController.h"
22 #include "remote_animation.h"
23 #include "starting_window.h"
24 #include "window_helper.h"
25 #include "window_transition_info.h"
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Rosen {
31 class StartingWindowTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37 
38     sptr<WindowProperty> CreateWindowProperty();
39 private:
40     static sptr<WindowTransitionInfo> transitionInfo_;
41     RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
42     std::shared_ptr<Media::PixelMap> ContructPixelMap();
43     static sptr<RSIWindowAnimationController> animationController_;
44     sptr<WindowNode> node_;
45     AnimationConfig animationConfig_;
46 };
47 
48 sptr<WindowTransitionInfo> StartingWindowTest::transitionInfo_ = nullptr;
49 sptr<RSIWindowAnimationController> StartingWindowTest::animationController_ = nullptr;
50 
SetUpTestCase()51 void StartingWindowTest::SetUpTestCase()
52 {
53 }
54 
TearDownTestCase()55 void StartingWindowTest::TearDownTestCase()
56 {
57 }
58 
SetUp()59 void StartingWindowTest::SetUp()
60 {
61     auto display = DisplayManager::GetInstance().GetDefaultDisplay();
62     ASSERT_TRUE((display != nullptr));
63     sptr<DisplayInfo> displayInfo = display->GetDisplayInfo();
64     ASSERT_TRUE((displayInfo != nullptr));
65     transitionInfo_ = new WindowTransitionInfo();
66     animationController_ = new RSIWindowAnimationControllerMocker();
67     ASSERT_EQ(WMError::WM_OK, RemoteAnimation::SetWindowAnimationController(animationController_));
68     transitionInfo_->supportWindowModes_ = {
69         AppExecFwk::SupportWindowMode::FULLSCREEN,
70         AppExecFwk::SupportWindowMode::SPLIT,
71         AppExecFwk::SupportWindowMode::FLOATING
72     };
73     node_ = StartingWindow::CreateWindowNode(transitionInfo_, 101); // 101 is windowId
74     node_->SetWindowRect({0, 0, 100, 100}); // 100 test data
75     StartingWindow::SetAnimationConfig(animationConfig_);
76     StartingWindow::transAnimateEnable_ = true;
77 }
78 
TearDown()79 void StartingWindowTest::TearDown()
80 {
81     transitionInfo_ = nullptr;
82     node_ = nullptr;
83 }
84 
ContructPixelMap()85 std::shared_ptr<Media::PixelMap> StartingWindowTest::ContructPixelMap()
86 {
87     Media::InitializationOptions opts;
88     opts.size.width = 200;  // 200: test width
89     opts.size.height = 300; // 300: test height
90     opts.pixelFormat = Media::PixelFormat::ARGB_8888;
91     opts.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
92     std::unique_ptr<Media::PixelMap> pixelMapPtr = Media::PixelMap::Create(opts);
93     return std::shared_ptr<Media::PixelMap>(pixelMapPtr.release());
94 }
95 
CreateRSSurfaceNode()96 RSSurfaceNode::SharedPtr StartingWindowTest::CreateRSSurfaceNode()
97 {
98     struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
99     rsSurfaceNodeConfig.SurfaceNodeName = "startingWindowTestSurfaceNode";
100     auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
101     return surfaceNode;
102 }
103 
CreateWindowProperty()104 sptr<WindowProperty> StartingWindowTest::CreateWindowProperty()
105 {
106     sptr<WindowProperty> property = new WindowProperty();
107     return property;
108 }
109 namespace {
110 /**
111  * @tc.name: NeedToStopStartingWindow01
112  * @tc.desc: stop starting window test without main App window
113  * @tc.type: FUNC
114  */
115 HWTEST_F(StartingWindowTest, NeedToStopStartingWindow01, Function | SmallTest | Level2)
116 {
117     transitionInfo_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
118     sptr<WindowNode> node = new WindowNode(CreateWindowProperty());
119     ASSERT_EQ(true, WindowHelper::CheckSupportWindowMode(node->GetWindowMode(),
120         node->GetModeSupportInfo(), transitionInfo_));
121 }
122 
123 /**
124  * @tc.name: NeedToStopStartingWindow02
125  * @tc.desc: need to stop starting window test with unsupport mode
126  * @tc.type: FUNC
127  */
128 HWTEST_F(StartingWindowTest, NeedToStopStartingWindow02, Function | SmallTest | Level2)
129 {
130     sptr<WindowNode> node = new WindowNode(CreateWindowProperty());
131     node->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
132     node->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING);
133     ASSERT_EQ(false, WindowHelper::CheckSupportWindowMode(node->GetWindowMode(),
134         node->GetModeSupportInfo(), transitionInfo_));
135 }
136 
137 /**
138  * @tc.name: NeedToStopStartingWindow03
139  * @tc.desc: need to stop starting window test with support mode
140  * @tc.type: FUNC
141  */
142 HWTEST_F(StartingWindowTest, NeedToStopStartingWindow03, Function | SmallTest | Level2)
143 {
144     sptr<WindowNode> node = new WindowNode(CreateWindowProperty());
145     ASSERT_EQ(false, WindowHelper::CheckSupportWindowMode(node->GetWindowMode(),
146         node->GetModeSupportInfo(), transitionInfo_));
147 }
148 
149 /**
150  * @tc.name: NeedToStopStartingWindow04
151  * @tc.desc: need to stop starting window test with support mode
152  * @tc.type: FUNC
153  */
154 HWTEST_F(StartingWindowTest, NeedToStopStartingWindow04, Function | SmallTest | Level2)
155 {
156     sptr<WindowNode> node = new WindowNode(CreateWindowProperty());
157     transitionInfo_->SetShowFlagWhenLocked(true);
158     node->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
159                              WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY);
160     ASSERT_EQ(false, WindowHelper::CheckSupportWindowMode(node->GetWindowMode(),
161         node->GetModeSupportInfo(), transitionInfo_));
162 }
163 
164 /**
165  * @tc.name: CreateWindowNode01
166  * @tc.desc: create starting window node test
167  * @tc.type: FUNC
168  */
169 HWTEST_F(StartingWindowTest, CreateWindowNode01, Function | SmallTest | Level2)
170 {
171     sptr<WindowTransitionInfo> info = nullptr;
172     ASSERT_EQ(nullptr, StartingWindow::CreateWindowNode(info, 0));
173 }
174 
175 /**
176  * @tc.name: CreateWindowNode02
177  * @tc.desc: create starting window node test
178  * @tc.type: FUNC
179  */
180 HWTEST_F(StartingWindowTest, CreateWindowNode02, Function | SmallTest | Level2)
181 {
182     transitionInfo_->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
183     sptr<WindowNode> node = StartingWindow::CreateWindowNode(transitionInfo_, 0);
184     ASSERT_NE(nullptr, node);
185     ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, node->GetWindowMode());
186 }
187 
188 /**
189  * @tc.name: CreateWindowNode03
190  * @tc.desc: create starting window node test
191  * @tc.type: FUNC
192  */
193 HWTEST_F(StartingWindowTest, CreateWindowNode03, Function | SmallTest | Level2)
194 {
195     transitionInfo_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
196     sptr<WindowNode> node = StartingWindow::CreateWindowNode(transitionInfo_, 0);
197     ASSERT_NE(nullptr, node);
198     ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, node->GetWindowMode());
199 }
200 
201 /**
202  * @tc.name: CreateWindowNode04
203  * @tc.desc: create starting window node test
204  * @tc.type: FUNC
205  */
206 HWTEST_F(StartingWindowTest, CreateWindowNode04, Function | SmallTest | Level2)
207 {
208     transitionInfo_->SetShowFlagWhenLocked(true);
209     sptr<WindowNode> node = StartingWindow::CreateWindowNode(transitionInfo_, 0);
210     ASSERT_NE(nullptr, node);
211 }
212 
213 /**
214  * @tc.name: DrawStartingWindow01
215  * @tc.desc: draw starting window node
216  * @tc.type: FUNC
217  */
218 HWTEST_F(StartingWindowTest, DrawStartingWindow01, Function | SmallTest | Level2)
219 {
220     std::shared_ptr<Media::PixelMap> pixelMap = ContructPixelMap();
221     sptr<WindowNode> node = nullptr;
222     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, StartingWindow::DrawStartingWindow(node, pixelMap, 0x00FFFFFF, true));
223     usleep(10000);
224 }
225 
226 /**
227  * @tc.name: DrawStartingWindow02
228  * @tc.desc: draw starting window node
229  * @tc.type: FUNC
230  */
231 HWTEST_F(StartingWindowTest, DrawStartingWindow02, Function | SmallTest | Level2)
232 {
233     node_->leashWinSurfaceNode_ = nullptr;
234     std::shared_ptr<Media::PixelMap> pixelMap = ContructPixelMap();
235     ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, pixelMap, 0x00FFFFFF, true));
236     usleep(10000);
237 }
238 
239 /**
240  * @tc.name: DrawStartingWindow03
241  * @tc.desc: draw starting window node
242  * @tc.type: FUNC
243  */
244 HWTEST_F(StartingWindowTest, DrawStartingWindow03, Function | SmallTest | Level2)
245 {
246     std::shared_ptr<Media::PixelMap> pixelMap = ContructPixelMap();
247     ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, pixelMap, 0x00FFFFFF, false));
248     usleep(10000);
249 }
250 
251 /**
252  * @tc.name: DrawStartingWindow04
253  * @tc.desc: draw starting window node
254  * @tc.type: FUNC
255  */
256 HWTEST_F(StartingWindowTest, DrawStartingWindow04, Function | SmallTest | Level2)
257 {
258     node_->startingWinSurfaceNode_ = nullptr;
259     std::shared_ptr<Media::PixelMap> pixelMap = ContructPixelMap();
260     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, StartingWindow::DrawStartingWindow(node_, pixelMap, 0x00FFFFFF, true));
261     usleep(10000);
262 }
263 
264 /**
265  * @tc.name: DrawStartingWindow05
266  * @tc.desc: draw starting window node
267  * @tc.type: FUNC
268  */
269 HWTEST_F(StartingWindowTest, DrawStartingWindow05, Function | SmallTest | Level2)
270 {
271     ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, nullptr, 0x00FFFFFF, true));
272     usleep(10000);
273 }
274 
275 /**
276  * @tc.name: DrawStartingWindow06
277  * @tc.desc: draw starting window node
278  * @tc.type: FUNC
279  */
280 HWTEST_F(StartingWindowTest, DrawStartingWindow06, Function | SmallTest | Level2)
281 {
282     std::shared_ptr<Media::PixelMap> pixelMap = ContructPixelMap();
283     ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, pixelMap, 0x00FFFFFF, true));
284     usleep(10000);
285 }
286 
287 /**
288  * @tc.name: HandleClientWindowCreateAndRelease01
289  * @tc.desc: handle client window create
290  * @tc.type: FUNC
291  */
292 HWTEST_F(StartingWindowTest, HandleClientWindowCreateAndRelease01, Function | SmallTest | Level2)
293 {
294     sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker();
295     sptr<IWindow> iWindow = iface_cast<IWindow>(iRemoteObjectMocker);
296     ASSERT_NE(nullptr, iWindow);
297     uint32_t windowId = 0;
298     auto surfaceNode = CreateRSSurfaceNode();
299     ASSERT_NE(nullptr, surfaceNode);
300     sptr<WindowProperty> windowProperty = new WindowProperty();
301     StartingWindow::HandleClientWindowCreate(node_, iWindow, windowId, surfaceNode, windowProperty, 0, 0);
302     ASSERT_EQ(node_->GetWindowId(), windowId);
303     usleep(200000);
304     StartingWindow::transAnimateEnable_ = false;
305     StartingWindow::HandleClientWindowCreate(node_, iWindow, windowId, surfaceNode, windowProperty, 0, 0);
306     ASSERT_EQ(node_->GetWindowId(), windowId);
307     usleep(200000);
308     StartingWindow::ReleaseStartWinSurfaceNode(node_);
309 }
310 
311 /**
312  * @tc.name: HandleClientWindowCreate02
313  * @tc.desc: handle client window create
314  * @tc.type: FUNC
315  */
316 HWTEST_F(StartingWindowTest, HandleClientWindowCreate02, Function | SmallTest | Level2)
317 {
318     sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker();
319     sptr<IWindow> iWindow = iface_cast<IWindow>(iRemoteObjectMocker);
320     ASSERT_NE(nullptr, iWindow);
321     uint32_t windowId = 0;
322     auto surfaceNode = CreateRSSurfaceNode();
323     ASSERT_NE(nullptr, surfaceNode);
324     sptr<WindowProperty> windowProperty = new WindowProperty();
325     sptr<WindowNode> node = nullptr;
326     StartingWindow::HandleClientWindowCreate(node, iWindow, windowId, surfaceNode, windowProperty, 0, 0);
327     usleep(200000);
328 }
329 
330 /**
331  * @tc.name: HandleClientWindowCreateAndRelease03
332  * @tc.desc: handle client window create and Release with null leashNode
333  * @tc.type: FUNC
334  */
335 HWTEST_F(StartingWindowTest, HandleClientWindowCreateAndRelease03, Function | SmallTest | Level2)
336 {
337     node_->leashWinSurfaceNode_ = nullptr;
338     uint32_t windowId = 0;
339     auto surfaceNode = CreateRSSurfaceNode();
340     ASSERT_NE(nullptr, surfaceNode);
341     sptr<WindowProperty> windowProperty = new WindowProperty();
342     sptr<IWindow> iWindow = nullptr;
343     StartingWindow::HandleClientWindowCreate(node_, iWindow, windowId, surfaceNode, windowProperty, 0, 0);
344     usleep(200000);
345     StartingWindow::ReleaseStartWinSurfaceNode(node_);
346 }
347 
348 /**
349  * @tc.name: AddNodeOnRSTree01
350  * @tc.desc: Add node on rs tree test with surfaceNode nullptr and hot start
351  * @tc.type: FUNC
352  */
353 HWTEST_F(StartingWindowTest, AddNodeOnRSTree01, Function | SmallTest | Level2)
354 {
355     sptr<RSIWindowAnimationController> testController = nullptr;
356     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, RemoteAnimation::SetWindowAnimationController(testController));
357     StartingWindow::AddNodeOnRSTree(node_, true);
358     ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, nullptr, 0x66FFFFFF, false));
359     usleep(200000);
360 }
361 
362 /**
363  * @tc.name: AddNodeOnRSTree02
364  * @tc.desc: Add node on rs tree test with hot start and surfaceNode
365  * @tc.type: FUNC
366  */
367 HWTEST_F(StartingWindowTest, AddNodeOnRSTree02, Function | SmallTest | Level2)
368 {
369     auto surfaceNode = CreateRSSurfaceNode();
370     ASSERT_NE(nullptr, surfaceNode);
371     node_->surfaceNode_ = surfaceNode;
372     sptr<RSIWindowAnimationController> testController = nullptr;
373     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, RemoteAnimation::SetWindowAnimationController(testController));
374     StartingWindow::AddNodeOnRSTree(node_, true);
375     ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, nullptr, 0x66FFFFFF, false));
376     usleep(200000);
377 }
378 
379 /**
380  * @tc.name: AddNodeOnRSTree03
381  * @tc.desc: Add node on rs tree test
382  * @tc.type: FUNC
383  */
384 HWTEST_F(StartingWindowTest, AddNodeOnRSTree03, Function | SmallTest | Level2)
385 {
386     auto surfaceNode = CreateRSSurfaceNode();
387     ASSERT_NE(nullptr, surfaceNode);
388     node_->surfaceNode_ = surfaceNode;
389     node_->leashWinSurfaceNode_ = nullptr;
390     sptr<RSIWindowAnimationController> testController = nullptr;
391     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, RemoteAnimation::SetWindowAnimationController(testController));
392     StartingWindow::AddNodeOnRSTree(node_, true);
393     ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, nullptr, 0x66FFFFFF, false));
394     usleep(200000);
395 }
396 
397 /**
398  * @tc.name: AddNodeOnRSTree04
399  * @tc.desc: Add node on rs tree test with surfaceNode nullptr, with animation controller
400  * @tc.type: FUNC
401  */
402 HWTEST_F(StartingWindowTest, AddNodeOnRSTree04, Function | SmallTest | Level2)
403 {
404     sptr<RSIWindowAnimationController> testController = new RSIWindowAnimationControllerMocker();
405     ASSERT_EQ(WMError::WM_OK, RemoteAnimation::SetWindowAnimationController(testController));
406     StartingWindow::AddNodeOnRSTree(node_, true);
407     ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, nullptr, 0x66FFFFFF, false));
408     usleep(200000);
409 }
410 
411 /**
412  * @tc.name: AddNodeOnRSTree05
413  * @tc.desc: Add node on rs tree test
414  * @tc.type: FUNC
415  */
416 HWTEST_F(StartingWindowTest, AddNodeOnRSTree05, Function | SmallTest | Level2)
417 {
418     auto surfaceNode = CreateRSSurfaceNode();
419     ASSERT_NE(nullptr, surfaceNode);
420     node_->surfaceNode_ = surfaceNode;
421     sptr<RSIWindowAnimationController> testController = new RSIWindowAnimationControllerMocker();
422     ASSERT_EQ(WMError::WM_OK, RemoteAnimation::SetWindowAnimationController(testController));
423     AnimationConfig config;
424     StartingWindow::AddNodeOnRSTree(node_, true);
425     ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, nullptr, 0x66FFFFFF, false));
426     usleep(200000);
427 }
428 
429 /**
430  * @tc.name: AddNodeOnRSTree06
431  * @tc.desc: Add node on rs tree test
432  * @tc.type: FUNC
433  */
434 HWTEST_F(StartingWindowTest, AddNodeOnRSTree06, Function | SmallTest | Level2)
435 {
436     auto surfaceNode = CreateRSSurfaceNode();
437     ASSERT_NE(nullptr, surfaceNode);
438     node_->surfaceNode_ = surfaceNode;
439     node_->leashWinSurfaceNode_ = nullptr;
440     sptr<RSIWindowAnimationController> testController = new RSIWindowAnimationControllerMocker();
441     ASSERT_EQ(WMError::WM_OK, RemoteAnimation::SetWindowAnimationController(testController));
442     StartingWindow::AddNodeOnRSTree(node_, true);
443     ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, nullptr, 0x66FFFFFF, false));
444     usleep(200000);
445 }
446 
447 /**
448  * @tc.name: SetStartingWindowAnimation
449  * @tc.desc: set starting window animation with different parameter
450  * @tc.type: FUNC
451  */
452 HWTEST_F(StartingWindowTest, SetStartingWindowAnimation01, Function | SmallTest | Level2)
453 {
454     sptr<WindowNode> windowNode = nullptr;
455     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, StartingWindow::SetStartingWindowAnimation(windowNode));
456 
457     ASSERT_EQ(WMError::WM_OK, StartingWindow::SetStartingWindowAnimation(node_));
458 
459     node_->leashWinSurfaceNode_ = nullptr;
460     ASSERT_EQ(WMError::WM_OK, StartingWindow::SetStartingWindowAnimation(node_));
461 
462     node_->startingWinSurfaceNode_ = nullptr;
463     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, StartingWindow::SetStartingWindowAnimation(node_));
464 }
465 }
466 }
467 }
468