Signed-off-by: huangshiwei <huangshiwei4@huawei.com>
This commit is contained in:
huangshiwei 2024-01-24 17:32:42 +08:00
parent 1d5eb70c00
commit fac4abc258
15 changed files with 143 additions and 36 deletions

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef UNITTEST_OHOS_ABILITY_RUNTIME_IS_SA_CALL_TEST_H
#define UNITTEST_OHOS_ABILITY_RUNTIME_IS_SA_CALL_TEST_H
#include "accesstoken_kit.h"
#include "nativetoken_kit.h"
#include "token_setproc.h"
namespace OHOS::AAFwk {
class IsMockSaCall {
public:
static void IsMockSaCallWithPermission()
{
uint64_t tokenId;
const char* perms[] = {
perms[0] = "ohos.permission.ACCESS_DLP_FILE",
perms[1] = "ohos.permission.CLEAN_APPLICATION_DATA",
perms[2] = "ohos.permission.CLEAN_BACKGROUND_PROCESSES",
perms[3] = "ohos.permission.GET_RUNNING_INFO",
perms[4] = "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS",
perms[5] = "ohos.permission.MANAGE_MISSIONS",
perms[6] = "ohos.permission.RUNNING_STATE_OBSERVER",
perms[7] = "ohos.permission.SET_ABILITY_CONTROLLER",
perms[8] = "ohos.permission.UPDATE_CONFIGURATION",
perms[9] = "ohos.permission.INSTALL_BUNDLE",
perms[10] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
perms[11] = "ohos.permission.START_INVISIBLE_ABILITY",
perms[12] = "ohos.permission.START_ABILITIES_FROM_BACKGROUND",
perms[13] = "ohos.permission.START_ABILIIES_FROM_BACKGROUND",
perms[14] = "ohos.permission.ABILITY_BACKGROUND_COMMUNICATION",
perms[15] = "ohos.permission.MANAGER_ABILITY_FROM_GATEWAY",
perms[16] = "ohos.permission.PROXY_AUTHORIZATION_URI",
perms[17] = "ohos.permission.EXEMPT_AS_CALLER",
perms[18] = "ohos.permission.EXEMPT_AS_TARGET",
perms[19] = "ohos.permission.PREPARE_APP_TERMINATE",
perms[20] = "ohos.permission.START_ABILITY_WITH_ANIMATION",
perms[21] = "ohos.permission.MANAGE_APP_BOOT_INTERNAL",
perms[22] = "ohos.permission.CONNECT_UI_EXTENSION_ABILITY",
perms[23] = "ohos.permission.START_RECENT_ABILITY"
};
NativeTokenInfoParams infoInstance = {
.dcapsNum = 0,
.permsNum = static_cast<int32_t>(sizeof(perms)/sizeof(perms[0])),
.aclsNum = 0,
.dcaps = nullptr,
.perms = perms,
.acls = nullptr,
.aplStr = "system_core",
};
infoInstance.processName = "distributedsched";
tokenId = GetAccessTokenId(&infoInstance);
SetSelfTokenID(tokenId);
Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
}
};
} // namespace OHOS::AAFwk
#endif // UNITTEST_OHOS_ABILITY_RUNTIME_IS_SA_CALL_TEST_H

View File

@ -21,6 +21,7 @@ ohos_moduletest("app_mgr_client_test") {
include_dirs = [
"${ability_runtime_test_path}/mock/common/include",
"${ability_runtime_test_path}/mock/mock_sa_call",
"${ability_runtime_test_path}/moduletest/mock/include",
]
@ -33,6 +34,7 @@ ohos_moduletest("app_mgr_client_test") {
deps = [
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"//third_party/googletest:gtest_main",
]
@ -41,6 +43,7 @@ ohos_moduletest("app_mgr_client_test") {
"ability_base:want",
"ability_runtime:ability_manager",
"ability_runtime:app_manager",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"bundle_framework:appexecfwk_base",

View File

@ -20,6 +20,7 @@
#include "hilog_wrapper.h"
#include "mock_configuration_observer.h"
#include "mock_native_token.h"
#include "mock_sa_call.h"
using namespace testing;
using namespace testing::ext;
@ -63,6 +64,7 @@ HWTEST_F(AppMgrClientTest, AppMgrClient_GetProcessRunningInfosByUserId_0100, Tes
{
HILOG_INFO("AppMgrClient_GetProcessRunningInfosByUserId_0100 start");
AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
auto appMgrClient = std::make_unique<AppMgrClient>();
EXPECT_NE(appMgrClient, nullptr);

View File

@ -25,6 +25,7 @@ ohos_unittest("ability_manager_service_first_test") {
"${ability_runtime_path}/interfaces/inner_api/ability_manager/include",
"${ability_runtime_test_path}/mock/ability_manager_collaborator",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
"${ability_runtime_test_path}/mock/mock_sa_call",
"${ability_runtime_test_path}/mock/prepare_terminate_callback",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit/include",
"${ability_runtime_test_path}/unittest/app_debug_listener_stub_test",
@ -58,6 +59,9 @@ ohos_unittest("ability_manager_service_first_test") {
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",

View File

@ -26,7 +26,6 @@
#include "recovery_param.h"
#undef private
#undef protected
#include "ability_manager_errors.h"
#include "connection_observer_errors.h"
#include "mock_ability_connect_callback.h"
@ -36,6 +35,7 @@
#include "session/host/include/session.h"
#include "mock_ability_manager_collaborator.h"
#include "mock_prepare_terminate_callback.h"
#include "mock_sa_call.h"
#include "scene_board_judgement.h"
using namespace testing;
@ -591,6 +591,7 @@ HWTEST_F(AbilityManagerServiceFirstTest, GetMissionIdByToken_001, TestSize.Level
{
HILOG_INFO("AbilityManagerServiceFirstTest GetMissionIdByToken_001 start");
auto abilityMs_ = std::make_shared<AbilityManagerService>();
AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
EXPECT_EQ(abilityMs_->GetMissionIdByToken(nullptr), -1);
EXPECT_EQ(abilityMs_->GetMissionIdByToken(MockToken(AbilityType::PAGE)), -1);
HILOG_INFO("AbilityManagerServiceFirstTest GetMissionIdByToken_001 end");

View File

@ -24,6 +24,7 @@ ohos_unittest("AmsMgrKillProcessTest") {
include_dirs = [
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper",
"${ability_runtime_test_path}/mock/common/include",
"${ability_runtime_test_path}/mock/mock_sa_call",
"${ability_runtime_test_path}/mock/services_appmgr_test/include",
]
@ -48,6 +49,7 @@ ohos_unittest("AmsMgrKillProcessTest") {
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_services_path}/appmgr:libappms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:task_handler_wrap",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
@ -55,6 +57,7 @@ ohos_unittest("AmsMgrKillProcessTest") {
external_deps = [
"ability_base:want",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"bundle_framework:appexecfwk_base",

View File

@ -22,6 +22,7 @@
#include "hilog_wrapper.h"
#include "mock_bundle_manager.h"
#include "mock_native_token.h"
#include "mock_sa_call.h"
#include "system_ability_definition.h"
#include "sys_mgr_client.h"
@ -96,6 +97,7 @@ HWTEST_F(AmsMgrKillProcessTest, KillProcess_0100, TestSize.Level0)
{
HILOG_INFO("AmsMgrKillProcessTest_KillProcess_0100");
AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
auto appMgrServiceInner = GetAppMgrServiceInner();
EXPECT_NE(appMgrServiceInner, nullptr);
@ -115,6 +117,7 @@ HWTEST_F(AmsMgrKillProcessTest, KillProcess_0200, TestSize.Level0)
{
HILOG_INFO("AmsMgrKillProcessTest_KillProcess_0200");
AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
auto proxy = GetAppMgrProxy();
EXPECT_NE(proxy, nullptr);

View File

@ -19,7 +19,10 @@ module_output_path = "ability_runtime/abilitymgr"
ohos_unittest("app_mgr_service_dump_test") {
module_out_path = module_output_path
include_dirs = [ "${ability_runtime_test_path}/mock/common/include" ]
include_dirs = [
"${ability_runtime_test_path}/mock/common/include",
"${ability_runtime_test_path}/mock/mock_sa_call",
]
sources = [
"${ability_runtime_test_path}/mock/common/src/mock_native_token.cpp",
@ -30,6 +33,7 @@ ohos_unittest("app_mgr_service_dump_test") {
deps = [
"${ability_runtime_services_path}/appmgr:libappms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:task_handler_wrap",
"//third_party/googletest:gtest_main",
]
@ -37,6 +41,7 @@ ohos_unittest("app_mgr_service_dump_test") {
external_deps = [
"ability_base:want",
"ability_runtime:app_manager",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"bundle_framework:appexecfwk_base",

View File

@ -20,6 +20,7 @@
#undef private
#include "hilog_wrapper.h"
#include "mock_native_token.h"
#include "mock_sa_call.h"
using namespace testing;
using namespace testing::ext;
@ -62,6 +63,7 @@ HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_GetProcessRunningInfosByUserId
{
HILOG_INFO("AppMgrServiceDump_GetProcessRunningInfosByUserId_0100 start");
AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(appMgrServiceInner, nullptr);
@ -82,6 +84,7 @@ HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_GetProcessRunningInfosByUserId
{
HILOG_INFO("AppMgrServiceDump_GetProcessRunningInfosByUserId_0200 start");
AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
auto appMgrService = std::make_shared<AppMgrService>();
EXPECT_NE(appMgrService, nullptr);

View File

@ -22,6 +22,7 @@ ohos_unittest("AppMgrServiceInnerTest") {
include_dirs = [
"${ability_runtime_test_path}/mock/common/include",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
"${ability_runtime_test_path}/mock/mock_sa_call",
"${ability_runtime_test_path}/mock/services_appmgr_test/include",
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_test_path}/moduletest/mock/include",
@ -36,6 +37,7 @@ ohos_unittest("AppMgrServiceInnerTest") {
deps = [
"${ability_runtime_services_path}/appmgr:libappms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:task_handler_wrap",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
@ -45,6 +47,7 @@ ohos_unittest("AppMgrServiceInnerTest") {
"ability_base:configuration",
"ability_base:want",
"ability_runtime:app_manager",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"bundle_framework:appexecfwk_base",

View File

@ -31,6 +31,7 @@
#include "mock_iapp_state_callback.h"
#include "mock_native_token.h"
#include "mock_render_scheduler.h"
#include "mock_sa_call.h"
#include "parameters.h"
#include "window_manager.h"
@ -837,6 +838,7 @@ HWTEST_F(AppMgrServiceInnerTest, KillApplicationSelf_001, TestSize.Level0)
HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUserId_001, TestSize.Level0)
{
HILOG_INFO("KillApplicationByUserId_001 start");
AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(appMgrServiceInner, nullptr);

View File

@ -23,6 +23,7 @@ ohos_unittest("app_scheduler_test") {
include_dirs = [
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_test_path}/mock/mock_sa_call",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock",
"${ability_runtime_test_path}/unittest/app_debug_listener_proxy_test",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
@ -54,6 +55,8 @@ ohos_unittest("app_scheduler_test") {
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",

View File

@ -27,6 +27,7 @@
#include "app_process_data.h"
#include "app_state_call_back_mock.h"
#include "element_name.h"
#include "mock_sa_call.h"
using namespace testing;
using namespace testing::ext;
@ -1181,6 +1182,7 @@ HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAppDebugListener_001, TestSize.L
*/
HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAppDebugListener_002, TestSize.Level1)
{
AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
auto listener = new AppDebugListenerStubMock();
int res = DelayedSingleton<AppScheduler>::GetInstance()->RegisterAppDebugListener(listener);
EXPECT_EQ(res, ERR_OK);
@ -1205,6 +1207,7 @@ HWTEST_F(AppSchedulerTest, AppScheduler_UnregisterAppDebugListener_001, TestSize
*/
HWTEST_F(AppSchedulerTest, AppScheduler_UnregisterAppDebugListener_002, TestSize.Level1)
{
AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
auto listener = new AppDebugListenerStubMock();
int res = DelayedSingleton<AppScheduler>::GetInstance()->UnregisterAppDebugListener(listener);
EXPECT_EQ(res, ERR_OK);

View File

@ -24,7 +24,9 @@
#include "context_deal.h"
#include "hilog_wrapper.h"
#include "locale_config.h"
#include "mock_ability_impl.h"
#include "mock_ability_token.h"
#include "mock_page_ability.h"
#include "mock_ui_ability.h"
#include "mock_ui_ability_impl.h"
#include "ohos_application.h"
@ -341,7 +343,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_Stop_001, TestSize.Level1)
HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_001 start";
std::shared_ptr<MockUIAbilityimpl> mockUIAbilityimpl = std::make_shared<MockUIAbilityimpl>();
std::shared_ptr<MockAbilityimpl> mockAbilityimpl = std::make_shared<MockAbilityimpl>();
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "uiAbility";
@ -353,8 +355,8 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_001, TestSize.Level1)
std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner);
std::shared_ptr<UIAbility> uiability = nullptr;
MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility();
std::shared_ptr<Ability> uiability = nullptr;
MockPageAbility *pMocKUIAbility = new (std::nothrow) MockPageAbility();
EXPECT_NE(pMocKUIAbility, nullptr);
if (pMocKUIAbility != nullptr) {
uiability.reset(pMocKUIAbility);
@ -364,11 +366,11 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_001, TestSize.Level1)
contextDeal->SetAbilityInfo(abilityInfo);
pMocKUIAbility->AttachBaseContext(contextDeal);
application->AttachBaseContext(contextDeal);
mockUIAbilityimpl->Init(application, record, uiability, handler, token);
mockAbilityimpl->Init(application, record, uiability, handler, token);
Want want;
mockUIAbilityimpl->ImplForeground(want);
EXPECT_EQ(MockUIAbility::Event::ON_FOREGROUND, pMocKUIAbility->state_);
EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockUIAbilityimpl->GetCurrentState());
mockAbilityimpl->ImplForeground(want);
EXPECT_EQ(MockPageAbility::Event::ON_FOREGROUND, pMocKUIAbility->state_);
EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockAbilityimpl->GetCurrentState());
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_001 end";
@ -385,7 +387,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_001, TestSize.Level1)
HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_002 start";
std::shared_ptr<MockUIAbilityimpl> mockUIAbilityimpl = std::make_shared<MockUIAbilityimpl>();
std::shared_ptr<MockAbilityimpl> mockAbilityimpl = std::make_shared<MockAbilityimpl>();
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "uiAbility";
@ -397,8 +399,8 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_002, TestSize.Level1)
std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner);
std::shared_ptr<UIAbility> uiability = nullptr;
MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility();
std::shared_ptr<Ability> uiability = nullptr;
MockPageAbility *pMocKUIAbility = new (std::nothrow) MockPageAbility();
EXPECT_NE(pMocKUIAbility, nullptr);
if (pMocKUIAbility != nullptr) {
uiability.reset(pMocKUIAbility);
@ -408,13 +410,11 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_002, TestSize.Level1)
contextDeal->SetAbilityInfo(abilityInfo);
pMocKUIAbility->AttachBaseContext(contextDeal);
application->AttachBaseContext(contextDeal);
mockUIAbilityimpl->Init(application, record, uiability, handler, token);
mockAbilityimpl->Init(application, record, uiability, handler, token);
Want want;
mockUIAbilityimpl->ImplForeground(want);
mockUIAbilityimpl->ImplForeground(want);
mockUIAbilityimpl->ImplForeground(want);
EXPECT_EQ(MockUIAbility::Event::ON_FOREGROUND, pMocKUIAbility->state_);
EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockUIAbilityimpl->GetCurrentState());
mockAbilityimpl->ImplForeground(want);
EXPECT_EQ(MockPageAbility::Event::ON_FOREGROUND, pMocKUIAbility->state_);
EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockAbilityimpl->GetCurrentState());
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_002 end";
@ -562,7 +562,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_001, TestSi
HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_Background_002 start";
std::shared_ptr<MockUIAbilityimpl> mockUIAbilityimpl = std::make_shared<MockUIAbilityimpl>();
std::shared_ptr<MockAbilityimpl> mockAbilityimpl = std::make_shared<MockAbilityimpl>();
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "uiAbility";
@ -574,8 +574,8 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_002, TestSi
std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner);
std::shared_ptr<UIAbility> uiability = nullptr;
MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility();
std::shared_ptr<Ability> uiability = nullptr;
MockPageAbility *pMocKUIAbility = new (std::nothrow) MockPageAbility();
EXPECT_NE(pMocKUIAbility, nullptr);
if (pMocKUIAbility != nullptr) {
uiability.reset(pMocKUIAbility);
@ -585,13 +585,13 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_002, TestSi
contextDeal->SetAbilityInfo(abilityInfo);
pMocKUIAbility->AttachBaseContext(contextDeal);
application->AttachBaseContext(contextDeal);
mockUIAbilityimpl->Init(application, record, uiability, handler, token);
mockAbilityimpl->Init(application, record, uiability, handler, token);
Want want;
mockUIAbilityimpl->ImplForeground(want);
mockUIAbilityimpl->ImplBackground();
mockUIAbilityimpl->ImplForeground(want);
EXPECT_EQ(MockUIAbility::Event::ON_FOREGROUND, pMocKUIAbility->state_);
EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockUIAbilityimpl->GetCurrentState());
mockAbilityimpl->ImplForeground(want);
mockAbilityimpl->ImplBackground();
mockAbilityimpl->ImplForeground(want);
EXPECT_EQ(MockPageAbility::Event::ON_FOREGROUND, pMocKUIAbility->state_);
EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockAbilityimpl->GetCurrentState());
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_Background_002 end";
@ -608,7 +608,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_002, TestSi
HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_Background_002 start";
std::shared_ptr<MockUIAbilityimpl> mockUIAbilityimpl = std::make_shared<MockUIAbilityimpl>();
std::shared_ptr<MockAbilityimpl> mockAbilityimpl = std::make_shared<MockAbilityimpl>();
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "uiAbility";
@ -620,8 +620,8 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_003, TestSi
std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> eventRunner = EventRunner::Create(abilityInfo->name);
std::shared_ptr<AbilityHandler> handler = std::make_shared<AbilityHandler>(eventRunner);
std::shared_ptr<UIAbility> uiability = nullptr;
MockUIAbility *pMocKUIAbility = new (std::nothrow) MockUIAbility();
std::shared_ptr<Ability> uiability = nullptr;
MockPageAbility *pMocKUIAbility = new (std::nothrow) MockPageAbility();
EXPECT_NE(pMocKUIAbility, nullptr);
if (pMocKUIAbility != nullptr) {
uiability.reset(pMocKUIAbility);
@ -631,12 +631,12 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_New_Foreground_Background_003, TestSi
contextDeal->SetAbilityInfo(abilityInfo);
pMocKUIAbility->AttachBaseContext(contextDeal);
application->AttachBaseContext(contextDeal);
mockUIAbilityimpl->Init(application, record, uiability, handler, token);
mockAbilityimpl->Init(application, record, uiability, handler, token);
Want want;
mockUIAbilityimpl->ImplBackground();
mockUIAbilityimpl->ImplForeground(want);
EXPECT_EQ(MockUIAbility::Event::ON_FOREGROUND, pMocKUIAbility->state_);
EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockUIAbilityimpl->GetCurrentState());
mockAbilityimpl->ImplBackground();
mockAbilityimpl->ImplForeground(want);
EXPECT_EQ(MockPageAbility::Event::ON_FOREGROUND, pMocKUIAbility->state_);
EXPECT_EQ(AAFwk::ABILITY_STATE_FOREGROUND_NEW, mockAbilityimpl->GetCurrentState());
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_New_Foreground_Background_003 end";

View File

@ -447,7 +447,7 @@ HWTEST_F(MissionInfoMgrTest, FindReusedMissionInfo_001, TestSize.Level1)
missionInfo.missionName = "test";
missionInfo.launchMode = static_cast<int32_t>(AppExecFwk::LaunchMode::STANDARD);
missionInfoMgr->missionInfoList_.push_back(missionInfo);
EXPECT_TRUE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo));
EXPECT_TRUE(missionInfoMgr->FindReusedMissionInfo("test", "", true, missionInfo));
}
/*