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 <gtest/hwext/gtest-multithread.h>
18 
19 #include <string>
20 #include <map>
21 
22 #define private public
23 #include "ability_delegator.h"
24 #include "ability_manager_client.h"
25 #include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h"
26 #undef private
27 
28 #include "ability_delegator_infos.h"
29 #include "ability_delegator_registry.h"
30 #include "app_loader.h"
31 #include "hilog_tag_wrapper.h"
32 #include "js_runtime.h"
33 #include "mock_ability_delegator_stub.h"
34 #include "mock_iability_monitor.h"
35 #include "mock_test_observer_stub.h"
36 #include "mock_test_runner.h"
37 #include "ohos_application.h"
38 #include "test_observer_stub.h"
39 #include "test_observer.h"
40 #include "test_runner.h"
41 #include "want.h"
42 #include "scene_board_judgement.h"
43 
44 using namespace testing;
45 using namespace testing::ext;
46 using namespace testing::mt;
47 using namespace OHOS;
48 using namespace OHOS::AppExecFwk;
49 using namespace OHOS::AAFwk;
50 
51 namespace OHOS {
52 namespace AppExecFwk {
53 namespace {
54 const std::string KEY_TEST_BUNDLE_NAME = "-p";
55 const std::string VALUE_TEST_BUNDLE_NAME = "com.example.myapplication";
56 const std::string CHANGE_VALUE_TEST_BUNDLE_NAME = "com.example.myapplication1";
57 const std::string KEY_TEST_RUNNER_CLASS = "-s unittest";
58 const std::string VALUE_TEST_RUNNER_CLASS = "JSUserTestRunner";
59 const std::string CHANGE_VALUE_TEST_RUNNER_CLASS = "JSUserTestRunner1";
60 const std::string KEY_TEST_CASE = "-s class";
61 const std::string VALUE_TEST_CASE = "ohos.acts.aafwk.ability.test.ConstructorTest#testDataAbilityOtherFunction0010";
62 const std::string CHANGE_VALUE_TEST_CASE =
63     "ohos.acts.aafwk.ability.test.ConstructorTest#testDataAbilityOtherFunction00101";
64 const std::string KEY_TEST_WAIT_TIMEOUT = "-w";
65 const std::string VALUE_TEST_WAIT_TIMEOUT = "50";
66 const std::string CHANGE_VALUE_TEST_WAIT_TIMEOUT = "80";
67 const std::string SET_VALUE_TEST_BUNDLE_NAME = "com.example.myapplicationset";
68 const std::string ABILITY_NAME = "com.example.myapplication.MainAbility";
69 const std::string FINISH_MSG = "finish message";
70 const int32_t FINISH_RESULT_CODE = 144;
71 const std::string PRINT_MSG = "print aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
72 const int ZERO = 0;
73 const int ONE = 1;
74 const int TWO = 2;
75 const int64_t TIMEOUT = 50;
76 const std::string CMD = "ls -l";
77 const std::string KEY_TEST_DEBUG {"-D"};
78 const std::string VALUE_TEST_DEBUG {"true"};
79 const std::string ABILITY_STAGE_MONITOR_MODULE_NAME {"entry"};
80 const std::string ABILITY_STAGE_MONITOR_SRC_ENTRANCE {"MainAbility"};
81 }  // namespace
82 
83 class AbilityDelegatorTest : public ::testing::Test {
84 public:
85     static void SetUpTestCase();
86     static void TearDownTestCase();
87     void SetUp() override;
88     void TearDown() override;
89     void MakeMockObjects() const;
90 
91 public:
92     static std::shared_ptr<AbilityDelegator> commonDelegator_;
93     static std::shared_ptr<AbilityDelegatorArgs> delegatorArgs_;
94 };
95 
96 std::shared_ptr<AbilityDelegator> AbilityDelegatorTest::commonDelegator_ = nullptr;
97 std::shared_ptr<AbilityDelegatorArgs> AbilityDelegatorTest::delegatorArgs_ = nullptr;
98 
SetUpTestCase()99 void AbilityDelegatorTest::SetUpTestCase()
100 {
101     // Construct a common ability delegator firstly.
102     std::map<std::string, std::string> paras;
103     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
104     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
105     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
106     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
107     paras.emplace(KEY_TEST_DEBUG, VALUE_TEST_DEBUG);
108 
109     Want want;
110     for (auto para : paras) {
111         want.SetParam(para.first, para.second);
112     }
113 
114     delegatorArgs_ = std::make_shared<AbilityDelegatorArgs>(want);
115     AbilityRuntime::Runtime::Options options;
116     auto testRunner = TestRunner::Create(AbilityRuntime::Runtime::Create(options), delegatorArgs_, true);
117     commonDelegator_ = std::make_shared<AbilityDelegator>(std::make_shared<AbilityRuntime::ContextImpl>(),
118         std::move(testRunner), sptr<IRemoteObject>(new AAFwk::MockTestObserverStub));
119 }
120 
TearDownTestCase()121 void AbilityDelegatorTest::TearDownTestCase()
122 {}
123 
SetUp()124 void AbilityDelegatorTest::SetUp()
125 {
126     // reset optind to 0
127     optind = 0;
128 
129     // make mock objects
130     MakeMockObjects();
131 }
132 
TearDown()133 void AbilityDelegatorTest::TearDown()
134 {}
135 
MakeMockObjects() const136 void AbilityDelegatorTest::MakeMockObjects() const
137 {
138     // mock a stub
139     auto managerStubPtr = sptr<OHOS::AAFwk::IAbilityManager>(new MockAbilityDelegatorStub);
140 
141     // set the mock stub
142     auto managerClientPtr = AbilityManagerClient::GetInstance();
143     managerClientPtr->proxy_ = managerStubPtr;
144 }
145 
146 class AbilityDelegatorTest2 : public ::testing::Test {
147 public:
148     static void SetUpTestCase();
149     static void TearDownTestCase();
150     void SetUp() override;
151     void TearDown() override;
152     void MakeMockObjects() const;
153 };
154 
SetUpTestCase()155 void AbilityDelegatorTest2::SetUpTestCase()
156 {}
157 
TearDownTestCase()158 void AbilityDelegatorTest2::TearDownTestCase()
159 {}
160 
SetUp()161 void AbilityDelegatorTest2::SetUp()
162 {
163     // reset optind to 0
164     optind = 0;
165 
166     // make mock objects
167     MakeMockObjects();
168 }
169 
TearDown()170 void AbilityDelegatorTest2::TearDown()
171 {}
172 
MakeMockObjects() const173 void AbilityDelegatorTest2::MakeMockObjects() const
174 {
175     // mock a stub
176     auto managerStubPtr = sptr<OHOS::AAFwk::IAbilityManager>(new MockAbilityDelegatorStub2);
177 
178     // set the mock stub
179     auto managerClientPtr = AbilityManagerClient::GetInstance();
180     managerClientPtr->proxy_ = managerStubPtr;
181 }
182 
183 /**
184  * @tc.number: Ability_Delegator_Test_0100
185  * @tc.name: ClearAllMonitors and AddAbilityMonitor and GetMonitorsNum.
186  * @tc.desc: Verify the ClearAllMonitors and AddAbilityMonitor and GetMonitorsNum.
187  */
188 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0100, Function | MediumTest | Level1)
189 {
190     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_0100 is called");
191     std::map<std::string, std::string> paras;
192     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
193     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
194     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
195     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
196 
197     Want want;
198     for (auto para : paras) {
199         want.SetParam(para.first, para.second);
200     }
201 
202     std::shared_ptr<AbilityDelegatorArgs> abilityArgs = std::make_shared<AbilityDelegatorArgs>(want);
203     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
204     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
205         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
206         abilityArgs,
207         true);
208     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
209     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
210 
211     abilityDelegator.ClearAllMonitors();
212     std::shared_ptr<IAbilityMonitor> imotor = std::make_shared<IAbilityMonitor>(ABILITY_NAME);
213     std::shared_ptr<IAbilityMonitor> imotor1 = std::make_shared<IAbilityMonitor>(ABILITY_NAME);
214 
215     abilityDelegator.AddAbilityMonitor(imotor);
216     EXPECT_EQ((int)(abilityDelegator.GetMonitorsNum()), ONE);
217     abilityDelegator.AddAbilityMonitor(imotor);
218     EXPECT_EQ((int)(abilityDelegator.GetMonitorsNum()), ONE);
219     abilityDelegator.AddAbilityMonitor(imotor1);
220     EXPECT_EQ((int)(abilityDelegator.GetMonitorsNum()), TWO);
221 }
222 
223 /**
224  * @tc.number: Ability_Delegator_Test_0200
225  * @tc.name: ClearAllMonitors and AddAbilityMonitor and RemoveAbilityMonitor and GetMonitorsNum.
226  * @tc.desc: Verify the ClearAllMonitors and AddAbilityMonitor and RemoveAbilityMonitor and GetMonitorsNum.
227  */
228 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0200, Function | MediumTest | Level1)
229 {
230     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_0200 is called");
231     std::map<std::string, std::string> paras;
232     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
233     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
234     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
235     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
236 
237     Want want;
238     for (auto para : paras) {
239         want.SetParam(para.first, para.second);
240     }
241 
242     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
243     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
244         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
245         std::make_shared<AbilityDelegatorArgs>(want),
246         true);
247     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
248     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
249 
250     std::shared_ptr<IAbilityMonitor> imotor = std::make_shared<IAbilityMonitor>(ABILITY_NAME);
251     abilityDelegator.ClearAllMonitors();
252     abilityDelegator.AddAbilityMonitor(imotor);
253     EXPECT_EQ((int)(abilityDelegator.GetMonitorsNum()), ONE);
254     abilityDelegator.RemoveAbilityMonitor(imotor);
255     EXPECT_EQ((int)(abilityDelegator.GetMonitorsNum()), ZERO);
256 }
257 
258 /**
259  * @tc.number: Ability_Delegator_Test_0300
260  * @tc.name: GetBundleName
261  * @tc.desc: Verify the GetBundleName is null.
262  */
263 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0300, Function | MediumTest | Level1)
264 {
265     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_0300 is called");
266     std::map<std::string, std::string> paras;
267     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
268     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
269     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
270     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
271 
272     Want want;
273     for (auto para : paras) {
274         want.SetParam(para.first, para.second);
275     }
276 
277     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
278     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
279         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
280         std::make_shared<AbilityDelegatorArgs>(want),
281         true);
282     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
283     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
284 
285     EXPECT_EQ(abilityDelegator.GetAppContext()->GetBundleName(), "");
286 }
287 
288 /**
289  * @tc.number: Ability_Delegator_Test_0400
290  * @tc.name: GetAbilityState
291  * @tc.desc: Verify the GetAbilityState input para is nullptr.
292  */
293 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0400, Function | MediumTest | Level1)
294 {
295     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_0400 is called");
296     std::map<std::string, std::string> paras;
297     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
298     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
299     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
300     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
301 
302     Want want;
303     for (auto para : paras) {
304         want.SetParam(para.first, para.second);
305     }
306 
307     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
308     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
309         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
310         std::make_shared<AbilityDelegatorArgs>(want),
311         true);
312     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
313     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
314 
315     int abilityState = static_cast<int>(abilityDelegator.GetAbilityState(nullptr));
316 
317     EXPECT_EQ(abilityState, static_cast<int>(AbilityDelegator::AbilityState::UNINITIALIZED));
318 }
319 
320 /**
321  * @tc.number: Ability_Delegator_Test_0500
322  * @tc.name: GetAbilityState
323  * @tc.desc: Verify the GetAbilityState input para is valid.
324  */
325 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0500, Function | MediumTest | Level1)
326 {
327     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_0500 is called");
328     std::map<std::string, std::string> paras;
329     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
330     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
331     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
332     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
333 
334     Want want;
335     for (auto para : paras) {
336         want.SetParam(para.first, para.second);
337     }
338 
339     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
340     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
341         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
342         std::make_shared<AbilityDelegatorArgs>(want),
343         true);
344     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
345     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
346 
347     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
348     std::shared_ptr<ADelegatorAbilityProperty> abilityProperty = std::make_shared<ADelegatorAbilityProperty>();
349     abilityProperty->token_ = token;
350     abilityProperty->name_ = ABILITY_NAME;
351     abilityProperty->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
352     abilityDelegator.abilityProperties_.emplace_front(abilityProperty);
353     int abilityState = static_cast<int>(abilityDelegator.GetAbilityState(token));
354 
355     EXPECT_EQ(abilityState, static_cast<int>(AbilityDelegator::AbilityState::STARTED));
356 }
357 
358 /**
359  * @tc.number: Ability_Delegator_Test_0600
360  * @tc.name: GetAbilityState
361  * @tc.desc: Verify the GetAbilityState input para is valid but not find in abilityProperties_.
362  */
363 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0600, Function | MediumTest | Level1)
364 {
365     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_0600 is called");
366     std::map<std::string, std::string> paras;
367     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
368     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
369     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
370     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
371 
372     Want want;
373     for (auto para : paras) {
374         want.SetParam(para.first, para.second);
375     }
376 
377     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
378     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
379         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
380         std::make_shared<AbilityDelegatorArgs>(want),
381         true);
382     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
383     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
384 
385     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
386     int abilityState = static_cast<int>(abilityDelegator.GetAbilityState(token));
387 
388     EXPECT_EQ(abilityState, static_cast<int>(AbilityDelegator::AbilityState::UNINITIALIZED));
389 }
390 
391 /**
392  * @tc.number: Ability_Delegator_Test_0700
393  * @tc.name: GetCurrentTopAbility
394  * @tc.desc: Verify the GetCurrentTopAbility is invalid.
395  */
396 HWTEST_F(AbilityDelegatorTest2, Ability_Delegator_Test_070, Function | MediumTest | Level1)
397 {
398     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_0700 is called");
399     std::map<std::string, std::string> paras;
400     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
401     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
402     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
403     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
404 
405     Want want;
406     for (auto para : paras) {
407         want.SetParam(para.first, para.second);
408     }
409 
410     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
411     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
412         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
413         std::make_shared<AbilityDelegatorArgs>(want),
414         true);
415     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub2());
416     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
417     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub2);
418     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
419     ability->token_ = token;
420     ability->name_ = ABILITY_NAME;
421     ability->fullName_ = ABILITY_NAME;
422     abilityDelegator.abilityProperties_.emplace_back(ability);
423 
424     // Empty abilityName.
425     MockAbilityDelegatorStub2::testcaseBranch_ = TESTCASE_BRANCH::BRANCH_1;
426     EXPECT_EQ(abilityDelegator.GetCurrentTopAbility(), nullptr);
427 
428     // Unkonwn abilityName.
429     MockAbilityDelegatorStub2::testcaseBranch_ = TESTCASE_BRANCH::BRANCH_2;
430     EXPECT_EQ(abilityDelegator.GetCurrentTopAbility(), nullptr);
431 
432     // Valid abilityName.
433     MockAbilityDelegatorStub2::testcaseBranch_ = TESTCASE_BRANCH::BRANCH_3;
434     if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
435         EXPECT_EQ(abilityDelegator.GetCurrentTopAbility(), ability);
436     }
437 
438     // Set testcase branch to default.
439     MockAbilityDelegatorStub2::testcaseBranch_ = TESTCASE_BRANCH::BRANCH_1;
440 }
441 
442 /**
443  * @tc.number: Ability_Delegator_Test_0800
444  * @tc.name: DoAbilityForeground
445  * @tc.desc: Verify the DoAbilityForeground is valid.
446  */
447 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0800, Function | MediumTest | Level1)
448 {
449     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_0800 is called");
450     std::map<std::string, std::string> paras;
451     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
452     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
453     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
454     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
455 
456     Want want;
457     for (auto para : paras) {
458         want.SetParam(para.first, para.second);
459     }
460 
461     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
462     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
463         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
464         std::make_shared<AbilityDelegatorArgs>(want),
465         true);
466     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
467     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
468 
469     if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
470         sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
471         EXPECT_TRUE(abilityDelegator.DoAbilityForeground(token));
472     }
473 
474     EXPECT_TRUE(iRemoteObj != nullptr);
475 }
476 
477 /**
478  * @tc.number: Ability_Delegator_Test_0900
479  * @tc.name: DoAbilityForeground
480  * @tc.desc: Verify the DoAbilityForeground is invalid.
481  */
482 HWTEST_F(AbilityDelegatorTest2, Ability_Delegator_Test_0900, Function | MediumTest | Level1)
483 {
484     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_0900 is called");
485     std::map<std::string, std::string> paras;
486     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
487     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
488     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
489     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
490 
491     Want want;
492     for (auto para : paras) {
493         want.SetParam(para.first, para.second);
494     }
495 
496     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
497     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
498         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
499         std::make_shared<AbilityDelegatorArgs>(want),
500         true);
501     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub2());
502     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
503 
504     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub2);
505 
506     EXPECT_FALSE(abilityDelegator.DoAbilityForeground(token));
507 }
508 
509 /**
510  * @tc.number: Ability_Delegator_Test_1000
511  * @tc.name: DoAbilityForeground
512  * @tc.desc: Verify the DoAbilityForeground input token is nullptr and result is invalid.
513  */
514 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1000, Function | MediumTest | Level1)
515 {
516     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_1000 is called");
517     std::map<std::string, std::string> paras;
518     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
519     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
520     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
521     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
522 
523     Want want;
524     for (auto para : paras) {
525         want.SetParam(para.first, para.second);
526     }
527 
528     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
529     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
530         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
531         std::make_shared<AbilityDelegatorArgs>(want),
532         true);
533     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
534     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
535 
536     EXPECT_FALSE(abilityDelegator.DoAbilityForeground(nullptr));
537 }
538 
539 /**
540  * @tc.number: Ability_Delegator_Test_1100
541  * @tc.name: DoAbilityBackground
542  * @tc.desc: Verify the DoAbilityBackground is valid.
543  */
544 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1100, Function | MediumTest | Level1)
545 {
546     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_1100 is called");
547     std::map<std::string, std::string> paras;
548     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
549     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
550     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
551     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
552 
553     Want want;
554     for (auto para : paras) {
555         want.SetParam(para.first, para.second);
556     }
557 
558     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
559     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
560         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
561         std::make_shared<AbilityDelegatorArgs>(want),
562         true);
563     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
564     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
565 
566     if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
567         sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
568         EXPECT_TRUE(abilityDelegator.DoAbilityBackground(token));
569     }
570 
571     EXPECT_TRUE(iRemoteObj != nullptr);
572 }
573 
574 /**
575  * @tc.number: Ability_Delegator_Test_1200
576  * @tc.name: DoAbilityBackground
577  * @tc.desc: Verify the DoAbilityBackground is invalid.
578  */
579 HWTEST_F(AbilityDelegatorTest2, Ability_Delegator_Test_1200, Function | MediumTest | Level1)
580 {
581     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_1200 is called");
582     std::map<std::string, std::string> paras;
583     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
584     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
585     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
586     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
587 
588     Want want;
589     for (auto para : paras) {
590         want.SetParam(para.first, para.second);
591     }
592 
593     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
594     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
595         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
596         std::make_shared<AbilityDelegatorArgs>(want),
597         true);
598     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub2());
599     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
600 
601     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub2);
602 
603     EXPECT_FALSE(abilityDelegator.DoAbilityBackground(token));
604 }
605 
606 /**
607  * @tc.number: Ability_Delegator_Test_1300
608  * @tc.name: DoAbilityBackground
609  * @tc.desc: Verify the DoAbilityBackground input token is nullptr and result is invalid.
610  */
611 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1300, Function | MediumTest | Level1)
612 {
613     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_1300 is called");
614     std::map<std::string, std::string> paras;
615     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
616     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
617     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
618     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
619 
620     Want want;
621     for (auto para : paras) {
622         want.SetParam(para.first, para.second);
623     }
624 
625     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
626     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
627         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
628         std::make_shared<AbilityDelegatorArgs>(want),
629         true);
630     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
631     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
632 
633     EXPECT_FALSE(abilityDelegator.DoAbilityBackground(nullptr));
634 }
635 
636 /**
637  * @tc.number: Ability_Delegator_Test_1400
638  * @tc.name: ExecuteShellCommand
639  * @tc.desc: Verify the ExecuteShellCommand input para cmd is null and result is invalid.
640  */
641 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1400, Function | MediumTest | Level1)
642 {
643     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_1400 is called");
644     std::map<std::string, std::string> paras;
645     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
646     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
647     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
648     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
649 
650     Want want;
651     for (auto para : paras) {
652         want.SetParam(para.first, para.second);
653     }
654 
655     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
656     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
657         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
658         std::make_shared<AbilityDelegatorArgs>(want),
659         true);
660     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
661     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
662 
663     EXPECT_EQ(abilityDelegator.ExecuteShellCommand("", TIMEOUT), nullptr);
664 }
665 
666 /**
667  * @tc.number: Ability_Delegator_Test_1500
668  * @tc.name: ExecuteShellCommand
669  * @tc.desc: Verify the ExecuteShellCommand para observer is null and result is invalid.
670  */
671 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1500, Function | MediumTest | Level1)
672 {
673     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_1500 is called");
674     std::map<std::string, std::string> paras;
675     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
676     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
677     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
678     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
679 
680     Want want;
681     for (auto para : paras) {
682         want.SetParam(para.first, para.second);
683     }
684 
685     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
686     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
687         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
688         std::make_shared<AbilityDelegatorArgs>(want),
689         true);
690     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
691     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
692     abilityDelegator.observer_ = nullptr;
693 
694     EXPECT_EQ(abilityDelegator.ExecuteShellCommand(CMD, TIMEOUT), nullptr);
695 }
696 
697 /**
698  * @tc.number: Ability_Delegator_Test_1600
699  * @tc.name: ExecuteShellCommand
700  * @tc.desc: Verify the ExecuteShellCommand is valid.
701  */
702 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1600, Function | MediumTest | Level1)
703 {
704     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_1600 is called");
705     std::map<std::string, std::string> paras;
706     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
707     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
708     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
709     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
710 
711     Want want;
712     for (auto para : paras) {
713         want.SetParam(para.first, para.second);
714     }
715 
716     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
717     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
718         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
719         std::make_shared<AbilityDelegatorArgs>(want),
720         true);
721     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
722     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
723     sptr<IRemoteObject> shobserver = sptr<IRemoteObject>(new MockTestObserverStub);
724     abilityDelegator.observer_ = shobserver;
725 
726     EXPECT_NE(abilityDelegator.ExecuteShellCommand(CMD, TIMEOUT), nullptr);
727 }
728 
729 /**
730  * @tc.number: Ability_Delegator_Test_1700
731  * @tc.name: Print
732  * @tc.desc: Verify the Print is invalid.
733  */
734 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1700, Function | MediumTest | Level1)
735 {
736     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_1700 is called");
737     std::map<std::string, std::string> paras;
738     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
739     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
740     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
741     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
742 
743     Want want;
744     for (auto para : paras) {
745         want.SetParam(para.first, para.second);
746     }
747 
748     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
749     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
750         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
751         std::make_shared<AbilityDelegatorArgs>(want),
752         true);
753     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
754     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
755     sptr<IRemoteObject> shobserver = sptr<IRemoteObject>(new MockTestObserverStub);
756     abilityDelegator.observer_ = nullptr;
757     abilityDelegator.Print(PRINT_MSG);
758 
759     EXPECT_FALSE(iface_cast<MockTestObserverStub>(shobserver)->testStatusFlag);
760 }
761 
762 /**
763  * @tc.number: Ability_Delegator_Test_1800
764  * @tc.name: Print
765  * @tc.desc: Verify the Print is valid.
766  */
767 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1800, Function | MediumTest | Level1)
768 {
769     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_1800 is called");
770     std::map<std::string, std::string> paras;
771     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
772     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
773     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
774     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
775 
776     Want want;
777     for (auto para : paras) {
778         want.SetParam(para.first, para.second);
779     }
780 
781     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
782     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
783         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
784         std::make_shared<AbilityDelegatorArgs>(want),
785         true);
786     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
787     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
788     sptr<IRemoteObject> shobserver = sptr<IRemoteObject>(new MockTestObserverStub);
789     abilityDelegator.observer_ = shobserver;
790     abilityDelegator.Print(PRINT_MSG);
791 
792     EXPECT_TRUE(iface_cast<MockTestObserverStub>(shobserver)->testStatusFlag);
793 }
794 
795 /**
796  * @tc.number: Ability_Delegator_Test_1900
797  * @tc.name: ProcessAbilityProperties
798  * @tc.desc: Verify the ProcessAbilityProperties list is add.
799  */
800 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1900, Function | MediumTest | Level1)
801 {
802     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_1900 is called");
803     std::map<std::string, std::string> paras;
804     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
805     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
806     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
807     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
808 
809     Want want;
810     for (auto para : paras) {
811         want.SetParam(para.first, para.second);
812     }
813 
814     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
815     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
816         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
817         std::make_shared<AbilityDelegatorArgs>(want),
818         true);
819     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
820     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
821 
822     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
823     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
824     ability->token_ = token;
825     ability->name_ = ABILITY_NAME;
826     ability->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
827     ability->object_ = std::shared_ptr<NativeReference>();
828     abilityDelegator.abilityProperties_.clear();
829     abilityDelegator.PostPerformStart(ability);
830 
831     EXPECT_EQ(abilityDelegator.abilityProperties_.size(), ONE);
832 }
833 
834 /**
835  * @tc.number: Ability_Delegator_Test_2000
836  * @tc.name: ProcessAbilityProperties
837  * @tc.desc: Verify the ProcessAbilityProperties list is not add.
838  */
839 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2000, Function | MediumTest | Level1)
840 {
841     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_2000 is called");
842     std::map<std::string, std::string> paras;
843     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
844     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
845     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
846     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
847 
848     Want want;
849     for (auto para : paras) {
850         want.SetParam(para.first, para.second);
851     }
852 
853     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
854     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
855         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
856         std::make_shared<AbilityDelegatorArgs>(want),
857         true);
858     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
859     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
860     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
861     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
862     ability->token_ = token;
863     ability->name_ = ABILITY_NAME;
864     ability->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
865     ability->object_ = std::shared_ptr<NativeReference>();
866     abilityDelegator.abilityProperties_.clear();
867     abilityDelegator.abilityProperties_.emplace_back(ability);
868     abilityDelegator.PostPerformStart(ability);
869     EXPECT_EQ(abilityDelegator.abilityProperties_.size(), ONE);
870 }
871 
872 /**
873  * @tc.number: Ability_Delegator_Test_2100
874  * @tc.name: PostPerformStart
875  * @tc.desc: Verify the PostPerformStart is invalid.
876  */
877 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2100, Function | MediumTest | Level1)
878 {
879     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_2100 is called");
880     std::map<std::string, std::string> paras;
881     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
882     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
883     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
884     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
885 
886     Want want;
887     for (auto para : paras) {
888         want.SetParam(para.first, para.second);
889     }
890 
891     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
892     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
893         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
894         std::make_shared<AbilityDelegatorArgs>(want),
895         true);
896     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
897     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
898     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
899     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
900     abilityDelegator.PostPerformStart(nullptr);
901 
902     EXPECT_FALSE(mockMonitor->start_);
903 }
904 
905 /**
906  * @tc.number: Ability_Delegator_Test_2200
907  * @tc.name: PostPerformStart
908  * @tc.desc: Verify the PostPerformStart is valid.
909  */
910 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2200, Function | MediumTest | Level1)
911 {
912     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_2200 is called");
913     std::map<std::string, std::string> paras;
914     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
915     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
916     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
917     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
918 
919     Want want;
920     for (auto para : paras) {
921         want.SetParam(para.first, para.second);
922     }
923 
924     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
925     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
926         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
927         std::make_shared<AbilityDelegatorArgs>(want),
928         true);
929     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
930     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
931     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
932     abilityDelegator.abilityMonitors_.clear();
933     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
934     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
935     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
936     ability->token_ = token;
937     ability->name_ = ABILITY_NAME;
938     ability->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
939     ability->object_ = std::shared_ptr<NativeReference>();
940     abilityDelegator.PostPerformStart(ability);
941 
942     EXPECT_TRUE(mockMonitor->start_);
943 }
944 
945 /**
946  * @tc.number: Ability_Delegator_Test_2300
947  * @tc.name: PostPerformScenceCreated
948  * @tc.desc: Verify the PostPerformScenceCreated is invalid.
949  */
950 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_23400, Function | MediumTest | Level1)
951 {
952     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_2300 is called");
953     std::map<std::string, std::string> paras;
954     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
955     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
956     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
957     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
958 
959     Want want;
960     for (auto para : paras) {
961         want.SetParam(para.first, para.second);
962     }
963 
964     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
965     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
966         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
967         std::make_shared<AbilityDelegatorArgs>(want),
968         true);
969     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
970     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
971     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
972     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
973     abilityDelegator.PostPerformScenceCreated(nullptr);
974 
975     EXPECT_FALSE(mockMonitor->windowStageCreate_);
976 }
977 
978 /**
979  * @tc.number: Ability_Delegator_Test_2400
980  * @tc.name: PostPerformScenceCreated
981  * @tc.desc: Verify the PostPerformScenceCreated is valid.
982  */
983 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2400, Function | MediumTest | Level1)
984 {
985     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_2400 is called");
986     std::map<std::string, std::string> paras;
987     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
988     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
989     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
990     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
991 
992     Want want;
993     for (auto para : paras) {
994         want.SetParam(para.first, para.second);
995     }
996 
997     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
998     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
999         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1000         std::make_shared<AbilityDelegatorArgs>(want),
1001         true);
1002     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
1003     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1004     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
1005     abilityDelegator.abilityMonitors_.clear();
1006     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
1007     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
1008     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
1009     ability->token_ = token;
1010     ability->name_ = ABILITY_NAME;
1011     ability->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
1012     ability->object_ = std::shared_ptr<NativeReference>();
1013     abilityDelegator.PostPerformScenceCreated(ability);
1014 
1015     EXPECT_TRUE(mockMonitor->windowStageCreate_);
1016 }
1017 
1018 /**
1019  * @tc.number: Ability_Delegator_Test_2500
1020  * @tc.name: PostPerformScenceRestored
1021  * @tc.desc: Verify the PostPerformScenceRestored is invalid.
1022  */
1023 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2500, Function | MediumTest | Level1)
1024 {
1025     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_2500 is called");
1026     std::map<std::string, std::string> paras;
1027     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1028     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1029     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1030     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1031 
1032     Want want;
1033     for (auto para : paras) {
1034         want.SetParam(para.first, para.second);
1035     }
1036 
1037     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1038     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1039         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1040         std::make_shared<AbilityDelegatorArgs>(want),
1041         true);
1042     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
1043     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1044     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
1045     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
1046     abilityDelegator.PostPerformScenceRestored(nullptr);
1047 
1048     EXPECT_FALSE(mockMonitor->windowStageRestore_);
1049 }
1050 
1051 /**
1052  * @tc.number: Ability_Delegator_Test_2600
1053  * @tc.name: PostPerformScenceRestored
1054  * @tc.desc: Verify the PostPerformScenceRestored is valid.
1055  */
1056 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2600, Function | MediumTest | Level1)
1057 {
1058     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_2600 is called");
1059     std::map<std::string, std::string> paras;
1060     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1061     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1062     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1063     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1064 
1065     Want want;
1066     for (auto para : paras) {
1067         want.SetParam(para.first, para.second);
1068     }
1069 
1070     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1071     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1072         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1073         std::make_shared<AbilityDelegatorArgs>(want),
1074         true);
1075     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
1076     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1077     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
1078     abilityDelegator.abilityMonitors_.clear();
1079     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
1080     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
1081     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
1082     ability->token_ = token;
1083     ability->name_ = ABILITY_NAME;
1084     ability->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
1085     ability->object_ = std::shared_ptr<NativeReference>();
1086     abilityDelegator.PostPerformScenceRestored(ability);
1087 
1088     EXPECT_TRUE(mockMonitor->windowStageRestore_);
1089 }
1090 
1091 /**
1092  * @tc.number: Ability_Delegator_Test_2700
1093  * @tc.name: PostPerformScenceDestroyed
1094  * @tc.desc: Verify the PostPerformScenceDestroyed is invalid.
1095  */
1096 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2700, Function | MediumTest | Level1)
1097 {
1098     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_2700 is called");
1099     std::map<std::string, std::string> paras;
1100     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1101     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1102     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1103     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1104 
1105     Want want;
1106     for (auto para : paras) {
1107         want.SetParam(para.first, para.second);
1108     }
1109 
1110     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1111     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1112         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1113         std::make_shared<AbilityDelegatorArgs>(want),
1114         true);
1115     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
1116     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1117     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
1118     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
1119     abilityDelegator.PostPerformScenceDestroyed(nullptr);
1120 
1121     EXPECT_FALSE(mockMonitor->windowStageDestroy_);
1122 }
1123 
1124 /**
1125  * @tc.number: Ability_Delegator_Test_2800
1126  * @tc.name: PostPerformScenceDestroyed
1127  * @tc.desc: Verify the PostPerformScenceDestroyed is valid.
1128  */
1129 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2800, Function | MediumTest | Level1)
1130 {
1131     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_2800 is called");
1132     std::map<std::string, std::string> paras;
1133     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1134     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1135     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1136     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1137 
1138     Want want;
1139     for (auto para : paras) {
1140         want.SetParam(para.first, para.second);
1141     }
1142 
1143     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1144     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1145         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1146         std::make_shared<AbilityDelegatorArgs>(want),
1147         true);
1148     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
1149     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1150     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
1151     abilityDelegator.abilityMonitors_.clear();
1152     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
1153     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
1154     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
1155     ability->token_ = token;
1156     ability->name_ = ABILITY_NAME;
1157     ability->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
1158     ability->object_ = std::shared_ptr<NativeReference>();
1159     abilityDelegator.PostPerformScenceDestroyed(ability);
1160 
1161     EXPECT_TRUE(mockMonitor->windowStageDestroy_);
1162 }
1163 
1164 /**
1165  * @tc.number: Ability_Delegator_Test_2900
1166  * @tc.name: PostPerformForeground
1167  * @tc.desc: Verify the PostPerformForeground is invalid.
1168  */
1169 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2900, Function | MediumTest | Level1)
1170 {
1171     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_2900 is called");
1172     std::map<std::string, std::string> paras;
1173     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1174     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1175     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1176     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1177 
1178     Want want;
1179     for (auto para : paras) {
1180         want.SetParam(para.first, para.second);
1181     }
1182 
1183     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1184     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1185         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1186         std::make_shared<AbilityDelegatorArgs>(want),
1187         true);
1188     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
1189     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1190     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
1191     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
1192     abilityDelegator.PostPerformForeground(nullptr);
1193 
1194     EXPECT_FALSE(mockMonitor->foreground_);
1195 }
1196 
1197 /**
1198  * @tc.number: Ability_Delegator_Test_3000
1199  * @tc.name: PostPerformForeground
1200  * @tc.desc: Verify the PostPerformForeground is valid.
1201  */
1202 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3000, Function | MediumTest | Level1)
1203 {
1204     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_3000 is called");
1205     std::map<std::string, std::string> paras;
1206     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1207     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1208     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1209     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1210 
1211     Want want;
1212     for (auto para : paras) {
1213         want.SetParam(para.first, para.second);
1214     }
1215 
1216     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1217     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1218         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1219         std::make_shared<AbilityDelegatorArgs>(want),
1220         true);
1221     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
1222     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1223     abilityDelegator.abilityMonitors_.clear();
1224     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
1225     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
1226     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
1227     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
1228     ability->token_ = token;
1229     ability->name_ = ABILITY_NAME;
1230     ability->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
1231     ability->object_ = std::shared_ptr<NativeReference>();
1232     abilityDelegator.PostPerformForeground(ability);
1233 
1234     EXPECT_TRUE(mockMonitor->foreground_);
1235 }
1236 
1237 /**
1238  * @tc.number: Ability_Delegator_Test_3100
1239  * @tc.name: PostPerformBackground
1240  * @tc.desc: Verify the PostPerformBackground is invalid.
1241  */
1242 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3100, Function | MediumTest | Level1)
1243 {
1244     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_3100 is called");
1245     std::map<std::string, std::string> paras;
1246     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1247     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1248     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1249     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1250 
1251     Want want;
1252     for (auto para : paras) {
1253         want.SetParam(para.first, para.second);
1254     }
1255 
1256     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1257     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1258         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1259         std::make_shared<AbilityDelegatorArgs>(want),
1260         true);
1261     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
1262     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1263     abilityDelegator.abilityMonitors_.clear();
1264     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
1265     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
1266     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
1267     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
1268     ability->token_ = token;
1269     ability->name_ = ABILITY_NAME;
1270     ability->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
1271     abilityDelegator.PostPerformBackground(nullptr);
1272 
1273     EXPECT_FALSE(mockMonitor->background_);
1274 }
1275 
1276 /**
1277  * @tc.number: Ability_Delegator_Test_3200
1278  * @tc.name: PostPerformBackground
1279  * @tc.desc: Verify the PostPerformBackground is valid.
1280  */
1281 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3200, Function | MediumTest | Level1)
1282 {
1283     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_3200 is called");
1284     std::map<std::string, std::string> paras;
1285     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1286     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1287     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1288     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1289 
1290     Want want;
1291     for (auto para : paras) {
1292         want.SetParam(para.first, para.second);
1293     }
1294 
1295     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1296     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1297         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1298         std::make_shared<AbilityDelegatorArgs>(want),
1299         true);
1300     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
1301     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1302     abilityDelegator.abilityMonitors_.clear();
1303     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
1304     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
1305     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
1306     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
1307     ability->token_ = token;
1308     ability->name_ = ABILITY_NAME;
1309     ability->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
1310     ability->object_ = std::shared_ptr<NativeReference>();
1311     abilityDelegator.PostPerformBackground(ability);
1312 
1313     EXPECT_TRUE(mockMonitor->background_);
1314 }
1315 
1316 /**
1317  * @tc.number: Ability_Delegator_Test_3300
1318  * @tc.name: PostPerformStop
1319  * @tc.desc: Verify the PostPerformStop is invalid.
1320  */
1321 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3300, Function | MediumTest | Level1)
1322 {
1323     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_3300 is called");
1324     std::map<std::string, std::string> paras;
1325     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1326     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1327     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1328     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1329 
1330     Want want;
1331     for (auto para : paras) {
1332         want.SetParam(para.first, para.second);
1333     }
1334 
1335     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1336     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1337         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1338         std::make_shared<AbilityDelegatorArgs>(want),
1339         true);
1340     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
1341     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1342     abilityDelegator.abilityMonitors_.clear();
1343     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
1344     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
1345     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
1346     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
1347     ability->token_ = token;
1348     ability->name_ = ABILITY_NAME;
1349     ability->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
1350     abilityDelegator.PostPerformStop(nullptr);
1351 
1352     EXPECT_FALSE(mockMonitor->stop_);
1353 }
1354 
1355 /**
1356  * @tc.number: Ability_Delegator_Test_3400
1357  * @tc.name: PostPerformStop
1358  * @tc.desc: Verify the PostPerformStop is valid.
1359  */
1360 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3400, Function | MediumTest | Level1)
1361 {
1362     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_3400 is called");
1363     std::map<std::string, std::string> paras;
1364     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1365     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1366     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1367     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1368 
1369     Want want;
1370     for (auto para : paras) {
1371         want.SetParam(para.first, para.second);
1372     }
1373 
1374     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1375     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1376         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1377         std::make_shared<AbilityDelegatorArgs>(want),
1378         true);
1379     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub());
1380     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1381     abilityDelegator.abilityMonitors_.clear();
1382     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
1383     abilityDelegator.abilityMonitors_.emplace_back(mockMonitor);
1384     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
1385     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
1386     ability->token_ = token;
1387     ability->name_ = ABILITY_NAME;
1388     ability->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
1389     ability->object_ = std::shared_ptr<NativeReference>();
1390     abilityDelegator.PostPerformStop(ability);
1391 
1392     EXPECT_TRUE(mockMonitor->stop_);
1393 }
1394 
1395 /**
1396  * @tc.number: Ability_Delegator_Test_3500
1397  * @tc.name: FinishUserTest
1398  * @tc.desc: Verify the FinishUserTest is valid.
1399  */
1400 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3500, Function | MediumTest | Level1)
1401 {
1402     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_3500 is called");
1403     MockAbilityDelegatorStub::finishFlag_ = false;
1404     std::map<std::string, std::string> paras;
1405     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1406     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1407     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1408     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1409 
1410     Want want;
1411     for (auto para : paras) {
1412         want.SetParam(para.first, para.second);
1413     }
1414 
1415     std::shared_ptr<AbilityDelegatorArgs> abilityArgs = std::make_shared<AbilityDelegatorArgs>(want);
1416 
1417     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1418     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1419         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1420         abilityArgs,
1421         true);
1422     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
1423     std::shared_ptr<AbilityDelegator> abilityDelegator =
1424         std::make_shared<AbilityDelegator>(context, std::move(testRunner), iRemoteObj);
1425     AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs);
1426 
1427     abilityDelegator->abilityMonitors_.clear();
1428     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
1429     abilityDelegator->abilityMonitors_.emplace_back(mockMonitor);
1430     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
1431     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
1432     ability->token_ = token;
1433     ability->name_ = ABILITY_NAME;
1434     ability->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
1435     abilityDelegator->FinishUserTest(FINISH_MSG, FINISH_RESULT_CODE);
1436 
1437     EXPECT_TRUE(MockAbilityDelegatorStub::finishFlag_);
1438 }
1439 
1440 /**
1441  * @tc.number: Ability_Delegator_Test_3600
1442  * @tc.name: FinishUserTest
1443  * @tc.desc: Verify the FinishUserTest is invalid.
1444  */
1445 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3600, Function | MediumTest | Level1)
1446 {
1447     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_3600 is called");
1448     MockAbilityDelegatorStub2::finishFlag_ = false;
1449     std::map<std::string, std::string> paras;
1450     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1451     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1452     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1453     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1454 
1455     Want want;
1456     for (auto para : paras) {
1457         want.SetParam(para.first, para.second);
1458     }
1459 
1460     std::shared_ptr<AbilityDelegatorArgs> abilityArgs = std::make_shared<AbilityDelegatorArgs>(want);
1461 
1462     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1463     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1464         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1465         abilityArgs,
1466         true);
1467     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new MockAbilityDelegatorStub2);
1468     std::shared_ptr<AbilityDelegator> abilityDelegator =
1469         std::make_shared<AbilityDelegator>(context, std::move(testRunner), iRemoteObj);
1470     AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs);
1471 
1472     abilityDelegator->abilityMonitors_.clear();
1473     std::shared_ptr<MockIabilityMonitor> mockMonitor = std::make_shared<MockIabilityMonitor>(ABILITY_NAME);
1474     abilityDelegator->abilityMonitors_.emplace_back(mockMonitor);
1475     sptr<IRemoteObject> token = sptr<IRemoteObject>(new MockAbilityDelegatorStub2);
1476     std::shared_ptr<ADelegatorAbilityProperty> ability = std::make_shared<ADelegatorAbilityProperty>();
1477     ability->token_ = token;
1478     ability->name_ = ABILITY_NAME;
1479     ability->lifecycleState_ = AbilityLifecycleExecutor::LifecycleState::STARTED_NEW;
1480     abilityDelegator->FinishUserTest(FINISH_MSG, FINISH_RESULT_CODE);
1481 
1482     EXPECT_FALSE(MockAbilityDelegatorStub2::finishFlag_);
1483 }
1484 
1485 
1486 /**
1487  * @tc.number: Ability_Delegator_Test_3700
1488  * @tc.name: ConvertAbilityState
1489  * @tc.desc: Verify the ConvertAbilityState and result is STARTED.
1490  */
1491 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3700, Function | MediumTest | Level1)
1492 {
1493     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_3700 is called");
1494     std::map<std::string, std::string> paras;
1495     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1496     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1497     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1498     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1499 
1500     Want want;
1501     for (auto para : paras) {
1502         want.SetParam(para.first, para.second);
1503     }
1504 
1505     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1506     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1507         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1508         std::make_shared<AbilityDelegatorArgs>(want),
1509         true);
1510     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new AAFwk::MockTestObserverStub);
1511     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1512 
1513     EXPECT_EQ((int)(abilityDelegator.ConvertAbilityState(AbilityLifecycleExecutor::LifecycleState::STARTED_NEW)),
1514         (int)(AbilityDelegator::AbilityState::STARTED));
1515 }
1516 
1517 /**
1518  * @tc.number: Ability_Delegator_Test_3800
1519  * @tc.name: ConvertAbilityState
1520  * @tc.desc: Verify the ConvertAbilityState and result is FOREGROUND.
1521  */
1522 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3800, Function | MediumTest | Level1)
1523 {
1524     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_3800 is called");
1525     std::map<std::string, std::string> paras;
1526     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1527     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1528     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1529     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1530 
1531     Want want;
1532     for (auto para : paras) {
1533         want.SetParam(para.first, para.second);
1534     }
1535 
1536     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1537     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1538         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1539         std::make_shared<AbilityDelegatorArgs>(want),
1540         true);
1541     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new AAFwk::MockTestObserverStub);
1542     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1543 
1544     EXPECT_EQ((int)(abilityDelegator.ConvertAbilityState(AbilityLifecycleExecutor::LifecycleState::FOREGROUND_NEW)),
1545         (int)(AbilityDelegator::AbilityState::FOREGROUND));
1546 }
1547 
1548 /**
1549  * @tc.number: Ability_Delegator_Test_3900
1550  * @tc.name: ConvertAbilityState
1551  * @tc.desc: Verify the ConvertAbilityState and result is BACKGROUND.
1552  */
1553 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3900, Function | MediumTest | Level1)
1554 {
1555     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_3900 is called");
1556     std::map<std::string, std::string> paras;
1557     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1558     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1559     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1560     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1561 
1562     Want want;
1563     for (auto para : paras) {
1564         want.SetParam(para.first, para.second);
1565     }
1566 
1567     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1568     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1569         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1570         std::make_shared<AbilityDelegatorArgs>(want),
1571         true);
1572     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new AAFwk::MockTestObserverStub);
1573     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1574 
1575     EXPECT_EQ((int)(abilityDelegator.ConvertAbilityState(AbilityLifecycleExecutor::LifecycleState::BACKGROUND_NEW)),
1576         (int)(AbilityDelegator::AbilityState::BACKGROUND));
1577 }
1578 
1579 /**
1580  * @tc.number: Ability_Delegator_Test_4000
1581  * @tc.name: ConvertAbilityState
1582  * @tc.desc: Verify the ConvertAbilityState and result is STOPED.
1583  */
1584 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_4000, Function | MediumTest | Level1)
1585 {
1586     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_4000 is called");
1587     std::map<std::string, std::string> paras;
1588     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1589     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1590     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1591     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1592 
1593     Want want;
1594     for (auto para : paras) {
1595         want.SetParam(para.first, para.second);
1596     }
1597 
1598     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1599     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1600         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1601         std::make_shared<AbilityDelegatorArgs>(want),
1602         true);
1603     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new AAFwk::MockTestObserverStub);
1604     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1605 
1606     EXPECT_EQ((int)(abilityDelegator.ConvertAbilityState(AbilityLifecycleExecutor::LifecycleState::STOPED_NEW)),
1607         (int)(AbilityDelegator::AbilityState::STOPPED));
1608 }
1609 
1610 /**
1611  * @tc.number: Ability_Delegator_Test_4100
1612  * @tc.name: ConvertAbilityState
1613  * @tc.desc: Verify the ConvertAbilityState and result is UNINITIALIZED.
1614  */
1615 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_4100, Function | MediumTest | Level1)
1616 {
1617     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_4100 is called");
1618     std::map<std::string, std::string> paras;
1619     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1620     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1621     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1622     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1623 
1624     Want want;
1625     for (auto para : paras) {
1626         want.SetParam(para.first, para.second);
1627     }
1628 
1629     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1630     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1631         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1632         std::make_shared<AbilityDelegatorArgs>(want),
1633         true);
1634     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new AAFwk::MockTestObserverStub);
1635     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1636 
1637     EXPECT_EQ((int)(abilityDelegator.ConvertAbilityState(AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED)),
1638         (int)(AbilityDelegator::AbilityState::UNINITIALIZED));
1639 }
1640 
1641 /**
1642  * @tc.number: Ability_Delegator_Test_4200
1643  * @tc.name: Prepare
1644  * @tc.desc: Verify the Prepare is invalid.
1645  */
1646 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_4200, Function | MediumTest | Level1)
1647 {
1648     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_4200 is called");
1649     MockTestRunner::prepareFlag_ = false;
1650     std::map<std::string, std::string> paras;
1651     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1652     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1653     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1654     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1655 
1656     Want want;
1657     for (auto para : paras) {
1658         want.SetParam(para.first, para.second);
1659     }
1660 
1661     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1662     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1663         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1664         std::make_shared<AbilityDelegatorArgs>(want),
1665         true);
1666     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new AAFwk::MockTestObserverStub);
1667     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1668     abilityDelegator.testRunner_ = nullptr;
1669     abilityDelegator.Prepare();
1670 
1671     EXPECT_FALSE(MockTestRunner::prepareFlag_);
1672 }
1673 
1674 /**
1675  * @tc.number: Ability_Delegator_Test_4300
1676  * @tc.name: Prepare
1677  * @tc.desc: Verify the Prepare is valid.
1678  */
1679 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_4300, Function | MediumTest | Level1)
1680 {
1681     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_4300 is called");
1682     MockTestRunner::prepareFlag_ = false;
1683     std::map<std::string, std::string> paras;
1684     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1685     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1686     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1687     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1688 
1689     Want want;
1690     for (auto para : paras) {
1691         want.SetParam(para.first, para.second);
1692     }
1693 
1694     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1695     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1696         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1697         std::make_shared<AbilityDelegatorArgs>(want),
1698         true);
1699     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new AAFwk::MockTestObserverStub);
1700     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1701     std::unique_ptr<TestRunner> tptr{ new MockTestRunner };
1702     abilityDelegator.testRunner_ = std::move(tptr);
1703     abilityDelegator.Prepare();
1704 
1705     EXPECT_TRUE(MockTestRunner::prepareFlag_);
1706 }
1707 
1708 /**
1709  * @tc.number: Ability_Delegator_Test_4400
1710  * @tc.name: OnRun
1711  * @tc.desc: Verify the OnRun is invalid.
1712  */
1713 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_4400, Function | MediumTest | Level1)
1714 {
1715     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_4400 is called");
1716     MockTestRunner::runFlag_ = false;
1717     std::map<std::string, std::string> paras;
1718     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1719     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1720     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1721     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1722 
1723     Want want;
1724     for (auto para : paras) {
1725         want.SetParam(para.first, para.second);
1726     }
1727 
1728     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1729     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1730         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1731         std::make_shared<AbilityDelegatorArgs>(want),
1732         true);
1733     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new AAFwk::MockTestObserverStub);
1734     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1735     abilityDelegator.testRunner_ = nullptr;
1736     abilityDelegator.OnRun();
1737 
1738     EXPECT_FALSE(MockTestRunner::runFlag_);
1739 }
1740 
1741 /**
1742  * @tc.number: Ability_Delegator_Test_4500
1743  * @tc.name: OnRun
1744  * @tc.desc: Verify the OnRun is valid.
1745  */
1746 HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_4500, Function | MediumTest | Level1)
1747 {
1748     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Test_4500 is called");
1749     MockTestRunner::runFlag_ = false;
1750     std::map<std::string, std::string> paras;
1751     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
1752     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
1753     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
1754     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
1755 
1756     Want want;
1757     for (auto para : paras) {
1758         want.SetParam(para.first, para.second);
1759     }
1760 
1761     std::shared_ptr<OHOS::AbilityRuntime::Context> context = std::make_shared<OHOS::AbilityRuntime::ContextImpl>();
1762     std::unique_ptr<TestRunner> testRunner = TestRunner::Create(
1763         std::shared_ptr<OHOSApplication>(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(),
1764         std::make_shared<AbilityDelegatorArgs>(want),
1765         true);
1766     sptr<IRemoteObject> iRemoteObj = sptr<IRemoteObject>(new AAFwk::MockTestObserverStub);
1767     AbilityDelegator abilityDelegator(context, std::move(testRunner), iRemoteObj);
1768     std::unique_ptr<TestRunner> tptr{ new MockTestRunner };
1769     abilityDelegator.testRunner_ = std::move(tptr);
1770     abilityDelegator.OnRun();
1771 
1772     EXPECT_TRUE(MockTestRunner::runFlag_);
1773 }
1774 
1775 /**
1776  * @tc.name: RegisterClearFuncTest_0100
1777  * @tc.desc: Register clear function test.
1778  * @tc.type: FUNC
1779  * @tc.require: issueI76SHL
1780  */
1781 HWTEST_F(AbilityDelegatorTest, RegisterClearFuncTest_0100, TestSize.Level1)
1782 {
1783     TAG_LOGI(AAFwkTag::TEST, "test start.");
1784     ASSERT_NE(commonDelegator_, nullptr);
1785 
1786     // Register clear function.
__anon53ebaf800202(const std::shared_ptr<ADelegatorAbilityProperty> &property) 1787     auto clearFunc = [](const std::shared_ptr<ADelegatorAbilityProperty> &property) {
1788         TAG_LOGI(AAFwkTag::TEST, "Clear function is called");
1789     };
1790     commonDelegator_->RegisterClearFunc(clearFunc);
1791 
1792     // Add ability monitor, so CallClearFunc can be called by PostPerformStop
1793     auto iMonitor = std::make_shared<IAbilityMonitor>(ABILITY_NAME);
1794     commonDelegator_->AddAbilityMonitor(iMonitor);
1795     auto abilityProperty = std::make_shared<ADelegatorAbilityProperty>();
1796     commonDelegator_->PostPerformStop(abilityProperty);
1797 }
1798 
1799 /**
1800  * @tc.name: FindPropertyByNameTest_0100
1801  * @tc.desc: Find property by name function test.
1802  * @tc.type: FUNC
1803  * @tc.require: issueI76SHL
1804  */
1805 HWTEST_F(AbilityDelegatorTest, FindPropertyByNameTest_0100, TestSize.Level1)
1806 {
1807     TAG_LOGI(AAFwkTag::TEST, "test start.");
1808     ASSERT_NE(commonDelegator_, nullptr);
1809 
1810     auto result = commonDelegator_->FindPropertyByName("");
1811     EXPECT_EQ(result, nullptr);
1812 
1813     auto token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
1814     auto abilityProperty = std::make_shared<ADelegatorAbilityProperty>();
1815     abilityProperty->token_ = token;
1816     abilityProperty->name_ = ABILITY_NAME;
1817     abilityProperty->fullName_ = ABILITY_NAME;
1818     commonDelegator_->ProcessAbilityProperties(abilityProperty);
1819     EXPECT_EQ(commonDelegator_->abilityProperties_.size(), 1);
1820 
1821     result = commonDelegator_->FindPropertyByName(ABILITY_NAME);
1822     EXPECT_EQ(result, abilityProperty);
1823 }
1824 
1825 /**
1826  * @tc.name: InputParamTest_0100
1827  * @tc.desc: Input param test.
1828  * @tc.type: FUNC
1829  * @tc.require: issueI76SHL
1830  */
1831 HWTEST_F(AbilityDelegatorTest, InputParamTest_0100, TestSize.Level1)
1832 {
1833     TAG_LOGI(AAFwkTag::TEST, "test start.");
1834     ASSERT_NE(commonDelegator_, nullptr);
1835 
1836     // Process ability properties when ability is invalid.
1837     commonDelegator_->ProcessAbilityProperties(nullptr);
1838 
1839     // Remove ability property when ability is invalid.
1840     commonDelegator_->RemoveAbilityProperty(nullptr);
1841 
1842     // Find property by invalid token.
1843     commonDelegator_->FindPropertyByToken(nullptr);
1844 
1845     // Finish user test when observer is invalid.
1846     AbilityRuntime::Runtime::Options options;
1847     AAFwk::Want want;
1848     auto testRunner = TestRunner::Create(AbilityRuntime::Runtime::Create(options),
1849         std::make_shared<AbilityDelegatorArgs>(want), true);
1850     auto delegator = std::make_shared<AbilityDelegator>(std::make_shared<AbilityRuntime::ContextImpl>(),
1851         std::move(testRunner), nullptr);
1852     std::string msg("");
1853     int64_t resultCode = 0;
1854     delegator->FinishUserTest(msg, resultCode);
1855 }
1856 
1857 /**
1858  * @tc.name: AbilityMonitorEmptyTest_0100
1859  * @tc.desc: Perform when ability monitor is empty.
1860  * @tc.type: FUNC
1861  * @tc.require: issueI76SHL
1862  */
1863 HWTEST_F(AbilityDelegatorTest, AbilityMonitorEmptyTest_0100, TestSize.Level1)
1864 {
1865     TAG_LOGI(AAFwkTag::TEST, "test start.");
1866     ASSERT_NE(commonDelegator_, nullptr);
1867 
1868     auto token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
1869     auto abilityProperty = std::make_shared<ADelegatorAbilityProperty>();
1870     abilityProperty->token_ = token;
1871     abilityProperty->name_ = ABILITY_NAME;
1872     abilityProperty->fullName_ = ABILITY_NAME;
1873     commonDelegator_->PostPerformStart(abilityProperty);
1874     commonDelegator_->PostPerformScenceCreated(abilityProperty);
1875     commonDelegator_->PostPerformScenceRestored(abilityProperty);
1876     commonDelegator_->PostPerformScenceDestroyed(abilityProperty);
1877     commonDelegator_->PostPerformForeground(abilityProperty);
1878     commonDelegator_->PostPerformBackground(abilityProperty);
1879     commonDelegator_->PostPerformStop(abilityProperty);
1880 }
1881 
1882 /**
1883  * @tc.name: GetThreadNameTest_0100
1884  * @tc.desc: Get thread name test.
1885  * @tc.type: FUNC
1886  * @tc.require: issueI76SHL
1887  */
1888 HWTEST_F(AbilityDelegatorTest, GetThreadNameTest_0100, TestSize.Level1)
1889 {
1890     TAG_LOGI(AAFwkTag::TEST, "test start.");
1891     ASSERT_NE(commonDelegator_, nullptr);
1892     auto result = commonDelegator_->GetThreadName();
1893     EXPECT_EQ(result, "");
1894 }
1895 
1896 /**
1897  * @tc.name: StartAbilityTest_0100
1898  * @tc.desc: Get thread name test.
1899  * @tc.type: FUNC
1900  * @tc.require: issueI76SHL
1901  */
1902 HWTEST_F(AbilityDelegatorTest, StartAbilityTest_0100, TestSize.Level1)
1903 {
1904     TAG_LOGI(AAFwkTag::TEST, "test start.");
1905     ASSERT_NE(commonDelegator_, nullptr);
1906     AbilityDelegatorRegistry::RegisterInstance(commonDelegator_, delegatorArgs_);
1907 
1908     AAFwk::Want want;
1909     want.SetElementName(VALUE_TEST_BUNDLE_NAME, ABILITY_NAME);
1910     auto result = commonDelegator_->StartAbility(want);
1911     EXPECT_EQ(result, ERR_OK);
1912 }
1913 
1914 /**
1915  * @tc.name: WaitAbilityMonitorTest_0100
1916  * @tc.desc: Wait ability monitor test.
1917  * @tc.type: FUNC
1918  * @tc.require: issueI76SHL
1919  */
1920 HWTEST_F(AbilityDelegatorTest, WaitAbilityMonitorTest_0100, TestSize.Level1)
1921 {
1922     TAG_LOGI(AAFwkTag::TEST, "test start.");
1923     ASSERT_NE(commonDelegator_, nullptr);
1924     auto property = commonDelegator_->WaitAbilityMonitor(nullptr);
1925     EXPECT_EQ(property, nullptr);
1926 }
1927 
1928 /**
1929  * @tc.name: WaitAbilityMonitorTest_0200
1930  * @tc.desc: Wait ability monitor test.
1931  * @tc.type: FUNC
1932  * @tc.require: issueI76SHL
1933  */
1934 std::shared_ptr<IAbilityMonitor> gt_iAbilityMonitor = nullptr;
1935 
IAbilityMonitorWaitTask()1936 void IAbilityMonitorWaitTask()
1937 {
1938     ASSERT_NE(gt_iAbilityMonitor, nullptr);
1939     TAG_LOGI(AAFwkTag::TEST, "Running in thread %{public}d", gettid());
1940     auto property = AbilityDelegatorTest::commonDelegator_->WaitAbilityMonitor(gt_iAbilityMonitor);
1941     if (property == nullptr) {
1942         TAG_LOGW(AAFwkTag::TEST, "Wait for ability failed.");
1943     }
1944 }
1945 
IAbilityMonitorMatchTask()1946 void IAbilityMonitorMatchTask()
1947 {
1948     ASSERT_NE(gt_iAbilityMonitor, nullptr);
1949     TAG_LOGI(AAFwkTag::TEST, "Running in thread %{public}d", gettid());
1950     auto token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
1951     std::shared_ptr<ADelegatorAbilityProperty> proterty = std::make_shared<ADelegatorAbilityProperty>();
1952     proterty->token_ = token;
1953     proterty->name_ = ABILITY_NAME;
1954     EXPECT_TRUE(gt_iAbilityMonitor->Match(proterty, true));
1955 }
1956 
1957 HWTEST_F(AbilityDelegatorTest, WaitAbilityMonitorTest_0200, TestSize.Level1)
1958 {
1959     TAG_LOGI(AAFwkTag::TEST, "test start.");
1960     ASSERT_NE(commonDelegator_, nullptr);
1961 
1962     gt_iAbilityMonitor = std::make_shared<IAbilityMonitor>(ABILITY_NAME);
1963     commonDelegator_->AddAbilityMonitor(gt_iAbilityMonitor);
1964     SET_THREAD_NUM(1);
1965     GTEST_RUN_TASK(IAbilityMonitorWaitTask);
1966     GTEST_RUN_TASK(IAbilityMonitorMatchTask);
1967     gt_iAbilityMonitor.reset();
1968 }
1969 
1970 /**
1971  * @tc.name: WaitAbilityStageMonitorTest_0100
1972  * @tc.desc: Wait ability stage monitor test.
1973  * @tc.type: FUNC
1974  * @tc.require: issueI76SHL
1975  */
1976 HWTEST_F(AbilityDelegatorTest, WaitAbilityStageMonitorTest_0100, TestSize.Level1)
1977 {
1978     TAG_LOGI(AAFwkTag::TEST, "test start.");
1979     ASSERT_NE(commonDelegator_, nullptr);
1980     auto property = commonDelegator_->WaitAbilityStageMonitor(nullptr);
1981     EXPECT_EQ(property, nullptr);
1982 }
1983 
1984 /**
1985  * @tc.name: WaitAbilityStageMonitorTest_0200
1986  * @tc.desc: Wait ability stage monitor test.
1987  * @tc.type: FUNC
1988  * @tc.require: issueI76SHL
1989  */
1990 std::shared_ptr<IAbilityStageMonitor> gt_iAbilityStageMonitor = nullptr;
1991 
IAbilityStageMonitorWaitTask()1992 void IAbilityStageMonitorWaitTask()
1993 {
1994     ASSERT_NE(gt_iAbilityStageMonitor, nullptr);
1995     TAG_LOGI(AAFwkTag::TEST, "Running in thread %{public}d", gettid());
1996     auto property = AbilityDelegatorTest::commonDelegator_->WaitAbilityStageMonitor(gt_iAbilityStageMonitor);
1997     if (property == nullptr) {
1998         TAG_LOGW(AAFwkTag::TEST, "Wait for ability failed.");
1999     }
2000 }
2001 
IAbilityStageMonitorMatchTask()2002 void IAbilityStageMonitorMatchTask()
2003 {
2004     ASSERT_NE(gt_iAbilityStageMonitor, nullptr);
2005     TAG_LOGI(AAFwkTag::TEST, "Running in thread %{public}d", gettid());
2006     std::shared_ptr<DelegatorAbilityStageProperty> property = std::make_shared<DelegatorAbilityStageProperty>();
2007     property->moduleName_ = ABILITY_STAGE_MONITOR_MODULE_NAME;
2008     property->srcEntrance_ = ABILITY_STAGE_MONITOR_SRC_ENTRANCE;
2009     EXPECT_TRUE(gt_iAbilityStageMonitor->Match(property, true));
2010 }
2011 
2012 HWTEST_F(AbilityDelegatorTest, WaitAbilityStageMonitorTest_0200, TestSize.Level1)
2013 {
2014     TAG_LOGI(AAFwkTag::TEST, "test start.");
2015     ASSERT_NE(commonDelegator_, nullptr);
2016 
2017     gt_iAbilityStageMonitor = std::make_shared<IAbilityStageMonitor>(ABILITY_STAGE_MONITOR_MODULE_NAME,
2018         ABILITY_STAGE_MONITOR_SRC_ENTRANCE);
2019     commonDelegator_->AddAbilityStageMonitor(gt_iAbilityStageMonitor);
2020     SET_THREAD_NUM(1);
2021     GTEST_RUN_TASK(IAbilityStageMonitorWaitTask);
2022     GTEST_RUN_TASK(IAbilityStageMonitorMatchTask);
2023     gt_iAbilityStageMonitor.reset();
2024 }
2025 
2026 /**
2027  * @tc.name: PostPerformStageStartTest_0100
2028  * @tc.desc: Post perform stage start when ability stage monitor is empty.
2029  * @tc.type: FUNC
2030  * @tc.require: issueI76SHL
2031  */
2032 HWTEST_F(AbilityDelegatorTest, PostPerformStageStartTest_0100, TestSize.Level1)
2033 {
2034     TAG_LOGI(AAFwkTag::TEST, "test start.");
2035     ASSERT_NE(commonDelegator_, nullptr);
2036     auto property = std::make_shared<DelegatorAbilityStageProperty>();
2037     property->moduleName_ = ABILITY_STAGE_MONITOR_MODULE_NAME;
2038     property->srcEntrance_ = ABILITY_STAGE_MONITOR_SRC_ENTRANCE;
2039     commonDelegator_->PostPerformStageStart(property);
2040 }
2041 
2042 /**
2043  * @tc.name: PostPerformStageStartTest_0200
2044  * @tc.desc: Post perform stage start when ability stage monitor is valid.
2045  * @tc.type: FUNC
2046  * @tc.require: issueI76SHL
2047  */
2048 HWTEST_F(AbilityDelegatorTest, PostPerformStageStartTest_0200, TestSize.Level1)
2049 {
2050     TAG_LOGI(AAFwkTag::TEST, "test start.");
2051     ASSERT_NE(commonDelegator_, nullptr);
2052 
2053     auto stageMonitor = std::make_shared<IAbilityStageMonitor>(ABILITY_STAGE_MONITOR_MODULE_NAME,
2054         ABILITY_STAGE_MONITOR_SRC_ENTRANCE);
2055     commonDelegator_->AddAbilityStageMonitor(stageMonitor);
2056     auto property = std::make_shared<DelegatorAbilityStageProperty>();
2057     property->moduleName_ = ABILITY_STAGE_MONITOR_MODULE_NAME;
2058     property->srcEntrance_ = ABILITY_STAGE_MONITOR_SRC_ENTRANCE;
2059     commonDelegator_->PostPerformStageStart(property);
2060 }
2061 } // namespace AppExecFwk
2062 } // namespace OHOS
2063