mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
游戏预启动需求增加TDD用例
Signed-off-by: lidongrui <lidongrui3@huawei.com> Co-Authored-By: Agent
This commit is contained in:
@@ -516,6 +516,90 @@ HWTEST_F(JsUiAbilityTest, JSUIAbility_OnStart_0600, TestSize.Level1)
|
||||
GTEST_LOG_(INFO) << "JSUIAbility_OnStart_0600 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: JSUIAbility_OnStart_0700
|
||||
* @tc.desc: OnStart test with GAME_PRELAUNCH = true
|
||||
* @tc.desc: Verify isGamePreLaunch_ is set to true when GAME_PRELAUNCH param is true
|
||||
*/
|
||||
HWTEST_F(JsUiAbilityTest, JSUIAbility_OnStart_0700, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "JSUIAbility_OnStart_0700 start";
|
||||
AbilityRuntime::Runtime::Options options;
|
||||
options.lang = AbilityRuntime::Runtime::Language::JS;
|
||||
auto runtime = AbilityRuntime::Runtime::Create(options);
|
||||
auto jsRuntime = static_cast<AbilityRuntime::JsRuntime*>(runtime.get());
|
||||
auto ability = std::make_shared<AbilityRuntime::JsUIAbility>(*jsRuntime);
|
||||
EXPECT_NE(ability, nullptr);
|
||||
Want want;
|
||||
want.SetParam(std::string("ohos.params.gamePrelaunch"), true);
|
||||
napi_ref ref = nullptr;
|
||||
auto env = jsRuntime->GetNapiEnv();
|
||||
napi_value value = OHOS::AppExecFwk::WrapWant(env, want);
|
||||
napi_create_reference(env, value, 1, &ref);
|
||||
ability->jsAbilityObj_ = std::unique_ptr<NativeReference>(
|
||||
reinterpret_cast<NativeReference *>(ref));
|
||||
EXPECT_NE(ability->jsAbilityObj_, nullptr);
|
||||
|
||||
sptr<AAFwk::SessionInfo> sessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
|
||||
EXPECT_NE(sessionInfo, nullptr);
|
||||
ability->scene_ = std::make_shared<Rosen::WindowScene>();
|
||||
EXPECT_NE(ability->scene_, nullptr);
|
||||
auto abilityContextImpl = std::make_shared<AbilityContextImpl>();
|
||||
EXPECT_NE(abilityContextImpl, nullptr);
|
||||
auto abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
|
||||
EXPECT_NE(abilityInfo, nullptr);
|
||||
abilityContextImpl->SetAbilityInfo(abilityInfo);
|
||||
ability->abilityContext_ = abilityContextImpl;
|
||||
ability->abilityInfo_ = abilityInfo;
|
||||
EXPECT_NE(ability->abilityInfo_, nullptr);
|
||||
ability->OnStart(want, sessionInfo);
|
||||
EXPECT_TRUE(ability->isGamePreLaunch_);
|
||||
|
||||
GTEST_LOG_(INFO) << "JSUIAbility_OnStart_0700 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: JSUIAbility_OnStart_0800
|
||||
* @tc.desc: OnStart test with GAME_PRELAUNCH = false
|
||||
* @tc.desc: Verify isGamePreLaunch_ remains false when GAME_PRELAUNCH param is false
|
||||
*/
|
||||
HWTEST_F(JsUiAbilityTest, JSUIAbility_OnStart_0800, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "JSUIAbility_OnStart_0800 start";
|
||||
AbilityRuntime::Runtime::Options options;
|
||||
options.lang = AbilityRuntime::Runtime::Language::JS;
|
||||
auto runtime = AbilityRuntime::Runtime::Create(options);
|
||||
auto jsRuntime = static_cast<AbilityRuntime::JsRuntime*>(runtime.get());
|
||||
auto ability = std::make_shared<AbilityRuntime::JsUIAbility>(*jsRuntime);
|
||||
EXPECT_NE(ability, nullptr);
|
||||
Want want;
|
||||
want.SetParam(std::string("ohos.params.gamePrelaunch"), false);
|
||||
napi_ref ref = nullptr;
|
||||
auto env = jsRuntime->GetNapiEnv();
|
||||
napi_value value = OHOS::AppExecFwk::WrapWant(env, want);
|
||||
napi_create_reference(env, value, 1, &ref);
|
||||
ability->jsAbilityObj_ = std::unique_ptr<NativeReference>(
|
||||
reinterpret_cast<NativeReference *>(ref));
|
||||
EXPECT_NE(ability->jsAbilityObj_, nullptr);
|
||||
|
||||
sptr<AAFwk::SessionInfo> sessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
|
||||
EXPECT_NE(sessionInfo, nullptr);
|
||||
ability->scene_ = std::make_shared<Rosen::WindowScene>();
|
||||
EXPECT_NE(ability->scene_, nullptr);
|
||||
auto abilityContextImpl = std::make_shared<AbilityContextImpl>();
|
||||
EXPECT_NE(abilityContextImpl, nullptr);
|
||||
auto abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
|
||||
EXPECT_NE(abilityInfo, nullptr);
|
||||
abilityContextImpl->SetAbilityInfo(abilityInfo);
|
||||
ability->abilityContext_ = abilityContextImpl;
|
||||
ability->abilityInfo_ = abilityInfo;
|
||||
EXPECT_NE(ability->abilityInfo_, nullptr);
|
||||
ability->OnStart(want, sessionInfo);
|
||||
EXPECT_FALSE(ability->isGamePreLaunch_);
|
||||
|
||||
GTEST_LOG_(INFO) << "JSUIAbility_OnStart_0800 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: JSUIAbility_GetWindowStage_0100
|
||||
* @tc.desc: GetWindowStage test
|
||||
|
||||
@@ -348,5 +348,107 @@ HWTEST_F(PreloadManagerServiceTest, PreloadApplication_011, TestSize.Level1)
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest PreloadApplication_011 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: PreloadManagerService
|
||||
* Name: LaunchGameCustomized_001
|
||||
* Function: LaunchGameCustomized
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: PreloadManagerService LaunchGameCustomized verification failed
|
||||
*/
|
||||
HWTEST_F(PreloadManagerServiceTest, LaunchGameCustomized_001, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest LaunchGameCustomized_001 start");
|
||||
|
||||
// Set up for verification failure
|
||||
MyStatus::GetInstance().isMultiUserConcurrency_ = false;
|
||||
std::string bundleName = "com.test.game";
|
||||
int32_t userId = 100;
|
||||
int32_t appIndex = 0;
|
||||
|
||||
// PreloadApplicationVerification will fail due to isMultiUserConcurrency_ = false
|
||||
auto result = PreloadManagerService::GetInstance().LaunchGameCustomized(bundleName, userId, appIndex);
|
||||
EXPECT_EQ(result, ERR_CROSS_USER);
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest LaunchGameCustomized_001 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: PreloadManagerService
|
||||
* Name: LaunchGameCustomized_002
|
||||
* Function: LaunchGameCustomized
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: PreloadManagerService LaunchGameCustomized record already exist
|
||||
*/
|
||||
HWTEST_F(PreloadManagerServiceTest, LaunchGameCustomized_002, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest LaunchGameCustomized_002 start");
|
||||
|
||||
// Set up for record already exist
|
||||
MyStatus::GetInstance().isMultiUserConcurrency_ = true;
|
||||
MyStatus::GetInstance().retCheckPreloadAppRecordExist_ = ERR_OK;
|
||||
MyStatus::GetInstance().isPreloadApplicationRecordExist_ = true;
|
||||
std::string bundleName = "com.test.game";
|
||||
int32_t userId = 100;
|
||||
int32_t appIndex = 0;
|
||||
|
||||
auto result = PreloadManagerService::GetInstance().LaunchGameCustomized(bundleName, userId, appIndex);
|
||||
EXPECT_EQ(result, ERR_PRELOAD_APP_RECORD_ALREADY_EXIST);
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest LaunchGameCustomized_002 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: PreloadManagerService
|
||||
* Name: LaunchGameCustomized_003
|
||||
* Function: LaunchGameCustomized
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: PreloadManagerService LaunchGameCustomized bundle mgr helper is null
|
||||
*/
|
||||
HWTEST_F(PreloadManagerServiceTest, LaunchGameCustomized_003, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest LaunchGameCustomized_003 start");
|
||||
|
||||
// Set up for bundle mgr helper null
|
||||
MyStatus::GetInstance().isMultiUserConcurrency_ = true;
|
||||
MyStatus::GetInstance().retCheckPreloadAppRecordExist_ = ERR_OK;
|
||||
MyStatus::GetInstance().isPreloadApplicationRecordExist_ = false;
|
||||
MyStatus::GetInstance().bundleMgrHelper_ = nullptr;
|
||||
std::string bundleName = "com.test.game";
|
||||
int32_t userId = 100;
|
||||
int32_t appIndex = 0;
|
||||
|
||||
auto result = PreloadManagerService::GetInstance().LaunchGameCustomized(bundleName, userId, appIndex);
|
||||
EXPECT_EQ(result, INNER_ERR);
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest LaunchGameCustomized_003 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: PreloadManagerService
|
||||
* Name: LaunchGameCustomized_004
|
||||
* Function: LaunchGameCustomized
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: PreloadManagerService LaunchGameCustomized get launch want failed
|
||||
*/
|
||||
HWTEST_F(PreloadManagerServiceTest, LaunchGameCustomized_004, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest LaunchGameCustomized_004 start");
|
||||
|
||||
// Set up for GetLaunchWantForBundle failure
|
||||
MyStatus::GetInstance().isMultiUserConcurrency_ = true;
|
||||
MyStatus::GetInstance().retCheckPreloadAppRecordExist_ = ERR_OK;
|
||||
MyStatus::GetInstance().isPreloadApplicationRecordExist_ = false;
|
||||
MyStatus::GetInstance().bundleMgrHelper_ = DelayedSingleton<BundleMgrHelper>::GetInstance();
|
||||
MyStatus::GetInstance().retGetLaunchWantForBundle_ = -1;
|
||||
std::string bundleName = "com.test.game";
|
||||
int32_t userId = 100;
|
||||
int32_t appIndex = 0;
|
||||
|
||||
auto result = PreloadManagerService::GetInstance().LaunchGameCustomized(bundleName, userId, appIndex);
|
||||
EXPECT_EQ(result, -1);
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "PreloadManagerServiceTest LaunchGameCustomized_004 end");
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -8809,5 +8809,87 @@ HWTEST_F(UIAbilityLifecycleManagerTest, CalcHideNativeWindow_0010, TestSize.Leve
|
||||
|
||||
EXPECT_FALSE(mgr->CalcHideNativeWindow(1, abilityInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CompleteForegroundSuccess_GameSAPreLaunch_0001
|
||||
* @tc.desc: CompleteForegroundSuccess with GameSAPreLaunch = true
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UIAbilityLifecycleManagerTest, CompleteForegroundSuccess_GameSAPreLaunch_0001, TestSize.Level1)
|
||||
{
|
||||
auto mgr = std::make_unique<UIAbilityLifecycleManager>();
|
||||
AbilityRequest abilityRequest;
|
||||
auto abilityRecord = UIAbilityRecord::CreateAbilityRecord(abilityRequest);
|
||||
abilityRecord->SetPendingState(AbilityState::FOREGROUND);
|
||||
abilityRecord->SetGameSAPreLaunch(true);
|
||||
|
||||
mgr->CompleteForegroundSuccess(abilityRecord);
|
||||
|
||||
EXPECT_EQ(abilityRecord->GetAbilityState(), AbilityState::FOREGROUND);
|
||||
EXPECT_TRUE(abilityRecord->IsGameSAPreLaunch());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CompleteForegroundSuccess_GameSAPreLaunch_0002
|
||||
* @tc.desc: CompleteForegroundSuccess with GameSAPreLaunch = false
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UIAbilityLifecycleManagerTest, CompleteForegroundSuccess_GameSAPreLaunch_0002, TestSize.Level1)
|
||||
{
|
||||
auto mgr = std::make_unique<UIAbilityLifecycleManager>();
|
||||
AbilityRequest abilityRequest;
|
||||
auto abilityRecord = UIAbilityRecord::CreateAbilityRecord(abilityRequest);
|
||||
abilityRecord->SetPendingState(AbilityState::FOREGROUND);
|
||||
abilityRecord->SetGameSAPreLaunch(false);
|
||||
|
||||
mgr->CompleteForegroundSuccess(abilityRecord);
|
||||
|
||||
EXPECT_EQ(abilityRecord->GetAbilityState(), AbilityState::FOREGROUND);
|
||||
EXPECT_FALSE(abilityRecord->IsGameSAPreLaunch());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CompleteForegroundSuccess_GameSAPreLaunch_0003
|
||||
* @tc.desc: CompleteForegroundSuccess with GameSAPreLaunch = true and startedByCall = true
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UIAbilityLifecycleManagerTest, CompleteForegroundSuccess_GameSAPreLaunch_0003, TestSize.Level1)
|
||||
{
|
||||
auto mgr = std::make_unique<UIAbilityLifecycleManager>();
|
||||
AbilityRequest abilityRequest;
|
||||
auto abilityRecord = UIAbilityRecord::CreateAbilityRecord(abilityRequest);
|
||||
abilityRecord->SetPendingState(AbilityState::FOREGROUND);
|
||||
abilityRecord->SetGameSAPreLaunch(true);
|
||||
abilityRecord->SetStartedByCall(true);
|
||||
abilityRecord->SetStartToForeground(true);
|
||||
abilityRecord->isReady_ = true;
|
||||
|
||||
mgr->CompleteForegroundSuccess(abilityRecord);
|
||||
|
||||
EXPECT_EQ(abilityRecord->GetAbilityState(), AbilityState::FOREGROUND);
|
||||
EXPECT_TRUE(abilityRecord->IsGameSAPreLaunch());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CompleteForegroundSuccess_GameSAPreLaunch_0004
|
||||
* @tc.desc: CompleteForegroundSuccess with GameSAPreLaunch = true and HasLastWant = true
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UIAbilityLifecycleManagerTest, CompleteForegroundSuccess_GameSAPreLaunch_0004, TestSize.Level1)
|
||||
{
|
||||
auto mgr = std::make_unique<UIAbilityLifecycleManager>();
|
||||
AbilityRequest abilityRequest;
|
||||
Want lastWant;
|
||||
lastWant.SetElementName("com.example.unittest", "MainAbility");
|
||||
auto abilityRecord = UIAbilityRecord::CreateAbilityRecord(abilityRequest);
|
||||
abilityRecord->SetPendingState(AbilityState::FOREGROUND);
|
||||
abilityRecord->SetGameSAPreLaunch(true);
|
||||
abilityRecord->SetLastWant(std::make_shared<Want>(lastWant));
|
||||
|
||||
mgr->CompleteForegroundSuccess(abilityRecord);
|
||||
|
||||
EXPECT_EQ(abilityRecord->GetAbilityState(), AbilityState::FOREGROUNDING);
|
||||
EXPECT_TRUE(abilityRecord->IsGameSAPreLaunch());
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
Reference in New Issue
Block a user