Signed-off-by: donglin <donglin9@huawei.com>
Change-Id: I83d717678f5d91134336937d20b61d5723a901e9
This commit is contained in:
donglin
2022-12-27 17:04:43 +08:00
125 changed files with 12505 additions and 236 deletions
@@ -45,6 +45,7 @@ template("abilitymanager") {
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:runtime",
"access_token:libtokenid_sdk",
"c_utils:utils",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
@@ -27,11 +27,13 @@
#include "js_runtime_utils.h"
#include "napi/native_api.h"
#include "if_system_ability_manager.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "js_ability_manager_utils.h"
#include "event_runner.h"
#include "napi_common_configuration.h"
#include "tokenid_kit.h"
namespace OHOS {
namespace AbilityRuntime {
@@ -211,6 +213,14 @@ private:
NativeValue* OnGetTopAbility(NativeEngine &engine, const NativeCallbackInfo &info)
{
HILOG_INFO("%{public}s is called", __FUNCTION__);
#ifdef ENABLE_ERRCODE
auto selfToken = IPCSkeleton::GetSelfTokenID();
if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) {
HILOG_ERROR("This application is not system-app, can not use system-api");
ThrowError(engine, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
return engine.CreateUndefined();
}
#endif
AsyncTask::CompleteCallback complete =
[](NativeEngine &engine, AsyncTask &task, int32_t status) {
AppExecFwk::ElementName elementName = AbilityManagerClient::GetInstance()->GetTopAbility();
@@ -32,6 +32,7 @@ ohos_shared_library("appmanager") {
deps = [
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability/native:ability_business_error",
"${ability_runtime_services_path}/abilitymgr:abilityms",
]
@@ -188,7 +188,6 @@ private:
ThrowTooFewParametersError(engine);
return engine.CreateUndefined();
}
if (!CheckOnOffType(engine, info)) {
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return engine.CreateUndefined();
@@ -198,8 +197,13 @@ private:
napi_get_value_int64(reinterpret_cast<napi_env>(&engine),
reinterpret_cast<napi_value>(info.argv[INDEX_ONE]), &observerId);
std::lock_guard<std::mutex> lock(g_observerMutex);
if (observer_ == nullptr) {
HILOG_ERROR("observer_ is nullpter, please register first");
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return engine.CreateUndefined();
}
if (!observer_->FindObserverByObserverId(observerId)) {
HILOG_INFO("not find observer, observer:%{public}d", static_cast<int32_t>(observerId));
HILOG_ERROR("not find observer, observer:%{public}d", static_cast<int32_t>(observerId));
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return engine.CreateUndefined();
}
@@ -249,7 +253,7 @@ private:
task.ResolveWithNoError(engine, CreateJsAppStateDataArray(engine, list));
} else {
HILOG_ERROR("OnGetForegroundApplications failed error:%{public}d", ret);
task.Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_PERMISSION_DENIED));
task.Reject(engine, CreateJsError(engine, GetJsErrorCodeByNativeError(ret)));
}
};
@@ -275,7 +279,7 @@ private:
if (ret == 0) {
task.ResolveWithNoError(engine, CreateJsProcessRunningInfoArray(engine, infos));
} else {
task.Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_PERMISSION_DENIED));
task.Reject(engine, CreateJsError(engine, GetJsErrorCodeByNativeError(ret)));
}
};
@@ -28,6 +28,7 @@ ohos_shared_library("missionmanager") {
deps = [
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability/native:ability_business_error",
"${ability_runtime_services_path}/abilitymgr:abilityms",
]
@@ -151,7 +151,7 @@ private:
if (ret == CHECK_PERMISSION_FAILED) {
ThrowNoPermissionError(engine, PermissionConstants::PERMISSION_MANAGE_MISSION);
} else {
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INNER);
ThrowError(engine, GetJsErrorCodeByNativeError(ret));
}
return engine.CreateUndefined();
}
@@ -172,7 +172,7 @@ private:
}
int32_t missionListenerId = -1;
if (!ConvertFromJsValue(engine, info.argv[0], missionListenerId)) {
if (!ConvertFromJsValue(engine, info.argv[ARGC_ONE], missionListenerId)) {
HILOG_ERROR("Parse missionListenerId failed");
ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return engine.CreateUndefined();
+1
View File
@@ -40,6 +40,7 @@ ohos_shared_library("wantagent") {
"ability_runtime:abilitykit_native",
"ability_runtime:runtime",
"ability_runtime:wantagent_innerkits",
"access_token:libtokenid_sdk",
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
@@ -41,6 +41,7 @@ ohos_shared_library("wantagent_napi") {
"ability_runtime:abilitykit_native",
"ability_runtime:runtime",
"ability_runtime:wantagent_innerkits",
"access_token:libtokenid_sdk",
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
@@ -22,9 +22,12 @@
#include "ability_runtime_error_util.h"
#include "hilog_wrapper.h"
#include "ipc_skeleton.h"
#include "js_runtime_utils.h"
#include "napi_common.h"
#include "want_agent_helper.h"
#include "tokenid_kit.h"
using namespace OHOS::AbilityRuntime;
namespace OHOS {
#define NAPI_ASSERT_RETURN_NULL(env, assertion, message) \
@@ -926,6 +929,12 @@ NativeValue* JsWantAgent::OnNapiGetWant(NativeEngine &engine, NativeCallbackInfo
AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER);
return engine.CreateUndefined();
}
auto selfToken = IPCSkeleton::GetSelfTokenID();
if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) {
HILOG_ERROR("This application is not system-app, can not use system-api");
AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP);
return engine.CreateUndefined();
}
if (info.argv[0]->TypeOf() != NativeValueType::NATIVE_OBJECT) {
HILOG_ERROR("Wrong argument type. Object expected.");
@@ -243,23 +243,23 @@ void AbilityContextImpl::OnAbilityResult(int requestCode, int resultCode, const
HILOG_INFO("%{public}s. End calling OnAbilityResult.", __func__);
}
bool AbilityContextImpl::ConnectAbility(const AAFwk::Want& want, const sptr<AbilityConnectCallback>& connectCallback)
ErrCode AbilityContextImpl::ConnectAbility(const AAFwk::Want& want, const sptr<AbilityConnectCallback>& connectCallback)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_DEBUG("ConnectAbility begin, name:%{public}s.", abilityInfo_ == nullptr ? "" : abilityInfo_->name.c_str());
ErrCode ret = ConnectionManager::GetInstance().ConnectAbility(token_, want, connectCallback);
HILOG_INFO("AbilityContextImpl::ConnectAbility ErrorCode = %{public}d", ret);
return ret == ERR_OK;
return ret;
}
bool AbilityContextImpl::ConnectAbilityWithAccount(const AAFwk::Want& want, int accountId,
ErrCode AbilityContextImpl::ConnectAbilityWithAccount(const AAFwk::Want& want, int accountId,
const sptr<AbilityConnectCallback>& connectCallback)
{
HILOG_DEBUG("%{public}s begin.", __func__);
ErrCode ret =
ConnectionManager::GetInstance().ConnectAbilityWithAccount(token_, want, accountId, connectCallback);
HILOG_INFO("AbilityContextImpl::ConnectAbility ErrorCode = %{public}d", ret);
return ret == ERR_OK;
return ret;
}
void AbilityContextImpl::DisconnectAbility(const AAFwk::Want& want,
@@ -212,6 +212,7 @@ ohos_shared_library("abilitykit_native") {
"ability_runtime:runtime",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"hisysevent_native:libhisysevent",
@@ -26,33 +26,35 @@ namespace {
constexpr const char* TAG_PERMISSION = " permission:";
constexpr const char* ERROR_MSG_OK = "OK.";
constexpr const char* ERROR_MSG_PERMISSION_DENIED = "The application does not have permission to call the interface.";
constexpr const char* ERROR_MSG_NOT_SYSTEM_APP = "The application is not system-app, can not use system-api.";
constexpr const char* ERROR_MSG_INVALID_PARAM = "Invalid input parameter.";
constexpr const char* ERROR_MSG_SYSTEMCAP = "The specified SystemCapability name was not found.";
constexpr const char* ERROR_MSG_INNER = "Inner Error.";
constexpr const char* ERROR_MSG_INNER = "Internal error.";
constexpr const char* ERROR_MSG_RESOLVE_ABILITY = "The specified ability does not exist.";
constexpr const char* ERROR_MSG_INVALID_ABILITY_TYPE = "Ability type error. The specified ability type is wrong";
constexpr const char* ERROR_MSG_INVALID_ID = "The specified id does not exist.";
constexpr const char* ERROR_MSG_INVALID_ABILITY_TYPE = "Incorrect ability type.";
constexpr const char* ERROR_MSG_INVALID_ID = "Input error. The specified ID does not exist.";
constexpr const char* ERROR_MSG_INVISIBLE = "Can not start invisible component.";
constexpr const char* ERROR_MSG_STATIC_CFG_PERMISSION = "The specified process does not have the permission.";
constexpr const char* ERROR_MSG_CROSS_USER = "Can not cross user operations.";
constexpr const char* ERROR_MSG_CROWDTEST_EXPIRED = "Crowdtest App Expiration.";
constexpr const char* ERROR_MSG_WUKONG_MODE = "Cannot operate in wukong mode.";
constexpr const char* ERROR_MSG_CONTINUATION_FLAG = "StartAbility with continuation flags is not allowed!";
constexpr const char* ERROR_MSG_INVALID_CONTEXT = "Context does not exist!";
constexpr const char* ERROR_MSG_NETWORK_ABNORMAL = "Network error. The network is abnormal when free install.";
constexpr const char* ERROR_MSG_NOT_SUPPORT_FREE_INSTALL = "The Application does not support free install.";
constexpr const char* ERROR_MSG_NOT_TOP_ABILITY = "Not top ability, Can not free install ability.";
constexpr const char* ERROR_MSG_CROSS_USER = "Cross-user operations are not allowed.";
constexpr const char* ERROR_MSG_CROWDTEST_EXPIRED = "The crowdtesting application expires.";
constexpr const char* ERROR_MSG_WUKONG_MODE = "An ability cannot be started or stopped in Wukong mode.";
constexpr const char* ERROR_MSG_CONTINUATION_FLAG = "The call with the continuation flage is forbidden.";
constexpr const char* ERROR_MSG_INVALID_CONTEXT = "The context does not exist.";
constexpr const char* ERROR_MSG_NETWORK_ABNORMAL = "Network error.";
constexpr const char* ERROR_MSG_NOT_SUPPORT_FREE_INSTALL = "Installation-free is not supported.";
constexpr const char* ERROR_MSG_NOT_TOP_ABILITY = "The ability is not on the top of the UI.";
constexpr const char* ERROR_MSG_FREE_INSTALL_TOO_BUSY =
"Free install busyness. There are concurrent tasks waiting for retry.";
constexpr const char* ERROR_MSG_FREE_INSTALL_TIMEOUT = "Free install timeout.";
constexpr const char* ERROR_MSG_FREE_INSTALL_OTHERS = "Can not free install other ability.";
constexpr const char* ERROR_MSG_INVALID_CALLER = "Caller released, The caller has been released.";
constexpr const char* ERROR_MSG_NO_MISSION_ID = "The specified mission id does not exist.";
constexpr const char* ERROR_MSG_NO_MISSION_LISTENER = "The specified mission listener does not exist.";
"The installation-free service is busy. Try again later.";
constexpr const char* ERROR_MSG_FREE_INSTALL_TIMEOUT = "Installation-free timed out.";
constexpr const char* ERROR_MSG_FREE_INSTALL_OTHERS = "Installation-free is not allowed for other applications.";
constexpr const char* ERROR_MSG_INVALID_CALLER = "The caller has been released.";
constexpr const char* ERROR_MSG_NO_MISSION_ID = "The specified mission does not exist.";
constexpr const char* ERROR_MSG_NO_MISSION_LISTENER = "Input error. The specified mission listener does not exist.";
static std::unordered_map<AbilityErrorCode, const char*> ERR_CODE_MAP = {
{ AbilityErrorCode::ERROR_OK, ERROR_MSG_OK },
{ AbilityErrorCode::ERROR_CODE_PERMISSION_DENIED, ERROR_MSG_PERMISSION_DENIED },
{ AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP, ERROR_MSG_NOT_SYSTEM_APP },
{ AbilityErrorCode::ERROR_CODE_INVALID_PARAM, ERROR_MSG_INVALID_PARAM },
{ AbilityErrorCode::ERROR_CODE_SYSTEMCAP, ERROR_MSG_SYSTEMCAP },
{ AbilityErrorCode::ERROR_CODE_INNER, ERROR_MSG_INNER },
@@ -80,6 +82,8 @@ static std::unordered_map<AbilityErrorCode, const char*> ERR_CODE_MAP = {
static std::unordered_map<int32_t, AbilityErrorCode> INNER_TO_JS_ERROR_CODE_MAP {
{0, AbilityErrorCode::ERROR_OK},
{CHECK_PERMISSION_FAILED, AbilityErrorCode::ERROR_CODE_PERMISSION_DENIED},
{ERR_PERMISSION_DENIED, AbilityErrorCode::ERROR_CODE_PERMISSION_DENIED},
{ERR_NOT_SYSTEM_APP, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP},
{RESOLVE_ABILITY_ERR, AbilityErrorCode::ERROR_CODE_RESOLVE_ABILITY},
{ERR_WRONG_INTERFACE_CALL, AbilityErrorCode::ERROR_CODE_INVALID_ABILITY_TYPE},
{TARGET_ABILITY_NOT_SERVICE, AbilityErrorCode::ERROR_CODE_INVALID_ABILITY_TYPE},
@@ -418,6 +418,7 @@ void JsAbility::OnForeground(const Want &want)
void JsAbility::OnBackground()
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_DEBUG("OnBackground begin, ability is %{public}s.", GetAbilityName().c_str());
CallObjectMethod("onBackground");
Ability::OnBackground();
@@ -432,6 +433,7 @@ void JsAbility::OnBackground()
if (applicationContext != nullptr) {
applicationContext->DispatchOnAbilityBackground(jsAbilityObj_);
}
HILOG_DEBUG("OnBackground end, ability is %{public}s.", GetAbilityName().c_str());
}
std::unique_ptr<NativeReference> JsAbility::CreateAppWindowStage()
@@ -896,7 +898,16 @@ std::shared_ptr<AppExecFwk::ADelegatorAbilityProperty> JsAbility::CreateADelegat
{
auto property = std::make_shared<AppExecFwk::ADelegatorAbilityProperty>();
property->token_ = GetAbilityContext()->GetToken();
property->name_ = GetAbilityName();
if (GetApplicationInfo() == nullptr || GetApplicationInfo()->bundleName.empty()) {
property->name_ = GetAbilityName();
} else {
std::string::size_type pos = GetAbilityName().find(GetApplicationInfo()->bundleName);
if (pos == std::string::npos || pos != 0) {
property->name_ = GetApplicationInfo()->bundleName + "." + GetAbilityName();
} else {
property->name_ = GetAbilityName();
}
}
property->lifecycleState_ = GetState();
property->object_ = jsAbilityObj_;
@@ -24,6 +24,7 @@
#include "js_error_utils.h"
#include "js_runtime_utils.h"
#include "ability_runtime/js_caller_complex.h"
#include "ipc_skeleton.h"
#include "napi_common_ability.h"
#include "napi_common_start_options.h"
#include "napi_common_util.h"
@@ -33,6 +34,7 @@
#include "want.h"
#include "event_handler.h"
#include "hitrace_meter.h"
#include "tokenid_kit.h"
#ifdef SUPPORT_GRAPHICS
#include "pixel_map_napi.h"
@@ -45,7 +47,6 @@ constexpr size_t ARGC_ZERO = 0;
constexpr size_t ARGC_ONE = 1;
constexpr size_t ARGC_TWO = 2;
constexpr size_t ARGC_THREE = 3;
constexpr int32_t ERROR_CODE_ONE = 1;
class StartAbilityByCallParameters {
public:
@@ -69,6 +70,12 @@ NativeValue* JsAbilityContext::StartAbility(NativeEngine* engine, NativeCallback
return (me != nullptr) ? me->OnStartAbility(*engine, *info) : nullptr;
}
NativeValue* JsAbilityContext::StartRecentAbility(NativeEngine* engine, NativeCallbackInfo* info)
{
JsAbilityContext* me = CheckParamsAndGetThis<JsAbilityContext>(engine, info);
return (me != nullptr) ? me->OnStartAbility(*engine, *info, true) : nullptr;
}
NativeValue* JsAbilityContext::StartAbilityWithAccount(NativeEngine* engine, NativeCallbackInfo* info)
{
JsAbilityContext* me = CheckParamsAndGetThis<JsAbilityContext>(engine, info);
@@ -167,7 +174,7 @@ NativeValue* JsAbilityContext::IsTerminating(NativeEngine* engine, NativeCallbac
return (me != nullptr) ? me->OnIsTerminating(*engine, *info) : nullptr;
}
NativeValue* JsAbilityContext::OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info)
NativeValue* JsAbilityContext::OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info, bool isStartRecent)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_INFO("OnStartAbility is called.");
@@ -190,6 +197,12 @@ NativeValue* JsAbilityContext::OnStartAbility(NativeEngine& engine, NativeCallba
reinterpret_cast<napi_value>(info.argv[1]), startOptions);
unwrapArgc++;
}
if (isStartRecent) {
HILOG_INFO("OnStartRecentAbility is called");
want.SetParam(Want::PARAM_RESV_START_RECENT, true);
}
AsyncTask::CompleteCallback complete =
[weak = context_, want, startOptions, unwrapArgc](NativeEngine& engine, AsyncTask& task, int32_t status) {
auto context = weak.lock();
@@ -441,6 +454,12 @@ NativeValue* JsAbilityContext::OnStartAbilityForResult(NativeEngine& engine, Nat
NativeValue* JsAbilityContext::OnStartAbilityForResultWithAccount(NativeEngine& engine, NativeCallbackInfo& info)
{
HILOG_INFO("OnStartAbilityForResultWithAccount is called");
auto selfToken = IPCSkeleton::GetSelfTokenID();
if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) {
HILOG_ERROR("This application is not system-app, can not use system-api");
ThrowError(engine, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
return engine.CreateUndefined();
}
if (info.argc < ARGC_TWO) {
HILOG_ERROR("Not enough params");
ThrowTooFewParametersError(engine);
@@ -748,8 +767,11 @@ NativeValue* JsAbilityContext::OnConnectAbility(NativeEngine& engine, NativeCall
task.Reject(engine, CreateJsError(engine, 1, "Context is released"));
return;
}
if (!context->ConnectAbility(want, connection)) {
connection->CallJsFailed(ERROR_CODE_ONE);
HILOG_INFO("ConnectAbility connection:%{public}d", static_cast<int32_t>(connectId));
auto innerErrorCode = context->ConnectAbility(want, connection);
int32_t errcode = static_cast<int32_t>(AbilityRuntime::GetJsErrorCodeByNativeError(innerErrorCode));
if (errcode) {
connection->CallJsFailed(errcode);
}
task.Resolve(engine, engine.CreateUndefined());
};
@@ -811,9 +833,11 @@ NativeValue* JsAbilityContext::OnConnectAbilityWithAccount(NativeEngine& engine,
task.Reject(engine, CreateJsError(engine, 1, "Context is released"));
return;
}
HILOG_INFO("context->ConnectAbilityWithAccount connection:%{public}d", (int32_t)connectId);
if (!context->ConnectAbilityWithAccount(want, accountId, connection)) {
connection->CallJsFailed(ERROR_CODE_ONE);
HILOG_INFO("context->ConnectAbilityWithAccount connection:%{public}d", static_cast<int32_t>(connectId));
auto innerErrorCode = context->ConnectAbilityWithAccount(want, accountId, connection);
int32_t errcode = static_cast<int32_t>(AbilityRuntime::GetJsErrorCodeByNativeError(innerErrorCode));
if (errcode) {
connection->CallJsFailed(errcode);
}
task.Resolve(engine, engine.CreateUndefined());
};
@@ -1163,6 +1187,8 @@ NativeValue* CreateJsAbilityContext(NativeEngine& engine, std::shared_ptr<Abilit
JsAbilityContext::RequestPermissionsFromUser);
BindNativeFunction(engine, *object, "restoreWindowStage", moduleName, JsAbilityContext::RestoreWindowStage);
BindNativeFunction(engine, *object, "isTerminating", moduleName, JsAbilityContext::IsTerminating);
BindNativeFunction(engine, *object, "startRecentAbility", moduleName,
JsAbilityContext::StartRecentAbility);
#ifdef SUPPORT_GRAPHICS
BindNativeFunction(engine, *object, "setMissionLabel", moduleName, JsAbilityContext::SetMissionLabel);
@@ -155,7 +155,7 @@ private:
} else {
HILOG_ERROR("Failed to StartAbility, errorCode: %{public}d.", innerErrorCode);
task.Reject(engine,
NapiFormUtil::CreateErrorByInternalErrorCode(engine, ERR_APPEXECFWK_FORM_COMMON_CODE));
NapiFormUtil::CreateErrorByInternalErrorCode(engine, innerErrorCode));
}
};
@@ -72,6 +72,12 @@ public:
return (me != nullptr) ? me->OnStartAbility(*engine, *info) : nullptr;
}
static NativeValue* StartRecentAbility(NativeEngine* engine, NativeCallbackInfo* info)
{
JsServiceExtensionContext* me = CheckParamsAndGetThis<JsServiceExtensionContext>(engine, info);
return (me != nullptr) ? me->OnStartAbility(*engine, *info, true) : nullptr;
}
static NativeValue* StartAbilityByCall(NativeEngine* engine, NativeCallbackInfo* info)
{
JsServiceExtensionContext* me = CheckParamsAndGetThis<JsServiceExtensionContext>(engine, info);
@@ -134,7 +140,7 @@ public:
private:
std::weak_ptr<ServiceExtensionContext> context_;
NativeValue* OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info)
NativeValue* OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info, bool isStartRecent = false)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_INFO("OnStartAbility is called");
@@ -152,6 +158,11 @@ private:
return engine.CreateUndefined();
}
if (isStartRecent) {
HILOG_INFO("OnStartRecentAbility is called");
want.SetParam(Want::PARAM_RESV_START_RECENT, true);
}
AsyncTask::CompleteCallback complete =
[weak = context_, want, startOptions, unwrapArgc](NativeEngine& engine, AsyncTask& task, int32_t status) {
HILOG_INFO("startAbility begin");
@@ -872,6 +883,8 @@ NativeValue* CreateJsServiceExtensionContext(NativeEngine& engine, std::shared_p
JsServiceExtensionContext::StopServiceExtensionAbility);
BindNativeFunction(engine, *object, "stopServiceExtensionAbilityWithAccount", moduleName,
JsServiceExtensionContext::StopServiceExtensionAbilityWithAccount);
BindNativeFunction(engine, *object, "startRecentAbility", moduleName,
JsServiceExtensionContext::StartRecentAbility);
return objValue;
}
+1
View File
@@ -249,6 +249,7 @@ ohos_shared_library("app_context_utils") {
external_deps = [
"ability_runtime:ability_runtime_error_util",
"ability_runtime:runtime",
"access_token:libtokenid_sdk",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
@@ -204,16 +204,25 @@ AbilityDelegator::AbilityState AbilityDelegator::GetAbilityState(const sptr<IRem
std::shared_ptr<ADelegatorAbilityProperty> AbilityDelegator::GetCurrentTopAbility()
{
sptr<IRemoteObject> topAbilityToken;
if (AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility(topAbilityToken)) {
AppExecFwk::ElementName elementName = AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility();
std::string bundleName = elementName.GetBundleName();
std::string abilityName = elementName.GetAbilityName();
if (abilityName.empty()) {
HILOG_ERROR("Failed to get top ability");
return {};
}
if (!bundleName.empty()) {
std::string::size_type pos = abilityName.find(bundleName);
if (pos == std::string::npos || pos != 0) {
abilityName = bundleName + "." + abilityName;
}
}
std::unique_lock<std::mutex> lck(mutexAbilityProperties_);
auto existedProperty = FindPropertyByToken(topAbilityToken);
auto existedProperty = FindPropertyByName(abilityName);
if (!existedProperty) {
HILOG_WARN("Unknown ability token");
HILOG_WARN("Unknown ability name");
return {};
}
@@ -654,7 +663,31 @@ std::shared_ptr<ADelegatorAbilityProperty> AbilityDelegator::FindPropertyByToken
}
if (token == it->token_) {
HILOG_INFO("Porperty exists");
HILOG_INFO("Property exists");
return it;
}
}
return {};
}
std::shared_ptr<ADelegatorAbilityProperty> AbilityDelegator::FindPropertyByName(const std::string &name)
{
HILOG_INFO("Enter");
if (name.empty()) {
HILOG_WARN("Invalid input parameter");
return {};
}
for (const auto &it : abilityProperties_) {
if (!it) {
HILOG_WARN("Invalid ability property");
continue;
}
if (name == it->name_) {
HILOG_INFO("Property exists");
return it;
}
}
@@ -490,7 +490,7 @@ void ContextImpl::InitHapModuleInfo(const AppExecFwk::HapModuleInfo &hapModuleIn
std::shared_ptr<AppExecFwk::HapModuleInfo> ContextImpl::GetHapModuleInfo() const
{
if (hapModuleInfo_ == nullptr) {
HILOG_ERROR("ContextImpl::GetHapModuleInfo, hapModuleInfo is empty");
HILOG_DEBUG("ContextImpl::GetHapModuleInfo, hapModuleInfo is empty");
}
return hapModuleInfo_;
}
@@ -20,11 +20,13 @@
#include "ability_runtime_error_util.h"
#include "application_context.h"
#include "hilog_wrapper.h"
#include "ipc_skeleton.h"
#include "js_context_utils.h"
#include "js_data_struct_converter.h"
#include "js_hap_module_info_utils.h"
#include "js_resource_manager_utils.h"
#include "js_runtime_utils.h"
#include "tokenid_kit.h"
namespace OHOS {
namespace AbilityRuntime {
@@ -101,6 +103,8 @@ private:
NativeValue* OnGetArea(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnCreateModuleContext(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnGetApplicationContext(NativeEngine& engine, NativeCallbackInfo& info);
bool CheckCallerIsSystemApp();
std::shared_ptr<ApplicationContext> keepApplicationContext_;
std::shared_ptr<JsAbilityLifecycleCallback> callback_;
std::shared_ptr<JsEnvironmentCallback> envCallback_;
@@ -115,6 +119,12 @@ NativeValue *JsApplicationContextUtils::CreateBundleContext(NativeEngine *engine
NativeValue *JsApplicationContextUtils::OnCreateBundleContext(NativeEngine &engine, NativeCallbackInfo &info)
{
if (!CheckCallerIsSystemApp()) {
HILOG_ERROR("This application is not system-app, can not use system-api");
AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP);
return engine.CreateUndefined();
}
if (info.argc == 0) {
HILOG_ERROR("Not enough params");
AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER);
@@ -223,6 +233,12 @@ NativeValue* JsApplicationContextUtils::CreateModuleContext(NativeEngine* engine
NativeValue* JsApplicationContextUtils::OnCreateModuleContext(NativeEngine& engine, NativeCallbackInfo& info)
{
if (!CheckCallerIsSystemApp()) {
HILOG_ERROR("This application is not system-app, can not use system-api");
AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP);
return engine.CreateUndefined();
}
auto applicationContext = applicationContext_.lock();
if (!applicationContext) {
HILOG_WARN("applicationContext is already released");
@@ -857,6 +873,15 @@ NativeValue* JsApplicationContextUtils::OnGetApplicationContext(NativeEngine& en
nullptr);
return contextObj;
}
bool JsApplicationContextUtils::CheckCallerIsSystemApp()
{
auto selfToken = IPCSkeleton::GetSelfTokenID();
if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) {
return false;
}
return true;
}
} // namespace
NativeValue *CreateJsApplicationContext(NativeEngine &engine, std::shared_ptr<ApplicationContext> applicationContext,
@@ -17,11 +17,13 @@
#include "ability_runtime_error_util.h"
#include "hilog_wrapper.h"
#include "ipc_skeleton.h"
#include "js_application_context_utils.h"
#include "js_data_struct_converter.h"
#include "js_hap_module_info_utils.h"
#include "js_resource_manager_utils.h"
#include "js_runtime_utils.h"
#include "tokenid_kit.h"
#include "application_context.h"
namespace OHOS {
@@ -71,6 +73,7 @@ private:
NativeValue* OnSwitchArea(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnGetArea(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnCreateModuleContext(NativeEngine& engine, NativeCallbackInfo& info);
bool CheckCallerIsSystemApp();
std::shared_ptr<Context> keepContext_;
};
@@ -146,6 +149,12 @@ NativeValue* JsBaseContext::CreateModuleContext(NativeEngine* engine, NativeCall
NativeValue* JsBaseContext::OnCreateModuleContext(NativeEngine& engine, NativeCallbackInfo& info)
{
if (!CheckCallerIsSystemApp()) {
HILOG_ERROR("This application is not system-app, can not use system-api");
AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP);
return engine.CreateUndefined();
}
auto context = context_.lock();
if (!context) {
HILOG_WARN("context is already released");
@@ -200,7 +209,7 @@ NativeValue* JsBaseContext::OnCreateModuleContext(NativeEngine& engine, NativeCa
nativeObj->SetNativePointer(
workContext,
[](NativeEngine *, void *data, void *) {
HILOG_INFO("Finalizer for weak_ptr module context is called");
HILOG_DEBUG("Finalizer for weak_ptr module context is called");
delete static_cast<std::weak_ptr<Context> *>(data);
},
nullptr);
@@ -353,6 +362,12 @@ NativeValue* JsBaseContext::OnGetBundleCodeDir(NativeEngine& engine, NativeCallb
NativeValue* JsBaseContext::OnCreateBundleContext(NativeEngine& engine, NativeCallbackInfo& info)
{
if (!CheckCallerIsSystemApp()) {
HILOG_ERROR("This application is not system-app, can not use system-api");
AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP);
return engine.CreateUndefined();
}
if (info.argc == 0) {
HILOG_ERROR("Not enough params");
AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER);
@@ -399,7 +414,7 @@ NativeValue* JsBaseContext::OnCreateBundleContext(NativeEngine& engine, NativeCa
nativeObj->SetNativePointer(
workContext,
[](NativeEngine *, void *data, void *) {
HILOG_INFO("Finalizer for weak_ptr bundle context is called");
HILOG_DEBUG("Finalizer for weak_ptr bundle context is called");
delete static_cast<std::weak_ptr<Context> *>(data);
},
nullptr);
@@ -442,12 +457,21 @@ NativeValue* JsBaseContext::OnGetApplicationContext(NativeEngine& engine, Native
nativeObj->SetNativePointer(
workContext,
[](NativeEngine *, void *data, void *) {
HILOG_INFO("Finalizer for weak_ptr application context is called");
HILOG_DEBUG("Finalizer for weak_ptr application context is called");
delete static_cast<std::weak_ptr<ApplicationContext> *>(data);
},
nullptr);
return contextObj;
}
bool JsBaseContext::CheckCallerIsSystemApp()
{
auto selfToken = IPCSkeleton::GetSelfTokenID();
if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) {
return false;
}
return true;
}
} // namespace
NativeValue* AttachBaseContext(NativeEngine* engine, void* value, void* hint)
@@ -478,7 +502,7 @@ NativeValue* AttachBaseContext(NativeEngine* engine, void* value, void* hint)
auto workContext = new (std::nothrow) std::weak_ptr<Context>(ptr);
nObject->SetNativePointer(workContext,
[](NativeEngine *, void *data, void *) {
HILOG_INFO("Finalizer for weak_ptr base context is called");
HILOG_DEBUG("Finalizer for weak_ptr base context is called");
delete static_cast<std::weak_ptr<Context> *>(data);
}, nullptr);
return contextObj;
+1 -1
View File
@@ -45,7 +45,7 @@ std::string MakeLogContent(NativeCallbackInfo& info)
size_t bufferLen = str->GetLength();
if (bufferLen >= JS_CONSOLE_LOG_MAX_LOG_LEN) {
HILOG_ERROR("Log length exceeds maximum");
HILOG_DEBUG("Log length exceeds maximum");
return content;
}
@@ -303,6 +303,11 @@ enum {
* Result(2097208) for not granted for static permission.
*/
ERR_STATIC_CFG_PERMISSION,
/**
* Result(2097209) for non-system-app use system-api.
*/
ERR_NOT_SYSTEM_APP,
};
enum {
@@ -44,7 +44,14 @@ bool ComponentInterceptionProxy::AllowComponentStart(const Want &want, const spt
return true;
}
data.WriteParcelable(&want);
data.WriteRemoteObject(callerToken);
if (callerToken == nullptr) {
data.WriteBool(false);
} else {
data.WriteBool(true);
data.WriteRemoteObject(callerToken);
}
data.WriteInt32(requestCode);
data.WriteInt32(componentStatus);
sptr<IRemoteObject> remote = Remote();
@@ -68,7 +68,12 @@ int32_t ComponentInterceptionStub::HandleAllowComponentStart(MessageParcel &data
HILOG_ERROR("ReadParcelable<Want> failed");
return ERR_APPEXECFWK_PARCEL_ERROR;
}
sptr<IRemoteObject> token = data.ReadRemoteObject();
sptr<IRemoteObject> token = nullptr;
bool hasRemoteToken = data.ReadBool();
if (hasRemoteToken) {
token = data.ReadRemoteObject();
}
int requestCode = data.ReadInt32();
int componentStatus = data.ReadInt32();
@@ -72,6 +72,7 @@ enum {
ERR_ABILITY_RUNTIME_EXTERNAL_QUICK_FIX_INTERNAL_ERROR = 18500008,
ERR_ABILITY_RUNTIME_EXTERNAL_NO_ACCESS_PERMISSION = 201,
ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP = 202,
ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER = 401,
ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_SYSCAP = 801,
};
@@ -121,6 +121,8 @@ const std::map<int32_t, std::string> ERROR_MSG_MAP = {
"Internal error." },
{ ERR_ABILITY_RUNTIME_EXTERNAL_NO_ACCESS_PERMISSION,
"The application does not have permission to call the interface." },
{ ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP,
"The application is not system-app, can not use system-api." },
{ ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER,
"Invalid input parameter." },
{ ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_SYSCAP,
@@ -42,6 +42,7 @@ enum {
QUICK_FIX_SET_INFO_FAILED = 17,
QUICK_FIX_PROCESS_TIMEOUT = 18,
QUICK_FIX_NOTIFY_UNLOAD_PATCH_FAILED = 19,
QUICK_FIX_NOT_SYSTEM_APP = 20,
};
enum {
@@ -51,6 +52,9 @@ enum {
// The application does not have permission to call the interface.
ERR_QUICKFIX_PERMISSION_DENIED = 201,
// non-system-app use system-api.
ERR_QUICKFIX_NOT_SYSTEM_APP = 202,
// Invalid input parameter.
ERR_QUICKFIX_PARAM_INVALID = 401,
@@ -29,6 +29,7 @@ const std::map<int32_t, int32_t> INTERNAL_ERR_CODE_MAP = {
{ QUICK_FIX_INVALID_PARAM, ERR_QUICKFIX_PARAM_INVALID },
{ QUICK_FIX_CONNECT_FAILED, ERR_QUICKFIX_INTERNAL_ERROR },
{ QUICK_FIX_VERIFY_PERMISSION_FAILED, ERR_QUICKFIX_PERMISSION_DENIED },
{ QUICK_FIX_NOT_SYSTEM_APP, ERR_QUICKFIX_NOT_SYSTEM_APP },
{ QUICK_FIX_GET_BUNDLE_INFO_FAILED, ERR_QUICKFIX_BUNDLE_NAME_INVALID },
{ QUICK_FIX_DEPLOY_FAILED, ERR_QUICKFIX_HQF_DEPLOY_FAILED },
{ QUICK_FIX_SWICH_FAILED, ERR_QUICKFIX_HQF_SWITCH_FAILED },
@@ -59,6 +60,7 @@ const std::map<int32_t, std::string> INTERNAL_ERR_MSG_MAP = {
const std::map<int32_t, std::string> EXTERNAL_ERR_MSG_MAP = {
{ ERR_OK, "Success." },
{ ERR_QUICKFIX_PERMISSION_DENIED, "The application does not have permission to call the interface." },
{ ERR_QUICKFIX_NOT_SYSTEM_APP, "The application is not system-app, can not use system-api." },
{ ERR_QUICKFIX_PARAM_INVALID, "Invalid input parameter." },
{ ERR_QUICKFIX_BUNDLE_NAME_INVALID, "The specified bundleName is invalid." },
{ ERR_QUICKFIX_HQF_INVALID, "The specified hqf is invalid. Hqf may not exist or inaccessible." },
@@ -134,7 +134,7 @@ public:
* @param connectCallback Indicates the callback object when the target ability is connected.
* @return True means success and false means failure
*/
virtual bool ConnectAbility(const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) = 0;
virtual ErrCode ConnectAbility(const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) = 0;
/**
* @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template.
@@ -143,7 +143,7 @@ public:
* @param connectCallback Indicates the callback object when the target ability is connected.
* @return True means success and false means failure
*/
virtual bool ConnectAbilityWithAccount(const AAFwk::Want &want, int accountId,
virtual ErrCode ConnectAbilityWithAccount(const AAFwk::Want &want, int accountId,
const sptr<AbilityConnectCallback> &connectCallback) = 0;
/**
@@ -68,9 +68,9 @@ public:
ErrCode StopServiceExtensionAbility(const Want& want, int32_t accountId = -1) override;
ErrCode TerminateAbilityWithResult(const AAFwk::Want &want, int resultCode) override;
void OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want &resultData) override;
bool ConnectAbility(const AAFwk::Want &want,
ErrCode ConnectAbility(const AAFwk::Want &want,
const sptr<AbilityConnectCallback> &connectCallback) override;
bool ConnectAbilityWithAccount(const AAFwk::Want &want, int accountId,
ErrCode ConnectAbilityWithAccount(const AAFwk::Want &want, int accountId,
const sptr<AbilityConnectCallback> &connectCallback) override;
void DisconnectAbility(const AAFwk::Want &want,
const sptr<AbilityConnectCallback> &connectCallback) override;
@@ -27,6 +27,9 @@ enum class AbilityErrorCode {
// no such permission.
ERROR_CODE_PERMISSION_DENIED = 201,
// non-system-app use system-api.
ERROR_CODE_NOT_SYSTEM_APP = 202,
// invalid param.
ERROR_CODE_INVALID_PARAM = 401,
@@ -39,6 +39,7 @@ public:
static void Finalizer(NativeEngine* engine, void* data, void* hint);
static NativeValue* StartAbility(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* StartRecentAbility(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* StartAbilityWithAccount(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* StartAbilityByCall(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* StartAbilityForResult(NativeEngine* engine, NativeCallbackInfo* info);
@@ -75,7 +76,7 @@ private:
#endif
private:
NativeValue* OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info, bool isStartRecent = false);
NativeValue* OnStartAbilityWithAccount(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnStartAbilityByCall(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnStartAbilityForResult(NativeEngine& engine, NativeCallbackInfo& info);
@@ -20,7 +20,7 @@
#include <map>
#include <string>
#include "context.h"
#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/app/context.h"
#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context.h"
#include "uri.h"
@@ -328,7 +328,7 @@ private:
void ProcessAbilityProperties(const std::shared_ptr<ADelegatorAbilityProperty> &ability);
void RemoveAbilityProperty(const std::shared_ptr<ADelegatorAbilityProperty> &ability);
std::shared_ptr<ADelegatorAbilityProperty> FindPropertyByToken(const sptr<IRemoteObject> &token);
std::shared_ptr<ADelegatorAbilityProperty> FindPropertyByName(const std::string &name);
inline void CallClearFunc(const std::shared_ptr<ADelegatorAbilityProperty> &ability);
private:
@@ -1174,6 +1174,10 @@ private:
AAFWK::EventInfo BuildEventInfo(const Want &want, int32_t userId);
int CheckDlpForExtension(
const Want &want, const sptr<IRemoteObject> &callerToken,
int32_t userId, AAFWK::EventInfo &eventInfo, const std::string &eventName);
void InitStartupFlag();
void UpdateAbilityRequestInfo(const sptr<Want> &want, AbilityRequest &request);
@@ -199,6 +199,7 @@ struct AbilityRequest {
bool restart = false;
int32_t restartCount = -1;
int64_t restartTime = 0;
bool startRecent = false;
// call ability
int callerUid = -1;
+18
View File
@@ -55,6 +55,13 @@ public:
*/
bool IsSpecifiedAbility() const;
/**
* check whether ability contains by this mission is standard.
*
* @return is ability contains by this mission is standard.
*/
bool IsStandardAbility() const;
/**
* get owner mission list.
*
@@ -188,6 +195,16 @@ public:
return needNotifyUpdateLabel_;
}
inline void UpdateMissionTime(const std::string &missionTime)
{
missionTime_ = missionTime;
}
inline std::string GetMissionTime() const
{
return missionTime_;
}
private:
int32_t missionId_;
int32_t startMethod_;
@@ -200,6 +217,7 @@ private:
bool isANRState_ = false;
bool needNotify_ = true;
bool needNotifyUpdateLabel_ = false;
std::string missionTime_ = "0";
};
} // namespace AAFwk
} // namespace OHOS
@@ -97,10 +97,12 @@ public:
*
* @param missionName name of mission.
* @param flag name of specified mission flag.
* @param isFindRecentStandard find recent standard mission.
* @param info found mission info.
* @return true if success.
*/
bool FindReusedMissionInfo(const std::string &missionName, const std::string &flag, InnerMissionInfo &info);
bool FindReusedMissionInfo(const std::string &missionName, const std::string &flag,
bool isFindRecentStandard, InnerMissionInfo &info);
/**
* @brief Delete all the mission info.
@@ -70,6 +70,14 @@ public:
*/
std::shared_ptr<Mission> GetSpecifiedMission(const std::string& missionName, const std::string& flag) const;
/**
* Get recent standard mission by name.
*
* @param missionName target mission name.
* @return founded mission.
*/
std::shared_ptr<Mission> GetRecentStandardMission(const std::string& missionName) const;
/**
* Get top mission of this mission list.
*
@@ -392,11 +392,12 @@ private:
const std::shared_ptr<AbilityRecord> &callerAbility, const AbilityRequest &abilityRequest);
std::shared_ptr<Mission> GetReusedMission(const AbilityRequest &abilityRequest);
std::shared_ptr<Mission> GetReusedSpecifiedMission(const AbilityRequest &abilityRequest);
std::shared_ptr<Mission> GetReusedStandardMission(const AbilityRequest &abilityRequest);
void GetTargetMissionAndAbility(const AbilityRequest &abilityRequest, std::shared_ptr<Mission> &targetMission,
std::shared_ptr<AbilityRecord> &targetRecord);
bool HandleReusedMissionAndAbility(const AbilityRequest &abilityRequest, std::shared_ptr<Mission> &targetMission,
std::shared_ptr<AbilityRecord> &targetRecord);
std::string GetMissionName(const AbilityRequest &abilityRequest, bool isStandard) const;
std::string GetMissionName(const AbilityRequest &abilityRequest) const;
bool CreateOrReusedMissionInfo(const AbilityRequest &abilityRequest, InnerMissionInfo &info) const;
void MoveMissionToTargetList(bool isCallFromLauncher,
const std::shared_ptr<MissionList> &targetMissionList,
@@ -889,7 +889,8 @@ int AbilityManagerProxy::GetMissionSnapshot(const std::string& deviceId, int32_t
std::unique_ptr<MissionSnapshot> info(reply.ReadParcelable<MissionSnapshot>());
if (!info) {
HILOG_ERROR("readParcelableInfo failed.");
return ERR_UNKNOWN_OBJECT;
auto errorCode = reply.ReadInt32();
return errorCode ? errorCode : ERR_UNKNOWN_OBJECT;
}
snapshot = *info;
return reply.ReadInt32();
@@ -51,6 +51,7 @@
#include "string_ex.h"
#include "system_ability_definition.h"
#include "os_account_manager_wrapper.h"
#include "permission_constants.h"
#include "uri_permission_manager_client.h"
#include "xcollie/watchdog.h"
#include "hisysevent.h"
@@ -79,6 +80,12 @@ using OHOS::Security::AccessToken::AccessTokenKit;
namespace OHOS {
namespace AAFwk {
namespace {
#define CHECK_CALLER_IS_SYSTEM_APP \
if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { \
HILOG_ERROR("The caller is not system-app, can not use system-api"); \
return ERR_NOT_SYSTEM_APP; \
}
const std::string ARGS_USER_ID = "-u";
const std::string ARGS_CLIENT = "-c";
const std::string ILLEGAL_INFOMATION = "The arguments are illegal and you can enter '-h' for help.";
@@ -283,6 +290,7 @@ const std::string DLP_INDEX = "ohos.dlp.params.index";
const std::string BOOTEVENT_APPFWK_READY = "bootevent.appfwk.ready";
const std::string BOOTEVENT_BOOT_COMPLETED = "bootevent.boot.completed";
const std::string BOOTEVENT_BOOT_ANIMATION_STARTED = "bootevent.bootanimation.started";
const std::string NEED_STARTINGWINDOW = "ohos.ability.NeedStartingWindow";
const int DEFAULT_DMS_MISSION_ID = -1;
const std::map<std::string, AbilityManagerService::DumpKey> AbilityManagerService::dumpMap = {
std::map<std::string, AbilityManagerService::DumpKey>::value_type("--all", KEY_DUMP_ALL),
@@ -476,6 +484,9 @@ int AbilityManagerService::StartAbility(const Want &want, int32_t userId, int re
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_INFO("%{public}s coldStart:%{public}d", __func__, want.GetBoolParam("coldStart", false));
if (userId != DEFAULT_INVAL_VALUE) {
CHECK_CALLER_IS_SYSTEM_APP;
}
AAFWK::EventInfo eventInfo = BuildEventInfo(want, userId);
AAFWK::EventReport::SendAbilityEvent(AAFWK::START_ABILITY, HiSysEventType::BEHAVIOR, eventInfo);
int32_t ret = StartAbilityInner(want, nullptr, requestCode, -1, userId);
@@ -490,6 +501,9 @@ int AbilityManagerService::StartAbility(const Want &want, const sptr<IRemoteObje
int32_t userId, int requestCode)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
if (userId != DEFAULT_INVAL_VALUE) {
CHECK_CALLER_IS_SYSTEM_APP;
}
auto flags = want.GetFlags();
AAFWK::EventInfo eventInfo = BuildEventInfo(want, userId);
AAFWK::EventReport::SendAbilityEvent(AAFWK::START_ABILITY, HiSysEventType::BEHAVIOR, eventInfo);
@@ -663,6 +677,9 @@ int AbilityManagerService::StartAbility(const Want &want, const AbilityStartSett
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_DEBUG("Start ability setting.");
if (userId != DEFAULT_INVAL_VALUE) {
CHECK_CALLER_IS_SYSTEM_APP;
}
AAFWK::EventInfo eventInfo = BuildEventInfo(want, userId);
AAFWK::EventReport::SendAbilityEvent(AAFWK::START_ABILITY, HiSysEventType::BEHAVIOR, eventInfo);
@@ -805,6 +822,9 @@ int AbilityManagerService::StartAbility(const Want &want, const StartOptions &st
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_DEBUG("Start ability options.");
if (userId != DEFAULT_INVAL_VALUE) {
CHECK_CALLER_IS_SYSTEM_APP;
}
AAFWK::EventInfo eventInfo = BuildEventInfo(want, userId);
AAFWK::EventReport::SendAbilityEvent(AAFWK::START_ABILITY, HiSysEventType::BEHAVIOR, eventInfo);
@@ -1061,16 +1081,15 @@ int AbilityManagerService::StartExtensionAbility(const Want &want, const sptr<IR
{
HILOG_INFO("Start extension ability come, bundlename: %{public}s, ability is %{public}s, userId is %{public}d",
want.GetElement().GetBundleName().c_str(), want.GetElement().GetAbilityName().c_str(), userId);
CHECK_CALLER_IS_SYSTEM_APP;
AAFWK::EventInfo eventInfo = BuildEventInfo(want, userId);
eventInfo.extensionType = static_cast<int32_t>(extensionType);
AAFWK::EventReport::SendExtensionEvent(AAFWK::START_SERVICE, HiSysEventType::BEHAVIOR, eventInfo);
if (!DlpUtils::OtherAppsAccessDlpCheck(callerToken, want) ||
VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED ||
!DlpUtils::DlpAccessOtherAppsCheck(callerToken, want)) {
HILOG_ERROR("%{public}s: Permission verification failed.", __func__);
eventInfo.errCode = CHECK_PERMISSION_FAILED;
AAFWK::EventReport::SendExtensionEvent(AAFWK::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo);
return CHECK_PERMISSION_FAILED;
auto result = CheckDlpForExtension(want, callerToken, userId, eventInfo, AAFWK::START_EXTENSION_ERROR);
if (result != ERR_OK) {
HILOG_ERROR("CheckDlpForExtension error.");
return result;
}
if (callerToken != nullptr && !VerificationAllToken(callerToken)) {
@@ -1080,7 +1099,7 @@ int AbilityManagerService::StartExtensionAbility(const Want &want, const sptr<IR
return ERR_INVALID_CALLER;
}
auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE :
result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE :
interceptorExecuter_->DoProcess(want, 0, GetUserId(), false);
if (result != ERR_OK) {
return result;
@@ -1151,16 +1170,15 @@ int AbilityManagerService::StopExtensionAbility(const Want &want, const sptr<IRe
{
HILOG_INFO("Stop extension ability come, bundlename: %{public}s, ability is %{public}s, userId is %{public}d",
want.GetElement().GetBundleName().c_str(), want.GetElement().GetAbilityName().c_str(), userId);
CHECK_CALLER_IS_SYSTEM_APP;
AAFWK::EventInfo eventInfo = BuildEventInfo(want, userId);
eventInfo.extensionType = static_cast<int32_t>(extensionType);
AAFWK::EventReport::SendExtensionEvent(AAFWK::STOP_SERVICE, HiSysEventType::BEHAVIOR, eventInfo);
if (!DlpUtils::OtherAppsAccessDlpCheck(callerToken, want) ||
VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED ||
!DlpUtils::DlpAccessOtherAppsCheck(callerToken, want)) {
HILOG_ERROR("%{public}s: Permission verification failed.", __func__);
eventInfo.errCode = CHECK_PERMISSION_FAILED;
AAFWK::EventReport::SendExtensionEvent(AAFWK::STOP_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo);
return CHECK_PERMISSION_FAILED;
auto result = CheckDlpForExtension(want, callerToken, userId, eventInfo, AAFWK::STOP_EXTENSION_ERROR);
if (result != ERR_OK) {
HILOG_ERROR("CheckDlpForExtension error.");
return result;
}
if (callerToken != nullptr && !VerificationAllToken(callerToken)) {
@@ -1178,7 +1196,7 @@ int AbilityManagerService::StopExtensionAbility(const Want &want, const sptr<IRe
}
AbilityRequest abilityRequest;
auto result = GenerateExtensionAbilityRequest(want, abilityRequest, callerToken, validUserId);
result = GenerateExtensionAbilityRequest(want, abilityRequest, callerToken, validUserId);
if (result != ERR_OK) {
HILOG_ERROR("Generate ability request local error.");
eventInfo.errCode = result;
@@ -1590,19 +1608,19 @@ int AbilityManagerService::ConnectAbilityCommon(
HILOG_DEBUG("Connect ability called, element uri: %{public}s.", want.GetElement().GetURI().c_str());
CHECK_POINTER_AND_RETURN(connect, ERR_INVALID_VALUE);
CHECK_POINTER_AND_RETURN(connect->AsObject(), ERR_INVALID_VALUE);
if (extensionType == AppExecFwk::ExtensionAbilityType::SERVICE && userId != DEFAULT_INVAL_VALUE) {
CHECK_CALLER_IS_SYSTEM_APP;
}
AAFWK::EventInfo eventInfo = BuildEventInfo(want, userId);
AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE, HiSysEventType::BEHAVIOR, eventInfo);
if (!DlpUtils::OtherAppsAccessDlpCheck(callerToken, want) ||
VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED ||
!DlpUtils::DlpAccessOtherAppsCheck(callerToken, want)) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
eventInfo.errCode = CHECK_PERMISSION_FAILED;
AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR, HiSysEventType::FAULT, eventInfo);
return CHECK_PERMISSION_FAILED;
auto result = CheckDlpForExtension(want, callerToken, userId, eventInfo, AAFWK::CONNECT_SERVICE_ERROR);
if (result != ERR_OK) {
HILOG_ERROR("CheckDlpForExtension error.");
return result;
}
auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE :
result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE :
interceptorExecuter_->DoProcess(want, 0, GetUserId(), false);
if (result != ERR_OK) {
return result;
@@ -1634,6 +1652,14 @@ int AbilityManagerService::ConnectAbilityCommon(
AppExecFwk::ExtensionAbilityInfo extensionInfo;
auto bms = GetBundleManager();
CHECK_POINTER_AND_RETURN(bms, ERR_INVALID_VALUE);
AbilityRequest abilityRequest;
abilityWant.SetParam("abilityConnectionObj", connect->AsObject());
if (!IsComponentInterceptionStart(abilityWant, callerToken, 0, 0, abilityRequest)) {
return ERR_OK;
}
abilityWant.RemoveParam("abilityConnectionObj");
bool queryResult = IN_PROCESS_CALL(bms->QueryExtensionAbilityInfoByUri(uri, validUserId, extensionInfo));
if (!queryResult || extensionInfo.name.empty() || extensionInfo.bundleName.empty()) {
HILOG_ERROR("Invalid extension ability info.");
@@ -1917,6 +1943,7 @@ int AbilityManagerService::GetDlpConnectionInfos(std::vector<AbilityRuntime::Dlp
int AbilityManagerService::RegisterMissionListener(const std::string &deviceId,
const sptr<IRemoteMissionListener> &listener)
{
CHECK_CALLER_IS_SYSTEM_APP;
std::string localDeviceId;
if (!GetLocalDeviceId(localDeviceId) || localDeviceId == deviceId) {
HILOG_ERROR("RegisterMissionListener: Check DeviceId failed");
@@ -1934,6 +1961,7 @@ int AbilityManagerService::RegisterMissionListener(const std::string &deviceId,
int AbilityManagerService::UnRegisterMissionListener(const std::string &deviceId,
const sptr<IRemoteMissionListener> &listener)
{
CHECK_CALLER_IS_SYSTEM_APP;
std::string localDeviceId;
if (!GetLocalDeviceId(localDeviceId) || localDeviceId == deviceId) {
HILOG_ERROR("RegisterMissionListener: Check DeviceId failed");
@@ -2132,6 +2160,7 @@ int AbilityManagerService::GetPendingRequestWant(const sptr<IWantSender> &target
CHECK_POINTER_AND_RETURN(pendingWantManager_, ERR_INVALID_VALUE);
CHECK_POINTER_AND_RETURN(target, ERR_INVALID_VALUE);
CHECK_POINTER_AND_RETURN(want, ERR_INVALID_VALUE);
CHECK_CALLER_IS_SYSTEM_APP;
return pendingWantManager_->GetPendingRequestWant(target, want);
}
@@ -2139,6 +2168,7 @@ int AbilityManagerService::LockMissionForCleanup(int32_t missionId)
{
HILOG_INFO("request unlock mission for clean up all, id :%{public}d", missionId);
CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT);
CHECK_CALLER_IS_SYSTEM_APP;
if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
@@ -2151,6 +2181,7 @@ int AbilityManagerService::UnlockMissionForCleanup(int32_t missionId)
{
HILOG_INFO("request unlock mission for clean up all, id :%{public}d", missionId);
CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT);
CHECK_CALLER_IS_SYSTEM_APP;
if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
@@ -2163,6 +2194,7 @@ int AbilityManagerService::RegisterMissionListener(const sptr<IMissionListener>
{
HILOG_INFO("request RegisterMissionListener ");
CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT);
CHECK_CALLER_IS_SYSTEM_APP;
if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
@@ -2175,6 +2207,7 @@ int AbilityManagerService::UnRegisterMissionListener(const sptr<IMissionListener
{
HILOG_INFO("request RegisterMissionListener ");
CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT);
CHECK_CALLER_IS_SYSTEM_APP;
if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
@@ -2188,6 +2221,7 @@ int AbilityManagerService::GetMissionInfos(const std::string& deviceId, int32_t
{
HILOG_INFO("request GetMissionInfos.");
CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT);
CHECK_CALLER_IS_SYSTEM_APP;
if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
@@ -2219,6 +2253,7 @@ int AbilityManagerService::GetMissionInfo(const std::string& deviceId, int32_t m
{
HILOG_INFO("request GetMissionInfo, missionId:%{public}d", missionId);
CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT);
CHECK_CALLER_IS_SYSTEM_APP;
if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
@@ -2255,6 +2290,7 @@ int AbilityManagerService::CleanMission(int32_t missionId)
{
HILOG_INFO("request CleanMission, missionId:%{public}d", missionId);
CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT);
CHECK_CALLER_IS_SYSTEM_APP;
if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
@@ -2268,6 +2304,7 @@ int AbilityManagerService::CleanAllMissions()
{
HILOG_INFO("request CleanAllMissions ");
CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT);
CHECK_CALLER_IS_SYSTEM_APP;
if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
@@ -2288,6 +2325,7 @@ int AbilityManagerService::MoveMissionToFront(int32_t missionId)
{
HILOG_INFO("request MoveMissionToFront, missionId:%{public}d", missionId);
CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT);
CHECK_CALLER_IS_SYSTEM_APP;
if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
@@ -2306,6 +2344,7 @@ int AbilityManagerService::MoveMissionToFront(int32_t missionId, const StartOpti
{
HILOG_INFO("request MoveMissionToFront, missionId:%{public}d", missionId);
CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT);
CHECK_CALLER_IS_SYSTEM_APP;
if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
@@ -3141,6 +3180,10 @@ void AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isB
HILOG_ERROR("Query highest priority ability failed.");
return;
}
AbilityRequest abilityRequest;
if (!IsComponentInterceptionStart(want, nullptr, 0, 0, abilityRequest)) {
return;
}
usleep(REPOLL_TIME_MICRO_SECONDS);
}
@@ -3163,6 +3206,7 @@ void AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isB
}
#ifdef SUPPORT_GRAPHICS
abilityWant.SetParam(NEED_STARTINGWINDOW, false);
// wait BOOT_ANIMATION_STARTED to start LAUNCHER
WaitParameter(BOOTEVENT_BOOT_ANIMATION_STARTED.c_str(), "true", amsConfigResolver_->GetBootAnimationTimeoutTime());
#endif
@@ -3254,6 +3298,11 @@ int AbilityManagerService::GenerateAbilityRequest(
HILOG_INFO("GenerateAbilityRequest, moduleName: %{public}s.", request.abilityInfo.moduleName.c_str());
request.want.SetModuleName(request.abilityInfo.moduleName);
if (want.GetBoolParam(Want::PARAM_RESV_START_RECENT, false) &&
AAFwk::PermissionVerification::GetInstance()->VerifyMissionPermission()) {
request.startRecent = true;
}
return ERR_OK;
}
@@ -3434,6 +3483,7 @@ void AbilityManagerService::GetRestartIntervalTime(int &restartIntervalTime)
int AbilityManagerService::KillProcess(const std::string &bundleName)
{
HILOG_DEBUG("Kill process, bundleName: %{public}s", bundleName.c_str());
CHECK_CALLER_IS_SYSTEM_APP;
auto bms = GetBundleManager();
CHECK_POINTER_AND_RETURN(bms, KILL_PROCESS_FAILED);
int32_t userId = GetUserId();
@@ -3459,6 +3509,7 @@ int AbilityManagerService::KillProcess(const std::string &bundleName)
int AbilityManagerService::ClearUpApplicationData(const std::string &bundleName)
{
HILOG_DEBUG("ClearUpApplicationData, bundleName: %{public}s", bundleName.c_str());
CHECK_CALLER_IS_SYSTEM_APP;
int ret = DelayedSingleton<AppScheduler>::GetInstance()->ClearUpApplicationData(bundleName);
if (ret != ERR_OK) {
return CLEAR_APPLICATION_DATA_FAIL;
@@ -3948,6 +3999,7 @@ int AbilityManagerService::StartAbilityByCall(
HILOG_INFO("call ability.");
CHECK_POINTER_AND_RETURN(connect, ERR_INVALID_VALUE);
CHECK_POINTER_AND_RETURN(connect->AsObject(), ERR_INVALID_VALUE);
CHECK_CALLER_IS_SYSTEM_APP;
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
if (abilityRecord && !JudgeSelfCalled(abilityRecord)) {
@@ -4141,6 +4193,7 @@ void AbilityManagerService::OnStartSpecifiedAbilityTimeoutResponse(const AAFwk::
int AbilityManagerService::GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info)
{
HILOG_DEBUG("Get running ability infos.");
CHECK_CALLER_IS_SYSTEM_APP;
auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm();
if (!currentMissionListManager_ || !connectManager_ || !dataAbilityManager_) {
return ERR_INVALID_VALUE;
@@ -4186,6 +4239,7 @@ void AbilityManagerService::UpdateFocusState(std::vector<AbilityRunningInfo> &in
int AbilityManagerService::GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info)
{
HILOG_DEBUG("Get extension infos, upperLimit : %{public}d", upperLimit);
CHECK_CALLER_IS_SYSTEM_APP;
auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm();
if (!connectManager_) {
return ERR_INVALID_VALUE;
@@ -4236,6 +4290,7 @@ int AbilityManagerService::RegisterSnapshotHandler(const sptr<ISnapshotHandler>&
int32_t AbilityManagerService::GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
MissionSnapshot& missionSnapshot, bool isLowResolution)
{
CHECK_CALLER_IS_SYSTEM_APP;
if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
return CHECK_PERMISSION_FAILED;
@@ -4773,6 +4828,7 @@ int AbilityManagerService::FinishUserTest(
int AbilityManagerService::GetTopAbility(sptr<IRemoteObject> &token)
{
#ifdef SUPPORT_GRAPHICS
CHECK_CALLER_IS_SYSTEM_APP;
if (!wmsHandler_) {
HILOG_ERROR("wmsHandler_ is nullptr.");
return ERR_INVALID_VALUE;
@@ -4973,7 +5029,8 @@ int AbilityManagerService::CheckStaticCfgPermission(AppExecFwk::AbilityInfo &abi
}
// verify permission if 'permission' is not empty
if (abilityInfo.permissions.empty()) {
if (abilityInfo.permissions.empty() ||
AccessTokenKit::VerifyAccessToken(tokenId, PermissionConstants::PERMISSION_START_INVISIBLE_ABILITY)) {
return AppExecFwk::Constants::PERMISSION_GRANTED;
}
@@ -5312,6 +5369,7 @@ int AbilityManagerService::SetMissionIcon(const sptr<IRemoteObject> &token,
const std::shared_ptr<OHOS::Media::PixelMap> &icon)
{
HILOG_DEBUG("%{public}s", __func__);
CHECK_CALLER_IS_SYSTEM_APP;
auto abilityRecord = Token::GetAbilityRecordByToken(token);
if (!abilityRecord) {
HILOG_ERROR("no such ability record");
@@ -5763,6 +5821,21 @@ int AbilityManagerService::AddStartControlParam(Want &want, const sptr<IRemoteOb
return ERR_OK;
}
int AbilityManagerService::CheckDlpForExtension(
const Want &want, const sptr<IRemoteObject> &callerToken,
int32_t userId, AAFWK::EventInfo &eventInfo, const std::string &eventName)
{
if (!DlpUtils::OtherAppsAccessDlpCheck(callerToken, want) ||
VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED ||
!DlpUtils::DlpAccessOtherAppsCheck(callerToken, want)) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
eventInfo.errCode = CHECK_PERMISSION_FAILED;
AAFWK::EventReport::SendExtensionEvent(eventName, HiSysEventType::FAULT, eventInfo);
return CHECK_PERMISSION_FAILED;
}
return ERR_OK;
}
bool AbilityManagerService::JudgeSelfCalled(const std::shared_ptr<AbilityRecord> &abilityRecord)
{
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
+8 -3
View File
@@ -57,6 +57,7 @@ const std::string SHOW_ON_LOCK_SCREEN = "ShowOnLockScreen";
const std::string DLP_INDEX = "ohos.dlp.params.index";
const std::string DLP_BUNDLE_NAME = "com.ohos.dlpmanager";
const std::string COMPONENT_STARTUP_NEW_RULES = "component.startup.newRules";
const std::string NEED_STARTINGWINDOW = "ohos.ability.NeedStartingWindow";
const uint32_t RELEASE_STARTING_BG_TIMEOUT = 15000; // release starting window resource timeout.
int64_t AbilityRecord::abilityRecordId = 0;
int64_t AbilityRecord::g_abilityRecordEventId_ = 0;
@@ -499,9 +500,13 @@ void AbilityRecord::ProcessForegroundAbility(bool isRecent, const AbilityRequest
} else {
HILOG_INFO("SUPPORT_GRAPHICS: to load ability.");
lifeCycleStateInfo_.sceneFlagBak = sceneFlag;
StartingWindowTask(isRecent, true, abilityRequest, startOptions);
AnimationTask(isRecent, abilityRequest, startOptions, callerAbility);
PostCancelStartingWindowColdTask();
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
auto needStartingWindow = abilityRequest.want.GetBoolParam(NEED_STARTINGWINDOW, true);
if (!isSaCall || needStartingWindow) {
StartingWindowTask(isRecent, true, abilityRequest, startOptions);
AnimationTask(isRecent, abilityRequest, startOptions, callerAbility);
PostCancelStartingWindowColdTask();
}
LoadAbility();
}
}
+9
View File
@@ -68,6 +68,15 @@ bool Mission::IsSpecifiedAbility() const
return false;
}
bool Mission::IsStandardAbility() const
{
if (abilityRecord_) {
return abilityRecord_->GetAbilityInfo().launchMode == AppExecFwk::LaunchMode::STANDARD;
}
return false;
}
void Mission::SetSpecifiedFlag(const std::string &flag)
{
specifiedFlag_ = flag;
+12 -5
View File
@@ -289,25 +289,32 @@ int MissionInfoMgr::GetInnerMissionInfoById(int32_t missionId, InnerMissionInfo
}
bool MissionInfoMgr::FindReusedMissionInfo(const std::string &missionName,
const std::string &flag, InnerMissionInfo &info)
const std::string &flag, bool isFindRecentStandard, InnerMissionInfo &info)
{
if (missionName.empty()) {
return false;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
auto it = std::find_if(missionInfoList_.begin(), missionInfoList_.end(),
[&missionName, &flag](const InnerMissionInfo item) {
if (item.launchMode == static_cast<int32_t>(AppExecFwk::LaunchMode::STANDARD)) {
[&missionName, &flag, &isFindRecentStandard](const InnerMissionInfo item) {
if (missionName != item.missionName) {
return false;
}
// already sorted, return head of list
if (isFindRecentStandard && item.launchMode == static_cast<int32_t>(AppExecFwk::LaunchMode::STANDARD)) {
return true;
}
if (item.launchMode == static_cast<int32_t>(AppExecFwk::LaunchMode::SINGLETON)) {
return missionName == item.missionName;
return true;
}
if (item.launchMode == static_cast<int32_t>(AppExecFwk::LaunchMode::SPECIFIED)) {
return missionName == item.missionName && flag == item.specifiedFlag;
return flag == item.specifiedFlag;
}
return false;
}
+19
View File
@@ -94,6 +94,25 @@ std::shared_ptr<Mission> MissionList::GetSpecifiedMission(
return nullptr;
}
std::shared_ptr<Mission> MissionList::GetRecentStandardMission(const std::string &missionName) const
{
if (missionName.empty()) {
return nullptr;
}
std::string missionTime = "0";
std::shared_ptr<Mission> result = nullptr;
for (auto& mission : missions_) {
if (mission && mission->IsStandardAbility() && mission->GetMissionName() == missionName &&
mission->GetMissionTime() >= missionTime) {
result = mission;
missionTime = mission->GetMissionTime();
}
}
return result;
}
std::shared_ptr<AbilityRecord> MissionList::GetAbilityRecordByToken(const sptr<IRemoteObject> &token) const
{
for (auto mission : missions_) {
@@ -384,30 +384,46 @@ bool MissionListManager::HandleReusedMissionAndAbility(const AbilityRequest &abi
HILOG_DEBUG("mission exists. No update required");
return true;
}
HILOG_DEBUG("mission exists. need to be updated");
return false;
auto missionId = targetMission->GetMissionId();
HILOG_INFO("mission exists. need to be updated, missionId:%{public}d", missionId);
InnerMissionInfo info;
if (DelayedSingleton<MissionInfoMgr>::GetInstance()->GetInnerMissionInfoById(
targetMission->GetMissionId(), info) == 0) {
info.missionInfo.time = GetCurrentTime();
info.missionInfo.runningState = 0;
info.startMethod = CallType2StartMethod(abilityRequest.callType);
DelayedSingleton<MissionInfoMgr>::GetInstance()->UpdateMissionInfo(info);
targetMission->UpdateMissionId(missionId, info.startMethod);
targetMission->UpdateMissionTime(info.missionInfo.time);
}
return true;
}
std::string MissionListManager::GetMissionName(const AbilityRequest &abilityRequest, bool isStandard) const
std::string MissionListManager::GetMissionName(const AbilityRequest &abilityRequest) const
{
int32_t appIndex = abilityRequest.want.GetIntParam(DLP_INDEX, 0);
std::string missionName = isStandard ? abilityRequest.abilityInfo.bundleName :
AbilityUtil::ConvertBundleNameSingleton(
abilityRequest.abilityInfo.bundleName, abilityRequest.abilityInfo.name,
abilityRequest.abilityInfo.moduleName, appIndex);
return missionName;
return AbilityUtil::ConvertBundleNameSingleton(abilityRequest.abilityInfo.bundleName,
abilityRequest.abilityInfo.name, abilityRequest.abilityInfo.moduleName, appIndex);
}
bool MissionListManager::CreateOrReusedMissionInfo(const AbilityRequest &abilityRequest, InnerMissionInfo &info) const
{
// get mission name.
bool reUsedMissionInfo = false;
bool isStandard = abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::STANDARD;
std::string missionName = GetMissionName(abilityRequest, isStandard);
bool needFind = false;
bool isFindRecentStandard = abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::STANDARD &&
abilityRequest.startRecent;
if (abilityRequest.abilityInfo.launchMode != AppExecFwk::LaunchMode::STANDARD || isFindRecentStandard) {
needFind = true;
}
std::string missionName = GetMissionName(abilityRequest);
auto mgr = DelayedSingleton<MissionInfoMgr>::GetInstance();
if (!isStandard && !abilityRequest.abilityInfo.applicationInfo.isLauncherApp && mgr &&
mgr->FindReusedMissionInfo(missionName, abilityRequest.specifiedFlag, info) && info.missionInfo.id > 0) {
if (needFind && !abilityRequest.abilityInfo.applicationInfo.isLauncherApp && mgr &&
mgr->FindReusedMissionInfo(missionName, abilityRequest.specifiedFlag, isFindRecentStandard, info)
&& info.missionInfo.id > 0) {
reUsedMissionInfo = true;
}
HILOG_INFO("try find reused mission info. result:%{public}d", reUsedMissionInfo);
@@ -439,27 +455,21 @@ void MissionListManager::GetTargetMissionAndAbility(const AbilityRequest &abilit
targetMission = std::make_shared<Mission>(info.missionInfo.id, targetRecord,
info.missionName, info.startMethod);
targetMission->SetLockedState(info.missionInfo.lockedState);
targetMission->UpdateMissionTime(info.missionInfo.time);
targetRecord->SetMission(targetMission);
targetRecord->SetOwnerMissionUserId(userId_);
} else {
HILOG_DEBUG("Update old mission data.");
auto state = targetMission->UpdateMissionId(info.missionInfo.id, info.startMethod);
if (!state) {
HILOG_INFO("targetMission UpdateMissionId(%{public}d, %{public}d) failed", info.missionInfo.id,
info.startMethod);
// handle specified
if (abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::SPECIFIED) {
targetMission->SetSpecifiedFlag(abilityRequest.specifiedFlag);
targetRecord->SetSpecifiedFlag(abilityRequest.specifiedFlag);
}
HILOG_DEBUG("Update MissionId (%{public}d, %{public}d) end", info.missionInfo.id, info.startMethod);
}
if (!findReusedMissionInfo && targetRecord) {
info.missionInfo.label = targetRecord->GetLabel();
}
if (abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::SPECIFIED) {
targetMission->SetSpecifiedFlag(abilityRequest.specifiedFlag);
targetRecord->SetSpecifiedFlag(abilityRequest.specifiedFlag);
}
if (abilityRequest.abilityInfo.applicationInfo.isLauncherApp || abilityRequest.abilityInfo.excludeFromMissions) {
return;
}
@@ -572,14 +582,16 @@ std::shared_ptr<Mission> MissionListManager::GetReusedMission(const AbilityReque
return GetReusedSpecifiedMission(abilityRequest);
}
if (abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::STANDARD) {
return GetReusedStandardMission(abilityRequest);
}
if (abilityRequest.abilityInfo.launchMode != AppExecFwk::LaunchMode::SINGLETON) {
return nullptr;
}
std::shared_ptr<Mission> reUsedMission = nullptr;
int32_t appIndex = abilityRequest.want.GetIntParam(DLP_INDEX, 0);
std::string missionName = AbilityUtil::ConvertBundleNameSingleton(abilityRequest.abilityInfo.bundleName,
abilityRequest.abilityInfo.name, abilityRequest.abilityInfo.moduleName, appIndex);
std::string missionName = GetMissionName(abilityRequest);
// find launcher first.
if (abilityRequest.abilityInfo.applicationInfo.isLauncherApp) {
@@ -611,9 +623,7 @@ std::shared_ptr<Mission> MissionListManager::GetReusedSpecifiedMission(const Abi
// specified mission name format is same as singleton.
std::shared_ptr<Mission> reUsedMission = nullptr;
int32_t appIndex = abilityRequest.want.GetIntParam(DLP_INDEX, 0);
std::string missionName = AbilityUtil::ConvertBundleNameSingleton(abilityRequest.abilityInfo.bundleName,
abilityRequest.abilityInfo.name, abilityRequest.abilityInfo.moduleName, appIndex);
std::string missionName = GetMissionName(abilityRequest);
std::string flag = abilityRequest.specifiedFlag;
// find launcher first.
@@ -638,6 +648,49 @@ std::shared_ptr<Mission> MissionListManager::GetReusedSpecifiedMission(const Abi
return nullptr;
}
std::shared_ptr<Mission> MissionListManager::GetReusedStandardMission(const AbilityRequest &abilityRequest)
{
if (abilityRequest.abilityInfo.launchMode != AppExecFwk::LaunchMode::STANDARD) {
return nullptr;
}
if (!abilityRequest.startRecent) {
return nullptr;
}
// all mission name format is same.
std::string missionName = GetMissionName(abilityRequest);
std::shared_ptr<Mission> reUsedMission = nullptr;
// find launcher first, if find it in launcher list, no need to find in other list.
if (abilityRequest.abilityInfo.applicationInfo.isLauncherApp) {
if ((reUsedMission = launcherList_->GetRecentStandardMission(missionName)) != nullptr) {
return reUsedMission;
}
}
// try find it from current and default standard.
std::string missionTime = "0";
for (const auto &missionList : currentMissionLists_) {
if (!missionList) {
continue;
}
auto mission = missionList->GetRecentStandardMission(missionName);
if (mission && mission->GetMissionTime() >= missionTime) {
missionTime = mission->GetMissionTime();
reUsedMission = mission;
}
}
auto mission = defaultStandardList_->GetRecentStandardMission(missionName);
if (mission && mission->GetMissionTime() >= missionTime) {
reUsedMission = mission;
}
return reUsedMission;
}
void MissionListManager::MoveMissionToTargetList(bool isCallFromLauncher,
const std::shared_ptr<MissionList> &targetMissionList,
const std::shared_ptr<Mission> &mission)
@@ -1031,10 +1084,12 @@ void MissionListManager::CompleteForegroundSuccess(const std::shared_ptr<Ability
auto mission = abilityRecord->GetMission();
if (mission) {
auto currentTime = GetCurrentTime();
mission->UpdateMissionTime(currentTime);
InnerMissionInfo info;
if (DelayedSingleton<MissionInfoMgr>::GetInstance()->GetInnerMissionInfoById(
mission->GetMissionId(), info) == 0) {
info.missionInfo.time = GetCurrentTime();
info.missionInfo.time = currentTime;
info.missionInfo.runningState = 0;
DelayedSingleton<MissionInfoMgr>::GetInstance()->UpdateMissionInfo(info);
}
+14 -4
View File
@@ -20,6 +20,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include "ability_manager_errors.h"
#include "accesstoken_kit.h"
#include "application_state_observer_stub.h"
#include "datetime_ex.h"
@@ -58,6 +59,12 @@ using namespace OHOS::Rosen;
using namespace OHOS::Security;
namespace {
#define CHECK_CALLER_IS_SYSTEM_APP \
if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { \
HILOG_ERROR("The caller is not system-app, can not use system-api"); \
return AAFwk::ERR_NOT_SYSTEM_APP; \
}
// NANOSECONDS mean 10^9 nano second
constexpr int64_t NANOSECONDS = 1000000000;
// MICROSECONDS mean 10^6 milli second
@@ -375,7 +382,6 @@ void AppMgrServiceInner::ApplicationForegrounded(const int32_t recordId)
appRecord->PopForegroundingAbilityTokens();
ApplicationState appState = appRecord->GetState();
if (appState == ApplicationState::APP_STATE_READY || appState == ApplicationState::APP_STATE_BACKGROUND) {
appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
bool needNotifyApp = appRunningManager_->IsApplicationFirstForeground(*appRecord);
OnAppStateChanged(appRecord, ApplicationState::APP_STATE_FOREGROUND, needNotifyApp);
@@ -582,9 +588,9 @@ int32_t AppMgrServiceInner::KillApplicationByUserId(const std::string &bundleNam
HILOG_ERROR("appRunningManager_ is nullptr");
return ERR_NO_INIT;
}
if (VerifyAccountPermission(AAFwk::PermissionConstants::PERMISSION_CLEAN_BACKGROUND_PROCESSES, userId) ==
ERR_PERMISSION_DENIED) {
CHECK_CALLER_IS_SYSTEM_APP;
if (VerifyAccountPermission(
AAFwk::PermissionConstants::PERMISSION_CLEAN_BACKGROUND_PROCESSES, userId) == ERR_PERMISSION_DENIED) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
return ERR_PERMISSION_DENIED;
}
@@ -1915,18 +1921,21 @@ void AppMgrServiceInner::NotifyAppStatusByCallerUid(const std::string &bundleNam
int32_t AppMgrServiceInner::RegisterApplicationStateObserver(
const sptr<IApplicationStateObserver> &observer, const std::vector<std::string> &bundleNameList)
{
CHECK_CALLER_IS_SYSTEM_APP;
return DelayedSingleton<AppStateObserverManager>::GetInstance()->RegisterApplicationStateObserver(
observer, bundleNameList);
}
int32_t AppMgrServiceInner::UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer)
{
CHECK_CALLER_IS_SYSTEM_APP;
return DelayedSingleton<AppStateObserverManager>::GetInstance()->UnregisterApplicationStateObserver(observer);
}
int32_t AppMgrServiceInner::GetForegroundApplications(std::vector<AppStateData> &list)
{
HILOG_INFO("%{public}s, begin.", __func__);
CHECK_CALLER_IS_SYSTEM_APP;
auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm();
if (!isPerm) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
@@ -2256,6 +2265,7 @@ int32_t AppMgrServiceInner::UpdateConfiguration(const Configuration &config)
HILOG_ERROR("appRunningManager_ is null");
return ERR_INVALID_VALUE;
}
CHECK_CALLER_IS_SYSTEM_APP;
auto ret = AAFwk::PermissionVerification::GetInstance()->VerifyUpdateConfigurationPerm();
if (ret != ERR_OK) {
+1
View File
@@ -44,6 +44,7 @@ ohos_shared_library("perm_verification") {
external_deps = [
"ability_base:want",
"access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk",
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
@@ -79,6 +79,8 @@ struct VerificationInfo {
int CheckStartByCallPermission(const VerificationInfo &verificationInfo) const;
bool JudgeCallerIsAllowedToUseSystemAPI() const;
private:
DISALLOW_COPY_AND_MOVE(PermissionVerification);
@@ -19,6 +19,7 @@
#include "accesstoken_kit.h"
#include "hilog_wrapper.h"
#include "permission_constants.h"
#include "tokenid_kit.h"
namespace OHOS {
namespace AAFwk {
@@ -357,5 +358,14 @@ int PermissionVerification::JudgeInvisibleAndBackground(const VerificationInfo &
return ERR_OK;
}
bool PermissionVerification::JudgeCallerIsAllowedToUseSystemAPI() const
{
if (IsSACall() || IsShellCall()) {
return true;
}
auto callerToken = IPCSkeleton::GetCallingFullTokenID();
return Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(callerToken);
}
} // namespace AAFwk
} // namespace OHOS
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import AbilityStage from "@ohos.application.AbilityStage"
import AbilityStage from "@ohos.app.ability.AbilityStage"
export default class DialogAbilityStage extends AbilityStage {
onCreate() {
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import extension from '@ohos.application.ServiceExtensionAbility';
import extension from '@ohos.app.ability.ServiceExtensionAbility';
import window from '@ohos.window';
import display from '@ohos.display';
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import extension from '@ohos.application.ServiceExtensionAbility';
import extension from '@ohos.app.ability.ServiceExtensionAbility';
import window from '@ohos.window';
import display from '@ohos.display';
@@ -58,7 +58,10 @@ int32_t QuickFixManagerService::ApplyQuickFix(const std::vector<std::string> &qu
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_DEBUG("function called.");
if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) {
HILOG_ERROR("The caller is not system-app, can not use system-api");
return QUICK_FIX_NOT_SYSTEM_APP;
}
if (!AAFwk::PermissionVerification::GetInstance()->VerifyInstallBundlePermission()) {
return QUICK_FIX_VERIFY_PERMISSION_FAILED;
}
@@ -88,7 +91,10 @@ int32_t QuickFixManagerService::GetApplyedQuickFixInfo(const std::string &bundle
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_DEBUG("function called.");
if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) {
HILOG_ERROR("The caller is not system-app, can not use system-api");
return QUICK_FIX_NOT_SYSTEM_APP;
}
if (!AAFwk::PermissionVerification::GetInstance()->VerifyGetBundleInfoPrivilegedPermission()) {
return QUICK_FIX_VERIFY_PERMISSION_FAILED;
}
@@ -31,6 +31,7 @@ namespace OHOS {
namespace {
constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4;
constexpr uint8_t ENABLE = 2;
}
uint32_t GetU32Data(const char* ptr)
@@ -43,6 +44,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
{
int32_t int32Param = static_cast<int32_t>(GetU32Data(data));
std::string stringParam(data, size);
bool boolParam = *data % ENABLE;
InnerMissionInfo innerMissionInfo;
// fuzz for MissionInfoMgr
@@ -52,7 +54,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
MissionInfo missionInfo;
missionInfoMgr->GetMissionInfoById(int32Param, missionInfo);
missionInfoMgr->GetInnerMissionInfoById(int32Param, innerMissionInfo);
missionInfoMgr->FindReusedMissionInfo(stringParam, stringParam, innerMissionInfo);
missionInfoMgr->FindReusedMissionInfo(stringParam, stringParam, boolParam, innerMissionInfo);
return true;
}
@@ -90,4 +92,3 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
ch = nullptr;
return 0;
}
@@ -105,7 +105,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
missionListManager->StartAbilityLocked(abilityRecord, abilityRecord, abilityRequest);
std::shared_ptr<Mission> mission = std::make_shared<Mission>(int32Param, abilityRecord);
missionListManager->HandleReusedMissionAndAbility(abilityRequest, mission, abilityRecord);
missionListManager->GetMissionName(abilityRequest, boolParam);
missionListManager->GetMissionName(abilityRequest);
InnerMissionInfo innerMissionInfo;
missionListManager->CreateOrReusedMissionInfo(abilityRequest, innerMissionInfo);
missionListManager->GetTargetMissionAndAbility(abilityRequest, mission, abilityRecord);
@@ -165,4 +165,3 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
ch = nullptr;
return 0;
}
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2022 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 OHOS_FORM_FWK_MOCK_FORM_MGR_PROXY_H
#define OHOS_FORM_FWK_MOCK_FORM_MGR_PROXY_H
#include <gtest/gtest.h>
#include "gmock/gmock.h"
#include "form_mgr_proxy.h"
#include "form_provider_data.h"
namespace OHOS {
namespace AppExecFwk {
class MockFormMgrProxy : public FormMgrProxy {
public:
MockFormMgrProxy(const sptr<IRemoteObject> &impl) : FormMgrProxy(impl) {};
MOCK_METHOD2(GetFormsInfo, int(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos));
MOCK_METHOD0(IsRequestPublishFormSupported, bool());
MOCK_METHOD2(StartAbility, int32_t(const Want &want, const sptr<IRemoteObject> &callerToken));
MOCK_METHOD2(UpdateForm, int32_t(int64_t formId, const FormProviderData &formBindingData));
MOCK_METHOD3(RequestForm, int32_t(int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want));
MOCK_METHOD3(MessageEvent, int32_t(int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken));
MOCK_METHOD3(NotifyFormsPrivacyProtected, int(const std::vector<int64_t> &formIds, bool isProtected,
const sptr<IRemoteObject> &callerToken));
MOCK_METHOD1(DumpStorageFormInfos, int(std::string &formInfos));
MOCK_METHOD2(DumpFormInfoByFormId, int(int64_t formId, std::string &formInfos));
MOCK_METHOD2(DumpFormTimerByFormId, int(int64_t formId, std::string &isTimingService));
MOCK_METHOD3(RouterEvent, int(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken));
MOCK_METHOD3(NotifyFormsVisible, int(const std::vector<int64_t> &formIds, bool isProtected,
const sptr<IRemoteObject> &callerToken));
MOCK_METHOD3(DeleteInvalidForms, int(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
int32_t &numFormsDeleted));
MOCK_METHOD3(NotifyFormsEnableUpdate, int(const std::vector<int64_t> &formIds, bool isProtected,
const sptr<IRemoteObject> &callerToken));
MOCK_METHOD1(GetAllFormsInfo, int(std::vector<FormInfo> &formInfos));
MOCK_METHOD2(GetFormsInfoByApp, int(std::string &bundleName, std::vector<FormInfo> &formInfos));
MOCK_METHOD3(GetFormsInfoByModule, int(std::string &bundleName, std::string &moduleName, std::vector<FormInfo> &formInfos));
MOCK_METHOD2(DumpFormInfoByBundleName, int(const std::string &bundleName, std::string &formInfos));
MOCK_METHOD3(AcquireFormState, int(const Want &want, const sptr<IRemoteObject> &callerToken, FormStateInfo &stateInfo));
MOCK_METHOD0(CheckFMSReady, bool());
};
}
}
#endif // OHOS_FORM_FWK_MOCK_FORM_MGR_PROXY_H
@@ -14,6 +14,8 @@
*/
#include <gtest/gtest.h>
#define private public
#define protected public
#include "ability_thread.h"
#include "ability_context.h"
#include "ability_loader.h"
@@ -23,6 +25,8 @@
#include "ohos_application.h"
#include "system_ability_definition.h"
#include "sys_mgr_client.h"
#undef protected
#undef private
namespace OHOS {
namespace AppExecFwk {
@@ -251,5 +255,758 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_StopService_0200, Function |
EXPECT_TRUE(ret);
usleep(AbilityContextTest::TEST_WAIT_TIME);
}
/**
* @tc.number: AaFwk_Ability_Context_GetCallingBundle_0100
* @tc.name: SetCallingContext and GetCallingBundle
* @tc.desc: Verify that function SetCallingContext and GetCallingBundle.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetCallingBundle_0100, Function | MediumTest | Level1)
{
std::string deviceId = "deviceId";
std::string bundleName = "bundleName";
std::string abilityName = "abilityName";
std::string moduleName = "moduleName";
context_->SetCallingContext(deviceId, bundleName, abilityName, moduleName);
EXPECT_EQ(context_->GetCallingBundle(), "bundleName");
}
/**
* @tc.number: AaFwk_Ability_Context_GetElementName_0100
* @tc.name: GetElementName
* @tc.desc: Verify that function GetElementName.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetElementName_0100, Function | MediumTest | Level1)
{
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
std::shared_ptr<ContextDeal> deal = std::make_shared<ContextDeal>();
deal->SetAbilityInfo(abilityInfo);
auto result = context_->GetElementName();
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetElementName_0200
* @tc.name: GetElementName
* @tc.desc: Verify that function GetElementName.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetElementName_0200, Function | MediumTest | Level1)
{
auto result = context_->GetElementName();
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetCallingAbility_0100
* @tc.name: GetCallingAbility
* @tc.desc: Verify that function GetCallingAbility.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetCallingAbility_0100, Function | MediumTest | Level1)
{
auto result = context_->GetCallingAbility();
EXPECT_TRUE(result != nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_ConnectAbility_0200
* @tc.name: ConnectAbility
* @tc.desc: Verify that function ConnectAbility.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_ConnectAbility_0200, Function | MediumTest | Level1)
{
Want want;
bool ret = context_->ConnectAbility(want, nullptr);
EXPECT_FALSE(ret);
}
/**
* @tc.number: AaFwk_Ability_Context_ConnectAbility_0300
* @tc.name: ConnectAbility
* @tc.desc: Verify that function ConnectAbility.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_ConnectAbility_0300, Function | MediumTest | Level1)
{
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityThread());
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->type = AppExecFwk::AbilityType::DATA;
abilityInfo->name = "DemoAbility";
std::shared_ptr<AbilityLocalRecord> abilityRecord = std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
std::shared_ptr<ContextDeal> deal = std::make_shared<ContextDeal>();
deal->SetAbilityInfo(abilityInfo);
context_->AttachBaseContext(deal);
Want want;
bool ret = context_->ConnectAbility(want, nullptr);
EXPECT_FALSE(ret);
}
/**
* @tc.number: AaFwk_Ability_Context_StopService_0300
* @tc.name: StopAbility
* @tc.desc: Verify that function StopAbility.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_StopService_0300, Function | MediumTest | Level1)
{
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityThread());
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->type = AppExecFwk::AbilityType::DATA;
abilityInfo->name = "DemoAbility";
std::shared_ptr<AbilityLocalRecord> abilityRecord = std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
std::shared_ptr<ContextDeal> deal = std::make_shared<ContextDeal>();
deal->SetAbilityInfo(abilityInfo);
context_->AttachBaseContext(deal);
Want want;
bool ret = context_->StopAbility(want);
EXPECT_FALSE(ret);
}
/**
* @tc.number: AaFwk_Ability_Context_GetApplicationInfo_0100
* @tc.name: GetApplicationInfo
* @tc.desc: Verify that function GetApplicationInfo.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetApplicationInfo_0100, Function | MediumTest | Level1)
{
auto result = context_->GetApplicationInfo();
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetCacheDir_0100
* @tc.name: GetCacheDir
* @tc.desc: Verify that function GetCacheDir.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetCacheDir_0100, Function | MediumTest | Level1)
{
auto result = context_->GetCacheDir();
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_GetCodeCacheDir_0100
* @tc.name: GetCodeCacheDir
* @tc.desc: Verify that function GetCodeCacheDir.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetCodeCacheDir_0100, Function | MediumTest | Level1)
{
auto result = context_->GetCodeCacheDir();
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_GetDatabaseDir_0100
* @tc.name: GetDatabaseDir
* @tc.desc: Verify that function GetDatabaseDir.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetDatabaseDir_0100, Function | MediumTest | Level1)
{
auto result = context_->GetDatabaseDir();
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_GetDataDir_0100
* @tc.name: GetDataDir
* @tc.desc: Verify that function GetDataDir.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetDataDir_0100, Function | MediumTest | Level1)
{
auto result = context_->GetDataDir();
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_GetBundleManager_0100
* @tc.name: GetBundleManager
* @tc.desc: Verify that function GetBundleManager.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetBundleManager_0100, Function | MediumTest | Level1)
{
auto result = context_->GetBundleManager();
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetDir_0100
* @tc.name: GetDir
* @tc.desc: Verify that function GetDir.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetDir_0100, Function | MediumTest | Level1)
{
std::string name = "name";
int32_t mode = 1;
auto result = context_->GetDir(name, mode);
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_GetBundleCodePath_0100
* @tc.name: GetBundleCodePath
* @tc.desc: Verify that function GetBundleCodePath.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetBundleCodePath_0100, Function | MediumTest | Level1)
{
auto result = context_->GetBundleCodePath();
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_GetBundleName_0100
* @tc.name: GetBundleName
* @tc.desc: Verify that function GetBundleName.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetBundleName_0100, Function | MediumTest | Level1)
{
auto result = context_->GetBundleName();
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_GetBundleResourcePath_0100
* @tc.name: GetBundleResourcePath
* @tc.desc: Verify that function GetBundleResourcePath.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetBundleResourcePath_0100, Function | MediumTest | Level1)
{
auto result = context_->GetBundleResourcePath();
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_GetApplicationContext_0100
* @tc.name: GetApplicationContext
* @tc.desc: Verify that function GetApplicationContext.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetApplicationContext_0100, Function | MediumTest | Level1)
{
auto result = context_->GetApplicationContext();
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetContext_0100
* @tc.name: GetContext
* @tc.desc: Verify that function GetContext.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetContext_0100, Function | MediumTest | Level1)
{
auto result = context_->GetContext();
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetAbilityManager_0100
* @tc.name: GetAbilityManager
* @tc.desc: Verify that function GetAbilityManager.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetAbilityManager_0100, Function | MediumTest | Level1)
{
auto result = context_->GetAbilityManager();
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetProcessInfo_0100
* @tc.name: GetProcessInfo
* @tc.desc: Verify that function GetProcessInfo.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetProcessInfo_0100, Function | MediumTest | Level1)
{
auto result = context_->GetProcessInfo();
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetAppType_0100
* @tc.name: GetAppType
* @tc.desc: Verify that function GetAppType.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetAppType_0100, Function | MediumTest | Level1)
{
auto result = context_->GetAppType();
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_GetAbilityInfo_0100
* @tc.name: GetAbilityInfo
* @tc.desc: Verify that function GetAbilityInfo.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetAbilityInfo_0100, Function | MediumTest | Level1)
{
auto result = context_->GetAbilityInfo();
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetHapModuleInfo_0100
* @tc.name: GetHapModuleInfo
* @tc.desc: Verify that function GetHapModuleInfo.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetHapModuleInfo_0100, Function | MediumTest | Level1)
{
auto result = context_->GetHapModuleInfo();
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetHapModuleInfo_0100
* @tc.name: GetAbilityInfoType
* @tc.desc: Verify that function GetAbilityInfoType.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetAbilityInfoType_0100, Function | MediumTest | Level1)
{
auto result = context_->GetAbilityInfoType();
EXPECT_EQ(result, AppExecFwk::AbilityType::UNKNOWN);
}
/**
* @tc.number: AaFwk_Ability_Context_GetAbilityInfoType_0200
* @tc.name: GetAbilityInfoType
* @tc.desc: Verify that function GetAbilityInfoType.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetAbilityInfoType_0200, Function | MediumTest | Level1)
{
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityThread());
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->type = AppExecFwk::AbilityType::SERVICE;
abilityInfo->name = "DemoAbility";
std::shared_ptr<AbilityLocalRecord> abilityRecord = std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
std::shared_ptr<ContextDeal> deal = std::make_shared<ContextDeal>();
deal->SetAbilityInfo(abilityInfo);
context_->AttachBaseContext(deal);
auto result = context_->GetAbilityInfoType();
EXPECT_EQ(result, AppExecFwk::AbilityType::SERVICE);
}
/**
* @tc.number: AaFwk_Ability_Context_CreateBundleContext_0100
* @tc.name: CreateBundleContext
* @tc.desc: Verify that function CreateBundleContext.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_CreateBundleContext_0100, Function | MediumTest | Level1)
{
std::string bundleName;
int32_t flag = 1;
int32_t accountId = 1;
auto result = context_->CreateBundleContext(bundleName, flag, accountId);
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetResourceManager_0100
* @tc.name: GetResourceManager
* @tc.desc: Verify that function GetResourceManager.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetResourceManager_0100, Function | MediumTest | Level1)
{
auto result = context_->GetResourceManager();
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetResourceManager_0200
* @tc.name: GetResourceManager
* @tc.desc: Verify that function GetResourceManager.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetResourceManager_0200, Function | MediumTest | Level1)
{
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityThread());
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->type = AppExecFwk::AbilityType::SERVICE;
abilityInfo->name = "DemoAbility";
std::shared_ptr<AbilityLocalRecord> abilityRecord = std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
std::shared_ptr<ContextDeal> deal = std::make_shared<ContextDeal>();
deal->SetAbilityInfo(abilityInfo);
context_->AttachBaseContext(deal);
auto result = context_->GetResourceManager();
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_VerifyPermission_0100
* @tc.name: VerifyPermission
* @tc.desc: Verify that function VerifyPermission.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_VerifyPermission_0100, Function | MediumTest | Level1)
{
std::string permission;
int32_t pid = 1;
int32_t uid = 1;
auto result = context_->VerifyPermission(permission, pid, uid);
EXPECT_EQ(result, AppExecFwk::Constants::PERMISSION_NOT_GRANTED);
}
/**
* @tc.number: AaFwk_Ability_Context_VerifyPermission_0200
* @tc.name: VerifyPermission
* @tc.desc: Verify that function VerifyPermission.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_VerifyPermission_0200, Function | MediumTest | Level1)
{
std::string permission = "permission";
int32_t pid = 1;
int32_t uid = 1;
auto result = context_->VerifyPermission(permission, pid, uid);
EXPECT_EQ(result, AppExecFwk::Constants::PERMISSION_NOT_GRANTED);
}
/**
* @tc.number: AaFwk_Ability_Context_VerifyPermission_0300
* @tc.name: VerifyPermission
* @tc.desc: Verify that function VerifyPermission.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_VerifyPermission_0300, Function | MediumTest | Level1)
{
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityThread());
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->type = AppExecFwk::AbilityType::SERVICE;
abilityInfo->name = "DemoAbility";
std::shared_ptr<AbilityLocalRecord> abilityRecord = std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
std::shared_ptr<ContextDeal> deal = std::make_shared<ContextDeal>();
deal->SetAbilityInfo(abilityInfo);
context_->AttachBaseContext(deal);
std::string permission = "permission";
int32_t pid = 1;
int32_t uid = 1;
auto result = context_->VerifyPermission(permission, pid, uid);
EXPECT_EQ(result, AppExecFwk::Constants::PERMISSION_NOT_GRANTED);
}
/**
* @tc.number: AaFwk_Ability_Context_GetPermissionDes_0100
* @tc.name: GetPermissionDes
* @tc.desc: Verify that function GetPermissionDes.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetPermissionDes_0100, Function | MediumTest | Level1)
{
std::string permissionName = "permissionName";
std::string des = "des";
context_->GetPermissionDes(permissionName, des);
EXPECT_TRUE(permissionName.length() != des.length());
}
/**
* @tc.number: AaFwk_Ability_Context_RequestPermissionsFromUser_0100
* @tc.name: RequestPermissionsFromUser
* @tc.desc: Verify that function RequestPermissionsFromUser.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_RequestPermissionsFromUser_0100, Function | MediumTest | Level1)
{
std::vector<std::string> permissions;
std::vector<int> permissionsState;
context_->RequestPermissionsFromUser(permissions, permissionsState, nullptr);
EXPECT_TRUE(permissions.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_RequestPermissionsFromUser_0200
* @tc.name: RequestPermissionsFromUser
* @tc.desc: Verify that function RequestPermissionsFromUser.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_RequestPermissionsFromUser_0200, Function | MediumTest | Level1)
{
std::vector<std::string> permissions;
permissions.emplace_back("a");
std::vector<int> permissionsState;
context_->RequestPermissionsFromUser(permissions, permissionsState, nullptr);
EXPECT_TRUE(!permissions.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_DeleteFile_0100
* @tc.name: DeleteFile
* @tc.desc: Verify that function DeleteFile.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_DeleteFile_0100, Function | MediumTest | Level1)
{
std::string fileName;
auto result = context_->DeleteFile(fileName);
EXPECT_FALSE(result);
}
/**
* @tc.number: AaFwk_Ability_Context_GetCaller_0100
* @tc.name: GetCaller
* @tc.desc: Verify that function GetCaller.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetCaller_0100, Function | MediumTest | Level1)
{
auto result = context_->GetCaller();
EXPECT_EQ(result.GetScheme(), "");
}
/**
* @tc.number: AaFwk_Ability_Context_GetExternalCacheDir_0100
* @tc.name: GetExternalCacheDir
* @tc.desc: Verify that function GetExternalCacheDir.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetExternalCacheDir_0100, Function | MediumTest | Level1)
{
auto result = context_->GetExternalCacheDir();
EXPECT_EQ(result, "");
}
/**
* @tc.number: AaFwk_Ability_Context_GetExternalFilesDir_0100
* @tc.name: GetExternalFilesDir
* @tc.desc: Verify that function GetExternalFilesDir.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetExternalFilesDir_0100, Function | MediumTest | Level1)
{
std::string type;
auto result = context_->GetExternalFilesDir(type);
EXPECT_EQ(result, "");
}
/**
* @tc.number: AaFwk_Ability_Context_GetFilesDir_0100
* @tc.name: GetFilesDir
* @tc.desc: Verify that function GetFilesDir.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetFilesDir_0100, Function | MediumTest | Level1)
{
auto result = context_->GetFilesDir();
EXPECT_EQ(result, "");
}
/**
* @tc.number: AaFwk_Ability_Context_GetNoBackupFilesDir_0100
* @tc.name: GetNoBackupFilesDir
* @tc.desc: Verify that function GetNoBackupFilesDir.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetNoBackupFilesDir_0100, Function | MediumTest | Level1)
{
auto result = context_->GetNoBackupFilesDir();
EXPECT_EQ(result, "");
}
/**
* @tc.number: AaFwk_Ability_Context_GetDistributedDir_0100
* @tc.name: GetDistributedDir
* @tc.desc: Verify that function GetDistributedDir.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetDistributedDir_0100, Function | MediumTest | Level1)
{
auto result = context_->GetDistributedDir();
EXPECT_EQ(result, "");
}
/**
* @tc.number: AaFwk_Ability_Context_GetAbilityPackageContext_0100
* @tc.name: GetAbilityPackageContext
* @tc.desc: Verify that function GetAbilityPackageContext.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetAbilityPackageContext_0100, Function | MediumTest | Level1)
{
auto result = context_->GetAbilityPackageContext();
EXPECT_TRUE(result == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetProcessName_0100
* @tc.name: GetProcessName
* @tc.desc: Verify that function GetProcessName.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetProcessName_0100, Function | MediumTest | Level1)
{
auto result = context_->GetProcessName();
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_InitResourceManager_0100
* @tc.name: InitResourceManager
* @tc.desc: Verify that function InitResourceManager.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_InitResourceManager_0100, Function | MediumTest | Level1)
{
BundleInfo bundleInfo;
std::shared_ptr<ContextDeal> deal = nullptr;
context_->InitResourceManager(bundleInfo, deal);
EXPECT_TRUE(deal == nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetString_0100
* @tc.name: GetString
* @tc.desc: Verify that function GetString.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetString_0100, Function | MediumTest | Level1)
{
int32_t resId = 1;
auto result = context_->GetString(resId);
EXPECT_EQ(result, "");
}
/**
* @tc.number: AaFwk_Ability_Context_GetStringArray_0100
* @tc.name: GetStringArray
* @tc.desc: Verify that function GetStringArray.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetStringArray_0100, Function | MediumTest | Level1)
{
int32_t resId = 1;
auto result = context_->GetStringArray(resId);
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_GetIntArray_0100
* @tc.name: GetIntArray
* @tc.desc: Verify that function GetIntArray.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetIntArray_0100, Function | MediumTest | Level1)
{
int32_t resId = 1;
auto result = context_->GetIntArray(resId);
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_GetTheme_0100
* @tc.name: GetTheme
* @tc.desc: Verify that function GetTheme.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetTheme_0100, Function | MediumTest | Level1)
{
auto result = context_->GetTheme();
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_GetPattern_0100
* @tc.name: GetPattern
* @tc.desc: Verify that function GetPattern.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetPattern_0100, Function | MediumTest | Level1)
{
auto result = context_->GetPattern();
EXPECT_TRUE(result.empty());
}
/**
* @tc.number: AaFwk_Ability_Context_GetColor_0100
* @tc.name: GetColor
* @tc.desc: Verify that function GetColor.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetColor_0100, Function | MediumTest | Level1)
{
int32_t resId = 1;
auto result = context_->GetColor(resId);
EXPECT_EQ(result, INVALID_RESOURCE_VALUE);
}
/**
* @tc.number: AaFwk_Ability_Context_GetThemeId_0100
* @tc.name: GetThemeId
* @tc.desc: Verify that function GetThemeId.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetThemeId_0100, Function | MediumTest | Level1)
{
auto result = context_->GetThemeId();
EXPECT_EQ(result, -1);
}
/**
* @tc.number: AaFwk_Ability_Context_TerminateAbilityResult_0100
* @tc.name: TerminateAbilityResult
* @tc.desc: Verify that function TerminateAbilityResult.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_TerminateAbilityResult_0100, Function | MediumTest | Level1)
{
int32_t startId = 1;
auto result = context_->TerminateAbilityResult(startId);
EXPECT_FALSE(result);
}
/**
* @tc.number: AaFwk_Ability_Context_GetDisplayOrientation_0100
* @tc.name: GetDisplayOrientation
* @tc.desc: Verify that function GetDisplayOrientation.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetDisplayOrientation_0100, Function | MediumTest | Level1)
{
auto result = context_->GetDisplayOrientation();
EXPECT_EQ(result, 0);
}
/**
* @tc.number: AaFwk_Ability_Context_GetPreferencesDir_0100
* @tc.name: GetPreferencesDir
* @tc.desc: Verify that function GetPreferencesDir.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetPreferencesDir_0100, Function | MediumTest | Level1)
{
auto result = context_->GetPreferencesDir();
EXPECT_EQ(result, "");
}
/**
* @tc.number: AaFwk_Ability_Context_SetColorMode_0100
* @tc.name: SetColorMode and GetColorMode
* @tc.desc: Verify that function SetColorMode and GetColorMode.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_SetColorMode_0100, Function | MediumTest | Level1)
{
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityThread());
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
std::shared_ptr<AbilityLocalRecord> abilityRecord = std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
std::shared_ptr<ContextDeal> deal = std::make_shared<ContextDeal>();
deal->SetAbilityInfo(abilityInfo);
context_->AttachBaseContext(deal);
int32_t mode = 1;
context_->SetColorMode(mode);
auto result = context_->GetColorMode();
EXPECT_EQ(result, 1);
EXPECT_TRUE(context_->baseContext_ != nullptr);
}
/**
* @tc.number: AaFwk_Ability_Context_GetMissionId_0100
* @tc.name: GetMissionId
* @tc.desc: Verify that function GetMissionId.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetMissionId_0100, Function | MediumTest | Level1)
{
auto result = context_->GetMissionId();
EXPECT_EQ(result, -1);
}
/**
* @tc.number: AaFwk_Ability_Context_IsUpdatingConfigurations_0100
* @tc.name: IsUpdatingConfigurations
* @tc.desc: Verify that function IsUpdatingConfigurations.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_IsUpdatingConfigurations_0100, Function | MediumTest | Level1)
{
auto result = context_->IsUpdatingConfigurations();
EXPECT_FALSE(result);
}
/**
* @tc.number: AaFwk_Ability_Context_PrintDrawnCompleted_0100
* @tc.name: PrintDrawnCompleted
* @tc.desc: Verify that function PrintDrawnCompleted.
*/
HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_PrintDrawnCompleted_0100, Function | MediumTest | Level1)
{
auto result = context_->PrintDrawnCompleted();
EXPECT_FALSE(result);
}
} // namespace AppExecFwk
} // namespace OHOS
+2
View File
@@ -327,6 +327,7 @@ group("unittest") {
"app_spawn_socket_test:unittest",
"app_state_observer_manager_test:unittest",
"appkit:unittest",
"application_context_test:unittest",
"atomic_service_status_callback_proxy_test:unittest",
"atomic_service_status_callback_stub_test:unittest",
"background_task_observer_test:unittest",
@@ -385,6 +386,7 @@ group("unittest") {
"start_options_test:unittest",
"stop_user_callback_proxy_test:unittest",
"stop_user_callback_stub_test:unittest",
"sys_mgr_client_test:unittest",
"system_ability_token_callback_stub_test:unittest",
"task_data_persistence_mgr_test:unittest",
"trigger_Info_test:unittest",
@@ -128,5 +128,44 @@ HWTEST_F(AbilityExtensionContextTest, SetAbilityInfo_0100, TestSize.Level1)
HILOG_INFO("SetAbilityInfo end");
}
/**
* @tc.number: SetAbilityInfo_0200
* @tc.name: SetAbilityInfo
* @tc.desc: Set AbilityInfo Failed
*/
HWTEST_F(AbilityExtensionContextTest, SetAbilityInfo_0200, TestSize.Level1)
{
HILOG_INFO("SetAbilityInfo start");
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
info->name = "ExtensionContextTest";
std::shared_ptr<AppExecFwk::AbilityLocalRecord> record =
std::make_shared<AppExecFwk::AbilityLocalRecord>(info, nullptr);
std::shared_ptr<AppExecFwk::OHOSApplication> application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AppExecFwk::AbilityHandler> handler = std::make_shared<AppExecFwk::AbilityHandler>(nullptr);
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
std::shared_ptr<AbilityRuntime::ContextImpl> contextImpl = std::make_shared<AbilityRuntime::ContextImpl>();
std::shared_ptr<AbilityRuntime::ApplicationContext> applicationContext =
std::make_shared<AbilityRuntime::ApplicationContext>();
applicationContext->AttachContextImpl(contextImpl);
applicationContext->InitApplicationContext();
application->SetApplicationContext(applicationContext);
ExtensionBase<ExtensionContext> extensionBase;
extensionBase.Init(record, application, handler, token);
std::shared_ptr<ExtensionContext> context = extensionBase.GetContext();
std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = context->GetAbilityInfo();
EXPECT_STREQ(abilityInfo->name.c_str(), "ExtensionContextTest");
info = nullptr;
context->SetAbilityInfo(info);
abilityInfo = context->GetAbilityInfo();
EXPECT_EQ(abilityInfo, nullptr);
HILOG_INFO("SetAbilityInfo end");
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -58,6 +58,7 @@ ohos_unittest("ability_manager_service_test") {
"${ability_runtime_innerkits_path}/connectionobs_manager:connection_obs_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/unittest:abilityms_test_source",
@@ -69,12 +70,6 @@ ohos_unittest("ability_manager_service_test") {
"ability_base:configuration",
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:app_manager",
"ability_runtime:connection_obs_manager",
"access_token:libaccesstoken_sdk",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"common_event_service:cesfwk_core",
@@ -91,6 +91,8 @@ struct VerificationInfo {
{
return IPCSkeleton::GetCallingTokenID() == accessTokenId;
}
bool JudgeCallerIsAllowedToUseSystemAPI() const;
};
} // namespace AAFwk
} // namespace OHOS
@@ -115,5 +115,9 @@ int PermissionVerification::JudgeInvisibleAndBackground(const VerificationInfo &
{
return MyFlag::flag_;
}
bool PermissionVerification::JudgeCallerIsAllowedToUseSystemAPI() const
{
return true;
}
} // namespace AAFwk
} // namespace OHOS
@@ -0,0 +1,57 @@
# Copyright (c) 2022 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.
import("//build/ohos.gni")
import("//build/test.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
ohos_unittest("application_context_test") {
module_out_path = "ability_runtime/service_extension"
include_dirs = [ "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include" ]
sources = [
"//foundation/ability/ability_runtime/test/unittest/application_context_test/mock_context_impl.cpp",
"application_context_test.cpp",
]
configs = [ "${ability_runtime_services_path}/common:common_config" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${ability_runtime_native_path}/ability/native:service_extension",
"${ability_runtime_native_path}/appkit:app_context",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:configuration",
"ability_runtime:ability_context_native",
"ability_runtime:abilitykit_native",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
]
}
group("unittest") {
testonly = true
deps = [ ":application_context_test" ]
}
@@ -0,0 +1,702 @@
/*
* Copyright (c) 2022 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 <gtest/gtest.h>
#define private public
#include "application_context.h"
#undef private
#include "mock_ability_token.h"
#include "mock_context_impl.h"
using namespace testing::ext;
namespace OHOS {
namespace AbilityRuntime {
class ApplicationContextTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
std::shared_ptr<ApplicationContext> context_ = nullptr;
std::shared_ptr<MockContextImpl> mock_ = nullptr;
};
void ApplicationContextTest::SetUpTestCase(void)
{}
void ApplicationContextTest::TearDownTestCase(void)
{}
void ApplicationContextTest::SetUp()
{
context_ = std::make_shared<ApplicationContext>();
mock_ = std::make_shared<MockContextImpl>();
}
void ApplicationContextTest::TearDown()
{}
/**
* @tc.number: RegisterAbilityLifecycleCallback_0100
* @tc.name: RegisterAbilityLifecycleCallback
* @tc.desc: Register Ability Lifecycle Callback
*/
HWTEST_F(ApplicationContextTest, RegisterAbilityLifecycleCallback_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "RegisterAbilityLifecycleCallback_0100 start";
context_->callbacks_.clear();
std::shared_ptr<AbilityLifecycleCallback> abilityLifecycleCallback = nullptr;
context_->RegisterAbilityLifecycleCallback(abilityLifecycleCallback);
EXPECT_TRUE(context_->IsAbilityLifecycleCallbackEmpty());
GTEST_LOG_(INFO) << "RegisterAbilityLifecycleCallback_0100 end";
}
/**
* @tc.number: RegisterEnvironmentCallback_0100
* @tc.name: RegisterEnvironmentCallback
* @tc.desc: Register Environment Callback
*/
HWTEST_F(ApplicationContextTest, RegisterEnvironmentCallback_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "RegisterEnvironmentCallback_0100 start";
context_->envCallbacks_.clear();
std::shared_ptr<EnvironmentCallback> environmentCallback = nullptr;
context_->RegisterEnvironmentCallback(environmentCallback);
EXPECT_TRUE(context_->envCallbacks_.empty());
GTEST_LOG_(INFO) << "RegisterEnvironmentCallback_0100 end";
}
/**
* @tc.number: GetBundleName_0100
* @tc.name: GetBundleName
* @tc.desc: Get BundleName failed
*/
HWTEST_F(ApplicationContextTest, GetBundleName_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetBundleName_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetBundleName();
EXPECT_EQ(ret, "");
GTEST_LOG_(INFO) << "GetBundleName_0100 end";
}
/**
* @tc.number: GetBundleName_0200
* @tc.name: GetBundleName
* @tc.desc: Get BundleName sucess
*/
HWTEST_F(ApplicationContextTest, GetBundleName_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetBundleName_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetBundleName();
EXPECT_EQ(ret, "com.test.bundleName");
GTEST_LOG_(INFO) << "GetBundleName_0200 end";
}
/**
* @tc.number: CreateBundleContext_0100
* @tc.name: CreateBundleContext
* @tc.desc: Create BundleContext failed
*/
HWTEST_F(ApplicationContextTest, CreateBundleContext_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "CreateBundleContext_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
std::string bundleName = "com.test.bundleName";
auto ret = context_->CreateBundleContext(bundleName);
EXPECT_EQ(ret, nullptr);
GTEST_LOG_(INFO) << "CreateBundleContext_0100 end";
}
/**
* @tc.number: CreateBundleContext_0200
* @tc.name: CreateBundleContext
* @tc.desc: Create BundleContext sucess
*/
HWTEST_F(ApplicationContextTest, CreateBundleContext_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "CreateBundleContext_0200 start";
context_->AttachContextImpl(mock_);
std::string bundleName = "com.test.bundleName";
auto ret = context_->CreateBundleContext(bundleName);
EXPECT_NE(ret, nullptr);
GTEST_LOG_(INFO) << "CreateBundleContext_0200 end";
}
/**
* @tc.number: CreateModuleContext_0100
* @tc.name: CreateModuleContext
* @tc.desc: Create ModuleContext failed
*/
HWTEST_F(ApplicationContextTest, CreateModuleContext_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "CreateModuleContext_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
std::string moduleName = "moduleName";
auto ret = context_->CreateModuleContext(moduleName);
EXPECT_EQ(ret, nullptr);
GTEST_LOG_(INFO) << "CreateModuleContext_0100 end";
}
/**
* @tc.number: CreateModuleContext_0200
* @tc.name: CreateModuleContext
* @tc.desc: Create ModuleContext sucess
*/
HWTEST_F(ApplicationContextTest, CreateModuleContext_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "CreateModuleContext_0200 start";
context_->AttachContextImpl(mock_);
std::string moduleName = "moduleName";
auto ret = context_->CreateModuleContext(moduleName);
EXPECT_NE(ret, nullptr);
GTEST_LOG_(INFO) << "CreateModuleContext_0200 end";
}
/**
* @tc.number: CreateModuleContext_0300
* @tc.name: CreateModuleContext
* @tc.desc: Create ModuleContext failed
*/
HWTEST_F(ApplicationContextTest, CreateModuleContext_0300, TestSize.Level1)
{
GTEST_LOG_(INFO) << "CreateModuleContext_0300 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
std::string moduleName = "moduleName";
std::string bundleName = "com.test.bundleName";
auto ret = context_->CreateModuleContext(bundleName, moduleName);
EXPECT_EQ(ret, nullptr);
GTEST_LOG_(INFO) << "CreateModuleContext_0300 end";
}
/**
* @tc.number: CreateModuleContext_0400
* @tc.name: CreateModuleContext
* @tc.desc: Create ModuleContext sucess
*/
HWTEST_F(ApplicationContextTest, CreateModuleContext_0400, TestSize.Level1)
{
GTEST_LOG_(INFO) << "CreateModuleContext_0400 start";
context_->AttachContextImpl(mock_);
std::string moduleName = "moduleName";
std::string bundleName = "com.test.bundleName";
auto ret = context_->CreateModuleContext(bundleName, moduleName);
EXPECT_NE(ret, nullptr);
GTEST_LOG_(INFO) << "CreateModuleContext_0400 end";
}
/**
* @tc.number: GetApplicationInfo_0100
* @tc.name: GetApplicationInfo
* @tc.desc: Get ApplicationInfo failed
*/
HWTEST_F(ApplicationContextTest, GetApplicationInfo_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetApplicationInfo_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetApplicationInfo();
EXPECT_EQ(ret, nullptr);
GTEST_LOG_(INFO) << "GetApplicationInfo_0100 end";
}
/**
* @tc.number: GetApplicationInfo_0200
* @tc.name: GetApplicationInfo
* @tc.desc:Get ApplicationInfo sucess
*/
HWTEST_F(ApplicationContextTest, GetApplicationInfo_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetApplicationInfo_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetApplicationInfo();
EXPECT_NE(ret, nullptr);
GTEST_LOG_(INFO) << "GetApplicationInfo_0200 end";
}
/**
* @tc.number: GetResourceManager_0100
* @tc.name: GetResourceManager
* @tc.desc: Get ResourceManager failed
*/
HWTEST_F(ApplicationContextTest, GetResourceManager_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetResourceManager_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetResourceManager();
EXPECT_EQ(ret, nullptr);
GTEST_LOG_(INFO) << "GetResourceManager_0100 end";
}
/**
* @tc.number: GetApplicationInfo_0200
* @tc.name: GetResourceManager
* @tc.desc:Get ResourceManager sucess
*/
HWTEST_F(ApplicationContextTest, GetResourceManager_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetResourceManager_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetResourceManager();
EXPECT_NE(ret, nullptr);
GTEST_LOG_(INFO) << "GetResourceManager_0200 end";
}
/**
* @tc.number: GetBundleCodePath_0100
* @tc.name: GetBundleCodePath
* @tc.desc: Get BundleCode Path failed
*/
HWTEST_F(ApplicationContextTest, GetBundleCodePath_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetBundleCodePath_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetBundleCodePath();
EXPECT_EQ(ret, "");
GTEST_LOG_(INFO) << "GetBundleCodePath_0100 end";
}
/**
* @tc.number: GetBundleCodePath_0200
* @tc.name: GetBundleCodePath
* @tc.desc:Get BundleCode Path sucess
*/
HWTEST_F(ApplicationContextTest, GetBundleCodePath_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetBundleCodePath_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetBundleCodePath();
EXPECT_EQ(ret, "codePath");
GTEST_LOG_(INFO) << "GetBundleCodePath_0200 end";
}
/**
* @tc.number: GetHapModuleInfo_0100
* @tc.name: GetHapModuleInfo
* @tc.desc: Get HapModuleInfo failed
*/
HWTEST_F(ApplicationContextTest, GetHapModuleInfo_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetHapModuleInfo_0100 start";
auto ret = context_->GetHapModuleInfo();
EXPECT_EQ(ret, nullptr);
GTEST_LOG_(INFO) << "GetHapModuleInfo_0100 end";
}
/**
* @tc.number: GetBundleCodeDir_0100
* @tc.name: GetBundleCodeDir
* @tc.desc: Get Bundle Code Dir failed
*/
HWTEST_F(ApplicationContextTest, GetBundleCodeDir_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetBundleCodeDir_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetBundleCodeDir();
EXPECT_EQ(ret, "");
GTEST_LOG_(INFO) << "GetBundleCodeDir_0100 end";
}
/**
* @tc.number: GetBundleCodeDir_0200
* @tc.name: GetBundleCodeDir
* @tc.desc:Get Bundle Code Dir sucess
*/
HWTEST_F(ApplicationContextTest, GetBundleCodeDir_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetBundleCodeDir_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetBundleCodeDir();
EXPECT_EQ(ret, "/code");
GTEST_LOG_(INFO) << "GetBundleCodeDir_0200 end";
}
/**
* @tc.number: GetCacheDir_0100
* @tc.name: GetCacheDir
* @tc.desc: Get Cache Dir failed
*/
HWTEST_F(ApplicationContextTest, GetCacheDir_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetCacheDir_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetCacheDir();
EXPECT_EQ(ret, "");
GTEST_LOG_(INFO) << "GetCacheDir_0100 end";
}
/**
* @tc.number: GetCacheDir_0200
* @tc.name: GetCacheDir
* @tc.desc:Get Cache Dir sucess
*/
HWTEST_F(ApplicationContextTest, GetCacheDir_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetCacheDir_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetCacheDir();
EXPECT_EQ(ret, "/cache");
GTEST_LOG_(INFO) << "GetCacheDir_0200 end";
}
/**
* @tc.number: GetTempDir_0100
* @tc.name: GetTempDir
* @tc.desc: Get Temp Dir failed
*/
HWTEST_F(ApplicationContextTest, GetTempDir_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetTempDir_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetTempDir();
EXPECT_EQ(ret, "");
GTEST_LOG_(INFO) << "GetTempDir_0100 end";
}
/**
* @tc.number: GetTempDir_0200
* @tc.name: GetTempDir
* @tc.desc:Get Temp Dir sucess
*/
HWTEST_F(ApplicationContextTest, GetTempDir_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetTempDir_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetTempDir();
EXPECT_EQ(ret, "/temp");
GTEST_LOG_(INFO) << "GetTempDir_0200 end";
}
/**
* @tc.number: GetFilesDir_0100
* @tc.name: GetFilesDir
* @tc.desc: Get Files Dir failed
*/
HWTEST_F(ApplicationContextTest, GetFilesDir_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetFilesDir_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetFilesDir();
EXPECT_EQ(ret, "");
GTEST_LOG_(INFO) << "GetFilesDir_0100 end";
}
/**
* @tc.number: GetFilesDir_0200
* @tc.name: GetFilesDir
* @tc.desc:Get Files Dir sucess
*/
HWTEST_F(ApplicationContextTest, GetFilesDir_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetFilesDir_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetFilesDir();
EXPECT_EQ(ret, "/files");
GTEST_LOG_(INFO) << "GetFilesDir_0200 end";
}
/**
* @tc.number: IsUpdatingConfigurations_0100
* @tc.name: IsUpdatingConfigurations
* @tc.desc: Is Updating Configurations failed
*/
HWTEST_F(ApplicationContextTest, IsUpdatingConfigurations_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->IsUpdatingConfigurations();
EXPECT_EQ(ret, false);
GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0100 end";
}
/**
* @tc.number: IsUpdatingConfigurations_0200
* @tc.name: IsUpdatingConfigurations
* @tc.desc:Is Updating Configurations sucess
*/
HWTEST_F(ApplicationContextTest, IsUpdatingConfigurations_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->IsUpdatingConfigurations();
EXPECT_EQ(ret, true);
GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0200 end";
}
/**
* @tc.number: PrintDrawnCompleted_0100
* @tc.name: PrintDrawnCompleted
* @tc.desc: Print Drawn Completed failed
*/
HWTEST_F(ApplicationContextTest, PrintDrawnCompleted_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "PrintDrawnCompleted_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->PrintDrawnCompleted();
EXPECT_EQ(ret, false);
GTEST_LOG_(INFO) << "PrintDrawnCompleted_0100 end";
}
/**
* @tc.number: PrintDrawnCompleted_0200
* @tc.name: PrintDrawnCompleted
* @tc.desc:Print Drawn Completed sucess
*/
HWTEST_F(ApplicationContextTest, PrintDrawnCompleted_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "PrintDrawnCompleted_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->PrintDrawnCompleted();
EXPECT_EQ(ret, true);
GTEST_LOG_(INFO) << "PrintDrawnCompleted_0200 end";
}
/**
* @tc.number: GetDatabaseDir_0100
* @tc.name: GetDatabaseDir
* @tc.desc: Get Data base Dir failed
*/
HWTEST_F(ApplicationContextTest, GetDatabaseDir_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetDatabaseDir_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetDatabaseDir();
EXPECT_EQ(ret, "");
GTEST_LOG_(INFO) << "GetDatabaseDir_0100 end";
}
/**
* @tc.number: GetDatabaseDir_0200
* @tc.name: GetDatabaseDir
* @tc.desc:Get Data base Dir sucess
*/
HWTEST_F(ApplicationContextTest, GetDatabaseDir_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetDatabaseDir_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetDatabaseDir();
EXPECT_EQ(ret, "/data/app/database");
GTEST_LOG_(INFO) << "GetDatabaseDir_0200 end";
}
/**
* @tc.number: GetPreferencesDir_0100
* @tc.name: GetPreferencesDir
* @tc.desc: Get Preferences Dir failed
*/
HWTEST_F(ApplicationContextTest, GetPreferencesDir_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetPreferencesDir_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetPreferencesDir();
EXPECT_EQ(ret, "");
GTEST_LOG_(INFO) << "GetPreferencesDir_0100 end";
}
/**
* @tc.number: GetPreferencesDir_0200
* @tc.name: GetPreferencesDir
* @tc.desc:Get Preferences Dir sucess
*/
HWTEST_F(ApplicationContextTest, GetPreferencesDir_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetPreferencesDir_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetPreferencesDir();
EXPECT_EQ(ret, "/preferences");
GTEST_LOG_(INFO) << "GetPreferencesDir_0200 end";
}
/**
* @tc.number: GetDistributedFilesDir_0100
* @tc.name: GetDistributedFilesDir
* @tc.desc: Get Distributed Files Dir failed
*/
HWTEST_F(ApplicationContextTest, GetDistributedFilesDir_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetDistributedFilesDir_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetDistributedFilesDir();
EXPECT_EQ(ret, "");
GTEST_LOG_(INFO) << "GetDistributedFilesDir_0100 end";
}
/**
* @tc.number: GetDistributedFilesDir_0200
* @tc.name: GetDistributedFilesDir
* @tc.desc:Get Distributed Files Dir sucess
*/
HWTEST_F(ApplicationContextTest, GetDistributedFilesDir_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetDistributedFilesDir_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetDistributedFilesDir();
EXPECT_EQ(ret, "/mnt/hmdfs/device_view/local/data/bundleName");
GTEST_LOG_(INFO) << "GetDistributedFilesDir_0200 end";
}
/**
* @tc.number: GetToken_0100
* @tc.name: GetToken
* @tc.desc: Get Token failed
*/
HWTEST_F(ApplicationContextTest, GetToken_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetToken_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetToken();
EXPECT_EQ(ret, nullptr);
GTEST_LOG_(INFO) << "GetToken_0100 end";
}
/**
* @tc.number: GetToken_0200
* @tc.name: GetToken
* @tc.desc:Get Token sucess
*/
HWTEST_F(ApplicationContextTest, GetToken_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetToken_0200 start";
std::shared_ptr<ContextImpl> contextImpl = std::make_shared<ContextImpl>();
context_->AttachContextImpl(contextImpl);
sptr<IRemoteObject> token = new OHOS::AppExecFwk::MockAbilityToken();
context_->SetToken(token);
auto ret = context_->GetToken();
EXPECT_EQ(ret, token);
GTEST_LOG_(INFO) << "GetToken_0200 end";
}
/**
* @tc.number: GetArea_0100
* @tc.name: GetArea
* @tc.desc: Get Area failed
*/
HWTEST_F(ApplicationContextTest, GetArea_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetArea_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetArea();
EXPECT_EQ(ret, 1);
GTEST_LOG_(INFO) << "GetArea_0100 end";
}
/**
* @tc.number: GetArea_0200
* @tc.name: GetArea
* @tc.desc:Get Area sucess
*/
HWTEST_F(ApplicationContextTest, GetArea_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetArea_0200 start";
std::shared_ptr<ContextImpl> contextImpl = std::make_shared<ContextImpl>();
context_->AttachContextImpl(contextImpl);
int32_t mode = 1;
context_->SwitchArea(mode);
auto ret = context_->GetArea();
EXPECT_EQ(ret, mode);
GTEST_LOG_(INFO) << "GetArea_0200 end";
}
/**
* @tc.number: GetConfiguration_0100
* @tc.name: GetConfiguration
* @tc.desc: Get Configuration failed
*/
HWTEST_F(ApplicationContextTest, GetConfiguration_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetConfiguration_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetConfiguration();
EXPECT_EQ(ret, nullptr);
GTEST_LOG_(INFO) << "GetConfiguration_0100 end";
}
/**
* @tc.number: GetConfiguration_0200
* @tc.name: GetConfiguration
* @tc.desc:Get Configuration sucess
*/
HWTEST_F(ApplicationContextTest, GetConfiguration_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetConfiguration_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetConfiguration();
EXPECT_NE(ret, nullptr);
GTEST_LOG_(INFO) << "GetConfiguration_0200 end";
}
/**
* @tc.number: GetBaseDir_0100
* @tc.name: GetBaseDir
* @tc.desc:Get Base Dir sucess
*/
HWTEST_F(ApplicationContextTest, GetBaseDir_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetBaseDir_0100 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetBaseDir();
EXPECT_EQ(ret, "/data/app/base");
GTEST_LOG_(INFO) << "GetBaseDir_0100 end";
}
/**
* @tc.number: GetDeviceType_0100
* @tc.name: GetDeviceType
* @tc.desc: Get DeviceType failed
*/
HWTEST_F(ApplicationContextTest, GetDeviceType_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetDeviceType_0100 start";
std::shared_ptr<ContextImpl> contextImpl = nullptr;
context_->AttachContextImpl(contextImpl);
auto ret = context_->GetDeviceType();
EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_PHONE);
GTEST_LOG_(INFO) << "GetDeviceType_0100 end";
}
/**
* @tc.number: GetDeviceType_0200
* @tc.name: GetDeviceType
* @tc.desc:Get DeviceType sucess
*/
HWTEST_F(ApplicationContextTest, GetDeviceType_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetDeviceType_0200 start";
context_->AttachContextImpl(mock_);
auto ret = context_->GetDeviceType();
EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_NOT_SET);
GTEST_LOG_(INFO) << "GetDeviceType_0200 end";
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -0,0 +1,146 @@
/*
* Copyright (c) 2022 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 "mock_context_impl.h"
#include "sys_mgr_client.h"
namespace OHOS {
namespace AbilityRuntime {
std::string MockContextImpl::GetBundleName() const
{
return "com.test.bundleName";
}
std::string MockContextImpl::GetBundleCodeDir()
{
return "/code";
}
std::string MockContextImpl::GetCacheDir()
{
return "/cache";
}
bool MockContextImpl::IsUpdatingConfigurations()
{
return true;
}
bool MockContextImpl::PrintDrawnCompleted()
{
return true;
}
std::string MockContextImpl::GetDatabaseDir()
{
return "/data/app/database";
}
std::string MockContextImpl::GetPreferencesDir()
{
return "/preferences";
}
std::string MockContextImpl::GetTempDir()
{
return "/temp";
}
std::string MockContextImpl::GetFilesDir()
{
return "/files";
}
std::string MockContextImpl::GetDistributedFilesDir()
{
return "/mnt/hmdfs/device_view/local/data/bundleName";
}
std::shared_ptr<Context> MockContextImpl::CreateModuleContext(const std::string &moduleName)
{
std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>();
return appContext;
}
std::shared_ptr<Context> MockContextImpl::CreateModuleContext(const std::string &bundleName, const std::string &moduleName)
{
std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>();
return appContext;
}
int MockContextImpl::GetArea()
{
return 1;
}
std::string MockContextImpl::GetBaseDir() const
{
return "/data/app/base";
}
std::shared_ptr<Context> MockContextImpl::CreateBundleContext(const std::string &bundleName)
{
std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>();
return appContext;
}
sptr<AppExecFwk::IBundleMgr> MockContextImpl::GetBundleManager() const
{
auto instance = OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance();
if (instance == nullptr) {
return nullptr;
}
auto bundleObj = instance->GetSystemAbility(401);
if (bundleObj == nullptr) {
return nullptr;
}
sptr<AppExecFwk::IBundleMgr> bms = iface_cast<AppExecFwk::IBundleMgr>(bundleObj);
return bms;
}
std::string MockContextImpl::GetBundleCodePath() const
{
return "codePath";
}
void MockContextImpl::InitHapModuleInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo)
{}
Global::Resource::DeviceType MockContextImpl::GetDeviceType() const
{
return Global::Resource::DeviceType::DEVICE_NOT_SET;
}
std::shared_ptr<AppExecFwk::ApplicationInfo> MockContextImpl::GetApplicationInfo() const
{
std::shared_ptr<AppExecFwk::ApplicationInfo> info = std::make_shared<AppExecFwk::ApplicationInfo>();
info->name = "ContextTest";
return info;
}
std::shared_ptr<Global::Resource::ResourceManager> MockContextImpl::GetResourceManager() const
{
std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager());
return resourceManager;
}
std::shared_ptr<AppExecFwk::Configuration> MockContextImpl::GetConfiguration() const
{
std::shared_ptr<AppExecFwk::Configuration> config = std::make_shared<AppExecFwk::Configuration>();
return config;
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2022 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 OHOS_ABILITY_RUNTIME_MOCK_CONTEXT_IMPL_H
#define OHOS_ABILITY_RUNTIME_MOCK_CONTEXT_IMPL_H
#include "bundle_mgr_interface.h"
#include "context_impl.h"
namespace OHOS {
namespace AbilityRuntime {
class MockContextImpl : public ContextImpl {
public:
MockContextImpl() = default;
virtual ~MockContextImpl() = default;
std::string GetBundleName() const override;
std::string GetBundleCodeDir() override;
std::string GetCacheDir() override;
bool IsUpdatingConfigurations() override;
bool PrintDrawnCompleted() override;
std::string GetTempDir() override;
std::string GetFilesDir() override;
std::string GetDatabaseDir() override;
std::string GetPreferencesDir() override;
std::string GetDistributedFilesDir() override;
std::shared_ptr<Context> CreateModuleContext(const std::string &moduleName) override;
std::shared_ptr<Context> CreateModuleContext(const std::string &bundleName, const std::string &moduleName) override;
int GetArea() override;
std::shared_ptr<Context> CreateBundleContext(const std::string &bundleName) override;
sptr<AppExecFwk::IBundleMgr> GetBundleManager() const;
void SetApplicationInfo(const std::shared_ptr<AppExecFwk::ApplicationInfo> &info);
void SetParentContext(const std::shared_ptr<Context> &context);
std::string GetBundleCodePath() const override;
void InitHapModuleInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo);
std::string GetBaseDir() const override;
Global::Resource::DeviceType GetDeviceType() const override;
std::shared_ptr<AppExecFwk::ApplicationInfo> GetApplicationInfo() const override;
std::shared_ptr<Global::Resource::ResourceManager> GetResourceManager() const override;
std::shared_ptr<AppExecFwk::Configuration> GetConfiguration() const override;
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_MOCK_CONTEXT_IMPL_H
@@ -25,7 +25,6 @@ ohos_unittest("background_task_observer_test") {
]
sources = [
"${ability_runtime_services_path}/common/src/permission_verification.cpp",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"background_task_observer_test.cpp", # add mock file
]
@@ -41,6 +40,7 @@ ohos_unittest("background_task_observer_test") {
deps = [
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
@@ -51,7 +51,6 @@ ohos_unittest("background_task_observer_test") {
external_deps = [
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
@@ -25,7 +25,6 @@ ohos_unittest("connection_observer_controller_test") {
]
sources = [
"${ability_runtime_services_path}/common/src/permission_verification.cpp",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"connection_observer_controller_test.cpp", # add mock file
]
@@ -41,6 +40,7 @@ ohos_unittest("connection_observer_controller_test") {
deps = [
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
@@ -51,7 +51,6 @@ ohos_unittest("connection_observer_controller_test") {
external_deps = [
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
@@ -25,7 +25,6 @@ ohos_unittest("connection_state_item_test") {
]
sources = [
"${ability_runtime_services_path}/common/src/permission_verification.cpp",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"connection_state_item_test.cpp", # add mock file
]
@@ -41,6 +40,7 @@ ohos_unittest("connection_state_item_test") {
deps = [
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
@@ -51,7 +51,6 @@ ohos_unittest("connection_state_item_test") {
external_deps = [
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
@@ -25,7 +25,6 @@ ohos_unittest("connection_state_manager_test") {
]
sources = [
"${ability_runtime_services_path}/common/src/permission_verification.cpp",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"connection_state_manager_test.cpp", # add mock file
]
@@ -41,6 +40,7 @@ ohos_unittest("connection_state_manager_test") {
deps = [
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
@@ -51,7 +51,6 @@ ohos_unittest("connection_state_manager_test") {
external_deps = [
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
@@ -27,7 +27,6 @@ ohos_unittest("form_extension_context_test") {
]
sources = [
"${ability_runtime_services_path}/common/src/permission_verification.cpp",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"form_extension_context_test.cpp", # add mock file
]
@@ -46,6 +45,7 @@ ohos_unittest("form_extension_context_test") {
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
@@ -60,7 +60,6 @@ ohos_unittest("form_extension_context_test") {
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"ability_runtime:runtime",
"access_token:libaccesstoken_sdk",
"c_utils:utils",
"eventhandler:libeventhandler",
"hitrace_native:hitrace_meter",
@@ -25,12 +25,16 @@ config("module_private_config") {
ohos_unittest("ability_context_impl_ut_test") {
module_out_path = module_out_path
include_dirs = [ "${ability_runtime_test_path}/mock/frameworks_kits_ability_ability_runtime_test/AMS" ]
include_dirs = [
"${ability_runtime_test_path}/mock/frameworks_kits_ability_ability_runtime_test/AMS",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context/",
]
sources = [
"${ability_runtime_test_path}/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_ability_manager_client.cpp",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.cpp",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include/sys_mgr_client_mock.cpp",
"${ability_runtime_test_path}/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.cpp",
"ability_context_impl_ut_test.cpp",
]
@@ -39,12 +43,15 @@ ohos_unittest("ability_context_impl_ut_test") {
"${ability_runtime_native_path}/ability:ability_context_native",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${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:configuration",
"ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
@@ -20,6 +20,7 @@
#include "ability_loader.h"
#include "ability_thread.h"
#include "iability_callback.h"
#include "mock_context.h"
#include "mock_serviceability_manager_service.h"
#include "system_ability_definition.h"
#include "sys_mgr_client.h"
@@ -60,6 +61,7 @@ public:
void TearDown();
public:
std::unique_ptr<AbilityContextImpl> context_ = nullptr;
std::shared_ptr<MockContext> mock_ = nullptr;
};
void AbilityContextImplTest::SetUpTestCase(void)
@@ -79,6 +81,7 @@ void AbilityContextImplTest::TearDownTestCase(void)
void AbilityContextImplTest::SetUp(void)
{
context_ = std::make_unique<AbilityContextImpl>();
mock_ = std::make_shared<MockContext>();
}
void AbilityContextImplTest::TearDown(void)
@@ -236,5 +239,804 @@ HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_SetMissionIcon_0100, Funct
context_->RegisterAbilityCallback(abilityCallback);
AAFwk::AbilityManagerClient::GetInstance()->proxy_ = nullptr;
}
/**
* @tc.number: Ability_Context_Impl_GetCurrentWindowMode_0100
* @tc.name: GetCurrentWindowMode
* @tc.desc: Get Current Window Mode failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetCurrentWindowMode_0100, Function | MediumTest | Level1)
{
std::weak_ptr<AppExecFwk::IAbilityCallback> abilityCallback;
context_->RegisterAbilityCallback(abilityCallback);
auto ret = context_->GetCurrentWindowMode();
EXPECT_EQ(ret, AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED);
}
/**
* @tc.number: Ability_Context_Impl_GetCurrentWindowMode_0200
* @tc.name: GetCurrentWindowMode
* @tc.desc: Get Current Window Mode sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetCurrentWindowMode_0200, Function | MediumTest | Level1)
{
auto abilityCallback = std::weak_ptr<AppExecFwk::IAbilityCallback>();
context_->RegisterAbilityCallback(abilityCallback);
auto ret = context_->GetCurrentWindowMode();
EXPECT_EQ(ret, AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED);
}
/**
* @tc.number: Ability_Context_Impl_ConnectAbility_0100
* @tc.name: ConnectAbility
* @tc.desc: Connect Ability
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_ConnectAbility_0100, Function | MediumTest | Level1)
{
AAFwk::Want want;
sptr<AbilityConnectCallback> connectCallback;
auto ret = context_->ConnectAbility(want, connectCallback);
EXPECT_EQ(ret, false);
}
/**
* @tc.number: Ability_Context_Impl_ConnectAbilityWithAccount_0100
* @tc.name: ConnectAbilityWithAccount
* @tc.desc: Connect Ability With Account
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_ConnectAbilityWithAccount_0100, Function | MediumTest | Level1)
{
AAFwk::Want want;
int32_t accountId = 1;
sptr<AbilityConnectCallback> connectCallback;
auto ret = context_->ConnectAbilityWithAccount(want, accountId, connectCallback);
EXPECT_EQ(ret, false);
}
/**
* @tc.number: Ability_Context_Impl_TerminateSelf_0100
* @tc.name: TerminateSelf
* @tc.desc: Terminate Self
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_TerminateSelf_0100, Function | MediumTest | Level1)
{
auto ret = context_->TerminateSelf();
EXPECT_EQ(ret, false);
}
/**
* @tc.number: Ability_Context_Impl_SetAbilityInfo_0100
* @tc.name: SetAbilityInfo
* @tc.desc: Set AbilityInfo
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_SetAbilityInfo_0100, Function | MediumTest | Level1)
{
auto abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
abilityInfo->name = "AbilityContextImplTest";
context_->SetAbilityInfo(abilityInfo);
EXPECT_EQ(context_->GetAbilityInfo(), abilityInfo);
}
/**
* @tc.number: Ability_Context_Impl_SetConfiguration_0100
* @tc.name: SetConfiguration
* @tc.desc: Set Configuration
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_SetConfiguration_0100, Function | MediumTest | Level1)
{
auto config = std::make_shared<AppExecFwk::Configuration>();
context_->SetConfiguration(config);
EXPECT_EQ(context_->GetConfiguration(), config);
}
/**
* @tc.number: Ability_Context_Impl_CloseAbility_0100
* @tc.name: CloseAbility
* @tc.desc: Close Ability
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CloseAbility_0100, Function | MediumTest | Level1)
{
auto ret = context_->CloseAbility();
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.number: Ability_Context_Impl_TerminateAbilityWithResult_0100
* @tc.name: TerminateAbilityWithResult
* @tc.desc: Terminate Ability With Result
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_TerminateAbilityWithResult_0100, Function | MediumTest | Level1)
{
AAFwk::Want want;
int32_t resultCode = 1;
auto ret = context_->TerminateAbilityWithResult(want, resultCode);
EXPECT_EQ(ret, ERR_OK);
}
/**
* @tc.number: Ability_Context_Impl_StopServiceExtensionAbility_0100
* @tc.name: StopServiceExtensionAbility
* @tc.desc: Stop Service Extension Ability
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StopServiceExtensionAbility_0100, Function | MediumTest | Level1)
{
AAFwk::Want want;
int32_t accountId = 1;
auto ret = context_->StopServiceExtensionAbility(want, accountId);
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.number: Ability_Context_Impl_StartServiceExtensionAbility_0100
* @tc.name: StartServiceExtensionAbility
* @tc.desc: Start Service Extension Ability
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartServiceExtensionAbility_0100, Function | MediumTest | Level1)
{
AAFwk::Want want;
int32_t accountId = 1;
auto ret = context_->StartServiceExtensionAbility(want, accountId);
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.number: Ability_Context_Impl_StartAbilityForResultWithAccount_0100
* @tc.name: StartAbilityForResultWithAccount
* @tc.desc: Start Ability For Result With Account
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbilityForResultWithAccount_0100, Function | MediumTest | Level1)
{
AAFwk::Want want;
int32_t accountId = 1;
AAFwk::StartOptions startOptions;
int32_t requestCode = 1;
RuntimeTask task = [](const int32_t count, const Want& want)
{ GTEST_LOG_(INFO) << "Ability_Context_Impl_StartAbilityForResultWithAccount_0100 task called"; };
auto ret = context_->StartAbilityForResultWithAccount(want, accountId, startOptions, requestCode, std::move(task));
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.number: Ability_Context_Impl_StartAbilityForResult_0100
* @tc.name: StartAbilityForResult
* @tc.desc: Start Ability For Result
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbilityForResult_0100, Function | MediumTest | Level1)
{
AAFwk::Want want;
AAFwk::StartOptions startOptions;
int32_t requestCode = 1;
RuntimeTask task = [](const int32_t count, const Want& want)
{ GTEST_LOG_(INFO) << "Ability_Context_Impl_StartAbilityForResult_0100 task called"; };
auto ret = context_->StartAbilityForResult(want, startOptions, requestCode, std::move(task));
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.number: Ability_Context_Impl_StartAbilityForResultWithAccount_0200
* @tc.name: StartAbilityForResultWithAccount
* @tc.desc: Start Ability For Result With Account
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbilityForResultWithAccount_0200, Function | MediumTest | Level1)
{
AAFwk::Want want;
int32_t requestCode = 1;
int32_t accountId = 1;
RuntimeTask task = [](const int32_t count, const Want& want)
{ GTEST_LOG_(INFO) << "Ability_Context_Impl_StartAbilityForResultWithAccount_0200 task called"; };
auto ret = context_->StartAbilityForResultWithAccount(want, accountId, requestCode, std::move(task));
EXPECT_EQ(ret, ERR_OK);
}
/**
* @tc.number: Ability_Context_Impl_StartAbilityForResult_0200
* @tc.name: StartAbilityForResult
* @tc.desc: Start Ability For Result
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbilityForResult_0200, Function | MediumTest | Level1)
{
AAFwk::Want want;
int32_t requestCode = 1;
RuntimeTask task = [](const int32_t count, const Want& want)
{ GTEST_LOG_(INFO) << "Ability_Context_Impl_StartAbilityForResult_0200 task called"; };
auto ret = context_->StartAbilityForResult(want, requestCode, std::move(task));
EXPECT_EQ(ret, ERR_OK);
}
/**
* @tc.number: Ability_Context_Impl_StartAbilityWithAccount_0100
* @tc.name: StartAbilityWithAccount
* @tc.desc: Start Ability With Account
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbilityWithAccount_0100, Function | MediumTest | Level1)
{
AAFwk::Want want;
int32_t accountId = 1;
AAFwk::StartOptions startOptions;
int32_t requestCode = 1;
auto ret = context_->StartAbilityWithAccount(want, accountId, startOptions, requestCode);
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.number: Ability_Context_Impl_StartAbilityWithAccount_0200
* @tc.name: StartAbilityWithAccount
* @tc.desc: Start Ability With Account
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbilityWithAccount_0200, Function | MediumTest | Level1)
{
AAFwk::Want want;
int32_t accountId = 1;
int32_t requestCode = 1;
auto ret = context_->StartAbilityWithAccount(want, accountId, requestCode);
EXPECT_EQ(ret, ERR_OK);
}
/**
* @tc.number: Ability_Context_Impl_StartAbility_0300
* @tc.name: StartAbility
* @tc.desc: Start Ability
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbility_0300, Function | MediumTest | Level1)
{
AAFwk::Want want;
AAFwk::StartOptions startOptions;
int32_t requestCode = 1;
auto ret = context_->StartAbility(want, startOptions, requestCode);
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.number: Ability_Context_Impl_StartAbility_0400
* @tc.name: StartAbility
* @tc.desc: Start Ability
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbility_0400, Function | MediumTest | Level1)
{
AAFwk::Want want;
int32_t requestCode = 1;
auto ret = context_->StartAbility(want, requestCode);
EXPECT_EQ(ret, ERR_OK);
}
/**
* @tc.number: Ability_Context_Impl_OnAbilityResult_0100
* @tc.name: OnAbilityResult
* @tc.desc: On Ability Result
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_OnAbilityResult_0100, Function | MediumTest | Level1)
{
AAFwk::Want want;
int32_t accountId = 1;
AAFwk::StartOptions startOptions;
int32_t requestCode = 1;
RuntimeTask task = [](const int32_t count, const Want& want)
{ GTEST_LOG_(INFO) << "Ability_Context_Impl_OnAbilityResult_0100 task called"; };
context_->StartAbilityForResultWithAccount(want, accountId, startOptions, requestCode, std::move(task));
int32_t count = context_->resultCallbacks_.size();
EXPECT_EQ(count, 1);
int32_t code = 2;
int32_t resultCode = 2;
AAFwk::Want resultData;
context_->OnAbilityResult(code, resultCode, resultData);
count = context_->resultCallbacks_.size();
EXPECT_EQ(count, 1);
}
/**
* @tc.number: Ability_Context_Impl_OnAbilityResult_0200
* @tc.name: OnAbilityResult
* @tc.desc: On Ability Result
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_OnAbilityResult_0200, Function | MediumTest | Level1)
{
AAFwk::Want want;
int32_t accountId = 1;
AAFwk::StartOptions startOptions;
int32_t requestCode = 1;
RuntimeTask task = [](const int32_t count, const Want& want)
{ GTEST_LOG_(INFO) << "Ability_Context_Impl_OnAbilityResult_0200 task called"; };
context_->StartAbilityForResultWithAccount(want, accountId, startOptions, requestCode, std::move(task));
int32_t count = context_->resultCallbacks_.size();
EXPECT_EQ(count, 1);
int32_t code = 1;
int32_t resultCode = 1;
AAFwk::Want resultData;
context_->OnAbilityResult(code, resultCode, resultData);
count = context_->resultCallbacks_.size();
EXPECT_EQ(count, 0);
}
/**
* @tc.number: Ability_Context_Impl_GetDeviceType_0100
* @tc.name: GetDeviceType
* @tc.desc: Get Device Type sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetDeviceType_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetDeviceType();
EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_NOT_SET);
}
/**
* @tc.number: Ability_Context_Impl_GetDeviceType_0200
* @tc.name: GetDeviceType
* @tc.desc: Get Device Type failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetDeviceType_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetDeviceType();
EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_PHONE);
}
/**
* @tc.number: Ability_Context_Impl_GetBaseDir_0100
* @tc.name: GetBaseDir
* @tc.desc: Get Base Dir sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBaseDir_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetBaseDir();
EXPECT_EQ(ret, "/data/app/base");
}
/**
* @tc.number: Ability_Context_Impl_GetBaseDir_0200
* @tc.name: GetBaseDir
* @tc.desc: Get Base Dir failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBaseDir_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetBaseDir();
EXPECT_EQ(ret, "");
}
/**
* @tc.number: Ability_Context_Impl_GetBundleCodeDir_0100
* @tc.name: GetBundleCodeDir
* @tc.desc: Get Bundle Code Dir sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBundleCodeDir_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetBundleCodeDir();
EXPECT_EQ(ret, "/code");
}
/**
* @tc.number: Ability_Context_Impl_GetBundleCodeDir_0200
* @tc.name: GetBundleCodeDir
* @tc.desc: Get Bundle Code Dir failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBundleCodeDir_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetBundleCodeDir();
EXPECT_EQ(ret, "");
}
/**
* @tc.number: Ability_Context_Impl_GetCacheDir_0100
* @tc.name: GetCacheDir
* @tc.desc: Get Cache Dir sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetCacheDir_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetCacheDir();
EXPECT_EQ(ret, "/cache");
}
/**
* @tc.number: Ability_Context_Impl_GetCacheDir_0200
* @tc.name: GetCacheDir
* @tc.desc: Get Cache Dir failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetCacheDir_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetCacheDir();
EXPECT_EQ(ret, "");
}
/**
* @tc.number: Ability_Context_Impl_GetDatabaseDir_0100
* @tc.name: GetDatabaseDir
* @tc.desc: Get Database Dir sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetDatabaseDir_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetDatabaseDir();
EXPECT_EQ(ret, "/data/app/database");
}
/**
* @tc.number: Ability_Context_Impl_GetDatabaseDir_0200
* @tc.name: GetDatabaseDir
* @tc.desc: Get Database Dir failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetDatabaseDir_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetDatabaseDir();
EXPECT_EQ(ret, "");
}
/**
* @tc.number: Ability_Context_Impl_GetPreferencesDir_0100
* @tc.name: GetPreferencesDir
* @tc.desc: Get Preferences Dir sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetPreferencesDir_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetPreferencesDir();
EXPECT_EQ(ret, "/preferences");
}
/**
* @tc.number: Ability_Context_Impl_GetPreferencesDir_0200
* @tc.name: GetPreferencesDir
* @tc.desc: Get Preferences Dir failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetPreferencesDir_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetPreferencesDir();
EXPECT_EQ(ret, "");
}
/**
* @tc.number: Ability_Context_Impl_GetTempDir_0100
* @tc.name: GetTempDir
* @tc.desc: Get Temp Dir sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetTempDir_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetTempDir();
EXPECT_EQ(ret, "/temp");
}
/**
* @tc.number: Ability_Context_Impl_GetTempDir_0200
* @tc.name: GetTempDir
* @tc.desc: Get Temp Dir failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetTempDir_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetTempDir();
EXPECT_EQ(ret, "");
}
/**
* @tc.number: Ability_Context_Impl_GetFilesDir_0100
* @tc.name: GetFilesDir
* @tc.desc: Get Files Dir sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetFilesDir_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetFilesDir();
EXPECT_EQ(ret, "/files");
}
/**
* @tc.number: Ability_Context_Impl_GetFilesDir_0200
* @tc.name: GetFilesDir
* @tc.desc: Get Files Dir failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetFilesDir_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetFilesDir();
EXPECT_EQ(ret, "");
}
/**
* @tc.number: Ability_Context_Impl_GetDistributedFilesDir_0100
* @tc.name: GetDistributedFilesDir
* @tc.desc: Get Distributed Files Dir sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetDistributedFilesDir_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetDistributedFilesDir();
EXPECT_EQ(ret, "/mnt/hmdfs/device_view/local/data/bundleName");
}
/**
* @tc.number: Ability_Context_Impl_GetDistributedFilesDir_0200
* @tc.name: GetDistributedFilesDir
* @tc.desc: Get Distributed Files Dir failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetDistributedFilesDir_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetDistributedFilesDir();
EXPECT_EQ(ret, "");
}
/**
* @tc.number: Ability_Context_Impl_IsUpdatingConfigurations_0100
* @tc.name: IsUpdatingConfigurations
* @tc.desc: Is Updating Configurations true
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_IsUpdatingConfigurations_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->IsUpdatingConfigurations();
EXPECT_EQ(ret, true);
}
/**
* @tc.number: Ability_Context_Impl_IsUpdatingConfigurations_0200
* @tc.name: IsUpdatingConfigurations
* @tc.desc: Is Updating Configurations false
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_IsUpdatingConfigurations_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->IsUpdatingConfigurations();
EXPECT_EQ(ret, false);
}
/**
* @tc.number: Ability_Context_Impl_PrintDrawnCompleted_0100
* @tc.name: PrintDrawnCompleted
* @tc.desc: Print Drawn Completed true
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_PrintDrawnCompleted_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->PrintDrawnCompleted();
EXPECT_EQ(ret, true);
}
/**
* @tc.number: Ability_Context_Impl_PrintDrawnCompleted_0200
* @tc.name: PrintDrawnCompleted
* @tc.desc: Print Drawn Completed false
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_PrintDrawnCompleted_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->PrintDrawnCompleted();
EXPECT_EQ(ret, false);
}
/**
* @tc.number: Ability_Context_Impl_SwitchArea_0200
* @tc.name: SwitchArea
* @tc.desc: Switch Area failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_SwitchArea_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
int32_t mode = 2;
context_->SwitchArea(mode);
EXPECT_EQ(context_->GetArea(), 1);
}
/**
* @tc.number: Ability_Context_Impl_SwitchArea_0100
* @tc.name: SwitchArea
* @tc.desc: Switch Area sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_SwitchArea_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
int32_t mode = 2;
context_->SwitchArea(mode);
EXPECT_EQ(context_->GetArea(), mode);
}
/**
* @tc.number: Ability_Context_Impl_GetBundleName_0100
* @tc.name: GetBundleName
* @tc.desc: Get BundleName sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBundleName_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetBundleName();
EXPECT_EQ(ret, "com.test.bundleName");
}
/**
* @tc.number: Ability_Context_Impl_GetBundleName_0200
* @tc.name: GetBundleName
* @tc.desc: Get BundleName failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBundleName_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetBundleName();
EXPECT_EQ(ret, "");
}
/**
* @tc.number: Ability_Context_Impl_GetApplicationInfo_0100
* @tc.name: GetApplicationInfo
* @tc.desc: Get ApplicationInfo sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetApplicationInfo_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetApplicationInfo();
EXPECT_NE(ret, nullptr);
}
/**
* @tc.number: Ability_Context_Impl_GetApplicationInfo_0200
* @tc.name: GetApplicationInfo
* @tc.desc: Get ApplicationInfo failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetApplicationInfo_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetApplicationInfo();
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.number: Ability_Context_Impl_GetBundleCodePath_0100
* @tc.name: GetBundleCodePath
* @tc.desc: Get Bundle Code Path sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBundleCodePath_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetBundleCodePath();
EXPECT_EQ(ret, "codePath");
}
/**
* @tc.number: Ability_Context_Impl_GetBundleCodePath_0200
* @tc.name: GetBundleCodePath
* @tc.desc: Get Bundle Code Path failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBundleCodePath_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetBundleCodePath();
EXPECT_EQ(ret, "");
}
/**
* @tc.number: Ability_Context_Impl_GetHapModuleInfo_0100
* @tc.name: GetHapModuleInfo
* @tc.desc: Get Hap Module Info sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetHapModuleInfo_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetHapModuleInfo();
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.number: Ability_Context_Impl_GetHapModuleInfo_0200
* @tc.name: GetHapModuleInfo
* @tc.desc: Get Hap Module Info failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetHapModuleInfo_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetHapModuleInfo();
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.number: Ability_Context_Impl_GetResourceManager_0100
* @tc.name: GetResourceManager
* @tc.desc: Get Resource Manager sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetResourceManager_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
auto ret = context_->GetResourceManager();
EXPECT_NE(ret, nullptr);
}
/**
* @tc.number: Ability_Context_Impl_GetResourceManager_0200
* @tc.name: GetResourceManager
* @tc.desc: Get Resource Manager failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetResourceManager_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
auto ret = context_->GetResourceManager();
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.number: Ability_Context_Impl_CreateBundleContext_0100
* @tc.name: CreateBundleContext
* @tc.desc: Create Bundle Context sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CreateBundleContext_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
std::string bundleName = "com.test.bundleName";
auto ret = context_->CreateBundleContext(bundleName);
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.number: Ability_Context_Impl_CreateBundleContext_0200
* @tc.name: CreateBundleContext
* @tc.desc: Create Bundle Context failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CreateBundleContext_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
std::string bundleName = "com.test.bundleName";
auto ret = context_->CreateBundleContext(bundleName);
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.number: Ability_Context_Impl_CreateModuleContext_0100
* @tc.name: CreateModuleContext
* @tc.desc: Create Module Context sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CreateModuleContext_0100, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
std::string moduleName = "com.test.moduleName";
auto ret = context_->CreateModuleContext(moduleName);
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.number: Ability_Context_Impl_CreateModuleContext_0200
* @tc.name: CreateModuleContext
* @tc.desc: Create Module Context failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CreateModuleContext_0200, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
std::string moduleName = "com.test.moduleName";
auto ret = context_->CreateModuleContext(moduleName);
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.number: Ability_Context_Impl_CreateModuleContext_0300
* @tc.name: CreateModuleContext
* @tc.desc: Create Module Context sucess
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CreateModuleContext_0300, Function | MediumTest | Level1)
{
context_->SetStageContext(mock_);
std::string moduleName = "com.test.moduleName";
std::string bundleName = "com.test.bundleName";
auto ret = context_->CreateModuleContext(bundleName, moduleName);
EXPECT_EQ(ret, nullptr);
}
/**
* @tc.number: Ability_Context_Impl_CreateModuleContext_0400
* @tc.name: CreateModuleContext
* @tc.desc: Create Module Context failed
*/
HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CreateModuleContext_0400, Function | MediumTest | Level1)
{
context_->SetStageContext(nullptr);
std::string moduleName = "com.test.moduleName";
std::string bundleName = "com.test.bundleName";
auto ret = context_->CreateModuleContext(bundleName, moduleName);
EXPECT_EQ(ret, nullptr);
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -411,5 +411,24 @@ HWTEST_F(LocalCallContainerTest, Local_Call_Container_GetCallLocalRecord_0200, F
bool ret = localCallContainer.GetCallLocalRecord(elementName, localCallRecord);
EXPECT_TRUE(ret == false);
}
/**
* @tc.number: Local_Call_Container_OnCallStubDied_0100
* @tc.name: OnCallStubDied
* @tc.desc: Verify that function IsSameObject.
*/
HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnCallStubDied_0100, Function | MediumTest | Level1)
{
LocalCallContainer localCallContainer;
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> localCallRecord = std::make_shared<LocalCallRecord>(elementName);
sptr<IRemoteObject> remoteObject = new (std::nothrow) MockServiceAbilityManagerService();
wptr<IRemoteObject> remote(remoteObject);
localCallContainer.OnCallStubDied(remote);
EXPECT_TRUE(localCallContainer.callProxyRecords_.empty());
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -0,0 +1,163 @@
/*
* Copyright (c) 2022 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 "connection_manager.h"
#include "mock_context.h"
#include "resource_manager.h"
#include "sys_mgr_client.h"
namespace OHOS {
namespace AbilityRuntime {
const size_t Context::CONTEXT_TYPE_ID(std::hash<const char*> {} ("Context"));
std::string MockContext::GetBundleName() const
{
return "com.test.bundleName";
}
std::string MockContext::GetBundleCodeDir()
{
return "/code";
}
std::string MockContext::GetCacheDir()
{
return "/cache";
}
bool MockContext::IsUpdatingConfigurations()
{
return true;
}
bool MockContext::PrintDrawnCompleted()
{
return true;
}
std::string MockContext::GetDatabaseDir()
{
return "/data/app/database";
}
std::string MockContext::GetPreferencesDir()
{
return "/preferences";
}
std::string MockContext::GetTempDir()
{
return "/temp";
}
std::string MockContext::GetFilesDir()
{
return "/files";
}
std::string MockContext::GetDistributedFilesDir()
{
return "/mnt/hmdfs/device_view/local/data/bundleName";
}
std::shared_ptr<Context> MockContext::CreateModuleContext(const std::string &moduleName)
{
return nullptr;
}
std::shared_ptr<Context> MockContext::CreateModuleContext(const std::string &bundleName, const std::string &moduleName)
{
return nullptr;
}
int MockContext::GetArea()
{
return mode_;
}
std::string MockContext::GetBaseDir() const
{
return "/data/app/base";
}
std::shared_ptr<Context> MockContext::CreateBundleContext(const std::string &bundleName)
{
return nullptr;
}
sptr<AppExecFwk::IBundleMgr> MockContext::GetBundleManager() const
{
auto instance = OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance();
if (instance == nullptr) {
return nullptr;
}
auto bundleObj = instance->GetSystemAbility(401);
if (bundleObj == nullptr) {
return nullptr;
}
sptr<AppExecFwk::IBundleMgr> bms = iface_cast<AppExecFwk::IBundleMgr>(bundleObj);
return bms;
}
std::string MockContext::GetBundleCodePath() const
{
return "codePath";
}
void MockContext::InitHapModuleInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo)
{}
Global::Resource::DeviceType MockContext::GetDeviceType() const
{
return Global::Resource::DeviceType::DEVICE_NOT_SET;
}
std::shared_ptr<AppExecFwk::ApplicationInfo> MockContext::GetApplicationInfo() const
{
std::shared_ptr<AppExecFwk::ApplicationInfo> info = std::make_shared<AppExecFwk::ApplicationInfo>();
info->name = "ContextTest";
return info;
}
std::shared_ptr<Global::Resource::ResourceManager> MockContext::GetResourceManager() const
{
std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager());
return resourceManager;
}
std::shared_ptr<AppExecFwk::Configuration> MockContext::GetConfiguration() const
{
std::shared_ptr<AppExecFwk::Configuration> config = std::make_shared<AppExecFwk::Configuration>();
return config;
}
void MockContext::SetToken(const sptr<IRemoteObject> &token)
{}
sptr<IRemoteObject> MockContext::GetToken()
{
return nullptr;
}
std::shared_ptr<AppExecFwk::HapModuleInfo> MockContext::GetHapModuleInfo() const
{
return nullptr;
}
void MockContext::SwitchArea(int mode)
{
mode_ = mode;
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -0,0 +1,98 @@
/*
* Copyright (c) 2022 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 OHOS_ABILITY_RUNTIME_MOCK_CONTEXT_H
#define OHOS_ABILITY_RUNTIME_MOCK_CONTEXT_H
#define protected public
#include "context.h"
#undef protected
#include "configuration.h"
#include "bundle_mgr_interface.h"
namespace OHOS {
namespace AbilityRuntime {
class MockContext : public AbilityRuntime::Context{
public:
MockContext() = default;
virtual ~MockContext() = default;
std::string GetBundleName() const override;
std::string GetBundleCodeDir() override;
std::string GetCacheDir() override;
bool IsUpdatingConfigurations() override;
bool PrintDrawnCompleted() override;
std::string GetTempDir() override;
std::string GetFilesDir() override;
std::string GetDatabaseDir() override;
std::string GetPreferencesDir() override;
std::string GetDistributedFilesDir() override;
void SwitchArea(int mode) override;
std::shared_ptr<Context> CreateModuleContext(const std::string &moduleName) override;
std::shared_ptr<Context> CreateModuleContext(const std::string &bundleName, const std::string &moduleName) override;
int GetArea() override;
void SetResourceManager(const std::shared_ptr<Global::Resource::ResourceManager> &resourceManager);
std::shared_ptr<Global::Resource::ResourceManager> GetResourceManager() const override;
std::shared_ptr<Context> CreateBundleContext(const std::string &bundleName) override;
sptr<AppExecFwk::IBundleMgr> GetBundleManager() const;
void SetApplicationInfo(const std::shared_ptr<AppExecFwk::ApplicationInfo> &info);
std::shared_ptr<AppExecFwk::ApplicationInfo> GetApplicationInfo() const override;
void SetParentContext(const std::shared_ptr<Context> &context);
std::string GetBundleCodePath() const override;
std::shared_ptr<AppExecFwk::HapModuleInfo> GetHapModuleInfo() const override;
void InitHapModuleInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo);
void InitHapModuleInfo(const AppExecFwk::HapModuleInfo &hapModuleInfo);
void SetToken(const sptr<IRemoteObject> &token) override;
sptr<IRemoteObject> GetToken() override;
void SetConfiguration(const std::shared_ptr<AppExecFwk::Configuration> &config);
std::shared_ptr<AppExecFwk::Configuration> GetConfiguration() const override;
std::string GetBaseDir() const override;
Global::Resource::DeviceType GetDeviceType() const override;
int32_t mode_ = 0;
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_MOCK_CONTEXT_H
@@ -16,6 +16,11 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni")
module_output_path = "ability_runtime/ability_test"
config("coverage_flags") {
cflags = [ "--coverage" ]
ldflags = [ "--coverage" ]
}
###############################################################################
config("module_private_config") {
visibility = [ ":*" ]
@@ -352,17 +357,28 @@ ohos_unittest("scene_created_test") {
ohos_unittest("data_ability_helper_test") {
module_out_path = module_output_path
include_dirs = [ "${ability_runtime_services_path}/abilitymgr/include" ]
include_dirs = [
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
]
sources = [ "data_ability_helper_test.cpp" ]
sources = [
"data_ability_helper_test.cpp",
"mock_ability_runtime_context.cpp",
]
configs = [ ":module_ability_context_config" ]
configs = [
":module_ability_context_config",
":coverage_flags",
]
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:data_ability_helper",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
@@ -372,12 +388,16 @@ ohos_unittest("data_ability_helper_test") {
"ability_base:want",
"ability_base:zuri",
"c_utils:utils",
"data_share:datashare_common",
"data_share:datashare_consumer",
"eventhandler:libeventhandler",
"hitrace_native:hitrace_meter",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"relational_store:native_appdatafwk",
"relational_store:native_dataability",
"relational_store:native_rdb",
"relational_store:rdb_data_ability_adapter",
]
if (ability_runtime_graphics) {
@@ -1022,6 +1042,93 @@ ohos_unittest("data_uri_utils_test") {
}
}
ohos_unittest("extension_impl_test") {
module_out_path = module_output_path
include_dirs = [ "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include" ]
sources = [ "extension_impl_test.cpp" ]
configs = [ ":module_private_config" ]
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:form_extension",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_native",
"${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:want",
"ability_base:zuri",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:runtime",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"eventhandler:libeventhandler",
"form_fwk:form_manager",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"relational_store:native_appdatafwk",
"relational_store:native_dataability",
"relational_store:native_rdb",
]
if (ability_runtime_graphics) {
external_deps += [ "input:libmmi-client" ]
}
}
ohos_unittest("form_js_event_handler_test") {
module_out_path = module_output_path
include_dirs = [ "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include" ]
sources = [ "form_js_event_handler_test.cpp" ]
configs = [ ":module_private_config" ]
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:form_extension",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_native",
"${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:want",
"ability_base:zuri",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:runtime",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"eventhandler:libeventhandler",
"form_fwk:fmskit_native",
"form_fwk:form_manager",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"relational_store:native_appdatafwk",
"relational_store:native_dataability",
"relational_store:native_rdb",
]
if (ability_runtime_graphics) {
external_deps += [ "input:libmmi-client" ]
}
}
ohos_unittest("pac_map_test") {
module_out_path = module_output_path
sources = [ "pac_map_test.cpp" ]
@@ -1205,6 +1312,7 @@ ohos_unittest("continuation_test") {
"${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",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit/src/mock_ability_connect_callback.cpp",
"continuation_test.cpp",
]
@@ -1304,6 +1412,76 @@ ohos_unittest("new_ability_impl_test") {
}
}
ohos_unittest("reserse_continuation_scheduler_primary_stub_test") {
module_out_path = module_output_path
if (ability_runtime_graphics) {
sources = [
"${ability_runtime_native_path}/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_stub.cpp",
"reserse_continuation_scheduler_primary_stub_test.cpp",
]
configs = [ ":module_private_config" ]
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_native",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"${global_path}/resource_management/frameworks/resmgr:global_resmgr",
"${multimodalinput_path}/frameworks/proxy:libmmi-common",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"hitrace_native:hitrace_meter",
"hiviewdfx_hilog_native:libhilog",
"input:libmmi-client",
"ipc:ipc_core",
]
}
}
ohos_unittest("reserse_continuation_scheduler_primary_proxy_test") {
module_out_path = module_output_path
if (ability_runtime_graphics) {
sources = [
"${ability_runtime_native_path}/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_proxy.cpp",
"${ability_runtime_native_path}/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_stub.cpp",
"${ability_runtime_native_path}/ability/native/new_ability_impl.cpp",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include/mock_replace_ability_impl.cpp",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit/src/mock_ability_connect_callback.cpp",
"reserse_continuation_scheduler_primary_proxy_test.cpp",
]
configs = [ ":module_private_config" ]
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_native",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"${global_path}/resource_management/frameworks/resmgr:global_resmgr",
"${multimodalinput_path}/frameworks/proxy:libmmi-common",
"//third_party/googletest:gmock_main",
]
external_deps = [
"ability_base:want",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"hitrace_native:hitrace_meter",
"hiviewdfx_hilog_native:libhilog",
"input:libmmi-client",
"ipc:ipc_core",
]
}
}
ohos_unittest("distributed_client_test") {
module_out_path = module_output_path
sources = [
@@ -1362,10 +1540,14 @@ group("unittest") {
":data_ability_result_test",
":data_uri_utils_test",
":distributed_client_test",
":extension_impl_test",
":extension_test",
":form_extension_test",
":form_js_event_handler_test",
":new_ability_impl_test",
":pac_map_test",
":reserse_continuation_scheduler_primary_proxy_test",
":reserse_continuation_scheduler_primary_stub_test",
":service_ability_impl_test",
":task_handler_client_test",
]
File diff suppressed because it is too large Load Diff
@@ -26,7 +26,7 @@
#include "continuation_manager.h"
#include "continuation_handler.h"
#include "data_ability_predicates.h"
#include "mock_ability_impl.h"
#include "mock_ability_connect_callback.h"
#include "mock_ability_lifecycle_callbacks.h"
#include "mock_ability_token.h"
#include "mock_continuation_ability.h"
@@ -70,6 +70,25 @@ public:
void TearDown();
};
class MockReverseContinuationSchedulerPrimaryProxy : public IRemoteProxy<IReverseContinuationSchedulerPrimary> {
public:
explicit MockReverseContinuationSchedulerPrimaryProxy(const sptr<IRemoteObject> &remoteObject) :
IRemoteProxy<IReverseContinuationSchedulerPrimary>(remoteObject) {}
virtual ~MockReverseContinuationSchedulerPrimaryProxy() = default;
MOCK_METHOD0(NotifyReplicaTerminated, void());
MOCK_METHOD1(ContinuationBack, bool(const AAFwk::Want &want));
};
class MockReverseContinuationSchedulerReplicaProxy : public IRemoteProxy<IReverseContinuationSchedulerReplica> {
public:
explicit MockReverseContinuationSchedulerReplicaProxy(const sptr<IRemoteObject> &remoteObject) :
IRemoteProxy<IReverseContinuationSchedulerReplica>(remoteObject) {}
virtual ~MockReverseContinuationSchedulerReplicaProxy() = default;
MOCK_METHOD1(PassPrimary, void(const sptr<IRemoteObject> &primary));
MOCK_METHOD0(ReverseContinuation, bool());
MOCK_METHOD1(NotifyReverseResult, void(int reverseResult));
};
void ContinuationTest::SetUpTestCase(void)
{}
@@ -373,6 +392,47 @@ HWTEST_F(ContinuationTest, continue_handler_HandleStartContinuation_006, TestSiz
GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuation_006 end";
}
/*
* @tc.number: continue_handler_HandleReceiveRemoteScheduler_001
* @tc.name: HandleReceiveRemoteScheduler
* @tc.desc: call HandleReceiveRemoteScheduler with remoteReplica is null
*/
HWTEST_F(ContinuationTest, continue_handler_HandleReceiveRemoteScheduler_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_HandleReceiveRemoteScheduler_001 start";
sptr<IRemoteObject> continueToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
sptr<IRemoteObject> primary = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub();
continuationHandler->SetPrimaryStub(primary);
continuationHandler->HandleReceiveRemoteScheduler(nullptr);
EXPECT_TRUE(continuationHandler->remotePrimaryProxy_ == nullptr);
GTEST_LOG_(INFO) << "continue_handler_HandleReceiveRemoteScheduler_001 end";
}
/*
* @tc.number: continue_handler_HandleReceiveRemoteScheduler_002
* @tc.name: HandleReceiveRemoteScheduler
* @tc.desc: call HandleReceiveRemoteScheduler using remoteReplicaProxy_ and DeathRecipient_ in different situations.
*/
HWTEST_F(ContinuationTest, continue_handler_HandleReceiveRemoteScheduler_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_HandleReceiveRemoteScheduler_002 start";
sptr<IRemoteObject> continueToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
sptr<MockReverseContinuationSchedulerReplicaStub> remoteReplica =
new (std::nothrow) MockReverseContinuationSchedulerReplicaStub();
EXPECT_CALL(*remoteReplica, PassPrimary(_)).Times(3);
continuationHandler->HandleReceiveRemoteScheduler(remoteReplica);
continuationHandler->HandleReceiveRemoteScheduler(remoteReplica);
continuationHandler->schedulerDeathRecipient_ = nullptr;
continuationHandler->HandleReceiveRemoteScheduler(remoteReplica);
GTEST_LOG_(INFO) << "continue_handler_HandleReceiveRemoteScheduler_002 end";
}
/*
* @tc.number: continue_handler_HandleCompleteContinuation_001
* @tc.name: HandleStartContinuation
@@ -411,6 +471,172 @@ HWTEST_F(ContinuationTest, continue_handler_HandleCompleteContinuation_002, Test
GTEST_LOG_(INFO) << "continue_handler_HandleCompleteContinuation_002 end";
}
/*
* @tc.number: continue_handler_PassPrimary_001
* @tc.name: PassPrimary
* @tc.desc: call PassPrimary success
*/
HWTEST_F(ContinuationTest, continue_handler_PassPrimary_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_PassPrimary_001 start";
sptr<IRemoteObject> continueToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
sptr<IRemoteObject> primary = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub();
continuationHandler->PassPrimary(primary);
EXPECT_TRUE(continuationHandler->remotePrimaryProxy_ != nullptr);
GTEST_LOG_(INFO) << "continue_handler_PassPrimary_001 end";
}
/*
* @tc.number: continue_handler_ReverseContinuation_001
* @tc.name: ReverseContinuation
* @tc.desc: call ReverseContinuation with remotePrimaryProxy is null
*/
HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_001 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationHandler->SetAbilityInfo(abilityInfo_);
bool result = continuationHandler->ReverseContinuation();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_001 end";
}
/*
* @tc.number: continue_handler_ReverseContinuation_002
* @tc.name: ReverseContinuation
* @tc.desc: call ReverseContinuation with abilityInfo_ is null
*/
HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_002 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
sptr<IRemoteObject> primary = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub();
continuationHandler->PassPrimary(primary);
bool result = continuationHandler->ReverseContinuation();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_002 end";
}
/*
* @tc.number: continue_handler_ReverseContinuation_003
* @tc.name: ReverseContinuation
* @tc.desc: call ReverseContinuation with continuationManagerTmp is null
*/
HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_003 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
continuationManager.reset();
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
sptr<IRemoteObject> primary = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub();
continuationHandler->PassPrimary(primary);
continuationHandler->SetAbilityInfo(abilityInfo_);
bool result = continuationHandler->ReverseContinuation();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_003 end";
}
/*
* @tc.number: continue_handler_ReverseContinuation_004
* @tc.name: ReverseContinuation
* @tc.desc: call ReverseContinuation with OnStartContinuation failed
*/
HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_004 start";
EXPECT_CALL(*mockAbility_, OnStartContinuation()).Times(1).WillOnce(Return(false));
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
sptr<IRemoteObject> primary = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub();
continuationHandler->PassPrimary(primary);
continuationHandler->SetAbilityInfo(abilityInfo_);
bool result = continuationHandler->ReverseContinuation();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_004 end";
}
/*
* @tc.number: continue_handler_ReverseContinuation_005
* @tc.name: ReverseContinuation
* @tc.desc: call ReverseContinuation with OnSaveData failed
*/
HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_005, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_005 start";
EXPECT_CALL(*mockAbility_, OnStartContinuation()).Times(1).WillOnce(Return(true));
EXPECT_CALL(*mockAbility_, OnSaveData(_)).Times(1).WillOnce(Return(false));
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
sptr<IRemoteObject> primary = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub();
continuationHandler->PassPrimary(primary);
continuationHandler->SetAbilityInfo(abilityInfo_);
bool result = continuationHandler->ReverseContinuation();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_005 end";
}
/*
* @tc.number: continue_handler_ReverseContinuation_006
* @tc.name: ReverseContinuation
* @tc.desc: call ReverseContinuation with ContinuationBack failed
*/
HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_006, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_006 start";
EXPECT_CALL(*mockAbility_, OnStartContinuation()).Times(1).WillOnce(Return(true));
EXPECT_CALL(*mockAbility_, OnSaveData(_)).Times(1).WillOnce(Return(true));
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
sptr<IRemoteObject> remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback();
sptr<MockReverseContinuationSchedulerPrimaryProxy> primary =
new (std::nothrow) MockReverseContinuationSchedulerPrimaryProxy(remoteObject);
EXPECT_CALL(*primary, ContinuationBack(_)).Times(1).WillOnce(Return(true));
continuationHandler->remotePrimaryProxy_ = primary;
continuationHandler->SetAbilityInfo(abilityInfo_);
bool result = continuationHandler->ReverseContinuation();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_006 end";
}
/*
* @tc.number: continue_handler_ReverseContinuation_007
* @tc.name: ReverseContinuation
* @tc.desc: call ReverseContinuation with success
*/
HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_007, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_007 start";
EXPECT_CALL(*mockAbility_, OnStartContinuation()).Times(1).WillOnce(Return(true));
EXPECT_CALL(*mockAbility_, OnSaveData(_)).Times(1).WillOnce(Return(true));
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
sptr<IRemoteObject> remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback();
sptr<MockReverseContinuationSchedulerPrimaryProxy> primary =
new (std::nothrow) MockReverseContinuationSchedulerPrimaryProxy(remoteObject);
EXPECT_CALL(*primary, ContinuationBack(_)).Times(1).WillOnce(Return(false));
continuationHandler->remotePrimaryProxy_ = primary;
continuationHandler->SetAbilityInfo(abilityInfo_);
bool result = continuationHandler->ReverseContinuation();
EXPECT_TRUE(result);
GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_007 end";
}
/*
* @tc.number: continue_handler_NotifyReverseResult_001
* @tc.name: NotifyReverseResult
@@ -463,6 +689,67 @@ HWTEST_F(ContinuationTest, continue_handler_NotifyReverseResult_003, TestSize.Le
GTEST_LOG_(INFO) << "continue_handler_NotifyReverseResult_003 end";
}
/*
* @tc.number: continue_handler_ContinuationBack_001
* @tc.name: ContinuationBack
* @tc.desc: call ContinuationBack with continuationManager is null
*/
HWTEST_F(ContinuationTest, continue_handler_ContinuationBack_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_ContinuationBack_001 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
continuationManager.reset();
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
Want want;
bool result = continuationHandler->ContinuationBack(want);
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_handler_ContinuationBack_001 end";
}
/*
* @tc.number: continue_handler_ContinuationBack_002
* @tc.name: ContinuationBack
* @tc.desc: call ContinuationBack with RestoreFromRemote failed
*/
HWTEST_F(ContinuationTest, continue_handler_ContinuationBack_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_ContinuationBack_002 start";
EXPECT_CALL(*mockAbility_, OnRestoreData(_)).Times(1).WillOnce(Return(false));
EXPECT_CALL(*mockAbility_, TerminateAbility()).Times(0);
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
Want want;
sptr<IRemoteObject> remoteReplica = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub();
continuationHandler->remoteReplicaProxy_ = iface_cast<IReverseContinuationSchedulerReplica>(remoteReplica);
bool result = continuationHandler->ContinuationBack(want);
EXPECT_TRUE(result);
GTEST_LOG_(INFO) << "continue_handler_ContinuationBack_002 end";
}
/*
* @tc.number: continue_handler_ContinuationBack_003
* @tc.name: ContinuationBack
* @tc.desc: call ContinuationBack with RestoreFromRemote success
*/
HWTEST_F(ContinuationTest, continue_handler_ContinuationBack_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_ContinuationBack_003 start";
EXPECT_CALL(*mockAbility_, OnRestoreData(_)).Times(1).WillOnce(Return(true));
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
Want want;
sptr<IRemoteObject> remoteReplica = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub();
continuationHandler->remoteReplicaProxy_ = iface_cast<IReverseContinuationSchedulerReplica>(remoteReplica);
bool result = continuationHandler->ContinuationBack(want);
EXPECT_TRUE(result);
GTEST_LOG_(INFO) << "continue_handler_ContinuationBack_003 end";
}
/*
* @tc.number: continue_handler_NotifyReplicaTerminated_001
* @tc.name: NotifyReplicaTerminated
@@ -481,6 +768,45 @@ HWTEST_F(ContinuationTest, continue_handler_NotifyReplicaTerminated_001, TestSiz
GTEST_LOG_(INFO) << "continue_handler_NotifyReplicaTerminated_001 end";
}
/*
* @tc.number: continue_handler_NotifyTerminationToPrimary_001
* @tc.name: NotifyTerminationToPrimary
* @tc.desc: call NotifyTerminationToPrimary with null remotePrimaryProxy_
*/
HWTEST_F(ContinuationTest, continue_handler_NotifyTerminationToPrimary_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_NotifyTerminationToPrimary_001 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
sptr<IRemoteObject> remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback();
sptr<MockReverseContinuationSchedulerPrimaryProxy> primary =
new (std::nothrow) MockReverseContinuationSchedulerPrimaryProxy(remoteObject);
EXPECT_CALL(*primary, NotifyReplicaTerminated()).Times(0);
continuationHandler->NotifyTerminationToPrimary();
GTEST_LOG_(INFO) << "continue_handler_NotifyTerminationToPrimary_001 end";
}
/*
* @tc.number: continue_handler_NotifyTerminationToPrimary_002
* @tc.name: NotifyTerminationToPrimary
* @tc.desc: call NotifyTerminationToPrimary success
*/
HWTEST_F(ContinuationTest, continue_handler_NotifyTerminationToPrimary_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_NotifyTerminationToPrimary_002 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
sptr<IRemoteObject> remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback();
sptr<MockReverseContinuationSchedulerPrimaryProxy> primary =
new (std::nothrow) MockReverseContinuationSchedulerPrimaryProxy(remoteObject);
EXPECT_CALL(*primary, NotifyReplicaTerminated()).Times(1);
continuationHandler->remotePrimaryProxy_ = primary;
continuationHandler->NotifyTerminationToPrimary();
GTEST_LOG_(INFO) << "continue_handler_NotifyTerminationToPrimary_002 end";
}
/*
* @tc.number: continue_handler_SetReversible_001
* @tc.name: SetReversible
@@ -533,6 +859,141 @@ HWTEST_F(ContinuationTest, continue_handler_SetPrimaryStub_001, TestSize.Level1)
GTEST_LOG_(INFO) << "continue_handler_SetPrimaryStub_001 end";
}
/*
* @tc.number: continue_handler_ReverseContinueAbility_001
* @tc.name: ReverseContinueAbility
* @tc.desc: call ReverseContinueAbility with null remoteReplicaProxy_
*/
HWTEST_F(ContinuationTest, continue_handler_ReverseContinueAbility_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_SetPrimaryStub_001 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
auto result = continuationHandler->ReverseContinueAbility();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_handler_ReverseContinueAbility_001 end";
}
/*
* @tc.number: continue_handler_ReverseContinueAbility_002
* @tc.name: ReverseContinueAbility
* @tc.desc: call ReverseContinueAbility success
*/
HWTEST_F(ContinuationTest, continue_handler_ReverseContinueAbility_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_SetPrimaryStub_001 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
sptr<IRemoteObject> remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback();
sptr<MockReverseContinuationSchedulerReplicaProxy> primary =
new (std::nothrow) MockReverseContinuationSchedulerReplicaProxy(remoteObject);
EXPECT_CALL(*primary, ReverseContinuation()).Times(1).WillOnce(Return(true));
continuationHandler->remoteReplicaProxy_ = primary;
auto result = continuationHandler->ReverseContinueAbility();
EXPECT_TRUE(result);
GTEST_LOG_(INFO) << "continue_handler_ReverseContinueAbility_002 end";
}
/*
* @tc.number: continue_handler_HandleStartContinuationWithStack_001
* @tc.name: HandleStartContinuationWithStack
* @tc.desc: call HandleStartContinuationWithStack with nullptr token
*/
HWTEST_F(ContinuationTest, continue_handler_HandleStartContinuationWithStack_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_001 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
uint32_t versionCode = 0;
auto result = continuationHandler->HandleStartContinuationWithStack(nullptr, "deviceId", versionCode);
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_001 end";
}
/*
* @tc.number: continue_handler_HandleStartContinuationWithStack_002
* @tc.name: HandleStartContinuationWithStack
* @tc.desc: call HandleStartContinuationWithStack with no abilityInfo_
*/
HWTEST_F(ContinuationTest, continue_handler_HandleStartContinuationWithStack_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_002 start";
sptr<IRemoteObject> continueToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
uint32_t versionCode = 0;
auto result = continuationHandler->HandleStartContinuationWithStack(continueToken, "deviceId", versionCode);
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_002 end";
}
/*
* @tc.number: continue_handler_HandleStartContinuationWithStack_003
* @tc.name: HandleStartContinuationWithStack
* @tc.desc: call HandleStartContinuationWithStack with null continuationManager
*/
HWTEST_F(ContinuationTest, continue_handler_HandleStartContinuationWithStack_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_003 start";
sptr<IRemoteObject> continueToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
continuationManager.reset();
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
uint32_t versionCode = 0;
continuationHandler->SetAbilityInfo(abilityInfo_);
auto result = continuationHandler->HandleStartContinuationWithStack(continueToken, "deviceId", versionCode);
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_003 end";
}
/*
* @tc.number: continue_handler_HandleStartContinuationWithStack_004
* @tc.name: HandleStartContinuationWithStack
* @tc.desc: call HandleStartContinuationWithStack with OnContinue failed
*/
HWTEST_F(ContinuationTest, continue_handler_HandleStartContinuationWithStack_004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_004 start";
sptr<IRemoteObject> continueToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(ability_, continueToken, abilityInfo_, continuationHandler);
uint32_t versionCode = 0;
continuationHandler->SetAbilityInfo(abilityInfo_);
auto result = continuationHandler->HandleStartContinuationWithStack(continueToken, "deviceId", versionCode);
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_004 end";
}
/*
* @tc.number: continue_handler_HandleStartContinuationWithStack_005
* @tc.name: HandleStartContinuationWithStack
* @tc.desc: call HandleStartContinuationWithStack success
*/
HWTEST_F(ContinuationTest, continue_handler_HandleStartContinuationWithStack_005, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_005 start";
EXPECT_CALL(*mockAbility_, OnContinue(_)).Times(1).WillOnce(Return(ContinuationManager::OnContinueResult::AGREE));
EXPECT_CALL(*mockAbility_, GetContentInfo()).Times(1).WillOnce(Return("ContentInfo"));
sptr<IRemoteObject> continueToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
uint32_t versionCode = 0;
ability_->abilityInfo_->isStageBasedModel = true;
continuationHandler->SetAbilityInfo(abilityInfo_);
auto result = continuationHandler->HandleStartContinuationWithStack(continueToken, "deviceId", versionCode);
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_005 end";
}
/*
* @tc.number: continue_manager_GetContinuationState_001
* @tc.name: GetContinuationState
@@ -569,6 +1030,294 @@ HWTEST_F(ContinuationTest, continue_manager_GetOriginalDeviceId_001, TestSize.Le
GTEST_LOG_(INFO) << "continue_manager_GetOriginalDeviceId_001 end";
}
/*
* @tc.number: continue_manager_ContinueAbilityWithStack_001
* @tc.name: ContinueAbilityWithStack
* @tc.desc: call ContinueAbilityWithStack
*/
HWTEST_F(ContinuationTest, continue_manager_ContinueAbilityWithStack_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_ContinueAbilityWithStack_001 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
uint32_t versionCode = 0;
mockAbility_->abilityInfo_->isStageBasedModel = true;
continuationHandler->SetAbilityInfo(abilityInfo_);
continuationManager_->ContinueAbilityWithStack("deviceId", versionCode);
EXPECT_TRUE(continuationManager_->mainHandler_ != nullptr);
GTEST_LOG_(INFO) << "continue_manager_ContinueAbilityWithStack_001 end";
}
/*
* @tc.number: continue_manager_HandleContinueAbilityWithStack_001
* @tc.name: HandleContinueAbilityWithStack
* @tc.desc: call HandleContinueAbilityWithStack with checkAbilityToken failed
*/
HWTEST_F(ContinuationTest, continue_manager_HandleContinueAbilityWithStack_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbilityWithStack_001 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, nullptr, abilityInfo_, continuationHandler);
uint32_t versionCode = 0;
bool result = continuationManager_->HandleContinueAbilityWithStack("deviceId", versionCode);
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbilityWithStack_001 end";
}
/*
* @tc.number: continue_manager_HandleContinueAbilityWithStack_002
* @tc.name: HandleContinueAbilityWithStack
* @tc.desc: call HandleContinueAbilityWithStack with null continuationHandler
*/
HWTEST_F(ContinuationTest, continue_manager_HandleContinueAbilityWithStack_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbilityWithStack_002 start";
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, nullptr);
uint32_t versionCode = 0;
bool result = continuationManager_->HandleContinueAbilityWithStack("deviceId", versionCode);
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbilityWithStack_002 end";
}
/*
* @tc.number: continue_manager_HandleContinueAbilityWithStack_003
* @tc.name: HandleContinueAbilityWithStack
* @tc.desc: call HandleContinueAbilityWithStack success
*/
HWTEST_F(ContinuationTest, continue_manager_HandleContinueAbilityWithStack_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbilityWithStack_003 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
uint32_t versionCode = 0;
mockAbility_->abilityInfo_->isStageBasedModel = true;
continuationHandler->SetAbilityInfo(abilityInfo_);
bool result = continuationManager_->HandleContinueAbilityWithStack("deviceId", versionCode);
EXPECT_TRUE(result);
GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbilityWithStack_003 end";
}
/*
* @tc.number: continue_manager_ContinueAbility_001
* @tc.name: ContinueAbility
* @tc.desc: call ContinueAbility with CheckContinuation Illegal
*/
HWTEST_F(ContinuationTest, continue_manager_ContinueAbility_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_001 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
mockAbility_->abilityLifecycleExecutor_->DispatchLifecycleState(
AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED);
bool reversible = false;
continuationManager_->ContinueAbility(reversible, "deviceId");
EXPECT_TRUE(continuationManager_->CheckContinuationIllegal());
GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_001 end";
}
/*
* @tc.number: continue_manager_ContinueAbility_002
* @tc.name: ContinueAbility
* @tc.desc: call ContinueAbility with progressState_ is IN_PROGRESS
*/
HWTEST_F(ContinuationTest, continue_manager_ContinueAbility_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_002 start";
bool reversible = false;
continuationManager_->progressState_ = ContinuationManager::ProgressState::IN_PROGRESS;
continuationManager_->ContinueAbility(reversible, "deviceId");
EXPECT_NE(ContinuationManager::ProgressState::WAITING_SCHEDULE, continuationManager_->progressState_);
GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_002 end";
}
/*
* @tc.number: continue_manager_ContinueAbility_003
* @tc.name: ContinueAbility
* @tc.desc: call ContinueAbility with continuationState_ is REMOTE_RUNNING
*/
HWTEST_F(ContinuationTest, continue_manager_ContinueAbility_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_003 start";
bool reversible = false;
continuationManager_->continuationState_ = ContinuationState::REMOTE_RUNNING;
continuationManager_->ContinueAbility(reversible, "deviceId");
EXPECT_NE(ContinuationManager::ProgressState::WAITING_SCHEDULE, continuationManager_->progressState_);
GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_003 end";
}
/*
* @tc.number: continue_manager_ContinueAbility_004
* @tc.name: ContinueAbility
* @tc.desc: call ContinueAbility with HandleContinueAbility return true
*/
HWTEST_F(ContinuationTest, continue_manager_ContinueAbility_004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_004 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
bool reversible = false;
continuationManager_->ContinueAbility(reversible, "deviceId");
EXPECT_EQ(ContinuationManager::ProgressState::WAITING_SCHEDULE, continuationManager_->progressState_);
GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_004 end";
}
/*
* @tc.number: continue_manager_HandleContinueAbility_001
* @tc.name: HandleContinueAbility
* @tc.desc: call HandleContinueAbility with CheckAbilityToken failed
*/
HWTEST_F(ContinuationTest, continue_manager_HandleContinueAbility_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbility_001 start";
bool reversible = false;
bool result = continuationManager_->HandleContinueAbility(reversible, "deviceId");
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbility_001 end";
}
/*
* @tc.number: continue_manager_HandleContinueAbility_002
* @tc.name: HandleContinueAbility
* @tc.desc: call HandleContinueAbility with continuationHandler null
*/
HWTEST_F(ContinuationTest, continue_manager_HandleContinueAbility_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbility_002 start";
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, nullptr);
bool reversible = false;
bool result = continuationManager_->HandleContinueAbility(reversible, "deviceId");
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbility_002 end";
}
/*
* @tc.number: continue_manager_HandleContinueAbility_003
* @tc.name: HandleContinueAbility
* @tc.desc: call HandleContinueAbility success
*/
HWTEST_F(ContinuationTest, continue_manager_HandleContinueAbility_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbility_003 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
bool reversible = false;
bool result = continuationManager_->HandleContinueAbility(reversible, "deviceId");
EXPECT_TRUE(result);
GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbility_003 end";
}
/*
* @tc.number: continue_manager_ReverseContinueAbility_001
* @tc.name: ReverseContinueAbility
* @tc.desc: call ReverseContinueAbility with wrong ProgressState_
*/
HWTEST_F(ContinuationTest, continue_manager_ReverseContinueAbility_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_001 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(ability_, continueToken_, abilityInfo_, continuationHandler);
continuationManager_->progressState_ = ContinuationManager::ProgressState::WAITING_SCHEDULE;
continuationManager_->continuationState_ = ContinuationState::REMOTE_RUNNING;
bool result = continuationManager_->ReverseContinueAbility();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_001 end";
}
/*
* @tc.number: continue_manager_ReverseContinueAbility_002
* @tc.name: ReverseContinueAbility
* @tc.desc: call ReverseContinueAbility with wrong continuationState_
*/
HWTEST_F(ContinuationTest, continue_manager_ReverseContinueAbility_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_002 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = ability_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(ability_, continueToken_, abilityInfo_, continuationHandler);
continuationManager_->progressState_ = ContinuationManager::ProgressState::INITIAL;
continuationManager_->continuationState_ = ContinuationState::LOCAL_RUNNING;
bool result = continuationManager_->ReverseContinueAbility();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_002 end";
}
/*
* @tc.number: continue_manager_ReverseContinueAbility_003
* @tc.name: ReverseContinueAbility
* @tc.desc: call ReverseContinueAbility with null continuationHandler_
*/
HWTEST_F(ContinuationTest, continue_manager_ReverseContinueAbility_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_003 start";
continuationManager_->Init(ability_, continueToken_, abilityInfo_, nullptr);
continuationManager_->progressState_ = ContinuationManager::ProgressState::INITIAL;
continuationManager_->continuationState_ = ContinuationState::REMOTE_RUNNING;
bool result = continuationManager_->ReverseContinueAbility();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_003 end";
}
/*
* @tc.number: continue_manager_ReverseContinueAbility_004
* @tc.name: ReverseContinueAbility
* @tc.desc: call ReverseContinueAbility with requestSuccess is true
*/
HWTEST_F(ContinuationTest, continue_manager_ReverseContinueAbility_004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_004 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
continuationManager_->continuationState_ = ContinuationState::REMOTE_RUNNING;
sptr<IRemoteObject> remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback();
sptr<MockReverseContinuationSchedulerReplicaProxy> primary =
new (std::nothrow) MockReverseContinuationSchedulerReplicaProxy(remoteObject);
EXPECT_CALL(*primary, ReverseContinuation()).Times(1).WillOnce(Return(true));
continuationHandler->remoteReplicaProxy_ = primary;
bool result = continuationManager_->ReverseContinueAbility();
EXPECT_TRUE(result);
GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_004 end";
}
/*
* @tc.number: continue_manager_ReverseContinueAbility_005
* @tc.name: ReverseContinueAbility
* @tc.desc: call ReverseContinueAbility with requestSuccess is false
*/
HWTEST_F(ContinuationTest, continue_manager_ReverseContinueAbility_005, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_005 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
continuationManager_->continuationState_ = ContinuationState::REMOTE_RUNNING;
sptr<IRemoteObject> remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback();
sptr<MockReverseContinuationSchedulerReplicaProxy> primary =
new (std::nothrow) MockReverseContinuationSchedulerReplicaProxy(remoteObject);
EXPECT_CALL(*primary, ReverseContinuation()).Times(1).WillOnce(Return(false));
continuationHandler->remoteReplicaProxy_ = primary;
bool result = continuationManager_->ReverseContinueAbility();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_005 end";
}
/*
* @tc.number: continue_manager_OnContinue_001
* @tc.name: OnContinue
@@ -1088,5 +1837,83 @@ HWTEST_F(ContinuationTest, continue_manager_ChangeProcessStateToInit_002, TestSi
EXPECT_EQ(ContinuationManager::ProgressState::INITIAL, continuationManager_->progressState_);
GTEST_LOG_(INFO) << "continue_manager_ChangeProcessStateToInit_002 end";
}
/*
* @tc.name: continue_manager_DoScheduleStartContinuation_001
* @tc.name: DoScheduleStartContinuation
* @tc.desc: call DoScheduleStartContinuation with CheckContinuationIllegal failed
*/
HWTEST_F(ContinuationTest, continue_manager_DoScheduleStartContinuation_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_DoScheduleStartContinuation_001 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
mockAbility_->abilityLifecycleExecutor_->DispatchLifecycleState(
AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED);
bool result = continuationManager_->DoScheduleStartContinuation();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_manager_DoScheduleStartContinuation_001 end";
}
/*
* @tc.name: continue_manager_DoScheduleSaveData_001
* @tc.name: DoScheduleSaveData
* @tc.desc: call DoScheduleSaveData with CheckContinuationIllegal failed
*/
HWTEST_F(ContinuationTest, continue_manager_DoScheduleSaveData_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_DoScheduleSaveData_001 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
mockAbility_->abilityLifecycleExecutor_->DispatchLifecycleState(
AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED);
WantParams saveData;
bool result = continuationManager_->DoScheduleSaveData(saveData);
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_manager_DoScheduleSaveData_001 end";
}
/*
* @tc.name: continue_manager_DoScheduleRestoreData_001
* @tc.name: DoScheduleRestoreData
* @tc.desc: call DoScheduleRestoreData with CheckContinuationIllegal failed
*/
HWTEST_F(ContinuationTest, continue_manager_DoScheduleRestoreData_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_DoScheduleRestoreData_001 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
mockAbility_->abilityLifecycleExecutor_->DispatchLifecycleState(
AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED);
WantParams restoreData;
bool result = continuationManager_->DoScheduleRestoreData(restoreData);
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_manager_DoScheduleSaveData_001 end";
}
/*
* @tc.name: continue_manager_DoScheduleRestoreData_002
* @tc.name: DoScheduleRestoreData
* @tc.desc: call DoScheduleRestoreData with ability is null
*/
HWTEST_F(ContinuationTest, continue_manager_DoScheduleRestoreData_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "continue_manager_DoScheduleRestoreData_002 start";
std::weak_ptr<ContinuationManager> continuationManager = continuationManager_;
std::weak_ptr<Ability> abilityTmp = mockAbility_;
auto continuationHandler = std::make_shared<ContinuationHandler>(continuationManager, abilityTmp);
continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler);
continuationManager_->ability_.reset();
WantParams restoreData;
bool result = continuationManager_->DoScheduleRestoreData(restoreData);
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "continue_manager_DoScheduleRestoreData_002 end";
}
} // namespace AppExecFwk
} // namespace OHOS
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,637 @@
/*
* Copyright (c) 2022 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 <gtest/gtest.h>
#define private public
#define protected public
#include "ability_handler.h"
#include "ability_info.h"
#include "ability_local_record.h"
#include "extension_impl.h"
#undef private
#undef protected
#include "event_runner.h"
#include "mock_ability_token.h"
#include "ohos_application.h"
namespace OHOS {
namespace AppExecFwk {
using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::AppExecFwk;
class ExtensionImplTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void ExtensionImplTest::SetUpTestCase(void)
{
}
void ExtensionImplTest::TearDownTestCase(void)
{
}
void ExtensionImplTest::SetUp(void)
{
}
void ExtensionImplTest::TearDown(void)
{
}
/**
* @tc.number: AaFwk_ExtensionImpl_0100
* @tc.name: Init
* @tc.desc: params is nullptr, Validation initialization failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0100 start";
std::shared_ptr<OHOSApplication> application;
std::shared_ptr<AbilityLocalRecord> record;
std::shared_ptr<AbilityRuntime::Extension> extension;
std::shared_ptr<AppExecFwk::AbilityHandler> handler;
sptr<IRemoteObject> token = nullptr;
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
EXPECT_TRUE(impl->token_ == nullptr);
EXPECT_TRUE(impl->extension_ == nullptr);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0100 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_0200
* @tc.name: Init
* @tc.desc: application is not null, others is null, Validation initialization failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0200 start";
auto application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AbilityLocalRecord> record;
std::shared_ptr<AbilityRuntime::Extension> extension;
std::shared_ptr<AppExecFwk::AbilityHandler> handler;
sptr<IRemoteObject> token = nullptr;
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
EXPECT_TRUE(impl->token_ == nullptr);
EXPECT_TRUE(impl->extension_ == nullptr);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0200 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_0300
* @tc.name: Init
* @tc.desc: record is not null, others is null, Validation initialization failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0300, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0300 start";
std::shared_ptr<OHOSApplication> application;
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
auto record = std::make_shared<AppExecFwk::AbilityLocalRecord>(info, token);
std::shared_ptr<AbilityRuntime::Extension> extension;
std::shared_ptr<AppExecFwk::AbilityHandler> handler;
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
EXPECT_TRUE(impl->token_ == nullptr);
EXPECT_TRUE(impl->extension_ == nullptr);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0300 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_0400
* @tc.name: Init
* @tc.desc: token is not null, others is null, Validation initialization failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0400, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0400 start";
std::shared_ptr<OHOSApplication> application;
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
std::shared_ptr<AbilityLocalRecord> record;
std::shared_ptr<AbilityRuntime::Extension> extension;
std::shared_ptr<AppExecFwk::AbilityHandler> handler;
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
EXPECT_TRUE(impl->token_ == nullptr);
EXPECT_TRUE(impl->extension_ == nullptr);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0400 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_0500
* @tc.name: Init
* @tc.desc: handler is not null, others is null, Validation initialization failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0500, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0500 start";
std::shared_ptr<OHOSApplication> application;
sptr<IRemoteObject> token = nullptr;
std::shared_ptr<AbilityLocalRecord> record;
std::shared_ptr<AbilityRuntime::Extension> extension;
std::shared_ptr<EventRunner> runner;
auto handler = std::make_shared<AppExecFwk::AbilityHandler>(runner);
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
EXPECT_TRUE(impl->token_ == nullptr);
EXPECT_TRUE(impl->extension_ == nullptr);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0500 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_0600
* @tc.name: Init
* @tc.desc: extension is not null, others is null, Validation initialization failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0600, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0600 start";
std::shared_ptr<OHOSApplication> application;
sptr<IRemoteObject> token = nullptr;
std::shared_ptr<AbilityLocalRecord> record;
auto extension = std::make_shared<AbilityRuntime::Extension>();
std::shared_ptr<AppExecFwk::AbilityHandler> handler;
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
EXPECT_TRUE(impl->token_ == nullptr);
EXPECT_TRUE(impl->extension_ == nullptr);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0600 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_0700
* @tc.name: Init
* @tc.desc: extension is not null, others is null, Validation initialization succeeded.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0700, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0700 start";
auto application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
auto record = std::make_shared<AppExecFwk::AbilityLocalRecord>(info, token);
auto extension = std::make_shared<AbilityRuntime::Extension>();
std::shared_ptr<EventRunner> runner;
auto handler = std::make_shared<AppExecFwk::AbilityHandler>(runner);
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
EXPECT_TRUE(impl->token_ != nullptr);
EXPECT_TRUE(impl->extension_ != nullptr);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0700 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_0800
* @tc.name: NotifyMemoryLevel
* @tc.desc: Validation NotifyMemoryLevel succeeded.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0800, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0800 start";
auto application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
auto record = std::make_shared<AppExecFwk::AbilityLocalRecord>(info, token);
auto extension = std::make_shared<AbilityRuntime::Extension>();
std::shared_ptr<EventRunner> runner;
auto handler = std::make_shared<AppExecFwk::AbilityHandler>(runner);
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
EXPECT_TRUE(impl->token_ != nullptr);
EXPECT_TRUE(impl->extension_ != nullptr);
impl->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
int32_t level = 0;
impl->NotifyMemoryLevel(level);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0800 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_0900
* @tc.name: NotifyMemoryLevel
* @tc.desc: Validation NotifyMemoryLevel succeeded.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0900, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0900 start";
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
int32_t level = 0;
impl->NotifyMemoryLevel(level);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0900 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_1000
* @tc.name: Start
* @tc.desc: extension is nullptr, Validation Start failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1000, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1000 start";
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL;
Want want;
impl->Start(want);
EXPECT_NE(impl->lifecycleState_, AAFwk::ABILITY_STATE_INACTIVE);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1000 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_1100
* @tc.name: Start
* @tc.desc: extension is not nullptr, Validation Start succeeded.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1100 start";
auto application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
auto record = std::make_shared<AppExecFwk::AbilityLocalRecord>(info, token);
auto extension = std::make_shared<AbilityRuntime::Extension>();
std::shared_ptr<EventRunner> runner;
auto handler = std::make_shared<AppExecFwk::AbilityHandler>(runner);
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
Want want;
impl->Start(want);
EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_INACTIVE);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1100 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_1200
* @tc.name: Stop
* @tc.desc: extension is not nullptr, Validation Stop succeeded.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1200 start";
auto application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
auto record = std::make_shared<AppExecFwk::AbilityLocalRecord>(info, token);
auto extension = std::make_shared<AbilityRuntime::Extension>();
std::shared_ptr<EventRunner> runner;
auto handler = std::make_shared<AppExecFwk::AbilityHandler>(runner);
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
impl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
impl->Stop();
EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1200 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_1300
* @tc.name: Stop
* @tc.desc: extension is nullptr, Validation Stop failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1300, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1300 start";
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
impl->Stop();
EXPECT_NE(impl->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1300 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_1400
* @tc.name: ConnectExtension
* @tc.desc: extension is nullptr, Validation ConnectExtension failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1400, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1400 start";
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
Want want;
auto object = impl->ConnectExtension(want);
EXPECT_NE(impl->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE);
EXPECT_TRUE(object == nullptr);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1400 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_1500
* @tc.name: ConnectExtension
* @tc.desc: extension is not nullptr, Validation ConnectExtension succeeded.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1500, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1500 start";
auto application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
auto record = std::make_shared<AppExecFwk::AbilityLocalRecord>(info, token);
auto extension = std::make_shared<AbilityRuntime::Extension>();
std::shared_ptr<EventRunner> runner;
auto handler = std::make_shared<AppExecFwk::AbilityHandler>(runner);
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
impl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
Want want;
auto object = impl->ConnectExtension(want);
EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE);
EXPECT_TRUE(object == nullptr);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1500 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_1600
* @tc.name: DisconnectExtension
* @tc.desc: extension is not nullptr, Validation DisconnectExtension succeeded.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1600, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1600 start";
auto application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
auto record = std::make_shared<AppExecFwk::AbilityLocalRecord>(info, token);
auto extension = std::make_shared<AbilityRuntime::Extension>();
std::shared_ptr<EventRunner> runner;
auto handler = std::make_shared<AppExecFwk::AbilityHandler>(runner);
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
Want want;
impl->DisconnectExtension(want);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1600 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_1700
* @tc.name: DisconnectExtension
* @tc.desc: extension is not nullptr, Validation DisconnectExtension failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1700, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1700 start";
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
Want want;
impl->DisconnectExtension(want);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1700 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_1800
* @tc.name: DisconnectExtension
* @tc.desc: extension is nullptr, Validation DisconnectExtension failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1800, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1800 start";
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
Want want;
bool isAsyncCallback = true;
impl->DisconnectExtension(want, isAsyncCallback);
EXPECT_FALSE(isAsyncCallback);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1800 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_1900
* @tc.name: DisconnectExtension
* @tc.desc: extension is nullptr, Validation DisconnectExtension failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1900, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1900 start";
auto application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
auto record = std::make_shared<AppExecFwk::AbilityLocalRecord>(info, token);
auto extension = std::make_shared<AbilityRuntime::Extension>();
std::shared_ptr<EventRunner> runner;
auto handler = std::make_shared<AppExecFwk::AbilityHandler>(runner);
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
Want want;
bool isAsyncCallback = true;
impl->DisconnectExtension(want, isAsyncCallback);
EXPECT_FALSE(isAsyncCallback);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1900 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_2000
* @tc.name: DisconnectExtensionCallback
* @tc.desc: Validation DisconnectExtensionCallback succeeded.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2000, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2000 start";
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->DisconnectExtensionCallback();
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2000 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_2100
* @tc.name: CommandExtension
* @tc.desc: extension is nullptr, Validation CommandExtension failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2100 start";
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
Want want;
bool restart = false;
int32_t startId = 0;
impl->CommandExtension(want, restart, startId);
EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_INACTIVE);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2100 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_2200
* @tc.name: CommandExtension
* @tc.desc: extension is not nullptr, Validation CommandExtension succeeded.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2200 start";
auto application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
auto record = std::make_shared<AppExecFwk::AbilityLocalRecord>(info, token);
auto extension = std::make_shared<AbilityRuntime::Extension>();
std::shared_ptr<EventRunner> runner;
auto handler = std::make_shared<AppExecFwk::AbilityHandler>(runner);
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
impl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
Want want;
bool restart = false;
int32_t startId = 0;
impl->CommandExtension(want, restart, startId);
EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2200 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_2300
* @tc.name: ScheduleUpdateConfiguration
* @tc.desc: extension is not nullptr, Validation ScheduleUpdateConfiguration succeeded.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2300, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2300 start";
auto application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
auto record = std::make_shared<AppExecFwk::AbilityLocalRecord>(info, token);
auto extension = std::make_shared<AbilityRuntime::Extension>();
std::shared_ptr<EventRunner> runner;
auto handler = std::make_shared<AppExecFwk::AbilityHandler>(runner);
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
AppExecFwk::Configuration config;
impl->ScheduleUpdateConfiguration(config);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2300 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_2400
* @tc.name: ScheduleUpdateConfiguration
* @tc.desc: extension is not nullptr, Validation ScheduleUpdateConfiguration failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2400, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2400 start";
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
AppExecFwk::Configuration config;
impl->ScheduleUpdateConfiguration(config);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2400 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_2600
* @tc.name: HandleExtensionTransaction
* @tc.desc: current state is init, target state is inactive, Validation HandleExtensionTransaction succeeded.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2600, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2600 start";
auto application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
auto record = std::make_shared<AppExecFwk::AbilityLocalRecord>(info, token);
auto extension = std::make_shared<AbilityRuntime::Extension>();
std::shared_ptr<EventRunner> runner;
auto handler = std::make_shared<AppExecFwk::AbilityHandler>(runner);
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
impl->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL;
AAFwk::LifeCycleStateInfo targetState;
targetState.state = AAFwk::ABILITY_STATE_INITIAL;
Want want;
impl->HandleExtensionTransaction(want, targetState);
targetState.state = AAFwk::ABILITY_STATE_INACTIVE;
impl->HandleExtensionTransaction(want, targetState);
EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_INACTIVE);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2600 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_2700
* @tc.name: HandleExtensionTransaction
* @tc.desc: current state is active, target state is init, Validation HandleExtensionTransaction succeeded.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2700, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2700 start";
auto application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
auto record = std::make_shared<AppExecFwk::AbilityLocalRecord>(info, token);
auto extension = std::make_shared<AbilityRuntime::Extension>();
std::shared_ptr<EventRunner> runner;
auto handler = std::make_shared<AppExecFwk::AbilityHandler>(runner);
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
impl->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
Want want;
AAFwk::LifeCycleStateInfo targetState;
targetState.state = AAFwk::ABILITY_STATE_INITIAL;
impl->HandleExtensionTransaction(want, targetState);
EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2700 end";
}
/**
* @tc.number: AaFwk_ExtensionImpl_2800
* @tc.name: HandleExtensionTransaction
* @tc.desc: current state is active, target state is inactive, Validation HandleExtensionTransaction failed.
*/
HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2800, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2800 start";
auto application = std::make_shared<AppExecFwk::OHOSApplication>();
std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
sptr<IRemoteObject> token = new AppExecFwk::MockAbilityToken();
auto record = std::make_shared<AppExecFwk::AbilityLocalRecord>(info, token);
auto extension = std::make_shared<AbilityRuntime::Extension>();
std::shared_ptr<EventRunner> runner;
auto handler = std::make_shared<AppExecFwk::AbilityHandler>(runner);
auto impl = std::make_shared<AbilityRuntime::ExtensionImpl>();
impl->Init(application, record, extension, handler, token);
impl->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
Want want;
AAFwk::LifeCycleStateInfo targetState;
targetState.state = AAFwk::ABILITY_STATE_INACTIVE;
impl->HandleExtensionTransaction(want, targetState);
EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE);
GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2800 end";
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -0,0 +1,271 @@
/*
* Copyright (c) 2022 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 <gtest/gtest.h>
#define private public
#define protected public
#include "form_js_event_handler.h"
#include "form_mgr.h"
#include "inner_event.h"
#undef private
#undef protected
#include "mock_form_mgr_proxy.h"
#include "mock_service_ability.h"
namespace OHOS {
namespace AppExecFwk {
using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::AppExecFwk;
using testing::_;
class FormJsEventHandlerTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void FormJsEventHandlerTest::SetUpTestCase(void)
{
}
void FormJsEventHandlerTest::TearDownTestCase(void)
{
}
void FormJsEventHandlerTest::SetUp(void)
{
}
void FormJsEventHandlerTest::TearDown(void)
{
}
/**
* @tc.number: AaFwk_FormJsEventHandler_0100
* @tc.name: Create
* @tc.desc: Constructor method
*/
HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0100 start";
std::shared_ptr<EventRunner> runner;
std::shared_ptr<Ability> ability;
FormJsInfo formJsInfo;
auto eventHandler = std::make_shared<FormJsEventHandler>(runner, ability, formJsInfo);
EXPECT_TRUE(eventHandler->ability_ == nullptr);
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0100 end";
}
/**
* @tc.number: AaFwk_FormJsEventHandler_0200
* @tc.name: Create
* @tc.desc: Constructor method
*/
HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0200 start";
std::shared_ptr<EventRunner> runner;
std::shared_ptr<Ability> ability = std::make_shared<MockServiceAbility>();
FormJsInfo formJsInfo;
auto eventHandler = std::make_shared<FormJsEventHandler>(runner, ability, formJsInfo);
EXPECT_TRUE(eventHandler->ability_ != nullptr);
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0200 end";
}
/**
* @tc.number: AaFwk_FormJsEventHandler_0300
* @tc.name: IsSystemApp
* @tc.desc: Validation IsSystemApp succeeded.
*/
HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0300, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0300 start";
std::shared_ptr<EventRunner> runner;
std::shared_ptr<Ability> ability = std::make_shared<MockServiceAbility>();
FormJsInfo formJsInfo;
auto eventHandler = std::make_shared<FormJsEventHandler>(runner, ability, formJsInfo);
auto result = eventHandler->IsSystemApp();
EXPECT_TRUE(result);
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0300 end";
}
/**
* @tc.number: AaFwk_FormJsEventHandler_0400
* @tc.name: ProcessEvent
* @tc.desc: event is nullptr, Verify that the ProcessEvent succeeded.
*/
HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0400, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0400 start";
std::shared_ptr<EventRunner> runner;
std::shared_ptr<Ability> ability = std::make_shared<MockServiceAbility>();
FormJsInfo formJsInfo;
auto eventHandler = std::make_shared<FormJsEventHandler>(runner, ability, formJsInfo);
InnerEvent::Pointer event = InnerEvent::Pointer(nullptr, nullptr);
eventHandler->ProcessEvent(event);
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0400 end";
}
/**
* @tc.number: AaFwk_FormJsEventHandler_0500
* @tc.name: ProcessEvent
* @tc.desc: empty event, Verify that the ProcessEvent succeeded.
*/
HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0500, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0500 start";
std::shared_ptr<EventRunner> runner;
std::shared_ptr<Ability> ability = std::make_shared<MockServiceAbility>();
FormJsInfo formJsInfo;
auto eventHandler = std::make_shared<FormJsEventHandler>(runner, ability, formJsInfo);
InnerEvent::Pointer event = InnerEvent::Get();
eventHandler->ProcessEvent(event);
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0500 end";
}
/**
* @tc.number: AaFwk_FormJsEventHandler_0600
* @tc.name: ProcessRouterEvent
* @tc.desc: Validation ProcessRouterEvent succeeded.
*/
HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0600, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0600 start";
std::shared_ptr<EventRunner> runner;
std::shared_ptr<Ability> ability = std::make_shared<MockServiceAbility>();
FormJsInfo formJsInfo;
formJsInfo.bundleName = "bundleName";
auto eventHandler = std::make_shared<FormJsEventHandler>(runner, ability, formJsInfo);
Want want;
eventHandler->ProcessRouterEvent(want);
std::string abilityName = "formAbility";
want.SetParam(Constants::PARAM_FORM_ABILITY_NAME_KEY, abilityName);
eventHandler->ProcessRouterEvent(want);
auto bundleName = want.GetElement().GetBundleName();
EXPECT_STREQ(bundleName.c_str(), "bundleName");
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0600 end";
}
/**
* @tc.number: AaFwk_FormJsEventHandler_0700
* @tc.name: ProcessMessageEvent
* @tc.desc: Validation ProcessMessageEvent succeeded.
*/
HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0700, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0700 start";
sptr<IRemoteObject> impl = nullptr;
sptr<MockFormMgrProxy> mockProxy = new (std::nothrow) MockFormMgrProxy(impl);
FormMgr::GetInstance().SetFormMgrService(mockProxy);
std::shared_ptr<EventRunner> runner;
std::shared_ptr<Ability> ability = std::make_shared<MockServiceAbility>();
FormJsInfo formJsInfo;
auto eventHandler = std::make_shared<FormJsEventHandler>(runner, ability, formJsInfo);
Want want;
std::string formId = "1";
want.SetParam(Constants::PARAM_FORM_IDENTITY_KEY, formId);
std::string message = "message";
want.SetParam(Constants::PARAM_MESSAGE_KEY, message);
EXPECT_CALL(*mockProxy, MessageEvent(_, _, _)).Times(1);
eventHandler->ProcessMessageEvent(want);
testing::Mock::AllowLeak(mockProxy);
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0700 end";
}
/**
* @tc.number: AaFwk_FormJsEventHandler_0800
* @tc.name: ProcessMessageEvent
* @tc.desc: There is no formId in want, Validation ProcessMessageEvent failed.
*/
HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0800, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0800 start";
std::shared_ptr<EventRunner> runner;
std::shared_ptr<Ability> ability = std::make_shared<MockServiceAbility>();
FormJsInfo formJsInfo;
auto eventHandler = std::make_shared<FormJsEventHandler>(runner, ability, formJsInfo);
Want want;
eventHandler->ProcessMessageEvent(want);
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0800 end";
}
/**
* @tc.number: AaFwk_FormJsEventHandler_0900
* @tc.name: ProcessMessageEvent
* @tc.desc: form id is equal to 0, Validation ProcessMessageEvent failed.
*/
HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0900, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0900 start";
std::shared_ptr<EventRunner> runner;
std::shared_ptr<Ability> ability = std::make_shared<MockServiceAbility>();
FormJsInfo formJsInfo;
auto eventHandler = std::make_shared<FormJsEventHandler>(runner, ability, formJsInfo);
Want want;
std::string formId = "0";
want.SetParam(Constants::PARAM_FORM_IDENTITY_KEY, formId);
eventHandler->ProcessMessageEvent(want);
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0900 end";
}
/**
* @tc.number: AaFwk_FormJsEventHandler_1000
* @tc.name: ProcessMessageEvent
* @tc.desc: There is no PARAM_MESSAGE_KEY in want, Validation ProcessMessageEvent failed.
*/
HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_1000, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_1000 start";
std::shared_ptr<EventRunner> runner;
std::shared_ptr<Ability> ability = std::make_shared<MockServiceAbility>();
FormJsInfo formJsInfo;
auto eventHandler = std::make_shared<FormJsEventHandler>(runner, ability, formJsInfo);
Want want;
std::string formId = "1";
want.SetParam(Constants::PARAM_FORM_IDENTITY_KEY, formId);
eventHandler->ProcessMessageEvent(want);
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_1000 end";
}
/**
* @tc.number: AaFwk_FormJsEventHandler_1100
* @tc.name: ProcessMessageEvent
* @tc.desc: Form mgr set IN_RECOVERING, Validation ProcessMessageEvent failed.
*/
HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_1100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_1100 start";
std::shared_ptr<EventRunner> runner;
std::shared_ptr<Ability> ability = std::make_shared<MockServiceAbility>();
FormJsInfo formJsInfo;
auto eventHandler = std::make_shared<FormJsEventHandler>(runner, ability, formJsInfo);
Want want;
std::string formId = "1";
want.SetParam(Constants::PARAM_FORM_IDENTITY_KEY, formId);
std::string message = "message";
want.SetParam(Constants::PARAM_MESSAGE_KEY, message);
FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING);
eventHandler->ProcessMessageEvent(want);
GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_1100 end";
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -0,0 +1,147 @@
/*
* Copyright (c) 2021-2022 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 "gtest/gtest.h"
#define private public
#define protected public
#include "context.h"
#include "mock_ability_runtime_context.h"
#undef private
#undef protected
namespace OHOS {
namespace AbilityRuntime {
MockAbilityRuntimeContext::MockAbilityRuntimeContext()
{};
std::string MockAbilityRuntimeContext::GetBundleName() const
{
return {};
};
std::shared_ptr<Context> MockAbilityRuntimeContext::CreateBundleContext(const std::string &bundleName)
{
return {};
};
std::shared_ptr<AppExecFwk::ApplicationInfo> MockAbilityRuntimeContext::GetApplicationInfo() const
{
return {};
};
std::shared_ptr<Global::Resource::ResourceManager> MockAbilityRuntimeContext::GetResourceManager() const
{
return {};
};
std::string MockAbilityRuntimeContext::GetBundleCodePath() const
{
return {};
};
std::shared_ptr<AppExecFwk::HapModuleInfo> MockAbilityRuntimeContext::GetHapModuleInfo() const
{
return {};
};
std::string MockAbilityRuntimeContext::GetBundleCodeDir()
{
return {};
};
std::string MockAbilityRuntimeContext::GetCacheDir()
{
return {};
};
std::string MockAbilityRuntimeContext::GetTempDir()
{
return {};
};
std::string MockAbilityRuntimeContext::GetFilesDir()
{
return {};
};
bool MockAbilityRuntimeContext::IsUpdatingConfigurations()
{
return {};
};
bool MockAbilityRuntimeContext::PrintDrawnCompleted()
{
return {};
};
std::string MockAbilityRuntimeContext::GetDatabaseDir()
{
return {};
};
std::string MockAbilityRuntimeContext::GetPreferencesDir()
{
return {};
};
std::string MockAbilityRuntimeContext::GetDistributedFilesDir()
{
return {};
};
sptr<IRemoteObject> MockAbilityRuntimeContext::GetToken()
{
return {};
};
void MockAbilityRuntimeContext::SetToken(const sptr<IRemoteObject> &token)
{};
void MockAbilityRuntimeContext::SwitchArea(int mode)
{};
std::shared_ptr<Context> MockAbilityRuntimeContext::CreateModuleContext(const std::string &moduleName)
{
return {};
};
std::shared_ptr<Context> MockAbilityRuntimeContext::CreateModuleContext(
const std::string &bundleName, const std::string &moduleName)
{
return {};
};
int MockAbilityRuntimeContext::GetArea()
{
return {};
};
std::shared_ptr<AppExecFwk::Configuration> MockAbilityRuntimeContext::GetConfiguration() const
{
return {};
};
std::string MockAbilityRuntimeContext::GetBaseDir() const
{
return {};
};
Global::Resource::DeviceType MockAbilityRuntimeContext::GetDeviceType() const
{
return {};
};
} // namespace AbilityRuntime
} // namespace OHOS
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2021-2022 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 "gtest/gtest.h"
#define private public
#define protected public
#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context.h"
#undef private
#undef protected
namespace OHOS {
namespace AbilityRuntime {
class MockAbilityRuntimeContext : public OHOS::AbilityRuntime::Context {
public:
MockAbilityRuntimeContext();
virtual ~MockAbilityRuntimeContext() = default;
std::string GetBundleName() const override;
std::shared_ptr<Context> CreateBundleContext(const std::string &bundleName) override;
std::shared_ptr<AppExecFwk::ApplicationInfo> GetApplicationInfo() const override;
std::shared_ptr<Global::Resource::ResourceManager> GetResourceManager() const override;
std::string GetBundleCodePath() const override;
std::shared_ptr<AppExecFwk::HapModuleInfo> GetHapModuleInfo() const override;
std::string GetBundleCodeDir() override;
std::string GetCacheDir() override;
std::string GetTempDir() override;
std::string GetFilesDir() override;
bool IsUpdatingConfigurations() override;
bool PrintDrawnCompleted() override;
std::string GetDatabaseDir() override;
std::string GetPreferencesDir() override;
std::string GetDistributedFilesDir() override;
sptr<IRemoteObject> GetToken() override;
void SetToken(const sptr<IRemoteObject> &token) override;
void SwitchArea(int mode) override;
std::shared_ptr<Context> CreateModuleContext(const std::string &moduleName) override;
std::shared_ptr<Context> CreateModuleContext(
const std::string &bundleName, const std::string &moduleName) override;
int GetArea() override;
std::shared_ptr<AppExecFwk::Configuration> GetConfiguration() const override;
std::string GetBaseDir() const override;
Global::Resource::DeviceType GetDeviceType() const override;
};
} // namespace AbilityRuntime
} // namespace OHOS
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2022 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 <gtest/gtest.h>
#include "gmock/gmock.h"
#define private public
#define protected public
#include "message_parcel.h"
#include "mock_ability_connect_callback.h"
#include "peer_holder.h"
#include "reverse_continuation_scheduler_primary.h"
#include "reverse_continuation_scheduler_primary_proxy.h"
#include "reverse_continuation_scheduler_primary_stub.h"
#undef private
#undef protected
namespace OHOS {
namespace AppExecFwk {
using namespace testing::ext;
using ::testing::_;
using namespace OHOS;
using namespace OHOS::AppExecFwk;
class MockContinuationSchedulerPrimaryStub : public ReverseContinuationSchedulerPrimaryStub {
public:
MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option));
MOCK_METHOD0(NotifyReplicaTerminated, void());
MOCK_METHOD1(ContinuationBack, bool(const AAFwk::Want& want));
};
class ReverseContinuationSchedulerPrimaryProxyTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void ReverseContinuationSchedulerPrimaryProxyTest::SetUpTestCase(void) {}
void ReverseContinuationSchedulerPrimaryProxyTest::TearDownTestCase(void) {}
void ReverseContinuationSchedulerPrimaryProxyTest::SetUp(void) {}
void ReverseContinuationSchedulerPrimaryProxyTest::TearDown(void) {}
/**
* @tc.number: ContinuationBack_0100
* @tc.name: ContinuationBack
* @tc.desc: Verify that function ContinuationBack.
*/
HWTEST_F(ReverseContinuationSchedulerPrimaryProxyTest, ContinuationBack_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "ContinuationBack_0100 start";
auto remoteObject = new (std::nothrow) MockContinuationSchedulerPrimaryStub();
auto primaryProxy_ = new (std::nothrow) ReverseContinuationSchedulerPrimaryProxy(remoteObject->AsObject());
AAFwk::Want want;
EXPECT_CALL(*remoteObject, OnRemoteRequest(_, _, _, _))
.Times(::testing::AtLeast(1)).WillOnce(::testing::Return(2));
auto result = primaryProxy_->ContinuationBack(want);
EXPECT_TRUE(result);
testing::Mock::AllowLeak(remoteObject);
GTEST_LOG_(INFO) << "ContinuationBack_0100 end";
}
/**
* @tc.number: ContinuationBack_0200
* @tc.name: ContinuationBack
* @tc.desc: Verify that function ContinuationBack.
*/
HWTEST_F(ReverseContinuationSchedulerPrimaryProxyTest, ContinuationBack_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "ContinuationBack_0100 start";
sptr<IRemoteObject> remoteObject = nullptr;
auto primaryProxy_ = new (std::nothrow) ReverseContinuationSchedulerPrimaryProxy(remoteObject);
AAFwk::Want want;
auto result = primaryProxy_->ContinuationBack(want);
EXPECT_TRUE(!result);
GTEST_LOG_(INFO) << "ContinuationBack_0100 end";
}
/**
* @tc.number: NotifyReplicaTerminated_0100
* @tc.name: NotifyReplicaTerminated
* @tc.desc: Verify that function NotifyReplicaTerminated.
*/
HWTEST_F(ReverseContinuationSchedulerPrimaryProxyTest, NotifyReplicaTerminated_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "NotifyReplicaTerminated_0100 start";
sptr<IRemoteObject> remoteObject = nullptr;
auto primaryProxy_ = new (std::nothrow) ReverseContinuationSchedulerPrimaryProxy(remoteObject);
primaryProxy_->NotifyReplicaTerminated();
auto Object = new (std::nothrow) MockContinuationSchedulerPrimaryStub();
primaryProxy_ = new (std::nothrow) ReverseContinuationSchedulerPrimaryProxy(Object->AsObject());
EXPECT_CALL(*Object, OnRemoteRequest(_, _, _, _))
.Times(::testing::AtLeast(1)).WillOnce(::testing::Return(2));
primaryProxy_->NotifyReplicaTerminated();
testing::Mock::AllowLeak(Object);
GTEST_LOG_(INFO) << "NotifyReplicaTerminated_0100 end";
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -0,0 +1,186 @@
/*
* Copyright (c) 2022 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 <gtest/gtest.h>
#define private public
#define protected public
#include "event_handler.h"
#include "message_parcel.h"
#include "parcel.h"
#include "reverse_continuation_scheduler_primary.h"
#include "reverse_continuation_scheduler_primary_stub.h"
#undef protected
#undef private
namespace OHOS {
namespace AppExecFwk {
using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::AppExecFwk;
using namespace OHOS::AAFwk;
class MockReverseContinuationSchedulerPrimaryStub : public ReverseContinuationSchedulerPrimaryStub {
public:
MockReverseContinuationSchedulerPrimaryStub() = default;
virtual ~MockReverseContinuationSchedulerPrimaryStub() {}
bool ContinuationBack(const AAFwk::Want& want) override
{
return true;
}
void NotifyReplicaTerminated() override {}
};
class ReverseContinuationSchedulerPrimaryStubTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
sptr<ReverseContinuationSchedulerPrimaryStub> primaryStub_;
};
void ReverseContinuationSchedulerPrimaryStubTest::SetUpTestCase(void) {}
void ReverseContinuationSchedulerPrimaryStubTest::TearDownTestCase(void) {}
void ReverseContinuationSchedulerPrimaryStubTest::SetUp(void)
{
primaryStub_ = new (std::nothrow) MockReverseContinuationSchedulerPrimaryStub();
}
void ReverseContinuationSchedulerPrimaryStubTest::TearDown(void)
{
primaryStub_ = nullptr;
}
/**
* @tc.number: OnRemoteRequest_0100
* @tc.name: OnRemoteRequest
* @tc.desc: Verify that function OnRemoteRequest
*/
HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, OnRemoteRequest_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "OnRemoteRequest_0100 start";
uint32_t code = 1;
MessageParcel data;
MessageParcel reply;
MessageOption option;
auto result = primaryStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, INVALID_FD);
GTEST_LOG_(INFO) << "OnRemoteRequest_0100 end";
}
/**
* @tc.number: OnRemoteRequest_0200
* @tc.name: OnRemoteRequest
* @tc.desc: Verify that function OnRemoteRequest
*/
HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, OnRemoteRequest_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "OnRemoteRequest_0200 start";
uint32_t code = 1;
MessageParcel data;
MessageParcel reply;
MessageOption option;
std::u16string name = u"ohos.abilityshell.ReverseContinuationSchedulerMaster";
data.WriteInterfaceToken(name);
auto result = primaryStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
GTEST_LOG_(INFO) << "OnRemoteRequest_0200 end";
}
/**
* @tc.number: OnRemoteRequest_0300
* @tc.name: OnRemoteRequest
* @tc.desc: Verify that function OnRemoteRequest
*/
HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, OnRemoteRequest_0300, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "OnRemoteRequest_0300 start";
uint32_t code = 3;
MessageParcel data;
MessageParcel reply;
MessageOption option;
std::u16string name = u"ohos.abilityshell.ReverseContinuationSchedulerMaster";
data.WriteInterfaceToken(name);
primaryStub_->requestFuncMap_[3] = nullptr;
auto result = primaryStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, IPC_STUB_UNKNOW_TRANS_ERR);
GTEST_LOG_(INFO) << "OnRemoteRequest_0300 end";
}
/**
* @tc.number: NotifyReplicaTerminatedInner_0100
* @tc.name: NotifyReplicaTerminatedInner
* @tc.desc: Verify that function NotifyReplicaTerminatedInner
*/
HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, NotifyReplicaTerminatedInner_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "NotifyReplicaTerminatedInner_0100 start";
MessageParcel data;
MessageParcel reply;
auto result = primaryStub_->NotifyReplicaTerminatedInner(data, reply);
EXPECT_EQ(result, ERR_NONE);
GTEST_LOG_(INFO) << "NotifyReplicaTerminatedInner_0100 end";
}
/**
* @tc.number: ContinuationBackInner_0100
* @tc.name: ContinuationBackInner
* @tc.desc: Verify that function ContinuationBackInner
*/
HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, ContinuationBackInner_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "ContinuationBackInner_0100 start";
MessageParcel data;
MessageParcel reply;
data.WriteInt32(0);
auto result = primaryStub_->ContinuationBackInner(data, reply);
EXPECT_EQ(result, -1);
GTEST_LOG_(INFO) << "ContinuationBackInner_0100 end";
}
/**
* @tc.number: ContinuationBackInner_0200
* @tc.name: ContinuationBackInner
* @tc.desc: Verify that function ContinuationBackInner
*/
HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, ContinuationBackInner_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "ContinuationBackInner_0200 start";
MessageParcel data;
MessageParcel reply;
auto result = primaryStub_->ContinuationBackInner(data, reply);
EXPECT_EQ(result, -1);
GTEST_LOG_(INFO) << "ContinuationBackInner_0200 end";
}
/**
* @tc.number: ContinuationBackInner_0300
* @tc.name: ContinuationBackInner
* @tc.desc: Verify that function ContinuationBackInner
*/
HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, ContinuationBackInner_0300, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "ContinuationBackInner_0300 start";
MessageParcel data;
MessageParcel reply;
data.WriteInt32(1);
auto result = primaryStub_->ContinuationBackInner(data, reply);
EXPECT_EQ(result, -1);
GTEST_LOG_(INFO) << "ContinuationBackInner_0300 end";
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -86,6 +86,10 @@ ohos_unittest("context_deal_interface_test") {
ohos_unittest("application_test") {
module_out_path = module_output_path
include_dirs =
[ "//base/global/resource_management/frameworks/resmgr/include" ]
sources = [
"${ability_runtime_native_path}/appkit/app/app_context.cpp",
"${ability_runtime_native_path}/appkit/app/app_loader.cpp",
@@ -370,6 +374,39 @@ ohos_unittest("ability_stage_test") {
]
}
ohos_unittest("form_extension_context_test") {
module_out_path = module_output_path
sources = [
"${ability_runtime_native_path}/appkit/app/app_loader.cpp",
"${ability_runtime_native_path}/appkit/app/ohos_application.cpp",
"form_extension_context_test.cpp",
]
configs = [ ":module_context_config" ]
deps = [
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:form_extension",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_native",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:configuration",
"ability_base:want",
"ability_runtime:runtime",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"form_fwk:fmskit_native",
"form_fwk:form_manager",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
]
}
###############################################################################
group("unittest") {
@@ -383,6 +420,7 @@ group("unittest") {
":application_test",
":context_container_test",
":context_deal_test",
":form_extension_context_test",
":mix_stack_dumper_test",
":watchdog_test",
]
@@ -1259,5 +1259,758 @@ HWTEST_F(ContextContainerTest, PrintDrawnCompleted_0200, Function | MediumTest |
context_->AttachBaseContext(nullptr);
EXPECT_FALSE(context_->PrintDrawnCompleted());
}
/**
* @tc.number: AppExecFwk_ContextContainer_DeleteFile_0100
* @tc.name: Delete File
* @tc.desc: Test Delete File When baseContext is not null,
* and verify whether the return value of DeleteFile is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_DeleteFile_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_TRUE(context_->DeleteFile("test"));
}
/**
* @tc.number: AppExecFwk_ContextContainer_DeleteFile_0200
* @tc.name: Delete File
* @tc.desc: Test Delete File When baseContext is null.
* and verify whether the return value of DeleteFile is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_DeleteFile_0200, Function | MediumTest | Level3)
{
EXPECT_FALSE(context_->DeleteFile("test"));
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetExternalCacheDir_0100
* @tc.name: Get External Cache Dir
* @tc.desc: Test Get External Cache Dir When baseContext is not null,
* and verify whether the return value of Get External Cache Dir is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetExternalCacheDir_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->GetExternalCacheDir(), "");
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetExternalCacheDir_0200
* @tc.name: Get External Cache Dir
* @tc.desc: Test Get External Cache Dir When baseContext is null.
* and verify whether the return value of Get External Cache Dir is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetExternalCacheDir_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->GetExternalCacheDir(), "");
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetExternalFilesDir_0100
* @tc.name: Get External Files Dir
* @tc.desc: Test Get External Files Dir When baseContext is not null,
* and verify whether the return value of Get External Files Dir is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetExternalFilesDir_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
std::string type = "type";
EXPECT_EQ(context_->GetExternalFilesDir(type), "");
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetExternalFilesDir_0200
* @tc.name: Get External FilesDir
* @tc.desc: Test Get External Files Dir When baseContext is null.
* and verify whether the return value of Get External Files Dir is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetExternalFilesDir_0200, Function | MediumTest | Level3)
{
std::string type = "type";
EXPECT_EQ(context_->GetExternalFilesDir(type), "");
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetNoBackupFilesDir_0100
* @tc.name: Get No Backup Files Dir
* @tc.desc: Test Get No Backup Files Dir When baseContext is not null,
* and verify whether the return value of Get No Backup Files Dir is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetNoBackupFilesDir_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->GetNoBackupFilesDir(), "/data/storage/el2/base/data/no_backup");
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetNoBackupFilesDir_0200
* @tc.name: Get No Backup FilesDir
* @tc.desc: Test Get No Backup Files Dir When baseContext is null.
* and verify whether the return value of Get No Backup Files Dir is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetNoBackupFilesDir_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->GetNoBackupFilesDir(), "");
}
/**
* @tc.number: AppExecFwk_ContextContainer_VerifySelfPermission_0100
* @tc.name: Verify Self Permission
* @tc.desc: Test Verify Self Permission When baseContext is not null,
* and verify whether the return value of Verify Self Permission is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_VerifySelfPermission_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->VerifySelfPermission("permission"), AppExecFwk::Constants::PERMISSION_GRANTED);
}
/**
* @tc.number: AppExecFwk_ContextContainer_VerifySelfPermission_0200
* @tc.name: Verify Self Permission
* @tc.desc: Test Verify Self Permission When baseContext is null.
* and verify whether the return value of Verify Self Permission is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_VerifySelfPermission_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->VerifySelfPermission("permission"), AppExecFwk::Constants::PERMISSION_NOT_GRANTED);
}
/**
* @tc.number: AppExecFwk_ContextContainer_UnauthUriPermission_0100
* @tc.name: Unauth Uri Permission
* @tc.desc: Test Unauth Uri Permission When baseContext is not null
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_UnauthUriPermission_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
Uri urivalue("");
context_->UnauthUriPermission("permission", urivalue, 0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_UnauthUriPermission_0200
* @tc.name: Unauth Uri Permission
* @tc.desc: TestUnauth Uri Permission When baseContext is null.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_UnauthUriPermission_0200, Function | MediumTest | Level3)
{
Uri urivalue("");
context_->UnauthUriPermission("permission", urivalue, 0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetDistributedDir_0100
* @tc.name: Get Distributed Dir
* @tc.desc: Test Get Distributed Dir When baseContext is not null,
* and verify whether the return value of Get Distributed Dir is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetDistributedDir_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->GetDistributedDir(), "/data/storage/el2/distributedfiles");
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetDistributedDir_0200
* @tc.name: Get Distributed Dir
* @tc.desc: Test Get Distributed Dir When baseContext is null.
* and verify whether the return value of Get Distributed Dir is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetDistributedDir_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->GetDistributedDir(), "");
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetAbilityPackageContext_0100
* @tc.name: Get Ability Package Context
* @tc.desc: Test Get Ability Package Context When baseContext is not null,
* and verify whether the return value of Get Ability Package Context is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetAbilityPackageContext_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->GetAbilityPackageContext(), nullptr);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetAbilityPackageContext_0200
* @tc.name: Get Ability Package Context
* @tc.desc: Test Get Ability Package Context When baseContext is null.
* and verify whether the return value of Get Ability Package Context is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetAbilityPackageContext_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->GetAbilityPackageContext(), nullptr);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetHapModuleInfo_0100
* @tc.name: Get Hap Module Info
* @tc.desc: Test Get Hap Module Info When baseContext is not null,
* and verify whether the return value of Get Hap Module Info is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetHapModuleInfo_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
contextDeal_->hapModuleInfoLocal_ = std::make_shared<HapModuleInfo>();
context_->AttachBaseContext(contextDeal_);
EXPECT_NE(context_->GetHapModuleInfo(), nullptr);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetHapModuleInfo_0200
* @tc.name: Get Hap Module Info
* @tc.desc: Test Get Hap Module Info When baseContext is null.
* and verify whether the return value of Get Hap Module Info is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetHapModuleInfo_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->GetHapModuleInfo(), nullptr);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetCaller_0100
* @tc.name: Get Caller
* @tc.desc: Test Get Caller When baseContext is not null,
* and verify whether the return value of Get Caller is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetCaller_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
contextDeal_->SerUriString("test");
context_->AttachBaseContext(contextDeal_);
Uri uri("test");
EXPECT_EQ(context_->GetCaller(), uri);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetCaller_0200
* @tc.name: Request Permissions From User
* @tc.desc: Test Get Caller When baseContext is null.
* and verify whether the return value of Get Caller is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetCaller_0200, Function | MediumTest | Level3)
{
Uri uri("");
EXPECT_EQ(context_->GetCaller(), uri);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetString_0100
* @tc.name: Get String
* @tc.desc: Test Get String When baseContext is not null,
* and verify whether the return value of Get String is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetString_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->GetString(0), "");
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetString_0200
* @tc.name: Get String
* @tc.desc: Test Get String When baseContext is null.
* and verify whether the return value of Get String is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetString_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->GetString(0), "");
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetStringArray_0100
* @tc.name: Get String Array
* @tc.desc: Test Get String Array When baseContext is not null,
* and verify whether the return value of Get String Array is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetStringArray_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
std::vector<std::string> ret = context_->GetStringArray(0);
EXPECT_EQ(ret.size(), 0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetStringArray_0200
* @tc.name: Get String Array
* @tc.desc: Test Get String Array When baseContext is null.
* and verify whether the return value of Get String Array is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetStringArray_0200, Function | MediumTest | Level3)
{
std::vector<std::string> ret = context_->GetStringArray(0);
EXPECT_EQ(ret.size(), 0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetIntArray_0100
* @tc.name: Get Int Array
* @tc.desc: Test Get Int Array When baseContext is not null,
* and verify whether the return value of Get Int Array is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetIntArray_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
std::vector<int> ret = context_->GetIntArray(0);
EXPECT_EQ(ret.size(), 0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetIntArray_0200
* @tc.name: Get Int Array
* @tc.desc: Test Get Int Array When baseContext is null.
* and verify whether the return value of Get Int Array is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetIntArray_0200, Function | MediumTest | Level3)
{
std::vector<int> ret = context_->GetIntArray(0);
EXPECT_EQ(ret.size(), 0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetTheme_0100
* @tc.name: Get Theme
* @tc.desc: Test Get Theme When baseContext is not null,
* and verify whether the return value of Get Theme is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetTheme_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
std::map<std::string, std::string> ret = context_->GetTheme();
EXPECT_EQ(ret.size(), 0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetTheme_0200
* @tc.name: Get Theme
* @tc.desc: Test Get Theme When baseContext is null.
* and verify whether the return value of Get Theme is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetTheme_0200, Function | MediumTest | Level3)
{
std::map<std::string, std::string> ret = context_->GetTheme();
EXPECT_EQ(ret.size(), 0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_SetTheme_0100
* @tc.name: Set Theme
* @tc.desc: Test Set Theme When baseContext is not null,
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_SetTheme_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
context_->SetTheme(0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_SetTheme_0200
* @tc.name: Set Theme
* @tc.desc: Test Set Theme When baseContext is null.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_SetTheme_0200, Function | MediumTest | Level3)
{
context_->SetTheme(0);
}
/**
* @tc.number: AppExecFwk_ContextContainerGetPattern_0100
* @tc.name: Get Pattern
* @tc.desc: Test Get Pattern When baseContext is not null,
* and verify whether the return value of Get Pattern is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetPattern_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
std::map<std::string, std::string> ret = context_->GetPattern();
EXPECT_EQ(ret.size(), 0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetPattern_0200
* @tc.name: Get Pattern
* @tc.desc: Test Get Pattern When baseContext is null.
* and verify whether the return value of Get Pattern is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetPattern_0200, Function | MediumTest | Level3)
{
std::map<std::string, std::string> ret = context_->GetPattern();
EXPECT_EQ(ret.size(), 0);
}
/**
* @tc.number: AppExecFwk_ContextContainerSetPattern_0100
* @tc.name: Set Pattern
* @tc.desc: Test Get Pattern When baseContext is not null,
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_SetPattern_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
context_->SetPattern(0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_SetPattern_0200
* @tc.name: Set Pattern
* @tc.desc: Test Set Pattern When baseContext is null.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_SetPattern_0200, Function | MediumTest | Level3)
{
context_->SetPattern(0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetColor_0100
* @tc.name: Get Color
* @tc.desc: Test Get Color When baseContext is not null,
* and verify whether the return value of Get Color is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetColor_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->GetColor(0), -1);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetColor_0200
* @tc.name: Get Color
* @tc.desc: Test Get Color When baseContext is null.
* and verify whether the return value of Get Color is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetColor_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->GetColor(0), -1);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetThemeId_0100
* @tc.name: Get Theme Id
* @tc.desc: Test Get Theme Id When baseContext is not null,
* and verify whether the return value of Get Theme Id is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetThemeId_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->GetThemeId(), -1);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetThemeId_0200
* @tc.name: Get Theme Id
* @tc.desc: Test Get Theme Id When baseContext is null.
* and verify whether the return value of Get Theme Id is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetThemeId_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->GetThemeId(), -1);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetDisplayOrientation_0100
* @tc.name: Get Display Orientation
* @tc.desc: Test Get Display Orientation When baseContext is not null,
* and verify whether the return value of Get Display Orientation is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetDisplayOrientation_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
contextDeal_-> abilityInfo_ = std::make_shared<AbilityInfo>();
contextDeal_->abilityInfo_->orientation = DisplayOrientation::LANDSCAPE;
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->GetDisplayOrientation(), 1);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetDisplayOrientation_0200
* @tc.name: Get Display Orientation
* @tc.desc: Test Get Display Orientation When baseContext is null.
* and verify whether the return value of Get Display Orientation is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetDisplayOrientation_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->GetDisplayOrientation(), 0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetPreferencesDir_0100
* @tc.name: Get Preferences Dir
* @tc.desc: Test Get Preferences Dir When baseContext is not null,
* and verify whether the return value of Get Preferences Dir is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetPreferencesDire_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->GetPreferencesDir(), "/data/storage/el2/base/preferences");
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetPreferencesDir_0200
* @tc.name: Get Preferences Dir
* @tc.desc: Test Get Preferences Dir When baseContext is null.
* and verify whether the return value of Get Preferences Dir is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetPreferencesDir_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->GetPreferencesDir(), "");
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetColorMode_0100
* @tc.name: Get Color Mode
* @tc.desc: Test Get Color Mode When baseContext is not null,
* and verify whether the return value of Get Color Mode is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetColorMode_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
contextDeal_->hapModuleInfoLocal_ = std::make_shared<HapModuleInfo>();
context_->AttachBaseContext(contextDeal_);
context_->SetColorMode(static_cast<int>(ModuleColorMode::DARK));
EXPECT_EQ(context_->GetColorMode(), static_cast<int>(ModuleColorMode::DARK));
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetColorMode_0200
* @tc.name: Get Color Mode
* @tc.desc: Test Get Color Mode When baseContext is null.
* and verify whether the return value of Get Color Mode is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetColorMode_0200, Function | MediumTest | Level3)
{
context_->SetColorMode(-1);
EXPECT_EQ(context_->GetColorMode(), -1);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetMissionId_0100
* @tc.name: Get Mission Id
* @tc.desc: Test Get Mission Id When baseContext is not null,
* and verify whether the return value of Get Mission Id is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetMissionId_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
AAFwk::LifeCycleStateInfo lifeCycleStateInfo;
lifeCycleStateInfo.missionId = 0;
contextDeal_->SetLifeCycleStateInfo(lifeCycleStateInfo);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->GetMissionId(), 0);
}
/**
* @tc.number: AppExecFwk_ContextContainer_GetMissionId_0200
* @tc.name: Get Mission Id
* @tc.desc: Test Get Mission Id When baseContext is null.
* and verify whether the return value of Get Mission Id is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetMissionId_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->GetMissionId(), -1);
}
/**
* @tc.number: AppExecFwk_ContextContainer_IsUpdatingConfigurations_0100
* @tc.name: Is Updating Configurations
* @tc.desc: Test Is Updating Configurations When baseContext is not null,
* and verify whether the return value of Is Updating Configurations is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_IsUpdatingConfigurations_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->IsUpdatingConfigurations(), false);
}
/**
* @tc.number: AppExecFwk_ContextContainer_IsUpdatingConfigurations_0200
* @tc.name: Is Updating Configurations
* @tc.desc: Test Is Updating Configurations When baseContext is null.
* and verify whether the return value of Is Updating Configurations is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_IsUpdatingConfigurations_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->IsUpdatingConfigurations(), false);
}
/**
* @tc.number: AppExecFwk_ContextContainer_PrintDrawnCompleted_0100
* @tc.name: Print Drawn Completed
* @tc.desc: Test Print Drawn Completed When baseContext is not null,
* and verify whether the return value of Print Drawn Completed is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_PrintDrawnCompleted_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->PrintDrawnCompleted(), false);
}
/**
* @tc.number: AppExecFwk_ContextContainer_PrintDrawnCompleted_0200
* @tc.name: Print Drawn Completed
* @tc.desc: Test Print Drawn Completed When baseContext is null.
* and verify whether the return value of Print Drawn Completed is correct.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_PrintDrawnCompleted_0200, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->PrintDrawnCompleted(), false);
}
/**
* @tc.number: AppExecFwk_ContextContainer_CreateBundleContext_0100
* @tc.name: Create Bundle Context
* @tc.desc: Test Create Bundle Context return is not null.
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_CreateBundleContext_0100, Function | MediumTest | Level1)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
std::shared_ptr<ApplicationInfo> info = std::make_shared<ApplicationInfo>();
std::string bundleName = "BundleName";
info->bundleName = bundleName;
contextDeal_->SetContext(context);
contextDeal_->SetApplicationInfo(info);
contextDeal_->SetApplicationContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_NE(context_->CreateBundleContext("BundleName", 0, 0), nullptr);
}
/**
* @tc.number: AppExecFwk_ContextContainer_CreateBundleContext_0200
* @tc.name: Create Bundle Context
* @tc.desc: Test Create Bundle Context return is null because bundle info is error account id is not DEFAULT_ACCOUNT_ID
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_CreateBundleContext_0200, Function | MediumTest | Level3)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->CreateBundleContext("bundlename", 0, 0), nullptr);
}
/**
* @tc.number: AppExecFwk_ContextContainer_CreateBundleContext_0300
* @tc.name: Create Bundle Context
* @tc.desc: Test Create Bundle Context return is null because bundle info is error account id is DEFAULT_ACCOUNT_ID
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_CreateBundleContext_0300, Function | MediumTest | Level3)
{
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<Context> context(ability);
contextDeal_->SetContext(context);
context_->AttachBaseContext(contextDeal_);
EXPECT_EQ(context_->CreateBundleContext("bundlename", 0, DEFAULT_ACCOUNT_ID), nullptr);
}
/**
* @tc.number: AppExecFwk_ContextContainer_CreateBundleContext_0400
* @tc.name: Create Bundle Context
* @tc.desc: Test Create Bundle Context return is null because bundle name is empty
*/
HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_CreateBundleContext_0400, Function | MediumTest | Level3)
{
EXPECT_EQ(context_->CreateBundleContext("", 0, 0), nullptr);
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -29,6 +29,7 @@
#include "iremote_object.h"
#include "mock_ability_token.h"
#include "mock_bundle_manager.h"
#include "mock_resource_manager.h"
#include "system_ability_definition.h"
#include "sys_mgr_client.h"
@@ -945,5 +946,125 @@ HWTEST_F(ContextImplTest, GetDeviceType_0100, TestSize.Level1)
HILOG_INFO("%{public}s end.", __func__);
}
/**
* @tc.number: GetCacheDir_0100
* @tc.name: GetCacheDir_0100
* @tc.desc: Get cache dir test.
*/
HWTEST_F(ContextImplTest, GetCacheDir_0100, TestSize.Level1)
{
HILOG_INFO("%{public}s start.", __func__);
auto contextImpl = std::make_shared<AbilityRuntime::ContextImpl>();
EXPECT_NE(contextImpl, nullptr);
auto cacheDir = contextImpl->GetCacheDir();
EXPECT_EQ(cacheDir, "/data/storage/el2/base/cache");
HILOG_INFO("%{public}s end.", __func__);
}
/**
* @tc.number: GetConfiguration_0100
* @tc.name: GetConfiguration_0100
* @tc.desc: Get configuration test.
*/
HWTEST_F(ContextImplTest, GetConfiguration_0100, TestSize.Level1)
{
HILOG_INFO("%{public}s start.", __func__);
auto contextImpl = std::make_shared<AbilityRuntime::ContextImpl>();
EXPECT_NE(contextImpl, nullptr);
auto configRet = contextImpl->GetConfiguration();
EXPECT_EQ(configRet, nullptr);
// construct configuration
auto config = std::make_shared<AppExecFwk::Configuration>();
EXPECT_NE(config, nullptr);
config->AddItem(AAFwk::GlobalConfigurationKey::DEVICE_TYPE, "phone");
contextImpl->SetConfiguration(config);
configRet = contextImpl->GetConfiguration();
EXPECT_NE(configRet, nullptr);
HILOG_INFO("%{public}s end.", __func__);
}
/**
* @tc.number: IsCreateBySystemApp_0100
* @tc.name: IsCreateBySystemApp_0100
* @tc.desc: Is create by system app test.
*/
HWTEST_F(ContextImplTest, IsCreateBySystemApp_0100, TestSize.Level1)
{
HILOG_INFO("%{public}s start.", __func__);
auto contextImpl = std::make_shared<AbilityRuntime::ContextImpl>();
EXPECT_NE(contextImpl, nullptr);
auto isSystemApp = contextImpl->IsCreateBySystemApp();
EXPECT_EQ(isSystemApp, false);
contextImpl->flags_ = CONTEXT_CREATE_BY_SYSTEM_APP;
isSystemApp = contextImpl->IsCreateBySystemApp();
EXPECT_EQ(isSystemApp, true);
HILOG_INFO("%{public}s end.", __func__);
}
/**
* @tc.number: SetResourceManager_0100
* @tc.name: SetResourceManager_0100
* @tc.desc: Set Resource Manager test.
*/
HWTEST_F(ContextImplTest, SetResourceManager_0100, TestSize.Level1)
{
HILOG_INFO("%{public}s start.", __func__);
auto contextImpl = std::make_shared<AbilityRuntime::ContextImpl>();
EXPECT_NE(contextImpl, nullptr);
EXPECT_EQ(contextImpl->GetResourceManager(), nullptr);
auto resourceManager = std::make_shared<Global::Resource::MockResourceManager>();
EXPECT_NE(resourceManager, nullptr);
contextImpl->SetResourceManager(resourceManager);
EXPECT_NE(contextImpl->GetResourceManager(), nullptr);
HILOG_INFO("%{public}s end.", __func__);
}
/**
* @tc.number: GetResourceManager_0100
* @tc.name: GetResourceManager_0100
* @tc.desc: Get Resource Manager test.
*/
HWTEST_F(ContextImplTest, GetResourceManager_0100, TestSize.Level1)
{
HILOG_INFO("%{public}s start.", __func__);
auto contextImpl = std::make_shared<AbilityRuntime::ContextImpl>();
EXPECT_NE(contextImpl, nullptr);
EXPECT_EQ(contextImpl->GetResourceManager(), nullptr);
auto parentContext = std::make_shared<AbilityRuntime::ContextImpl>();
EXPECT_NE(parentContext, nullptr);
contextImpl->SetParentContext(parentContext);
auto resourceManager = std::make_shared<Global::Resource::MockResourceManager>();
EXPECT_NE(resourceManager, nullptr);
parentContext->SetResourceManager(resourceManager);
EXPECT_NE(contextImpl->GetResourceManager(), nullptr);
HILOG_INFO("%{public}s end.", __func__);
}
/**
* @tc.number: GetBundleManager_0100
* @tc.name: GetBundleManager_0100
* @tc.desc: Get Bundle Manager test.
*/
HWTEST_F(ContextImplTest, GetBundleManager_0100, TestSize.Level1)
{
HILOG_INFO("%{public}s start.", __func__);
auto contextImpl = std::make_shared<AbilityRuntime::ContextImpl>();
EXPECT_NE(contextImpl, nullptr);
EXPECT_NE(contextImpl->GetBundleManager(), nullptr);
HILOG_INFO("%{public}s end.", __func__);
}
} // namespace AppExecFwk
}
@@ -0,0 +1,193 @@
/*
* Copyright (c) 2022 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_FORM_MOCK_EXTENSION_H
#define MOCK_OHOS_ABILITY_FORM_MOCK_EXTENSION_H
#include "form_mgr.h"
#include "form_mgr_interface.h"
#include <gmock/gmock.h>
#include <iremote_object.h>
#include <iremote_stub.h>
namespace OHOS {
namespace AppExecFwk {
using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::AppExecFwk;
constexpr int32_t STARTABILITYVALUE = 0;
class MockIFormMgr : public IRemoteStub<OHOS::AppExecFwk::IFormMgr> {
public:
MockIFormMgr() = default;
~MockIFormMgr() = default;
int32_t StartAbility(const Want &want, const sptr<IRemoteObject> &callerToken) override
{
return STARTABILITYVALUE;
}
int AddForm(
const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken, FormJsInfo &formInfo) override
{
return 0;
}
int DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken) override
{
return 0;
}
int ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache) override
{
return 0;
}
int UpdateForm(const int64_t formId, const FormProviderData &formProviderData) override
{
return 0;
}
int SetNextRefreshTime(const int64_t formId, const int64_t nextTime) override
{
return 0;
}
ErrCode RequestPublishForm(Want &want, bool withFormBindingData, std::unique_ptr<FormProviderData> &formBindingData,
int64_t &formId) override
{
return 0;
}
int LifecycleUpdate(
const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken, bool updateType) override
{
return 0;
}
int RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want) override
{
return 0;
}
int NotifyWhetherVisibleForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
const int32_t formVisibleType) override
{
return 0;
}
int CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken) override
{
return 0;
}
int DumpStorageFormInfos(std::string &formInfos) override
{
return 0;
}
int DumpFormInfoByBundleName(const std::string &bundleName, std::string &formInfos) override
{
return 0;
}
int DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo) override
{
return 0;
}
int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) override
{
return 0;
}
int MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken) override
{
return 0;
}
int RouterEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken) override
{
return 0;
}
int DeleteInvalidForms(
const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken, int32_t &numFormsDeleted) override
{
return 0;
}
int AcquireFormState(const Want &want, const sptr<IRemoteObject> &callerToken, FormStateInfo &stateInfo) override
{
return 0;
}
int NotifyFormsVisible(
const std::vector<int64_t> &formIds, bool isVisible, const sptr<IRemoteObject> &callerToken) override
{
return 0;
}
int NotifyFormsPrivacyProtected(
const std::vector<int64_t> &formIds, bool isProtected, const sptr<IRemoteObject> &callerToken) override
{
return 0;
}
int NotifyFormsEnableUpdate(
const std::vector<int64_t> &formIds, bool isEnableUpdate, const sptr<IRemoteObject> &callerToken) override
{
return 0;
}
int GetAllFormsInfo(std::vector<FormInfo> &formInfos) override
{
return 0;
}
int GetFormsInfoByApp(std::string &bundleName, std::vector<FormInfo> &formInfos) override
{
return 0;
}
int GetFormsInfoByModule(
std::string &bundleName, std::string &moduleName, std::vector<FormInfo> &formInfos) override
{
return 0;
}
int32_t GetFormsInfo(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos) override
{
return 0;
}
bool IsRequestPublishFormSupported() override
{
return 0;
}
int32_t ShareForm(int64_t formId, const std::string &deviceId, const sptr<IRemoteObject> &callerToken,
int64_t requestCode) override
{
return 0;
}
int32_t RecvFormShareInfoFromRemote(const FormShareInfo &info) override
{
return 0;
}
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // MOCK_OHOS_ABILITY_FORM_MOCK_EXTENSION_H
@@ -0,0 +1,246 @@
/*
* Copyright (c) 2022 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 <gtest/gtest.h>
#define private public
#include "form_extension_context.h"
#undef private
#include "form_extension_context_mock_test.h"
#include "form_mgr_errors.h"
namespace OHOS {
namespace AppExecFwk {
using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::AppExecFwk;
class FormExtensionContextTest : public testing::Test {
public:
std::shared_ptr<AbilityRuntime::FormExtensionContext> formextension_ = nullptr;
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void FormExtensionContextTest::SetUpTestCase(void)
{}
void FormExtensionContextTest::TearDownTestCase(void)
{}
void FormExtensionContextTest::SetUp(void)
{
formextension_ = std::make_shared<AbilityRuntime::FormExtensionContext>();
}
void FormExtensionContextTest::TearDown(void)
{}
/**
* @tc.number: formExtensionContext_UpdateForm_0100
* @tc.name: UpdateForm
* @tc.desc: Verify whether UpdateForm is called normally (formID is less than 0).
*/
HWTEST_F(FormExtensionContextTest, formExtensionContext_UpdateForm_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0100 start";
FormProviderData formProviderData;
std::string inputTestJsonStr = "{"
" \"deviceType\": \"PHONE\", "
" \"fontScale\": 1.0 , "
" \"fontScalse\": 1.0 "
"}";
formProviderData.SetDataString(inputTestJsonStr);
int32_t formId = -1;
auto result = formextension_->UpdateForm(formId, formProviderData);
EXPECT_EQ(ERR_APPEXECFWK_FORM_INVALID_PARAM, result);
GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0100 end";
}
/**
* @tc.number: formExtensionContext_UpdateForm_0200
* @tc.name: UpdateForm
* @tc.desc: Verify whether UpdateForm is called normally (the formProviderData parameter is not set).
*/
HWTEST_F(FormExtensionContextTest, formExtensionContext_UpdateForm_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0200 start";
FormProviderData formProviderData;
int32_t formId = 200;
auto result = formextension_->UpdateForm(formId, formProviderData);
EXPECT_EQ(ERR_APPEXECFWK_FORM_INVALID_PARAM, result);
GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0200 end";
}
/**
* @tc.number: formExtensionContext_UpdateForm_0300
* @tc.name: UpdateForm
* @tc.desc: Verify that the setting status is IN_ RECOVERING returned result execution exception.
*/
HWTEST_F(FormExtensionContextTest, formExtensionContext_UpdateForm_0300, TestSize.Level1)
{
GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0300 start";
FormMgr::SetRecoverStatus(AppExecFwk::Constants::IN_RECOVERING);
FormProviderData formProviderData;
std::string inputTestJsonStr = "{"
" \"deviceType\": \"PHONE\", "
" \"fontScale\": 1.0 , "
" \"fontScalse\": 1.0 "
"}";
formProviderData.SetDataString(inputTestJsonStr);
int32_t formId = 200;
auto result = formextension_->UpdateForm(formId, formProviderData);
EXPECT_EQ(ERR_APPEXECFWK_FORM_IN_RECOVER, result);
FormMgr::SetRecoverStatus(Constants::NOT_IN_RECOVERY);
GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0300 end";
}
/**
* @tc.number: formExtensionContext_UpdateForm_0400
* @tc.name: UpdateForm
* @tc.desc: Verify whether calling UpdateForm normally will trigger a mock (parameters are normal).
*/
HWTEST_F(FormExtensionContextTest, formExtensionContext_UpdateForm_0400, TestSize.Level1)
{
GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0400 start";
FormProviderData formProviderData;
std::string inputTestJsonStr = "{"
" \"deviceType\": \"PHONE\", "
" \"fontScale\": 1.0 , "
" \"fontScalse\": 1.0 "
"}";
formProviderData.SetDataString(inputTestJsonStr);
int32_t formId = 200;
sptr<MockIFormMgr> mockIFormMgr = new (std::nothrow) MockIFormMgr();
OHOS::AppExecFwk::FormMgr::GetInstance().SetFormMgrService(mockIFormMgr);
auto result = formextension_->UpdateForm(formId, formProviderData);
EXPECT_EQ(ERR_OK, result);
OHOS::AppExecFwk::FormMgr::GetInstance().SetFormMgrService(nullptr);
GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0400 end";
}
/**
* @tc.number: formExtensionContext_GetAbilityInfo_0100
* @tc.name: SetAbilityInfo/GetAbilityInfo
* @tc.desc: Verify whether the SetAbilityInfo setting content and GetAbilityInformation get.
*/
HWTEST_F(FormExtensionContextTest, formExtensionContext_GetAbilityInfo_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfo_0100 start";
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
EXPECT_EQ(formextension_->GetAbilityInfo(), nullptr);
abilityInfo->name = "Ability";
formextension_->SetAbilityInfo(abilityInfo);
abilityInfo = formextension_->GetAbilityInfo();
EXPECT_STREQ(abilityInfo->name.c_str(), "Ability");
GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfo_0100 end";
}
/**
* @tc.number: formExtensionContext_GetAbilityInfo_0200
* @tc.name: SetAbilityInfo/GetAbilityInfo
* @tc.desc: Verify that SetAbilityInfo is set to null and GetAbilityInformation gets.
*/
HWTEST_F(FormExtensionContextTest, formExtensionContext_GetAbilityInfo_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfo_0200 start";
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
EXPECT_EQ(formextension_->GetAbilityInfo(), nullptr);
abilityInfo->name = "";
formextension_->SetAbilityInfo(abilityInfo);
abilityInfo = formextension_->GetAbilityInfo();
EXPECT_STREQ(abilityInfo->name.c_str(), "");
GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfo_0200 end";
}
/**
* @tc.number: formExtensionContext_SetAbilityInfo_0100
* @tc.name: SetAbilityInfo
* @tc.desc: Verify that the SetAbilityInfo parameter is null and exit without exception.
*/
HWTEST_F(FormExtensionContextTest, formExtensionContext_SetAbilityInfo_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "formExtensionContext_SetAbilityInfo_0100 start";
std::shared_ptr<AbilityInfo> abilityInfo = nullptr;
formextension_->SetAbilityInfo(abilityInfo);
EXPECT_EQ(abilityInfo, nullptr);
GTEST_LOG_(INFO) << "formExtensionContext_SetAbilityInfo_0100 end";
}
/**
* @tc.number: formExtensionContext_StartAbility_0100
* @tc.name: StartAbility
* @tc.desc: Verify that StartAbility return is not equal to ERR_OK.
*/
HWTEST_F(FormExtensionContextTest, formExtensionContext_StartAbility_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "formExtensionContext_StartAbility_0100 start";
AAFwk::Want want;
ElementName element("device", "ohos.samples", "form_extension_context_test");
want.SetElement(element);
EXPECT_TRUE(formextension_->StartAbility(want) != ERR_OK);
GTEST_LOG_(INFO) << "formExtensionContext_StartAbility_0100 end";
}
/**
* @tc.number: formExtensionContext_StartAbility_0200
* @tc.name: StartAbility
* @tc.desc: Verify that StartAbility returns equal to ERR_OK.
*/
HWTEST_F(FormExtensionContextTest, formExtensionContext_StartAbility_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "formExtensionContext_StartAbility_0200 start";
AAFwk::Want want;
sptr<MockIFormMgr> mockIFormMgr = new (std::nothrow) MockIFormMgr();
OHOS::AppExecFwk::FormMgr::GetInstance().SetFormMgrService(mockIFormMgr);
ElementName element("device", "ohos.samples", "form_extension_context_test");
want.SetElement(element);
EXPECT_TRUE(formextension_->StartAbility(want) == ERR_OK);
OHOS::AppExecFwk::FormMgr::GetInstance().SetFormMgrService(nullptr);
GTEST_LOG_(INFO) << "formExtensionContext_StartAbility_0200 end";
}
/**
* @tc.number: formExtensionContext_GetAbilityInfoType_0100
* @tc.name: GetAbilityInfoType
* @tc.desc: Verify whether GetAbilityInfoType gets the unset information.
*/
HWTEST_F(FormExtensionContextTest, formExtensionContext_GetAbilityInfoType_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfoType_0100 start";
EXPECT_EQ(OHOS::AppExecFwk::AbilityType::UNKNOWN, formextension_->GetAbilityInfoType());
GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfoType_0100 end";
}
/**
* @tc.number: formExtensionContext_GetAbilityInfoType_0200
* @tc.name: GetAbilityInfoType
* @tc.desc: Verify whether the setting information GetAbilityInfoType gets.
*/
HWTEST_F(FormExtensionContextTest, formExtensionContext_GetAbilityInfoType_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfoType_0200 start";
EXPECT_EQ(OHOS::AppExecFwk::AbilityType::UNKNOWN, formextension_->GetAbilityInfoType());
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->type = OHOS::AppExecFwk::AbilityType::SERVICE;
formextension_->SetAbilityInfo(abilityInfo);
EXPECT_EQ(abilityInfo->type, formextension_->GetAbilityInfoType());
GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfoType_0200 end";
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -0,0 +1,305 @@
/*
* Copyright (c) 2022 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 "resource_manager.h"
namespace OHOS {
namespace Global {
namespace Resource {
class MockResourceManager : public ResourceManager {
public:
MockResourceManager *CreateMockResourceManager()
{
MockResourceManager *impl = new (std::nothrow) MockResourceManager;
return impl;
}
~MockResourceManager() {}
bool AddResource(const char *path)
{
return true;
}
bool AddResource(const std::string &path, const std::vector<std::string> &overlayPaths)
{
return true;
}
RState UpdateResConfig(ResConfig &resConfig)
{
return SUCCESS;
}
void GetResConfig(ResConfig &resConfig) {}
RState GetStringById(uint32_t id, std::string &outValue)
{
outValue = "ENTRY";
return SUCCESS;
}
RState GetStringByName(const char *name, std::string &outValue)
{
outValue = "bgmode_test";
return SUCCESS;
}
RState GetStringFormatById(std::string &outValue, uint32_t id, ...)
{
return SUCCESS;
}
RState GetStringFormatByName(std::string &outValue, const char *name, ...)
{
return SUCCESS;
}
RState GetStringArrayById(uint32_t id, std::vector<std::string> &outValue)
{
return SUCCESS;
}
RState GetStringArrayByName(const char *name, std::vector<std::string> &outValue)
{
return SUCCESS;
}
RState GetPatternById(uint32_t id, std::map<std::string, std::string> &outValue)
{
return SUCCESS;
}
RState GetPatternByName(const char *name, std::map<std::string, std::string> &outValue)
{
return SUCCESS;
}
RState GetPluralStringById(uint32_t id, int32_t quantity, std::string &outValue)
{
return SUCCESS;
}
RState GetPluralStringByName(const char *name, int32_t quantity, std::string &outValue)
{
return SUCCESS;
}
RState GetPluralStringByIdFormat(std::string &outValue, uint32_t id, int32_t quantity, ...)
{
return SUCCESS;
}
RState GetPluralStringByNameFormat(std::string &outValue, const char *name, int32_t quantity, ...)
{
return SUCCESS;
}
RState GetThemeById(uint32_t id, std::map<std::string, std::string> &outValue)
{
return SUCCESS;
}
RState GetThemeByName(const char *name, std::map<std::string, std::string> &outValue)
{
return SUCCESS;
}
RState GetBooleanById(uint32_t id, bool &outValue)
{
return SUCCESS;
}
RState GetBooleanByName(const char *name, bool &outValue)
{
return SUCCESS;
}
RState GetIntegerById(uint32_t id, int32_t &outValue)
{
return SUCCESS;
}
RState GetIntegerByName(const char *name, int32_t &outValue)
{
return SUCCESS;
}
RState GetFloatById(uint32_t id, float &outValue)
{
return SUCCESS;
}
RState GetFloatById(uint32_t id, float &outValue, std::string &unit)
{
return SUCCESS;
}
RState GetFloatByName(const char *name, float &outValue)
{
return SUCCESS;
}
RState GetFloatByName(const char *name, float &outValue, std::string &unit)
{
return SUCCESS;
}
RState GetIntArrayById(uint32_t id, std::vector<int32_t> &outValue)
{
return SUCCESS;
}
RState GetIntArrayByName(const char *name, std::vector<int32_t> &outValue)
{
return SUCCESS;
}
RState GetColorById(uint32_t id, uint32_t &outValue)
{
return SUCCESS;
}
RState GetColorByName(const char *name, uint32_t &outValue)
{
return SUCCESS;
}
RState GetProfileById(uint32_t id, std::string &outValue)
{
return SUCCESS;
}
RState GetProfileByName(const char *name, std::string &outValue)
{
return SUCCESS;
}
RState GetMediaById(uint32_t id, std::string &outValue)
{
return SUCCESS;
}
RState GetMediaById(uint32_t id, uint32_t density, std::string &outValue)
{
return SUCCESS;
}
RState GetMediaByName(const char *name, std::string &outValue)
{
return SUCCESS;
}
RState GetMediaByName(const char *name, uint32_t density, std::string &outValue)
{
return SUCCESS;
}
RState GetRawFilePathByName(const std::string &name, std::string &outValue)
{
return SUCCESS;
}
RState GetRawFileDescriptor(const std::string &name, RawFileDescriptor &descriptor)
{
return SUCCESS;
}
RState CloseRawFileDescriptor(const std::string &name)
{
return SUCCESS;
}
RState GetMediaBase64ByIdData(uint32_t id, uint32_t density, std::string &base64Data)
{
return SUCCESS;
}
RState GetMediaBase64ByNameData(const char *name, uint32_t density, std::string &base64Data)
{
return SUCCESS;
}
RState GetMediaDataById(uint32_t id, size_t &len, std::unique_ptr<uint8_t[]> &outValue)
{
return SUCCESS;
}
RState GetMediaDataByName(const char *name, size_t &len, std::unique_ptr<uint8_t[]> &outValue)
{
return SUCCESS;
}
RState GetMediaDataById(uint32_t id, uint32_t density, size_t &len,
std::unique_ptr<uint8_t[]> &outValue)
{
return SUCCESS;
}
RState GetMediaDataByName(const char *name, uint32_t density, size_t &len,
std::unique_ptr<uint8_t[]> &outValue)
{
return SUCCESS;
}
RState GetMediaBase64DataById(uint32_t id, std::string &outValue)
{
return SUCCESS;
}
RState GetMediaBase64DataByName(const char *name, std::string &outValue)
{
return SUCCESS;
}
RState GetMediaBase64DataById(uint32_t id, uint32_t density, std::string &outValue)
{
return SUCCESS;
}
RState GetMediaBase64DataByName(const char *name, uint32_t density, std::string &outValue)
{
return SUCCESS;
}
RState GetProfileDataById(uint32_t id, size_t &len, std::unique_ptr<uint8_t[]> &outValue)
{
return SUCCESS;
}
RState GetProfileDataByName(const char *name, size_t &len, std::unique_ptr<uint8_t[]> &outValue)
{
return SUCCESS;
}
RState GetRawFileFromHap(const std::string& rawFileName, size_t& len,
std::unique_ptr<uint8_t[]>& outValue)
{
return SUCCESS;
}
RState GetRawFileDescriptorFromHap(const std::string &rawFileName, RawFileDescriptor &descriptor)
{
return SUCCESS;
}
RState IsLoadHap(std::string& hapPath)
{
return SUCCESS;
}
};
} // namespace Resource
} // namespace Global
} // namespace OHOS
@@ -41,6 +41,7 @@ public:
std::shared_ptr<MockHandler> mockHandler_ = nullptr;
std::shared_ptr<EventRunner> runner_ = nullptr;
std::shared_ptr<Watchdog> watchdog_ = nullptr;
std::shared_ptr<MainHandlerDumper> mainHandlerDumper_;
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
@@ -60,32 +61,34 @@ void WatchdogTest::SetUp(void)
watchdog_ = std::make_shared<Watchdog>();
watchdog_->Init(mockHandler_);
mainHandlerDumper_ = std::make_shared<MainHandlerDumper>();
}
void WatchdogTest::TearDown(void)
{
watchdog_->Stop();
mainHandlerDumper_ = nullptr;
}
/**
* @tc.number: AppExecFwk_Watchdog_IsReportEvent_0001
* @tc.number: AppExecFwk_watchdog_IsReportEvent_0001
* @tc.name: IsReportEvent
* @tc.desc: Test the abnormal state of IsReportEvent.
* @tc.require: issueI5MGFU
*/
HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_IsReportEvent_0001, Function | MediumTest | Level3)
HWTEST_F(WatchdogTest, AppExecFwk_watchdog_IsReportEvent_0001, Function | MediumTest | Level3)
{
bool ret = watchdog_->IsReportEvent();
EXPECT_TRUE(ret);
}
/**
* @tc.number: AppExecFwk_Watchdog_IsReportEvent_0002
* @tc.number: AppExecFwk_watchdog_IsReportEvent_0002
* @tc.name: IsReportEvent
* @tc.desc: Test the change state of IsReportEvent.
* @tc.require: issueI5MGFU
*/
HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_IsReportEvent_0002, Function | MediumTest | Level3)
HWTEST_F(WatchdogTest, AppExecFwk_watchdog_IsReportEvent_0002, Function | MediumTest | Level3)
{
watchdog_->SetAppMainThreadState(true);
watchdog_->AllowReportEvent();
@@ -94,12 +97,12 @@ HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_IsReportEvent_0002, Function | Medium
}
/**
* @tc.number: AppExecFwk_Watchdog_ReportEvent_0001
* @tc.number: AppExecFwk_watchdog_ReportEvent_0001
* @tc.name: ReportEvent
* @tc.desc: Test ReportEvent.
* @tc.require: I5UL6H
*/
HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_ReportEvent_0001, Function | MediumTest | Level3)
HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0001, Function | MediumTest | Level3)
{
// be ready for ReportEvent
watchdog_->lastWatchTime_ = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::
@@ -115,12 +118,12 @@ HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_ReportEvent_0001, Function | MediumTe
}
/**
* @tc.number: AppExecFwk_Watchdog_ReportEvent_0002
* @tc.number: AppExecFwk_watchdog_ReportEvent_0002
* @tc.name: ReportEvent
* @tc.desc: Test ReportEvent.
* @tc.require: I5UL6H
*/
HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_ReportEvent_0002, Function | MediumTest | Level3)
HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0002, Function | MediumTest | Level3)
{
// be ready for ReportEvent
watchdog_->lastWatchTime_ = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::
@@ -134,5 +137,341 @@ HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_ReportEvent_0002, Function | MediumTe
watchdog_->ReportEvent();
EXPECT_TRUE(1);
}
/**
* @tc.number: WatchdogTest_Init_001
* @tc.name: Init
* @tc.desc: Verify that function Init.
*/
HWTEST_F(WatchdogTest, WatchdogTest_Init_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_Init_001 start";
std::shared_ptr<EventHandler> eventHandler = std::make_shared<EventHandler>();
watchdog_->Init(eventHandler);
EXPECT_TRUE(watchdog_->appMainHandler_ != nullptr);
GTEST_LOG_(INFO) << "WatchdogTest_Init_001 end";
}
/**
* @tc.number: WatchdogTest_Init_002
* @tc.name: Init
* @tc.desc: Verify that function Init.
*/
HWTEST_F(WatchdogTest, WatchdogTest_Init_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_Init_002 start";
std::shared_ptr<EventHandler> eventHandler = nullptr;
watchdog_->lastWatchTime_ = 2;
watchdog_->Init(eventHandler);
EXPECT_EQ(watchdog_->lastWatchTime_, 0);
GTEST_LOG_(INFO) << "WatchdogTest_Init_002 end";
}
/**
* @tc.number: WatchdogTest_Stop_001
* @tc.name: Stop
* @tc.desc: Verify that function Init.
*/
HWTEST_F(WatchdogTest, WatchdogTest_Stop_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_Stop_001 start";
std::shared_ptr<EventHandler> eventHandler = std::make_shared<EventHandler>();
watchdog_->Init(eventHandler);
EXPECT_TRUE(watchdog_->appMainHandler_ != nullptr);
watchdog_->Stop();
EXPECT_TRUE(watchdog_->appMainHandler_ == nullptr);
GTEST_LOG_(INFO) << "WatchdogTest_Stop_001 end";
}
/**
* @tc.number: WatchdogTest_Stop_002
* @tc.name: Stop
* @tc.desc: Verify that function Stop.
*/
HWTEST_F(WatchdogTest, WatchdogTest_Stop_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_Stop_002 start";
std::shared_ptr<EventHandler> eventHandler = nullptr;
watchdog_->Stop();
EXPECT_TRUE(watchdog_->stopWatchdog_);
GTEST_LOG_(INFO) << "WatchdogTest_Stop_002 end";
}
/**
* @tc.number: WatchdogTest_SetApplicationInfo_001
* @tc.name: SetApplicationInfo
* @tc.desc: Verify that function SetApplicationInfo.
*/
HWTEST_F(WatchdogTest, WatchdogTest_SetApplicationInfo_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_SetApplicationInfo_001 start";
std::shared_ptr<ApplicationInfo> applicationInfo = std::make_shared<ApplicationInfo>();
EXPECT_TRUE(watchdog_->applicationInfo_ == nullptr);
watchdog_->SetApplicationInfo(applicationInfo);
EXPECT_TRUE(watchdog_->applicationInfo_ != nullptr);
GTEST_LOG_(INFO) << "WatchdogTest_SetApplicationInfo_001 end";
}
/**
* @tc.number: WatchdogTest_SetAppMainThreadState_001
* @tc.name: SetAppMainThreadState
* @tc.desc: Verify that function SetAppMainThreadState.
*/
HWTEST_F(WatchdogTest, WatchdogTest_SetAppMainThreadState_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_SetAppMainThreadState_001 start";
bool appMainThreadState = true;
EXPECT_FALSE(watchdog_->appMainThreadIsAlive_);
watchdog_->SetAppMainThreadState(appMainThreadState);
EXPECT_TRUE(watchdog_->appMainThreadIsAlive_);
GTEST_LOG_(INFO) << "WatchdogTest_SetAppMainThreadState_001 end";
}
/**
* @tc.number: WatchdogTest_SetBackgroundStatus_001
* @tc.name: SetBackgroundStatus
* @tc.desc: Verify that function SetBackgroundStatus.
*/
HWTEST_F(WatchdogTest, WatchdogTest_SetBackgroundStatus_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_SetBackgroundStatus_001 start";
bool isInBackground = true;
EXPECT_FALSE(watchdog_->isInBackground_);
watchdog_->SetBackgroundStatus(isInBackground);
EXPECT_TRUE(watchdog_->isInBackground_);
GTEST_LOG_(INFO) << "WatchdogTest_SetBackgroundStatus_001 end";
}
/**
* @tc.number: WatchdogTest_AllowReportEvent_001
* @tc.name: AllowReportEvent
* @tc.desc: Verify that function AllowReportEvent.
*/
HWTEST_F(WatchdogTest, WatchdogTest_AllowReportEvent_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_AllowReportEvent_001 start";
watchdog_->needReport_ = false;
watchdog_->AllowReportEvent();
EXPECT_TRUE(watchdog_->needReport_);
GTEST_LOG_(INFO) << "WatchdogTest_AllowReportEvent_001 end";
}
/**
* @tc.number: WatchdogTest_IsReportEvent_001
* @tc.name: IsReportEvent
* @tc.desc: Verify that function IsReportEvent.
*/
HWTEST_F(WatchdogTest, WatchdogTest_IsReportEvent_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_IsReportEvent_001 start";
auto result = watchdog_->IsReportEvent();
EXPECT_TRUE(result);
GTEST_LOG_(INFO) << "WatchdogTest_IsReportEvent_001 end";
}
/**
* @tc.number: WatchdogTest_IsReportEvent_002
* @tc.name: IsReportEvent
* @tc.desc: Verify that function IsReportEvent.
*/
HWTEST_F(WatchdogTest, WatchdogTest_IsReportEvent_004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_IsReportEvent_002 start";
bool appMainThreadState = true;
EXPECT_FALSE(watchdog_->appMainThreadIsAlive_);
watchdog_->SetAppMainThreadState(appMainThreadState);
auto result = watchdog_->IsReportEvent();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "WatchdogTest_IsReportEvent_002 end";
}
/**
* @tc.number: WatchdogTest_IsStopwatchdog_001
* @tc.name: IsStopWatchdog
* @tc.desc: Verify that function IsStopWatchdog.
*/
HWTEST_F(WatchdogTest, WatchdogTest_IsStopwatchdog_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_IsStopwatchdog_001 start";
auto result = watchdog_->IsStopWatchdog();
EXPECT_FALSE(result);
GTEST_LOG_(INFO) << "WatchdogTest_IsStopwatchdog_001 end";
}
/**
* @tc.number: WatchdogTest_Timer_001
* @tc.name: Timer
* @tc.desc: Verify that function Timer.
*/
HWTEST_F(WatchdogTest, WatchdogTest_Timer_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_Timer_001 start";
watchdog_->needReport_ = false;
watchdog_->Timer();
EXPECT_TRUE(!watchdog_->needReport_);
GTEST_LOG_(INFO) << "WatchdogTest_Timer_001 end";
}
/**
* @tc.number: WatchdogTest_Timer_002
* @tc.name: Timer
* @tc.desc: Verify that function Timer.
*/
HWTEST_F(WatchdogTest, WatchdogTest_Timer_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_Timer_002 start";
bool isInBackground = true;
EXPECT_FALSE(watchdog_->isInBackground_);
watchdog_->SetBackgroundStatus(isInBackground);
watchdog_->Timer();
EXPECT_TRUE(watchdog_->appMainThreadIsAlive_);
GTEST_LOG_(INFO) << "WatchdogTest_Timer_002 end";
}
/**
* @tc.number: WatchdogTest_Timer_003
* @tc.name: Timer
* @tc.desc: Verify that function Timer.
*/
HWTEST_F(WatchdogTest, WatchdogTest_Timer_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_Timer_003 start";
bool appMainThreadState = true;
EXPECT_FALSE(watchdog_->appMainThreadIsAlive_);
watchdog_->SetAppMainThreadState(appMainThreadState);
watchdog_->Timer();
EXPECT_TRUE(watchdog_->needReport_);
EXPECT_FALSE(watchdog_->isInBackground_);
EXPECT_FALSE(watchdog_->appMainThreadIsAlive_);
GTEST_LOG_(INFO) << "WatchdogTest_Timer_003 end";
}
/**
* @tc.number: WatchdogTest_Timer_004
* @tc.name: Timer
* @tc.desc: Verify that function Timer.
*/
HWTEST_F(WatchdogTest, WatchdogTest_Timer_004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_Timer_004 start";
bool appMainThreadState = true;
EXPECT_FALSE(watchdog_->appMainThreadIsAlive_);
watchdog_->SetAppMainThreadState(appMainThreadState);
watchdog_->appMainHandler_ = std::make_shared<EventHandler>();
watchdog_->Timer();
EXPECT_TRUE(watchdog_->needReport_);
EXPECT_FALSE(watchdog_->isInBackground_);
EXPECT_FALSE(watchdog_->appMainThreadIsAlive_);
EXPECT_TRUE(watchdog_->appMainHandler_ != nullptr);
GTEST_LOG_(INFO) << "WatchdogTest_Timer_004 end";
}
/**
* @tc.number: WatchdogTest_ReportEvent_003
* @tc.name: ReportEvent
* @tc.desc: Verify that function ReportEvent.
*/
HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_001 start";
watchdog_->ReportEvent();
EXPECT_TRUE(watchdog_->lastWatchTime_ != 0);
GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_001 end";
}
/**
* @tc.number: WatchdogTest_ReportEvent_004
* @tc.name: ReportEvent
* @tc.desc: Verify that function ReportEvent.
*/
HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_002 start";
watchdog_->lastWatchTime_ =
std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
watchdog_->ReportEvent();
EXPECT_TRUE(watchdog_->applicationInfo_ == nullptr);
GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_002 end";
}
/**
* @tc.number: WatchdogTest_ReportEvent_005
* @tc.name: ReportEvent
* @tc.desc: Verify that function ReportEvent.
*/
HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_005, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_003 start";
watchdog_->lastWatchTime_ =
std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
watchdog_->applicationInfo_ = std::make_shared<ApplicationInfo>();
watchdog_->needReport_ = false;
watchdog_->ReportEvent();
EXPECT_TRUE(watchdog_->applicationInfo_ != nullptr);
EXPECT_TRUE(watchdog_->needReport_ == false);
GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_003 end";
}
/**
* @tc.number: WatchdogTest_ReportEvent_006
* @tc.name: ReportEvent
* @tc.desc: Verify that function ReportEvent.
*/
HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_006, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_004 start";
watchdog_->lastWatchTime_ =
std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
watchdog_->applicationInfo_ = std::make_shared<ApplicationInfo>();
watchdog_->isSixSecondEvent_ = true;
watchdog_->ReportEvent();
EXPECT_TRUE(watchdog_->applicationInfo_ != nullptr);
EXPECT_TRUE(watchdog_->needReport_ == false);
GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_004 end";
}
/**
* @tc.number: WatchdogTest_ReportEvent_007
* @tc.name: ReportEvent
* @tc.desc: Verify that function ReportEvent.
*/
HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_007, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_005 start";
watchdog_->lastWatchTime_ =
std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
watchdog_->applicationInfo_ = std::make_shared<ApplicationInfo>();
watchdog_->ReportEvent();
EXPECT_TRUE(watchdog_->applicationInfo_ != nullptr);
EXPECT_TRUE(watchdog_->isSixSecondEvent_ == true);
GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_005 end";
}
/**
* @tc.number: WatchdogTest_Dump_001
* @tc.name: Dump
* @tc.desc: Verify that function Dump.
*/
HWTEST_F(WatchdogTest, WatchdogTest_Dump_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_Dump_001 start";
std::string message = "message";
mainHandlerDumper_->dumpInfo = "dump";
mainHandlerDumper_->Dump(message);
EXPECT_EQ(mainHandlerDumper_->GetDumpInfo(), "dumpmessage");
GTEST_LOG_(INFO) << "WatchdogTest_Dump_001 end";
}
/**
* @tc.number: WatchdogTest_GetTag_001
* @tc.name: GetTag
* @tc.desc: Verify that function GetTag.
*/
HWTEST_F(WatchdogTest, WatchdogTest_GetTag_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "WatchdogTest_GetTag_001 start";
EXPECT_EQ(mainHandlerDumper_->GetTag(), "");
GTEST_LOG_(INFO) << "WatchdogTest_GetTag_001 end";
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -25,7 +25,6 @@ ohos_unittest("mission_data_storage_test") {
]
sources = [
"${ability_runtime_services_path}/common/src/permission_verification.cpp",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"mission_data_storage_test.cpp", # add mock file
]
@@ -41,6 +40,7 @@ ohos_unittest("mission_data_storage_test") {
deps = [
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
@@ -51,7 +51,6 @@ ohos_unittest("mission_data_storage_test") {
external_deps = [
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
+1 -2
View File
@@ -26,7 +26,6 @@ ohos_unittest("mission_info_mgr_test") {
]
sources = [
"${ability_runtime_services_path}/common/src/permission_verification.cpp",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"mission_info_mgr_test.cpp", # add mock file
]
@@ -42,6 +41,7 @@ ohos_unittest("mission_info_mgr_test") {
deps = [
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
@@ -52,7 +52,6 @@ ohos_unittest("mission_info_mgr_test") {
external_deps = [
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
@@ -388,44 +388,50 @@ HWTEST_F(MissionInfoMgrTest, FindReusedMissionInfo_001, TestSize.Level1)
int userId = 0;
missionInfoMgr->Init(userId);
InnerMissionInfo missionInfo;
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("", "", missionInfo));
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo));
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("", "", false, missionInfo));
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo));
missionInfo.missionInfo.id = 1;
missionInfo.launchMode = static_cast<int32_t>(AppExecFwk::LaunchMode::STANDARD);
missionInfoMgr->missionInfoList_.push_back(missionInfo);
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo));
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo));
missionInfoMgr->missionInfoList_.clear();
missionInfo.launchMode = static_cast<int32_t>(AppExecFwk::LaunchMode::SINGLETON);
missionInfoMgr->missionInfoList_.push_back(missionInfo);
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo));
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo));
missionInfoMgr->missionInfoList_.clear();
missionInfo.missionName = "test";
missionInfoMgr->missionInfoList_.push_back(missionInfo);
EXPECT_TRUE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo));
EXPECT_TRUE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo));
missionInfoMgr->missionInfoList_.clear();
missionInfo.launchMode = static_cast<int32_t>(AppExecFwk::LaunchMode::SPECIFIED);
missionInfoMgr->missionInfoList_.push_back(missionInfo);
EXPECT_TRUE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo));
EXPECT_TRUE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo));
missionInfoMgr->missionInfoList_.clear();
missionInfo.missionName = "test1";
missionInfoMgr->missionInfoList_.push_back(missionInfo);
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo));
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo));
missionInfoMgr->missionInfoList_.clear();
missionInfo.missionName = "test";
missionInfo.specifiedFlag = "flag";
missionInfoMgr->missionInfoList_.push_back(missionInfo);
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo));
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo));
missionInfoMgr->missionInfoList_.clear();
missionInfo.specifiedFlag = "";
missionInfo.launchMode = 1000;
missionInfoMgr->missionInfoList_.push_back(missionInfo);
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo));
EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo));
missionInfoMgr->missionInfoList_.clear();
missionInfo.missionName = "test";
missionInfo.launchMode = static_cast<int32_t>(AppExecFwk::LaunchMode::STANDARD);
missionInfoMgr->missionInfoList_.push_back(missionInfo);
EXPECT_TRUE(missionInfoMgr->FindReusedMissionInfo("test", "", true, missionInfo));
}
/*
@@ -25,7 +25,6 @@ ohos_unittest("mission_list_manager_test") {
]
sources = [
"${ability_runtime_services_path}/common/src/permission_verification.cpp",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"mission_list_manager_test.cpp", # add mock file
]
@@ -41,6 +40,7 @@ ohos_unittest("mission_list_manager_test") {
deps = [
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
@@ -51,7 +51,6 @@ ohos_unittest("mission_list_manager_test") {
external_deps = [
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",

Some files were not shown because too many files have changed in this diff Show More