1 /*
2 * Copyright (c) 2021 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
18 #include "ability.h"
19 #include "ability_local_record.h"
20 #include "ability_handler.h"
21 #include "ability_info.h"
22 #include "ability_start_setting.h"
23 #include "context_deal.h"
24 #include "mock_page_ability.h"
25 #include "abs_shared_result_set.h"
26 #include "data_ability_predicates.h"
27 #include "values_bucket.h"
28 #include "data_ability_operation.h"
29 #include "data_ability_result.h"
30
31 namespace OHOS {
32 namespace AppExecFwk {
33 using namespace testing::ext;
34 using namespace OHOS;
35 using namespace OHOS::AppExecFwk;
36 using OHOS::Parcel;
37
38 class AbilityBaseTest : public testing::Test {
39 public:
AbilityBaseTest()40 AbilityBaseTest() : ability_(nullptr)
41 {}
~AbilityBaseTest()42 ~AbilityBaseTest()
43 {}
44 std::shared_ptr<Ability> ability_;
45 static void SetUpTestCase(void);
46 static void TearDownTestCase(void);
47 void SetUp();
48 void TearDown();
49 };
50
SetUpTestCase(void)51 void AbilityBaseTest::SetUpTestCase(void)
52 {}
53
TearDownTestCase(void)54 void AbilityBaseTest::TearDownTestCase(void)
55 {}
56
SetUp(void)57 void AbilityBaseTest::SetUp(void)
58 {
59 ability_ = std::make_shared<Ability>();
60 }
61
TearDown(void)62 void AbilityBaseTest::TearDown(void)
63 {}
64
65 /**
66 * @tc.number: AaFwk_Ability_Name_0100
67 * @tc.name: GetAbilityName
68 * @tc.desc: Verify that the return value of getabilityname is correct.
69 */
70 HWTEST_F(AbilityBaseTest, AaFwk_Ability_Name_0100, Function | MediumTest | Level1)
71 {
72 GTEST_LOG_(INFO) << "AaFwk_Ability_Name_0100 start";
73 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
74 abilityInfo->name = "ability";
75 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
76 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
77 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
78 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
79 sptr<IRemoteObject> token = nullptr;
80
81 ability_->Init(abilityInfo, application, handler, token);
82 EXPECT_STREQ(abilityInfo->name.c_str(), ability_->GetAbilityName().c_str());
83
84 GTEST_LOG_(INFO) << "AaFwk_Ability_Name_0100 end";
85 }
86
87 /**
88 * @tc.number: AaFwk_Ability_GetLifecycle_0100
89 * @tc.name: GetLifecycle
90 * @tc.desc: Verify that the return value of getlifecycle is not empty.
91 */
92 HWTEST_F(AbilityBaseTest, AaFwk_Ability_GetLifecycle_0100, Function | MediumTest | Level1)
93 {
94 GTEST_LOG_(INFO) << "AaFwk_Ability_GetLifecycle_0100 start";
95
96 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
97 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
98 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
99 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
100 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
101 sptr<IRemoteObject> token = nullptr;
102
103 ability_->Init(abilityInfo, application, handler, token);
104 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
105
106 EXPECT_NE(lifeCycle, nullptr);
107
108 GTEST_LOG_(INFO) << "AaFwk_Ability_GetLifecycle_0100 end";
109 }
110
111 /**
112 * @tc.number: AaFwk_Ability_GetState_0100
113 * @tc.name: GetState
114 * @tc.desc: Verify that the return value of getstate is equal to active.
115 */
116 HWTEST_F(AbilityBaseTest, AaFwk_Ability_GetState_0100, Function | MediumTest | Level1)
117 {
118 GTEST_LOG_(INFO) << "AaFwk_Ability_GetState_0100 start";
119
120 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
121 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
122 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
123 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
124 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
125 sptr<IRemoteObject> token = nullptr;
126
127 ability_->Init(abilityInfo, application, handler, token);
128
129 ability_->OnActive();
130 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
131 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::ACTIVE, state);
132
133 GTEST_LOG_(INFO) << "AaFwk_Ability_GetState_0100 end";
134 }
135
136 /**
137 * @tc.number: AaFwk_Ability_GetState_0200
138 * @tc.name: GetState
139 * @tc.desc: Getstate exception test.
140 */
141 HWTEST_F(AbilityBaseTest, AaFwk_Ability_GetState_0200, Function | MediumTest | Level3)
142 {
143 GTEST_LOG_(INFO) << "AaFwk_Ability_GetState_0200 start";
144
145 ability_->OnActive();
146 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
147 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED, state);
148
149 GTEST_LOG_(INFO) << "AaFwk_Ability_GetState_0200 end";
150 }
151
152 /**
153 * @tc.number: AaFwk_Ability_Dump_0100
154 * @tc.name: Dump
155 * @tc.desc: Test dump normal flow.
156 */
157 HWTEST_F(AbilityBaseTest, AaFwk_Ability_Dump_0100, Function | MediumTest | Level1)
158 {
159 GTEST_LOG_(INFO) << "AaFwk_Ability_Dump_0100 start";
160
161 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
162 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
163 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
164 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
165 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
166 sptr<IRemoteObject> token = nullptr;
167
168 ability_->Init(abilityInfo, application, handler, token);
169
170 std::string extra = "";
171 ability_->Dump(extra);
172
173 GTEST_LOG_(INFO) << "AaFwk_Ability_Dump_0100 end";
174 }
175
176 /**
177 * @tc.number: AaFwk_Ability_OnNewWant_0100
178 * @tc.name: OnNewWant
179 * @tc.desc: Test whether onnewwant can be called normally.
180 */
181 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnNewWant_0100, Function | MediumTest | Level1)
182 {
183 GTEST_LOG_(INFO) << "AaFwk_Ability_OnNewWant_0100 start";
184
185 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
186 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
187 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
188 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
189 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
190 sptr<IRemoteObject> token = nullptr;
191
192 ability_->Init(abilityInfo, application, handler, token);
193
194 Want want;
195 ability_->OnNewWant(want);
196
197 GTEST_LOG_(INFO) << "AaFwk_Ability_OnNewWant_0100 end";
198 }
199
200 /**
201 * @tc.number: AaFwk_Ability_OnRestoreAbilityState_0100
202 * @tc.name: OnRestoreAbilityState
203 * @tc.desc: Test whether onnewwant can be called normally.
204 */
205 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnRestoreAbilityState_0100, Function | MediumTest | Level1)
206 {
207 GTEST_LOG_(INFO) << "AaFwk_Ability_OnRestoreAbilityState_0100 start";
208
209 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
210 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
211 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
212 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
213 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
214 sptr<IRemoteObject> token = nullptr;
215
216 ability_->Init(abilityInfo, application, handler, token);
217
218 PacMap inState;
219 ability_->OnRestoreAbilityState(inState);
220
221 GTEST_LOG_(INFO) << "AaFwk_Ability_OnRestoreAbilityState_0100 end";
222 }
223
224 /**
225 * @tc.number: AaFwk_Ability_GetAbilityName_0100
226 * @tc.name: GetAbilityName
227 * @tc.desc: Verify that the getabilityname return value is correct.
228 */
229 HWTEST_F(AbilityBaseTest, AaFwk_Ability_GetAbilityName_0100, Function | MediumTest | Level1)
230 {
231 GTEST_LOG_(INFO) << "AaFwk_Ability_GetAbilityName_0100 start";
232
233 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
234 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
235 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
236 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
237 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
238 sptr<IRemoteObject> token = nullptr;
239
240 std::string name = "LOL";
241 abilityInfo->name = name;
242 ability_->Init(abilityInfo, application, handler, token);
243
244 EXPECT_STREQ(ability_->GetAbilityName().c_str(), name.c_str());
245
246 GTEST_LOG_(INFO) << "AaFwk_Ability_GetAbilityName_0100 end";
247 }
248
249 /**
250 * @tc.number: AaFwk_Ability_GetApplication_0100
251 * @tc.name: GetApplication
252 * @tc.desc: Verify that the getapplication return value is correct.
253 */
254 HWTEST_F(AbilityBaseTest, AaFwk_Ability_GetApplication_0100, Function | MediumTest | Level1)
255 {
256 GTEST_LOG_(INFO) << "AaFwk_Ability_GetApplication_0100 start";
257
258 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
259 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
260 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
261 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
262 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
263 sptr<IRemoteObject> token = nullptr;
264
265 ability_->Init(abilityInfo, application, handler, token);
266 std::shared_ptr<OHOSApplication> applicationRet = ability_->GetApplication();
267 EXPECT_EQ(application, applicationRet);
268
269 GTEST_LOG_(INFO) << "AaFwk_Ability_GetApplication_0100 end";
270 }
271
272 /**
273 * @tc.number: AaFwk_Ability_GetApplication_0200
274 * @tc.name: GetApplication
275 * @tc.desc: Test getapplication exception status.
276 */
277 HWTEST_F(AbilityBaseTest, AaFwk_Ability_GetApplication_0200, Function | MediumTest | Level3)
278 {
279 GTEST_LOG_(INFO) << "AaFwk_Ability_GetApplication_0200 start";
280
281 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
282 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
283 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
284 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
285 sptr<IRemoteObject> token = nullptr;
286
287 ability_->Init(abilityInfo, nullptr, handler, token);
288 std::shared_ptr<OHOSApplication> application = ability_->GetApplication();
289 EXPECT_EQ(application, nullptr);
290
291 GTEST_LOG_(INFO) << "AaFwk_Ability_GetApplication_0200 end";
292 }
293
294 /**
295 * @tc.number: AaFwk_Ability_OnSaveAbilityState_0100
296 * @tc.name: OnSaveAbilityState
297 * @tc.desc: Test whether onsaveabilitystate is called normally.
298 */
299 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnSaveAbilityState_0100, Function | MediumTest | Level1)
300 {
301 GTEST_LOG_(INFO) << "AaFwk_Ability_OnSaveAbilityState_0100 start";
302
303 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
304 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
305 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
306 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
307 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
308 sptr<IRemoteObject> token = nullptr;
309
310 ability_->Init(abilityInfo, application, handler, token);
311
312 PacMap outState;
313 ability_->OnSaveAbilityState(outState);
314
315 GTEST_LOG_(INFO) << "AaFwk_Ability_OnSaveAbilityState_0100 end";
316 }
317
318 /**
319 * @tc.number: AaFwk_Ability_SetWant_GetWant_0100
320 * @tc.name: OnSaveAbilityState
321 * @tc.desc: Verify that setwant creates the object normally,
322 * and judge whether the return value of getwant is correct.
323 */
324 HWTEST_F(AbilityBaseTest, AaFwk_Ability_SetWant_GetWant_0100, Function | MediumTest | Level1)
325 {
326 GTEST_LOG_(INFO) << "AaFwk_Ability_SetWant_GetWant_0100 start";
327
328 std::string abilityName = "Ability";
329 std::string bundleName = "Bundle";
330 AAFwk::Want want;
331 want.SetElementName(bundleName, abilityName);
332 ability_->SetWant(want);
333
334 EXPECT_STREQ(ability_->GetWant()->GetElement().GetBundleName().c_str(), bundleName.c_str());
335 EXPECT_STREQ(ability_->GetWant()->GetElement().GetAbilityName().c_str(), abilityName.c_str());
336 GTEST_LOG_(INFO) << "AaFwk_Ability_SetWant_GetWant_0100 end";
337 }
338
339 /**
340 * @tc.number: AaFwk_Ability_SetResult_0100
341 * @tc.name: SetResult
342 * @tc.desc: Test whether setresult is called normally.
343 */
344 HWTEST_F(AbilityBaseTest, AaFwk_Ability_SetResult_0100, Function | MediumTest | Level1)
345 {
346 GTEST_LOG_(INFO) << "AaFwk_Ability_SetResult_0100 start";
347
348 int resultCode = 0;
349 Want want;
350 std::string action = "Action";
351 want.SetAction(action);
352
353 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
354 AbilityType type = AbilityType::PAGE;
355 abilityInfo->type = type;
356 std::shared_ptr<OHOSApplication> application = nullptr;
357 std::shared_ptr<AbilityHandler> handler = nullptr;
358 sptr<IRemoteObject> token = nullptr;
359 ability_->Init(abilityInfo, application, handler, token);
360 ability_->SetResult(resultCode, want);
361
362 GTEST_LOG_(INFO) << "AaFwk_Ability_SetResult_0100 end";
363 }
364
365 /**
366 * @tc.number: AaFwk_Ability_StartAbilityForResult_0100
367 * @tc.name: StartAbilityForResult
368 * @tc.desc: Test whether startabilityforesult is called normally.
369 */
370 HWTEST_F(AbilityBaseTest, AaFwk_Ability_StartAbilityForResult_0100, Function | MediumTest | Level1)
371 {
372 GTEST_LOG_(INFO) << "AaFwk_Ability_StartAbilityForResult_0100 start";
373
374 int resultCode = 0;
375 Want want;
376 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
377 AbilityType type = AbilityType::PAGE;
378 abilityInfo->type = type;
379 std::shared_ptr<OHOSApplication> application = nullptr;
380 std::shared_ptr<AbilityHandler> handler = nullptr;
381 sptr<IRemoteObject> token = nullptr;
382 ability_->Init(abilityInfo, application, handler, token);
383 ability_->StartAbilityForResult(want, resultCode);
384
385 GTEST_LOG_(INFO) << "AaFwk_Ability_StartAbilityForResult_0100 end";
386 }
387
388 /**
389 * @tc.number: AaFwk_Ability_StartAbility_0100
390 * @tc.name: StartAbility
391 * @tc.desc: Test whether startability is called normally.
392 */
393 HWTEST_F(AbilityBaseTest, AaFwk_Ability_StartAbility_0100, Function | MediumTest | Level1)
394 {
395 GTEST_LOG_(INFO) << "AaFwk_Ability_StartAbility_0100 start";
396
397 Want want;
398 ability_->StartAbility(want);
399
400 GTEST_LOG_(INFO) << "AaFwk_Ability_StartAbility_0100 end";
401 }
402
403 /**
404 * @tc.number: AaFwk_Ability_TerminateAbility_0100
405 * @tc.name: TerminateAbility
406 * @tc.desc: Test whether terminateability is called normally.
407 */
408 HWTEST_F(AbilityBaseTest, AaFwk_Ability_TerminateAbility_0100, Function | MediumTest | Level1)
409 {
410 GTEST_LOG_(INFO) << "AaFwk_Ability_TerminateAbility_0100 start";
411
412 ability_->TerminateAbility();
413
414 GTEST_LOG_(INFO) << "AaFwk_Ability_TerminateAbility_0100 end";
415 }
416
417 HWTEST_F(AbilityBaseTest, AaFwk_Ability_GetWindow_001, Function | MediumTest | Level1)
418 {
419 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
420 AbilityType type = AbilityType::PAGE;
421 abilityInfo->type = type;
422 std::shared_ptr<OHOSApplication> application = nullptr;
423 std::shared_ptr<AbilityHandler> handler = nullptr;
424 sptr<IRemoteObject> token = nullptr;
425 ability_->Init(abilityInfo, application, handler, token);
426 }
427
428 /**
429 * @tc.number: AaFwk_Ability_OnStart_0100
430 * @tc.name: OnStart
431 * @tc.desc: Test whether OnStart is called normally and verify whether the members are correct.
432 */
433 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnStart_0100, Function | MediumTest | Level1)
434 {
435 GTEST_LOG_(INFO) << "AaFwk_Ability_OnStart_0100 start";
436
437 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
438 AbilityType type = AbilityType::PAGE;
439 abilityInfo->type = type;
440 std::shared_ptr<OHOSApplication> application = nullptr;
441 std::shared_ptr<AbilityHandler> handler = nullptr;
442 sptr<IRemoteObject> token = nullptr;
443 ability_->Init(abilityInfo, application, handler, token);
444
445 Want want;
446 ability_->OnStart(want);
447
448 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
449 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
450 LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState();
451
452 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::INACTIVE, state);
453 EXPECT_EQ(LifeCycle::Event::ON_START, lifeCycleState);
454
455 GTEST_LOG_(INFO) << "AaFwk_Ability_OnStart_0100 end";
456 }
457
458 /**
459 * @tc.number: AaFwk_Ability_OnStart_0200
460 * @tc.name: OnStart
461 * @tc.desc: Test the OnStart exception.
462 */
463 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnStart_0200, Function | MediumTest | Level3)
464 {
465 GTEST_LOG_(INFO) << "AaFwk_Ability_OnStart_0200 start";
466
467 Want want;
468 ability_->OnStart(want);
469 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
470 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
471
472 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED, state);
473 EXPECT_EQ(nullptr, lifeCycle);
474
475 GTEST_LOG_(INFO) << "AaFwk_Ability_OnStart_0200 end";
476 }
477
478 /**
479 * @tc.number: AaFwk_Ability_OnStop_0100
480 * @tc.name: OnStop
481 * @tc.desc: Test whether onstop is called normally and verify whether the members are correct.
482 */
483 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnStop_0100, Function | MediumTest | Level1)
484 {
485 GTEST_LOG_(INFO) << "AaFwk_Ability_OnStop_0100 start";
486
487 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
488 AbilityType type = AbilityType::PAGE;
489 abilityInfo->type = type;
490 std::shared_ptr<OHOSApplication> application = nullptr;
491 std::shared_ptr<AbilityHandler> handler = nullptr;
492 sptr<IRemoteObject> token = nullptr;
493 ability_->Init(abilityInfo, application, handler, token);
494
495 ability_->OnStop();
496
497 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
498 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
499 LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState();
500
501 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::INITIAL, state);
502 EXPECT_EQ(LifeCycle::Event::ON_STOP, lifeCycleState);
503
504 GTEST_LOG_(INFO) << "AaFwk_Ability_OnStop_0100 end";
505 }
506
507 /**
508 * @tc.number: AaFwk_Ability_OnStop_0200
509 * @tc.name: OnStop
510 * @tc.desc: Test the OnStop exception.
511 */
512 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnStop_0200, Function | MediumTest | Level3)
513 {
514 GTEST_LOG_(INFO) << "AaFwk_Ability_OnStop_0200 start";
515
516 ability_->OnStop();
517
518 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
519 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
520
521 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED, state);
522 EXPECT_EQ(nullptr, lifeCycle);
523
524 GTEST_LOG_(INFO) << "AaFwk_Ability_OnStop_0200 end";
525 }
526
527 /**
528 * @tc.number: AaFwk_Ability_OnActive_0100
529 * @tc.name: OnActive
530 * @tc.desc: Test whether onactive is called normally and verify whether the member is correct.
531 */
532 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnActive_0100, Function | MediumTest | Level1)
533 {
534 GTEST_LOG_(INFO) << "AaFwk_Ability_OnActive_0100 start";
535
536 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
537 AbilityType type = AbilityType::PAGE;
538 abilityInfo->type = type;
539 std::shared_ptr<OHOSApplication> application = nullptr;
540 std::shared_ptr<AbilityHandler> handler = nullptr;
541 sptr<IRemoteObject> token = nullptr;
542 ability_->Init(abilityInfo, application, handler, token);
543
544 ability_->OnActive();
545
546 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
547 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
548 LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState();
549
550 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::ACTIVE, state);
551 EXPECT_EQ(LifeCycle::Event::ON_ACTIVE, lifeCycleState);
552
553 GTEST_LOG_(INFO) << "AaFwk_Ability_OnActive_0100 end";
554 }
555
556 /**
557 * @tc.number: AaFwk_Ability_OnActive_0200
558 * @tc.name: OnActive
559 * @tc.desc: Test the OnActive exception.
560 */
561 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnActive_0200, Function | MediumTest | Level3)
562 {
563 GTEST_LOG_(INFO) << "AaFwk_Ability_OnActive_0200 start";
564
565 ability_->OnActive();
566
567 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
568 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
569
570 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED, state);
571 EXPECT_EQ(nullptr, lifeCycle);
572
573 GTEST_LOG_(INFO) << "AaFwk_Ability_OnActive_0200 end";
574 }
575
576 /**
577 * @tc.number: AaFwk_Ability_OnInactive_0100
578 * @tc.name: OnInactive
579 * @tc.desc: Test whether oninactive is called normally and verify whether the member is correct.
580 */
581 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnInactive_0100, Function | MediumTest | Level1)
582 {
583 GTEST_LOG_(INFO) << "AaFwk_Ability_OnInactive_0100 start";
584
585 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
586 AbilityType type = AbilityType::PAGE;
587 abilityInfo->type = type;
588 std::shared_ptr<OHOSApplication> application = nullptr;
589 std::shared_ptr<AbilityHandler> handler = nullptr;
590 sptr<IRemoteObject> token = nullptr;
591 ability_->Init(abilityInfo, application, handler, token);
592
593 ability_->OnInactive();
594
595 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
596 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
597 LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState();
598
599 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::INACTIVE, state);
600 EXPECT_EQ(LifeCycle::Event::ON_INACTIVE, lifeCycleState);
601
602 GTEST_LOG_(INFO) << "AaFwk_Ability_OnInactive_0100 end";
603 }
604
605 /**
606 * @tc.number: AaFwk_Ability_OnInactive_0200
607 * @tc.name: OnInactive
608 * @tc.desc: Test the OnInactive exception.
609 */
610 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnInactive_0200, Function | MediumTest | Level3)
611 {
612 GTEST_LOG_(INFO) << "AaFwk_Ability_OnInactive_0200 start";
613
614 ability_->OnInactive();
615
616 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
617 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
618
619 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED, state);
620 EXPECT_EQ(nullptr, lifeCycle);
621
622 GTEST_LOG_(INFO) << "AaFwk_Ability_OnInactive_0200 end";
623 }
624
625 /**
626 * @tc.number: AaFwk_Ability_OnForeground_0100
627 * @tc.name: OnForeground
628 * @tc.desc: Test whether onforegroup is called normally, and verify whether the member is correct.
629 */
630 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnForeground_0100, Function | MediumTest | Level1)
631 {
632 GTEST_LOG_(INFO) << "AaFwk_Ability_OnForeground_0100 start";
633
634 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
635 AbilityType type = AbilityType::PAGE;
636 abilityInfo->type = type;
637 std::shared_ptr<OHOSApplication> application = nullptr;
638 std::shared_ptr<AbilityHandler> handler = nullptr;
639 sptr<IRemoteObject> token = nullptr;
640 ability_->Init(abilityInfo, application, handler, token);
641
642 Want want;
643 ability_->OnForeground(want);
644
645 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
646 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
647 LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState();
648
649 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::INACTIVE, state);
650 EXPECT_EQ(LifeCycle::Event::ON_FOREGROUND, lifeCycleState);
651
652 GTEST_LOG_(INFO) << "AaFwk_Ability_OnForeground_0100 end";
653 }
654
655 /**
656 * @tc.number: AaFwk_Ability_OnForeground_0200
657 * @tc.name: OnForeground
658 * @tc.desc: Test the OnInactive exception.
659 */
660 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnForeground_0200, Function | MediumTest | Level3)
661 {
662 GTEST_LOG_(INFO) << "AaFwk_Ability_OnForeground_0200 start";
663
664 Want want;
665 ability_->OnForeground(want);
666
667 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
668 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
669
670 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED, state);
671 EXPECT_EQ(nullptr, lifeCycle);
672
673 GTEST_LOG_(INFO) << "AaFwk_Ability_OnForeground_0200 end";
674 }
675
676 /**
677 * @tc.number: AaFwk_Ability_OnForeground_0300
678 * @tc.name: OnForeground
679 * @tc.desc: Test the OnForeground exception.
680 */
681 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnForeground_0300, Function | MediumTest | Level3)
682 {
683 GTEST_LOG_(INFO) << "AaFwk_Ability_OnForeground_0300 start";
684
685 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
686 AbilityType type = AbilityType::PAGE;
687 abilityInfo->type = type;
688 abilityInfo->isStageBasedModel = true;
689 std::shared_ptr<OHOSApplication> application = nullptr;
690 std::shared_ptr<AbilityHandler> handler = nullptr;
691 sptr<IRemoteObject> token = nullptr;
692 ability_->Init(abilityInfo, application, handler, token);
693 Want want;
694 ability_->OnForeground(want);
695
696 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
697 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
698 LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState();
699
700 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::FOREGROUND_NEW, state);
701 EXPECT_EQ(LifeCycle::Event::ON_FOREGROUND, lifeCycleState);
702
703 GTEST_LOG_(INFO) << "AaFwk_Ability_OnForeground_0300 end";
704 }
705
706
707 /**
708 * @tc.number: AaFwk_Ability_OnBackground_0100
709 * @tc.name: OnBackground
710 * @tc.desc: Test whether onbackground is called normally and verify whether the members are correct.
711 */
712 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnBackground_0100, Function | MediumTest | Level1)
713 {
714 GTEST_LOG_(INFO) << "AaFwk_Ability_OnBackground_0100 start";
715
716 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
717 AbilityType type = AbilityType::PAGE;
718 abilityInfo->type = type;
719 std::shared_ptr<OHOSApplication> application = nullptr;
720 std::shared_ptr<AbilityHandler> handler = nullptr;
721 sptr<IRemoteObject> token = nullptr;
722 ability_->Init(abilityInfo, application, handler, token);
723
724 ability_->OnBackground();
725
726 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
727 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
728 LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState();
729
730 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::BACKGROUND, state);
731 EXPECT_EQ(LifeCycle::Event::ON_BACKGROUND, lifeCycleState);
732
733 GTEST_LOG_(INFO) << "AaFwk_Ability_OnBackground_0100 end";
734 }
735
736 /**
737 * @tc.number: AaFwk_Ability_OnBackground_0200
738 * @tc.name: OnBackground
739 * @tc.desc: Test the OnBackground exception.
740 */
741 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnBackground_0200, Function | MediumTest | Level3)
742 {
743 GTEST_LOG_(INFO) << "AaFwk_Ability_OnBackground_0200 start";
744 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
745 std::shared_ptr<OHOSApplication> application = nullptr;
746 std::shared_ptr<AbilityHandler> handler = nullptr;
747 sptr<IRemoteObject> token = nullptr;
748 ability_->Init(abilityInfo, application, handler, token);
749 ability_->OnBackground();
750
751 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
752 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
753
754 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::BACKGROUND, state);
755 EXPECT_TRUE(lifeCycle);
756
757 GTEST_LOG_(INFO) << "AaFwk_Ability_OnBackground_0200 end";
758 }
759
760 /**
761 * @tc.number: AaFwk_Ability_OnBackground_0300
762 * @tc.name: OnBackground
763 * @tc.desc: Test the OnBackground exception.
764 */
765 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnBackground_0300, Function | MediumTest | Level3)
766 {
767 GTEST_LOG_(INFO) << "AaFwk_Ability_OnBackground_0300 start";
768
769 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
770 AbilityType type = AbilityType::PAGE;
771 abilityInfo->type = type;
772 abilityInfo->isStageBasedModel = true;
773 std::shared_ptr<OHOSApplication> application = nullptr;
774 std::shared_ptr<AbilityHandler> handler = nullptr;
775 sptr<IRemoteObject> token = nullptr;
776 ability_->Init(abilityInfo, application, handler, token);
777 ability_->OnBackground();
778
779 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
780 std::shared_ptr<LifeCycle> lifeCycle = ability_->GetLifecycle();
781 LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState();
782
783 // Sence is nullptr, so lifecycle schedule failed.
784 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::INITIAL, state);
785 EXPECT_EQ(LifeCycle::Event::UNDEFINED, lifeCycleState);
786
787 GTEST_LOG_(INFO) << "AaFwk_Ability_OBackground_0300 end";
788 }
789
790 /**
791 * @tc.number: AaFwk_Ability_OnConnect_0100
792 * @tc.name: OnConnect
793 * @tc.desc: Test whether onconnect is called normally and verify whether the members are correct.
794 */
795 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnConnect_0100, Function | MediumTest | Level1)
796 {
797 GTEST_LOG_(INFO) << "AaFwk_Ability_OnConnect_0100 start";
798
799 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
800 AbilityType type = AbilityType::PAGE;
801 abilityInfo->type = type;
802 std::shared_ptr<OHOSApplication> application = nullptr;
803 std::shared_ptr<AbilityHandler> handler = nullptr;
804 sptr<IRemoteObject> token = nullptr;
805 ability_->Init(abilityInfo, application, handler, token);
806
807 Want want;
808 ability_->OnConnect(want);
809
810 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
811
812 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::ACTIVE, state);
813
814 GTEST_LOG_(INFO) << "AaFwk_Ability_OnConnect_0100 end";
815 }
816
817 /**
818 * @tc.number: AaFwk_Ability_OnCommond_0100
819 * @tc.name: OnCommand
820 * @tc.desc: Test whether oncommand is called normally and verify whether the members are correct.
821 */
822 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnCommond_0100, Function | MediumTest | Level1)
823 {
824 GTEST_LOG_(INFO) << "AaFwk_Ability_OnCommond_0100 start";
825
826 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
827 AbilityType type = AbilityType::PAGE;
828 abilityInfo->type = type;
829 std::shared_ptr<OHOSApplication> application = nullptr;
830 std::shared_ptr<AbilityHandler> handler = nullptr;
831 sptr<IRemoteObject> token = nullptr;
832 ability_->Init(abilityInfo, application, handler, token);
833
834 Want want;
835 ability_->OnCommand(want, false, 0);
836
837 AbilityLifecycleExecutor::LifecycleState state = ability_->GetState();
838
839 EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::ACTIVE, state);
840
841 GTEST_LOG_(INFO) << "AaFwk_Ability_OnCommond_0100 end";
842 }
843
844 /**
845 * @tc.number: AaFwk_Ability_OnDisconnect_0100
846 * @tc.name: OnDisconnect
847 * @tc.desc: Test whether ondisconnect is called normally.
848 */
849 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnDisconnect_0100, Function | MediumTest | Level1)
850 {
851 GTEST_LOG_(INFO) << "AaFwk_Ability_OnDisconnect_0100 start";
852
853 Want want;
854 ability_->OnDisconnect(want);
855
856 GTEST_LOG_(INFO) << "AaFwk_Ability_OnDisconnect_0100 end";
857 }
858
859 /**
860 * @tc.number: AaFwk_Ability_StartAbilitySetting_0100
861 * @tc.name: StartAbility
862 * @tc.desc: Test whether startability is called normally.
863 */
864 HWTEST_F(AbilityBaseTest, AaFwk_Ability_StartAbilitySetting_0100, Function | MediumTest | Level1)
865 {
866 GTEST_LOG_(INFO) << "AaFwk_Ability_StartAbilitySetting_0100 start";
867
868 Want want;
869 std::shared_ptr<AbilityStartSetting> setting = AbilityStartSetting::GetEmptySetting();
870
871 ability_->StartAbility(want, *setting.get());
872
873 GTEST_LOG_(INFO) << "AaFwk_Ability_StartAbilitySetting_0100 end";
874 }
875
876 /**
877 * @tc.number: AaFwk_Ability_StartAbilitySetting_0200
878 * @tc.name: StartAbility
879 * @tc.desc: Test startability exception status.
880 */
881 HWTEST_F(AbilityBaseTest, AaFwk_Ability_StartAbilitySetting_0200, Function | MediumTest | Level3)
882 {
883 GTEST_LOG_(INFO) << "AaFwk_Ability_StartAbilitySetting_0200 start";
884
885 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
886 abilityInfo->type = AbilityType::PAGE;
887 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
888 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
889 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
890
891 ability_->Init(abilityInfo, nullptr, handler, nullptr);
892 Want want;
893 std::shared_ptr<AbilityStartSetting> setting = AbilityStartSetting::GetEmptySetting();
894 ability_->StartAbility(want, *setting.get());
895
896 GTEST_LOG_(INFO) << "AaFwk_Ability_StartAbilitySetting_0200 end";
897 }
898
899 /**
900 * @tc.number: AaFwk_Ability_PostTask_0100
901 * @tc.name: PostTask
902 * @tc.desc: Test whether posttask is called normally.
903 */
904 HWTEST_F(AbilityBaseTest, AaFwk_Ability_PostTask_0100, Function | MediumTest | Level1)
905 {
906 GTEST_LOG_(INFO) << "AaFwk_Ability_PostTask_0100 start";
907
908 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
909 abilityInfo->type = AbilityType::PAGE;
910 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
911 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
912 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
913
914 ability_->Init(abilityInfo, nullptr, handler, nullptr);
__anon2cc243960102() 915 auto task = []() { GTEST_LOG_(INFO) << "AaFwk_Ability_PostTask_001 task called"; };
916 ability_->PostTask(task, 1000);
917
918 GTEST_LOG_(INFO) << "AaFwk_Ability_PostTask_0100 end";
919 }
920
921 /**
922 * @tc.number: AaFwk_Ability_ExecuteBatch_0100
923 * @tc.name: ExecuteBatch
924 * @tc.desc: Test whether ExecuteBatch is called normally.
925 */
926 HWTEST_F(AbilityBaseTest, AaFwk_Ability_ExecuteBatch_0100, Function | MediumTest | Level1)
927 {
928 GTEST_LOG_(INFO) << "AaFwk_Ability_ExecuteBatch_0100 start";
929
930 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
931 abilityInfo->type = AbilityType::DATA;
932 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
933 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
934 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
935 abilityInfo->isNativeAbility = true;
936
937 ability_->Init(abilityInfo, nullptr, handler, nullptr);
938
939 OHOS::NativeRdb::ValuesBucket calllogValues;
940 calllogValues.PutString("phone_number", "12345");
941 OHOS::NativeRdb::DataAbilityPredicates predicates;
942 predicates.GreaterThan("id", "0");
943 std::shared_ptr<OHOS::NativeRdb::ValuesBucket> values =
944 std::make_shared<OHOS::NativeRdb::ValuesBucket>(calllogValues);
945 std::shared_ptr<OHOS::NativeRdb::DataAbilityPredicates> executePredicates =
946 std::make_shared<OHOS::NativeRdb::DataAbilityPredicates>(predicates);
947 std::shared_ptr<Uri> uri = std::make_shared<Uri>("dataability:///com.ohos.test");
948 std::shared_ptr<DataAbilityOperation> operation =
949 DataAbilityOperation::NewUpdateBuilder(uri)
950 ->WithValuesBucket(values)
951 ->WithPredicatesBackReference(0, 0)
952 ->WithPredicates(executePredicates)
953 ->WithInterruptionAllowed(true)
954 ->Build();
955 std::vector<std::shared_ptr<DataAbilityOperation>> executeBatchOperations;
956 executeBatchOperations.push_back(operation);
957
958 std::vector<std::shared_ptr<DataAbilityResult>> ret = ability_->ExecuteBatch(executeBatchOperations);
959
960 EXPECT_STREQ(ret.at(0)->GetUri().ToString().c_str(), uri->ToString().c_str());
961
962 GTEST_LOG_(INFO) << "AaFwk_Ability_ExecuteBatch_0100 end";
963 }
964
965 class AbilityTest final : public Ability {
966 public:
AbilityTest()967 AbilityTest() {}
~AbilityTest()968 virtual ~AbilityTest() {}
969
OnBackPressed()970 void OnBackPressed() override
971 {
972 Ability::OnBackPressed();
973 onBackPressed_ = true;
974 }
975
976 public:
977 bool onBackPressed_ = false;
978 };
979 /**
980 * @tc.number: AaFwk_Ability_OnBackPressed_0100
981 * @tc.name: OnBackPress
982 * @tc.desc: Test whether OnBackPress can be called normally.
983 */
984 HWTEST_F(AbilityBaseTest, AaFwk_Ability_OnBackPressed_0100, Function | MediumTest | Level1)
985 {
986 GTEST_LOG_(INFO) << "AaFwk_Ability_OnBackPressed_0100 start";
987 std::shared_ptr<AbilityTest> ability = std::make_shared<AbilityTest>();
988 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
989 abilityInfo->type = AbilityType::PAGE;
990 std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
991 sptr<AbilityThread> abilityThread = sptr<AbilityThread>(new (std::nothrow) AbilityThread());
992 std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner, abilityThread);
993 ability->Init(abilityInfo, nullptr, handler, nullptr);
994 ability->OnBackPressed();
995 EXPECT_TRUE(ability->onBackPressed_);
996 GTEST_LOG_(INFO) << "AaFwk_Ability_OnBackPressed_0100 end";
997 }
998 } // namespace AppExecFwk
999 } // namespace OHOS
1000