diff --git a/frameworks/js/napi/app/recovery/BUILD.gn b/frameworks/js/napi/app/recovery/BUILD.gn index 2045a4ae53..27e1be5244 100644 --- a/frameworks/js/napi/app/recovery/BUILD.gn +++ b/frameworks/js/napi/app/recovery/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -35,7 +35,7 @@ ohos_shared_library("apprecovery_napi") { "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/runtime:runtime", "${ability_runtime_napi_path}/inner/napi_common:napi_common", - "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:appkit_native", ] diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 92c16b496d..503a09c891 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -216,9 +216,6 @@ ohos_shared_library("abilitykit_native") { "${ability_runtime_native_path}/ability/native/free_install_observer_stub.cpp", "${ability_runtime_native_path}/ability/native/js_free_install_observer.cpp", "${ability_runtime_native_path}/ability/native/new_ability_impl.cpp", - "${ability_runtime_native_path}/ability/native/recovery/ability_recovery.cpp", - "${ability_runtime_native_path}/ability/native/recovery/app_recovery.cpp", - "${ability_runtime_native_path}/ability/native/recovery/app_recovery_parcel_allocator.cpp", "${ability_runtime_native_path}/ability/native/service_ability_impl.cpp", "${ability_runtime_native_path}/appkit/app/app_context.cpp", "${ability_runtime_native_path}/appkit/app/context_container.cpp", @@ -407,6 +404,102 @@ ohos_shared_library("extensionkit_native") { part_name = "ability_runtime" } +config("uiability_config") { + visibility = [ ":*" ] + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_innerkits_path}/app_manager/include/appmgr", + "${ability_runtime_innerkits_path}/wantagent/include", + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/distributed", + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/kits", + "${ability_runtime_path}/interfaces/kits/native/ability/native/recovery/", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app", + "${ability_runtime_path}/interfaces/kits/native/appkit/app", + "${ability_runtime_services_path}/abilitymgr/include", + "${arkui_path}/napi", + "${arkui_path}/napi/interfaces/kits", + "${bundlefwk_inner_api_path}/appexecfwk_base/include", + "${bundlefwk_inner_api_path}/appexecfwk_core/include/bundlemgr", + "//third_party/libuv/include", + "//third_party/node/src", + ] + + if (ability_runtime_graphics) { + include_dirs += [ + "${form_fwk_path}/interfaces/inner_api/include", + "${multimedia_path}/interfaces/innerkits/include", + "${windowmanager_path}/interfaces/innerkits/dm", + "${windowmanager_path}/interfaces/innerkits/wm", + "${windowmanager_path}/utils/include", + ] + defines = [ "SUPPORT_GRAPHICS" ] + } +} + +ohos_shared_library("uiabilitykit_native") { + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime", + ] + + sources = [ + "${ability_runtime_native_path}/ability/native/ability_runtime/js_ui_ability.cpp", + "${ability_runtime_native_path}/ability/native/continuation/distributed/continuation_handler_stage.cpp", + "${ability_runtime_native_path}/ability/native/continuation/distributed/continuation_manager_stage.cpp", + "${ability_runtime_native_path}/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_stage.cpp", + "${ability_runtime_native_path}/ability/native/recovery/ability_recovery.cpp", + "${ability_runtime_native_path}/ability/native/recovery/app_recovery.cpp", + "${ability_runtime_native_path}/ability/native/recovery/app_recovery_parcel_allocator.cpp", + "${ability_runtime_native_path}/ability/native/ui_ability.cpp", + "${ability_runtime_native_path}/ability/native/ui_ability_impl.cpp", + ] + + public_configs = [ ":uiability_config" ] + + deps = [ + ":abilitykit_native", + ":continuation_ipc", + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", + "${ability_runtime_innerkits_path}/runtime:runtime", + "${ability_runtime_native_path}/ability:ability_context_native", + "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_delegator", + "${ability_runtime_services_path}/common:event_report", + ] + + external_deps = [ + "ability_base:base", + "ability_base:configuration", + "ability_base:want", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "ipc:ipc_napi_common", + "napi:ace_napi", + "resource_management:global_resmgr", + "window_manager:libwsutils", + "window_manager:windowstage_kit", + ] + + if (ability_runtime_graphics) { + deps += [ "//third_party/icu/icu4c:shared_icuuc" ] + external_deps += [ + "ability_base:session_info", + "window_manager:libdm", + "window_manager:libwm", + ] + } + + innerapi_tags = [ "platformsdk" ] + subsystem_name = "ability" + part_name = "ability_runtime" +} + ohos_shared_library("ability_thread") { include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/ability/native" ] @@ -415,11 +508,13 @@ ohos_shared_library("ability_thread") { "${ability_runtime_native_path}/ability/native/ability_thread.cpp", "${ability_runtime_native_path}/ability/native/extension_ability_thread.cpp", "${ability_runtime_native_path}/ability/native/fa_ability_thread.cpp", + "${ability_runtime_native_path}/ability/native/ui_ability_thread.cpp", ] deps = [ ":abilitykit_native", ":extensionkit_native", + ":uiabilitykit_native", "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager", "${ability_runtime_native_path}/ability:ability_context_native", diff --git a/frameworks/native/ability/native/ability.cpp b/frameworks/native/ability/native/ability.cpp index 81c3df3c5f..185d98df21 100644 --- a/frameworks/native/ability/native/ability.cpp +++ b/frameworks/native/ability/native/ability.cpp @@ -19,7 +19,6 @@ #include #include "ability_post_event_timeout.h" -#include "ability_recovery.h" #include "ability_runtime/js_ability.h" #include "abs_shared_result_set.h" #include "configuration_convertor.h" @@ -253,9 +252,6 @@ void Ability::OnStop() HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("called"); #ifdef SUPPORT_GRAPHICS - if (abilityRecovery_ != nullptr) { - abilityRecovery_->ScheduleSaveAbilityState(StateReason::LIFECYCLE); - } (void)Rosen::DisplayManager::GetInstance().UnregisterDisplayListener(abilityDisplayListener_); auto && window = GetWindow(); if (window != nullptr) { @@ -402,11 +398,6 @@ bool Ability::ShouldRecoverState(const Want& want) return false; } - if (abilityRecovery_ == nullptr) { - HILOG_WARN("AppRecovery Not enable"); - return false; - } - if (abilityContext_ == nullptr) { HILOG_WARN("AppRecovery abilityContext_ is null"); return false; @@ -1024,14 +1015,7 @@ void Ability::HandleCreateAsContinuation(const Want &want) void Ability::HandleCreateAsRecovery(const Want &want) { - if (!want.GetBoolParam(Want::PARAM_ABILITY_RECOVERY_RESTART, false)) { - HILOG_DEBUG("AppRecovery not recovery restart"); - return; - } - - if (abilityRecovery_ != nullptr) { - abilityRecovery_->ScheduleRestoreAbilityState(StateReason::DEVELOPER_REQUEST, want); - } + HILOG_DEBUG("called"); } bool Ability::IsFlagExists(unsigned int flag, unsigned int flagSet) @@ -1503,7 +1487,7 @@ bool Ability::IsUseNewStartUpRule() void Ability::EnableAbilityRecovery(const std::shared_ptr& abilityRecovery) { - abilityRecovery_ = abilityRecovery; + HILOG_DEBUG("called"); } int32_t Ability::OnShare(WantParams &wantParams) @@ -1567,9 +1551,6 @@ void Ability::OnBackground() HILOG_DEBUG("GoBackground sceneFlag:%{public}d.", sceneFlag_); scene_->GoBackground(sceneFlag_); } - if (abilityRecovery_ != nullptr) { - abilityRecovery_->ScheduleSaveAbilityState(StateReason::LIFECYCLE); - } } else { if (abilityWindow_ == nullptr) { HILOG_ERROR("Ability::OnBackground error. abilityWindow_ == nullptr."); diff --git a/frameworks/native/ability/native/ability_impl.cpp b/frameworks/native/ability/native/ability_impl.cpp index c534f0a143..dfe01b674b 100644 --- a/frameworks/native/ability/native/ability_impl.cpp +++ b/frameworks/native/ability/native/ability_impl.cpp @@ -98,7 +98,6 @@ void AbilityImpl::Start(const Want &want, sptr sessionInfo) } #endif - abilityLifecycleCallbacks_->OnAbilityStart(ability_); HILOG_DEBUG("%{public}s end.", __func__); } @@ -168,7 +167,6 @@ void AbilityImpl::StopCallback() #ifdef SUPPORT_GRAPHICS } #endif - abilityLifecycleCallbacks_->OnAbilityStop(ability_); ability_->DestroyInstance(); // Release window and ability. } @@ -188,7 +186,6 @@ void AbilityImpl::Active() } #endif lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; - abilityLifecycleCallbacks_->OnAbilityActive(ability_); HILOG_DEBUG("%{public}s end.", __func__); } @@ -208,7 +205,6 @@ void AbilityImpl::Inactive() } #endif lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE; - abilityLifecycleCallbacks_->OnAbilityInactive(ability_); HILOG_DEBUG("%{public}s end.", __func__); } @@ -272,7 +268,6 @@ sptr AbilityImpl::ConnectAbility(const Want &want) } sptr object = ability_->OnConnect(want); lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; - abilityLifecycleCallbacks_->OnAbilityActive(ability_); HILOG_DEBUG("%{public}s end.", __func__); return object; @@ -297,7 +292,6 @@ void AbilityImpl::CommandAbility(const Want &want, bool restart, int startId) } ability_->OnCommand(want, restart, startId); lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; - abilityLifecycleCallbacks_->OnAbilityActive(ability_); HILOG_DEBUG("%{public}s end.", __func__); } @@ -468,7 +462,6 @@ bool AbilityImpl::CheckAndSave() } ability_->OnSaveAbilityState(restoreData_); - abilityLifecycleCallbacks_->OnAbilitySaveState(restoreData_); needSaveDate_ = false; @@ -746,7 +739,6 @@ void AbilityImpl::Foreground(const Want &want) std::lock_guard lock(notifyForegroundLock_); notifyForegroundByAbility_ = true; } - abilityLifecycleCallbacks_->OnAbilityForeground(ability_); HILOG_INFO("%{public}s end.", __func__); } @@ -775,7 +767,6 @@ void AbilityImpl::Background() } else { lifecycleState_ = AAFwk::ABILITY_STATE_BACKGROUND; } - abilityLifecycleCallbacks_->OnAbilityBackground(ability_); HILOG_INFO("%{public}s end.", __func__); } diff --git a/frameworks/native/ability/native/ability_loader.cpp b/frameworks/native/ability/native/ability_loader.cpp index 2ee08e8b16..b4f156a68f 100644 --- a/frameworks/native/ability/native/ability_loader.cpp +++ b/frameworks/native/ability/native/ability_loader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -36,6 +36,12 @@ void AbilityLoader::RegisterExtension(const std::string &abilityName, const Crea HILOG_DEBUG("AbilityLoader::RegisterExtension:%{public}s", abilityName.c_str()); } +void AbilityLoader::RegisterUIAbility(const std::string &abilityName, const CreateUIAbility &createFunc) +{ + HILOG_DEBUG("RegisterUIAbility: %{public}s", abilityName.c_str()); + uiAbilities_.emplace(abilityName, createFunc); +} + Ability *AbilityLoader::GetAbilityByName(const std::string &abilityName) { auto it = abilities_.find(abilityName); @@ -56,6 +62,16 @@ AbilityRuntime::Extension *AbilityLoader::GetExtensionByName(const std::string & return nullptr; } +AbilityRuntime::UIAbility *AbilityLoader::GetUIAbilityByName(const std::string &abilityName) +{ + auto it = uiAbilities_.find(abilityName); + if (it != uiAbilities_.end()) { + return it->second(); + } + HILOG_ERROR("GetAbilityByName failed: %{public}s", abilityName.c_str()); + return nullptr; +} + #ifdef ABILITY_WINDOW_SUPPORT void AbilityLoader::RegisterAbilitySlice(const std::string &sliceName, const CreateSlice &createFunc) { diff --git a/frameworks/native/ability/native/ability_runtime/js_ability.cpp b/frameworks/native/ability/native/ability_runtime/js_ability.cpp index 4f163f9835..a9ee7e1644 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability.cpp @@ -22,9 +22,7 @@ #include "ability_runtime/js_ability.h" #include "ability_runtime/js_ability_context.h" -#include "ability_recovery.h" #include "ability_start_setting.h" -#include "app_recovery.h" #include "connection_manager.h" #include "hilog_wrapper.h" #include "js_data_struct_converter.h" @@ -120,13 +118,6 @@ void JsAbility::Init(const std::shared_ptr &abilityInfo, HILOG_ERROR("abilityInfo is nullptr"); return; } -#ifdef SUPPORT_GRAPHICS - if (abilityInfo->type == AppExecFwk::AbilityType::PAGE && abilityInfo->isStageBasedModel && - abilityContext_ != nullptr) { - AppExecFwk::AppRecovery::GetInstance().AddAbility(shared_from_this(), abilityContext_->GetAbilityInfo(), - abilityContext_->GetToken()); - } -#endif std::string srcPath(abilityInfo->package); if (!abilityInfo->isModuleJson) { /* temporary compatibility api8 + config.json */ @@ -182,9 +173,6 @@ void JsAbility::Init(const std::shared_ptr &abilityInfo, napi_set_named_property(env, obj, "context", contextObj); HILOG_DEBUG("Set ability context"); - if (abilityRecovery_ != nullptr) { - abilityRecovery_->SetJsAbility(reinterpret_cast(workContext)); - } napi_wrap(env, contextObj, workContext, [](napi_env, void *data, void *) { HILOG_DEBUG("Finalizer for weak_ptr ability context is called"); @@ -581,15 +569,6 @@ void JsAbility::AbilityContinuationOrRecover(const Want &want) OnSceneRestored(); NotifyContinuationResult(want, true); } else if (ShouldRecoverState(want)) { - std::string pageStack = abilityRecovery_->GetSavedPageStack(AppExecFwk::StateReason::DEVELOPER_REQUEST); - HandleScope handleScope(jsRuntime_); - auto &engine = jsRuntime_.GetNativeEngine(); - auto mainWindow = scene_->GetMainWindow(); - if (mainWindow != nullptr) { - mainWindow->SetUIContent(pageStack, &engine, abilityContext_->GetContentStorage()->Get(), true); - } else { - HILOG_ERROR("AppRecovery:AbilityContinuationOrRecover mainWindow nullptr"); - } OnSceneRestored(); } else { OnSceneCreated(); diff --git a/frameworks/native/ability/native/ability_thread.cpp b/frameworks/native/ability/native/ability_thread.cpp index 257aa30bf4..1243b044f1 100644 --- a/frameworks/native/ability/native/ability_thread.cpp +++ b/frameworks/native/ability/native/ability_thread.cpp @@ -17,6 +17,7 @@ #include "extension_ability_thread.h" #include "fa_ability_thread.h" +#include "ui_ability_thread.h" #include "hilog_wrapper.h" #include "hitrace_meter.h" @@ -42,7 +43,9 @@ void AbilityThread::AbilityThreadMain(const std::shared_ptr &ap } sptr thread = nullptr; - if (abilityInfo->type == AbilityType::EXTENSION) { + if (abilityInfo->type == AbilityType::PAGE && abilityInfo->isStageBasedModel) { + thread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + } else if (abilityInfo->type == AbilityType::EXTENSION) { thread = new (std::nothrow) AbilityRuntime::ExtensionAbilityThread(); } else { thread = new (std::nothrow) AbilityRuntime::FAAbilityThread(); @@ -73,7 +76,9 @@ void AbilityThread::AbilityThreadMain(const std::shared_ptr &ap } sptr thread = nullptr; - if (abilityInfo->type == AbilityType::EXTENSION) { + if (abilityInfo->type == AbilityType::PAGE && abilityInfo->isStageBasedModel) { + thread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + } else if (abilityInfo->type == AbilityType::EXTENSION) { thread = new (std::nothrow) AbilityRuntime::ExtensionAbilityThread(); } else { thread = new (std::nothrow) AbilityRuntime::FAAbilityThread(); diff --git a/frameworks/native/ability/native/recovery/ability_recovery.cpp b/frameworks/native/ability/native/recovery/ability_recovery.cpp index 66331a4b43..d9096cd6ec 100644 --- a/frameworks/native/ability/native/recovery/ability_recovery.cpp +++ b/frameworks/native/ability/native/recovery/ability_recovery.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,18 +18,17 @@ #include #include #include - #include -#include "file_ex.h" -#include "napi/native_api.h" -#include "napi/native_common.h" -#include "js_runtime.h" -#include "js_runtime_utils.h" - #include "ability_manager_client.h" #include "app_recovery_parcel_allocator.h" +#include "context/application_context.h" +#include "file_ex.h" #include "hilog_wrapper.h" +#include "js_runtime.h" +#include "js_runtime_utils.h" +#include "napi/native_api.h" +#include "napi/native_common.h" #include "parcel.h" #include "recovery_param.h" #include "string_ex.h" @@ -67,7 +66,7 @@ AbilityRecovery::~AbilityRecovery() { } -bool AbilityRecovery::InitAbilityInfo(const std::shared_ptr ability, +bool AbilityRecovery::InitAbilityInfo(const std::shared_ptr ability, const std::shared_ptr& abilityInfo, const sptr& token) { isEnable_ = true; diff --git a/frameworks/native/ability/native/recovery/app_recovery.cpp b/frameworks/native/ability/native/recovery/app_recovery.cpp index d635f539b8..81a61c3884 100644 --- a/frameworks/native/ability/native/recovery/app_recovery.cpp +++ b/frameworks/native/ability/native/recovery/app_recovery.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,24 +25,23 @@ #include #include -#include "ability_runtime/js_ability.h" -#include "js_runtime.h" -#include "js_runtime_utils.h" -#include "mission_info.h" -#include "napi/native_api.h" -#include "napi/native_common.h" - #include "ability_manager_client.h" - +#include "context/application_context.h" #include "directory_ex.h" #include "file_ex.h" #include "hilog_wrapper.h" +#include "js_runtime.h" +#include "js_runtime_utils.h" +#include "js_ui_ability.h" +#include "mission_info.h" +#include "napi/native_api.h" +#include "napi/native_common.h" +#include "ohos_application.h" #include "parcel.h" -#include "want_params.h" #include "recovery_param.h" #include "string_ex.h" #include "string_wrapper.h" -#include "ohos_application.h" +#include "want_params.h" namespace OHOS { namespace AppExecFwk { @@ -113,7 +112,7 @@ bool AppRecovery::InitApplicationInfo(const std::shared_ptr& mainH return true; } -bool AppRecovery::AddAbility(std::shared_ptr ability, +bool AppRecovery::AddAbility(std::shared_ptr ability, const std::shared_ptr& abilityInfo, const sptr& token) { if (!isEnable_) { @@ -190,7 +189,7 @@ bool AppRecovery::ScheduleSaveAppState(StateReason reason, uintptr_t ability) HILOG_ERROR("AppRecovery Failed to block main thread, skip save state when appfreeze"); return false; } - OHOS::AbilityRuntime::JsAbility& jsAbility = static_cast(*abilityPtr); + OHOS::AbilityRuntime::JsUIAbility& jsAbility = static_cast(*abilityPtr); AbilityRuntime::JsRuntime& runtime = const_cast(jsAbility.GetJsRuntime()); auto& nativeEngine = runtime.GetNativeEngine(); nativeEngine.AllowCrossThreadExecution(); diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 15f70854c3..69f116054e 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -134,6 +134,7 @@ ohos_shared_library("appkit_native") { "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:app_context_utils", "${ability_runtime_path}/js_environment/frameworks/js_environment:js_environment", diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 0b64d17179..5150ae1f29 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1363,11 +1363,11 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con application_->SetRuntime(std::move(runtime)); std::weak_ptr wpApplication = application_; - AbilityLoader::GetInstance().RegisterAbility("Ability", - [wpApplication]() -> Ability* { + AbilityLoader::GetInstance().RegisterUIAbility("UIAbility", + [wpApplication]() -> AbilityRuntime::UIAbility* { auto app = wpApplication.lock(); if (app != nullptr) { - return Ability::Create(app->GetRuntime()); + return AbilityRuntime::UIAbility::Create(app->GetRuntime()); } HILOG_ERROR("AbilityLoader::GetAbilityByName failed."); return nullptr; diff --git a/frameworks/native/appkit/app/ohos_application.cpp b/frameworks/native/appkit/app/ohos_application.cpp index 53ab0a1cb9..aae6a2023a 100644 --- a/frameworks/native/appkit/app/ohos_application.cpp +++ b/frameworks/native/appkit/app/ohos_application.cpp @@ -19,6 +19,7 @@ #include "ability_record_mgr.h" #include "ability_thread.h" #include "app_loader.h" +#include "application_context.h" #include "application_impl.h" #include "context_impl.h" #include "hilog_wrapper.h" @@ -26,6 +27,7 @@ #include "iservice_registry.h" #include "runtime.h" #include "system_ability_definition.h" +#include "ui_ability.h" #ifdef SUPPORT_GRAPHICS #include "window.h" #endif @@ -246,7 +248,7 @@ void OHOSApplication::UnregisterAbilityLifecycleCallbacks(const std::shared_ptr< * * @param Ability Indicates the ability object that calls the onStart() method. */ -void OHOSApplication::OnAbilityStart(const std::shared_ptr &ability) +void OHOSApplication::OnAbilityStart(const std::shared_ptr &ability) { if (ability == nullptr) { HILOG_ERROR("ContextDeal::OnAbilityStart failed, ability is nullptr"); @@ -267,7 +269,7 @@ void OHOSApplication::OnAbilityStart(const std::shared_ptr &ability) * * @param Ability Indicates the Ability object that calls the onInactive() method. */ -void OHOSApplication::OnAbilityInactive(const std::shared_ptr &ability) +void OHOSApplication::OnAbilityInactive(const std::shared_ptr &ability) { if (ability == nullptr) { HILOG_ERROR("ContextDeal::OnAbilityInactive failed, ability is nullptr"); @@ -288,7 +290,7 @@ void OHOSApplication::OnAbilityInactive(const std::shared_ptr &ability) * * @param Ability Indicates the Ability object that calls the onBackground() method. */ -void OHOSApplication::OnAbilityBackground(const std::shared_ptr &ability) +void OHOSApplication::OnAbilityBackground(const std::shared_ptr &ability) { if (ability == nullptr) { HILOG_ERROR("ContextDeal::OnAbilityBackground failed, ability is nullptr"); @@ -309,7 +311,7 @@ void OHOSApplication::OnAbilityBackground(const std::shared_ptr &abilit * * @param Ability Indicates the Ability object that calls the onForeground() method. */ -void OHOSApplication::OnAbilityForeground(const std::shared_ptr &ability) +void OHOSApplication::OnAbilityForeground(const std::shared_ptr &ability) { if (ability == nullptr) { HILOG_ERROR("ContextDeal::OnAbilityForeground failed, ability is nullptr"); @@ -330,7 +332,7 @@ void OHOSApplication::OnAbilityForeground(const std::shared_ptr &abilit * * @param Ability Indicates the Ability object that calls the onActive() method. */ -void OHOSApplication::OnAbilityActive(const std::shared_ptr &ability) +void OHOSApplication::OnAbilityActive(const std::shared_ptr &ability) { if (ability == nullptr) { HILOG_ERROR("ContextDeal::OnAbilityActive failed, ability is nullptr"); @@ -351,7 +353,7 @@ void OHOSApplication::OnAbilityActive(const std::shared_ptr &ability) * * @param Ability Indicates the Ability object that calls the onStop() method. */ -void OHOSApplication::OnAbilityStop(const std::shared_ptr &ability) +void OHOSApplication::OnAbilityStop(const std::shared_ptr &ability) { if (ability == nullptr) { HILOG_ERROR("ContextDeal::OnAbilityStop failed, ability is nullptr"); diff --git a/interfaces/kits/native/ability/native/ability.h b/interfaces/kits/native/ability/native/ability.h index fc68c7d58c..9df0bba5dc 100644 --- a/interfaces/kits/native/ability/native/ability.h +++ b/interfaces/kits/native/ability/native/ability.h @@ -80,6 +80,7 @@ class AbilityWindow; #endif class ILifeCycle; class ContinuationManager; +class ContinuationHandler; class AbilityRecovery; class ContinuationRegisterManager; class Ability : public IAbilityEvent, @@ -1273,7 +1274,6 @@ protected: std::shared_ptr abilityContext_ = nullptr; std::shared_ptr setting_ = nullptr; - std::shared_ptr abilityRecovery_ = nullptr; std::shared_ptr abilityInfo_ = nullptr; LaunchParam launchParam_; int32_t appIndex_ = 0; diff --git a/interfaces/kits/native/ability/native/ability_lifecycle_callbacks.h b/interfaces/kits/native/ability/native/ability_lifecycle_callbacks.h index 77882b1298..76740fb7b1 100644 --- a/interfaces/kits/native/ability/native/ability_lifecycle_callbacks.h +++ b/interfaces/kits/native/ability/native/ability_lifecycle_callbacks.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,8 +19,10 @@ #include "pac_map.h" namespace OHOS { +namespace AbilityRuntime { +class UIAbility; +} namespace AppExecFwk { -class Ability; class AbilityLifecycleCallbacks { public: AbilityLifecycleCallbacks() = default; @@ -32,7 +34,7 @@ public: * * @param Ability Indicates the ability object that calls the onStart() method. */ - virtual void OnAbilityStart(const std::shared_ptr &ability) = 0; + virtual void OnAbilityStart(const std::shared_ptr &ability) = 0; /** * @@ -40,7 +42,7 @@ public: * * @param Ability Indicates the Ability object that calls the onInactive() method. */ - virtual void OnAbilityInactive(const std::shared_ptr &ability) = 0; + virtual void OnAbilityInactive(const std::shared_ptr &ability) = 0; /** * @@ -48,7 +50,7 @@ public: * * @param Ability Indicates the Ability object that calls the onBackground() method. */ - virtual void OnAbilityBackground(const std::shared_ptr &ability) = 0; + virtual void OnAbilityBackground(const std::shared_ptr &ability) = 0; /** * @@ -56,7 +58,7 @@ public: * * @param Ability Indicates the Ability object that calls the onForeground() method. */ - virtual void OnAbilityForeground(const std::shared_ptr &ability) = 0; + virtual void OnAbilityForeground(const std::shared_ptr &ability) = 0; /** * @@ -64,7 +66,7 @@ public: * * @param Ability Indicates the Ability object that calls the onActive() method. */ - virtual void OnAbilityActive(const std::shared_ptr &ability) = 0; + virtual void OnAbilityActive(const std::shared_ptr &ability) = 0; /** * @@ -72,7 +74,7 @@ public: * * @param Ability Indicates the Ability object that calls the onStop() method. */ - virtual void OnAbilityStop(const std::shared_ptr &ability) = 0; + virtual void OnAbilityStop(const std::shared_ptr &ability) = 0; /** * diff --git a/interfaces/kits/native/ability/native/ability_loader.h b/interfaces/kits/native/ability/native/ability_loader.h index 49247c815d..13a9f4dd14 100644 --- a/interfaces/kits/native/ability/native/ability_loader.h +++ b/interfaces/kits/native/ability/native/ability_loader.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,18 +16,21 @@ #ifndef OHOS_ABILITY_RUNTIME_ABILITY_LOADER_H #define OHOS_ABILITY_RUNTIME_ABILITY_LOADER_H +#include +#include +#include + #include "ability.h" #include "context.h" #include "extension.h" #include "ohos_application.h" -#include -#include -#include +#include "ui_ability.h" namespace OHOS { namespace AppExecFwk { using CreateExtension = std::function; using CreateAblity = std::function; +using CreateUIAbility = std::function; #ifdef ABILITY_WINDOW_SUPPORT using CreateSlice = std::function; #endif @@ -64,6 +67,13 @@ public: */ void RegisterExtension(const std::string &abilityName, const CreateExtension &createFunc); + /** + * @brief Register UIAbility Info + * @param abilityName UIAbility classname + * @param createFunc Constructor address + */ + void RegisterUIAbility(const std::string &abilityName, const CreateUIAbility &createFunc); + /** * @brief Get Ability address * @@ -82,6 +92,13 @@ public: */ AbilityRuntime::Extension *GetExtensionByName(const std::string &abilityName); + /** + * @brief Get UIAbility address + * @param abilityName UIAbility classname + * @return return UIAbility address + */ + AbilityRuntime::UIAbility *GetUIAbilityByName(const std::string &abilityName); + #ifdef ABILITY_WINDOW_SUPPORT void RegisterAbilitySlice(const std::string &sliceName, const CreateSlice &createFunc); AbilitySlice *GetAbilitySliceByName(const std::string &sliceName); @@ -96,6 +113,7 @@ private: std::unordered_map abilities_; std::unordered_map extensions_; + std::unordered_map uiAbilities_; }; /** * @brief Registers the class name of an {@link Ability} child class. diff --git a/interfaces/kits/native/ability/native/recovery/ability_recovery.h b/interfaces/kits/native/ability/native/recovery/ability_recovery.h index 5f9588328f..635cb29245 100644 --- a/interfaces/kits/native/ability/native/recovery/ability_recovery.h +++ b/interfaces/kits/native/ability/native/recovery/ability_recovery.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,13 +19,13 @@ #include #include -#include "ability.h" #include "ability_info.h" #include "application_info.h" #include "event_handler.h" #include "iremote_object.h" #include "parcel.h" #include "recovery_param.h" +#include "ui_ability.h" #include "want.h" #include "want_params.h" @@ -36,8 +36,8 @@ public: AbilityRecovery(); virtual ~AbilityRecovery(); void EnableAbilityRecovery(uint16_t restartFlag, uint16_t saveFlag, uint16_t saveMode); - bool InitAbilityInfo(const std::shared_ptr ability, - const std::shared_ptr& abilityInfo, const sptr& token); + bool InitAbilityInfo(const std::shared_ptr ability, + const std::shared_ptr &abilityInfo, const sptr &token); bool ScheduleSaveAbilityState(StateReason reason); bool ScheduleRecoverAbility(StateReason reason, const Want *want = nullptr); bool ScheduleRestoreAbilityState(StateReason reason, const Want &want); @@ -67,7 +67,7 @@ private: uint16_t restartFlag_; uint16_t saveOccasion_; uint16_t saveMode_; - std::weak_ptr ability_; + std::weak_ptr ability_; std::weak_ptr abilityInfo_; uintptr_t jsAbilityPtr_; wptr token_; diff --git a/interfaces/kits/native/ability/native/recovery/app_recovery.h b/interfaces/kits/native/ability/native/recovery/app_recovery.h index 22ed706a13..be2863eb6e 100644 --- a/interfaces/kits/native/ability/native/recovery/app_recovery.h +++ b/interfaces/kits/native/ability/native/recovery/app_recovery.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,13 +20,13 @@ #include #include -#include "ability.h" #include "ability_info.h" #include "ability_recovery.h" #include "application_info.h" #include "event_handler.h" #include "iremote_object.h" #include "parcel.h" +#include "ui_ability.h" #include "want.h" #include "want_params.h" @@ -38,8 +38,8 @@ public: void EnableAppRecovery(uint16_t restartFlag, uint16_t saveFlag, uint16_t saveMode); bool InitApplicationInfo(const std::shared_ptr& mainHandler, const std::shared_ptr& applicationInfo); - bool AddAbility(std::shared_ptr ability, - const std::shared_ptr& abilityInfo, const sptr& token); + bool AddAbility(std::shared_ptr ability, const std::shared_ptr &abilityInfo, + const sptr &token); bool RemoveAbility(const sptr& tokenId); bool IsEnabled() const; @@ -71,7 +71,7 @@ private: uint16_t saveMode_; std::weak_ptr mainHandler_; std::weak_ptr applicationInfo_; - std::weak_ptr ability_; + std::weak_ptr ability_; std::vector> abilityRecoverys_; std::shared_ptr want_ = nullptr; }; diff --git a/interfaces/kits/native/appkit/app/element_callback.h b/interfaces/kits/native/appkit/app/element_callback.h index 2c3fa1c68e..503e2b2a09 100644 --- a/interfaces/kits/native/appkit/app/element_callback.h +++ b/interfaces/kits/native/appkit/app/element_callback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -32,7 +32,7 @@ public: * @param config Indicates the new Configuration object. * @param ability Indicates the new Ability object. */ - virtual void OnConfigurationUpdated(const std::shared_ptr &ability, const Configuration &config) = 0; + virtual void OnConfigurationUpdated(const std::shared_ptr &ability, const Configuration &config) = 0; /** * diff --git a/interfaces/kits/native/appkit/app/ohos_application.h b/interfaces/kits/native/appkit/app/ohos_application.h index 7029a899df..13ef1602ab 100644 --- a/interfaces/kits/native/appkit/app/ohos_application.h +++ b/interfaces/kits/native/appkit/app/ohos_application.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -92,7 +92,7 @@ public: * * @param Ability Indicates the ability object that calls the onStart() method. */ - void OnAbilityStart(const std::shared_ptr &ability); + void OnAbilityStart(const std::shared_ptr &ability); /** * @@ -100,7 +100,7 @@ public: * * @param Ability Indicates the Ability object that calls the onInactive() method. */ - void OnAbilityInactive(const std::shared_ptr &ability); + void OnAbilityInactive(const std::shared_ptr &ability); /** * @@ -108,7 +108,7 @@ public: * * @param Ability Indicates the Ability object that calls the onBackground() method. */ - void OnAbilityBackground(const std::shared_ptr &ability); + void OnAbilityBackground(const std::shared_ptr &ability); /** * @@ -116,7 +116,7 @@ public: * * @param Ability Indicates the Ability object that calls the onForeground() method. */ - void OnAbilityForeground(const std::shared_ptr &ability); + void OnAbilityForeground(const std::shared_ptr &ability); /** * @@ -124,7 +124,7 @@ public: * * @param Ability Indicates the Ability object that calls the onActive() method. */ - void OnAbilityActive(const std::shared_ptr &ability); + void OnAbilityActive(const std::shared_ptr &ability); /** * @@ -132,7 +132,7 @@ public: * * @param Ability Indicates the Ability object that calls the onStop() method. */ - void OnAbilityStop(const std::shared_ptr &ability); + void OnAbilityStop(const std::shared_ptr &ability); /** * diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ui_ability.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ui_ability.h new file mode 100644 index 0000000000..2ad33c467a --- /dev/null +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ui_ability.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MOCK_OHOS_ABILITY_RUNTIME_MOCK_UI_ABILITY_H +#define MOCK_OHOS_ABILITY_RUNTIME_MOCK_UI_ABILITY_H + +#include + +#include "ui_ability.h" + +namespace OHOS { +namespace AppExecFwk { +using namespace OHOS; +using Want = OHOS::AAFwk::Want; + +class MockUIAbility : public AbilityRuntime::UIAbility { +public: + MockUIAbility() = default; + virtual ~MockUIAbility() = default; + + enum Event { ON_ACTIVE = 0, ON_BACKGROUND, ON_FOREGROUND, ON_INACTIVE, ON_START, ON_STOP, UNDEFINED }; + + void OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want &resultData) + { + GTEST_LOG_(INFO) << "MockUIAbility::OnAbilityResult called"; + state_ = ON_ACTIVE; + } + + void OnNewWant(const Want &want) + { + onNewWantCalled_ = true; + GTEST_LOG_(INFO) << "MockUIAbility::OnNewWant called"; + } + + void OnStart(const Want &want, sptr sessionInfo) + { + GTEST_LOG_(INFO) << "MockUIAbility::OnStart called"; + state_ = ON_START; + } + + void OnStop() + { + GTEST_LOG_(INFO) << "MockUIAbility::OnStop called"; + state_ = ON_STOP; + } + + void OnForeground(const Want &want) + { + GTEST_LOG_(INFO) << "MockUIAbility::OnForeground called"; + state_ = ON_FOREGROUND; + } + + void OnBackground() + { + GTEST_LOG_(INFO) << "MockUIAbility::OnBackground called"; + state_ = ON_BACKGROUND; + } + + void OnRestoreAbilityState(const PacMap &inState) + { + GTEST_LOG_(INFO) << "Mock UIAbility::OnRestoreAbilityState called"; + } + + void OnConfigurationUpdated(const Configuration &config) + { + GTEST_LOG_(INFO) << "Mock UIAbility::OnConfigurationUpdated called"; + OnConfigurationUpdated_++; + } + + void ContinuationRestore(const Want &want) + { + GTEST_LOG_(INFO) << "Mock UIAbility::ContinuationRestore called"; + continueRestoreCalled_ = true; + } + + MockUIAbility::Event state_ = UNDEFINED; + bool onNewWantCalled_ = false; + bool continueRestoreCalled_ = false; + int OnConfigurationUpdated_ = 0; + std::vector value; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // MOCK_OHOS_ABILITY_RUNTIME_MOCK_UI_ABILITY_H diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ui_ability_impl.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ui_ability_impl.h new file mode 100644 index 0000000000..01cf91a49f --- /dev/null +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ui_ability_impl.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MOCK_OHOS_ABILITY_RUNTIME_MOCK_UI_ABILITY_IMPL_H +#define MOCK_OHOS_ABILITY_RUNTIME_MOCK_UI_ABILITY_IMPL_H + +#include + +#include "ui_ability_impl.h" + +namespace OHOS { +namespace AbilityRuntime { +using Want = OHOS::AAFwk::Want; + +class MockUIAbilityimpl : public UIAbilityImpl { +public: + MockUIAbilityimpl() = default; + virtual ~MockUIAbilityimpl() = default; + + void ImplStart(const Want &want) + { + this->Start(want); + } + + void ImplStop() + { + this->Stop(); + } + + void SetlifecycleState(int state) + { + this->lifecycleState_ = state; + } + + int GetCurrentState() + { + return lifecycleState_; + } + + sptr GetToken() + { + return token_; + } + + std::shared_ptr GetAbility() + { + return ability_; + } + + bool CheckAndRestore() + { + return UIAbilityImpl::CheckAndRestore(); + } + +#ifdef SUPPORT_GRAPHICS + void ImplForeground(const Want &want) + { + this->Foreground(want); + } + + void ImplBackground() + { + this->Background(); + } +#endif + +private: + UIAbilityImpl AbilityImpl_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // MOCK_OHOS_ABILITY_RUNTIME_MOCK_UI_ABILITY_IMPL_H diff --git a/test/mock/frameworks_kits_appkit_native_test/include/mock_ability_lifecycle_callbacks.h b/test/mock/frameworks_kits_appkit_native_test/include/mock_ability_lifecycle_callbacks.h index 02acc03641..9641c4ee34 100644 --- a/test/mock/frameworks_kits_appkit_native_test/include/mock_ability_lifecycle_callbacks.h +++ b/test/mock/frameworks_kits_appkit_native_test/include/mock_ability_lifecycle_callbacks.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -34,7 +34,7 @@ public: * * @param Ability Indicates the ability object that calls the onStart() method. */ - virtual void OnAbilityStart(const std::shared_ptr& ability) + virtual void OnAbilityStart(const std::shared_ptr& ability) { GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityStart called"; } @@ -45,7 +45,7 @@ public: * * @param Ability Indicates the Ability object that calls the onInactive() method. */ - virtual void OnAbilityInactive(const std::shared_ptr& ability) + virtual void OnAbilityInactive(const std::shared_ptr& ability) { GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityInactive called"; } @@ -56,7 +56,7 @@ public: * * @param Ability Indicates the Ability object that calls the onBackground() method. */ - virtual void OnAbilityBackground(const std::shared_ptr& ability) + virtual void OnAbilityBackground(const std::shared_ptr& ability) { GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityBackground called"; } @@ -67,7 +67,7 @@ public: * * @param Ability Indicates the Ability object that calls the onForeground() method. */ - virtual void OnAbilityForeground(const std::shared_ptr& ability) + virtual void OnAbilityForeground(const std::shared_ptr& ability) { GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityForeground called"; } @@ -78,7 +78,7 @@ public: * * @param Ability Indicates the Ability object that calls the onActive() method. */ - virtual void OnAbilityActive(const std::shared_ptr& ability) + virtual void OnAbilityActive(const std::shared_ptr& ability) { GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityActive called"; } @@ -89,7 +89,7 @@ public: * * @param Ability Indicates the Ability object that calls the onStop() method. */ - virtual void OnAbilityStop(const std::shared_ptr& ability) + virtual void OnAbilityStop(const std::shared_ptr& ability) { GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityStop called"; } diff --git a/test/mock/frameworks_kits_appkit_native_test/include/mock_element_callback.h b/test/mock/frameworks_kits_appkit_native_test/include/mock_element_callback.h index caf8307167..ba67382d5d 100644 --- a/test/mock/frameworks_kits_appkit_native_test/include/mock_element_callback.h +++ b/test/mock/frameworks_kits_appkit_native_test/include/mock_element_callback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -33,7 +33,7 @@ public: * @param config Indicates the new Configuration object. * @param ability Indicates the new Ability object. */ - virtual void OnConfigurationUpdated(const std::shared_ptr& ability, const Configuration& config) + virtual void OnConfigurationUpdated(const std::shared_ptr& ability, const Configuration& config) { GTEST_LOG_(INFO) << "MockElementsCallback::OnConfigurationUpdated called"; configurationUpdated_ = true; diff --git a/test/unittest/app_recovery_test/BUILD.gn b/test/unittest/app_recovery_test/BUILD.gn index f425ff042c..85e0691d06 100644 --- a/test/unittest/app_recovery_test/BUILD.gn +++ b/test/unittest/app_recovery_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -36,6 +36,7 @@ ohos_unittest("AppRecoveryUnitTest") { deps = [ "${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:app_context_utils", "${ability_runtime_native_path}/appkit:appkit_delegator", @@ -95,6 +96,7 @@ ohos_unittest("AbilityRecoveryUnitTest") { deps = [ "${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:app_context_utils", "${ability_runtime_native_path}/appkit:appkit_delegator", diff --git a/test/unittest/app_recovery_test/ability_recovery_test.cpp b/test/unittest/app_recovery_test/ability_recovery_test.cpp index 7367ae3621..7f60dc9de5 100644 --- a/test/unittest/app_recovery_test/ability_recovery_test.cpp +++ b/test/unittest/app_recovery_test/ability_recovery_test.cpp @@ -18,7 +18,6 @@ #define private public #include "ability_recovery.h" #undef private -#include "ability.h" #include "ability_info.h" #include "app_recovery_parcel_allocator.h" #include "event_handler.h" @@ -27,6 +26,7 @@ #include "mock_ability_token.h" #include "mock_app_ability.h" #include "recovery_param.h" +#include "ui_ability.h" #include "want.h" #include "want_params.h" @@ -40,9 +40,9 @@ public: void SetUp(); void TearDown(); std::shared_ptr abilityRecovery_ = std::make_shared(); - std::shared_ptr ability_ = std::make_shared(); - std::shared_ptr mockAbility_ = std::make_shared(); - std::shared_ptr mockAbility2_ = std::make_shared(); + std::shared_ptr ability_ = std::make_shared(); + std::shared_ptr mockAbility_ = std::make_shared(); + std::shared_ptr mockAbility2_ = std::make_shared(); std::shared_ptr abilityInfo_ = std::make_shared(); std::shared_ptr applicationInfo_ = std::make_shared(); sptr token_ = new MockAbilityToken(); diff --git a/test/unittest/app_recovery_test/app_recovery_test.cpp b/test/unittest/app_recovery_test/app_recovery_test.cpp index dd9e2777d5..6e00630daf 100644 --- a/test/unittest/app_recovery_test/app_recovery_test.cpp +++ b/test/unittest/app_recovery_test/app_recovery_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -22,14 +22,14 @@ #define private public #include "app_recovery.h" #undef private -#include "ability.h" #include "ability_info.h" -#include "ability_runtime/js_ability.h" +#include "ability_runtime/js_ui_ability.h" #include "event_handler.h" #include "js_runtime.h" #include "mock_ability_context.h" #include "mock_ability_token.h" #include "recovery_param.h" +#include "ui_ability.h" using namespace testing::ext; namespace OHOS { @@ -40,7 +40,7 @@ public: static void TearDownTestCase(); void SetUp(); void TearDown(); - std::shared_ptr ability_ = std::make_shared(); + std::shared_ptr ability_ = std::make_shared(); std::shared_ptr abilityInfo_ = std::make_shared(); std::shared_ptr applicationInfo_ = std::make_shared(); std::shared_ptr testHandler_ = std::make_shared(); @@ -321,7 +321,7 @@ HWTEST_F(AppRecoveryUnitTest, ScheduleSaveAppState_003, TestSize.Level1) AbilityRuntime::Runtime::Options options; auto runtime = AbilityRuntime::JsRuntime::Create(options); auto jsRuntime = static_cast(runtime.get()); - std::shared_ptr ability = std::make_shared(*jsRuntime); + std::shared_ptr ability = std::make_shared(*jsRuntime); ability->AttachAbilityContext(constContext); AppRecovery::GetInstance().AddAbility(ability, abilityInfo_, token_); // this call will block main thread, thus call it in new thread @@ -504,7 +504,7 @@ HWTEST_F(AppRecoveryUnitTest, ScheduleRecoverApp_004, TestSize.Level1) AppRecovery::GetInstance().EnableAppRecovery(RestartFlag::ALWAYS_RESTART, SaveOccasionFlag::SAVE_WHEN_ERROR, SaveModeFlag::SAVE_WITH_FILE); auto caseAbilityInfo = std::make_shared(); - auto ability = std::make_shared(); + auto ability = std::make_shared(); sptr token = new MockAbilityToken(); EXPECT_TRUE(AppRecovery::GetInstance().AddAbility(ability_, abilityInfo_, token_)); bool ret = AppRecovery::GetInstance().ScheduleRecoverApp(StateReason::APP_FREEZE); @@ -522,7 +522,7 @@ HWTEST_F(AppRecoveryUnitTest, ScheduleRecoverApp_005, TestSize.Level1) AppRecovery::GetInstance().EnableAppRecovery(RestartFlag::ALWAYS_RESTART, SaveOccasionFlag::SAVE_WHEN_ERROR, SaveModeFlag::SAVE_WITH_FILE); auto caseAbilityInfo = std::make_shared(); - auto ability = std::make_shared(); + auto ability = std::make_shared(); sptr token = new MockAbilityToken(); EXPECT_TRUE(AppRecovery::GetInstance().AddAbility(ability_, abilityInfo_, token_)); AppRecovery::GetInstance().mainHandler_.reset(); @@ -541,7 +541,7 @@ HWTEST_F(AppRecoveryUnitTest, ScheduleRecoverApp_006, TestSize.Level1) AppRecovery::GetInstance().EnableAppRecovery(RestartFlag::ALWAYS_RESTART, SaveOccasionFlag::SAVE_WHEN_ERROR, SaveModeFlag::SAVE_WITH_FILE); auto caseAbilityInfo = std::make_shared(); - auto ability = std::make_shared(); + auto ability = std::make_shared(); sptr token = new MockAbilityToken(); EXPECT_TRUE(AppRecovery::GetInstance().AddAbility(ability_, abilityInfo_, token_)); bool ret = AppRecovery::GetInstance().ScheduleRecoverApp(StateReason::DEVELOPER_REQUEST); @@ -571,7 +571,7 @@ HWTEST_F(AppRecoveryUnitTest, TryRecoverApp_002, TestSize.Level1) AppRecovery::GetInstance().EnableAppRecovery(RestartFlag::ALWAYS_RESTART, SaveOccasionFlag::SAVE_WHEN_ERROR, SaveModeFlag::SAVE_WITH_FILE); auto caseAbilityInfo = std::make_shared(); - auto ability = std::make_shared(); + auto ability = std::make_shared(); sptr token = new MockAbilityToken(); EXPECT_TRUE(AppRecovery::GetInstance().AddAbility(ability_, abilityInfo_, token_)); bool ret = AppRecovery::GetInstance().TryRecoverApp(StateReason::APP_FREEZE); @@ -615,7 +615,7 @@ HWTEST_F(AppRecoveryUnitTest, PersistAppState_003, TestSize.Level1) AppRecovery::GetInstance().EnableAppRecovery(RestartFlag::ALWAYS_RESTART, SaveOccasionFlag::SAVE_WHEN_ERROR, SaveModeFlag::SAVE_WITH_SHARED_MEMORY); auto constContext = std::static_pointer_cast(context_); - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); ability->AttachAbilityContext(constContext); AppRecovery::GetInstance().AddAbility(ability, abilityInfo_, token_); EXPECT_TRUE(AppRecovery::GetInstance().PersistAppState()); diff --git a/test/unittest/app_recovery_test/mock/mock_ability.h b/test/unittest/app_recovery_test/mock/mock_ability.h index e24c5a66a9..21dec33d98 100644 --- a/test/unittest/app_recovery_test/mock/mock_ability.h +++ b/test/unittest/app_recovery_test/mock/mock_ability.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,14 +15,14 @@ #ifndef MOCK_OHOS_ABILITY_RECOVERY_TEST_H #define MOCK_OHOS_ABILITY_RECOVERY_TEST_H -#include "ability.h" #include "ability_loader.h" -#include "want.h" #include "recovery_param.h" +#include "ui_ability.h" +#include "want.h" namespace OHOS { namespace AppExecFwk { -class MockAbility : public Ability { +class MockAbility : public AbilityRuntime::UIAbility { protected: int32_t OnSaveState(int32_t reason, WantParams &wantParams) override { diff --git a/test/unittest/app_recovery_test/mock/mock_app_ability.h b/test/unittest/app_recovery_test/mock/mock_app_ability.h index 56797282ef..4deb6a2042 100644 --- a/test/unittest/app_recovery_test/mock/mock_app_ability.h +++ b/test/unittest/app_recovery_test/mock/mock_app_ability.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,14 +15,14 @@ #ifndef MOCK_OHOS_APP_ABILITY_RECOVERY_TEST_H #define MOCK_OHOS_APP_ABILITY_RECOVERY_TEST_H -#include "ability.h" #include "ability_loader.h" -#include "want.h" #include "recovery_param.h" +#include "ui_ability.h" +#include "want.h" namespace OHOS { namespace AppExecFwk { -class MockAppAbility : public Ability { +class MockAppAbility : public AbilityRuntime::UIAbility { protected: int32_t OnSaveState(int32_t reason, WantParams &wantParams) override { diff --git a/test/unittest/appkit/ohos_application_test/BUILD.gn b/test/unittest/appkit/ohos_application_test/BUILD.gn index 89034fb521..2a7116e001 100644 --- a/test/unittest/appkit/ohos_application_test/BUILD.gn +++ b/test/unittest/appkit/ohos_application_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -49,6 +49,7 @@ ohos_unittest("ohos_application_test") { deps = [ "${ability_runtime_native_path}/ability/native:ability_thread", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_native", "../../../../frameworks/native/ability/native:abilitykit_native", diff --git a/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp b/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp index 0ea50d5cd6..3299239ce9 100644 --- a/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp +++ b/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp @@ -31,6 +31,7 @@ #include "ohos_application.h" #include "pac_map.h" #include "runtime.h" +#include "ui_ability.h" #undef private using namespace testing; @@ -362,7 +363,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_UnregisterAbilityLi HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStart_0100, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityStart_0100 start."; - std::shared_ptr ability = nullptr; + std::shared_ptr ability = nullptr; EXPECT_TRUE(ability == nullptr); ohosApplication_->OnAbilityStart(ability); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityStart_0100 end."; @@ -376,7 +377,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStart_0100 HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStart_0200, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityStart_0200 start."; - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); EXPECT_TRUE(ability != nullptr); ohosApplication_->OnAbilityStart(ability); EXPECT_TRUE(ohosApplication_->abilityLifecycleCallbacks_.empty()); @@ -397,7 +398,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStart_0200 HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0100, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0100 start."; - std::shared_ptr ability = nullptr; + std::shared_ptr ability = nullptr; ohosApplication_->OnAbilityInactive(ability); EXPECT_TRUE(ability == nullptr); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0100 end."; @@ -411,7 +412,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0 HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0200, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0200 start."; - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); EXPECT_TRUE(ability != nullptr); ohosApplication_->OnAbilityInactive(ability); EXPECT_TRUE(ohosApplication_->abilityLifecycleCallbacks_.empty()); @@ -432,7 +433,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0 HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityBackground_0100, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityBackground_0100 start."; - std::shared_ptr ability = nullptr; + std::shared_ptr ability = nullptr; ohosApplication_->OnAbilityBackground(ability); EXPECT_TRUE(ability == nullptr); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityBackground_0100 end."; @@ -446,7 +447,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityBackground HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityBackground_0200, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityBackground_0200 start."; - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); EXPECT_TRUE(ability != nullptr); ohosApplication_->OnAbilityBackground(ability); EXPECT_TRUE(ohosApplication_->abilityLifecycleCallbacks_.empty()); @@ -465,7 +466,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityBackground HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityForeground_0100, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityForeground_0100 start."; - std::shared_ptr ability = nullptr; + std::shared_ptr ability = nullptr; ohosApplication_->OnAbilityForeground(ability); EXPECT_TRUE(ability == nullptr); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityForeground_0100 end."; @@ -479,7 +480,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityForeground HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityForeground_0200, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityForeground_0200 start."; - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); EXPECT_TRUE(ability != nullptr); ohosApplication_->OnAbilityForeground(ability); EXPECT_TRUE(ohosApplication_->abilityLifecycleCallbacks_.empty()); @@ -498,7 +499,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityForeground HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityActive_0100, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityActive_0100 start."; - std::shared_ptr ability = nullptr; + std::shared_ptr ability = nullptr; ohosApplication_->OnAbilityActive(ability); EXPECT_TRUE(ability == nullptr); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityActive_0100 end."; @@ -512,7 +513,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityActive_010 HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityActive_0200, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityActive_0200 start."; - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); EXPECT_TRUE(ability != nullptr); ohosApplication_->OnAbilityActive(ability); EXPECT_TRUE(ohosApplication_->abilityLifecycleCallbacks_.empty()); @@ -531,7 +532,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityActive_020 HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStop_0100, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityStop_0100 start."; - std::shared_ptr ability = nullptr; + std::shared_ptr ability = nullptr; ohosApplication_->OnAbilityStop(ability); EXPECT_TRUE(ability == nullptr); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityStop_0100 end."; @@ -545,7 +546,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStop_0100, HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStop_0200, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityStop_0200 start."; - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); EXPECT_TRUE(ability != nullptr); ohosApplication_->OnAbilityStop(ability); EXPECT_TRUE(ohosApplication_->abilityLifecycleCallbacks_.empty()); diff --git a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn index 9fe36b846f..960f348f52 100644 --- a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn @@ -96,6 +96,7 @@ ohos_unittest("ability_test") { "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", @@ -623,6 +624,53 @@ ohos_unittest("ability_impl_test") { } } +ohos_unittest("ui_ability_impl_test") { + module_out_path = module_output_path + sources = [ + "${ability_runtime_native_path}/appkit/app/app_context.cpp", + "${ability_runtime_native_path}/appkit/app/app_loader.cpp", + "${ability_runtime_native_path}/appkit/app/ohos_application.cpp", + ] + + configs = [ ":module_private_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_native_path}/ability/native:ability_thread", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", + "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_native", + "${global_path}/resource_management/frameworks/resmgr:global_resmgr", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:base", + "ability_base:configuration", + "ability_base:want", + "ability_runtime:runtime", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + ] + + if (ability_runtime_graphics) { + sources += [ "ui_ability_impl_test.cpp" ] + deps += [ "${global_path}/i18n/frameworks/intl:intl_util" ] + external_deps += [ + "input:libmmi-client", + "window_manager:libwm", + ] + } +} + ohos_unittest("ability_thread_test") { module_out_path = module_output_path @@ -729,6 +777,59 @@ ohos_unittest("extension_ability_thread_test") { } } +ohos_unittest("ui_ability_thread_test") { + module_out_path = module_output_path + sources = [ + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/process_info.cpp", + "${ability_runtime_native_path}/appkit/app/app_context.cpp", + "${ability_runtime_native_path}/appkit/app/app_loader.cpp", + "${ability_runtime_native_path}/appkit/app/context_container.cpp", + "${ability_runtime_native_path}/appkit/app/ohos_application.cpp", + "ui_ability_thread_test.cpp", + ] + + configs = [ ":module_private_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager", + "${ability_runtime_native_path}/ability/native:ability_thread", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", + "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_native", + "${ability_runtime_services_path}/dataobsmgr:dataobsms_static", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:base", + "ability_base:configuration", + "ability_base:want", + "ability_runtime:ability_deps_wrapper", + "ability_runtime:runtime", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + "resource_management:global_resmgr", + ] + + if (ability_runtime_graphics) { + external_deps += [ + "ability_base:session_info", + "input:libmmi-client", + "window_manager:libwm", + ] + } +} + ohos_unittest("service_extension_module_loader_test") { module_out_path = module_output_path include_dirs = [ @@ -1407,6 +1508,60 @@ ohos_unittest("task_handler_client_test") { } } +ohos_unittest("ui_ability_test") { + module_out_path = module_output_path + sources = [ + "${ability_runtime_native_path}/appkit/app/ability_record_mgr.cpp", + "${ability_runtime_native_path}/appkit/app/app_context.cpp", + "${ability_runtime_native_path}/appkit/app/app_loader.cpp", + "${ability_runtime_native_path}/appkit/app/ohos_application.cpp", + "ui_ability_test.cpp", + ] + + configs = [ ":module_private_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", + "${ability_runtime_native_path}/ability/native:ability_thread", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", + "${ability_runtime_native_path}/appkit:app_context", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "${global_path}/resource_management/frameworks/resmgr:global_resmgr", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:base", + "ability_base:configuration", + "ability_base:session_info", + "ability_base:want", + "ability_runtime:ability_context_native", + "ability_runtime:runtime", + "ability_runtime:wantagent_innerkits", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + "window_manager:scene_session", + ] + + if (ability_runtime_graphics) { + external_deps += [ + "image_framework:image_native", + "input:libmmi-client", + "window_manager:libwm", + ] + } +} + ohos_unittest("ability_thread_for_ability_on_configuration_update") { module_out_path = module_output_path @@ -1888,6 +2043,7 @@ ohos_unittest("ability_loader_test") { deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", @@ -2273,6 +2429,9 @@ group("unittest") { ":share_extension_module_loader_test", ":share_extension_test", ":task_handler_client_test", + ":ui_ability_impl_test", + ":ui_ability_test", + ":ui_ability_thread_test", ] if (ability_runtime_graphics) { diff --git a/test/unittest/frameworks_kits_ability_native_test/ability_loader_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ability_loader_test.cpp index d47a01d8e1..7bbd949937 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ability_loader_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ability_loader_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -29,6 +29,7 @@ using namespace testing; using namespace testing::ext; using CreateAblity = std::function; using CreateExtension = std::function; +using CreateUIAblity = std::function; class AbilityLoaderTest : public testing::Test { public: @@ -158,4 +159,59 @@ HWTEST_F(AbilityLoaderTest, GetExtensionByName_0200, TestSize.Level1) AbilityLoader::GetInstance().extensions_.clear(); EXPECT_FALSE(AbilityLoader::GetInstance().GetExtensionByName(abilityName) != nullptr); GTEST_LOG_(INFO) << "AbilityLoaderTest GetExtensionByName_0200 end"; +} + +/** + * @tc.number: RegisterUIAbility_0100 + * @tc.name: RegisterUIAbility + * @tc.desc: RegisterUIAbility Test, return true. + */ +HWTEST_F(AbilityLoaderTest, RegisterUIAbility_0100, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "AbilityLoaderTest RegisterUIAbility_0100 start"; + auto loader = std::make_shared(); + std::string abilityName; + CreateUIAblity createFunc; + loader->RegisterUIAbility(abilityName, createFunc); + bool result = false; + auto it = loader->uiAbilities_.find(abilityName); + if (it != loader->uiAbilities_.end()) { + result = true; + } + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "AbilityLoaderTest RegisterUIAbility_0100 end"; +} + +/** + * @tc.number: GetUIAbilityByName_0100 + * @tc.name: GetUIAbilityByName + * @tc.desc: GetUIAbilityByName Test When UIAbility is not nullptr. + */ +HWTEST_F(AbilityLoaderTest, GetUIAbilityByName_0100, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "AbilityLoaderTest GetUIAbilityByName_0100 start"; + std::string abilityName = "UIAbility"; + CreateAblity createFunc; + auto createAblity = []() -> AbilityRuntime::UIAbility *{ + AbilityRuntime::UIAbility *callBack = new (std::nothrow) AbilityRuntime::UIAbility; + return callBack; + }; + AbilityLoader::GetInstance().uiAbilities_.clear(); + AbilityLoader::GetInstance().RegisterUIAbility(abilityName, createAblity); + EXPECT_TRUE(AbilityLoader::GetInstance().GetUIAbilityByName(abilityName) != nullptr); + GTEST_LOG_(INFO) << "AbilityLoaderTest GetUIAbilityByName_0100 end"; +} + +/** + * @tc.number: GetUIAbilityByName_0200 + * @tc.name: GetUIAbilityByName + * @tc.desc: GetUIAbilityByName Test When UIAbility is nullptr. + */ +HWTEST_F(AbilityLoaderTest, GetUIAbilityByName_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityLoaderTest GetAbilityByName_0200 start"; + std::string abilityName = "UIAbilityName"; + AbilityLoader::GetInstance().abilities_.clear(); + EXPECT_FALSE(AbilityLoader::GetInstance().GetUIAbilityByName(abilityName) != nullptr); + GTEST_LOG_(INFO) << "AbilityLoaderTest GetUIAbilityByName_0200 start"; } \ No newline at end of file diff --git a/test/unittest/frameworks_kits_ability_native_test/ui_ability_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ui_ability_impl_test.cpp new file mode 100644 index 0000000000..5af6c4e0e1 --- /dev/null +++ b/test/unittest/frameworks_kits_ability_native_test/ui_ability_impl_test.cpp @@ -0,0 +1,2008 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public +#define protected public +#include "ui_ability_impl.h" +#undef protected +#undef private +#include "ability_handler.h" +#include "context_deal.h" +#include "hilog_wrapper.h" +#include "locale_config.h" +#include "mock_ability_token.h" +#include "mock_ui_ability.h" +#include "mock_ui_ability_impl.h" +#include "ohos_application.h" + +namespace OHOS { +namespace AppExecFwk { +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::AbilityRuntime; + +class UIAbilityImplTest : public testing::Test { +public: + UIAbilityImplTest() : abilityImpl_(nullptr), MocKUIAbility_(nullptr) {} + ~UIAbilityImplTest() {} + std::shared_ptr abilityImpl_; + std::shared_ptr MocKUIAbility_; + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void UIAbilityImplTest::SetUpTestCase(void) {} + +void UIAbilityImplTest::TearDownTestCase(void) {} + +void UIAbilityImplTest::SetUp(void) +{ + abilityImpl_ = std::make_shared(); + MocKUIAbility_ = std::make_shared(); +} + +void UIAbilityImplTest::TearDown(void) {} + +/* + * Feature: UIAbilityImpl + * Function: ScheduleUpdateConfiguration + * SubFunction: NA + * FunctionPoints: ScheduleUpdateConfiguration + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::ScheduleUpdateConfiguration init + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_ScheduleUpdateConfiguration_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_001 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr pMocKUIAbility = std::make_shared(); + EXPECT_NE(pMocKUIAbility, nullptr); + std::shared_ptr uiability = pMocKUIAbility; + if (pMocKUIAbility != nullptr) { + std::shared_ptr contextDeal = std::make_shared(); + std::shared_ptr resourceManager( + Global::Resource::CreateResourceManager()); + if (resourceManager == nullptr) { + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_001 resourceManager is nullptr"; + } + contextDeal->initResourceManager(resourceManager); + contextDeal->SetApplicationContext(application); + pMocKUIAbility->AttachBaseContext(contextDeal); + application->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + + Configuration config; + auto testNotify1 = pMocKUIAbility->OnConfigurationUpdated_; + EXPECT_EQ(testNotify1, 0); + mockUIAbilityimpl->ScheduleUpdateConfiguration(config); + auto testNotify2 = pMocKUIAbility->OnConfigurationUpdated_; + EXPECT_EQ(testNotify2, 0); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_001 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: ScheduleUpdateConfiguration + * SubFunction: NA + * FunctionPoints: ScheduleUpdateConfiguration + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::ScheduleUpdateConfiguration change + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_ScheduleUpdateConfiguration_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_002 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr pMocKUIAbility = std::make_shared(); + EXPECT_NE(pMocKUIAbility, nullptr); + std::shared_ptr uiability = pMocKUIAbility; + if (pMocKUIAbility != nullptr) { + std::shared_ptr contextDeal = std::make_shared(); + std::shared_ptr resourceManager( + Global::Resource::CreateResourceManager()); + if (resourceManager == nullptr) { + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_002 resourceManager is nullptr"; + } + contextDeal->initResourceManager(resourceManager); + contextDeal->SetApplicationContext(application); + pMocKUIAbility->AttachBaseContext(contextDeal); + application->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + + auto testNotify1 = pMocKUIAbility->OnConfigurationUpdated_; + EXPECT_EQ(testNotify1, 0); + Configuration config; + mockUIAbilityimpl->ScheduleUpdateConfiguration(config); + auto testNotify2 = pMocKUIAbility->OnConfigurationUpdated_; + EXPECT_EQ(testNotify2, 0); + auto language = OHOS::Global::I18n::LocaleConfig::GetSystemLanguage(); + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_002 : " << language; + config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, language); + mockUIAbilityimpl->SetlifecycleState(AAFwk::ABILITY_STATE_ACTIVE); + mockUIAbilityimpl->ScheduleUpdateConfiguration(config); + auto testNotify3 = pMocKUIAbility->OnConfigurationUpdated_; + EXPECT_EQ(testNotify3, 1); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_002 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: ScheduleUpdateConfiguration + * SubFunction: NA + * FunctionPoints: ScheduleUpdateConfiguration + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::ScheduleUpdateConfiguration repeat + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_ScheduleUpdateConfiguration_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_003 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr applicationInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr pMocKUIAbility = std::make_shared(); + EXPECT_NE(pMocKUIAbility, nullptr); + std::shared_ptr uiability = pMocKUIAbility; + if (pMocKUIAbility != nullptr) { + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetApplicationInfo(applicationInfo); + contextDeal->SetAbilityInfo(abilityInfo); + std::shared_ptr resourceManager( + Global::Resource::CreateResourceManager()); + if (resourceManager == nullptr) { + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_003 resourceManager is nullptr"; + } + contextDeal->initResourceManager(resourceManager); + contextDeal->SetApplicationContext(application); + pMocKUIAbility->AttachBaseContext(contextDeal); + application->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + + Configuration config; + auto testNotify1 = pMocKUIAbility->OnConfigurationUpdated_; + EXPECT_EQ(testNotify1, 0); + mockUIAbilityimpl->ScheduleUpdateConfiguration(config); + auto testNotify2 = pMocKUIAbility->OnConfigurationUpdated_; + EXPECT_EQ(testNotify2, 0); + auto language = OHOS::Global::I18n::LocaleConfig::GetSystemLanguage(); + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_003 : " << language; + config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, language); + mockUIAbilityimpl->SetlifecycleState(AAFwk::ABILITY_STATE_ACTIVE); + mockUIAbilityimpl->ScheduleUpdateConfiguration(config); + auto testNotify3 = pMocKUIAbility->OnConfigurationUpdated_; + EXPECT_EQ(testNotify3, 1); + mockUIAbilityimpl->ScheduleUpdateConfiguration(config); + auto testNotify4 = pMocKUIAbility->OnConfigurationUpdated_; + EXPECT_EQ(testNotify4, 2); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_003 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: Init + * SubFunction: NA + * FunctionPoints: Init + * EnvConditions: NA + * CaseDescription: Validate when normally entering a string + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Init_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Init_001 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability = std::make_shared(); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + EXPECT_EQ(mockUIAbilityimpl->GetToken(), record->GetToken()); + EXPECT_EQ(mockUIAbilityimpl->GetAbility(), uiability); + EXPECT_EQ(mockUIAbilityimpl->GetCurrentState(), AAFwk::ABILITY_STATE_INITIAL); + } + GTEST_LOG_(INFO) << "AbilityRuntime_Init_001 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: Start + * SubFunction: NA + * FunctionPoints: Start + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::Start + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Start_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Start_001 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + Want want; + mockUIAbilityimpl->ImplStart(want); + EXPECT_EQ(MockUIAbility::Event::ON_START, pMocKUIAbility->state_); + EXPECT_EQ(AAFwk::ABILITY_STATE_STARTED_NEW, mockUIAbilityimpl->GetCurrentState()); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_Start_001 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: Stop + * SubFunction: NA + * FunctionPoints: Stop + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::Stop + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Stop_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_001 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + mockUIAbilityimpl->ImplStop(); + EXPECT_EQ(MockUIAbility::Event::ON_STOP, pMocKUIAbility->state_); + EXPECT_EQ(AAFwk::ABILITY_STATE_STOPED_NEW, mockUIAbilityimpl->GetCurrentState()); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_001 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: Foreground + * SubFunction: NA + * FunctionPoints: Foreground + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::Foreground + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_001 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + abilityInfo->isStageBasedModel = true; + abilityInfo->type = AppExecFwk::AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability = nullptr; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + std::shared_ptr contextDeal = std::make_shared(); + std::shared_ptr applicationInfo = std::make_shared(); + contextDeal->SetApplicationInfo(applicationInfo); + contextDeal->SetAbilityInfo(abilityInfo); + pMocKUIAbility->AttachBaseContext(contextDeal); + application->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + Want want; + mockUIAbilityimpl->ImplForeground(want); + EXPECT_EQ(MockUIAbility::Event::ON_FOREGROUND, pMocKUIAbility->state_); + EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockUIAbilityimpl->GetCurrentState()); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_001 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: Foreground + * SubFunction: NA + * FunctionPoints: Foreground + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::Foreground + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_002 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + abilityInfo->isStageBasedModel = true; + abilityInfo->type = AppExecFwk::AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability = nullptr; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + std::shared_ptr contextDeal = std::make_shared(); + std::shared_ptr applicationInfo = std::make_shared(); + contextDeal->SetApplicationInfo(applicationInfo); + contextDeal->SetAbilityInfo(abilityInfo); + pMocKUIAbility->AttachBaseContext(contextDeal); + application->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + Want want; + mockUIAbilityimpl->ImplForeground(want); + mockUIAbilityimpl->ImplForeground(want); + mockUIAbilityimpl->ImplForeground(want); + EXPECT_EQ(MockUIAbility::Event::ON_FOREGROUND, pMocKUIAbility->state_); + EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockUIAbilityimpl->GetCurrentState()); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_002 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: Background + * SubFunction: NA + * FunctionPoints: Background + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::Background + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Background_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_New_Background_001 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability = nullptr; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + std::shared_ptr contextDeal = std::make_shared(); + std::shared_ptr applicationInfo = std::make_shared(); + contextDeal->SetApplicationInfo(applicationInfo); + contextDeal->SetAbilityInfo(abilityInfo); + pMocKUIAbility->AttachBaseContext(contextDeal); + application->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + mockUIAbilityimpl->ImplBackground(); + EXPECT_EQ(MockUIAbility::Event::ON_BACKGROUND, pMocKUIAbility->state_); + EXPECT_EQ(AAFwk::ABILITY_STATE_BACKGROUND_NEW, mockUIAbilityimpl->GetCurrentState()); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_New_Background_001 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: Background + * SubFunction: NA + * FunctionPoints: Background + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::Background + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Background_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_New_Background_002 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + abilityInfo->isStageBasedModel = true; + abilityInfo->type = AppExecFwk::AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability = nullptr; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + std::shared_ptr contextDeal = std::make_shared(); + std::shared_ptr applicationInfo = std::make_shared(); + contextDeal->SetApplicationInfo(applicationInfo); + contextDeal->SetAbilityInfo(abilityInfo); + pMocKUIAbility->AttachBaseContext(contextDeal); + application->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + mockUIAbilityimpl->ImplBackground(); + mockUIAbilityimpl->ImplBackground(); + mockUIAbilityimpl->ImplBackground(); + EXPECT_EQ(MockUIAbility::Event::ON_BACKGROUND, pMocKUIAbility->state_); + EXPECT_EQ(AAFwk::ABILITY_STATE_BACKGROUND_NEW, mockUIAbilityimpl->GetCurrentState()); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_New_Background_002 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: Background + * SubFunction: NA + * FunctionPoints: Background + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::Background + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_Background_001 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + abilityInfo->isStageBasedModel = true; + abilityInfo->type = AppExecFwk::AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability = nullptr; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + std::shared_ptr contextDeal = std::make_shared(); + std::shared_ptr applicationInfo = std::make_shared(); + contextDeal->SetApplicationInfo(applicationInfo); + contextDeal->SetAbilityInfo(abilityInfo); + pMocKUIAbility->AttachBaseContext(contextDeal); + application->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + Want want; + mockUIAbilityimpl->ImplForeground(want); + mockUIAbilityimpl->ImplBackground(); + EXPECT_EQ(MockUIAbility::Event::ON_BACKGROUND, pMocKUIAbility->state_); + EXPECT_EQ(AAFwk::ABILITY_STATE_BACKGROUND_NEW, mockUIAbilityimpl->GetCurrentState()); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_Background_001 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: Background + * SubFunction: NA + * FunctionPoints: Background + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::Background + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_Background_002 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + abilityInfo->isStageBasedModel = true; + abilityInfo->type = AppExecFwk::AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability = nullptr; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + std::shared_ptr contextDeal = std::make_shared(); + std::shared_ptr applicationInfo = std::make_shared(); + contextDeal->SetApplicationInfo(applicationInfo); + contextDeal->SetAbilityInfo(abilityInfo); + pMocKUIAbility->AttachBaseContext(contextDeal); + application->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + Want want; + mockUIAbilityimpl->ImplForeground(want); + mockUIAbilityimpl->ImplBackground(); + mockUIAbilityimpl->ImplForeground(want); + EXPECT_EQ(MockUIAbility::Event::ON_FOREGROUND, pMocKUIAbility->state_); + EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockUIAbilityimpl->GetCurrentState()); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_Background_002 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: Background + * SubFunction: NA + * FunctionPoints: Background + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::Background + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_Background_002 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + abilityInfo->isStageBasedModel = true; + abilityInfo->type = AppExecFwk::AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability = nullptr; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + std::shared_ptr contextDeal = std::make_shared(); + std::shared_ptr applicationInfo = std::make_shared(); + contextDeal->SetApplicationInfo(applicationInfo); + contextDeal->SetAbilityInfo(abilityInfo); + pMocKUIAbility->AttachBaseContext(contextDeal); + application->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + Want want; + mockUIAbilityimpl->ImplBackground(); + mockUIAbilityimpl->ImplForeground(want); + EXPECT_EQ(MockUIAbility::Event::ON_FOREGROUND, pMocKUIAbility->state_); + EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockUIAbilityimpl->GetCurrentState()); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_Background_003 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: Background + * SubFunction: NA + * FunctionPoints: Background + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::Background + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_Background_004 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + abilityInfo->isStageBasedModel = true; + abilityInfo->type = AppExecFwk::AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability = nullptr; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + std::shared_ptr contextDeal = std::make_shared(); + std::shared_ptr applicationInfo = std::make_shared(); + contextDeal->SetApplicationInfo(applicationInfo); + contextDeal->SetAbilityInfo(abilityInfo); + pMocKUIAbility->AttachBaseContext(contextDeal); + application->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + Want want; + mockUIAbilityimpl->ImplBackground(); + mockUIAbilityimpl->ImplForeground(want); + mockUIAbilityimpl->ImplBackground(); + EXPECT_EQ(MockUIAbility::Event::ON_BACKGROUND, pMocKUIAbility->state_); + EXPECT_EQ(AAFwk::ABILITY_STATE_BACKGROUND_NEW, mockUIAbilityimpl->GetCurrentState()); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_Background_004 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: DispatchRestoreAbilityState + * SubFunction: NA + * FunctionPoints: DispatchRestoreAbilityState + * EnvConditions: NA + * CaseDescription: Test the abnormal behavior of the UIAbilityImpl::DispatchRestoreAbilityState + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_DispatchRestoreAbilityState_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DispatchRestoreAbilityState_001 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability = std::make_shared(); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + + PacMap inState; + mockUIAbilityimpl->DispatchRestoreAbilityState(inState); + } + GTEST_LOG_(INFO) << "AbilityRuntime_DispatchRestoreAbilityState_001 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: DispatchRestoreAbilityState + * SubFunction: NA + * FunctionPoints: DispatchRestoreAbilityState + * EnvConditions: NA + * CaseDescription: Test the abnormal behavior of the UIAbilityImpl::DispatchRestoreAbilityState + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_DispatchRestoreAbilityState_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DispatchRestoreAbilityState_002 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability = nullptr; + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + + PacMap inState; + mockUIAbilityimpl->DispatchRestoreAbilityState(inState); + } + GTEST_LOG_(INFO) << "AbilityRuntime_DispatchRestoreAbilityState_002 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: SendResult + * SubFunction: NA + * FunctionPoints: SendResult + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::SendResult + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_SendResult_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_001 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + + int requestCode = 0; + int resultCode = 0; + Want resultData; + mockUIAbilityimpl->SendResult(requestCode, resultCode, resultData); + EXPECT_EQ(MockUIAbility::Event::ON_ACTIVE, pMocKUIAbility->state_); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_001 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: NewWant + * SubFunction: NA + * FunctionPoints: NewWant + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::NewWant + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_NewWant_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_NewWant_001 start"; + + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + + Want want; + mockUIAbilityimpl->NewWant(want); + EXPECT_EQ(1, pMocKUIAbility->onNewWantCalled_); + EXPECT_EQ(1, pMocKUIAbility->continueRestoreCalled_); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_NewWant_001 end"; +} + +/* + * Feature: UIAbilityImpl + * Function: CheckAndRestore + * SubFunction: NA + * FunctionPoints: CheckAndRestore + * EnvConditions: NA + * CaseDescription: Test the normal behavior of the UIAbilityImpl::CheckAndRestore + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_CheckAndRestore_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_CheckAndRestore_001 start"; + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + EXPECT_FALSE(mockUIAbilityimpl->CheckAndRestore()); + PacMap inState; + mockUIAbilityimpl->DispatchRestoreAbilityState(inState); + EXPECT_TRUE(mockUIAbilityimpl->CheckAndRestore()); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_CheckAndRestore_001 end"; +} + +/** + * @tc.number: AbilityRuntime_Init_0200 + * @tc.name: Init + * @tc.desc: application is nullptr, Verify Init failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Init_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Init_0200 start"; + std::shared_ptr application; + std::shared_ptr abilityInfo = std::make_shared(); + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + abilityImpl_->Init(application, record, uiability, handler, token); + EXPECT_TRUE(abilityImpl_->token_ == nullptr); + GTEST_LOG_(INFO) << "AbilityRuntime_Init_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_Init_0300 + * @tc.name: Init + * @tc.desc: record is nullptr, Verify Init failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Init_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Init_0300 start"; + std::shared_ptr application = std::make_shared(); + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr eventRunner = EventRunner::Create(""); + std::shared_ptr handler = std::make_shared(eventRunner); + abilityImpl_->Init(application, record, uiability, handler, token); + EXPECT_TRUE(abilityImpl_->token_ == nullptr); + GTEST_LOG_(INFO) << "AbilityRuntime_Init_0300 end"; +} + +/** + * @tc.number: AbilityRuntime_Init_0400 + * @tc.name: Init + * @tc.desc: uiability is nullptr, Verify Init failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Init_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Init_0400 start"; + std::shared_ptr application = std::make_shared(); + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr uiability; + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + abilityImpl_->Init(application, record, uiability, handler, token); + EXPECT_TRUE(abilityImpl_->token_ == nullptr); + GTEST_LOG_(INFO) << "AbilityRuntime_Init_0400 end"; +} + +/** + * @tc.number: AbilityRuntime_Init_0500 + * @tc.name: Init + * @tc.desc: handler is nullptr, Verify Init failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Init_0500, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Init_0500 start"; + std::shared_ptr application = std::make_shared(); + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr handler; + abilityImpl_->Init(application, record, uiability, handler, token); + EXPECT_TRUE(abilityImpl_->token_ == nullptr); + GTEST_LOG_(INFO) << "AbilityRuntime_Init_0500 end"; +} + +/** + * @tc.number: AbilityRuntime_Init_0600 + * @tc.name: Init + * @tc.desc: token is nullptr, Verify Init failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Init_0600, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Init_0600 start"; + std::shared_ptr application = std::make_shared(); + sptr token = nullptr; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + abilityImpl_->Init(application, record, uiability, handler, token); + EXPECT_TRUE(abilityImpl_->token_ == nullptr); + GTEST_LOG_(INFO) << "AbilityRuntime_Init_0600 end"; +} + +/** + * @tc.number: AbilityRuntime_Init_0700 + * @tc.name: Init + * @tc.desc: contextDeal is nullptr, Verify Init failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Init_0700, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Init_0700 start"; + std::shared_ptr application = std::make_shared(); + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + abilityImpl_->Init(application, record, uiability, handler, token); + EXPECT_TRUE(abilityImpl_->token_ != nullptr); + GTEST_LOG_(INFO) << "AbilityRuntime_Init_0700 end"; +} + +/** + * @tc.number: AbilityRuntime_Start_0300 + * @tc.name: Start + * @tc.desc: Test the normal behavior of the UIAbilityImpl::Start + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Start_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Start_0300 start"; + + std::shared_ptr mockUIAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + abilityInfo->type = AppExecFwk::AbilityType::PAGE; + abilityInfo->isStageBasedModel = true; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + mockUIAbilityimpl->Init(application, record, uiability, handler, token); + Want want; + mockUIAbilityimpl->ImplStart(want); + EXPECT_EQ(AAFwk::ABILITY_STATE_STARTED_NEW, mockUIAbilityimpl->GetCurrentState()); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_Start_0300 end"; +} + +/** + * @tc.number: AbilityRuntime_Start_0400 + * @tc.name: Start + * @tc.desc: uiability is nullptr, Verify Start failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Start_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Start_0400 start"; + abilityImpl_->ability_ = nullptr; + Want want; + abilityImpl_->Start(want); + EXPECT_EQ(abilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AbilityRuntime_Start_0400 end"; +} + +/** + * @tc.number: AbilityRuntime_Start_0500 + * @tc.name: Start + * @tc.desc: abilityInfo is nullptr, Verify Start failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Start_0500, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Start_0500 start"; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + abilityImpl_->ability_ = uiability; + Want want; + abilityImpl_->Start(want); + EXPECT_EQ(abilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AbilityRuntime_Start_0500 end"; +} + +/** + * @tc.number: AbilityRuntime_Start_0600 + * @tc.name: Start + * @tc.desc: abilityLifecycleCallbacks_ is nullptr, Verify Start failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Start_0600, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Start_0600 start"; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + abilityImpl_->abilityLifecycleCallbacks_ = nullptr; + Want want; + abilityImpl_->Start(want); + EXPECT_EQ(abilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AbilityRuntime_Start_0600 end"; +} + +/** + * @tc.number: AbilityRuntime_Stop_0200 + * @tc.name: Stop + * @tc.desc: uiability is nullptr, Verify Stop failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Stop_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0200 start"; + abilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + abilityImpl_->ability_ = nullptr; + abilityImpl_->Stop(); + EXPECT_EQ(abilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_Stop_0300 + * @tc.name: Stop + * @tc.desc: abilityInfo is nullptr, Verify Stop failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Stop_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0300 start"; + abilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + abilityImpl_->ability_ = uiability; + abilityImpl_->Stop(); + EXPECT_EQ(abilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0300 end"; +} + +/** + * @tc.number: AbilityRuntime_Stop_0400 + * @tc.name: Stop + * @tc.desc: abilityLifecycleCallbacks_ is nullptr, Verify Stop failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Stop_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0400 start"; + abilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + abilityImpl_->abilityLifecycleCallbacks_ = nullptr; + abilityImpl_->Stop(); + EXPECT_EQ(abilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0400 end"; +} + +/** + * @tc.number: AbilityRuntime_Stop_0500 + * @tc.name: Stop + * @tc.desc: uiability is nullptr, Verify Stop failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Stop_0500, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0500 start"; + abilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + abilityImpl_->ability_ = nullptr; + bool isAsyncCallback = true; + abilityImpl_->Stop(isAsyncCallback); + EXPECT_FALSE(isAsyncCallback); + EXPECT_EQ(abilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0500 end"; +} + +/** + * @tc.number: AbilityRuntime_Stop_0600 + * @tc.name: Stop + * @tc.desc: abilityInfo is nullptr, Verify Stop failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Stop_0600, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0600 start"; + abilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + abilityImpl_->ability_ = uiability; + bool isAsyncCallback = true; + abilityImpl_->Stop(isAsyncCallback); + EXPECT_FALSE(isAsyncCallback); + EXPECT_EQ(abilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0600 end"; +} + +/** + * @tc.number: AbilityRuntime_Stop_0700 + * @tc.name: Stop + * @tc.desc: abilityLifecycleCallbacks_ is nullptr, Verify Stop failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Stop_0700, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0700 start"; + abilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + abilityImpl_->abilityLifecycleCallbacks_ = nullptr; + bool isAsyncCallback = true; + abilityImpl_->Stop(isAsyncCallback); + EXPECT_FALSE(isAsyncCallback); + EXPECT_EQ(abilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0700 end"; +} + +/** + * @tc.number: AbilityRuntime_Stop_0800 + * @tc.name: Stop + * @tc.desc: Verify Stop succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_Stop_0800, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0800 start"; + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "uiAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr uiability; + MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility(); + EXPECT_NE(pMocKUIAbility, nullptr); + if (pMocKUIAbility != nullptr) { + uiability.reset(pMocKUIAbility); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->Init(application, record, uiability, handler, token); + abilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + bool isAsyncCallback = false; + abilityImpl_->Stop(isAsyncCallback); + EXPECT_EQ(MockUIAbility::Event::ON_STOP, pMocKUIAbility->state_); + EXPECT_EQ(abilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_STOPED_NEW); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_Stop_0800 end"; +} + +/** + * @tc.number: AbilityRuntime_StopCallback_0200 + * @tc.name: StopCallback + * @tc.desc: uiability is nullptr, Verify StopCallback failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_StopCallback_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_StopCallback_0200 start"; + abilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + abilityImpl_->ability_ = nullptr; + abilityImpl_->StopCallback(); + EXPECT_EQ(abilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AbilityRuntime_StopCallback_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_StopCallback_0300 + * @tc.name: StopCallback + * @tc.desc: abilityInfo is nullptr, Verify StopCallback failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_StopCallback_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_StopCallback_0300 start"; + abilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + abilityImpl_->ability_ = uiability; + abilityImpl_->StopCallback(); + EXPECT_EQ(abilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AbilityRuntime_StopCallback_0300 end"; +} + +/** + * @tc.number: AbilityRuntime_StopCallback_0400 + * @tc.name: StopCallback + * @tc.desc: abilityLifecycleCallbacks_ is nullptr, Verify Stop failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_StopCallback_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_StopCallback_0400 start"; + abilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + abilityImpl_->abilityLifecycleCallbacks_ = nullptr; + abilityImpl_->StopCallback(); + EXPECT_EQ(abilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AbilityRuntime_StopCallback_0400 end"; +} + +/** + * @tc.number: AbilityRuntime_DispatchSaveAbilityState_0100 + * @tc.name: DispatchSaveAbilityState + * @tc.desc: uiability is nullptr, Verify DispatchSaveAbilityState failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_DispatchSaveAbilityState_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DispatchSaveAbilityState_0100 start"; + abilityImpl_->ability_ = nullptr; + abilityImpl_->DispatchSaveAbilityState(); + EXPECT_FALSE(abilityImpl_->needSaveDate_); + GTEST_LOG_(INFO) << "AbilityRuntime_DispatchSaveAbilityState_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_DispatchSaveAbilityState_0200 + * @tc.name: DispatchSaveAbilityState + * @tc.desc: abilityLifecycleCallbacks_ is nullptr, Verify DispatchSaveAbilityState failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_DispatchSaveAbilityState_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DispatchSaveAbilityState_0200 start"; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + abilityImpl_->abilityLifecycleCallbacks_ = nullptr; + abilityImpl_->DispatchSaveAbilityState(); + EXPECT_FALSE(abilityImpl_->needSaveDate_); + GTEST_LOG_(INFO) << "AbilityRuntime_DispatchSaveAbilityState_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_DispatchRestoreAbilityState_0100 + * @tc.name: DispatchRestoreAbilityState + * @tc.desc: uiability is nullptr, Verify DispatchRestoreAbilityState failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_DispatchRestoreAbilityState_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DispatchRestoreAbilityState_0100 start"; + abilityImpl_->ability_ = nullptr; + PacMap inState; + abilityImpl_->DispatchRestoreAbilityState(inState); + EXPECT_FALSE(abilityImpl_->hasSaveData_); + GTEST_LOG_(INFO) << "AbilityRuntime_DispatchRestoreAbilityState_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_HandleAbilityTransaction_0100 + * @tc.name: HandleAbilityTransaction + * @tc.desc: Verify HandleAbilityTransaction succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_HandleAbilityTransaction_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_HandleAbilityTransaction_0100 start"; + Want want; + AAFwk::LifeCycleStateInfo targetState; + ASSERT_NE(abilityImpl_, nullptr); + abilityImpl_->HandleAbilityTransaction(want, targetState); + GTEST_LOG_(INFO) << "AbilityRuntime_HandleAbilityTransaction_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_AbilityTransactionCallback_0100 + * @tc.name: AbilityTransactionCallback + * @tc.desc: Verify AbilityTransactionCallback succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AbilityTransactionCallback_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AbilityTransactionCallback_0100 start"; + AAFwk::AbilityLifeCycleState state = AAFwk::ABILITY_STATE_INITIAL; + ASSERT_NE(abilityImpl_, nullptr); + abilityImpl_->AbilityTransactionCallback(state); + GTEST_LOG_(INFO) << "AbilityRuntime_AbilityTransactionCallback_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_SendResult_0100 + * @tc.name: SendResult + * @tc.desc: uiability is nullptr, Verify SendResult failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_SendResult_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0100 start"; + ASSERT_NE(abilityImpl_, nullptr); + abilityImpl_->ability_ = nullptr; + int32_t requestCode = 0; + int32_t resultCode = 0; + Want resultData; + abilityImpl_->SendResult(requestCode, resultCode, resultData); + GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_NewWant_0100 + * @tc.name: NewWant + * @tc.desc: uiability is nullptr, Verify NewWant failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_NewWant_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_NewWant_0100 start"; + ASSERT_NE(abilityImpl_, nullptr); + abilityImpl_->ability_ = nullptr; + Want want; + abilityImpl_->NewWant(want); + GTEST_LOG_(INFO) << "AbilityRuntime_NewWant_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_SetLifeCycleStateInfo_0100 + * @tc.name: SetLifeCycleStateInfo + * @tc.desc: Verify SetLifeCycleStateInfo succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_SetLifeCycleStateInfo_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_SetLifeCycleStateInfo_0100 start"; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + AAFwk::LifeCycleStateInfo info; + info.isNewWant = true; + abilityImpl_->SetLifeCycleStateInfo(info); + auto state = abilityImpl_->ability_->GetLifeCycleStateInfo(); + EXPECT_TRUE(state.isNewWant); + GTEST_LOG_(INFO) << "AbilityRuntime_SetLifeCycleStateInfo_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_SetLifeCycleStateInfo_0200 + * @tc.name: SetLifeCycleStateInfo + * @tc.desc: Verify SetLifeCycleStateInfo succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_SetLifeCycleStateInfo_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_SetLifeCycleStateInfo_0200 start"; + ASSERT_NE(abilityImpl_, nullptr); + AAFwk::LifeCycleStateInfo info; + info.isNewWant = true; + abilityImpl_->SetLifeCycleStateInfo(info); + GTEST_LOG_(INFO) << "AbilityRuntime_SetLifeCycleStateInfo_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_CheckAndRestore_0100 + * @tc.name: CheckAndRestore + * @tc.desc: hasSaveData_ is false, Verify CheckAndRestore failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_CheckAndRestore_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_CheckAndRestore_0100 start"; + abilityImpl_->hasSaveData_ = false; + auto result = abilityImpl_->CheckAndRestore(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "AbilityRuntime_CheckAndRestore_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_CheckAndRestore_0200 + * @tc.name: CheckAndRestore + * @tc.desc: uiability is nullptr, Verify CheckAndRestore failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_CheckAndRestore_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_CheckAndRestore_0200 start"; + abilityImpl_->hasSaveData_ = true; + abilityImpl_->ability_ = nullptr; + auto result = abilityImpl_->CheckAndRestore(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "AbilityRuntime_CheckAndRestore_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_GetRestoreData_0100 + * @tc.name: GetRestoreData + * @tc.desc: Verify GetRestoreData succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_GetRestoreData_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_GetRestoreData_0100 start"; + PacMap pacMap; + std::string key = "key"; + pacMap.PutIntValue(key, 1); + abilityImpl_->restoreData_ = pacMap; + auto result = abilityImpl_->GetRestoreData(); + auto value = result.GetIntValue(key, 0); + EXPECT_EQ(value, 1); + GTEST_LOG_(INFO) << "AbilityRuntime_GetRestoreData_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_SetCallingContext_0100 + * @tc.name: SetCallingContext + * @tc.desc: Verify GetRestoreData succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_SetCallingContext_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_SetCallingContext_0100 start"; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + std::string deviceId = "deviceId"; + std::string bundleName = "bundleName"; + std::string abilityName = "abilityName"; + std::string moduleName = "moduleName"; + abilityImpl_->SetCallingContext(deviceId, bundleName, abilityName, moduleName); + auto element = abilityImpl_->ability_->GetCallingAbility(); + EXPECT_STREQ(element->GetDeviceID().c_str(), deviceId.c_str()); + EXPECT_STREQ(element->GetBundleName().c_str(), bundleName.c_str()); + EXPECT_STREQ(element->GetAbilityName().c_str(), abilityName.c_str()); + EXPECT_STREQ(element->GetModuleName().c_str(), moduleName.c_str()); + GTEST_LOG_(INFO) << "AbilityRuntime_SetCallingContext_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_ScheduleUpdateConfiguration_0100 + * @tc.name: ScheduleUpdateConfiguration + * @tc.desc: uiability is nullptr, Verify ScheduleUpdateConfiguration failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_ScheduleUpdateConfiguration_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_0100 start"; + ASSERT_NE(abilityImpl_, nullptr); + abilityImpl_->ability_ = nullptr; + Configuration config; + abilityImpl_->ScheduleUpdateConfiguration(config); + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_ContinueAbility_0100 + * @tc.name: ContinueAbility + * @tc.desc: uiability is nullptr, Verify ContinueAbility failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_ContinueAbility_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ContinueAbility_0100 start"; + ASSERT_NE(abilityImpl_, nullptr); + abilityImpl_->ability_ = nullptr; + std::string deviceId = "deviceId"; + uint32_t versionCode = 0; + abilityImpl_->ContinueAbility(deviceId, versionCode); + GTEST_LOG_(INFO) << "AbilityRuntime_ContinueAbility_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_ContinueAbility_0200 + * @tc.name: ContinueAbility + * @tc.desc: Verify ContinueAbility succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_ContinueAbility_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ContinueAbility_0200 start"; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + ASSERT_NE(contextDeal, nullptr); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + + std::string deviceId = "deviceId"; + uint32_t versionCode = 0; + abilityImpl_->ContinueAbility(deviceId, versionCode); + GTEST_LOG_(INFO) << "AbilityRuntime_ContinueAbility_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_NotifyContinuationResult_0100 + * @tc.name: NotifyContinuationResult + * @tc.desc: uiability is nullptr, Verify NotifyContinuationResult failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_NotifyContinuationResult_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyContinuationResult_0100 start"; + ASSERT_NE(abilityImpl_, nullptr); + abilityImpl_->ability_ = nullptr; + int32_t result = 0; + abilityImpl_->NotifyContinuationResult(result); + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyContinuationResult_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_NotifyContinuationResult_0200 + * @tc.name: NotifyContinuationResult + * @tc.desc: Verify NotifyContinuationResult succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_NotifyContinuationResult_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyContinuationResult_0200 start"; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + ASSERT_NE(contextDeal, nullptr); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + + int32_t result = 0; + abilityImpl_->NotifyContinuationResult(result); + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyContinuationResult_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_NotifyMemoryLevel_0100 + * @tc.name: NotifyMemoryLevel + * @tc.desc: uiability is nullptr, Verify NotifyMemoryLevel failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_NotifyMemoryLevel_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyMemoryLevel_0100 start"; + ASSERT_NE(abilityImpl_, nullptr); + abilityImpl_->ability_ = nullptr; + int32_t level = 0; + abilityImpl_->NotifyMemoryLevel(level); + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyMemoryLevel_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_NotifyMemoryLevel_0200 + * @tc.name: NotifyMemoryLevel + * @tc.desc: Verify NotifyMemoryLevel succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_NotifyMemoryLevel_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyMemoryLevel_0200 start"; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + ASSERT_NE(contextDeal, nullptr); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + + int32_t level = 0; + abilityImpl_->NotifyContinuationResult(level); + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyMemoryLevel_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterUnFocused_0100 + * @tc.name: AfterUnFocused + * @tc.desc: Verify AfterUnFocused succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterUnFocused_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterUnFocused_0100 start"; + ASSERT_NE(abilityImpl_, nullptr); + abilityImpl_->AfterUnFocused(); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterUnFocused_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterFocused_0100 + * @tc.name: AfterFocused + * @tc.desc: Verify AfterFocused succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterFocused_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocused_0100 start"; + ASSERT_NE(abilityImpl_, nullptr); + abilityImpl_->AfterFocused(); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocused_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterFocusedCommon_0100 + * @tc.name: AfterFocusedCommon + * @tc.desc: uiability is nullptr, Verify AfterFocusedCommon failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterFocusedCommon_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocusedCommon_0100 start"; + ASSERT_NE(abilityImpl_, nullptr); + abilityImpl_->AfterFocusedCommon(true); + abilityImpl_->AfterFocusedCommon(false); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocusedCommon_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterFocusedCommon_0200 + * @tc.name: AfterFocusedCommon + * @tc.desc: abilityInfo is nullptr, Verify AfterFocusedCommon failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterFocusedCommon_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocusedCommon_0200 start"; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + ASSERT_NE(uiability, nullptr); + abilityImpl_->ability_ = uiability; + abilityImpl_->AfterFocusedCommon(true); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocusedCommon_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterFocusedCommon_0300 + * @tc.name: AfterFocusedCommon + * @tc.desc: contextDeal_ is nullptr, Verify AfterFocusedCommon failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterFocusedCommon_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocusedCommon_0300 start"; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + ASSERT_NE(contextDeal, nullptr); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + abilityImpl_->AfterFocusedCommon(true); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocusedCommon_0300 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterFocusedCommon_0400 + * @tc.name: AfterFocusedCommon + * @tc.desc: handler_ is nullptr, Verify AfterFocusedCommon failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterFocusedCommon_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocusedCommon_0400 start"; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + auto abilityInfo = std::make_shared(); + auto contextDeal = std::make_shared(); + ASSERT_NE(contextDeal, nullptr); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + abilityImpl_->AfterFocusedCommon(true); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocusedCommon_0400 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterFocusedCommon_0500 + * @tc.name: AfterFocusedCommon + * @tc.desc: Verify AfterFocusedCommon succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterFocusedCommon_0500, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocusedCommon_0500 start"; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + auto abilityInfo = std::make_shared(); + abilityInfo->isStageBasedModel = true; + auto contextDeal = std::make_shared(); + ASSERT_NE(contextDeal, nullptr); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + auto eventRunner = EventRunner::Create(abilityInfo->name); + auto handler = std::make_shared(eventRunner); + abilityImpl_->handler_ = handler; + abilityImpl_->AfterFocusedCommon(true); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocusedCommon_0500 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterFocusedCommon_0600 + * @tc.name: AfterFocusedCommon + * @tc.desc: Verify AfterFocusedCommon succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterFocusedCommon_0600, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocusedCommon_0600 start"; + std::shared_ptr pMocKUIAbility = std::make_shared(); + std::shared_ptr uiability = pMocKUIAbility; + auto abilityInfo = std::make_shared(); + abilityInfo->isStageBasedModel = false; + auto contextDeal = std::make_shared(); + ASSERT_NE(contextDeal, nullptr); + contextDeal->SetAbilityInfo(abilityInfo); + uiability->AttachBaseContext(contextDeal); + abilityImpl_->ability_ = uiability; + auto eventRunner = EventRunner::Create(abilityInfo->name); + auto handler = std::make_shared(eventRunner); + abilityImpl_->handler_ = handler; + abilityImpl_->AfterFocusedCommon(true); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterFocusedCommon_0600 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterForeground_0100 + * @tc.name: AfterForeground + * @tc.desc: Verify AfterForeground succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterForeground_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterForeground_0100 start"; + auto abilityImpl = std::make_shared(); + abilityImpl->isStageBasedModel_ = true; + abilityImpl->notifyForegroundByAbility_ = true; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl->AfterForeground(); + EXPECT_FALSE(abilityImpl->notifyForegroundByAbility_); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterForeground_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterForeground_0200 + * @tc.name: AfterForeground + * @tc.desc: Verify AfterForeground succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterForeground_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterForeground_0200 start"; + auto abilityImpl = std::make_shared(); + abilityImpl->isStageBasedModel_ = true; + abilityImpl->notifyForegroundByAbility_ = false; + abilityImpl->notifyForegroundByWindow_ = false; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl->AfterForeground(); + EXPECT_TRUE(abilityImpl->notifyForegroundByWindow_); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterForeground_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterForeground_0300 + * @tc.name: AfterForeground + * @tc.desc: Verify AfterForeground failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterForeground_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterForeground_0300 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, nullptr); + ASSERT_NE(impl, nullptr); + impl->AfterForeground(); + auto abilityImpl = std::make_shared(); + abilityImpl->isStageBasedModel_ = false; + abilityImpl->notifyForegroundByAbility_ = false; + abilityImpl->notifyForegroundByWindow_ = false; + sptr impl1 = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl1->AfterForeground(); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterForeground_0300 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterBackground_0100 + * @tc.name: AfterBackground + * @tc.desc: Verify AfterBackground failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterBackground_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterBackground_0100 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, nullptr); + impl->AfterBackground(); + ASSERT_NE(impl, nullptr); + auto abilityImpl = std::make_shared(); + abilityImpl->isStageBasedModel_ = false; + abilityImpl->notifyForegroundByAbility_ = false; + abilityImpl->notifyForegroundByWindow_ = false; + sptr impl1 = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl1->AfterBackground(); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterBackground_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterBackground_0200 + * @tc.name: AfterBackground + * @tc.desc: Verify AfterBackground succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterBackground_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterBackground_0200 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + auto abilityImpl = std::make_shared(); + ASSERT_NE(abilityImpl, nullptr); + abilityImpl->isStageBasedModel_ = true; + abilityImpl->notifyForegroundByAbility_ = false; + abilityImpl->notifyForegroundByWindow_ = false; + sptr impl = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl->AfterBackground(); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterBackground_0200 end"; +} + +/** + * @tc.number: AaFwk_WindowLifeCycleImpl_0100 + * @tc.name: AfterFocused + * @tc.desc: Verify AfterFocused succeeded. + */ +HWTEST_F(UIAbilityImplTest, AaFwk_WindowLifeCycleImpl_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_WindowLifeCycleImpl_0100 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + auto abilityImpl = std::make_shared(); + ASSERT_NE(abilityImpl, nullptr); + sptr impl = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl->AfterFocused(); + GTEST_LOG_(INFO) << "AaFwk_WindowLifeCycleImpl_0100 end"; +} + +/** + * @tc.number: AaFwk_WindowLifeCycleImpl_0200 + * @tc.name: AfterFocused + * @tc.desc: abilityImpl is nullptr, Verify AfterFocused failed. + */ +HWTEST_F(UIAbilityImplTest, AaFwk_WindowLifeCycleImpl_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_WindowLifeCycleImpl_0200 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, nullptr); + ASSERT_NE(impl, nullptr); + impl->AfterFocused(); + GTEST_LOG_(INFO) << "AaFwk_WindowLifeCycleImpl_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterUnfocused_0100 + * @tc.name: AfterUnfocused + * @tc.desc: abilityImpl is nullptr, Verify AfterUnfocused failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterUnfocused_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterUnfocused_0100 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, nullptr); + ASSERT_NE(impl, nullptr); + impl->AfterUnfocused(); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterUnfocused_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_AfterUnfocused_0200 + * @tc.name: AfterUnfocused + * @tc.desc: Verify AfterUnfocused succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_AfterUnfocused_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_AfterUnfocused_0200 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + auto abilityImpl = std::make_shared(); + sptr impl = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + ASSERT_NE(impl, nullptr); + impl->AfterUnfocused(); + GTEST_LOG_(INFO) << "AbilityRuntime_AfterUnfocused_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_ForegroundFailed_0100 + * @tc.name: ForegroundFailed + * @tc.desc: Verify ForegroundFailed succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_ForegroundFailed_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ForegroundFailed_0100 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + auto abilityImpl = std::make_shared(); + sptr impl = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + ASSERT_NE(impl, nullptr); + auto wmErrNoMem = 2; + impl->ForegroundFailed(wmErrNoMem); + GTEST_LOG_(INFO) << "AbilityRuntime_ForegroundFailed_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_ForegroundFailed_0200 + * @tc.name: ForegroundFailed + * @tc.desc: Verify ForegroundFailed failed. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_ForegroundFailed_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ForegroundFailed_0200 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, nullptr); + ASSERT_NE(impl, nullptr); + auto wmErrInvalidWindowModeOrSize = 5; + impl->ForegroundFailed(wmErrInvalidWindowModeOrSize); + auto abilityImpl = std::make_shared(); + abilityImpl->isStageBasedModel_ = false; + sptr impl1 = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl1->ForegroundFailed(wmErrInvalidWindowModeOrSize); + GTEST_LOG_(INFO) << "AbilityRuntime_ForegroundFailed_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_ForegroundFailed_0300 + * @tc.name: ForegroundFailed + * @tc.desc: Verify ForegroundFailed succeeded. + */ +HWTEST_F(UIAbilityImplTest, AbilityRuntime_ForegroundFailed_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ForegroundFailed_0300 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + auto abilityImpl = std::make_shared(); + abilityImpl->isStageBasedModel_ = true; + sptr impl = + new (std::nothrow) UIAbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + ASSERT_NE(impl, nullptr); + auto wmErrInvalidWindowModeOrSize = 5; + impl->ForegroundFailed(wmErrInvalidWindowModeOrSize); + GTEST_LOG_(INFO) << "AbilityRuntime_ForegroundFailed_0300 end"; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp new file mode 100644 index 0000000000..ae06996f89 --- /dev/null +++ b/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp @@ -0,0 +1,1245 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public +#define protected public +#include "ui_ability.h" +#undef protected +#undef private +#include "ability_context_impl.h" +#include "ability_handler.h" +#include "ability_recovery.h" +#include "hilog_wrapper.h" +#include "ohos_application.h" +#include "runtime.h" + +namespace OHOS { +namespace AppExecFwk { +using namespace testing::ext; +using namespace OHOS; +using OHOS::Parcel; + +class UIAbilityBaseTest : public testing::Test { +public: + UIAbilityBaseTest() : ability_(nullptr) {} + ~UIAbilityBaseTest() {} + std::shared_ptr ability_; + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void UIAbilityBaseTest::SetUpTestCase(void) {} + +void UIAbilityBaseTest::TearDownTestCase(void) {} + +void UIAbilityBaseTest::SetUp(void) +{ + ability_ = std::make_shared(); +} + +void UIAbilityBaseTest::TearDown(void) {} + +/** + * @tc.number: AbilityRuntime_Name_0100 + * @tc.name: GetUIAbilityName + * @tc.desc: Verify that the return value of getabilityname is correct. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_Name_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Name_0100 start"; + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "UIability"; + std::shared_ptr application = std::make_shared(); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + EXPECT_STREQ(abilityInfo->name.c_str(), ability_->GetAbilityName().c_str()); + GTEST_LOG_(INFO) << "AbilityRuntime_Name_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_GetAbilityName_0100 + * @tc.name: GetAbilityName + * @tc.desc: Verify that the getabilityname return value is correct. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_GetAbilityName_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_GetAbilityName_0100 start"; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + sptr token = nullptr; + std::string name = "LOL"; + abilityInfo->name = name; + ability_->Init(abilityInfo, application, handler, token); + EXPECT_STREQ(ability_->GetAbilityName().c_str(), name.c_str()); + GTEST_LOG_(INFO) << "AbilityRuntime_GetAbilityName_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_GetLifecycle_0100 + * @tc.name: GetLifecycle + * @tc.desc: Verify that the return value of getlifecycle is not empty. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_GetLifecycle_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_GetLifecycle_0100 start"; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + std::shared_ptr lifeCycle = ability_->GetLifecycle(); + EXPECT_NE(lifeCycle, nullptr); + GTEST_LOG_(INFO) << "AaFwk_Ability_GetLifecycle_0100 end"; +} + +/** + * @tc.number: UIAbility_Create_0100 + * @tc.name: UIAbility_Create_0100 + * @tc.desc: Create JS ability. + */ +HWTEST_F(UIAbilityBaseTest, UIAbility_Create_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + AbilityRuntime::Runtime::Options options; + options.lang = AbilityRuntime::Runtime::Language::JS; + auto runtime = AbilityRuntime::Runtime::Create(options); + auto ability = AbilityRuntime::UIAbility::Create(runtime); + EXPECT_NE(ability, nullptr); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.number: UIAbility_Create_0200 + * @tc.name: UIAbility_Create_0200 + * @tc.desc: Create ability which runtime is nullptr. + */ +HWTEST_F(UIAbilityBaseTest, UIAbility_Create_0200, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + auto ability = AbilityRuntime::UIAbility::Create(nullptr); + EXPECT_NE(ability, nullptr); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.number: AbilityRuntime_OnNewWant_0100 + * @tc.name: OnNewWant + * @tc.desc: Test whether onnewwant can be called normally. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnNewWant_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_OnNewWant_0100 start"; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + Want want; + ability_->OnNewWant(want); + GTEST_LOG_(INFO) << "AbilityRuntime_OnNewWant_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_OnRestoreAbilityState_0100 + * @tc.name: OnRestoreAbilityState + * @tc.desc: Test whether onnewwant can be called normally. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnRestoreAbilityState_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_OnRestoreAbilityState_0100 start"; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + PacMap inState; + ability_->OnRestoreAbilityState(inState); + GTEST_LOG_(INFO) << "AbilityRuntime_OnRestoreAbilityState_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_TerminateAbility_0100 + * @tc.name: GetWindow + * @tc.desc: Test whether GetWindow is called normally. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_GetWindow_001, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_GetWindow_0100 start"; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + EXPECT_EQ(ability_->GetWindow(), nullptr); + GTEST_LOG_(INFO) << "AbilityRuntime_GetWindow_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_OnStart_0100 + * @tc.name: OnStart + * @tc.desc: Test whether OnStart is called normally and verify whether the members are correct. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnStart_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_OnStart_0100 start"; + std::shared_ptr abilityInfo = std::make_shared(); + AbilityType type = AbilityType::PAGE; + abilityInfo->type = type; + abilityInfo->isStageBasedModel = true; + std::shared_ptr application = nullptr; + std::shared_ptr handler = nullptr; + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + Want want; + ability_->OnStart(want); + AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); + std::shared_ptr lifeCycle = ability_->GetLifecycle(); + LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState(); + EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::STARTED_NEW, state); + EXPECT_EQ(LifeCycle::Event::ON_START, lifeCycleState); + GTEST_LOG_(INFO) << "AbilityRuntime_OnStart_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_OnStart_0200 + * @tc.name: OnStart + * @tc.desc: Test the OnStart exception. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnStart_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_OnStart_0200 start"; + Want want; + ability_->OnStart(want); + AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); + std::shared_ptr lifeCycle = ability_->GetLifecycle(); + EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED, state); + EXPECT_EQ(nullptr, lifeCycle); + GTEST_LOG_(INFO) << "AbilityRuntime_OnStart_0200 end"; +} + +/** + * @tc.name: AbilityRuntime_OnStart_0300 + * @tc.desc: UIAbility OnStart test when configuration is not nullptr. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnStart_0300, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + auto abilityInfo = std::make_shared(); + EXPECT_NE(abilityInfo, nullptr); + abilityInfo->name = "test_OnStart"; + abilityInfo->type = AbilityType::PAGE; + abilityInfo->isStageBasedModel = true; + auto application = std::make_shared(); + EXPECT_NE(application, nullptr); + Configuration config; + application->SetConfiguration(config); + auto eventRunner = EventRunner::Create(abilityInfo->name); + auto handler = std::make_shared(eventRunner); + sptr token = nullptr; + ability->Init(abilityInfo, application, handler, token); + Want want; + ability->OnStart(want); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: AbilityRuntime_OnStart_0400 + * @tc.desc: UIAbility OnStart test when ability lifecycle executor or lifecycle is nullptr. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnStart_0400, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + auto abilityInfo = std::make_shared(); + EXPECT_NE(abilityInfo, nullptr); + abilityInfo->name = "test_OnStart"; + abilityInfo->type = AbilityType::PAGE; + ability->abilityInfo_ = abilityInfo; + Want want; + ability->OnStart(want); + auto lifecycleExecutor = std::make_shared(); + ability->abilityLifecycleExecutor_ = lifecycleExecutor; + ability->OnStart(want); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.number: AbilityRuntime_OnStop_0100 + * @tc.name: OnStop + * @tc.desc: Test whether onstop is called normally and verify whether the members are correct. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnStop_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_OnStop_0100 start"; + std::shared_ptr abilityInfo = std::make_shared(); + AbilityType type = AbilityType::PAGE; + abilityInfo->type = type; + std::shared_ptr application = nullptr; + std::shared_ptr handler = nullptr; + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + ability_->OnStop(); + AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); + std::shared_ptr lifeCycle = ability_->GetLifecycle(); + LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState(); + EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::INITIAL, state); + EXPECT_EQ(LifeCycle::Event::ON_STOP, lifeCycleState); + GTEST_LOG_(INFO) << "AbilityRuntime_OnStop_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_OnStop_0200 + * @tc.name: OnStop + * @tc.desc: Test the OnStop exception. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnStop_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_OnStop_0200 start"; + ability_->OnStop(); + AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); + std::shared_ptr lifeCycle = ability_->GetLifecycle(); + EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED, state); + EXPECT_EQ(nullptr, lifeCycle); + GTEST_LOG_(INFO) << "AbilityRuntime_OnStop_0200 end"; +} + +/** + * @tc.name: AaFwk_Ability_OnStop_0300 + * @tc.desc: UIAbility OnStop test when ability recovery, window is not nullptr. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnStop_0300, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + auto abilityRecovery = std::make_shared(); + EXPECT_NE(abilityRecovery, nullptr); + ability->EnableAbilityRecovery(abilityRecovery); + ability->OnStop(); + + // window is not nullptr + int32_t displayId = 0; + sptr option = new Rosen::WindowOption(); + ability->InitWindow(displayId, option); + ability->OnStop(); + + // lifecycle is nullptr and lifecycle executor is not nullptr + auto lifecycleExecutor = std::make_shared(); + ability->abilityLifecycleExecutor_ = lifecycleExecutor; + ability->OnStop(); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: DestroyInstance_0100 + * @tc.desc: UIAbility DestroyInstance test. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, DestroyInstance_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + auto abilityInfo = std::make_shared(); + EXPECT_NE(abilityInfo, nullptr); + abilityInfo->name = "test_DestroyInstance"; + abilityInfo->type = AbilityType::PAGE; + abilityInfo->isStageBasedModel = false; + auto application = std::make_shared(); + EXPECT_NE(application, nullptr); + auto eventRunner = EventRunner::Create(abilityInfo->name); + auto handler = std::make_shared(eventRunner); + sptr token = nullptr; + ability->Init(abilityInfo, application, handler, token); + ability->DestroyInstance(); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.number: AbilityRuntime_OnForeground_0100 + * @tc.name: OnForeground + * @tc.desc: Test whether onforegroup is called normally, and verify whether the member is correct. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnForeground_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_OnForeground_0100 start"; + std::shared_ptr abilityInfo = std::make_shared(); + AbilityType type = AbilityType::PAGE; + abilityInfo->type = type; + std::shared_ptr application = nullptr; + std::shared_ptr handler = nullptr; + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + Want want; + ability_->OnForeground(want); + AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); + std::shared_ptr lifeCycle = ability_->GetLifecycle(); + LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState(); + EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::FOREGROUND_NEW, state); + EXPECT_EQ(LifeCycle::Event::ON_FOREGROUND, lifeCycleState); + GTEST_LOG_(INFO) << "AbilityRuntime_OnForeground_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_OnForeground_0200 + * @tc.name: OnForeground + * @tc.desc: Test the OnInactive exception. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnForeground_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_OnForeground_0200 start"; + Want want; + ability_->OnForeground(want); + AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); + std::shared_ptr lifeCycle = ability_->GetLifecycle(); + EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED, state); + EXPECT_EQ(nullptr, lifeCycle); + GTEST_LOG_(INFO) << "AbilityRuntime_OnForeground_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_OnForeground_0300 + * @tc.name: OnForeground + * @tc.desc: Test the OnForeground exception. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnForeground_0300, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_OnForeground_0300 start"; + std::shared_ptr abilityInfo = std::make_shared(); + AbilityType type = AbilityType::PAGE; + abilityInfo->type = type; + abilityInfo->isStageBasedModel = true; + std::shared_ptr application = nullptr; + std::shared_ptr handler = nullptr; + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + Want want; + ability_->OnForeground(want); + AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); + std::shared_ptr lifeCycle = ability_->GetLifecycle(); + LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState(); + EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::FOREGROUND_NEW, state); + EXPECT_EQ(LifeCycle::Event::ON_FOREGROUND, lifeCycleState); + GTEST_LOG_(INFO) << "AbilityRuntime_OnForeground_0300 end"; +} + +/** + * @tc.number: AbilityRuntime_OnBackground_0100 + * @tc.name: OnBackground + * @tc.desc: Test whether onbackground is called normally and verify whether the members are correct. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnBackground_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_OnBackground_0100 start"; + std::shared_ptr abilityInfo = std::make_shared(); + AbilityType type = AbilityType::PAGE; + abilityInfo->type = type; + std::shared_ptr application = nullptr; + std::shared_ptr handler = nullptr; + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + ability_->OnBackground(); + AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); + std::shared_ptr lifeCycle = ability_->GetLifecycle(); + LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState(); + EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::BACKGROUND_NEW, state); + EXPECT_EQ(LifeCycle::Event::ON_BACKGROUND, lifeCycleState); + GTEST_LOG_(INFO) << "AbilityRuntime_OnBackground_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_OnBackground_0200 + * @tc.name: OnBackground + * @tc.desc: Test the OnBackground exception. + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnBackground_0200, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_OnBackground_0200 start"; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr application = nullptr; + std::shared_ptr handler = nullptr; + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + ability_->OnBackground(); + AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); + std::shared_ptr lifeCycle = ability_->GetLifecycle(); + EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::BACKGROUND_NEW, state); + EXPECT_TRUE(lifeCycle); + GTEST_LOG_(INFO) << "AbilityRuntime_OnBackground_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_OnBackground_0300 + * @tc.name: OnBackground + * @tc.desc: Test the OnBackground exception. + */ +HWTEST_F(UIAbilityBaseTest, AaFwk_Ability_OnBackground_0300, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_OnBackground_0300 start"; + std::shared_ptr abilityInfo = std::make_shared(); + AbilityType type = AbilityType::PAGE; + abilityInfo->type = type; + abilityInfo->isStageBasedModel = true; + std::shared_ptr application = nullptr; + std::shared_ptr handler = nullptr; + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + ability_->OnBackground(); + AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); + std::shared_ptr lifeCycle = ability_->GetLifecycle(); + LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState(); + // Sence is nullptr, so lifecycle schedule failed. + EXPECT_NE(AbilityLifecycleExecutor::LifecycleState::INITIAL, state); + EXPECT_NE(LifeCycle::Event::UNDEFINED, lifeCycleState); + GTEST_LOG_(INFO) << "AbilityRuntime_OBackground_0300 end"; +} + +/** + * @tc.name: AaFwk_Ability_OnBackground_0400 + * @tc.desc: Ability OnBackground basic test. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnBackground_0400, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + // ability info is nullptr + ability->OnBackground(); + // stage mode, scene is not nullptr + auto abilityInfo = std::make_shared(); + EXPECT_NE(abilityInfo, nullptr); + abilityInfo->name = "test_OnStart"; + abilityInfo->type = AbilityType::PAGE; + abilityInfo->isStageBasedModel = true; + auto application = std::make_shared(); + EXPECT_NE(application, nullptr); + auto eventRunner = EventRunner::Create(abilityInfo->name); + auto handler = std::make_shared(eventRunner); + sptr token = nullptr; + ability->Init(abilityInfo, application, handler, token); + int32_t displayId = 0; + sptr option = new Rosen::WindowOption(); + ability->InitWindow(displayId, option); + ability->OnBackground(); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityCreate_0100 + * @tc.desc: UIAbility create test. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityCreate_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + AbilityRuntime::Runtime::Options options; + auto runtime = AbilityRuntime::Runtime::Create(options); + auto ability = AbilityRuntime::UIAbility::Create(runtime); + EXPECT_NE(ability, nullptr); + AbilityRuntime::Runtime::Options anotherOptions; + anotherOptions.lang = static_cast(100); // invalid Runtime::Language + auto anotherRuntime = AbilityRuntime::Runtime::Create(anotherOptions); + auto anotherAbility = AbilityRuntime::UIAbility::Create(anotherRuntime); + EXPECT_NE(anotherAbility, nullptr); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityOnStop_0100 + * @tc.desc: UIAbility onStop test. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityOnStop_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + bool isAsyncCallback = true; + ability_->OnStop(nullptr, isAsyncCallback); + ability_->OnStopCallback(); + EXPECT_EQ(isAsyncCallback, false); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityContinuation_0100 + * @tc.desc: UIAbility Continuation test. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityContinuation_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + + // branch when abilityContext_ is nullptr + auto ret = ability->IsRestoredInContinuation(); + EXPECT_EQ(ret, false); + auto abilityContext = std::make_shared(); + ability->AttachAbilityContext(abilityContext); + AAFwk::LaunchParam launchParam; + launchParam.launchReason = LaunchReason::LAUNCHREASON_START_ABILITY; + ability->SetLaunchParam(launchParam); + + // branch when launchReason is not LAUNCHREASON_CONTINUATION + ret = ability->IsRestoredInContinuation(); + EXPECT_EQ(ret, false); + launchParam.launchReason = LaunchReason::LAUNCHREASON_CONTINUATION; + ability->SetLaunchParam(launchParam); + + // branch when contentStorage_ is nullptr + ret = ability->IsRestoredInContinuation(); + EXPECT_EQ(ret, false); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityContinuation_0200 + * @tc.desc: UIAbility ShouldRecoverState test. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityContinuation_0200, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + + // branch when abilityRecovery_ is nullptr + Want want; + bool ret = ability->ShouldRecoverState(want); + EXPECT_EQ(ret, false); + ability->HandleCreateAsRecovery(want); + auto abilityRecovery = std::make_shared(); + ability->EnableAbilityRecovery(abilityRecovery); + + // branch when abilityContext_ is nullptr + want.SetParam(Want::PARAM_ABILITY_RECOVERY_RESTART, true); + ability->HandleCreateAsRecovery(want); + ret = ability->ShouldRecoverState(want); + EXPECT_EQ(ret, false); + auto abilityContext = std::make_shared(); + ability->AttachAbilityContext(abilityContext); + + // branch when contentStorage_ is nullpt + ret = ability->ShouldRecoverState(want); + EXPECT_EQ(ret, false); + + // branch when want parameter didn't set + ret = ability->ShouldRecoverState(want); + EXPECT_EQ(ret, false); + + // NativeEngine is hard to construct + want.SetParam(Want::PARAM_ABILITY_RECOVERY_RESTART, true); + ret = ability->ShouldRecoverState(want); + EXPECT_EQ(ret, false); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityContinuation_0300 + * @tc.desc: UIAbility NotifyContinuationResult test. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityContinuation_0300, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + std::shared_ptr pageAbilityInfo = std::make_shared(); + pageAbilityInfo->type = AppExecFwk::AbilityType::PAGE; + auto eventRunner = EventRunner::Create(pageAbilityInfo->name); + auto handler = std::make_shared(eventRunner); + ability->Init(pageAbilityInfo, nullptr, handler, nullptr); + Want want; + bool success = false; + ability->NotifyContinuationResult(want, success); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: InitConfigurationProperties_0100 + * @tc.desc: UIAbility InitConfigurationProperties test. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, InitConfigurationProperties_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + Configuration config; + config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, "en"); + config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE, "dark"); + config.AddItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE, "true"); + std::string language; + std::string colormode; + std::string hasPointerDevice; + ability->InitConfigurationProperties(config, language, colormode, hasPointerDevice); + EXPECT_EQ(language, "en"); + EXPECT_EQ(colormode, "dark"); + EXPECT_EQ(hasPointerDevice, "true"); + + // branch when setting is not nullptr + auto setting = std::make_shared(); + ability->SetStartAbilitySetting(setting); + ability->InitConfigurationProperties(config, language, colormode, hasPointerDevice); + EXPECT_EQ(language, "en"); + EXPECT_EQ(colormode, "dark"); + EXPECT_EQ(hasPointerDevice, "true"); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityOnMemoryLevel_0100 + * @tc.desc: UIAbility OnMemoryLevel test. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityOnMemoryLevel_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + int level = 0; + ability->OnMemoryLevel(level); + ability->scene_ = std::make_shared(); + ability->OnMemoryLevel(level); + auto contentInfo = ability->GetContentInfo(); + EXPECT_EQ(contentInfo, ""); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityVirtualFunc_0100 + * @tc.desc: UIAbility virtual function test, such as OnAbilityResult, IsTerminating and so on. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityVirtualFunc_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + Configuration configuration; + ability->OnConfigurationUpdated(configuration); + int requestCode = 0; + int resultCode = 0; + Want want; + ability->OnAbilityResult(requestCode, resultCode, want); + std::vector params; + std::vector info; + ability->Dump(params, info); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityVirtualFunc_0200 + * @tc.desc: UIAbility virtual function test, such as OnStartContinuation, OnSaveData and so on. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityVirtualFunc_0200, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + bool ret = ability->OnStartContinuation(); + EXPECT_EQ(ret, false); + WantParams data; + ret = ability->OnSaveData(data); + EXPECT_EQ(ret, false); + ret = ability->OnRestoreData(data); + EXPECT_EQ(ret, false); + int32_t reason = 0; + EXPECT_EQ(ability->OnSaveState(reason, data), 0); + int result = 0; + ability->OnCompleteContinuation(result); + ability->OnRemoteTerminated(); + AAFwk::LaunchParam launchParam; + ability->SetLaunchParam(launchParam); + (void)ability->GetLaunchParam(); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: DispatchLifecycleOnForeground_0200 + * @tc.desc: UIAbility DispatchLifecycleOnForeground test. + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, DispatchLifecycleOnForeground_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + + // lifecycle executor is nullptr + Want want; + ability->DispatchLifecycleOnForeground(want); + + // lifecycle is nullptr and lifecycle executor is not nullptr + auto lifecycleExecutor = std::make_shared(); + ability->abilityLifecycleExecutor_ = lifecycleExecutor; + ability->DispatchLifecycleOnForeground(want); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityFuncList_0100 + * @tc.desc: UIAbility function test, including CallRequest, IsUseNewStartUpRule and so on + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityFuncList_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + ability->CallRequest(); + AAFwk::Want want; + want.SetParam("component.startup.newRules", true); + ability->SetWant(want); + bool isNewRule = ability->IsUseNewStartUpRule(); + EXPECT_EQ(isNewRule, true); + auto abilityRecovery = std::make_shared(); + ability->EnableAbilityRecovery(abilityRecovery); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: AbilityFuncList_0200 + * @tc.desc: Ability function test, including OnLeaveForeground and so on + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityFuncList_0200, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + ability->OnLeaveForeground(); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityScene_0100 + * @tc.desc: UIAbility Scene test + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityScene_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + ability->OnSceneCreated(); + ability->OnSceneRestored(); + ability->onSceneDestroyed(); + auto scene = ability->GetScene(); + EXPECT_EQ(scene, nullptr); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityGetCurrentWindowMode_0100 + * @tc.desc: UIAbility GetCurrentWindowMode test + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, AbilityGetCurrentWindowMode_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + + // scene_ is nullptr + int windowMode = ability->GetCurrentWindowMode(); + EXPECT_EQ(windowMode, static_cast(Rosen::WindowMode::WINDOW_MODE_UNDEFINED)); + ability->scene_ = std::make_shared(); + windowMode = ability->GetCurrentWindowMode(); + EXPECT_EQ(windowMode, static_cast(Rosen::WindowMode::WINDOW_MODE_UNDEFINED)); + int32_t displayId = 0; + sptr option = new Rosen::WindowOption(); + ability->InitWindow(displayId, option); + windowMode = ability->GetCurrentWindowMode(); + EXPECT_EQ(windowMode, static_cast(Rosen::WindowMode::WINDOW_MODE_UNDEFINED)); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilitySetMissionLabel_0100 + * @tc.desc: UIAbility SetMissionLabel test + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilitySetMissionLabel_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + std::string label = "test_label"; + auto ret = ability->SetMissionLabel(label); + EXPECT_EQ(ret, -1); + + std::shared_ptr pageAbilityInfo = std::make_shared(); + pageAbilityInfo->type = AppExecFwk::AbilityType::PAGE; + pageAbilityInfo->isStageBasedModel = true; + std::shared_ptr eventRunner = EventRunner::Create(pageAbilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + ability->Init(pageAbilityInfo, nullptr, handler, nullptr); + ret = ability->SetMissionLabel(label); + EXPECT_EQ(ret, -1); + int32_t displayId = 0; + sptr option = new Rosen::WindowOption(); + ability->InitWindow(displayId, option); + ret = ability->SetMissionLabel(label); + EXPECT_EQ(ret, -1); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilitySetMissionIcon_0100 + * @tc.desc: UIAbility SetMissionIcon test + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilitySetMissionIcon_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + auto icon = std::make_shared(); + auto ret = ability->SetMissionIcon(icon); + EXPECT_EQ(ret, -1); + + std::shared_ptr pageAbilityInfo = std::make_shared(); + pageAbilityInfo->type = AppExecFwk::AbilityType::PAGE; + pageAbilityInfo->isStageBasedModel = true; + std::shared_ptr eventRunner = EventRunner::Create(pageAbilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + ability->Init(pageAbilityInfo, nullptr, handler, nullptr); + ret = ability->SetMissionIcon(icon); + EXPECT_EQ(ret, -1); + int32_t displayId = 0; + sptr option = new Rosen::WindowOption(); + ability->InitWindow(displayId, option); + ret = ability->SetMissionIcon(icon); + EXPECT_EQ(ret, -1); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityOnChange_0100 + * @tc.desc: UIAbility OnChange test + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityOnChange_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + std::shared_ptr pageAbilityInfo = std::make_shared(); + pageAbilityInfo->type = AppExecFwk::AbilityType::PAGE; + auto eventRunner = EventRunner::Create(pageAbilityInfo->name); + auto handler = std::make_shared(eventRunner); + ability->Init(pageAbilityInfo, nullptr, handler, nullptr); + + // application is nullptr + Rosen::DisplayId displayId = 0; + ability->OnCreate(displayId); + ability->OnDestroy(displayId); + ability->OnChange(displayId); + auto application = std::make_shared(); + EXPECT_NE(application, nullptr); + Configuration config; + config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE, "dark"); + application->SetConfiguration(config); + ability->Init(pageAbilityInfo, application, handler, nullptr); + ability->OnChange(displayId); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityOnDisplayMove_0100 + * @tc.desc: UIAbility OnDisplayMove test + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityOnDisplayMove_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + std::shared_ptr pageAbilityInfo = std::make_shared(); + pageAbilityInfo->type = AppExecFwk::AbilityType::PAGE; + auto eventRunner = EventRunner::Create(pageAbilityInfo->name); + auto handler = std::make_shared(eventRunner); + ability->Init(pageAbilityInfo, nullptr, handler, nullptr); + + // application is nullptr + Rosen::DisplayId fromDisplayId = 1; + Rosen::DisplayId toDisplayId = 0; + ability->OnDisplayMove(fromDisplayId, toDisplayId); + + auto application = std::make_shared(); + EXPECT_NE(application, nullptr); + Configuration config; + config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE, "dark"); + application->SetConfiguration(config); + ability->Init(pageAbilityInfo, application, handler, nullptr); + ability->OnDisplayMove(fromDisplayId, toDisplayId); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbilityRequestFocus_0100 + * @tc.desc: UIAbility RequestFocus test + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(UIAbilityBaseTest, UIAbilityRequestFocus_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + + // ability window is nullptr + Want want; + ability->RequestFocus(want); + std::shared_ptr pageAbilityInfo = std::make_shared(); + pageAbilityInfo->type = AppExecFwk::AbilityType::PAGE; + pageAbilityInfo->isStageBasedModel = true; + auto eventRunner = EventRunner::Create(pageAbilityInfo->name); + auto handler = std::make_shared(eventRunner); + ability->Init(pageAbilityInfo, nullptr, handler, nullptr); + + // window is nullptr + ability->RequestFocus(want); + int32_t displayId = 0; + sptr option = new Rosen::WindowOption(); + ability->InitWindow(displayId, option); + ability->RequestFocus(want); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.number: UIAbility_GetResourceManager_0100 + * @tc.name: GetResourceManager + * @tc.desc: Get ResourceManager by function GetResourceManager. + */ +HWTEST_F(UIAbilityBaseTest, UIAbility_GetResourceManager_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + auto resourceMgr = ability->GetResourceManager(); + EXPECT_EQ(resourceMgr, nullptr); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.number: UIAbility_OnStop_AsyncCallback_0100 + * @tc.name: OnStop + * @tc.desc: Verify OnStop with AsyncCallback. + */ +HWTEST_F(UIAbilityBaseTest, UIAbility_OnStop_AsyncCallback_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->type = AbilityType::PAGE; + std::shared_ptr application = nullptr; + std::shared_ptr handler = nullptr; + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + bool isAsyncCallback = false; + ability_->OnStop(nullptr, isAsyncCallback); + AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); + std::shared_ptr lifeCycle = ability_->GetLifecycle(); + LifeCycle::Event lifeCycleState = lifeCycle->GetLifecycleState(); + EXPECT_EQ(AbilityLifecycleExecutor::LifecycleState::INITIAL, state); + EXPECT_EQ(LifeCycle::Event::ON_STOP, lifeCycleState); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.number: UIAbility_OnConfigurationUpdatedNotify_0100 + * @tc.name: OnConfigurationUpdatedNotify + * @tc.desc: Verify OnConfigurationUpdatedNotify. + */ +HWTEST_F(UIAbilityBaseTest, UIAbility_OnConfigurationUpdatedNotify_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + Configuration configuration; + ability_->OnConfigurationUpdatedNotify(configuration); + EXPECT_NE(ability_, nullptr); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbility_InitWindow_0100 + * @tc.desc: InitWindow test + * @tc.desc: Verify function InitWindow. + */ +HWTEST_F(UIAbilityBaseTest, UIAbility_InitWindow_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "ability"; + AbilityType type = AbilityType::PAGE; + abilityInfo->type = type; + abilityInfo->isStageBasedModel = false; + std::shared_ptr application = std::make_shared(); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + int32_t displayId = 0; + sptr option = new Rosen::WindowOption(); + ability_->InitWindow(displayId, option); + ASSERT_NE(ability_, nullptr); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: SetSceneListener_0100 + * @tc.desc: SetSceneListener test + * @tc.desc: Verify function SetSceneListener. + */ +HWTEST_F(UIAbilityBaseTest, UIAbility_SetSceneListener_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + sptr listener; + ability_->SetSceneListener(listener); + ASSERT_NE(ability_, nullptr); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: Ability_GetWindowOption_0100 + * @tc.desc: GetWindowOption test + * @tc.desc: Verify function GetWindowOption. + */ +HWTEST_F(UIAbilityBaseTest, UIAbility_GetWindowOption_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "ability"; + AbilityType type = AbilityType::PAGE; + abilityInfo->type = type; + abilityInfo->isStageBasedModel = false; + std::shared_ptr application = std::make_shared(); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + CustomizeData custData = CustomizeData("ShowOnLockScreen", "0", ""); + std::vector vecCustData; + vecCustData.push_back(custData); + abilityInfo->metaData.customizeData = vecCustData; + Want want; + auto option = ability_->GetWindowOption(want); + ASSERT_NE(option, nullptr); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbility_DoOnForeground_0100 + * @tc.desc: DoOnForeground test + * @tc.desc: Verify function DoOnForeground when abilityWindow is not nullptr. + */ +HWTEST_F(UIAbilityBaseTest, UIAbility_DoOnForeground_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "ability"; + AbilityType type = AbilityType::PAGE; + abilityInfo->type = type; + abilityInfo->isStageBasedModel = false; + std::shared_ptr application = std::make_shared(); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + Want want; + ability_->DoOnForeground(want); + ASSERT_NE(ability_, nullptr); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: UIAbility_DoOnForeground_0200 + * @tc.desc: DoOnForeground test + * @tc.desc: Verify function DoOnForeground when abilityWindow is nullptr. + */ +HWTEST_F(UIAbilityBaseTest, UIAbility_DoOnForeground_0200, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "ability"; + AbilityType type = AbilityType::PAGE; + abilityInfo->type = type; + abilityInfo->isStageBasedModel = true; + std::shared_ptr application = std::make_shared(); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + sptr token = nullptr; + ability_->Init(abilityInfo, application, handler, token); + Want want; + ability_->DoOnForeground(want); + ASSERT_NE(ability_, nullptr); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: GetAbilityContext_0100 + * @tc.desc: GetAbilityContext test + * @tc.desc: Verify function GetAbilityContext. + */ +HWTEST_F(UIAbilityBaseTest, UIAbility_GetAbilityContext_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + auto abilityContext = ability_->GetAbilityContext(); + ASSERT_EQ(abilityContext, nullptr); + HILOG_INFO("%{public}s end.", __func__); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/frameworks_kits_ability_native_test/ui_ability_thread_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ui_ability_thread_test.cpp new file mode 100644 index 0000000000..9e76caf721 --- /dev/null +++ b/test/unittest/frameworks_kits_ability_native_test/ui_ability_thread_test.cpp @@ -0,0 +1,922 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#define private public +#define protected public +#include "ability_loader.h" +#include "ui_ability_thread.h" +#undef private +#undef protected +#include "ability_handler.h" +#include "ability_local_record.h" +#include "mock_ability_token.h" +#include "ohos_application.h" +#include "ui_ability_impl.h" + +namespace OHOS { +namespace AppExecFwk { +using namespace testing::ext; +using namespace OHOS; +using Want = OHOS::AAFwk::Want; + +static const int32_t STARTID = 0; +static const std::string DEVICE_ID = "deviceId"; +static const std::string TEST = "test"; +const unsigned int ZEROTAG = 0; + +class UIAbilityThreadTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp() override; + void TearDown() override; +}; + +void UIAbilityThreadTest::SetUpTestCase(void) {} + +void UIAbilityThreadTest::TearDownTestCase(void) {} + +void UIAbilityThreadTest::SetUp(void) {} + +void UIAbilityThreadTest::TearDown(void) {} + +/** + * @tc.number: AbilityRuntime_DumpAbilityInfo_0100 + * @tc.name: DumpAbilityInfo + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpAbilityInfo_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0100 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityRecord = + std::make_shared(abilityInfo, token); + std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); + abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); + + std::vector params; + std::vector info; + abilitythread->DumpAbilityInfo(params, info); + EXPECT_EQ(info.size(), ZEROTAG); + GTEST_LOG_(INFO) << "info:"; + for (auto item : info) { + GTEST_LOG_(INFO) << item; + } + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_DumpAbilityInfo_0200 + * @tc.name: DumpAbilityInfo + * @tc.desc: Test DumpAbilityInfo function when token_ and abilityHandler_ is not nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpAbilityInfo_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0200 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->token_ = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(abilitythread->token_, nullptr); + abilitythread->abilityHandler_ = std::make_shared(nullptr); + EXPECT_NE(abilitythread->abilityHandler_, nullptr); + std::vector params; + std::vector info; + abilitythread->DumpAbilityInfo(params, info); + GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_DumpAbilityInfo_0300 + * @tc.name: DumpAbilityInfo + * @tc.desc: Test DumpAbilityInfo function when abilityHandler_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpAbilityInfo_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0300 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->token_ = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(abilitythread->token_, nullptr); + EXPECT_EQ(abilitythread->abilityHandler_, nullptr); + std::vector params; + std::vector info; + abilitythread->DumpAbilityInfo(params, info); + GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0300 end"; +} + +/** + * @tc.number: AbilityRuntime_DumpAbilityInfo_0400 + * @tc.name: DumpAbilityInfo + * @tc.desc: Test DumpAbilityInfo function when token_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpAbilityInfo_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0400 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->token_ = nullptr; + EXPECT_EQ(abilitythread->token_, nullptr); + abilitythread->abilityHandler_ = std::make_shared(nullptr); + EXPECT_NE(abilitythread->abilityHandler_, nullptr); + std::vector params; + std::vector info; + abilitythread->DumpAbilityInfo(params, info); + GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0400 end"; +} + +/** + * @tc.number: AbilityRuntime_ScheduleSaveAbilityState_0100 + * @tc.name: ScheduleSaveAbilityState + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleSaveAbilityState_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleSaveAbilityState_0100 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityRecord = + std::make_shared(abilityInfo, token); + std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); + abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); + abilitythread->ScheduleSaveAbilityState(); + sleep(1); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleSaveAbilityState_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_ScheduleSaveAbilityState_0200 + * @tc.name: ScheduleSaveAbilityState + * @tc.desc: Test ScheduleSaveAbilityState function when abilityImpl_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleSaveAbilityState_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleSaveAbilityState_0200 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + abilitythread->ScheduleSaveAbilityState(); + } + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleSaveAbilityState_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_ScheduleRestoreAbilityState_0100 + * @tc.name: ScheduleRestoreAbilityState + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleRestoreAbilityState_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleRestoreAbilityState_0100 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityRecord = + std::make_shared(abilityInfo, token); + std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); + abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); + PacMap state; + abilitythread->ScheduleRestoreAbilityState(state); + sleep(1); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleRestoreAbilityState_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_ScheduleRestoreAbilityState_0200 + * @tc.name: ScheduleRestoreAbilityState + * @tc.desc: Test Attach_3_Param function when abilityImpl_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleRestoreAbilityState_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleRestoreAbilityState_0200 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + abilitythread->ScheduleSaveAbilityState(); + } + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleRestoreAbilityState_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_Attach_3_Param_0100 + * @tc.name: Attach + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_Attach_3_Param_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Attach_3_Param_0100 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityRecord = + std::make_shared(abilityInfo, token); + std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); + abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); + sleep(1); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_Attach_3_Param_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_Attach_3_Param_0200 + * @tc.name: Attach + * @tc.desc: Test Attach_3_Param function when application is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_Attach_3_Param_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Attach_3_Param_0200 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr application = nullptr; + std::shared_ptr abilityRecord = + std::make_shared(abilityInfo, token); + std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); + abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); + sleep(1); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_Attach_3_Param_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_Attach_2_Param_0100 + * @tc.name: Attach + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_Attach_2_Param_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Attach_2_Param_0100 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityRecord = + std::make_shared(abilityInfo, token); + abilitythread->Attach(application, abilityRecord, nullptr); + sleep(1); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_Attach_2_Param_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_Attach_2_Param_0200 + * @tc.name: Attach + * @tc.desc: Test Attach_2_Param function when application is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_Attach_2_Param_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_Attach_2_Param_0200 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr application = nullptr; + std::shared_ptr abilityRecord = + std::make_shared(abilityInfo, token); + std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); + abilitythread->Attach(application, abilityRecord, nullptr); + sleep(1); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_Attach_2_Param_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_ScheduleAbilityTransaction_0100 + * @tc.name: ScheduleAbilityTransaction + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleAbilityTransaction_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0100 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityRecord = + std::make_shared(abilityInfo, token); + std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); + abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); + Want want; + LifeCycleStateInfo lifeCycleStateInfo; + abilitythread->ScheduleAbilityTransaction(want, lifeCycleStateInfo); + sleep(1); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_ScheduleAbilityTransaction_0200 + * @tc.name: ScheduleAbilityTransaction + * @tc.desc: Validate when normally entering a string + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleAbilityTransaction_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0200 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityRecord = + std::make_shared(abilityInfo, token); + abilitythread->Attach(application, abilityRecord, nullptr); + Want want; + LifeCycleStateInfo lifeCycleStateInfo; + abilitythread->ScheduleAbilityTransaction(want, lifeCycleStateInfo); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0200 end"; +} + +/* + * @tc.number: AbilityRuntime_ScheduleAbilityTransaction_0300 + * @tc.name: ScheduleAbilityTransaction + * @tc.desc: Test ScheduleAbilityTransaction function when token_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleAbilityTransaction_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0100 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + abilitythread->token_ = nullptr; + EXPECT_EQ(abilitythread->token_, nullptr); + abilitythread->abilityHandler_ = std::make_shared(nullptr); + EXPECT_NE(abilitythread->abilityHandler_, nullptr); + Want want; + LifeCycleStateInfo lifeCycleStateInfo; + abilitythread->ScheduleAbilityTransaction(want, lifeCycleStateInfo); + } + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0300 end"; +} + +/** + * @tc.number: AbilityRuntime_ScheduleAbilityTransaction_0300 + * @tc.name: ScheduleAbilityTransaction + * @tc.desc: Test ScheduleAbilityTransaction function when token_ is not nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleAbilityTransaction_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0400 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->token_ = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(abilitythread->token_, nullptr); + Want want; + LifeCycleStateInfo lifeCycleStateInfo; + abilitythread->ScheduleAbilityTransaction(want, lifeCycleStateInfo); + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0400 end"; +} + +/** + * @tc.number: AbilityRuntime_ScheduleAbilityTransaction_0400 + * @tc.name: ScheduleAbilityTransaction + * @tc.desc: Test ScheduleAbilityTransaction function when abilityHandler_ and token_ is not nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleAbilityTransaction_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0500 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->token_ = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(abilitythread->token_, nullptr); + abilitythread->abilityHandler_ = std::make_shared(nullptr); + EXPECT_NE(abilitythread->abilityHandler_, nullptr); + Want want; + LifeCycleStateInfo lifeCycleStateInfo; + abilitythread->ScheduleAbilityTransaction(want, lifeCycleStateInfo); + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0500 end"; +} + +/** + * @tc.number: AbilityRuntime_SendResult_0100 + * @tc.name: SendResult + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_SendResult_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0100 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityRecord = + std::make_shared(abilityInfo, token); + std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr abilityimpl = + std::make_shared(); + abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); + int requestCode = 0; + int resultCode = 0; + Want want; + abilitythread->SendResult(requestCode, resultCode, want); + sleep(1); + } + } + GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_SendResult_0200 + * @tc.name: SendResult + * @tc.desc: Test SendResult function when abilityImpl_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_SendResult_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0200 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + if (abilitythread != nullptr) { + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, token); + std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); + abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); + int requestCode = 0; + int resultCode = 0; + Want want; + abilitythread->SendResult(requestCode, resultCode, want); + } + GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_SendResult_0300 + * @tc.name: SendResult + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_SendResult_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0300 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + auto abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + auto application = std::make_shared(); + auto abilityRecord = std::make_shared(abilityInfo, token); + std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); + abilitythread->Attach(application, abilityRecord, mainRunner, nullptr); + abilitythread->abilityImpl_ = std::make_shared(); + EXPECT_NE(abilitythread->abilityImpl_, nullptr); + EXPECT_NE(abilitythread->abilityHandler_, nullptr); + int requestCode = STARTID; + int resultCode = STARTID; + Want want; + abilitythread->SendResult(requestCode, resultCode, want); + GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0300 end"; +} + +/** + * @tc.number: AbilityRuntime_HandleAbilityTransaction_0100 + * @tc.name: HandleAbilityTransaction + * @tc.desc: Test HandleAbilityTransaction function when abilityImpl_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_HandleAbilityTransaction_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_HandleAbilityTransaction_0100 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + EXPECT_EQ(abilitythread->abilityImpl_, nullptr); + Want want; + LifeCycleStateInfo lifeCycleStateInfo; + abilitythread->HandleAbilityTransaction(want, lifeCycleStateInfo); + GTEST_LOG_(INFO) << "AbilityRuntime_HandleAbilityTransaction_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_HandleAbilityTransaction_0200 + * @tc.name: HandleAbilityTransaction + * @tc.desc: Test HandleAbilityTransaction function when abilityImpl_ is not nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_HandleAbilityTransaction_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_HandleAbilityTransaction_0200 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->abilityImpl_ = std::make_shared(); + EXPECT_NE(abilitythread->abilityImpl_, nullptr); + Want want; + LifeCycleStateInfo lifeCycleStateInfo; + abilitythread->HandleAbilityTransaction(want, lifeCycleStateInfo); + GTEST_LOG_(INFO) << "AbilityRuntime_HandleAbilityTransaction_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_ScheduleUpdateConfiguration_0100 + * @tc.name: ScheduleUpdateConfiguration + * @tc.desc: Test ScheduleUpdateConfiguration function when abilityHandler_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleUpdateConfiguration_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_0100 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + EXPECT_EQ(abilitythread->abilityHandler_, nullptr); + Configuration config; + abilitythread->ScheduleUpdateConfiguration(config); + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_ScheduleUpdateConfiguration_0200 + * @tc.name: ScheduleUpdateConfiguration + * @tc.desc: Test ScheduleUpdateConfiguration function when abilityHandler_ is not nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleUpdateConfiguration_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_0200 start"; + AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->abilityHandler_ = std::make_shared(nullptr); + EXPECT_NE(abilitythread->abilityHandler_, nullptr); + Configuration config; + abilitythread->ScheduleUpdateConfiguration(config); + GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_HandleUpdateConfiguration_0100 + * @tc.name: HandleUpdateConfiguration + * @tc.desc: Test HandleUpdateConfiguration function when abilityImpl_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_HandleUpdateConfiguration_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_HandleUpdateConfiguration_0100 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + EXPECT_EQ(abilitythread->abilityImpl_, nullptr); + Configuration config; + abilitythread->HandleUpdateConfiguration(config); + GTEST_LOG_(INFO) << "AbilityRuntime_HandleUpdateConfiguration_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_HandleUpdateConfiguration_0200 + * @tc.name: HandleUpdateConfiguration + * @tc.desc: Test HandleUpdateConfiguration function when abilityImpl_ is not nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_HandleUpdateConfiguration_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_HandleUpdateConfiguration_0200 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->abilityImpl_ = std::make_shared(); + EXPECT_NE(abilitythread->abilityImpl_, nullptr); + Configuration config; + abilitythread->HandleUpdateConfiguration(config); + GTEST_LOG_(INFO) << "AbilityRuntime_HandleUpdateConfiguration_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_ContinueAbility_0100 + * @tc.name: ContinueAbility + * @tc.desc: Test ContinueAbility function when abilityImpl_ is not nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ContinueAbility_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ContinueAbility_0100 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->abilityImpl_ = std::make_shared(); + EXPECT_NE(abilitythread->abilityImpl_, nullptr); + std::string deviceId = DEVICE_ID; + uint32_t versionCode = STARTID; + abilitythread->ContinueAbility(deviceId, versionCode); + GTEST_LOG_(INFO) << "AbilityRuntime_ContinueAbility_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_ContinueAbility_0200 + * @tc.name: ContinueAbility + * @tc.desc: Test ContinueAbility function when abilityImpl_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ContinueAbility_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_ContinueAbility_0200 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + EXPECT_EQ(abilitythread->abilityImpl_, nullptr); + std::string deviceId = DEVICE_ID; + uint32_t versionCode = STARTID; + abilitythread->ContinueAbility(deviceId, versionCode); + GTEST_LOG_(INFO) << "AbilityRuntime_ContinueAbility_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_NotifyContinuationResult_0100 + * @tc.name: NotifyContinuationResult + * @tc.desc: Test NotifyContinuationResult function when abilityImpl_ is not nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_NotifyContinuationResult_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyContinuationResult_0100 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->abilityImpl_ = std::make_shared(); + EXPECT_NE(abilitythread->abilityImpl_, nullptr); + int32_t result = STARTID; + abilitythread->NotifyContinuationResult(result); + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyContinuationResult_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_NotifyContinuationResult_0200 + * @tc.name: NotifyContinuationResult + * @tc.desc: Test NotifyContinuationResult function when abilityImpl_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_NotifyContinuationResult_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyContinuationResult_0200 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + EXPECT_EQ(abilitythread->abilityImpl_, nullptr); + int32_t result = STARTID; + abilitythread->NotifyContinuationResult(result); + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyContinuationResult_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_NotifyMemoryLevel_0100 + * @tc.name: NotifyMemoryLevel + * @tc.desc: Test NotifyMemoryLevel function when abilityImpl_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_NotifyMemoryLevel_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyMemoryLevel_0100 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + EXPECT_EQ(abilitythread->abilityImpl_, nullptr); + int32_t result = STARTID; + abilitythread->NotifyMemoryLevel(result); + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyMemoryLevel_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_NotifyMemoryLevel_0200 + * @tc.name: NotifyMemoryLevel + * @tc.desc: Test NotifyMemoryLevel function when abilityImpl_ is not nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_NotifyMemoryLevel_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyMemoryLevel_0200 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->abilityImpl_ = std::make_shared(); + EXPECT_NE(abilitythread->abilityImpl_, nullptr); + int32_t result = STARTID; + abilitythread->NotifyMemoryLevel(result); + GTEST_LOG_(INFO) << "AbilityRuntime_NotifyMemoryLevel_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_BuildAbilityContext_0100 + * @tc.name: BuildAbilityContext + * @tc.desc: Test BuildAbilityContext function when Parameters is not nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_BuildAbilityContext_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_BuildAbilityContext_0100 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + std::shared_ptr application = std::make_shared(); + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(abilityInfo, nullptr); + EXPECT_NE(application, nullptr); + EXPECT_NE(token, nullptr); + abilitythread->BuildAbilityContext(abilityInfo, application, token, nullptr); + GTEST_LOG_(INFO) << "AbilityRuntime_BuildAbilityContext_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_DumpAbilityInfoInner_0100 + * @tc.name: DumpAbilityInfoInner + * @tc.desc: Test DumpAbilityInfoInner function when currentAbility_ is not nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpAbilityInfoInner_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfoInner_0100 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->currentAbility_ = std::make_shared(); + EXPECT_NE(abilitythread->currentAbility_, nullptr); + abilitythread->abilityImpl_ = std::make_shared(); + EXPECT_NE(abilitythread->abilityImpl_, nullptr); + std::vector params; + std::vector info; + abilitythread->DumpAbilityInfoInner(params, info); + GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfoInner_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_DumpAbilityInfoInner_0200 + * @tc.name: DumpAbilityInfoInner + * @tc.desc: Test DumpAbilityInfoInner function when currentAbility_ is nulllptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpAbilityInfoInner_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfoInner_0200 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + EXPECT_EQ(abilitythread->currentAbility_, nullptr); + abilitythread->abilityImpl_ = std::make_shared(); + EXPECT_NE(abilitythread->abilityImpl_, nullptr); + std::vector params; + std::vector info; + abilitythread->DumpAbilityInfoInner(params, info); + GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfoInner_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_DumpOtherInfo_0100 + * @tc.name: DumpOtherInfo + * @tc.desc: Test DumpOtherInfo function when abilityHandler_ and currentAbility_ is not nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpOtherInfo_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DumpOtherInfo_0100 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->abilityHandler_ = std::make_shared(nullptr); + EXPECT_NE(abilitythread->abilityHandler_, nullptr); + auto abilityInfo = std::make_shared(); + abilityInfo->name = "MockUIAbility"; + abilityInfo->type = AbilityType::PAGE; + auto setRunner = EventRunner::Create(abilityInfo->name); + abilitythread->abilityHandler_->SetEventRunner(setRunner); + auto getRunner = abilitythread->abilityHandler_->GetEventRunner(); + EXPECT_NE(getRunner, nullptr); + abilitythread->currentAbility_ = std::make_shared(); + EXPECT_NE(abilitythread->currentAbility_, nullptr); + std::vector info; + abilitythread->DumpOtherInfo(info); + GTEST_LOG_(INFO) << "AbilityRuntime_DumpOtherInfo_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_DumpOtherInfo_0200 + * @tc.name: DumpOtherInfo + * @tc.desc: Test DumpOtherInfo function when abilityHandler_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpOtherInfo_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DumpOtherInfo_0200 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + EXPECT_EQ(abilitythread->abilityHandler_, nullptr); + std::vector info; + abilitythread->DumpOtherInfo(info); + GTEST_LOG_(INFO) << "AbilityRuntime_DumpOtherInfo_0200 end"; +} + +/** + * @tc.number: AbilityRuntime_DumpOtherInfo_0300 + * @tc.name: DumpOtherInfo + * @tc.desc: Test DumpOtherInfo function when currentAbility_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpOtherInfo_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_DumpOtherInfo_0300 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + abilitythread->abilityHandler_ = std::make_shared(nullptr); + EXPECT_NE(abilitythread->abilityHandler_, nullptr); + EXPECT_EQ(abilitythread->currentAbility_, nullptr); + std::vector info; + abilitythread->DumpOtherInfo(info); + GTEST_LOG_(INFO) << "AbilityRuntime_DumpOtherInfo_0300 end"; +} + +/** + * @tc.number: AbilityRuntime_CallRequest_0100 + * @tc.name: CallRequest + * @tc.desc: Test CallRequest function when abilityHandler_ and currentAbility_ is not nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_CallRequest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_CallRequest_0100 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + std::vector info; + abilitythread->abilityHandler_ = std::make_shared(nullptr); + EXPECT_NE(abilitythread->abilityHandler_, nullptr); + abilitythread->currentAbility_ = std::make_shared(); + EXPECT_NE(abilitythread->currentAbility_, nullptr); + abilitythread->CallRequest(); + GTEST_LOG_(INFO) << "AbilityRuntime_CallRequest_0100 end"; +} + +/** + * @tc.number: AbilityRuntime_CallRequest_0200 + * @tc.name: CallRequest + * @tc.desc: Test CallRequest function when abilityHandler_ and currentAbility_ is nullptr + */ +HWTEST_F(UIAbilityThreadTest, AbilityRuntime_CallRequest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AbilityRuntime_CallRequest_0200 start"; + AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread(); + EXPECT_NE(abilitythread, nullptr); + std::vector info; + EXPECT_EQ(abilitythread->abilityHandler_, nullptr); + EXPECT_EQ(abilitythread->currentAbility_, nullptr); + abilitythread->CallRequest(); + GTEST_LOG_(INFO) << "AbilityRuntime_CallRequest_0200 end"; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn index 286c56b902..139cebb66b 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn @@ -109,6 +109,7 @@ ohos_unittest("application_test") { "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", @@ -401,6 +402,7 @@ ohos_unittest("ability_stage_test") { "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", @@ -498,6 +500,7 @@ ohos_unittest("appfreeze_inner_test") { "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:app_context_utils", "${ability_runtime_native_path}/appkit:appkit_native", diff --git a/test/unittest/frameworks_kits_appkit_native_test/application_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/application_test.cpp index 0480741beb..9c79d1b7e5 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/application_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/application_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,9 +16,9 @@ #include #include "ohos_application.h" -#include "ability.h" #include "mock_ability_lifecycle_callbacks.h" #include "mock_element_callback.h" +#include "ui_ability.h" using namespace testing::ext; using namespace OHOS; @@ -67,7 +67,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_RegisterAbilityLifecycleCallbac std::shared_ptr callback = std::make_shared(); ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback); - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); ApplicationTest_->OnAbilityActive(ability); ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback); @@ -88,7 +88,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_RegisterAbilityLifecycleCallbac if (ApplicationTest_ != nullptr) { ApplicationTest_->RegisterAbilityLifecycleCallbacks(nullptr); - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); ApplicationTest_->OnAbilityActive(ability); } GTEST_LOG_(INFO) << "AppExecFwk_Application_RegisterAbilityLifecycleCallbacks_0200 end"; @@ -110,7 +110,7 @@ HWTEST_F( ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback); ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback); - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); ApplicationTest_->OnAbilityActive(ability); } GTEST_LOG_(INFO) << "AppExecFwk_Application_UnregisterAbilityLifecycleCallbacks_0100 end"; @@ -132,7 +132,7 @@ HWTEST_F( ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback); ApplicationTest_->UnregisterAbilityLifecycleCallbacks(nullptr); - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); ApplicationTest_->OnAbilityActive(ability); ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback); @@ -154,7 +154,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_OnAbilityStart_0100, Function | std::shared_ptr callback = std::make_shared(); ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback); - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); ApplicationTest_->OnAbilityStart(ability); ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback); @@ -176,7 +176,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_OnAbilityInactive_0100, Functio std::shared_ptr callback = std::make_shared(); ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback); - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); ApplicationTest_->OnAbilityInactive(ability); ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback); @@ -198,7 +198,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_OnAbilityBackground_0100, Funct std::shared_ptr callback = std::make_shared(); ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback); - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); ApplicationTest_->OnAbilityBackground(ability); ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback); @@ -220,7 +220,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_OnAbilityForeground_0100, Funct std::shared_ptr callback = std::make_shared(); ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback); - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); ApplicationTest_->OnAbilityForeground(ability); ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback); @@ -242,7 +242,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_OnAbilityActive_0100, Function std::shared_ptr callback = std::make_shared(); ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback); - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); ApplicationTest_->OnAbilityActive(ability); ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback); @@ -264,7 +264,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_OnAbilityStop_0100, Function | std::shared_ptr callback = std::make_shared(); ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback); - std::shared_ptr ability = std::make_shared(); + std::shared_ptr ability = std::make_shared(); ApplicationTest_->OnAbilityStop(ability); ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback);