From 6fbdd6231afd34a4dbd65eb33150dcf734940e86 Mon Sep 17 00:00:00 2001 From: "DESKTOP-UGVMD4B\\DawnComing" Date: Mon, 11 May 2026 15:44:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=B8=E6=88=8F=E9=A2=84=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E5=A2=9E=E5=8A=A0TDD=E7=94=A8=E4=BE=8B=20Sig?= =?UTF-8?q?ned-off-by:=20lidongrui=20=20Co-Authored?= =?UTF-8?q?-By:=20Agent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js_ui_ability_test/js_ui_ability_test.cpp | 84 +++++++++++++++ .../preload_manager_service_test.cpp | 102 ++++++++++++++++++ .../ui_ability_lifecycle_manager_test.cpp | 82 ++++++++++++++ 3 files changed, 268 insertions(+) diff --git a/test/unittest/js_ui_ability_test/js_ui_ability_test.cpp b/test/unittest/js_ui_ability_test/js_ui_ability_test.cpp index 750cbcdd6b..d5f06e7751 100644 --- a/test/unittest/js_ui_ability_test/js_ui_ability_test.cpp +++ b/test/unittest/js_ui_ability_test/js_ui_ability_test.cpp @@ -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(runtime.get()); + auto ability = std::make_shared(*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( + reinterpret_cast(ref)); + EXPECT_NE(ability->jsAbilityObj_, nullptr); + + sptr sessionInfo = sptr::MakeSptr(); + EXPECT_NE(sessionInfo, nullptr); + ability->scene_ = std::make_shared(); + EXPECT_NE(ability->scene_, nullptr); + auto abilityContextImpl = std::make_shared(); + EXPECT_NE(abilityContextImpl, nullptr); + auto abilityInfo = std::make_shared(); + 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(runtime.get()); + auto ability = std::make_shared(*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( + reinterpret_cast(ref)); + EXPECT_NE(ability->jsAbilityObj_, nullptr); + + sptr sessionInfo = sptr::MakeSptr(); + EXPECT_NE(sessionInfo, nullptr); + ability->scene_ = std::make_shared(); + EXPECT_NE(ability->scene_, nullptr); + auto abilityContextImpl = std::make_shared(); + EXPECT_NE(abilityContextImpl, nullptr); + auto abilityInfo = std::make_shared(); + 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 diff --git a/test/unittest/preload_manager_service_test/preload_manager_service_test.cpp b/test/unittest/preload_manager_service_test/preload_manager_service_test.cpp index 16f2352941..87d7eb635f 100644 --- a/test/unittest/preload_manager_service_test/preload_manager_service_test.cpp +++ b/test/unittest/preload_manager_service_test/preload_manager_service_test.cpp @@ -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::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 diff --git a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp index 3f6418adc2..df7e2f210f 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp +++ b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp @@ -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(); + 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(); + 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(); + 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(); + 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(lastWant)); + + mgr->CompleteForegroundSuccess(abilityRecord); + + EXPECT_EQ(abilityRecord->GetAbilityState(), AbilityState::FOREGROUNDING); + EXPECT_TRUE(abilityRecord->IsGameSAPreLaunch()); +} } // namespace AAFwk } // namespace OHOS