• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gmock/gmock.h>
17 #include <bundle_mgr_interface.h>
18 #include <filesystem>
19 #include <fstream>
20 
21 #include "mock_resource_manager.h"
22 #include "starting_window.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 namespace {
27 constexpr size_t MAX_SOURCE_SIZE = 300 * 1024 * 1024;
28 const uint8_t RAW_PNG_DATA[] = {
29     0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
30     0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4,
31     0x89, 0x00, 0x00, 0x00, 0x0A, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9C, 0x63, 0x62, 0x00, 0x04, 0x00,
32     0x00, 0xFF, 0xFF, 0x00, 0x06, 0x00, 0x03, 0x57, 0x0A, 0xC9, 0xD4, 0x00, 0x00, 0x00, 0x00, 0x49,
33     0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82
34 };
35 const uint8_t RAW_GIF_DATA[] = {
36     'G', 'I', 'F', '8', '9', 'a', 0x01, 0x00, 0x01, 0x00, 0x80, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
37     0x2C, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00, 0x2C, 0x00,
38     0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x04, 0x01, 0x00, 0x3B
39 };
40 const uint8_t RAW_INVALID_GIF_DATA[] = {
41     'G', 'I', 'F', '8', '9', 'a', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3B
42 };
43 const std::string IMAGE_PLACE_HOLDER_PNG_PATH = "/etc/window/resources/bg_place_holder.png";
44 }
45 
46 namespace OHOS {
47 namespace AppExecFwk {
48 class MockIBundleMgr : public IBundleMgr {
49 public:
50     MockIBundleMgr() = default;
51     virtual ~MockIBundleMgr() = default;
52     MOCK_METHOD4(QueryAbilityInfo, bool(const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo));
AsObject()53     virtual OHOS::sptr<OHOS::IRemoteObject> AsObject()
54     {
55         return nullptr;
56     }
57 };
58 }
59 
60 namespace Rosen {
61 class StartingWindowTest : public testing::Test {
62 public:
63     static void SetUpTestCase();
64     static void TearDownTestCase();
65     void SetUp() override;
66     void TearDown() override;
67 };
68 
SetUpTestCase()69 void StartingWindowTest::SetUpTestCase()
70 {
71 }
72 
TearDownTestCase()73 void StartingWindowTest::TearDownTestCase()
74 {
75 }
76 
SetUp()77 void StartingWindowTest::SetUp()
78 {
79 }
80 
TearDown()81 void StartingWindowTest::TearDown()
82 {
83     StartingWindow::startingWindowShowRunning_ = false;
84     if (StartingWindow::startingWindowShowThread_.joinable()) {
85         StartingWindow::startingWindowShowThread_.join();
86     }
87     StartingWindow::firstFrameCompleted_ = false;
88     StartingWindow::UnRegisterStartingWindowShowInfo();
89 }
90 
91 /**
92  * @tc.name: GetBundleManager01
93  * @tc.desc: GetBundleManager
94  * @tc.type: FUNC
95  */
96 HWTEST_F(StartingWindowTest, GetBundleManager01, TestSize.Level1)
97 {
98     auto bundleMgr = StartingWindow::GetBundleManager();
99     ASSERT_NE(bundleMgr, nullptr);
100 }
101 
102 /**
103  * @tc.name: CreateResourceManager01
104  * @tc.desc: CreateResourceManager
105  * @tc.type: FUNC
106  */
107 HWTEST_F(StartingWindowTest, CreateResourceManager01, TestSize.Level1)
108 {
109     std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = nullptr;
110     auto ref = StartingWindow::CreateResourceManager(abilityInfo);
111     ASSERT_EQ(ref, nullptr);
112 
113     abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
114     abilityInfo->bundleName = "com.ohos.test.bundleName";
115     abilityInfo->moduleName = "com.ohos.test.moduleName";
116     abilityInfo->hapPath = "data/resource/testHapPath";
117 
118     ref = StartingWindow::CreateResourceManager(abilityInfo);
119     ASSERT_NE(ref, nullptr);
120     EXPECT_EQ(ref->bundleInfo.first, abilityInfo->bundleName);
121     EXPECT_EQ(ref->bundleInfo.second, abilityInfo->moduleName);
122 }
123 
124 /**
125  * @tc.name: GetAbilityInfoFromBMS01
126  * @tc.desc: GetAbilityInfoFromBMS
127  * @tc.type: FUNC
128  */
129 HWTEST_F(StartingWindowTest, GetAbilityInfoFromBMS01, TestSize.Level1)
130 {
131     auto ref = StartingWindow::GetAbilityInfoFromBMS(nullptr, nullptr);
132     ASSERT_EQ(ref, nullptr);
133 
134     sptr<WindowTransitionInfo> winInfo = sptr<WindowTransitionInfo>::MakeSptr();
135     sptr<WindowNode> node = StartingWindow::CreateWindowNode(winInfo, 1);
136     node->abilityInfo_.abilityName_ = "com.ohos.test.abilityName";
137     node->abilityInfo_.bundleName_ = "com.ohos.test.bundleName";
138     ASSERT_NE(node, nullptr);
139     ref = StartingWindow::GetAbilityInfoFromBMS(node, nullptr);
140     ASSERT_EQ(ref, nullptr);
141 
142     auto mockBundleMgr = sptr<AppExecFwk::MockIBundleMgr>::MakeSptr();
143     EXPECT_CALL(*mockBundleMgr, QueryAbilityInfo(_, _, _, _))
144         .Times(1).WillOnce(Return(false));
145     ref = StartingWindow::GetAbilityInfoFromBMS(node, mockBundleMgr);
146     ASSERT_EQ(ref, nullptr);
147 
148     AppExecFwk::AbilityInfo abilityInfo;
149     abilityInfo.name = node->abilityInfo_.abilityName_;
150     EXPECT_CALL(*mockBundleMgr, QueryAbilityInfo(_, _, _, _))
151         .Times(1).WillOnce(DoAll(
152             SetArgReferee<3>(abilityInfo),
153             Return(true)));
154     ref = StartingWindow::GetAbilityInfoFromBMS(node, mockBundleMgr);
155     ASSERT_NE(ref, nullptr);
156     EXPECT_EQ(ref->name, node->abilityInfo_.abilityName_);
157 }
158 
159 /**
160  * @tc.name: GetPixelMapListInfo01
161  * @tc.desc: GetPixelMapListInfo
162  * @tc.type: FUNC
163  */
164 HWTEST_F(StartingWindowTest, GetPixelMapListInfo01, TestSize.Level1)
165 {
166     std::shared_ptr<Global::Resource::ResourceManager> resourceMgr = nullptr;
167     std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = nullptr;
168     auto ref = StartingWindow::GetPixelMapListInfo(1, resourceMgr, abilityInfo);
169     ASSERT_EQ(ref, nullptr);
170 
171     abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
172     ref = StartingWindow::GetPixelMapListInfo(1, resourceMgr, abilityInfo);
173     ASSERT_EQ(ref, nullptr);
174 
175     resourceMgr = StartingWindow::CreateResourceManager(abilityInfo);
176     ref = StartingWindow::GetPixelMapListInfo(1, resourceMgr, abilityInfo);
177     ASSERT_EQ(ref, nullptr);
178 
179     ref = StartingWindow::GetPixelMapListInfo(std::numeric_limits<uint32_t>::min(), resourceMgr, abilityInfo);
180     ASSERT_EQ(ref, nullptr);
181 
182     ref = StartingWindow::GetPixelMapListInfo(-1, resourceMgr, abilityInfo);
183     ASSERT_EQ(ref, nullptr);
184 }
185 
186 /**
187  * @tc.name: GetPixelMapListInfo02
188  * @tc.desc: GetPixelMapListInfo
189  * @tc.type: FUNC
190  */
191 HWTEST_F(StartingWindowTest, GetPixelMapListInfo02, TestSize.Level1)
192 {
193     auto mockResourceManager = std::make_shared<OHOS::Global::Resource::MockResourceManager>();
194     auto abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
195     uint32_t mediaDataId = std::numeric_limits<uint32_t>::max();
196 
197     abilityInfo->hapPath = "";
198     EXPECT_CALL(*mockResourceManager, GetMediaById(_, _, _))
199         .Times(1).WillOnce(Return(Global::Resource::RState::NOT_FOUND));
200     auto ref = StartingWindow::GetPixelMapListInfo(mediaDataId, mockResourceManager, abilityInfo);
201     ASSERT_EQ(ref, nullptr);
202 
203     EXPECT_CALL(*mockResourceManager, GetMediaById(_, _, _))
204         .Times(1).WillOnce(Return(Global::Resource::RState::SUCCESS));
205     ref = StartingWindow::GetPixelMapListInfo(mediaDataId, mockResourceManager, abilityInfo);
206     ASSERT_EQ(ref, nullptr);
207 
208     abilityInfo->hapPath = "/home/somepath/somefile";
209     EXPECT_CALL(*mockResourceManager, GetMediaDataById(_, _, _, _))
210         .Times(1).WillOnce(Return(Global::Resource::RState::NOT_FOUND));
211     ref = StartingWindow::GetPixelMapListInfo(mediaDataId, mockResourceManager, abilityInfo);
212     ASSERT_EQ(ref, nullptr);
213 
214     EXPECT_CALL(*mockResourceManager, GetMediaDataById(_, _, _, _))
215         .Times(1).WillOnce(Return(Global::Resource::RState::SUCCESS));
216     ref = StartingWindow::GetPixelMapListInfo(mediaDataId, mockResourceManager, abilityInfo);
217     ASSERT_EQ(ref, nullptr);
218 }
219 
220 /**
221  * @tc.name: GetPixelMapListInfo03
222  * @tc.desc: GetPixelMapListInfo
223  * @tc.type: FUNC
224  */
225 HWTEST_F(StartingWindowTest, GetPixelMapListInfo03, TestSize.Level1)
226 {
227     auto mockResourceManager = std::make_shared<OHOS::Global::Resource::MockResourceManager>();
228     auto abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
229     uint32_t mediaDataId = 1;
230     abilityInfo->hapPath = "/home/somepath/somefile";
231 
232     const size_t pngDataSize = sizeof(RAW_PNG_DATA);
233     auto testPngData = std::make_unique<uint8_t[]>(pngDataSize);
234     for (size_t i = 0; i < pngDataSize; ++i) {
235         testPngData[i] = RAW_PNG_DATA[i];
236     }
237 
238     EXPECT_CALL(*mockResourceManager, GetMediaDataById(_, _, _, _))
239     .WillOnce(DoAll(
240         SetArgReferee<1>(pngDataSize),
__anon3550e7cf0202(uint32_t, size_t&, std::unique_ptr<uint8_t[]>& dataOut, uint32_t) 241         testing::Invoke([&testPngData](uint32_t, size_t&, std::unique_ptr<uint8_t[]>& dataOut, uint32_t) {
242             dataOut = std::move(testPngData);
243         }),
244         Return(Global::Resource::RState::SUCCESS)
245     ));
246     auto ref = StartingWindow::GetPixelMapListInfo(mediaDataId, mockResourceManager, abilityInfo);
247     ASSERT_NE(ref, nullptr);
248 
249     //SOURCE_SIZE is bigger than MAX_SOURCE_SIZE
250     EXPECT_CALL(*mockResourceManager, GetMediaDataById(_, _, _, _))
251     .WillOnce(DoAll(
252         SetArgReferee<1>(MAX_SOURCE_SIZE + 1),
__anon3550e7cf0302(uint32_t, size_t&, std::unique_ptr<uint8_t[]>& dataOut, uint32_t) 253         testing::Invoke([&testPngData](uint32_t, size_t&, std::unique_ptr<uint8_t[]>& dataOut, uint32_t) {
254             dataOut = std::move(testPngData);
255         }),
256         Return(Global::Resource::RState::SUCCESS)
257     ));
258     ref = StartingWindow::GetPixelMapListInfo(mediaDataId, mockResourceManager, abilityInfo);
259     ASSERT_EQ(ref, nullptr);
260 }
261 
262 
263 /**
264  * @tc.name: GetPixelMapListInfo04
265  * @tc.desc: GetPixelMapListInfo
266  * @tc.type: FUNC
267  */
268 HWTEST_F(StartingWindowTest, GetPixelMapListInfo04, TestSize.Level1)
269 {
270     auto mockResourceManager = std::make_shared<OHOS::Global::Resource::MockResourceManager>();
271     auto abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
272     uint32_t mediaDataId = 1;
273     abilityInfo->hapPath = "/home/somepath/somefile";
274 
275     const size_t gifDataSize = sizeof(RAW_GIF_DATA);
276     auto testGifData = std::make_unique<uint8_t[]>(gifDataSize);
277     for (size_t i = 0; i < gifDataSize; i++) {
278         testGifData[i] = RAW_GIF_DATA[i];
279     }
280 
281     EXPECT_CALL(*mockResourceManager, GetMediaDataById(_, _, _, _))
282     .WillOnce(DoAll(
283         SetArgReferee<1>(gifDataSize),
__anon3550e7cf0402(uint32_t, size_t&, std::unique_ptr<uint8_t[]>& dataOut, uint32_t) 284         testing::Invoke([&testGifData](uint32_t, size_t&, std::unique_ptr<uint8_t[]>& dataOut, uint32_t) {
285             dataOut = std::move(testGifData);
286         }),
287         Return(Global::Resource::RState::SUCCESS)
288     ));
289     auto ref = StartingWindow::GetPixelMapListInfo(mediaDataId, mockResourceManager, abilityInfo);
290     ASSERT_NE(ref, nullptr);
291     EXPECT_EQ(ref->pixelMaps.size(), 2);
292     EXPECT_EQ(ref->delayTimes.size(), 2);
293 
294     const size_t invalidGifDataSize = sizeof(RAW_INVALID_GIF_DATA);
295     auto testInvalidGifData = std::make_unique<uint8_t[]>(invalidGifDataSize);
296     for (size_t i = 0; i < invalidGifDataSize; i++) {
297         testInvalidGifData[i] = RAW_INVALID_GIF_DATA[i];
298     }
299 
300     EXPECT_CALL(*mockResourceManager, GetMediaDataById(_, _, _, _))
301     .WillOnce(DoAll(
302         SetArgReferee<1>(invalidGifDataSize),
__anon3550e7cf0502(uint32_t, size_t&, std::unique_ptr<uint8_t[]>& dataOut, uint32_t) 303         testing::Invoke([&testInvalidGifData](uint32_t, size_t&, std::unique_ptr<uint8_t[]>& dataOut, uint32_t) {
304             dataOut = std::move(testInvalidGifData);
305         }),
306         Return(Global::Resource::RState::SUCCESS)
307     ));
308     ref = StartingWindow::GetPixelMapListInfo(mediaDataId, mockResourceManager, abilityInfo);
309     ASSERT_EQ(ref, nullptr);
310 }
311 
312 /**
313  * @tc.name: GetPixelMapListInfo05
314  * @tc.desc: GetPixelMapListInfo
315  * @tc.type: FUNC
316  */
317 HWTEST_F(StartingWindowTest, GetPixelMapListInfo05, TestSize.Level1)
318 {
319     auto mockResourceManager = std::make_shared<OHOS::Global::Resource::MockResourceManager>();
320     auto abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
321     uint32_t mediaDataId = 1;
322     abilityInfo->hapPath = "";
323 
324     //Resource path is inValid
325     std::string tmpPath1 = "home/data:";
326     EXPECT_CALL(*mockResourceManager, GetMediaById(_, _, _))
327         .WillOnce(DoAll(
328             SetArgReferee<1>(std::string(tmpPath1)),
329             Return(Global::Resource::RState::SUCCESS)
330     ));
331     auto ref = StartingWindow::GetPixelMapListInfo(mediaDataId, mockResourceManager, abilityInfo);
332     ASSERT_EQ(ref, nullptr);
333 
334     std::filesystem::path tmpDir = std::filesystem::temp_directory_path();
335     std::filesystem::path tmpFile = tmpDir / "wms_test_XXXXXX.png";
336     std::string tmpPath2 = tmpFile.string();
337     std::ofstream outFile(tmpPath2, std::ios::binary);
338     ASSERT_TRUE(outFile.is_open()) << "Failed to create temp file: " << tmpPath2;
339     outFile.write(reinterpret_cast<const char*>(RAW_PNG_DATA), sizeof(RAW_PNG_DATA));
340     outFile.close();
341 
342     EXPECT_CALL(*mockResourceManager, GetMediaById(_, _, _))
343         .WillOnce(DoAll(
344             SetArgReferee<1>(std::string(tmpPath2)),
345             Return(Global::Resource::RState::SUCCESS)
346         ));
347     ref = StartingWindow::GetPixelMapListInfo(mediaDataId, mockResourceManager, abilityInfo);
348     ASSERT_NE(ref, nullptr);
349     std::filesystem::remove(tmpPath2);
350 }
351 
352 /**
353  * @tc.name: GetPixelMapListInfo06
354  * @tc.desc: GetPixelMapListInfo
355  * @tc.type: FUNC
356  */
357 HWTEST_F(StartingWindowTest, GetPixelMapListInfo06, TestSize.Level1)
358 {
359     auto mockResourceManager = std::make_shared<OHOS::Global::Resource::MockResourceManager>();
360     auto abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
361     uint32_t mediaDataId = 1;
362     abilityInfo->hapPath = "";
363 
364     std::filesystem::path tmpDir1 = std::filesystem::temp_directory_path();
365     std::filesystem::path tmpFile1 = tmpDir1 / "wms_test_XXXXXX.gif";
366     std::string tmpPath1 = tmpFile1.string();
367     std::ofstream outFile1(tmpPath1, std::ios::binary);
368     ASSERT_TRUE(outFile1.is_open()) << "Failed to create temp file: " << tmpPath1;
369     outFile1.write(reinterpret_cast<const char*>(RAW_GIF_DATA), sizeof(RAW_GIF_DATA));
370     outFile1.close();
371     EXPECT_CALL(*mockResourceManager, GetMediaById(_, _, _))
372         .WillOnce(DoAll(
373             SetArgReferee<1>(std::string(tmpPath1)),
374             Return(Global::Resource::RState::SUCCESS)
375         ));
376     auto ref = StartingWindow::GetPixelMapListInfo(mediaDataId, mockResourceManager, abilityInfo);
377     ASSERT_NE(ref, nullptr);
378     EXPECT_EQ(ref->pixelMaps.size(), 2);
379     EXPECT_EQ(ref->delayTimes.size(), 2);
380     std::filesystem::remove(tmpPath1);
381 
382     std::filesystem::path tmpDir2 = std::filesystem::temp_directory_path();
383     std::filesystem::path tmpFile2 = tmpDir2 / "wms_test_Invalid.gif";
384     std::string tmpPath2 = tmpFile2.string();
385     std::ofstream outFile2(tmpPath2, std::ios::binary);
386     ASSERT_TRUE(outFile2.is_open()) << "Failed to create temp file: " << tmpPath2;
387     outFile2.write(reinterpret_cast<const char*>(RAW_INVALID_GIF_DATA), sizeof(RAW_INVALID_GIF_DATA));
388     outFile2.close();
389     EXPECT_CALL(*mockResourceManager, GetMediaById(_, _, _))
390         .WillOnce(DoAll(
391             SetArgReferee<1>(std::string(tmpPath2)),
392             Return(Global::Resource::RState::SUCCESS)
393         ));
394     ref = StartingWindow::GetPixelMapListInfo(mediaDataId, mockResourceManager, abilityInfo);
395     ASSERT_EQ(ref, nullptr);
396     std::filesystem::remove(tmpPath2);
397 }
398 
399 /**
400  * @tc.name: GetCustomStartingWindowInfo01
401  * @tc.desc: GetCustomStartingWindowInfo
402  * @tc.type: FUNC
403  */
404 HWTEST_F(StartingWindowTest, GetCustomStartingWindowInfo01, TestSize.Level1)
405 {
406     auto ref = StartingWindow::GetCustomStartingWindowInfo(nullptr, nullptr);
407     ASSERT_EQ(ref, nullptr);
408 
409     sptr<WindowTransitionInfo> winInfo = sptr<WindowTransitionInfo>::MakeSptr();
410     sptr<WindowNode> node = StartingWindow::CreateWindowNode(winInfo, 1);
411     ref = StartingWindow::GetCustomStartingWindowInfo(node, nullptr);
412     ASSERT_EQ(ref, nullptr);
413 
414     auto bundleMgr = StartingWindow::GetBundleManager();
415     ref = StartingWindow::GetCustomStartingWindowInfo(node, bundleMgr);
416     ASSERT_EQ(ref, nullptr);
417 
418     auto mockBundleMgr = sptr<AppExecFwk::MockIBundleMgr>::MakeSptr();
419     EXPECT_CALL(*mockBundleMgr, QueryAbilityInfo(_, _, _, _))
420         .Times(1).WillOnce(Return(true));
421     ref = StartingWindow::GetCustomStartingWindowInfo(node, mockBundleMgr);
422     ASSERT_EQ(ref, nullptr);
423 }
424 
425 /**
426  * @tc.name: DoGetCustomStartingWindowInfo01
427  * @tc.desc: DoGetCustomStartingWindowInfo
428  * @tc.type: FUNC
429  */
430 HWTEST_F(StartingWindowTest, DoGetCustomStartingWindowInfo01, TestSize.Level1)
431 {
432     auto ref = StartingWindow::DoGetCustomStartingWindowInfo(nullptr, nullptr);
433     ASSERT_EQ(ref, nullptr);
434 
435     auto abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
436     abilityInfo->startWindowResource.startWindowBackgroundColorId = 0;
437     ref = StartingWindow::DoGetCustomStartingWindowInfo(abilityInfo, nullptr);
438     ASSERT_EQ(ref, nullptr);
439 
440     auto mockResourceManager = std::make_shared<OHOS::Global::Resource::MockResourceManager>();
441     EXPECT_CALL(*mockResourceManager, GetColorById(_, _))
442         .Times(1).WillOnce(Return(Global::Resource::RState::NOT_FOUND));
443     ref = StartingWindow::DoGetCustomStartingWindowInfo(abilityInfo, mockResourceManager);
444     ASSERT_EQ(ref, nullptr);
445 
446     abilityInfo->startWindowResource.startWindowBackgroundColorId = 1;
447     abilityInfo->startWindowResource.startWindowAppIconId = 1;
448     abilityInfo->hapPath = "home/starting_window/hapPath";
449     const size_t pngDataSize = sizeof(RAW_PNG_DATA);
450     auto testData = std::make_unique<uint8_t[]>(pngDataSize);
451     for (size_t i = 0; i < pngDataSize; ++i) {
452         testData[i] = RAW_PNG_DATA[i];
453     }
454 
455     EXPECT_CALL(*mockResourceManager, GetColorById(_, _))
456         .Times(1).WillOnce(Return(Global::Resource::RState::SUCCESS));
457     EXPECT_CALL(*mockResourceManager, GetMediaDataById(_, _, _, _))
458     .WillOnce(DoAll(Return(Global::Resource::RState::NOT_FOUND)));
459     ref = StartingWindow::DoGetCustomStartingWindowInfo(abilityInfo, mockResourceManager);
460     ASSERT_NE(ref, nullptr);
461 
462     EXPECT_CALL(*mockResourceManager, GetColorById(_, _))
463         .Times(1).WillOnce(Return(Global::Resource::RState::SUCCESS));
464     EXPECT_CALL(*mockResourceManager, GetMediaDataById(_, _, _, _))
465     .WillOnce(DoAll(
466         SetArgReferee<1>(pngDataSize),
__anon3550e7cf0602(uint32_t, size_t&, std::unique_ptr<uint8_t[]>& dataOut, uint32_t) 467         testing::Invoke([&testData](uint32_t, size_t&, std::unique_ptr<uint8_t[]>& dataOut, uint32_t) {
468             dataOut = std::move(testData);
469         }),
470         Return(Global::Resource::RState::SUCCESS)
471     ));
472     ref = StartingWindow::DoGetCustomStartingWindowInfo(abilityInfo, mockResourceManager);
473     ASSERT_NE(ref, nullptr);
474 }
475 
476 /**
477  * @tc.name: DrawStartingWindow01
478  * @tc.desc: DrawStartingWindow
479  * @tc.type: FUNC
480  */
481 HWTEST_F(StartingWindowTest, DrawStartingWindow01, TestSize.Level1)
482 {
483     sptr<WindowTransitionInfo> winInfo = sptr<WindowTransitionInfo>::MakeSptr();
484     sptr<WindowNode> node = StartingWindow::CreateWindowNode(winInfo, 1);
485     ASSERT_NE(node, nullptr);
486     Rosen::RSSurfaceNodeConfig config;
487     node->startingWinSurfaceNode_ = Rosen::RSSurfaceNode::Create(config);
488     ASSERT_NE(node->startingWinSurfaceNode_, nullptr);
489 
490     Rosen::Rect rect {0, 0, 0, 0};
491     auto ret = StartingWindow::DrawStartingWindow(nullptr, node, rect);
492     EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
493 
494     auto info = std::make_shared<Rosen::StartingWindowPageDrawInfo>();
495     info->bgColor = 0x00660000;
496     ret = StartingWindow::DrawStartingWindow(info, node, rect);
497     EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_PARAM);
498     rect = {0, 0, 200, 300};
499     ret = StartingWindow::DrawStartingWindow(info, node, rect);
500     EXPECT_EQ(ret, WMError::WM_OK);
501 }
502 
503 /**
504  * @tc.name: DrawStartingWindow02
505  * @tc.desc: DrawStartingWindow
506  * @tc.type: FUNC
507  */
508 HWTEST_F(StartingWindowTest, DrawStartingWindow02, TestSize.Level1)
509 {
510     sptr<WindowTransitionInfo> winInfo = sptr<WindowTransitionInfo>::MakeSptr();
511     sptr<WindowNode> node = StartingWindow::CreateWindowNode(winInfo, 1);
512     ASSERT_NE(node, nullptr);
513     Rosen::RSSurfaceNodeConfig config;
514     node->startingWinSurfaceNode_ = Rosen::RSSurfaceNode::Create(config);
515     ASSERT_NE(node->startingWinSurfaceNode_, nullptr);
516 
517     Rosen::Rect rect {0, 0, 0, -1};
518     auto info = std::make_shared<Rosen::StartingWindowPageDrawInfo>();
519     info->bgColor = 0x00660000;
520     info->appIcon = std::make_shared<ResourceInfo>();
521     std::shared_ptr<Media::PixelMap> pixelMap = SurfaceDraw::DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH);
522     info->appIcon->pixelMaps.push_back(pixelMap);
523 
524     auto ret = StartingWindow::DrawStartingWindow(info, node, rect);
525     EXPECT_EQ(StartingWindow::startingWindowShowRunning_, false);
526     EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_PARAM);
527 }
528 
529 /**
530  * @tc.name: DrawStartingWindow03
531  * @tc.desc: DrawStartingWindow
532  * @tc.type: FUNC
533  */
534 HWTEST_F(StartingWindowTest, DrawStartingWindow03, TestSize.Level1)
535 {
536     sptr<WindowTransitionInfo> winInfo = sptr<WindowTransitionInfo>::MakeSptr();
537     sptr<WindowNode> node = StartingWindow::CreateWindowNode(winInfo, 1);
538     ASSERT_NE(node, nullptr);
539     Rosen::RSSurfaceNodeConfig config;
540     node->startingWinSurfaceNode_ = Rosen::RSSurfaceNode::Create(config);
541     ASSERT_NE(node->startingWinSurfaceNode_, nullptr);
542 
543     Rosen::Rect rect {0, 0, 300, 600};
544     auto info = std::make_shared<Rosen::StartingWindowPageDrawInfo>();
545     info->bgColor = 0x00660000;
546     info->appIcon = std::make_shared<ResourceInfo>();
547     std::shared_ptr<Media::PixelMap> pixelMap = SurfaceDraw::DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH);
548     info->appIcon->pixelMaps.push_back(pixelMap);
549 
550     StartingWindow::startingWindowShowRunning_ = true;
551     auto ret = StartingWindow::DrawStartingWindow(info, node, rect);
552     EXPECT_EQ(ret, WMError::WM_OK);
553 }
554 
555 /**
556  * @tc.name: RegisterStartingWindowShowInfo01
557  * @tc.desc: RegisterStartingWindowShowInfo
558  * @tc.type: FUNC
559  */
560 HWTEST_F(StartingWindowTest, RegisterStartingWindowShowInfo01, TestSize.Level1)
561 {
562     sptr<WindowTransitionInfo> winInfo = sptr<WindowTransitionInfo>::MakeSptr();
563     sptr<WindowNode> node = StartingWindow::CreateWindowNode(winInfo, 1);
564     ASSERT_NE(node, nullptr);
565     Rosen::Rect rect { 0, 0, 200, 300 };
566     auto info = std::make_shared<Rosen::StartingWindowPageDrawInfo>();
567     info->bgColor = 0x00660000;
568     info->appIcon = std::make_shared<ResourceInfo>();
569     info->appIcon->delayTimes.push_back(0);
570     float vpRatio = 1.5;
571 
572     StartingWindow::RegisterStartingWindowShowInfo(node, rect, info, vpRatio);
573     ASSERT_NE(StartingWindow::startingWindowShowInfo_.info, nullptr);
574 }
575 
576 /**
577  * @tc.name: UnRegisterStartingWindowShowInfo01
578  * @tc.desc: UnRegisterStartingWindowShowInfo
579  * @tc.type: FUNC
580  */
581 HWTEST_F(StartingWindowTest, UnRegisterStartingWindowShowInfo01, TestSize.Level1)
582 {
583     StartingWindow::startingWindowShowInfo_.info = std::make_shared<Rosen::StartingWindowPageDrawInfo>();
584     StartingWindow::startingWindowShowInfo_.info->appIcon = std::make_shared<ResourceInfo>();
585     std::shared_ptr<Media::PixelMap> pixelMap = SurfaceDraw::DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH);
586     StartingWindow::startingWindowShowInfo_.info->appIcon->pixelMaps.push_back(pixelMap);
587     StartingWindow::UnRegisterStartingWindowShowInfo();
588     ASSERT_EQ(StartingWindow::startingWindowShowInfo_.info, nullptr);
589 }
590 
591 /**
592  * @tc.name: UpdateWindowShowInfo01
593  * @tc.desc: UpdateWindowShowInfo
594  * @tc.type: FUNC
595  */
596 HWTEST_F(StartingWindowTest, UpdateWindowShowInfo01, TestSize.Level1)
597 {
598     StartingWindowShowInfo startingWindowShowInfo;
599 
600     bool needDraw = false;
601     StartingWindow::UpdateWindowShowInfo(startingWindowShowInfo, needDraw);
602     EXPECT_EQ(needDraw, false);
603 
604     startingWindowShowInfo.resStates[0].next = std::chrono::steady_clock::now() - std::chrono::seconds(1);
605     startingWindowShowInfo.resStates[0].frameCount = 1;
606     startingWindowShowInfo.resStates[0].delay.push_back(INT32_MAX);
607     startingWindowShowInfo.resStates[0].frameIdx = 0;
608 
609     StartingWindow::UpdateWindowShowInfo(startingWindowShowInfo, needDraw);
610     EXPECT_EQ(needDraw, true);
611 }
612 } // namespace Rosen
613 } // namespace OHOS